]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/net/ethernet/brocade/bna/bfa_cee.c
ath9k: add AR9580 support
[karo-tx-linux.git] / drivers / net / ethernet / brocade / bna / bfa_cee.c
1 /*
2  * Linux network driver for Brocade 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-2010 Brocade Communications Systems, Inc.
15  * All rights reserved
16  * www.brocade.com
17  */
18
19 #include "bfa_defs_cna.h"
20 #include "cna.h"
21 #include "bfa_cee.h"
22 #include "bfi_cna.h"
23 #include "bfa_ioc.h"
24
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);
27
28 static void
29 bfa_cee_format_cee_cfg(void *buffer)
30 {
31         struct bfa_cee_attr *cee_cfg = buffer;
32         bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
33 }
34
35 static void
36 bfa_cee_stats_swap(struct bfa_cee_stats *stats)
37 {
38         u32 *buffer = (u32 *)stats;
39         int i;
40
41         for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
42                 i++) {
43                 buffer[i] = ntohl(buffer[i]);
44         }
45 }
46
47 static void
48 bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
49 {
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);
54 }
55
56 /**
57  * bfa_cee_attr_meminfo()
58  *
59  * @brief Returns the size of the DMA memory needed by CEE attributes
60  *
61  * @param[in] void
62  *
63  * @return Size of DMA region
64  */
65 static u32
66 bfa_cee_attr_meminfo(void)
67 {
68         return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
69 }
70 /**
71  * bfa_cee_stats_meminfo()
72  *
73  * @brief Returns the size of the DMA memory needed by CEE stats
74  *
75  * @param[in] void
76  *
77  * @return Size of DMA region
78  */
79 static u32
80 bfa_cee_stats_meminfo(void)
81 {
82         return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
83 }
84
85 /**
86  * bfa_cee_get_attr_isr()
87  *
88  * @brief CEE ISR for get-attributes responses from f/w
89  *
90  * @param[in] cee - Pointer to the CEE module
91  *            status - Return status from the f/w
92  *
93  * @return void
94  */
95 static void
96 bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
97 {
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);
103         }
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);
107 }
108
109 /**
110  * bfa_cee_get_attr_isr()
111  *
112  * @brief CEE ISR for get-stats responses from f/w
113  *
114  * @param[in] cee - Pointer to the CEE module
115  *            status - Return status from the f/w
116  *
117  * @return void
118  */
119 static void
120 bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
121 {
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);
127         }
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);
131 }
132
133 /**
134  * bfa_cee_get_attr_isr()
135  *
136  * @brief CEE ISR for reset-stats responses from f/w
137  *
138  * @param[in] cee - Pointer to the CEE module
139  *            status - Return status from the f/w
140  *
141  * @return void
142  */
143 static void
144 bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
145 {
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);
150 }
151 /**
152  * bfa_nw_cee_meminfo()
153  *
154  * @brief Returns the size of the DMA memory needed by CEE module
155  *
156  * @param[in] void
157  *
158  * @return Size of DMA region
159  */
160 u32
161 bfa_nw_cee_meminfo(void)
162 {
163         return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
164 }
165
166 /**
167  * bfa_nw_cee_mem_claim()
168  *
169  * @brief Initialized CEE DMA Memory
170  *
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
174  *
175  * @return void
176  */
177 void
178 bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
179 {
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());
187 }
188
189 /**
190  * bfa_cee_isrs()
191  *
192  * @brief Handles Mail-box interrupts for CEE module.
193  *
194  * @param[in] Pointer to the CEE module data structure.
195  *
196  * @return void
197  */
198
199 static void
200 bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
201 {
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);
210                 break;
211         case BFI_CEE_I2H_GET_STATS_RSP:
212                 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
213                 break;
214         case BFI_CEE_I2H_RESET_STATS_RSP:
215                 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
216                 break;
217         default:
218                 BUG_ON(1);
219         }
220 }
221
222 /**
223  * bfa_cee_notify()
224  *
225  * @brief CEE module heart-beat failure handler.
226  * @brief CEE module IOC event handler.
227  *
228  * @param[in] IOC event type
229  *
230  * @return void
231  */
232
233 static void
234 bfa_cee_notify(void *arg, enum bfa_ioc_event event)
235 {
236         struct bfa_cee *cee;
237         cee = (struct bfa_cee *) arg;
238
239         switch (event) {
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,
248                                         BFA_STATUS_FAILED);
249                         }
250                 }
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,
257                                         BFA_STATUS_FAILED);
258                         }
259                 }
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,
266                                         BFA_STATUS_FAILED);
267                         }
268                 }
269                 break;
270
271         default:
272                 break;
273         }
274 }
275
276 /**
277  * bfa_nw_cee_attach()
278  *
279  * @brief CEE module-attach API
280  *
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.
286  *
287  * @return void
288  */
289 void
290 bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
291                 void *dev)
292 {
293         BUG_ON(!(cee != NULL));
294         cee->dev = dev;
295         cee->ioc = ioc;
296
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);
301 }