2 * Linux network driver for QLogic BR-series Converged Network Adapter.
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
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.
14 * Copyright (c) 2005-2014 Brocade Communications Systems, Inc.
15 * Copyright (c) 2014-2015 QLogic Corporation
24 static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg
*lldp_cfg
);
25 static void bfa_cee_format_cee_cfg(void *buffer
);
28 bfa_cee_format_cee_cfg(void *buffer
)
30 struct bfa_cee_attr
*cee_cfg
= buffer
;
31 bfa_cee_format_lldp_cfg(&cee_cfg
->lldp_remote
);
35 bfa_cee_stats_swap(struct bfa_cee_stats
*stats
)
37 u32
*buffer
= (u32
*)stats
;
40 for (i
= 0; i
< (sizeof(struct bfa_cee_stats
) / sizeof(u32
));
42 buffer
[i
] = ntohl(buffer
[i
]);
47 bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg
*lldp_cfg
)
49 lldp_cfg
->time_to_live
=
50 ntohs(lldp_cfg
->time_to_live
);
51 lldp_cfg
->enabled_system_cap
=
52 ntohs(lldp_cfg
->enabled_system_cap
);
56 * bfa_cee_attr_meminfo - Returns the size of the DMA memory needed by CEE attributes
59 bfa_cee_attr_meminfo(void)
61 return roundup(sizeof(struct bfa_cee_attr
), BFA_DMA_ALIGN_SZ
);
64 * bfa_cee_stats_meminfo - Returns the size of the DMA memory needed by CEE stats
67 bfa_cee_stats_meminfo(void)
69 return roundup(sizeof(struct bfa_cee_stats
), BFA_DMA_ALIGN_SZ
);
73 * bfa_cee_get_attr_isr - CEE ISR for get-attributes responses from f/w
75 * @cee: Pointer to the CEE module
76 * @status: Return status from the f/w
79 bfa_cee_get_attr_isr(struct bfa_cee
*cee
, enum bfa_status status
)
81 cee
->get_attr_status
= status
;
82 if (status
== BFA_STATUS_OK
) {
83 memcpy(cee
->attr
, cee
->attr_dma
.kva
,
84 sizeof(struct bfa_cee_attr
));
85 bfa_cee_format_cee_cfg(cee
->attr
);
87 cee
->get_attr_pending
= false;
88 if (cee
->cbfn
.get_attr_cbfn
)
89 cee
->cbfn
.get_attr_cbfn(cee
->cbfn
.get_attr_cbarg
, status
);
93 * bfa_cee_get_attr_isr - CEE ISR for get-stats responses from f/w
95 * @cee: Pointer to the CEE module
96 * @status: Return status from the f/w
99 bfa_cee_get_stats_isr(struct bfa_cee
*cee
, enum bfa_status status
)
101 cee
->get_stats_status
= status
;
102 if (status
== BFA_STATUS_OK
) {
103 memcpy(cee
->stats
, cee
->stats_dma
.kva
,
104 sizeof(struct bfa_cee_stats
));
105 bfa_cee_stats_swap(cee
->stats
);
107 cee
->get_stats_pending
= false;
108 if (cee
->cbfn
.get_stats_cbfn
)
109 cee
->cbfn
.get_stats_cbfn(cee
->cbfn
.get_stats_cbarg
, status
);
113 * bfa_cee_get_attr_isr()
115 * @brief CEE ISR for reset-stats responses from f/w
117 * @param[in] cee - Pointer to the CEE module
118 * status - Return status from the f/w
123 bfa_cee_reset_stats_isr(struct bfa_cee
*cee
, enum bfa_status status
)
125 cee
->reset_stats_status
= status
;
126 cee
->reset_stats_pending
= false;
127 if (cee
->cbfn
.reset_stats_cbfn
)
128 cee
->cbfn
.reset_stats_cbfn(cee
->cbfn
.reset_stats_cbarg
, status
);
131 * bfa_nw_cee_meminfo - Returns the size of the DMA memory needed by CEE module
134 bfa_nw_cee_meminfo(void)
136 return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
140 * bfa_nw_cee_mem_claim - Initialized CEE DMA Memory
142 * @cee: CEE module pointer
143 * @dma_kva: Kernel Virtual Address of CEE DMA Memory
144 * @dma_pa: Physical Address of CEE DMA Memory
147 bfa_nw_cee_mem_claim(struct bfa_cee
*cee
, u8
*dma_kva
, u64 dma_pa
)
149 cee
->attr_dma
.kva
= dma_kva
;
150 cee
->attr_dma
.pa
= dma_pa
;
151 cee
->stats_dma
.kva
= dma_kva
+ bfa_cee_attr_meminfo();
152 cee
->stats_dma
.pa
= dma_pa
+ bfa_cee_attr_meminfo();
153 cee
->attr
= (struct bfa_cee_attr
*) dma_kva
;
154 cee
->stats
= (struct bfa_cee_stats
*)
155 (dma_kva
+ bfa_cee_attr_meminfo());
159 * bfa_cee_get_attr - Send the request to the f/w to fetch CEE attributes.
161 * @cee: Pointer to the CEE module data structure.
166 bfa_nw_cee_get_attr(struct bfa_cee
*cee
, struct bfa_cee_attr
*attr
,
167 bfa_cee_get_attr_cbfn_t cbfn
, void *cbarg
)
169 struct bfi_cee_get_req
*cmd
;
171 BUG_ON(!((cee
!= NULL
) && (cee
->ioc
!= NULL
)));
172 if (!bfa_nw_ioc_is_operational(cee
->ioc
))
173 return BFA_STATUS_IOC_FAILURE
;
175 if (cee
->get_attr_pending
)
176 return BFA_STATUS_DEVBUSY
;
178 cee
->get_attr_pending
= true;
179 cmd
= (struct bfi_cee_get_req
*) cee
->get_cfg_mb
.msg
;
181 cee
->cbfn
.get_attr_cbfn
= cbfn
;
182 cee
->cbfn
.get_attr_cbarg
= cbarg
;
183 bfi_h2i_set(cmd
->mh
, BFI_MC_CEE
, BFI_CEE_H2I_GET_CFG_REQ
,
184 bfa_ioc_portid(cee
->ioc
));
185 bfa_dma_be_addr_set(cmd
->dma_addr
, cee
->attr_dma
.pa
);
186 bfa_nw_ioc_mbox_queue(cee
->ioc
, &cee
->get_cfg_mb
, NULL
, NULL
);
188 return BFA_STATUS_OK
;
192 * bfa_cee_isrs - Handles Mail-box interrupts for CEE module.
196 bfa_cee_isr(void *cbarg
, struct bfi_mbmsg
*m
)
198 union bfi_cee_i2h_msg_u
*msg
;
199 struct bfi_cee_get_rsp
*get_rsp
;
200 struct bfa_cee
*cee
= (struct bfa_cee
*) cbarg
;
201 msg
= (union bfi_cee_i2h_msg_u
*) m
;
202 get_rsp
= (struct bfi_cee_get_rsp
*) m
;
203 switch (msg
->mh
.msg_id
) {
204 case BFI_CEE_I2H_GET_CFG_RSP
:
205 bfa_cee_get_attr_isr(cee
, get_rsp
->cmd_status
);
207 case BFI_CEE_I2H_GET_STATS_RSP
:
208 bfa_cee_get_stats_isr(cee
, get_rsp
->cmd_status
);
210 case BFI_CEE_I2H_RESET_STATS_RSP
:
211 bfa_cee_reset_stats_isr(cee
, get_rsp
->cmd_status
);
219 * bfa_cee_notify - CEE module heart-beat failure handler.
221 * @event: IOC event type
225 bfa_cee_notify(void *arg
, enum bfa_ioc_event event
)
228 cee
= (struct bfa_cee
*) arg
;
231 case BFA_IOC_E_DISABLED
:
232 case BFA_IOC_E_FAILED
:
233 if (cee
->get_attr_pending
) {
234 cee
->get_attr_status
= BFA_STATUS_FAILED
;
235 cee
->get_attr_pending
= false;
236 if (cee
->cbfn
.get_attr_cbfn
) {
237 cee
->cbfn
.get_attr_cbfn(
238 cee
->cbfn
.get_attr_cbarg
,
242 if (cee
->get_stats_pending
) {
243 cee
->get_stats_status
= BFA_STATUS_FAILED
;
244 cee
->get_stats_pending
= false;
245 if (cee
->cbfn
.get_stats_cbfn
) {
246 cee
->cbfn
.get_stats_cbfn(
247 cee
->cbfn
.get_stats_cbarg
,
251 if (cee
->reset_stats_pending
) {
252 cee
->reset_stats_status
= BFA_STATUS_FAILED
;
253 cee
->reset_stats_pending
= false;
254 if (cee
->cbfn
.reset_stats_cbfn
) {
255 cee
->cbfn
.reset_stats_cbfn(
256 cee
->cbfn
.reset_stats_cbarg
,
268 * bfa_nw_cee_attach - CEE module-attach API
270 * @cee: Pointer to the CEE module data structure
271 * @ioc: Pointer to the ioc module data structure
272 * @dev: Pointer to the device driver module data structure.
273 * The device driver specific mbox ISR functions have
274 * this pointer as one of the parameters.
277 bfa_nw_cee_attach(struct bfa_cee
*cee
, struct bfa_ioc
*ioc
,
280 BUG_ON(!(cee
!= NULL
));
284 bfa_nw_ioc_mbox_regisr(cee
->ioc
, BFI_MC_CEE
, bfa_cee_isr
, cee
);
285 bfa_ioc_notify_init(&cee
->ioc_notify
, bfa_cee_notify
, cee
);
286 bfa_nw_ioc_notify_register(cee
->ioc
, &cee
->ioc_notify
);