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