hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/infiniband/hw/hfi1/driver.c
....@@ -1,5 +1,5 @@
11 /*
2
- * Copyright(c) 2015-2018 Intel Corporation.
2
+ * Copyright(c) 2015-2020 Intel Corporation.
33 *
44 * This file is provided under a dual BSD/GPLv2 license. When using or
55 * redistributing this file, you may do so under either license.
....@@ -54,6 +54,7 @@
5454 #include <linux/module.h>
5555 #include <linux/prefetch.h>
5656 #include <rdma/ib_verbs.h>
57
+#include <linux/etherdevice.h>
5758
5859 #include "hfi.h"
5960 #include "trace.h"
....@@ -62,6 +63,9 @@
6263 #include "debugfs.h"
6364 #include "vnic.h"
6465 #include "fault.h"
66
+
67
+#include "ipoib.h"
68
+#include "netdev.h"
6569
6670 #undef pr_fmt
6771 #define pr_fmt(fmt) DRIVER_NAME ": " fmt
....@@ -72,8 +76,6 @@
7276 */
7377 const char ib_hfi1_version[] = HFI1_DRIVER_VERSION "\n";
7478
75
-DEFINE_SPINLOCK(hfi1_devs_lock);
76
-LIST_HEAD(hfi1_dev_list);
7779 DEFINE_MUTEX(hfi1_mutex); /* general driver use */
7880
7981 unsigned int hfi1_max_mtu = HFI1_DEFAULT_MAX_MTU;
....@@ -175,11 +177,11 @@
175177 {
176178 struct hfi1_devdata *dd;
177179 struct hfi1_pportdata *ppd;
178
- unsigned long flags;
180
+ unsigned long index, flags;
179181 int pidx, nunits_active = 0;
180182
181
- spin_lock_irqsave(&hfi1_devs_lock, flags);
182
- list_for_each_entry(dd, &hfi1_dev_list, list) {
183
+ xa_lock_irqsave(&hfi1_dev_table, flags);
184
+ xa_for_each(&hfi1_dev_table, index, dd) {
183185 if (!(dd->flags & HFI1_PRESENT) || !dd->kregbase1)
184186 continue;
185187 for (pidx = 0; pidx < dd->num_pports; ++pidx) {
....@@ -190,7 +192,7 @@
190192 }
191193 }
192194 }
193
- spin_unlock_irqrestore(&hfi1_devs_lock, flags);
195
+ xa_unlock_irqrestore(&hfi1_dev_table, flags);
194196 return nunits_active;
195197 }
196198
....@@ -264,7 +266,7 @@
264266 hfi1_dbg_fault_suppress_err(verbs_dev))
265267 return;
266268
267
- if (packet->rhf & (RHF_VCRC_ERR | RHF_ICRC_ERR))
269
+ if (packet->rhf & RHF_ICRC_ERR)
268270 return;
269271
270272 if (packet->etype == RHF_RCV_TYPE_BYPASS) {
....@@ -413,14 +415,14 @@
413415 static inline void init_packet(struct hfi1_ctxtdata *rcd,
414416 struct hfi1_packet *packet)
415417 {
416
- packet->rsize = rcd->rcvhdrqentsize; /* words */
417
- packet->maxcnt = rcd->rcvhdrq_cnt * packet->rsize; /* words */
418
+ packet->rsize = get_hdrqentsize(rcd); /* words */
419
+ packet->maxcnt = get_hdrq_cnt(rcd) * packet->rsize; /* words */
418420 packet->rcd = rcd;
419421 packet->updegr = 0;
420422 packet->etail = -1;
421423 packet->rhf_addr = get_rhf_addr(rcd);
422424 packet->rhf = rhf_to_cpu(packet->rhf_addr);
423
- packet->rhqoff = rcd->head;
425
+ packet->rhqoff = hfi1_rcd_head(rcd);
424426 packet->numpkt = 0;
425427 }
426428
....@@ -516,7 +518,9 @@
516518 */
517519 do_cnp = prescan ||
518520 (opcode >= IB_OPCODE_RC_RDMA_READ_RESPONSE_FIRST &&
519
- opcode <= IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE);
521
+ opcode <= IB_OPCODE_RC_ATOMIC_ACKNOWLEDGE) ||
522
+ opcode == TID_OP(READ_RESP) ||
523
+ opcode == TID_OP(ACK);
520524
521525 /* Call appropriate CNP handler */
522526 if (!ignore_fecn && do_cnp && fecn)
....@@ -551,22 +555,22 @@
551555 mdata->maxcnt = packet->maxcnt;
552556 mdata->ps_head = packet->rhqoff;
553557
554
- if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
558
+ if (get_dma_rtail_setting(rcd)) {
555559 mdata->ps_tail = get_rcvhdrtail(rcd);
556560 if (rcd->ctxt == HFI1_CTRL_CTXT)
557
- mdata->ps_seq = rcd->seq_cnt;
561
+ mdata->ps_seq = hfi1_seq_cnt(rcd);
558562 else
559563 mdata->ps_seq = 0; /* not used with DMA_RTAIL */
560564 } else {
561565 mdata->ps_tail = 0; /* used only with DMA_RTAIL*/
562
- mdata->ps_seq = rcd->seq_cnt;
566
+ mdata->ps_seq = hfi1_seq_cnt(rcd);
563567 }
564568 }
565569
566570 static inline int ps_done(struct ps_mdata *mdata, u64 rhf,
567571 struct hfi1_ctxtdata *rcd)
568572 {
569
- if (HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL))
573
+ if (get_dma_rtail_setting(rcd))
570574 return mdata->ps_head == mdata->ps_tail;
571575 return mdata->ps_seq != rhf_rcv_seq(rhf);
572576 }
....@@ -592,11 +596,9 @@
592596 mdata->ps_head = 0;
593597
594598 /* Control context must do seq counting */
595
- if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ||
596
- (rcd->ctxt == HFI1_CTRL_CTXT)) {
597
- if (++mdata->ps_seq > 13)
598
- mdata->ps_seq = 1;
599
- }
599
+ if (!get_dma_rtail_setting(rcd) ||
600
+ rcd->ctxt == HFI1_CTRL_CTXT)
601
+ mdata->ps_seq = hfi1_seq_incr_wrap(mdata->ps_seq);
600602 }
601603
602604 /*
....@@ -750,6 +752,39 @@
750752 return ret;
751753 }
752754
755
+static void process_rcv_packet_napi(struct hfi1_packet *packet)
756
+{
757
+ packet->etype = rhf_rcv_type(packet->rhf);
758
+
759
+ /* total length */
760
+ packet->tlen = rhf_pkt_len(packet->rhf); /* in bytes */
761
+ /* retrieve eager buffer details */
762
+ packet->etail = rhf_egr_index(packet->rhf);
763
+ packet->ebuf = get_egrbuf(packet->rcd, packet->rhf,
764
+ &packet->updegr);
765
+ /*
766
+ * Prefetch the contents of the eager buffer. It is
767
+ * OK to send a negative length to prefetch_range().
768
+ * The +2 is the size of the RHF.
769
+ */
770
+ prefetch_range(packet->ebuf,
771
+ packet->tlen - ((packet->rcd->rcvhdrqentsize -
772
+ (rhf_hdrq_offset(packet->rhf)
773
+ + 2)) * 4));
774
+
775
+ packet->rcd->rhf_rcv_function_map[packet->etype](packet);
776
+ packet->numpkt++;
777
+
778
+ /* Set up for the next packet */
779
+ packet->rhqoff += packet->rsize;
780
+ if (packet->rhqoff >= packet->maxcnt)
781
+ packet->rhqoff = 0;
782
+
783
+ packet->rhf_addr = (__le32 *)packet->rcd->rcvhdrq + packet->rhqoff +
784
+ packet->rcd->rhf_offset;
785
+ packet->rhf = rhf_to_cpu(packet->rhf_addr);
786
+}
787
+
753788 static inline int process_rcv_packet(struct hfi1_packet *packet, int thread)
754789 {
755790 int ret;
....@@ -770,7 +805,7 @@
770805 * The +2 is the size of the RHF.
771806 */
772807 prefetch_range(packet->ebuf,
773
- packet->tlen - ((packet->rcd->rcvhdrqentsize -
808
+ packet->tlen - ((get_hdrqentsize(packet->rcd) -
774809 (rhf_hdrq_offset(packet->rhf)
775810 + 2)) * 4));
776811 }
....@@ -824,8 +859,38 @@
824859 * The only thing we need to do is a final update and call for an
825860 * interrupt
826861 */
827
- update_usrhead(packet->rcd, packet->rcd->head, packet->updegr,
862
+ update_usrhead(packet->rcd, hfi1_rcd_head(packet->rcd), packet->updegr,
828863 packet->etail, rcv_intr_dynamic, packet->numpkt);
864
+}
865
+
866
+/*
867
+ * handle_receive_interrupt_napi_fp - receive a packet
868
+ * @rcd: the context
869
+ * @budget: polling budget
870
+ *
871
+ * Called from interrupt handler for receive interrupt.
872
+ * This is the fast path interrupt handler
873
+ * when executing napi soft irq environment.
874
+ */
875
+int handle_receive_interrupt_napi_fp(struct hfi1_ctxtdata *rcd, int budget)
876
+{
877
+ struct hfi1_packet packet;
878
+
879
+ init_packet(rcd, &packet);
880
+ if (last_rcv_seq(rcd, rhf_rcv_seq(packet.rhf)))
881
+ goto bail;
882
+
883
+ while (packet.numpkt < budget) {
884
+ process_rcv_packet_napi(&packet);
885
+ if (hfi1_seq_incr(rcd, rhf_rcv_seq(packet.rhf)))
886
+ break;
887
+
888
+ process_rcv_update(0, &packet);
889
+ }
890
+ hfi1_set_rcd_head(rcd, packet.rhqoff);
891
+bail:
892
+ finish_packet(&packet);
893
+ return packet.numpkt;
829894 }
830895
831896 /*
....@@ -833,13 +898,11 @@
833898 */
834899 int handle_receive_interrupt_nodma_rtail(struct hfi1_ctxtdata *rcd, int thread)
835900 {
836
- u32 seq;
837901 int last = RCV_PKT_OK;
838902 struct hfi1_packet packet;
839903
840904 init_packet(rcd, &packet);
841
- seq = rhf_rcv_seq(packet.rhf);
842
- if (seq != rcd->seq_cnt) {
905
+ if (last_rcv_seq(rcd, rhf_rcv_seq(packet.rhf))) {
843906 last = RCV_PKT_DONE;
844907 goto bail;
845908 }
....@@ -848,15 +911,12 @@
848911
849912 while (last == RCV_PKT_OK) {
850913 last = process_rcv_packet(&packet, thread);
851
- seq = rhf_rcv_seq(packet.rhf);
852
- if (++rcd->seq_cnt > 13)
853
- rcd->seq_cnt = 1;
854
- if (seq != rcd->seq_cnt)
914
+ if (hfi1_seq_incr(rcd, rhf_rcv_seq(packet.rhf)))
855915 last = RCV_PKT_DONE;
856916 process_rcv_update(last, &packet);
857917 }
858918 process_rcv_qp_work(&packet);
859
- rcd->head = packet.rhqoff;
919
+ hfi1_set_rcd_head(rcd, packet.rhqoff);
860920 bail:
861921 finish_packet(&packet);
862922 return last;
....@@ -885,15 +945,14 @@
885945 process_rcv_update(last, &packet);
886946 }
887947 process_rcv_qp_work(&packet);
888
- rcd->head = packet.rhqoff;
948
+ hfi1_set_rcd_head(rcd, packet.rhqoff);
889949 bail:
890950 finish_packet(&packet);
891951 return last;
892952 }
893953
894
-static inline void set_nodma_rtail(struct hfi1_devdata *dd, u16 ctxt)
954
+static void set_all_fastpath(struct hfi1_devdata *dd, struct hfi1_ctxtdata *rcd)
895955 {
896
- struct hfi1_ctxtdata *rcd;
897956 u16 i;
898957
899958 /*
....@@ -901,50 +960,17 @@
901960 * interrupt handler only for that context. Otherwise, switch
902961 * interrupt handler for all statically allocated kernel contexts.
903962 */
904
- if (ctxt >= dd->first_dyn_alloc_ctxt) {
905
- rcd = hfi1_rcd_get_by_index_safe(dd, ctxt);
906
- if (rcd) {
907
- rcd->do_interrupt =
908
- &handle_receive_interrupt_nodma_rtail;
909
- hfi1_rcd_put(rcd);
910
- }
911
- return;
912
- }
913
-
914
- for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) {
915
- rcd = hfi1_rcd_get_by_index(dd, i);
916
- if (rcd)
917
- rcd->do_interrupt =
918
- &handle_receive_interrupt_nodma_rtail;
963
+ if (rcd->ctxt >= dd->first_dyn_alloc_ctxt && !rcd->is_vnic) {
964
+ hfi1_rcd_get(rcd);
965
+ hfi1_set_fast(rcd);
919966 hfi1_rcd_put(rcd);
920
- }
921
-}
922
-
923
-static inline void set_dma_rtail(struct hfi1_devdata *dd, u16 ctxt)
924
-{
925
- struct hfi1_ctxtdata *rcd;
926
- u16 i;
927
-
928
- /*
929
- * For dynamically allocated kernel contexts (like vnic) switch
930
- * interrupt handler only for that context. Otherwise, switch
931
- * interrupt handler for all statically allocated kernel contexts.
932
- */
933
- if (ctxt >= dd->first_dyn_alloc_ctxt) {
934
- rcd = hfi1_rcd_get_by_index_safe(dd, ctxt);
935
- if (rcd) {
936
- rcd->do_interrupt =
937
- &handle_receive_interrupt_dma_rtail;
938
- hfi1_rcd_put(rcd);
939
- }
940967 return;
941968 }
942969
943
- for (i = HFI1_CTRL_CTXT + 1; i < dd->first_dyn_alloc_ctxt; i++) {
970
+ for (i = HFI1_CTRL_CTXT + 1; i < dd->num_rcv_contexts; i++) {
944971 rcd = hfi1_rcd_get_by_index(dd, i);
945
- if (rcd)
946
- rcd->do_interrupt =
947
- &handle_receive_interrupt_dma_rtail;
972
+ if (rcd && (i < dd->first_dyn_alloc_ctxt || rcd->is_vnic))
973
+ hfi1_set_fast(rcd);
948974 hfi1_rcd_put(rcd);
949975 }
950976 }
....@@ -960,17 +986,14 @@
960986 if (!rcd)
961987 continue;
962988 if (i < dd->first_dyn_alloc_ctxt || rcd->is_vnic)
963
- rcd->do_interrupt = &handle_receive_interrupt;
989
+ rcd->do_interrupt = rcd->slow_handler;
964990
965991 hfi1_rcd_put(rcd);
966992 }
967993 }
968994
969
-static inline int set_armed_to_active(struct hfi1_ctxtdata *rcd,
970
- struct hfi1_packet *packet,
971
- struct hfi1_devdata *dd)
995
+static bool __set_armed_to_active(struct hfi1_packet *packet)
972996 {
973
- struct work_struct *lsaw = &rcd->ppd->linkstate_active_work;
974997 u8 etype = rhf_rcv_type(packet->rhf);
975998 u8 sc = SC15_PACKET;
976999
....@@ -985,19 +1008,34 @@
9851008 sc = hfi1_16B_get_sc(hdr);
9861009 }
9871010 if (sc != SC15_PACKET) {
988
- int hwstate = driver_lstate(rcd->ppd);
1011
+ int hwstate = driver_lstate(packet->rcd->ppd);
1012
+ struct work_struct *lsaw =
1013
+ &packet->rcd->ppd->linkstate_active_work;
9891014
9901015 if (hwstate != IB_PORT_ACTIVE) {
991
- dd_dev_info(dd,
1016
+ dd_dev_info(packet->rcd->dd,
9921017 "Unexpected link state %s\n",
9931018 opa_lstate_name(hwstate));
994
- return 0;
1019
+ return false;
9951020 }
9961021
997
- queue_work(rcd->ppd->link_wq, lsaw);
998
- return 1;
1022
+ queue_work(packet->rcd->ppd->link_wq, lsaw);
1023
+ return true;
9991024 }
1000
- return 0;
1025
+ return false;
1026
+}
1027
+
1028
+/**
1029
+ * armed to active - the fast path for armed to active
1030
+ * @packet: the packet structure
1031
+ *
1032
+ * Return true if packet processing needs to bail.
1033
+ */
1034
+static bool set_armed_to_active(struct hfi1_packet *packet)
1035
+{
1036
+ if (likely(packet->rcd->ppd->host_link_state != HLS_UP_ARMED))
1037
+ return false;
1038
+ return __set_armed_to_active(packet);
10011039 }
10021040
10031041 /*
....@@ -1015,15 +1053,15 @@
10151053 struct hfi1_packet packet;
10161054 int skip_pkt = 0;
10171055
1056
+ if (!rcd->rcvhdrq)
1057
+ return RCV_PKT_OK;
10181058 /* Control context will always use the slow path interrupt handler */
10191059 needset = (rcd->ctxt == HFI1_CTRL_CTXT) ? 0 : 1;
10201060
10211061 init_packet(rcd, &packet);
10221062
1023
- if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
1024
- u32 seq = rhf_rcv_seq(packet.rhf);
1025
-
1026
- if (seq != rcd->seq_cnt) {
1063
+ if (!get_dma_rtail_setting(rcd)) {
1064
+ if (last_rcv_seq(rcd, rhf_rcv_seq(packet.rhf))) {
10271065 last = RCV_PKT_DONE;
10281066 goto bail;
10291067 }
....@@ -1040,22 +1078,15 @@
10401078 * Control context can potentially receive an invalid
10411079 * rhf. Drop such packets.
10421080 */
1043
- if (rcd->ctxt == HFI1_CTRL_CTXT) {
1044
- u32 seq = rhf_rcv_seq(packet.rhf);
1045
-
1046
- if (seq != rcd->seq_cnt)
1081
+ if (rcd->ctxt == HFI1_CTRL_CTXT)
1082
+ if (last_rcv_seq(rcd, rhf_rcv_seq(packet.rhf)))
10471083 skip_pkt = 1;
1048
- }
10491084 }
10501085
10511086 prescan_rxq(rcd, &packet);
10521087
10531088 while (last == RCV_PKT_OK) {
1054
- if (unlikely(dd->do_drop &&
1055
- atomic_xchg(&dd->drop_packet, DROP_PACKET_OFF) ==
1056
- DROP_PACKET_ON)) {
1057
- dd->do_drop = 0;
1058
-
1089
+ if (hfi1_need_drop(dd)) {
10591090 /* On to the next packet */
10601091 packet.rhqoff += packet.rsize;
10611092 packet.rhf_addr = (__le32 *)rcd->rcvhdrq +
....@@ -1067,26 +1098,14 @@
10671098 last = skip_rcv_packet(&packet, thread);
10681099 skip_pkt = 0;
10691100 } else {
1070
- /* Auto activate link on non-SC15 packet receive */
1071
- if (unlikely(rcd->ppd->host_link_state ==
1072
- HLS_UP_ARMED) &&
1073
- set_armed_to_active(rcd, &packet, dd))
1101
+ if (set_armed_to_active(&packet))
10741102 goto bail;
10751103 last = process_rcv_packet(&packet, thread);
10761104 }
10771105
1078
- if (!HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL)) {
1079
- u32 seq = rhf_rcv_seq(packet.rhf);
1080
-
1081
- if (++rcd->seq_cnt > 13)
1082
- rcd->seq_cnt = 1;
1083
- if (seq != rcd->seq_cnt)
1106
+ if (!get_dma_rtail_setting(rcd)) {
1107
+ if (hfi1_seq_incr(rcd, rhf_rcv_seq(packet.rhf)))
10841108 last = RCV_PKT_DONE;
1085
- if (needset) {
1086
- dd_dev_info(dd, "Switching to NO_DMA_RTAIL\n");
1087
- set_nodma_rtail(dd, rcd->ctxt);
1088
- needset = 0;
1089
- }
10901109 } else {
10911110 if (packet.rhqoff == hdrqtail)
10921111 last = RCV_PKT_DONE;
....@@ -1095,27 +1114,24 @@
10951114 * rhf. Drop such packets.
10961115 */
10971116 if (rcd->ctxt == HFI1_CTRL_CTXT) {
1098
- u32 seq = rhf_rcv_seq(packet.rhf);
1117
+ bool lseq;
10991118
1100
- if (++rcd->seq_cnt > 13)
1101
- rcd->seq_cnt = 1;
1102
- if (!last && (seq != rcd->seq_cnt))
1119
+ lseq = hfi1_seq_incr(rcd,
1120
+ rhf_rcv_seq(packet.rhf));
1121
+ if (!last && lseq)
11031122 skip_pkt = 1;
1104
- }
1105
-
1106
- if (needset) {
1107
- dd_dev_info(dd,
1108
- "Switching to DMA_RTAIL\n");
1109
- set_dma_rtail(dd, rcd->ctxt);
1110
- needset = 0;
11111123 }
11121124 }
11131125
1126
+ if (needset) {
1127
+ needset = false;
1128
+ set_all_fastpath(dd, rcd);
1129
+ }
11141130 process_rcv_update(last, &packet);
11151131 }
11161132
11171133 process_rcv_qp_work(&packet);
1118
- rcd->head = packet.rhqoff;
1134
+ hfi1_set_rcd_head(rcd, packet.rhqoff);
11191135
11201136 bail:
11211137 /*
....@@ -1124,6 +1140,63 @@
11241140 */
11251141 finish_packet(&packet);
11261142 return last;
1143
+}
1144
+
1145
+/*
1146
+ * handle_receive_interrupt_napi_sp - receive a packet
1147
+ * @rcd: the context
1148
+ * @budget: polling budget
1149
+ *
1150
+ * Called from interrupt handler for errors or receive interrupt.
1151
+ * This is the slow path interrupt handler
1152
+ * when executing napi soft irq environment.
1153
+ */
1154
+int handle_receive_interrupt_napi_sp(struct hfi1_ctxtdata *rcd, int budget)
1155
+{
1156
+ struct hfi1_devdata *dd = rcd->dd;
1157
+ int last = RCV_PKT_OK;
1158
+ bool needset = true;
1159
+ struct hfi1_packet packet;
1160
+
1161
+ init_packet(rcd, &packet);
1162
+ if (last_rcv_seq(rcd, rhf_rcv_seq(packet.rhf)))
1163
+ goto bail;
1164
+
1165
+ while (last != RCV_PKT_DONE && packet.numpkt < budget) {
1166
+ if (hfi1_need_drop(dd)) {
1167
+ /* On to the next packet */
1168
+ packet.rhqoff += packet.rsize;
1169
+ packet.rhf_addr = (__le32 *)rcd->rcvhdrq +
1170
+ packet.rhqoff +
1171
+ rcd->rhf_offset;
1172
+ packet.rhf = rhf_to_cpu(packet.rhf_addr);
1173
+
1174
+ } else {
1175
+ if (set_armed_to_active(&packet))
1176
+ goto bail;
1177
+ process_rcv_packet_napi(&packet);
1178
+ }
1179
+
1180
+ if (hfi1_seq_incr(rcd, rhf_rcv_seq(packet.rhf)))
1181
+ last = RCV_PKT_DONE;
1182
+
1183
+ if (needset) {
1184
+ needset = false;
1185
+ set_all_fastpath(dd, rcd);
1186
+ }
1187
+
1188
+ process_rcv_update(last, &packet);
1189
+ }
1190
+
1191
+ hfi1_set_rcd_head(rcd, packet.rhqoff);
1192
+
1193
+bail:
1194
+ /*
1195
+ * Always write head at end, and setup rcv interrupt, even
1196
+ * if no packets were processed.
1197
+ */
1198
+ finish_packet(&packet);
1199
+ return packet.numpkt;
11271200 }
11281201
11291202 /*
....@@ -1427,7 +1500,7 @@
14271500 if ((!(hfi1_is_16B_mcast(packet->dlid))) &&
14281501 (packet->dlid !=
14291502 opa_get_lid(be32_to_cpu(OPA_LID_PERMISSIVE), 16B))) {
1430
- if (packet->dlid != ppd->lid)
1503
+ if ((packet->dlid & ~((1 << ppd->lmc) - 1)) != ppd->lid)
14311504 return -EINVAL;
14321505 }
14331506
....@@ -1576,80 +1649,143 @@
15761649 return -EINVAL;
15771650 }
15781651
1579
-void handle_eflags(struct hfi1_packet *packet)
1652
+static void show_eflags_errs(struct hfi1_packet *packet)
15801653 {
15811654 struct hfi1_ctxtdata *rcd = packet->rcd;
15821655 u32 rte = rhf_rcv_type_err(packet->rhf);
15831656
1657
+ dd_dev_err(rcd->dd,
1658
+ "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s] rte 0x%x\n",
1659
+ rcd->ctxt, packet->rhf,
1660
+ packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "",
1661
+ packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "",
1662
+ packet->rhf & RHF_DC_ERR ? "dc " : "",
1663
+ packet->rhf & RHF_TID_ERR ? "tid " : "",
1664
+ packet->rhf & RHF_LEN_ERR ? "len " : "",
1665
+ packet->rhf & RHF_ECC_ERR ? "ecc " : "",
1666
+ packet->rhf & RHF_ICRC_ERR ? "icrc " : "",
1667
+ rte);
1668
+}
1669
+
1670
+void handle_eflags(struct hfi1_packet *packet)
1671
+{
1672
+ struct hfi1_ctxtdata *rcd = packet->rcd;
1673
+
15841674 rcv_hdrerr(rcd, rcd->ppd, packet);
15851675 if (rhf_err_flags(packet->rhf))
1586
- dd_dev_err(rcd->dd,
1587
- "receive context %d: rhf 0x%016llx, errs [ %s%s%s%s%s%s%s%s] rte 0x%x\n",
1588
- rcd->ctxt, packet->rhf,
1589
- packet->rhf & RHF_K_HDR_LEN_ERR ? "k_hdr_len " : "",
1590
- packet->rhf & RHF_DC_UNC_ERR ? "dc_unc " : "",
1591
- packet->rhf & RHF_DC_ERR ? "dc " : "",
1592
- packet->rhf & RHF_TID_ERR ? "tid " : "",
1593
- packet->rhf & RHF_LEN_ERR ? "len " : "",
1594
- packet->rhf & RHF_ECC_ERR ? "ecc " : "",
1595
- packet->rhf & RHF_VCRC_ERR ? "vcrc " : "",
1596
- packet->rhf & RHF_ICRC_ERR ? "icrc " : "",
1597
- rte);
1676
+ show_eflags_errs(packet);
1677
+}
1678
+
1679
+static void hfi1_ipoib_ib_rcv(struct hfi1_packet *packet)
1680
+{
1681
+ struct hfi1_ibport *ibp;
1682
+ struct net_device *netdev;
1683
+ struct hfi1_ctxtdata *rcd = packet->rcd;
1684
+ struct napi_struct *napi = rcd->napi;
1685
+ struct sk_buff *skb;
1686
+ struct hfi1_netdev_rxq *rxq = container_of(napi,
1687
+ struct hfi1_netdev_rxq, napi);
1688
+ u32 extra_bytes;
1689
+ u32 tlen, qpnum;
1690
+ bool do_work, do_cnp;
1691
+ struct hfi1_ipoib_dev_priv *priv;
1692
+
1693
+ trace_hfi1_rcvhdr(packet);
1694
+
1695
+ hfi1_setup_ib_header(packet);
1696
+
1697
+ packet->ohdr = &((struct ib_header *)packet->hdr)->u.oth;
1698
+ packet->grh = NULL;
1699
+
1700
+ if (unlikely(rhf_err_flags(packet->rhf))) {
1701
+ handle_eflags(packet);
1702
+ return;
1703
+ }
1704
+
1705
+ qpnum = ib_bth_get_qpn(packet->ohdr);
1706
+ netdev = hfi1_netdev_get_data(rcd->dd, qpnum);
1707
+ if (!netdev)
1708
+ goto drop_no_nd;
1709
+
1710
+ trace_input_ibhdr(rcd->dd, packet, !!(rhf_dc_info(packet->rhf)));
1711
+ trace_ctxt_rsm_hist(rcd->ctxt);
1712
+
1713
+ /* handle congestion notifications */
1714
+ do_work = hfi1_may_ecn(packet);
1715
+ if (unlikely(do_work)) {
1716
+ do_cnp = (packet->opcode != IB_OPCODE_CNP);
1717
+ (void)hfi1_process_ecn_slowpath(hfi1_ipoib_priv(netdev)->qp,
1718
+ packet, do_cnp);
1719
+ }
1720
+
1721
+ /*
1722
+ * We have split point after last byte of DETH
1723
+ * lets strip padding and CRC and ICRC.
1724
+ * tlen is whole packet len so we need to
1725
+ * subtract header size as well.
1726
+ */
1727
+ tlen = packet->tlen;
1728
+ extra_bytes = ib_bth_get_pad(packet->ohdr) + (SIZE_OF_CRC << 2) +
1729
+ packet->hlen;
1730
+ if (unlikely(tlen < extra_bytes))
1731
+ goto drop;
1732
+
1733
+ tlen -= extra_bytes;
1734
+
1735
+ skb = hfi1_ipoib_prepare_skb(rxq, tlen, packet->ebuf);
1736
+ if (unlikely(!skb))
1737
+ goto drop;
1738
+
1739
+ priv = hfi1_ipoib_priv(netdev);
1740
+ hfi1_ipoib_update_rx_netstats(priv, 1, skb->len);
1741
+
1742
+ skb->dev = netdev;
1743
+ skb->pkt_type = PACKET_HOST;
1744
+ netif_receive_skb(skb);
1745
+
1746
+ return;
1747
+
1748
+drop:
1749
+ ++netdev->stats.rx_dropped;
1750
+drop_no_nd:
1751
+ ibp = rcd_to_iport(packet->rcd);
1752
+ ++ibp->rvp.n_pkt_drops;
15981753 }
15991754
16001755 /*
16011756 * The following functions are called by the interrupt handler. They are type
16021757 * specific handlers for each packet type.
16031758 */
1604
-static int process_receive_ib(struct hfi1_packet *packet)
1759
+static void process_receive_ib(struct hfi1_packet *packet)
16051760 {
16061761 if (hfi1_setup_9B_packet(packet))
1607
- return RHF_RCV_CONTINUE;
1762
+ return;
16081763
16091764 if (unlikely(hfi1_dbg_should_fault_rx(packet)))
1610
- return RHF_RCV_CONTINUE;
1765
+ return;
16111766
16121767 trace_hfi1_rcvhdr(packet);
16131768
16141769 if (unlikely(rhf_err_flags(packet->rhf))) {
16151770 handle_eflags(packet);
1616
- return RHF_RCV_CONTINUE;
1771
+ return;
16171772 }
16181773
16191774 hfi1_ib_rcv(packet);
1620
- return RHF_RCV_CONTINUE;
16211775 }
16221776
1623
-static inline bool hfi1_is_vnic_packet(struct hfi1_packet *packet)
1624
-{
1625
- /* Packet received in VNIC context via RSM */
1626
- if (packet->rcd->is_vnic)
1627
- return true;
1628
-
1629
- if ((hfi1_16B_get_l2(packet->ebuf) == OPA_16B_L2_TYPE) &&
1630
- (hfi1_16B_get_l4(packet->ebuf) == OPA_16B_L4_ETHR))
1631
- return true;
1632
-
1633
- return false;
1634
-}
1635
-
1636
-static int process_receive_bypass(struct hfi1_packet *packet)
1777
+static void process_receive_bypass(struct hfi1_packet *packet)
16371778 {
16381779 struct hfi1_devdata *dd = packet->rcd->dd;
16391780
1640
- if (hfi1_is_vnic_packet(packet)) {
1641
- hfi1_vnic_bypass_rcv(packet);
1642
- return RHF_RCV_CONTINUE;
1643
- }
1644
-
16451781 if (hfi1_setup_bypass_packet(packet))
1646
- return RHF_RCV_CONTINUE;
1782
+ return;
16471783
16481784 trace_hfi1_rcvhdr(packet);
16491785
16501786 if (unlikely(rhf_err_flags(packet->rhf))) {
16511787 handle_eflags(packet);
1652
- return RHF_RCV_CONTINUE;
1788
+ return;
16531789 }
16541790
16551791 if (hfi1_16B_get_l2(packet->hdr) == 0x2) {
....@@ -1672,17 +1808,16 @@
16721808 (OPA_EI_STATUS_SMASK | BAD_L2_ERR);
16731809 }
16741810 }
1675
- return RHF_RCV_CONTINUE;
16761811 }
16771812
1678
-static int process_receive_error(struct hfi1_packet *packet)
1813
+static void process_receive_error(struct hfi1_packet *packet)
16791814 {
16801815 /* KHdrHCRCErr -- KDETH packet with a bad HCRC */
16811816 if (unlikely(
16821817 hfi1_dbg_fault_suppress_err(&packet->rcd->dd->verbs_dev) &&
16831818 (rhf_rcv_type_err(packet->rhf) == RHF_RCV_TYPE_ERROR ||
16841819 packet->rhf & RHF_DC_ERR)))
1685
- return RHF_RCV_CONTINUE;
1820
+ return;
16861821
16871822 hfi1_setup_ib_header(packet);
16881823 handle_eflags(packet);
....@@ -1690,61 +1825,71 @@
16901825 if (unlikely(rhf_err_flags(packet->rhf)))
16911826 dd_dev_err(packet->rcd->dd,
16921827 "Unhandled error packet received. Dropping.\n");
1693
-
1694
- return RHF_RCV_CONTINUE;
16951828 }
16961829
1697
-static int kdeth_process_expected(struct hfi1_packet *packet)
1830
+static void kdeth_process_expected(struct hfi1_packet *packet)
16981831 {
16991832 hfi1_setup_9B_packet(packet);
17001833 if (unlikely(hfi1_dbg_should_fault_rx(packet)))
1701
- return RHF_RCV_CONTINUE;
1834
+ return;
17021835
1703
- if (unlikely(rhf_err_flags(packet->rhf)))
1704
- handle_eflags(packet);
1836
+ if (unlikely(rhf_err_flags(packet->rhf))) {
1837
+ struct hfi1_ctxtdata *rcd = packet->rcd;
17051838
1706
- dd_dev_err(packet->rcd->dd,
1707
- "Unhandled expected packet received. Dropping.\n");
1708
- return RHF_RCV_CONTINUE;
1839
+ if (hfi1_handle_kdeth_eflags(rcd, rcd->ppd, packet))
1840
+ return;
1841
+ }
1842
+
1843
+ hfi1_kdeth_expected_rcv(packet);
17091844 }
17101845
1711
-static int kdeth_process_eager(struct hfi1_packet *packet)
1846
+static void kdeth_process_eager(struct hfi1_packet *packet)
17121847 {
17131848 hfi1_setup_9B_packet(packet);
17141849 if (unlikely(hfi1_dbg_should_fault_rx(packet)))
1715
- return RHF_RCV_CONTINUE;
1716
- if (unlikely(rhf_err_flags(packet->rhf)))
1717
- handle_eflags(packet);
1850
+ return;
17181851
1719
- dd_dev_err(packet->rcd->dd,
1720
- "Unhandled eager packet received. Dropping.\n");
1721
- return RHF_RCV_CONTINUE;
1852
+ trace_hfi1_rcvhdr(packet);
1853
+ if (unlikely(rhf_err_flags(packet->rhf))) {
1854
+ struct hfi1_ctxtdata *rcd = packet->rcd;
1855
+
1856
+ show_eflags_errs(packet);
1857
+ if (hfi1_handle_kdeth_eflags(rcd, rcd->ppd, packet))
1858
+ return;
1859
+ }
1860
+
1861
+ hfi1_kdeth_eager_rcv(packet);
17221862 }
17231863
1724
-static int process_receive_invalid(struct hfi1_packet *packet)
1864
+static void process_receive_invalid(struct hfi1_packet *packet)
17251865 {
17261866 dd_dev_err(packet->rcd->dd, "Invalid packet type %d. Dropping\n",
17271867 rhf_rcv_type(packet->rhf));
1728
- return RHF_RCV_CONTINUE;
17291868 }
1869
+
1870
+#define HFI1_RCVHDR_DUMP_MAX 5
17301871
17311872 void seqfile_dump_rcd(struct seq_file *s, struct hfi1_ctxtdata *rcd)
17321873 {
17331874 struct hfi1_packet packet;
17341875 struct ps_mdata mdata;
1876
+ int i;
17351877
1736
- seq_printf(s, "Rcd %u: RcvHdr cnt %u entsize %u %s head %llu tail %llu\n",
1737
- rcd->ctxt, rcd->rcvhdrq_cnt, rcd->rcvhdrqentsize,
1738
- HFI1_CAP_KGET_MASK(rcd->flags, DMA_RTAIL) ?
1878
+ seq_printf(s, "Rcd %u: RcvHdr cnt %u entsize %u %s ctrl 0x%08llx status 0x%08llx, head %llu tail %llu sw head %u\n",
1879
+ rcd->ctxt, get_hdrq_cnt(rcd), get_hdrqentsize(rcd),
1880
+ get_dma_rtail_setting(rcd) ?
17391881 "dma_rtail" : "nodma_rtail",
1882
+ read_kctxt_csr(rcd->dd, rcd->ctxt, RCV_CTXT_CTRL),
1883
+ read_kctxt_csr(rcd->dd, rcd->ctxt, RCV_CTXT_STATUS),
17401884 read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_HEAD) &
17411885 RCV_HDR_HEAD_HEAD_MASK,
1742
- read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL));
1886
+ read_uctxt_csr(rcd->dd, rcd->ctxt, RCV_HDR_TAIL),
1887
+ rcd->head);
17431888
17441889 init_packet(rcd, &packet);
17451890 init_ps_mdata(&mdata, &packet);
17461891
1747
- while (1) {
1892
+ for (i = 0; i < HFI1_RCVHDR_DUMP_MAX; i++) {
17481893 __le32 *rhf_addr = (__le32 *)rcd->rcvhdrq + mdata.ps_head +
17491894 rcd->rhf_offset;
17501895 struct ib_header *hdr;
....@@ -1796,3 +1941,14 @@
17961941 [RHF_RCV_TYPE_INVALID6] = process_receive_invalid,
17971942 [RHF_RCV_TYPE_INVALID7] = process_receive_invalid,
17981943 };
1944
+
1945
+const rhf_rcv_function_ptr netdev_rhf_rcv_functions[] = {
1946
+ [RHF_RCV_TYPE_EXPECTED] = process_receive_invalid,
1947
+ [RHF_RCV_TYPE_EAGER] = process_receive_invalid,
1948
+ [RHF_RCV_TYPE_IB] = hfi1_ipoib_ib_rcv,
1949
+ [RHF_RCV_TYPE_ERROR] = process_receive_error,
1950
+ [RHF_RCV_TYPE_BYPASS] = hfi1_vnic_bypass_rcv,
1951
+ [RHF_RCV_TYPE_INVALID5] = process_receive_invalid,
1952
+ [RHF_RCV_TYPE_INVALID6] = process_receive_invalid,
1953
+ [RHF_RCV_TYPE_INVALID7] = process_receive_invalid,
1954
+};