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