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