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