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