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