55c56644c8497db6a7cd44b8f18c9b351542ae6b
[dpdk.git] / drivers / net / enic / base / enic_vnic_wq.h
1 /*
2  * Copyright 2008-2015 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2015, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef _ENIC_VNIC_WQ_H_
36 #define _ENIC_VNIC_WQ_H_
37
38 #include "vnic_dev.h"
39 #include "vnic_cq.h"
40
41 static inline void enic_vnic_post_wq_index(struct vnic_wq *wq)
42 {
43         /* Adding write memory barrier prevents compiler and/or CPU
44          * reordering, thus avoiding descriptor posting before
45          * descriptor is initialized. Otherwise, hardware can read
46          * stale descriptor fields.
47         */
48         wmb();
49         iowrite32(wq->head_idx, &wq->ctrl->posted_index);
50 }
51
52 static inline void enic_vnic_post_wq(struct vnic_wq *wq,
53                                      void *os_buf, uint8_t cq_entry)
54 {
55         struct vnic_wq_buf *buf = &wq->bufs[wq->head_idx];
56         buf->mb = os_buf;
57         wq->head_idx = enic_ring_incr(wq->ring.desc_count, wq->head_idx);
58
59         if (cq_entry)
60                 enic_vnic_post_wq_index(wq);
61 }
62
63 #endif /* _ENIC_VNIC_WQ_H_ */