-
Notifications
You must be signed in to change notification settings - Fork 102
/
qeth_core_main.c
7365 lines (6290 loc) · 192 KB
/
qeth_core_main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright IBM Corp. 2007, 2009
* Author(s): Utz Bacher <utz.bacher@de.ibm.com>,
* Frank Pavlic <fpavlic@de.ibm.com>,
* Thomas Spatzier <tspat@de.ibm.com>,
* Frank Blaschka <frank.blaschka@de.ibm.com>
*/
#define KMSG_COMPONENT "qeth"
#define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
#include <linux/compat.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/string.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/log2.h>
#include <linux/io.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/mii.h>
#include <linux/mm.h>
#include <linux/kthread.h>
#include <linux/slab.h>
#include <linux/if_vlan.h>
#include <linux/netdevice.h>
#include <linux/netdev_features.h>
#include <linux/rcutree.h>
#include <linux/skbuff.h>
#include <linux/vmalloc.h>
#include <net/iucv/af_iucv.h>
#include <net/dsfield.h>
#include <net/sock.h>
#include <asm/ebcdic.h>
#include <asm/chpid.h>
#include <asm/sysinfo.h>
#include <asm/diag.h>
#include <asm/cio.h>
#include <asm/ccwdev.h>
#include <asm/cpcmd.h>
#include "qeth_core.h"
struct qeth_dbf_info qeth_dbf[QETH_DBF_INFOS] = {
/* define dbf - Name, Pages, Areas, Maxlen, Level, View, Handle */
/* N P A M L V H */
[QETH_DBF_SETUP] = {"qeth_setup",
8, 1, 8, 5, &debug_hex_ascii_view, NULL},
[QETH_DBF_MSG] = {"qeth_msg", 8, 1, 11 * sizeof(long), 3,
&debug_sprintf_view, NULL},
[QETH_DBF_CTRL] = {"qeth_control",
8, 1, QETH_DBF_CTRL_LEN, 5, &debug_hex_ascii_view, NULL},
};
EXPORT_SYMBOL_GPL(qeth_dbf);
struct kmem_cache *qeth_core_header_cache;
EXPORT_SYMBOL_GPL(qeth_core_header_cache);
static struct kmem_cache *qeth_qdio_outbuf_cache;
static struct device *qeth_core_root_dev;
static struct dentry *qeth_debugfs_root;
static struct lock_class_key qdio_out_skb_queue_key;
static void qeth_issue_next_read_cb(struct qeth_card *card,
struct qeth_cmd_buffer *iob,
unsigned int data_length);
static int qeth_qdio_establish(struct qeth_card *);
static void qeth_free_qdio_queues(struct qeth_card *card);
static void qeth_notify_skbs(struct qeth_qdio_out_q *queue,
struct qeth_qdio_out_buffer *buf,
enum iucv_tx_notify notification);
static void qeth_tx_complete_buf(struct qeth_qdio_out_buffer *buf, bool error,
int budget);
static void qeth_close_dev_handler(struct work_struct *work)
{
struct qeth_card *card;
card = container_of(work, struct qeth_card, close_dev_work);
QETH_CARD_TEXT(card, 2, "cldevhdl");
ccwgroup_set_offline(card->gdev);
}
static const char *qeth_get_cardname(struct qeth_card *card)
{
if (IS_VM_NIC(card)) {
switch (card->info.type) {
case QETH_CARD_TYPE_OSD:
return " Virtual NIC QDIO";
case QETH_CARD_TYPE_IQD:
return " Virtual NIC Hiper";
case QETH_CARD_TYPE_OSM:
return " Virtual NIC QDIO - OSM";
case QETH_CARD_TYPE_OSX:
return " Virtual NIC QDIO - OSX";
default:
return " unknown";
}
} else {
switch (card->info.type) {
case QETH_CARD_TYPE_OSD:
return " OSD Express";
case QETH_CARD_TYPE_IQD:
return " HiperSockets";
case QETH_CARD_TYPE_OSN:
return " OSN QDIO";
case QETH_CARD_TYPE_OSM:
return " OSM QDIO";
case QETH_CARD_TYPE_OSX:
return " OSX QDIO";
default:
return " unknown";
}
}
return " n/a";
}
/* max length to be returned: 14 */
const char *qeth_get_cardname_short(struct qeth_card *card)
{
if (IS_VM_NIC(card)) {
switch (card->info.type) {
case QETH_CARD_TYPE_OSD:
return "Virt.NIC QDIO";
case QETH_CARD_TYPE_IQD:
return "Virt.NIC Hiper";
case QETH_CARD_TYPE_OSM:
return "Virt.NIC OSM";
case QETH_CARD_TYPE_OSX:
return "Virt.NIC OSX";
default:
return "unknown";
}
} else {
switch (card->info.type) {
case QETH_CARD_TYPE_OSD:
switch (card->info.link_type) {
case QETH_LINK_TYPE_FAST_ETH:
return "OSD_100";
case QETH_LINK_TYPE_HSTR:
return "HSTR";
case QETH_LINK_TYPE_GBIT_ETH:
return "OSD_1000";
case QETH_LINK_TYPE_10GBIT_ETH:
return "OSD_10GIG";
case QETH_LINK_TYPE_25GBIT_ETH:
return "OSD_25GIG";
case QETH_LINK_TYPE_LANE_ETH100:
return "OSD_FE_LANE";
case QETH_LINK_TYPE_LANE_TR:
return "OSD_TR_LANE";
case QETH_LINK_TYPE_LANE_ETH1000:
return "OSD_GbE_LANE";
case QETH_LINK_TYPE_LANE:
return "OSD_ATM_LANE";
default:
return "OSD_Express";
}
case QETH_CARD_TYPE_IQD:
return "HiperSockets";
case QETH_CARD_TYPE_OSN:
return "OSN";
case QETH_CARD_TYPE_OSM:
return "OSM_1000";
case QETH_CARD_TYPE_OSX:
return "OSX_10GIG";
default:
return "unknown";
}
}
return "n/a";
}
void qeth_set_allowed_threads(struct qeth_card *card, unsigned long threads,
int clear_start_mask)
{
unsigned long flags;
spin_lock_irqsave(&card->thread_mask_lock, flags);
card->thread_allowed_mask = threads;
if (clear_start_mask)
card->thread_start_mask &= threads;
spin_unlock_irqrestore(&card->thread_mask_lock, flags);
wake_up(&card->wait_q);
}
EXPORT_SYMBOL_GPL(qeth_set_allowed_threads);
int qeth_threads_running(struct qeth_card *card, unsigned long threads)
{
unsigned long flags;
int rc = 0;
spin_lock_irqsave(&card->thread_mask_lock, flags);
rc = (card->thread_running_mask & threads);
spin_unlock_irqrestore(&card->thread_mask_lock, flags);
return rc;
}
EXPORT_SYMBOL_GPL(qeth_threads_running);
static void qeth_clear_working_pool_list(struct qeth_card *card)
{
struct qeth_buffer_pool_entry *pool_entry, *tmp;
struct qeth_qdio_q *queue = card->qdio.in_q;
unsigned int i;
QETH_CARD_TEXT(card, 5, "clwrklst");
list_for_each_entry_safe(pool_entry, tmp,
&card->qdio.in_buf_pool.entry_list, list)
list_del(&pool_entry->list);
for (i = 0; i < ARRAY_SIZE(queue->bufs); i++)
queue->bufs[i].pool_entry = NULL;
}
static void qeth_free_pool_entry(struct qeth_buffer_pool_entry *entry)
{
unsigned int i;
for (i = 0; i < ARRAY_SIZE(entry->elements); i++) {
if (entry->elements[i])
__free_page(entry->elements[i]);
}
kfree(entry);
}
static void qeth_free_buffer_pool(struct qeth_card *card)
{
struct qeth_buffer_pool_entry *entry, *tmp;
list_for_each_entry_safe(entry, tmp, &card->qdio.init_pool.entry_list,
init_list) {
list_del(&entry->init_list);
qeth_free_pool_entry(entry);
}
}
static struct qeth_buffer_pool_entry *qeth_alloc_pool_entry(unsigned int pages)
{
struct qeth_buffer_pool_entry *entry;
unsigned int i;
entry = kzalloc(sizeof(*entry), GFP_KERNEL);
if (!entry)
return NULL;
for (i = 0; i < pages; i++) {
entry->elements[i] = __dev_alloc_page(GFP_KERNEL);
if (!entry->elements[i]) {
qeth_free_pool_entry(entry);
return NULL;
}
}
return entry;
}
static int qeth_alloc_buffer_pool(struct qeth_card *card)
{
unsigned int buf_elements = QETH_MAX_BUFFER_ELEMENTS(card);
unsigned int i;
QETH_CARD_TEXT(card, 5, "alocpool");
for (i = 0; i < card->qdio.init_pool.buf_count; ++i) {
struct qeth_buffer_pool_entry *entry;
entry = qeth_alloc_pool_entry(buf_elements);
if (!entry) {
qeth_free_buffer_pool(card);
return -ENOMEM;
}
list_add(&entry->init_list, &card->qdio.init_pool.entry_list);
}
return 0;
}
int qeth_resize_buffer_pool(struct qeth_card *card, unsigned int count)
{
unsigned int buf_elements = QETH_MAX_BUFFER_ELEMENTS(card);
struct qeth_qdio_buffer_pool *pool = &card->qdio.init_pool;
struct qeth_buffer_pool_entry *entry, *tmp;
int delta = count - pool->buf_count;
LIST_HEAD(entries);
QETH_CARD_TEXT(card, 2, "realcbp");
/* Defer until queue is allocated: */
if (!card->qdio.in_q)
goto out;
/* Remove entries from the pool: */
while (delta < 0) {
entry = list_first_entry(&pool->entry_list,
struct qeth_buffer_pool_entry,
init_list);
list_del(&entry->init_list);
qeth_free_pool_entry(entry);
delta++;
}
/* Allocate additional entries: */
while (delta > 0) {
entry = qeth_alloc_pool_entry(buf_elements);
if (!entry) {
list_for_each_entry_safe(entry, tmp, &entries,
init_list) {
list_del(&entry->init_list);
qeth_free_pool_entry(entry);
}
return -ENOMEM;
}
list_add(&entry->init_list, &entries);
delta--;
}
list_splice(&entries, &pool->entry_list);
out:
card->qdio.in_buf_pool.buf_count = count;
pool->buf_count = count;
return 0;
}
EXPORT_SYMBOL_GPL(qeth_resize_buffer_pool);
static void qeth_free_qdio_queue(struct qeth_qdio_q *q)
{
if (!q)
return;
qdio_free_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q);
kfree(q);
}
static struct qeth_qdio_q *qeth_alloc_qdio_queue(void)
{
struct qeth_qdio_q *q = kzalloc(sizeof(*q), GFP_KERNEL);
int i;
if (!q)
return NULL;
if (qdio_alloc_buffers(q->qdio_bufs, QDIO_MAX_BUFFERS_PER_Q)) {
kfree(q);
return NULL;
}
for (i = 0; i < QDIO_MAX_BUFFERS_PER_Q; ++i)
q->bufs[i].buffer = q->qdio_bufs[i];
QETH_DBF_HEX(SETUP, 2, &q, sizeof(void *));
return q;
}
static int qeth_cq_init(struct qeth_card *card)
{
int rc;
if (card->options.cq == QETH_CQ_ENABLED) {
QETH_CARD_TEXT(card, 2, "cqinit");
qdio_reset_buffers(card->qdio.c_q->qdio_bufs,
QDIO_MAX_BUFFERS_PER_Q);
card->qdio.c_q->next_buf_to_init = 127;
rc = do_QDIO(CARD_DDEV(card), QDIO_FLAG_SYNC_INPUT,
card->qdio.no_in_queues - 1, 0,
127);
if (rc) {
QETH_CARD_TEXT_(card, 2, "1err%d", rc);
goto out;
}
}
rc = 0;
out:
return rc;
}
static int qeth_alloc_cq(struct qeth_card *card)
{
int rc;
if (card->options.cq == QETH_CQ_ENABLED) {
int i;
struct qdio_outbuf_state *outbuf_states;
QETH_CARD_TEXT(card, 2, "cqon");
card->qdio.c_q = qeth_alloc_qdio_queue();
if (!card->qdio.c_q) {
rc = -1;
goto kmsg_out;
}
card->qdio.no_in_queues = 2;
card->qdio.out_bufstates =
kcalloc(card->qdio.no_out_queues *
QDIO_MAX_BUFFERS_PER_Q,
sizeof(struct qdio_outbuf_state),
GFP_KERNEL);
outbuf_states = card->qdio.out_bufstates;
if (outbuf_states == NULL) {
rc = -1;
goto free_cq_out;
}
for (i = 0; i < card->qdio.no_out_queues; ++i) {
card->qdio.out_qs[i]->bufstates = outbuf_states;
outbuf_states += QDIO_MAX_BUFFERS_PER_Q;
}
} else {
QETH_CARD_TEXT(card, 2, "nocq");
card->qdio.c_q = NULL;
card->qdio.no_in_queues = 1;
}
QETH_CARD_TEXT_(card, 2, "iqc%d", card->qdio.no_in_queues);
rc = 0;
out:
return rc;
free_cq_out:
qeth_free_qdio_queue(card->qdio.c_q);
card->qdio.c_q = NULL;
kmsg_out:
dev_err(&card->gdev->dev, "Failed to create completion queue\n");
goto out;
}
static void qeth_free_cq(struct qeth_card *card)
{
if (card->qdio.c_q) {
--card->qdio.no_in_queues;
qeth_free_qdio_queue(card->qdio.c_q);
card->qdio.c_q = NULL;
}
kfree(card->qdio.out_bufstates);
card->qdio.out_bufstates = NULL;
}
static enum iucv_tx_notify qeth_compute_cq_notification(int sbalf15,
int delayed)
{
enum iucv_tx_notify n;
switch (sbalf15) {
case 0:
n = delayed ? TX_NOTIFY_DELAYED_OK : TX_NOTIFY_OK;
break;
case 4:
case 16:
case 17:
case 18:
n = delayed ? TX_NOTIFY_DELAYED_UNREACHABLE :
TX_NOTIFY_UNREACHABLE;
break;
default:
n = delayed ? TX_NOTIFY_DELAYED_GENERALERROR :
TX_NOTIFY_GENERALERROR;
break;
}
return n;
}
static void qeth_cleanup_handled_pending(struct qeth_qdio_out_q *q, int bidx,
int forced_cleanup)
{
if (q->card->options.cq != QETH_CQ_ENABLED)
return;
if (q->bufs[bidx]->next_pending != NULL) {
struct qeth_qdio_out_buffer *head = q->bufs[bidx];
struct qeth_qdio_out_buffer *c = q->bufs[bidx]->next_pending;
while (c) {
if (forced_cleanup ||
atomic_read(&c->state) == QETH_QDIO_BUF_EMPTY) {
struct qeth_qdio_out_buffer *f = c;
QETH_CARD_TEXT(f->q->card, 5, "fp");
QETH_CARD_TEXT_(f->q->card, 5, "%lx", (long) f);
/* release here to avoid interleaving between
outbound tasklet and inbound tasklet
regarding notifications and lifecycle */
qeth_tx_complete_buf(c, forced_cleanup, 0);
c = f->next_pending;
WARN_ON_ONCE(head->next_pending != f);
head->next_pending = c;
kmem_cache_free(qeth_qdio_outbuf_cache, f);
} else {
head = c;
c = c->next_pending;
}
}
}
}
static void qeth_qdio_handle_aob(struct qeth_card *card,
unsigned long phys_aob_addr)
{
enum qeth_qdio_out_buffer_state new_state = QETH_QDIO_BUF_QAOB_OK;
struct qaob *aob;
struct qeth_qdio_out_buffer *buffer;
enum iucv_tx_notify notification;
unsigned int i;
aob = (struct qaob *) phys_to_virt(phys_aob_addr);
QETH_CARD_TEXT(card, 5, "haob");
QETH_CARD_TEXT_(card, 5, "%lx", phys_aob_addr);
buffer = (struct qeth_qdio_out_buffer *) aob->user1;
QETH_CARD_TEXT_(card, 5, "%lx", aob->user1);
if (aob->aorc) {
QETH_CARD_TEXT_(card, 2, "aorc%02X", aob->aorc);
new_state = QETH_QDIO_BUF_QAOB_ERROR;
}
switch (atomic_xchg(&buffer->state, new_state)) {
case QETH_QDIO_BUF_PRIMED:
/* Faster than TX completion code, let it handle the async
* completion for us.
*/
break;
case QETH_QDIO_BUF_PENDING:
/* TX completion code is active and will handle the async
* completion for us.
*/
break;
case QETH_QDIO_BUF_NEED_QAOB:
/* TX completion code is already finished. */
notification = qeth_compute_cq_notification(aob->aorc, 1);
qeth_notify_skbs(buffer->q, buffer, notification);
/* Free dangling allocations. The attached skbs are handled by
* qeth_cleanup_handled_pending().
*/
for (i = 0;
i < aob->sb_count && i < QETH_MAX_BUFFER_ELEMENTS(card);
i++) {
void *data = phys_to_virt(aob->sba[i]);
if (data && buffer->is_header[i])
kmem_cache_free(qeth_core_header_cache, data);
buffer->is_header[i] = 0;
}
atomic_set(&buffer->state, QETH_QDIO_BUF_EMPTY);
break;
default:
WARN_ON_ONCE(1);
}
qdio_release_aob(aob);
}
static void qeth_setup_ccw(struct ccw1 *ccw, u8 cmd_code, u8 flags, u32 len,
void *data)
{
ccw->cmd_code = cmd_code;
ccw->flags = flags | CCW_FLAG_SLI;
ccw->count = len;
ccw->cda = (__u32) __pa(data);
}
static int __qeth_issue_next_read(struct qeth_card *card)
{
struct qeth_cmd_buffer *iob = card->read_cmd;
struct qeth_channel *channel = iob->channel;
struct ccw1 *ccw = __ccw_from_cmd(iob);
int rc;
QETH_CARD_TEXT(card, 5, "issnxrd");
if (channel->state != CH_STATE_UP)
return -EIO;
memset(iob->data, 0, iob->length);
qeth_setup_ccw(ccw, CCW_CMD_READ, 0, iob->length, iob->data);
iob->callback = qeth_issue_next_read_cb;
/* keep the cmd alive after completion: */
qeth_get_cmd(iob);
QETH_CARD_TEXT(card, 6, "noirqpnd");
rc = ccw_device_start(channel->ccwdev, ccw, (addr_t) iob, 0, 0);
if (!rc) {
channel->active_cmd = iob;
} else {
QETH_DBF_MESSAGE(2, "error %i on device %x when starting next read ccw!\n",
rc, CARD_DEVID(card));
qeth_unlock_channel(card, channel);
qeth_put_cmd(iob);
card->read_or_write_problem = 1;
qeth_schedule_recovery(card);
}
return rc;
}
static int qeth_issue_next_read(struct qeth_card *card)
{
int ret;
spin_lock_irq(get_ccwdev_lock(CARD_RDEV(card)));
ret = __qeth_issue_next_read(card);
spin_unlock_irq(get_ccwdev_lock(CARD_RDEV(card)));
return ret;
}
static void qeth_enqueue_cmd(struct qeth_card *card,
struct qeth_cmd_buffer *iob)
{
spin_lock_irq(&card->lock);
list_add_tail(&iob->list_entry, &card->cmd_waiter_list);
spin_unlock_irq(&card->lock);
}
static void qeth_dequeue_cmd(struct qeth_card *card,
struct qeth_cmd_buffer *iob)
{
spin_lock_irq(&card->lock);
list_del(&iob->list_entry);
spin_unlock_irq(&card->lock);
}
void qeth_notify_cmd(struct qeth_cmd_buffer *iob, int reason)
{
iob->rc = reason;
complete(&iob->done);
}
EXPORT_SYMBOL_GPL(qeth_notify_cmd);
static void qeth_flush_local_addrs4(struct qeth_card *card)
{
struct qeth_local_addr *addr;
struct hlist_node *tmp;
unsigned int i;
spin_lock_irq(&card->local_addrs4_lock);
hash_for_each_safe(card->local_addrs4, i, tmp, addr, hnode) {
hash_del_rcu(&addr->hnode);
kfree_rcu(addr, rcu);
}
spin_unlock_irq(&card->local_addrs4_lock);
}
static void qeth_flush_local_addrs6(struct qeth_card *card)
{
struct qeth_local_addr *addr;
struct hlist_node *tmp;
unsigned int i;
spin_lock_irq(&card->local_addrs6_lock);
hash_for_each_safe(card->local_addrs6, i, tmp, addr, hnode) {
hash_del_rcu(&addr->hnode);
kfree_rcu(addr, rcu);
}
spin_unlock_irq(&card->local_addrs6_lock);
}
static void qeth_flush_local_addrs(struct qeth_card *card)
{
qeth_flush_local_addrs4(card);
qeth_flush_local_addrs6(card);
}
static void qeth_add_local_addrs4(struct qeth_card *card,
struct qeth_ipacmd_local_addrs4 *cmd)
{
unsigned int i;
if (cmd->addr_length !=
sizeof_field(struct qeth_ipacmd_local_addr4, addr)) {
dev_err_ratelimited(&card->gdev->dev,
"Dropped IPv4 ADD LOCAL ADDR event with bad length %u\n",
cmd->addr_length);
return;
}
spin_lock(&card->local_addrs4_lock);
for (i = 0; i < cmd->count; i++) {
unsigned int key = ipv4_addr_hash(cmd->addrs[i].addr);
struct qeth_local_addr *addr;
bool duplicate = false;
hash_for_each_possible(card->local_addrs4, addr, hnode, key) {
if (addr->addr.s6_addr32[3] == cmd->addrs[i].addr) {
duplicate = true;
break;
}
}
if (duplicate)
continue;
addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
if (!addr) {
dev_err(&card->gdev->dev,
"Failed to allocate local addr object. Traffic to %pI4 might suffer.\n",
&cmd->addrs[i].addr);
continue;
}
ipv6_addr_set(&addr->addr, 0, 0, 0, cmd->addrs[i].addr);
hash_add_rcu(card->local_addrs4, &addr->hnode, key);
}
spin_unlock(&card->local_addrs4_lock);
}
static void qeth_add_local_addrs6(struct qeth_card *card,
struct qeth_ipacmd_local_addrs6 *cmd)
{
unsigned int i;
if (cmd->addr_length !=
sizeof_field(struct qeth_ipacmd_local_addr6, addr)) {
dev_err_ratelimited(&card->gdev->dev,
"Dropped IPv6 ADD LOCAL ADDR event with bad length %u\n",
cmd->addr_length);
return;
}
spin_lock(&card->local_addrs6_lock);
for (i = 0; i < cmd->count; i++) {
u32 key = ipv6_addr_hash(&cmd->addrs[i].addr);
struct qeth_local_addr *addr;
bool duplicate = false;
hash_for_each_possible(card->local_addrs6, addr, hnode, key) {
if (ipv6_addr_equal(&addr->addr, &cmd->addrs[i].addr)) {
duplicate = true;
break;
}
}
if (duplicate)
continue;
addr = kmalloc(sizeof(*addr), GFP_ATOMIC);
if (!addr) {
dev_err(&card->gdev->dev,
"Failed to allocate local addr object. Traffic to %pI6c might suffer.\n",
&cmd->addrs[i].addr);
continue;
}
addr->addr = cmd->addrs[i].addr;
hash_add_rcu(card->local_addrs6, &addr->hnode, key);
}
spin_unlock(&card->local_addrs6_lock);
}
static void qeth_del_local_addrs4(struct qeth_card *card,
struct qeth_ipacmd_local_addrs4 *cmd)
{
unsigned int i;
if (cmd->addr_length !=
sizeof_field(struct qeth_ipacmd_local_addr4, addr)) {
dev_err_ratelimited(&card->gdev->dev,
"Dropped IPv4 DEL LOCAL ADDR event with bad length %u\n",
cmd->addr_length);
return;
}
spin_lock(&card->local_addrs4_lock);
for (i = 0; i < cmd->count; i++) {
struct qeth_ipacmd_local_addr4 *addr = &cmd->addrs[i];
unsigned int key = ipv4_addr_hash(addr->addr);
struct qeth_local_addr *tmp;
hash_for_each_possible(card->local_addrs4, tmp, hnode, key) {
if (tmp->addr.s6_addr32[3] == addr->addr) {
hash_del_rcu(&tmp->hnode);
kfree_rcu(tmp, rcu);
break;
}
}
}
spin_unlock(&card->local_addrs4_lock);
}
static void qeth_del_local_addrs6(struct qeth_card *card,
struct qeth_ipacmd_local_addrs6 *cmd)
{
unsigned int i;
if (cmd->addr_length !=
sizeof_field(struct qeth_ipacmd_local_addr6, addr)) {
dev_err_ratelimited(&card->gdev->dev,
"Dropped IPv6 DEL LOCAL ADDR event with bad length %u\n",
cmd->addr_length);
return;
}
spin_lock(&card->local_addrs6_lock);
for (i = 0; i < cmd->count; i++) {
struct qeth_ipacmd_local_addr6 *addr = &cmd->addrs[i];
u32 key = ipv6_addr_hash(&addr->addr);
struct qeth_local_addr *tmp;
hash_for_each_possible(card->local_addrs6, tmp, hnode, key) {
if (ipv6_addr_equal(&tmp->addr, &addr->addr)) {
hash_del_rcu(&tmp->hnode);
kfree_rcu(tmp, rcu);
break;
}
}
}
spin_unlock(&card->local_addrs6_lock);
}
static bool qeth_next_hop_is_local_v4(struct qeth_card *card,
struct sk_buff *skb)
{
struct qeth_local_addr *tmp;
bool is_local = false;
unsigned int key;
__be32 next_hop;
if (hash_empty(card->local_addrs4))
return false;
rcu_read_lock();
next_hop = qeth_next_hop_v4_rcu(skb, qeth_dst_check_rcu(skb, 4));
key = ipv4_addr_hash(next_hop);
hash_for_each_possible_rcu(card->local_addrs4, tmp, hnode, key) {
if (tmp->addr.s6_addr32[3] == next_hop) {
is_local = true;
break;
}
}
rcu_read_unlock();
return is_local;
}
static bool qeth_next_hop_is_local_v6(struct qeth_card *card,
struct sk_buff *skb)
{
struct qeth_local_addr *tmp;
struct in6_addr *next_hop;
bool is_local = false;
u32 key;
if (hash_empty(card->local_addrs6))
return false;
rcu_read_lock();
next_hop = qeth_next_hop_v6_rcu(skb, qeth_dst_check_rcu(skb, 6));
key = ipv6_addr_hash(next_hop);
hash_for_each_possible_rcu(card->local_addrs6, tmp, hnode, key) {
if (ipv6_addr_equal(&tmp->addr, next_hop)) {
is_local = true;
break;
}
}
rcu_read_unlock();
return is_local;
}
static int qeth_debugfs_local_addr_show(struct seq_file *m, void *v)
{
struct qeth_card *card = m->private;
struct qeth_local_addr *tmp;
unsigned int i;
rcu_read_lock();
hash_for_each_rcu(card->local_addrs4, i, tmp, hnode)
seq_printf(m, "%pI4\n", &tmp->addr.s6_addr32[3]);
hash_for_each_rcu(card->local_addrs6, i, tmp, hnode)
seq_printf(m, "%pI6c\n", &tmp->addr);
rcu_read_unlock();
return 0;
}
DEFINE_SHOW_ATTRIBUTE(qeth_debugfs_local_addr);
static void qeth_issue_ipa_msg(struct qeth_ipa_cmd *cmd, int rc,
struct qeth_card *card)
{
const char *ipa_name;
int com = cmd->hdr.command;
ipa_name = qeth_get_ipa_cmd_name(com);
if (rc)
QETH_DBF_MESSAGE(2, "IPA: %s(%#x) for device %x returned %#x \"%s\"\n",
ipa_name, com, CARD_DEVID(card), rc,
qeth_get_ipa_msg(rc));
else
QETH_DBF_MESSAGE(5, "IPA: %s(%#x) for device %x succeeded\n",
ipa_name, com, CARD_DEVID(card));
}
static struct qeth_ipa_cmd *qeth_check_ipa_data(struct qeth_card *card,
struct qeth_ipa_cmd *cmd)
{
QETH_CARD_TEXT(card, 5, "chkipad");
if (IS_IPA_REPLY(cmd)) {
if (cmd->hdr.command != IPA_CMD_SETCCID &&
cmd->hdr.command != IPA_CMD_DELCCID &&
cmd->hdr.command != IPA_CMD_MODCCID &&
cmd->hdr.command != IPA_CMD_SET_DIAG_ASS)
qeth_issue_ipa_msg(cmd, cmd->hdr.return_code, card);
return cmd;
}
/* handle unsolicited event: */
switch (cmd->hdr.command) {
case IPA_CMD_STOPLAN:
if (cmd->hdr.return_code == IPA_RC_VEPA_TO_VEB_TRANSITION) {
dev_err(&card->gdev->dev,
"Interface %s is down because the adjacent port is no longer in reflective relay mode\n",
netdev_name(card->dev));
schedule_work(&card->close_dev_work);
} else {
dev_warn(&card->gdev->dev,
"The link for interface %s on CHPID 0x%X failed\n",
netdev_name(card->dev), card->info.chpid);
qeth_issue_ipa_msg(cmd, cmd->hdr.return_code, card);
netif_carrier_off(card->dev);
}
return NULL;
case IPA_CMD_STARTLAN:
dev_info(&card->gdev->dev,
"The link for %s on CHPID 0x%X has been restored\n",
netdev_name(card->dev), card->info.chpid);
if (card->info.hwtrap)
card->info.hwtrap = 2;
qeth_schedule_recovery(card);
return NULL;
case IPA_CMD_SETBRIDGEPORT_IQD:
case IPA_CMD_SETBRIDGEPORT_OSA:
case IPA_CMD_ADDRESS_CHANGE_NOTIF:
if (card->discipline->control_event_handler(card, cmd))
return cmd;
return NULL;
case IPA_CMD_MODCCID:
return cmd;
case IPA_CMD_REGISTER_LOCAL_ADDR:
if (cmd->hdr.prot_version == QETH_PROT_IPV4)
qeth_add_local_addrs4(card, &cmd->data.local_addrs4);
else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
qeth_add_local_addrs6(card, &cmd->data.local_addrs6);
QETH_CARD_TEXT(card, 3, "irla");
return NULL;
case IPA_CMD_UNREGISTER_LOCAL_ADDR:
if (cmd->hdr.prot_version == QETH_PROT_IPV4)
qeth_del_local_addrs4(card, &cmd->data.local_addrs4);
else if (cmd->hdr.prot_version == QETH_PROT_IPV6)
qeth_del_local_addrs6(card, &cmd->data.local_addrs6);
QETH_CARD_TEXT(card, 3, "urla");
return NULL;
default:
QETH_DBF_MESSAGE(2, "Received data is IPA but not a reply!\n");
return cmd;
}
}
static void qeth_clear_ipacmd_list(struct qeth_card *card)
{
struct qeth_cmd_buffer *iob;
unsigned long flags;
QETH_CARD_TEXT(card, 4, "clipalst");
spin_lock_irqsave(&card->lock, flags);
list_for_each_entry(iob, &card->cmd_waiter_list, list_entry)
qeth_notify_cmd(iob, -ECANCELED);
spin_unlock_irqrestore(&card->lock, flags);
}
static int qeth_check_idx_response(struct qeth_card *card,
unsigned char *buffer)
{
QETH_DBF_HEX(CTRL, 2, buffer, QETH_DBF_CTRL_LEN);
if ((buffer[2] & QETH_IDX_TERMINATE_MASK) == QETH_IDX_TERMINATE) {
QETH_DBF_MESSAGE(2, "received an IDX TERMINATE with cause code %#04x\n",
buffer[4]);
QETH_CARD_TEXT(card, 2, "ckidxres");
QETH_CARD_TEXT(card, 2, " idxterm");
QETH_CARD_TEXT_(card, 2, "rc%x", buffer[4]);
if (buffer[4] == QETH_IDX_TERM_BAD_TRANSPORT ||
buffer[4] == QETH_IDX_TERM_BAD_TRANSPORT_VM) {
dev_err(&card->gdev->dev,
"The device does not support the configured transport mode\n");
return -EPROTONOSUPPORT;
}
return -EIO;