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