Greg Kroah-Hartman | ab9953f | 2017-11-14 18:38:04 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2 | /* |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 3 | * Copyright IBM Corp. 2007, 2009 |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 4 | * 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 Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 10 | #define KMSG_COMPONENT "qeth" |
| 11 | #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt |
| 12 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 16 | #include <linux/string.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/etherdevice.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 20 | #include <linux/ip.h> |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 21 | #include <linux/in.h> |
Frank Blaschka | 64ef895 | 2009-03-24 20:57:16 +0000 | [diff] [blame] | 22 | #include <linux/ipv6.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 23 | #include <linux/inetdevice.h> |
| 24 | #include <linux/igmp.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 25 | #include <linux/slab.h> |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 26 | #include <linux/if_ether.h> |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 27 | #include <linux/if_vlan.h> |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 28 | #include <linux/skbuff.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 29 | |
| 30 | #include <net/ip.h> |
| 31 | #include <net/arp.h> |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 32 | #include <net/route.h> |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 33 | #include <net/ipv6.h> |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 34 | #include <net/ip6_route.h> |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 35 | #include <net/iucv/af_iucv.h> |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 36 | #include <linux/hashtable.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 37 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 38 | #include "qeth_l3.h" |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 39 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 40 | static int qeth_l3_register_addr_entry(struct qeth_card *, |
| 41 | struct qeth_ipaddr *); |
| 42 | static int qeth_l3_deregister_addr_entry(struct qeth_card *, |
| 43 | struct qeth_ipaddr *); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 44 | |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 45 | int qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const u8 *addr, |
| 46 | char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 47 | { |
| 48 | if (proto == QETH_PROT_IPV4) |
Julian Wiedmann | e6b1b7d | 2019-12-18 17:34:44 +0100 | [diff] [blame] | 49 | return sprintf(buf, "%pI4", addr); |
| 50 | else |
| 51 | return sprintf(buf, "%pI6", addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 54 | static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card, |
| 55 | struct qeth_ipaddr *query) |
| 56 | { |
Julian Wiedmann | 1b40d4b | 2019-10-31 13:42:20 +0100 | [diff] [blame] | 57 | u32 key = qeth_l3_ipaddr_hash(query); |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 58 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 72 | static 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 Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 86 | static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card, |
| 87 | struct qeth_ipaddr *addr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 88 | { |
| 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. Silva | 1a363b0 | 2018-08-09 14:48:04 +0200 | [diff] [blame] | 95 | return false; |
Julian Wiedmann | b22d73d6 | 2017-12-13 18:56:30 +0100 | [diff] [blame] | 96 | if (addr->type != QETH_IP_TYPE_NORMAL) |
Gustavo A. R. Silva | 1a363b0 | 2018-08-09 14:48:04 +0200 | [diff] [blame] | 97 | return false; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 98 | |
| 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 Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 125 | static int qeth_l3_delete_ip(struct qeth_card *card, |
| 126 | struct qeth_ipaddr *tmp_addr) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 127 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 128 | int rc = 0; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 129 | struct qeth_ipaddr *addr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 130 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 131 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 137 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 138 | if (tmp_addr->proto == QETH_PROT_IPV4) |
| 139 | QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 140 | else { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 141 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 143 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 144 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 145 | addr = qeth_l3_find_addr_by_ip(card, tmp_addr); |
| 146 | if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr)) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 147 | return -ENOENT; |
| 148 | |
| 149 | addr->ref_counter--; |
Julian Wiedmann | 4964c66 | 2018-02-27 18:58:15 +0100 | [diff] [blame] | 150 | if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 151 | return rc; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 152 | |
Julian Wiedmann | 98d823a | 2018-02-27 18:58:13 +0100 | [diff] [blame] | 153 | if (qeth_card_hw_is_reachable(card)) |
| 154 | rc = qeth_l3_deregister_addr_entry(card, addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 155 | |
| 156 | hash_del(&addr->hnode); |
| 157 | kfree(addr); |
| 158 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 159 | return rc; |
| 160 | } |
| 161 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 162 | static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *tmp_addr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 163 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 164 | int rc = 0; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 165 | struct qeth_ipaddr *addr; |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 166 | char buf[40]; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 167 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 168 | 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 Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 174 | |
| 175 | if (tmp_addr->proto == QETH_PROT_IPV4) |
| 176 | QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 177 | else { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 178 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 180 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 181 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 182 | 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 Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 196 | addr = kmemdup(tmp_addr, sizeof(*tmp_addr), GFP_KERNEL); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 197 | if (!addr) |
| 198 | return -ENOMEM; |
| 199 | |
Julian Wiedmann | b22d73d6 | 2017-12-13 18:56:30 +0100 | [diff] [blame] | 200 | if (qeth_l3_is_addr_covered_by_ipato(card, addr)) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 201 | QETH_CARD_TEXT(card, 2, "tkovaddr"); |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 202 | addr->ipato = 1; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 203 | } |
| 204 | hash_add(card->ip_htable, &addr->hnode, |
| 205 | qeth_l3_ipaddr_hash(addr)); |
| 206 | |
Ursula Braun | a7531c1 | 2016-09-15 14:39:23 +0200 | [diff] [blame] | 207 | if (!qeth_card_hw_is_reachable(card)) { |
| 208 | addr->disp_flag = QETH_DISP_ADDR_ADD; |
| 209 | return 0; |
| 210 | } |
| 211 | |
Julian Wiedmann | adee259 | 2019-12-18 17:34:48 +0100 | [diff] [blame] | 212 | rc = qeth_l3_register_addr_entry(card, addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 213 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 214 | if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 215 | addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 216 | } else { |
| 217 | hash_del(&addr->hnode); |
| 218 | kfree(addr); |
| 219 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 220 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 221 | return rc; |
| 222 | } |
| 223 | |
Julian Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 224 | static int qeth_l3_modify_ip(struct qeth_card *card, struct qeth_ipaddr *addr, |
| 225 | bool add) |
| 226 | { |
| 227 | int rc; |
| 228 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 229 | mutex_lock(&card->ip_lock); |
Julian Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 230 | rc = add ? qeth_l3_add_ip(card, addr) : qeth_l3_delete_ip(card, addr); |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 231 | mutex_unlock(&card->ip_lock); |
Julian Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 232 | |
| 233 | return rc; |
| 234 | } |
| 235 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 236 | static 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 Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 242 | hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) { |
| 243 | hash_del(&addr->hnode); |
| 244 | kfree(addr); |
| 245 | } |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 246 | } |
| 247 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 248 | static void qeth_l3_clear_ip_htable(struct qeth_card *card, int recover) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 249 | { |
| 250 | struct qeth_ipaddr *addr; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 251 | struct hlist_node *tmp; |
| 252 | int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 253 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 254 | QETH_CARD_TEXT(card, 4, "clearip"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 255 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 256 | mutex_lock(&card->ip_lock); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 257 | |
| 258 | hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { |
| 259 | if (!recover) { |
| 260 | hash_del(&addr->hnode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 261 | kfree(addr); |
| 262 | continue; |
| 263 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 264 | addr->disp_flag = QETH_DISP_ADDR_ADD; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 265 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 266 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 267 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 268 | } |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 269 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 270 | static void qeth_l3_recover_ip(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 271 | { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 272 | struct qeth_ipaddr *addr; |
| 273 | struct hlist_node *tmp; |
| 274 | int i; |
| 275 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 276 | |
Ursula Braun | a7531c1 | 2016-09-15 14:39:23 +0200 | [diff] [blame] | 277 | QETH_CARD_TEXT(card, 4, "recovrip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 278 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 279 | mutex_lock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 280 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 281 | hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { |
Julian Wiedmann | 98d823a | 2018-02-27 18:58:13 +0100 | [diff] [blame] | 282 | if (addr->disp_flag == QETH_DISP_ADDR_ADD) { |
Julian Wiedmann | adee259 | 2019-12-18 17:34:48 +0100 | [diff] [blame] | 283 | rc = qeth_l3_register_addr_entry(card, addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 284 | |
| 285 | if (!rc) { |
| 286 | addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 287 | } else { |
| 288 | hash_del(&addr->hnode); |
| 289 | kfree(addr); |
| 290 | } |
| 291 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 292 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 293 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 294 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 295 | } |
| 296 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 297 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 316 | static int qeth_l3_send_setdelmc(struct qeth_card *card, |
| 317 | struct qeth_ipaddr *addr, int ipacmd) |
| 318 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 319 | struct qeth_cmd_buffer *iob; |
| 320 | struct qeth_ipa_cmd *cmd; |
| 321 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 322 | QETH_CARD_TEXT(card, 4, "setdelmc"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 323 | |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 324 | iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto, |
| 325 | IPA_DATA_SIZEOF(setdelipm)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 326 | if (!iob) |
| 327 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 328 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | 8bf70b6 | 2019-10-31 13:42:21 +0100 | [diff] [blame] | 329 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 336 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 337 | return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 338 | } |
| 339 | |
Julian Wiedmann | 490df97 | 2019-12-18 17:34:46 +0100 | [diff] [blame] | 340 | static void qeth_l3_set_ipv6_prefix(struct in6_addr *prefix, unsigned int len) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 341 | { |
Julian Wiedmann | 490df97 | 2019-12-18 17:34:46 +0100 | [diff] [blame] | 342 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 353 | static u32 qeth_l3_get_setdelip_flags(struct qeth_ipaddr *addr, bool set) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 354 | { |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 355 | 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 | |
| 366 | static int qeth_l3_send_setdelip(struct qeth_card *card, |
| 367 | struct qeth_ipaddr *addr, |
| 368 | enum qeth_ipa_cmds ipacmd) |
| 369 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 370 | struct qeth_cmd_buffer *iob; |
| 371 | struct qeth_ipa_cmd *cmd; |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 372 | u32 flags; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 373 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 374 | QETH_CARD_TEXT(card, 4, "setdelip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 375 | |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 376 | iob = qeth_ipa_alloc_cmd(card, ipacmd, addr->proto, |
| 377 | IPA_DATA_SIZEOF(setdelip6)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 378 | if (!iob) |
| 379 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 380 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 381 | |
| 382 | flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP); |
| 383 | QETH_CARD_TEXT_(card, 4, "flags%02X", flags); |
| 384 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 385 | if (addr->proto == QETH_PROT_IPV6) { |
Julian Wiedmann | 490df97 | 2019-12-18 17:34:46 +0100 | [diff] [blame] | 386 | cmd->data.setdelip6.addr = addr->u.a6.addr; |
| 387 | qeth_l3_set_ipv6_prefix(&cmd->data.setdelip6.prefix, |
| 388 | addr->u.a6.pfxlen); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 389 | cmd->data.setdelip6.flags = flags; |
| 390 | } else { |
Julian Wiedmann | 490df97 | 2019-12-18 17:34:46 +0100 | [diff] [blame] | 391 | cmd->data.setdelip4.addr = addr->u.a4.addr; |
| 392 | cmd->data.setdelip4.mask = addr->u.a4.mask; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 393 | cmd->data.setdelip4.flags = flags; |
| 394 | } |
| 395 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 396 | return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | static 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 Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 406 | QETH_CARD_TEXT(card, 4, "setroutg"); |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 407 | iob = qeth_ipa_alloc_cmd(card, IPA_CMD_SETRTG, prot, |
| 408 | IPA_DATA_SIZEOF(setrtg)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 409 | if (!iob) |
| 410 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 411 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 412 | cmd->data.setrtg.type = (type); |
| 413 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 414 | |
| 415 | return rc; |
| 416 | } |
| 417 | |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 418 | static int qeth_l3_correct_routing_type(struct qeth_card *card, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 419 | enum qeth_routing_types *type, enum qeth_prot_versions prot) |
| 420 | { |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 421 | if (IS_IQD(card)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 422 | switch (*type) { |
| 423 | case NO_ROUTER: |
| 424 | case PRIMARY_CONNECTOR: |
| 425 | case SECONDARY_CONNECTOR: |
| 426 | case MULTICAST_ROUTER: |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 427 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 428 | default: |
| 429 | goto out_inval; |
| 430 | } |
| 431 | } else { |
| 432 | switch (*type) { |
| 433 | case NO_ROUTER: |
| 434 | case PRIMARY_ROUTER: |
| 435 | case SECONDARY_ROUTER: |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 436 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 437 | case MULTICAST_ROUTER: |
| 438 | if (qeth_is_ipafunc_supported(card, prot, |
| 439 | IPA_OSA_MC_ROUTER)) |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 440 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 441 | default: |
| 442 | goto out_inval; |
| 443 | } |
| 444 | } |
| 445 | out_inval: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 446 | *type = NO_ROUTER; |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 447 | return -EINVAL; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | int qeth_l3_setrouting_v4(struct qeth_card *card) |
| 451 | { |
| 452 | int rc; |
| 453 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 454 | QETH_CARD_TEXT(card, 3, "setrtg4"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 455 | |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 456 | rc = qeth_l3_correct_routing_type(card, &card->options.route4.type, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 457 | QETH_PROT_IPV4); |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 458 | if (rc) |
| 459 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 460 | |
| 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 Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 465 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 467 | } |
| 468 | return rc; |
| 469 | } |
| 470 | |
| 471 | int qeth_l3_setrouting_v6(struct qeth_card *card) |
| 472 | { |
| 473 | int rc = 0; |
| 474 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 475 | QETH_CARD_TEXT(card, 3, "setrtg6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 476 | |
| 477 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 478 | return 0; |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 479 | rc = qeth_l3_correct_routing_type(card, &card->options.route6.type, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 480 | QETH_PROT_IPV6); |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 481 | if (rc) |
| 482 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 483 | |
| 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 Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 488 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 490 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 491 | return rc; |
| 492 | } |
| 493 | |
| 494 | /* |
| 495 | * IP address takeover related functions |
| 496 | */ |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 497 | |
| 498 | /** |
| 499 | * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs. |
| 500 | * |
| 501 | * Caller must hold ip_lock. |
| 502 | */ |
| 503 | void 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 Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 511 | addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 515 | static void qeth_l3_clear_ipato_list(struct qeth_card *card) |
| 516 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 517 | struct qeth_ipato_entry *ipatoe, *tmp; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 518 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 519 | mutex_lock(&card->ip_lock); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 520 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 521 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { |
| 522 | list_del(&ipatoe->entry); |
| 523 | kfree(ipatoe); |
| 524 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 525 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 526 | qeth_l3_update_ipato(card); |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 527 | mutex_unlock(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | int qeth_l3_add_ipato_entry(struct qeth_card *card, |
| 531 | struct qeth_ipato_entry *new) |
| 532 | { |
| 533 | struct qeth_ipato_entry *ipatoe; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 534 | int rc = 0; |
| 535 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 536 | QETH_CARD_TEXT(card, 2, "addipato"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 537 | |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 538 | mutex_lock(&card->conf_mutex); |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 539 | mutex_lock(&card->ip_lock); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 540 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 541 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 547 | rc = -EEXIST; |
| 548 | break; |
| 549 | } |
| 550 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 551 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 552 | if (!rc) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 553 | list_add_tail(&new->entry, &card->ipato.entries); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 554 | qeth_l3_update_ipato(card); |
| 555 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 556 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 557 | mutex_unlock(&card->ip_lock); |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 558 | mutex_unlock(&card->conf_mutex); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 559 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 560 | return rc; |
| 561 | } |
| 562 | |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 563 | int qeth_l3_del_ipato_entry(struct qeth_card *card, |
| 564 | enum qeth_prot_versions proto, u8 *addr, |
| 565 | int mask_bits) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 566 | { |
| 567 | struct qeth_ipato_entry *ipatoe, *tmp; |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 568 | int rc = -ENOENT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 569 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 570 | QETH_CARD_TEXT(card, 2, "delipato"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 571 | |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 572 | mutex_lock(&card->conf_mutex); |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 573 | mutex_lock(&card->ip_lock); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 574 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 575 | 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 Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 582 | qeth_l3_update_ipato(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 583 | kfree(ipatoe); |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 584 | rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 585 | } |
| 586 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 587 | |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 588 | mutex_unlock(&card->ip_lock); |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 589 | mutex_unlock(&card->conf_mutex); |
| 590 | |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 591 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 592 | } |
| 593 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 594 | int 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 597 | { |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 598 | struct qeth_ipaddr addr; |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 599 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 600 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 601 | 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 Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 606 | |
Julian Wiedmann | 2390166 | 2019-12-18 17:34:45 +0100 | [diff] [blame] | 607 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 612 | } |
| 613 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 614 | int qeth_l3_modify_hsuid(struct qeth_card *card, bool add) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 615 | { |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 616 | struct qeth_ipaddr addr; |
Julian Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 617 | unsigned int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 618 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 619 | 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 Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 624 | |
Julian Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 625 | return qeth_l3_modify_ip(card, &addr, add); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | static 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 Wiedmann | bd74a7f | 2018-11-02 19:04:09 +0100 | [diff] [blame] | 635 | if (card->options.sniffer) |
| 636 | return 0; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 637 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 638 | if (addr->proto == QETH_PROT_IPV4) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 639 | QETH_CARD_TEXT(card, 2, "setaddr4"); |
| 640 | QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 641 | } else if (addr->proto == QETH_PROT_IPV6) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 642 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 645 | } else { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 646 | QETH_CARD_TEXT(card, 2, "setaddr?"); |
| 647 | QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 648 | } |
| 649 | do { |
| 650 | if (addr->is_multicast) |
| 651 | rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM); |
| 652 | else |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 653 | rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 654 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 655 | QETH_CARD_TEXT(card, 2, "failed"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 656 | } while ((--cnt > 0) && rc); |
| 657 | if (rc) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 658 | QETH_CARD_TEXT(card, 2, "FAILED"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 659 | qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 660 | dev_warn(&card->gdev->dev, |
| 661 | "Registering IP address %s failed\n", buf); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 662 | } |
| 663 | return rc; |
| 664 | } |
| 665 | |
| 666 | static int qeth_l3_deregister_addr_entry(struct qeth_card *card, |
| 667 | struct qeth_ipaddr *addr) |
| 668 | { |
| 669 | int rc = 0; |
| 670 | |
Julian Wiedmann | bd74a7f | 2018-11-02 19:04:09 +0100 | [diff] [blame] | 671 | if (card->options.sniffer) |
| 672 | return 0; |
| 673 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 674 | if (addr->proto == QETH_PROT_IPV4) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 675 | QETH_CARD_TEXT(card, 2, "deladdr4"); |
| 676 | QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 677 | } else if (addr->proto == QETH_PROT_IPV6) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 678 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 681 | } else { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 682 | QETH_CARD_TEXT(card, 2, "deladdr?"); |
| 683 | QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 684 | } |
| 685 | if (addr->is_multicast) |
| 686 | rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM); |
| 687 | else |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 688 | rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP); |
Frank Blaschka | c4cef07 | 2008-07-14 09:59:31 +0200 | [diff] [blame] | 689 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 690 | QETH_CARD_TEXT(card, 2, "failed"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 691 | |
| 692 | return rc; |
| 693 | } |
| 694 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 695 | static int qeth_l3_setadapter_parms(struct qeth_card *card) |
| 696 | { |
Julian Wiedmann | 699d3fe | 2017-08-15 17:02:41 +0200 | [diff] [blame] | 697 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 698 | |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 699 | QETH_CARD_TEXT(card, 2, "setadprm"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 700 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 701 | if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) { |
| 702 | rc = qeth_setadpparms_change_macaddr(card); |
| 703 | if (rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 704 | dev_warn(&card->gdev->dev, "Reading the adapter MAC" |
Heiko Carstens | 6ea2fde | 2009-01-04 17:36:32 -0800 | [diff] [blame] | 705 | " address failed\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 706 | } |
| 707 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 708 | return rc; |
| 709 | } |
| 710 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 711 | static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card) |
| 712 | { |
| 713 | int rc; |
| 714 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 715 | QETH_CARD_TEXT(card, 3, "ipaarp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 716 | |
| 717 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 718 | dev_info(&card->gdev->dev, |
| 719 | "ARP processing not supported on %s!\n", |
| 720 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 721 | return 0; |
| 722 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 723 | rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 724 | IPA_CMD_ASS_START, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 725 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 726 | dev_warn(&card->gdev->dev, |
| 727 | "Starting ARP processing support for %s failed\n", |
| 728 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 729 | } |
| 730 | return rc; |
| 731 | } |
| 732 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 733 | static int qeth_l3_start_ipa_source_mac(struct qeth_card *card) |
| 734 | { |
| 735 | int rc; |
| 736 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 737 | QETH_CARD_TEXT(card, 3, "stsrcmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 738 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 739 | if (!qeth_is_supported(card, IPA_SOURCE_MAC)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 740 | dev_info(&card->gdev->dev, |
Ursula Braun | fe94e2e | 2009-01-04 17:34:52 -0800 | [diff] [blame] | 741 | "Inbound source MAC-address not supported on %s\n", |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 742 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 743 | return -EOPNOTSUPP; |
| 744 | } |
| 745 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 746 | rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 747 | IPA_CMD_ASS_START, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 748 | if (rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 749 | dev_warn(&card->gdev->dev, |
Ursula Braun | fe94e2e | 2009-01-04 17:34:52 -0800 | [diff] [blame] | 750 | "Starting source MAC-address support for %s failed\n", |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 751 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 752 | return rc; |
| 753 | } |
| 754 | |
| 755 | static int qeth_l3_start_ipa_vlan(struct qeth_card *card) |
| 756 | { |
| 757 | int rc = 0; |
| 758 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 759 | QETH_CARD_TEXT(card, 3, "strtvlan"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 760 | |
| 761 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 762 | dev_info(&card->gdev->dev, |
| 763 | "VLAN not supported on %s\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 764 | return -EOPNOTSUPP; |
| 765 | } |
| 766 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 767 | rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 768 | IPA_CMD_ASS_START, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 769 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 770 | dev_warn(&card->gdev->dev, |
| 771 | "Starting VLAN support for %s failed\n", |
| 772 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 773 | } else { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 774 | dev_info(&card->gdev->dev, "VLAN enabled\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 775 | } |
| 776 | return rc; |
| 777 | } |
| 778 | |
| 779 | static int qeth_l3_start_ipa_multicast(struct qeth_card *card) |
| 780 | { |
| 781 | int rc; |
| 782 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 783 | QETH_CARD_TEXT(card, 3, "stmcast"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 784 | |
| 785 | if (!qeth_is_supported(card, IPA_MULTICASTING)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 786 | dev_info(&card->gdev->dev, |
| 787 | "Multicast not supported on %s\n", |
| 788 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 789 | return -EOPNOTSUPP; |
| 790 | } |
| 791 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 792 | rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 793 | IPA_CMD_ASS_START, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 794 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 795 | dev_warn(&card->gdev->dev, |
| 796 | "Starting multicast support for %s failed\n", |
| 797 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 798 | } else { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 799 | dev_info(&card->gdev->dev, "Multicast enabled\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 800 | card->dev->flags |= IFF_MULTICAST; |
| 801 | } |
| 802 | return rc; |
| 803 | } |
| 804 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 805 | static int qeth_l3_softsetup_ipv6(struct qeth_card *card) |
| 806 | { |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 807 | u32 ipv6_data = 3; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 808 | int rc; |
| 809 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 810 | QETH_CARD_TEXT(card, 3, "softipv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 811 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 812 | if (IS_IQD(card)) |
Julian Wiedmann | 2327459 | 2017-06-06 14:33:44 +0200 | [diff] [blame] | 813 | goto out; |
| 814 | |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 815 | rc = qeth_send_simple_setassparms(card, IPA_IPV6, IPA_CMD_ASS_START, |
| 816 | &ipv6_data); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 817 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 818 | dev_err(&card->gdev->dev, |
| 819 | "Activating IPv6 support for %s failed\n", |
| 820 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 821 | return rc; |
| 822 | } |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 823 | rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6, IPA_CMD_ASS_START, |
| 824 | NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 825 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 826 | dev_err(&card->gdev->dev, |
| 827 | "Activating IPv6 support for %s failed\n", |
| 828 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 829 | return rc; |
| 830 | } |
Kittipon Meesompop | a8155b0 | 2018-04-26 09:42:21 +0200 | [diff] [blame] | 831 | rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 832 | IPA_CMD_ASS_START, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 833 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 834 | dev_warn(&card->gdev->dev, |
| 835 | "Enabling the passthrough mode for %s failed\n", |
| 836 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 837 | return rc; |
| 838 | } |
| 839 | out: |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 840 | dev_info(&card->gdev->dev, "IPV6 enabled\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 841 | return 0; |
| 842 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 843 | |
| 844 | static int qeth_l3_start_ipa_ipv6(struct qeth_card *card) |
| 845 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 846 | QETH_CARD_TEXT(card, 3, "strtipv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 847 | |
| 848 | if (!qeth_is_supported(card, IPA_IPV6)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 849 | dev_info(&card->gdev->dev, |
| 850 | "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 851 | return 0; |
| 852 | } |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 853 | return qeth_l3_softsetup_ipv6(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | static int qeth_l3_start_ipa_broadcast(struct qeth_card *card) |
| 857 | { |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 858 | u32 filter_data = 1; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 859 | int rc; |
| 860 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 861 | QETH_CARD_TEXT(card, 3, "stbrdcst"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 862 | card->info.broadcast_capable = 0; |
| 863 | if (!qeth_is_supported(card, IPA_FILTERING)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 864 | dev_info(&card->gdev->dev, |
| 865 | "Broadcast not supported on %s\n", |
| 866 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 867 | rc = -EOPNOTSUPP; |
| 868 | goto out; |
| 869 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 870 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 871 | IPA_CMD_ASS_START, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 872 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 873 | dev_warn(&card->gdev->dev, "Enabling broadcast filtering for " |
| 874 | "%s failed\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 875 | goto out; |
| 876 | } |
| 877 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 878 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 879 | IPA_CMD_ASS_CONFIGURE, &filter_data); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 880 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 881 | dev_warn(&card->gdev->dev, |
| 882 | "Setting up broadcast filtering for %s failed\n", |
| 883 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 884 | goto out; |
| 885 | } |
| 886 | card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO; |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 887 | dev_info(&card->gdev->dev, "Broadcast enabled\n"); |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 888 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
Julian Wiedmann | 1c696c89 | 2019-06-27 17:01:23 +0200 | [diff] [blame] | 889 | IPA_CMD_ASS_ENABLE, &filter_data); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 890 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 891 | dev_warn(&card->gdev->dev, "Setting up broadcast echo " |
| 892 | "filtering for %s failed\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 893 | goto out; |
| 894 | } |
| 895 | card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO; |
| 896 | out: |
| 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 904 | static int qeth_l3_start_ipassists(struct qeth_card *card) |
| 905 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 906 | QETH_CARD_TEXT(card, 3, "strtipas"); |
Einar Lueck | d64ecc2 | 2009-11-12 00:11:41 +0000 | [diff] [blame] | 907 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 908 | qeth_l3_start_ipa_arp_processing(card); /* go on*/ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 909 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 914 | return 0; |
| 915 | } |
| 916 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 917 | static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card, |
| 918 | struct qeth_reply *reply, unsigned long data) |
| 919 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 920 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 921 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 922 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 927 | return 0; |
| 928 | } |
| 929 | |
| 930 | static 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 Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 936 | QETH_CARD_TEXT(card, 2, "hsrmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 937 | |
Julian Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 938 | iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6, |
| 939 | IPA_DATA_SIZEOF(create_destroy_addr)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 940 | if (!iob) |
| 941 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 942 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 943 | *((__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 | |
| 951 | static int qeth_l3_get_unique_id_cb(struct qeth_card *card, |
| 952 | struct qeth_reply *reply, unsigned long data) |
| 953 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 954 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 955 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 956 | if (cmd->hdr.return_code == 0) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 957 | card->info.unique_id = *((__u16 *) |
| 958 | &cmd->data.create_destroy_addr.unique_id[6]); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 959 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 960 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 961 | |
| 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | static 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 Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 974 | QETH_CARD_TEXT(card, 2, "guniqeid"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 975 | |
| 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 Wiedmann | a59d121 | 2019-06-27 17:01:22 +0200 | [diff] [blame] | 982 | iob = qeth_ipa_alloc_cmd(card, IPA_CMD_CREATE_ADDR, QETH_PROT_IPV6, |
| 983 | IPA_DATA_SIZEOF(create_destroy_addr)); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 984 | if (!iob) |
| 985 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 986 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 987 | *((__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 Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 994 | static int |
| 995 | qeth_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 Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 1001 | QETH_CARD_TEXT(card, 2, "diastrcb"); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1002 | |
| 1003 | cmd = (struct qeth_ipa_cmd *)data; |
| 1004 | rc = cmd->hdr.return_code; |
Ursula Braun | a959189 | 2010-03-08 20:36:55 +0000 | [diff] [blame] | 1005 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1006 | QETH_CARD_TEXT_(card, 2, "dxter%x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1007 | switch (cmd->data.diagass.action) { |
| 1008 | case QETH_DIAGS_CMD_TRACE_QUERY: |
| 1009 | break; |
| 1010 | case QETH_DIAGS_CMD_TRACE_DISABLE: |
Ursula Braun | a959189 | 2010-03-08 20:36:55 +0000 | [diff] [blame] | 1011 | 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 Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1021 | break; |
| 1022 | case QETH_DIAGS_CMD_TRACE_ENABLE: |
Ursula Braun | a959189 | 2010-03-08 20:36:55 +0000 | [diff] [blame] | 1023 | 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 Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | default: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1044 | QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n", |
| 1045 | cmd->data.diagass.action, CARD_DEVID(card)); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1046 | } |
| 1047 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1048 | return rc ? -EIO : 0; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static int |
| 1052 | qeth_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 Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 1057 | QETH_CARD_TEXT(card, 2, "diagtrac"); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1058 | |
Julian Wiedmann | 5cfbe10 | 2019-06-27 17:01:25 +0200 | [diff] [blame] | 1059 | iob = qeth_get_diag_cmd(card, QETH_DIAGS_CMD_TRACE, 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1060 | if (!iob) |
| 1061 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1062 | cmd = __ipa_cmd(iob); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1063 | 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 Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1068 | static int qeth_l3_add_mcast_rtnl(struct net_device *dev, int vid, void *arg) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1069 | { |
Julian Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1070 | struct qeth_card *card = arg; |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1071 | struct inet6_dev *in6_dev; |
| 1072 | struct in_device *in4_dev; |
| 1073 | struct qeth_ipaddr *ipm; |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1074 | struct qeth_ipaddr tmp; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1075 | struct ip_mc_list *im4; |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1076 | struct ifmcaddr6 *im6; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1077 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1078 | QETH_CARD_TEXT(card, 4, "addmc"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1079 | |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1080 | if (!dev || !(dev->flags & IFF_UP)) |
| 1081 | goto out; |
| 1082 | |
Julian Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1083 | in4_dev = __in_dev_get_rtnl(dev); |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1084 | if (!in4_dev) |
| 1085 | goto walk_ipv6; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1086 | |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1087 | 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 Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1091 | for (im4 = rtnl_dereference(in4_dev->mc_list); im4 != NULL; |
| 1092 | im4 = rtnl_dereference(im4->next_rcu)) { |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1093 | tmp.u.a4.addr = im4->multiaddr; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1094 | |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1095 | ipm = qeth_l3_find_addr_by_ip(card, &tmp); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1096 | if (ipm) { |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 1097 | /* for mcast, by-IP match means full match */ |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1098 | ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1099 | continue; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1100 | } |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1101 | |
| 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1108 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1109 | |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1110 | walk_ipv6: |
| 1111 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 1112 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1113 | |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1114 | in6_dev = __in6_dev_get(dev); |
| 1115 | if (!in6_dev) |
| 1116 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1117 | |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1118 | 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 Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1121 | |
Julian Wiedmann | ddf2810 | 2019-11-14 11:19:19 +0100 | [diff] [blame] | 1122 | read_lock_bh(&in6_dev->lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1123 | for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) { |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1124 | tmp.u.a6.addr = im6->mca_addr; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1125 | |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1126 | ipm = qeth_l3_find_addr_by_ip(card, &tmp); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1127 | if (ipm) { |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 1128 | /* for mcast, by-IP match means full match */ |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1129 | ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
| 1130 | continue; |
| 1131 | } |
| 1132 | |
Julian Wiedmann | b80c08a | 2019-11-14 11:19:23 +0100 | [diff] [blame] | 1133 | ipm = kmemdup(&tmp, sizeof(tmp), GFP_ATOMIC); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1134 | if (!ipm) |
| 1135 | continue; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1136 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1137 | hash_add(card->ip_mc_htable, |
| 1138 | &ipm->hnode, qeth_l3_ipaddr_hash(ipm)); |
| 1139 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1140 | } |
Julian Wiedmann | ddf2810 | 2019-11-14 11:19:19 +0100 | [diff] [blame] | 1141 | read_unlock_bh(&in6_dev->lock); |
| 1142 | |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1143 | out: |
Julian Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1144 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1145 | } |
| 1146 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1147 | static int qeth_l3_vlan_rx_add_vid(struct net_device *dev, |
| 1148 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1149 | { |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1150 | struct qeth_card *card = dev->ml_priv; |
| 1151 | |
Julian Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1152 | QETH_CARD_TEXT_(card, 4, "aid:%d", vid); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1153 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1154 | } |
| 1155 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1156 | static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev, |
| 1157 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1158 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1159 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1160 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1161 | QETH_CARD_TEXT_(card, 4, "kid:%d", vid); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1162 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1163 | } |
| 1164 | |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 1165 | static void qeth_l3_stop_card(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1166 | { |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 1167 | QETH_CARD_TEXT(card, 2, "stopcard"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1168 | |
| 1169 | qeth_set_allowed_threads(card, 0, 1); |
Julian Wiedmann | 0f7aedbd | 2019-02-28 18:59:44 +0100 | [diff] [blame] | 1170 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 1171 | cancel_work_sync(&card->rx_mode_work); |
| 1172 | qeth_l3_drain_rx_mode_cache(card); |
| 1173 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1174 | if (card->options.sniffer && |
| 1175 | (card->info.promisc_mode == SET_PROMISC_MODE_ON)) |
| 1176 | qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE); |
Julian Wiedmann | 0f7aedbd | 2019-02-28 18:59:44 +0100 | [diff] [blame] | 1177 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1178 | if (card->state == CARD_STATE_SOFTSETUP) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1179 | qeth_l3_clear_ip_htable(card, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1180 | qeth_clear_ipacmd_list(card); |
| 1181 | card->state = CARD_STATE_HARDSETUP; |
| 1182 | } |
| 1183 | if (card->state == CARD_STATE_HARDSETUP) { |
Julian Wiedmann | 41c47da | 2019-04-17 18:17:28 +0200 | [diff] [blame] | 1184 | qeth_drain_output_queues(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1185 | card->state = CARD_STATE_DOWN; |
| 1186 | } |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 1187 | |
Julian Wiedmann | 8b5026b | 2019-12-23 15:03:21 +0100 | [diff] [blame] | 1188 | qeth_qdio_clear_card(card, 0); |
Julian Wiedmann | aa3ad392 | 2020-01-25 16:53:00 +0100 | [diff] [blame] | 1189 | qeth_clear_working_pool_list(card); |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 1190 | flush_workqueue(card->event_wq); |
Julian Wiedmann | 0f39930 | 2019-12-18 16:32:27 +0100 | [diff] [blame] | 1191 | card->info.promisc_mode = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1192 | } |
| 1193 | |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 1194 | static void qeth_l3_set_promisc_mode(struct qeth_card *card) |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1195 | { |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 1196 | bool enable = card->dev->flags & IFF_PROMISC; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1197 | |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 1198 | if (card->info.promisc_mode == enable) |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1199 | return; |
| 1200 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1201 | if (IS_VM_NIC(card)) { /* Guestlan trace */ |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1202 | if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 1203 | qeth_setadp_promisc_mode(card, enable); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1204 | } else if (card->options.sniffer && /* HiperSockets trace */ |
| 1205 | qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) { |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 1206 | if (enable) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1207 | QETH_CARD_TEXT(card, 3, "+promisc"); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1208 | qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE); |
| 1209 | } else { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1210 | QETH_CARD_TEXT(card, 3, "-promisc"); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1211 | qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE); |
| 1212 | } |
| 1213 | } |
| 1214 | } |
| 1215 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 1216 | static void qeth_l3_rx_mode_work(struct work_struct *work) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1217 | { |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 1218 | struct qeth_card *card = container_of(work, struct qeth_card, |
| 1219 | rx_mode_work); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1220 | struct qeth_ipaddr *addr; |
| 1221 | struct hlist_node *tmp; |
| 1222 | int i, rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1223 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1224 | QETH_CARD_TEXT(card, 3, "setmulti"); |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 1225 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1226 | if (!card->options.sniffer) { |
Julian Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1227 | rtnl_lock(); |
| 1228 | qeth_l3_add_mcast_rtnl(card->dev, 0, card); |
Julian Wiedmann | 611abe5 | 2019-11-14 11:19:21 +0100 | [diff] [blame] | 1229 | if (qeth_is_supported(card, IPA_FULL_VLAN)) |
Julian Wiedmann | 8659c18 | 2019-11-14 11:19:22 +0100 | [diff] [blame] | 1230 | vlan_for_each(card->dev, qeth_l3_add_mcast_rtnl, card); |
| 1231 | rtnl_unlock(); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1232 | |
| 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 Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1237 | if (!rc || rc == -ENOENT) { |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1238 | 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 Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1244 | if (rc && rc != -ENETDOWN) { |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1245 | 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 Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1256 | } |
Julian Wiedmann | 59b757a | 2019-08-20 16:46:41 +0200 | [diff] [blame] | 1257 | |
| 1258 | qeth_l3_set_promisc_mode(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1259 | } |
| 1260 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1261 | static int qeth_l3_arp_makerc(u16 rc) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1262 | { |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1263 | switch (rc) { |
| 1264 | case IPA_RC_SUCCESS: |
| 1265 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1266 | case QETH_IPA_ARP_RC_NOTSUPP: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1267 | case QETH_IPA_ARP_RC_Q_NOTSUPP: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1268 | return -EOPNOTSUPP; |
| 1269 | case QETH_IPA_ARP_RC_OUT_OF_RANGE: |
| 1270 | return -EINVAL; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1271 | case QETH_IPA_ARP_RC_Q_NO_DATA: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1272 | return -ENOENT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1273 | default: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1274 | return -EIO; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1275 | } |
| 1276 | } |
| 1277 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1278 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1287 | static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries) |
| 1288 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1289 | struct qeth_cmd_buffer *iob; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1290 | int rc; |
| 1291 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1292 | QETH_CARD_TEXT(card, 3, "arpstnoe"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1293 | |
| 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 Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1299 | if (IS_VM_NIC(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1300 | return -EOPNOTSUPP; |
| 1301 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1302 | return -EOPNOTSUPP; |
| 1303 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1304 | |
| 1305 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1306 | IPA_CMD_ASS_ARP_SET_NO_ENTRIES, |
| 1307 | SETASS_DATA_SIZEOF(flags_32bit), |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1308 | 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 Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1314 | 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 Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1317 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1318 | } |
| 1319 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1320 | static __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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1323 | { |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1324 | __u32 rc; |
| 1325 | __u8 is_hsi; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1326 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1327 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1351 | } |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1352 | |
| 1353 | return rc; |
| 1354 | } |
| 1355 | |
| 1356 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | static 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 Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1368 | int e; |
| 1369 | int entrybytes_done; |
| 1370 | int stripped_bytes; |
| 1371 | __u8 do_strip_entries; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1372 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1373 | QETH_CARD_TEXT(card, 3, "arpquecb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1374 | |
| 1375 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 1376 | cmd = (struct qeth_ipa_cmd *) data; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1377 | QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1378 | if (cmd->hdr.return_code) { |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1379 | QETH_CARD_TEXT(card, 4, "arpcberr"); |
| 1380 | QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1381 | return qeth_l3_arp_makerc(cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1382 | } |
| 1383 | if (cmd->data.setassparms.hdr.return_code) { |
| 1384 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1385 | QETH_CARD_TEXT(card, 4, "setaperr"); |
| 1386 | QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1387 | return qeth_l3_arp_makerc(cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1388 | } |
| 1389 | qdata = &cmd->data.setassparms.data.query_arp; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1390 | QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1391 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1392 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1399 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1400 | 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 Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1414 | QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC); |
| 1415 | memset(qinfo->udata, 0, 4); |
| 1416 | return -ENOSPC; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1417 | } |
| 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1426 | /* 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 Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1430 | QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1431 | 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 Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1437 | QETH_CARD_TEXT_(card, 4, "rc%i", 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1438 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1441 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1444 | { |
| 1445 | struct qeth_cmd_buffer *iob; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1446 | struct qeth_ipa_cmd *cmd; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1447 | int rc; |
| 1448 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1449 | QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot); |
| 1450 | |
Thomas Richter | b475e31 | 2015-12-11 12:27:54 +0100 | [diff] [blame] | 1451 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 1452 | IPA_CMD_ASS_ARP_QUERY_INFO, |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1453 | SETASS_DATA_SIZEOF(query_arp), prot); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1454 | if (!iob) |
| 1455 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1456 | cmd = __ipa_cmd(iob); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1457 | cmd->data.setassparms.data.query_arp.request_bits = 0x000F; |
Julian Wiedmann | 84dbea4 | 2019-02-12 18:33:16 +0100 | [diff] [blame] | 1458 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_query_cb, qinfo); |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1459 | if (rc) |
| 1460 | QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n", |
| 1461 | CARD_DEVID(card), rc); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1462 | return rc; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1463 | } |
| 1464 | |
| 1465 | static 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 Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1470 | QETH_CARD_TEXT(card, 3, "arpquery"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1471 | |
| 1472 | if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/ |
| 1473 | IPA_ARP_PROCESSING)) { |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1474 | QETH_CARD_TEXT(card, 3, "arpqnsup"); |
| 1475 | rc = -EOPNOTSUPP; |
| 1476 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1477 | } |
| 1478 | /* get size of userspace buffer and mask_bits -> 6 bytes */ |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1479 | if (copy_from_user(&qinfo, udata, 6)) { |
| 1480 | rc = -EFAULT; |
| 1481 | goto out; |
| 1482 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1483 | qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1484 | if (!qinfo.udata) { |
| 1485 | rc = -ENOMEM; |
| 1486 | goto out; |
| 1487 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1488 | qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1489 | rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1490 | if (rc) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1491 | if (copy_to_user(udata, qinfo.udata, 4)) |
| 1492 | rc = -EFAULT; |
Sebastian Ott | 77a83ed | 2016-06-16 16:19:03 +0200 | [diff] [blame] | 1493 | goto free_and_out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1494 | } |
Sebastian Ott | 77a83ed | 2016-06-16 16:19:03 +0200 | [diff] [blame] | 1495 | 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 Ott | 77a83ed | 2016-06-16 16:19:03 +0200 | [diff] [blame] | 1499 | 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 Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1506 | free_and_out: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1507 | kfree(qinfo.udata); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1508 | out: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1509 | return rc; |
| 1510 | } |
| 1511 | |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1512 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1515 | { |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1516 | struct qeth_arp_cache_entry *cmd_entry; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1517 | struct qeth_cmd_buffer *iob; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1518 | int rc; |
| 1519 | |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1520 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1524 | |
| 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 Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1530 | if (IS_VM_NIC(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1531 | return -EOPNOTSUPP; |
| 1532 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1533 | return -EOPNOTSUPP; |
| 1534 | } |
| 1535 | |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1536 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd, |
Julian Wiedmann | b915046 | 2019-06-27 17:01:24 +0200 | [diff] [blame] | 1537 | SETASS_DATA_SIZEOF(arp_entry), |
| 1538 | QETH_PROT_IPV4); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1539 | if (!iob) |
| 1540 | return -ENOMEM; |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1541 | |
| 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 Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1545 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL); |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1546 | if (rc) |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1547 | QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n", |
| 1548 | arp_cmd, CARD_DEVID(card), rc); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1549 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | static int qeth_l3_arp_flush_cache(struct qeth_card *card) |
| 1553 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1554 | struct qeth_cmd_buffer *iob; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1555 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1556 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1557 | QETH_CARD_TEXT(card, 3, "arpflush"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1558 | |
| 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 Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1564 | if (IS_VM_NIC(card) || IS_IQD(card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1565 | return -EOPNOTSUPP; |
| 1566 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1567 | return -EOPNOTSUPP; |
| 1568 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1569 | |
| 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 Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1577 | if (rc) |
| 1578 | QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n", |
| 1579 | CARD_DEVID(card), rc); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1580 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1584 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1585 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1586 | struct qeth_arp_cache_entry arp_entry; |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1587 | enum qeth_arp_process_subcmds arp_cmd; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1588 | int rc = 0; |
| 1589 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1590 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1606 | case SIOC_QETH_ARP_REMOVE_ENTRY: |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1607 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1616 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1623 | default: |
| 1624 | rc = -EOPNOTSUPP; |
| 1625 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1626 | return rc; |
| 1627 | } |
| 1628 | |
Julian Wiedmann | 980f456 | 2019-06-27 17:01:32 +0200 | [diff] [blame] | 1629 | static int qeth_l3_get_cast_type_rcu(struct sk_buff *skb, struct dst_entry *dst, |
| 1630 | int ipv) |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1631 | { |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1632 | struct neighbour *n = NULL; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1633 | |
Julian Wiedmann | 980f456 | 2019-06-27 17:01:32 +0200 | [diff] [blame] | 1634 | if (dst) |
| 1635 | n = dst_neigh_lookup_skb(dst, skb); |
Julian Wiedmann | 0cd6783d3 | 2019-06-05 13:48:49 +0200 | [diff] [blame] | 1636 | |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1637 | if (n) { |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1638 | int cast_type = n->type; |
| 1639 | |
David S. Miller | 24db1ba | 2012-07-02 22:02:33 -0700 | [diff] [blame] | 1640 | neigh_release(n); |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1641 | if ((cast_type == RTN_BROADCAST) || |
| 1642 | (cast_type == RTN_MULTICAST) || |
| 1643 | (cast_type == RTN_ANYCAST)) |
| 1644 | return cast_type; |
Julian Wiedmann | 86c0cdb | 2018-07-11 17:42:41 +0200 | [diff] [blame] | 1645 | return RTN_UNICAST; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1646 | } |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1647 | |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1648 | /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */ |
Julian Wiedmann | 0cd6783d3 | 2019-06-05 13:48:49 +0200 | [diff] [blame] | 1649 | switch (ipv) { |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1650 | case 4: |
Julian Wiedmann | 72c8797 | 2019-06-05 13:48:48 +0200 | [diff] [blame] | 1651 | if (ipv4_is_lbcast(ip_hdr(skb)->daddr)) |
| 1652 | return RTN_BROADCAST; |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1653 | return ipv4_is_multicast(ip_hdr(skb)->daddr) ? |
Julian Wiedmann | 86c0cdb | 2018-07-11 17:42:41 +0200 | [diff] [blame] | 1654 | RTN_MULTICAST : RTN_UNICAST; |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1655 | case 6: |
| 1656 | return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ? |
| 1657 | RTN_MULTICAST : RTN_UNICAST; |
| 1658 | default: |
| 1659 | /* ... and MAC address */ |
Julian Wiedmann | 58aa249 | 2019-04-25 18:26:00 +0200 | [diff] [blame] | 1660 | return qeth_get_ether_cast_type(skb); |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1661 | } |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1662 | } |
| 1663 | |
Julian Wiedmann | 980f456 | 2019-06-27 17:01:32 +0200 | [diff] [blame] | 1664 | static 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 Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1678 | static u8 qeth_l3_cast_type_to_flag(int cast_type) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1679 | { |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1680 | 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. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1688 | |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1689 | static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue, |
| 1690 | struct qeth_hdr *hdr, struct sk_buff *skb, |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1691 | int ipv, unsigned int data_len) |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1692 | { |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 1693 | struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3; |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1694 | struct vlan_ethhdr *veth = vlan_eth_hdr(skb); |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1695 | struct qeth_card *card = queue->card; |
Julian Wiedmann | 0cd6783d3 | 2019-06-05 13:48:49 +0200 | [diff] [blame] | 1696 | struct dst_entry *dst; |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1697 | int cast_type; |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1698 | |
Julian Wiedmann | f6c1314 | 2017-12-20 20:11:08 +0100 | [diff] [blame] | 1699 | hdr->hdr.l3.length = data_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1700 | |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1701 | if (skb_is_gso(skb)) { |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 1702 | hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO; |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1703 | } else { |
| 1704 | hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 1705 | |
| 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 Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1714 | 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 Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1719 | } |
| 1720 | } |
| 1721 | |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1722 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1731 | } |
| 1732 | |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1733 | rcu_read_lock(); |
Julian Wiedmann | 980f456 | 2019-06-27 17:01:32 +0200 | [diff] [blame] | 1734 | dst = qeth_dst_check_rcu(skb, ipv); |
Julian Wiedmann | 0cd6783d3 | 2019-06-05 13:48:49 +0200 | [diff] [blame] | 1735 | |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1736 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1742 | if (ipv == 4) { |
Julian Wiedmann | 980f456 | 2019-06-27 17:01:32 +0200 | [diff] [blame] | 1743 | struct rtable *rt = (struct rtable *) dst; |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 1744 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1745 | *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ? |
| 1746 | rt_nexthop(rt, ip_hdr(skb)->daddr) : |
| 1747 | ip_hdr(skb)->daddr; |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1748 | } else if (ipv == 6) { |
Julian Wiedmann | 980f456 | 2019-06-27 17:01:32 +0200 | [diff] [blame] | 1749 | struct rt6_info *rt = (struct rt6_info *) dst; |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 1750 | |
Julian Wiedmann | ec2c672 | 2017-08-07 13:28:39 +0200 | [diff] [blame] | 1751 | if (rt && !ipv6_addr_any(&rt->rt6i_gateway)) |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 1752 | l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway; |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1753 | else |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 1754 | l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr; |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 1755 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1756 | hdr->hdr.l3.flags |= QETH_HDR_IPV6; |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1757 | if (!IS_IQD(card)) |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1758 | hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU; |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1759 | } else { |
| 1760 | /* OSA only: */ |
| 1761 | l3_hdr->flags |= QETH_HDR_PASSTHRU; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1762 | } |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1763 | rcu_read_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1764 | } |
| 1765 | |
Julian Wiedmann | 2d3986d | 2018-09-17 17:36:00 +0200 | [diff] [blame] | 1766 | static 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 Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1773 | 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 Wiedmann | 2d3986d | 2018-09-17 17:36:00 +0200 | [diff] [blame] | 1778 | } |
| 1779 | |
Julian Wiedmann | 356156b | 2018-09-17 17:36:03 +0200 | [diff] [blame] | 1780 | static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb, |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1781 | struct qeth_qdio_out_q *queue, int ipv) |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1782 | { |
Julian Wiedmann | 81ec543 | 2018-11-08 15:06:17 +0100 | [diff] [blame] | 1783 | unsigned int hw_hdr_len; |
| 1784 | int rc; |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1785 | |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1786 | /* re-use the L2 header area for the HW header: */ |
Julian Wiedmann | 81ec543 | 2018-11-08 15:06:17 +0100 | [diff] [blame] | 1787 | hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) : |
| 1788 | sizeof(struct qeth_hdr); |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1789 | rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN); |
| 1790 | if (rc) |
| 1791 | return rc; |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1792 | skb_pull(skb, ETH_HLEN); |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1793 | |
Julian Wiedmann | 2d3986d | 2018-09-17 17:36:00 +0200 | [diff] [blame] | 1794 | qeth_l3_fixup_headers(skb); |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1795 | return qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header); |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1796 | } |
| 1797 | |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1798 | static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb, |
| 1799 | struct net_device *dev) |
| 1800 | { |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1801 | struct qeth_card *card = dev->ml_priv; |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 1802 | u16 txq = skb_get_queue_mapping(skb); |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1803 | int ipv = qeth_get_ip_version(skb); |
| 1804 | struct qeth_qdio_out_q *queue; |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1805 | int rc; |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1806 | |
Julian Wiedmann | eeac0e2 | 2019-08-23 11:48:49 +0200 | [diff] [blame] | 1807 | if (!skb_is_gso(skb)) |
| 1808 | qdisc_skb_cb(skb)->pkt_len = skb->len; |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1809 | if (IS_IQD(card)) { |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 1810 | queue = card->qdio.out_qs[qeth_iqd_translate_txq(dev, txq)]; |
| 1811 | |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1812 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1817 | goto tx_drop; |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 1818 | } else { |
Julian Wiedmann | 73dc2da | 2019-04-17 18:17:33 +0200 | [diff] [blame] | 1819 | queue = card->qdio.out_qs[txq]; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1820 | } |
| 1821 | |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1822 | if (!(dev->flags & IFF_BROADCAST) && |
| 1823 | qeth_l3_get_cast_type(skb) == RTN_BROADCAST) |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1824 | goto tx_drop; |
| 1825 | |
Julian Wiedmann | 356156b | 2018-09-17 17:36:03 +0200 | [diff] [blame] | 1826 | if (ipv == 4 || IS_IQD(card)) |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1827 | rc = qeth_l3_xmit(card, skb, queue, ipv); |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1828 | else |
Julian Wiedmann | eca1d5c | 2019-06-27 17:01:33 +0200 | [diff] [blame] | 1829 | rc = qeth_xmit(card, skb, queue, ipv, qeth_l3_fill_header); |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1830 | |
Julian Wiedmann | eeac0e2 | 2019-08-23 11:48:49 +0200 | [diff] [blame] | 1831 | if (!rc) |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 1832 | return NETDEV_TX_OK; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1833 | |
| 1834 | tx_drop: |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1835 | QETH_TXQ_STAT_INC(queue, tx_dropped); |
Julian Wiedmann | 104b485 | 2019-03-18 16:40:56 +0100 | [diff] [blame] | 1836 | kfree_skb(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1837 | return NETDEV_TX_OK; |
| 1838 | } |
| 1839 | |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 1840 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1847 | /* |
| 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 | */ |
| 1854 | static 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 | |
| 1862 | static int |
| 1863 | qeth_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 Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1871 | static 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 Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 1880 | static 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 Wiedmann | 73dc2da | 2019-04-17 18:17:33 +0200 | [diff] [blame] | 1887 | static 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 Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1895 | static const struct net_device_ops qeth_l3_netdev_ops = { |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 1896 | .ndo_open = qeth_open, |
| 1897 | .ndo_stop = qeth_stop, |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1898 | .ndo_get_stats64 = qeth_get_stats64, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 1899 | .ndo_start_xmit = qeth_l3_hard_start_xmit, |
Julian Wiedmann | 3a18d75 | 2019-04-17 18:17:32 +0200 | [diff] [blame] | 1900 | .ndo_select_queue = qeth_l3_iqd_select_queue, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 1901 | .ndo_validate_addr = eth_validate_addr, |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1902 | .ndo_set_rx_mode = qeth_l3_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 1903 | .ndo_do_ioctl = qeth_do_ioctl, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1904 | .ndo_fix_features = qeth_fix_features, |
| 1905 | .ndo_set_features = qeth_set_features, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 1906 | .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid, |
| 1907 | .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid, |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1908 | .ndo_tx_timeout = qeth_tx_timeout, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 1909 | }; |
| 1910 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1911 | static const struct net_device_ops qeth_l3_osa_netdev_ops = { |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 1912 | .ndo_open = qeth_open, |
| 1913 | .ndo_stop = qeth_stop, |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1914 | .ndo_get_stats64 = qeth_get_stats64, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1915 | .ndo_start_xmit = qeth_l3_hard_start_xmit, |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1916 | .ndo_features_check = qeth_l3_osa_features_check, |
Julian Wiedmann | 73dc2da | 2019-04-17 18:17:33 +0200 | [diff] [blame] | 1917 | .ndo_select_queue = qeth_l3_osa_select_queue, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1918 | .ndo_validate_addr = eth_validate_addr, |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1919 | .ndo_set_rx_mode = qeth_l3_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 1920 | .ndo_do_ioctl = qeth_do_ioctl, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 1921 | .ndo_fix_features = qeth_fix_features, |
| 1922 | .ndo_set_features = qeth_set_features, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1923 | .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid, |
| 1924 | .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid, |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1925 | .ndo_tx_timeout = qeth_tx_timeout, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1926 | .ndo_neigh_setup = qeth_l3_neigh_setup, |
| 1927 | }; |
| 1928 | |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 1929 | static int qeth_l3_setup_netdev(struct qeth_card *card, bool carrier_ok) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1930 | { |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 1931 | unsigned int headroom; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1932 | int rc; |
| 1933 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1934 | if (IS_OSD(card) || IS_OSX(card)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1935 | if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) || |
| 1936 | (card->info.link_type == QETH_LINK_TYPE_HSTR)) { |
Paul Gortmaker | 1abd229 | 2012-05-10 15:50:52 -0400 | [diff] [blame] | 1937 | pr_info("qeth_l3: ignoring TR device\n"); |
| 1938 | return -ENODEV; |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 1939 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1940 | |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 1941 | card->dev->netdev_ops = &qeth_l3_osa_netdev_ops; |
Julian Wiedmann | 0f34294 | 2018-03-09 18:12:54 +0100 | [diff] [blame] | 1942 | |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 1943 | /*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 Wiedmann | 0f34294 | 2018-03-09 18:12:54 +0100 | [diff] [blame] | 1947 | |
Julian Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1948 | if (!IS_VM_NIC(card)) { |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 1949 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1954 | } |
Kittipon Meesompop | 571f9dd8 | 2018-04-26 09:42:22 +0200 | [diff] [blame] | 1955 | |
| 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 Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 1960 | 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 Wiedmann | 379ac99 | 2019-04-25 18:25:57 +0200 | [diff] [blame] | 1972 | } else if (IS_IQD(card)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1973 | card->dev->flags |= IFF_NOARP; |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 1974 | card->dev->netdev_ops = &qeth_l3_netdev_ops; |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 1975 | headroom = sizeof(struct qeth_hdr) - ETH_HLEN; |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1976 | |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1977 | rc = qeth_l3_iqd_read_initial_mac(card); |
| 1978 | if (rc) |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 1979 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1980 | } else |
| 1981 | return -ENODEV; |
| 1982 | |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 1983 | card->dev->needed_headroom = headroom; |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 1984 | card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX | |
| 1985 | NETIF_F_HW_VLAN_CTAG_RX | |
| 1986 | NETIF_F_HW_VLAN_CTAG_FILTER; |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 1987 | |
Eric Dumazet | 0287587 | 2014-10-05 18:38:35 -0700 | [diff] [blame] | 1988 | netif_keep_dst(card->dev); |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 1989 | if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) |
Julian Wiedmann | 371a1e7 | 2018-07-11 17:42:44 +0200 | [diff] [blame] | 1990 | netif_set_gso_max_size(card->dev, |
| 1991 | PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1992 | |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 1993 | netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 1994 | rc = register_netdev(card->dev); |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 1995 | if (!rc && carrier_ok) |
| 1996 | netif_carrier_on(card->dev); |
| 1997 | |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 1998 | out: |
| 1999 | if (rc) |
| 2000 | card->dev->netdev_ops = NULL; |
| 2001 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2002 | } |
| 2003 | |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2004 | static const struct device_type qeth_l3_devtype = { |
| 2005 | .name = "qeth_layer3", |
| 2006 | .groups = qeth_l3_attr_groups, |
| 2007 | }; |
| 2008 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2009 | static int qeth_l3_probe_device(struct ccwgroup_device *gdev) |
| 2010 | { |
| 2011 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | 9111e78 | 2017-05-10 19:07:51 +0200 | [diff] [blame] | 2012 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2013 | |
Julian Wiedmann | 7221b72 | 2019-03-18 16:40:55 +0100 | [diff] [blame] | 2014 | hash_init(card->ip_htable); |
Julian Wiedmann | df2a2a5 | 2019-03-28 16:39:23 +0100 | [diff] [blame] | 2015 | mutex_init(&card->ip_lock); |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2016 | card->cmd_wq = alloc_ordered_workqueue("%s_cmd", 0, |
| 2017 | dev_name(&gdev->dev)); |
| 2018 | if (!card->cmd_wq) |
| 2019 | return -ENOMEM; |
Julian Wiedmann | 7221b72 | 2019-03-18 16:40:55 +0100 | [diff] [blame] | 2020 | |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2021 | if (gdev->dev.type == &qeth_generic_devtype) { |
| 2022 | rc = qeth_l3_create_device_attributes(&gdev->dev); |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2023 | if (rc) { |
| 2024 | destroy_workqueue(card->cmd_wq); |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2025 | return rc; |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2026 | } |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2027 | } |
Julian Wiedmann | 7221b72 | 2019-03-18 16:40:55 +0100 | [diff] [blame] | 2028 | |
Ursula Braun | ebccc739 | 2017-05-10 19:07:54 +0200 | [diff] [blame] | 2029 | hash_init(card->ip_mc_htable); |
Julian Wiedmann | d0c7482 | 2019-03-28 16:39:19 +0100 | [diff] [blame] | 2030 | INIT_WORK(&card->rx_mode_work, qeth_l3_rx_mode_work); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2031 | return 0; |
| 2032 | } |
| 2033 | |
| 2034 | static void qeth_l3_remove_device(struct ccwgroup_device *cgdev) |
| 2035 | { |
| 2036 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 2037 | |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2038 | if (cgdev->dev.type == &qeth_generic_devtype) |
| 2039 | qeth_l3_remove_device_attributes(&cgdev->dev); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2040 | |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 2041 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2042 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 2043 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 2044 | if (cgdev->state == CCWGROUP_ONLINE) |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame^] | 2045 | qeth_set_offline(card, false); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2046 | |
Julian Wiedmann | c2780c1 | 2019-02-04 17:40:08 +0100 | [diff] [blame] | 2047 | cancel_work_sync(&card->close_dev_work); |
Julian Wiedmann | 30356d0 | 2018-11-02 19:04:10 +0100 | [diff] [blame] | 2048 | if (qeth_netdev_is_registered(card->dev)) |
| 2049 | unregister_netdev(card->dev); |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2050 | |
| 2051 | flush_workqueue(card->cmd_wq); |
| 2052 | destroy_workqueue(card->cmd_wq); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 2053 | qeth_l3_clear_ip_htable(card, 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2054 | qeth_l3_clear_ipato_list(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2055 | } |
| 2056 | |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame^] | 2057 | static int qeth_l3_set_online(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2058 | { |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame^] | 2059 | struct ccwgroup_device *gdev = card->gdev; |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2060 | struct net_device *dev = card->dev; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2061 | int rc = 0; |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 2062 | bool carrier_ok; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2063 | |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 2064 | rc = qeth_core_hardsetup_card(card, &carrier_ok); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2065 | if (rc) { |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 2066 | QETH_CARD_TEXT_(card, 2, "2err%04x", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 2067 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2068 | goto out_remove; |
| 2069 | } |
| 2070 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2071 | card->state = CARD_STATE_HARDSETUP; |
| 2072 | qeth_print_status_message(card); |
| 2073 | |
| 2074 | /* softsetup */ |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 2075 | QETH_CARD_TEXT(card, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2076 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2077 | rc = qeth_l3_setadapter_parms(card); |
| 2078 | if (rc) |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 2079 | QETH_CARD_TEXT_(card, 2, "2err%04x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2080 | if (!card->options.sniffer) { |
| 2081 | rc = qeth_l3_start_ipassists(card); |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 2082 | if (rc) { |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 2083 | QETH_CARD_TEXT_(card, 2, "3err%d", rc); |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 2084 | goto out_remove; |
| 2085 | } |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2086 | rc = qeth_l3_setrouting_v4(card); |
| 2087 | if (rc) |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 2088 | QETH_CARD_TEXT_(card, 2, "4err%04x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2089 | rc = qeth_l3_setrouting_v6(card); |
| 2090 | if (rc) |
Julian Wiedmann | 57a688aa | 2019-06-11 18:37:55 +0200 | [diff] [blame] | 2091 | QETH_CARD_TEXT_(card, 2, "5err%04x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2092 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2093 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2094 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2095 | |
| 2096 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 2097 | qeth_l3_recover_ip(card); |
Julian Wiedmann | d025da9 | 2018-06-29 19:45:54 +0200 | [diff] [blame] | 2098 | |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2099 | 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 Braun | 4763b0a | 2011-12-19 22:56:32 +0000 | [diff] [blame] | 2104 | rtnl_lock(); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2105 | if (carrier_ok) |
| 2106 | netif_carrier_on(dev); |
| 2107 | else |
| 2108 | netif_carrier_off(dev); |
| 2109 | |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 2110 | netif_device_attach(dev); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2111 | qeth_enable_hw_features(dev); |
| 2112 | |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 2113 | if (card->info.open_when_online) { |
| 2114 | card->info.open_when_online = 0; |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2115 | dev_open(dev, NULL); |
Julian Wiedmann | 9aa17df | 2018-07-11 17:42:40 +0200 | [diff] [blame] | 2116 | } |
Ursula Braun | 4763b0a | 2011-12-19 22:56:32 +0000 | [diff] [blame] | 2117 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2118 | } |
Stefan Raspl | 82f77cf | 2013-03-18 20:04:42 +0000 | [diff] [blame] | 2119 | qeth_trace_features(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2120 | /* let user_space know that device is online */ |
| 2121 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
| 2122 | return 0; |
| 2123 | out_remove: |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2124 | qeth_l3_stop_card(card); |
Julian Wiedmann | f9e50b0 | 2019-12-05 14:33:04 +0100 | [diff] [blame] | 2125 | qeth_stop_channel(&card->data); |
| 2126 | qeth_stop_channel(&card->write); |
| 2127 | qeth_stop_channel(&card->read); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 2128 | qdio_free(CARD_DDEV(card)); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 2129 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2130 | } |
| 2131 | |
Julian Wiedmann | 91003f3 | 2020-01-25 16:53:01 +0100 | [diff] [blame^] | 2132 | static void qeth_l3_set_offline(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2133 | { |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2134 | qeth_l3_stop_card(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2135 | } |
| 2136 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 2137 | /* Returns zero if the command is successfully "consumed" */ |
| 2138 | static int qeth_l3_control_event(struct qeth_card *card, |
| 2139 | struct qeth_ipa_cmd *cmd) |
| 2140 | { |
| 2141 | return 1; |
| 2142 | } |
| 2143 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 2144 | struct qeth_discipline qeth_l3_discipline = { |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2145 | .devtype = &qeth_l3_devtype, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 2146 | .setup = qeth_l3_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2147 | .remove = qeth_l3_remove_device, |
| 2148 | .set_online = qeth_l3_set_online, |
| 2149 | .set_offline = qeth_l3_set_offline, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 2150 | .do_ioctl = qeth_l3_do_ioctl, |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 2151 | .control_event_handler = qeth_l3_control_event, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2152 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 2153 | EXPORT_SYMBOL_GPL(qeth_l3_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2154 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2155 | static 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 Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 2161 | qeth_l3_modify_ip(card, addr, true); |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2162 | return NOTIFY_OK; |
| 2163 | case NETDEV_DOWN: |
Julian Wiedmann | 05a1785 | 2019-03-28 16:39:21 +0100 | [diff] [blame] | 2164 | qeth_l3_modify_ip(card, addr, false); |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2165 | return NOTIFY_OK; |
| 2166 | default: |
| 2167 | return NOTIFY_DONE; |
| 2168 | } |
| 2169 | } |
| 2170 | |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2171 | struct 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 | |
| 2179 | static 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 | |
| 2187 | static 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 Wiedmann | b9caa98 | 2018-03-09 18:13:01 +0100 | [diff] [blame] | 2195 | static 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2205 | static int qeth_l3_ip_event(struct notifier_block *this, |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 2206 | unsigned long event, void *ptr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2207 | { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 2208 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2209 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
Julian Wiedmann | b9caa98 | 2018-03-09 18:13:01 +0100 | [diff] [blame] | 2210 | struct net_device *dev = ifa->ifa_dev->dev; |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2211 | struct qeth_ipaddr addr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2212 | struct qeth_card *card; |
| 2213 | |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 2214 | if (dev_net(dev) != &init_net) |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 2215 | return NOTIFY_DONE; |
| 2216 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2217 | card = qeth_l3_get_card_from_dev(dev); |
| 2218 | if (!card) |
| 2219 | return NOTIFY_DONE; |
frank.blaschka@de.ibm.com | 6d8823d | 2012-05-16 01:28:26 +0000 | [diff] [blame] | 2220 | QETH_CARD_TEXT(card, 3, "ipevent"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2221 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2222 | qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4); |
Julian Wiedmann | 1b40d4b | 2019-10-31 13:42:20 +0100 | [diff] [blame] | 2223 | addr.u.a4.addr = ifa->ifa_address; |
Julian Wiedmann | 490df97 | 2019-12-18 17:34:46 +0100 | [diff] [blame] | 2224 | addr.u.a4.mask = ifa->ifa_mask; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2225 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2226 | return qeth_l3_handle_ip_event(card, &addr, event); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2227 | } |
| 2228 | |
| 2229 | static struct notifier_block qeth_l3_ip_notifier = { |
| 2230 | qeth_l3_ip_event, |
| 2231 | NULL, |
| 2232 | }; |
| 2233 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2234 | static int qeth_l3_ip6_event(struct notifier_block *this, |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 2235 | unsigned long event, void *ptr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2236 | { |
| 2237 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
Julian Wiedmann | b9caa98 | 2018-03-09 18:13:01 +0100 | [diff] [blame] | 2238 | struct net_device *dev = ifa->idev->dev; |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2239 | struct qeth_l3_ip_event_work *ip_work; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2240 | struct qeth_card *card; |
| 2241 | |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2242 | if (event != NETDEV_UP && event != NETDEV_DOWN) |
| 2243 | return NOTIFY_DONE; |
| 2244 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2245 | card = qeth_l3_get_card_from_dev(dev); |
| 2246 | if (!card) |
| 2247 | return NOTIFY_DONE; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2248 | QETH_CARD_TEXT(card, 3, "ip6event"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2249 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 2250 | return NOTIFY_DONE; |
| 2251 | |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2252 | ip_work = kmalloc(sizeof(*ip_work), GFP_ATOMIC); |
| 2253 | if (!ip_work) |
| 2254 | return NOTIFY_DONE; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2255 | |
Julian Wiedmann | 7686e4b | 2019-03-28 16:39:22 +0100 | [diff] [blame] | 2256 | 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 Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2269 | } |
| 2270 | |
| 2271 | static struct notifier_block qeth_l3_ip6_notifier = { |
| 2272 | qeth_l3_ip6_event, |
| 2273 | NULL, |
| 2274 | }; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2275 | |
| 2276 | static int qeth_l3_register_notifiers(void) |
| 2277 | { |
| 2278 | int rc; |
| 2279 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2280 | QETH_DBF_TEXT(SETUP, 5, "regnotif"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2281 | rc = register_inetaddr_notifier(&qeth_l3_ip_notifier); |
| 2282 | if (rc) |
| 2283 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2284 | rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier); |
| 2285 | if (rc) { |
| 2286 | unregister_inetaddr_notifier(&qeth_l3_ip_notifier); |
| 2287 | return rc; |
| 2288 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2289 | return 0; |
| 2290 | } |
| 2291 | |
| 2292 | static void qeth_l3_unregister_notifiers(void) |
| 2293 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2294 | QETH_DBF_TEXT(SETUP, 5, "unregnot"); |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 2295 | WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier)); |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 2296 | WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | static int __init qeth_l3_init(void) |
| 2300 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 2301 | pr_info("register layer 3 discipline\n"); |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 2302 | return qeth_l3_register_notifiers(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | static void __exit qeth_l3_exit(void) |
| 2306 | { |
| 2307 | qeth_l3_unregister_notifiers(); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 2308 | pr_info("unregister layer 3 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2309 | } |
| 2310 | |
| 2311 | module_init(qeth_l3_init); |
| 2312 | module_exit(qeth_l3_exit); |
| 2313 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 2314 | MODULE_DESCRIPTION("qeth layer 3 discipline"); |
| 2315 | MODULE_LICENSE("GPL"); |