blob: fff96226a383c6c06363d9e1036301f88d5bf8ac [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
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070018#include "bfa_defs_svc.h"
19#include "bfa_port.h"
20#include "bfi.h"
21#include "bfa_ioc.h"
22
Jing Huang7725ccf2009-09-23 17:46:15 -070023
24BFA_TRC_FILE(CNA, PORT);
25
26#define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
Jing Huang7725ccf2009-09-23 17:46:15 -070027
28static void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070029bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
Jing Huang7725ccf2009-09-23 17:46:15 -070030{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070031 u32 *dip = (u32 *) stats;
32 u32 t0, t1;
33 int i;
Jing Huang7725ccf2009-09-23 17:46:15 -070034
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070035 for (i = 0; i < sizeof(union bfa_port_stats_u)/sizeof(u32);
36 i += 2) {
Jing Huang7725ccf2009-09-23 17:46:15 -070037 t0 = dip[i];
38 t1 = dip[i + 1];
39#ifdef __BIGENDIAN
Jing Huangba816ea2010-10-18 17:10:50 -070040 dip[i] = be32_to_cpu(t0);
41 dip[i + 1] = be32_to_cpu(t1);
Jing Huang7725ccf2009-09-23 17:46:15 -070042#else
Jing Huangba816ea2010-10-18 17:10:50 -070043 dip[i] = be32_to_cpu(t1);
44 dip[i + 1] = be32_to_cpu(t0);
Jing Huang7725ccf2009-09-23 17:46:15 -070045#endif
46 }
Jing Huang7725ccf2009-09-23 17:46:15 -070047}
48
Jing Huang5fbe25c2010-10-18 17:17:23 -070049/*
Jing Huang7725ccf2009-09-23 17:46:15 -070050 * bfa_port_enable_isr()
51 *
52 *
53 * @param[in] port - Pointer to the port module
54 * status - Return status from the f/w
55 *
56 * @return void
57 */
58static void
59bfa_port_enable_isr(struct bfa_port_s *port, bfa_status_t status)
60{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070061 bfa_trc(port, status);
62 port->endis_pending = BFA_FALSE;
63 port->endis_cbfn(port->endis_cbarg, status);
Jing Huang7725ccf2009-09-23 17:46:15 -070064}
65
Jing Huang5fbe25c2010-10-18 17:17:23 -070066/*
Jing Huang7725ccf2009-09-23 17:46:15 -070067 * bfa_port_disable_isr()
68 *
69 *
70 * @param[in] port - Pointer to the port module
71 * status - Return status from the f/w
72 *
73 * @return void
74 */
75static void
76bfa_port_disable_isr(struct bfa_port_s *port, bfa_status_t status)
77{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -070078 bfa_trc(port, status);
79 port->endis_pending = BFA_FALSE;
80 port->endis_cbfn(port->endis_cbarg, status);
Jing Huang7725ccf2009-09-23 17:46:15 -070081}
82
Jing Huang5fbe25c2010-10-18 17:17:23 -070083/*
Jing Huang7725ccf2009-09-23 17:46:15 -070084 * bfa_port_get_stats_isr()
85 *
86 *
87 * @param[in] port - Pointer to the Port module
88 * status - Return status from the f/w
89 *
90 * @return void
91 */
92static void
93bfa_port_get_stats_isr(struct bfa_port_s *port, bfa_status_t status)
94{
95 port->stats_status = status;
96 port->stats_busy = BFA_FALSE;
97
98 if (status == BFA_STATUS_OK) {
Jing Huangb85d0452010-07-08 19:48:49 -070099 struct bfa_timeval_s tv;
100
Jing Huang7725ccf2009-09-23 17:46:15 -0700101 memcpy(port->stats, port->stats_dma.kva,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700102 sizeof(union bfa_port_stats_u));
Jing Huang7725ccf2009-09-23 17:46:15 -0700103 bfa_port_stats_swap(port, port->stats);
Jing Huangb85d0452010-07-08 19:48:49 -0700104
105 bfa_os_gettimeofday(&tv);
106 port->stats->fc.secs_reset = tv.tv_sec - port->stats_reset_time;
Jing Huang7725ccf2009-09-23 17:46:15 -0700107 }
108
109 if (port->stats_cbfn) {
110 port->stats_cbfn(port->stats_cbarg, status);
111 port->stats_cbfn = NULL;
112 }
113}
114
Jing Huang5fbe25c2010-10-18 17:17:23 -0700115/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700116 * bfa_port_clear_stats_isr()
117 *
118 *
119 * @param[in] port - Pointer to the Port module
120 * status - Return status from the f/w
121 *
122 * @return void
123 */
124static void
125bfa_port_clear_stats_isr(struct bfa_port_s *port, bfa_status_t status)
126{
Jing Huangb85d0452010-07-08 19:48:49 -0700127 struct bfa_timeval_s tv;
128
Jing Huang7725ccf2009-09-23 17:46:15 -0700129 port->stats_status = status;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700130 port->stats_busy = BFA_FALSE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700131
Jing Huang5fbe25c2010-10-18 17:17:23 -0700132 /*
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700133 * re-initialize time stamp for stats reset
134 */
Jing Huangb85d0452010-07-08 19:48:49 -0700135 bfa_os_gettimeofday(&tv);
136 port->stats_reset_time = tv.tv_sec;
137
Jing Huang7725ccf2009-09-23 17:46:15 -0700138 if (port->stats_cbfn) {
139 port->stats_cbfn(port->stats_cbarg, status);
140 port->stats_cbfn = NULL;
141 }
142}
143
Jing Huang5fbe25c2010-10-18 17:17:23 -0700144/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700145 * bfa_port_isr()
146 *
147 *
148 * @param[in] Pointer to the Port module data structure.
149 *
150 * @return void
151 */
152static void
153bfa_port_isr(void *cbarg, struct bfi_mbmsg_s *m)
154{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700155 struct bfa_port_s *port = (struct bfa_port_s *) cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700156 union bfi_port_i2h_msg_u *i2hmsg;
157
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700158 i2hmsg = (union bfi_port_i2h_msg_u *) m;
Jing Huang7725ccf2009-09-23 17:46:15 -0700159 bfa_trc(port, m->mh.msg_id);
160
161 switch (m->mh.msg_id) {
162 case BFI_PORT_I2H_ENABLE_RSP:
163 if (port->endis_pending == BFA_FALSE)
164 break;
165 bfa_port_enable_isr(port, i2hmsg->enable_rsp.status);
166 break;
167
168 case BFI_PORT_I2H_DISABLE_RSP:
169 if (port->endis_pending == BFA_FALSE)
170 break;
171 bfa_port_disable_isr(port, i2hmsg->disable_rsp.status);
172 break;
173
174 case BFI_PORT_I2H_GET_STATS_RSP:
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700175 /* Stats busy flag is still set? (may be cmd timed out) */
Jing Huang7725ccf2009-09-23 17:46:15 -0700176 if (port->stats_busy == BFA_FALSE)
177 break;
178 bfa_port_get_stats_isr(port, i2hmsg->getstats_rsp.status);
179 break;
180
181 case BFI_PORT_I2H_CLEAR_STATS_RSP:
182 if (port->stats_busy == BFA_FALSE)
183 break;
184 bfa_port_clear_stats_isr(port, i2hmsg->clearstats_rsp.status);
185 break;
186
187 default:
188 bfa_assert(0);
189 }
190}
191
Jing Huang5fbe25c2010-10-18 17:17:23 -0700192/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700193 * bfa_port_meminfo()
194 *
195 *
196 * @param[in] void
197 *
198 * @return Size of DMA region
199 */
200u32
201bfa_port_meminfo(void)
202{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700203 return BFA_ROUNDUP(sizeof(union bfa_port_stats_u), BFA_DMA_ALIGN_SZ);
Jing Huang7725ccf2009-09-23 17:46:15 -0700204}
205
Jing Huang5fbe25c2010-10-18 17:17:23 -0700206/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700207 * bfa_port_mem_claim()
208 *
209 *
210 * @param[in] port Port module pointer
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700211 * dma_kva Kernel Virtual Address of Port DMA Memory
212 * dma_pa Physical Address of Port DMA Memory
Jing Huang7725ccf2009-09-23 17:46:15 -0700213 *
214 * @return void
215 */
216void
217bfa_port_mem_claim(struct bfa_port_s *port, u8 *dma_kva, u64 dma_pa)
218{
219 port->stats_dma.kva = dma_kva;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700220 port->stats_dma.pa = dma_pa;
Jing Huang7725ccf2009-09-23 17:46:15 -0700221}
222
Jing Huang5fbe25c2010-10-18 17:17:23 -0700223/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700224 * bfa_port_enable()
225 *
226 * Send the Port enable request to the f/w
227 *
228 * @param[in] Pointer to the Port module data structure.
229 *
230 * @return Status
231 */
232bfa_status_t
233bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700234 void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700235{
236 struct bfi_port_generic_req_s *m;
237
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700238 if (bfa_ioc_is_disabled(port->ioc)) {
239 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
240 return BFA_STATUS_IOC_DISABLED;
241 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700242
243 if (!bfa_ioc_is_operational(port->ioc)) {
244 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
245 return BFA_STATUS_IOC_FAILURE;
246 }
247
248 if (port->endis_pending) {
249 bfa_trc(port, BFA_STATUS_DEVBUSY);
250 return BFA_STATUS_DEVBUSY;
251 }
252
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700253 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700254
255 port->msgtag++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700256 port->endis_cbfn = cbfn;
257 port->endis_cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700258 port->endis_pending = BFA_TRUE;
259
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);
263
264 return BFA_STATUS_OK;
265}
266
Jing Huang5fbe25c2010-10-18 17:17:23 -0700267/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700268 * bfa_port_disable()
269 *
270 * Send the Port disable request to the f/w
271 *
272 * @param[in] Pointer to the Port module data structure.
273 *
274 * @return Status
275 */
276bfa_status_t
277bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700278 void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700279{
280 struct bfi_port_generic_req_s *m;
281
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700282 if (bfa_ioc_is_disabled(port->ioc)) {
283 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
284 return BFA_STATUS_IOC_DISABLED;
285 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700286
287 if (!bfa_ioc_is_operational(port->ioc)) {
288 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
289 return BFA_STATUS_IOC_FAILURE;
290 }
291
292 if (port->endis_pending) {
293 bfa_trc(port, BFA_STATUS_DEVBUSY);
294 return BFA_STATUS_DEVBUSY;
295 }
296
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700297 m = (struct bfi_port_generic_req_s *) port->endis_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700298
299 port->msgtag++;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700300 port->endis_cbfn = cbfn;
301 port->endis_cbarg = cbarg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700302 port->endis_pending = BFA_TRUE;
303
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);
307
308 return BFA_STATUS_OK;
309}
310
Jing Huang5fbe25c2010-10-18 17:17:23 -0700311/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700312 * bfa_port_get_stats()
313 *
314 * Send the request to the f/w to fetch Port statistics.
315 *
316 * @param[in] Pointer to the Port module data structure.
317 *
318 * @return Status
319 */
320bfa_status_t
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700321bfa_port_get_stats(struct bfa_port_s *port, union bfa_port_stats_u *stats,
322 bfa_port_stats_cbfn_t cbfn, void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700323{
324 struct bfi_port_get_stats_req_s *m;
325
326 if (!bfa_ioc_is_operational(port->ioc)) {
327 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
328 return BFA_STATUS_IOC_FAILURE;
329 }
330
331 if (port->stats_busy) {
332 bfa_trc(port, BFA_STATUS_DEVBUSY);
333 return BFA_STATUS_DEVBUSY;
334 }
335
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700336 m = (struct bfi_port_get_stats_req_s *) port->stats_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700337
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700338 port->stats = stats;
339 port->stats_cbfn = cbfn;
Jing Huang7725ccf2009-09-23 17:46:15 -0700340 port->stats_cbarg = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700341 port->stats_busy = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700342 bfa_dma_be_addr_set(m->dma_addr, port->stats_dma.pa);
343
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);
347
348 return BFA_STATUS_OK;
349}
350
Jing Huang5fbe25c2010-10-18 17:17:23 -0700351/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700352 * bfa_port_clear_stats()
353 *
354 *
355 * @param[in] Pointer to the Port module data structure.
356 *
357 * @return Status
358 */
359bfa_status_t
360bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700361 void *cbarg)
Jing Huang7725ccf2009-09-23 17:46:15 -0700362{
363 struct bfi_port_generic_req_s *m;
364
365 if (!bfa_ioc_is_operational(port->ioc)) {
366 bfa_trc(port, BFA_STATUS_IOC_FAILURE);
367 return BFA_STATUS_IOC_FAILURE;
368 }
369
370 if (port->stats_busy) {
371 bfa_trc(port, BFA_STATUS_DEVBUSY);
372 return BFA_STATUS_DEVBUSY;
373 }
374
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700375 m = (struct bfi_port_generic_req_s *) port->stats_mb.msg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700376
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700377 port->stats_cbfn = cbfn;
Jing Huang7725ccf2009-09-23 17:46:15 -0700378 port->stats_cbarg = cbarg;
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700379 port->stats_busy = BFA_TRUE;
Jing Huang7725ccf2009-09-23 17:46:15 -0700380
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);
384
385 return BFA_STATUS_OK;
386}
387
Jing Huang5fbe25c2010-10-18 17:17:23 -0700388/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700389 * bfa_port_hbfail()
390 *
391 *
392 * @param[in] Pointer to the Port module data structure.
393 *
394 * @return void
395 */
396void
397bfa_port_hbfail(void *arg)
398{
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700399 struct bfa_port_s *port = (struct bfa_port_s *) arg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700400
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700401 /* Fail any pending get_stats/clear_stats requests */
Jing Huang7725ccf2009-09-23 17:46:15 -0700402 if (port->stats_busy) {
403 if (port->stats_cbfn)
Jing Huang8a4adf12010-07-08 20:01:07 -0700404 port->stats_cbfn(port->stats_cbarg, BFA_STATUS_FAILED);
Jing Huang7725ccf2009-09-23 17:46:15 -0700405 port->stats_cbfn = NULL;
406 port->stats_busy = BFA_FALSE;
407 }
408
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700409 /* Clear any enable/disable is pending */
Jing Huang7725ccf2009-09-23 17:46:15 -0700410 if (port->endis_pending) {
411 if (port->endis_cbfn)
Jing Huang8a4adf12010-07-08 20:01:07 -0700412 port->endis_cbfn(port->endis_cbarg, BFA_STATUS_FAILED);
Jing Huang7725ccf2009-09-23 17:46:15 -0700413 port->endis_cbfn = NULL;
414 port->endis_pending = BFA_FALSE;
415 }
416}
417
Jing Huang5fbe25c2010-10-18 17:17:23 -0700418/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700419 * bfa_port_attach()
420 *
421 *
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.
427 * trcmod -
Jing Huang7725ccf2009-09-23 17:46:15 -0700428 *
429 * @return void
430 */
431void
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700432bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
433 void *dev, struct bfa_trc_mod_s *trcmod)
Jing Huang7725ccf2009-09-23 17:46:15 -0700434{
Jing Huangb85d0452010-07-08 19:48:49 -0700435 struct bfa_timeval_s tv;
436
Jing Huang7725ccf2009-09-23 17:46:15 -0700437 bfa_assert(port);
438
Krishna Gudipatia36c61f2010-09-15 11:50:55 -0700439 port->dev = dev;
440 port->ioc = ioc;
Jing Huang7725ccf2009-09-23 17:46:15 -0700441 port->trcmod = trcmod;
Jing Huang7725ccf2009-09-23 17:46:15 -0700442
Jing Huangb85d0452010-07-08 19:48:49 -0700443 port->stats_busy = BFA_FALSE;
444 port->endis_pending = BFA_FALSE;
445 port->stats_cbfn = NULL;
446 port->endis_cbfn = NULL;
Jing Huang7725ccf2009-09-23 17:46:15 -0700447
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);
451
Jing Huang5fbe25c2010-10-18 17:17:23 -0700452 /*
Jing Huangb85d0452010-07-08 19:48:49 -0700453 * initialize time stamp for stats reset
454 */
455 bfa_os_gettimeofday(&tv);
456 port->stats_reset_time = tv.tv_sec;
457
Jing Huang7725ccf2009-09-23 17:46:15 -0700458 bfa_trc(port, 0);
459}
460
Jing Huang5fbe25c2010-10-18 17:17:23 -0700461/*
Jing Huang7725ccf2009-09-23 17:46:15 -0700462 * bfa_port_detach()
463 *
464 *
465 * @param[in] port - Pointer to the Port module data structure
466 *
467 * @return void
468 */
469void
470bfa_port_detach(struct bfa_port_s *port)
471{
472 bfa_trc(port, 0);
473}