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