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