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