blob: 8ea7697deb9bdd87f6be661d6cf5a70ff44c171a [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -07002 * Copyright (c) 2005-2010 Brocade Communications Systems, Inc.
Jing Huang7725ccf2009-09-23 17:46:15 -07003 * All rights reserved
4 * www.brocade.com
5 *
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License (GPL) Version 2 as
10 * published by the Free Software Foundation
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 */
17
Maggie Zhangf16a1752010-12-09 19:12:32 -080018#include "bfad_drv.h"
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070019#include "bfa_defs_svc.h"
20#include "bfa_port.h"
21#include "bfi.h"
22#include "bfa_ioc.h"
23
Jing Huang7725ccf2009-09-23 17:46:15 -070024
25BFA_TRC_FILE(CNA, PORT);
26
Jing Huang7725ccf2009-09-23 17:46:15 -070027static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070028bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
Jing Huang7725ccf2009-09-23 17:46:15 -070029{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070030 u32 *dip = (u32 *) stats;
Maggie50444a32010-11-29 18:26:32 -080031 __be32 t0, t1;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070032 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -070033
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070034 for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32);
35 i += 2) {
Jing Huang7725ccf2009-09-23 17:46:15 -070036 t0 = dip[i];
37 t1 = dip[i + 1];
Maggie Zhangf16a1752010-12-09 19:12:32 -080038#ifdef __BIG_ENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -070039 dip[i] = be32_to_cpu(t0);
40 dip[i + 1] = be32_to_cpu(t1);
Jing Huang7725ccf2009-09-23 17:46:15 -070041#else
Jing Huangba816ea2010-10-18 17:10:50 -070042 dip[i] = be32_to_cpu(t1);
43 dip[i + 1] = be32_to_cpu(t0);
Jing Huang7725ccf2009-09-23 17:46:15 -070044#endif
45 }
Jing Huang7725ccf2009-09-23 17:46:15 -070046}
47
Jing Huang5fbe25c2010-10-18 17:17:23 -070048/*
Jing Huang7725ccf2009-09-23 17:46:15 -070049 * bfa_port_enable_isr()
50 *
51 *
52 * @param[in] port - Pointer to the port module
53 * status - Return status from the f/w
54 *
55 * @return void
56 */
57static void
58bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
59{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070060 bfa_trc(port, status);
61 port->endis_pending = BFA_FALSE;
62 port->endis_cbfn(port->endis_cbarg, status);
Jing Huang7725ccf2009-09-23 17:46:15 -070063}
64
Jing Huang5fbe25c2010-10-18 17:17:23 -070065/*
Jing Huang7725ccf2009-09-23 17:46:15 -070066 * bfa_port_disable_isr()
67 *
68 *
69 * @param[in] port - Pointer to the port module
70 * status - Return status from the f/w
71 *
72 * @return void
73 */
74static void
75bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
76{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070077 bfa_trc(port, status);
78 port->endis_pending = BFA_FALSE;
79 port->endis_cbfn(port->endis_cbarg, status);
Jing Huang7725ccf2009-09-23 17:46:15 -070080}
81
Jing Huang5fbe25c2010-10-18 17:17:23 -070082/*
Jing Huang7725ccf2009-09-23 17:46:15 -070083 * bfa_port_get_stats_isr()
84 *
85 *
86 * @param[in] port - Pointer to the Port module
87 * status - Return status from the f/w
88 *
89 * @return void
90 */
91static void
92bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
93{
94 port->stats_status = status;
95 port->stats_busy = BFA_FALSE;
96
97 if (status == BFA_STATUS_OK) {
Maggie Zhangf16a1752010-12-09 19:12:32 -080098 struct timeval tv;
Jing Huangb85d0452010-07-08 19:48:49 -070099
Jing Huang7725ccf2009-09-23 17:46:15 -0700100 memcpy(port->stats, port->stats_dma.kva,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700101 sizeof(union bfa_port_stats_u));
Jing Huang7725ccf2009-09-23 17:46:15 -0700102 bfa_port_stats_swap(port, port->stats);
Jing Huangb85d0452010-07-08 19:48:49 -0700103
Maggie Zhangf16a1752010-12-09 19:12:32 -0800104 do_gettimeofday(&tv);
Jing Huangb85d0452010-07-08 19:48:49 -0700105 port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
Jing Huang7725ccf2009-09-23 17:46:15 -0700106 }
107
108 if (port->stats_cbfn) {
109 port->stats_cbfn(port->stats_cbarg, status);
110 port->stats_cbfn = NULL;
111 }
112}
113
Jing Huang5fbe25c2010-10-18 17:17:23 -0700114/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700115 * bfa_port_clear_stats_isr()
116 *
117 *
118 * @param[in] port - Pointer to the Port module
119 * status - Return status from the f/w
120 *
121 * @return void
122 */
123static void
124bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
125{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800126 struct timeval tv;
Jing Huangb85d0452010-07-08 19:48:49 -0700127
Jing Huang7725ccf2009-09-23 17:46:15 -0700128 port->stats_status = status;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700129 port->stats_busy = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700130
Jing Huang5fbe25c2010-10-18 17:17:23 -0700131 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700132 * re-initialize time stamp for stats reset
133 */
Maggie Zhangf16a1752010-12-09 19:12:32 -0800134 do_gettimeofday(&tv);
Jing Huangb85d0452010-07-08 19:48:49 -0700135 port->stats_reset_time = tv.tv_sec;
136
Jing Huang7725ccf2009-09-23 17:46:15 -0700137 if (port->stats_cbfn) {
138 port->stats_cbfn(port->stats_cbarg, status);
139 port->stats_cbfn = NULL;
140 }
141}
142
Jing Huang5fbe25c2010-10-18 17:17:23 -0700143/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700144 * bfa_port_isr()
145 *
146 *
147 * @param[in] Pointer to the Port module data structure.
148 *
149 * @return void
150 */
151static void
152bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
153{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700154 struct bfa_port_s *port = (struct bfa_port_s *) cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700155 union bfi_port_i2h_msg_u *i2hmsg;
156
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700157 i2hmsg = (union bfi_port_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -0700158 bfa_trc(port, m->mh.msg_id);
159
160 switch (m->mh.msg_id) {
161 case BFI_PORT_I2H_ENABLE_RSP:
162 if (port->endis_pending == BFA_FALSE)
163 break;
164 bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
165 break;
166
167 case BFI_PORT_I2H_DISABLE_RSP:
168 if (port->endis_pending == BFA_FALSE)
169 break;
170 bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
171 break;
172
173 case BFI_PORT_I2H_GET_STATS_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700174 /* Stats busy flag is still set? (may be cmd timed out) */
Jing Huang7725ccf2009-09-23 17:46:15 -0700175 if (port->stats_busy == BFA_FALSE)
176 break;
177 bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
178 break;
179
180 case BFI_PORT_I2H_CLEAR_STATS_RSP:
181 if (port->stats_busy == BFA_FALSE)
182 break;
183 bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
184 break;
185
186 default:
Jing Huangd4b671c2010-12-26 21:46:35 -0800187 WARN_ON(1);
Jing Huang7725ccf2009-09-23 17:46:15 -0700188 }
189}
190
Jing Huang5fbe25c2010-10-18 17:17:23 -0700191/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700192 * bfa_port_meminfo()
193 *
194 *
195 * @param[in] void
196 *
197 * @return Size of DMA region
198 */
199u32
200bfa_port_meminfo(void)
201{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700202 return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ);
Jing Huang7725ccf2009-09-23 17:46:15 -0700203}
204
Jing Huang5fbe25c2010-10-18 17:17:23 -0700205/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700206 * bfa_port_mem_claim()
207 *
208 *
209 * @param[in] port Port module pointer
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700210 * dma_kva Kernel Virtual Address of Port DMA Memory
211 * dma_pa Physical Address of Port DMA Memory
Jing Huang7725ccf2009-09-23 17:46:15 -0700212 *
213 * @return void
214 */
215void
216bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
217{
218 port->stats_dma.kva = dma_kva;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700219 port->stats_dma.pa = dma_pa;
Jing Huang7725ccf2009-09-23 17:46:15 -0700220}
221
Jing Huang5fbe25c2010-10-18 17:17:23 -0700222/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700223 * bfa_port_enable()
224 *
225 * Send the Port enable request to the f/w
226 *
227 * @param[in] Pointer to the Port module data structure.
228 *
229 * @return Status
230 */
231bfa_status_t
232bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700233 void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700234{
235 struct bfi_port_generic_req_s *m;
236
Krishna Gudipati43ffdf42011-06-13 15:46:21 -0700237 /* If port is PBC disabled, return error */
238 if (port->pbc_disabled) {
239 bfa_trc(port, BFA_STATUS_PBC);
240 return BFA_STATUS_PBC;
241 }
242
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700243 if (bfa_ioc_is_disabled(port->ioc)) {
244 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
245 return BFA_STATUS_IOC_DISABLED;
246 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700247
248 if (!bfa_ioc_is_operational(port->ioc)) {
249 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
250 return BFA_STATUS_IOC_FAILURE;
251 }
252
Krishna Gudipatie3535462012-09-21 17:26:07 -0700253 /* if port is d-port enabled, return error */
254 if (port->dport_enabled) {
255 bfa_trc(port, BFA_STATUS_DPORT_ERR);
256 return BFA_STATUS_DPORT_ERR;
257 }
258
Jing Huang7725ccf2009-09-23 17:46:15 -0700259 if (port->endis_pending) {
260 bfa_trc(port, BFA_STATUS_DEVBUSY);
261 return BFA_STATUS_DEVBUSY;
262 }
263
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700264 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700265
266 port->msgtag++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700267 port->endis_cbfn = cbfn;
268 port->endis_cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700269 port->endis_pending = BFA_TRUE;
270
271 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
272 bfa_ioc_portid(port->ioc));
273 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
274
275 return BFA_STATUS_OK;
276}
277
Jing Huang5fbe25c2010-10-18 17:17:23 -0700278/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700279 * bfa_port_disable()
280 *
281 * Send the Port disable request to the f/w
282 *
283 * @param[in] Pointer to the Port module data structure.
284 *
285 * @return Status
286 */
287bfa_status_t
288bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700289 void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700290{
291 struct bfi_port_generic_req_s *m;
292
Krishna Gudipati43ffdf42011-06-13 15:46:21 -0700293 /* If port is PBC disabled, return error */
294 if (port->pbc_disabled) {
295 bfa_trc(port, BFA_STATUS_PBC);
296 return BFA_STATUS_PBC;
297 }
298
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700299 if (bfa_ioc_is_disabled(port->ioc)) {
300 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
301 return BFA_STATUS_IOC_DISABLED;
302 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700303
304 if (!bfa_ioc_is_operational(port->ioc)) {
305 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
306 return BFA_STATUS_IOC_FAILURE;
307 }
308
Krishna Gudipatie3535462012-09-21 17:26:07 -0700309 /* if port is d-port enabled, return error */
310 if (port->dport_enabled) {
311 bfa_trc(port, BFA_STATUS_DPORT_ERR);
312 return BFA_STATUS_DPORT_ERR;
313 }
314
Jing Huang7725ccf2009-09-23 17:46:15 -0700315 if (port->endis_pending) {
316 bfa_trc(port, BFA_STATUS_DEVBUSY);
317 return BFA_STATUS_DEVBUSY;
318 }
319
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700320 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700321
322 port->msgtag++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700323 port->endis_cbfn = cbfn;
324 port->endis_cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700325 port->endis_pending = BFA_TRUE;
326
327 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
328 bfa_ioc_portid(port->ioc));
329 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
330
331 return BFA_STATUS_OK;
332}
333
Jing Huang5fbe25c2010-10-18 17:17:23 -0700334/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700335 * bfa_port_get_stats()
336 *
337 * Send the request to the f/w to fetch Port statistics.
338 *
339 * @param[in] Pointer to the Port module data structure.
340 *
341 * @return Status
342 */
343bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700344bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
345 bfa_port_stats_cbfn_t cbfn, void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700346{
347 struct bfi_port_get_stats_req_s *m;
348
349 if (!bfa_ioc_is_operational(port->ioc)) {
350 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
351 return BFA_STATUS_IOC_FAILURE;
352 }
353
354 if (port->stats_busy) {
355 bfa_trc(port, BFA_STATUS_DEVBUSY);
356 return BFA_STATUS_DEVBUSY;
357 }
358
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700359 m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700360
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700361 port->stats = stats;
362 port->stats_cbfn = cbfn;
Jing Huang7725ccf2009-09-23 17:46:15 -0700363 port->stats_cbarg = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700364 port->stats_busy = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700365 bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
366
367 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
368 bfa_ioc_portid(port->ioc));
369 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
370
371 return BFA_STATUS_OK;
372}
373
Jing Huang5fbe25c2010-10-18 17:17:23 -0700374/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700375 * bfa_port_clear_stats()
376 *
377 *
378 * @param[in] Pointer to the Port module data structure.
379 *
380 * @return Status
381 */
382bfa_status_t
383bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700384 void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700385{
386 struct bfi_port_generic_req_s *m;
387
388 if (!bfa_ioc_is_operational(port->ioc)) {
389 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
390 return BFA_STATUS_IOC_FAILURE;
391 }
392
393 if (port->stats_busy) {
394 bfa_trc(port, BFA_STATUS_DEVBUSY);
395 return BFA_STATUS_DEVBUSY;
396 }
397
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700398 m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700399
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700400 port->stats_cbfn = cbfn;
Jing Huang7725ccf2009-09-23 17:46:15 -0700401 port->stats_cbarg = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700402 port->stats_busy = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700403
404 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
405 bfa_ioc_portid(port->ioc));
406 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
407
408 return BFA_STATUS_OK;
409}
410
Jing Huang5fbe25c2010-10-18 17:17:23 -0700411/*
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700412 * bfa_port_notify()
Jing Huang7725ccf2009-09-23 17:46:15 -0700413 *
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700414 * Port module IOC event handler
Jing Huang7725ccf2009-09-23 17:46:15 -0700415 *
416 * @param[in] Pointer to the Port module data structure.
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700417 * @param[in] IOC event structure
Jing Huang7725ccf2009-09-23 17:46:15 -0700418 *
419 * @return void
420 */
421void
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700422bfa_port_notify(void *arg, enum bfa_ioc_event_e event)
Jing Huang7725ccf2009-09-23 17:46:15 -0700423{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700424 struct bfa_port_s *port = (struct bfa_port_s *) arg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700425
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700426 switch (event) {
427 case BFA_IOC_E_DISABLED:
428 case BFA_IOC_E_FAILED:
429 /* Fail any pending get_stats/clear_stats requests */
430 if (port->stats_busy) {
431 if (port->stats_cbfn)
432 port->stats_cbfn(port->stats_cbarg,
433 BFA_STATUS_FAILED);
434 port->stats_cbfn = NULL;
435 port->stats_busy = BFA_FALSE;
436 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700437
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700438 /* Clear any enable/disable is pending */
439 if (port->endis_pending) {
440 if (port->endis_cbfn)
441 port->endis_cbfn(port->endis_cbarg,
442 BFA_STATUS_FAILED);
443 port->endis_cbfn = NULL;
444 port->endis_pending = BFA_FALSE;
445 }
Krishna Gudipatie3535462012-09-21 17:26:07 -0700446
447 /* clear D-port mode */
448 if (port->dport_enabled)
449 bfa_port_set_dportenabled(port, BFA_FALSE);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700450 break;
451 default:
452 break;
Jing Huang7725ccf2009-09-23 17:46:15 -0700453 }
454}
455
Jing Huang5fbe25c2010-10-18 17:17:23 -0700456/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700457 * bfa_port_attach()
458 *
459 *
460 * @param[in] port - Pointer to the Port module data structure
461 * ioc - Pointer to the ioc module data structure
462 * dev - Pointer to the device driver module data structure
463 * The device driver specific mbox ISR functions have
464 * this pointer as one of the parameters.
465 * trcmod -
Jing Huang7725ccf2009-09-23 17:46:15 -0700466 *
467 * @return void
468 */
469void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700470bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
471 void *dev, struct bfa_trc_mod_s *trcmod)
Jing Huang7725ccf2009-09-23 17:46:15 -0700472{
Maggie Zhangf16a1752010-12-09 19:12:32 -0800473 struct timeval tv;
Jing Huangb85d0452010-07-08 19:48:49 -0700474
Jing Huangd4b671c2010-12-26 21:46:35 -0800475 WARN_ON(!port);
Jing Huang7725ccf2009-09-23 17:46:15 -0700476
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700477 port->dev = dev;
478 port->ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -0700479 port->trcmod = trcmod;
Jing Huang7725ccf2009-09-23 17:46:15 -0700480
Jing Huangb85d0452010-07-08 19:48:49 -0700481 port->stats_busy = BFA_FALSE;
482 port->endis_pending = BFA_FALSE;
483 port->stats_cbfn = NULL;
484 port->endis_cbfn = NULL;
Krishna Gudipati43ffdf42011-06-13 15:46:21 -0700485 port->pbc_disabled = BFA_FALSE;
Krishna Gudipatie3535462012-09-21 17:26:07 -0700486 port->dport_enabled = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700487
488 bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
Krishna Gudipati3350d982011-06-24 20:28:37 -0700489 bfa_q_qe_init(&port->ioc_notify);
Krishna Gudipatid37779f2011-06-13 15:42:10 -0700490 bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port);
491 list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q);
Jing Huang7725ccf2009-09-23 17:46:15 -0700492
Jing Huang5fbe25c2010-10-18 17:17:23 -0700493 /*
Jing Huangb85d0452010-07-08 19:48:49 -0700494 * initialize time stamp for stats reset
495 */
Maggie Zhangf16a1752010-12-09 19:12:32 -0800496 do_gettimeofday(&tv);
Jing Huangb85d0452010-07-08 19:48:49 -0700497 port->stats_reset_time = tv.tv_sec;
498
Jing Huang7725ccf2009-09-23 17:46:15 -0700499 bfa_trc(port, 0);
500}
Krishna Gudipati148d6102011-06-24 20:25:36 -0700501
502/*
Krishna Gudipatie3535462012-09-21 17:26:07 -0700503 * bfa_port_set_dportenabled();
504 *
505 * Port module- set pbc disabled flag
506 *
507 * @param[in] port - Pointer to the Port module data structure
508 *
509 * @return void
510 */
511void
512bfa_port_set_dportenabled(struct bfa_port_s *port, bfa_boolean_t enabled)
513{
514 port->dport_enabled = enabled;
515}
516
517/*
Krishna Gudipati148d6102011-06-24 20:25:36 -0700518 * CEE module specific definitions
519 */
520
521/*
522 * bfa_cee_get_attr_isr()
523 *
524 * @brief CEE ISR for get-attributes responses from f/w
525 *
526 * @param[in] cee - Pointer to the CEE module
527 * status - Return status from the f/w
528 *
529 * @return void
530 */
531static void
532bfa_cee_get_attr_isr(struct bfa_cee_s *cee, bfa_status_t status)
533{
534 struct bfa_cee_lldp_cfg_s *lldp_cfg = &cee->attr->lldp_remote;
535
536 cee->get_attr_status = status;
537 bfa_trc(cee, 0);
538 if (status == BFA_STATUS_OK) {
539 bfa_trc(cee, 0);
540 memcpy(cee->attr, cee->attr_dma.kva,
541 sizeof(struct bfa_cee_attr_s));
542 lldp_cfg->time_to_live = be16_to_cpu(lldp_cfg->time_to_live);
543 lldp_cfg->enabled_system_cap =
544 be16_to_cpu(lldp_cfg->enabled_system_cap);
545 }
546 cee->get_attr_pending = BFA_FALSE;
547 if (cee->cbfn.get_attr_cbfn) {
548 bfa_trc(cee, 0);
549 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
550 }
551}
552
553/*
554 * bfa_cee_get_stats_isr()
555 *
556 * @brief CEE ISR for get-stats responses from f/w
557 *
558 * @param[in] cee - Pointer to the CEE module
559 * status - Return status from the f/w
560 *
561 * @return void
562 */
563static void
564bfa_cee_get_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
565{
566 u32 *buffer;
567 int i;
568
569 cee->get_stats_status = status;
570 bfa_trc(cee, 0);
571 if (status == BFA_STATUS_OK) {
572 bfa_trc(cee, 0);
573 memcpy(cee->stats, cee->stats_dma.kva,
574 sizeof(struct bfa_cee_stats_s));
575 /* swap the cee stats */
576 buffer = (u32 *)cee->stats;
577 for (i = 0; i < (sizeof(struct bfa_cee_stats_s) /
578 sizeof(u32)); i++)
579 buffer[i] = cpu_to_be32(buffer[i]);
580 }
581 cee->get_stats_pending = BFA_FALSE;
582 bfa_trc(cee, 0);
583 if (cee->cbfn.get_stats_cbfn) {
584 bfa_trc(cee, 0);
585 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
586 }
587}
588
589/*
590 * bfa_cee_reset_stats_isr()
591 *
592 * @brief CEE ISR for reset-stats responses from f/w
593 *
594 * @param[in] cee - Pointer to the CEE module
595 * status - Return status from the f/w
596 *
597 * @return void
598 */
599static void
600bfa_cee_reset_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
601{
602 cee->reset_stats_status = status;
603 cee->reset_stats_pending = BFA_FALSE;
604 if (cee->cbfn.reset_stats_cbfn)
605 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
606}
607
608/*
609 * bfa_cee_meminfo()
610 *
611 * @brief Returns the size of the DMA memory needed by CEE module
612 *
613 * @param[in] void
614 *
615 * @return Size of DMA region
616 */
617u32
618bfa_cee_meminfo(void)
619{
620 return BFA_ROUNDUP(sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ) +
621 BFA_ROUNDUP(sizeof(struct bfa_cee_stats_s), BFA_DMA_ALIGN_SZ);
622}
623
624/*
625 * bfa_cee_mem_claim()
626 *
627 * @brief Initialized CEE DMA Memory
628 *
629 * @param[in] cee CEE module pointer
630 * dma_kva Kernel Virtual Address of CEE DMA Memory
631 * dma_pa Physical Address of CEE DMA Memory
632 *
633 * @return void
634 */
635void
636bfa_cee_mem_claim(struct bfa_cee_s *cee, u8 *dma_kva, u64 dma_pa)
637{
638 cee->attr_dma.kva = dma_kva;
639 cee->attr_dma.pa = dma_pa;
640 cee->stats_dma.kva = dma_kva + BFA_ROUNDUP(
641 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
642 cee->stats_dma.pa = dma_pa + BFA_ROUNDUP(
643 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
644 cee->attr = (struct bfa_cee_attr_s *) dma_kva;
645 cee->stats = (struct bfa_cee_stats_s *) (dma_kva + BFA_ROUNDUP(
646 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ));
647}
648
649/*
650 * bfa_cee_get_attr()
651 *
652 * @brief
653 * Send the request to the f/w to fetch CEE attributes.
654 *
655 * @param[in] Pointer to the CEE module data structure.
656 *
657 * @return Status
658 */
659
660bfa_status_t
661bfa_cee_get_attr(struct bfa_cee_s *cee, struct bfa_cee_attr_s *attr,
662 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
663{
664 struct bfi_cee_get_req_s *cmd;
665
666 WARN_ON((cee == NULL) || (cee->ioc == NULL));
667 bfa_trc(cee, 0);
668 if (!bfa_ioc_is_operational(cee->ioc)) {
669 bfa_trc(cee, 0);
670 return BFA_STATUS_IOC_FAILURE;
671 }
672 if (cee->get_attr_pending == BFA_TRUE) {
673 bfa_trc(cee, 0);
674 return BFA_STATUS_DEVBUSY;
675 }
676 cee->get_attr_pending = BFA_TRUE;
677 cmd = (struct bfi_cee_get_req_s *) cee->get_cfg_mb.msg;
678 cee->attr = attr;
679 cee->cbfn.get_attr_cbfn = cbfn;
680 cee->cbfn.get_attr_cbarg = cbarg;
681 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
682 bfa_ioc_portid(cee->ioc));
683 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
684 bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb);
685
686 return BFA_STATUS_OK;
687}
688
689/*
690 * bfa_cee_get_stats()
691 *
692 * @brief
693 * Send the request to the f/w to fetch CEE statistics.
694 *
695 * @param[in] Pointer to the CEE module data structure.
696 *
697 * @return Status
698 */
699
700bfa_status_t
701bfa_cee_get_stats(struct bfa_cee_s *cee, struct bfa_cee_stats_s *stats,
702 bfa_cee_get_stats_cbfn_t cbfn, void *cbarg)
703{
704 struct bfi_cee_get_req_s *cmd;
705
706 WARN_ON((cee == NULL) || (cee->ioc == NULL));
707
708 if (!bfa_ioc_is_operational(cee->ioc)) {
709 bfa_trc(cee, 0);
710 return BFA_STATUS_IOC_FAILURE;
711 }
712 if (cee->get_stats_pending == BFA_TRUE) {
713 bfa_trc(cee, 0);
714 return BFA_STATUS_DEVBUSY;
715 }
716 cee->get_stats_pending = BFA_TRUE;
717 cmd = (struct bfi_cee_get_req_s *) cee->get_stats_mb.msg;
718 cee->stats = stats;
719 cee->cbfn.get_stats_cbfn = cbfn;
720 cee->cbfn.get_stats_cbarg = cbarg;
721 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ,
722 bfa_ioc_portid(cee->ioc));
723 bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa);
724 bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb);
725
726 return BFA_STATUS_OK;
727}
728
729/*
730 * bfa_cee_reset_stats()
731 *
732 * @brief Clears CEE Stats in the f/w.
733 *
734 * @param[in] Pointer to the CEE module data structure.
735 *
736 * @return Status
737 */
738
739bfa_status_t
740bfa_cee_reset_stats(struct bfa_cee_s *cee,
741 bfa_cee_reset_stats_cbfn_t cbfn, void *cbarg)
742{
743 struct bfi_cee_reset_stats_s *cmd;
744
745 WARN_ON((cee == NULL) || (cee->ioc == NULL));
746 if (!bfa_ioc_is_operational(cee->ioc)) {
747 bfa_trc(cee, 0);
748 return BFA_STATUS_IOC_FAILURE;
749 }
750 if (cee->reset_stats_pending == BFA_TRUE) {
751 bfa_trc(cee, 0);
752 return BFA_STATUS_DEVBUSY;
753 }
754 cee->reset_stats_pending = BFA_TRUE;
755 cmd = (struct bfi_cee_reset_stats_s *) cee->reset_stats_mb.msg;
756 cee->cbfn.reset_stats_cbfn = cbfn;
757 cee->cbfn.reset_stats_cbarg = cbarg;
758 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS,
759 bfa_ioc_portid(cee->ioc));
760 bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb);
761
762 return BFA_STATUS_OK;
763}
764
765/*
766 * bfa_cee_isrs()
767 *
768 * @brief Handles Mail-box interrupts for CEE module.
769 *
770 * @param[in] Pointer to the CEE module data structure.
771 *
772 * @return void
773 */
774
775void
776bfa_cee_isr(void *cbarg, struct bfi_mbmsg_s *m)
777{
778 union bfi_cee_i2h_msg_u *msg;
779 struct bfi_cee_get_rsp_s *get_rsp;
780 struct bfa_cee_s *cee = (struct bfa_cee_s *) cbarg;
781 msg = (union bfi_cee_i2h_msg_u *) m;
782 get_rsp = (struct bfi_cee_get_rsp_s *) m;
783 bfa_trc(cee, msg->mh.msg_id);
784 switch (msg->mh.msg_id) {
785 case BFI_CEE_I2H_GET_CFG_RSP:
786 bfa_trc(cee, get_rsp->cmd_status);
787 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
788 break;
789 case BFI_CEE_I2H_GET_STATS_RSP:
790 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
791 break;
792 case BFI_CEE_I2H_RESET_STATS_RSP:
793 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
794 break;
795 default:
796 WARN_ON(1);
797 }
798}
799
800/*
801 * bfa_cee_notify()
802 *
803 * @brief CEE module IOC event handler.
804 *
805 * @param[in] Pointer to the CEE module data structure.
806 * @param[in] IOC event type
807 *
808 * @return void
809 */
810
811void
812bfa_cee_notify(void *arg, enum bfa_ioc_event_e event)
813{
814 struct bfa_cee_s *cee = (struct bfa_cee_s *) arg;
815
816 bfa_trc(cee, event);
817
818 switch (event) {
819 case BFA_IOC_E_DISABLED:
820 case BFA_IOC_E_FAILED:
821 if (cee->get_attr_pending == BFA_TRUE) {
822 cee->get_attr_status = BFA_STATUS_FAILED;
823 cee->get_attr_pending = BFA_FALSE;
824 if (cee->cbfn.get_attr_cbfn) {
825 cee->cbfn.get_attr_cbfn(
826 cee->cbfn.get_attr_cbarg,
827 BFA_STATUS_FAILED);
828 }
829 }
830 if (cee->get_stats_pending == BFA_TRUE) {
831 cee->get_stats_status = BFA_STATUS_FAILED;
832 cee->get_stats_pending = BFA_FALSE;
833 if (cee->cbfn.get_stats_cbfn) {
834 cee->cbfn.get_stats_cbfn(
835 cee->cbfn.get_stats_cbarg,
836 BFA_STATUS_FAILED);
837 }
838 }
839 if (cee->reset_stats_pending == BFA_TRUE) {
840 cee->reset_stats_status = BFA_STATUS_FAILED;
841 cee->reset_stats_pending = BFA_FALSE;
842 if (cee->cbfn.reset_stats_cbfn) {
843 cee->cbfn.reset_stats_cbfn(
844 cee->cbfn.reset_stats_cbarg,
845 BFA_STATUS_FAILED);
846 }
847 }
848 break;
849
850 default:
851 break;
852 }
853}
854
855/*
856 * bfa_cee_attach()
857 *
858 * @brief CEE module-attach API
859 *
860 * @param[in] cee - Pointer to the CEE module data structure
861 * ioc - Pointer to the ioc module data structure
862 * dev - Pointer to the device driver module data structure
863 * The device driver specific mbox ISR functions have
864 * this pointer as one of the parameters.
865 *
866 * @return void
867 */
868void
869bfa_cee_attach(struct bfa_cee_s *cee, struct bfa_ioc_s *ioc,
870 void *dev)
871{
872 WARN_ON(cee == NULL);
873 cee->dev = dev;
874 cee->ioc = ioc;
875
876 bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
877 bfa_q_qe_init(&cee->ioc_notify);
878 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
879 list_add_tail(&cee->ioc_notify.qe, &cee->ioc->notify_q);
880}