Add the rt linux 4.1.3-rt3 as base
[kvmfornfv.git] / kernel / drivers / net / ethernet / brocade / bna / bfa_msgq.h
1 /*
2  * Linux network driver for QLogic BR-series Converged Network Adapter.
3  *
4  * This program is free software; you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License (GPL) Version 2 as
6  * published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful, but
9  * WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11  * General Public License for more details.
12  */
13 /*
14  * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15  * Copyright (c) 2014-2015 QLogic Corporation
16  * All rights reserved
17  * www.qlogic.com
18  */
19
20 #ifndef __BFA_MSGQ_H__
21 #define __BFA_MSGQ_H__
22
23 #include "bfa_defs.h"
24 #include "bfi.h"
25 #include "bfa_ioc.h"
26 #include "bfa_cs.h"
27
28 #define BFA_MSGQ_FREE_CNT(_q)                                           \
29         (((_q)->consumer_index - (_q)->producer_index - 1) & ((_q)->depth - 1))
30
31 #define BFA_MSGQ_INDX_ADD(_q_indx, _qe_num, _q_depth)                   \
32         ((_q_indx) = (((_q_indx) + (_qe_num)) & ((_q_depth) - 1)))
33
34 #define BFA_MSGQ_CMDQ_NUM_ENTRY         128
35 #define BFA_MSGQ_CMDQ_SIZE                                              \
36         (BFI_MSGQ_CMD_ENTRY_SIZE * BFA_MSGQ_CMDQ_NUM_ENTRY)
37
38 #define BFA_MSGQ_RSPQ_NUM_ENTRY         128
39 #define BFA_MSGQ_RSPQ_SIZE                                              \
40         (BFI_MSGQ_RSP_ENTRY_SIZE * BFA_MSGQ_RSPQ_NUM_ENTRY)
41
42 #define bfa_msgq_cmd_set(_cmd, _cbfn, _cbarg, _msg_size, _msg_hdr)      \
43 do {                                                                    \
44         (_cmd)->cbfn = (_cbfn);                                         \
45         (_cmd)->cbarg = (_cbarg);                                       \
46         (_cmd)->msg_size = (_msg_size);                                 \
47         (_cmd)->msg_hdr = (_msg_hdr);                                   \
48 } while (0)
49
50 struct bfa_msgq;
51
52 typedef void (*bfa_msgq_cmdcbfn_t)(void *cbarg, enum bfa_status status);
53
54 struct bfa_msgq_cmd_entry {
55         struct list_head                                qe;
56         bfa_msgq_cmdcbfn_t              cbfn;
57         void                            *cbarg;
58         size_t                          msg_size;
59         struct bfi_msgq_mhdr *msg_hdr;
60 };
61
62 enum bfa_msgq_cmdq_flags {
63         BFA_MSGQ_CMDQ_F_DB_UPDATE       = 1,
64 };
65
66 struct bfa_msgq_cmdq {
67         bfa_fsm_t                       fsm;
68         enum bfa_msgq_cmdq_flags flags;
69
70         u16                     producer_index;
71         u16                     consumer_index;
72         u16                     depth; /* FW Q depth is 16 bits */
73         struct bfa_dma addr;
74         struct bfa_mbox_cmd dbell_mb;
75
76         u16                     token;
77         int                             offset;
78         int                             bytes_to_copy;
79         struct bfa_mbox_cmd copy_mb;
80
81         struct list_head                pending_q; /* pending command queue */
82
83         struct bfa_msgq *msgq;
84 };
85
86 enum bfa_msgq_rspq_flags {
87         BFA_MSGQ_RSPQ_F_DB_UPDATE       = 1,
88 };
89
90 typedef void (*bfa_msgq_mcfunc_t)(void *cbarg, struct bfi_msgq_mhdr *mhdr);
91
92 struct bfa_msgq_rspq {
93         bfa_fsm_t                       fsm;
94         enum bfa_msgq_rspq_flags flags;
95
96         u16                     producer_index;
97         u16                     consumer_index;
98         u16                     depth; /* FW Q depth is 16 bits */
99         struct bfa_dma addr;
100         struct bfa_mbox_cmd dbell_mb;
101
102         int                             nmclass;
103         struct {
104                 bfa_msgq_mcfunc_t       cbfn;
105                 void                    *cbarg;
106         } rsphdlr[BFI_MC_MAX];
107
108         struct bfa_msgq *msgq;
109 };
110
111 struct bfa_msgq {
112         struct bfa_msgq_cmdq cmdq;
113         struct bfa_msgq_rspq rspq;
114
115         struct bfa_wc                   init_wc;
116         struct bfa_mbox_cmd init_mb;
117
118         struct bfa_ioc_notify ioc_notify;
119         struct bfa_ioc *ioc;
120 };
121
122 u32 bfa_msgq_meminfo(void);
123 void bfa_msgq_memclaim(struct bfa_msgq *msgq, u8 *kva, u64 pa);
124 void bfa_msgq_attach(struct bfa_msgq *msgq, struct bfa_ioc *ioc);
125 void bfa_msgq_regisr(struct bfa_msgq *msgq, enum bfi_mclass mc,
126                      bfa_msgq_mcfunc_t cbfn, void *cbarg);
127 void bfa_msgq_cmd_post(struct bfa_msgq *msgq,
128                        struct bfa_msgq_cmd_entry *cmd);
129 void bfa_msgq_rsp_copy(struct bfa_msgq *msgq, u8 *buf, size_t buf_len);
130
131 #endif