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