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