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