blob: eb2d9c427b109f83e7fccf6b3191ccb025749920 [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
Frank Blaschka4a71df52008-02-15 09:19:42 +010040static int qeth_l3_register_addr_entry(struct qeth_card *,
41 struct qeth_ipaddr *);
42static int qeth_l3_deregister_addr_entry(struct qeth_card *,
43 struct qeth_ipaddr *);
Frank Blaschka4a71df52008-02-15 09:19:42 +010044
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +010045int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr,
46 char *buf)
Frank Blaschka4a71df52008-02-15 09:19:42 +010047{
48 if (proto == QETH_PROT_IPV4)
Julian Wiedmanne6b1b7d2019-12-18 17:34:44 +010049 return sprintf(buf, "%pI4", addr);
50 else
51 return sprintf(buf, "%pI6", addr);
Frank Blaschka4a71df52008-02-15 09:19:42 +010052}
53
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010054static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card,
55 struct qeth_ipaddr *query)
56{
Julian Wiedmann1b40d4b2019-10-31 13:42:20 +010057 u32 key = qeth_l3_ipaddr_hash(query);
Julian Wiedmannc5c48c52018-02-27 18:58:16 +010058 struct qeth_ipaddr *addr;
59
60 if (query->is_multicast) {
61 hash_for_each_possible(card->ip_mc_htable, addr, hnode, key)
62 if (qeth_l3_addr_match_ip(addr, query))
63 return addr;
64 } else {
65 hash_for_each_possible(card->ip_htable, addr, hnode, key)
66 if (qeth_l3_addr_match_ip(addr, query))
67 return addr;
68 }
69 return NULL;
70}
71
Frank Blaschka4a71df52008-02-15 09:19:42 +010072static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len)
73{
74 int i, j;
75 u8 octet;
76
77 for (i = 0; i < len; ++i) {
78 octet = addr[i];
79 for (j = 7; j >= 0; --j) {
80 bits[i*8 + j] = octet & 1;
81 octet >>= 1;
82 }
83 }
84}
85
Julian Wiedmann02f510f2017-12-13 18:56:32 +010086static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card,
87 struct qeth_ipaddr *addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +010088{
89 struct qeth_ipato_entry *ipatoe;
90 u8 addr_bits[128] = {0, };
91 u8 ipatoe_bits[128] = {0, };
92 int rc = 0;
93
94 if (!card->ipato.enabled)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +020095 return false;
Julian Wiedmannb22d73d62017-12-13 18:56:30 +010096 if (addr->type != QETH_IP_TYPE_NORMAL)
Gustavo A. R. Silva1a363b02018-08-09 14:48:04 +020097 return false;
Frank Blaschka4a71df52008-02-15 09:19:42 +010098
99 qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits,
100 (addr->proto == QETH_PROT_IPV4)? 4:16);
101 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
102 if (addr->proto != ipatoe->proto)
103 continue;
104 qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits,
105 (ipatoe->proto == QETH_PROT_IPV4) ?
106 4 : 16);
107 if (addr->proto == QETH_PROT_IPV4)
108 rc = !memcmp(addr_bits, ipatoe_bits,
109 min(32, ipatoe->mask_bits));
110 else
111 rc = !memcmp(addr_bits, ipatoe_bits,
112 min(128, ipatoe->mask_bits));
113 if (rc)
114 break;
115 }
116 /* invert? */
117 if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4)
118 rc = !rc;
119 else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6)
120 rc = !rc;
121
122 return rc;
123}
124
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100125static int qeth_l3_delete_ip(struct qeth_card *card,
126 struct qeth_ipaddr *tmp_addr)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200127{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100128 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200129 struct qeth_ipaddr *addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100130
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100131 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
132 QETH_CARD_TEXT(card, 2, "delrxip");
133 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
134 QETH_CARD_TEXT(card, 2, "delvipa");
135 else
136 QETH_CARD_TEXT(card, 2, "delip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100137
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200138 if (tmp_addr->proto == QETH_PROT_IPV4)
139 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100140 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200141 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
142 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100143 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200144
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100145 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
146 if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr))
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200147 return -ENOENT;
148
149 addr->ref_counter--;
Julian Wiedmann4964c662018-02-27 18:58:15 +0100150 if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200151 return rc;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200152
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100153 if (qeth_card_hw_is_reachable(card))
154 rc = qeth_l3_deregister_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200155
156 hash_del(&addr->hnode);
157 kfree(addr);
158
Frank Blaschka4a71df52008-02-15 09:19:42 +0100159 return rc;
160}
161
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100162static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100163{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100164 int rc = 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200165 struct qeth_ipaddr *addr;
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100166 char buf[40];
Frank Blaschka4a71df52008-02-15 09:19:42 +0100167
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100168 if (tmp_addr->type == QETH_IP_TYPE_RXIP)
169 QETH_CARD_TEXT(card, 2, "addrxip");
170 else if (tmp_addr->type == QETH_IP_TYPE_VIPA)
171 QETH_CARD_TEXT(card, 2, "addvipa");
172 else
173 QETH_CARD_TEXT(card, 2, "addip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200174
175 if (tmp_addr->proto == QETH_PROT_IPV4)
176 QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100177 else {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200178 QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8);
179 QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100180 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200181
Julian Wiedmannc5c48c52018-02-27 18:58:16 +0100182 addr = qeth_l3_find_addr_by_ip(card, tmp_addr);
183 if (addr) {
184 if (tmp_addr->type != QETH_IP_TYPE_NORMAL)
185 return -EADDRINUSE;
186 if (qeth_l3_addr_match_all(addr, tmp_addr)) {
187 addr->ref_counter++;
188 return 0;
189 }
190 qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u,
191 buf);
192 dev_warn(&card->gdev->dev,
193 "Registering IP address %s failed\n", buf);
194 return -EADDRINUSE;
195 } else {
Julian Wiedmannb80c08a2019-11-14 11:19:23 +0100196 addr = kmemdup(tmp_addr, sizeof(*tmp_addr), GFP_KERNEL);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200197 if (!addr)
198 return -ENOMEM;
199
Julian Wiedmannb22d73d62017-12-13 18:56:30 +0100200 if (qeth_l3_is_addr_covered_by_ipato(card, addr)) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200201 QETH_CARD_TEXT(card, 2, "tkovaddr");
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100202 addr->ipato = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200203 }
204 hash_add(card->ip_htable, &addr->hnode,
205 qeth_l3_ipaddr_hash(addr));
206
Ursula Brauna7531c12016-09-15 14:39:23 +0200207 if (!qeth_card_hw_is_reachable(card)) {
208 addr->disp_flag = QETH_DISP_ADDR_ADD;
209 return 0;
210 }
211
Julian Wiedmannadee2592019-12-18 17:34:48 +0100212 rc = qeth_l3_register_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200213
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100214 if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200215 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200216 } else {
217 hash_del(&addr->hnode);
218 kfree(addr);
219 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200220 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100221 return rc;
222}
223
Julian Wiedmann05a17852019-03-28 16:39:21 +0100224static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr,
225 bool add)
226{
227 int rc;
228
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100229 mutex_lock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100230 rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100231 mutex_unlock(&card->ip_lock);
Julian Wiedmann05a17852019-03-28 16:39:21 +0100232
233 return rc;
234}
235
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100236static void qeth_l3_drain_rx_mode_cache(struct qeth_card *card)
237{
238 struct qeth_ipaddr *addr;
239 struct hlist_node *tmp;
240 int i;
241
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100242 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
243 hash_del(&addr->hnode);
244 kfree(addr);
245 }
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100246}
247
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200248static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100249{
250 struct qeth_ipaddr *addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200251 struct hlist_node *tmp;
252 int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100253
Carsten Otte847a50f2010-06-21 22:57:05 +0000254 QETH_CARD_TEXT(card, 4, "clearip");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200255
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100256 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200257
258 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
259 if (!recover) {
260 hash_del(&addr->hnode);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100261 kfree(addr);
262 continue;
263 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200264 addr->disp_flag = QETH_DISP_ADDR_ADD;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100265 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200266
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100267 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100268}
Julian Wiedmannd0c74822019-03-28 16:39:19 +0100269
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200270static void qeth_l3_recover_ip(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100271{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200272 struct qeth_ipaddr *addr;
273 struct hlist_node *tmp;
274 int i;
275 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100276
Ursula Brauna7531c12016-09-15 14:39:23 +0200277 QETH_CARD_TEXT(card, 4, "recovrip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100278
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100279 mutex_lock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100280
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200281 hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) {
Julian Wiedmann98d823a2018-02-27 18:58:13 +0100282 if (addr->disp_flag == QETH_DISP_ADDR_ADD) {
Julian Wiedmannadee2592019-12-18 17:34:48 +0100283 rc = qeth_l3_register_addr_entry(card, addr);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200284
285 if (!rc) {
286 addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200287 } else {
288 hash_del(&addr->hnode);
289 kfree(addr);
290 }
291 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100292 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200293
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100294 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100295}
296
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100297static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply,
298 unsigned long data)
299{
300 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
301
302 switch (cmd->hdr.return_code) {
303 case IPA_RC_SUCCESS:
304 return 0;
305 case IPA_RC_DUPLICATE_IP_ADDRESS:
306 return -EADDRINUSE;
307 case IPA_RC_MC_ADDR_NOT_FOUND:
308 return -ENOENT;
309 case IPA_RC_LAN_OFFLINE:
310 return -ENETDOWN;
311 default:
312 return -EIO;
313 }
314}
315
Frank Blaschka4a71df52008-02-15 09:19:42 +0100316static int qeth_l3_send_setdelmc(struct qeth_card *card,
317 struct qeth_ipaddr *addr, int ipacmd)
318{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100319 struct qeth_cmd_buffer *iob;
320 struct qeth_ipa_cmd *cmd;
321
Carsten Otte847a50f2010-06-21 22:57:05 +0000322 QETH_CARD_TEXT(card, 4, "setdelmc");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100323
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200324 iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto,
325 IPA_DATA_SIZEOF(setdelipm));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100326 if (!iob)
327 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100328 cmd = __ipa_cmd(iob);
Julian Wiedmann8bf70b62019-10-31 13:42:21 +0100329 if (addr->proto == QETH_PROT_IPV6) {
330 cmd->data.setdelipm.ip = addr->u.a6.addr;
331 ipv6_eth_mc_map(&addr->u.a6.addr, cmd->data.setdelipm.mac);
332 } else {
333 cmd->data.setdelipm.ip.s6_addr32[3] = addr->u.a4.addr;
334 ip_eth_mc_map(addr->u.a4.addr, cmd->data.setdelipm.mac);
335 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100336
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100337 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100338}
339
Julian Wiedmann490df972019-12-18 17:34:46 +0100340static void qeth_l3_set_ipv6_prefix(struct in6_addr *prefix, unsigned int len)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100341{
Julian Wiedmann490df972019-12-18 17:34:46 +0100342 unsigned int i = 0;
343
344 while (len && i < 4) {
345 int mask_len = min_t(int, len, 32);
346
347 prefix->s6_addr32[i] = inet_make_mask(mask_len);
348 len -= mask_len;
349 i++;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100350 }
351}
352
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100353static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100354{
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100355 switch (addr->type) {
356 case QETH_IP_TYPE_RXIP:
357 return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
358 case QETH_IP_TYPE_VIPA:
359 return (set) ? QETH_IPA_SETIP_VIPA_FLAG :
360 QETH_IPA_DELIP_VIPA_FLAG;
361 default:
362 return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0;
363 }
364}
365
366static int qeth_l3_send_setdelip(struct qeth_card *card,
367 struct qeth_ipaddr *addr,
368 enum qeth_ipa_cmds ipacmd)
369{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100370 struct qeth_cmd_buffer *iob;
371 struct qeth_ipa_cmd *cmd;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100372 u32 flags;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100373
Carsten Otte847a50f2010-06-21 22:57:05 +0000374 QETH_CARD_TEXT(card, 4, "setdelip");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100375
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200376 iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto,
377 IPA_DATA_SIZEOF(setdelip6));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100378 if (!iob)
379 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100380 cmd = __ipa_cmd(iob);
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100381
382 flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP);
383 QETH_CARD_TEXT_(card, 4, "flags%02X", flags);
384
Frank Blaschka4a71df52008-02-15 09:19:42 +0100385 if (addr->proto == QETH_PROT_IPV6) {
Julian Wiedmann490df972019-12-18 17:34:46 +0100386 cmd->data.setdelip6.addr = addr->u.a6.addr;
387 qeth_l3_set_ipv6_prefix(&cmd->data.setdelip6.prefix,
388 addr->u.a6.pfxlen);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100389 cmd->data.setdelip6.flags = flags;
390 } else {
Julian Wiedmann490df972019-12-18 17:34:46 +0100391 cmd->data.setdelip4.addr = addr->u.a4.addr;
392 cmd->data.setdelip4.mask = addr->u.a4.mask;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100393 cmd->data.setdelip4.flags = flags;
394 }
395
Julian Wiedmann4b7ae122019-02-12 18:33:23 +0100396 return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100397}
398
399static int qeth_l3_send_setrouting(struct qeth_card *card,
400 enum qeth_routing_types type, enum qeth_prot_versions prot)
401{
402 int rc;
403 struct qeth_ipa_cmd *cmd;
404 struct qeth_cmd_buffer *iob;
405
Carsten Otte847a50f2010-06-21 22:57:05 +0000406 QETH_CARD_TEXT(card, 4, "setroutg");
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200407 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETRTG, prot,
408 IPA_DATA_SIZEOF(setrtg));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100409 if (!iob)
410 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100411 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100412 cmd->data.setrtg.type = (type);
413 rc = qeth_send_ipa_cmd(card, iob, NULL, NULL);
414
415 return rc;
416}
417
Stefan Raspl82e2e782013-03-18 20:04:43 +0000418static int qeth_l3_correct_routing_type(struct qeth_card *card,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100419 enum qeth_routing_types *type, enum qeth_prot_versions prot)
420{
Julian Wiedmann379ac992019-04-25 18:25:57 +0200421 if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100422 switch (*type) {
423 case NO_ROUTER:
424 case PRIMARY_CONNECTOR:
425 case SECONDARY_CONNECTOR:
426 case MULTICAST_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000427 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100428 default:
429 goto out_inval;
430 }
431 } else {
432 switch (*type) {
433 case NO_ROUTER:
434 case PRIMARY_ROUTER:
435 case SECONDARY_ROUTER:
Stefan Raspl82e2e782013-03-18 20:04:43 +0000436 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100437 case MULTICAST_ROUTER:
438 if (qeth_is_ipafunc_supported(card, prot,
439 IPA_OSA_MC_ROUTER))
Stefan Raspl82e2e782013-03-18 20:04:43 +0000440 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100441 default:
442 goto out_inval;
443 }
444 }
445out_inval:
Frank Blaschka4a71df52008-02-15 09:19:42 +0100446 *type = NO_ROUTER;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000447 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100448}
449
450int qeth_l3_setrouting_v4(struct qeth_card *card)
451{
452 int rc;
453
Carsten Otte847a50f2010-06-21 22:57:05 +0000454 QETH_CARD_TEXT(card, 3, "setrtg4");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100455
Stefan Raspl82e2e782013-03-18 20:04:43 +0000456 rc = qeth_l3_correct_routing_type(card, &card->options.route4.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100457 QETH_PROT_IPV4);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000458 if (rc)
459 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100460
461 rc = qeth_l3_send_setrouting(card, card->options.route4.type,
462 QETH_PROT_IPV4);
463 if (rc) {
464 card->options.route4.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100465 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
466 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100467 }
468 return rc;
469}
470
471int qeth_l3_setrouting_v6(struct qeth_card *card)
472{
473 int rc = 0;
474
Carsten Otte847a50f2010-06-21 22:57:05 +0000475 QETH_CARD_TEXT(card, 3, "setrtg6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100476
477 if (!qeth_is_supported(card, IPA_IPV6))
478 return 0;
Stefan Raspl82e2e782013-03-18 20:04:43 +0000479 rc = qeth_l3_correct_routing_type(card, &card->options.route6.type,
Frank Blaschka4a71df52008-02-15 09:19:42 +0100480 QETH_PROT_IPV6);
Stefan Raspl82e2e782013-03-18 20:04:43 +0000481 if (rc)
482 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100483
484 rc = qeth_l3_send_setrouting(card, card->options.route6.type,
485 QETH_PROT_IPV6);
486 if (rc) {
487 card->options.route6.type = NO_ROUTER;
Julian Wiedmanne19e5be2018-11-02 19:04:08 +0100488 QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n",
489 rc, CARD_DEVID(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100490 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100491 return rc;
492}
493
494/*
495 * IP address takeover related functions
496 */
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100497
498/**
499 * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs.
500 *
501 * Caller must hold ip_lock.
502 */
503void qeth_l3_update_ipato(struct qeth_card *card)
504{
505 struct qeth_ipaddr *addr;
506 unsigned int i;
507
508 hash_for_each(card->ip_htable, i, addr, hnode) {
509 if (addr->type != QETH_IP_TYPE_NORMAL)
510 continue;
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100511 addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100512 }
513}
514
Frank Blaschka4a71df52008-02-15 09:19:42 +0100515static void qeth_l3_clear_ipato_list(struct qeth_card *card)
516{
Frank Blaschka4a71df52008-02-15 09:19:42 +0100517 struct qeth_ipato_entry *ipatoe, *tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100518
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100519 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200520
Frank Blaschka4a71df52008-02-15 09:19:42 +0100521 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
522 list_del(&ipatoe->entry);
523 kfree(ipatoe);
524 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200525
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100526 qeth_l3_update_ipato(card);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100527 mutex_unlock(&card->ip_lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100528}
529
530int qeth_l3_add_ipato_entry(struct qeth_card *card,
531 struct qeth_ipato_entry *new)
532{
533 struct qeth_ipato_entry *ipatoe;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100534 int rc = 0;
535
Carsten Otte847a50f2010-06-21 22:57:05 +0000536 QETH_CARD_TEXT(card, 2, "addipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200537
Julian Wiedmann23901662019-12-18 17:34:45 +0100538 mutex_lock(&card->conf_mutex);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100539 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200540
Frank Blaschka4a71df52008-02-15 09:19:42 +0100541 list_for_each_entry(ipatoe, &card->ipato.entries, entry) {
542 if (ipatoe->proto != new->proto)
543 continue;
544 if (!memcmp(ipatoe->addr, new->addr,
545 (ipatoe->proto == QETH_PROT_IPV4)? 4:16) &&
546 (ipatoe->mask_bits == new->mask_bits)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100547 rc = -EEXIST;
548 break;
549 }
550 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200551
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100552 if (!rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100553 list_add_tail(&new->entry, &card->ipato.entries);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100554 qeth_l3_update_ipato(card);
555 }
Frank Blaschka4a71df52008-02-15 09:19:42 +0100556
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100557 mutex_unlock(&card->ip_lock);
Julian Wiedmann23901662019-12-18 17:34:45 +0100558 mutex_unlock(&card->conf_mutex);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200559
Frank Blaschka4a71df52008-02-15 09:19:42 +0100560 return rc;
561}
562
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100563int qeth_l3_del_ipato_entry(struct qeth_card *card,
564 enum qeth_prot_versions proto, u8 *addr,
565 int mask_bits)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100566{
567 struct qeth_ipato_entry *ipatoe, *tmp;
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100568 int rc = -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100569
Carsten Otte847a50f2010-06-21 22:57:05 +0000570 QETH_CARD_TEXT(card, 2, "delipato");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200571
Julian Wiedmann23901662019-12-18 17:34:45 +0100572 mutex_lock(&card->conf_mutex);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100573 mutex_lock(&card->ip_lock);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200574
Frank Blaschka4a71df52008-02-15 09:19:42 +0100575 list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) {
576 if (ipatoe->proto != proto)
577 continue;
578 if (!memcmp(ipatoe->addr, addr,
579 (proto == QETH_PROT_IPV4)? 4:16) &&
580 (ipatoe->mask_bits == mask_bits)) {
581 list_del(&ipatoe->entry);
Julian Wiedmann02f510f2017-12-13 18:56:32 +0100582 qeth_l3_update_ipato(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100583 kfree(ipatoe);
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100584 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100585 }
586 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200587
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +0100588 mutex_unlock(&card->ip_lock);
Julian Wiedmann23901662019-12-18 17:34:45 +0100589 mutex_unlock(&card->conf_mutex);
590
Julian Wiedmannb9ea5252017-12-27 17:44:28 +0100591 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100592}
593
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100594int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip,
595 enum qeth_ip_types type,
596 enum qeth_prot_versions proto)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100597{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100598 struct qeth_ipaddr addr;
Julian Wiedmann23901662019-12-18 17:34:45 +0100599 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100600
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100601 qeth_l3_init_ipaddr(&addr, type, proto);
602 if (proto == QETH_PROT_IPV4)
603 memcpy(&addr.u.a4.addr, ip, 4);
604 else
605 memcpy(&addr.u.a6.addr, ip, 16);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200606
Julian Wiedmann23901662019-12-18 17:34:45 +0100607 mutex_lock(&card->conf_mutex);
608 rc = qeth_l3_modify_ip(card, &addr, add);
609 mutex_unlock(&card->conf_mutex);
610
611 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100612}
613
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100614int qeth_l3_modify_hsuid(struct qeth_card *card, bool add)
Frank Blaschka4a71df52008-02-15 09:19:42 +0100615{
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100616 struct qeth_ipaddr addr;
Julian Wiedmann05a17852019-03-28 16:39:21 +0100617 unsigned int i;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100618
Julian Wiedmann1617dae2018-03-09 18:13:02 +0100619 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
620 addr.u.a6.addr.s6_addr[0] = 0xfe;
621 addr.u.a6.addr.s6_addr[1] = 0x80;
622 for (i = 0; i < 8; i++)
623 addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i];
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200624
Julian Wiedmann05a17852019-03-28 16:39:21 +0100625 return qeth_l3_modify_ip(card, &addr, add);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100626}
627
628static int qeth_l3_register_addr_entry(struct qeth_card *card,
629 struct qeth_ipaddr *addr)
630{
631 char buf[50];
632 int rc = 0;
633 int cnt = 3;
634
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100635 if (card->options.sniffer)
636 return 0;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +0200637
Frank Blaschka4a71df52008-02-15 09:19:42 +0100638 if (addr->proto == QETH_PROT_IPV4) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000639 QETH_CARD_TEXT(card, 2, "setaddr4");
640 QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100641 } else if (addr->proto == QETH_PROT_IPV6) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000642 QETH_CARD_TEXT(card, 2, "setaddr6");
643 QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8);
644 QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100645 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +0000646 QETH_CARD_TEXT(card, 2, "setaddr?");
647 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100648 }
649 do {
650 if (addr->is_multicast)
651 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM);
652 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100653 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100654 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000655 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100656 } while ((--cnt > 0) && rc);
657 if (rc) {
Carsten Otte847a50f2010-06-21 22:57:05 +0000658 QETH_CARD_TEXT(card, 2, "FAILED");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100659 qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf);
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100660 dev_warn(&card->gdev->dev,
661 "Registering IP address %s failed\n", buf);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100662 }
663 return rc;
664}
665
666static int qeth_l3_deregister_addr_entry(struct qeth_card *card,
667 struct qeth_ipaddr *addr)
668{
669 int rc = 0;
670
Julian Wiedmannbd74a7f2018-11-02 19:04:09 +0100671 if (card->options.sniffer)
672 return 0;
673
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, "deladdr4");
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, "deladdr6");
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, "deladdr?");
683 QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100684 }
685 if (addr->is_multicast)
686 rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM);
687 else
Julian Wiedmannb1d5e362018-03-09 18:13:03 +0100688 rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP);
Frank Blaschkac4cef072008-07-14 09:59:31 +0200689 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +0000690 QETH_CARD_TEXT(card, 2, "failed");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100691
692 return rc;
693}
694
Frank Blaschka4a71df52008-02-15 09:19:42 +0100695static int qeth_l3_setadapter_parms(struct qeth_card *card)
696{
Julian Wiedmann699d3fe2017-08-15 17:02:41 +0200697 int rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100698
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200699 QETH_CARD_TEXT(card, 2, "setadprm");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100700
Frank Blaschka4a71df52008-02-15 09:19:42 +0100701 if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) {
702 rc = qeth_setadpparms_change_macaddr(card);
703 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100704 dev_warn(&card->gdev->dev, "Reading the adapter MAC"
Heiko Carstens6ea2fde2009-01-04 17:36:32 -0800705 " address failed\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100706 }
707
Frank Blaschka4a71df52008-02-15 09:19:42 +0100708 return rc;
709}
710
Frank Blaschka4a71df52008-02-15 09:19:42 +0100711static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card)
712{
713 int rc;
714
Carsten Otte847a50f2010-06-21 22:57:05 +0000715 QETH_CARD_TEXT(card, 3, "ipaarp");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100716
717 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100718 dev_info(&card->gdev->dev,
719 "ARP processing not supported on %s!\n",
720 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100721 return 0;
722 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200723 rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200724 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100725 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100726 dev_warn(&card->gdev->dev,
727 "Starting ARP processing support for %s failed\n",
728 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100729 }
730 return rc;
731}
732
Frank Blaschka4a71df52008-02-15 09:19:42 +0100733static int qeth_l3_start_ipa_source_mac(struct qeth_card *card)
734{
735 int rc;
736
Carsten Otte847a50f2010-06-21 22:57:05 +0000737 QETH_CARD_TEXT(card, 3, "stsrcmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100738
Frank Blaschka4a71df52008-02-15 09:19:42 +0100739 if (!qeth_is_supported(card, IPA_SOURCE_MAC)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100740 dev_info(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800741 "Inbound source MAC-address not supported on %s\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100742 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100743 return -EOPNOTSUPP;
744 }
745
Thomas Richter4d7def22015-09-18 16:06:51 +0200746 rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200747 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100748 if (rc)
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100749 dev_warn(&card->gdev->dev,
Ursula Braunfe94e2e2009-01-04 17:34:52 -0800750 "Starting source MAC-address support for %s failed\n",
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100751 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100752 return rc;
753}
754
755static int qeth_l3_start_ipa_vlan(struct qeth_card *card)
756{
757 int rc = 0;
758
Carsten Otte847a50f2010-06-21 22:57:05 +0000759 QETH_CARD_TEXT(card, 3, "strtvlan");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100760
761 if (!qeth_is_supported(card, IPA_FULL_VLAN)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100762 dev_info(&card->gdev->dev,
763 "VLAN not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100764 return -EOPNOTSUPP;
765 }
766
Thomas Richter4d7def22015-09-18 16:06:51 +0200767 rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200768 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100769 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100770 dev_warn(&card->gdev->dev,
771 "Starting VLAN support for %s failed\n",
772 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100773 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100774 dev_info(&card->gdev->dev, "VLAN enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100775 }
776 return rc;
777}
778
779static int qeth_l3_start_ipa_multicast(struct qeth_card *card)
780{
781 int rc;
782
Carsten Otte847a50f2010-06-21 22:57:05 +0000783 QETH_CARD_TEXT(card, 3, "stmcast");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100784
785 if (!qeth_is_supported(card, IPA_MULTICASTING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100786 dev_info(&card->gdev->dev,
787 "Multicast not supported on %s\n",
788 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100789 return -EOPNOTSUPP;
790 }
791
Thomas Richter4d7def22015-09-18 16:06:51 +0200792 rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200793 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100794 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100795 dev_warn(&card->gdev->dev,
796 "Starting multicast support for %s failed\n",
797 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100798 } else {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100799 dev_info(&card->gdev->dev, "Multicast enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100800 card->dev->flags |= IFF_MULTICAST;
801 }
802 return rc;
803}
804
Frank Blaschka4a71df52008-02-15 09:19:42 +0100805static int qeth_l3_softsetup_ipv6(struct qeth_card *card)
806{
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200807 u32 ipv6_data = 3;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100808 int rc;
809
Carsten Otte847a50f2010-06-21 22:57:05 +0000810 QETH_CARD_TEXT(card, 3, "softipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100811
Julian Wiedmann379ac992019-04-25 18:25:57 +0200812 if (IS_IQD(card))
Julian Wiedmann23274592017-06-06 14:33:44 +0200813 goto out;
814
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200815 rc = qeth_send_simple_setassparms(card, IPA_IPV6, IPA_CMD_ASS_START,
816 &ipv6_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100817 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100818 dev_err(&card->gdev->dev,
819 "Activating IPv6 support for %s failed\n",
820 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100821 return rc;
822 }
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200823 rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6, IPA_CMD_ASS_START,
824 NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100825 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100826 dev_err(&card->gdev->dev,
827 "Activating IPv6 support for %s failed\n",
828 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100829 return rc;
830 }
Kittipon Meesompopa8155b02018-04-26 09:42:21 +0200831 rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200832 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100833 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100834 dev_warn(&card->gdev->dev,
835 "Enabling the passthrough mode for %s failed\n",
836 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100837 return rc;
838 }
839out:
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100840 dev_info(&card->gdev->dev, "IPV6 enabled\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100841 return 0;
842}
Frank Blaschka4a71df52008-02-15 09:19:42 +0100843
844static int qeth_l3_start_ipa_ipv6(struct qeth_card *card)
845{
Carsten Otte847a50f2010-06-21 22:57:05 +0000846 QETH_CARD_TEXT(card, 3, "strtipv6");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100847
848 if (!qeth_is_supported(card, IPA_IPV6)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100849 dev_info(&card->gdev->dev,
850 "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100851 return 0;
852 }
Julian Wiedmannc0622042017-12-20 20:10:58 +0100853 return qeth_l3_softsetup_ipv6(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100854}
855
856static int qeth_l3_start_ipa_broadcast(struct qeth_card *card)
857{
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200858 u32 filter_data = 1;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100859 int rc;
860
Carsten Otte847a50f2010-06-21 22:57:05 +0000861 QETH_CARD_TEXT(card, 3, "stbrdcst");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100862 card->info.broadcast_capable = 0;
863 if (!qeth_is_supported(card, IPA_FILTERING)) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100864 dev_info(&card->gdev->dev,
865 "Broadcast not supported on %s\n",
866 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100867 rc = -EOPNOTSUPP;
868 goto out;
869 }
Thomas Richter4d7def22015-09-18 16:06:51 +0200870 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200871 IPA_CMD_ASS_START, NULL);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100872 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100873 dev_warn(&card->gdev->dev, "Enabling broadcast filtering for "
874 "%s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100875 goto out;
876 }
877
Thomas Richter4d7def22015-09-18 16:06:51 +0200878 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200879 IPA_CMD_ASS_CONFIGURE, &filter_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100880 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100881 dev_warn(&card->gdev->dev,
882 "Setting up broadcast filtering for %s failed\n",
883 QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100884 goto out;
885 }
886 card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO;
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100887 dev_info(&card->gdev->dev, "Broadcast enabled\n");
Thomas Richter4d7def22015-09-18 16:06:51 +0200888 rc = qeth_send_simple_setassparms(card, IPA_FILTERING,
Julian Wiedmann1c696c892019-06-27 17:01:23 +0200889 IPA_CMD_ASS_ENABLE, &filter_data);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100890 if (rc) {
Frank Blaschka74eacdb2008-12-25 13:39:49 +0100891 dev_warn(&card->gdev->dev, "Setting up broadcast echo "
892 "filtering for %s failed\n", QETH_CARD_IFNAME(card));
Frank Blaschka4a71df52008-02-15 09:19:42 +0100893 goto out;
894 }
895 card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO;
896out:
897 if (card->info.broadcast_capable)
898 card->dev->flags |= IFF_BROADCAST;
899 else
900 card->dev->flags &= ~IFF_BROADCAST;
901 return rc;
902}
903
Frank Blaschka4a71df52008-02-15 09:19:42 +0100904static int qeth_l3_start_ipassists(struct qeth_card *card)
905{
Carsten Otte847a50f2010-06-21 22:57:05 +0000906 QETH_CARD_TEXT(card, 3, "strtipas");
Einar Lueckd64ecc22009-11-12 00:11:41 +0000907
Frank Blaschka4a71df52008-02-15 09:19:42 +0100908 qeth_l3_start_ipa_arp_processing(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100909 qeth_l3_start_ipa_source_mac(card); /* go on*/
910 qeth_l3_start_ipa_vlan(card); /* go on*/
911 qeth_l3_start_ipa_multicast(card); /* go on*/
912 qeth_l3_start_ipa_ipv6(card); /* go on*/
913 qeth_l3_start_ipa_broadcast(card); /* go on*/
Frank Blaschka4a71df52008-02-15 09:19:42 +0100914 return 0;
915}
916
Frank Blaschka4a71df52008-02-15 09:19:42 +0100917static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card,
918 struct qeth_reply *reply, unsigned long data)
919{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100920 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100921
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100922 if (cmd->hdr.return_code)
923 return -EIO;
924
925 ether_addr_copy(card->dev->dev_addr,
926 cmd->data.create_destroy_addr.unique_id);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100927 return 0;
928}
929
930static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card)
931{
932 int rc = 0;
933 struct qeth_cmd_buffer *iob;
934 struct qeth_ipa_cmd *cmd;
935
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200936 QETH_CARD_TEXT(card, 2, "hsrmac");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100937
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200938 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6,
939 IPA_DATA_SIZEOF(create_destroy_addr));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100940 if (!iob)
941 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100942 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100943 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
944 card->info.unique_id;
945
946 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb,
947 NULL);
948 return rc;
949}
950
951static int qeth_l3_get_unique_id_cb(struct qeth_card *card,
952 struct qeth_reply *reply, unsigned long data)
953{
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100954 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100955
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100956 if (cmd->hdr.return_code == 0) {
Frank Blaschka4a71df52008-02-15 09:19:42 +0100957 card->info.unique_id = *((__u16 *)
958 &cmd->data.create_destroy_addr.unique_id[6]);
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100959 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100960 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +0100961
962 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
963 UNIQUE_ID_NOT_BY_CARD;
964 dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n");
965 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +0100966}
967
968static int qeth_l3_get_unique_id(struct qeth_card *card)
969{
970 int rc = 0;
971 struct qeth_cmd_buffer *iob;
972 struct qeth_ipa_cmd *cmd;
973
Julian Wiedmann57a688aa2019-06-11 18:37:55 +0200974 QETH_CARD_TEXT(card, 2, "guniqeid");
Frank Blaschka4a71df52008-02-15 09:19:42 +0100975
976 if (!qeth_is_supported(card, IPA_IPV6)) {
977 card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED |
978 UNIQUE_ID_NOT_BY_CARD;
979 return 0;
980 }
981
Julian Wiedmanna59d1212019-06-27 17:01:22 +0200982 iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6,
983 IPA_DATA_SIZEOF(create_destroy_addr));
Thomas Richter1aec42b2015-01-21 13:39:10 +0100984 if (!iob)
985 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +0100986 cmd = __ipa_cmd(iob);
Frank Blaschka4a71df52008-02-15 09:19:42 +0100987 *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) =
988 card->info.unique_id;
989
990 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL);
991 return rc;
992}
993
Ursula Braun76b11f82010-01-11 02:50:50 +0000994static int
995qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply,
996 unsigned long data)
997{
998 struct qeth_ipa_cmd *cmd;
999 __u16 rc;
1000
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001001 QETH_CARD_TEXT(card, 2, "diastrcb");
Ursula Braun76b11f82010-01-11 02:50:50 +00001002
1003 cmd = (struct qeth_ipa_cmd *)data;
1004 rc = cmd->hdr.return_code;
Ursula Brauna9591892010-03-08 20:36:55 +00001005 if (rc)
Carsten Otte847a50f2010-06-21 22:57:05 +00001006 QETH_CARD_TEXT_(card, 2, "dxter%x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00001007 switch (cmd->data.diagass.action) {
1008 case QETH_DIAGS_CMD_TRACE_QUERY:
1009 break;
1010 case QETH_DIAGS_CMD_TRACE_DISABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001011 switch (rc) {
1012 case 0:
1013 case IPA_RC_INVALID_SUBCMD:
1014 card->info.promisc_mode = SET_PROMISC_MODE_OFF;
1015 dev_info(&card->gdev->dev, "The HiperSockets network "
1016 "traffic analyzer is deactivated\n");
1017 break;
1018 default:
1019 break;
1020 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001021 break;
1022 case QETH_DIAGS_CMD_TRACE_ENABLE:
Ursula Brauna9591892010-03-08 20:36:55 +00001023 switch (rc) {
1024 case 0:
1025 card->info.promisc_mode = SET_PROMISC_MODE_ON;
1026 dev_info(&card->gdev->dev, "The HiperSockets network "
1027 "traffic analyzer is activated\n");
1028 break;
1029 case IPA_RC_HARDWARE_AUTH_ERROR:
1030 dev_warn(&card->gdev->dev, "The device is not "
1031 "authorized to run as a HiperSockets network "
1032 "traffic analyzer\n");
1033 break;
1034 case IPA_RC_TRACE_ALREADY_ACTIVE:
1035 dev_warn(&card->gdev->dev, "A HiperSockets "
1036 "network traffic analyzer is already "
1037 "active in the HiperSockets LAN\n");
1038 break;
1039 default:
1040 break;
1041 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001042 break;
1043 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001044 QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n",
1045 cmd->data.diagass.action, CARD_DEVID(card));
Ursula Braun76b11f82010-01-11 02:50:50 +00001046 }
1047
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001048 return rc ? -EIO : 0;
Ursula Braun76b11f82010-01-11 02:50:50 +00001049}
1050
1051static int
1052qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd)
1053{
1054 struct qeth_cmd_buffer *iob;
1055 struct qeth_ipa_cmd *cmd;
1056
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001057 QETH_CARD_TEXT(card, 2, "diagtrac");
Ursula Braun76b11f82010-01-11 02:50:50 +00001058
Julian Wiedmann5cfbe102019-06-27 17:01:25 +02001059 iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRACE, 0);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001060 if (!iob)
1061 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001062 cmd = __ipa_cmd(iob);
Ursula Braun76b11f82010-01-11 02:50:50 +00001063 cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET;
1064 cmd->data.diagass.action = diags_cmd;
1065 return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL);
1066}
1067
Julian Wiedmann8659c182019-11-14 11:19:22 +01001068static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg)
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001069{
Julian Wiedmann8659c182019-11-14 11:19:22 +01001070 struct qeth_card *card = arg;
Julian Wiedmann611abe52019-11-14 11:19:21 +01001071 struct inet6_dev *in6_dev;
1072 struct in_device *in4_dev;
1073 struct qeth_ipaddr *ipm;
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001074 struct qeth_ipaddr tmp;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001075 struct ip_mc_list *im4;
Julian Wiedmann611abe52019-11-14 11:19:21 +01001076 struct ifmcaddr6 *im6;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001077
Carsten Otte847a50f2010-06-21 22:57:05 +00001078 QETH_CARD_TEXT(card, 4, "addmc");
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001079
Julian Wiedmann611abe52019-11-14 11:19:21 +01001080 if (!dev || !(dev->flags & IFF_UP))
1081 goto out;
1082
Julian Wiedmann8659c182019-11-14 11:19:22 +01001083 in4_dev = __in_dev_get_rtnl(dev);
Julian Wiedmann611abe52019-11-14 11:19:21 +01001084 if (!in4_dev)
1085 goto walk_ipv6;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001086
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001087 qeth_l3_init_ipaddr(&tmp, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
1088 tmp.disp_flag = QETH_DISP_ADDR_ADD;
1089 tmp.is_multicast = 1;
1090
Julian Wiedmann8659c182019-11-14 11:19:22 +01001091 for (im4 = rtnl_dereference(in4_dev->mc_list); im4 != NULL;
1092 im4 = rtnl_dereference(im4->next_rcu)) {
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001093 tmp.u.a4.addr = im4->multiaddr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001094
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001095 ipm = qeth_l3_find_addr_by_ip(card, &tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001096 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001097 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001098 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001099 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001100 }
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001101
1102 ipm = kmemdup(&tmp, sizeof(tmp), GFP_KERNEL);
1103 if (!ipm)
1104 continue;
1105
1106 hash_add(card->ip_mc_htable, &ipm->hnode,
1107 qeth_l3_ipaddr_hash(ipm));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001108 }
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001109
Julian Wiedmann611abe52019-11-14 11:19:21 +01001110walk_ipv6:
1111 if (!qeth_is_supported(card, IPA_IPV6))
1112 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001113
Julian Wiedmann611abe52019-11-14 11:19:21 +01001114 in6_dev = __in6_dev_get(dev);
1115 if (!in6_dev)
1116 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001117
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001118 qeth_l3_init_ipaddr(&tmp, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6);
1119 tmp.disp_flag = QETH_DISP_ADDR_ADD;
1120 tmp.is_multicast = 1;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001121
Julian Wiedmannddf28102019-11-14 11:19:19 +01001122 read_lock_bh(&in6_dev->lock);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001123 for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) {
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001124 tmp.u.a6.addr = im6->mca_addr;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001125
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001126 ipm = qeth_l3_find_addr_by_ip(card, &tmp);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001127 if (ipm) {
Julian Wiedmannc5c48c52018-02-27 18:58:16 +01001128 /* for mcast, by-IP match means full match */
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001129 ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING;
1130 continue;
1131 }
1132
Julian Wiedmannb80c08a2019-11-14 11:19:23 +01001133 ipm = kmemdup(&tmp, sizeof(tmp), GFP_ATOMIC);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001134 if (!ipm)
1135 continue;
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001136
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001137 hash_add(card->ip_mc_htable,
1138 &ipm->hnode, qeth_l3_ipaddr_hash(ipm));
1139
Frank Blaschka4a71df52008-02-15 09:19:42 +01001140 }
Julian Wiedmannddf28102019-11-14 11:19:19 +01001141 read_unlock_bh(&in6_dev->lock);
1142
Julian Wiedmann611abe52019-11-14 11:19:21 +01001143out:
Julian Wiedmann8659c182019-11-14 11:19:22 +01001144 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001145}
1146
Patrick McHardy80d5c362013-04-19 02:04:28 +00001147static int qeth_l3_vlan_rx_add_vid(struct net_device *dev,
1148 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001149{
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001150 struct qeth_card *card = dev->ml_priv;
1151
Julian Wiedmann8659c182019-11-14 11:19:22 +01001152 QETH_CARD_TEXT_(card, 4, "aid:%d", vid);
Jiri Pirko8e586132011-12-08 19:52:37 -05001153 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001154}
1155
Patrick McHardy80d5c362013-04-19 02:04:28 +00001156static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev,
1157 __be16 proto, u16 vid)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001158{
Heiko Carstens509e2562008-07-26 02:24:10 -07001159 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001160
Carsten Otte847a50f2010-06-21 22:57:05 +00001161 QETH_CARD_TEXT_(card, 4, "kid:%d", vid);
Jiri Pirko8e586132011-12-08 19:52:37 -05001162 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001163}
1164
Julian Wiedmannd4560152019-02-28 18:59:39 +01001165static void qeth_l3_stop_card(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001166{
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02001167 QETH_CARD_TEXT(card, 2, "stopcard");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001168
1169 qeth_set_allowed_threads(card, 0, 1);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001170
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001171 cancel_work_sync(&card->rx_mode_work);
1172 qeth_l3_drain_rx_mode_cache(card);
1173
Ursula Braun76b11f82010-01-11 02:50:50 +00001174 if (card->options.sniffer &&
1175 (card->info.promisc_mode == SET_PROMISC_MODE_ON))
1176 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
Julian Wiedmann0f7aedbd2019-02-28 18:59:44 +01001177
Frank Blaschka4a71df52008-02-15 09:19:42 +01001178 if (card->state == CARD_STATE_SOFTSETUP) {
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02001179 qeth_l3_clear_ip_htable(card, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001180 qeth_clear_ipacmd_list(card);
1181 card->state = CARD_STATE_HARDSETUP;
1182 }
1183 if (card->state == CARD_STATE_HARDSETUP) {
Julian Wiedmann41c47da2019-04-17 18:17:28 +02001184 qeth_drain_output_queues(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001185 card->state = CARD_STATE_DOWN;
1186 }
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001187
Julian Wiedmann8b5026b2019-12-23 15:03:21 +01001188 qeth_qdio_clear_card(card, 0);
Julian Wiedmannaa3ad3922020-01-25 16:53:00 +01001189 qeth_clear_working_pool_list(card);
Julian Wiedmannc0a2e4d2019-02-04 17:40:09 +01001190 flush_workqueue(card->event_wq);
Julian Wiedmann0f399302019-12-18 16:32:27 +01001191 card->info.promisc_mode = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001192}
1193
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001194static void qeth_l3_set_promisc_mode(struct qeth_card *card)
Ursula Braun76b11f82010-01-11 02:50:50 +00001195{
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001196 bool enable = card->dev->flags & IFF_PROMISC;
Ursula Braun76b11f82010-01-11 02:50:50 +00001197
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001198 if (card->info.promisc_mode == enable)
Ursula Braun76b11f82010-01-11 02:50:50 +00001199 return;
1200
Julian Wiedmann379ac992019-04-25 18:25:57 +02001201 if (IS_VM_NIC(card)) { /* Guestlan trace */
Ursula Braun76b11f82010-01-11 02:50:50 +00001202 if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE))
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001203 qeth_setadp_promisc_mode(card, enable);
Ursula Braun76b11f82010-01-11 02:50:50 +00001204 } else if (card->options.sniffer && /* HiperSockets trace */
1205 qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) {
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001206 if (enable) {
Carsten Otte847a50f2010-06-21 22:57:05 +00001207 QETH_CARD_TEXT(card, 3, "+promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001208 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE);
1209 } else {
Carsten Otte847a50f2010-06-21 22:57:05 +00001210 QETH_CARD_TEXT(card, 3, "-promisc");
Ursula Braun76b11f82010-01-11 02:50:50 +00001211 qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE);
1212 }
1213 }
1214}
1215
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001216static void qeth_l3_rx_mode_work(struct work_struct *work)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001217{
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001218 struct qeth_card *card = container_of(work, struct qeth_card,
1219 rx_mode_work);
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001220 struct qeth_ipaddr *addr;
1221 struct hlist_node *tmp;
1222 int i, rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001223
Carsten Otte847a50f2010-06-21 22:57:05 +00001224 QETH_CARD_TEXT(card, 3, "setmulti");
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01001225
Ursula Braun76b11f82010-01-11 02:50:50 +00001226 if (!card->options.sniffer) {
Julian Wiedmann8659c182019-11-14 11:19:22 +01001227 rtnl_lock();
1228 qeth_l3_add_mcast_rtnl(card->dev, 0, card);
Julian Wiedmann611abe52019-11-14 11:19:21 +01001229 if (qeth_is_supported(card, IPA_FULL_VLAN))
Julian Wiedmann8659c182019-11-14 11:19:22 +01001230 vlan_for_each(card->dev, qeth_l3_add_mcast_rtnl, card);
1231 rtnl_unlock();
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001232
1233 hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) {
1234 switch (addr->disp_flag) {
1235 case QETH_DISP_ADDR_DELETE:
1236 rc = qeth_l3_deregister_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001237 if (!rc || rc == -ENOENT) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001238 hash_del(&addr->hnode);
1239 kfree(addr);
1240 }
1241 break;
1242 case QETH_DISP_ADDR_ADD:
1243 rc = qeth_l3_register_addr_entry(card, addr);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001244 if (rc && rc != -ENETDOWN) {
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001245 hash_del(&addr->hnode);
1246 kfree(addr);
1247 break;
1248 }
1249 addr->ref_counter = 1;
1250 /* fall through */
1251 default:
1252 /* for next call to set_rx_mode(): */
1253 addr->disp_flag = QETH_DISP_ADDR_DELETE;
1254 }
1255 }
Ursula Braun76b11f82010-01-11 02:50:50 +00001256 }
Julian Wiedmann59b757a2019-08-20 16:46:41 +02001257
1258 qeth_l3_set_promisc_mode(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001259}
1260
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001261static int qeth_l3_arp_makerc(u16 rc)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001262{
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001263 switch (rc) {
1264 case IPA_RC_SUCCESS:
1265 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001266 case QETH_IPA_ARP_RC_NOTSUPP:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001267 case QETH_IPA_ARP_RC_Q_NOTSUPP:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001268 return -EOPNOTSUPP;
1269 case QETH_IPA_ARP_RC_OUT_OF_RANGE:
1270 return -EINVAL;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001271 case QETH_IPA_ARP_RC_Q_NO_DATA:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001272 return -ENOENT;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001273 default:
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001274 return -EIO;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001275 }
1276}
1277
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001278static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply,
1279 unsigned long data)
1280{
1281 struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data;
1282
1283 qeth_setassparms_cb(card, reply, data);
1284 return qeth_l3_arp_makerc(cmd->hdr.return_code);
1285}
1286
Frank Blaschka4a71df52008-02-15 09:19:42 +01001287static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries)
1288{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001289 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001290 int rc;
1291
Carsten Otte847a50f2010-06-21 22:57:05 +00001292 QETH_CARD_TEXT(card, 3, "arpstnoe");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001293
1294 /*
1295 * currently GuestLAN only supports the ARP assist function
1296 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES;
1297 * thus we say EOPNOTSUPP for this ARP function
1298 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001299 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001300 return -EOPNOTSUPP;
1301 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001302 return -EOPNOTSUPP;
1303 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001304
1305 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001306 IPA_CMD_ASS_ARP_SET_NO_ENTRIES,
1307 SETASS_DATA_SIZEOF(flags_32bit),
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001308 QETH_PROT_IPV4);
1309 if (!iob)
1310 return -ENOMEM;
1311
1312 __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries;
1313 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001314 if (rc)
1315 QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n",
1316 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001317 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001318}
1319
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001320static __u32 get_arp_entry_size(struct qeth_card *card,
1321 struct qeth_arp_query_data *qdata,
1322 struct qeth_arp_entrytype *type, __u8 strip_entries)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001323{
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001324 __u32 rc;
1325 __u8 is_hsi;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001326
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001327 is_hsi = qdata->reply_bits == 5;
1328 if (type->ip == QETHARP_IP_ADDR_V4) {
1329 QETH_CARD_TEXT(card, 4, "arpev4");
1330 if (strip_entries) {
1331 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) :
1332 sizeof(struct qeth_arp_qi_entry7_short);
1333 } else {
1334 rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) :
1335 sizeof(struct qeth_arp_qi_entry7);
1336 }
1337 } else if (type->ip == QETHARP_IP_ADDR_V6) {
1338 QETH_CARD_TEXT(card, 4, "arpev6");
1339 if (strip_entries) {
1340 rc = is_hsi ?
1341 sizeof(struct qeth_arp_qi_entry5_short_ipv6) :
1342 sizeof(struct qeth_arp_qi_entry7_short_ipv6);
1343 } else {
1344 rc = is_hsi ?
1345 sizeof(struct qeth_arp_qi_entry5_ipv6) :
1346 sizeof(struct qeth_arp_qi_entry7_ipv6);
1347 }
1348 } else {
1349 QETH_CARD_TEXT(card, 4, "arpinv");
1350 rc = 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001351 }
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001352
1353 return rc;
1354}
1355
1356static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot)
1357{
1358 return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) ||
1359 (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001360}
1361
1362static int qeth_l3_arp_query_cb(struct qeth_card *card,
1363 struct qeth_reply *reply, unsigned long data)
1364{
1365 struct qeth_ipa_cmd *cmd;
1366 struct qeth_arp_query_data *qdata;
1367 struct qeth_arp_query_info *qinfo;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001368 int e;
1369 int entrybytes_done;
1370 int stripped_bytes;
1371 __u8 do_strip_entries;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001372
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001373 QETH_CARD_TEXT(card, 3, "arpquecb");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001374
1375 qinfo = (struct qeth_arp_query_info *) reply->param;
1376 cmd = (struct qeth_ipa_cmd *) data;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001377 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001378 if (cmd->hdr.return_code) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001379 QETH_CARD_TEXT(card, 4, "arpcberr");
1380 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001381 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001382 }
1383 if (cmd->data.setassparms.hdr.return_code) {
1384 cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001385 QETH_CARD_TEXT(card, 4, "setaperr");
1386 QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001387 return qeth_l3_arp_makerc(cmd->hdr.return_code);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001388 }
1389 qdata = &cmd->data.setassparms.data.query_arp;
Carsten Otte847a50f2010-06-21 22:57:05 +00001390 QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001391
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001392 do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0;
1393 stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0;
1394 entrybytes_done = 0;
1395 for (e = 0; e < qdata->no_entries; ++e) {
1396 char *cur_entry;
1397 __u32 esize;
1398 struct qeth_arp_entrytype *etype;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001399
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001400 cur_entry = &qdata->data + entrybytes_done;
1401 etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type;
1402 if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) {
1403 QETH_CARD_TEXT(card, 4, "pmis");
1404 QETH_CARD_TEXT_(card, 4, "%i", etype->ip);
1405 break;
1406 }
1407 esize = get_arp_entry_size(card, qdata, etype,
1408 do_strip_entries);
1409 QETH_CARD_TEXT_(card, 5, "esz%i", esize);
1410 if (!esize)
1411 break;
1412
1413 if ((qinfo->udata_len - qinfo->udata_offset) < esize) {
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001414 QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC);
1415 memset(qinfo->udata, 0, 4);
1416 return -ENOSPC;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001417 }
1418
1419 memcpy(qinfo->udata + qinfo->udata_offset,
1420 &qdata->data + entrybytes_done + stripped_bytes,
1421 esize);
1422 entrybytes_done += esize + stripped_bytes;
1423 qinfo->udata_offset += esize;
1424 ++qinfo->no_entries;
1425 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001426 /* check if all replies received ... */
1427 if (cmd->data.setassparms.hdr.seq_no <
1428 cmd->data.setassparms.hdr.number_of_replies)
1429 return 1;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001430 QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001431 memcpy(qinfo->udata, &qinfo->no_entries, 4);
1432 /* keep STRIP_ENTRIES flag so the user program can distinguish
1433 * stripped entries from normal ones */
1434 if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES)
1435 qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES;
1436 memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001437 QETH_CARD_TEXT_(card, 4, "rc%i", 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001438 return 0;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001439}
1440
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001441static int qeth_l3_query_arp_cache_info(struct qeth_card *card,
1442 enum qeth_prot_versions prot,
1443 struct qeth_arp_query_info *qinfo)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001444{
1445 struct qeth_cmd_buffer *iob;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001446 struct qeth_ipa_cmd *cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001447 int rc;
1448
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001449 QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot);
1450
Thomas Richterb475e312015-12-11 12:27:54 +01001451 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1452 IPA_CMD_ASS_ARP_QUERY_INFO,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001453 SETASS_DATA_SIZEOF(query_arp), prot);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001454 if (!iob)
1455 return -ENOMEM;
Julian Wiedmannff5caa72018-03-09 18:12:52 +01001456 cmd = __ipa_cmd(iob);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001457 cmd->data.setassparms.data.query_arp.request_bits = 0x000F;
Julian Wiedmann84dbea42019-02-12 18:33:16 +01001458 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001459 if (rc)
1460 QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n",
1461 CARD_DEVID(card), rc);
Julian Wiedmann4b7ae122019-02-12 18:33:23 +01001462 return rc;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001463}
1464
1465static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata)
1466{
1467 struct qeth_arp_query_info qinfo = {0, };
1468 int rc;
1469
Carsten Otte847a50f2010-06-21 22:57:05 +00001470 QETH_CARD_TEXT(card, 3, "arpquery");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001471
1472 if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/
1473 IPA_ARP_PROCESSING)) {
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001474 QETH_CARD_TEXT(card, 3, "arpqnsup");
1475 rc = -EOPNOTSUPP;
1476 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001477 }
1478 /* get size of userspace buffer and mask_bits -> 6 bytes */
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001479 if (copy_from_user(&qinfo, udata, 6)) {
1480 rc = -EFAULT;
1481 goto out;
1482 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001483 qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001484 if (!qinfo.udata) {
1485 rc = -ENOMEM;
1486 goto out;
1487 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001488 qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET;
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001489 rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001490 if (rc) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001491 if (copy_to_user(udata, qinfo.udata, 4))
1492 rc = -EFAULT;
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001493 goto free_and_out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001494 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001495 if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) {
1496 /* fails in case of GuestLAN QDIO mode */
1497 qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo);
1498 }
Sebastian Ott77a83ed2016-06-16 16:19:03 +02001499 if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) {
1500 QETH_CARD_TEXT(card, 4, "qactf");
1501 rc = -EFAULT;
1502 goto free_and_out;
1503 }
1504 QETH_CARD_TEXT(card, 4, "qacts");
1505
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001506free_and_out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001507 kfree(qinfo.udata);
Einar Lueckd0ddf30f2010-12-08 02:57:58 +00001508out:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001509 return rc;
1510}
1511
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001512static int qeth_l3_arp_modify_entry(struct qeth_card *card,
1513 struct qeth_arp_cache_entry *entry,
1514 enum qeth_arp_process_subcmds arp_cmd)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001515{
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001516 struct qeth_arp_cache_entry *cmd_entry;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001517 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001518 int rc;
1519
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001520 if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY)
1521 QETH_CARD_TEXT(card, 3, "arpadd");
1522 else
1523 QETH_CARD_TEXT(card, 3, "arpdel");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001524
1525 /*
1526 * currently GuestLAN only supports the ARP assist function
1527 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY;
1528 * thus we say EOPNOTSUPP for this ARP function
1529 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001530 if (IS_VM_NIC(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001531 return -EOPNOTSUPP;
1532 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001533 return -EOPNOTSUPP;
1534 }
1535
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001536 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd,
Julian Wiedmannb9150462019-06-27 17:01:24 +02001537 SETASS_DATA_SIZEOF(arp_entry),
1538 QETH_PROT_IPV4);
Thomas Richter1aec42b2015-01-21 13:39:10 +01001539 if (!iob)
1540 return -ENOMEM;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001541
1542 cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry;
1543 ether_addr_copy(cmd_entry->macaddr, entry->macaddr);
1544 memcpy(cmd_entry->ipaddr, entry->ipaddr, 4);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001545 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001546 if (rc)
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001547 QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n",
1548 arp_cmd, CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001549 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001550}
1551
1552static int qeth_l3_arp_flush_cache(struct qeth_card *card)
1553{
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001554 struct qeth_cmd_buffer *iob;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001555 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001556
Carsten Otte847a50f2010-06-21 22:57:05 +00001557 QETH_CARD_TEXT(card, 3, "arpflush");
Frank Blaschka4a71df52008-02-15 09:19:42 +01001558
1559 /*
1560 * currently GuestLAN only supports the ARP assist function
1561 * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE;
1562 * thus we say EOPNOTSUPP for this ARP function
1563 */
Julian Wiedmann379ac992019-04-25 18:25:57 +02001564 if (IS_VM_NIC(card) || IS_IQD(card))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001565 return -EOPNOTSUPP;
1566 if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001567 return -EOPNOTSUPP;
1568 }
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001569
1570 iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING,
1571 IPA_CMD_ASS_ARP_FLUSH_CACHE, 0,
1572 QETH_PROT_IPV4);
1573 if (!iob)
1574 return -ENOMEM;
1575
1576 rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL);
Julian Wiedmanne19e5be2018-11-02 19:04:08 +01001577 if (rc)
1578 QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n",
1579 CARD_DEVID(card), rc);
Julian Wiedmann742d4d42019-02-12 18:33:25 +01001580 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001581}
1582
1583static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
1584{
Heiko Carstens509e2562008-07-26 02:24:10 -07001585 struct qeth_card *card = dev->ml_priv;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001586 struct qeth_arp_cache_entry arp_entry;
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001587 enum qeth_arp_process_subcmds arp_cmd;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001588 int rc = 0;
1589
Frank Blaschka4a71df52008-02-15 09:19:42 +01001590 switch (cmd) {
1591 case SIOC_QETH_ARP_SET_NO_ENTRIES:
1592 if (!capable(CAP_NET_ADMIN)) {
1593 rc = -EPERM;
1594 break;
1595 }
1596 rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue);
1597 break;
1598 case SIOC_QETH_ARP_QUERY_INFO:
1599 if (!capable(CAP_NET_ADMIN)) {
1600 rc = -EPERM;
1601 break;
1602 }
1603 rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data);
1604 break;
1605 case SIOC_QETH_ARP_ADD_ENTRY:
Frank Blaschka4a71df52008-02-15 09:19:42 +01001606 case SIOC_QETH_ARP_REMOVE_ENTRY:
Julian Wiedmann125d7d32018-11-02 19:04:12 +01001607 if (!capable(CAP_NET_ADMIN))
1608 return -EPERM;
1609 if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry)))
1610 return -EFAULT;
1611
1612 arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ?
1613 IPA_CMD_ASS_ARP_ADD_ENTRY :
1614 IPA_CMD_ASS_ARP_REMOVE_ENTRY;
1615 return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001616 case SIOC_QETH_ARP_FLUSH_CACHE:
1617 if (!capable(CAP_NET_ADMIN)) {
1618 rc = -EPERM;
1619 break;
1620 }
1621 rc = qeth_l3_arp_flush_cache(card);
1622 break;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001623 default:
1624 rc = -EOPNOTSUPP;
1625 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001626 return rc;
1627}
1628
Julian Wiedmann980f4562019-06-27 17:01:32 +02001629static int qeth_l3_get_cast_type_rcu(struct sk_buff *skb, struct dst_entry *dst,
1630 int ipv)
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001631{
David S. Miller69cce1d2011-07-17 23:09:49 -07001632 struct neighbour *n = NULL;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001633
Julian Wiedmann980f4562019-06-27 17:01:32 +02001634 if (dst)
1635 n = dst_neigh_lookup_skb(dst, skb);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001636
David S. Miller69cce1d2011-07-17 23:09:49 -07001637 if (n) {
Julian Wiedmann1f979122017-12-20 20:11:04 +01001638 int cast_type = n->type;
1639
David S. Miller24db1ba2012-07-02 22:02:33 -07001640 neigh_release(n);
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001641 if ((cast_type == RTN_BROADCAST) ||
1642 (cast_type == RTN_MULTICAST) ||
1643 (cast_type == RTN_ANYCAST))
1644 return cast_type;
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001645 return RTN_UNICAST;
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001646 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001647
Julian Wiedmann1f979122017-12-20 20:11:04 +01001648 /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001649 switch (ipv) {
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001650 case 4:
Julian Wiedmann72c87972019-06-05 13:48:48 +02001651 if (ipv4_is_lbcast(ip_hdr(skb)->daddr))
1652 return RTN_BROADCAST;
Julian Wiedmann1f979122017-12-20 20:11:04 +01001653 return ipv4_is_multicast(ip_hdr(skb)->daddr) ?
Julian Wiedmann86c0cdb2018-07-11 17:42:41 +02001654 RTN_MULTICAST : RTN_UNICAST;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001655 case 6:
1656 return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ?
1657 RTN_MULTICAST : RTN_UNICAST;
1658 default:
1659 /* ... and MAC address */
Julian Wiedmann58aa2492019-04-25 18:26:00 +02001660 return qeth_get_ether_cast_type(skb);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001661 }
Klaus-Dieter Wackerce73e102009-08-26 02:01:08 +00001662}
1663
Julian Wiedmann980f4562019-06-27 17:01:32 +02001664static int qeth_l3_get_cast_type(struct sk_buff *skb)
1665{
1666 int ipv = qeth_get_ip_version(skb);
1667 struct dst_entry *dst;
1668 int cast_type;
1669
1670 rcu_read_lock();
1671 dst = qeth_dst_check_rcu(skb, ipv);
1672 cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
1673 rcu_read_unlock();
1674
1675 return cast_type;
1676}
1677
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001678static u8 qeth_l3_cast_type_to_flag(int cast_type)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001679{
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001680 if (cast_type == RTN_MULTICAST)
1681 return QETH_CAST_MULTICAST;
1682 if (cast_type == RTN_ANYCAST)
1683 return QETH_CAST_ANYCAST;
1684 if (cast_type == RTN_BROADCAST)
1685 return QETH_CAST_BROADCAST;
1686 return QETH_CAST_UNICAST;
1687}
David S. Miller69cce1d2011-07-17 23:09:49 -07001688
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001689static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue,
1690 struct qeth_hdr *hdr, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001691 int ipv, unsigned int data_len)
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001692{
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001693 struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001694 struct vlan_ethhdr *veth = vlan_eth_hdr(skb);
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001695 struct qeth_card *card = queue->card;
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001696 struct dst_entry *dst;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001697 int cast_type;
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001698
Julian Wiedmannf6c13142017-12-20 20:11:08 +01001699 hdr->hdr.l3.length = data_len;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001700
Julian Wiedmanne517b642018-09-17 17:36:02 +02001701 if (skb_is_gso(skb)) {
Julian Wiedmann0aef8392018-10-12 17:27:15 +02001702 hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001703 } else {
1704 hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3;
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001705
1706 if (skb->protocol == htons(ETH_P_AF_IUCV)) {
1707 l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST;
1708 l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80);
1709 memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2],
1710 iucv_trans_hdr(skb)->destUserID, 8);
1711 return;
1712 }
1713
Julian Wiedmanne517b642018-09-17 17:36:02 +02001714 if (skb->ip_summed == CHECKSUM_PARTIAL) {
1715 qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv);
1716 /* some HW requires combined L3+L4 csum offload: */
1717 if (ipv == 4)
1718 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001719 }
1720 }
1721
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001722 if (ipv == 4 || IS_IQD(card)) {
1723 /* NETIF_F_HW_VLAN_CTAG_TX */
1724 if (skb_vlan_tag_present(skb)) {
1725 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME;
1726 hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb);
1727 }
1728 } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) {
1729 hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG;
1730 hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001731 }
1732
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001733 rcu_read_lock();
Julian Wiedmann980f4562019-06-27 17:01:32 +02001734 dst = qeth_dst_check_rcu(skb, ipv);
Julian Wiedmann0cd6783d32019-06-05 13:48:49 +02001735
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001736 if (IS_IQD(card) && skb_get_queue_mapping(skb) != QETH_IQD_MCAST_TXQ)
1737 cast_type = RTN_UNICAST;
1738 else
1739 cast_type = qeth_l3_get_cast_type_rcu(skb, dst, ipv);
1740 l3_hdr->flags |= qeth_l3_cast_type_to_flag(cast_type);
1741
Frank Blaschka4a71df52008-02-15 09:19:42 +01001742 if (ipv == 4) {
Julian Wiedmann980f4562019-06-27 17:01:32 +02001743 struct rtable *rt = (struct rtable *) dst;
David Miller87e75972012-02-01 10:49:17 +00001744
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001745 *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ?
1746 rt_nexthop(rt, ip_hdr(skb)->daddr) :
1747 ip_hdr(skb)->daddr;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001748 } else if (ipv == 6) {
Julian Wiedmann980f4562019-06-27 17:01:32 +02001749 struct rt6_info *rt = (struct rt6_info *) dst;
David Miller87e75972012-02-01 10:49:17 +00001750
Julian Wiedmannec2c6722017-08-07 13:28:39 +02001751 if (rt && !ipv6_addr_any(&rt->rt6i_gateway))
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001752 l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway;
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001753 else
Julian Wiedmann5a541f62018-11-08 15:06:16 +01001754 l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr;
David Miller87e75972012-02-01 10:49:17 +00001755
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001756 hdr->hdr.l3.flags |= QETH_HDR_IPV6;
Julian Wiedmann379ac992019-04-25 18:25:57 +02001757 if (!IS_IQD(card))
Julian Wiedmann910a0a82017-12-20 20:11:07 +01001758 hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001759 } else {
1760 /* OSA only: */
1761 l3_hdr->flags |= QETH_HDR_PASSTHRU;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001762 }
Frank Blaschka1d36cb42011-11-15 02:31:15 +00001763 rcu_read_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01001764}
1765
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02001766static void qeth_l3_fixup_headers(struct sk_buff *skb)
1767{
1768 struct iphdr *iph = ip_hdr(skb);
1769
1770 /* this is safe, IPv6 traffic takes a different path */
1771 if (skb->ip_summed == CHECKSUM_PARTIAL)
1772 iph->check = 0;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001773 if (skb_is_gso(skb)) {
1774 iph->tot_len = 0;
1775 tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr,
1776 iph->daddr, 0);
1777 }
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02001778}
1779
Julian Wiedmann356156b2018-09-17 17:36:03 +02001780static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb,
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001781 struct qeth_qdio_out_q *queue, int ipv)
Julian Wiedmanna647a022018-07-11 17:42:46 +02001782{
Julian Wiedmann81ec5432018-11-08 15:06:17 +01001783 unsigned int hw_hdr_len;
1784 int rc;
Julian Wiedmanne517b642018-09-17 17:36:02 +02001785
Julian Wiedmanna647a022018-07-11 17:42:46 +02001786 /* re-use the L2 header area for the HW header: */
Julian Wiedmann81ec5432018-11-08 15:06:17 +01001787 hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) :
1788 sizeof(struct qeth_hdr);
Julian Wiedmanna647a022018-07-11 17:42:46 +02001789 rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN);
1790 if (rc)
1791 return rc;
Julian Wiedmanna647a022018-07-11 17:42:46 +02001792 skb_pull(skb, ETH_HLEN);
Julian Wiedmanna647a022018-07-11 17:42:46 +02001793
Julian Wiedmann2d3986d2018-09-17 17:36:00 +02001794 qeth_l3_fixup_headers(skb);
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001795 return qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header);
Julian Wiedmanna647a022018-07-11 17:42:46 +02001796}
1797
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001798static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb,
1799 struct net_device *dev)
1800{
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001801 struct qeth_card *card = dev->ml_priv;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001802 u16 txq = skb_get_queue_mapping(skb);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001803 int ipv = qeth_get_ip_version(skb);
1804 struct qeth_qdio_out_q *queue;
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001805 int rc;
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001806
Julian Wiedmanneeac0e22019-08-23 11:48:49 +02001807 if (!skb_is_gso(skb))
1808 qdisc_skb_cb(skb)->pkt_len = skb->len;
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001809 if (IS_IQD(card)) {
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001810 queue = card->qdio.out_qs[qeth_iqd_translate_txq(dev, txq)];
1811
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001812 if (card->options.sniffer)
1813 goto tx_drop;
1814 if ((card->options.cq != QETH_CQ_ENABLED && !ipv) ||
1815 (card->options.cq == QETH_CQ_ENABLED &&
1816 skb->protocol != htons(ETH_P_AF_IUCV)))
Frank Blaschka4a71df52008-02-15 09:19:42 +01001817 goto tx_drop;
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001818 } else {
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02001819 queue = card->qdio.out_qs[txq];
Frank Blaschka4a71df52008-02-15 09:19:42 +01001820 }
1821
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001822 if (!(dev->flags & IFF_BROADCAST) &&
1823 qeth_l3_get_cast_type(skb) == RTN_BROADCAST)
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001824 goto tx_drop;
1825
Julian Wiedmann356156b2018-09-17 17:36:03 +02001826 if (ipv == 4 || IS_IQD(card))
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001827 rc = qeth_l3_xmit(card, skb, queue, ipv);
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001828 else
Julian Wiedmanneca1d5c2019-06-27 17:01:33 +02001829 rc = qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header);
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001830
Julian Wiedmanneeac0e22019-08-23 11:48:49 +02001831 if (!rc)
Julian Wiedmannea1d4a02018-07-11 17:42:45 +02001832 return NETDEV_TX_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001833
1834tx_drop:
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001835 QETH_TXQ_STAT_INC(queue, tx_dropped);
Julian Wiedmann104b4852019-03-18 16:40:56 +01001836 kfree_skb(skb);
Frank Blaschka4a71df52008-02-15 09:19:42 +01001837 return NETDEV_TX_OK;
1838}
1839
Julian Wiedmannd0c74822019-03-28 16:39:19 +01001840static void qeth_l3_set_rx_mode(struct net_device *dev)
1841{
1842 struct qeth_card *card = dev->ml_priv;
1843
1844 schedule_work(&card->rx_mode_work);
1845}
1846
Frank Blaschka4a71df52008-02-15 09:19:42 +01001847/*
1848 * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting
1849 * NOARP on the netdevice is no option because it also turns off neighbor
1850 * solicitation. For IPv4 we install a neighbor_setup function. We don't want
1851 * arp resolution but we want the hard header (packet socket will work
1852 * e.g. tcpdump)
1853 */
1854static int qeth_l3_neigh_setup_noarp(struct neighbour *n)
1855{
1856 n->nud_state = NUD_NOARP;
1857 memcpy(n->ha, "FAKELL", 6);
1858 n->output = n->ops->connected_output;
1859 return 0;
1860}
1861
1862static int
1863qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np)
1864{
1865 if (np->tbl->family == AF_INET)
1866 np->neigh_setup = qeth_l3_neigh_setup_noarp;
1867
1868 return 0;
1869}
1870
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001871static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb,
1872 struct net_device *dev,
1873 netdev_features_t features)
1874{
1875 if (qeth_get_ip_version(skb) != 4)
1876 features &= ~NETIF_F_HW_VLAN_CTAG_TX;
1877 return qeth_features_check(skb, dev, features);
1878}
1879
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001880static u16 qeth_l3_iqd_select_queue(struct net_device *dev, struct sk_buff *skb,
1881 struct net_device *sb_dev)
1882{
1883 return qeth_iqd_select_queue(dev, skb, qeth_l3_get_cast_type(skb),
1884 sb_dev);
1885}
1886
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02001887static u16 qeth_l3_osa_select_queue(struct net_device *dev, struct sk_buff *skb,
1888 struct net_device *sb_dev)
1889{
1890 struct qeth_card *card = dev->ml_priv;
1891
1892 return qeth_get_priority_queue(card, skb);
1893}
1894
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001895static const struct net_device_ops qeth_l3_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01001896 .ndo_open = qeth_open,
1897 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001898 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka8403b132009-01-08 10:50:55 -08001899 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmann3a18d752019-04-17 18:17:32 +02001900 .ndo_select_queue = qeth_l3_iqd_select_queue,
Frank Blaschka8403b132009-01-08 10:50:55 -08001901 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001902 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001903 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001904 .ndo_fix_features = qeth_fix_features,
1905 .ndo_set_features = qeth_set_features,
Frank Blaschka8403b132009-01-08 10:50:55 -08001906 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
1907 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001908 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka8403b132009-01-08 10:50:55 -08001909};
1910
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001911static const struct net_device_ops qeth_l3_osa_netdev_ops = {
Julian Wiedmanne22355e2019-01-25 15:44:18 +01001912 .ndo_open = qeth_open,
1913 .ndo_stop = qeth_stop,
Julian Wiedmannb0abc4f2019-02-15 19:22:29 +01001914 .ndo_get_stats64 = qeth_get_stats64,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001915 .ndo_start_xmit = qeth_l3_hard_start_xmit,
Julian Wiedmannf13ade12018-09-17 17:35:56 +02001916 .ndo_features_check = qeth_l3_osa_features_check,
Julian Wiedmann73dc2da2019-04-17 18:17:33 +02001917 .ndo_select_queue = qeth_l3_osa_select_queue,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001918 .ndo_validate_addr = eth_validate_addr,
Julian Wiedmann00c163f2017-12-20 20:11:02 +01001919 .ndo_set_rx_mode = qeth_l3_set_rx_mode,
Julian Wiedmann942d6982017-04-11 16:11:10 +02001920 .ndo_do_ioctl = qeth_do_ioctl,
Thomas Richter8f43fb02016-06-16 16:18:59 +02001921 .ndo_fix_features = qeth_fix_features,
1922 .ndo_set_features = qeth_set_features,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001923 .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid,
1924 .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid,
Jiri Pirko7ff0bcf2011-07-20 04:54:41 +00001925 .ndo_tx_timeout = qeth_tx_timeout,
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001926 .ndo_neigh_setup = qeth_l3_neigh_setup,
1927};
1928
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01001929static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok)
Frank Blaschka4a71df52008-02-15 09:19:42 +01001930{
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02001931 unsigned int headroom;
Thomas Richter1aec42b2015-01-21 13:39:10 +01001932 int rc;
1933
Julian Wiedmann379ac992019-04-25 18:25:57 +02001934 if (IS_OSD(card) || IS_OSX(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001935 if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) ||
1936 (card->info.link_type == QETH_LINK_TYPE_HSTR)) {
Paul Gortmaker1abd2292012-05-10 15:50:52 -04001937 pr_info("qeth_l3: ignoring TR device\n");
1938 return -ENODEV;
Kittipon Meesompop1b811432018-04-26 09:42:16 +02001939 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01001940
Kittipon Meesompop1b811432018-04-26 09:42:16 +02001941 card->dev->netdev_ops = &qeth_l3_osa_netdev_ops;
Julian Wiedmann0f342942018-03-09 18:12:54 +01001942
Kittipon Meesompop1b811432018-04-26 09:42:16 +02001943 /*IPv6 address autoconfiguration stuff*/
1944 qeth_l3_get_unique_id(card);
1945 if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD))
1946 card->dev->dev_id = card->info.unique_id & 0xffff;
Julian Wiedmann0f342942018-03-09 18:12:54 +01001947
Julian Wiedmann379ac992019-04-25 18:25:57 +02001948 if (!IS_VM_NIC(card)) {
Kittipon Meesompop1b811432018-04-26 09:42:16 +02001949 card->dev->features |= NETIF_F_SG;
1950 card->dev->hw_features |= NETIF_F_TSO |
1951 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
1952 card->dev->vlan_features |= NETIF_F_TSO |
1953 NETIF_F_RXCSUM | NETIF_F_IP_CSUM;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001954 }
Kittipon Meesompop571f9dd82018-04-26 09:42:22 +02001955
1956 if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) {
1957 card->dev->hw_features |= NETIF_F_IPV6_CSUM;
1958 card->dev->vlan_features |= NETIF_F_IPV6_CSUM;
1959 }
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02001960 if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) {
1961 card->dev->hw_features |= NETIF_F_TSO6;
1962 card->dev->vlan_features |= NETIF_F_TSO6;
1963 }
1964
1965 /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */
1966 if (card->dev->hw_features & NETIF_F_TSO6)
1967 headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN;
1968 else if (card->dev->hw_features & NETIF_F_TSO)
1969 headroom = sizeof(struct qeth_hdr_tso);
1970 else
1971 headroom = sizeof(struct qeth_hdr) + VLAN_HLEN;
Julian Wiedmann379ac992019-04-25 18:25:57 +02001972 } else if (IS_IQD(card)) {
Frank Blaschka4a71df52008-02-15 09:19:42 +01001973 card->dev->flags |= IFF_NOARP;
Frank Blaschka3d58cef2009-01-09 03:44:00 +00001974 card->dev->netdev_ops = &qeth_l3_netdev_ops;
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02001975 headroom = sizeof(struct qeth_hdr) - ETH_HLEN;
Julian Wiedmanna647a022018-07-11 17:42:46 +02001976
Thomas Richter1aec42b2015-01-21 13:39:10 +01001977 rc = qeth_l3_iqd_read_initial_mac(card);
1978 if (rc)
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001979 goto out;
Frank Blaschka4a71df52008-02-15 09:19:42 +01001980 } else
1981 return -ENODEV;
1982
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02001983 card->dev->needed_headroom = headroom;
Patrick McHardyf6469682013-04-19 02:04:27 +00001984 card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX |
1985 NETIF_F_HW_VLAN_CTAG_RX |
1986 NETIF_F_HW_VLAN_CTAG_FILTER;
Julian Wiedmanna647a022018-07-11 17:42:46 +02001987
Eric Dumazet02875872014-10-05 18:38:35 -07001988 netif_keep_dst(card->dev);
Julian Wiedmann82bf5c02018-10-12 17:27:14 +02001989 if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6))
Julian Wiedmann371a1e72018-07-11 17:42:44 +02001990 netif_set_gso_max_size(card->dev,
1991 PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1));
Frank Blaschka4a71df52008-02-15 09:19:42 +01001992
Julian Wiedmannd73ef322017-04-11 16:11:11 +02001993 netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT);
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001994 rc = register_netdev(card->dev);
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01001995 if (!rc && carrier_ok)
1996 netif_carrier_on(card->dev);
1997
Julian Wiedmannd3d1b202018-07-19 12:43:51 +02001998out:
1999 if (rc)
2000 card->dev->netdev_ops = NULL;
2001 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002002}
2003
Ursula Braun79a04e42017-06-06 14:33:49 +02002004static const struct device_type qeth_l3_devtype = {
2005 .name = "qeth_layer3",
2006 .groups = qeth_l3_attr_groups,
2007};
2008
Frank Blaschka4a71df52008-02-15 09:19:42 +01002009static int qeth_l3_probe_device(struct ccwgroup_device *gdev)
2010{
2011 struct qeth_card *card = dev_get_drvdata(&gdev->dev);
Ursula Braun9111e782017-05-10 19:07:51 +02002012 int rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002013
Julian Wiedmann7221b722019-03-18 16:40:55 +01002014 hash_init(card->ip_htable);
Julian Wiedmanndf2a2a52019-03-28 16:39:23 +01002015 mutex_init(&card->ip_lock);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002016 card->cmd_wq = alloc_ordered_workqueue("%s_cmd", 0,
2017 dev_name(&gdev->dev));
2018 if (!card->cmd_wq)
2019 return -ENOMEM;
Julian Wiedmann7221b722019-03-18 16:40:55 +01002020
Ursula Braun79a04e42017-06-06 14:33:49 +02002021 if (gdev->dev.type == &qeth_generic_devtype) {
2022 rc = qeth_l3_create_device_attributes(&gdev->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002023 if (rc) {
2024 destroy_workqueue(card->cmd_wq);
Ursula Braun79a04e42017-06-06 14:33:49 +02002025 return rc;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002026 }
Ursula Braun79a04e42017-06-06 14:33:49 +02002027 }
Julian Wiedmann7221b722019-03-18 16:40:55 +01002028
Ursula Braunebccc7392017-05-10 19:07:54 +02002029 hash_init(card->ip_mc_htable);
Julian Wiedmannd0c74822019-03-28 16:39:19 +01002030 INIT_WORK(&card->rx_mode_work, qeth_l3_rx_mode_work);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002031 return 0;
2032}
2033
2034static void qeth_l3_remove_device(struct ccwgroup_device *cgdev)
2035{
2036 struct qeth_card *card = dev_get_drvdata(&cgdev->dev);
2037
Ursula Braun79a04e42017-06-06 14:33:49 +02002038 if (cgdev->dev.type == &qeth_generic_devtype)
2039 qeth_l3_remove_device_attributes(&cgdev->dev);
Ursula Braun9dc48cc2010-07-22 23:15:05 +00002040
Ursula Braunf2148562009-05-19 21:38:37 +00002041 qeth_set_allowed_threads(card, 0, 1);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002042 wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0);
2043
Ursula Braun70919e22011-02-26 22:41:36 -08002044 if (cgdev->state == CCWGROUP_ONLINE)
Julian Wiedmann91003f32020-01-25 16:53:01 +01002045 qeth_set_offline(card, false);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002046
Julian Wiedmannc2780c12019-02-04 17:40:08 +01002047 cancel_work_sync(&card->close_dev_work);
Julian Wiedmann30356d02018-11-02 19:04:10 +01002048 if (qeth_netdev_is_registered(card->dev))
2049 unregister_netdev(card->dev);
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002050
2051 flush_workqueue(card->cmd_wq);
2052 destroy_workqueue(card->cmd_wq);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002053 qeth_l3_clear_ip_htable(card, 0);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002054 qeth_l3_clear_ipato_list(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002055}
2056
Julian Wiedmann91003f32020-01-25 16:53:01 +01002057static int qeth_l3_set_online(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002058{
Julian Wiedmann91003f32020-01-25 16:53:01 +01002059 struct ccwgroup_device *gdev = card->gdev;
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002060 struct net_device *dev = card->dev;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002061 int rc = 0;
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002062 bool carrier_ok;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002063
Julian Wiedmann9fae5c32018-11-02 19:04:11 +01002064 rc = qeth_core_hardsetup_card(card, &carrier_ok);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002065 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002066 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braunaa909222009-11-12 00:11:43 +00002067 rc = -ENODEV;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002068 goto out_remove;
2069 }
2070
Frank Blaschka4a71df52008-02-15 09:19:42 +01002071 card->state = CARD_STATE_HARDSETUP;
2072 qeth_print_status_message(card);
2073
2074 /* softsetup */
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002075 QETH_CARD_TEXT(card, 2, "softsetp");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002076
Frank Blaschka4a71df52008-02-15 09:19:42 +01002077 rc = qeth_l3_setadapter_parms(card);
2078 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002079 QETH_CARD_TEXT_(card, 2, "2err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002080 if (!card->options.sniffer) {
2081 rc = qeth_l3_start_ipassists(card);
Stefan Raspl0f547612013-01-21 02:30:20 +00002082 if (rc) {
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002083 QETH_CARD_TEXT_(card, 2, "3err%d", rc);
Stefan Raspl0f547612013-01-21 02:30:20 +00002084 goto out_remove;
2085 }
Ursula Braun76b11f82010-01-11 02:50:50 +00002086 rc = qeth_l3_setrouting_v4(card);
2087 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002088 QETH_CARD_TEXT_(card, 2, "4err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002089 rc = qeth_l3_setrouting_v6(card);
2090 if (rc)
Julian Wiedmann57a688aa2019-06-11 18:37:55 +02002091 QETH_CARD_TEXT_(card, 2, "5err%04x", rc);
Ursula Braun76b11f82010-01-11 02:50:50 +00002092 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002093
Frank Blaschka4a71df52008-02-15 09:19:42 +01002094 card->state = CARD_STATE_SOFTSETUP;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002095
2096 qeth_set_allowed_threads(card, 0xffffffff, 0);
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002097 qeth_l3_recover_ip(card);
Julian Wiedmannd025da92018-06-29 19:45:54 +02002098
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002099 if (!qeth_netdev_is_registered(dev)) {
2100 rc = qeth_l3_setup_netdev(card, carrier_ok);
2101 if (rc)
2102 goto out_remove;
2103 } else {
Ursula Braun4763b0a2011-12-19 22:56:32 +00002104 rtnl_lock();
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002105 if (carrier_ok)
2106 netif_carrier_on(dev);
2107 else
2108 netif_carrier_off(dev);
2109
Julian Wiedmanne6e771b2019-01-25 15:44:22 +01002110 netif_device_attach(dev);
Julian Wiedmannfa3d2e62019-01-25 15:44:21 +01002111 qeth_enable_hw_features(dev);
2112
Julian Wiedmannd7d543f2019-02-28 18:59:36 +01002113 if (card->info.open_when_online) {
2114 card->info.open_when_online = 0;
Julian Wiedmannd4560152019-02-28 18:59:39 +01002115 dev_open(dev, NULL);
Julian Wiedmann9aa17df2018-07-11 17:42:40 +02002116 }
Ursula Braun4763b0a2011-12-19 22:56:32 +00002117 rtnl_unlock();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002118 }
Stefan Raspl82f77cf2013-03-18 20:04:42 +00002119 qeth_trace_features(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002120 /* let user_space know that device is online */
2121 kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE);
2122 return 0;
2123out_remove:
Julian Wiedmannd4560152019-02-28 18:59:39 +01002124 qeth_l3_stop_card(card);
Julian Wiedmannf9e50b02019-12-05 14:33:04 +01002125 qeth_stop_channel(&card->data);
2126 qeth_stop_channel(&card->write);
2127 qeth_stop_channel(&card->read);
Ursula Braun22ae2792014-02-24 13:12:06 +01002128 qdio_free(CARD_DDEV(card));
Ursula Braunaa909222009-11-12 00:11:43 +00002129 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002130}
2131
Julian Wiedmann91003f32020-01-25 16:53:01 +01002132static void qeth_l3_set_offline(struct qeth_card *card)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002133{
Julian Wiedmannd4560152019-02-28 18:59:39 +01002134 qeth_l3_stop_card(card);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002135}
2136
Eugene Crosserc044dc22014-01-29 09:23:48 +01002137/* Returns zero if the command is successfully "consumed" */
2138static int qeth_l3_control_event(struct qeth_card *card,
2139 struct qeth_ipa_cmd *cmd)
2140{
2141 return 1;
2142}
2143
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002144struct qeth_discipline qeth_l3_discipline = {
Ursula Braun79a04e42017-06-06 14:33:49 +02002145 .devtype = &qeth_l3_devtype,
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002146 .setup = qeth_l3_probe_device,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002147 .remove = qeth_l3_remove_device,
2148 .set_online = qeth_l3_set_online,
2149 .set_offline = qeth_l3_set_offline,
Julian Wiedmann942d6982017-04-11 16:11:10 +02002150 .do_ioctl = qeth_l3_do_ioctl,
Eugene Crosserc044dc22014-01-29 09:23:48 +01002151 .control_event_handler = qeth_l3_control_event,
Frank Blaschka4a71df52008-02-15 09:19:42 +01002152};
Sebastian Ottc041f2d4872012-05-15 18:02:21 +02002153EXPORT_SYMBOL_GPL(qeth_l3_discipline);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002154
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002155static int qeth_l3_handle_ip_event(struct qeth_card *card,
2156 struct qeth_ipaddr *addr,
2157 unsigned long event)
2158{
2159 switch (event) {
2160 case NETDEV_UP:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002161 qeth_l3_modify_ip(card, addr, true);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002162 return NOTIFY_OK;
2163 case NETDEV_DOWN:
Julian Wiedmann05a17852019-03-28 16:39:21 +01002164 qeth_l3_modify_ip(card, addr, false);
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002165 return NOTIFY_OK;
2166 default:
2167 return NOTIFY_DONE;
2168 }
2169}
2170
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002171struct qeth_l3_ip_event_work {
2172 struct work_struct work;
2173 struct qeth_card *card;
2174 struct qeth_ipaddr addr;
2175};
2176
2177#define to_ip_work(w) container_of((w), struct qeth_l3_ip_event_work, work)
2178
2179static void qeth_l3_add_ip_worker(struct work_struct *work)
2180{
2181 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2182
2183 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, true);
2184 kfree(work);
2185}
2186
2187static void qeth_l3_delete_ip_worker(struct work_struct *work)
2188{
2189 struct qeth_l3_ip_event_work *ip_work = to_ip_work(work);
2190
2191 qeth_l3_modify_ip(ip_work->card, &ip_work->addr, false);
2192 kfree(work);
2193}
2194
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002195static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev)
2196{
2197 if (is_vlan_dev(dev))
2198 dev = vlan_dev_real_dev(dev);
2199 if (dev->netdev_ops == &qeth_l3_osa_netdev_ops ||
2200 dev->netdev_ops == &qeth_l3_netdev_ops)
2201 return (struct qeth_card *) dev->ml_priv;
2202 return NULL;
2203}
2204
Frank Blaschka4a71df52008-02-15 09:19:42 +01002205static int qeth_l3_ip_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002206 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002207{
Lakhvich Dmitriy5f78e292016-06-16 16:18:58 +02002208
Frank Blaschka4a71df52008-02-15 09:19:42 +01002209 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002210 struct net_device *dev = ifa->ifa_dev->dev;
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002211 struct qeth_ipaddr addr;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002212 struct qeth_card *card;
2213
YOSHIFUJI Hideakic346dca2008-03-25 21:47:49 +09002214 if (dev_net(dev) != &init_net)
David S. Miller76fef2b2008-03-22 18:22:42 -07002215 return NOTIFY_DONE;
2216
Frank Blaschka4a71df52008-02-15 09:19:42 +01002217 card = qeth_l3_get_card_from_dev(dev);
2218 if (!card)
2219 return NOTIFY_DONE;
frank.blaschka@de.ibm.com6d8823d2012-05-16 01:28:26 +00002220 QETH_CARD_TEXT(card, 3, "ipevent");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002221
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002222 qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4);
Julian Wiedmann1b40d4b2019-10-31 13:42:20 +01002223 addr.u.a4.addr = ifa->ifa_address;
Julian Wiedmann490df972019-12-18 17:34:46 +01002224 addr.u.a4.mask = ifa->ifa_mask;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002225
Julian Wiedmannd66b1c02018-03-09 18:13:00 +01002226 return qeth_l3_handle_ip_event(card, &addr, event);
Frank Blaschka4a71df52008-02-15 09:19:42 +01002227}
2228
2229static struct notifier_block qeth_l3_ip_notifier = {
2230 qeth_l3_ip_event,
2231 NULL,
2232};
2233
Frank Blaschka4a71df52008-02-15 09:19:42 +01002234static int qeth_l3_ip6_event(struct notifier_block *this,
David S. Miller76fef2b2008-03-22 18:22:42 -07002235 unsigned long event, void *ptr)
Frank Blaschka4a71df52008-02-15 09:19:42 +01002236{
2237 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr;
Julian Wiedmannb9caa982018-03-09 18:13:01 +01002238 struct net_device *dev = ifa->idev->dev;
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002239 struct qeth_l3_ip_event_work *ip_work;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002240 struct qeth_card *card;
2241
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002242 if (event != NETDEV_UP && event != NETDEV_DOWN)
2243 return NOTIFY_DONE;
2244
Frank Blaschka4a71df52008-02-15 09:19:42 +01002245 card = qeth_l3_get_card_from_dev(dev);
2246 if (!card)
2247 return NOTIFY_DONE;
Carsten Otte847a50f2010-06-21 22:57:05 +00002248 QETH_CARD_TEXT(card, 3, "ip6event");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002249 if (!qeth_is_supported(card, IPA_IPV6))
2250 return NOTIFY_DONE;
2251
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002252 ip_work = kmalloc(sizeof(*ip_work), GFP_ATOMIC);
2253 if (!ip_work)
2254 return NOTIFY_DONE;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002255
Julian Wiedmann7686e4b2019-03-28 16:39:22 +01002256 if (event == NETDEV_UP)
2257 INIT_WORK(&ip_work->work, qeth_l3_add_ip_worker);
2258 else
2259 INIT_WORK(&ip_work->work, qeth_l3_delete_ip_worker);
2260
2261 ip_work->card = card;
2262 qeth_l3_init_ipaddr(&ip_work->addr, QETH_IP_TYPE_NORMAL,
2263 QETH_PROT_IPV6);
2264 ip_work->addr.u.a6.addr = ifa->addr;
2265 ip_work->addr.u.a6.pfxlen = ifa->prefix_len;
2266
2267 queue_work(card->cmd_wq, &ip_work->work);
2268 return NOTIFY_OK;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002269}
2270
2271static struct notifier_block qeth_l3_ip6_notifier = {
2272 qeth_l3_ip6_event,
2273 NULL,
2274};
Frank Blaschka4a71df52008-02-15 09:19:42 +01002275
2276static int qeth_l3_register_notifiers(void)
2277{
2278 int rc;
2279
Carsten Otte847a50f2010-06-21 22:57:05 +00002280 QETH_DBF_TEXT(SETUP, 5, "regnotif");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002281 rc = register_inetaddr_notifier(&qeth_l3_ip_notifier);
2282 if (rc)
2283 return rc;
Frank Blaschka4a71df52008-02-15 09:19:42 +01002284 rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier);
2285 if (rc) {
2286 unregister_inetaddr_notifier(&qeth_l3_ip_notifier);
2287 return rc;
2288 }
Frank Blaschka4a71df52008-02-15 09:19:42 +01002289 return 0;
2290}
2291
2292static void qeth_l3_unregister_notifiers(void)
2293{
Carsten Otte847a50f2010-06-21 22:57:05 +00002294 QETH_DBF_TEXT(SETUP, 5, "unregnot");
Stefan Raspl18af5c12012-11-19 02:46:50 +00002295 WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier));
Stefan Raspl18af5c12012-11-19 02:46:50 +00002296 WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier));
Frank Blaschka4a71df52008-02-15 09:19:42 +01002297}
2298
2299static int __init qeth_l3_init(void)
2300{
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002301 pr_info("register layer 3 discipline\n");
Julian Wiedmannc0622042017-12-20 20:10:58 +01002302 return qeth_l3_register_notifiers();
Frank Blaschka4a71df52008-02-15 09:19:42 +01002303}
2304
2305static void __exit qeth_l3_exit(void)
2306{
2307 qeth_l3_unregister_notifiers();
Frank Blaschka74eacdb2008-12-25 13:39:49 +01002308 pr_info("unregister layer 3 discipline\n");
Frank Blaschka4a71df52008-02-15 09:19:42 +01002309}
2310
2311module_init(qeth_l3_init);
2312module_exit(qeth_l3_exit);
2313MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>");
2314MODULE_DESCRIPTION("qeth layer 3 discipline");
2315MODULE_LICENSE("GPL");