~ubuntu-branches/ubuntu/precise/linux-lowlatency/precise

« back to all changes in this revision

Viewing changes to drivers/net/ethernet/brocade/bna/bfa_cee.c

  • Committer: Package Import Robot
  • Author(s): Alessio Igor Bogani
  • Date: 2011-10-26 11:13:05 UTC
  • Revision ID: package-import@ubuntu.com-20111026111305-tz023xykf0i6eosh
Tags: upstream-3.2.0
ImportĀ upstreamĀ versionĀ 3.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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_cee.h"
 
20
#include "bfi_cna.h"
 
21
#include "bfa_ioc.h"
 
22
 
 
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);
 
25
 
 
26
static void
 
27
bfa_cee_format_cee_cfg(void *buffer)
 
28
{
 
29
        struct bfa_cee_attr *cee_cfg = buffer;
 
30
        bfa_cee_format_lldp_cfg(&cee_cfg->lldp_remote);
 
31
}
 
32
 
 
33
static void
 
34
bfa_cee_stats_swap(struct bfa_cee_stats *stats)
 
35
{
 
36
        u32 *buffer = (u32 *)stats;
 
37
        int i;
 
38
 
 
39
        for (i = 0; i < (sizeof(struct bfa_cee_stats) / sizeof(u32));
 
40
                i++) {
 
41
                buffer[i] = ntohl(buffer[i]);
 
42
        }
 
43
}
 
44
 
 
45
static void
 
46
bfa_cee_format_lldp_cfg(struct bfa_cee_lldp_cfg *lldp_cfg)
 
47
{
 
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);
 
52
}
 
53
 
 
54
/**
 
55
 * bfa_cee_attr_meminfo()
 
56
 *
 
57
 * @brief Returns the size of the DMA memory needed by CEE attributes
 
58
 *
 
59
 * @param[in] void
 
60
 *
 
61
 * @return Size of DMA region
 
62
 */
 
63
static u32
 
64
bfa_cee_attr_meminfo(void)
 
65
{
 
66
        return roundup(sizeof(struct bfa_cee_attr), BFA_DMA_ALIGN_SZ);
 
67
}
 
68
/**
 
69
 * bfa_cee_stats_meminfo()
 
70
 *
 
71
 * @brief Returns the size of the DMA memory needed by CEE stats
 
72
 *
 
73
 * @param[in] void
 
74
 *
 
75
 * @return Size of DMA region
 
76
 */
 
77
static u32
 
78
bfa_cee_stats_meminfo(void)
 
79
{
 
80
        return roundup(sizeof(struct bfa_cee_stats), BFA_DMA_ALIGN_SZ);
 
81
}
 
82
 
 
83
/**
 
84
 * bfa_cee_get_attr_isr()
 
85
 *
 
86
 * @brief CEE ISR for get-attributes responses from f/w
 
87
 *
 
88
 * @param[in] cee - Pointer to the CEE module
 
89
 *            status - Return status from the f/w
 
90
 *
 
91
 * @return void
 
92
 */
 
93
static void
 
94
bfa_cee_get_attr_isr(struct bfa_cee *cee, enum bfa_status status)
 
95
{
 
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);
 
101
        }
 
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);
 
105
}
 
106
 
 
107
/**
 
108
 * bfa_cee_get_attr_isr()
 
109
 *
 
110
 * @brief CEE ISR for get-stats responses from f/w
 
111
 *
 
112
 * @param[in] cee - Pointer to the CEE module
 
113
 *            status - Return status from the f/w
 
114
 *
 
115
 * @return void
 
116
 */
 
117
static void
 
118
bfa_cee_get_stats_isr(struct bfa_cee *cee, enum bfa_status status)
 
119
{
 
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);
 
125
        }
 
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);
 
129
}
 
130
 
 
131
/**
 
132
 * bfa_cee_get_attr_isr()
 
133
 *
 
134
 * @brief CEE ISR for reset-stats responses from f/w
 
135
 *
 
136
 * @param[in] cee - Pointer to the CEE module
 
137
 *            status - Return status from the f/w
 
138
 *
 
139
 * @return void
 
140
 */
 
141
static void
 
142
bfa_cee_reset_stats_isr(struct bfa_cee *cee, enum bfa_status status)
 
143
{
 
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);
 
148
}
 
149
/**
 
150
 * bfa_nw_cee_meminfo()
 
151
 *
 
152
 * @brief Returns the size of the DMA memory needed by CEE module
 
153
 *
 
154
 * @param[in] void
 
155
 *
 
156
 * @return Size of DMA region
 
157
 */
 
158
u32
 
159
bfa_nw_cee_meminfo(void)
 
160
{
 
161
        return bfa_cee_attr_meminfo() + bfa_cee_stats_meminfo();
 
162
}
 
163
 
 
164
/**
 
165
 * bfa_nw_cee_mem_claim()
 
166
 *
 
167
 * @brief Initialized CEE DMA Memory
 
168
 *
 
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
 
172
 *
 
173
 * @return void
 
174
 */
 
175
void
 
176
bfa_nw_cee_mem_claim(struct bfa_cee *cee, u8 *dma_kva, u64 dma_pa)
 
177
{
 
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());
 
185
}
 
186
 
 
187
/**
 
188
 * bfa_cee_isrs()
 
189
 *
 
190
 * @brief Handles Mail-box interrupts for CEE module.
 
191
 *
 
192
 * @param[in] Pointer to the CEE module data structure.
 
193
 *
 
194
 * @return void
 
195
 */
 
196
 
 
197
static void
 
198
bfa_cee_isr(void *cbarg, struct bfi_mbmsg *m)
 
199
{
 
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);
 
217
        }
 
218
}
 
219
 
 
220
/**
 
221
 * bfa_cee_notify()
 
222
 *
 
223
 * @brief CEE module heart-beat failure handler.
 
224
 * @brief CEE module IOC event handler.
 
225
 *
 
226
 * @param[in] IOC event type
 
227
 *
 
228
 * @return void
 
229
 */
 
230
 
 
231
static void
 
232
bfa_cee_notify(void *arg, enum bfa_ioc_event event)
 
233
{
 
234
        struct bfa_cee *cee;
 
235
        cee = (struct bfa_cee *) arg;
 
236
 
 
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);
 
247
                        }
 
248
                }
 
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);
 
256
                        }
 
257
                }
 
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);
 
265
                        }
 
266
                }
 
267
                break;
 
268
 
 
269
        default:
 
270
                break;
 
271
        }
 
272
}
 
273
 
 
274
/**
 
275
 * bfa_nw_cee_attach()
 
276
 *
 
277
 * @brief CEE module-attach API
 
278
 *
 
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.
 
284
 *
 
285
 * @return void
 
286
 */
 
287
void
 
288
bfa_nw_cee_attach(struct bfa_cee *cee, struct bfa_ioc *ioc,
 
289
                void *dev)
 
290
{
 
291
        BUG_ON(!(cee != NULL));
 
292
        cee->dev = dev;
 
293
        cee->ioc = ioc;
 
294
 
 
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);
 
299
}