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