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