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