spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / drivers / net / ethernet / brocade / bna / bfa_cee.c
blob29f284f79e02ace82f607509a5b27d21c3cb993b
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_get_attr()
190 * @brief Send the request to the f/w to fetch CEE attributes.
192 * @param[in] Pointer to the CEE module data structure.
194 * @return Status
196 enum bfa_status
197 bfa_nw_cee_get_attr(struct bfa_cee *cee, struct bfa_cee_attr *attr,
198 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
200 struct bfi_cee_get_req *cmd;
202 BUG_ON(!((cee != NULL) && (cee->ioc != NULL)));
203 if (!bfa_nw_ioc_is_operational(cee->ioc))
204 return BFA_STATUS_IOC_FAILURE;
206 if (cee->get_attr_pending == true)
207 return BFA_STATUS_DEVBUSY;
209 cee->get_attr_pending = true;
210 cmd = (struct bfi_cee_get_req *) cee->get_cfg_mb.msg;
211 cee->attr = attr;
212 cee->cbfn.get_attr_cbfn = cbfn;
213 cee->cbfn.get_attr_cbarg = cbarg;
214 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
215 bfa_ioc_portid(cee->ioc));
216 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
217 bfa_nw_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb, NULL, NULL);
219 return BFA_STATUS_OK;
223 * bfa_cee_isrs()
225 * @brief Handles Mail-box interrupts for CEE module.
227 * @param[in] Pointer to the CEE module data structure.
229 * @return void
232 static void
233 bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
235 union bfi_cee_i2h_msg_u *msg;
236 struct bfi_cee_get_rsp *get_rsp;
237 struct bfa_cee *cee = (struct bfa_cee *) cbarg;
238 msg = (union bfi_cee_i2h_msg_u *) m;
239 get_rsp = (struct bfi_cee_get_rsp *) m;
240 switch (msg->mh.msg_id) {
241 case BFI_CEE_I2H_GET_CFG_RSP:
242 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
243 break;
244 case BFI_CEE_I2H_GET_STATS_RSP:
245 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
246 break;
247 case BFI_CEE_I2H_RESET_STATS_RSP:
248 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
249 break;
250 default:
251 BUG_ON(1);
256 * bfa_cee_notify()
258 * @brief CEE module heart-beat failure handler.
259 * @brief CEE module IOC event handler.
261 * @param[in] IOC event type
263 * @return void
266 static void
267 bfa_cee_notify(void *arg, enum bfa_ioc_event event)
269 struct bfa_cee *cee;
270 cee = (struct bfa_cee *) arg;
272 switch (event) {
273 case BFA_IOC_E_DISABLED:
274 case BFA_IOC_E_FAILED:
275 if (cee->get_attr_pending == true) {
276 cee->get_attr_status = BFA_STATUS_FAILED;
277 cee->get_attr_pending = false;
278 if (cee->cbfn.get_attr_cbfn) {
279 cee->cbfn.get_attr_cbfn(
280 cee->cbfn.get_attr_cbarg,
281 BFA_STATUS_FAILED);
284 if (cee->get_stats_pending == true) {
285 cee->get_stats_status = BFA_STATUS_FAILED;
286 cee->get_stats_pending = false;
287 if (cee->cbfn.get_stats_cbfn) {
288 cee->cbfn.get_stats_cbfn(
289 cee->cbfn.get_stats_cbarg,
290 BFA_STATUS_FAILED);
293 if (cee->reset_stats_pending == true) {
294 cee->reset_stats_status = BFA_STATUS_FAILED;
295 cee->reset_stats_pending = false;
296 if (cee->cbfn.reset_stats_cbfn) {
297 cee->cbfn.reset_stats_cbfn(
298 cee->cbfn.reset_stats_cbarg,
299 BFA_STATUS_FAILED);
302 break;
304 default:
305 break;
310 * bfa_nw_cee_attach()
312 * @brief CEE module-attach API
314 * @param[in] cee - Pointer to the CEE module data structure
315 * ioc - Pointer to the ioc module data structure
316 * dev - Pointer to the device driver module data structure
317 * The device driver specific mbox ISR functions have
318 * this pointer as one of the parameters.
320 * @return void
322 void
323 bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
324 void *dev)
326 BUG_ON(!(cee != NULL));
327 cee->dev = dev;
328 cee->ioc = ioc;
330 bfa_nw_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
331 bfa_q_qe_init(&cee->ioc_notify);
332 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
333 bfa_nw_ioc_notify_register(cee->ioc, &cee->ioc_notify);