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