powerpc/vas: Return credits after handling fault
authorHaren Myneni <haren@linux.ibm.com>
Thu, 16 Apr 2020 06:04:19 +0000 (23:04 -0700)
committerMichael Ellerman <mpe@ellerman.id.au>
Mon, 20 Apr 2020 06:53:00 +0000 (16:53 +1000)
NX uses credit mechanism to control the number of requests issued on
a specific window at any point of time. Only send windows and fault
window are used credits. When the request is issued on a given window,
a credit is taken. This credit will be returned after that request is
processed. If credits are not available, returns RMA_Busy for send
window and RMA_Reject for fault window.

NX expects OS to return credit for send window after processing fault
CRB. Also credit has to be returned for fault window after handling
the fault.

Signed-off-by: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Signed-off-by: Haren Myneni <haren@linux.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/1587017059.2275.1064.camel@hbabu-laptop
arch/powerpc/platforms/powernv/vas-fault.c
arch/powerpc/platforms/powernv/vas-window.c
arch/powerpc/platforms/powernv/vas.h

index 354577dcf2dc060f8a8fd6e952553e22579518e9..b6bec64d793e7f9c2c1883c777e40c4cea685c63 100644 (file)
@@ -224,6 +224,10 @@ irqreturn_t vas_fault_thread_fn(int irq, void *data)
                memcpy(crb, fifo, CRB_SIZE);
                entry->stamp.nx.pswid = cpu_to_be32(FIFO_INVALID_ENTRY);
                entry->ccw |= cpu_to_be32(CCW0_INVALID);
+               /*
+                * Return credit for the fault window.
+                */
+               vas_return_credit(vinst->fault_win, false);
 
                pr_devel("VAS[%d] fault_fifo %p, fifo %p, fault_crbs %d\n",
                                vinst->vas_id, vinst->fault_fifo, fifo,
@@ -249,6 +253,11 @@ irqreturn_t vas_fault_thread_fn(int irq, void *data)
                        WARN_ON_ONCE(1);
                } else {
                        update_csb(window, crb);
+                       /*
+                        * Return credit for send window after processing
+                        * fault CRB.
+                        */
+                       vas_return_credit(window, true);
                }
        }
 }
index f12f7eb1a5a6dfa8d22e8dc7d7e8ccdc487737ea..3ef71209ff58df5171d1b1ddbee8733aad003360 100644 (file)
@@ -1317,6 +1317,42 @@ int vas_win_close(struct vas_window *window)
 }
 EXPORT_SYMBOL_GPL(vas_win_close);
 
+/*
+ * Return credit for the given window.
+ * Send windows and fault window uses credit mechanism as follows:
+ *
+ * Send windows:
+ * - The default number of credits available for each send window is
+ *   1024. It means 1024 requests can be issued asynchronously at the
+ *   same time. If the credit is not available, that request will be
+ *   returned with RMA_Busy.
+ * - One credit is taken when NX request is issued.
+ * - This credit is returned after NX processed that request.
+ * - If NX encounters translation error, kernel will return the
+ *   credit on the specific send window after processing the fault CRB.
+ *
+ * Fault window:
+ * - The total number credits available is FIFO_SIZE/CRB_SIZE.
+ *   Means 4MB/128 in the current implementation. If credit is not
+ *   available, RMA_Reject is returned.
+ * - A credit is taken when NX pastes CRB in fault FIFO.
+ * - The kernel with return credit on fault window after reading entry
+ *   from fault FIFO.
+ */
+void vas_return_credit(struct vas_window *window, bool tx)
+{
+       uint64_t val;
+
+       val = 0ULL;
+       if (tx) { /* send window */
+               val = SET_FIELD(VAS_TX_WCRED, val, 1);
+               write_hvwc_reg(window, VREG(TX_WCRED_ADDER), val);
+       } else {
+               val = SET_FIELD(VAS_LRX_WCRED, val, 1);
+               write_hvwc_reg(window, VREG(LRX_WCRED_ADDER), val);
+       }
+}
+
 struct vas_window *vas_pswid_to_window(struct vas_instance *vinst,
                uint32_t pswid)
 {
index cd165c8b2b5772629ca7dd7b7b5481c035889f30..60bdda663750b41938bfe511c096a3aab220ea0d 100644 (file)
@@ -436,6 +436,7 @@ extern void vas_window_free_dbgdir(struct vas_window *win);
 extern int vas_setup_fault_window(struct vas_instance *vinst);
 extern irqreturn_t vas_fault_thread_fn(int irq, void *data);
 extern irqreturn_t vas_fault_handler(int irq, void *dev_id);
+extern void vas_return_credit(struct vas_window *window, bool tx);
 extern struct vas_window *vas_pswid_to_window(struct vas_instance *vinst,
                                                uint32_t pswid);