2 * Linux network driver for Brocade 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-2010 Brocade Communications Systems, Inc.
19 #include "bfa_defs_cna.h"
25 static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg);
26 static void bfa_cee_format_cee_cfg(void *buffer);
29 bfa_cee_format_cee_cfg(void *buffer)
31 struct bfa_cee_attr *cee_cfg = buffer;
32 bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
36 bfa_cee_stats_swap(struct bfa_cee_stats *stats)
38 u32 *buffer = (u32 *)stats;
41 for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
43 buffer[i] = ntohl(buffer[i]);
48 bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
50 lldp_cfg->time_to_live =
51 ntohs(lldp_cfg->time_to_live);
52 lldp_cfg->enabled_system_cap =
53 ntohs(lldp_cfg->enabled_system_cap);
57 * bfa_cee_attr_meminfo()
59 * @brief Returns the size of the DMA memory needed by CEE attributes
63 * @return Size of DMA region
66 bfa_cee_attr_meminfo(void)
68 return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
71 * bfa_cee_stats_meminfo()
73 * @brief Returns the size of the DMA memory needed by CEE stats
77 * @return Size of DMA region
80 bfa_cee_stats_meminfo(void)
82 return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
86 * bfa_cee_get_attr_isr()
88 * @brief CEE ISR for get-attributes responses from f/w
90 * @param[in] cee - Pointer to the CEE module
91 * status - Return status from the f/w
96 bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
98 cee->get_attr_status = status;
99 if (status == BFA_STATUS_OK) {
100 memcpy(cee->attr, cee->attr_dma.kva,
101 sizeof(struct bfa_cee_attr));
102 bfa_cee_format_cee_cfg(cee->attr);
104 cee->get_attr_pending = false;
105 if (cee->cbfn.get_attr_cbfn)
106 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
110 * bfa_cee_get_attr_isr()
112 * @brief CEE ISR for get-stats responses from f/w
114 * @param[in] cee - Pointer to the CEE module
115 * status - Return status from the f/w
120 bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
122 cee->get_stats_status = status;
123 if (status == BFA_STATUS_OK) {
124 memcpy(cee->stats, cee->stats_dma.kva,
125 sizeof(struct bfa_cee_stats));
126 bfa_cee_stats_swap(cee->stats);
128 cee->get_stats_pending = false;
129 if (cee->cbfn.get_stats_cbfn)
130 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
134 * bfa_cee_get_attr_isr()
136 * @brief CEE ISR for reset-stats responses from f/w
138 * @param[in] cee - Pointer to the CEE module
139 * status - Return status from the f/w
144 bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
146 cee->reset_stats_status = status;
147 cee->reset_stats_pending = false;
148 if (cee->cbfn.reset_stats_cbfn)
149 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
152 * bfa_nw_cee_meminfo()
154 * @brief Returns the size of the DMA memory needed by CEE module
158 * @return Size of DMA region
161 bfa_nw_cee_meminfo(void)
163 return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
167 * bfa_nw_cee_mem_claim()
169 * @brief Initialized CEE DMA Memory
171 * @param[in] cee CEE module pointer
172 * dma_kva Kernel Virtual Address of CEE DMA Memory
173 * dma_pa Physical Address of CEE DMA Memory
178 bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
180 cee->attr_dma.kva = dma_kva;
181 cee->attr_dma.pa = dma_pa;
182 cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
183 cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
184 cee->attr = (struct bfa_cee_attr *) dma_kva;
185 cee->stats = (struct bfa_cee_stats *)
186 (dma_kva + bfa_cee_attr_meminfo());
192 * @brief Handles Mail-box interrupts for CEE module.
194 * @param[in] Pointer to the CEE module data structure.
200 bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
202 union bfi_cee_i2h_msg_u *msg;
203 struct bfi_cee_get_rsp *get_rsp;
204 struct bfa_cee *cee = (struct bfa_cee *) cbarg;
205 msg = (union bfi_cee_i2h_msg_u *) m;
206 get_rsp = (struct bfi_cee_get_rsp *) m;
207 switch (msg->mh.msg_id) {
208 case BFI_CEE_I2H_GET_CFG_RSP:
209 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
211 case BFI_CEE_I2H_GET_STATS_RSP:
212 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
214 case BFI_CEE_I2H_RESET_STATS_RSP:
215 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
225 * @brief CEE module heart-beat failure handler.
226 * @brief CEE module IOC event handler.
228 * @param[in] IOC event type
234 bfa_cee_notify(void *arg, enum bfa_ioc_event event)
237 cee = (struct bfa_cee *) arg;
240 case BFA_IOC_E_DISABLED:
241 case BFA_IOC_E_FAILED:
242 if (cee->get_attr_pending == true) {
243 cee->get_attr_status = BFA_STATUS_FAILED;
244 cee->get_attr_pending = false;
245 if (cee->cbfn.get_attr_cbfn) {
246 cee->cbfn.get_attr_cbfn(
247 cee->cbfn.get_attr_cbarg,
251 if (cee->get_stats_pending == true) {
252 cee->get_stats_status = BFA_STATUS_FAILED;
253 cee->get_stats_pending = false;
254 if (cee->cbfn.get_stats_cbfn) {
255 cee->cbfn.get_stats_cbfn(
256 cee->cbfn.get_stats_cbarg,
260 if (cee->reset_stats_pending == true) {
261 cee->reset_stats_status = BFA_STATUS_FAILED;
262 cee->reset_stats_pending = false;
263 if (cee->cbfn.reset_stats_cbfn) {
264 cee->cbfn.reset_stats_cbfn(
265 cee->cbfn.reset_stats_cbarg,
277 * bfa_nw_cee_attach()
279 * @brief CEE module-attach API
281 * @param[in] cee - Pointer to the CEE module data structure
282 * ioc - Pointer to the ioc module data structure
283 * dev - Pointer to the device driver module data structure
284 * The device driver specific mbox ISR functions have
285 * this pointer as one of the parameters.
290 bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
293 BUG_ON(!(cee != NULL));
297 bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
298 bfa_q_qe_init(&cee->ioc_notify);
299 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
300 bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);