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> |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 35 | #include <net/ip6_fib.h> |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 36 | #include <net/iucv/af_iucv.h> |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 37 | #include <linux/hashtable.h> |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 38 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 39 | #include "qeth_l3.h" |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 40 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 41 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 42 | static int qeth_l3_set_offline(struct ccwgroup_device *); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 43 | static void qeth_l3_set_rx_mode(struct net_device *dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 44 | static int qeth_l3_register_addr_entry(struct qeth_card *, |
| 45 | struct qeth_ipaddr *); |
| 46 | static int qeth_l3_deregister_addr_entry(struct qeth_card *, |
| 47 | struct qeth_ipaddr *); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 48 | |
Thomas Richter | 56530d6 | 2014-10-22 12:18:04 +0200 | [diff] [blame] | 49 | static void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 50 | { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 51 | sprintf(buf, "%pI4", addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 52 | } |
| 53 | |
Thomas Richter | 56530d6 | 2014-10-22 12:18:04 +0200 | [diff] [blame] | 54 | static void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 55 | { |
Joe Perches | 963a9fd | 2010-09-07 21:14:40 +0000 | [diff] [blame] | 56 | sprintf(buf, "%pI6", addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 57 | } |
| 58 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 59 | void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr, |
| 60 | char *buf) |
| 61 | { |
| 62 | if (proto == QETH_PROT_IPV4) |
| 63 | qeth_l3_ipaddr4_to_string(addr, buf); |
| 64 | else if (proto == QETH_PROT_IPV6) |
| 65 | qeth_l3_ipaddr6_to_string(addr, buf); |
| 66 | } |
| 67 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 68 | static struct qeth_ipaddr *qeth_l3_get_addr_buffer(enum qeth_prot_versions prot) |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 69 | { |
| 70 | struct qeth_ipaddr *addr = kmalloc(sizeof(*addr), GFP_ATOMIC); |
| 71 | |
| 72 | if (addr) |
| 73 | qeth_l3_init_ipaddr(addr, QETH_IP_TYPE_NORMAL, prot); |
| 74 | return addr; |
| 75 | } |
| 76 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 77 | static struct qeth_ipaddr *qeth_l3_find_addr_by_ip(struct qeth_card *card, |
| 78 | struct qeth_ipaddr *query) |
| 79 | { |
| 80 | u64 key = qeth_l3_ipaddr_hash(query); |
| 81 | struct qeth_ipaddr *addr; |
| 82 | |
| 83 | if (query->is_multicast) { |
| 84 | hash_for_each_possible(card->ip_mc_htable, addr, hnode, key) |
| 85 | if (qeth_l3_addr_match_ip(addr, query)) |
| 86 | return addr; |
| 87 | } else { |
| 88 | hash_for_each_possible(card->ip_htable, addr, hnode, key) |
| 89 | if (qeth_l3_addr_match_ip(addr, query)) |
| 90 | return addr; |
| 91 | } |
| 92 | return NULL; |
| 93 | } |
| 94 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 95 | static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len) |
| 96 | { |
| 97 | int i, j; |
| 98 | u8 octet; |
| 99 | |
| 100 | for (i = 0; i < len; ++i) { |
| 101 | octet = addr[i]; |
| 102 | for (j = 7; j >= 0; --j) { |
| 103 | bits[i*8 + j] = octet & 1; |
| 104 | octet >>= 1; |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 109 | static bool qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card, |
| 110 | struct qeth_ipaddr *addr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 111 | { |
| 112 | struct qeth_ipato_entry *ipatoe; |
| 113 | u8 addr_bits[128] = {0, }; |
| 114 | u8 ipatoe_bits[128] = {0, }; |
| 115 | int rc = 0; |
| 116 | |
| 117 | if (!card->ipato.enabled) |
Gustavo A. R. Silva | 1a363b0 | 2018-08-09 14:48:04 +0200 | [diff] [blame] | 118 | return false; |
Julian Wiedmann | b22d73d6 | 2017-12-13 18:56:30 +0100 | [diff] [blame] | 119 | if (addr->type != QETH_IP_TYPE_NORMAL) |
Gustavo A. R. Silva | 1a363b0 | 2018-08-09 14:48:04 +0200 | [diff] [blame] | 120 | return false; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 121 | |
| 122 | qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits, |
| 123 | (addr->proto == QETH_PROT_IPV4)? 4:16); |
| 124 | list_for_each_entry(ipatoe, &card->ipato.entries, entry) { |
| 125 | if (addr->proto != ipatoe->proto) |
| 126 | continue; |
| 127 | qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits, |
| 128 | (ipatoe->proto == QETH_PROT_IPV4) ? |
| 129 | 4 : 16); |
| 130 | if (addr->proto == QETH_PROT_IPV4) |
| 131 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 132 | min(32, ipatoe->mask_bits)); |
| 133 | else |
| 134 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 135 | min(128, ipatoe->mask_bits)); |
| 136 | if (rc) |
| 137 | break; |
| 138 | } |
| 139 | /* invert? */ |
| 140 | if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4) |
| 141 | rc = !rc; |
| 142 | else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6) |
| 143 | rc = !rc; |
| 144 | |
| 145 | return rc; |
| 146 | } |
| 147 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 148 | static int qeth_l3_delete_ip(struct qeth_card *card, |
| 149 | struct qeth_ipaddr *tmp_addr) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 150 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 151 | int rc = 0; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 152 | struct qeth_ipaddr *addr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 153 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 154 | if (tmp_addr->type == QETH_IP_TYPE_RXIP) |
| 155 | QETH_CARD_TEXT(card, 2, "delrxip"); |
| 156 | else if (tmp_addr->type == QETH_IP_TYPE_VIPA) |
| 157 | QETH_CARD_TEXT(card, 2, "delvipa"); |
| 158 | else |
| 159 | QETH_CARD_TEXT(card, 2, "delip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 160 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 161 | if (tmp_addr->proto == QETH_PROT_IPV4) |
| 162 | QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 163 | else { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 164 | QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8); |
| 165 | QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 166 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 167 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 168 | addr = qeth_l3_find_addr_by_ip(card, tmp_addr); |
| 169 | if (!addr || !qeth_l3_addr_match_all(addr, tmp_addr)) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 170 | return -ENOENT; |
| 171 | |
| 172 | addr->ref_counter--; |
Julian Wiedmann | 4964c66 | 2018-02-27 18:58:15 +0100 | [diff] [blame] | 173 | if (addr->type == QETH_IP_TYPE_NORMAL && addr->ref_counter > 0) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 174 | return rc; |
| 175 | if (addr->in_progress) |
| 176 | return -EINPROGRESS; |
| 177 | |
Julian Wiedmann | 98d823a | 2018-02-27 18:58:13 +0100 | [diff] [blame] | 178 | if (qeth_card_hw_is_reachable(card)) |
| 179 | rc = qeth_l3_deregister_addr_entry(card, addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 180 | |
| 181 | hash_del(&addr->hnode); |
| 182 | kfree(addr); |
| 183 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 184 | return rc; |
| 185 | } |
| 186 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 187 | 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] | 188 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 189 | int rc = 0; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 190 | struct qeth_ipaddr *addr; |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 191 | char buf[40]; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 192 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 193 | if (tmp_addr->type == QETH_IP_TYPE_RXIP) |
| 194 | QETH_CARD_TEXT(card, 2, "addrxip"); |
| 195 | else if (tmp_addr->type == QETH_IP_TYPE_VIPA) |
| 196 | QETH_CARD_TEXT(card, 2, "addvipa"); |
| 197 | else |
| 198 | QETH_CARD_TEXT(card, 2, "addip"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 199 | |
| 200 | if (tmp_addr->proto == QETH_PROT_IPV4) |
| 201 | QETH_CARD_HEX(card, 4, &tmp_addr->u.a4.addr, 4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 202 | else { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 203 | QETH_CARD_HEX(card, 4, &tmp_addr->u.a6.addr, 8); |
| 204 | QETH_CARD_HEX(card, 4, ((char *)&tmp_addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 205 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 206 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 207 | addr = qeth_l3_find_addr_by_ip(card, tmp_addr); |
| 208 | if (addr) { |
| 209 | if (tmp_addr->type != QETH_IP_TYPE_NORMAL) |
| 210 | return -EADDRINUSE; |
| 211 | if (qeth_l3_addr_match_all(addr, tmp_addr)) { |
| 212 | addr->ref_counter++; |
| 213 | return 0; |
| 214 | } |
| 215 | qeth_l3_ipaddr_to_string(tmp_addr->proto, (u8 *)&tmp_addr->u, |
| 216 | buf); |
| 217 | dev_warn(&card->gdev->dev, |
| 218 | "Registering IP address %s failed\n", buf); |
| 219 | return -EADDRINUSE; |
| 220 | } else { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 221 | addr = qeth_l3_get_addr_buffer(tmp_addr->proto); |
| 222 | if (!addr) |
| 223 | return -ENOMEM; |
| 224 | |
| 225 | memcpy(addr, tmp_addr, sizeof(struct qeth_ipaddr)); |
| 226 | addr->ref_counter = 1; |
| 227 | |
Julian Wiedmann | b22d73d6 | 2017-12-13 18:56:30 +0100 | [diff] [blame] | 228 | if (qeth_l3_is_addr_covered_by_ipato(card, addr)) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 229 | QETH_CARD_TEXT(card, 2, "tkovaddr"); |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 230 | addr->ipato = 1; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 231 | } |
| 232 | hash_add(card->ip_htable, &addr->hnode, |
| 233 | qeth_l3_ipaddr_hash(addr)); |
| 234 | |
Ursula Braun | a7531c1 | 2016-09-15 14:39:23 +0200 | [diff] [blame] | 235 | if (!qeth_card_hw_is_reachable(card)) { |
| 236 | addr->disp_flag = QETH_DISP_ADDR_ADD; |
| 237 | return 0; |
| 238 | } |
| 239 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 240 | /* qeth_l3_register_addr_entry can go to sleep |
| 241 | * if we add a IPV4 addr. It is caused by the reason |
| 242 | * that SETIP ipa cmd starts ARP staff for IPV4 addr. |
| 243 | * Thus we should unlock spinlock, and make a protection |
| 244 | * using in_progress variable to indicate that there is |
| 245 | * an hardware operation with this IPV4 address |
| 246 | */ |
| 247 | if (addr->proto == QETH_PROT_IPV4) { |
| 248 | addr->in_progress = 1; |
| 249 | spin_unlock_bh(&card->ip_lock); |
| 250 | rc = qeth_l3_register_addr_entry(card, addr); |
| 251 | spin_lock_bh(&card->ip_lock); |
| 252 | addr->in_progress = 0; |
| 253 | } else |
| 254 | rc = qeth_l3_register_addr_entry(card, addr); |
| 255 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 256 | if (!rc || rc == -EADDRINUSE || rc == -ENETDOWN) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 257 | addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
| 258 | if (addr->ref_counter < 1) { |
Julian Wiedmann | 14d066c | 2018-02-27 18:58:14 +0100 | [diff] [blame] | 259 | qeth_l3_deregister_addr_entry(card, addr); |
| 260 | hash_del(&addr->hnode); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 261 | kfree(addr); |
| 262 | } |
| 263 | } else { |
| 264 | hash_del(&addr->hnode); |
| 265 | kfree(addr); |
| 266 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 267 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 268 | return rc; |
| 269 | } |
| 270 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 271 | 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] | 272 | { |
| 273 | struct qeth_ipaddr *addr; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 274 | struct hlist_node *tmp; |
| 275 | int i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 276 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 277 | QETH_CARD_TEXT(card, 4, "clearip"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 278 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 279 | spin_lock_bh(&card->ip_lock); |
| 280 | |
| 281 | hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { |
| 282 | if (!recover) { |
| 283 | hash_del(&addr->hnode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 284 | kfree(addr); |
| 285 | continue; |
| 286 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 287 | addr->disp_flag = QETH_DISP_ADDR_ADD; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 288 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 289 | |
| 290 | spin_unlock_bh(&card->ip_lock); |
| 291 | |
| 292 | spin_lock_bh(&card->mclock); |
| 293 | |
| 294 | hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) { |
| 295 | hash_del(&addr->hnode); |
| 296 | kfree(addr); |
| 297 | } |
| 298 | |
| 299 | spin_unlock_bh(&card->mclock); |
| 300 | |
| 301 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 302 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 303 | static void qeth_l3_recover_ip(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 304 | { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 305 | struct qeth_ipaddr *addr; |
| 306 | struct hlist_node *tmp; |
| 307 | int i; |
| 308 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 309 | |
Ursula Braun | a7531c1 | 2016-09-15 14:39:23 +0200 | [diff] [blame] | 310 | QETH_CARD_TEXT(card, 4, "recovrip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 311 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 312 | spin_lock_bh(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 313 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 314 | hash_for_each_safe(card->ip_htable, i, tmp, addr, hnode) { |
Julian Wiedmann | 98d823a | 2018-02-27 18:58:13 +0100 | [diff] [blame] | 315 | if (addr->disp_flag == QETH_DISP_ADDR_ADD) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 316 | if (addr->proto == QETH_PROT_IPV4) { |
| 317 | addr->in_progress = 1; |
| 318 | spin_unlock_bh(&card->ip_lock); |
| 319 | rc = qeth_l3_register_addr_entry(card, addr); |
| 320 | spin_lock_bh(&card->ip_lock); |
| 321 | addr->in_progress = 0; |
| 322 | } else |
| 323 | rc = qeth_l3_register_addr_entry(card, addr); |
| 324 | |
| 325 | if (!rc) { |
| 326 | addr->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
Ursula Braun | a7531c1 | 2016-09-15 14:39:23 +0200 | [diff] [blame] | 327 | if (addr->ref_counter < 1) |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 328 | qeth_l3_delete_ip(card, addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 329 | } else { |
| 330 | hash_del(&addr->hnode); |
| 331 | kfree(addr); |
| 332 | } |
| 333 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 334 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 335 | |
| 336 | spin_unlock_bh(&card->ip_lock); |
| 337 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 338 | } |
| 339 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 340 | static int qeth_l3_setdelip_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 341 | unsigned long data) |
| 342 | { |
| 343 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 344 | |
| 345 | switch (cmd->hdr.return_code) { |
| 346 | case IPA_RC_SUCCESS: |
| 347 | return 0; |
| 348 | case IPA_RC_DUPLICATE_IP_ADDRESS: |
| 349 | return -EADDRINUSE; |
| 350 | case IPA_RC_MC_ADDR_NOT_FOUND: |
| 351 | return -ENOENT; |
| 352 | case IPA_RC_LAN_OFFLINE: |
| 353 | return -ENETDOWN; |
| 354 | default: |
| 355 | return -EIO; |
| 356 | } |
| 357 | } |
| 358 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 359 | static int qeth_l3_send_setdelmc(struct qeth_card *card, |
| 360 | struct qeth_ipaddr *addr, int ipacmd) |
| 361 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 362 | struct qeth_cmd_buffer *iob; |
| 363 | struct qeth_ipa_cmd *cmd; |
| 364 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 365 | QETH_CARD_TEXT(card, 4, "setdelmc"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 366 | |
| 367 | iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 368 | if (!iob) |
| 369 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 370 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 371 | ether_addr_copy(cmd->data.setdelipm.mac, addr->mac); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 372 | if (addr->proto == QETH_PROT_IPV6) |
| 373 | memcpy(cmd->data.setdelipm.ip6, &addr->u.a6.addr, |
| 374 | sizeof(struct in6_addr)); |
| 375 | else |
| 376 | memcpy(&cmd->data.setdelipm.ip4, &addr->u.a4.addr, 4); |
| 377 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 378 | return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | static void qeth_l3_fill_netmask(u8 *netmask, unsigned int len) |
| 382 | { |
| 383 | int i, j; |
| 384 | for (i = 0; i < 16; i++) { |
| 385 | j = (len) - (i * 8); |
| 386 | if (j >= 8) |
| 387 | netmask[i] = 0xff; |
| 388 | else if (j > 0) |
| 389 | netmask[i] = (u8)(0xFF00 >> j); |
| 390 | else |
| 391 | netmask[i] = 0; |
| 392 | } |
| 393 | } |
| 394 | |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 395 | 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] | 396 | { |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 397 | switch (addr->type) { |
| 398 | case QETH_IP_TYPE_RXIP: |
| 399 | return (set) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0; |
| 400 | case QETH_IP_TYPE_VIPA: |
| 401 | return (set) ? QETH_IPA_SETIP_VIPA_FLAG : |
| 402 | QETH_IPA_DELIP_VIPA_FLAG; |
| 403 | default: |
| 404 | return (set && addr->ipato) ? QETH_IPA_SETIP_TAKEOVER_FLAG : 0; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | static int qeth_l3_send_setdelip(struct qeth_card *card, |
| 409 | struct qeth_ipaddr *addr, |
| 410 | enum qeth_ipa_cmds ipacmd) |
| 411 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 412 | struct qeth_cmd_buffer *iob; |
| 413 | struct qeth_ipa_cmd *cmd; |
| 414 | __u8 netmask[16]; |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 415 | u32 flags; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 416 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 417 | QETH_CARD_TEXT(card, 4, "setdelip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 418 | |
| 419 | iob = qeth_get_ipacmd_buffer(card, ipacmd, addr->proto); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 420 | if (!iob) |
| 421 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 422 | cmd = __ipa_cmd(iob); |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 423 | |
| 424 | flags = qeth_l3_get_setdelip_flags(addr, ipacmd == IPA_CMD_SETIP); |
| 425 | QETH_CARD_TEXT_(card, 4, "flags%02X", flags); |
| 426 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 427 | if (addr->proto == QETH_PROT_IPV6) { |
| 428 | memcpy(cmd->data.setdelip6.ip_addr, &addr->u.a6.addr, |
| 429 | sizeof(struct in6_addr)); |
| 430 | qeth_l3_fill_netmask(netmask, addr->u.a6.pfxlen); |
| 431 | memcpy(cmd->data.setdelip6.mask, netmask, |
| 432 | sizeof(struct in6_addr)); |
| 433 | cmd->data.setdelip6.flags = flags; |
| 434 | } else { |
| 435 | memcpy(cmd->data.setdelip4.ip_addr, &addr->u.a4.addr, 4); |
| 436 | memcpy(cmd->data.setdelip4.mask, &addr->u.a4.mask, 4); |
| 437 | cmd->data.setdelip4.flags = flags; |
| 438 | } |
| 439 | |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 440 | return qeth_send_ipa_cmd(card, iob, qeth_l3_setdelip_cb, NULL); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | static int qeth_l3_send_setrouting(struct qeth_card *card, |
| 444 | enum qeth_routing_types type, enum qeth_prot_versions prot) |
| 445 | { |
| 446 | int rc; |
| 447 | struct qeth_ipa_cmd *cmd; |
| 448 | struct qeth_cmd_buffer *iob; |
| 449 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 450 | QETH_CARD_TEXT(card, 4, "setroutg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 451 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETRTG, prot); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 452 | if (!iob) |
| 453 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 454 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 455 | cmd->data.setrtg.type = (type); |
| 456 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 457 | |
| 458 | return rc; |
| 459 | } |
| 460 | |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 461 | static int qeth_l3_correct_routing_type(struct qeth_card *card, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 462 | enum qeth_routing_types *type, enum qeth_prot_versions prot) |
| 463 | { |
| 464 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
| 465 | switch (*type) { |
| 466 | case NO_ROUTER: |
| 467 | case PRIMARY_CONNECTOR: |
| 468 | case SECONDARY_CONNECTOR: |
| 469 | case MULTICAST_ROUTER: |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 470 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 471 | default: |
| 472 | goto out_inval; |
| 473 | } |
| 474 | } else { |
| 475 | switch (*type) { |
| 476 | case NO_ROUTER: |
| 477 | case PRIMARY_ROUTER: |
| 478 | case SECONDARY_ROUTER: |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 479 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 480 | case MULTICAST_ROUTER: |
| 481 | if (qeth_is_ipafunc_supported(card, prot, |
| 482 | IPA_OSA_MC_ROUTER)) |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 483 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 484 | default: |
| 485 | goto out_inval; |
| 486 | } |
| 487 | } |
| 488 | out_inval: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 489 | *type = NO_ROUTER; |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 490 | return -EINVAL; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | int qeth_l3_setrouting_v4(struct qeth_card *card) |
| 494 | { |
| 495 | int rc; |
| 496 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 497 | QETH_CARD_TEXT(card, 3, "setrtg4"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 498 | |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 499 | rc = qeth_l3_correct_routing_type(card, &card->options.route4.type, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 500 | QETH_PROT_IPV4); |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 501 | if (rc) |
| 502 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 503 | |
| 504 | rc = qeth_l3_send_setrouting(card, card->options.route4.type, |
| 505 | QETH_PROT_IPV4); |
| 506 | if (rc) { |
| 507 | card->options.route4.type = NO_ROUTER; |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 508 | QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n", |
| 509 | rc, CARD_DEVID(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 510 | } |
| 511 | return rc; |
| 512 | } |
| 513 | |
| 514 | int qeth_l3_setrouting_v6(struct qeth_card *card) |
| 515 | { |
| 516 | int rc = 0; |
| 517 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 518 | QETH_CARD_TEXT(card, 3, "setrtg6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 519 | |
| 520 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 521 | return 0; |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 522 | rc = qeth_l3_correct_routing_type(card, &card->options.route6.type, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 523 | QETH_PROT_IPV6); |
Stefan Raspl | 82e2e78 | 2013-03-18 20:04:43 +0000 | [diff] [blame] | 524 | if (rc) |
| 525 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 526 | |
| 527 | rc = qeth_l3_send_setrouting(card, card->options.route6.type, |
| 528 | QETH_PROT_IPV6); |
| 529 | if (rc) { |
| 530 | card->options.route6.type = NO_ROUTER; |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 531 | QETH_DBF_MESSAGE(2, "Error (%#06x) while setting routing type on device %x. Type set to 'no router'.\n", |
| 532 | rc, CARD_DEVID(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 533 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 534 | return rc; |
| 535 | } |
| 536 | |
| 537 | /* |
| 538 | * IP address takeover related functions |
| 539 | */ |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 540 | |
| 541 | /** |
| 542 | * qeth_l3_update_ipato() - Update 'takeover' property, for all NORMAL IPs. |
| 543 | * |
| 544 | * Caller must hold ip_lock. |
| 545 | */ |
| 546 | void qeth_l3_update_ipato(struct qeth_card *card) |
| 547 | { |
| 548 | struct qeth_ipaddr *addr; |
| 549 | unsigned int i; |
| 550 | |
| 551 | hash_for_each(card->ip_htable, i, addr, hnode) { |
| 552 | if (addr->type != QETH_IP_TYPE_NORMAL) |
| 553 | continue; |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 554 | addr->ipato = qeth_l3_is_addr_covered_by_ipato(card, addr); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 555 | } |
| 556 | } |
| 557 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 558 | static void qeth_l3_clear_ipato_list(struct qeth_card *card) |
| 559 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 560 | struct qeth_ipato_entry *ipatoe, *tmp; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 561 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 562 | spin_lock_bh(&card->ip_lock); |
| 563 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 564 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { |
| 565 | list_del(&ipatoe->entry); |
| 566 | kfree(ipatoe); |
| 567 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 568 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 569 | qeth_l3_update_ipato(card); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 570 | spin_unlock_bh(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | int qeth_l3_add_ipato_entry(struct qeth_card *card, |
| 574 | struct qeth_ipato_entry *new) |
| 575 | { |
| 576 | struct qeth_ipato_entry *ipatoe; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 577 | int rc = 0; |
| 578 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 579 | QETH_CARD_TEXT(card, 2, "addipato"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 580 | |
| 581 | spin_lock_bh(&card->ip_lock); |
| 582 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 583 | list_for_each_entry(ipatoe, &card->ipato.entries, entry) { |
| 584 | if (ipatoe->proto != new->proto) |
| 585 | continue; |
| 586 | if (!memcmp(ipatoe->addr, new->addr, |
| 587 | (ipatoe->proto == QETH_PROT_IPV4)? 4:16) && |
| 588 | (ipatoe->mask_bits == new->mask_bits)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 589 | rc = -EEXIST; |
| 590 | break; |
| 591 | } |
| 592 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 593 | |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 594 | if (!rc) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 595 | list_add_tail(&new->entry, &card->ipato.entries); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 596 | qeth_l3_update_ipato(card); |
| 597 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 598 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 599 | spin_unlock_bh(&card->ip_lock); |
| 600 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 601 | return rc; |
| 602 | } |
| 603 | |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 604 | int qeth_l3_del_ipato_entry(struct qeth_card *card, |
| 605 | enum qeth_prot_versions proto, u8 *addr, |
| 606 | int mask_bits) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 607 | { |
| 608 | struct qeth_ipato_entry *ipatoe, *tmp; |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 609 | int rc = -ENOENT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 610 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 611 | QETH_CARD_TEXT(card, 2, "delipato"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 612 | |
| 613 | spin_lock_bh(&card->ip_lock); |
| 614 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 615 | list_for_each_entry_safe(ipatoe, tmp, &card->ipato.entries, entry) { |
| 616 | if (ipatoe->proto != proto) |
| 617 | continue; |
| 618 | if (!memcmp(ipatoe->addr, addr, |
| 619 | (proto == QETH_PROT_IPV4)? 4:16) && |
| 620 | (ipatoe->mask_bits == mask_bits)) { |
| 621 | list_del(&ipatoe->entry); |
Julian Wiedmann | 02f510f | 2017-12-13 18:56:32 +0100 | [diff] [blame] | 622 | qeth_l3_update_ipato(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 623 | kfree(ipatoe); |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 624 | rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 625 | } |
| 626 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 627 | |
| 628 | spin_unlock_bh(&card->ip_lock); |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 629 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 630 | } |
| 631 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 632 | int qeth_l3_modify_rxip_vipa(struct qeth_card *card, bool add, const u8 *ip, |
| 633 | enum qeth_ip_types type, |
| 634 | enum qeth_prot_versions proto) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 635 | { |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 636 | struct qeth_ipaddr addr; |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 637 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 638 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 639 | qeth_l3_init_ipaddr(&addr, type, proto); |
| 640 | if (proto == QETH_PROT_IPV4) |
| 641 | memcpy(&addr.u.a4.addr, ip, 4); |
| 642 | else |
| 643 | memcpy(&addr.u.a6.addr, ip, 16); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 644 | |
| 645 | spin_lock_bh(&card->ip_lock); |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 646 | rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 647 | spin_unlock_bh(&card->ip_lock); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 648 | return rc; |
| 649 | } |
| 650 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 651 | int qeth_l3_modify_hsuid(struct qeth_card *card, bool add) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 652 | { |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 653 | struct qeth_ipaddr addr; |
| 654 | int rc, i; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 655 | |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 656 | qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6); |
| 657 | addr.u.a6.addr.s6_addr[0] = 0xfe; |
| 658 | addr.u.a6.addr.s6_addr[1] = 0x80; |
| 659 | for (i = 0; i < 8; i++) |
| 660 | addr.u.a6.addr.s6_addr[8+i] = card->options.hsuid[i]; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 661 | |
| 662 | spin_lock_bh(&card->ip_lock); |
Julian Wiedmann | 1617dae | 2018-03-09 18:13:02 +0100 | [diff] [blame] | 663 | rc = add ? qeth_l3_add_ip(card, &addr) : qeth_l3_delete_ip(card, &addr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 664 | spin_unlock_bh(&card->ip_lock); |
Julian Wiedmann | b9ea525 | 2017-12-27 17:44:28 +0100 | [diff] [blame] | 665 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | static int qeth_l3_register_addr_entry(struct qeth_card *card, |
| 669 | struct qeth_ipaddr *addr) |
| 670 | { |
| 671 | char buf[50]; |
| 672 | int rc = 0; |
| 673 | int cnt = 3; |
| 674 | |
Julian Wiedmann | bd74a7f | 2018-11-02 19:04:09 +0100 | [diff] [blame] | 675 | if (card->options.sniffer) |
| 676 | return 0; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 677 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 678 | if (addr->proto == QETH_PROT_IPV4) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 679 | QETH_CARD_TEXT(card, 2, "setaddr4"); |
| 680 | QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 681 | } else if (addr->proto == QETH_PROT_IPV6) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 682 | QETH_CARD_TEXT(card, 2, "setaddr6"); |
| 683 | QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8); |
| 684 | QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 685 | } else { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 686 | QETH_CARD_TEXT(card, 2, "setaddr?"); |
| 687 | QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 688 | } |
| 689 | do { |
| 690 | if (addr->is_multicast) |
| 691 | rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_SETIPM); |
| 692 | else |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 693 | rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_SETIP); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 694 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 695 | QETH_CARD_TEXT(card, 2, "failed"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 696 | } while ((--cnt > 0) && rc); |
| 697 | if (rc) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 698 | QETH_CARD_TEXT(card, 2, "FAILED"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 699 | qeth_l3_ipaddr_to_string(addr->proto, (u8 *)&addr->u, buf); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 700 | dev_warn(&card->gdev->dev, |
| 701 | "Registering IP address %s failed\n", buf); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 702 | } |
| 703 | return rc; |
| 704 | } |
| 705 | |
| 706 | static int qeth_l3_deregister_addr_entry(struct qeth_card *card, |
| 707 | struct qeth_ipaddr *addr) |
| 708 | { |
| 709 | int rc = 0; |
| 710 | |
Julian Wiedmann | bd74a7f | 2018-11-02 19:04:09 +0100 | [diff] [blame] | 711 | if (card->options.sniffer) |
| 712 | return 0; |
| 713 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 714 | if (addr->proto == QETH_PROT_IPV4) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 715 | QETH_CARD_TEXT(card, 2, "deladdr4"); |
| 716 | QETH_CARD_HEX(card, 3, &addr->u.a4.addr, sizeof(int)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 717 | } else if (addr->proto == QETH_PROT_IPV6) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 718 | QETH_CARD_TEXT(card, 2, "deladdr6"); |
| 719 | QETH_CARD_HEX(card, 3, &addr->u.a6.addr, 8); |
| 720 | QETH_CARD_HEX(card, 3, ((char *)&addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 721 | } else { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 722 | QETH_CARD_TEXT(card, 2, "deladdr?"); |
| 723 | QETH_CARD_HEX(card, 3, addr, sizeof(struct qeth_ipaddr)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 724 | } |
| 725 | if (addr->is_multicast) |
| 726 | rc = qeth_l3_send_setdelmc(card, addr, IPA_CMD_DELIPM); |
| 727 | else |
Julian Wiedmann | b1d5e36 | 2018-03-09 18:13:03 +0100 | [diff] [blame] | 728 | rc = qeth_l3_send_setdelip(card, addr, IPA_CMD_DELIP); |
Frank Blaschka | c4cef07 | 2008-07-14 09:59:31 +0200 | [diff] [blame] | 729 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 730 | QETH_CARD_TEXT(card, 2, "failed"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 731 | |
| 732 | return rc; |
| 733 | } |
| 734 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 735 | static int qeth_l3_setadapter_parms(struct qeth_card *card) |
| 736 | { |
Julian Wiedmann | 699d3fe | 2017-08-15 17:02:41 +0200 | [diff] [blame] | 737 | int rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 738 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 739 | QETH_DBF_TEXT(SETUP, 2, "setadprm"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 740 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 741 | if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) { |
| 742 | rc = qeth_setadpparms_change_macaddr(card); |
| 743 | if (rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 744 | dev_warn(&card->gdev->dev, "Reading the adapter MAC" |
Heiko Carstens | 6ea2fde | 2009-01-04 17:36:32 -0800 | [diff] [blame] | 745 | " address failed\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 746 | } |
| 747 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 748 | return rc; |
| 749 | } |
| 750 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 751 | static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card) |
| 752 | { |
| 753 | int rc; |
| 754 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 755 | QETH_CARD_TEXT(card, 3, "ipaarp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 756 | |
| 757 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 758 | dev_info(&card->gdev->dev, |
| 759 | "ARP processing not supported on %s!\n", |
| 760 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 761 | return 0; |
| 762 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 763 | rc = qeth_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 764 | IPA_CMD_ASS_START, 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 765 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 766 | dev_warn(&card->gdev->dev, |
| 767 | "Starting ARP processing support for %s failed\n", |
| 768 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 769 | } |
| 770 | return rc; |
| 771 | } |
| 772 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 773 | static int qeth_l3_start_ipa_source_mac(struct qeth_card *card) |
| 774 | { |
| 775 | int rc; |
| 776 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 777 | QETH_CARD_TEXT(card, 3, "stsrcmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 778 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 779 | if (!qeth_is_supported(card, IPA_SOURCE_MAC)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 780 | dev_info(&card->gdev->dev, |
Ursula Braun | fe94e2e | 2009-01-04 17:34:52 -0800 | [diff] [blame] | 781 | "Inbound source MAC-address not supported on %s\n", |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 782 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 783 | return -EOPNOTSUPP; |
| 784 | } |
| 785 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 786 | rc = qeth_send_simple_setassparms(card, IPA_SOURCE_MAC, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 787 | IPA_CMD_ASS_START, 0); |
| 788 | if (rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 789 | dev_warn(&card->gdev->dev, |
Ursula Braun | fe94e2e | 2009-01-04 17:34:52 -0800 | [diff] [blame] | 790 | "Starting source MAC-address support for %s failed\n", |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 791 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 792 | return rc; |
| 793 | } |
| 794 | |
| 795 | static int qeth_l3_start_ipa_vlan(struct qeth_card *card) |
| 796 | { |
| 797 | int rc = 0; |
| 798 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 799 | QETH_CARD_TEXT(card, 3, "strtvlan"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 800 | |
| 801 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 802 | dev_info(&card->gdev->dev, |
| 803 | "VLAN not supported on %s\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 804 | return -EOPNOTSUPP; |
| 805 | } |
| 806 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 807 | rc = qeth_send_simple_setassparms(card, IPA_VLAN_PRIO, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 808 | IPA_CMD_ASS_START, 0); |
| 809 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 810 | dev_warn(&card->gdev->dev, |
| 811 | "Starting VLAN support for %s failed\n", |
| 812 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 813 | } else { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 814 | dev_info(&card->gdev->dev, "VLAN enabled\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 815 | } |
| 816 | return rc; |
| 817 | } |
| 818 | |
| 819 | static int qeth_l3_start_ipa_multicast(struct qeth_card *card) |
| 820 | { |
| 821 | int rc; |
| 822 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 823 | QETH_CARD_TEXT(card, 3, "stmcast"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 824 | |
| 825 | if (!qeth_is_supported(card, IPA_MULTICASTING)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 826 | dev_info(&card->gdev->dev, |
| 827 | "Multicast not supported on %s\n", |
| 828 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 829 | return -EOPNOTSUPP; |
| 830 | } |
| 831 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 832 | rc = qeth_send_simple_setassparms(card, IPA_MULTICASTING, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 833 | IPA_CMD_ASS_START, 0); |
| 834 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 835 | dev_warn(&card->gdev->dev, |
| 836 | "Starting multicast support for %s failed\n", |
| 837 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 838 | } else { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 839 | dev_info(&card->gdev->dev, "Multicast enabled\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 840 | card->dev->flags |= IFF_MULTICAST; |
| 841 | } |
| 842 | return rc; |
| 843 | } |
| 844 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 845 | static int qeth_l3_softsetup_ipv6(struct qeth_card *card) |
| 846 | { |
| 847 | int rc; |
| 848 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 849 | QETH_CARD_TEXT(card, 3, "softipv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 850 | |
Julian Wiedmann | 2327459 | 2017-06-06 14:33:44 +0200 | [diff] [blame] | 851 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 852 | goto out; |
| 853 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 854 | rc = qeth_send_simple_setassparms(card, IPA_IPV6, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 855 | IPA_CMD_ASS_START, 3); |
| 856 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 857 | dev_err(&card->gdev->dev, |
| 858 | "Activating IPv6 support for %s failed\n", |
| 859 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 860 | return rc; |
| 861 | } |
Kittipon Meesompop | a8155b0 | 2018-04-26 09:42:21 +0200 | [diff] [blame] | 862 | rc = qeth_send_simple_setassparms_v6(card, IPA_IPV6, |
| 863 | IPA_CMD_ASS_START, 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 864 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 865 | dev_err(&card->gdev->dev, |
| 866 | "Activating IPv6 support for %s failed\n", |
| 867 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 868 | return rc; |
| 869 | } |
Kittipon Meesompop | a8155b0 | 2018-04-26 09:42:21 +0200 | [diff] [blame] | 870 | rc = qeth_send_simple_setassparms_v6(card, IPA_PASSTHRU, |
| 871 | IPA_CMD_ASS_START, 0); |
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, |
| 874 | "Enabling the passthrough mode for %s failed\n", |
| 875 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 876 | return rc; |
| 877 | } |
| 878 | out: |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 879 | dev_info(&card->gdev->dev, "IPV6 enabled\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 880 | return 0; |
| 881 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 882 | |
| 883 | static int qeth_l3_start_ipa_ipv6(struct qeth_card *card) |
| 884 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 885 | QETH_CARD_TEXT(card, 3, "strtipv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 886 | |
| 887 | if (!qeth_is_supported(card, IPA_IPV6)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 888 | dev_info(&card->gdev->dev, |
| 889 | "IPv6 not supported on %s\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 890 | return 0; |
| 891 | } |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 892 | return qeth_l3_softsetup_ipv6(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | static int qeth_l3_start_ipa_broadcast(struct qeth_card *card) |
| 896 | { |
| 897 | int rc; |
| 898 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 899 | QETH_CARD_TEXT(card, 3, "stbrdcst"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 900 | card->info.broadcast_capable = 0; |
| 901 | if (!qeth_is_supported(card, IPA_FILTERING)) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 902 | dev_info(&card->gdev->dev, |
| 903 | "Broadcast not supported on %s\n", |
| 904 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 905 | rc = -EOPNOTSUPP; |
| 906 | goto out; |
| 907 | } |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 908 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 909 | IPA_CMD_ASS_START, 0); |
| 910 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 911 | dev_warn(&card->gdev->dev, "Enabling broadcast filtering for " |
| 912 | "%s failed\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 913 | goto out; |
| 914 | } |
| 915 | |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 916 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 917 | IPA_CMD_ASS_CONFIGURE, 1); |
| 918 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 919 | dev_warn(&card->gdev->dev, |
| 920 | "Setting up broadcast filtering for %s failed\n", |
| 921 | QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 922 | goto out; |
| 923 | } |
| 924 | card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO; |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 925 | dev_info(&card->gdev->dev, "Broadcast enabled\n"); |
Thomas Richter | 4d7def2 | 2015-09-18 16:06:51 +0200 | [diff] [blame] | 926 | rc = qeth_send_simple_setassparms(card, IPA_FILTERING, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 927 | IPA_CMD_ASS_ENABLE, 1); |
| 928 | if (rc) { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 929 | dev_warn(&card->gdev->dev, "Setting up broadcast echo " |
| 930 | "filtering for %s failed\n", QETH_CARD_IFNAME(card)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 931 | goto out; |
| 932 | } |
| 933 | card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO; |
| 934 | out: |
| 935 | if (card->info.broadcast_capable) |
| 936 | card->dev->flags |= IFF_BROADCAST; |
| 937 | else |
| 938 | card->dev->flags &= ~IFF_BROADCAST; |
| 939 | return rc; |
| 940 | } |
| 941 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 942 | static int qeth_l3_start_ipassists(struct qeth_card *card) |
| 943 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 944 | QETH_CARD_TEXT(card, 3, "strtipas"); |
Einar Lueck | d64ecc2 | 2009-11-12 00:11:41 +0000 | [diff] [blame] | 945 | |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 946 | if (qeth_set_access_ctrl_online(card, 0)) |
| 947 | return -EIO; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 948 | qeth_l3_start_ipa_arp_processing(card); /* go on*/ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 949 | qeth_l3_start_ipa_source_mac(card); /* go on*/ |
| 950 | qeth_l3_start_ipa_vlan(card); /* go on*/ |
| 951 | qeth_l3_start_ipa_multicast(card); /* go on*/ |
| 952 | qeth_l3_start_ipa_ipv6(card); /* go on*/ |
| 953 | qeth_l3_start_ipa_broadcast(card); /* go on*/ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 954 | return 0; |
| 955 | } |
| 956 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 957 | static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card, |
| 958 | struct qeth_reply *reply, unsigned long data) |
| 959 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 960 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 961 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 962 | if (cmd->hdr.return_code) |
| 963 | return -EIO; |
| 964 | |
| 965 | ether_addr_copy(card->dev->dev_addr, |
| 966 | cmd->data.create_destroy_addr.unique_id); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 967 | return 0; |
| 968 | } |
| 969 | |
| 970 | static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card) |
| 971 | { |
| 972 | int rc = 0; |
| 973 | struct qeth_cmd_buffer *iob; |
| 974 | struct qeth_ipa_cmd *cmd; |
| 975 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 976 | QETH_DBF_TEXT(SETUP, 2, "hsrmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 977 | |
| 978 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, |
| 979 | QETH_PROT_IPV6); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 980 | if (!iob) |
| 981 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 982 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 983 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 984 | card->info.unique_id; |
| 985 | |
| 986 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb, |
| 987 | NULL); |
| 988 | return rc; |
| 989 | } |
| 990 | |
| 991 | static int qeth_l3_get_unique_id_cb(struct qeth_card *card, |
| 992 | struct qeth_reply *reply, unsigned long data) |
| 993 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 994 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 995 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 996 | if (cmd->hdr.return_code == 0) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 997 | card->info.unique_id = *((__u16 *) |
| 998 | &cmd->data.create_destroy_addr.unique_id[6]); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 999 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1000 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1001 | |
| 1002 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 1003 | UNIQUE_ID_NOT_BY_CARD; |
| 1004 | dev_warn(&card->gdev->dev, "The network adapter failed to generate a unique ID\n"); |
| 1005 | return -EIO; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | static int qeth_l3_get_unique_id(struct qeth_card *card) |
| 1009 | { |
| 1010 | int rc = 0; |
| 1011 | struct qeth_cmd_buffer *iob; |
| 1012 | struct qeth_ipa_cmd *cmd; |
| 1013 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1014 | QETH_DBF_TEXT(SETUP, 2, "guniqeid"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1015 | |
| 1016 | if (!qeth_is_supported(card, IPA_IPV6)) { |
| 1017 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 1018 | UNIQUE_ID_NOT_BY_CARD; |
| 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, |
| 1023 | QETH_PROT_IPV6); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1024 | if (!iob) |
| 1025 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1026 | cmd = __ipa_cmd(iob); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1027 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 1028 | card->info.unique_id; |
| 1029 | |
| 1030 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL); |
| 1031 | return rc; |
| 1032 | } |
| 1033 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1034 | static int |
| 1035 | qeth_diags_trace_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 1036 | unsigned long data) |
| 1037 | { |
| 1038 | struct qeth_ipa_cmd *cmd; |
| 1039 | __u16 rc; |
| 1040 | |
| 1041 | QETH_DBF_TEXT(SETUP, 2, "diastrcb"); |
| 1042 | |
| 1043 | cmd = (struct qeth_ipa_cmd *)data; |
| 1044 | rc = cmd->hdr.return_code; |
Ursula Braun | a959189 | 2010-03-08 20:36:55 +0000 | [diff] [blame] | 1045 | if (rc) |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1046 | QETH_CARD_TEXT_(card, 2, "dxter%x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1047 | switch (cmd->data.diagass.action) { |
| 1048 | case QETH_DIAGS_CMD_TRACE_QUERY: |
| 1049 | break; |
| 1050 | case QETH_DIAGS_CMD_TRACE_DISABLE: |
Ursula Braun | a959189 | 2010-03-08 20:36:55 +0000 | [diff] [blame] | 1051 | switch (rc) { |
| 1052 | case 0: |
| 1053 | case IPA_RC_INVALID_SUBCMD: |
| 1054 | card->info.promisc_mode = SET_PROMISC_MODE_OFF; |
| 1055 | dev_info(&card->gdev->dev, "The HiperSockets network " |
| 1056 | "traffic analyzer is deactivated\n"); |
| 1057 | break; |
| 1058 | default: |
| 1059 | break; |
| 1060 | } |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1061 | break; |
| 1062 | case QETH_DIAGS_CMD_TRACE_ENABLE: |
Ursula Braun | a959189 | 2010-03-08 20:36:55 +0000 | [diff] [blame] | 1063 | switch (rc) { |
| 1064 | case 0: |
| 1065 | card->info.promisc_mode = SET_PROMISC_MODE_ON; |
| 1066 | dev_info(&card->gdev->dev, "The HiperSockets network " |
| 1067 | "traffic analyzer is activated\n"); |
| 1068 | break; |
| 1069 | case IPA_RC_HARDWARE_AUTH_ERROR: |
| 1070 | dev_warn(&card->gdev->dev, "The device is not " |
| 1071 | "authorized to run as a HiperSockets network " |
| 1072 | "traffic analyzer\n"); |
| 1073 | break; |
| 1074 | case IPA_RC_TRACE_ALREADY_ACTIVE: |
| 1075 | dev_warn(&card->gdev->dev, "A HiperSockets " |
| 1076 | "network traffic analyzer is already " |
| 1077 | "active in the HiperSockets LAN\n"); |
| 1078 | break; |
| 1079 | default: |
| 1080 | break; |
| 1081 | } |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1082 | break; |
| 1083 | default: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1084 | QETH_DBF_MESSAGE(2, "Unknown sniffer action (%#06x) on device %x\n", |
| 1085 | cmd->data.diagass.action, CARD_DEVID(card)); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1086 | } |
| 1087 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1088 | return rc ? -EIO : 0; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | static int |
| 1092 | qeth_diags_trace(struct qeth_card *card, enum qeth_diags_trace_cmds diags_cmd) |
| 1093 | { |
| 1094 | struct qeth_cmd_buffer *iob; |
| 1095 | struct qeth_ipa_cmd *cmd; |
| 1096 | |
| 1097 | QETH_DBF_TEXT(SETUP, 2, "diagtrac"); |
| 1098 | |
| 1099 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SET_DIAG_ASS, 0); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1100 | if (!iob) |
| 1101 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1102 | cmd = __ipa_cmd(iob); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1103 | cmd->data.diagass.subcmd_len = 16; |
| 1104 | cmd->data.diagass.subcmd = QETH_DIAGS_CMD_TRACE; |
| 1105 | cmd->data.diagass.type = QETH_DIAGS_TYPE_HIPERSOCKET; |
| 1106 | cmd->data.diagass.action = diags_cmd; |
| 1107 | return qeth_send_ipa_cmd(card, iob, qeth_diags_trace_cb, NULL); |
| 1108 | } |
| 1109 | |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1110 | static void |
| 1111 | qeth_l3_add_mc_to_hash(struct qeth_card *card, struct in_device *in4_dev) |
| 1112 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1113 | struct ip_mc_list *im4; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1114 | struct qeth_ipaddr *tmp, *ipm; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1115 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1116 | QETH_CARD_TEXT(card, 4, "addmc"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1117 | |
| 1118 | tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1119 | if (!tmp) |
| 1120 | return; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1121 | |
Sachin Sant | f3aa313 | 2010-11-26 02:41:17 +0000 | [diff] [blame] | 1122 | for (im4 = rcu_dereference(in4_dev->mc_list); im4 != NULL; |
| 1123 | im4 = rcu_dereference(im4->next_rcu)) { |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1124 | ip_eth_mc_map(im4->multiaddr, tmp->mac); |
Hans Wippel | 6bee4e2 | 2017-04-07 09:15:36 +0200 | [diff] [blame] | 1125 | tmp->u.a4.addr = be32_to_cpu(im4->multiaddr); |
Julian Wiedmann | bc3ab705 | 2017-12-01 10:14:49 +0100 | [diff] [blame] | 1126 | tmp->is_multicast = 1; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1127 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 1128 | ipm = qeth_l3_find_addr_by_ip(card, tmp); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1129 | if (ipm) { |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 1130 | /* for mcast, by-IP match means full match */ |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1131 | ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
| 1132 | } else { |
| 1133 | ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); |
| 1134 | if (!ipm) |
| 1135 | continue; |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 1136 | ether_addr_copy(ipm->mac, tmp->mac); |
Hans Wippel | 6bee4e2 | 2017-04-07 09:15:36 +0200 | [diff] [blame] | 1137 | ipm->u.a4.addr = be32_to_cpu(im4->multiaddr); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1138 | ipm->is_multicast = 1; |
| 1139 | ipm->disp_flag = QETH_DISP_ADDR_ADD; |
| 1140 | hash_add(card->ip_mc_htable, |
| 1141 | &ipm->hnode, qeth_l3_ipaddr_hash(ipm)); |
| 1142 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1143 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1144 | |
| 1145 | kfree(tmp); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1146 | } |
| 1147 | |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1148 | /* called with rcu_read_lock */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1149 | static void qeth_l3_add_vlan_mc(struct qeth_card *card) |
| 1150 | { |
| 1151 | struct in_device *in_dev; |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1152 | u16 vid; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1153 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1154 | QETH_CARD_TEXT(card, 4, "addmcvl"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1155 | |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1156 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1157 | return; |
| 1158 | |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1159 | for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) { |
| 1160 | struct net_device *netdev; |
| 1161 | |
dingtianhong | f06c7f9f | 2014-05-09 14:58:05 +0800 | [diff] [blame] | 1162 | netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), |
Patrick McHardy | 91b1c1a | 2013-04-21 00:09:34 +0000 | [diff] [blame] | 1163 | vid); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1164 | if (netdev == NULL || |
| 1165 | !(netdev->flags & IFF_UP)) |
| 1166 | continue; |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1167 | in_dev = __in_dev_get_rcu(netdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1168 | if (!in_dev) |
| 1169 | continue; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1170 | qeth_l3_add_mc_to_hash(card, in_dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1171 | } |
| 1172 | } |
| 1173 | |
| 1174 | static void qeth_l3_add_multicast_ipv4(struct qeth_card *card) |
| 1175 | { |
| 1176 | struct in_device *in4_dev; |
| 1177 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1178 | QETH_CARD_TEXT(card, 4, "chkmcv4"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1179 | |
Sachin Sant | f3aa313 | 2010-11-26 02:41:17 +0000 | [diff] [blame] | 1180 | rcu_read_lock(); |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1181 | in4_dev = __in_dev_get_rcu(card->dev); |
| 1182 | if (in4_dev == NULL) |
| 1183 | goto unlock; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1184 | qeth_l3_add_mc_to_hash(card, in4_dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1185 | qeth_l3_add_vlan_mc(card); |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1186 | unlock: |
Sachin Sant | f3aa313 | 2010-11-26 02:41:17 +0000 | [diff] [blame] | 1187 | rcu_read_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1188 | } |
| 1189 | |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 1190 | static void qeth_l3_add_mc6_to_hash(struct qeth_card *card, |
| 1191 | struct inet6_dev *in6_dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1192 | { |
| 1193 | struct qeth_ipaddr *ipm; |
| 1194 | struct ifmcaddr6 *im6; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1195 | struct qeth_ipaddr *tmp; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1196 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1197 | QETH_CARD_TEXT(card, 4, "addmc6"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1198 | |
| 1199 | tmp = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1200 | if (!tmp) |
| 1201 | return; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1202 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1203 | for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) { |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1204 | ipv6_eth_mc_map(&im6->mca_addr, tmp->mac); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1205 | memcpy(&tmp->u.a6.addr, &im6->mca_addr.s6_addr, |
| 1206 | sizeof(struct in6_addr)); |
| 1207 | tmp->is_multicast = 1; |
| 1208 | |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 1209 | ipm = qeth_l3_find_addr_by_ip(card, tmp); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1210 | if (ipm) { |
Julian Wiedmann | c5c48c5 | 2018-02-27 18:58:16 +0100 | [diff] [blame] | 1211 | /* for mcast, by-IP match means full match */ |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1212 | ipm->disp_flag = QETH_DISP_ADDR_DO_NOTHING; |
| 1213 | continue; |
| 1214 | } |
| 1215 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1216 | ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); |
| 1217 | if (!ipm) |
| 1218 | continue; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1219 | |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 1220 | ether_addr_copy(ipm->mac, tmp->mac); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1221 | memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr, |
| 1222 | sizeof(struct in6_addr)); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1223 | ipm->is_multicast = 1; |
| 1224 | ipm->disp_flag = QETH_DISP_ADDR_ADD; |
| 1225 | hash_add(card->ip_mc_htable, |
| 1226 | &ipm->hnode, qeth_l3_ipaddr_hash(ipm)); |
| 1227 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1228 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1229 | kfree(tmp); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1230 | } |
| 1231 | |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1232 | /* called with rcu_read_lock */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1233 | static void qeth_l3_add_vlan_mc6(struct qeth_card *card) |
| 1234 | { |
| 1235 | struct inet6_dev *in_dev; |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1236 | u16 vid; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1237 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1238 | QETH_CARD_TEXT(card, 4, "admc6vl"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1239 | |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1240 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1241 | return; |
| 1242 | |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1243 | for_each_set_bit(vid, card->active_vlans, VLAN_N_VID) { |
| 1244 | struct net_device *netdev; |
| 1245 | |
dingtianhong | f06c7f9f | 2014-05-09 14:58:05 +0800 | [diff] [blame] | 1246 | netdev = __vlan_find_dev_deep_rcu(card->dev, htons(ETH_P_8021Q), |
Patrick McHardy | 91b1c1a | 2013-04-21 00:09:34 +0000 | [diff] [blame] | 1247 | vid); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1248 | if (netdev == NULL || |
| 1249 | !(netdev->flags & IFF_UP)) |
| 1250 | continue; |
| 1251 | in_dev = in6_dev_get(netdev); |
| 1252 | if (!in_dev) |
| 1253 | continue; |
| 1254 | read_lock_bh(&in_dev->lock); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1255 | qeth_l3_add_mc6_to_hash(card, in_dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1256 | read_unlock_bh(&in_dev->lock); |
| 1257 | in6_dev_put(in_dev); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | static void qeth_l3_add_multicast_ipv6(struct qeth_card *card) |
| 1262 | { |
| 1263 | struct inet6_dev *in6_dev; |
| 1264 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1265 | QETH_CARD_TEXT(card, 4, "chkmcv6"); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1266 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1267 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 1268 | return ; |
| 1269 | in6_dev = in6_dev_get(card->dev); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1270 | if (!in6_dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1271 | return; |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1272 | |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1273 | rcu_read_lock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1274 | read_lock_bh(&in6_dev->lock); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1275 | qeth_l3_add_mc6_to_hash(card, in6_dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1276 | qeth_l3_add_vlan_mc6(card); |
| 1277 | read_unlock_bh(&in6_dev->lock); |
Jiri Pirko | 0347af5 | 2013-01-03 22:48:58 +0000 | [diff] [blame] | 1278 | rcu_read_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1279 | in6_dev_put(in6_dev); |
| 1280 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1281 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1282 | static int qeth_l3_vlan_rx_add_vid(struct net_device *dev, |
| 1283 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1284 | { |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1285 | struct qeth_card *card = dev->ml_priv; |
| 1286 | |
| 1287 | set_bit(vid, card->active_vlans); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1288 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1289 | } |
| 1290 | |
Patrick McHardy | 80d5c36 | 2013-04-19 02:04:28 +0000 | [diff] [blame] | 1291 | static int qeth_l3_vlan_rx_kill_vid(struct net_device *dev, |
| 1292 | __be16 proto, u16 vid) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1293 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1294 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1295 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1296 | QETH_CARD_TEXT_(card, 4, "kid:%d", vid); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1297 | |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 1298 | clear_bit(vid, card->active_vlans); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1299 | qeth_l3_set_rx_mode(dev); |
Jiri Pirko | 8e58613 | 2011-12-08 19:52:37 -0500 | [diff] [blame] | 1300 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1301 | } |
| 1302 | |
Julian Wiedmann | d7aa9d0 | 2017-09-18 21:18:21 +0200 | [diff] [blame] | 1303 | static void qeth_l3_rebuild_skb(struct qeth_card *card, struct sk_buff *skb, |
| 1304 | struct qeth_hdr *hdr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1305 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1306 | if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) { |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1307 | u16 prot = (hdr->hdr.l3.flags & QETH_HDR_IPV6) ? ETH_P_IPV6 : |
| 1308 | ETH_P_IP; |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 1309 | unsigned char tg_addr[ETH_ALEN]; |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1310 | |
| 1311 | skb_reset_network_header(skb); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1312 | switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) { |
| 1313 | case QETH_CAST_MULTICAST: |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 1314 | if (prot == ETH_P_IP) |
Julian Wiedmann | 8d9183d | 2017-12-20 20:10:57 +0100 | [diff] [blame] | 1315 | ip_eth_mc_map(ip_hdr(skb)->daddr, tg_addr); |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 1316 | else |
| 1317 | ipv6_eth_mc_map(&ipv6_hdr(skb)->daddr, tg_addr); |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1318 | QETH_CARD_STAT_INC(card, rx_multicast); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1319 | break; |
| 1320 | case QETH_CAST_BROADCAST: |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 1321 | ether_addr_copy(tg_addr, card->dev->broadcast); |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1322 | QETH_CARD_STAT_INC(card, rx_multicast); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1323 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1324 | default: |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1325 | if (card->options.sniffer) |
| 1326 | skb->pkt_type = PACKET_OTHERHOST; |
Julian Wiedmann | 99f0b85 | 2017-12-20 20:11:01 +0100 | [diff] [blame] | 1327 | ether_addr_copy(tg_addr, card->dev->dev_addr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1328 | } |
Julian Wiedmann | 04f6739 | 2018-03-09 18:12:58 +0100 | [diff] [blame] | 1329 | |
Ursula Braun | fe94e2e | 2009-01-04 17:34:52 -0800 | [diff] [blame] | 1330 | if (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_SRC_MAC_ADDR) |
| 1331 | card->dev->header_ops->create(skb, card->dev, prot, |
Julian Wiedmann | a843383 | 2017-12-20 20:11:06 +0100 | [diff] [blame] | 1332 | tg_addr, &hdr->hdr.l3.next_hop.rx.src_mac, |
Julian Wiedmann | f0ea8bf | 2018-03-09 18:12:56 +0100 | [diff] [blame] | 1333 | skb->len); |
Ursula Braun | fe94e2e | 2009-01-04 17:34:52 -0800 | [diff] [blame] | 1334 | else |
| 1335 | card->dev->header_ops->create(skb, card->dev, prot, |
Julian Wiedmann | f0ea8bf | 2018-03-09 18:12:56 +0100 | [diff] [blame] | 1336 | tg_addr, "FAKELL", skb->len); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1337 | } |
| 1338 | |
Paul Gortmaker | 1abd229 | 2012-05-10 15:50:52 -0400 | [diff] [blame] | 1339 | skb->protocol = eth_type_trans(skb, card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1340 | |
Julian Wiedmann | d7aa9d0 | 2017-09-18 21:18:21 +0200 | [diff] [blame] | 1341 | /* copy VLAN tag from hdr into skb */ |
| 1342 | if (!card->options.sniffer && |
| 1343 | (hdr->hdr.l3.ext_flags & (QETH_HDR_EXT_VLAN_FRAME | |
| 1344 | QETH_HDR_EXT_INCLUDE_VLAN_TAG))) { |
| 1345 | u16 tag = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME) ? |
| 1346 | hdr->hdr.l3.vlan_id : |
Julian Wiedmann | a843383 | 2017-12-20 20:11:06 +0100 | [diff] [blame] | 1347 | hdr->hdr.l3.next_hop.rx.vlan_id; |
Julian Wiedmann | d7aa9d0 | 2017-09-18 21:18:21 +0200 | [diff] [blame] | 1348 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), tag); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1349 | } |
| 1350 | |
Julian Wiedmann | 6195b93 | 2018-04-26 09:42:17 +0200 | [diff] [blame] | 1351 | qeth_rx_csum(card, skb, hdr->hdr.l3.ext_flags); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1352 | } |
| 1353 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1354 | static int qeth_l3_process_inbound_buffer(struct qeth_card *card, |
| 1355 | int budget, int *done) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1356 | { |
Julian Wiedmann | cd11d11 | 2018-09-26 18:29:06 +0200 | [diff] [blame] | 1357 | struct net_device *dev = card->dev; |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1358 | int work_done = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1359 | struct sk_buff *skb; |
| 1360 | struct qeth_hdr *hdr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1361 | unsigned int len; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1362 | __u16 magic; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1363 | |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1364 | *done = 0; |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 1365 | WARN_ON_ONCE(!budget); |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1366 | while (budget) { |
| 1367 | skb = qeth_core_get_next_skb(card, |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1368 | &card->qdio.in_q->bufs[card->rx.b_index], |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1369 | &card->rx.b_element, &card->rx.e_offset, &hdr); |
| 1370 | if (!skb) { |
| 1371 | *done = 1; |
| 1372 | break; |
| 1373 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1374 | switch (hdr->hdr.l3.id) { |
| 1375 | case QETH_HEADER_TYPE_LAYER3: |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1376 | magic = *(__u16 *)skb->data; |
| 1377 | if ((card->info.type == QETH_CARD_TYPE_IQD) && |
| 1378 | (magic == ETH_P_AF_IUCV)) { |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1379 | len = skb->len; |
Julian Wiedmann | cd11d11 | 2018-09-26 18:29:06 +0200 | [diff] [blame] | 1380 | dev_hard_header(skb, dev, ETH_P_AF_IUCV, |
| 1381 | dev->dev_addr, "FAKELL", len); |
| 1382 | skb->protocol = eth_type_trans(skb, dev); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1383 | netif_receive_skb(skb); |
| 1384 | } else { |
Julian Wiedmann | d7aa9d0 | 2017-09-18 21:18:21 +0200 | [diff] [blame] | 1385 | qeth_l3_rebuild_skb(card, skb, hdr); |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1386 | len = skb->len; |
Frank Blaschka | b333293 | 2011-08-08 01:33:59 +0000 | [diff] [blame] | 1387 | napi_gro_receive(&card->napi, skb); |
| 1388 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1389 | break; |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1390 | case QETH_HEADER_TYPE_LAYER2: /* for HiperSockets sniffer */ |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1391 | skb->protocol = eth_type_trans(skb, skb->dev); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1392 | len = skb->len; |
| 1393 | netif_receive_skb(skb); |
| 1394 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1395 | default: |
| 1396 | dev_kfree_skb_any(skb); |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1397 | QETH_CARD_TEXT(card, 3, "inbunkno"); |
Julian Wiedmann | 0ac1487 | 2018-09-12 15:31:35 +0200 | [diff] [blame] | 1398 | QETH_DBF_HEX(CTRL, 3, hdr, sizeof(*hdr)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1399 | continue; |
| 1400 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1401 | work_done++; |
| 1402 | budget--; |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1403 | QETH_CARD_STAT_INC(card, rx_packets); |
| 1404 | QETH_CARD_STAT_ADD(card, rx_bytes, len); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1405 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 1406 | return work_done; |
| 1407 | } |
| 1408 | |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 1409 | static void qeth_l3_stop_card(struct qeth_card *card) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1410 | { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1411 | QETH_DBF_TEXT(SETUP, 2, "stopcard"); |
| 1412 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1413 | |
| 1414 | qeth_set_allowed_threads(card, 0, 1); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1415 | if (card->options.sniffer && |
| 1416 | (card->info.promisc_mode == SET_PROMISC_MODE_ON)) |
| 1417 | qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1418 | if (card->read.state == CH_STATE_UP && |
| 1419 | card->write.state == CH_STATE_UP && |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 1420 | card->state == CARD_STATE_UP) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1421 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1422 | if (card->state == CARD_STATE_SOFTSETUP) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1423 | qeth_l3_clear_ip_htable(card, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1424 | qeth_clear_ipacmd_list(card); |
| 1425 | card->state = CARD_STATE_HARDSETUP; |
| 1426 | } |
| 1427 | if (card->state == CARD_STATE_HARDSETUP) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1428 | qeth_qdio_clear_card(card, 0); |
| 1429 | qeth_clear_qdio_buffers(card); |
| 1430 | qeth_clear_working_pool_list(card); |
| 1431 | card->state = CARD_STATE_DOWN; |
| 1432 | } |
| 1433 | if (card->state == CARD_STATE_DOWN) { |
| 1434 | qeth_clear_cmd_buffers(&card->read); |
| 1435 | qeth_clear_cmd_buffers(&card->write); |
| 1436 | } |
Julian Wiedmann | c0a2e4d | 2019-02-04 17:40:09 +0100 | [diff] [blame] | 1437 | |
| 1438 | flush_workqueue(card->event_wq); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1439 | } |
| 1440 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1441 | /* |
| 1442 | * test for and Switch promiscuous mode (on or off) |
| 1443 | * either for guestlan or HiperSocket Sniffer |
| 1444 | */ |
| 1445 | static void |
| 1446 | qeth_l3_handle_promisc_mode(struct qeth_card *card) |
| 1447 | { |
| 1448 | struct net_device *dev = card->dev; |
| 1449 | |
| 1450 | if (((dev->flags & IFF_PROMISC) && |
| 1451 | (card->info.promisc_mode == SET_PROMISC_MODE_ON)) || |
| 1452 | (!(dev->flags & IFF_PROMISC) && |
| 1453 | (card->info.promisc_mode == SET_PROMISC_MODE_OFF))) |
| 1454 | return; |
| 1455 | |
| 1456 | if (card->info.guestlan) { /* Guestlan trace */ |
| 1457 | if (qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 1458 | qeth_setadp_promisc_mode(card); |
| 1459 | } else if (card->options.sniffer && /* HiperSockets trace */ |
| 1460 | qeth_adp_supported(card, IPA_SETADP_SET_DIAG_ASSIST)) { |
| 1461 | if (dev->flags & IFF_PROMISC) { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1462 | QETH_CARD_TEXT(card, 3, "+promisc"); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1463 | qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_ENABLE); |
| 1464 | } else { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1465 | QETH_CARD_TEXT(card, 3, "-promisc"); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1466 | qeth_diags_trace(card, QETH_DIAGS_CMD_TRACE_DISABLE); |
| 1467 | } |
| 1468 | } |
| 1469 | } |
| 1470 | |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1471 | static void qeth_l3_set_rx_mode(struct net_device *dev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1472 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1473 | struct qeth_card *card = dev->ml_priv; |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1474 | struct qeth_ipaddr *addr; |
| 1475 | struct hlist_node *tmp; |
| 1476 | int i, rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1477 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1478 | QETH_CARD_TEXT(card, 3, "setmulti"); |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 1479 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1480 | if (!card->options.sniffer) { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1481 | spin_lock_bh(&card->mclock); |
| 1482 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1483 | qeth_l3_add_multicast_ipv4(card); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1484 | qeth_l3_add_multicast_ipv6(card); |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1485 | |
| 1486 | hash_for_each_safe(card->ip_mc_htable, i, tmp, addr, hnode) { |
| 1487 | switch (addr->disp_flag) { |
| 1488 | case QETH_DISP_ADDR_DELETE: |
| 1489 | rc = qeth_l3_deregister_addr_entry(card, addr); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1490 | if (!rc || rc == -ENOENT) { |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1491 | hash_del(&addr->hnode); |
| 1492 | kfree(addr); |
| 1493 | } |
| 1494 | break; |
| 1495 | case QETH_DISP_ADDR_ADD: |
| 1496 | rc = qeth_l3_register_addr_entry(card, addr); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1497 | if (rc && rc != -ENETDOWN) { |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 1498 | hash_del(&addr->hnode); |
| 1499 | kfree(addr); |
| 1500 | break; |
| 1501 | } |
| 1502 | addr->ref_counter = 1; |
| 1503 | /* fall through */ |
| 1504 | default: |
| 1505 | /* for next call to set_rx_mode(): */ |
| 1506 | addr->disp_flag = QETH_DISP_ADDR_DELETE; |
| 1507 | } |
| 1508 | } |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 1509 | |
| 1510 | spin_unlock_bh(&card->mclock); |
| 1511 | |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 1512 | if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 1513 | return; |
| 1514 | } |
| 1515 | qeth_l3_handle_promisc_mode(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1516 | } |
| 1517 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1518 | static int qeth_l3_arp_makerc(u16 rc) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1519 | { |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1520 | switch (rc) { |
| 1521 | case IPA_RC_SUCCESS: |
| 1522 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1523 | case QETH_IPA_ARP_RC_NOTSUPP: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1524 | case QETH_IPA_ARP_RC_Q_NOTSUPP: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1525 | return -EOPNOTSUPP; |
| 1526 | case QETH_IPA_ARP_RC_OUT_OF_RANGE: |
| 1527 | return -EINVAL; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1528 | case QETH_IPA_ARP_RC_Q_NO_DATA: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1529 | return -ENOENT; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1530 | default: |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1531 | return -EIO; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1532 | } |
| 1533 | } |
| 1534 | |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1535 | static int qeth_l3_arp_cmd_cb(struct qeth_card *card, struct qeth_reply *reply, |
| 1536 | unsigned long data) |
| 1537 | { |
| 1538 | struct qeth_ipa_cmd *cmd = (struct qeth_ipa_cmd *) data; |
| 1539 | |
| 1540 | qeth_setassparms_cb(card, reply, data); |
| 1541 | return qeth_l3_arp_makerc(cmd->hdr.return_code); |
| 1542 | } |
| 1543 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1544 | static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries) |
| 1545 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1546 | struct qeth_cmd_buffer *iob; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1547 | int rc; |
| 1548 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1549 | QETH_CARD_TEXT(card, 3, "arpstnoe"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1550 | |
| 1551 | /* |
| 1552 | * currently GuestLAN only supports the ARP assist function |
| 1553 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES; |
| 1554 | * thus we say EOPNOTSUPP for this ARP function |
| 1555 | */ |
| 1556 | if (card->info.guestlan) |
| 1557 | return -EOPNOTSUPP; |
| 1558 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1559 | return -EOPNOTSUPP; |
| 1560 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1561 | |
| 1562 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 1563 | IPA_CMD_ASS_ARP_SET_NO_ENTRIES, 4, |
| 1564 | QETH_PROT_IPV4); |
| 1565 | if (!iob) |
| 1566 | return -ENOMEM; |
| 1567 | |
| 1568 | __ipa_cmd(iob)->data.setassparms.data.flags_32bit = (u32) no_entries; |
| 1569 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL); |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1570 | if (rc) |
| 1571 | QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on device %x: %#x\n", |
| 1572 | CARD_DEVID(card), rc); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1573 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1574 | } |
| 1575 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1576 | static __u32 get_arp_entry_size(struct qeth_card *card, |
| 1577 | struct qeth_arp_query_data *qdata, |
| 1578 | struct qeth_arp_entrytype *type, __u8 strip_entries) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1579 | { |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1580 | __u32 rc; |
| 1581 | __u8 is_hsi; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1582 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1583 | is_hsi = qdata->reply_bits == 5; |
| 1584 | if (type->ip == QETHARP_IP_ADDR_V4) { |
| 1585 | QETH_CARD_TEXT(card, 4, "arpev4"); |
| 1586 | if (strip_entries) { |
| 1587 | rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5_short) : |
| 1588 | sizeof(struct qeth_arp_qi_entry7_short); |
| 1589 | } else { |
| 1590 | rc = is_hsi ? sizeof(struct qeth_arp_qi_entry5) : |
| 1591 | sizeof(struct qeth_arp_qi_entry7); |
| 1592 | } |
| 1593 | } else if (type->ip == QETHARP_IP_ADDR_V6) { |
| 1594 | QETH_CARD_TEXT(card, 4, "arpev6"); |
| 1595 | if (strip_entries) { |
| 1596 | rc = is_hsi ? |
| 1597 | sizeof(struct qeth_arp_qi_entry5_short_ipv6) : |
| 1598 | sizeof(struct qeth_arp_qi_entry7_short_ipv6); |
| 1599 | } else { |
| 1600 | rc = is_hsi ? |
| 1601 | sizeof(struct qeth_arp_qi_entry5_ipv6) : |
| 1602 | sizeof(struct qeth_arp_qi_entry7_ipv6); |
| 1603 | } |
| 1604 | } else { |
| 1605 | QETH_CARD_TEXT(card, 4, "arpinv"); |
| 1606 | rc = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1607 | } |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1608 | |
| 1609 | return rc; |
| 1610 | } |
| 1611 | |
| 1612 | static int arpentry_matches_prot(struct qeth_arp_entrytype *type, __u16 prot) |
| 1613 | { |
| 1614 | return (type->ip == QETHARP_IP_ADDR_V4 && prot == QETH_PROT_IPV4) || |
| 1615 | (type->ip == QETHARP_IP_ADDR_V6 && prot == QETH_PROT_IPV6); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | static int qeth_l3_arp_query_cb(struct qeth_card *card, |
| 1619 | struct qeth_reply *reply, unsigned long data) |
| 1620 | { |
| 1621 | struct qeth_ipa_cmd *cmd; |
| 1622 | struct qeth_arp_query_data *qdata; |
| 1623 | struct qeth_arp_query_info *qinfo; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1624 | int e; |
| 1625 | int entrybytes_done; |
| 1626 | int stripped_bytes; |
| 1627 | __u8 do_strip_entries; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1628 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1629 | QETH_CARD_TEXT(card, 3, "arpquecb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1630 | |
| 1631 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 1632 | cmd = (struct qeth_ipa_cmd *) data; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1633 | QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.prot_version); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1634 | if (cmd->hdr.return_code) { |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1635 | QETH_CARD_TEXT(card, 4, "arpcberr"); |
| 1636 | QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1637 | return qeth_l3_arp_makerc(cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1638 | } |
| 1639 | if (cmd->data.setassparms.hdr.return_code) { |
| 1640 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1641 | QETH_CARD_TEXT(card, 4, "setaperr"); |
| 1642 | QETH_CARD_TEXT_(card, 4, "%i", cmd->hdr.return_code); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1643 | return qeth_l3_arp_makerc(cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1644 | } |
| 1645 | qdata = &cmd->data.setassparms.data.query_arp; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1646 | QETH_CARD_TEXT_(card, 4, "anoen%i", qdata->no_entries); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1647 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1648 | do_strip_entries = (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) > 0; |
| 1649 | stripped_bytes = do_strip_entries ? QETH_QARP_MEDIASPECIFIC_BYTES : 0; |
| 1650 | entrybytes_done = 0; |
| 1651 | for (e = 0; e < qdata->no_entries; ++e) { |
| 1652 | char *cur_entry; |
| 1653 | __u32 esize; |
| 1654 | struct qeth_arp_entrytype *etype; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1655 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1656 | cur_entry = &qdata->data + entrybytes_done; |
| 1657 | etype = &((struct qeth_arp_qi_entry5 *) cur_entry)->type; |
| 1658 | if (!arpentry_matches_prot(etype, cmd->hdr.prot_version)) { |
| 1659 | QETH_CARD_TEXT(card, 4, "pmis"); |
| 1660 | QETH_CARD_TEXT_(card, 4, "%i", etype->ip); |
| 1661 | break; |
| 1662 | } |
| 1663 | esize = get_arp_entry_size(card, qdata, etype, |
| 1664 | do_strip_entries); |
| 1665 | QETH_CARD_TEXT_(card, 5, "esz%i", esize); |
| 1666 | if (!esize) |
| 1667 | break; |
| 1668 | |
| 1669 | if ((qinfo->udata_len - qinfo->udata_offset) < esize) { |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1670 | QETH_CARD_TEXT_(card, 4, "qaer3%i", -ENOSPC); |
| 1671 | memset(qinfo->udata, 0, 4); |
| 1672 | return -ENOSPC; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1673 | } |
| 1674 | |
| 1675 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 1676 | &qdata->data + entrybytes_done + stripped_bytes, |
| 1677 | esize); |
| 1678 | entrybytes_done += esize + stripped_bytes; |
| 1679 | qinfo->udata_offset += esize; |
| 1680 | ++qinfo->no_entries; |
| 1681 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1682 | /* check if all replies received ... */ |
| 1683 | if (cmd->data.setassparms.hdr.seq_no < |
| 1684 | cmd->data.setassparms.hdr.number_of_replies) |
| 1685 | return 1; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1686 | QETH_CARD_TEXT_(card, 4, "nove%i", qinfo->no_entries); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1687 | memcpy(qinfo->udata, &qinfo->no_entries, 4); |
| 1688 | /* keep STRIP_ENTRIES flag so the user program can distinguish |
| 1689 | * stripped entries from normal ones */ |
| 1690 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 1691 | qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES; |
| 1692 | memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1693 | QETH_CARD_TEXT_(card, 4, "rc%i", 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1694 | return 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1695 | } |
| 1696 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1697 | static int qeth_l3_query_arp_cache_info(struct qeth_card *card, |
| 1698 | enum qeth_prot_versions prot, |
| 1699 | struct qeth_arp_query_info *qinfo) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1700 | { |
| 1701 | struct qeth_cmd_buffer *iob; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1702 | struct qeth_ipa_cmd *cmd; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1703 | int rc; |
| 1704 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1705 | QETH_CARD_TEXT_(card, 3, "qarpipv%i", prot); |
| 1706 | |
Thomas Richter | b475e31 | 2015-12-11 12:27:54 +0100 | [diff] [blame] | 1707 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 1708 | IPA_CMD_ASS_ARP_QUERY_INFO, |
| 1709 | sizeof(struct qeth_arp_query_data) |
| 1710 | - sizeof(char), |
| 1711 | prot); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1712 | if (!iob) |
| 1713 | return -ENOMEM; |
Julian Wiedmann | ff5caa7 | 2018-03-09 18:12:52 +0100 | [diff] [blame] | 1714 | cmd = __ipa_cmd(iob); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1715 | cmd->data.setassparms.data.query_arp.request_bits = 0x000F; |
Julian Wiedmann | 84dbea4 | 2019-02-12 18:33:16 +0100 | [diff] [blame] | 1716 | 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] | 1717 | if (rc) |
| 1718 | QETH_DBF_MESSAGE(2, "Error while querying ARP cache on device %x: %#x\n", |
| 1719 | CARD_DEVID(card), rc); |
Julian Wiedmann | 4b7ae12 | 2019-02-12 18:33:23 +0100 | [diff] [blame] | 1720 | return rc; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1721 | } |
| 1722 | |
| 1723 | static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata) |
| 1724 | { |
| 1725 | struct qeth_arp_query_info qinfo = {0, }; |
| 1726 | int rc; |
| 1727 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1728 | QETH_CARD_TEXT(card, 3, "arpquery"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1729 | |
| 1730 | if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/ |
| 1731 | IPA_ARP_PROCESSING)) { |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1732 | QETH_CARD_TEXT(card, 3, "arpqnsup"); |
| 1733 | rc = -EOPNOTSUPP; |
| 1734 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1735 | } |
| 1736 | /* get size of userspace buffer and mask_bits -> 6 bytes */ |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1737 | if (copy_from_user(&qinfo, udata, 6)) { |
| 1738 | rc = -EFAULT; |
| 1739 | goto out; |
| 1740 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1741 | qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1742 | if (!qinfo.udata) { |
| 1743 | rc = -ENOMEM; |
| 1744 | goto out; |
| 1745 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1746 | qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1747 | rc = qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV4, &qinfo); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1748 | if (rc) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1749 | if (copy_to_user(udata, qinfo.udata, 4)) |
| 1750 | rc = -EFAULT; |
Sebastian Ott | 77a83ed | 2016-06-16 16:19:03 +0200 | [diff] [blame] | 1751 | goto free_and_out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1752 | } |
Sebastian Ott | 77a83ed | 2016-06-16 16:19:03 +0200 | [diff] [blame] | 1753 | if (qinfo.mask_bits & QETH_QARP_WITH_IPV6) { |
| 1754 | /* fails in case of GuestLAN QDIO mode */ |
| 1755 | qeth_l3_query_arp_cache_info(card, QETH_PROT_IPV6, &qinfo); |
| 1756 | } |
Sebastian Ott | 77a83ed | 2016-06-16 16:19:03 +0200 | [diff] [blame] | 1757 | if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) { |
| 1758 | QETH_CARD_TEXT(card, 4, "qactf"); |
| 1759 | rc = -EFAULT; |
| 1760 | goto free_and_out; |
| 1761 | } |
| 1762 | QETH_CARD_TEXT(card, 4, "qacts"); |
| 1763 | |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1764 | free_and_out: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1765 | kfree(qinfo.udata); |
Einar Lueck | d0ddf30f | 2010-12-08 02:57:58 +0000 | [diff] [blame] | 1766 | out: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1767 | return rc; |
| 1768 | } |
| 1769 | |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1770 | static int qeth_l3_arp_modify_entry(struct qeth_card *card, |
| 1771 | struct qeth_arp_cache_entry *entry, |
| 1772 | enum qeth_arp_process_subcmds arp_cmd) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1773 | { |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1774 | struct qeth_arp_cache_entry *cmd_entry; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1775 | struct qeth_cmd_buffer *iob; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1776 | int rc; |
| 1777 | |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1778 | if (arp_cmd == IPA_CMD_ASS_ARP_ADD_ENTRY) |
| 1779 | QETH_CARD_TEXT(card, 3, "arpadd"); |
| 1780 | else |
| 1781 | QETH_CARD_TEXT(card, 3, "arpdel"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1782 | |
| 1783 | /* |
| 1784 | * currently GuestLAN only supports the ARP assist function |
| 1785 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY; |
| 1786 | * thus we say EOPNOTSUPP for this ARP function |
| 1787 | */ |
| 1788 | if (card->info.guestlan) |
| 1789 | return -EOPNOTSUPP; |
| 1790 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1791 | return -EOPNOTSUPP; |
| 1792 | } |
| 1793 | |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1794 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, arp_cmd, |
| 1795 | sizeof(*cmd_entry), QETH_PROT_IPV4); |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 1796 | if (!iob) |
| 1797 | return -ENOMEM; |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1798 | |
| 1799 | cmd_entry = &__ipa_cmd(iob)->data.setassparms.data.arp_entry; |
| 1800 | ether_addr_copy(cmd_entry->macaddr, entry->macaddr); |
| 1801 | memcpy(cmd_entry->ipaddr, entry->ipaddr, 4); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1802 | 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] | 1803 | if (rc) |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1804 | QETH_DBF_MESSAGE(2, "Could not modify (cmd: %#x) ARP entry on device %x: %#x\n", |
| 1805 | arp_cmd, CARD_DEVID(card), rc); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1806 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1807 | } |
| 1808 | |
| 1809 | static int qeth_l3_arp_flush_cache(struct qeth_card *card) |
| 1810 | { |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1811 | struct qeth_cmd_buffer *iob; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1812 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1813 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 1814 | QETH_CARD_TEXT(card, 3, "arpflush"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1815 | |
| 1816 | /* |
| 1817 | * currently GuestLAN only supports the ARP assist function |
| 1818 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE; |
| 1819 | * thus we say EOPNOTSUPP for this ARP function |
| 1820 | */ |
| 1821 | if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD)) |
| 1822 | return -EOPNOTSUPP; |
| 1823 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1824 | return -EOPNOTSUPP; |
| 1825 | } |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1826 | |
| 1827 | iob = qeth_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 1828 | IPA_CMD_ASS_ARP_FLUSH_CACHE, 0, |
| 1829 | QETH_PROT_IPV4); |
| 1830 | if (!iob) |
| 1831 | return -ENOMEM; |
| 1832 | |
| 1833 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_arp_cmd_cb, NULL); |
Julian Wiedmann | e19e5be | 2018-11-02 19:04:08 +0100 | [diff] [blame] | 1834 | if (rc) |
| 1835 | QETH_DBF_MESSAGE(2, "Could not flush ARP cache on device %x: %#x\n", |
| 1836 | CARD_DEVID(card), rc); |
Julian Wiedmann | 742d4d4 | 2019-02-12 18:33:25 +0100 | [diff] [blame] | 1837 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 1841 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1842 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1843 | struct qeth_arp_cache_entry arp_entry; |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1844 | enum qeth_arp_process_subcmds arp_cmd; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1845 | int rc = 0; |
| 1846 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1847 | switch (cmd) { |
| 1848 | case SIOC_QETH_ARP_SET_NO_ENTRIES: |
| 1849 | if (!capable(CAP_NET_ADMIN)) { |
| 1850 | rc = -EPERM; |
| 1851 | break; |
| 1852 | } |
| 1853 | rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue); |
| 1854 | break; |
| 1855 | case SIOC_QETH_ARP_QUERY_INFO: |
| 1856 | if (!capable(CAP_NET_ADMIN)) { |
| 1857 | rc = -EPERM; |
| 1858 | break; |
| 1859 | } |
| 1860 | rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data); |
| 1861 | break; |
| 1862 | case SIOC_QETH_ARP_ADD_ENTRY: |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1863 | case SIOC_QETH_ARP_REMOVE_ENTRY: |
Julian Wiedmann | 125d7d3 | 2018-11-02 19:04:12 +0100 | [diff] [blame] | 1864 | if (!capable(CAP_NET_ADMIN)) |
| 1865 | return -EPERM; |
| 1866 | if (copy_from_user(&arp_entry, rq->ifr_data, sizeof(arp_entry))) |
| 1867 | return -EFAULT; |
| 1868 | |
| 1869 | arp_cmd = (cmd == SIOC_QETH_ARP_ADD_ENTRY) ? |
| 1870 | IPA_CMD_ASS_ARP_ADD_ENTRY : |
| 1871 | IPA_CMD_ASS_ARP_REMOVE_ENTRY; |
| 1872 | return qeth_l3_arp_modify_entry(card, &arp_entry, arp_cmd); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1873 | case SIOC_QETH_ARP_FLUSH_CACHE: |
| 1874 | if (!capable(CAP_NET_ADMIN)) { |
| 1875 | rc = -EPERM; |
| 1876 | break; |
| 1877 | } |
| 1878 | rc = qeth_l3_arp_flush_cache(card); |
| 1879 | break; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1880 | default: |
| 1881 | rc = -EOPNOTSUPP; |
| 1882 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1883 | return rc; |
| 1884 | } |
| 1885 | |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1886 | static int qeth_l3_get_cast_type(struct sk_buff *skb) |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1887 | { |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1888 | struct neighbour *n = NULL; |
| 1889 | struct dst_entry *dst; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1890 | |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1891 | rcu_read_lock(); |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1892 | dst = skb_dst(skb); |
| 1893 | if (dst) |
David S. Miller | 24db1ba | 2012-07-02 22:02:33 -0700 | [diff] [blame] | 1894 | n = dst_neigh_lookup_skb(dst, skb); |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1895 | if (n) { |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1896 | int cast_type = n->type; |
| 1897 | |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1898 | rcu_read_unlock(); |
David S. Miller | 24db1ba | 2012-07-02 22:02:33 -0700 | [diff] [blame] | 1899 | neigh_release(n); |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1900 | if ((cast_type == RTN_BROADCAST) || |
| 1901 | (cast_type == RTN_MULTICAST) || |
| 1902 | (cast_type == RTN_ANYCAST)) |
| 1903 | return cast_type; |
Julian Wiedmann | 86c0cdb | 2018-07-11 17:42:41 +0200 | [diff] [blame] | 1904 | return RTN_UNICAST; |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1905 | } |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1906 | rcu_read_unlock(); |
| 1907 | |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1908 | /* no neighbour (eg AF_PACKET), fall back to target's IP address ... */ |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1909 | switch (qeth_get_ip_version(skb)) { |
| 1910 | case 4: |
Julian Wiedmann | 1f97912 | 2017-12-20 20:11:04 +0100 | [diff] [blame] | 1911 | return ipv4_is_multicast(ip_hdr(skb)->daddr) ? |
Julian Wiedmann | 86c0cdb | 2018-07-11 17:42:41 +0200 | [diff] [blame] | 1912 | RTN_MULTICAST : RTN_UNICAST; |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1913 | case 6: |
| 1914 | return ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr) ? |
| 1915 | RTN_MULTICAST : RTN_UNICAST; |
| 1916 | default: |
| 1917 | /* ... and MAC address */ |
| 1918 | if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, |
| 1919 | skb->dev->broadcast)) |
| 1920 | return RTN_BROADCAST; |
| 1921 | if (is_multicast_ether_addr(eth_hdr(skb)->h_dest)) |
| 1922 | return RTN_MULTICAST; |
| 1923 | /* default to unicast */ |
| 1924 | return RTN_UNICAST; |
| 1925 | } |
Klaus-Dieter Wacker | ce73e10 | 2009-08-26 02:01:08 +0000 | [diff] [blame] | 1926 | } |
| 1927 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1928 | static u8 qeth_l3_cast_type_to_flag(int cast_type) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1929 | { |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1930 | if (cast_type == RTN_MULTICAST) |
| 1931 | return QETH_CAST_MULTICAST; |
| 1932 | if (cast_type == RTN_ANYCAST) |
| 1933 | return QETH_CAST_ANYCAST; |
| 1934 | if (cast_type == RTN_BROADCAST) |
| 1935 | return QETH_CAST_BROADCAST; |
| 1936 | return QETH_CAST_UNICAST; |
| 1937 | } |
David S. Miller | 69cce1d | 2011-07-17 23:09:49 -0700 | [diff] [blame] | 1938 | |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1939 | static void qeth_l3_fill_header(struct qeth_qdio_out_q *queue, |
| 1940 | struct qeth_hdr *hdr, struct sk_buff *skb, |
| 1941 | int ipv, int cast_type, unsigned int data_len) |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1942 | { |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 1943 | struct qeth_hdr_layer3 *l3_hdr = &hdr->hdr.l3; |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1944 | struct vlan_ethhdr *veth = vlan_eth_hdr(skb); |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1945 | struct qeth_card *card = queue->card; |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1946 | |
Julian Wiedmann | f6c1314 | 2017-12-20 20:11:08 +0100 | [diff] [blame] | 1947 | hdr->hdr.l3.length = data_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1948 | |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1949 | if (skb_is_gso(skb)) { |
Julian Wiedmann | 0aef839 | 2018-10-12 17:27:15 +0200 | [diff] [blame] | 1950 | hdr->hdr.l3.id = QETH_HEADER_TYPE_L3_TSO; |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1951 | } else { |
| 1952 | hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 1953 | |
| 1954 | if (skb->protocol == htons(ETH_P_AF_IUCV)) { |
| 1955 | l3_hdr->flags = QETH_HDR_IPV6 | QETH_CAST_UNICAST; |
| 1956 | l3_hdr->next_hop.ipv6_addr.s6_addr16[0] = htons(0xfe80); |
| 1957 | memcpy(&l3_hdr->next_hop.ipv6_addr.s6_addr32[2], |
| 1958 | iucv_trans_hdr(skb)->destUserID, 8); |
| 1959 | return; |
| 1960 | } |
| 1961 | |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1962 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 1963 | qeth_tx_csum(skb, &hdr->hdr.l3.ext_flags, ipv); |
| 1964 | /* some HW requires combined L3+L4 csum offload: */ |
| 1965 | if (ipv == 4) |
| 1966 | hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_CSUM_HDR_REQ; |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 1967 | QETH_TXQ_STAT_INC(queue, skbs_csum); |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 1968 | } |
| 1969 | } |
| 1970 | |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 1971 | if (ipv == 4 || IS_IQD(card)) { |
| 1972 | /* NETIF_F_HW_VLAN_CTAG_TX */ |
| 1973 | if (skb_vlan_tag_present(skb)) { |
| 1974 | hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_VLAN_FRAME; |
| 1975 | hdr->hdr.l3.vlan_id = skb_vlan_tag_get(skb); |
| 1976 | } |
| 1977 | } else if (veth->h_vlan_proto == htons(ETH_P_8021Q)) { |
| 1978 | hdr->hdr.l3.ext_flags |= QETH_HDR_EXT_INCLUDE_VLAN_TAG; |
| 1979 | hdr->hdr.l3.vlan_id = ntohs(veth->h_vlan_TCI); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1980 | } |
| 1981 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1982 | /* OSA only: */ |
| 1983 | if (!ipv) { |
| 1984 | hdr->hdr.l3.flags = QETH_HDR_PASSTHRU; |
| 1985 | if (ether_addr_equal_64bits(eth_hdr(skb)->h_dest, |
| 1986 | skb->dev->broadcast)) |
| 1987 | hdr->hdr.l3.flags |= QETH_CAST_BROADCAST; |
| 1988 | else |
| 1989 | hdr->hdr.l3.flags |= (cast_type == RTN_MULTICAST) ? |
| 1990 | QETH_CAST_MULTICAST : QETH_CAST_UNICAST; |
| 1991 | return; |
| 1992 | } |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1993 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1994 | hdr->hdr.l3.flags = qeth_l3_cast_type_to_flag(cast_type); |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 1995 | rcu_read_lock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1996 | if (ipv == 4) { |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1997 | struct rtable *rt = skb_rtable(skb); |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 1998 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 1999 | *((__be32 *) &hdr->hdr.l3.next_hop.ipv4.addr) = (rt) ? |
| 2000 | rt_nexthop(rt, ip_hdr(skb)->daddr) : |
| 2001 | ip_hdr(skb)->daddr; |
| 2002 | } else { |
| 2003 | /* IPv6 */ |
| 2004 | const struct rt6_info *rt = skb_rt6_info(skb); |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 2005 | |
Julian Wiedmann | ec2c672 | 2017-08-07 13:28:39 +0200 | [diff] [blame] | 2006 | if (rt && !ipv6_addr_any(&rt->rt6i_gateway)) |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 2007 | l3_hdr->next_hop.ipv6_addr = rt->rt6i_gateway; |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 2008 | else |
Julian Wiedmann | 5a541f6 | 2018-11-08 15:06:16 +0100 | [diff] [blame] | 2009 | l3_hdr->next_hop.ipv6_addr = ipv6_hdr(skb)->daddr; |
David Miller | 87e7597 | 2012-02-01 10:49:17 +0000 | [diff] [blame] | 2010 | |
Julian Wiedmann | 910a0a8 | 2017-12-20 20:11:07 +0100 | [diff] [blame] | 2011 | hdr->hdr.l3.flags |= QETH_HDR_IPV6; |
| 2012 | if (card->info.type != QETH_CARD_TYPE_IQD) |
| 2013 | hdr->hdr.l3.flags |= QETH_HDR_PASSTHRU; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2014 | } |
Frank Blaschka | 1d36cb4 | 2011-11-15 02:31:15 +0000 | [diff] [blame] | 2015 | rcu_read_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2016 | } |
| 2017 | |
Julian Wiedmann | 2d3986d | 2018-09-17 17:36:00 +0200 | [diff] [blame] | 2018 | static void qeth_l3_fixup_headers(struct sk_buff *skb) |
| 2019 | { |
| 2020 | struct iphdr *iph = ip_hdr(skb); |
| 2021 | |
| 2022 | /* this is safe, IPv6 traffic takes a different path */ |
| 2023 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 2024 | iph->check = 0; |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 2025 | if (skb_is_gso(skb)) { |
| 2026 | iph->tot_len = 0; |
| 2027 | tcp_hdr(skb)->check = ~tcp_v4_check(0, iph->saddr, |
| 2028 | iph->daddr, 0); |
| 2029 | } |
Julian Wiedmann | 2d3986d | 2018-09-17 17:36:00 +0200 | [diff] [blame] | 2030 | } |
| 2031 | |
Julian Wiedmann | 356156b | 2018-09-17 17:36:03 +0200 | [diff] [blame] | 2032 | static int qeth_l3_xmit(struct qeth_card *card, struct sk_buff *skb, |
| 2033 | struct qeth_qdio_out_q *queue, int ipv, int cast_type) |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2034 | { |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2035 | unsigned char eth_hdr[ETH_HLEN]; |
Julian Wiedmann | 81ec543 | 2018-11-08 15:06:17 +0100 | [diff] [blame] | 2036 | unsigned int hw_hdr_len; |
| 2037 | int rc; |
Julian Wiedmann | e517b64 | 2018-09-17 17:36:02 +0200 | [diff] [blame] | 2038 | |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2039 | /* re-use the L2 header area for the HW header: */ |
Julian Wiedmann | 81ec543 | 2018-11-08 15:06:17 +0100 | [diff] [blame] | 2040 | hw_hdr_len = skb_is_gso(skb) ? sizeof(struct qeth_hdr_tso) : |
| 2041 | sizeof(struct qeth_hdr); |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2042 | rc = skb_cow_head(skb, hw_hdr_len - ETH_HLEN); |
| 2043 | if (rc) |
| 2044 | return rc; |
| 2045 | skb_copy_from_linear_data(skb, eth_hdr, ETH_HLEN); |
| 2046 | skb_pull(skb, ETH_HLEN); |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2047 | |
Julian Wiedmann | 2d3986d | 2018-09-17 17:36:00 +0200 | [diff] [blame] | 2048 | qeth_l3_fixup_headers(skb); |
Julian Wiedmann | 81ec543 | 2018-11-08 15:06:17 +0100 | [diff] [blame] | 2049 | rc = qeth_xmit(card, skb, queue, ipv, cast_type, qeth_l3_fill_header); |
| 2050 | if (rc == -EBUSY) { |
| 2051 | /* roll back to ETH header */ |
| 2052 | skb_push(skb, ETH_HLEN); |
| 2053 | skb_copy_to_linear_data(skb, eth_hdr, ETH_HLEN); |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2054 | } |
| 2055 | return rc; |
| 2056 | } |
| 2057 | |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 2058 | static netdev_tx_t qeth_l3_hard_start_xmit(struct sk_buff *skb, |
| 2059 | struct net_device *dev) |
| 2060 | { |
| 2061 | int cast_type = qeth_l3_get_cast_type(skb); |
| 2062 | struct qeth_card *card = dev->ml_priv; |
| 2063 | int ipv = qeth_get_ip_version(skb); |
| 2064 | struct qeth_qdio_out_q *queue; |
| 2065 | int tx_bytes = skb->len; |
| 2066 | int rc; |
| 2067 | |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 2068 | queue = qeth_get_tx_queue(card, skb, ipv, cast_type); |
| 2069 | |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 2070 | if (IS_IQD(card)) { |
| 2071 | if (card->options.sniffer) |
| 2072 | goto tx_drop; |
| 2073 | if ((card->options.cq != QETH_CQ_ENABLED && !ipv) || |
| 2074 | (card->options.cq == QETH_CQ_ENABLED && |
| 2075 | skb->protocol != htons(ETH_P_AF_IUCV))) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2076 | goto tx_drop; |
| 2077 | } |
| 2078 | |
Julian Wiedmann | 91cc98f | 2018-09-26 18:29:16 +0200 | [diff] [blame] | 2079 | if (card->state != CARD_STATE_UP) { |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 2080 | QETH_TXQ_STAT_INC(queue, tx_carrier_errors); |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 2081 | goto tx_drop; |
| 2082 | } |
| 2083 | |
| 2084 | if (cast_type == RTN_BROADCAST && !card->info.broadcast_capable) |
| 2085 | goto tx_drop; |
| 2086 | |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 2087 | netif_stop_queue(dev); |
| 2088 | |
Julian Wiedmann | 356156b | 2018-09-17 17:36:03 +0200 | [diff] [blame] | 2089 | if (ipv == 4 || IS_IQD(card)) |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2090 | rc = qeth_l3_xmit(card, skb, queue, ipv, cast_type); |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 2091 | else |
| 2092 | rc = qeth_xmit(card, skb, queue, ipv, cast_type, |
| 2093 | qeth_l3_fill_header); |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 2094 | |
| 2095 | if (!rc) { |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 2096 | QETH_TXQ_STAT_INC(queue, tx_packets); |
| 2097 | QETH_TXQ_STAT_ADD(queue, tx_bytes, tx_bytes); |
Julian Wiedmann | ea1d4a0 | 2018-07-11 17:42:45 +0200 | [diff] [blame] | 2098 | netif_wake_queue(dev); |
| 2099 | return NETDEV_TX_OK; |
| 2100 | } else if (rc == -EBUSY) { |
| 2101 | return NETDEV_TX_BUSY; |
| 2102 | } /* else fall through */ |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2103 | |
| 2104 | tx_drop: |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 2105 | QETH_TXQ_STAT_INC(queue, tx_dropped); |
| 2106 | QETH_TXQ_STAT_INC(queue, tx_errors); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2107 | dev_kfree_skb_any(skb); |
Frank Blaschka | d0ec0f5 | 2008-06-06 12:37:48 +0200 | [diff] [blame] | 2108 | netif_wake_queue(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2109 | return NETDEV_TX_OK; |
| 2110 | } |
| 2111 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2112 | /* |
| 2113 | * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting |
| 2114 | * NOARP on the netdevice is no option because it also turns off neighbor |
| 2115 | * solicitation. For IPv4 we install a neighbor_setup function. We don't want |
| 2116 | * arp resolution but we want the hard header (packet socket will work |
| 2117 | * e.g. tcpdump) |
| 2118 | */ |
| 2119 | static int qeth_l3_neigh_setup_noarp(struct neighbour *n) |
| 2120 | { |
| 2121 | n->nud_state = NUD_NOARP; |
| 2122 | memcpy(n->ha, "FAKELL", 6); |
| 2123 | n->output = n->ops->connected_output; |
| 2124 | return 0; |
| 2125 | } |
| 2126 | |
| 2127 | static int |
| 2128 | qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np) |
| 2129 | { |
| 2130 | if (np->tbl->family == AF_INET) |
| 2131 | np->neigh_setup = qeth_l3_neigh_setup_noarp; |
| 2132 | |
| 2133 | return 0; |
| 2134 | } |
| 2135 | |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 2136 | static netdev_features_t qeth_l3_osa_features_check(struct sk_buff *skb, |
| 2137 | struct net_device *dev, |
| 2138 | netdev_features_t features) |
| 2139 | { |
| 2140 | if (qeth_get_ip_version(skb) != 4) |
| 2141 | features &= ~NETIF_F_HW_VLAN_CTAG_TX; |
| 2142 | return qeth_features_check(skb, dev, features); |
| 2143 | } |
| 2144 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2145 | static const struct net_device_ops qeth_l3_netdev_ops = { |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 2146 | .ndo_open = qeth_open, |
| 2147 | .ndo_stop = qeth_stop, |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 2148 | .ndo_get_stats64 = qeth_get_stats64, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 2149 | .ndo_start_xmit = qeth_l3_hard_start_xmit, |
| 2150 | .ndo_validate_addr = eth_validate_addr, |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 2151 | .ndo_set_rx_mode = qeth_l3_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 2152 | .ndo_do_ioctl = qeth_do_ioctl, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 2153 | .ndo_fix_features = qeth_fix_features, |
| 2154 | .ndo_set_features = qeth_set_features, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 2155 | .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid, |
| 2156 | .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid, |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 2157 | .ndo_tx_timeout = qeth_tx_timeout, |
Frank Blaschka | 8403b13 | 2009-01-08 10:50:55 -0800 | [diff] [blame] | 2158 | }; |
| 2159 | |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2160 | static const struct net_device_ops qeth_l3_osa_netdev_ops = { |
Julian Wiedmann | e22355e | 2019-01-25 15:44:18 +0100 | [diff] [blame] | 2161 | .ndo_open = qeth_open, |
| 2162 | .ndo_stop = qeth_stop, |
Julian Wiedmann | b0abc4f | 2019-02-15 19:22:29 +0100 | [diff] [blame] | 2163 | .ndo_get_stats64 = qeth_get_stats64, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2164 | .ndo_start_xmit = qeth_l3_hard_start_xmit, |
Julian Wiedmann | f13ade1 | 2018-09-17 17:35:56 +0200 | [diff] [blame] | 2165 | .ndo_features_check = qeth_l3_osa_features_check, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2166 | .ndo_validate_addr = eth_validate_addr, |
Julian Wiedmann | 00c163f | 2017-12-20 20:11:02 +0100 | [diff] [blame] | 2167 | .ndo_set_rx_mode = qeth_l3_set_rx_mode, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 2168 | .ndo_do_ioctl = qeth_do_ioctl, |
Thomas Richter | 8f43fb0 | 2016-06-16 16:18:59 +0200 | [diff] [blame] | 2169 | .ndo_fix_features = qeth_fix_features, |
| 2170 | .ndo_set_features = qeth_set_features, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2171 | .ndo_vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid, |
| 2172 | .ndo_vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid, |
Jiri Pirko | 7ff0bcf | 2011-07-20 04:54:41 +0000 | [diff] [blame] | 2173 | .ndo_tx_timeout = qeth_tx_timeout, |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2174 | .ndo_neigh_setup = qeth_l3_neigh_setup, |
| 2175 | }; |
| 2176 | |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 2177 | 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] | 2178 | { |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 2179 | unsigned int headroom; |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 2180 | int rc; |
| 2181 | |
Ursula Braun | 5113fec | 2010-05-16 21:15:14 +0000 | [diff] [blame] | 2182 | if (card->info.type == QETH_CARD_TYPE_OSD || |
| 2183 | card->info.type == QETH_CARD_TYPE_OSX) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2184 | if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) || |
| 2185 | (card->info.link_type == QETH_LINK_TYPE_HSTR)) { |
Paul Gortmaker | 1abd229 | 2012-05-10 15:50:52 -0400 | [diff] [blame] | 2186 | pr_info("qeth_l3: ignoring TR device\n"); |
| 2187 | return -ENODEV; |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 2188 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2189 | |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 2190 | card->dev->netdev_ops = &qeth_l3_osa_netdev_ops; |
Julian Wiedmann | 0f34294 | 2018-03-09 18:12:54 +0100 | [diff] [blame] | 2191 | |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 2192 | /*IPv6 address autoconfiguration stuff*/ |
| 2193 | qeth_l3_get_unique_id(card); |
| 2194 | if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD)) |
| 2195 | card->dev->dev_id = card->info.unique_id & 0xffff; |
Julian Wiedmann | 0f34294 | 2018-03-09 18:12:54 +0100 | [diff] [blame] | 2196 | |
Kittipon Meesompop | 1b81143 | 2018-04-26 09:42:16 +0200 | [diff] [blame] | 2197 | if (!card->info.guestlan) { |
| 2198 | card->dev->features |= NETIF_F_SG; |
| 2199 | card->dev->hw_features |= NETIF_F_TSO | |
| 2200 | NETIF_F_RXCSUM | NETIF_F_IP_CSUM; |
| 2201 | card->dev->vlan_features |= NETIF_F_TSO | |
| 2202 | NETIF_F_RXCSUM | NETIF_F_IP_CSUM; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2203 | } |
Kittipon Meesompop | 571f9dd8 | 2018-04-26 09:42:22 +0200 | [diff] [blame] | 2204 | |
| 2205 | if (qeth_is_supported6(card, IPA_OUTBOUND_CHECKSUM_V6)) { |
| 2206 | card->dev->hw_features |= NETIF_F_IPV6_CSUM; |
| 2207 | card->dev->vlan_features |= NETIF_F_IPV6_CSUM; |
| 2208 | } |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 2209 | if (qeth_is_supported6(card, IPA_OUTBOUND_TSO)) { |
| 2210 | card->dev->hw_features |= NETIF_F_TSO6; |
| 2211 | card->dev->vlan_features |= NETIF_F_TSO6; |
| 2212 | } |
| 2213 | |
| 2214 | /* allow for de-acceleration of NETIF_F_HW_VLAN_CTAG_TX: */ |
| 2215 | if (card->dev->hw_features & NETIF_F_TSO6) |
| 2216 | headroom = sizeof(struct qeth_hdr_tso) + VLAN_HLEN; |
| 2217 | else if (card->dev->hw_features & NETIF_F_TSO) |
| 2218 | headroom = sizeof(struct qeth_hdr_tso); |
| 2219 | else |
| 2220 | headroom = sizeof(struct qeth_hdr) + VLAN_HLEN; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2221 | } else if (card->info.type == QETH_CARD_TYPE_IQD) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2222 | card->dev->flags |= IFF_NOARP; |
Frank Blaschka | 3d58cef | 2009-01-09 03:44:00 +0000 | [diff] [blame] | 2223 | card->dev->netdev_ops = &qeth_l3_netdev_ops; |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 2224 | headroom = sizeof(struct qeth_hdr) - ETH_HLEN; |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2225 | |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 2226 | rc = qeth_l3_iqd_read_initial_mac(card); |
| 2227 | if (rc) |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 2228 | goto out; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2229 | } else |
| 2230 | return -ENODEV; |
| 2231 | |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 2232 | card->dev->needed_headroom = headroom; |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2233 | card->dev->features |= NETIF_F_HW_VLAN_CTAG_TX | |
| 2234 | NETIF_F_HW_VLAN_CTAG_RX | |
| 2235 | NETIF_F_HW_VLAN_CTAG_FILTER; |
Julian Wiedmann | a647a02 | 2018-07-11 17:42:46 +0200 | [diff] [blame] | 2236 | |
Eric Dumazet | 0287587 | 2014-10-05 18:38:35 -0700 | [diff] [blame] | 2237 | netif_keep_dst(card->dev); |
Julian Wiedmann | 82bf5c0 | 2018-10-12 17:27:14 +0200 | [diff] [blame] | 2238 | if (card->dev->hw_features & (NETIF_F_TSO | NETIF_F_TSO6)) |
Julian Wiedmann | 371a1e7 | 2018-07-11 17:42:44 +0200 | [diff] [blame] | 2239 | netif_set_gso_max_size(card->dev, |
| 2240 | PAGE_SIZE * (QETH_MAX_BUFFER_ELEMENTS(card) - 1)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2241 | |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 2242 | netif_napi_add(card->dev, &card->napi, qeth_poll, QETH_NAPI_WEIGHT); |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 2243 | rc = register_netdev(card->dev); |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 2244 | if (!rc && carrier_ok) |
| 2245 | netif_carrier_on(card->dev); |
| 2246 | |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 2247 | out: |
| 2248 | if (rc) |
| 2249 | card->dev->netdev_ops = NULL; |
| 2250 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2251 | } |
| 2252 | |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2253 | static const struct device_type qeth_l3_devtype = { |
| 2254 | .name = "qeth_layer3", |
| 2255 | .groups = qeth_l3_attr_groups, |
| 2256 | }; |
| 2257 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2258 | static int qeth_l3_probe_device(struct ccwgroup_device *gdev) |
| 2259 | { |
| 2260 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Ursula Braun | 9111e78 | 2017-05-10 19:07:51 +0200 | [diff] [blame] | 2261 | int rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2262 | |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2263 | if (gdev->dev.type == &qeth_generic_devtype) { |
| 2264 | rc = qeth_l3_create_device_attributes(&gdev->dev); |
| 2265 | if (rc) |
| 2266 | return rc; |
| 2267 | } |
Ursula Braun | ebccc739 | 2017-05-10 19:07:54 +0200 | [diff] [blame] | 2268 | hash_init(card->ip_htable); |
| 2269 | hash_init(card->ip_mc_htable); |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 2270 | card->info.hwtrap = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2271 | return 0; |
| 2272 | } |
| 2273 | |
| 2274 | static void qeth_l3_remove_device(struct ccwgroup_device *cgdev) |
| 2275 | { |
| 2276 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 2277 | |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2278 | if (cgdev->dev.type == &qeth_generic_devtype) |
| 2279 | qeth_l3_remove_device_attributes(&cgdev->dev); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2280 | |
Ursula Braun | f214856 | 2009-05-19 21:38:37 +0000 | [diff] [blame] | 2281 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2282 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 2283 | |
Ursula Braun | 70919e2 | 2011-02-26 22:41:36 -0800 | [diff] [blame] | 2284 | if (cgdev->state == CCWGROUP_ONLINE) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2285 | qeth_l3_set_offline(cgdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2286 | |
Julian Wiedmann | c2780c1 | 2019-02-04 17:40:08 +0100 | [diff] [blame] | 2287 | cancel_work_sync(&card->close_dev_work); |
Julian Wiedmann | 30356d0 | 2018-11-02 19:04:10 +0100 | [diff] [blame] | 2288 | if (qeth_netdev_is_registered(card->dev)) |
| 2289 | unregister_netdev(card->dev); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 2290 | qeth_l3_clear_ip_htable(card, 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2291 | qeth_l3_clear_ipato_list(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2292 | } |
| 2293 | |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2294 | static int qeth_l3_set_online(struct ccwgroup_device *gdev) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2295 | { |
| 2296 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2297 | struct net_device *dev = card->dev; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2298 | int rc = 0; |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 2299 | bool carrier_ok; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2300 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2301 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 2302 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2303 | QETH_DBF_TEXT(SETUP, 2, "setonlin"); |
| 2304 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2305 | |
Julian Wiedmann | 9fae5c3 | 2018-11-02 19:04:11 +0100 | [diff] [blame] | 2306 | rc = qeth_core_hardsetup_card(card, &carrier_ok); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2307 | if (rc) { |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 2308 | QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 2309 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2310 | goto out_remove; |
| 2311 | } |
| 2312 | |
Frank Blaschka | 1da74b1 | 2011-05-12 18:45:02 +0000 | [diff] [blame] | 2313 | if (qeth_is_diagass_supported(card, QETH_DIAGS_CMD_TRAP)) { |
| 2314 | if (card->info.hwtrap && |
| 2315 | qeth_hw_trap(card, QETH_DIAGS_TRAP_ARM)) |
| 2316 | card->info.hwtrap = 0; |
| 2317 | } else |
| 2318 | card->info.hwtrap = 0; |
| 2319 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2320 | card->state = CARD_STATE_HARDSETUP; |
| 2321 | qeth_print_status_message(card); |
| 2322 | |
| 2323 | /* softsetup */ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2324 | QETH_DBF_TEXT(SETUP, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2325 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2326 | rc = qeth_l3_setadapter_parms(card); |
| 2327 | if (rc) |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 2328 | QETH_DBF_TEXT_(SETUP, 2, "2err%04x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2329 | if (!card->options.sniffer) { |
| 2330 | rc = qeth_l3_start_ipassists(card); |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 2331 | if (rc) { |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2332 | QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc); |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 2333 | goto out_remove; |
| 2334 | } |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2335 | rc = qeth_l3_setrouting_v4(card); |
| 2336 | if (rc) |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 2337 | QETH_DBF_TEXT_(SETUP, 2, "4err%04x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2338 | rc = qeth_l3_setrouting_v6(card); |
| 2339 | if (rc) |
Thomas Richter | 1aec42b | 2015-01-21 13:39:10 +0100 | [diff] [blame] | 2340 | QETH_DBF_TEXT_(SETUP, 2, "5err%04x", rc); |
Ursula Braun | 76b11f8 | 2010-01-11 02:50:50 +0000 | [diff] [blame] | 2341 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2342 | |
| 2343 | rc = qeth_init_qdio_queues(card); |
| 2344 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2345 | QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 2346 | rc = -ENODEV; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2347 | goto out_remove; |
| 2348 | } |
| 2349 | card->state = CARD_STATE_SOFTSETUP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2350 | |
| 2351 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 2352 | qeth_l3_recover_ip(card); |
Julian Wiedmann | d025da9 | 2018-06-29 19:45:54 +0200 | [diff] [blame] | 2353 | |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2354 | if (!qeth_netdev_is_registered(dev)) { |
| 2355 | rc = qeth_l3_setup_netdev(card, carrier_ok); |
| 2356 | if (rc) |
| 2357 | goto out_remove; |
| 2358 | } else { |
Ursula Braun | 4763b0a | 2011-12-19 22:56:32 +0000 | [diff] [blame] | 2359 | rtnl_lock(); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2360 | if (carrier_ok) |
| 2361 | netif_carrier_on(dev); |
| 2362 | else |
| 2363 | netif_carrier_off(dev); |
| 2364 | |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 2365 | netif_device_attach(dev); |
Julian Wiedmann | fa3d2e6 | 2019-01-25 15:44:21 +0100 | [diff] [blame] | 2366 | qeth_enable_hw_features(dev); |
| 2367 | |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 2368 | if (card->info.open_when_online) { |
| 2369 | card->info.open_when_online = 0; |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2370 | dev_open(dev, NULL); |
Julian Wiedmann | 9aa17df | 2018-07-11 17:42:40 +0200 | [diff] [blame] | 2371 | } |
Ursula Braun | 4763b0a | 2011-12-19 22:56:32 +0000 | [diff] [blame] | 2372 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2373 | } |
Stefan Raspl | 82f77cf | 2013-03-18 20:04:42 +0000 | [diff] [blame] | 2374 | qeth_trace_features(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2375 | /* let user_space know that device is online */ |
| 2376 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 2377 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2378 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2379 | return 0; |
| 2380 | out_remove: |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2381 | qeth_l3_stop_card(card); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2382 | ccw_device_set_offline(CARD_DDEV(card)); |
| 2383 | ccw_device_set_offline(CARD_WDEV(card)); |
| 2384 | ccw_device_set_offline(CARD_RDEV(card)); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 2385 | qdio_free(CARD_DDEV(card)); |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 2386 | card->state = CARD_STATE_DOWN; |
| 2387 | |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 2388 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2389 | mutex_unlock(&card->discipline_mutex); |
Ursula Braun | aa90922 | 2009-11-12 00:11:43 +0000 | [diff] [blame] | 2390 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2391 | } |
| 2392 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2393 | static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev, |
| 2394 | int recovery_mode) |
| 2395 | { |
| 2396 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 2397 | int rc = 0, rc2 = 0, rc3 = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2398 | |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2399 | mutex_lock(&card->discipline_mutex); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 2400 | mutex_lock(&card->conf_mutex); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2401 | QETH_DBF_TEXT(SETUP, 3, "setoffl"); |
| 2402 | QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2403 | |
Julian Wiedmann | d7ef489f | 2019-02-28 18:59:37 +0100 | [diff] [blame] | 2404 | if ((!recovery_mode && card->info.hwtrap) || card->info.hwtrap == 2) { |
| 2405 | qeth_hw_trap(card, QETH_DIAGS_TRAP_DISARM); |
| 2406 | card->info.hwtrap = 1; |
| 2407 | } |
| 2408 | |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 2409 | rtnl_lock(); |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 2410 | card->info.open_when_online = card->dev->flags & IFF_UP; |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2411 | dev_close(card->dev); |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 2412 | netif_device_detach(card->dev); |
Julian Wiedmann | d3d1b20 | 2018-07-19 12:43:51 +0200 | [diff] [blame] | 2413 | netif_carrier_off(card->dev); |
Julian Wiedmann | e6e771b | 2019-01-25 15:44:22 +0100 | [diff] [blame] | 2414 | rtnl_unlock(); |
| 2415 | |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2416 | qeth_l3_stop_card(card); |
Julian Wiedmann | 464e86d | 2019-02-28 18:59:40 +0100 | [diff] [blame] | 2417 | if (card->options.cq == QETH_CQ_ENABLED) { |
Einar Lueck | 72861ae | 2011-12-19 22:56:36 +0000 | [diff] [blame] | 2418 | rtnl_lock(); |
| 2419 | call_netdevice_notifiers(NETDEV_REBOOT, card->dev); |
| 2420 | rtnl_unlock(); |
| 2421 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2422 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 2423 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 2424 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 2425 | if (!rc) |
| 2426 | rc = (rc2) ? rc2 : rc3; |
| 2427 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2428 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Ursula Braun | 22ae279 | 2014-02-24 13:12:06 +0100 | [diff] [blame] | 2429 | qdio_free(CARD_DDEV(card)); |
Julian Wiedmann | d7d543f | 2019-02-28 18:59:36 +0100 | [diff] [blame] | 2430 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2431 | /* let user_space know that device is offline */ |
| 2432 | kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); |
Frank Blaschka | c4949f0 | 2010-05-11 19:34:47 +0000 | [diff] [blame] | 2433 | mutex_unlock(&card->conf_mutex); |
Ursula Braun | 9dc48cc | 2010-07-22 23:15:05 +0000 | [diff] [blame] | 2434 | mutex_unlock(&card->discipline_mutex); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2435 | return 0; |
| 2436 | } |
| 2437 | |
| 2438 | static int qeth_l3_set_offline(struct ccwgroup_device *cgdev) |
| 2439 | { |
| 2440 | return __qeth_l3_set_offline(cgdev, 0); |
| 2441 | } |
| 2442 | |
| 2443 | static int qeth_l3_recover(void *ptr) |
| 2444 | { |
| 2445 | struct qeth_card *card; |
| 2446 | int rc = 0; |
| 2447 | |
| 2448 | card = (struct qeth_card *) ptr; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2449 | QETH_CARD_TEXT(card, 2, "recover1"); |
| 2450 | QETH_CARD_HEX(card, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2451 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 2452 | return 0; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2453 | QETH_CARD_TEXT(card, 2, "recover2"); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 2454 | dev_warn(&card->gdev->dev, |
| 2455 | "A recovery process has been started for the device\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2456 | __qeth_l3_set_offline(card->gdev, 1); |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2457 | rc = qeth_l3_set_online(card->gdev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2458 | if (!rc) |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 2459 | dev_info(&card->gdev->dev, |
| 2460 | "Device successfully recovered!\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 2461 | else { |
Julian Wiedmann | bf42d40 | 2019-02-28 18:59:41 +0100 | [diff] [blame] | 2462 | ccwgroup_set_offline(card->gdev); |
Stefan Raspl | 0f54761 | 2013-01-21 02:30:20 +0000 | [diff] [blame] | 2463 | dev_warn(&card->gdev->dev, "The qeth device driver " |
Stefan Raspl | 2efaf5f | 2012-10-15 19:21:18 +0000 | [diff] [blame] | 2464 | "failed to recover an error on the device\n"); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 2465 | } |
Frank Blaschka | a1c3ed4 | 2010-09-07 21:14:42 +0000 | [diff] [blame] | 2466 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 2467 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2468 | return 0; |
| 2469 | } |
| 2470 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2471 | static int qeth_l3_pm_suspend(struct ccwgroup_device *gdev) |
| 2472 | { |
| 2473 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 2474 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2475 | qeth_set_allowed_threads(card, 0, 1); |
| 2476 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 2477 | if (gdev->state == CCWGROUP_OFFLINE) |
| 2478 | return 0; |
Julian Wiedmann | 62ca98d | 2019-02-28 18:59:43 +0100 | [diff] [blame^] | 2479 | |
| 2480 | qeth_l3_set_offline(gdev); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2481 | return 0; |
| 2482 | } |
| 2483 | |
| 2484 | static int qeth_l3_pm_resume(struct ccwgroup_device *gdev) |
| 2485 | { |
| 2486 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2487 | int rc; |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2488 | |
Julian Wiedmann | d456015 | 2019-02-28 18:59:39 +0100 | [diff] [blame] | 2489 | rc = qeth_l3_set_online(gdev); |
Julian Wiedmann | 6585ac4 | 2018-09-26 18:29:12 +0200 | [diff] [blame] | 2490 | |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2491 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2492 | if (rc) |
| 2493 | dev_warn(&card->gdev->dev, "The qeth device driver " |
| 2494 | "failed to recover an error on the device\n"); |
| 2495 | return rc; |
| 2496 | } |
| 2497 | |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 2498 | /* Returns zero if the command is successfully "consumed" */ |
| 2499 | static int qeth_l3_control_event(struct qeth_card *card, |
| 2500 | struct qeth_ipa_cmd *cmd) |
| 2501 | { |
| 2502 | return 1; |
| 2503 | } |
| 2504 | |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 2505 | struct qeth_discipline qeth_l3_discipline = { |
Ursula Braun | 79a04e4 | 2017-06-06 14:33:49 +0200 | [diff] [blame] | 2506 | .devtype = &qeth_l3_devtype, |
Julian Wiedmann | d73ef32 | 2017-04-11 16:11:11 +0200 | [diff] [blame] | 2507 | .process_rx_buffer = qeth_l3_process_inbound_buffer, |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 2508 | .recover = qeth_l3_recover, |
| 2509 | .setup = qeth_l3_probe_device, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2510 | .remove = qeth_l3_remove_device, |
| 2511 | .set_online = qeth_l3_set_online, |
| 2512 | .set_offline = qeth_l3_set_offline, |
Frank Blaschka | bbcfcdc | 2009-06-16 10:30:31 +0200 | [diff] [blame] | 2513 | .freeze = qeth_l3_pm_suspend, |
| 2514 | .thaw = qeth_l3_pm_resume, |
| 2515 | .restore = qeth_l3_pm_resume, |
Julian Wiedmann | 942d698 | 2017-04-11 16:11:10 +0200 | [diff] [blame] | 2516 | .do_ioctl = qeth_l3_do_ioctl, |
Eugene Crosser | c044dc2 | 2014-01-29 09:23:48 +0100 | [diff] [blame] | 2517 | .control_event_handler = qeth_l3_control_event, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2518 | }; |
Sebastian Ott | c041f2d487 | 2012-05-15 18:02:21 +0200 | [diff] [blame] | 2519 | EXPORT_SYMBOL_GPL(qeth_l3_discipline); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2520 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2521 | static int qeth_l3_handle_ip_event(struct qeth_card *card, |
| 2522 | struct qeth_ipaddr *addr, |
| 2523 | unsigned long event) |
| 2524 | { |
| 2525 | switch (event) { |
| 2526 | case NETDEV_UP: |
| 2527 | spin_lock_bh(&card->ip_lock); |
| 2528 | qeth_l3_add_ip(card, addr); |
| 2529 | spin_unlock_bh(&card->ip_lock); |
| 2530 | return NOTIFY_OK; |
| 2531 | case NETDEV_DOWN: |
| 2532 | spin_lock_bh(&card->ip_lock); |
| 2533 | qeth_l3_delete_ip(card, addr); |
| 2534 | spin_unlock_bh(&card->ip_lock); |
| 2535 | return NOTIFY_OK; |
| 2536 | default: |
| 2537 | return NOTIFY_DONE; |
| 2538 | } |
| 2539 | } |
| 2540 | |
Julian Wiedmann | b9caa98 | 2018-03-09 18:13:01 +0100 | [diff] [blame] | 2541 | static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev) |
| 2542 | { |
| 2543 | if (is_vlan_dev(dev)) |
| 2544 | dev = vlan_dev_real_dev(dev); |
| 2545 | if (dev->netdev_ops == &qeth_l3_osa_netdev_ops || |
| 2546 | dev->netdev_ops == &qeth_l3_netdev_ops) |
| 2547 | return (struct qeth_card *) dev->ml_priv; |
| 2548 | return NULL; |
| 2549 | } |
| 2550 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2551 | static int qeth_l3_ip_event(struct notifier_block *this, |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 2552 | unsigned long event, void *ptr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2553 | { |
Lakhvich Dmitriy | 5f78e29 | 2016-06-16 16:18:58 +0200 | [diff] [blame] | 2554 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2555 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
Julian Wiedmann | b9caa98 | 2018-03-09 18:13:01 +0100 | [diff] [blame] | 2556 | struct net_device *dev = ifa->ifa_dev->dev; |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2557 | struct qeth_ipaddr addr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2558 | struct qeth_card *card; |
| 2559 | |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 2560 | if (dev_net(dev) != &init_net) |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 2561 | return NOTIFY_DONE; |
| 2562 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2563 | card = qeth_l3_get_card_from_dev(dev); |
| 2564 | if (!card) |
| 2565 | return NOTIFY_DONE; |
frank.blaschka@de.ibm.com | 6d8823d | 2012-05-16 01:28:26 +0000 | [diff] [blame] | 2566 | QETH_CARD_TEXT(card, 3, "ipevent"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2567 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2568 | qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV4); |
| 2569 | addr.u.a4.addr = be32_to_cpu(ifa->ifa_address); |
| 2570 | addr.u.a4.mask = be32_to_cpu(ifa->ifa_mask); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2571 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2572 | return qeth_l3_handle_ip_event(card, &addr, event); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | static struct notifier_block qeth_l3_ip_notifier = { |
| 2576 | qeth_l3_ip_event, |
| 2577 | NULL, |
| 2578 | }; |
| 2579 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2580 | static int qeth_l3_ip6_event(struct notifier_block *this, |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 2581 | unsigned long event, void *ptr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2582 | { |
| 2583 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
Julian Wiedmann | b9caa98 | 2018-03-09 18:13:01 +0100 | [diff] [blame] | 2584 | struct net_device *dev = ifa->idev->dev; |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2585 | struct qeth_ipaddr addr; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2586 | struct qeth_card *card; |
| 2587 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2588 | card = qeth_l3_get_card_from_dev(dev); |
| 2589 | if (!card) |
| 2590 | return NOTIFY_DONE; |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2591 | QETH_CARD_TEXT(card, 3, "ip6event"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2592 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 2593 | return NOTIFY_DONE; |
| 2594 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2595 | qeth_l3_init_ipaddr(&addr, QETH_IP_TYPE_NORMAL, QETH_PROT_IPV6); |
| 2596 | addr.u.a6.addr = ifa->addr; |
| 2597 | addr.u.a6.pfxlen = ifa->prefix_len; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2598 | |
Julian Wiedmann | d66b1c0 | 2018-03-09 18:13:00 +0100 | [diff] [blame] | 2599 | return qeth_l3_handle_ip_event(card, &addr, event); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2600 | } |
| 2601 | |
| 2602 | static struct notifier_block qeth_l3_ip6_notifier = { |
| 2603 | qeth_l3_ip6_event, |
| 2604 | NULL, |
| 2605 | }; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2606 | |
| 2607 | static int qeth_l3_register_notifiers(void) |
| 2608 | { |
| 2609 | int rc; |
| 2610 | |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2611 | QETH_DBF_TEXT(SETUP, 5, "regnotif"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2612 | rc = register_inetaddr_notifier(&qeth_l3_ip_notifier); |
| 2613 | if (rc) |
| 2614 | return rc; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2615 | rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier); |
| 2616 | if (rc) { |
| 2617 | unregister_inetaddr_notifier(&qeth_l3_ip_notifier); |
| 2618 | return rc; |
| 2619 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2620 | return 0; |
| 2621 | } |
| 2622 | |
| 2623 | static void qeth_l3_unregister_notifiers(void) |
| 2624 | { |
Carsten Otte | 847a50f | 2010-06-21 22:57:05 +0000 | [diff] [blame] | 2625 | QETH_DBF_TEXT(SETUP, 5, "unregnot"); |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 2626 | WARN_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier)); |
Stefan Raspl | 18af5c1 | 2012-11-19 02:46:50 +0000 | [diff] [blame] | 2627 | WARN_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2628 | } |
| 2629 | |
| 2630 | static int __init qeth_l3_init(void) |
| 2631 | { |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 2632 | pr_info("register layer 3 discipline\n"); |
Julian Wiedmann | c062204 | 2017-12-20 20:10:58 +0100 | [diff] [blame] | 2633 | return qeth_l3_register_notifiers(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2634 | } |
| 2635 | |
| 2636 | static void __exit qeth_l3_exit(void) |
| 2637 | { |
| 2638 | qeth_l3_unregister_notifiers(); |
Frank Blaschka | 74eacdb | 2008-12-25 13:39:49 +0100 | [diff] [blame] | 2639 | pr_info("unregister layer 3 discipline\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2640 | } |
| 2641 | |
| 2642 | module_init(qeth_l3_init); |
| 2643 | module_exit(qeth_l3_exit); |
| 2644 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 2645 | MODULE_DESCRIPTION("qeth layer 3 discipline"); |
| 2646 | MODULE_LICENSE("GPL"); |