2 * Copyright (c) 2005-2010 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 "bfa_defs_svc.h"
24 BFA_TRC_FILE(CNA, PORT);
26 #define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
29 bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
31 u32 *dip = (u32 *) stats;
35 for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32);
40 dip[i] = bfa_os_ntohl(t0);
41 dip[i + 1] = bfa_os_ntohl(t1);
43 dip[i] = bfa_os_ntohl(t1);
44 dip[i + 1] = bfa_os_ntohl(t0);
50 * bfa_port_enable_isr()
53 * @param[in] port - Pointer to the port module
54 * status - Return status from the f/w
59 bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
61 bfa_trc(port, status);
62 port->endis_pending = BFA_FALSE;
63 port->endis_cbfn(port->endis_cbarg, status);
67 * bfa_port_disable_isr()
70 * @param[in] port - Pointer to the port module
71 * status - Return status from the f/w
76 bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
78 bfa_trc(port, status);
79 port->endis_pending = BFA_FALSE;
80 port->endis_cbfn(port->endis_cbarg, status);
84 * bfa_port_get_stats_isr()
87 * @param[in] port - Pointer to the Port module
88 * status - Return status from the f/w
93 bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
95 port->stats_status = status;
96 port->stats_busy = BFA_FALSE;
98 if (status == BFA_STATUS_OK) {
99 struct bfa_timeval_s tv;
101 memcpy(port->stats, port->stats_dma.kva,
102 sizeof(union bfa_port_stats_u));
103 bfa_port_stats_swap(port, port->stats);
105 bfa_os_gettimeofday(&tv);
106 port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
109 if (port->stats_cbfn) {
110 port->stats_cbfn(port->stats_cbarg, status);
111 port->stats_cbfn = NULL;
116 * bfa_port_clear_stats_isr()
119 * @param[in] port - Pointer to the Port module
120 * status - Return status from the f/w
125 bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
127 struct bfa_timeval_s tv;
129 port->stats_status = status;
130 port->stats_busy = BFA_FALSE;
133 * re-initialize time stamp for stats reset
135 bfa_os_gettimeofday(&tv);
136 port->stats_reset_time = tv.tv_sec;
138 if (port->stats_cbfn) {
139 port->stats_cbfn(port->stats_cbarg, status);
140 port->stats_cbfn = NULL;
148 * @param[in] Pointer to the Port module data structure.
153 bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
155 struct bfa_port_s *port = (struct bfa_port_s *) cbarg;
156 union bfi_port_i2h_msg_u *i2hmsg;
158 i2hmsg = (union bfi_port_i2h_msg_u *) m;
159 bfa_trc(port, m->mh.msg_id);
161 switch (m->mh.msg_id) {
162 case BFI_PORT_I2H_ENABLE_RSP:
163 if (port->endis_pending == BFA_FALSE)
165 bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
168 case BFI_PORT_I2H_DISABLE_RSP:
169 if (port->endis_pending == BFA_FALSE)
171 bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
174 case BFI_PORT_I2H_GET_STATS_RSP:
175 /* Stats busy flag is still set? (may be cmd timed out) */
176 if (port->stats_busy == BFA_FALSE)
178 bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
181 case BFI_PORT_I2H_CLEAR_STATS_RSP:
182 if (port->stats_busy == BFA_FALSE)
184 bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
198 * @return Size of DMA region
201 bfa_port_meminfo(void)
203 return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ);
207 * bfa_port_mem_claim()
210 * @param[in] port Port module pointer
211 * dma_kva Kernel Virtual Address of Port DMA Memory
212 * dma_pa Physical Address of Port DMA Memory
217 bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
219 port->stats_dma.kva = dma_kva;
220 port->stats_dma.pa = dma_pa;
226 * Send the Port enable request to the f/w
228 * @param[in] Pointer to the Port module data structure.
233 bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
236 struct bfi_port_generic_req_s *m;
238 if (bfa_ioc_is_disabled(port->ioc)) {
239 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
240 return BFA_STATUS_IOC_DISABLED;
243 if (!bfa_ioc_is_operational(port->ioc)) {
244 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
245 return BFA_STATUS_IOC_FAILURE;
248 if (port->endis_pending) {
249 bfa_trc(port, BFA_STATUS_DEVBUSY);
250 return BFA_STATUS_DEVBUSY;
253 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
256 port->endis_cbfn = cbfn;
257 port->endis_cbarg = cbarg;
258 port->endis_pending = BFA_TRUE;
260 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_ENABLE_REQ,
261 bfa_ioc_portid(port->ioc));
262 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
264 return BFA_STATUS_OK;
270 * Send the Port disable request to the f/w
272 * @param[in] Pointer to the Port module data structure.
277 bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
280 struct bfi_port_generic_req_s *m;
282 if (bfa_ioc_is_disabled(port->ioc)) {
283 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
284 return BFA_STATUS_IOC_DISABLED;
287 if (!bfa_ioc_is_operational(port->ioc)) {
288 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
289 return BFA_STATUS_IOC_FAILURE;
292 if (port->endis_pending) {
293 bfa_trc(port, BFA_STATUS_DEVBUSY);
294 return BFA_STATUS_DEVBUSY;
297 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
300 port->endis_cbfn = cbfn;
301 port->endis_cbarg = cbarg;
302 port->endis_pending = BFA_TRUE;
304 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_DISABLE_REQ,
305 bfa_ioc_portid(port->ioc));
306 bfa_ioc_mbox_queue(port->ioc, &port->endis_mb);
308 return BFA_STATUS_OK;
312 * bfa_port_get_stats()
314 * Send the request to the f/w to fetch Port statistics.
316 * @param[in] Pointer to the Port module data structure.
321 bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
322 bfa_port_stats_cbfn_t cbfn, void *cbarg)
324 struct bfi_port_get_stats_req_s *m;
326 if (!bfa_ioc_is_operational(port->ioc)) {
327 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
328 return BFA_STATUS_IOC_FAILURE;
331 if (port->stats_busy) {
332 bfa_trc(port, BFA_STATUS_DEVBUSY);
333 return BFA_STATUS_DEVBUSY;
336 m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
339 port->stats_cbfn = cbfn;
340 port->stats_cbarg = cbarg;
341 port->stats_busy = BFA_TRUE;
342 bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
344 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_GET_STATS_REQ,
345 bfa_ioc_portid(port->ioc));
346 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
348 return BFA_STATUS_OK;
352 * bfa_port_clear_stats()
355 * @param[in] Pointer to the Port module data structure.
360 bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
363 struct bfi_port_generic_req_s *m;
365 if (!bfa_ioc_is_operational(port->ioc)) {
366 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
367 return BFA_STATUS_IOC_FAILURE;
370 if (port->stats_busy) {
371 bfa_trc(port, BFA_STATUS_DEVBUSY);
372 return BFA_STATUS_DEVBUSY;
375 m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
377 port->stats_cbfn = cbfn;
378 port->stats_cbarg = cbarg;
379 port->stats_busy = BFA_TRUE;
381 bfi_h2i_set(m->mh, BFI_MC_PORT, BFI_PORT_H2I_CLEAR_STATS_REQ,
382 bfa_ioc_portid(port->ioc));
383 bfa_ioc_mbox_queue(port->ioc, &port->stats_mb);
385 return BFA_STATUS_OK;
392 * @param[in] Pointer to the Port module data structure.
397 bfa_port_hbfail(void *arg)
399 struct bfa_port_s *port = (struct bfa_port_s *) arg;
401 /* Fail any pending get_stats/clear_stats requests */
402 if (port->stats_busy) {
403 if (port->stats_cbfn)
404 port->stats_cbfn(port->stats_cbarg, BFA_STATUS_FAILED);
405 port->stats_cbfn = NULL;
406 port->stats_busy = BFA_FALSE;
409 /* Clear any enable/disable is pending */
410 if (port->endis_pending) {
411 if (port->endis_cbfn)
412 port->endis_cbfn(port->endis_cbarg, BFA_STATUS_FAILED);
413 port->endis_cbfn = NULL;
414 port->endis_pending = BFA_FALSE;
422 * @param[in] port - Pointer to the Port module data structure
423 * ioc - Pointer to the ioc module data structure
424 * dev - Pointer to the device driver module data structure
425 * The device driver specific mbox ISR functions have
426 * this pointer as one of the parameters.
432 bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
433 void *dev, struct bfa_trc_mod_s *trcmod)
435 struct bfa_timeval_s tv;
441 port->trcmod = trcmod;
443 port->stats_busy = BFA_FALSE;
444 port->endis_pending = BFA_FALSE;
445 port->stats_cbfn = NULL;
446 port->endis_cbfn = NULL;
448 bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
449 bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port);
450 bfa_ioc_hbfail_register(port->ioc, &port->hbfail);
453 * initialize time stamp for stats reset
455 bfa_os_gettimeofday(&tv);
456 port->stats_reset_time = tv.tv_sec;
465 * @param[in] port - Pointer to the Port module data structure
470 bfa_port_detach(struct bfa_port_s *port)