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