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