Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1 | /* |
| 2 | * drivers/s390/net/qeth_l3_main.c |
| 3 | * |
| 4 | * Copyright IBM Corp. 2007 |
| 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 | |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/moduleparam.h> |
| 13 | #include <linux/string.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/etherdevice.h> |
| 17 | #include <linux/mii.h> |
| 18 | #include <linux/ip.h> |
| 19 | #include <linux/reboot.h> |
| 20 | #include <linux/inetdevice.h> |
| 21 | #include <linux/igmp.h> |
| 22 | |
| 23 | #include <net/ip.h> |
| 24 | #include <net/arp.h> |
| 25 | |
| 26 | #include <asm/s390_rdev.h> |
| 27 | |
| 28 | #include "qeth_l3.h" |
| 29 | #include "qeth_core_offl.h" |
| 30 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 31 | static int qeth_l3_set_offline(struct ccwgroup_device *); |
| 32 | static int qeth_l3_recover(void *); |
| 33 | static int qeth_l3_stop(struct net_device *); |
| 34 | static void qeth_l3_set_multicast_list(struct net_device *); |
| 35 | static int qeth_l3_neigh_setup(struct net_device *, struct neigh_parms *); |
| 36 | static int qeth_l3_register_addr_entry(struct qeth_card *, |
| 37 | struct qeth_ipaddr *); |
| 38 | static int qeth_l3_deregister_addr_entry(struct qeth_card *, |
| 39 | struct qeth_ipaddr *); |
| 40 | static int __qeth_l3_set_online(struct ccwgroup_device *, int); |
| 41 | static int __qeth_l3_set_offline(struct ccwgroup_device *, int); |
| 42 | |
| 43 | |
| 44 | static int qeth_l3_isxdigit(char *buf) |
| 45 | { |
| 46 | while (*buf) { |
| 47 | if (!isxdigit(*buf++)) |
| 48 | return 0; |
| 49 | } |
| 50 | return 1; |
| 51 | } |
| 52 | |
| 53 | void qeth_l3_ipaddr4_to_string(const __u8 *addr, char *buf) |
| 54 | { |
| 55 | sprintf(buf, "%i.%i.%i.%i", addr[0], addr[1], addr[2], addr[3]); |
| 56 | } |
| 57 | |
| 58 | int qeth_l3_string_to_ipaddr4(const char *buf, __u8 *addr) |
| 59 | { |
| 60 | int count = 0, rc = 0; |
| 61 | int in[4]; |
| 62 | char c; |
| 63 | |
| 64 | rc = sscanf(buf, "%u.%u.%u.%u%c", |
| 65 | &in[0], &in[1], &in[2], &in[3], &c); |
| 66 | if (rc != 4 && (rc != 5 || c != '\n')) |
| 67 | return -EINVAL; |
| 68 | for (count = 0; count < 4; count++) { |
| 69 | if (in[count] > 255) |
| 70 | return -EINVAL; |
| 71 | addr[count] = in[count]; |
| 72 | } |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | void qeth_l3_ipaddr6_to_string(const __u8 *addr, char *buf) |
| 77 | { |
| 78 | sprintf(buf, "%02x%02x:%02x%02x:%02x%02x:%02x%02x" |
| 79 | ":%02x%02x:%02x%02x:%02x%02x:%02x%02x", |
| 80 | addr[0], addr[1], addr[2], addr[3], |
| 81 | addr[4], addr[5], addr[6], addr[7], |
| 82 | addr[8], addr[9], addr[10], addr[11], |
| 83 | addr[12], addr[13], addr[14], addr[15]); |
| 84 | } |
| 85 | |
| 86 | int qeth_l3_string_to_ipaddr6(const char *buf, __u8 *addr) |
| 87 | { |
| 88 | const char *end, *end_tmp, *start; |
| 89 | __u16 *in; |
| 90 | char num[5]; |
| 91 | int num2, cnt, out, found, save_cnt; |
| 92 | unsigned short in_tmp[8] = {0, }; |
| 93 | |
| 94 | cnt = out = found = save_cnt = num2 = 0; |
| 95 | end = start = buf; |
| 96 | in = (__u16 *) addr; |
| 97 | memset(in, 0, 16); |
| 98 | while (*end) { |
| 99 | end = strchr(start, ':'); |
| 100 | if (end == NULL) { |
| 101 | end = buf + strlen(buf); |
| 102 | end_tmp = strchr(start, '\n'); |
| 103 | if (end_tmp != NULL) |
| 104 | end = end_tmp; |
| 105 | out = 1; |
| 106 | } |
| 107 | if ((end - start)) { |
| 108 | memset(num, 0, 5); |
| 109 | if ((end - start) > 4) |
| 110 | return -EINVAL; |
| 111 | memcpy(num, start, end - start); |
| 112 | if (!qeth_l3_isxdigit(num)) |
| 113 | return -EINVAL; |
| 114 | sscanf(start, "%x", &num2); |
| 115 | if (found) |
| 116 | in_tmp[save_cnt++] = num2; |
| 117 | else |
| 118 | in[cnt++] = num2; |
| 119 | if (out) |
| 120 | break; |
| 121 | } else { |
| 122 | if (found) |
| 123 | return -EINVAL; |
| 124 | found = 1; |
| 125 | } |
| 126 | start = ++end; |
| 127 | } |
| 128 | if (cnt + save_cnt > 8) |
| 129 | return -EINVAL; |
| 130 | cnt = 7; |
| 131 | while (save_cnt) |
| 132 | in[cnt--] = in_tmp[--save_cnt]; |
| 133 | return 0; |
| 134 | } |
| 135 | |
| 136 | void qeth_l3_ipaddr_to_string(enum qeth_prot_versions proto, const __u8 *addr, |
| 137 | char *buf) |
| 138 | { |
| 139 | if (proto == QETH_PROT_IPV4) |
| 140 | qeth_l3_ipaddr4_to_string(addr, buf); |
| 141 | else if (proto == QETH_PROT_IPV6) |
| 142 | qeth_l3_ipaddr6_to_string(addr, buf); |
| 143 | } |
| 144 | |
| 145 | int qeth_l3_string_to_ipaddr(const char *buf, enum qeth_prot_versions proto, |
| 146 | __u8 *addr) |
| 147 | { |
| 148 | if (proto == QETH_PROT_IPV4) |
| 149 | return qeth_l3_string_to_ipaddr4(buf, addr); |
| 150 | else if (proto == QETH_PROT_IPV6) |
| 151 | return qeth_l3_string_to_ipaddr6(buf, addr); |
| 152 | else |
| 153 | return -EINVAL; |
| 154 | } |
| 155 | |
| 156 | static void qeth_l3_convert_addr_to_bits(u8 *addr, u8 *bits, int len) |
| 157 | { |
| 158 | int i, j; |
| 159 | u8 octet; |
| 160 | |
| 161 | for (i = 0; i < len; ++i) { |
| 162 | octet = addr[i]; |
| 163 | for (j = 7; j >= 0; --j) { |
| 164 | bits[i*8 + j] = octet & 1; |
| 165 | octet >>= 1; |
| 166 | } |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | static int qeth_l3_is_addr_covered_by_ipato(struct qeth_card *card, |
| 171 | struct qeth_ipaddr *addr) |
| 172 | { |
| 173 | struct qeth_ipato_entry *ipatoe; |
| 174 | u8 addr_bits[128] = {0, }; |
| 175 | u8 ipatoe_bits[128] = {0, }; |
| 176 | int rc = 0; |
| 177 | |
| 178 | if (!card->ipato.enabled) |
| 179 | return 0; |
| 180 | |
| 181 | qeth_l3_convert_addr_to_bits((u8 *) &addr->u, addr_bits, |
| 182 | (addr->proto == QETH_PROT_IPV4)? 4:16); |
| 183 | list_for_each_entry(ipatoe, &card->ipato.entries, entry) { |
| 184 | if (addr->proto != ipatoe->proto) |
| 185 | continue; |
| 186 | qeth_l3_convert_addr_to_bits(ipatoe->addr, ipatoe_bits, |
| 187 | (ipatoe->proto == QETH_PROT_IPV4) ? |
| 188 | 4 : 16); |
| 189 | if (addr->proto == QETH_PROT_IPV4) |
| 190 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 191 | min(32, ipatoe->mask_bits)); |
| 192 | else |
| 193 | rc = !memcmp(addr_bits, ipatoe_bits, |
| 194 | min(128, ipatoe->mask_bits)); |
| 195 | if (rc) |
| 196 | break; |
| 197 | } |
| 198 | /* invert? */ |
| 199 | if ((addr->proto == QETH_PROT_IPV4) && card->ipato.invert4) |
| 200 | rc = !rc; |
| 201 | else if ((addr->proto == QETH_PROT_IPV6) && card->ipato.invert6) |
| 202 | rc = !rc; |
| 203 | |
| 204 | return rc; |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Add IP to be added to todo list. If there is already an "add todo" |
| 209 | * in this list we just incremenent the reference count. |
| 210 | * Returns 0 if we just incremented reference count. |
| 211 | */ |
| 212 | static int __qeth_l3_insert_ip_todo(struct qeth_card *card, |
| 213 | struct qeth_ipaddr *addr, int add) |
| 214 | { |
| 215 | struct qeth_ipaddr *tmp, *t; |
| 216 | int found = 0; |
| 217 | |
| 218 | list_for_each_entry_safe(tmp, t, card->ip_tbd_list, entry) { |
| 219 | if ((addr->type == QETH_IP_TYPE_DEL_ALL_MC) && |
| 220 | (tmp->type == QETH_IP_TYPE_DEL_ALL_MC)) |
| 221 | return 0; |
| 222 | if ((tmp->proto == QETH_PROT_IPV4) && |
| 223 | (addr->proto == QETH_PROT_IPV4) && |
| 224 | (tmp->type == addr->type) && |
| 225 | (tmp->is_multicast == addr->is_multicast) && |
| 226 | (tmp->u.a4.addr == addr->u.a4.addr) && |
| 227 | (tmp->u.a4.mask == addr->u.a4.mask)) { |
| 228 | found = 1; |
| 229 | break; |
| 230 | } |
| 231 | if ((tmp->proto == QETH_PROT_IPV6) && |
| 232 | (addr->proto == QETH_PROT_IPV6) && |
| 233 | (tmp->type == addr->type) && |
| 234 | (tmp->is_multicast == addr->is_multicast) && |
| 235 | (tmp->u.a6.pfxlen == addr->u.a6.pfxlen) && |
| 236 | (memcmp(&tmp->u.a6.addr, &addr->u.a6.addr, |
| 237 | sizeof(struct in6_addr)) == 0)) { |
| 238 | found = 1; |
| 239 | break; |
| 240 | } |
| 241 | } |
| 242 | if (found) { |
| 243 | if (addr->users != 0) |
| 244 | tmp->users += addr->users; |
| 245 | else |
| 246 | tmp->users += add ? 1 : -1; |
| 247 | if (tmp->users == 0) { |
| 248 | list_del(&tmp->entry); |
| 249 | kfree(tmp); |
| 250 | } |
| 251 | return 0; |
| 252 | } else { |
| 253 | if (addr->type == QETH_IP_TYPE_DEL_ALL_MC) |
| 254 | list_add(&addr->entry, card->ip_tbd_list); |
| 255 | else { |
| 256 | if (addr->users == 0) |
| 257 | addr->users += add ? 1 : -1; |
| 258 | if (add && (addr->type == QETH_IP_TYPE_NORMAL) && |
| 259 | qeth_l3_is_addr_covered_by_ipato(card, addr)) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 260 | QETH_DBF_TEXT(TRACE, 2, "tkovaddr"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 261 | addr->set_flags |= QETH_IPA_SETIP_TAKEOVER_FLAG; |
| 262 | } |
| 263 | list_add_tail(&addr->entry, card->ip_tbd_list); |
| 264 | } |
| 265 | return 1; |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | static int qeth_l3_delete_ip(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 270 | { |
| 271 | unsigned long flags; |
| 272 | int rc = 0; |
| 273 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 274 | QETH_DBF_TEXT(TRACE, 4, "delip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 275 | |
| 276 | if (addr->proto == QETH_PROT_IPV4) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 277 | QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 278 | else { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 279 | QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8); |
| 280 | QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 281 | } |
| 282 | spin_lock_irqsave(&card->ip_lock, flags); |
| 283 | rc = __qeth_l3_insert_ip_todo(card, addr, 0); |
| 284 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 285 | return rc; |
| 286 | } |
| 287 | |
| 288 | static int qeth_l3_add_ip(struct qeth_card *card, struct qeth_ipaddr *addr) |
| 289 | { |
| 290 | unsigned long flags; |
| 291 | int rc = 0; |
| 292 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 293 | QETH_DBF_TEXT(TRACE, 4, "addip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 294 | if (addr->proto == QETH_PROT_IPV4) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 295 | QETH_DBF_HEX(TRACE, 4, &addr->u.a4.addr, 4); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 296 | else { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 297 | QETH_DBF_HEX(TRACE, 4, &addr->u.a6.addr, 8); |
| 298 | QETH_DBF_HEX(TRACE, 4, ((char *)&addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 299 | } |
| 300 | spin_lock_irqsave(&card->ip_lock, flags); |
| 301 | rc = __qeth_l3_insert_ip_todo(card, addr, 1); |
| 302 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 303 | return rc; |
| 304 | } |
| 305 | |
| 306 | |
| 307 | static struct qeth_ipaddr *qeth_l3_get_addr_buffer( |
| 308 | enum qeth_prot_versions prot) |
| 309 | { |
| 310 | struct qeth_ipaddr *addr; |
| 311 | |
| 312 | addr = kzalloc(sizeof(struct qeth_ipaddr), GFP_ATOMIC); |
| 313 | if (addr == NULL) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 314 | return NULL; |
| 315 | } |
| 316 | addr->type = QETH_IP_TYPE_NORMAL; |
| 317 | addr->proto = prot; |
| 318 | return addr; |
| 319 | } |
| 320 | |
| 321 | static void qeth_l3_delete_mc_addresses(struct qeth_card *card) |
| 322 | { |
| 323 | struct qeth_ipaddr *iptodo; |
| 324 | unsigned long flags; |
| 325 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 326 | QETH_DBF_TEXT(TRACE, 4, "delmc"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 327 | iptodo = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); |
| 328 | if (!iptodo) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 329 | QETH_DBF_TEXT(TRACE, 2, "dmcnomem"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 330 | return; |
| 331 | } |
| 332 | iptodo->type = QETH_IP_TYPE_DEL_ALL_MC; |
| 333 | spin_lock_irqsave(&card->ip_lock, flags); |
| 334 | if (!__qeth_l3_insert_ip_todo(card, iptodo, 0)) |
| 335 | kfree(iptodo); |
| 336 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 337 | } |
| 338 | |
| 339 | /* |
| 340 | * Add/remove address to/from card's ip list, i.e. try to add or remove |
| 341 | * reference to/from an IP address that is already registered on the card. |
| 342 | * Returns: |
| 343 | * 0 address was on card and its reference count has been adjusted, |
| 344 | * but is still > 0, so nothing has to be done |
| 345 | * also returns 0 if card was not on card and the todo was to delete |
| 346 | * the address -> there is also nothing to be done |
| 347 | * 1 address was not on card and the todo is to add it to the card's ip |
| 348 | * list |
| 349 | * -1 address was on card and its reference count has been decremented |
| 350 | * to <= 0 by the todo -> address must be removed from card |
| 351 | */ |
| 352 | static int __qeth_l3_ref_ip_on_card(struct qeth_card *card, |
| 353 | struct qeth_ipaddr *todo, struct qeth_ipaddr **__addr) |
| 354 | { |
| 355 | struct qeth_ipaddr *addr; |
| 356 | int found = 0; |
| 357 | |
| 358 | list_for_each_entry(addr, &card->ip_list, entry) { |
| 359 | if ((addr->proto == QETH_PROT_IPV4) && |
| 360 | (todo->proto == QETH_PROT_IPV4) && |
| 361 | (addr->type == todo->type) && |
| 362 | (addr->u.a4.addr == todo->u.a4.addr) && |
| 363 | (addr->u.a4.mask == todo->u.a4.mask)) { |
| 364 | found = 1; |
| 365 | break; |
| 366 | } |
| 367 | if ((addr->proto == QETH_PROT_IPV6) && |
| 368 | (todo->proto == QETH_PROT_IPV6) && |
| 369 | (addr->type == todo->type) && |
| 370 | (addr->u.a6.pfxlen == todo->u.a6.pfxlen) && |
| 371 | (memcmp(&addr->u.a6.addr, &todo->u.a6.addr, |
| 372 | sizeof(struct in6_addr)) == 0)) { |
| 373 | found = 1; |
| 374 | break; |
| 375 | } |
| 376 | } |
| 377 | if (found) { |
| 378 | addr->users += todo->users; |
| 379 | if (addr->users <= 0) { |
| 380 | *__addr = addr; |
| 381 | return -1; |
| 382 | } else { |
| 383 | /* for VIPA and RXIP limit refcount to 1 */ |
| 384 | if (addr->type != QETH_IP_TYPE_NORMAL) |
| 385 | addr->users = 1; |
| 386 | return 0; |
| 387 | } |
| 388 | } |
| 389 | if (todo->users > 0) { |
| 390 | /* for VIPA and RXIP limit refcount to 1 */ |
| 391 | if (todo->type != QETH_IP_TYPE_NORMAL) |
| 392 | todo->users = 1; |
| 393 | return 1; |
| 394 | } else |
| 395 | return 0; |
| 396 | } |
| 397 | |
| 398 | static void __qeth_l3_delete_all_mc(struct qeth_card *card, |
| 399 | unsigned long *flags) |
| 400 | { |
Ursula Braun | 2d921c3 | 2008-04-01 10:26:53 +0200 | [diff] [blame] | 401 | struct list_head fail_list; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 402 | struct qeth_ipaddr *addr, *tmp; |
| 403 | int rc; |
Ursula Braun | 2d921c3 | 2008-04-01 10:26:53 +0200 | [diff] [blame] | 404 | |
| 405 | INIT_LIST_HEAD(&fail_list); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 406 | again: |
| 407 | list_for_each_entry_safe(addr, tmp, &card->ip_list, entry) { |
| 408 | if (addr->is_multicast) { |
| 409 | list_del(&addr->entry); |
| 410 | spin_unlock_irqrestore(&card->ip_lock, *flags); |
| 411 | rc = qeth_l3_deregister_addr_entry(card, addr); |
| 412 | spin_lock_irqsave(&card->ip_lock, *flags); |
Ursula Braun | 2d921c3 | 2008-04-01 10:26:53 +0200 | [diff] [blame] | 413 | if (!rc || (rc == IPA_RC_MC_ADDR_NOT_FOUND)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 414 | kfree(addr); |
Ursula Braun | 2d921c3 | 2008-04-01 10:26:53 +0200 | [diff] [blame] | 415 | else |
| 416 | list_add_tail(&addr->entry, &fail_list); |
| 417 | goto again; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 418 | } |
| 419 | } |
Ursula Braun | 2d921c3 | 2008-04-01 10:26:53 +0200 | [diff] [blame] | 420 | list_splice(&fail_list, &card->ip_list); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 421 | } |
| 422 | |
| 423 | static void qeth_l3_set_ip_addr_list(struct qeth_card *card) |
| 424 | { |
| 425 | struct list_head *tbd_list; |
| 426 | struct qeth_ipaddr *todo, *addr; |
| 427 | unsigned long flags; |
| 428 | int rc; |
| 429 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 430 | QETH_DBF_TEXT(TRACE, 2, "sdiplist"); |
| 431 | QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 432 | |
| 433 | spin_lock_irqsave(&card->ip_lock, flags); |
| 434 | tbd_list = card->ip_tbd_list; |
| 435 | card->ip_tbd_list = kmalloc(sizeof(struct list_head), GFP_ATOMIC); |
| 436 | if (!card->ip_tbd_list) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 437 | QETH_DBF_TEXT(TRACE, 0, "silnomem"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 438 | card->ip_tbd_list = tbd_list; |
| 439 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 440 | return; |
| 441 | } else |
| 442 | INIT_LIST_HEAD(card->ip_tbd_list); |
| 443 | |
| 444 | while (!list_empty(tbd_list)) { |
| 445 | todo = list_entry(tbd_list->next, struct qeth_ipaddr, entry); |
| 446 | list_del(&todo->entry); |
| 447 | if (todo->type == QETH_IP_TYPE_DEL_ALL_MC) { |
| 448 | __qeth_l3_delete_all_mc(card, &flags); |
| 449 | kfree(todo); |
| 450 | continue; |
| 451 | } |
| 452 | rc = __qeth_l3_ref_ip_on_card(card, todo, &addr); |
| 453 | if (rc == 0) { |
| 454 | /* nothing to be done; only adjusted refcount */ |
| 455 | kfree(todo); |
| 456 | } else if (rc == 1) { |
| 457 | /* new entry to be added to on-card list */ |
| 458 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 459 | rc = qeth_l3_register_addr_entry(card, todo); |
| 460 | spin_lock_irqsave(&card->ip_lock, flags); |
Ursula Braun | 3caa4af | 2008-04-01 10:27:00 +0200 | [diff] [blame] | 461 | if (!rc || (rc == IPA_RC_LAN_OFFLINE)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 462 | list_add_tail(&todo->entry, &card->ip_list); |
| 463 | else |
| 464 | kfree(todo); |
| 465 | } else if (rc == -1) { |
| 466 | /* on-card entry to be removed */ |
| 467 | list_del_init(&addr->entry); |
| 468 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 469 | rc = qeth_l3_deregister_addr_entry(card, addr); |
| 470 | spin_lock_irqsave(&card->ip_lock, flags); |
Ursula Braun | 2d921c3 | 2008-04-01 10:26:53 +0200 | [diff] [blame] | 471 | if (!rc || (rc == IPA_RC_PRIMARY_ALREADY_DEFINED)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 472 | kfree(addr); |
| 473 | else |
| 474 | list_add_tail(&addr->entry, &card->ip_list); |
| 475 | kfree(todo); |
| 476 | } |
| 477 | } |
| 478 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 479 | kfree(tbd_list); |
| 480 | } |
| 481 | |
| 482 | static void qeth_l3_clear_ip_list(struct qeth_card *card, int clean, |
| 483 | int recover) |
| 484 | { |
| 485 | struct qeth_ipaddr *addr, *tmp; |
| 486 | unsigned long flags; |
| 487 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 488 | QETH_DBF_TEXT(TRACE, 4, "clearip"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 489 | spin_lock_irqsave(&card->ip_lock, flags); |
| 490 | /* clear todo list */ |
| 491 | list_for_each_entry_safe(addr, tmp, card->ip_tbd_list, entry) { |
| 492 | list_del(&addr->entry); |
| 493 | kfree(addr); |
| 494 | } |
| 495 | |
| 496 | while (!list_empty(&card->ip_list)) { |
| 497 | addr = list_entry(card->ip_list.next, |
| 498 | struct qeth_ipaddr, entry); |
| 499 | list_del_init(&addr->entry); |
| 500 | if (clean) { |
| 501 | spin_unlock_irqrestore(&card->ip_lock, flags); |
| 502 | qeth_l3_deregister_addr_entry(card, addr); |
| 503 | spin_lock_irqsave(&card->ip_lock, flags); |
| 504 | } |
| 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 546 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 584 | QETH_DBF_TEXT(TRACE, 4, "setdelip"); |
| 585 | QETH_DBF_TEXT_(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 614 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 658 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 678 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 722 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 747 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 775 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 779 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 810 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 814 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 839 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 843 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 874 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 878 | QETH_DBF_TEXT(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 898 | QETH_DBF_TEXT(TRACE, 2, "setaddr4"); |
| 899 | QETH_DBF_HEX(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 901 | QETH_DBF_TEXT(TRACE, 2, "setaddr6"); |
| 902 | QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8); |
| 903 | QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 904 | } else { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 905 | QETH_DBF_TEXT(TRACE, 2, "setaddr?"); |
| 906 | QETH_DBF_HEX(TRACE, 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) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 915 | QETH_DBF_TEXT(TRACE, 2, "failed"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 916 | } while ((--cnt > 0) && rc); |
| 917 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 918 | QETH_DBF_TEXT(TRACE, 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); |
| 920 | PRINT_WARN("Could not register IP address %s (rc=0x%x/%d)\n", |
| 921 | buf, rc, rc); |
| 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 932 | QETH_DBF_TEXT(TRACE, 2, "deladdr4"); |
| 933 | QETH_DBF_HEX(TRACE, 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) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 935 | QETH_DBF_TEXT(TRACE, 2, "deladdr6"); |
| 936 | QETH_DBF_HEX(TRACE, 3, &addr->u.a6.addr, 8); |
| 937 | QETH_DBF_HEX(TRACE, 3, ((char *)&addr->u.a6.addr) + 8, 8); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 938 | } else { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 939 | QETH_DBF_TEXT(TRACE, 2, "deladdr?"); |
| 940 | QETH_DBF_HEX(TRACE, 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) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 948 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 981 | QETH_DBF_TEXT(TRACE, 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 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 996 | QETH_DBF_TEXT(TRACE, 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)) { |
| 1032 | PRINT_WARN("set adapter parameters not supported " |
| 1033 | "on device %s.\n", |
| 1034 | CARD_BUS_ID(card)); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1035 | QETH_DBF_TEXT(SETUP, 2, " notsupp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1036 | return 0; |
| 1037 | } |
| 1038 | rc = qeth_query_setadapterparms(card); |
| 1039 | if (rc) { |
| 1040 | PRINT_WARN("couldn't set adapter parameters on device %s: " |
| 1041 | "x%x\n", CARD_BUS_ID(card), rc); |
| 1042 | return rc; |
| 1043 | } |
| 1044 | if (qeth_adp_supported(card, IPA_SETADP_ALTER_MAC_ADDRESS)) { |
| 1045 | rc = qeth_setadpparms_change_macaddr(card); |
| 1046 | if (rc) |
| 1047 | PRINT_WARN("couldn't get MAC address on " |
| 1048 | "device %s: x%x\n", |
| 1049 | CARD_BUS_ID(card), rc); |
| 1050 | } |
| 1051 | |
| 1052 | if ((card->info.link_type == QETH_LINK_TYPE_HSTR) || |
| 1053 | (card->info.link_type == QETH_LINK_TYPE_LANE_TR)) |
| 1054 | rc = qeth_l3_setadapter_hstr(card); |
| 1055 | |
| 1056 | return rc; |
| 1057 | } |
| 1058 | |
| 1059 | static int qeth_l3_default_setassparms_cb(struct qeth_card *card, |
| 1060 | struct qeth_reply *reply, unsigned long data) |
| 1061 | { |
| 1062 | struct qeth_ipa_cmd *cmd; |
| 1063 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1064 | QETH_DBF_TEXT(TRACE, 4, "defadpcb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1065 | |
| 1066 | cmd = (struct qeth_ipa_cmd *) data; |
| 1067 | if (cmd->hdr.return_code == 0) { |
| 1068 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
| 1069 | if (cmd->hdr.prot_version == QETH_PROT_IPV4) |
| 1070 | card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled; |
| 1071 | if (cmd->hdr.prot_version == QETH_PROT_IPV6) |
| 1072 | card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled; |
| 1073 | } |
| 1074 | if (cmd->data.setassparms.hdr.assist_no == IPA_INBOUND_CHECKSUM && |
| 1075 | cmd->data.setassparms.hdr.command_code == IPA_CMD_ASS_START) { |
| 1076 | card->info.csum_mask = cmd->data.setassparms.data.flags_32bit; |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1077 | QETH_DBF_TEXT_(TRACE, 3, "csum:%d", card->info.csum_mask); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1078 | } |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | static struct qeth_cmd_buffer *qeth_l3_get_setassparms_cmd( |
| 1083 | struct qeth_card *card, enum qeth_ipa_funcs ipa_func, __u16 cmd_code, |
| 1084 | __u16 len, enum qeth_prot_versions prot) |
| 1085 | { |
| 1086 | struct qeth_cmd_buffer *iob; |
| 1087 | struct qeth_ipa_cmd *cmd; |
| 1088 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1089 | QETH_DBF_TEXT(TRACE, 4, "getasscm"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1090 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_SETASSPARMS, prot); |
| 1091 | |
| 1092 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1093 | cmd->data.setassparms.hdr.assist_no = ipa_func; |
| 1094 | cmd->data.setassparms.hdr.length = 8 + len; |
| 1095 | cmd->data.setassparms.hdr.command_code = cmd_code; |
| 1096 | cmd->data.setassparms.hdr.return_code = 0; |
| 1097 | cmd->data.setassparms.hdr.seq_no = 0; |
| 1098 | |
| 1099 | return iob; |
| 1100 | } |
| 1101 | |
| 1102 | static int qeth_l3_send_setassparms(struct qeth_card *card, |
| 1103 | struct qeth_cmd_buffer *iob, __u16 len, long data, |
| 1104 | int (*reply_cb)(struct qeth_card *, struct qeth_reply *, |
| 1105 | unsigned long), |
| 1106 | void *reply_param) |
| 1107 | { |
| 1108 | int rc; |
| 1109 | struct qeth_ipa_cmd *cmd; |
| 1110 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1111 | QETH_DBF_TEXT(TRACE, 4, "sendassp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1112 | |
| 1113 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1114 | if (len <= sizeof(__u32)) |
| 1115 | cmd->data.setassparms.data.flags_32bit = (__u32) data; |
| 1116 | else /* (len > sizeof(__u32)) */ |
| 1117 | memcpy(&cmd->data.setassparms.data, (void *) data, len); |
| 1118 | |
| 1119 | rc = qeth_send_ipa_cmd(card, iob, reply_cb, reply_param); |
| 1120 | return rc; |
| 1121 | } |
| 1122 | |
| 1123 | #ifdef CONFIG_QETH_IPV6 |
| 1124 | static int qeth_l3_send_simple_setassparms_ipv6(struct qeth_card *card, |
| 1125 | enum qeth_ipa_funcs ipa_func, __u16 cmd_code) |
| 1126 | { |
| 1127 | int rc; |
| 1128 | struct qeth_cmd_buffer *iob; |
| 1129 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1130 | QETH_DBF_TEXT(TRACE, 4, "simassp6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1131 | iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code, |
| 1132 | 0, QETH_PROT_IPV6); |
| 1133 | rc = qeth_l3_send_setassparms(card, iob, 0, 0, |
| 1134 | qeth_l3_default_setassparms_cb, NULL); |
| 1135 | return rc; |
| 1136 | } |
| 1137 | #endif |
| 1138 | |
| 1139 | static int qeth_l3_send_simple_setassparms(struct qeth_card *card, |
| 1140 | enum qeth_ipa_funcs ipa_func, __u16 cmd_code, long data) |
| 1141 | { |
| 1142 | int rc; |
| 1143 | int length = 0; |
| 1144 | struct qeth_cmd_buffer *iob; |
| 1145 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1146 | QETH_DBF_TEXT(TRACE, 4, "simassp4"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1147 | if (data) |
| 1148 | length = sizeof(__u32); |
| 1149 | iob = qeth_l3_get_setassparms_cmd(card, ipa_func, cmd_code, |
| 1150 | length, QETH_PROT_IPV4); |
| 1151 | rc = qeth_l3_send_setassparms(card, iob, length, data, |
| 1152 | qeth_l3_default_setassparms_cb, NULL); |
| 1153 | return rc; |
| 1154 | } |
| 1155 | |
| 1156 | static int qeth_l3_start_ipa_arp_processing(struct qeth_card *card) |
| 1157 | { |
| 1158 | int rc; |
| 1159 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1160 | QETH_DBF_TEXT(TRACE, 3, "ipaarp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1161 | |
| 1162 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
| 1163 | PRINT_WARN("ARP processing not supported " |
| 1164 | "on %s!\n", QETH_CARD_IFNAME(card)); |
| 1165 | return 0; |
| 1166 | } |
| 1167 | rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 1168 | IPA_CMD_ASS_START, 0); |
| 1169 | if (rc) { |
| 1170 | PRINT_WARN("Could not start ARP processing " |
| 1171 | "assist on %s: 0x%x\n", |
| 1172 | QETH_CARD_IFNAME(card), rc); |
| 1173 | } |
| 1174 | return rc; |
| 1175 | } |
| 1176 | |
| 1177 | static int qeth_l3_start_ipa_ip_fragmentation(struct qeth_card *card) |
| 1178 | { |
| 1179 | int rc; |
| 1180 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1181 | QETH_DBF_TEXT(TRACE, 3, "ipaipfrg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1182 | |
| 1183 | if (!qeth_is_supported(card, IPA_IP_FRAGMENTATION)) { |
| 1184 | PRINT_INFO("Hardware IP fragmentation not supported on %s\n", |
| 1185 | QETH_CARD_IFNAME(card)); |
| 1186 | return -EOPNOTSUPP; |
| 1187 | } |
| 1188 | |
| 1189 | rc = qeth_l3_send_simple_setassparms(card, IPA_IP_FRAGMENTATION, |
| 1190 | IPA_CMD_ASS_START, 0); |
| 1191 | if (rc) { |
| 1192 | PRINT_WARN("Could not start Hardware IP fragmentation " |
| 1193 | "assist on %s: 0x%x\n", |
| 1194 | QETH_CARD_IFNAME(card), rc); |
| 1195 | } else |
| 1196 | PRINT_INFO("Hardware IP fragmentation enabled \n"); |
| 1197 | return rc; |
| 1198 | } |
| 1199 | |
| 1200 | static int qeth_l3_start_ipa_source_mac(struct qeth_card *card) |
| 1201 | { |
| 1202 | int rc; |
| 1203 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1204 | QETH_DBF_TEXT(TRACE, 3, "stsrcmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1205 | |
| 1206 | if (!card->options.fake_ll) |
| 1207 | return -EOPNOTSUPP; |
| 1208 | |
| 1209 | if (!qeth_is_supported(card, IPA_SOURCE_MAC)) { |
| 1210 | PRINT_INFO("Inbound source address not " |
| 1211 | "supported on %s\n", QETH_CARD_IFNAME(card)); |
| 1212 | return -EOPNOTSUPP; |
| 1213 | } |
| 1214 | |
| 1215 | rc = qeth_l3_send_simple_setassparms(card, IPA_SOURCE_MAC, |
| 1216 | IPA_CMD_ASS_START, 0); |
| 1217 | if (rc) |
| 1218 | PRINT_WARN("Could not start inbound source " |
| 1219 | "assist on %s: 0x%x\n", |
| 1220 | QETH_CARD_IFNAME(card), rc); |
| 1221 | return rc; |
| 1222 | } |
| 1223 | |
| 1224 | static int qeth_l3_start_ipa_vlan(struct qeth_card *card) |
| 1225 | { |
| 1226 | int rc = 0; |
| 1227 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1228 | QETH_DBF_TEXT(TRACE, 3, "strtvlan"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1229 | |
| 1230 | if (!qeth_is_supported(card, IPA_FULL_VLAN)) { |
| 1231 | PRINT_WARN("VLAN not supported on %s\n", |
| 1232 | QETH_CARD_IFNAME(card)); |
| 1233 | return -EOPNOTSUPP; |
| 1234 | } |
| 1235 | |
| 1236 | rc = qeth_l3_send_simple_setassparms(card, IPA_VLAN_PRIO, |
| 1237 | IPA_CMD_ASS_START, 0); |
| 1238 | if (rc) { |
| 1239 | PRINT_WARN("Could not start vlan " |
| 1240 | "assist on %s: 0x%x\n", |
| 1241 | QETH_CARD_IFNAME(card), rc); |
| 1242 | } else { |
| 1243 | PRINT_INFO("VLAN enabled \n"); |
| 1244 | } |
| 1245 | return rc; |
| 1246 | } |
| 1247 | |
| 1248 | static int qeth_l3_start_ipa_multicast(struct qeth_card *card) |
| 1249 | { |
| 1250 | int rc; |
| 1251 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1252 | QETH_DBF_TEXT(TRACE, 3, "stmcast"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1253 | |
| 1254 | if (!qeth_is_supported(card, IPA_MULTICASTING)) { |
| 1255 | PRINT_WARN("Multicast not supported on %s\n", |
| 1256 | QETH_CARD_IFNAME(card)); |
| 1257 | return -EOPNOTSUPP; |
| 1258 | } |
| 1259 | |
| 1260 | rc = qeth_l3_send_simple_setassparms(card, IPA_MULTICASTING, |
| 1261 | IPA_CMD_ASS_START, 0); |
| 1262 | if (rc) { |
| 1263 | PRINT_WARN("Could not start multicast " |
| 1264 | "assist on %s: rc=%i\n", |
| 1265 | QETH_CARD_IFNAME(card), rc); |
| 1266 | } else { |
| 1267 | PRINT_INFO("Multicast enabled\n"); |
| 1268 | card->dev->flags |= IFF_MULTICAST; |
| 1269 | } |
| 1270 | return rc; |
| 1271 | } |
| 1272 | |
| 1273 | static int qeth_l3_query_ipassists_cb(struct qeth_card *card, |
| 1274 | struct qeth_reply *reply, unsigned long data) |
| 1275 | { |
| 1276 | struct qeth_ipa_cmd *cmd; |
| 1277 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1278 | QETH_DBF_TEXT(SETUP, 2, "qipasscb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1279 | |
| 1280 | cmd = (struct qeth_ipa_cmd *) data; |
| 1281 | if (cmd->hdr.prot_version == QETH_PROT_IPV4) { |
| 1282 | card->options.ipa4.supported_funcs = cmd->hdr.ipa_supported; |
| 1283 | card->options.ipa4.enabled_funcs = cmd->hdr.ipa_enabled; |
| 1284 | } else { |
| 1285 | card->options.ipa6.supported_funcs = cmd->hdr.ipa_supported; |
| 1286 | card->options.ipa6.enabled_funcs = cmd->hdr.ipa_enabled; |
| 1287 | } |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1288 | QETH_DBF_TEXT(SETUP, 2, "suppenbl"); |
| 1289 | QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_supported); |
| 1290 | QETH_DBF_TEXT_(SETUP, 2, "%x", cmd->hdr.ipa_enabled); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1291 | return 0; |
| 1292 | } |
| 1293 | |
| 1294 | static int qeth_l3_query_ipassists(struct qeth_card *card, |
| 1295 | enum qeth_prot_versions prot) |
| 1296 | { |
| 1297 | int rc; |
| 1298 | struct qeth_cmd_buffer *iob; |
| 1299 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1300 | QETH_DBF_TEXT_(SETUP, 2, "qipassi%i", prot); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1301 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_QIPASSIST, prot); |
| 1302 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_query_ipassists_cb, NULL); |
| 1303 | return rc; |
| 1304 | } |
| 1305 | |
| 1306 | #ifdef CONFIG_QETH_IPV6 |
| 1307 | static int qeth_l3_softsetup_ipv6(struct qeth_card *card) |
| 1308 | { |
| 1309 | int rc; |
| 1310 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1311 | QETH_DBF_TEXT(TRACE, 3, "softipv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1312 | |
| 1313 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 1314 | goto out; |
| 1315 | |
| 1316 | rc = qeth_l3_query_ipassists(card, QETH_PROT_IPV6); |
| 1317 | if (rc) { |
| 1318 | PRINT_ERR("IPv6 query ipassist failed on %s\n", |
| 1319 | QETH_CARD_IFNAME(card)); |
| 1320 | return rc; |
| 1321 | } |
| 1322 | rc = qeth_l3_send_simple_setassparms(card, IPA_IPV6, |
| 1323 | IPA_CMD_ASS_START, 3); |
| 1324 | if (rc) { |
| 1325 | PRINT_WARN("IPv6 start assist (version 4) failed " |
| 1326 | "on %s: 0x%x\n", |
| 1327 | QETH_CARD_IFNAME(card), rc); |
| 1328 | return rc; |
| 1329 | } |
| 1330 | rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_IPV6, |
| 1331 | IPA_CMD_ASS_START); |
| 1332 | if (rc) { |
| 1333 | PRINT_WARN("IPV6 start assist (version 6) failed " |
| 1334 | "on %s: 0x%x\n", |
| 1335 | QETH_CARD_IFNAME(card), rc); |
| 1336 | return rc; |
| 1337 | } |
| 1338 | rc = qeth_l3_send_simple_setassparms_ipv6(card, IPA_PASSTHRU, |
| 1339 | IPA_CMD_ASS_START); |
| 1340 | if (rc) { |
| 1341 | PRINT_WARN("Could not enable passthrough " |
| 1342 | "on %s: 0x%x\n", |
| 1343 | QETH_CARD_IFNAME(card), rc); |
| 1344 | return rc; |
| 1345 | } |
| 1346 | out: |
| 1347 | PRINT_INFO("IPV6 enabled \n"); |
| 1348 | return 0; |
| 1349 | } |
| 1350 | #endif |
| 1351 | |
| 1352 | static int qeth_l3_start_ipa_ipv6(struct qeth_card *card) |
| 1353 | { |
| 1354 | int rc = 0; |
| 1355 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1356 | QETH_DBF_TEXT(TRACE, 3, "strtipv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1357 | |
| 1358 | if (!qeth_is_supported(card, IPA_IPV6)) { |
| 1359 | PRINT_WARN("IPv6 not supported on %s\n", |
| 1360 | QETH_CARD_IFNAME(card)); |
| 1361 | return 0; |
| 1362 | } |
| 1363 | #ifdef CONFIG_QETH_IPV6 |
| 1364 | rc = qeth_l3_softsetup_ipv6(card); |
| 1365 | #endif |
| 1366 | return rc ; |
| 1367 | } |
| 1368 | |
| 1369 | static int qeth_l3_start_ipa_broadcast(struct qeth_card *card) |
| 1370 | { |
| 1371 | int rc; |
| 1372 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1373 | QETH_DBF_TEXT(TRACE, 3, "stbrdcst"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1374 | card->info.broadcast_capable = 0; |
| 1375 | if (!qeth_is_supported(card, IPA_FILTERING)) { |
| 1376 | PRINT_WARN("Broadcast not supported on %s\n", |
| 1377 | QETH_CARD_IFNAME(card)); |
| 1378 | rc = -EOPNOTSUPP; |
| 1379 | goto out; |
| 1380 | } |
| 1381 | rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING, |
| 1382 | IPA_CMD_ASS_START, 0); |
| 1383 | if (rc) { |
| 1384 | PRINT_WARN("Could not enable broadcasting filtering " |
| 1385 | "on %s: 0x%x\n", |
| 1386 | QETH_CARD_IFNAME(card), rc); |
| 1387 | goto out; |
| 1388 | } |
| 1389 | |
| 1390 | rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING, |
| 1391 | IPA_CMD_ASS_CONFIGURE, 1); |
| 1392 | if (rc) { |
| 1393 | PRINT_WARN("Could not set up broadcast filtering on %s: 0x%x\n", |
| 1394 | QETH_CARD_IFNAME(card), rc); |
| 1395 | goto out; |
| 1396 | } |
| 1397 | card->info.broadcast_capable = QETH_BROADCAST_WITH_ECHO; |
| 1398 | PRINT_INFO("Broadcast enabled \n"); |
| 1399 | rc = qeth_l3_send_simple_setassparms(card, IPA_FILTERING, |
| 1400 | IPA_CMD_ASS_ENABLE, 1); |
| 1401 | if (rc) { |
| 1402 | PRINT_WARN("Could not set up broadcast echo filtering on " |
| 1403 | "%s: 0x%x\n", QETH_CARD_IFNAME(card), rc); |
| 1404 | goto out; |
| 1405 | } |
| 1406 | card->info.broadcast_capable = QETH_BROADCAST_WITHOUT_ECHO; |
| 1407 | out: |
| 1408 | if (card->info.broadcast_capable) |
| 1409 | card->dev->flags |= IFF_BROADCAST; |
| 1410 | else |
| 1411 | card->dev->flags &= ~IFF_BROADCAST; |
| 1412 | return rc; |
| 1413 | } |
| 1414 | |
| 1415 | static int qeth_l3_send_checksum_command(struct qeth_card *card) |
| 1416 | { |
| 1417 | int rc; |
| 1418 | |
| 1419 | rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM, |
| 1420 | IPA_CMD_ASS_START, 0); |
| 1421 | if (rc) { |
| 1422 | PRINT_WARN("Starting Inbound HW Checksumming failed on %s: " |
| 1423 | "0x%x,\ncontinuing using Inbound SW Checksumming\n", |
| 1424 | QETH_CARD_IFNAME(card), rc); |
| 1425 | return rc; |
| 1426 | } |
| 1427 | rc = qeth_l3_send_simple_setassparms(card, IPA_INBOUND_CHECKSUM, |
| 1428 | IPA_CMD_ASS_ENABLE, |
| 1429 | card->info.csum_mask); |
| 1430 | if (rc) { |
| 1431 | PRINT_WARN("Enabling Inbound HW Checksumming failed on %s: " |
| 1432 | "0x%x,\ncontinuing using Inbound SW Checksumming\n", |
| 1433 | QETH_CARD_IFNAME(card), rc); |
| 1434 | return rc; |
| 1435 | } |
| 1436 | return 0; |
| 1437 | } |
| 1438 | |
| 1439 | static int qeth_l3_start_ipa_checksum(struct qeth_card *card) |
| 1440 | { |
| 1441 | int rc = 0; |
| 1442 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1443 | QETH_DBF_TEXT(TRACE, 3, "strtcsum"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1444 | |
| 1445 | if (card->options.checksum_type == NO_CHECKSUMMING) { |
| 1446 | PRINT_WARN("Using no checksumming on %s.\n", |
| 1447 | QETH_CARD_IFNAME(card)); |
| 1448 | return 0; |
| 1449 | } |
| 1450 | if (card->options.checksum_type == SW_CHECKSUMMING) { |
| 1451 | PRINT_WARN("Using SW checksumming on %s.\n", |
| 1452 | QETH_CARD_IFNAME(card)); |
| 1453 | return 0; |
| 1454 | } |
| 1455 | if (!qeth_is_supported(card, IPA_INBOUND_CHECKSUM)) { |
| 1456 | PRINT_WARN("Inbound HW Checksumming not " |
| 1457 | "supported on %s,\ncontinuing " |
| 1458 | "using Inbound SW Checksumming\n", |
| 1459 | QETH_CARD_IFNAME(card)); |
| 1460 | card->options.checksum_type = SW_CHECKSUMMING; |
| 1461 | return 0; |
| 1462 | } |
| 1463 | rc = qeth_l3_send_checksum_command(card); |
| 1464 | if (!rc) |
| 1465 | PRINT_INFO("HW Checksumming (inbound) enabled \n"); |
| 1466 | |
| 1467 | return rc; |
| 1468 | } |
| 1469 | |
| 1470 | static int qeth_l3_start_ipa_tso(struct qeth_card *card) |
| 1471 | { |
| 1472 | int rc; |
| 1473 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1474 | QETH_DBF_TEXT(TRACE, 3, "sttso"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1475 | |
| 1476 | if (!qeth_is_supported(card, IPA_OUTBOUND_TSO)) { |
| 1477 | PRINT_WARN("Outbound TSO not supported on %s\n", |
| 1478 | QETH_CARD_IFNAME(card)); |
| 1479 | rc = -EOPNOTSUPP; |
| 1480 | } else { |
| 1481 | rc = qeth_l3_send_simple_setassparms(card, IPA_OUTBOUND_TSO, |
| 1482 | IPA_CMD_ASS_START, 0); |
| 1483 | if (rc) |
| 1484 | PRINT_WARN("Could not start outbound TSO " |
| 1485 | "assist on %s: rc=%i\n", |
| 1486 | QETH_CARD_IFNAME(card), rc); |
| 1487 | else |
| 1488 | PRINT_INFO("Outbound TSO enabled\n"); |
| 1489 | } |
| 1490 | if (rc && (card->options.large_send == QETH_LARGE_SEND_TSO)) { |
| 1491 | card->options.large_send = QETH_LARGE_SEND_NO; |
| 1492 | card->dev->features &= ~(NETIF_F_TSO | NETIF_F_SG); |
| 1493 | } |
| 1494 | return rc; |
| 1495 | } |
| 1496 | |
| 1497 | static int qeth_l3_start_ipassists(struct qeth_card *card) |
| 1498 | { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1499 | QETH_DBF_TEXT(TRACE, 3, "strtipas"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1500 | qeth_l3_start_ipa_arp_processing(card); /* go on*/ |
| 1501 | qeth_l3_start_ipa_ip_fragmentation(card); /* go on*/ |
| 1502 | qeth_l3_start_ipa_source_mac(card); /* go on*/ |
| 1503 | qeth_l3_start_ipa_vlan(card); /* go on*/ |
| 1504 | qeth_l3_start_ipa_multicast(card); /* go on*/ |
| 1505 | qeth_l3_start_ipa_ipv6(card); /* go on*/ |
| 1506 | qeth_l3_start_ipa_broadcast(card); /* go on*/ |
| 1507 | qeth_l3_start_ipa_checksum(card); /* go on*/ |
| 1508 | qeth_l3_start_ipa_tso(card); /* go on*/ |
| 1509 | return 0; |
| 1510 | } |
| 1511 | |
| 1512 | static int qeth_l3_put_unique_id(struct qeth_card *card) |
| 1513 | { |
| 1514 | |
| 1515 | int rc = 0; |
| 1516 | struct qeth_cmd_buffer *iob; |
| 1517 | struct qeth_ipa_cmd *cmd; |
| 1518 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1519 | QETH_DBF_TEXT(TRACE, 2, "puniqeid"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1520 | |
| 1521 | if ((card->info.unique_id & UNIQUE_ID_NOT_BY_CARD) == |
| 1522 | UNIQUE_ID_NOT_BY_CARD) |
| 1523 | return -1; |
| 1524 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_DESTROY_ADDR, |
| 1525 | QETH_PROT_IPV6); |
| 1526 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1527 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 1528 | card->info.unique_id; |
| 1529 | memcpy(&cmd->data.create_destroy_addr.unique_id[0], |
| 1530 | card->dev->dev_addr, OSA_ADDR_LEN); |
| 1531 | rc = qeth_send_ipa_cmd(card, iob, NULL, NULL); |
| 1532 | return rc; |
| 1533 | } |
| 1534 | |
| 1535 | static int qeth_l3_iqd_read_initial_mac_cb(struct qeth_card *card, |
| 1536 | struct qeth_reply *reply, unsigned long data) |
| 1537 | { |
| 1538 | struct qeth_ipa_cmd *cmd; |
| 1539 | |
| 1540 | cmd = (struct qeth_ipa_cmd *) data; |
| 1541 | if (cmd->hdr.return_code == 0) |
| 1542 | memcpy(card->dev->dev_addr, |
| 1543 | cmd->data.create_destroy_addr.unique_id, ETH_ALEN); |
| 1544 | else |
| 1545 | random_ether_addr(card->dev->dev_addr); |
| 1546 | |
| 1547 | return 0; |
| 1548 | } |
| 1549 | |
| 1550 | static int qeth_l3_iqd_read_initial_mac(struct qeth_card *card) |
| 1551 | { |
| 1552 | int rc = 0; |
| 1553 | struct qeth_cmd_buffer *iob; |
| 1554 | struct qeth_ipa_cmd *cmd; |
| 1555 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1556 | QETH_DBF_TEXT(SETUP, 2, "hsrmac"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1557 | |
| 1558 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, |
| 1559 | QETH_PROT_IPV6); |
| 1560 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1561 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 1562 | card->info.unique_id; |
| 1563 | |
| 1564 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_iqd_read_initial_mac_cb, |
| 1565 | NULL); |
| 1566 | return rc; |
| 1567 | } |
| 1568 | |
| 1569 | static int qeth_l3_get_unique_id_cb(struct qeth_card *card, |
| 1570 | struct qeth_reply *reply, unsigned long data) |
| 1571 | { |
| 1572 | struct qeth_ipa_cmd *cmd; |
| 1573 | |
| 1574 | cmd = (struct qeth_ipa_cmd *) data; |
| 1575 | if (cmd->hdr.return_code == 0) |
| 1576 | card->info.unique_id = *((__u16 *) |
| 1577 | &cmd->data.create_destroy_addr.unique_id[6]); |
| 1578 | else { |
| 1579 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 1580 | UNIQUE_ID_NOT_BY_CARD; |
| 1581 | PRINT_WARN("couldn't get a unique id from the card on device " |
| 1582 | "%s (result=x%x), using default id. ipv6 " |
| 1583 | "autoconfig on other lpars may lead to duplicate " |
| 1584 | "ip addresses. please use manually " |
| 1585 | "configured ones.\n", |
| 1586 | CARD_BUS_ID(card), cmd->hdr.return_code); |
| 1587 | } |
| 1588 | return 0; |
| 1589 | } |
| 1590 | |
| 1591 | static int qeth_l3_get_unique_id(struct qeth_card *card) |
| 1592 | { |
| 1593 | int rc = 0; |
| 1594 | struct qeth_cmd_buffer *iob; |
| 1595 | struct qeth_ipa_cmd *cmd; |
| 1596 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1597 | QETH_DBF_TEXT(SETUP, 2, "guniqeid"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1598 | |
| 1599 | if (!qeth_is_supported(card, IPA_IPV6)) { |
| 1600 | card->info.unique_id = UNIQUE_ID_IF_CREATE_ADDR_FAILED | |
| 1601 | UNIQUE_ID_NOT_BY_CARD; |
| 1602 | return 0; |
| 1603 | } |
| 1604 | |
| 1605 | iob = qeth_get_ipacmd_buffer(card, IPA_CMD_CREATE_ADDR, |
| 1606 | QETH_PROT_IPV6); |
| 1607 | cmd = (struct qeth_ipa_cmd *)(iob->data+IPA_PDU_HEADER_SIZE); |
| 1608 | *((__u16 *) &cmd->data.create_destroy_addr.unique_id[6]) = |
| 1609 | card->info.unique_id; |
| 1610 | |
| 1611 | rc = qeth_send_ipa_cmd(card, iob, qeth_l3_get_unique_id_cb, NULL); |
| 1612 | return rc; |
| 1613 | } |
| 1614 | |
| 1615 | static void qeth_l3_get_mac_for_ipm(__u32 ipm, char *mac, |
| 1616 | struct net_device *dev) |
| 1617 | { |
| 1618 | if (dev->type == ARPHRD_IEEE802_TR) |
| 1619 | ip_tr_mc_map(ipm, mac); |
| 1620 | else |
| 1621 | ip_eth_mc_map(ipm, mac); |
| 1622 | } |
| 1623 | |
| 1624 | static void qeth_l3_add_mc(struct qeth_card *card, struct in_device *in4_dev) |
| 1625 | { |
| 1626 | struct qeth_ipaddr *ipm; |
| 1627 | struct ip_mc_list *im4; |
| 1628 | char buf[MAX_ADDR_LEN]; |
| 1629 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1630 | QETH_DBF_TEXT(TRACE, 4, "addmc"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1631 | for (im4 = in4_dev->mc_list; im4; im4 = im4->next) { |
| 1632 | qeth_l3_get_mac_for_ipm(im4->multiaddr, buf, in4_dev->dev); |
| 1633 | ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); |
| 1634 | if (!ipm) |
| 1635 | continue; |
| 1636 | ipm->u.a4.addr = im4->multiaddr; |
| 1637 | memcpy(ipm->mac, buf, OSA_ADDR_LEN); |
| 1638 | ipm->is_multicast = 1; |
| 1639 | if (!qeth_l3_add_ip(card, ipm)) |
| 1640 | kfree(ipm); |
| 1641 | } |
| 1642 | } |
| 1643 | |
| 1644 | static void qeth_l3_add_vlan_mc(struct qeth_card *card) |
| 1645 | { |
| 1646 | struct in_device *in_dev; |
| 1647 | struct vlan_group *vg; |
| 1648 | int i; |
| 1649 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1650 | QETH_DBF_TEXT(TRACE, 4, "addmcvl"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1651 | if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL)) |
| 1652 | return; |
| 1653 | |
| 1654 | vg = card->vlangrp; |
| 1655 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 1656 | struct net_device *netdev = vlan_group_get_device(vg, i); |
| 1657 | if (netdev == NULL || |
| 1658 | !(netdev->flags & IFF_UP)) |
| 1659 | continue; |
| 1660 | in_dev = in_dev_get(netdev); |
| 1661 | if (!in_dev) |
| 1662 | continue; |
| 1663 | read_lock(&in_dev->mc_list_lock); |
| 1664 | qeth_l3_add_mc(card, in_dev); |
| 1665 | read_unlock(&in_dev->mc_list_lock); |
| 1666 | in_dev_put(in_dev); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | static void qeth_l3_add_multicast_ipv4(struct qeth_card *card) |
| 1671 | { |
| 1672 | struct in_device *in4_dev; |
| 1673 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1674 | QETH_DBF_TEXT(TRACE, 4, "chkmcv4"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1675 | in4_dev = in_dev_get(card->dev); |
| 1676 | if (in4_dev == NULL) |
| 1677 | return; |
| 1678 | read_lock(&in4_dev->mc_list_lock); |
| 1679 | qeth_l3_add_mc(card, in4_dev); |
| 1680 | qeth_l3_add_vlan_mc(card); |
| 1681 | read_unlock(&in4_dev->mc_list_lock); |
| 1682 | in_dev_put(in4_dev); |
| 1683 | } |
| 1684 | |
| 1685 | #ifdef CONFIG_QETH_IPV6 |
| 1686 | static void qeth_l3_add_mc6(struct qeth_card *card, struct inet6_dev *in6_dev) |
| 1687 | { |
| 1688 | struct qeth_ipaddr *ipm; |
| 1689 | struct ifmcaddr6 *im6; |
| 1690 | char buf[MAX_ADDR_LEN]; |
| 1691 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1692 | QETH_DBF_TEXT(TRACE, 4, "addmc6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1693 | for (im6 = in6_dev->mc_list; im6 != NULL; im6 = im6->next) { |
| 1694 | ndisc_mc_map(&im6->mca_addr, buf, in6_dev->dev, 0); |
| 1695 | ipm = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); |
| 1696 | if (!ipm) |
| 1697 | continue; |
| 1698 | ipm->is_multicast = 1; |
| 1699 | memcpy(ipm->mac, buf, OSA_ADDR_LEN); |
| 1700 | memcpy(&ipm->u.a6.addr, &im6->mca_addr.s6_addr, |
| 1701 | sizeof(struct in6_addr)); |
| 1702 | if (!qeth_l3_add_ip(card, ipm)) |
| 1703 | kfree(ipm); |
| 1704 | } |
| 1705 | } |
| 1706 | |
| 1707 | static void qeth_l3_add_vlan_mc6(struct qeth_card *card) |
| 1708 | { |
| 1709 | struct inet6_dev *in_dev; |
| 1710 | struct vlan_group *vg; |
| 1711 | int i; |
| 1712 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1713 | QETH_DBF_TEXT(TRACE, 4, "admc6vl"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1714 | if (!qeth_is_supported(card, IPA_FULL_VLAN) || (card->vlangrp == NULL)) |
| 1715 | return; |
| 1716 | |
| 1717 | vg = card->vlangrp; |
| 1718 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 1719 | struct net_device *netdev = vlan_group_get_device(vg, i); |
| 1720 | if (netdev == NULL || |
| 1721 | !(netdev->flags & IFF_UP)) |
| 1722 | continue; |
| 1723 | in_dev = in6_dev_get(netdev); |
| 1724 | if (!in_dev) |
| 1725 | continue; |
| 1726 | read_lock_bh(&in_dev->lock); |
| 1727 | qeth_l3_add_mc6(card, in_dev); |
| 1728 | read_unlock_bh(&in_dev->lock); |
| 1729 | in6_dev_put(in_dev); |
| 1730 | } |
| 1731 | } |
| 1732 | |
| 1733 | static void qeth_l3_add_multicast_ipv6(struct qeth_card *card) |
| 1734 | { |
| 1735 | struct inet6_dev *in6_dev; |
| 1736 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1737 | QETH_DBF_TEXT(TRACE, 4, "chkmcv6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1738 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 1739 | return ; |
| 1740 | in6_dev = in6_dev_get(card->dev); |
| 1741 | if (in6_dev == NULL) |
| 1742 | return; |
| 1743 | read_lock_bh(&in6_dev->lock); |
| 1744 | qeth_l3_add_mc6(card, in6_dev); |
| 1745 | qeth_l3_add_vlan_mc6(card); |
| 1746 | read_unlock_bh(&in6_dev->lock); |
| 1747 | in6_dev_put(in6_dev); |
| 1748 | } |
| 1749 | #endif /* CONFIG_QETH_IPV6 */ |
| 1750 | |
| 1751 | static void qeth_l3_free_vlan_addresses4(struct qeth_card *card, |
| 1752 | unsigned short vid) |
| 1753 | { |
| 1754 | struct in_device *in_dev; |
| 1755 | struct in_ifaddr *ifa; |
| 1756 | struct qeth_ipaddr *addr; |
| 1757 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1758 | QETH_DBF_TEXT(TRACE, 4, "frvaddr4"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1759 | |
| 1760 | in_dev = in_dev_get(vlan_group_get_device(card->vlangrp, vid)); |
| 1761 | if (!in_dev) |
| 1762 | return; |
| 1763 | for (ifa = in_dev->ifa_list; ifa; ifa = ifa->ifa_next) { |
| 1764 | addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); |
| 1765 | if (addr) { |
| 1766 | addr->u.a4.addr = ifa->ifa_address; |
| 1767 | addr->u.a4.mask = ifa->ifa_mask; |
| 1768 | addr->type = QETH_IP_TYPE_NORMAL; |
| 1769 | if (!qeth_l3_delete_ip(card, addr)) |
| 1770 | kfree(addr); |
| 1771 | } |
| 1772 | } |
| 1773 | in_dev_put(in_dev); |
| 1774 | } |
| 1775 | |
| 1776 | static void qeth_l3_free_vlan_addresses6(struct qeth_card *card, |
| 1777 | unsigned short vid) |
| 1778 | { |
| 1779 | #ifdef CONFIG_QETH_IPV6 |
| 1780 | struct inet6_dev *in6_dev; |
| 1781 | struct inet6_ifaddr *ifa; |
| 1782 | struct qeth_ipaddr *addr; |
| 1783 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1784 | QETH_DBF_TEXT(TRACE, 4, "frvaddr6"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1785 | |
| 1786 | in6_dev = in6_dev_get(vlan_group_get_device(card->vlangrp, vid)); |
| 1787 | if (!in6_dev) |
| 1788 | return; |
| 1789 | for (ifa = in6_dev->addr_list; ifa; ifa = ifa->lst_next) { |
| 1790 | addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); |
| 1791 | if (addr) { |
| 1792 | memcpy(&addr->u.a6.addr, &ifa->addr, |
| 1793 | sizeof(struct in6_addr)); |
| 1794 | addr->u.a6.pfxlen = ifa->prefix_len; |
| 1795 | addr->type = QETH_IP_TYPE_NORMAL; |
| 1796 | if (!qeth_l3_delete_ip(card, addr)) |
| 1797 | kfree(addr); |
| 1798 | } |
| 1799 | } |
| 1800 | in6_dev_put(in6_dev); |
| 1801 | #endif /* CONFIG_QETH_IPV6 */ |
| 1802 | } |
| 1803 | |
| 1804 | static void qeth_l3_free_vlan_addresses(struct qeth_card *card, |
| 1805 | unsigned short vid) |
| 1806 | { |
| 1807 | if (!card->vlangrp) |
| 1808 | return; |
| 1809 | qeth_l3_free_vlan_addresses4(card, vid); |
| 1810 | qeth_l3_free_vlan_addresses6(card, vid); |
| 1811 | } |
| 1812 | |
| 1813 | static void qeth_l3_vlan_rx_register(struct net_device *dev, |
| 1814 | struct vlan_group *grp) |
| 1815 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1816 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1817 | unsigned long flags; |
| 1818 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1819 | QETH_DBF_TEXT(TRACE, 4, "vlanreg"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1820 | spin_lock_irqsave(&card->vlanlock, flags); |
| 1821 | card->vlangrp = grp; |
| 1822 | spin_unlock_irqrestore(&card->vlanlock, flags); |
| 1823 | } |
| 1824 | |
| 1825 | static void qeth_l3_vlan_rx_add_vid(struct net_device *dev, unsigned short vid) |
| 1826 | { |
| 1827 | struct net_device *vlandev; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1828 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1829 | struct in_device *in_dev; |
| 1830 | |
| 1831 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 1832 | return; |
| 1833 | |
| 1834 | vlandev = vlan_group_get_device(card->vlangrp, vid); |
| 1835 | vlandev->neigh_setup = qeth_l3_neigh_setup; |
| 1836 | |
| 1837 | in_dev = in_dev_get(vlandev); |
| 1838 | #ifdef CONFIG_SYSCTL |
| 1839 | neigh_sysctl_unregister(in_dev->arp_parms); |
| 1840 | #endif |
| 1841 | neigh_parms_release(&arp_tbl, in_dev->arp_parms); |
| 1842 | |
| 1843 | in_dev->arp_parms = neigh_parms_alloc(vlandev, &arp_tbl); |
| 1844 | #ifdef CONFIG_SYSCTL |
| 1845 | neigh_sysctl_register(vlandev, in_dev->arp_parms, NET_IPV4, |
| 1846 | NET_IPV4_NEIGH, "ipv4", NULL, NULL); |
| 1847 | #endif |
| 1848 | in_dev_put(in_dev); |
| 1849 | return; |
| 1850 | } |
| 1851 | |
| 1852 | static void qeth_l3_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 1853 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 1854 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1855 | unsigned long flags; |
| 1856 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1857 | QETH_DBF_TEXT_(TRACE, 4, "kid:%d", vid); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1858 | spin_lock_irqsave(&card->vlanlock, flags); |
| 1859 | /* unregister IP addresses of vlan device */ |
| 1860 | qeth_l3_free_vlan_addresses(card, vid); |
| 1861 | vlan_group_set_device(card->vlangrp, vid, NULL); |
| 1862 | spin_unlock_irqrestore(&card->vlanlock, flags); |
| 1863 | qeth_l3_set_multicast_list(card->dev); |
| 1864 | } |
| 1865 | |
| 1866 | static inline __u16 qeth_l3_rebuild_skb(struct qeth_card *card, |
| 1867 | struct sk_buff *skb, struct qeth_hdr *hdr) |
| 1868 | { |
| 1869 | unsigned short vlan_id = 0; |
| 1870 | __be16 prot; |
| 1871 | struct iphdr *ip_hdr; |
| 1872 | unsigned char tg_addr[MAX_ADDR_LEN]; |
| 1873 | |
| 1874 | if (!(hdr->hdr.l3.flags & QETH_HDR_PASSTHRU)) { |
| 1875 | prot = htons((hdr->hdr.l3.flags & QETH_HDR_IPV6)? ETH_P_IPV6 : |
| 1876 | ETH_P_IP); |
| 1877 | switch (hdr->hdr.l3.flags & QETH_HDR_CAST_MASK) { |
| 1878 | case QETH_CAST_MULTICAST: |
| 1879 | switch (prot) { |
| 1880 | #ifdef CONFIG_QETH_IPV6 |
| 1881 | case __constant_htons(ETH_P_IPV6): |
| 1882 | ndisc_mc_map((struct in6_addr *) |
| 1883 | skb->data + 24, |
| 1884 | tg_addr, card->dev, 0); |
| 1885 | break; |
| 1886 | #endif |
| 1887 | case __constant_htons(ETH_P_IP): |
| 1888 | ip_hdr = (struct iphdr *)skb->data; |
| 1889 | (card->dev->type == ARPHRD_IEEE802_TR) ? |
| 1890 | ip_tr_mc_map(ip_hdr->daddr, tg_addr): |
| 1891 | ip_eth_mc_map(ip_hdr->daddr, tg_addr); |
| 1892 | break; |
| 1893 | default: |
| 1894 | memcpy(tg_addr, card->dev->broadcast, |
| 1895 | card->dev->addr_len); |
| 1896 | } |
| 1897 | card->stats.multicast++; |
| 1898 | skb->pkt_type = PACKET_MULTICAST; |
| 1899 | break; |
| 1900 | case QETH_CAST_BROADCAST: |
| 1901 | memcpy(tg_addr, card->dev->broadcast, |
| 1902 | card->dev->addr_len); |
| 1903 | card->stats.multicast++; |
| 1904 | skb->pkt_type = PACKET_BROADCAST; |
| 1905 | break; |
| 1906 | case QETH_CAST_UNICAST: |
| 1907 | case QETH_CAST_ANYCAST: |
| 1908 | case QETH_CAST_NOCAST: |
| 1909 | default: |
| 1910 | skb->pkt_type = PACKET_HOST; |
| 1911 | memcpy(tg_addr, card->dev->dev_addr, |
| 1912 | card->dev->addr_len); |
| 1913 | } |
| 1914 | card->dev->header_ops->create(skb, card->dev, prot, tg_addr, |
| 1915 | "FAKELL", card->dev->addr_len); |
| 1916 | } |
| 1917 | |
| 1918 | #ifdef CONFIG_TR |
| 1919 | if (card->dev->type == ARPHRD_IEEE802_TR) |
| 1920 | skb->protocol = tr_type_trans(skb, card->dev); |
| 1921 | else |
| 1922 | #endif |
| 1923 | skb->protocol = eth_type_trans(skb, card->dev); |
| 1924 | |
| 1925 | if (hdr->hdr.l3.ext_flags & |
| 1926 | (QETH_HDR_EXT_VLAN_FRAME | QETH_HDR_EXT_INCLUDE_VLAN_TAG)) { |
| 1927 | vlan_id = (hdr->hdr.l3.ext_flags & QETH_HDR_EXT_VLAN_FRAME)? |
| 1928 | hdr->hdr.l3.vlan_id : *((u16 *)&hdr->hdr.l3.dest_addr[12]); |
| 1929 | } |
| 1930 | |
| 1931 | skb->ip_summed = card->options.checksum_type; |
| 1932 | if (card->options.checksum_type == HW_CHECKSUMMING) { |
| 1933 | if ((hdr->hdr.l3.ext_flags & |
| 1934 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 1935 | QETH_HDR_EXT_CSUM_TRANSP_REQ)) == |
| 1936 | (QETH_HDR_EXT_CSUM_HDR_REQ | |
| 1937 | QETH_HDR_EXT_CSUM_TRANSP_REQ)) |
| 1938 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1939 | else |
| 1940 | skb->ip_summed = SW_CHECKSUMMING; |
| 1941 | } |
| 1942 | |
| 1943 | return vlan_id; |
| 1944 | } |
| 1945 | |
| 1946 | static void qeth_l3_process_inbound_buffer(struct qeth_card *card, |
| 1947 | struct qeth_qdio_buffer *buf, int index) |
| 1948 | { |
| 1949 | struct qdio_buffer_element *element; |
| 1950 | struct sk_buff *skb; |
| 1951 | struct qeth_hdr *hdr; |
| 1952 | int offset; |
| 1953 | __u16 vlan_tag = 0; |
| 1954 | unsigned int len; |
| 1955 | |
| 1956 | /* get first element of current buffer */ |
| 1957 | element = (struct qdio_buffer_element *)&buf->buffer->element[0]; |
| 1958 | offset = 0; |
| 1959 | if (card->options.performance_stats) |
| 1960 | card->perf_stats.bufs_rec++; |
| 1961 | while ((skb = qeth_core_get_next_skb(card, buf->buffer, &element, |
| 1962 | &offset, &hdr))) { |
| 1963 | skb->dev = card->dev; |
| 1964 | /* is device UP ? */ |
| 1965 | if (!(card->dev->flags & IFF_UP)) { |
| 1966 | dev_kfree_skb_any(skb); |
| 1967 | continue; |
| 1968 | } |
| 1969 | |
| 1970 | switch (hdr->hdr.l3.id) { |
| 1971 | case QETH_HEADER_TYPE_LAYER3: |
| 1972 | vlan_tag = qeth_l3_rebuild_skb(card, skb, hdr); |
| 1973 | len = skb->len; |
| 1974 | if (vlan_tag) |
| 1975 | if (card->vlangrp) |
| 1976 | vlan_hwaccel_rx(skb, card->vlangrp, |
| 1977 | vlan_tag); |
| 1978 | else { |
| 1979 | dev_kfree_skb_any(skb); |
| 1980 | continue; |
| 1981 | } |
| 1982 | else |
| 1983 | netif_rx(skb); |
| 1984 | break; |
| 1985 | default: |
| 1986 | dev_kfree_skb_any(skb); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 1987 | QETH_DBF_TEXT(TRACE, 3, "inbunkno"); |
| 1988 | QETH_DBF_HEX(CTRL, 3, hdr, QETH_DBF_CTRL_LEN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 1989 | continue; |
| 1990 | } |
| 1991 | |
| 1992 | card->dev->last_rx = jiffies; |
| 1993 | card->stats.rx_packets++; |
| 1994 | card->stats.rx_bytes += len; |
| 1995 | } |
| 1996 | } |
| 1997 | |
| 1998 | static int qeth_l3_verify_vlan_dev(struct net_device *dev, |
| 1999 | struct qeth_card *card) |
| 2000 | { |
| 2001 | int rc = 0; |
| 2002 | struct vlan_group *vg; |
| 2003 | int i; |
| 2004 | |
| 2005 | vg = card->vlangrp; |
| 2006 | if (!vg) |
| 2007 | return rc; |
| 2008 | |
| 2009 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 2010 | if (vlan_group_get_device(vg, i) == dev) { |
| 2011 | rc = QETH_VLAN_CARD; |
| 2012 | break; |
| 2013 | } |
| 2014 | } |
| 2015 | |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2016 | if (rc && !(vlan_dev_real_dev(dev)->ml_priv == (void *)card)) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2017 | return 0; |
| 2018 | |
| 2019 | return rc; |
| 2020 | } |
| 2021 | |
| 2022 | static int qeth_l3_verify_dev(struct net_device *dev) |
| 2023 | { |
| 2024 | struct qeth_card *card; |
| 2025 | unsigned long flags; |
| 2026 | int rc = 0; |
| 2027 | |
| 2028 | read_lock_irqsave(&qeth_core_card_list.rwlock, flags); |
| 2029 | list_for_each_entry(card, &qeth_core_card_list.list, list) { |
| 2030 | if (card->dev == dev) { |
| 2031 | rc = QETH_REAL_CARD; |
| 2032 | break; |
| 2033 | } |
| 2034 | rc = qeth_l3_verify_vlan_dev(dev, card); |
| 2035 | if (rc) |
| 2036 | break; |
| 2037 | } |
| 2038 | read_unlock_irqrestore(&qeth_core_card_list.rwlock, flags); |
| 2039 | |
| 2040 | return rc; |
| 2041 | } |
| 2042 | |
| 2043 | static struct qeth_card *qeth_l3_get_card_from_dev(struct net_device *dev) |
| 2044 | { |
| 2045 | struct qeth_card *card = NULL; |
| 2046 | int rc; |
| 2047 | |
| 2048 | rc = qeth_l3_verify_dev(dev); |
| 2049 | if (rc == QETH_REAL_CARD) |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2050 | card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2051 | else if (rc == QETH_VLAN_CARD) |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2052 | card = vlan_dev_real_dev(dev)->ml_priv; |
Frank Blaschka | e5bd7be | 2008-06-06 12:37:44 +0200 | [diff] [blame] | 2053 | if (card && card->options.layer2) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2054 | card = NULL; |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2055 | QETH_DBF_TEXT_(TRACE, 4, "%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2056 | return card ; |
| 2057 | } |
| 2058 | |
| 2059 | static int qeth_l3_stop_card(struct qeth_card *card, int recovery_mode) |
| 2060 | { |
| 2061 | int rc = 0; |
| 2062 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2063 | QETH_DBF_TEXT(SETUP, 2, "stopcard"); |
| 2064 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2065 | |
| 2066 | qeth_set_allowed_threads(card, 0, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2067 | if (card->read.state == CH_STATE_UP && |
| 2068 | card->write.state == CH_STATE_UP && |
| 2069 | (card->state == CARD_STATE_UP)) { |
| 2070 | if (recovery_mode) |
| 2071 | qeth_l3_stop(card->dev); |
Frank Blaschka | 8af7c5a | 2008-04-24 10:15:25 +0200 | [diff] [blame] | 2072 | else { |
| 2073 | rtnl_lock(); |
| 2074 | dev_close(card->dev); |
| 2075 | rtnl_unlock(); |
| 2076 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2077 | if (!card->use_hard_stop) { |
| 2078 | rc = qeth_send_stoplan(card); |
| 2079 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2080 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2081 | } |
| 2082 | card->state = CARD_STATE_SOFTSETUP; |
| 2083 | } |
| 2084 | if (card->state == CARD_STATE_SOFTSETUP) { |
| 2085 | qeth_l3_clear_ip_list(card, !card->use_hard_stop, 1); |
| 2086 | qeth_clear_ipacmd_list(card); |
| 2087 | card->state = CARD_STATE_HARDSETUP; |
| 2088 | } |
| 2089 | if (card->state == CARD_STATE_HARDSETUP) { |
| 2090 | if (!card->use_hard_stop && |
| 2091 | (card->info.type != QETH_CARD_TYPE_IQD)) { |
| 2092 | rc = qeth_l3_put_unique_id(card); |
| 2093 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2094 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2095 | } |
| 2096 | qeth_qdio_clear_card(card, 0); |
| 2097 | qeth_clear_qdio_buffers(card); |
| 2098 | qeth_clear_working_pool_list(card); |
| 2099 | card->state = CARD_STATE_DOWN; |
| 2100 | } |
| 2101 | if (card->state == CARD_STATE_DOWN) { |
| 2102 | qeth_clear_cmd_buffers(&card->read); |
| 2103 | qeth_clear_cmd_buffers(&card->write); |
| 2104 | } |
| 2105 | card->use_hard_stop = 0; |
| 2106 | return rc; |
| 2107 | } |
| 2108 | |
| 2109 | static void qeth_l3_set_multicast_list(struct net_device *dev) |
| 2110 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2111 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2112 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2113 | QETH_DBF_TEXT(TRACE, 3, "setmulti"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2114 | qeth_l3_delete_mc_addresses(card); |
| 2115 | qeth_l3_add_multicast_ipv4(card); |
| 2116 | #ifdef CONFIG_QETH_IPV6 |
| 2117 | qeth_l3_add_multicast_ipv6(card); |
| 2118 | #endif |
| 2119 | qeth_l3_set_ip_addr_list(card); |
| 2120 | if (!qeth_adp_supported(card, IPA_SETADP_SET_PROMISC_MODE)) |
| 2121 | return; |
| 2122 | qeth_setadp_promisc_mode(card); |
| 2123 | } |
| 2124 | |
| 2125 | static const char *qeth_l3_arp_get_error_cause(int *rc) |
| 2126 | { |
| 2127 | switch (*rc) { |
| 2128 | case QETH_IPA_ARP_RC_FAILED: |
| 2129 | *rc = -EIO; |
| 2130 | return "operation failed"; |
| 2131 | case QETH_IPA_ARP_RC_NOTSUPP: |
| 2132 | *rc = -EOPNOTSUPP; |
| 2133 | return "operation not supported"; |
| 2134 | case QETH_IPA_ARP_RC_OUT_OF_RANGE: |
| 2135 | *rc = -EINVAL; |
| 2136 | return "argument out of range"; |
| 2137 | case QETH_IPA_ARP_RC_Q_NOTSUPP: |
| 2138 | *rc = -EOPNOTSUPP; |
| 2139 | return "query operation not supported"; |
| 2140 | case QETH_IPA_ARP_RC_Q_NO_DATA: |
| 2141 | *rc = -ENOENT; |
| 2142 | return "no query data available"; |
| 2143 | default: |
| 2144 | return "unknown error"; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | static int qeth_l3_arp_set_no_entries(struct qeth_card *card, int no_entries) |
| 2149 | { |
| 2150 | int tmp; |
| 2151 | int rc; |
| 2152 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2153 | QETH_DBF_TEXT(TRACE, 3, "arpstnoe"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2154 | |
| 2155 | /* |
| 2156 | * currently GuestLAN only supports the ARP assist function |
| 2157 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_SET_NO_ENTRIES; |
| 2158 | * thus we say EOPNOTSUPP for this ARP function |
| 2159 | */ |
| 2160 | if (card->info.guestlan) |
| 2161 | return -EOPNOTSUPP; |
| 2162 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2163 | return -EOPNOTSUPP; |
| 2164 | } |
| 2165 | rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 2166 | IPA_CMD_ASS_ARP_SET_NO_ENTRIES, |
| 2167 | no_entries); |
| 2168 | if (rc) { |
| 2169 | tmp = rc; |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 2170 | QETH_DBF_MESSAGE(2, "Could not set number of ARP entries on " |
| 2171 | "%s: %s (0x%x/%d)\n", QETH_CARD_IFNAME(card), |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2172 | qeth_l3_arp_get_error_cause(&rc), tmp, tmp); |
| 2173 | } |
| 2174 | return rc; |
| 2175 | } |
| 2176 | |
| 2177 | static void qeth_l3_copy_arp_entries_stripped(struct qeth_arp_query_info *qinfo, |
| 2178 | struct qeth_arp_query_data *qdata, int entry_size, |
| 2179 | int uentry_size) |
| 2180 | { |
| 2181 | char *entry_ptr; |
| 2182 | char *uentry_ptr; |
| 2183 | int i; |
| 2184 | |
| 2185 | entry_ptr = (char *)&qdata->data; |
| 2186 | uentry_ptr = (char *)(qinfo->udata + qinfo->udata_offset); |
| 2187 | for (i = 0; i < qdata->no_entries; ++i) { |
| 2188 | /* strip off 32 bytes "media specific information" */ |
| 2189 | memcpy(uentry_ptr, (entry_ptr + 32), entry_size - 32); |
| 2190 | entry_ptr += entry_size; |
| 2191 | uentry_ptr += uentry_size; |
| 2192 | } |
| 2193 | } |
| 2194 | |
| 2195 | static int qeth_l3_arp_query_cb(struct qeth_card *card, |
| 2196 | struct qeth_reply *reply, unsigned long data) |
| 2197 | { |
| 2198 | struct qeth_ipa_cmd *cmd; |
| 2199 | struct qeth_arp_query_data *qdata; |
| 2200 | struct qeth_arp_query_info *qinfo; |
| 2201 | int entry_size; |
| 2202 | int uentry_size; |
| 2203 | int i; |
| 2204 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2205 | QETH_DBF_TEXT(TRACE, 4, "arpquecb"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2206 | |
| 2207 | qinfo = (struct qeth_arp_query_info *) reply->param; |
| 2208 | cmd = (struct qeth_ipa_cmd *) data; |
| 2209 | if (cmd->hdr.return_code) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2210 | QETH_DBF_TEXT_(TRACE, 4, "qaer1%i", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2211 | return 0; |
| 2212 | } |
| 2213 | if (cmd->data.setassparms.hdr.return_code) { |
| 2214 | cmd->hdr.return_code = cmd->data.setassparms.hdr.return_code; |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2215 | QETH_DBF_TEXT_(TRACE, 4, "qaer2%i", cmd->hdr.return_code); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2216 | return 0; |
| 2217 | } |
| 2218 | qdata = &cmd->data.setassparms.data.query_arp; |
| 2219 | switch (qdata->reply_bits) { |
| 2220 | case 5: |
| 2221 | uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry5); |
| 2222 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 2223 | uentry_size = sizeof(struct qeth_arp_qi_entry5_short); |
| 2224 | break; |
| 2225 | case 7: |
| 2226 | /* fall through to default */ |
| 2227 | default: |
| 2228 | /* tr is the same as eth -> entry7 */ |
| 2229 | uentry_size = entry_size = sizeof(struct qeth_arp_qi_entry7); |
| 2230 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 2231 | uentry_size = sizeof(struct qeth_arp_qi_entry7_short); |
| 2232 | break; |
| 2233 | } |
| 2234 | /* check if there is enough room in userspace */ |
| 2235 | if ((qinfo->udata_len - qinfo->udata_offset) < |
| 2236 | qdata->no_entries * uentry_size){ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2237 | QETH_DBF_TEXT_(TRACE, 4, "qaer3%i", -ENOMEM); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2238 | cmd->hdr.return_code = -ENOMEM; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2239 | goto out_error; |
| 2240 | } |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2241 | QETH_DBF_TEXT_(TRACE, 4, "anore%i", |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2242 | cmd->data.setassparms.hdr.number_of_replies); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2243 | QETH_DBF_TEXT_(TRACE, 4, "aseqn%i", cmd->data.setassparms.hdr.seq_no); |
| 2244 | QETH_DBF_TEXT_(TRACE, 4, "anoen%i", qdata->no_entries); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2245 | |
| 2246 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) { |
| 2247 | /* strip off "media specific information" */ |
| 2248 | qeth_l3_copy_arp_entries_stripped(qinfo, qdata, entry_size, |
| 2249 | uentry_size); |
| 2250 | } else |
| 2251 | /*copy entries to user buffer*/ |
| 2252 | memcpy(qinfo->udata + qinfo->udata_offset, |
| 2253 | (char *)&qdata->data, qdata->no_entries*uentry_size); |
| 2254 | |
| 2255 | qinfo->no_entries += qdata->no_entries; |
| 2256 | qinfo->udata_offset += (qdata->no_entries*uentry_size); |
| 2257 | /* check if all replies received ... */ |
| 2258 | if (cmd->data.setassparms.hdr.seq_no < |
| 2259 | cmd->data.setassparms.hdr.number_of_replies) |
| 2260 | return 1; |
| 2261 | memcpy(qinfo->udata, &qinfo->no_entries, 4); |
| 2262 | /* keep STRIP_ENTRIES flag so the user program can distinguish |
| 2263 | * stripped entries from normal ones */ |
| 2264 | if (qinfo->mask_bits & QETH_QARP_STRIP_ENTRIES) |
| 2265 | qdata->reply_bits |= QETH_QARP_STRIP_ENTRIES; |
| 2266 | memcpy(qinfo->udata + QETH_QARP_MASK_OFFSET, &qdata->reply_bits, 2); |
| 2267 | return 0; |
| 2268 | out_error: |
| 2269 | i = 0; |
| 2270 | memcpy(qinfo->udata, &i, 4); |
| 2271 | return 0; |
| 2272 | } |
| 2273 | |
| 2274 | static int qeth_l3_send_ipa_arp_cmd(struct qeth_card *card, |
| 2275 | struct qeth_cmd_buffer *iob, int len, |
| 2276 | int (*reply_cb)(struct qeth_card *, struct qeth_reply *, |
| 2277 | unsigned long), |
| 2278 | void *reply_param) |
| 2279 | { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2280 | QETH_DBF_TEXT(TRACE, 4, "sendarp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2281 | |
| 2282 | memcpy(iob->data, IPA_PDU_HEADER, IPA_PDU_HEADER_SIZE); |
| 2283 | memcpy(QETH_IPA_CMD_DEST_ADDR(iob->data), |
| 2284 | &card->token.ulp_connection_r, QETH_MPC_TOKEN_LENGTH); |
| 2285 | return qeth_send_control_data(card, IPA_PDU_HEADER_SIZE + len, iob, |
| 2286 | reply_cb, reply_param); |
| 2287 | } |
| 2288 | |
| 2289 | static int qeth_l3_arp_query(struct qeth_card *card, char __user *udata) |
| 2290 | { |
| 2291 | struct qeth_cmd_buffer *iob; |
| 2292 | struct qeth_arp_query_info qinfo = {0, }; |
| 2293 | int tmp; |
| 2294 | int rc; |
| 2295 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2296 | QETH_DBF_TEXT(TRACE, 3, "arpquery"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2297 | |
| 2298 | if (!qeth_is_supported(card,/*IPA_QUERY_ARP_ADDR_INFO*/ |
| 2299 | IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2300 | return -EOPNOTSUPP; |
| 2301 | } |
| 2302 | /* get size of userspace buffer and mask_bits -> 6 bytes */ |
| 2303 | if (copy_from_user(&qinfo, udata, 6)) |
| 2304 | return -EFAULT; |
| 2305 | qinfo.udata = kzalloc(qinfo.udata_len, GFP_KERNEL); |
| 2306 | if (!qinfo.udata) |
| 2307 | return -ENOMEM; |
| 2308 | qinfo.udata_offset = QETH_QARP_ENTRIES_OFFSET; |
| 2309 | iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 2310 | IPA_CMD_ASS_ARP_QUERY_INFO, |
| 2311 | sizeof(int), QETH_PROT_IPV4); |
| 2312 | |
| 2313 | rc = qeth_l3_send_ipa_arp_cmd(card, iob, |
| 2314 | QETH_SETASS_BASE_LEN+QETH_ARP_CMD_LEN, |
| 2315 | qeth_l3_arp_query_cb, (void *)&qinfo); |
| 2316 | if (rc) { |
| 2317 | tmp = rc; |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 2318 | QETH_DBF_MESSAGE(2, "Error while querying ARP cache on %s: %s " |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2319 | "(0x%x/%d)\n", QETH_CARD_IFNAME(card), |
| 2320 | qeth_l3_arp_get_error_cause(&rc), tmp, tmp); |
| 2321 | if (copy_to_user(udata, qinfo.udata, 4)) |
| 2322 | rc = -EFAULT; |
| 2323 | } else { |
| 2324 | if (copy_to_user(udata, qinfo.udata, qinfo.udata_len)) |
| 2325 | rc = -EFAULT; |
| 2326 | } |
| 2327 | kfree(qinfo.udata); |
| 2328 | return rc; |
| 2329 | } |
| 2330 | |
| 2331 | static int qeth_l3_arp_add_entry(struct qeth_card *card, |
| 2332 | struct qeth_arp_cache_entry *entry) |
| 2333 | { |
| 2334 | struct qeth_cmd_buffer *iob; |
| 2335 | char buf[16]; |
| 2336 | int tmp; |
| 2337 | int rc; |
| 2338 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2339 | QETH_DBF_TEXT(TRACE, 3, "arpadent"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2340 | |
| 2341 | /* |
| 2342 | * currently GuestLAN only supports the ARP assist function |
| 2343 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_ADD_ENTRY; |
| 2344 | * thus we say EOPNOTSUPP for this ARP function |
| 2345 | */ |
| 2346 | if (card->info.guestlan) |
| 2347 | return -EOPNOTSUPP; |
| 2348 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2349 | return -EOPNOTSUPP; |
| 2350 | } |
| 2351 | |
| 2352 | iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 2353 | IPA_CMD_ASS_ARP_ADD_ENTRY, |
| 2354 | sizeof(struct qeth_arp_cache_entry), |
| 2355 | QETH_PROT_IPV4); |
| 2356 | rc = qeth_l3_send_setassparms(card, iob, |
| 2357 | sizeof(struct qeth_arp_cache_entry), |
| 2358 | (unsigned long) entry, |
| 2359 | qeth_l3_default_setassparms_cb, NULL); |
| 2360 | if (rc) { |
| 2361 | tmp = rc; |
| 2362 | qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf); |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 2363 | QETH_DBF_MESSAGE(2, "Could not add ARP entry for address %s " |
| 2364 | "on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card), |
| 2365 | qeth_l3_arp_get_error_cause(&rc), tmp, tmp); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2366 | } |
| 2367 | return rc; |
| 2368 | } |
| 2369 | |
| 2370 | static int qeth_l3_arp_remove_entry(struct qeth_card *card, |
| 2371 | struct qeth_arp_cache_entry *entry) |
| 2372 | { |
| 2373 | struct qeth_cmd_buffer *iob; |
| 2374 | char buf[16] = {0, }; |
| 2375 | int tmp; |
| 2376 | int rc; |
| 2377 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2378 | QETH_DBF_TEXT(TRACE, 3, "arprment"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2379 | |
| 2380 | /* |
| 2381 | * currently GuestLAN only supports the ARP assist function |
| 2382 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_REMOVE_ENTRY; |
| 2383 | * thus we say EOPNOTSUPP for this ARP function |
| 2384 | */ |
| 2385 | if (card->info.guestlan) |
| 2386 | return -EOPNOTSUPP; |
| 2387 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2388 | return -EOPNOTSUPP; |
| 2389 | } |
| 2390 | memcpy(buf, entry, 12); |
| 2391 | iob = qeth_l3_get_setassparms_cmd(card, IPA_ARP_PROCESSING, |
| 2392 | IPA_CMD_ASS_ARP_REMOVE_ENTRY, |
| 2393 | 12, |
| 2394 | QETH_PROT_IPV4); |
| 2395 | rc = qeth_l3_send_setassparms(card, iob, |
| 2396 | 12, (unsigned long)buf, |
| 2397 | qeth_l3_default_setassparms_cb, NULL); |
| 2398 | if (rc) { |
| 2399 | tmp = rc; |
| 2400 | memset(buf, 0, 16); |
| 2401 | qeth_l3_ipaddr4_to_string((u8 *)entry->ipaddr, buf); |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 2402 | QETH_DBF_MESSAGE(2, "Could not delete ARP entry for address %s" |
| 2403 | " on %s: %s (0x%x/%d)\n", buf, QETH_CARD_IFNAME(card), |
| 2404 | qeth_l3_arp_get_error_cause(&rc), tmp, tmp); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2405 | } |
| 2406 | return rc; |
| 2407 | } |
| 2408 | |
| 2409 | static int qeth_l3_arp_flush_cache(struct qeth_card *card) |
| 2410 | { |
| 2411 | int rc; |
| 2412 | int tmp; |
| 2413 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2414 | QETH_DBF_TEXT(TRACE, 3, "arpflush"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2415 | |
| 2416 | /* |
| 2417 | * currently GuestLAN only supports the ARP assist function |
| 2418 | * IPA_CMD_ASS_ARP_QUERY_INFO, but not IPA_CMD_ASS_ARP_FLUSH_CACHE; |
| 2419 | * thus we say EOPNOTSUPP for this ARP function |
| 2420 | */ |
| 2421 | if (card->info.guestlan || (card->info.type == QETH_CARD_TYPE_IQD)) |
| 2422 | return -EOPNOTSUPP; |
| 2423 | if (!qeth_is_supported(card, IPA_ARP_PROCESSING)) { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2424 | return -EOPNOTSUPP; |
| 2425 | } |
| 2426 | rc = qeth_l3_send_simple_setassparms(card, IPA_ARP_PROCESSING, |
| 2427 | IPA_CMD_ASS_ARP_FLUSH_CACHE, 0); |
| 2428 | if (rc) { |
| 2429 | tmp = rc; |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 2430 | QETH_DBF_MESSAGE(2, "Could not flush ARP cache on %s: %s " |
| 2431 | "(0x%x/%d)\n", QETH_CARD_IFNAME(card), |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2432 | qeth_l3_arp_get_error_cause(&rc), tmp, tmp); |
| 2433 | } |
| 2434 | return rc; |
| 2435 | } |
| 2436 | |
| 2437 | static int qeth_l3_do_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
| 2438 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2439 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2440 | struct qeth_arp_cache_entry arp_entry; |
| 2441 | struct mii_ioctl_data *mii_data; |
| 2442 | int rc = 0; |
| 2443 | |
| 2444 | if (!card) |
| 2445 | return -ENODEV; |
| 2446 | |
| 2447 | if ((card->state != CARD_STATE_UP) && |
| 2448 | (card->state != CARD_STATE_SOFTSETUP)) |
| 2449 | return -ENODEV; |
| 2450 | |
| 2451 | switch (cmd) { |
| 2452 | case SIOC_QETH_ARP_SET_NO_ENTRIES: |
| 2453 | if (!capable(CAP_NET_ADMIN)) { |
| 2454 | rc = -EPERM; |
| 2455 | break; |
| 2456 | } |
| 2457 | rc = qeth_l3_arp_set_no_entries(card, rq->ifr_ifru.ifru_ivalue); |
| 2458 | break; |
| 2459 | case SIOC_QETH_ARP_QUERY_INFO: |
| 2460 | if (!capable(CAP_NET_ADMIN)) { |
| 2461 | rc = -EPERM; |
| 2462 | break; |
| 2463 | } |
| 2464 | rc = qeth_l3_arp_query(card, rq->ifr_ifru.ifru_data); |
| 2465 | break; |
| 2466 | case SIOC_QETH_ARP_ADD_ENTRY: |
| 2467 | if (!capable(CAP_NET_ADMIN)) { |
| 2468 | rc = -EPERM; |
| 2469 | break; |
| 2470 | } |
| 2471 | if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data, |
| 2472 | sizeof(struct qeth_arp_cache_entry))) |
| 2473 | rc = -EFAULT; |
| 2474 | else |
| 2475 | rc = qeth_l3_arp_add_entry(card, &arp_entry); |
| 2476 | break; |
| 2477 | case SIOC_QETH_ARP_REMOVE_ENTRY: |
| 2478 | if (!capable(CAP_NET_ADMIN)) { |
| 2479 | rc = -EPERM; |
| 2480 | break; |
| 2481 | } |
| 2482 | if (copy_from_user(&arp_entry, rq->ifr_ifru.ifru_data, |
| 2483 | sizeof(struct qeth_arp_cache_entry))) |
| 2484 | rc = -EFAULT; |
| 2485 | else |
| 2486 | rc = qeth_l3_arp_remove_entry(card, &arp_entry); |
| 2487 | break; |
| 2488 | case SIOC_QETH_ARP_FLUSH_CACHE: |
| 2489 | if (!capable(CAP_NET_ADMIN)) { |
| 2490 | rc = -EPERM; |
| 2491 | break; |
| 2492 | } |
| 2493 | rc = qeth_l3_arp_flush_cache(card); |
| 2494 | break; |
| 2495 | case SIOC_QETH_ADP_SET_SNMP_CONTROL: |
| 2496 | rc = qeth_snmp_command(card, rq->ifr_ifru.ifru_data); |
| 2497 | break; |
| 2498 | case SIOC_QETH_GET_CARD_TYPE: |
| 2499 | if ((card->info.type == QETH_CARD_TYPE_OSAE) && |
| 2500 | !card->info.guestlan) |
| 2501 | return 1; |
| 2502 | return 0; |
| 2503 | break; |
| 2504 | case SIOCGMIIPHY: |
| 2505 | mii_data = if_mii(rq); |
| 2506 | mii_data->phy_id = 0; |
| 2507 | break; |
| 2508 | case SIOCGMIIREG: |
| 2509 | mii_data = if_mii(rq); |
| 2510 | if (mii_data->phy_id != 0) |
| 2511 | rc = -EINVAL; |
| 2512 | else |
| 2513 | mii_data->val_out = qeth_mdio_read(dev, |
| 2514 | mii_data->phy_id, |
| 2515 | mii_data->reg_num); |
| 2516 | break; |
| 2517 | default: |
| 2518 | rc = -EOPNOTSUPP; |
| 2519 | } |
| 2520 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2521 | QETH_DBF_TEXT_(TRACE, 2, "ioce%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2522 | return rc; |
| 2523 | } |
| 2524 | |
| 2525 | static void qeth_l3_fill_header(struct qeth_card *card, struct qeth_hdr *hdr, |
| 2526 | struct sk_buff *skb, int ipv, int cast_type) |
| 2527 | { |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2528 | memset(hdr, 0, sizeof(struct qeth_hdr)); |
| 2529 | hdr->hdr.l3.id = QETH_HEADER_TYPE_LAYER3; |
| 2530 | hdr->hdr.l3.ext_flags = 0; |
| 2531 | |
| 2532 | /* |
| 2533 | * before we're going to overwrite this location with next hop ip. |
| 2534 | * v6 uses passthrough, v4 sets the tag in the QDIO header. |
| 2535 | */ |
| 2536 | if (card->vlangrp && vlan_tx_tag_present(skb)) { |
Frank Blaschka | 213298f | 2008-04-24 10:15:22 +0200 | [diff] [blame] | 2537 | if ((ipv == 4) || (card->info.type == QETH_CARD_TYPE_IQD)) |
| 2538 | hdr->hdr.l3.ext_flags = QETH_HDR_EXT_VLAN_FRAME; |
| 2539 | else |
| 2540 | hdr->hdr.l3.ext_flags = QETH_HDR_EXT_INCLUDE_VLAN_TAG; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2541 | hdr->hdr.l3.vlan_id = vlan_tx_tag_get(skb); |
| 2542 | } |
| 2543 | |
| 2544 | hdr->hdr.l3.length = skb->len - sizeof(struct qeth_hdr); |
| 2545 | if (ipv == 4) { |
| 2546 | /* IPv4 */ |
| 2547 | hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags4(cast_type); |
| 2548 | memset(hdr->hdr.l3.dest_addr, 0, 12); |
| 2549 | if ((skb->dst) && (skb->dst->neighbour)) { |
| 2550 | *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = |
| 2551 | *((u32 *) skb->dst->neighbour->primary_key); |
| 2552 | } else { |
| 2553 | /* fill in destination address used in ip header */ |
| 2554 | *((u32 *) (&hdr->hdr.l3.dest_addr[12])) = |
| 2555 | ip_hdr(skb)->daddr; |
| 2556 | } |
| 2557 | } else if (ipv == 6) { |
| 2558 | /* IPv6 */ |
| 2559 | hdr->hdr.l3.flags = qeth_l3_get_qeth_hdr_flags6(cast_type); |
| 2560 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 2561 | hdr->hdr.l3.flags &= ~QETH_HDR_PASSTHRU; |
| 2562 | if ((skb->dst) && (skb->dst->neighbour)) { |
| 2563 | memcpy(hdr->hdr.l3.dest_addr, |
| 2564 | skb->dst->neighbour->primary_key, 16); |
| 2565 | } else { |
| 2566 | /* fill in destination address used in ip header */ |
| 2567 | memcpy(hdr->hdr.l3.dest_addr, |
| 2568 | &ipv6_hdr(skb)->daddr, 16); |
| 2569 | } |
| 2570 | } else { |
| 2571 | /* passthrough */ |
| 2572 | if ((skb->dev->type == ARPHRD_IEEE802_TR) && |
| 2573 | !memcmp(skb->data + sizeof(struct qeth_hdr) + |
| 2574 | sizeof(__u16), skb->dev->broadcast, 6)) { |
| 2575 | hdr->hdr.l3.flags = QETH_CAST_BROADCAST | |
| 2576 | QETH_HDR_PASSTHRU; |
| 2577 | } else if (!memcmp(skb->data + sizeof(struct qeth_hdr), |
| 2578 | skb->dev->broadcast, 6)) { |
| 2579 | /* broadcast? */ |
| 2580 | hdr->hdr.l3.flags = QETH_CAST_BROADCAST | |
| 2581 | QETH_HDR_PASSTHRU; |
| 2582 | } else { |
| 2583 | hdr->hdr.l3.flags = (cast_type == RTN_MULTICAST) ? |
| 2584 | QETH_CAST_MULTICAST | QETH_HDR_PASSTHRU : |
| 2585 | QETH_CAST_UNICAST | QETH_HDR_PASSTHRU; |
| 2586 | } |
| 2587 | } |
| 2588 | } |
| 2589 | |
| 2590 | static int qeth_l3_hard_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 2591 | { |
| 2592 | int rc; |
| 2593 | u16 *tag; |
| 2594 | struct qeth_hdr *hdr = NULL; |
| 2595 | int elements_needed = 0; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2596 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2597 | struct sk_buff *new_skb = NULL; |
| 2598 | int ipv = qeth_get_ip_version(skb); |
| 2599 | int cast_type = qeth_get_cast_type(card, skb); |
| 2600 | struct qeth_qdio_out_q *queue = card->qdio.out_qs |
| 2601 | [qeth_get_priority_queue(card, skb, ipv, cast_type)]; |
| 2602 | int tx_bytes = skb->len; |
| 2603 | enum qeth_large_send_types large_send = QETH_LARGE_SEND_NO; |
| 2604 | struct qeth_eddp_context *ctx = NULL; |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2605 | int data_offset = -1; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2606 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2607 | if ((card->info.type == QETH_CARD_TYPE_IQD) && |
| 2608 | (skb->protocol != htons(ETH_P_IPV6)) && |
| 2609 | (skb->protocol != htons(ETH_P_IP))) |
| 2610 | goto tx_drop; |
| 2611 | |
| 2612 | if ((card->state != CARD_STATE_UP) || !card->lan_online) { |
| 2613 | card->stats.tx_carrier_errors++; |
| 2614 | goto tx_drop; |
| 2615 | } |
| 2616 | |
| 2617 | if ((cast_type == RTN_BROADCAST) && |
| 2618 | (card->info.broadcast_capable == 0)) |
| 2619 | goto tx_drop; |
| 2620 | |
| 2621 | if (card->options.performance_stats) { |
| 2622 | card->perf_stats.outbound_cnt++; |
| 2623 | card->perf_stats.outbound_start_time = qeth_get_micros(); |
| 2624 | } |
| 2625 | |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2626 | if (skb_is_gso(skb)) |
| 2627 | large_send = card->options.large_send; |
| 2628 | |
| 2629 | if ((card->info.type == QETH_CARD_TYPE_IQD) && (!large_send) && |
| 2630 | (skb_shinfo(skb)->nr_frags == 0)) { |
| 2631 | new_skb = skb; |
| 2632 | data_offset = ETH_HLEN; |
| 2633 | hdr = kmem_cache_alloc(qeth_core_header_cache, GFP_ATOMIC); |
| 2634 | if (!hdr) |
| 2635 | goto tx_drop; |
| 2636 | elements_needed++; |
| 2637 | } else { |
| 2638 | /* create a clone with writeable headroom */ |
| 2639 | new_skb = skb_realloc_headroom(skb, sizeof(struct qeth_hdr_tso) |
| 2640 | + VLAN_HLEN); |
| 2641 | if (!new_skb) |
| 2642 | goto tx_drop; |
| 2643 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2644 | |
| 2645 | if (card->info.type == QETH_CARD_TYPE_IQD) { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2646 | if (data_offset < 0) |
| 2647 | skb_pull(new_skb, ETH_HLEN); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2648 | } else { |
| 2649 | if (new_skb->protocol == htons(ETH_P_IP)) { |
| 2650 | if (card->dev->type == ARPHRD_IEEE802_TR) |
| 2651 | skb_pull(new_skb, TR_HLEN); |
| 2652 | else |
| 2653 | skb_pull(new_skb, ETH_HLEN); |
| 2654 | } |
| 2655 | |
| 2656 | if (new_skb->protocol == ETH_P_IPV6 && card->vlangrp && |
| 2657 | vlan_tx_tag_present(new_skb)) { |
| 2658 | skb_push(new_skb, VLAN_HLEN); |
| 2659 | skb_copy_to_linear_data(new_skb, new_skb->data + 4, 4); |
| 2660 | skb_copy_to_linear_data_offset(new_skb, 4, |
| 2661 | new_skb->data + 8, 4); |
| 2662 | skb_copy_to_linear_data_offset(new_skb, 8, |
| 2663 | new_skb->data + 12, 4); |
| 2664 | tag = (u16 *)(new_skb->data + 12); |
| 2665 | *tag = __constant_htons(ETH_P_8021Q); |
| 2666 | *(tag + 1) = htons(vlan_tx_tag_get(new_skb)); |
frank.blaschka@de.ibm.com | 2b4ff11 | 2008-07-22 09:39:25 +0200 | [diff] [blame] | 2667 | new_skb->vlan_tci = 0; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | netif_stop_queue(dev); |
| 2672 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2673 | /* fix hardware limitation: as long as we do not have sbal |
| 2674 | * chaining we can not send long frag lists so we temporary |
| 2675 | * switch to EDDP |
| 2676 | */ |
| 2677 | if ((large_send == QETH_LARGE_SEND_TSO) && |
| 2678 | ((skb_shinfo(new_skb)->nr_frags + 2) > 16)) |
| 2679 | large_send = QETH_LARGE_SEND_EDDP; |
| 2680 | |
| 2681 | if ((large_send == QETH_LARGE_SEND_TSO) && |
| 2682 | (cast_type == RTN_UNSPEC)) { |
| 2683 | hdr = (struct qeth_hdr *)skb_push(new_skb, |
| 2684 | sizeof(struct qeth_hdr_tso)); |
| 2685 | memset(hdr, 0, sizeof(struct qeth_hdr_tso)); |
| 2686 | qeth_l3_fill_header(card, hdr, new_skb, ipv, cast_type); |
| 2687 | qeth_tso_fill_header(card, hdr, new_skb); |
| 2688 | elements_needed++; |
| 2689 | } else { |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2690 | if (data_offset < 0) { |
| 2691 | hdr = (struct qeth_hdr *)skb_push(new_skb, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2692 | sizeof(struct qeth_hdr)); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2693 | qeth_l3_fill_header(card, hdr, new_skb, ipv, |
| 2694 | cast_type); |
| 2695 | } else { |
| 2696 | qeth_l3_fill_header(card, hdr, new_skb, ipv, |
| 2697 | cast_type); |
| 2698 | hdr->hdr.l3.length = new_skb->len - data_offset; |
| 2699 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2700 | } |
| 2701 | |
| 2702 | if (large_send == QETH_LARGE_SEND_EDDP) { |
| 2703 | /* new_skb is not owned by a socket so we use skb to get |
| 2704 | * the protocol |
| 2705 | */ |
| 2706 | ctx = qeth_eddp_create_context(card, new_skb, hdr, |
| 2707 | skb->sk->sk_protocol); |
| 2708 | if (ctx == NULL) { |
Frank Blaschka | 14cc21b | 2008-06-06 12:37:46 +0200 | [diff] [blame] | 2709 | QETH_DBF_MESSAGE(2, "could not create eddp context\n"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2710 | goto tx_drop; |
| 2711 | } |
| 2712 | } else { |
| 2713 | int elems = qeth_get_elements_no(card, (void *)hdr, new_skb, |
| 2714 | elements_needed); |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2715 | if (!elems) { |
| 2716 | if (data_offset >= 0) |
| 2717 | kmem_cache_free(qeth_core_header_cache, hdr); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2718 | goto tx_drop; |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2719 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2720 | elements_needed += elems; |
| 2721 | } |
| 2722 | |
| 2723 | if ((large_send == QETH_LARGE_SEND_NO) && |
| 2724 | (new_skb->ip_summed == CHECKSUM_PARTIAL)) |
| 2725 | qeth_tx_csum(new_skb); |
| 2726 | |
| 2727 | if (card->info.type != QETH_CARD_TYPE_IQD) |
| 2728 | rc = qeth_do_send_packet(card, queue, new_skb, hdr, |
| 2729 | elements_needed, ctx); |
| 2730 | else |
| 2731 | rc = qeth_do_send_packet_fast(card, queue, new_skb, hdr, |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2732 | elements_needed, ctx, data_offset, 0); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2733 | |
| 2734 | if (!rc) { |
| 2735 | card->stats.tx_packets++; |
| 2736 | card->stats.tx_bytes += tx_bytes; |
| 2737 | if (new_skb != skb) |
| 2738 | dev_kfree_skb_any(skb); |
| 2739 | if (card->options.performance_stats) { |
| 2740 | if (large_send != QETH_LARGE_SEND_NO) { |
| 2741 | card->perf_stats.large_send_bytes += tx_bytes; |
| 2742 | card->perf_stats.large_send_cnt++; |
| 2743 | } |
| 2744 | if (skb_shinfo(new_skb)->nr_frags > 0) { |
| 2745 | card->perf_stats.sg_skbs_sent++; |
| 2746 | /* nr_frags + skb->data */ |
| 2747 | card->perf_stats.sg_frags_sent += |
| 2748 | skb_shinfo(new_skb)->nr_frags + 1; |
| 2749 | } |
| 2750 | } |
| 2751 | |
| 2752 | if (ctx != NULL) { |
| 2753 | qeth_eddp_put_context(ctx); |
| 2754 | dev_kfree_skb_any(new_skb); |
| 2755 | } |
| 2756 | } else { |
| 2757 | if (ctx != NULL) |
| 2758 | qeth_eddp_put_context(ctx); |
| 2759 | |
Frank Blaschka | 683d718 | 2008-08-01 16:39:13 +0200 | [diff] [blame] | 2760 | if (data_offset >= 0) |
| 2761 | kmem_cache_free(qeth_core_header_cache, hdr); |
| 2762 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2763 | if (rc == -EBUSY) { |
| 2764 | if (new_skb != skb) |
| 2765 | dev_kfree_skb_any(new_skb); |
| 2766 | return NETDEV_TX_BUSY; |
| 2767 | } else |
| 2768 | goto tx_drop; |
| 2769 | } |
| 2770 | |
| 2771 | netif_wake_queue(dev); |
| 2772 | if (card->options.performance_stats) |
| 2773 | card->perf_stats.outbound_time += qeth_get_micros() - |
| 2774 | card->perf_stats.outbound_start_time; |
| 2775 | return rc; |
| 2776 | |
| 2777 | tx_drop: |
| 2778 | card->stats.tx_dropped++; |
| 2779 | card->stats.tx_errors++; |
| 2780 | if ((new_skb != skb) && new_skb) |
| 2781 | dev_kfree_skb_any(new_skb); |
| 2782 | dev_kfree_skb_any(skb); |
Frank Blaschka | d0ec0f5 | 2008-06-06 12:37:48 +0200 | [diff] [blame] | 2783 | netif_wake_queue(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2784 | return NETDEV_TX_OK; |
| 2785 | } |
| 2786 | |
| 2787 | static int qeth_l3_open(struct net_device *dev) |
| 2788 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2789 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2790 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2791 | QETH_DBF_TEXT(TRACE, 4, "qethopen"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2792 | if (card->state != CARD_STATE_SOFTSETUP) |
| 2793 | return -ENODEV; |
| 2794 | card->data.state = CH_STATE_UP; |
| 2795 | card->state = CARD_STATE_UP; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2796 | netif_start_queue(dev); |
| 2797 | |
| 2798 | if (!card->lan_online && netif_carrier_ok(dev)) |
| 2799 | netif_carrier_off(dev); |
| 2800 | return 0; |
| 2801 | } |
| 2802 | |
| 2803 | static int qeth_l3_stop(struct net_device *dev) |
| 2804 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2805 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2806 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 2807 | QETH_DBF_TEXT(TRACE, 4, "qethstop"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2808 | netif_tx_disable(dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2809 | if (card->state == CARD_STATE_UP) |
| 2810 | card->state = CARD_STATE_SOFTSETUP; |
| 2811 | return 0; |
| 2812 | } |
| 2813 | |
| 2814 | static u32 qeth_l3_ethtool_get_rx_csum(struct net_device *dev) |
| 2815 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2816 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2817 | |
| 2818 | return (card->options.checksum_type == HW_CHECKSUMMING); |
| 2819 | } |
| 2820 | |
| 2821 | static int qeth_l3_ethtool_set_rx_csum(struct net_device *dev, u32 data) |
| 2822 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2823 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2824 | enum qeth_card_states old_state; |
| 2825 | enum qeth_checksum_types csum_type; |
| 2826 | |
| 2827 | if ((card->state != CARD_STATE_UP) && |
| 2828 | (card->state != CARD_STATE_DOWN)) |
| 2829 | return -EPERM; |
| 2830 | |
| 2831 | if (data) |
| 2832 | csum_type = HW_CHECKSUMMING; |
| 2833 | else |
| 2834 | csum_type = SW_CHECKSUMMING; |
| 2835 | |
| 2836 | if (card->options.checksum_type != csum_type) { |
| 2837 | old_state = card->state; |
| 2838 | if (card->state == CARD_STATE_UP) |
| 2839 | __qeth_l3_set_offline(card->gdev, 1); |
| 2840 | card->options.checksum_type = csum_type; |
| 2841 | if (old_state == CARD_STATE_UP) |
| 2842 | __qeth_l3_set_online(card->gdev, 1); |
| 2843 | } |
| 2844 | return 0; |
| 2845 | } |
| 2846 | |
| 2847 | static int qeth_l3_ethtool_set_tso(struct net_device *dev, u32 data) |
| 2848 | { |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2849 | struct qeth_card *card = dev->ml_priv; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2850 | |
| 2851 | if (data) { |
| 2852 | if (card->options.large_send == QETH_LARGE_SEND_NO) { |
| 2853 | if (card->info.type == QETH_CARD_TYPE_IQD) |
| 2854 | card->options.large_send = QETH_LARGE_SEND_EDDP; |
| 2855 | else |
| 2856 | card->options.large_send = QETH_LARGE_SEND_TSO; |
| 2857 | dev->features |= NETIF_F_TSO; |
| 2858 | } |
| 2859 | } else { |
| 2860 | dev->features &= ~NETIF_F_TSO; |
| 2861 | card->options.large_send = QETH_LARGE_SEND_NO; |
| 2862 | } |
| 2863 | return 0; |
| 2864 | } |
| 2865 | |
| 2866 | static struct ethtool_ops qeth_l3_ethtool_ops = { |
| 2867 | .get_link = ethtool_op_get_link, |
| 2868 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 2869 | .set_tx_csum = ethtool_op_set_tx_hw_csum, |
| 2870 | .get_rx_csum = qeth_l3_ethtool_get_rx_csum, |
| 2871 | .set_rx_csum = qeth_l3_ethtool_set_rx_csum, |
| 2872 | .get_sg = ethtool_op_get_sg, |
| 2873 | .set_sg = ethtool_op_set_sg, |
| 2874 | .get_tso = ethtool_op_get_tso, |
| 2875 | .set_tso = qeth_l3_ethtool_set_tso, |
| 2876 | .get_strings = qeth_core_get_strings, |
| 2877 | .get_ethtool_stats = qeth_core_get_ethtool_stats, |
| 2878 | .get_stats_count = qeth_core_get_stats_count, |
| 2879 | .get_drvinfo = qeth_core_get_drvinfo, |
Frank Blaschka | 3f9975a | 2008-04-24 10:15:23 +0200 | [diff] [blame] | 2880 | .get_settings = qeth_core_ethtool_get_settings, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2881 | }; |
| 2882 | |
| 2883 | /* |
| 2884 | * we need NOARP for IPv4 but we want neighbor solicitation for IPv6. Setting |
| 2885 | * NOARP on the netdevice is no option because it also turns off neighbor |
| 2886 | * solicitation. For IPv4 we install a neighbor_setup function. We don't want |
| 2887 | * arp resolution but we want the hard header (packet socket will work |
| 2888 | * e.g. tcpdump) |
| 2889 | */ |
| 2890 | static int qeth_l3_neigh_setup_noarp(struct neighbour *n) |
| 2891 | { |
| 2892 | n->nud_state = NUD_NOARP; |
| 2893 | memcpy(n->ha, "FAKELL", 6); |
| 2894 | n->output = n->ops->connected_output; |
| 2895 | return 0; |
| 2896 | } |
| 2897 | |
| 2898 | static int |
| 2899 | qeth_l3_neigh_setup(struct net_device *dev, struct neigh_parms *np) |
| 2900 | { |
| 2901 | if (np->tbl->family == AF_INET) |
| 2902 | np->neigh_setup = qeth_l3_neigh_setup_noarp; |
| 2903 | |
| 2904 | return 0; |
| 2905 | } |
| 2906 | |
| 2907 | static int qeth_l3_setup_netdev(struct qeth_card *card) |
| 2908 | { |
| 2909 | if (card->info.type == QETH_CARD_TYPE_OSAE) { |
| 2910 | if ((card->info.link_type == QETH_LINK_TYPE_LANE_TR) || |
| 2911 | (card->info.link_type == QETH_LINK_TYPE_HSTR)) { |
| 2912 | #ifdef CONFIG_TR |
| 2913 | card->dev = alloc_trdev(0); |
| 2914 | #endif |
| 2915 | if (!card->dev) |
| 2916 | return -ENODEV; |
| 2917 | } else { |
| 2918 | card->dev = alloc_etherdev(0); |
| 2919 | if (!card->dev) |
| 2920 | return -ENODEV; |
| 2921 | card->dev->neigh_setup = qeth_l3_neigh_setup; |
| 2922 | |
| 2923 | /*IPv6 address autoconfiguration stuff*/ |
| 2924 | qeth_l3_get_unique_id(card); |
| 2925 | if (!(card->info.unique_id & UNIQUE_ID_NOT_BY_CARD)) |
| 2926 | card->dev->dev_id = card->info.unique_id & |
| 2927 | 0xffff; |
| 2928 | } |
| 2929 | } else if (card->info.type == QETH_CARD_TYPE_IQD) { |
| 2930 | card->dev = alloc_netdev(0, "hsi%d", ether_setup); |
| 2931 | if (!card->dev) |
| 2932 | return -ENODEV; |
| 2933 | card->dev->flags |= IFF_NOARP; |
| 2934 | qeth_l3_iqd_read_initial_mac(card); |
| 2935 | } else |
| 2936 | return -ENODEV; |
| 2937 | |
| 2938 | card->dev->hard_start_xmit = qeth_l3_hard_start_xmit; |
Heiko Carstens | 509e256 | 2008-07-26 02:24:10 -0700 | [diff] [blame] | 2939 | card->dev->ml_priv = card; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2940 | card->dev->tx_timeout = &qeth_tx_timeout; |
| 2941 | card->dev->watchdog_timeo = QETH_TX_TIMEOUT; |
| 2942 | card->dev->open = qeth_l3_open; |
| 2943 | card->dev->stop = qeth_l3_stop; |
| 2944 | card->dev->do_ioctl = qeth_l3_do_ioctl; |
| 2945 | card->dev->get_stats = qeth_get_stats; |
| 2946 | card->dev->change_mtu = qeth_change_mtu; |
| 2947 | card->dev->set_multicast_list = qeth_l3_set_multicast_list; |
| 2948 | card->dev->vlan_rx_register = qeth_l3_vlan_rx_register; |
| 2949 | card->dev->vlan_rx_add_vid = qeth_l3_vlan_rx_add_vid; |
| 2950 | card->dev->vlan_rx_kill_vid = qeth_l3_vlan_rx_kill_vid; |
| 2951 | card->dev->mtu = card->info.initial_mtu; |
Frank Blaschka | b7624ec | 2008-04-01 10:26:57 +0200 | [diff] [blame] | 2952 | card->dev->set_mac_address = NULL; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2953 | SET_ETHTOOL_OPS(card->dev, &qeth_l3_ethtool_ops); |
| 2954 | card->dev->features |= NETIF_F_HW_VLAN_TX | |
| 2955 | NETIF_F_HW_VLAN_RX | |
| 2956 | NETIF_F_HW_VLAN_FILTER; |
| 2957 | |
| 2958 | SET_NETDEV_DEV(card->dev, &card->gdev->dev); |
| 2959 | return register_netdev(card->dev); |
| 2960 | } |
| 2961 | |
| 2962 | static void qeth_l3_qdio_input_handler(struct ccw_device *ccwdev, |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 2963 | unsigned int qdio_err, unsigned int queue, int first_element, |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2964 | int count, unsigned long card_ptr) |
| 2965 | { |
| 2966 | struct net_device *net_dev; |
| 2967 | struct qeth_card *card; |
| 2968 | struct qeth_qdio_buffer *buffer; |
| 2969 | int index; |
| 2970 | int i; |
| 2971 | |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2972 | card = (struct qeth_card *) card_ptr; |
| 2973 | net_dev = card->dev; |
| 2974 | if (card->options.performance_stats) { |
| 2975 | card->perf_stats.inbound_cnt++; |
| 2976 | card->perf_stats.inbound_start_time = qeth_get_micros(); |
| 2977 | } |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 2978 | if (qdio_err & QDIO_ERROR_ACTIVATE_CHECK_CONDITION) { |
| 2979 | QETH_DBF_TEXT(TRACE, 1, "qdinchk"); |
| 2980 | QETH_DBF_TEXT_(TRACE, 1, "%s", CARD_BUS_ID(card)); |
| 2981 | QETH_DBF_TEXT_(TRACE, 1, "%04X%04X", |
| 2982 | first_element, count); |
| 2983 | QETH_DBF_TEXT_(TRACE, 1, "%04X", queue); |
| 2984 | qeth_schedule_recovery(card); |
| 2985 | return; |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2986 | } |
| 2987 | for (i = first_element; i < (first_element + count); ++i) { |
| 2988 | index = i % QDIO_MAX_BUFFERS_PER_Q; |
| 2989 | buffer = &card->qdio.in_q->bufs[index]; |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 2990 | if (!(qdio_err && |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2991 | qeth_check_qdio_errors(buffer->buffer, |
Jan Glauber | 779e6e1 | 2008-07-17 17:16:48 +0200 | [diff] [blame] | 2992 | qdio_err, "qinerr"))) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 2993 | qeth_l3_process_inbound_buffer(card, buffer, index); |
| 2994 | /* clear buffer and give back to hardware */ |
| 2995 | qeth_put_buffer_pool_entry(card, buffer->pool_entry); |
| 2996 | qeth_queue_input_buffer(card, index); |
| 2997 | } |
| 2998 | if (card->options.performance_stats) |
| 2999 | card->perf_stats.inbound_time += qeth_get_micros() - |
| 3000 | card->perf_stats.inbound_start_time; |
| 3001 | } |
| 3002 | |
| 3003 | static int qeth_l3_probe_device(struct ccwgroup_device *gdev) |
| 3004 | { |
| 3005 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 3006 | |
| 3007 | qeth_l3_create_device_attributes(&gdev->dev); |
| 3008 | card->options.layer2 = 0; |
| 3009 | card->discipline.input_handler = (qdio_handler_t *) |
| 3010 | qeth_l3_qdio_input_handler; |
| 3011 | card->discipline.output_handler = (qdio_handler_t *) |
| 3012 | qeth_qdio_output_handler; |
| 3013 | card->discipline.recover = qeth_l3_recover; |
| 3014 | return 0; |
| 3015 | } |
| 3016 | |
| 3017 | static void qeth_l3_remove_device(struct ccwgroup_device *cgdev) |
| 3018 | { |
| 3019 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 3020 | |
| 3021 | wait_event(card->wait_q, qeth_threads_running(card, 0xffffffff) == 0); |
| 3022 | |
| 3023 | if (cgdev->state == CCWGROUP_ONLINE) { |
| 3024 | card->use_hard_stop = 1; |
| 3025 | qeth_l3_set_offline(cgdev); |
| 3026 | } |
| 3027 | |
| 3028 | if (card->dev) { |
| 3029 | unregister_netdev(card->dev); |
| 3030 | card->dev = NULL; |
| 3031 | } |
| 3032 | |
| 3033 | qeth_l3_remove_device_attributes(&cgdev->dev); |
| 3034 | qeth_l3_clear_ip_list(card, 0, 0); |
| 3035 | qeth_l3_clear_ipato_list(card); |
| 3036 | return; |
| 3037 | } |
| 3038 | |
| 3039 | static int __qeth_l3_set_online(struct ccwgroup_device *gdev, int recovery_mode) |
| 3040 | { |
| 3041 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 3042 | int rc = 0; |
| 3043 | enum qeth_card_states recover_flag; |
| 3044 | |
| 3045 | BUG_ON(!card); |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3046 | QETH_DBF_TEXT(SETUP, 2, "setonlin"); |
| 3047 | QETH_DBF_HEX(SETUP, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3048 | |
| 3049 | qeth_set_allowed_threads(card, QETH_RECOVER_THREAD, 1); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3050 | |
| 3051 | recover_flag = card->state; |
| 3052 | rc = ccw_device_set_online(CARD_RDEV(card)); |
| 3053 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3054 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3055 | return -EIO; |
| 3056 | } |
| 3057 | rc = ccw_device_set_online(CARD_WDEV(card)); |
| 3058 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3059 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3060 | return -EIO; |
| 3061 | } |
| 3062 | rc = ccw_device_set_online(CARD_DDEV(card)); |
| 3063 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3064 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3065 | return -EIO; |
| 3066 | } |
| 3067 | |
| 3068 | rc = qeth_core_hardsetup_card(card); |
| 3069 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3070 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3071 | goto out_remove; |
| 3072 | } |
| 3073 | |
| 3074 | qeth_l3_query_ipassists(card, QETH_PROT_IPV4); |
| 3075 | |
| 3076 | if (!card->dev && qeth_l3_setup_netdev(card)) |
| 3077 | goto out_remove; |
| 3078 | |
| 3079 | card->state = CARD_STATE_HARDSETUP; |
| 3080 | qeth_print_status_message(card); |
| 3081 | |
| 3082 | /* softsetup */ |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3083 | QETH_DBF_TEXT(SETUP, 2, "softsetp"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3084 | |
| 3085 | rc = qeth_send_startlan(card); |
| 3086 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3087 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3088 | if (rc == 0xe080) { |
| 3089 | PRINT_WARN("LAN on card %s if offline! " |
| 3090 | "Waiting for STARTLAN from card.\n", |
| 3091 | CARD_BUS_ID(card)); |
| 3092 | card->lan_online = 0; |
| 3093 | } |
| 3094 | return rc; |
| 3095 | } else |
| 3096 | card->lan_online = 1; |
| 3097 | qeth_set_large_send(card, card->options.large_send); |
| 3098 | |
| 3099 | rc = qeth_l3_setadapter_parms(card); |
| 3100 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3101 | QETH_DBF_TEXT_(SETUP, 2, "2err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3102 | rc = qeth_l3_start_ipassists(card); |
| 3103 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3104 | QETH_DBF_TEXT_(SETUP, 2, "3err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3105 | rc = qeth_l3_setrouting_v4(card); |
| 3106 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3107 | QETH_DBF_TEXT_(SETUP, 2, "4err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3108 | rc = qeth_l3_setrouting_v6(card); |
| 3109 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3110 | QETH_DBF_TEXT_(SETUP, 2, "5err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3111 | netif_tx_disable(card->dev); |
| 3112 | |
| 3113 | rc = qeth_init_qdio_queues(card); |
| 3114 | if (rc) { |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3115 | QETH_DBF_TEXT_(SETUP, 2, "6err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3116 | goto out_remove; |
| 3117 | } |
| 3118 | card->state = CARD_STATE_SOFTSETUP; |
| 3119 | netif_carrier_on(card->dev); |
| 3120 | |
| 3121 | qeth_set_allowed_threads(card, 0xffffffff, 0); |
Frank Blaschka | 8af7c5a | 2008-04-24 10:15:25 +0200 | [diff] [blame] | 3122 | if (recover_flag == CARD_STATE_RECOVER) { |
| 3123 | if (recovery_mode) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3124 | qeth_l3_open(card->dev); |
Frank Blaschka | 8af7c5a | 2008-04-24 10:15:25 +0200 | [diff] [blame] | 3125 | else { |
| 3126 | rtnl_lock(); |
| 3127 | dev_open(card->dev); |
| 3128 | rtnl_unlock(); |
| 3129 | } |
| 3130 | qeth_l3_set_multicast_list(card->dev); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3131 | } |
| 3132 | /* let user_space know that device is online */ |
| 3133 | kobject_uevent(&gdev->dev.kobj, KOBJ_CHANGE); |
| 3134 | return 0; |
| 3135 | out_remove: |
| 3136 | card->use_hard_stop = 1; |
| 3137 | qeth_l3_stop_card(card, 0); |
| 3138 | ccw_device_set_offline(CARD_DDEV(card)); |
| 3139 | ccw_device_set_offline(CARD_WDEV(card)); |
| 3140 | ccw_device_set_offline(CARD_RDEV(card)); |
| 3141 | if (recover_flag == CARD_STATE_RECOVER) |
| 3142 | card->state = CARD_STATE_RECOVER; |
| 3143 | else |
| 3144 | card->state = CARD_STATE_DOWN; |
| 3145 | return -ENODEV; |
| 3146 | } |
| 3147 | |
| 3148 | static int qeth_l3_set_online(struct ccwgroup_device *gdev) |
| 3149 | { |
| 3150 | return __qeth_l3_set_online(gdev, 0); |
| 3151 | } |
| 3152 | |
| 3153 | static int __qeth_l3_set_offline(struct ccwgroup_device *cgdev, |
| 3154 | int recovery_mode) |
| 3155 | { |
| 3156 | struct qeth_card *card = dev_get_drvdata(&cgdev->dev); |
| 3157 | int rc = 0, rc2 = 0, rc3 = 0; |
| 3158 | enum qeth_card_states recover_flag; |
| 3159 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3160 | QETH_DBF_TEXT(SETUP, 3, "setoffl"); |
| 3161 | QETH_DBF_HEX(SETUP, 3, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3162 | |
| 3163 | if (card->dev && netif_carrier_ok(card->dev)) |
| 3164 | netif_carrier_off(card->dev); |
| 3165 | recover_flag = card->state; |
Ursula Braun | 0f5623c | 2008-10-24 11:16:52 +0200 | [diff] [blame] | 3166 | qeth_l3_stop_card(card, recovery_mode); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3167 | rc = ccw_device_set_offline(CARD_DDEV(card)); |
| 3168 | rc2 = ccw_device_set_offline(CARD_WDEV(card)); |
| 3169 | rc3 = ccw_device_set_offline(CARD_RDEV(card)); |
| 3170 | if (!rc) |
| 3171 | rc = (rc2) ? rc2 : rc3; |
| 3172 | if (rc) |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3173 | QETH_DBF_TEXT_(SETUP, 2, "1err%d", rc); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3174 | if (recover_flag == CARD_STATE_UP) |
| 3175 | card->state = CARD_STATE_RECOVER; |
| 3176 | /* let user_space know that device is offline */ |
| 3177 | kobject_uevent(&cgdev->dev.kobj, KOBJ_CHANGE); |
| 3178 | return 0; |
| 3179 | } |
| 3180 | |
| 3181 | static int qeth_l3_set_offline(struct ccwgroup_device *cgdev) |
| 3182 | { |
| 3183 | return __qeth_l3_set_offline(cgdev, 0); |
| 3184 | } |
| 3185 | |
| 3186 | static int qeth_l3_recover(void *ptr) |
| 3187 | { |
| 3188 | struct qeth_card *card; |
| 3189 | int rc = 0; |
| 3190 | |
| 3191 | card = (struct qeth_card *) ptr; |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3192 | QETH_DBF_TEXT(TRACE, 2, "recover1"); |
| 3193 | QETH_DBF_HEX(TRACE, 2, &card, sizeof(void *)); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3194 | if (!qeth_do_run_thread(card, QETH_RECOVER_THREAD)) |
| 3195 | return 0; |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3196 | QETH_DBF_TEXT(TRACE, 2, "recover2"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3197 | PRINT_WARN("Recovery of device %s started ...\n", |
| 3198 | CARD_BUS_ID(card)); |
| 3199 | card->use_hard_stop = 1; |
| 3200 | __qeth_l3_set_offline(card->gdev, 1); |
| 3201 | rc = __qeth_l3_set_online(card->gdev, 1); |
| 3202 | /* don't run another scheduled recovery */ |
| 3203 | qeth_clear_thread_start_bit(card, QETH_RECOVER_THREAD); |
| 3204 | qeth_clear_thread_running_bit(card, QETH_RECOVER_THREAD); |
| 3205 | if (!rc) |
| 3206 | PRINT_INFO("Device %s successfully recovered!\n", |
| 3207 | CARD_BUS_ID(card)); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 3208 | else { |
| 3209 | rtnl_lock(); |
| 3210 | dev_close(card->dev); |
| 3211 | rtnl_unlock(); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3212 | PRINT_INFO("Device %s could not be recovered!\n", |
| 3213 | CARD_BUS_ID(card)); |
Ursula Braun | 28a7e4c | 2008-09-19 12:56:03 +0200 | [diff] [blame] | 3214 | } |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3215 | return 0; |
| 3216 | } |
| 3217 | |
| 3218 | static void qeth_l3_shutdown(struct ccwgroup_device *gdev) |
| 3219 | { |
| 3220 | struct qeth_card *card = dev_get_drvdata(&gdev->dev); |
| 3221 | qeth_l3_clear_ip_list(card, 0, 0); |
| 3222 | qeth_qdio_clear_card(card, 0); |
| 3223 | qeth_clear_qdio_buffers(card); |
| 3224 | } |
| 3225 | |
| 3226 | struct ccwgroup_driver qeth_l3_ccwgroup_driver = { |
| 3227 | .probe = qeth_l3_probe_device, |
| 3228 | .remove = qeth_l3_remove_device, |
| 3229 | .set_online = qeth_l3_set_online, |
| 3230 | .set_offline = qeth_l3_set_offline, |
| 3231 | .shutdown = qeth_l3_shutdown, |
| 3232 | }; |
| 3233 | EXPORT_SYMBOL_GPL(qeth_l3_ccwgroup_driver); |
| 3234 | |
| 3235 | static int qeth_l3_ip_event(struct notifier_block *this, |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 3236 | unsigned long event, void *ptr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3237 | { |
| 3238 | struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; |
| 3239 | struct net_device *dev = (struct net_device *)ifa->ifa_dev->dev; |
| 3240 | struct qeth_ipaddr *addr; |
| 3241 | struct qeth_card *card; |
| 3242 | |
YOSHIFUJI Hideaki | c346dca | 2008-03-25 21:47:49 +0900 | [diff] [blame] | 3243 | if (dev_net(dev) != &init_net) |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 3244 | return NOTIFY_DONE; |
| 3245 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3246 | QETH_DBF_TEXT(TRACE, 3, "ipevent"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3247 | card = qeth_l3_get_card_from_dev(dev); |
| 3248 | if (!card) |
| 3249 | return NOTIFY_DONE; |
| 3250 | |
| 3251 | addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV4); |
| 3252 | if (addr != NULL) { |
| 3253 | addr->u.a4.addr = ifa->ifa_address; |
| 3254 | addr->u.a4.mask = ifa->ifa_mask; |
| 3255 | addr->type = QETH_IP_TYPE_NORMAL; |
| 3256 | } else |
| 3257 | goto out; |
| 3258 | |
| 3259 | switch (event) { |
| 3260 | case NETDEV_UP: |
| 3261 | if (!qeth_l3_add_ip(card, addr)) |
| 3262 | kfree(addr); |
| 3263 | break; |
| 3264 | case NETDEV_DOWN: |
| 3265 | if (!qeth_l3_delete_ip(card, addr)) |
| 3266 | kfree(addr); |
| 3267 | break; |
| 3268 | default: |
| 3269 | break; |
| 3270 | } |
| 3271 | qeth_l3_set_ip_addr_list(card); |
| 3272 | out: |
| 3273 | return NOTIFY_DONE; |
| 3274 | } |
| 3275 | |
| 3276 | static struct notifier_block qeth_l3_ip_notifier = { |
| 3277 | qeth_l3_ip_event, |
| 3278 | NULL, |
| 3279 | }; |
| 3280 | |
| 3281 | #ifdef CONFIG_QETH_IPV6 |
| 3282 | /** |
| 3283 | * IPv6 event handler |
| 3284 | */ |
| 3285 | static int qeth_l3_ip6_event(struct notifier_block *this, |
David S. Miller | 76fef2b | 2008-03-22 18:22:42 -0700 | [diff] [blame] | 3286 | unsigned long event, void *ptr) |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3287 | { |
| 3288 | struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; |
| 3289 | struct net_device *dev = (struct net_device *)ifa->idev->dev; |
| 3290 | struct qeth_ipaddr *addr; |
| 3291 | struct qeth_card *card; |
| 3292 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3293 | QETH_DBF_TEXT(TRACE, 3, "ip6event"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3294 | |
| 3295 | card = qeth_l3_get_card_from_dev(dev); |
| 3296 | if (!card) |
| 3297 | return NOTIFY_DONE; |
| 3298 | if (!qeth_is_supported(card, IPA_IPV6)) |
| 3299 | return NOTIFY_DONE; |
| 3300 | |
| 3301 | addr = qeth_l3_get_addr_buffer(QETH_PROT_IPV6); |
| 3302 | if (addr != NULL) { |
| 3303 | memcpy(&addr->u.a6.addr, &ifa->addr, sizeof(struct in6_addr)); |
| 3304 | addr->u.a6.pfxlen = ifa->prefix_len; |
| 3305 | addr->type = QETH_IP_TYPE_NORMAL; |
| 3306 | } else |
| 3307 | goto out; |
| 3308 | |
| 3309 | switch (event) { |
| 3310 | case NETDEV_UP: |
| 3311 | if (!qeth_l3_add_ip(card, addr)) |
| 3312 | kfree(addr); |
| 3313 | break; |
| 3314 | case NETDEV_DOWN: |
| 3315 | if (!qeth_l3_delete_ip(card, addr)) |
| 3316 | kfree(addr); |
| 3317 | break; |
| 3318 | default: |
| 3319 | break; |
| 3320 | } |
| 3321 | qeth_l3_set_ip_addr_list(card); |
| 3322 | out: |
| 3323 | return NOTIFY_DONE; |
| 3324 | } |
| 3325 | |
| 3326 | static struct notifier_block qeth_l3_ip6_notifier = { |
| 3327 | qeth_l3_ip6_event, |
| 3328 | NULL, |
| 3329 | }; |
| 3330 | #endif |
| 3331 | |
| 3332 | static int qeth_l3_register_notifiers(void) |
| 3333 | { |
| 3334 | int rc; |
| 3335 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3336 | QETH_DBF_TEXT(TRACE, 5, "regnotif"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3337 | rc = register_inetaddr_notifier(&qeth_l3_ip_notifier); |
| 3338 | if (rc) |
| 3339 | return rc; |
| 3340 | #ifdef CONFIG_QETH_IPV6 |
| 3341 | rc = register_inet6addr_notifier(&qeth_l3_ip6_notifier); |
| 3342 | if (rc) { |
| 3343 | unregister_inetaddr_notifier(&qeth_l3_ip_notifier); |
| 3344 | return rc; |
| 3345 | } |
| 3346 | #else |
| 3347 | PRINT_WARN("layer 3 discipline no IPv6 support\n"); |
| 3348 | #endif |
| 3349 | return 0; |
| 3350 | } |
| 3351 | |
| 3352 | static void qeth_l3_unregister_notifiers(void) |
| 3353 | { |
| 3354 | |
Peter Tiedemann | d11ba0c | 2008-04-01 10:26:58 +0200 | [diff] [blame] | 3355 | QETH_DBF_TEXT(TRACE, 5, "unregnot"); |
Frank Blaschka | 4a71df5 | 2008-02-15 09:19:42 +0100 | [diff] [blame] | 3356 | BUG_ON(unregister_inetaddr_notifier(&qeth_l3_ip_notifier)); |
| 3357 | #ifdef CONFIG_QETH_IPV6 |
| 3358 | BUG_ON(unregister_inet6addr_notifier(&qeth_l3_ip6_notifier)); |
| 3359 | #endif /* QETH_IPV6 */ |
| 3360 | } |
| 3361 | |
| 3362 | static int __init qeth_l3_init(void) |
| 3363 | { |
| 3364 | int rc = 0; |
| 3365 | |
| 3366 | PRINT_INFO("register layer 3 discipline\n"); |
| 3367 | rc = qeth_l3_register_notifiers(); |
| 3368 | return rc; |
| 3369 | } |
| 3370 | |
| 3371 | static void __exit qeth_l3_exit(void) |
| 3372 | { |
| 3373 | qeth_l3_unregister_notifiers(); |
| 3374 | PRINT_INFO("unregister layer 3 discipline\n"); |
| 3375 | } |
| 3376 | |
| 3377 | module_init(qeth_l3_init); |
| 3378 | module_exit(qeth_l3_exit); |
| 3379 | MODULE_AUTHOR("Frank Blaschka <frank.blaschka@de.ibm.com>"); |
| 3380 | MODULE_DESCRIPTION("qeth layer 3 discipline"); |
| 3381 | MODULE_LICENSE("GPL"); |