usb: Netlogic: Use CPU_XLR in place of NLM_XLR
[zen-stable.git] / drivers / net / ethernet / brocade / bna / bfa_cee.c
blob8e627186507ceee29a5f281b6c2f36b52850f0b4
1 /*
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.
15 * All rights reserved
16 * www.brocade.com
19 #include "bfa_cee.h"
20 #include "bfi_cna.h"
21 #include "bfa_ioc.h"
23 static void bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg);
24 static void bfa_cee_format_cee_cfg(void *buffer);
26 static void
27 bfa_cee_format_cee_cfg(void *buffer)
29 struct bfa_cee_attr *cee_cfg = buffer;
30 bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
33 static void
34 bfa_cee_stats_swap(struct bfa_cee_stats *stats)
36 u32 *buffer = (u32 *)stats;
37 int i;
39 for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
40 i++) {
41 buffer[i] = ntohl(buffer[i]);
45 static void
46 bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
48 lldp_cfg->time_to_live =
49 ntohs(lldp_cfg->time_to_live);
50 lldp_cfg->enabled_system_cap =
51 ntohs(lldp_cfg->enabled_system_cap);
54 /**
55 * bfa_cee_attr_meminfo()
57 * @brief Returns the size of the DMA memory needed by CEE attributes
59 * @param[in] void
61 * @return Size of DMA region
63 static u32
64 bfa_cee_attr_meminfo(void)
66 return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
68 /**
69 * bfa_cee_stats_meminfo()
71 * @brief Returns the size of the DMA memory needed by CEE stats
73 * @param[in] void
75 * @return Size of DMA region
77 static u32
78 bfa_cee_stats_meminfo(void)
80 return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
83 /**
84 * bfa_cee_get_attr_isr()
86 * @brief CEE ISR for get-attributes responses from f/w
88 * @param[in] cee - Pointer to the CEE module
89 * status - Return status from the f/w
91 * @return void
93 static void
94 bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
96 cee->get_attr_status = status;
97 if (status == BFA_STATUS_OK) {
98 memcpy(cee->attr, cee->attr_dma.kva,
99 sizeof(struct bfa_cee_attr));
100 bfa_cee_format_cee_cfg(cee->attr);
102 cee->get_attr_pending = false;
103 if (cee->cbfn.get_attr_cbfn)
104 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
108 * bfa_cee_get_attr_isr()
110 * @brief CEE ISR for get-stats responses from f/w
112 * @param[in] cee - Pointer to the CEE module
113 * status - Return status from the f/w
115 * @return void
117 static void
118 bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
120 cee->get_stats_status = status;
121 if (status == BFA_STATUS_OK) {
122 memcpy(cee->stats, cee->stats_dma.kva,
123 sizeof(struct bfa_cee_stats));
124 bfa_cee_stats_swap(cee->stats);
126 cee->get_stats_pending = false;
127 if (cee->cbfn.get_stats_cbfn)
128 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
132 * bfa_cee_get_attr_isr()
134 * @brief CEE ISR for reset-stats responses from f/w
136 * @param[in] cee - Pointer to the CEE module
137 * status - Return status from the f/w
139 * @return void
141 static void
142 bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
144 cee->reset_stats_status = status;
145 cee->reset_stats_pending = false;
146 if (cee->cbfn.reset_stats_cbfn)
147 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
150 * bfa_nw_cee_meminfo()
152 * @brief Returns the size of the DMA memory needed by CEE module
154 * @param[in] void
156 * @return Size of DMA region
159 bfa_nw_cee_meminfo(void)
161 return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
165 * bfa_nw_cee_mem_claim()
167 * @brief Initialized CEE DMA Memory
169 * @param[in] cee CEE module pointer
170 * dma_kva Kernel Virtual Address of CEE DMA Memory
171 * dma_pa Physical Address of CEE DMA Memory
173 * @return void
175 void
176 bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
178 cee->attr_dma.kva = dma_kva;
179 cee->attr_dma.pa = dma_pa;
180 cee->stats_dma.kva = dma_kva + bfa_cee_attr_meminfo();
181 cee->stats_dma.pa = dma_pa + bfa_cee_attr_meminfo();
182 cee->attr = (struct bfa_cee_attr *) dma_kva;
183 cee->stats = (struct bfa_cee_stats *)
184 (dma_kva + bfa_cee_attr_meminfo());
188 * bfa_cee_isrs()
190 * @brief Handles Mail-box interrupts for CEE module.
192 * @param[in] Pointer to the CEE module data structure.
194 * @return void
197 static void
198 bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
200 union bfi_cee_i2h_msg_u *msg;
201 struct bfi_cee_get_rsp *get_rsp;
202 struct bfa_cee *cee = (struct bfa_cee *) cbarg;
203 msg = (union bfi_cee_i2h_msg_u *) m;
204 get_rsp = (struct bfi_cee_get_rsp *) m;
205 switch (msg->mh.msg_id) {
206 case BFI_CEE_I2H_GET_CFG_RSP:
207 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
208 break;
209 case BFI_CEE_I2H_GET_STATS_RSP:
210 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
211 break;
212 case BFI_CEE_I2H_RESET_STATS_RSP:
213 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
214 break;
215 default:
216 BUG_ON(1);
221 * bfa_cee_notify()
223 * @brief CEE module heart-beat failure handler.
224 * @brief CEE module IOC event handler.
226 * @param[in] IOC event type
228 * @return void
231 static void
232 bfa_cee_notify(void *arg, enum bfa_ioc_event event)
234 struct bfa_cee *cee;
235 cee = (struct bfa_cee *) arg;
237 switch (event) {
238 case BFA_IOC_E_DISABLED:
239 case BFA_IOC_E_FAILED:
240 if (cee->get_attr_pending == true) {
241 cee->get_attr_status = BFA_STATUS_FAILED;
242 cee->get_attr_pending = false;
243 if (cee->cbfn.get_attr_cbfn) {
244 cee->cbfn.get_attr_cbfn(
245 cee->cbfn.get_attr_cbarg,
246 BFA_STATUS_FAILED);
249 if (cee->get_stats_pending == true) {
250 cee->get_stats_status = BFA_STATUS_FAILED;
251 cee->get_stats_pending = false;
252 if (cee->cbfn.get_stats_cbfn) {
253 cee->cbfn.get_stats_cbfn(
254 cee->cbfn.get_stats_cbarg,
255 BFA_STATUS_FAILED);
258 if (cee->reset_stats_pending == true) {
259 cee->reset_stats_status = BFA_STATUS_FAILED;
260 cee->reset_stats_pending = false;
261 if (cee->cbfn.reset_stats_cbfn) {
262 cee->cbfn.reset_stats_cbfn(
263 cee->cbfn.reset_stats_cbarg,
264 BFA_STATUS_FAILED);
267 break;
269 default:
270 break;
275 * bfa_nw_cee_attach()
277 * @brief CEE module-attach API
279 * @param[in] cee - Pointer to the CEE module data structure
280 * ioc - Pointer to the ioc module data structure
281 * dev - Pointer to the device driver module data structure
282 * The device driver specific mbox ISR functions have
283 * this pointer as one of the parameters.
285 * @return void
287 void
288 bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
289 void *dev)
291 BUG_ON(!(cee != NULL));
292 cee->dev = dev;
293 cee->ioc = ioc;
295 bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
296 bfa_q_qe_init(&cee->ioc_notify);
297 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
298 bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);