2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
6 * Linux driver for Brocade Fibre Channel Host Bus Adapter.
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
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.
18 #include <defs/bfa_defs_port.h>
19 #include <cs/bfa_trc.h>
20 #include <cs/bfa_log.h>
21 #include <cs/bfa_debug.h>
22 #include <port/bfa_port.h>
24 #include <bfi/bfi_port.h>
26 #include <cna/bfa_cna_trcmod.h>
28 BFA_TRC_FILE(CNA, PORT);
30 #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
31 #define bfa_lpuid(__arg) bfa_ioc_portid(&(__arg)->ioc)
34 bfa_port_stats_swap(struct bfa_port_s *port, union bfa_pport_stats_u *stats)
36 u32 *dip = (u32 *) stats;
40 for (i = 0; i < sizeof(union bfa_pport_stats_u) / sizeof(u32);
45 dip[i] = bfa_os_ntohl(t0);
46 dip[i + 1] = bfa_os_ntohl(t1);
48 dip[i] = bfa_os_ntohl(t1);
49 dip[i + 1] = bfa_os_ntohl(t0);
54 * QoS stats r also swapped as 64bit; that structure also
55 * has to use 64 bit counters
60 * bfa_port_enable_isr()
63 * @param[in] port - Pointer to the port module
64 * status - Return status from the f/w
69 bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
75 * bfa_port_disable_isr()
78 * @param[in] port - Pointer to the port module
79 * status - Return status from the f/w
84 bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
90 * bfa_port_get_stats_isr()
93 * @param[in] port - Pointer to the Port module
94 * status - Return status from the f/w
99 bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
101 port->stats_status = status;
102 port->stats_busy = BFA_FALSE;
104 if (status == BFA_STATUS_OK) {
105 struct bfa_timeval_s tv;
107 memcpy(port->stats, port->stats_dma.kva,
108 sizeof(union bfa_pport_stats_u));
109 bfa_port_stats_swap(port, port->stats);
111 bfa_os_gettimeofday(&tv);
112 port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
115 if (port->stats_cbfn) {
116 port->stats_cbfn(port->stats_cbarg, status);
117 port->stats_cbfn = NULL;
122 * bfa_port_clear_stats_isr()
125 * @param[in] port - Pointer to the Port module
126 * status - Return status from the f/w
131 bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
133 struct bfa_timeval_s tv;
135 port->stats_status = status;
136 port->stats_busy = BFA_FALSE;
139 * re-initialize time stamp for stats reset
141 bfa_os_gettimeofday(&tv);
142 port->stats_reset_time = tv.tv_sec;
144 if (port->stats_cbfn) {
145 port->stats_cbfn(port->stats_cbarg, status);
146 port->stats_cbfn = NULL;
154 * @param[in] Pointer to the Port module data structure.
159 bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
161 struct bfa_port_s *port = (struct bfa_port_s *)cbarg;
162 union bfi_port_i2h_msg_u *i2hmsg;
164 i2hmsg = (union bfi_port_i2h_msg_u *)m;
165 bfa_trc(port, m->mh.msg_id);
167 switch (m->mh.msg_id) {
168 case BFI_PORT_I2H_ENABLE_RSP:
169 if (port->endis_pending == BFA_FALSE)
171 bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
174 case BFI_PORT_I2H_DISABLE_RSP:
175 if (port->endis_pending == BFA_FALSE)
177 bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
180 case BFI_PORT_I2H_GET_STATS_RSP:
182 * Stats busy flag is still set? (may be cmd timed out)
184 if (port->stats_busy == BFA_FALSE)
186 bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
189 case BFI_PORT_I2H_CLEAR_STATS_RSP:
190 if (port->stats_busy == BFA_FALSE)
192 bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
206 * @return Size of DMA region
209 bfa_port_meminfo(void)
211 return BFA_ROUNDUP(sizeof(union bfa_pport_stats_u), BFA_DMA_ALIGN_SZ);
215 * bfa_port_mem_claim()
218 * @param[in] port Port module pointer
219 * dma_kva Kernel Virtual Address of Port DMA Memory
220 * dma_pa Physical Address of Port DMA Memory
225 bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
227 port->stats_dma.kva = dma_kva;
228 port->stats_dma.pa = dma_pa;
234 * Send the Port enable request to the f/w
236 * @param[in] Pointer to the Port module data structure.
241 bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
244 struct bfi_port_generic_req_s *m;
246 /** todo Not implemented */
249 if (!bfa_ioc_is_operational(port->ioc)) {
250 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
251 return BFA_STATUS_IOC_FAILURE;
254 if (port->endis_pending) {
255 bfa_trc(port, BFA_STATUS_DEVBUSY);
256 return BFA_STATUS_DEVBUSY;
259 m = (struct bfi_port_generic_req_s *)port->endis_mb.msg;
262 port->endis_cbfn = cbfn;
263 port->endis_cbarg = cbarg;
264 port->endis_pending = BFA_TRUE;
266 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
267 bfa_ioc_portid(port->ioc));
268 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
270 return BFA_STATUS_OK;
276 * Send the Port disable request to the f/w
278 * @param[in] Pointer to the Port module data structure.
283 bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
286 struct bfi_port_generic_req_s *m;
288 /** todo Not implemented */
291 if (!bfa_ioc_is_operational(port->ioc)) {
292 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
293 return BFA_STATUS_IOC_FAILURE;
296 if (port->endis_pending) {
297 bfa_trc(port, BFA_STATUS_DEVBUSY);
298 return BFA_STATUS_DEVBUSY;
301 m = (struct bfi_port_generic_req_s *)port->endis_mb.msg;
304 port->endis_cbfn = cbfn;
305 port->endis_cbarg = cbarg;
306 port->endis_pending = BFA_TRUE;
308 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
309 bfa_ioc_portid(port->ioc));
310 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
312 return BFA_STATUS_OK;
316 * bfa_port_get_stats()
318 * Send the request to the f/w to fetch Port statistics.
320 * @param[in] Pointer to the Port module data structure.
325 bfa_port_get_stats(struct bfa_port_s *port, union bfa_pport_stats_u *stats,
326 bfa_port_stats_cbfn_t cbfn, void *cbarg)
328 struct bfi_port_get_stats_req_s *m;
330 if (!bfa_ioc_is_operational(port->ioc)) {
331 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
332 return BFA_STATUS_IOC_FAILURE;
335 if (port->stats_busy) {
336 bfa_trc(port, BFA_STATUS_DEVBUSY);
337 return BFA_STATUS_DEVBUSY;
340 m = (struct bfi_port_get_stats_req_s *)port->stats_mb.msg;
343 port->stats_cbfn = cbfn;
344 port->stats_cbarg = cbarg;
345 port->stats_busy = BFA_TRUE;
346 bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
348 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
349 bfa_ioc_portid(port->ioc));
350 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
352 return BFA_STATUS_OK;
356 * bfa_port_clear_stats()
359 * @param[in] Pointer to the Port module data structure.
364 bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
367 struct bfi_port_generic_req_s *m;
369 if (!bfa_ioc_is_operational(port->ioc)) {
370 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
371 return BFA_STATUS_IOC_FAILURE;
374 if (port->stats_busy) {
375 bfa_trc(port, BFA_STATUS_DEVBUSY);
376 return BFA_STATUS_DEVBUSY;
379 m = (struct bfi_port_generic_req_s *)port->stats_mb.msg;
381 port->stats_cbfn = cbfn;
382 port->stats_cbarg = cbarg;
383 port->stats_busy = BFA_TRUE;
385 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
386 bfa_ioc_portid(port->ioc));
387 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
389 return BFA_STATUS_OK;
396 * @param[in] Pointer to the Port module data structure.
401 bfa_port_hbfail(void *arg)
403 struct bfa_port_s *port = (struct bfa_port_s *)arg;
406 * Fail any pending get_stats/clear_stats requests
408 if (port->stats_busy) {
409 if (port->stats_cbfn)
410 port->stats_cbfn(port->stats_cbarg, BFA_STATUS_FAILED);
411 port->stats_cbfn = NULL;
412 port->stats_busy = BFA_FALSE;
416 * Clear any enable/disable is pending
418 if (port->endis_pending) {
419 if (port->endis_cbfn)
420 port->endis_cbfn(port->endis_cbarg, BFA_STATUS_FAILED);
421 port->endis_cbfn = NULL;
422 port->endis_pending = BFA_FALSE;
430 * @param[in] port - Pointer to the Port module data structure
431 * ioc - Pointer to the ioc module data structure
432 * dev - Pointer to the device driver module data structure
433 * The device driver specific mbox ISR functions have
434 * this pointer as one of the parameters.
441 bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc, void *dev,
442 struct bfa_trc_mod_s *trcmod, struct bfa_log_mod_s *logmod)
444 struct bfa_timeval_s tv;
450 port->trcmod = trcmod;
451 port->logmod = logmod;
453 port->stats_busy = BFA_FALSE;
454 port->endis_pending = BFA_FALSE;
455 port->stats_cbfn = NULL;
456 port->endis_cbfn = NULL;
458 bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
459 bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port);
460 bfa_ioc_hbfail_register(port->ioc, &port->hbfail);
463 * initialize time stamp for stats reset
465 bfa_os_gettimeofday(&tv);
466 port->stats_reset_time = tv.tv_sec;
475 * @param[in] port - Pointer to the Port module data structure
480 bfa_port_detach(struct bfa_port_s *port)