xref: /dpdk/drivers/event/dlb2/pf/base/dlb2_resource.h (revision 8d1d9070bbe97d58115179c1e5dfc85a7cfe7a65)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2020 Intel Corporation
3  */
4 
5 #ifndef __DLB2_RESOURCE_H
6 #define __DLB2_RESOURCE_H
7 
8 #include "dlb2_user.h"
9 #include "dlb2_osdep_types.h"
10 
11 /**
12  * dlb2_resource_init() - initialize the device
13  * @hw: pointer to struct dlb2_hw.
14  * @ver: device version.
15  *
16  * This function initializes the device's software state (pointed to by the hw
17  * argument) and programs global scheduling QoS registers. This function should
18  * be called during driver initialization.
19  *
20  * The dlb2_hw struct must be unique per DLB 2.0 device and persist until the
21  * device is reset.
22  *
23  * Return:
24  * Returns 0 upon success, <0 otherwise.
25  */
26 int dlb2_resource_init(struct dlb2_hw *hw, enum dlb2_hw_ver ver, const void *probe_args);
27 
28 /**
29  * dlb2_resource_probe() - probe hw resources
30  * @hw: pointer to struct dlb2_hw.
31  *
32  * This function probes hw resources for best port allocation to producer
33  * cores.
34  *
35  * Return:
36  * Returns 0 upon success, <0 otherwise.
37  */
38 int dlb2_resource_probe(struct dlb2_hw *hw, const void *probe_args);
39 
40 
41 /**
42  * dlb2_clr_pmcsr_disable() - power on bulk of DLB 2.0 logic
43  * @hw: dlb2_hw handle for a particular device.
44  * @ver: device version.
45  *
46  * Clearing the PMCSR must be done at initialization to make the device fully
47  * operational.
48  */
49 void dlb2_clr_pmcsr_disable(struct dlb2_hw *hw, enum dlb2_hw_ver ver);
50 
51 /**
52  * dlb2_resource_free() - free device state memory
53  * @hw: dlb2_hw handle for a particular device.
54  *
55  * This function frees software state pointed to by dlb2_hw. This function
56  * should be called when resetting the device or unloading the driver.
57  */
58 void dlb2_resource_free(struct dlb2_hw *hw);
59 
60 /**
61  * dlb2_resource_reset() - reset in-use resources to their initial state
62  * @hw: dlb2_hw handle for a particular device.
63  *
64  * This function resets in-use resources, and makes them available for use.
65  * All resources go back to their owning function, whether a PF or a VF.
66  */
67 void dlb2_resource_reset(struct dlb2_hw *hw);
68 
69 /**
70  * dlb2_hw_create_sched_domain() - create a scheduling domain
71  * @hw: dlb2_hw handle for a particular device.
72  * @args: scheduling domain creation arguments.
73  * @resp: response structure.
74  * @vdev_request: indicates whether this request came from a vdev.
75  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
76  *
77  * This function creates a scheduling domain containing the resources specified
78  * in args. The individual resources (queues, ports, credits) can be configured
79  * after creating a scheduling domain.
80  *
81  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
82  * device.
83  *
84  * Return:
85  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
86  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
87  * contains the domain ID.
88  *
89  * resp->id contains a virtual ID if vdev_request is true.
90  *
91  * Errors:
92  * EINVAL - A requested resource is unavailable, or the requested domain name
93  *	    is already in use.
94  * EFAULT - Internal error (resp->status not set).
95  */
96 int dlb2_hw_create_sched_domain(struct dlb2_hw *hw,
97 				struct dlb2_create_sched_domain_args *args,
98 				struct dlb2_cmd_response *resp,
99 				bool vdev_request,
100 				unsigned int vdev_id);
101 
102 /**
103  * dlb2_hw_create_ldb_queue() - create a load-balanced queue
104  * @hw: dlb2_hw handle for a particular device.
105  * @domain_id: domain ID.
106  * @args: queue creation arguments.
107  * @resp: response structure.
108  * @vdev_request: indicates whether this request came from a vdev.
109  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
110  *
111  * This function creates a load-balanced queue.
112  *
113  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
114  * device.
115  *
116  * Return:
117  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
118  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
119  * contains the queue ID.
120  *
121  * resp->id contains a virtual ID if vdev_request is true.
122  *
123  * Errors:
124  * EINVAL - A requested resource is unavailable, the domain is not configured,
125  *	    the domain has already been started, or the requested queue name is
126  *	    already in use.
127  * EFAULT - Internal error (resp->status not set).
128  */
129 int dlb2_hw_create_ldb_queue(struct dlb2_hw *hw,
130 			     u32 domain_id,
131 			     struct dlb2_create_ldb_queue_args *args,
132 			     struct dlb2_cmd_response *resp,
133 			     bool vdev_request,
134 			     unsigned int vdev_id);
135 
136 /**
137  * dlb2_hw_create_dir_queue() - create a directed queue
138  * @hw: dlb2_hw handle for a particular device.
139  * @domain_id: domain ID.
140  * @args: queue creation arguments.
141  * @resp: response structure.
142  * @vdev_request: indicates whether this request came from a vdev.
143  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
144  *
145  * This function creates a directed queue.
146  *
147  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
148  * device.
149  *
150  * Return:
151  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
152  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
153  * contains the queue ID.
154  *
155  * resp->id contains a virtual ID if vdev_request is true.
156  *
157  * Errors:
158  * EINVAL - A requested resource is unavailable, the domain is not configured,
159  *	    or the domain has already been started.
160  * EFAULT - Internal error (resp->status not set).
161  */
162 int dlb2_hw_create_dir_queue(struct dlb2_hw *hw,
163 			     u32 domain_id,
164 			     struct dlb2_create_dir_queue_args *args,
165 			     struct dlb2_cmd_response *resp,
166 			     bool vdev_request,
167 			     unsigned int vdev_id);
168 
169 /**
170  * dlb2_hw_create_dir_port() - create a directed port
171  * @hw: dlb2_hw handle for a particular device.
172  * @domain_id: domain ID.
173  * @args: port creation arguments.
174  * @cq_dma_base: base address of the CQ memory. This can be a PA or an IOVA.
175  * @resp: response structure.
176  * @vdev_request: indicates whether this request came from a vdev.
177  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
178  *
179  * This function creates a directed port.
180  *
181  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
182  * device.
183  *
184  * Return:
185  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
186  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
187  * contains the port ID.
188  *
189  * resp->id contains a virtual ID if vdev_request is true.
190  *
191  * Errors:
192  * EINVAL - A requested resource is unavailable, a credit setting is invalid, a
193  *	    pointer address is not properly aligned, the domain is not
194  *	    configured, or the domain has already been started.
195  * EFAULT - Internal error (resp->status not set).
196  */
197 int dlb2_hw_create_dir_port(struct dlb2_hw *hw,
198 			    u32 domain_id,
199 			    struct dlb2_create_dir_port_args *args,
200 			    uintptr_t cq_dma_base,
201 			    struct dlb2_cmd_response *resp,
202 			    bool vdev_request,
203 			    unsigned int vdev_id);
204 
205 /**
206  * dlb2_hw_create_ldb_port() - create a load-balanced port
207  * @hw: dlb2_hw handle for a particular device.
208  * @domain_id: domain ID.
209  * @args: port creation arguments.
210  * @cq_dma_base: base address of the CQ memory. This can be a PA or an IOVA.
211  * @resp: response structure.
212  * @vdev_request: indicates whether this request came from a vdev.
213  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
214  *
215  * This function creates a load-balanced port.
216  *
217  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
218  * device.
219  *
220  * Return:
221  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
222  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
223  * contains the port ID.
224  *
225  * resp->id contains a virtual ID if vdev_request is true.
226  *
227  * Errors:
228  * EINVAL - A requested resource is unavailable, a credit setting is invalid, a
229  *	    pointer address is not properly aligned, the domain is not
230  *	    configured, or the domain has already been started.
231  * EFAULT - Internal error (resp->status not set).
232  */
233 int dlb2_hw_create_ldb_port(struct dlb2_hw *hw,
234 			    u32 domain_id,
235 			    struct dlb2_create_ldb_port_args *args,
236 			    uintptr_t cq_dma_base,
237 			    struct dlb2_cmd_response *resp,
238 			    bool vdev_request,
239 			    unsigned int vdev_id);
240 
241 /**
242  * dlb2_hw_start_domain() - start a scheduling domain
243  * @hw: dlb2_hw handle for a particular device.
244  * @domain_id: domain ID.
245  * @args: start domain arguments.
246  * @resp: response structure.
247  * @vdev_request: indicates whether this request came from a vdev.
248  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
249  *
250  * This function starts a scheduling domain, which allows applications to send
251  * traffic through it. Once a domain is started, its resources can no longer be
252  * configured (besides QID remapping and port enable/disable).
253  *
254  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
255  * device.
256  *
257  * Return:
258  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
259  * assigned a detailed error code from enum dlb2_error.
260  *
261  * Errors:
262  * EINVAL - the domain is not configured, or the domain is already started.
263  */
264 int dlb2_hw_start_domain(struct dlb2_hw *hw,
265 			 u32 domain_id,
266 			 struct dlb2_start_domain_args *args,
267 			 struct dlb2_cmd_response *resp,
268 			 bool vdev_request,
269 			 unsigned int vdev_id);
270 
271 /**
272  * dlb2_hw_map_qid() - map a load-balanced queue to a load-balanced port
273  * @hw: dlb2_hw handle for a particular device.
274  * @domain_id: domain ID.
275  * @args: map QID arguments.
276  * @resp: response structure.
277  * @vdev_request: indicates whether this request came from a vdev.
278  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
279  *
280  * This function configures the DLB to schedule QEs from the specified queue
281  * to the specified port. Each load-balanced port can be mapped to up to 8
282  * queues; each load-balanced queue can potentially map to all the
283  * load-balanced ports.
284  *
285  * A successful return does not necessarily mean the mapping was configured. If
286  * this function is unable to immediately map the queue to the port, it will
287  * add the requested operation to a per-port list of pending map/unmap
288  * operations, and (if it's not already running) launch a kernel thread that
289  * periodically attempts to process all pending operations. In a sense, this is
290  * an asynchronous function.
291  *
292  * This asynchronicity creates two views of the state of hardware: the actual
293  * hardware state and the requested state (as if every request completed
294  * immediately). If there are any pending map/unmap operations, the requested
295  * state will differ from the actual state. All validation is performed with
296  * respect to the pending state; for instance, if there are 8 pending map
297  * operations for port X, a request for a 9th will fail because a load-balanced
298  * port can only map up to 8 queues.
299  *
300  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
301  * device.
302  *
303  * Return:
304  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
305  * assigned a detailed error code from enum dlb2_error.
306  *
307  * Errors:
308  * EINVAL - A requested resource is unavailable, invalid port or queue ID, or
309  *	    the domain is not configured.
310  * EFAULT - Internal error (resp->status not set).
311  */
312 int dlb2_hw_map_qid(struct dlb2_hw *hw,
313 		    u32 domain_id,
314 		    struct dlb2_map_qid_args *args,
315 		    struct dlb2_cmd_response *resp,
316 		    bool vdev_request,
317 		    unsigned int vdev_id);
318 
319 /**
320  * dlb2_hw_unmap_qid() - Unmap a load-balanced queue from a load-balanced port
321  * @hw: dlb2_hw handle for a particular device.
322  * @domain_id: domain ID.
323  * @args: unmap QID arguments.
324  * @resp: response structure.
325  * @vdev_request: indicates whether this request came from a vdev.
326  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
327  *
328  * This function configures the DLB to stop scheduling QEs from the specified
329  * queue to the specified port.
330  *
331  * A successful return does not necessarily mean the mapping was removed. If
332  * this function is unable to immediately unmap the queue from the port, it
333  * will add the requested operation to a per-port list of pending map/unmap
334  * operations, and (if it's not already running) launch a kernel thread that
335  * periodically attempts to process all pending operations. See
336  * dlb2_hw_map_qid() for more details.
337  *
338  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
339  * device.
340  *
341  * Return:
342  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
343  * assigned a detailed error code from enum dlb2_error.
344  *
345  * Errors:
346  * EINVAL - A requested resource is unavailable, invalid port or queue ID, or
347  *	    the domain is not configured.
348  * EFAULT - Internal error (resp->status not set).
349  */
350 int dlb2_hw_unmap_qid(struct dlb2_hw *hw,
351 		      u32 domain_id,
352 		      struct dlb2_unmap_qid_args *args,
353 		      struct dlb2_cmd_response *resp,
354 		      bool vdev_request,
355 		      unsigned int vdev_id);
356 
357 /**
358  * dlb2_finish_unmap_qid_procedures() - finish any pending unmap procedures
359  * @hw: dlb2_hw handle for a particular device.
360  *
361  * This function attempts to finish any outstanding unmap procedures.
362  * This function should be called by the kernel thread responsible for
363  * finishing map/unmap procedures.
364  *
365  * Return:
366  * Returns the number of procedures that weren't completed.
367  */
368 unsigned int dlb2_finish_unmap_qid_procedures(struct dlb2_hw *hw);
369 
370 /**
371  * dlb2_finish_map_qid_procedures() - finish any pending map procedures
372  * @hw: dlb2_hw handle for a particular device.
373  *
374  * This function attempts to finish any outstanding map procedures.
375  * This function should be called by the kernel thread responsible for
376  * finishing map/unmap procedures.
377  *
378  * Return:
379  * Returns the number of procedures that weren't completed.
380  */
381 unsigned int dlb2_finish_map_qid_procedures(struct dlb2_hw *hw);
382 
383 /**
384  * dlb2_hw_enable_ldb_port() - enable a load-balanced port for scheduling
385  * @hw: dlb2_hw handle for a particular device.
386  * @domain_id: domain ID.
387  * @args: port enable arguments.
388  * @resp: response structure.
389  * @vdev_request: indicates whether this request came from a vdev.
390  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
391  *
392  * This function configures the DLB to schedule QEs to a load-balanced port.
393  * Ports are enabled by default.
394  *
395  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
396  * device.
397  *
398  * Return:
399  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
400  * assigned a detailed error code from enum dlb2_error.
401  *
402  * Errors:
403  * EINVAL - The port ID is invalid or the domain is not configured.
404  * EFAULT - Internal error (resp->status not set).
405  */
406 int dlb2_hw_enable_ldb_port(struct dlb2_hw *hw,
407 			    u32 domain_id,
408 			    struct dlb2_enable_ldb_port_args *args,
409 			    struct dlb2_cmd_response *resp,
410 			    bool vdev_request,
411 			    unsigned int vdev_id);
412 
413 /**
414  * dlb2_hw_disable_ldb_port() - disable a load-balanced port for scheduling
415  * @hw: dlb2_hw handle for a particular device.
416  * @domain_id: domain ID.
417  * @args: port disable arguments.
418  * @resp: response structure.
419  * @vdev_request: indicates whether this request came from a vdev.
420  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
421  *
422  * This function configures the DLB to stop scheduling QEs to a load-balanced
423  * port. Ports are enabled by default.
424  *
425  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
426  * device.
427  *
428  * Return:
429  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
430  * assigned a detailed error code from enum dlb2_error.
431  *
432  * Errors:
433  * EINVAL - The port ID is invalid or the domain is not configured.
434  * EFAULT - Internal error (resp->status not set).
435  */
436 int dlb2_hw_disable_ldb_port(struct dlb2_hw *hw,
437 			     u32 domain_id,
438 			     struct dlb2_disable_ldb_port_args *args,
439 			     struct dlb2_cmd_response *resp,
440 			     bool vdev_request,
441 			     unsigned int vdev_id);
442 
443 /**
444  * dlb2_hw_enable_dir_port() - enable a directed port for scheduling
445  * @hw: dlb2_hw handle for a particular device.
446  * @domain_id: domain ID.
447  * @args: port enable arguments.
448  * @resp: response structure.
449  * @vdev_request: indicates whether this request came from a vdev.
450  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
451  *
452  * This function configures the DLB to schedule QEs to a directed port.
453  * Ports are enabled by default.
454  *
455  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
456  * device.
457  *
458  * Return:
459  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
460  * assigned a detailed error code from enum dlb2_error.
461  *
462  * Errors:
463  * EINVAL - The port ID is invalid or the domain is not configured.
464  * EFAULT - Internal error (resp->status not set).
465  */
466 int dlb2_hw_enable_dir_port(struct dlb2_hw *hw,
467 			    u32 domain_id,
468 			    struct dlb2_enable_dir_port_args *args,
469 			    struct dlb2_cmd_response *resp,
470 			    bool vdev_request,
471 			    unsigned int vdev_id);
472 
473 /**
474  * dlb2_hw_disable_dir_port() - disable a directed port for scheduling
475  * @hw: dlb2_hw handle for a particular device.
476  * @domain_id: domain ID.
477  * @args: port disable arguments.
478  * @resp: response structure.
479  * @vdev_request: indicates whether this request came from a vdev.
480  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
481  *
482  * This function configures the DLB to stop scheduling QEs to a directed port.
483  * Ports are enabled by default.
484  *
485  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
486  * device.
487  *
488  * Return:
489  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
490  * assigned a detailed error code from enum dlb2_error.
491  *
492  * Errors:
493  * EINVAL - The port ID is invalid or the domain is not configured.
494  * EFAULT - Internal error (resp->status not set).
495  */
496 int dlb2_hw_disable_dir_port(struct dlb2_hw *hw,
497 			     u32 domain_id,
498 			     struct dlb2_disable_dir_port_args *args,
499 			     struct dlb2_cmd_response *resp,
500 			     bool vdev_request,
501 			     unsigned int vdev_id);
502 
503 /**
504  * dlb2_configure_ldb_cq_interrupt() - configure load-balanced CQ for
505  *					interrupts
506  * @hw: dlb2_hw handle for a particular device.
507  * @port_id: load-balanced port ID.
508  * @vector: interrupt vector ID. Should be 0 for MSI or compressed MSI-X mode,
509  *	    else a value up to 64.
510  * @mode: interrupt type (DLB2_CQ_ISR_MODE_MSI or DLB2_CQ_ISR_MODE_MSIX)
511  * @vf: If the port is VF-owned, the VF's ID. This is used for translating the
512  *	virtual port ID to a physical port ID. Ignored if mode is not MSI.
513  * @owner_vf: the VF to route the interrupt to. Ignore if mode is not MSI.
514  * @threshold: the minimum CQ depth at which the interrupt can fire. Must be
515  *	greater than 0.
516  *
517  * This function configures the DLB registers for load-balanced CQ's
518  * interrupts. This doesn't enable the CQ's interrupt; that can be done with
519  * dlb2_arm_cq_interrupt() or through an interrupt arm QE.
520  *
521  * Return:
522  * Returns 0 upon success, < 0 otherwise.
523  *
524  * Errors:
525  * EINVAL - The port ID is invalid.
526  */
527 int dlb2_configure_ldb_cq_interrupt(struct dlb2_hw *hw,
528 				    int port_id,
529 				    int vector,
530 				    int mode,
531 				    unsigned int vf,
532 				    unsigned int owner_vf,
533 				    u16 threshold);
534 
535 /**
536  * dlb2_configure_dir_cq_interrupt() - configure directed CQ for interrupts
537  * @hw: dlb2_hw handle for a particular device.
538  * @port_id: load-balanced port ID.
539  * @vector: interrupt vector ID. Should be 0 for MSI or compressed MSI-X mode,
540  *	    else a value up to 64.
541  * @mode: interrupt type (DLB2_CQ_ISR_MODE_MSI or DLB2_CQ_ISR_MODE_MSIX)
542  * @vf: If the port is VF-owned, the VF's ID. This is used for translating the
543  *	virtual port ID to a physical port ID. Ignored if mode is not MSI.
544  * @owner_vf: the VF to route the interrupt to. Ignore if mode is not MSI.
545  * @threshold: the minimum CQ depth at which the interrupt can fire. Must be
546  *	greater than 0.
547  *
548  * This function configures the DLB registers for directed CQ's interrupts.
549  * This doesn't enable the CQ's interrupt; that can be done with
550  * dlb2_arm_cq_interrupt() or through an interrupt arm QE.
551  *
552  * Return:
553  * Returns 0 upon success, < 0 otherwise.
554  *
555  * Errors:
556  * EINVAL - The port ID is invalid.
557  */
558 int dlb2_configure_dir_cq_interrupt(struct dlb2_hw *hw,
559 				    int port_id,
560 				    int vector,
561 				    int mode,
562 				    unsigned int vf,
563 				    unsigned int owner_vf,
564 				    u16 threshold);
565 
566 /**
567  * dlb2_enable_ingress_error_alarms() - enable ingress error alarm interrupts
568  * @hw: dlb2_hw handle for a particular device.
569  */
570 void dlb2_enable_ingress_error_alarms(struct dlb2_hw *hw);
571 
572 /**
573  * dlb2_disable_ingress_error_alarms() - disable ingress error alarm interrupts
574  * @hw: dlb2_hw handle for a particular device.
575  */
576 void dlb2_disable_ingress_error_alarms(struct dlb2_hw *hw);
577 
578 /**
579  * dlb2_set_msix_mode() - enable certain hardware alarm interrupts
580  * @hw: dlb2_hw handle for a particular device.
581  * @mode: MSI-X mode (DLB2_MSIX_MODE_PACKED or DLB2_MSIX_MODE_COMPRESSED)
582  *
583  * This function configures the hardware to use either packed or compressed
584  * mode. This function should not be called if using MSI interrupts.
585  */
586 void dlb2_set_msix_mode(struct dlb2_hw *hw, int mode);
587 
588 /**
589  * dlb2_ack_msix_interrupt() - Ack an MSI-X interrupt
590  * @hw: dlb2_hw handle for a particular device.
591  * @vector: interrupt vector.
592  *
593  * Note: Only needed for PF service interrupts (vector 0). CQ interrupts are
594  * acked in dlb2_ack_compressed_cq_intr().
595  */
596 void dlb2_ack_msix_interrupt(struct dlb2_hw *hw, int vector);
597 
598 /**
599  * dlb2_arm_cq_interrupt() - arm a CQ's interrupt
600  * @hw: dlb2_hw handle for a particular device.
601  * @port_id: port ID
602  * @is_ldb: true for load-balanced port, false for a directed port
603  * @vdev_request: indicates whether this request came from a vdev.
604  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
605  *
606  * This function arms the CQ's interrupt. The CQ must be configured prior to
607  * calling this function.
608  *
609  * The function does no parameter validation; that is the caller's
610  * responsibility.
611  *
612  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
613  * device.
614  *
615  * Return: returns 0 upon success, <0 otherwise.
616  *
617  * EINVAL - Invalid port ID.
618  */
619 int dlb2_arm_cq_interrupt(struct dlb2_hw *hw,
620 			  int port_id,
621 			  bool is_ldb,
622 			  bool vdev_request,
623 			  unsigned int vdev_id);
624 
625 /**
626  * dlb2_read_compressed_cq_intr_status() - read compressed CQ interrupt status
627  * @hw: dlb2_hw handle for a particular device.
628  * @ldb_interrupts: 2-entry array of u32 bitmaps
629  * @dir_interrupts: 4-entry array of u32 bitmaps
630  *
631  * This function can be called from a compressed CQ interrupt handler to
632  * determine which CQ interrupts have fired. The caller should take appropriate
633  * (such as waking threads blocked on a CQ's interrupt) then ack the interrupts
634  * with dlb2_ack_compressed_cq_intr().
635  */
636 void dlb2_read_compressed_cq_intr_status(struct dlb2_hw *hw,
637 					 u32 *ldb_interrupts,
638 					 u32 *dir_interrupts);
639 
640 /**
641  * dlb2_ack_compressed_cq_intr_status() - ack compressed CQ interrupts
642  * @hw: dlb2_hw handle for a particular device.
643  * @ldb_interrupts: 2-entry array of u32 bitmaps
644  * @dir_interrupts: 4-entry array of u32 bitmaps
645  *
646  * This function ACKs compressed CQ interrupts. Its arguments should be the
647  * same ones passed to dlb2_read_compressed_cq_intr_status().
648  */
649 void dlb2_ack_compressed_cq_intr(struct dlb2_hw *hw,
650 				 u32 *ldb_interrupts,
651 				 u32 *dir_interrupts);
652 
653 /**
654  * dlb2_read_vf_intr_status() - read the VF interrupt status register
655  * @hw: dlb2_hw handle for a particular device.
656  *
657  * This function can be called from a VF's interrupt handler to determine
658  * which interrupts have fired. The first 31 bits correspond to CQ interrupt
659  * vectors, and the final bit is for the PF->VF mailbox interrupt vector.
660  *
661  * Return:
662  * Returns a bit vector indicating which interrupt vectors are active.
663  */
664 u32 dlb2_read_vf_intr_status(struct dlb2_hw *hw);
665 
666 /**
667  * dlb2_ack_vf_intr_status() - ack VF interrupts
668  * @hw: dlb2_hw handle for a particular device.
669  * @interrupts: 32-bit bitmap
670  *
671  * This function ACKs a VF's interrupts. Its interrupts argument should be the
672  * value returned by dlb2_read_vf_intr_status().
673  */
674 void dlb2_ack_vf_intr_status(struct dlb2_hw *hw, u32 interrupts);
675 
676 /**
677  * dlb2_ack_vf_msi_intr() - ack VF MSI interrupt
678  * @hw: dlb2_hw handle for a particular device.
679  * @interrupts: 32-bit bitmap
680  *
681  * This function clears the VF's MSI interrupt pending register. Its interrupts
682  * argument should be contain the MSI vectors to ACK. For example, if MSI MME
683  * is in mode 0, then one bit 0 should ever be set.
684  */
685 void dlb2_ack_vf_msi_intr(struct dlb2_hw *hw, u32 interrupts);
686 
687 /**
688  * dlb2_ack_pf_mbox_int() - ack PF->VF mailbox interrupt
689  * @hw: dlb2_hw handle for a particular device.
690  *
691  * When done processing the PF mailbox request, this function unsets
692  * the PF's mailbox ISR register.
693  */
694 void dlb2_ack_pf_mbox_int(struct dlb2_hw *hw);
695 
696 /**
697  * dlb2_read_vdev_to_pf_int_bitvec() - return a bit vector of all requesting
698  *					vdevs
699  * @hw: dlb2_hw handle for a particular device.
700  *
701  * When the vdev->PF ISR fires, this function can be called to determine which
702  * vdev(s) are requesting service. This bitvector must be passed to
703  * dlb2_ack_vdev_to_pf_int() when processing is complete for all requesting
704  * vdevs.
705  *
706  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
707  * device.
708  *
709  * Return:
710  * Returns a bit vector indicating which VFs (0-15) have requested service.
711  */
712 u32 dlb2_read_vdev_to_pf_int_bitvec(struct dlb2_hw *hw);
713 
714 /**
715  * dlb2_ack_vdev_mbox_int() - ack processed vdev->PF mailbox interrupt
716  * @hw: dlb2_hw handle for a particular device.
717  * @bitvec: bit vector returned by dlb2_read_vdev_to_pf_int_bitvec()
718  *
719  * When done processing all VF mailbox requests, this function unsets the VF's
720  * mailbox ISR register.
721  *
722  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
723  * device.
724  */
725 void dlb2_ack_vdev_mbox_int(struct dlb2_hw *hw, u32 bitvec);
726 
727 /**
728  * dlb2_read_vf_flr_int_bitvec() - return a bit vector of all VFs requesting
729  *				    FLR
730  * @hw: dlb2_hw handle for a particular device.
731  *
732  * When the VF FLR ISR fires, this function can be called to determine which
733  * VF(s) are requesting FLRs. This bitvector must passed to
734  * dlb2_ack_vf_flr_int() when processing is complete for all requesting VFs.
735  *
736  * Return:
737  * Returns a bit vector indicating which VFs (0-15) have requested FLRs.
738  */
739 u32 dlb2_read_vf_flr_int_bitvec(struct dlb2_hw *hw);
740 
741 /**
742  * dlb2_ack_vf_flr_int() - ack processed VF<->PF interrupt(s)
743  * @hw: dlb2_hw handle for a particular device.
744  * @bitvec: bit vector returned by dlb2_read_vf_flr_int_bitvec()
745  *
746  * When done processing all VF FLR requests, this function unsets the VF's FLR
747  * ISR register.
748  */
749 void dlb2_ack_vf_flr_int(struct dlb2_hw *hw, u32 bitvec);
750 
751 /**
752  * dlb2_ack_vdev_to_pf_int() - ack processed VF mbox and FLR interrupt(s)
753  * @hw: dlb2_hw handle for a particular device.
754  * @mbox_bitvec: bit vector returned by dlb2_read_vdev_to_pf_int_bitvec()
755  * @flr_bitvec: bit vector returned by dlb2_read_vf_flr_int_bitvec()
756  *
757  * When done processing all VF requests, this function communicates to the
758  * hardware that processing is complete.
759  *
760  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
761  * device.
762  */
763 void dlb2_ack_vdev_to_pf_int(struct dlb2_hw *hw,
764 			     u32 mbox_bitvec,
765 			     u32 flr_bitvec);
766 
767 /**
768  * dlb2_process_wdt_interrupt() - process watchdog timer interrupts
769  * @hw: dlb2_hw handle for a particular device.
770  *
771  * This function reads the watchdog timer interrupt cause registers to
772  * determine which port(s) had a watchdog timeout, and notifies the
773  * application(s) that own the port(s).
774  */
775 void dlb2_process_wdt_interrupt(struct dlb2_hw *hw);
776 
777 /**
778  * dlb2_process_alarm_interrupt() - process an alarm interrupt
779  * @hw: dlb2_hw handle for a particular device.
780  *
781  * This function reads and logs the alarm syndrome, then acks the interrupt.
782  * This function should be called from the alarm interrupt handler when
783  * interrupt vector DLB2_INT_ALARM fires.
784  */
785 void dlb2_process_alarm_interrupt(struct dlb2_hw *hw);
786 
787 /**
788  * dlb2_process_ingress_error_interrupt() - process ingress error interrupts
789  * @hw: dlb2_hw handle for a particular device.
790  *
791  * This function reads the alarm syndrome, logs it, notifies user-space, and
792  * acks the interrupt. This function should be called from the alarm interrupt
793  * handler when interrupt vector DLB2_INT_INGRESS_ERROR fires.
794  *
795  * Return:
796  * Returns true if an ingress error interrupt occurred, false otherwise
797  */
798 bool dlb2_process_ingress_error_interrupt(struct dlb2_hw *hw);
799 
800 /**
801  * dlb2_get_group_sequence_numbers() - return a group's number of SNs per queue
802  * @hw: dlb2_hw handle for a particular device.
803  * @group_id: sequence number group ID.
804  *
805  * This function returns the configured number of sequence numbers per queue
806  * for the specified group.
807  *
808  * Return:
809  * Returns -EINVAL if group_id is invalid, else the group's SNs per queue.
810  */
811 int dlb2_get_group_sequence_numbers(struct dlb2_hw *hw,
812 				    unsigned int group_id);
813 
814 /**
815  * dlb2_get_group_sequence_number_occupancy() - return a group's in-use slots
816  * @hw: dlb2_hw handle for a particular device.
817  * @group_id: sequence number group ID.
818  *
819  * This function returns the group's number of in-use slots (i.e. load-balanced
820  * queues using the specified group).
821  *
822  * Return:
823  * Returns -EINVAL if group_id is invalid, else the group's SNs per queue.
824  */
825 int dlb2_get_group_sequence_number_occupancy(struct dlb2_hw *hw,
826 					     unsigned int group_id);
827 
828 /**
829  * dlb2_set_group_sequence_numbers() - assign a group's number of SNs per queue
830  * @hw: dlb2_hw handle for a particular device.
831  * @group_id: sequence number group ID.
832  * @val: requested amount of sequence numbers per queue.
833  *
834  * This function configures the group's number of sequence numbers per queue.
835  * val can be a power-of-two between 32 and 1024, inclusive. This setting can
836  * be configured until the first ordered load-balanced queue is configured, at
837  * which point the configuration is locked.
838  *
839  * Return:
840  * Returns 0 upon success; -EINVAL if group_id or val is invalid, -EPERM if an
841  * ordered queue is configured.
842  */
843 int dlb2_set_group_sequence_numbers(struct dlb2_hw *hw,
844 				    u32 group_id,
845 				    u32 val);
846 
847 /**
848  * dlb2_reset_domain() - reset a scheduling domain
849  * @hw: dlb2_hw handle for a particular device.
850  * @domain_id: domain ID.
851  * @vdev_request: indicates whether this request came from a vdev.
852  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
853  *
854  * This function resets and frees a DLB 2.0 scheduling domain and its associated
855  * resources.
856  *
857  * Pre-condition: the driver must ensure software has stopped sending QEs
858  * through this domain's producer ports before invoking this function, or
859  * undefined behavior will result.
860  *
861  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
862  * device.
863  *
864  * Return:
865  * Returns 0 upon success, -1 otherwise.
866  *
867  * EINVAL - Invalid domain ID, or the domain is not configured.
868  * EFAULT - Internal error. (Possibly caused if software is the pre-condition
869  *	    is not met.)
870  * ETIMEDOUT - Hardware component didn't reset in the expected time.
871  */
872 int dlb2_reset_domain(struct dlb2_hw *hw,
873 		      u32 domain_id,
874 		      bool vdev_request,
875 		      unsigned int vdev_id);
876 
877 /**
878  * dlb2_ldb_port_owned_by_domain() - query whether a port is owned by a domain
879  * @hw: dlb2_hw handle for a particular device.
880  * @domain_id: domain ID.
881  * @port_id: indicates whether this request came from a VF.
882  * @vdev_request: indicates whether this request came from a vdev.
883  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
884  *
885  * This function returns whether a load-balanced port is owned by a specified
886  * domain.
887  *
888  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
889  * device.
890  *
891  * Return:
892  * Returns 0 if false, 1 if true, <0 otherwise.
893  *
894  * EINVAL - Invalid domain or port ID, or the domain is not configured.
895  */
896 int dlb2_ldb_port_owned_by_domain(struct dlb2_hw *hw,
897 				  u32 domain_id,
898 				  u32 port_id,
899 				  bool vdev_request,
900 				  unsigned int vdev_id);
901 
902 /**
903  * dlb2_dir_port_owned_by_domain() - query whether a port is owned by a domain
904  * @hw: dlb2_hw handle for a particular device.
905  * @domain_id: domain ID.
906  * @port_id: indicates whether this request came from a VF.
907  * @vdev_request: indicates whether this request came from a vdev.
908  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
909  *
910  * This function returns whether a directed port is owned by a specified
911  * domain.
912  *
913  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
914  * device.
915  *
916  * Return:
917  * Returns 0 if false, 1 if true, <0 otherwise.
918  *
919  * EINVAL - Invalid domain or port ID, or the domain is not configured.
920  */
921 int dlb2_dir_port_owned_by_domain(struct dlb2_hw *hw,
922 				  u32 domain_id,
923 				  u32 port_id,
924 				  bool vdev_request,
925 				  unsigned int vdev_id);
926 
927 /**
928  * dlb2_hw_get_num_resources() - query the PCI function's available resources
929  * @hw: dlb2_hw handle for a particular device.
930  * @arg: pointer to resource counts.
931  * @vdev_request: indicates whether this request came from a vdev.
932  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
933  *
934  * This function returns the number of available resources for the PF or for a
935  * VF.
936  *
937  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
938  * device.
939  *
940  * Return:
941  * Returns 0 upon success, -EINVAL if vdev_request is true and vdev_id is
942  * invalid.
943  */
944 int dlb2_hw_get_num_resources(struct dlb2_hw *hw,
945 			      struct dlb2_get_num_resources_args *arg,
946 			      bool vdev_request,
947 			      unsigned int vdev_id);
948 
949 /**
950  * dlb2_hw_get_num_used_resources() - query the PCI function's used resources
951  * @hw: dlb2_hw handle for a particular device.
952  * @arg: pointer to resource counts.
953  * @vdev_request: indicates whether this request came from a vdev.
954  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
955  *
956  * This function returns the number of resources in use by the PF or a VF. It
957  * fills in the fields that args points to, except the following:
958  * - max_contiguous_atomic_inflights
959  * - max_contiguous_hist_list_entries
960  * - max_contiguous_ldb_credits
961  * - max_contiguous_dir_credits
962  *
963  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
964  * device.
965  *
966  * Return:
967  * Returns 0 upon success, -EINVAL if vdev_request is true and vdev_id is
968  * invalid.
969  */
970 int dlb2_hw_get_num_used_resources(struct dlb2_hw *hw,
971 				   struct dlb2_get_num_resources_args *arg,
972 				   bool vdev_request,
973 				   unsigned int vdev_id);
974 
975 /**
976  * dlb2_send_async_vdev_to_pf_msg() - (vdev only) send a mailbox message to
977  *				       the PF
978  * @hw: dlb2_hw handle for a particular device.
979  *
980  * This function sends a VF->PF mailbox message. It is asynchronous, so it
981  * returns once the message is sent but potentially before the PF has processed
982  * the message. The caller must call dlb2_vdev_to_pf_complete() to determine
983  * when the PF has finished processing the request.
984  *
985  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
986  * device.
987  */
988 void dlb2_send_async_vdev_to_pf_msg(struct dlb2_hw *hw);
989 
990 /**
991  * dlb2_vdev_to_pf_complete() - check the status of an asynchronous mailbox
992  *				 request
993  * @hw: dlb2_hw handle for a particular device.
994  *
995  * This function returns a boolean indicating whether the PF has finished
996  * processing a VF->PF mailbox request. It should only be called after sending
997  * an asynchronous request with dlb2_send_async_vdev_to_pf_msg().
998  *
999  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1000  * device.
1001  */
1002 bool dlb2_vdev_to_pf_complete(struct dlb2_hw *hw);
1003 
1004 /**
1005  * dlb2_vf_flr_complete() - check the status of a VF FLR
1006  * @hw: dlb2_hw handle for a particular device.
1007  *
1008  * This function returns a boolean indicating whether the PF has finished
1009  * executing the VF FLR. It should only be called after setting the VF's FLR
1010  * bit.
1011  */
1012 bool dlb2_vf_flr_complete(struct dlb2_hw *hw);
1013 
1014 /**
1015  * dlb2_send_async_pf_to_vdev_msg() - (PF only) send a mailbox message to a
1016  *					vdev
1017  * @hw: dlb2_hw handle for a particular device.
1018  * @vdev_id: vdev ID.
1019  *
1020  * This function sends a PF->vdev mailbox message. It is asynchronous, so it
1021  * returns once the message is sent but potentially before the vdev has
1022  * processed the message. The caller must call dlb2_pf_to_vdev_complete() to
1023  * determine when the vdev has finished processing the request.
1024  *
1025  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1026  * device.
1027  */
1028 void dlb2_send_async_pf_to_vdev_msg(struct dlb2_hw *hw, unsigned int vdev_id);
1029 
1030 /**
1031  * dlb2_pf_to_vdev_complete() - check the status of an asynchronous mailbox
1032  *			       request
1033  * @hw: dlb2_hw handle for a particular device.
1034  * @vdev_id: vdev ID.
1035  *
1036  * This function returns a boolean indicating whether the vdev has finished
1037  * processing a PF->vdev mailbox request. It should only be called after
1038  * sending an asynchronous request with dlb2_send_async_pf_to_vdev_msg().
1039  *
1040  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1041  * device.
1042  */
1043 bool dlb2_pf_to_vdev_complete(struct dlb2_hw *hw, unsigned int vdev_id);
1044 
1045 /**
1046  * dlb2_pf_read_vf_mbox_req() - (PF only) read a VF->PF mailbox request
1047  * @hw: dlb2_hw handle for a particular device.
1048  * @vf_id: VF ID.
1049  * @data: pointer to message data.
1050  * @len: size, in bytes, of the data array.
1051  *
1052  * This function copies one of the PF's VF->PF mailboxes into the array pointed
1053  * to by data.
1054  *
1055  * Return:
1056  * Returns 0 upon success, <0 otherwise.
1057  *
1058  * EINVAL - len >= DLB2_VF2PF_REQ_BYTES.
1059  */
1060 int dlb2_pf_read_vf_mbox_req(struct dlb2_hw *hw,
1061 			     unsigned int vf_id,
1062 			     void *data,
1063 			     int len);
1064 
1065 /**
1066  * dlb2_pf_read_vf_mbox_resp() - (PF only) read a VF->PF mailbox response
1067  * @hw: dlb2_hw handle for a particular device.
1068  * @vf_id: VF ID.
1069  * @data: pointer to message data.
1070  * @len: size, in bytes, of the data array.
1071  *
1072  * This function copies one of the PF's VF->PF mailboxes into the array pointed
1073  * to by data.
1074  *
1075  * Return:
1076  * Returns 0 upon success, <0 otherwise.
1077  *
1078  * EINVAL - len >= DLB2_VF2PF_RESP_BYTES.
1079  */
1080 int dlb2_pf_read_vf_mbox_resp(struct dlb2_hw *hw,
1081 			      unsigned int vf_id,
1082 			      void *data,
1083 			      int len);
1084 
1085 /**
1086  * dlb2_pf_write_vf_mbox_resp() - (PF only) write a PF->VF mailbox response
1087  * @hw: dlb2_hw handle for a particular device.
1088  * @vf_id: VF ID.
1089  * @data: pointer to message data.
1090  * @len: size, in bytes, of the data array.
1091  *
1092  * This function copies the user-provided message data into of the PF's VF->PF
1093  * mailboxes.
1094  *
1095  * Return:
1096  * Returns 0 upon success, <0 otherwise.
1097  *
1098  * EINVAL - len >= DLB2_PF2VF_RESP_BYTES.
1099  */
1100 int dlb2_pf_write_vf_mbox_resp(struct dlb2_hw *hw,
1101 			       unsigned int vf_id,
1102 			       void *data,
1103 			       int len);
1104 
1105 /**
1106  * dlb2_pf_write_vf_mbox_req() - (PF only) write a PF->VF mailbox request
1107  * @hw: dlb2_hw handle for a particular device.
1108  * @vf_id: VF ID.
1109  * @data: pointer to message data.
1110  * @len: size, in bytes, of the data array.
1111  *
1112  * This function copies the user-provided message data into of the PF's VF->PF
1113  * mailboxes.
1114  *
1115  * Return:
1116  * Returns 0 upon success, <0 otherwise.
1117  *
1118  * EINVAL - len >= DLB2_PF2VF_REQ_BYTES.
1119  */
1120 int dlb2_pf_write_vf_mbox_req(struct dlb2_hw *hw,
1121 			      unsigned int vf_id,
1122 			      void *data,
1123 			      int len);
1124 
1125 /**
1126  * dlb2_vf_read_pf_mbox_resp() - (VF only) read a PF->VF mailbox response
1127  * @hw: dlb2_hw handle for a particular device.
1128  * @data: pointer to message data.
1129  * @len: size, in bytes, of the data array.
1130  *
1131  * This function copies the VF's PF->VF mailbox into the array pointed to by
1132  * data.
1133  *
1134  * Return:
1135  * Returns 0 upon success, <0 otherwise.
1136  *
1137  * EINVAL - len >= DLB2_PF2VF_RESP_BYTES.
1138  */
1139 int dlb2_vf_read_pf_mbox_resp(struct dlb2_hw *hw, void *data, int len);
1140 
1141 /**
1142  * dlb2_vf_read_pf_mbox_req() - (VF only) read a PF->VF mailbox request
1143  * @hw: dlb2_hw handle for a particular device.
1144  * @data: pointer to message data.
1145  * @len: size, in bytes, of the data array.
1146  *
1147  * This function copies the VF's PF->VF mailbox into the array pointed to by
1148  * data.
1149  *
1150  * Return:
1151  * Returns 0 upon success, <0 otherwise.
1152  *
1153  * EINVAL - len >= DLB2_PF2VF_REQ_BYTES.
1154  */
1155 int dlb2_vf_read_pf_mbox_req(struct dlb2_hw *hw, void *data, int len);
1156 
1157 /**
1158  * dlb2_vf_write_pf_mbox_req() - (VF only) write a VF->PF mailbox request
1159  * @hw: dlb2_hw handle for a particular device.
1160  * @data: pointer to message data.
1161  * @len: size, in bytes, of the data array.
1162  *
1163  * This function copies the user-provided message data into of the VF's PF->VF
1164  * mailboxes.
1165  *
1166  * Return:
1167  * Returns 0 upon success, <0 otherwise.
1168  *
1169  * EINVAL - len >= DLB2_VF2PF_REQ_BYTES.
1170  */
1171 int dlb2_vf_write_pf_mbox_req(struct dlb2_hw *hw, void *data, int len);
1172 
1173 /**
1174  * dlb2_vf_write_pf_mbox_resp() - (VF only) write a VF->PF mailbox response
1175  * @hw: dlb2_hw handle for a particular device.
1176  * @data: pointer to message data.
1177  * @len: size, in bytes, of the data array.
1178  *
1179  * This function copies the user-provided message data into of the VF's PF->VF
1180  * mailboxes.
1181  *
1182  * Return:
1183  * Returns 0 upon success, <0 otherwise.
1184  *
1185  * EINVAL - len >= DLB2_VF2PF_RESP_BYTES.
1186  */
1187 int dlb2_vf_write_pf_mbox_resp(struct dlb2_hw *hw, void *data, int len);
1188 
1189 /**
1190  * dlb2_reset_vdev() - reset the hardware owned by a virtual device
1191  * @hw: dlb2_hw handle for a particular device.
1192  * @id: virtual device ID
1193  *
1194  * This function resets the hardware owned by a vdev, by resetting the vdev's
1195  * domains one by one.
1196  *
1197  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1198  * device.
1199  */
1200 int dlb2_reset_vdev(struct dlb2_hw *hw, unsigned int id);
1201 
1202 /**
1203  * dlb2_vdev_is_locked() - check whether the vdev's resources are locked
1204  * @hw: dlb2_hw handle for a particular device.
1205  * @id: virtual device ID
1206  *
1207  * This function returns whether or not the vdev's resource assignments are
1208  * locked. If locked, no resources can be added to or subtracted from the
1209  * group.
1210  *
1211  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1212  * device.
1213  */
1214 bool dlb2_vdev_is_locked(struct dlb2_hw *hw, unsigned int id);
1215 
1216 /**
1217  * dlb2_lock_vdev() - lock the vdev's resources
1218  * @hw: dlb2_hw handle for a particular device.
1219  * @id: virtual device ID
1220  *
1221  * This function sets a flag indicating that the vdev is using its resources.
1222  * When the vdev is locked, its resource assignment cannot be changed.
1223  *
1224  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1225  * device.
1226  */
1227 void dlb2_lock_vdev(struct dlb2_hw *hw, unsigned int id);
1228 
1229 /**
1230  * dlb2_unlock_vdev() - unlock the vdev's resources
1231  * @hw: dlb2_hw handle for a particular device.
1232  * @id: virtual device ID
1233  *
1234  * This function unlocks the vdev's resource assignment, allowing it to be
1235  * modified.
1236  *
1237  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1238  * device.
1239  */
1240 void dlb2_unlock_vdev(struct dlb2_hw *hw, unsigned int id);
1241 
1242 /**
1243  * dlb2_update_vdev_sched_domains() - update the domains assigned to a vdev
1244  * @hw: dlb2_hw handle for a particular device.
1245  * @id: virtual device ID
1246  * @num: number of scheduling domains to assign to this vdev
1247  *
1248  * This function assigns num scheduling domains to the specified vdev. If the
1249  * vdev already has domains assigned, this existing assignment is adjusted
1250  * accordingly.
1251  *
1252  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1253  * device.
1254  *
1255  * Return:
1256  * Returns 0 upon success, <0 otherwise.
1257  *
1258  * Errors:
1259  * EINVAL - id is invalid, or the requested number of resources are
1260  *	    unavailable.
1261  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1262  */
1263 int dlb2_update_vdev_sched_domains(struct dlb2_hw *hw, u32 id, u32 num);
1264 
1265 /**
1266  * dlb2_update_vdev_ldb_queues() - update the LDB queues assigned to a vdev
1267  * @hw: dlb2_hw handle for a particular device.
1268  * @id: virtual device ID
1269  * @num: number of LDB queues to assign to this vdev
1270  *
1271  * This function assigns num LDB queues to the specified vdev. If the vdev
1272  * already has LDB queues assigned, this existing assignment is adjusted
1273  * accordingly.
1274  *
1275  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1276  * device.
1277  *
1278  * Return:
1279  * Returns 0 upon success, <0 otherwise.
1280  *
1281  * Errors:
1282  * EINVAL - id is invalid, or the requested number of resources are
1283  *	    unavailable.
1284  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1285  */
1286 int dlb2_update_vdev_ldb_queues(struct dlb2_hw *hw, u32 id, u32 num);
1287 
1288 /**
1289  * dlb2_update_vdev_ldb_ports() - update the LDB ports assigned to a vdev
1290  * @hw: dlb2_hw handle for a particular device.
1291  * @id: virtual device ID
1292  * @num: number of LDB ports to assign to this vdev
1293  *
1294  * This function assigns num LDB ports to the specified vdev. If the vdev
1295  * already has LDB ports assigned, this existing assignment is adjusted
1296  * accordingly.
1297  *
1298  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1299  * device.
1300  *
1301  * Return:
1302  * Returns 0 upon success, <0 otherwise.
1303  *
1304  * Errors:
1305  * EINVAL - id is invalid, or the requested number of resources are
1306  *	    unavailable.
1307  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1308  */
1309 int dlb2_update_vdev_ldb_ports(struct dlb2_hw *hw, u32 id, u32 num);
1310 
1311 /**
1312  * dlb2_update_vdev_ldb_cos_ports() - update the LDB ports assigned to a vdev
1313  * @hw: dlb2_hw handle for a particular device.
1314  * @id: virtual device ID
1315  * @cos: class-of-service ID
1316  * @num: number of LDB ports to assign to this vdev
1317  *
1318  * This function assigns num LDB ports from class-of-service cos to the
1319  * specified vdev. If the vdev already has LDB ports from this class-of-service
1320  * assigned, this existing assignment is adjusted accordingly.
1321  *
1322  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1323  * device.
1324  *
1325  * Return:
1326  * Returns 0 upon success, <0 otherwise.
1327  *
1328  * Errors:
1329  * EINVAL - id is invalid, or the requested number of resources are
1330  *	    unavailable.
1331  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1332  */
1333 int dlb2_update_vdev_ldb_cos_ports(struct dlb2_hw *hw,
1334 				   u32 id,
1335 				   u32 cos,
1336 				   u32 num);
1337 
1338 /**
1339  * dlb2_update_vdev_dir_ports() - update the DIR ports assigned to a vdev
1340  * @hw: dlb2_hw handle for a particular device.
1341  * @id: virtual device ID
1342  * @num: number of DIR ports to assign to this vdev
1343  *
1344  * This function assigns num DIR ports to the specified vdev. If the vdev
1345  * already has DIR ports assigned, this existing assignment is adjusted
1346  * accordingly.
1347  *
1348  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1349  * device.
1350  *
1351  * Return:
1352  * Returns 0 upon success, <0 otherwise.
1353  *
1354  * Errors:
1355  * EINVAL - id is invalid, or the requested number of resources are
1356  *	    unavailable.
1357  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1358  */
1359 int dlb2_update_vdev_dir_ports(struct dlb2_hw *hw, u32 id, u32 num);
1360 
1361 /**
1362  * dlb2_update_vdev_ldb_credits() - update the vdev's assigned LDB credits
1363  * @hw: dlb2_hw handle for a particular device.
1364  * @id: virtual device ID
1365  * @num: number of LDB credit credits to assign to this vdev
1366  *
1367  * This function assigns num LDB credit to the specified vdev. If the vdev
1368  * already has LDB credits assigned, this existing assignment is adjusted
1369  * accordingly. vdevs are assigned a contiguous chunk of credits, so this
1370  * function may fail if a sufficiently large contiguous chunk is not available.
1371  *
1372  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1373  * device.
1374  *
1375  * Return:
1376  * Returns 0 upon success, <0 otherwise.
1377  *
1378  * Errors:
1379  * EINVAL - id is invalid, or the requested number of resources are
1380  *	    unavailable.
1381  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1382  */
1383 int dlb2_update_vdev_ldb_credits(struct dlb2_hw *hw, u32 id, u32 num);
1384 
1385 /**
1386  * dlb2_update_vdev_dir_credits() - update the vdev's assigned DIR credits
1387  * @hw: dlb2_hw handle for a particular device.
1388  * @id: virtual device ID
1389  * @num: number of DIR credits to assign to this vdev
1390  *
1391  * This function assigns num DIR credit to the specified vdev. If the vdev
1392  * already has DIR credits assigned, this existing assignment is adjusted
1393  * accordingly. vdevs are assigned a contiguous chunk of credits, so this
1394  * function may fail if a sufficiently large contiguous chunk is not available.
1395  *
1396  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1397  * device.
1398  *
1399  * Return:
1400  * Returns 0 upon success, <0 otherwise.
1401  *
1402  * Errors:
1403  * EINVAL - id is invalid, or the requested number of resources are
1404  *	    unavailable.
1405  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1406  */
1407 int dlb2_update_vdev_dir_credits(struct dlb2_hw *hw, u32 id, u32 num);
1408 
1409 /**
1410  * dlb2_update_vdev_hist_list_entries() - update the vdev's assigned HL entries
1411  * @hw: dlb2_hw handle for a particular device.
1412  * @id: virtual device ID
1413  * @num: number of history list entries to assign to this vdev
1414  *
1415  * This function assigns num history list entries to the specified vdev. If the
1416  * vdev already has history list entries assigned, this existing assignment is
1417  * adjusted accordingly. vdevs are assigned a contiguous chunk of entries, so
1418  * this function may fail if a sufficiently large contiguous chunk is not
1419  * available.
1420  *
1421  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1422  * device.
1423  *
1424  * Return:
1425  * Returns 0 upon success, <0 otherwise.
1426  *
1427  * Errors:
1428  * EINVAL - id is invalid, or the requested number of resources are
1429  *	    unavailable.
1430  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1431  */
1432 int dlb2_update_vdev_hist_list_entries(struct dlb2_hw *hw, u32 id, u32 num);
1433 
1434 /**
1435  * dlb2_update_vdev_atomic_inflights() - update the vdev's atomic inflights
1436  * @hw: dlb2_hw handle for a particular device.
1437  * @id: virtual device ID
1438  * @num: number of atomic inflights to assign to this vdev
1439  *
1440  * This function assigns num atomic inflights to the specified vdev. If the vdev
1441  * already has atomic inflights assigned, this existing assignment is adjusted
1442  * accordingly. vdevs are assigned a contiguous chunk of entries, so this
1443  * function may fail if a sufficiently large contiguous chunk is not available.
1444  *
1445  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1446  * device.
1447  *
1448  * Return:
1449  * Returns 0 upon success, <0 otherwise.
1450  *
1451  * Errors:
1452  * EINVAL - id is invalid, or the requested number of resources are
1453  *	    unavailable.
1454  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1455  */
1456 int dlb2_update_vdev_atomic_inflights(struct dlb2_hw *hw, u32 id, u32 num);
1457 
1458 /**
1459  * dlb2_reset_vdev_resources() - reassign the vdev's resources to the PF
1460  * @hw: dlb2_hw handle for a particular device.
1461  * @id: virtual device ID
1462  *
1463  * This function takes any resources currently assigned to the vdev and
1464  * reassigns them to the PF.
1465  *
1466  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1467  * device.
1468  *
1469  * Return:
1470  * Returns 0 upon success, <0 otherwise.
1471  *
1472  * Errors:
1473  * EINVAL - id is invalid
1474  * EPERM  - The vdev's resource assignment is locked and cannot be changed.
1475  */
1476 int dlb2_reset_vdev_resources(struct dlb2_hw *hw, unsigned int id);
1477 
1478 /**
1479  * dlb2_notify_vf() - send an alarm to a VF
1480  * @hw: dlb2_hw handle for a particular device.
1481  * @vf_id: VF ID
1482  * @notification: notification
1483  *
1484  * This function sends a notification (as defined in dlb2_mbox.h) to a VF.
1485  *
1486  * Return:
1487  * Returns 0 upon success, <0 if the VF doesn't ACK the PF->VF interrupt.
1488  */
1489 int dlb2_notify_vf(struct dlb2_hw *hw,
1490 		   unsigned int vf_id,
1491 		   u32 notification);
1492 
1493 /**
1494  * dlb2_vdev_in_use() - query whether a virtual device is in use
1495  * @hw: dlb2_hw handle for a particular device.
1496  * @id: virtual device ID
1497  *
1498  * This function sends a mailbox request to the vdev to query whether the vdev
1499  * is in use.
1500  *
1501  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1502  * device.
1503  *
1504  * Return:
1505  * Returns 0 for false, 1 for true, and <0 if the mailbox request times out or
1506  * an internal error occurs.
1507  */
1508 int dlb2_vdev_in_use(struct dlb2_hw *hw, unsigned int id);
1509 
1510 /**
1511  * dlb2_hw_get_ldb_queue_depth() - returns the depth of a load-balanced queue
1512  * @hw: dlb2_hw handle for a particular device.
1513  * @domain_id: domain ID.
1514  * @args: queue depth args
1515  * @resp: response structure.
1516  * @vdev_request: indicates whether this request came from a vdev.
1517  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
1518  *
1519  * This function returns the depth of a load-balanced queue.
1520  *
1521  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1522  * device.
1523  *
1524  * Return:
1525  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
1526  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
1527  * contains the depth.
1528  *
1529  * Errors:
1530  * EINVAL - Invalid domain ID or queue ID.
1531  */
1532 int dlb2_hw_get_ldb_queue_depth(struct dlb2_hw *hw,
1533 				u32 domain_id,
1534 				struct dlb2_get_ldb_queue_depth_args *args,
1535 				struct dlb2_cmd_response *resp,
1536 				bool vdev_request,
1537 				unsigned int vdev_id);
1538 
1539 /**
1540  * dlb2_hw_get_dir_queue_depth() - returns the depth of a directed queue
1541  * @hw: dlb2_hw handle for a particular device.
1542  * @domain_id: domain ID.
1543  * @args: queue depth args
1544  * @resp: response structure.
1545  * @vdev_request: indicates whether this request came from a vdev.
1546  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
1547  *
1548  * This function returns the depth of a directed queue.
1549  *
1550  * A vdev can be either an SR-IOV virtual function or a Scalable IOV virtual
1551  * device.
1552  *
1553  * Return:
1554  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
1555  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
1556  * contains the depth.
1557  *
1558  * Errors:
1559  * EINVAL - Invalid domain ID or queue ID.
1560  */
1561 int dlb2_hw_get_dir_queue_depth(struct dlb2_hw *hw,
1562 				u32 domain_id,
1563 				struct dlb2_get_dir_queue_depth_args *args,
1564 				struct dlb2_cmd_response *resp,
1565 				bool vdev_request,
1566 				unsigned int vdev_id);
1567 
1568 enum dlb2_virt_mode {
1569 	DLB2_VIRT_NONE,
1570 	DLB2_VIRT_SRIOV,
1571 	DLB2_VIRT_SIOV,
1572 
1573 	/* NUM_DLB2_VIRT_MODES must be last */
1574 	NUM_DLB2_VIRT_MODES,
1575 };
1576 
1577 /**
1578  * dlb2_hw_set_virt_mode() - set the device's virtualization mode
1579  * @hw: dlb2_hw handle for a particular device.
1580  * @mode: either none, SR-IOV, or Scalable IOV.
1581  *
1582  * This function sets the virtualization mode of the device. This controls
1583  * whether the device uses a software or hardware mailbox.
1584  *
1585  * This should be called by the PF driver when either SR-IOV or Scalable IOV is
1586  * selected as the virtualization mechanism, and by the VF/VDEV driver during
1587  * initialization after recognizing itself as an SR-IOV or Scalable IOV device.
1588  *
1589  * Errors:
1590  * EINVAL - Invalid mode.
1591  */
1592 int dlb2_hw_set_virt_mode(struct dlb2_hw *hw, enum dlb2_virt_mode mode);
1593 
1594 /**
1595  * dlb2_hw_get_virt_mode() - get the device's virtualization mode
1596  * @hw: dlb2_hw handle for a particular device.
1597  *
1598  * This function gets the virtualization mode of the device.
1599  */
1600 enum dlb2_virt_mode dlb2_hw_get_virt_mode(struct dlb2_hw *hw);
1601 
1602 /**
1603  * dlb2_hw_get_ldb_port_phys_id() - get a physical port ID from its virt ID
1604  * @hw: dlb2_hw handle for a particular device.
1605  * @id: virtual port ID.
1606  * @vdev_id: vdev ID.
1607  *
1608  * Return:
1609  * Returns >= 0 upon success, -1 otherwise.
1610  */
1611 s32 dlb2_hw_get_ldb_port_phys_id(struct dlb2_hw *hw,
1612 				 u32 id,
1613 				 unsigned int vdev_id);
1614 
1615 /**
1616  * dlb2_hw_get_dir_port_phys_id() - get a physical port ID from its virt ID
1617  * @hw: dlb2_hw handle for a particular device.
1618  * @id: virtual port ID.
1619  * @vdev_id: vdev ID.
1620  *
1621  * Return:
1622  * Returns >= 0 upon success, -1 otherwise.
1623  */
1624 s32 dlb2_hw_get_dir_port_phys_id(struct dlb2_hw *hw,
1625 				 u32 id,
1626 				 unsigned int vdev_id);
1627 
1628 /**
1629  * dlb2_hw_register_sw_mbox() - register a software mailbox
1630  * @hw: dlb2_hw handle for a particular device.
1631  * @vdev_id: vdev ID.
1632  * @vdev2pf_mbox: pointer to a 4KB memory page used for vdev->PF communication.
1633  * @pf2vdev_mbox: pointer to a 4KB memory page used for PF->vdev communication.
1634  * @pf2vdev_inject: callback function for injecting a PF->vdev interrupt.
1635  * @inject_arg: user argument for pf2vdev_inject callback.
1636  *
1637  * When Scalable IOV is enabled, the VDCM must register a software mailbox for
1638  * every virtual device during vdev creation.
1639  *
1640  * This function notifies the driver to use a software mailbox using the
1641  * provided pointers, instead of the device's hardware mailbox. When the driver
1642  * calls mailbox functions like dlb2_pf_write_vf_mbox_req(), the request will
1643  * go to the software mailbox instead of the hardware one. This is used in
1644  * Scalable IOV virtualization.
1645  */
1646 void dlb2_hw_register_sw_mbox(struct dlb2_hw *hw,
1647 			      unsigned int vdev_id,
1648 			      u32 *vdev2pf_mbox,
1649 			      u32 *pf2vdev_mbox,
1650 			      void (*pf2vdev_inject)(void *),
1651 			      void *inject_arg);
1652 
1653 /**
1654  * dlb2_hw_unregister_sw_mbox() - unregister a software mailbox
1655  * @hw: dlb2_hw handle for a particular device.
1656  * @vdev_id: vdev ID.
1657  *
1658  * This function notifies the driver to stop using a previously registered
1659  * software mailbox.
1660  */
1661 void dlb2_hw_unregister_sw_mbox(struct dlb2_hw *hw, unsigned int vdev_id);
1662 
1663 /**
1664  * dlb2_hw_setup_cq_ims_entry() - setup a CQ's IMS entry
1665  * @hw: dlb2_hw handle for a particular device.
1666  * @vdev_id: vdev ID.
1667  * @virt_cq_id: virtual CQ ID.
1668  * @is_ldb: CQ is load-balanced.
1669  * @addr_lo: least-significant 32 bits of address.
1670  * @data: 32 data bits.
1671  *
1672  * This sets up the CQ's IMS entry with the provided address and data values.
1673  * This function should only be called if the device is configured for Scalable
1674  * IOV virtualization. The upper 32 address bits are fixed in hardware and thus
1675  * not needed.
1676  */
1677 void dlb2_hw_setup_cq_ims_entry(struct dlb2_hw *hw,
1678 				unsigned int vdev_id,
1679 				u32 virt_cq_id,
1680 				bool is_ldb,
1681 				u32 addr_lo,
1682 				u32 data);
1683 
1684 /**
1685  * dlb2_hw_clear_cq_ims_entry() - clear a CQ's IMS entry
1686  * @hw: dlb2_hw handle for a particular device.
1687  * @vdev_id: vdev ID.
1688  * @virt_cq_id: virtual CQ ID.
1689  * @is_ldb: CQ is load-balanced.
1690  *
1691  * This clears the CQ's IMS entry, reverting it to its reset state.
1692  */
1693 void dlb2_hw_clear_cq_ims_entry(struct dlb2_hw *hw,
1694 				unsigned int vdev_id,
1695 				u32 virt_cq_id,
1696 				bool is_ldb);
1697 
1698 /**
1699  * dlb2_hw_register_pasid() - register a vdev's PASID
1700  * @hw: dlb2_hw handle for a particular device.
1701  * @vdev_id: vdev ID.
1702  * @pasid: the vdev's PASID.
1703  *
1704  * This function stores the user-supplied PASID, and uses it when configuring
1705  * the vdev's CQs.
1706  *
1707  * Return:
1708  * Returns >= 0 upon success, -1 otherwise.
1709  */
1710 int dlb2_hw_register_pasid(struct dlb2_hw *hw,
1711 			   unsigned int vdev_id,
1712 			   unsigned int pasid);
1713 
1714 /**
1715  * dlb2_hw_pending_port_unmaps() - returns the number of unmap operations in
1716  *	progress.
1717  * @hw: dlb2_hw handle for a particular device.
1718  * @domain_id: domain ID.
1719  * @args: number of unmaps in progress args
1720  * @resp: response structure.
1721  * @vf_request: indicates whether this request came from a VF.
1722  * @vf_id: If vf_request is true, this contains the VF's ID.
1723  *
1724  * Return:
1725  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
1726  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
1727  * contains the number of unmaps in progress.
1728  *
1729  * Errors:
1730  * EINVAL - Invalid port ID.
1731  */
1732 int dlb2_hw_pending_port_unmaps(struct dlb2_hw *hw,
1733 				u32 domain_id,
1734 				struct dlb2_pending_port_unmaps_args *args,
1735 				struct dlb2_cmd_response *resp,
1736 				bool vf_request,
1737 				unsigned int vf_id);
1738 
1739 /**
1740  * dlb2_hw_get_cos_bandwidth() - returns the percent of bandwidth allocated
1741  *	to a port class-of-service.
1742  * @hw: dlb2_hw handle for a particular device.
1743  * @cos_id: class-of-service ID.
1744  *
1745  * Return:
1746  * Returns -EINVAL if cos_id is invalid, else the class' bandwidth allocation.
1747  */
1748 int dlb2_hw_get_cos_bandwidth(struct dlb2_hw *hw, u32 cos_id);
1749 
1750 /**
1751  * dlb2_hw_set_cos_bandwidth() - set a bandwidth allocation percentage for a
1752  *	port class-of-service.
1753  * @hw: dlb2_hw handle for a particular device.
1754  * @cos_id: class-of-service ID.
1755  * @bandwidth: class-of-service bandwidth.
1756  *
1757  * Return:
1758  * Returns 0 upon success, < 0 otherwise.
1759  *
1760  * Errors:
1761  * EINVAL - Invalid cos ID, bandwidth is greater than 100, or bandwidth would
1762  *	    cause the total bandwidth across all classes of service to exceed
1763  *	    100%.
1764  */
1765 int dlb2_hw_set_cos_bandwidth(struct dlb2_hw *hw, u32 cos_id, u8 bandwidth);
1766 
1767 enum dlb2_wd_tmo {
1768 	/* 40s watchdog timeout */
1769 	DLB2_WD_TMO_40S,
1770 	/* 10s watchdog timeout */
1771 	DLB2_WD_TMO_10S,
1772 	/* 1s watchdog timeout */
1773 	DLB2_WD_TMO_1S,
1774 
1775 	/* Must be last */
1776 	NUM_DLB2_WD_TMOS,
1777 };
1778 
1779 /**
1780  * dlb2_hw_enable_wd_timer() - enable the CQ watchdog timers with a
1781  *	caller-specified timeout.
1782  * @hw: dlb2_hw handle for a particular device.
1783  * @tmo: watchdog timeout.
1784  *
1785  * This function should be called during device initialization and after reset.
1786  * The watchdog timer interrupt must also be enabled per-CQ, using either
1787  * dlb2_hw_enable_dir_cq_wd_int() or dlb2_hw_enable_ldb_cq_wd_int().
1788  *
1789  * Return:
1790  * Returns 0 upon success, < 0 otherwise.
1791  *
1792  * Errors:
1793  * EINVAL - Invalid timeout.
1794  */
1795 int dlb2_hw_enable_wd_timer(struct dlb2_hw *hw, enum dlb2_wd_tmo tmo);
1796 
1797 /**
1798  * dlb2_hw_enable_dir_cq_wd_int() - enable the CQ watchdog interrupt on an
1799  *	individual CQ.
1800  * @hw: dlb2_hw handle for a particular device.
1801  * @id: port ID.
1802  * @vdev_req: indicates whether this request came from a vdev.
1803  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
1804  *
1805  * Return:
1806  * Returns 0 upon success, < 0 otherwise.
1807  *
1808  * Errors:
1809  * EINVAL - Invalid directed port ID.
1810  */
1811 int dlb2_hw_enable_dir_cq_wd_int(struct dlb2_hw *hw,
1812 				 u32 id,
1813 				 bool vdev_req,
1814 				 unsigned int vdev_id);
1815 
1816 /**
1817  * dlb2_hw_enable_ldb_cq_wd_int() - enable the CQ watchdog interrupt on an
1818  *	individual CQ.
1819  * @hw: dlb2_hw handle for a particular device.
1820  * @id: port ID.
1821  * @vdev_req: indicates whether this request came from a vdev.
1822  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
1823  *
1824  * Return:
1825  * Returns 0 upon success, < 0 otherwise.
1826  *
1827  * Errors:
1828  * EINVAL - Invalid load-balanced port ID.
1829  */
1830 int dlb2_hw_enable_ldb_cq_wd_int(struct dlb2_hw *hw,
1831 				 u32 id,
1832 				 bool vdev_req,
1833 				 unsigned int vdev_id);
1834 
1835 /**
1836  * dlb2_hw_enable_sparse_ldb_cq_mode() - enable sparse mode for load-balanced
1837  *	ports.
1838  * @hw: dlb2_hw handle for a particular device.
1839  *
1840  * This function must be called prior to configuring scheduling domains.
1841  */
1842 void dlb2_hw_enable_sparse_ldb_cq_mode(struct dlb2_hw *hw);
1843 
1844 /**
1845  * dlb2_hw_enable_sparse_dir_cq_mode() - enable sparse mode for directed ports.
1846  * @hw: dlb2_hw handle for a particular device.
1847  *
1848  * This function must be called prior to configuring scheduling domains.
1849  */
1850 void dlb2_hw_enable_sparse_dir_cq_mode(struct dlb2_hw *hw);
1851 
1852 /**
1853  * dlb2_hw_set_qe_arbiter_weights() - program QE arbiter weights
1854  * @hw: dlb2_hw handle for a particular device.
1855  * @weight: 8-entry array of arbiter weights.
1856  *
1857  * weight[N] programs priority N's weight. In cases where the 8 priorities are
1858  * reduced to 4 bins, the mapping is:
1859  * - weight[1] programs bin 0
1860  * - weight[3] programs bin 1
1861  * - weight[5] programs bin 2
1862  * - weight[7] programs bin 3
1863  */
1864 void dlb2_hw_set_qe_arbiter_weights(struct dlb2_hw *hw, u8 weight[8]);
1865 
1866 /**
1867  * dlb2_hw_set_qid_arbiter_weights() - program QID arbiter weights
1868  * @hw: dlb2_hw handle for a particular device.
1869  * @weight: 8-entry array of arbiter weights.
1870  *
1871  * weight[N] programs priority N's weight. In cases where the 8 priorities are
1872  * reduced to 4 bins, the mapping is:
1873  * - weight[1] programs bin 0
1874  * - weight[3] programs bin 1
1875  * - weight[5] programs bin 2
1876  * - weight[7] programs bin 3
1877  */
1878 void dlb2_hw_set_qid_arbiter_weights(struct dlb2_hw *hw, u8 weight[8]);
1879 
1880 /**
1881  * dlb2_hw_ldb_cq_interrupt_enabled() - Check if the interrupt is enabled
1882  * @hw: dlb2_hw handle for a particular device.
1883  * @port_id: physical load-balanced port ID.
1884  *
1885  * This function returns whether the load-balanced CQ interrupt is enabled.
1886  */
1887 int dlb2_hw_ldb_cq_interrupt_enabled(struct dlb2_hw *hw, int port_id);
1888 
1889 /**
1890  * dlb2_hw_ldb_cq_interrupt_set_mode() - Program the CQ interrupt mode
1891  * @hw: dlb2_hw handle for a particular device.
1892  * @port_id: physical load-balanced port ID.
1893  * @mode: interrupt type (DLB2_CQ_ISR_MODE_{DIS, MSI, MSIX, ADI})
1894  *
1895  * This function can be used to disable (MODE_DIS) and re-enable the
1896  * load-balanced CQ's interrupt. It should only be called after the interrupt
1897  * has been configured with dlb2_configure_ldb_cq_interrupt().
1898  */
1899 void dlb2_hw_ldb_cq_interrupt_set_mode(struct dlb2_hw *hw,
1900 				       int port_id,
1901 				       int mode);
1902 
1903 /**
1904  * dlb2_hw_dir_cq_interrupt_enabled() - Check if the interrupt is enabled
1905  * @hw: dlb2_hw handle for a particular device.
1906  * @port_id: physical load-balanced port ID.
1907  *
1908  * This function returns whether the load-balanced CQ interrupt is enabled.
1909  */
1910 int dlb2_hw_dir_cq_interrupt_enabled(struct dlb2_hw *hw, int port_id);
1911 
1912 /**
1913  * dlb2_hw_dir_cq_interrupt_set_mode() - Program the CQ interrupt mode
1914  * @hw: dlb2_hw handle for a particular device.
1915  * @port_id: physical directed port ID.
1916  * @mode: interrupt type (DLB2_CQ_ISR_MODE_{DIS, MSI, MSIX, ADI})
1917  *
1918  * This function can be used to disable (MODE_DIS) and re-enable the
1919  * directed CQ's interrupt. It should only be called after the interrupt
1920  * has been configured with dlb2_configure_dir_cq_interrupt().
1921  */
1922 void dlb2_hw_dir_cq_interrupt_set_mode(struct dlb2_hw *hw,
1923 				       int port_id,
1924 				       int mode);
1925 
1926 /**
1927  * dlb2_hw_enable_cq_weight() - Enable QE-weight based scheduling on an LDB port.
1928  * @hw: dlb2_hw handle for a particular device.
1929  * @domain_id: domain ID.
1930  * @args: CQ weight enablement arguments.
1931  * @resp: response structure.
1932  * @vdev_request: indicates whether this request came from a vdev.
1933  * @vdev_id: If vdev_request is true, this contains the vdev's ID.
1934  *
1935  * This function enables QE-weight based scheduling on a load-balanced port's
1936  * CQ and configures the CQ's weight limit.
1937  *
1938  * This must be called after creating the port but before starting the
1939  * domain.
1940  *
1941  * Return:
1942  * Returns 0 upon success, < 0 otherwise. If an error occurs, resp->status is
1943  * assigned a detailed error code from enum dlb2_error. If successful, resp->id
1944  * contains the queue ID.
1945  *
1946  * Errors:
1947  * EINVAL - The domain or port is not configured, the domainhas already been
1948  *          started, the requested limit exceeds the port's CQ depth, or this
1949  *          feature is unavailable on the device.
1950  * EFAULT - Internal error (resp->status not set).
1951  */
1952 int dlb2_hw_enable_cq_weight(struct dlb2_hw *hw,
1953 			     u32 domain_id,
1954 			     struct dlb2_enable_cq_weight_args *args,
1955 			     struct dlb2_cmd_response *resp,
1956 			     bool vdev_request,
1957 			     unsigned int vdev_id);
1958 
1959 #endif /* __DLB2_RESOURCE_H */
1960