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