blob: 0776d74d40de78b7c25f4c4a1e74f1463bf0aa5c [file] [log] [blame]
Jing Huang7725ccf2009-09-23 17:46:15 -07001/*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * 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
18#include <cs/bfa_debug.h>
19#include <bfa_priv.h>
20#include <log/bfa_log_hal.h>
21#include <bfi/bfi_boot.h>
22#include <bfi/bfi_cbreg.h>
23#include <aen/bfa_aen_ioc.h>
24#include <defs/bfa_defs_iocfc.h>
25#include <defs/bfa_defs_pci.h>
26#include "bfa_callback_priv.h"
27#include "bfad_drv.h"
28
29BFA_TRC_FILE(HAL, IOCFC);
30
31/**
32 * IOC local definitions
33 */
34#define BFA_IOCFC_TOV 5000 /* msecs */
35
36enum {
37 BFA_IOCFC_ACT_NONE = 0,
38 BFA_IOCFC_ACT_INIT = 1,
39 BFA_IOCFC_ACT_STOP = 2,
40 BFA_IOCFC_ACT_DISABLE = 3,
41};
42
43/*
44 * forward declarations
45 */
46static void bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status);
47static void bfa_iocfc_disable_cbfn(void *bfa_arg);
48static void bfa_iocfc_hbfail_cbfn(void *bfa_arg);
49static void bfa_iocfc_reset_cbfn(void *bfa_arg);
50static void bfa_iocfc_stats_clear(void *bfa_arg);
51static void bfa_iocfc_stats_swap(struct bfa_fw_stats_s *d,
52 struct bfa_fw_stats_s *s);
53static void bfa_iocfc_stats_clr_cb(void *bfa_arg, bfa_boolean_t complete);
54static void bfa_iocfc_stats_clr_timeout(void *bfa_arg);
55static void bfa_iocfc_stats_cb(void *bfa_arg, bfa_boolean_t complete);
56static void bfa_iocfc_stats_timeout(void *bfa_arg);
57
58static struct bfa_ioc_cbfn_s bfa_iocfc_cbfn;
59
60/**
61 * bfa_ioc_pvt BFA IOC private functions
62 */
63
64static void
65bfa_iocfc_cqs_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
66{
67 int i, per_reqq_sz, per_rspq_sz;
68
69 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
70 BFA_DMA_ALIGN_SZ);
71 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
72 BFA_DMA_ALIGN_SZ);
73
74 /*
75 * Calculate CQ size
76 */
77 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
78 *dm_len = *dm_len + per_reqq_sz;
79 *dm_len = *dm_len + per_rspq_sz;
80 }
81
82 /*
83 * Calculate Shadow CI/PI size
84 */
85 for (i = 0; i < cfg->fwcfg.num_cqs; i++)
86 *dm_len += (2 * BFA_CACHELINE_SZ);
87}
88
89static void
90bfa_iocfc_fw_cfg_sz(struct bfa_iocfc_cfg_s *cfg, u32 *dm_len)
91{
92 *dm_len +=
93 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
94 *dm_len +=
95 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
96 BFA_CACHELINE_SZ);
97 *dm_len += BFA_ROUNDUP(sizeof(struct bfa_fw_stats_s), BFA_CACHELINE_SZ);
98}
99
100/**
101 * Use the Mailbox interface to send BFI_IOCFC_H2I_CFG_REQ
102 */
103static void
104bfa_iocfc_send_cfg(void *bfa_arg)
105{
106 struct bfa_s *bfa = bfa_arg;
107 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
108 struct bfi_iocfc_cfg_req_s cfg_req;
109 struct bfi_iocfc_cfg_s *cfg_info = iocfc->cfginfo;
110 struct bfa_iocfc_cfg_s *cfg = &iocfc->cfg;
111 int i;
112
113 bfa_assert(cfg->fwcfg.num_cqs <= BFI_IOC_MAX_CQS);
114 bfa_trc(bfa, cfg->fwcfg.num_cqs);
115
Jing Huang7725ccf2009-09-23 17:46:15 -0700116 bfa_iocfc_reset_queues(bfa);
117
118 /**
119 * initialize IOC configuration info
120 */
121 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
122 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
123
124 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
125 bfa_dma_be_addr_set(cfg_info->stats_addr, iocfc->stats_pa);
126
127 /**
128 * dma map REQ and RSP circular queues and shadow pointers
129 */
130 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
131 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
132 iocfc->req_cq_ba[i].pa);
133 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
134 iocfc->req_cq_shadow_ci[i].pa);
135 cfg_info->req_cq_elems[i] =
136 bfa_os_htons(cfg->drvcfg.num_reqq_elems);
137
138 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
139 iocfc->rsp_cq_ba[i].pa);
140 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
141 iocfc->rsp_cq_shadow_pi[i].pa);
142 cfg_info->rsp_cq_elems[i] =
143 bfa_os_htons(cfg->drvcfg.num_rspq_elems);
144 }
145
146 /**
Jing Huang7c814652010-07-08 19:50:38 -0700147 * Enable interrupt coalescing if it is driver init path
148 * and not ioc disable/enable path.
149 */
150 if (!iocfc->cfgdone)
151 cfg_info->intr_attr.coalesce = BFA_TRUE;
152
153 iocfc->cfgdone = BFA_FALSE;
154
155 /**
Jing Huang7725ccf2009-09-23 17:46:15 -0700156 * dma map IOC configuration itself
157 */
158 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
159 bfa_lpuid(bfa));
160 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
161
162 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
163 sizeof(struct bfi_iocfc_cfg_req_s));
164}
165
166static void
167bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
168 struct bfa_pcidev_s *pcidev)
169{
170 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
171
172 bfa->bfad = bfad;
173 iocfc->bfa = bfa;
174 iocfc->action = BFA_IOCFC_ACT_NONE;
175
176 bfa_os_assign(iocfc->cfg, *cfg);
177
178 /**
179 * Initialize chip specific handlers.
180 */
Jing Huang293f82d2010-07-08 19:45:20 -0700181 if (bfa_asic_id_ct(bfa_ioc_devid(&bfa->ioc))) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700182 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
Krishna Gudipatif5713c52010-03-05 19:37:09 -0800183 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
Jing Huang7725ccf2009-09-23 17:46:15 -0700184 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
185 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
186 iocfc->hwif.hw_msix_install = bfa_hwct_msix_install;
187 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
188 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
189 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
190 } else {
191 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
Krishna Gudipatif5713c52010-03-05 19:37:09 -0800192 iocfc->hwif.hw_reqq_ack = bfa_hwcb_reqq_ack;
Jing Huang7725ccf2009-09-23 17:46:15 -0700193 iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
194 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
195 iocfc->hwif.hw_msix_install = bfa_hwcb_msix_install;
196 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
197 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
198 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
199 }
200
201 iocfc->hwif.hw_reginit(bfa);
202 bfa->msix.nvecs = 0;
203}
204
205static void
206bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
207 struct bfa_meminfo_s *meminfo)
208{
209 u8 *dm_kva;
210 u64 dm_pa;
211 int i, per_reqq_sz, per_rspq_sz;
212 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
213 int dbgsz;
214
215 dm_kva = bfa_meminfo_dma_virt(meminfo);
216 dm_pa = bfa_meminfo_dma_phys(meminfo);
217
218 /*
219 * First allocate dma memory for IOC.
220 */
221 bfa_ioc_mem_claim(&bfa->ioc, dm_kva, dm_pa);
222 dm_kva += bfa_ioc_meminfo();
223 dm_pa += bfa_ioc_meminfo();
224
225 /*
226 * Claim DMA-able memory for the request/response queues and for shadow
227 * ci/pi registers
228 */
229 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
230 BFA_DMA_ALIGN_SZ);
231 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
232 BFA_DMA_ALIGN_SZ);
233
234 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
235 iocfc->req_cq_ba[i].kva = dm_kva;
236 iocfc->req_cq_ba[i].pa = dm_pa;
237 bfa_os_memset(dm_kva, 0, per_reqq_sz);
238 dm_kva += per_reqq_sz;
239 dm_pa += per_reqq_sz;
240
241 iocfc->rsp_cq_ba[i].kva = dm_kva;
242 iocfc->rsp_cq_ba[i].pa = dm_pa;
243 bfa_os_memset(dm_kva, 0, per_rspq_sz);
244 dm_kva += per_rspq_sz;
245 dm_pa += per_rspq_sz;
246 }
247
248 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
249 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
250 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
251 dm_kva += BFA_CACHELINE_SZ;
252 dm_pa += BFA_CACHELINE_SZ;
253
254 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
255 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
256 dm_kva += BFA_CACHELINE_SZ;
257 dm_pa += BFA_CACHELINE_SZ;
258 }
259
260 /*
261 * Claim DMA-able memory for the config info page
262 */
263 bfa->iocfc.cfg_info.kva = dm_kva;
264 bfa->iocfc.cfg_info.pa = dm_pa;
265 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
266 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
267 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
268
269 /*
270 * Claim DMA-able memory for the config response
271 */
272 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
273 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
274 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
275
276 dm_kva +=
277 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
278 BFA_CACHELINE_SZ);
279 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
280 BFA_CACHELINE_SZ);
281
282 /*
283 * Claim DMA-able memory for iocfc stats
284 */
285 bfa->iocfc.stats_kva = dm_kva;
286 bfa->iocfc.stats_pa = dm_pa;
287 bfa->iocfc.fw_stats = (struct bfa_fw_stats_s *) dm_kva;
288 dm_kva += BFA_ROUNDUP(sizeof(struct bfa_fw_stats_s), BFA_CACHELINE_SZ);
289 dm_pa += BFA_ROUNDUP(sizeof(struct bfa_fw_stats_s), BFA_CACHELINE_SZ);
290
291 bfa_meminfo_dma_virt(meminfo) = dm_kva;
292 bfa_meminfo_dma_phys(meminfo) = dm_pa;
293
294 dbgsz = bfa_ioc_debug_trcsz(bfa_auto_recover);
295 if (dbgsz > 0) {
296 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_meminfo_kva(meminfo));
297 bfa_meminfo_kva(meminfo) += dbgsz;
298 }
299}
300
301/**
Jing Huang7725ccf2009-09-23 17:46:15 -0700302 * Start BFA submodules.
303 */
304static void
305bfa_iocfc_start_submod(struct bfa_s *bfa)
306{
307 int i;
308
309 bfa->rme_process = BFA_TRUE;
310
311 for (i = 0; hal_mods[i]; i++)
312 hal_mods[i]->start(bfa);
313}
314
315/**
316 * Disable BFA submodules.
317 */
318static void
319bfa_iocfc_disable_submod(struct bfa_s *bfa)
320{
321 int i;
322
323 for (i = 0; hal_mods[i]; i++)
324 hal_mods[i]->iocdisable(bfa);
325}
326
327static void
328bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
329{
330 struct bfa_s *bfa = bfa_arg;
331
332 if (complete) {
333 if (bfa->iocfc.cfgdone)
334 bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
335 else
336 bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800337 } else {
338 if (bfa->iocfc.cfgdone)
339 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
340 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700341}
342
343static void
344bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
345{
346 struct bfa_s *bfa = bfa_arg;
347 struct bfad_s *bfad = bfa->bfad;
348
349 if (compl)
350 complete(&bfad->comp);
351
352 else
353 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
354}
355
356static void
357bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
358{
359 struct bfa_s *bfa = bfa_arg;
360 struct bfad_s *bfad = bfa->bfad;
361
362 if (compl)
363 complete(&bfad->disable_comp);
364}
365
366/**
367 * Update BFA configuration from firmware configuration.
368 */
369static void
370bfa_iocfc_cfgrsp(struct bfa_s *bfa)
371{
372 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
373 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
374 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
Jing Huang7725ccf2009-09-23 17:46:15 -0700375
376 fwcfg->num_cqs = fwcfg->num_cqs;
377 fwcfg->num_ioim_reqs = bfa_os_ntohs(fwcfg->num_ioim_reqs);
378 fwcfg->num_tskim_reqs = bfa_os_ntohs(fwcfg->num_tskim_reqs);
379 fwcfg->num_fcxp_reqs = bfa_os_ntohs(fwcfg->num_fcxp_reqs);
380 fwcfg->num_uf_bufs = bfa_os_ntohs(fwcfg->num_uf_bufs);
381 fwcfg->num_rports = bfa_os_ntohs(fwcfg->num_rports);
382
Jing Huang7725ccf2009-09-23 17:46:15 -0700383 iocfc->cfgdone = BFA_TRUE;
384
385 /**
386 * Configuration is complete - initialize/start submodules
387 */
Jing Huanged969322010-07-08 19:45:56 -0700388 bfa_fcport_init(bfa);
389
Jing Huang7725ccf2009-09-23 17:46:15 -0700390 if (iocfc->action == BFA_IOCFC_ACT_INIT)
391 bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
392 else
393 bfa_iocfc_start_submod(bfa);
394}
395
396static void
397bfa_iocfc_stats_clear(void *bfa_arg)
398{
399 struct bfa_s *bfa = bfa_arg;
400 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
401 struct bfi_iocfc_stats_req_s stats_req;
402
403 bfa_timer_start(bfa, &iocfc->stats_timer,
404 bfa_iocfc_stats_clr_timeout, bfa,
405 BFA_IOCFC_TOV);
406
407 bfi_h2i_set(stats_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CLEAR_STATS_REQ,
408 bfa_lpuid(bfa));
409 bfa_ioc_mbox_send(&bfa->ioc, &stats_req,
410 sizeof(struct bfi_iocfc_stats_req_s));
411}
412
413static void
414bfa_iocfc_stats_swap(struct bfa_fw_stats_s *d, struct bfa_fw_stats_s *s)
415{
416 u32 *dip = (u32 *) d;
417 u32 *sip = (u32 *) s;
418 int i;
419
420 for (i = 0; i < (sizeof(struct bfa_fw_stats_s) / sizeof(u32)); i++)
421 dip[i] = bfa_os_ntohl(sip[i]);
422}
423
424static void
425bfa_iocfc_stats_clr_cb(void *bfa_arg, bfa_boolean_t complete)
426{
427 struct bfa_s *bfa = bfa_arg;
428 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
429
430 if (complete) {
431 bfa_ioc_clr_stats(&bfa->ioc);
432 iocfc->stats_cbfn(iocfc->stats_cbarg, iocfc->stats_status);
433 } else {
434 iocfc->stats_busy = BFA_FALSE;
435 iocfc->stats_status = BFA_STATUS_OK;
436 }
437}
438
439static void
440bfa_iocfc_stats_clr_timeout(void *bfa_arg)
441{
442 struct bfa_s *bfa = bfa_arg;
443 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
444
445 bfa_trc(bfa, 0);
446
447 iocfc->stats_status = BFA_STATUS_ETIMER;
448 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe, bfa_iocfc_stats_clr_cb, bfa);
449}
450
451static void
452bfa_iocfc_stats_cb(void *bfa_arg, bfa_boolean_t complete)
453{
454 struct bfa_s *bfa = bfa_arg;
455 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
456
457 if (complete) {
458 if (iocfc->stats_status == BFA_STATUS_OK) {
459 bfa_os_memset(iocfc->stats_ret, 0,
460 sizeof(*iocfc->stats_ret));
461 bfa_iocfc_stats_swap(&iocfc->stats_ret->fw_stats,
462 iocfc->fw_stats);
463 }
464 iocfc->stats_cbfn(iocfc->stats_cbarg, iocfc->stats_status);
465 } else {
466 iocfc->stats_busy = BFA_FALSE;
467 iocfc->stats_status = BFA_STATUS_OK;
468 }
469}
470
471static void
472bfa_iocfc_stats_timeout(void *bfa_arg)
473{
474 struct bfa_s *bfa = bfa_arg;
475 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
476
477 bfa_trc(bfa, 0);
478
479 iocfc->stats_status = BFA_STATUS_ETIMER;
480 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe, bfa_iocfc_stats_cb, bfa);
481}
482
483static void
484bfa_iocfc_stats_query(struct bfa_s *bfa)
485{
486 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
487 struct bfi_iocfc_stats_req_s stats_req;
488
489 bfa_timer_start(bfa, &iocfc->stats_timer,
490 bfa_iocfc_stats_timeout, bfa, BFA_IOCFC_TOV);
491
492 bfi_h2i_set(stats_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_GET_STATS_REQ,
493 bfa_lpuid(bfa));
494 bfa_ioc_mbox_send(&bfa->ioc, &stats_req,
495 sizeof(struct bfi_iocfc_stats_req_s));
496}
497
498void
499bfa_iocfc_reset_queues(struct bfa_s *bfa)
500{
501 int q;
502
503 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
504 bfa_reqq_ci(bfa, q) = 0;
505 bfa_reqq_pi(bfa, q) = 0;
506 bfa_rspq_ci(bfa, q) = 0;
507 bfa_rspq_pi(bfa, q) = 0;
508 }
509}
510
511/**
512 * IOC enable request is complete
513 */
514static void
515bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
516{
517 struct bfa_s *bfa = bfa_arg;
518
519 if (status != BFA_STATUS_OK) {
520 bfa_isr_disable(bfa);
521 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
522 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
523 bfa_iocfc_init_cb, bfa);
524 return;
525 }
526
Jing Huang7725ccf2009-09-23 17:46:15 -0700527 bfa_iocfc_send_cfg(bfa);
528}
529
530/**
531 * IOC disable request is complete
532 */
533static void
534bfa_iocfc_disable_cbfn(void *bfa_arg)
535{
536 struct bfa_s *bfa = bfa_arg;
537
538 bfa_isr_disable(bfa);
539 bfa_iocfc_disable_submod(bfa);
540
541 if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
542 bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
543 bfa);
544 else {
545 bfa_assert(bfa->iocfc.action == BFA_IOCFC_ACT_DISABLE);
546 bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
547 bfa);
548 }
549}
550
551/**
552 * Notify sub-modules of hardware failure.
553 */
554static void
555bfa_iocfc_hbfail_cbfn(void *bfa_arg)
556{
557 struct bfa_s *bfa = bfa_arg;
558
559 bfa->rme_process = BFA_FALSE;
560
561 bfa_isr_disable(bfa);
562 bfa_iocfc_disable_submod(bfa);
563
564 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
565 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
566 bfa);
567}
568
569/**
570 * Actions on chip-reset completion.
571 */
572static void
573bfa_iocfc_reset_cbfn(void *bfa_arg)
574{
575 struct bfa_s *bfa = bfa_arg;
576
577 bfa_iocfc_reset_queues(bfa);
578 bfa_isr_enable(bfa);
579}
580
581
582
583/**
584 * bfa_ioc_public
585 */
586
587/**
588 * Query IOC memory requirement information.
589 */
590void
591bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
592 u32 *dm_len)
593{
594 /* dma memory for IOC */
595 *dm_len += bfa_ioc_meminfo();
596
597 bfa_iocfc_fw_cfg_sz(cfg, dm_len);
598 bfa_iocfc_cqs_sz(cfg, dm_len);
599 *km_len += bfa_ioc_debug_trcsz(bfa_auto_recover);
600}
601
602/**
603 * Query IOC memory requirement information.
604 */
605void
606bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
607 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
608{
609 int i;
610
611 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
612 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
613 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
614 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
615
616 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod,
617 bfa->trcmod, bfa->aen, bfa->logm);
Jing Huang7725ccf2009-09-23 17:46:15 -0700618
619 /**
Jing Huang293f82d2010-07-08 19:45:20 -0700620 * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC.
Jing Huang7725ccf2009-09-23 17:46:15 -0700621 */
Jing Huang293f82d2010-07-08 19:45:20 -0700622 if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC)
Jing Huang7725ccf2009-09-23 17:46:15 -0700623 bfa_ioc_set_fcmode(&bfa->ioc);
624
Krishna Gudipati2f9b8852010-03-03 17:42:51 -0800625 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_MC_IOCFC);
626 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
627
Jing Huang7725ccf2009-09-23 17:46:15 -0700628 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
629 bfa_iocfc_mem_claim(bfa, cfg, meminfo);
630 bfa_timer_init(&bfa->timer_mod);
631
632 INIT_LIST_HEAD(&bfa->comp_q);
633 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
634 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
635}
636
637/**
638 * Query IOC memory requirement information.
639 */
640void
641bfa_iocfc_detach(struct bfa_s *bfa)
642{
643 bfa_ioc_detach(&bfa->ioc);
644}
645
646/**
647 * Query IOC memory requirement information.
648 */
649void
650bfa_iocfc_init(struct bfa_s *bfa)
651{
652 bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
653 bfa_ioc_enable(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700654}
655
656/**
657 * IOC start called from bfa_start(). Called to start IOC operations
658 * at driver instantiation for this instance.
659 */
660void
661bfa_iocfc_start(struct bfa_s *bfa)
662{
663 if (bfa->iocfc.cfgdone)
664 bfa_iocfc_start_submod(bfa);
665}
666
667/**
668 * IOC stop called from bfa_stop(). Called only when driver is unloaded
669 * for this instance.
670 */
671void
672bfa_iocfc_stop(struct bfa_s *bfa)
673{
674 bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
675
676 bfa->rme_process = BFA_FALSE;
677 bfa_ioc_disable(&bfa->ioc);
678}
679
680void
681bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
682{
683 struct bfa_s *bfa = bfaarg;
684 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
685 union bfi_iocfc_i2h_msg_u *msg;
686
687 msg = (union bfi_iocfc_i2h_msg_u *) m;
688 bfa_trc(bfa, msg->mh.msg_id);
689
690 switch (msg->mh.msg_id) {
691 case BFI_IOCFC_I2H_CFG_REPLY:
692 iocfc->cfg_reply = &msg->cfg_reply;
693 bfa_iocfc_cfgrsp(bfa);
694 break;
695
696 case BFI_IOCFC_I2H_GET_STATS_RSP:
697 if (iocfc->stats_busy == BFA_FALSE
698 || iocfc->stats_status == BFA_STATUS_ETIMER)
699 break;
700
701 bfa_timer_stop(&iocfc->stats_timer);
702 iocfc->stats_status = BFA_STATUS_OK;
703 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe, bfa_iocfc_stats_cb,
704 bfa);
705 break;
706 case BFI_IOCFC_I2H_CLEAR_STATS_RSP:
707 /*
708 * check for timer pop before processing the rsp
709 */
710 if (iocfc->stats_busy == BFA_FALSE
711 || iocfc->stats_status == BFA_STATUS_ETIMER)
712 break;
713
714 bfa_timer_stop(&iocfc->stats_timer);
715 iocfc->stats_status = BFA_STATUS_OK;
716 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe,
717 bfa_iocfc_stats_clr_cb, bfa);
718 break;
719 case BFI_IOCFC_I2H_UPDATEQ_RSP:
720 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
721 break;
722 default:
723 bfa_assert(0);
724 }
725}
726
727#ifndef BFA_BIOS_BUILD
728void
729bfa_adapter_get_attr(struct bfa_s *bfa, struct bfa_adapter_attr_s *ad_attr)
730{
731 bfa_ioc_get_adapter_attr(&bfa->ioc, ad_attr);
732}
733
734u64
735bfa_adapter_get_id(struct bfa_s *bfa)
736{
737 return bfa_ioc_get_adid(&bfa->ioc);
738}
739
740void
741bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
742{
Jing Huang7c814652010-07-08 19:50:38 -0700743 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
Jing Huang7725ccf2009-09-23 17:46:15 -0700744
Jing Huang7c814652010-07-08 19:50:38 -0700745 attr->intr_attr.coalesce = iocfc->cfginfo->intr_attr.coalesce;
746
747 attr->intr_attr.delay = iocfc->cfginfo->intr_attr.delay ?
748 bfa_os_ntohs(iocfc->cfginfo->intr_attr.delay) :
749 bfa_os_ntohs(iocfc->cfgrsp->intr_attr.delay);
750
751 attr->intr_attr.latency = iocfc->cfginfo->intr_attr.latency ?
752 bfa_os_ntohs(iocfc->cfginfo->intr_attr.latency) :
753 bfa_os_ntohs(iocfc->cfgrsp->intr_attr.latency);
754
755 attr->config = iocfc->cfg;
756
Jing Huang7725ccf2009-09-23 17:46:15 -0700757}
758
759bfa_status_t
760bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
761{
762 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
763 struct bfi_iocfc_set_intr_req_s *m;
764
Jing Huang7c814652010-07-08 19:50:38 -0700765 iocfc->cfginfo->intr_attr.coalesce = attr->coalesce;
766 iocfc->cfginfo->intr_attr.delay = bfa_os_htons(attr->delay);
767 iocfc->cfginfo->intr_attr.latency = bfa_os_htons(attr->latency);
768
Jing Huang7725ccf2009-09-23 17:46:15 -0700769 if (!bfa_iocfc_is_operational(bfa))
770 return BFA_STATUS_OK;
771
772 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
773 if (!m)
774 return BFA_STATUS_DEVBUSY;
775
776 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
777 bfa_lpuid(bfa));
Jing Huang7c814652010-07-08 19:50:38 -0700778 m->coalesce = iocfc->cfginfo->intr_attr.coalesce;
779 m->delay = iocfc->cfginfo->intr_attr.delay;
780 m->latency = iocfc->cfginfo->intr_attr.latency;
781
Jing Huang7725ccf2009-09-23 17:46:15 -0700782
783 bfa_trc(bfa, attr->delay);
784 bfa_trc(bfa, attr->latency);
785
786 bfa_reqq_produce(bfa, BFA_REQQ_IOC);
787 return BFA_STATUS_OK;
788}
789
790void
791bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa)
792{
793 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
794
795 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
796 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa);
797}
798
799bfa_status_t
800bfa_iocfc_get_stats(struct bfa_s *bfa, struct bfa_iocfc_stats_s *stats,
801 bfa_cb_ioc_t cbfn, void *cbarg)
802{
803 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
804
805 if (iocfc->stats_busy) {
806 bfa_trc(bfa, iocfc->stats_busy);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700807 return BFA_STATUS_DEVBUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700808 }
809
Krishna Gudipati13cc20c2010-03-05 19:37:29 -0800810 if (!bfa_iocfc_is_operational(bfa)) {
811 bfa_trc(bfa, 0);
812 return BFA_STATUS_IOC_NON_OP;
813 }
814
Jing Huang7725ccf2009-09-23 17:46:15 -0700815 iocfc->stats_busy = BFA_TRUE;
816 iocfc->stats_ret = stats;
817 iocfc->stats_cbfn = cbfn;
818 iocfc->stats_cbarg = cbarg;
819
820 bfa_iocfc_stats_query(bfa);
821
Jing Huangf8ceafd2009-09-25 12:29:54 -0700822 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700823}
824
825bfa_status_t
826bfa_iocfc_clear_stats(struct bfa_s *bfa, bfa_cb_ioc_t cbfn, void *cbarg)
827{
828 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
829
830 if (iocfc->stats_busy) {
831 bfa_trc(bfa, iocfc->stats_busy);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700832 return BFA_STATUS_DEVBUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700833 }
834
Krishna Gudipati13cc20c2010-03-05 19:37:29 -0800835 if (!bfa_iocfc_is_operational(bfa)) {
836 bfa_trc(bfa, 0);
837 return BFA_STATUS_IOC_NON_OP;
838 }
839
Jing Huang7725ccf2009-09-23 17:46:15 -0700840 iocfc->stats_busy = BFA_TRUE;
841 iocfc->stats_cbfn = cbfn;
842 iocfc->stats_cbarg = cbarg;
843
844 bfa_iocfc_stats_clear(bfa);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700845 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700846}
847
848/**
849 * Enable IOC after it is disabled.
850 */
851void
852bfa_iocfc_enable(struct bfa_s *bfa)
853{
854 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
855 "IOC Enable");
856 bfa_ioc_enable(&bfa->ioc);
857}
858
859void
860bfa_iocfc_disable(struct bfa_s *bfa)
861{
862 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
863 "IOC Disable");
864 bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
865
866 bfa->rme_process = BFA_FALSE;
867 bfa_ioc_disable(&bfa->ioc);
868}
869
870
871bfa_boolean_t
872bfa_iocfc_is_operational(struct bfa_s *bfa)
873{
874 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
875}
876
877/**
878 * Return boot target port wwns -- read from boot information in flash.
879 */
880void
Jing Huang15b64a82010-07-08 19:48:12 -0700881bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
Jing Huang7725ccf2009-09-23 17:46:15 -0700882{
Jing Huang15b64a82010-07-08 19:48:12 -0700883 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
884 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
885 int i;
886
887 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
888 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
889 *nwwns = cfgrsp->pbc_cfg.nbluns;
890 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
891 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
892
893 return;
894 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700895
896 *nwwns = cfgrsp->bootwwns.nwwns;
Jing Huang15b64a82010-07-08 19:48:12 -0700897 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
Jing Huang7725ccf2009-09-23 17:46:15 -0700898}
899
Jing Huanged969322010-07-08 19:45:56 -0700900void
901bfa_iocfc_get_pbc_boot_cfg(struct bfa_s *bfa, struct bfa_boot_pbc_s *pbcfg)
902{
903 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
904 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
905
906 pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
907 pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
908 pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
909 memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
910}
911
Jing Huangd9883542010-07-08 19:46:26 -0700912int
913bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
914{
915 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
916 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
917
918 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
919 return cfgrsp->pbc_cfg.nvports;
920}
921
922
Jing Huang7725ccf2009-09-23 17:46:15 -0700923#endif
924
925