forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/drivers/net/ethernet/cavium/liquidio/octeon_droq.c
....@@ -280,13 +280,10 @@
280280 dev_dbg(&oct->pci_dev->dev, "droq[%d]: num_desc: %d\n", q_no,
281281 droq->max_count);
282282
283
- droq->recv_buf_list = (struct octeon_recv_buffer *)
284
- vzalloc_node(array_size(droq->max_count, OCT_DROQ_RECVBUF_SIZE),
285
- numa_node);
283
+ droq->recv_buf_list = vzalloc_node(array_size(droq->max_count, OCT_DROQ_RECVBUF_SIZE),
284
+ numa_node);
286285 if (!droq->recv_buf_list)
287
- droq->recv_buf_list = (struct octeon_recv_buffer *)
288
- vzalloc(array_size(droq->max_count,
289
- OCT_DROQ_RECVBUF_SIZE));
286
+ droq->recv_buf_list = vzalloc(array_size(droq->max_count, OCT_DROQ_RECVBUF_SIZE));
290287 if (!droq->recv_buf_list) {
291288 dev_err(&oct->pci_dev->dev, "Output queue recv buf list alloc failed\n");
292289 goto init_droq_fail;
....@@ -300,8 +297,6 @@
300297
301298 dev_dbg(&oct->pci_dev->dev, "DROQ INIT: max_empty_descs: %d\n",
302299 droq->max_empty_descs);
303
-
304
- spin_lock_init(&droq->lock);
305300
306301 INIT_LIST_HEAD(&droq->dispatch_list);
307302
....@@ -333,8 +328,6 @@
333328 * Returns:
334329 * Success: Pointer to recv_info_t
335330 * Failure: NULL.
336
- * Locks:
337
- * The droq->lock is held when this routine is called.
338331 */
339332 static inline struct octeon_recv_info *octeon_create_recv_info(
340333 struct octeon_device *octeon_dev,
....@@ -433,8 +426,6 @@
433426 * up buffers (that were not dispatched) to form a contiguous ring.
434427 * Returns:
435428 * No of descriptors refilled.
436
- * Locks:
437
- * This routine is called with droq->lock held.
438429 */
439430 static u32
440431 octeon_droq_refill(struct octeon_device *octeon_dev, struct octeon_droq *droq)
....@@ -449,8 +440,7 @@
449440
450441 while (droq->refill_count && (desc_refilled < droq->max_count)) {
451442 /* If a valid buffer exists (happens if there is no dispatch),
452
- * reuse
453
- * the buffer, else allocate.
443
+ * reuse the buffer, else allocate.
454444 */
455445 if (!droq->recv_buf_list[droq->refill_idx].buffer) {
456446 pg_info =
....@@ -503,34 +493,35 @@
503493
504494 /** check if we can allocate packets to get out of oom.
505495 * @param droq - Droq being checked.
506
- * @return does not return anything
496
+ * @return 1 if fails to refill minimum
507497 */
508
-void octeon_droq_check_oom(struct octeon_droq *droq)
498
+int octeon_retry_droq_refill(struct octeon_droq *droq)
509499 {
510
- int desc_refilled;
511500 struct octeon_device *oct = droq->oct_dev;
501
+ int desc_refilled, reschedule = 1;
502
+ u32 pkts_credit;
512503
513
- if (readl(droq->pkts_credit_reg) <= CN23XX_SLI_DEF_BP) {
514
- spin_lock_bh(&droq->lock);
515
- desc_refilled = octeon_droq_refill(oct, droq);
516
- if (desc_refilled) {
517
- /* Flush the droq descriptor data to memory to be sure
518
- * that when we update the credits the data in memory
519
- * is accurate.
520
- */
521
- wmb();
522
- writel(desc_refilled, droq->pkts_credit_reg);
523
- /* make sure mmio write completes */
524
- mmiowb();
525
- }
526
- spin_unlock_bh(&droq->lock);
504
+ pkts_credit = readl(droq->pkts_credit_reg);
505
+ desc_refilled = octeon_droq_refill(oct, droq);
506
+ if (desc_refilled) {
507
+ /* Flush the droq descriptor data to memory to be sure
508
+ * that when we update the credits the data in memory
509
+ * is accurate.
510
+ */
511
+ wmb();
512
+ writel(desc_refilled, droq->pkts_credit_reg);
513
+
514
+ if (pkts_credit + desc_refilled >= CN23XX_SLI_DEF_BP)
515
+ reschedule = 0;
527516 }
517
+
518
+ return reschedule;
528519 }
529520
530521 static inline u32
531522 octeon_droq_get_bufcount(u32 buf_size, u32 total_len)
532523 {
533
- return ((total_len + buf_size - 1) / buf_size);
524
+ return DIV_ROUND_UP(total_len, buf_size);
534525 }
535526
536527 static int
....@@ -603,9 +594,9 @@
603594 struct octeon_droq *droq,
604595 u32 pkts_to_process)
605596 {
597
+ u32 pkt, total_len = 0, pkt_count, retval;
606598 struct octeon_droq_info *info;
607599 union octeon_rh *rh;
608
- u32 pkt, total_len = 0, pkt_count;
609600
610601 pkt_count = pkts_to_process;
611602
....@@ -709,30 +700,41 @@
709700 if (droq->refill_count >= droq->refill_threshold) {
710701 int desc_refilled = octeon_droq_refill(oct, droq);
711702
712
- /* Flush the droq descriptor data to memory to be sure
713
- * that when we update the credits the data in memory
714
- * is accurate.
715
- */
716
- wmb();
717
- writel((desc_refilled), droq->pkts_credit_reg);
718
- /* make sure mmio write completes */
719
- mmiowb();
703
+ if (desc_refilled) {
704
+ /* Flush the droq descriptor data to memory to
705
+ * be sure that when we update the credits the
706
+ * data in memory is accurate.
707
+ */
708
+ wmb();
709
+ writel(desc_refilled, droq->pkts_credit_reg);
710
+ }
720711 }
721
-
722712 } /* for (each packet)... */
723713
724714 /* Increment refill_count by the number of buffers processed. */
725715 droq->stats.pkts_received += pkt;
726716 droq->stats.bytes_received += total_len;
727717
718
+ retval = pkt;
728719 if ((droq->ops.drop_on_max) && (pkts_to_process - pkt)) {
729720 octeon_droq_drop_packets(oct, droq, (pkts_to_process - pkt));
730721
731722 droq->stats.dropped_toomany += (pkts_to_process - pkt);
732
- return pkts_to_process;
723
+ retval = pkts_to_process;
733724 }
734725
735
- return pkt;
726
+ atomic_sub(retval, &droq->pkts_pending);
727
+
728
+ if (droq->refill_count >= droq->refill_threshold &&
729
+ readl(droq->pkts_credit_reg) < CN23XX_SLI_DEF_BP) {
730
+ octeon_droq_check_hw_for_pkts(droq);
731
+
732
+ /* Make sure there are no pkts_pending */
733
+ if (!atomic_read(&droq->pkts_pending))
734
+ octeon_schedule_rxq_oom_work(oct, droq);
735
+ }
736
+
737
+ return retval;
736738 }
737739
738740 int
....@@ -740,29 +742,19 @@
740742 struct octeon_droq *droq,
741743 u32 budget)
742744 {
743
- u32 pkt_count = 0, pkts_processed = 0;
745
+ u32 pkt_count = 0;
744746 struct list_head *tmp, *tmp2;
745
-
746
- /* Grab the droq lock */
747
- spin_lock(&droq->lock);
748747
749748 octeon_droq_check_hw_for_pkts(droq);
750749 pkt_count = atomic_read(&droq->pkts_pending);
751750
752
- if (!pkt_count) {
753
- spin_unlock(&droq->lock);
751
+ if (!pkt_count)
754752 return 0;
755
- }
756753
757754 if (pkt_count > budget)
758755 pkt_count = budget;
759756
760
- pkts_processed = octeon_droq_fast_process_packets(oct, droq, pkt_count);
761
-
762
- atomic_sub(pkts_processed, &droq->pkts_pending);
763
-
764
- /* Release the spin lock */
765
- spin_unlock(&droq->lock);
757
+ octeon_droq_fast_process_packets(oct, droq, pkt_count);
766758
767759 list_for_each_safe(tmp, tmp2, &droq->dispatch_list) {
768760 struct __dispatch *rdisp = (struct __dispatch *)tmp;
....@@ -782,7 +774,7 @@
782774 return 0;
783775 }
784776
785
-/**
777
+/*
786778 * Utility function to poll for packets. check_hw_for_packets must be
787779 * called before calling this routine.
788780 */
....@@ -798,8 +790,6 @@
798790 if (budget > droq->max_count)
799791 budget = droq->max_count;
800792
801
- spin_lock(&droq->lock);
802
-
803793 while (total_pkts_processed < budget) {
804794 octeon_droq_check_hw_for_pkts(droq);
805795
....@@ -813,12 +803,8 @@
813803 octeon_droq_fast_process_packets(oct, droq,
814804 pkts_available);
815805
816
- atomic_sub(pkts_processed, &droq->pkts_pending);
817
-
818806 total_pkts_processed += pkts_processed;
819807 }
820
-
821
- spin_unlock(&droq->lock);
822808
823809 list_for_each_safe(tmp, tmp2, &droq->dispatch_list) {
824810 struct __dispatch *rdisp = (struct __dispatch *)tmp;
....@@ -879,9 +865,8 @@
879865 int octeon_register_droq_ops(struct octeon_device *oct, u32 q_no,
880866 struct octeon_droq_ops *ops)
881867 {
882
- struct octeon_droq *droq;
883
- unsigned long flags;
884868 struct octeon_config *oct_cfg = NULL;
869
+ struct octeon_droq *droq;
885870
886871 oct_cfg = octeon_get_conf(oct);
887872
....@@ -901,21 +886,15 @@
901886 }
902887
903888 droq = oct->droq[q_no];
904
-
905
- spin_lock_irqsave(&droq->lock, flags);
906
-
907889 memcpy(&droq->ops, ops, sizeof(struct octeon_droq_ops));
908
-
909
- spin_unlock_irqrestore(&droq->lock, flags);
910890
911891 return 0;
912892 }
913893
914894 int octeon_unregister_droq_ops(struct octeon_device *oct, u32 q_no)
915895 {
916
- unsigned long flags;
917
- struct octeon_droq *droq;
918896 struct octeon_config *oct_cfg = NULL;
897
+ struct octeon_droq *droq;
919898
920899 oct_cfg = octeon_get_conf(oct);
921900
....@@ -936,13 +915,9 @@
936915 return 0;
937916 }
938917
939
- spin_lock_irqsave(&droq->lock, flags);
940
-
941918 droq->ops.fptr = NULL;
942919 droq->ops.farg = NULL;
943920 droq->ops.drop_on_max = 0;
944
-
945
- spin_unlock_irqrestore(&droq->lock, flags);
946921
947922 return 0;
948923 }