forked from torvalds/linux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ehea_main.c
3571 lines (2937 loc) · 83.9 KB
/
ehea_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
/*
* linux/drivers/net/ehea/ehea_main.c
*
* eHEA ethernet device driver for IBM eServer System p
*
* (C) Copyright IBM Corp. 2006
*
* Authors:
* Christoph Raisch <raisch@de.ibm.com>
* Jan-Bernd Themann <themann@de.ibm.com>
* Thomas Klein <tklein@de.ibm.com>
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/udp.h>
#include <linux/if.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/if_ether.h>
#include <linux/notifier.h>
#include <linux/reboot.h>
#include <linux/memory.h>
#include <asm/kexec.h>
#include <linux/mutex.h>
#include <linux/prefetch.h>
#include <net/ip.h>
#include "ehea.h"
#include "ehea_qmr.h"
#include "ehea_phyp.h"
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");
MODULE_DESCRIPTION("IBM eServer HEA Driver");
MODULE_VERSION(DRV_VERSION);
static int msg_level = -1;
static int rq1_entries = EHEA_DEF_ENTRIES_RQ1;
static int rq2_entries = EHEA_DEF_ENTRIES_RQ2;
static int rq3_entries = EHEA_DEF_ENTRIES_RQ3;
static int sq_entries = EHEA_DEF_ENTRIES_SQ;
static int use_mcs = 1;
static int prop_carrier_state;
module_param(msg_level, int, 0);
module_param(rq1_entries, int, 0);
module_param(rq2_entries, int, 0);
module_param(rq3_entries, int, 0);
module_param(sq_entries, int, 0);
module_param(prop_carrier_state, int, 0);
module_param(use_mcs, int, 0);
MODULE_PARM_DESC(msg_level, "msg_level");
MODULE_PARM_DESC(prop_carrier_state, "Propagate carrier state of physical "
"port to stack. 1:yes, 0:no. Default = 0 ");
MODULE_PARM_DESC(rq3_entries, "Number of entries for Receive Queue 3 "
"[2^x - 1], x = [6..14]. Default = "
__MODULE_STRING(EHEA_DEF_ENTRIES_RQ3) ")");
MODULE_PARM_DESC(rq2_entries, "Number of entries for Receive Queue 2 "
"[2^x - 1], x = [6..14]. Default = "
__MODULE_STRING(EHEA_DEF_ENTRIES_RQ2) ")");
MODULE_PARM_DESC(rq1_entries, "Number of entries for Receive Queue 1 "
"[2^x - 1], x = [6..14]. Default = "
__MODULE_STRING(EHEA_DEF_ENTRIES_RQ1) ")");
MODULE_PARM_DESC(sq_entries, " Number of entries for the Send Queue "
"[2^x - 1], x = [6..14]. Default = "
__MODULE_STRING(EHEA_DEF_ENTRIES_SQ) ")");
MODULE_PARM_DESC(use_mcs, " Multiple receive queues, 1: enable, 0: disable, "
"Default = 1");
static int port_name_cnt;
static LIST_HEAD(adapter_list);
static unsigned long ehea_driver_flags;
static DEFINE_MUTEX(dlpar_mem_lock);
static struct ehea_fw_handle_array ehea_fw_handles;
static struct ehea_bcmc_reg_array ehea_bcmc_regs;
static int __devinit ehea_probe_adapter(struct platform_device *dev,
const struct of_device_id *id);
static int __devexit ehea_remove(struct platform_device *dev);
static struct of_device_id ehea_device_table[] = {
{
.name = "lhea",
.compatible = "IBM,lhea",
},
{},
};
MODULE_DEVICE_TABLE(of, ehea_device_table);
static struct of_platform_driver ehea_driver = {
.driver = {
.name = "ehea",
.owner = THIS_MODULE,
.of_match_table = ehea_device_table,
},
.probe = ehea_probe_adapter,
.remove = ehea_remove,
};
void ehea_dump(void *adr, int len, char *msg)
{
int x;
unsigned char *deb = adr;
for (x = 0; x < len; x += 16) {
pr_info("%s adr=%p ofs=%04x %016llx %016llx\n",
msg, deb, x, *((u64 *)&deb[0]), *((u64 *)&deb[8]));
deb += 16;
}
}
static void ehea_schedule_port_reset(struct ehea_port *port)
{
if (!test_bit(__EHEA_DISABLE_PORT_RESET, &port->flags))
schedule_work(&port->reset_task);
}
static void ehea_update_firmware_handles(void)
{
struct ehea_fw_handle_entry *arr = NULL;
struct ehea_adapter *adapter;
int num_adapters = 0;
int num_ports = 0;
int num_portres = 0;
int i = 0;
int num_fw_handles, k, l;
/* Determine number of handles */
mutex_lock(&ehea_fw_handles.lock);
list_for_each_entry(adapter, &adapter_list, list) {
num_adapters++;
for (k = 0; k < EHEA_MAX_PORTS; k++) {
struct ehea_port *port = adapter->port[k];
if (!port || (port->state != EHEA_PORT_UP))
continue;
num_ports++;
num_portres += port->num_def_qps;
}
}
num_fw_handles = num_adapters * EHEA_NUM_ADAPTER_FW_HANDLES +
num_ports * EHEA_NUM_PORT_FW_HANDLES +
num_portres * EHEA_NUM_PORTRES_FW_HANDLES;
if (num_fw_handles) {
arr = kcalloc(num_fw_handles, sizeof(*arr), GFP_KERNEL);
if (!arr)
goto out; /* Keep the existing array */
} else
goto out_update;
list_for_each_entry(adapter, &adapter_list, list) {
if (num_adapters == 0)
break;
for (k = 0; k < EHEA_MAX_PORTS; k++) {
struct ehea_port *port = adapter->port[k];
if (!port || (port->state != EHEA_PORT_UP) ||
(num_ports == 0))
continue;
for (l = 0; l < port->num_def_qps; l++) {
struct ehea_port_res *pr = &port->port_res[l];
arr[i].adh = adapter->handle;
arr[i++].fwh = pr->qp->fw_handle;
arr[i].adh = adapter->handle;
arr[i++].fwh = pr->send_cq->fw_handle;
arr[i].adh = adapter->handle;
arr[i++].fwh = pr->recv_cq->fw_handle;
arr[i].adh = adapter->handle;
arr[i++].fwh = pr->eq->fw_handle;
arr[i].adh = adapter->handle;
arr[i++].fwh = pr->send_mr.handle;
arr[i].adh = adapter->handle;
arr[i++].fwh = pr->recv_mr.handle;
}
arr[i].adh = adapter->handle;
arr[i++].fwh = port->qp_eq->fw_handle;
num_ports--;
}
arr[i].adh = adapter->handle;
arr[i++].fwh = adapter->neq->fw_handle;
if (adapter->mr.handle) {
arr[i].adh = adapter->handle;
arr[i++].fwh = adapter->mr.handle;
}
num_adapters--;
}
out_update:
kfree(ehea_fw_handles.arr);
ehea_fw_handles.arr = arr;
ehea_fw_handles.num_entries = i;
out:
mutex_unlock(&ehea_fw_handles.lock);
}
static void ehea_update_bcmc_registrations(void)
{
unsigned long flags;
struct ehea_bcmc_reg_entry *arr = NULL;
struct ehea_adapter *adapter;
struct ehea_mc_list *mc_entry;
int num_registrations = 0;
int i = 0;
int k;
spin_lock_irqsave(&ehea_bcmc_regs.lock, flags);
/* Determine number of registrations */
list_for_each_entry(adapter, &adapter_list, list)
for (k = 0; k < EHEA_MAX_PORTS; k++) {
struct ehea_port *port = adapter->port[k];
if (!port || (port->state != EHEA_PORT_UP))
continue;
num_registrations += 2; /* Broadcast registrations */
list_for_each_entry(mc_entry, &port->mc_list->list,list)
num_registrations += 2;
}
if (num_registrations) {
arr = kcalloc(num_registrations, sizeof(*arr), GFP_ATOMIC);
if (!arr)
goto out; /* Keep the existing array */
} else
goto out_update;
list_for_each_entry(adapter, &adapter_list, list) {
for (k = 0; k < EHEA_MAX_PORTS; k++) {
struct ehea_port *port = adapter->port[k];
if (!port || (port->state != EHEA_PORT_UP))
continue;
if (num_registrations == 0)
goto out_update;
arr[i].adh = adapter->handle;
arr[i].port_id = port->logical_port_id;
arr[i].reg_type = EHEA_BCMC_BROADCAST |
EHEA_BCMC_UNTAGGED;
arr[i++].macaddr = port->mac_addr;
arr[i].adh = adapter->handle;
arr[i].port_id = port->logical_port_id;
arr[i].reg_type = EHEA_BCMC_BROADCAST |
EHEA_BCMC_VLANID_ALL;
arr[i++].macaddr = port->mac_addr;
num_registrations -= 2;
list_for_each_entry(mc_entry,
&port->mc_list->list, list) {
if (num_registrations == 0)
goto out_update;
arr[i].adh = adapter->handle;
arr[i].port_id = port->logical_port_id;
arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
EHEA_BCMC_MULTICAST |
EHEA_BCMC_UNTAGGED;
arr[i++].macaddr = mc_entry->macaddr;
arr[i].adh = adapter->handle;
arr[i].port_id = port->logical_port_id;
arr[i].reg_type = EHEA_BCMC_SCOPE_ALL |
EHEA_BCMC_MULTICAST |
EHEA_BCMC_VLANID_ALL;
arr[i++].macaddr = mc_entry->macaddr;
num_registrations -= 2;
}
}
}
out_update:
kfree(ehea_bcmc_regs.arr);
ehea_bcmc_regs.arr = arr;
ehea_bcmc_regs.num_entries = i;
out:
spin_unlock_irqrestore(&ehea_bcmc_regs.lock, flags);
}
static struct rtnl_link_stats64 *ehea_get_stats64(struct net_device *dev,
struct rtnl_link_stats64 *stats)
{
struct ehea_port *port = netdev_priv(dev);
u64 rx_packets = 0, tx_packets = 0, rx_bytes = 0, tx_bytes = 0;
int i;
for (i = 0; i < port->num_def_qps; i++) {
rx_packets += port->port_res[i].rx_packets;
rx_bytes += port->port_res[i].rx_bytes;
}
for (i = 0; i < port->num_def_qps; i++) {
tx_packets += port->port_res[i].tx_packets;
tx_bytes += port->port_res[i].tx_bytes;
}
stats->tx_packets = tx_packets;
stats->rx_bytes = rx_bytes;
stats->tx_bytes = tx_bytes;
stats->rx_packets = rx_packets;
stats->multicast = port->stats.multicast;
stats->rx_errors = port->stats.rx_errors;
return stats;
}
static void ehea_update_stats(struct work_struct *work)
{
struct ehea_port *port =
container_of(work, struct ehea_port, stats_work.work);
struct net_device *dev = port->netdev;
struct rtnl_link_stats64 *stats = &port->stats;
struct hcp_ehea_port_cb2 *cb2;
u64 hret;
cb2 = (void *)get_zeroed_page(GFP_KERNEL);
if (!cb2) {
netdev_err(dev, "No mem for cb2. Some interface statistics were not updated\n");
goto resched;
}
hret = ehea_h_query_ehea_port(port->adapter->handle,
port->logical_port_id,
H_PORT_CB2, H_PORT_CB2_ALL, cb2);
if (hret != H_SUCCESS) {
netdev_err(dev, "query_ehea_port failed\n");
goto out_herr;
}
if (netif_msg_hw(port))
ehea_dump(cb2, sizeof(*cb2), "net_device_stats");
stats->multicast = cb2->rxmcp;
stats->rx_errors = cb2->rxuerr;
out_herr:
free_page((unsigned long)cb2);
resched:
schedule_delayed_work(&port->stats_work,
round_jiffies_relative(msecs_to_jiffies(1000)));
}
static void ehea_refill_rq1(struct ehea_port_res *pr, int index, int nr_of_wqes)
{
struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
struct net_device *dev = pr->port->netdev;
int max_index_mask = pr->rq1_skba.len - 1;
int fill_wqes = pr->rq1_skba.os_skbs + nr_of_wqes;
int adder = 0;
int i;
pr->rq1_skba.os_skbs = 0;
if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
if (nr_of_wqes > 0)
pr->rq1_skba.index = index;
pr->rq1_skba.os_skbs = fill_wqes;
return;
}
for (i = 0; i < fill_wqes; i++) {
if (!skb_arr_rq1[index]) {
skb_arr_rq1[index] = netdev_alloc_skb(dev,
EHEA_L_PKT_SIZE);
if (!skb_arr_rq1[index]) {
netdev_info(dev, "Unable to allocate enough skb in the array\n");
pr->rq1_skba.os_skbs = fill_wqes - i;
break;
}
}
index--;
index &= max_index_mask;
adder++;
}
if (adder == 0)
return;
/* Ring doorbell */
ehea_update_rq1a(pr->qp, adder);
}
static void ehea_init_fill_rq1(struct ehea_port_res *pr, int nr_rq1a)
{
struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
struct net_device *dev = pr->port->netdev;
int i;
if (nr_rq1a > pr->rq1_skba.len) {
netdev_err(dev, "NR_RQ1A bigger than skb array len\n");
return;
}
for (i = 0; i < nr_rq1a; i++) {
skb_arr_rq1[i] = netdev_alloc_skb(dev, EHEA_L_PKT_SIZE);
if (!skb_arr_rq1[i]) {
netdev_info(dev, "Not enough memory to allocate skb array\n");
break;
}
}
/* Ring doorbell */
ehea_update_rq1a(pr->qp, i - 1);
}
static int ehea_refill_rq_def(struct ehea_port_res *pr,
struct ehea_q_skb_arr *q_skba, int rq_nr,
int num_wqes, int wqe_type, int packet_size)
{
struct net_device *dev = pr->port->netdev;
struct ehea_qp *qp = pr->qp;
struct sk_buff **skb_arr = q_skba->arr;
struct ehea_rwqe *rwqe;
int i, index, max_index_mask, fill_wqes;
int adder = 0;
int ret = 0;
fill_wqes = q_skba->os_skbs + num_wqes;
q_skba->os_skbs = 0;
if (unlikely(test_bit(__EHEA_STOP_XFER, &ehea_driver_flags))) {
q_skba->os_skbs = fill_wqes;
return ret;
}
index = q_skba->index;
max_index_mask = q_skba->len - 1;
for (i = 0; i < fill_wqes; i++) {
u64 tmp_addr;
struct sk_buff *skb;
skb = netdev_alloc_skb_ip_align(dev, packet_size);
if (!skb) {
q_skba->os_skbs = fill_wqes - i;
if (q_skba->os_skbs == q_skba->len - 2) {
netdev_info(pr->port->netdev,
"rq%i ran dry - no mem for skb\n",
rq_nr);
ret = -ENOMEM;
}
break;
}
skb_arr[index] = skb;
tmp_addr = ehea_map_vaddr(skb->data);
if (tmp_addr == -1) {
dev_kfree_skb(skb);
q_skba->os_skbs = fill_wqes - i;
ret = 0;
break;
}
rwqe = ehea_get_next_rwqe(qp, rq_nr);
rwqe->wr_id = EHEA_BMASK_SET(EHEA_WR_ID_TYPE, wqe_type)
| EHEA_BMASK_SET(EHEA_WR_ID_INDEX, index);
rwqe->sg_list[0].l_key = pr->recv_mr.lkey;
rwqe->sg_list[0].vaddr = tmp_addr;
rwqe->sg_list[0].len = packet_size;
rwqe->data_segments = 1;
index++;
index &= max_index_mask;
adder++;
}
q_skba->index = index;
if (adder == 0)
goto out;
/* Ring doorbell */
iosync();
if (rq_nr == 2)
ehea_update_rq2a(pr->qp, adder);
else
ehea_update_rq3a(pr->qp, adder);
out:
return ret;
}
static int ehea_refill_rq2(struct ehea_port_res *pr, int nr_of_wqes)
{
return ehea_refill_rq_def(pr, &pr->rq2_skba, 2,
nr_of_wqes, EHEA_RWQE2_TYPE,
EHEA_RQ2_PKT_SIZE);
}
static int ehea_refill_rq3(struct ehea_port_res *pr, int nr_of_wqes)
{
return ehea_refill_rq_def(pr, &pr->rq3_skba, 3,
nr_of_wqes, EHEA_RWQE3_TYPE,
EHEA_MAX_PACKET_SIZE);
}
static inline int ehea_check_cqe(struct ehea_cqe *cqe, int *rq_num)
{
*rq_num = (cqe->type & EHEA_CQE_TYPE_RQ) >> 5;
if ((cqe->status & EHEA_CQE_STAT_ERR_MASK) == 0)
return 0;
if (((cqe->status & EHEA_CQE_STAT_ERR_TCP) != 0) &&
(cqe->header_length == 0))
return 0;
return -EINVAL;
}
static inline void ehea_fill_skb(struct net_device *dev,
struct sk_buff *skb, struct ehea_cqe *cqe,
struct ehea_port_res *pr)
{
int length = cqe->num_bytes_transfered - 4; /*remove CRC */
skb_put(skb, length);
skb->protocol = eth_type_trans(skb, dev);
/* The packet was not an IPV4 packet so a complemented checksum was
calculated. The value is found in the Internet Checksum field. */
if (cqe->status & EHEA_CQE_BLIND_CKSUM) {
skb->ip_summed = CHECKSUM_COMPLETE;
skb->csum = csum_unfold(~cqe->inet_checksum_value);
} else
skb->ip_summed = CHECKSUM_UNNECESSARY;
skb_record_rx_queue(skb, pr - &pr->port->port_res[0]);
}
static inline struct sk_buff *get_skb_by_index(struct sk_buff **skb_array,
int arr_len,
struct ehea_cqe *cqe)
{
int skb_index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
struct sk_buff *skb;
void *pref;
int x;
x = skb_index + 1;
x &= (arr_len - 1);
pref = skb_array[x];
if (pref) {
prefetchw(pref);
prefetchw(pref + EHEA_CACHE_LINE);
pref = (skb_array[x]->data);
prefetch(pref);
prefetch(pref + EHEA_CACHE_LINE);
prefetch(pref + EHEA_CACHE_LINE * 2);
prefetch(pref + EHEA_CACHE_LINE * 3);
}
skb = skb_array[skb_index];
skb_array[skb_index] = NULL;
return skb;
}
static inline struct sk_buff *get_skb_by_index_ll(struct sk_buff **skb_array,
int arr_len, int wqe_index)
{
struct sk_buff *skb;
void *pref;
int x;
x = wqe_index + 1;
x &= (arr_len - 1);
pref = skb_array[x];
if (pref) {
prefetchw(pref);
prefetchw(pref + EHEA_CACHE_LINE);
pref = (skb_array[x]->data);
prefetchw(pref);
prefetchw(pref + EHEA_CACHE_LINE);
}
skb = skb_array[wqe_index];
skb_array[wqe_index] = NULL;
return skb;
}
static int ehea_treat_poll_error(struct ehea_port_res *pr, int rq,
struct ehea_cqe *cqe, int *processed_rq2,
int *processed_rq3)
{
struct sk_buff *skb;
if (cqe->status & EHEA_CQE_STAT_ERR_TCP)
pr->p_stats.err_tcp_cksum++;
if (cqe->status & EHEA_CQE_STAT_ERR_IP)
pr->p_stats.err_ip_cksum++;
if (cqe->status & EHEA_CQE_STAT_ERR_CRC)
pr->p_stats.err_frame_crc++;
if (rq == 2) {
*processed_rq2 += 1;
skb = get_skb_by_index(pr->rq2_skba.arr, pr->rq2_skba.len, cqe);
dev_kfree_skb(skb);
} else if (rq == 3) {
*processed_rq3 += 1;
skb = get_skb_by_index(pr->rq3_skba.arr, pr->rq3_skba.len, cqe);
dev_kfree_skb(skb);
}
if (cqe->status & EHEA_CQE_STAT_FAT_ERR_MASK) {
if (netif_msg_rx_err(pr->port)) {
pr_err("Critical receive error for QP %d. Resetting port.\n",
pr->qp->init_attr.qp_nr);
ehea_dump(cqe, sizeof(*cqe), "CQE");
}
ehea_schedule_port_reset(pr->port);
return 1;
}
return 0;
}
static int ehea_proc_rwqes(struct net_device *dev,
struct ehea_port_res *pr,
int budget)
{
struct ehea_port *port = pr->port;
struct ehea_qp *qp = pr->qp;
struct ehea_cqe *cqe;
struct sk_buff *skb;
struct sk_buff **skb_arr_rq1 = pr->rq1_skba.arr;
struct sk_buff **skb_arr_rq2 = pr->rq2_skba.arr;
struct sk_buff **skb_arr_rq3 = pr->rq3_skba.arr;
int skb_arr_rq1_len = pr->rq1_skba.len;
int skb_arr_rq2_len = pr->rq2_skba.len;
int skb_arr_rq3_len = pr->rq3_skba.len;
int processed, processed_rq1, processed_rq2, processed_rq3;
u64 processed_bytes = 0;
int wqe_index, last_wqe_index, rq, port_reset;
processed = processed_rq1 = processed_rq2 = processed_rq3 = 0;
last_wqe_index = 0;
cqe = ehea_poll_rq1(qp, &wqe_index);
while ((processed < budget) && cqe) {
ehea_inc_rq1(qp);
processed_rq1++;
processed++;
if (netif_msg_rx_status(port))
ehea_dump(cqe, sizeof(*cqe), "CQE");
last_wqe_index = wqe_index;
rmb();
if (!ehea_check_cqe(cqe, &rq)) {
if (rq == 1) {
/* LL RQ1 */
skb = get_skb_by_index_ll(skb_arr_rq1,
skb_arr_rq1_len,
wqe_index);
if (unlikely(!skb)) {
netif_info(port, rx_err, dev,
"LL rq1: skb=NULL\n");
skb = netdev_alloc_skb(dev,
EHEA_L_PKT_SIZE);
if (!skb) {
netdev_err(dev, "Not enough memory to allocate skb\n");
break;
}
}
skb_copy_to_linear_data(skb, ((char *)cqe) + 64,
cqe->num_bytes_transfered - 4);
ehea_fill_skb(dev, skb, cqe, pr);
} else if (rq == 2) {
/* RQ2 */
skb = get_skb_by_index(skb_arr_rq2,
skb_arr_rq2_len, cqe);
if (unlikely(!skb)) {
netif_err(port, rx_err, dev,
"rq2: skb=NULL\n");
break;
}
ehea_fill_skb(dev, skb, cqe, pr);
processed_rq2++;
} else {
/* RQ3 */
skb = get_skb_by_index(skb_arr_rq3,
skb_arr_rq3_len, cqe);
if (unlikely(!skb)) {
netif_err(port, rx_err, dev,
"rq3: skb=NULL\n");
break;
}
ehea_fill_skb(dev, skb, cqe, pr);
processed_rq3++;
}
processed_bytes += skb->len;
if (cqe->status & EHEA_CQE_VLAN_TAG_XTRACT)
__vlan_hwaccel_put_tag(skb, cqe->vlan_tag);
napi_gro_receive(&pr->napi, skb);
} else {
pr->p_stats.poll_receive_errors++;
port_reset = ehea_treat_poll_error(pr, rq, cqe,
&processed_rq2,
&processed_rq3);
if (port_reset)
break;
}
cqe = ehea_poll_rq1(qp, &wqe_index);
}
pr->rx_packets += processed;
pr->rx_bytes += processed_bytes;
ehea_refill_rq1(pr, last_wqe_index, processed_rq1);
ehea_refill_rq2(pr, processed_rq2);
ehea_refill_rq3(pr, processed_rq3);
return processed;
}
#define SWQE_RESTART_CHECK 0xdeadbeaff00d0000ull
static void reset_sq_restart_flag(struct ehea_port *port)
{
int i;
for (i = 0; i < port->num_def_qps; i++) {
struct ehea_port_res *pr = &port->port_res[i];
pr->sq_restart_flag = 0;
}
wake_up(&port->restart_wq);
}
static void check_sqs(struct ehea_port *port)
{
struct ehea_swqe *swqe;
int swqe_index;
int i, k;
for (i = 0; i < port->num_def_qps; i++) {
struct ehea_port_res *pr = &port->port_res[i];
int ret;
k = 0;
swqe = ehea_get_swqe(pr->qp, &swqe_index);
memset(swqe, 0, SWQE_HEADER_SIZE);
atomic_dec(&pr->swqe_avail);
swqe->tx_control |= EHEA_SWQE_PURGE;
swqe->wr_id = SWQE_RESTART_CHECK;
swqe->tx_control |= EHEA_SWQE_SIGNALLED_COMPLETION;
swqe->tx_control |= EHEA_SWQE_IMM_DATA_PRESENT;
swqe->immediate_data_length = 80;
ehea_post_swqe(pr->qp, swqe);
ret = wait_event_timeout(port->restart_wq,
pr->sq_restart_flag == 0,
msecs_to_jiffies(100));
if (!ret) {
pr_err("HW/SW queues out of sync\n");
ehea_schedule_port_reset(pr->port);
return;
}
}
}
static struct ehea_cqe *ehea_proc_cqes(struct ehea_port_res *pr, int my_quota)
{
struct sk_buff *skb;
struct ehea_cq *send_cq = pr->send_cq;
struct ehea_cqe *cqe;
int quota = my_quota;
int cqe_counter = 0;
int swqe_av = 0;
int index;
struct netdev_queue *txq = netdev_get_tx_queue(pr->port->netdev,
pr - &pr->port->port_res[0]);
cqe = ehea_poll_cq(send_cq);
while (cqe && (quota > 0)) {
ehea_inc_cq(send_cq);
cqe_counter++;
rmb();
if (cqe->wr_id == SWQE_RESTART_CHECK) {
pr->sq_restart_flag = 1;
swqe_av++;
break;
}
if (cqe->status & EHEA_CQE_STAT_ERR_MASK) {
pr_err("Bad send completion status=0x%04X\n",
cqe->status);
if (netif_msg_tx_err(pr->port))
ehea_dump(cqe, sizeof(*cqe), "Send CQE");
if (cqe->status & EHEA_CQE_STAT_RESET_MASK) {
pr_err("Resetting port\n");
ehea_schedule_port_reset(pr->port);
break;
}
}
if (netif_msg_tx_done(pr->port))
ehea_dump(cqe, sizeof(*cqe), "CQE");
if (likely(EHEA_BMASK_GET(EHEA_WR_ID_TYPE, cqe->wr_id)
== EHEA_SWQE2_TYPE)) {
index = EHEA_BMASK_GET(EHEA_WR_ID_INDEX, cqe->wr_id);
skb = pr->sq_skba.arr[index];
dev_kfree_skb(skb);
pr->sq_skba.arr[index] = NULL;
}
swqe_av += EHEA_BMASK_GET(EHEA_WR_ID_REFILL, cqe->wr_id);
quota--;
cqe = ehea_poll_cq(send_cq);
}
ehea_update_feca(send_cq, cqe_counter);
atomic_add(swqe_av, &pr->swqe_avail);
if (unlikely(netif_tx_queue_stopped(txq) &&
(atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))) {
__netif_tx_lock(txq, smp_processor_id());
if (netif_tx_queue_stopped(txq) &&
(atomic_read(&pr->swqe_avail) >= pr->swqe_refill_th))
netif_tx_wake_queue(txq);
__netif_tx_unlock(txq);
}
wake_up(&pr->port->swqe_avail_wq);
return cqe;
}
#define EHEA_POLL_MAX_CQES 65535
static int ehea_poll(struct napi_struct *napi, int budget)
{
struct ehea_port_res *pr = container_of(napi, struct ehea_port_res,
napi);
struct net_device *dev = pr->port->netdev;
struct ehea_cqe *cqe;
struct ehea_cqe *cqe_skb = NULL;
int wqe_index;
int rx = 0;
cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
rx += ehea_proc_rwqes(dev, pr, budget - rx);
while (rx != budget) {
napi_complete(napi);
ehea_reset_cq_ep(pr->recv_cq);
ehea_reset_cq_ep(pr->send_cq);
ehea_reset_cq_n1(pr->recv_cq);
ehea_reset_cq_n1(pr->send_cq);
rmb();
cqe = ehea_poll_rq1(pr->qp, &wqe_index);
cqe_skb = ehea_poll_cq(pr->send_cq);
if (!cqe && !cqe_skb)
return rx;
if (!napi_reschedule(napi))
return rx;
cqe_skb = ehea_proc_cqes(pr, EHEA_POLL_MAX_CQES);
rx += ehea_proc_rwqes(dev, pr, budget - rx);
}
return rx;
}
#ifdef CONFIG_NET_POLL_CONTROLLER
static void ehea_netpoll(struct net_device *dev)
{
struct ehea_port *port = netdev_priv(dev);
int i;
for (i = 0; i < port->num_def_qps; i++)
napi_schedule(&port->port_res[i].napi);
}
#endif
static irqreturn_t ehea_recv_irq_handler(int irq, void *param)
{
struct ehea_port_res *pr = param;
napi_schedule(&pr->napi);
return IRQ_HANDLED;
}
static irqreturn_t ehea_qp_aff_irq_handler(int irq, void *param)
{
struct ehea_port *port = param;
struct ehea_eqe *eqe;
struct ehea_qp *qp;
u32 qp_token;
u64 resource_type, aer, aerr;
int reset_port = 0;
eqe = ehea_poll_eq(port->qp_eq);
while (eqe) {
qp_token = EHEA_BMASK_GET(EHEA_EQE_QP_TOKEN, eqe->entry);
pr_err("QP aff_err: entry=0x%llx, token=0x%x\n",
eqe->entry, qp_token);
qp = port->port_res[qp_token].qp;
resource_type = ehea_error_data(port->adapter, qp->fw_handle,
&aer, &aerr);
if (resource_type == EHEA_AER_RESTYPE_QP) {
if ((aer & EHEA_AER_RESET_MASK) ||
(aerr & EHEA_AERR_RESET_MASK))
reset_port = 1;
} else
reset_port = 1; /* Reset in case of CQ or EQ error */
eqe = ehea_poll_eq(port->qp_eq);
}
if (reset_port) {
pr_err("Resetting port\n");
ehea_schedule_port_reset(port);
}
return IRQ_HANDLED;
}
static struct ehea_port *ehea_get_port(struct ehea_adapter *adapter,
int logical_port)
{
int i;
for (i = 0; i < EHEA_MAX_PORTS; i++)
if (adapter->port[i])
if (adapter->port[i]->logical_port_id == logical_port)
return adapter->port[i];
return NULL;
}
int ehea_sense_port_attr(struct ehea_port *port)
{
int ret;
u64 hret;
struct hcp_ehea_port_cb0 *cb0;
/* may be called via ehea_neq_tasklet() */
cb0 = (void *)get_zeroed_page(GFP_ATOMIC);
if (!cb0) {
pr_err("no mem for cb0\n");
ret = -ENOMEM;
goto out;
}
hret = ehea_h_query_ehea_port(port->adapter->handle,