blob: 6f54bea356c68bfe40999a7a72ad26b12f8f0b62 [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
116 iocfc->cfgdone = BFA_FALSE;
117 bfa_iocfc_reset_queues(bfa);
118
119 /**
120 * initialize IOC configuration info
121 */
122 cfg_info->endian_sig = BFI_IOC_ENDIAN_SIG;
123 cfg_info->num_cqs = cfg->fwcfg.num_cqs;
124
125 bfa_dma_be_addr_set(cfg_info->cfgrsp_addr, iocfc->cfgrsp_dma.pa);
126 bfa_dma_be_addr_set(cfg_info->stats_addr, iocfc->stats_pa);
127
128 /**
129 * dma map REQ and RSP circular queues and shadow pointers
130 */
131 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
132 bfa_dma_be_addr_set(cfg_info->req_cq_ba[i],
133 iocfc->req_cq_ba[i].pa);
134 bfa_dma_be_addr_set(cfg_info->req_shadow_ci[i],
135 iocfc->req_cq_shadow_ci[i].pa);
136 cfg_info->req_cq_elems[i] =
137 bfa_os_htons(cfg->drvcfg.num_reqq_elems);
138
139 bfa_dma_be_addr_set(cfg_info->rsp_cq_ba[i],
140 iocfc->rsp_cq_ba[i].pa);
141 bfa_dma_be_addr_set(cfg_info->rsp_shadow_pi[i],
142 iocfc->rsp_cq_shadow_pi[i].pa);
143 cfg_info->rsp_cq_elems[i] =
144 bfa_os_htons(cfg->drvcfg.num_rspq_elems);
145 }
146
147 /**
148 * dma map IOC configuration itself
149 */
150 bfi_h2i_set(cfg_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CFG_REQ,
151 bfa_lpuid(bfa));
152 bfa_dma_be_addr_set(cfg_req.ioc_cfg_dma_addr, iocfc->cfg_info.pa);
153
154 bfa_ioc_mbox_send(&bfa->ioc, &cfg_req,
155 sizeof(struct bfi_iocfc_cfg_req_s));
156}
157
158static void
159bfa_iocfc_init_mem(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
160 struct bfa_pcidev_s *pcidev)
161{
162 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
163
164 bfa->bfad = bfad;
165 iocfc->bfa = bfa;
166 iocfc->action = BFA_IOCFC_ACT_NONE;
167
168 bfa_os_assign(iocfc->cfg, *cfg);
169
170 /**
171 * Initialize chip specific handlers.
172 */
Jing Huang293f82d2010-07-08 19:45:20 -0700173 if (bfa_asic_id_ct(bfa_ioc_devid(&bfa->ioc))) {
Jing Huang7725ccf2009-09-23 17:46:15 -0700174 iocfc->hwif.hw_reginit = bfa_hwct_reginit;
Krishna Gudipatif5713c52010-03-05 19:37:09 -0800175 iocfc->hwif.hw_reqq_ack = bfa_hwct_reqq_ack;
Jing Huang7725ccf2009-09-23 17:46:15 -0700176 iocfc->hwif.hw_rspq_ack = bfa_hwct_rspq_ack;
177 iocfc->hwif.hw_msix_init = bfa_hwct_msix_init;
178 iocfc->hwif.hw_msix_install = bfa_hwct_msix_install;
179 iocfc->hwif.hw_msix_uninstall = bfa_hwct_msix_uninstall;
180 iocfc->hwif.hw_isr_mode_set = bfa_hwct_isr_mode_set;
181 iocfc->hwif.hw_msix_getvecs = bfa_hwct_msix_getvecs;
182 } else {
183 iocfc->hwif.hw_reginit = bfa_hwcb_reginit;
Krishna Gudipatif5713c52010-03-05 19:37:09 -0800184 iocfc->hwif.hw_reqq_ack = bfa_hwcb_reqq_ack;
Jing Huang7725ccf2009-09-23 17:46:15 -0700185 iocfc->hwif.hw_rspq_ack = bfa_hwcb_rspq_ack;
186 iocfc->hwif.hw_msix_init = bfa_hwcb_msix_init;
187 iocfc->hwif.hw_msix_install = bfa_hwcb_msix_install;
188 iocfc->hwif.hw_msix_uninstall = bfa_hwcb_msix_uninstall;
189 iocfc->hwif.hw_isr_mode_set = bfa_hwcb_isr_mode_set;
190 iocfc->hwif.hw_msix_getvecs = bfa_hwcb_msix_getvecs;
191 }
192
193 iocfc->hwif.hw_reginit(bfa);
194 bfa->msix.nvecs = 0;
195}
196
197static void
198bfa_iocfc_mem_claim(struct bfa_s *bfa, struct bfa_iocfc_cfg_s *cfg,
199 struct bfa_meminfo_s *meminfo)
200{
201 u8 *dm_kva;
202 u64 dm_pa;
203 int i, per_reqq_sz, per_rspq_sz;
204 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
205 int dbgsz;
206
207 dm_kva = bfa_meminfo_dma_virt(meminfo);
208 dm_pa = bfa_meminfo_dma_phys(meminfo);
209
210 /*
211 * First allocate dma memory for IOC.
212 */
213 bfa_ioc_mem_claim(&bfa->ioc, dm_kva, dm_pa);
214 dm_kva += bfa_ioc_meminfo();
215 dm_pa += bfa_ioc_meminfo();
216
217 /*
218 * Claim DMA-able memory for the request/response queues and for shadow
219 * ci/pi registers
220 */
221 per_reqq_sz = BFA_ROUNDUP((cfg->drvcfg.num_reqq_elems * BFI_LMSG_SZ),
222 BFA_DMA_ALIGN_SZ);
223 per_rspq_sz = BFA_ROUNDUP((cfg->drvcfg.num_rspq_elems * BFI_LMSG_SZ),
224 BFA_DMA_ALIGN_SZ);
225
226 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
227 iocfc->req_cq_ba[i].kva = dm_kva;
228 iocfc->req_cq_ba[i].pa = dm_pa;
229 bfa_os_memset(dm_kva, 0, per_reqq_sz);
230 dm_kva += per_reqq_sz;
231 dm_pa += per_reqq_sz;
232
233 iocfc->rsp_cq_ba[i].kva = dm_kva;
234 iocfc->rsp_cq_ba[i].pa = dm_pa;
235 bfa_os_memset(dm_kva, 0, per_rspq_sz);
236 dm_kva += per_rspq_sz;
237 dm_pa += per_rspq_sz;
238 }
239
240 for (i = 0; i < cfg->fwcfg.num_cqs; i++) {
241 iocfc->req_cq_shadow_ci[i].kva = dm_kva;
242 iocfc->req_cq_shadow_ci[i].pa = dm_pa;
243 dm_kva += BFA_CACHELINE_SZ;
244 dm_pa += BFA_CACHELINE_SZ;
245
246 iocfc->rsp_cq_shadow_pi[i].kva = dm_kva;
247 iocfc->rsp_cq_shadow_pi[i].pa = dm_pa;
248 dm_kva += BFA_CACHELINE_SZ;
249 dm_pa += BFA_CACHELINE_SZ;
250 }
251
252 /*
253 * Claim DMA-able memory for the config info page
254 */
255 bfa->iocfc.cfg_info.kva = dm_kva;
256 bfa->iocfc.cfg_info.pa = dm_pa;
257 bfa->iocfc.cfginfo = (struct bfi_iocfc_cfg_s *) dm_kva;
258 dm_kva += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
259 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfg_s), BFA_CACHELINE_SZ);
260
261 /*
262 * Claim DMA-able memory for the config response
263 */
264 bfa->iocfc.cfgrsp_dma.kva = dm_kva;
265 bfa->iocfc.cfgrsp_dma.pa = dm_pa;
266 bfa->iocfc.cfgrsp = (struct bfi_iocfc_cfgrsp_s *) dm_kva;
267
268 dm_kva +=
269 BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
270 BFA_CACHELINE_SZ);
271 dm_pa += BFA_ROUNDUP(sizeof(struct bfi_iocfc_cfgrsp_s),
272 BFA_CACHELINE_SZ);
273
274 /*
275 * Claim DMA-able memory for iocfc stats
276 */
277 bfa->iocfc.stats_kva = dm_kva;
278 bfa->iocfc.stats_pa = dm_pa;
279 bfa->iocfc.fw_stats = (struct bfa_fw_stats_s *) dm_kva;
280 dm_kva += BFA_ROUNDUP(sizeof(struct bfa_fw_stats_s), BFA_CACHELINE_SZ);
281 dm_pa += BFA_ROUNDUP(sizeof(struct bfa_fw_stats_s), BFA_CACHELINE_SZ);
282
283 bfa_meminfo_dma_virt(meminfo) = dm_kva;
284 bfa_meminfo_dma_phys(meminfo) = dm_pa;
285
286 dbgsz = bfa_ioc_debug_trcsz(bfa_auto_recover);
287 if (dbgsz > 0) {
288 bfa_ioc_debug_memclaim(&bfa->ioc, bfa_meminfo_kva(meminfo));
289 bfa_meminfo_kva(meminfo) += dbgsz;
290 }
291}
292
293/**
Jing Huang7725ccf2009-09-23 17:46:15 -0700294 * Start BFA submodules.
295 */
296static void
297bfa_iocfc_start_submod(struct bfa_s *bfa)
298{
299 int i;
300
301 bfa->rme_process = BFA_TRUE;
302
303 for (i = 0; hal_mods[i]; i++)
304 hal_mods[i]->start(bfa);
305}
306
307/**
308 * Disable BFA submodules.
309 */
310static void
311bfa_iocfc_disable_submod(struct bfa_s *bfa)
312{
313 int i;
314
315 for (i = 0; hal_mods[i]; i++)
316 hal_mods[i]->iocdisable(bfa);
317}
318
319static void
320bfa_iocfc_init_cb(void *bfa_arg, bfa_boolean_t complete)
321{
322 struct bfa_s *bfa = bfa_arg;
323
324 if (complete) {
325 if (bfa->iocfc.cfgdone)
326 bfa_cb_init(bfa->bfad, BFA_STATUS_OK);
327 else
328 bfa_cb_init(bfa->bfad, BFA_STATUS_FAILED);
Krishna Gudipatie6714322010-03-03 17:44:02 -0800329 } else {
330 if (bfa->iocfc.cfgdone)
331 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
332 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700333}
334
335static void
336bfa_iocfc_stop_cb(void *bfa_arg, bfa_boolean_t compl)
337{
338 struct bfa_s *bfa = bfa_arg;
339 struct bfad_s *bfad = bfa->bfad;
340
341 if (compl)
342 complete(&bfad->comp);
343
344 else
345 bfa->iocfc.action = BFA_IOCFC_ACT_NONE;
346}
347
348static void
349bfa_iocfc_disable_cb(void *bfa_arg, bfa_boolean_t compl)
350{
351 struct bfa_s *bfa = bfa_arg;
352 struct bfad_s *bfad = bfa->bfad;
353
354 if (compl)
355 complete(&bfad->disable_comp);
356}
357
358/**
359 * Update BFA configuration from firmware configuration.
360 */
361static void
362bfa_iocfc_cfgrsp(struct bfa_s *bfa)
363{
364 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
365 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
366 struct bfa_iocfc_fwcfg_s *fwcfg = &cfgrsp->fwcfg;
367 struct bfi_iocfc_cfg_s *cfginfo = iocfc->cfginfo;
368
369 fwcfg->num_cqs = fwcfg->num_cqs;
370 fwcfg->num_ioim_reqs = bfa_os_ntohs(fwcfg->num_ioim_reqs);
371 fwcfg->num_tskim_reqs = bfa_os_ntohs(fwcfg->num_tskim_reqs);
372 fwcfg->num_fcxp_reqs = bfa_os_ntohs(fwcfg->num_fcxp_reqs);
373 fwcfg->num_uf_bufs = bfa_os_ntohs(fwcfg->num_uf_bufs);
374 fwcfg->num_rports = bfa_os_ntohs(fwcfg->num_rports);
375
376 cfginfo->intr_attr.coalesce = cfgrsp->intr_attr.coalesce;
377 cfginfo->intr_attr.delay = bfa_os_ntohs(cfgrsp->intr_attr.delay);
378 cfginfo->intr_attr.latency = bfa_os_ntohs(cfgrsp->intr_attr.latency);
379
380 iocfc->cfgdone = BFA_TRUE;
381
382 /**
383 * Configuration is complete - initialize/start submodules
384 */
Jing Huanged969322010-07-08 19:45:56 -0700385 bfa_fcport_init(bfa);
386
Jing Huang7725ccf2009-09-23 17:46:15 -0700387 if (iocfc->action == BFA_IOCFC_ACT_INIT)
388 bfa_cb_queue(bfa, &iocfc->init_hcb_qe, bfa_iocfc_init_cb, bfa);
389 else
390 bfa_iocfc_start_submod(bfa);
391}
392
393static void
394bfa_iocfc_stats_clear(void *bfa_arg)
395{
396 struct bfa_s *bfa = bfa_arg;
397 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
398 struct bfi_iocfc_stats_req_s stats_req;
399
400 bfa_timer_start(bfa, &iocfc->stats_timer,
401 bfa_iocfc_stats_clr_timeout, bfa,
402 BFA_IOCFC_TOV);
403
404 bfi_h2i_set(stats_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_CLEAR_STATS_REQ,
405 bfa_lpuid(bfa));
406 bfa_ioc_mbox_send(&bfa->ioc, &stats_req,
407 sizeof(struct bfi_iocfc_stats_req_s));
408}
409
410static void
411bfa_iocfc_stats_swap(struct bfa_fw_stats_s *d, struct bfa_fw_stats_s *s)
412{
413 u32 *dip = (u32 *) d;
414 u32 *sip = (u32 *) s;
415 int i;
416
417 for (i = 0; i < (sizeof(struct bfa_fw_stats_s) / sizeof(u32)); i++)
418 dip[i] = bfa_os_ntohl(sip[i]);
419}
420
421static void
422bfa_iocfc_stats_clr_cb(void *bfa_arg, bfa_boolean_t complete)
423{
424 struct bfa_s *bfa = bfa_arg;
425 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
426
427 if (complete) {
428 bfa_ioc_clr_stats(&bfa->ioc);
429 iocfc->stats_cbfn(iocfc->stats_cbarg, iocfc->stats_status);
430 } else {
431 iocfc->stats_busy = BFA_FALSE;
432 iocfc->stats_status = BFA_STATUS_OK;
433 }
434}
435
436static void
437bfa_iocfc_stats_clr_timeout(void *bfa_arg)
438{
439 struct bfa_s *bfa = bfa_arg;
440 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
441
442 bfa_trc(bfa, 0);
443
444 iocfc->stats_status = BFA_STATUS_ETIMER;
445 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe, bfa_iocfc_stats_clr_cb, bfa);
446}
447
448static void
449bfa_iocfc_stats_cb(void *bfa_arg, bfa_boolean_t complete)
450{
451 struct bfa_s *bfa = bfa_arg;
452 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
453
454 if (complete) {
455 if (iocfc->stats_status == BFA_STATUS_OK) {
456 bfa_os_memset(iocfc->stats_ret, 0,
457 sizeof(*iocfc->stats_ret));
458 bfa_iocfc_stats_swap(&iocfc->stats_ret->fw_stats,
459 iocfc->fw_stats);
460 }
461 iocfc->stats_cbfn(iocfc->stats_cbarg, iocfc->stats_status);
462 } else {
463 iocfc->stats_busy = BFA_FALSE;
464 iocfc->stats_status = BFA_STATUS_OK;
465 }
466}
467
468static void
469bfa_iocfc_stats_timeout(void *bfa_arg)
470{
471 struct bfa_s *bfa = bfa_arg;
472 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
473
474 bfa_trc(bfa, 0);
475
476 iocfc->stats_status = BFA_STATUS_ETIMER;
477 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe, bfa_iocfc_stats_cb, bfa);
478}
479
480static void
481bfa_iocfc_stats_query(struct bfa_s *bfa)
482{
483 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
484 struct bfi_iocfc_stats_req_s stats_req;
485
486 bfa_timer_start(bfa, &iocfc->stats_timer,
487 bfa_iocfc_stats_timeout, bfa, BFA_IOCFC_TOV);
488
489 bfi_h2i_set(stats_req.mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_GET_STATS_REQ,
490 bfa_lpuid(bfa));
491 bfa_ioc_mbox_send(&bfa->ioc, &stats_req,
492 sizeof(struct bfi_iocfc_stats_req_s));
493}
494
495void
496bfa_iocfc_reset_queues(struct bfa_s *bfa)
497{
498 int q;
499
500 for (q = 0; q < BFI_IOC_MAX_CQS; q++) {
501 bfa_reqq_ci(bfa, q) = 0;
502 bfa_reqq_pi(bfa, q) = 0;
503 bfa_rspq_ci(bfa, q) = 0;
504 bfa_rspq_pi(bfa, q) = 0;
505 }
506}
507
508/**
509 * IOC enable request is complete
510 */
511static void
512bfa_iocfc_enable_cbfn(void *bfa_arg, enum bfa_status status)
513{
514 struct bfa_s *bfa = bfa_arg;
515
516 if (status != BFA_STATUS_OK) {
517 bfa_isr_disable(bfa);
518 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
519 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe,
520 bfa_iocfc_init_cb, bfa);
521 return;
522 }
523
Jing Huang7725ccf2009-09-23 17:46:15 -0700524 bfa_iocfc_send_cfg(bfa);
525}
526
527/**
528 * IOC disable request is complete
529 */
530static void
531bfa_iocfc_disable_cbfn(void *bfa_arg)
532{
533 struct bfa_s *bfa = bfa_arg;
534
535 bfa_isr_disable(bfa);
536 bfa_iocfc_disable_submod(bfa);
537
538 if (bfa->iocfc.action == BFA_IOCFC_ACT_STOP)
539 bfa_cb_queue(bfa, &bfa->iocfc.stop_hcb_qe, bfa_iocfc_stop_cb,
540 bfa);
541 else {
542 bfa_assert(bfa->iocfc.action == BFA_IOCFC_ACT_DISABLE);
543 bfa_cb_queue(bfa, &bfa->iocfc.dis_hcb_qe, bfa_iocfc_disable_cb,
544 bfa);
545 }
546}
547
548/**
549 * Notify sub-modules of hardware failure.
550 */
551static void
552bfa_iocfc_hbfail_cbfn(void *bfa_arg)
553{
554 struct bfa_s *bfa = bfa_arg;
555
556 bfa->rme_process = BFA_FALSE;
557
558 bfa_isr_disable(bfa);
559 bfa_iocfc_disable_submod(bfa);
560
561 if (bfa->iocfc.action == BFA_IOCFC_ACT_INIT)
562 bfa_cb_queue(bfa, &bfa->iocfc.init_hcb_qe, bfa_iocfc_init_cb,
563 bfa);
564}
565
566/**
567 * Actions on chip-reset completion.
568 */
569static void
570bfa_iocfc_reset_cbfn(void *bfa_arg)
571{
572 struct bfa_s *bfa = bfa_arg;
573
574 bfa_iocfc_reset_queues(bfa);
575 bfa_isr_enable(bfa);
576}
577
578
579
580/**
581 * bfa_ioc_public
582 */
583
584/**
585 * Query IOC memory requirement information.
586 */
587void
588bfa_iocfc_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len,
589 u32 *dm_len)
590{
591 /* dma memory for IOC */
592 *dm_len += bfa_ioc_meminfo();
593
594 bfa_iocfc_fw_cfg_sz(cfg, dm_len);
595 bfa_iocfc_cqs_sz(cfg, dm_len);
596 *km_len += bfa_ioc_debug_trcsz(bfa_auto_recover);
597}
598
599/**
600 * Query IOC memory requirement information.
601 */
602void
603bfa_iocfc_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
604 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
605{
606 int i;
607
608 bfa_iocfc_cbfn.enable_cbfn = bfa_iocfc_enable_cbfn;
609 bfa_iocfc_cbfn.disable_cbfn = bfa_iocfc_disable_cbfn;
610 bfa_iocfc_cbfn.hbfail_cbfn = bfa_iocfc_hbfail_cbfn;
611 bfa_iocfc_cbfn.reset_cbfn = bfa_iocfc_reset_cbfn;
612
613 bfa_ioc_attach(&bfa->ioc, bfa, &bfa_iocfc_cbfn, &bfa->timer_mod,
614 bfa->trcmod, bfa->aen, bfa->logm);
Jing Huang7725ccf2009-09-23 17:46:15 -0700615
616 /**
Jing Huang293f82d2010-07-08 19:45:20 -0700617 * Set FC mode for BFA_PCI_DEVICE_ID_CT_FC.
Jing Huang7725ccf2009-09-23 17:46:15 -0700618 */
Jing Huang293f82d2010-07-08 19:45:20 -0700619 if (pcidev->device_id == BFA_PCI_DEVICE_ID_CT_FC)
Jing Huang7725ccf2009-09-23 17:46:15 -0700620 bfa_ioc_set_fcmode(&bfa->ioc);
621
Krishna Gudipati2f9b8852010-03-03 17:42:51 -0800622 bfa_ioc_pci_init(&bfa->ioc, pcidev, BFI_MC_IOCFC);
623 bfa_ioc_mbox_register(&bfa->ioc, bfa_mbox_isrs);
624
Jing Huang7725ccf2009-09-23 17:46:15 -0700625 bfa_iocfc_init_mem(bfa, bfad, cfg, pcidev);
626 bfa_iocfc_mem_claim(bfa, cfg, meminfo);
627 bfa_timer_init(&bfa->timer_mod);
628
629 INIT_LIST_HEAD(&bfa->comp_q);
630 for (i = 0; i < BFI_IOC_MAX_CQS; i++)
631 INIT_LIST_HEAD(&bfa->reqq_waitq[i]);
632}
633
634/**
635 * Query IOC memory requirement information.
636 */
637void
638bfa_iocfc_detach(struct bfa_s *bfa)
639{
640 bfa_ioc_detach(&bfa->ioc);
641}
642
643/**
644 * Query IOC memory requirement information.
645 */
646void
647bfa_iocfc_init(struct bfa_s *bfa)
648{
649 bfa->iocfc.action = BFA_IOCFC_ACT_INIT;
650 bfa_ioc_enable(&bfa->ioc);
Jing Huang7725ccf2009-09-23 17:46:15 -0700651}
652
653/**
654 * IOC start called from bfa_start(). Called to start IOC operations
655 * at driver instantiation for this instance.
656 */
657void
658bfa_iocfc_start(struct bfa_s *bfa)
659{
660 if (bfa->iocfc.cfgdone)
661 bfa_iocfc_start_submod(bfa);
662}
663
664/**
665 * IOC stop called from bfa_stop(). Called only when driver is unloaded
666 * for this instance.
667 */
668void
669bfa_iocfc_stop(struct bfa_s *bfa)
670{
671 bfa->iocfc.action = BFA_IOCFC_ACT_STOP;
672
673 bfa->rme_process = BFA_FALSE;
674 bfa_ioc_disable(&bfa->ioc);
675}
676
677void
678bfa_iocfc_isr(void *bfaarg, struct bfi_mbmsg_s *m)
679{
680 struct bfa_s *bfa = bfaarg;
681 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
682 union bfi_iocfc_i2h_msg_u *msg;
683
684 msg = (union bfi_iocfc_i2h_msg_u *) m;
685 bfa_trc(bfa, msg->mh.msg_id);
686
687 switch (msg->mh.msg_id) {
688 case BFI_IOCFC_I2H_CFG_REPLY:
689 iocfc->cfg_reply = &msg->cfg_reply;
690 bfa_iocfc_cfgrsp(bfa);
691 break;
692
693 case BFI_IOCFC_I2H_GET_STATS_RSP:
694 if (iocfc->stats_busy == BFA_FALSE
695 || iocfc->stats_status == BFA_STATUS_ETIMER)
696 break;
697
698 bfa_timer_stop(&iocfc->stats_timer);
699 iocfc->stats_status = BFA_STATUS_OK;
700 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe, bfa_iocfc_stats_cb,
701 bfa);
702 break;
703 case BFI_IOCFC_I2H_CLEAR_STATS_RSP:
704 /*
705 * check for timer pop before processing the rsp
706 */
707 if (iocfc->stats_busy == BFA_FALSE
708 || iocfc->stats_status == BFA_STATUS_ETIMER)
709 break;
710
711 bfa_timer_stop(&iocfc->stats_timer);
712 iocfc->stats_status = BFA_STATUS_OK;
713 bfa_cb_queue(bfa, &iocfc->stats_hcb_qe,
714 bfa_iocfc_stats_clr_cb, bfa);
715 break;
716 case BFI_IOCFC_I2H_UPDATEQ_RSP:
717 iocfc->updateq_cbfn(iocfc->updateq_cbarg, BFA_STATUS_OK);
718 break;
719 default:
720 bfa_assert(0);
721 }
722}
723
724#ifndef BFA_BIOS_BUILD
725void
726bfa_adapter_get_attr(struct bfa_s *bfa, struct bfa_adapter_attr_s *ad_attr)
727{
728 bfa_ioc_get_adapter_attr(&bfa->ioc, ad_attr);
729}
730
731u64
732bfa_adapter_get_id(struct bfa_s *bfa)
733{
734 return bfa_ioc_get_adid(&bfa->ioc);
735}
736
737void
738bfa_iocfc_get_attr(struct bfa_s *bfa, struct bfa_iocfc_attr_s *attr)
739{
740 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
741
742 attr->intr_attr = iocfc->cfginfo->intr_attr;
743 attr->config = iocfc->cfg;
744}
745
746bfa_status_t
747bfa_iocfc_israttr_set(struct bfa_s *bfa, struct bfa_iocfc_intr_attr_s *attr)
748{
749 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
750 struct bfi_iocfc_set_intr_req_s *m;
751
752 iocfc->cfginfo->intr_attr = *attr;
753 if (!bfa_iocfc_is_operational(bfa))
754 return BFA_STATUS_OK;
755
756 m = bfa_reqq_next(bfa, BFA_REQQ_IOC);
757 if (!m)
758 return BFA_STATUS_DEVBUSY;
759
760 bfi_h2i_set(m->mh, BFI_MC_IOCFC, BFI_IOCFC_H2I_SET_INTR_REQ,
761 bfa_lpuid(bfa));
762 m->coalesce = attr->coalesce;
763 m->delay = bfa_os_htons(attr->delay);
764 m->latency = bfa_os_htons(attr->latency);
765
766 bfa_trc(bfa, attr->delay);
767 bfa_trc(bfa, attr->latency);
768
769 bfa_reqq_produce(bfa, BFA_REQQ_IOC);
770 return BFA_STATUS_OK;
771}
772
773void
774bfa_iocfc_set_snsbase(struct bfa_s *bfa, u64 snsbase_pa)
775{
776 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
777
778 iocfc->cfginfo->sense_buf_len = (BFI_IOIM_SNSLEN - 1);
779 bfa_dma_be_addr_set(iocfc->cfginfo->ioim_snsbase, snsbase_pa);
780}
781
782bfa_status_t
783bfa_iocfc_get_stats(struct bfa_s *bfa, struct bfa_iocfc_stats_s *stats,
784 bfa_cb_ioc_t cbfn, void *cbarg)
785{
786 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
787
788 if (iocfc->stats_busy) {
789 bfa_trc(bfa, iocfc->stats_busy);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700790 return BFA_STATUS_DEVBUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700791 }
792
Krishna Gudipati13cc20c2010-03-05 19:37:29 -0800793 if (!bfa_iocfc_is_operational(bfa)) {
794 bfa_trc(bfa, 0);
795 return BFA_STATUS_IOC_NON_OP;
796 }
797
Jing Huang7725ccf2009-09-23 17:46:15 -0700798 iocfc->stats_busy = BFA_TRUE;
799 iocfc->stats_ret = stats;
800 iocfc->stats_cbfn = cbfn;
801 iocfc->stats_cbarg = cbarg;
802
803 bfa_iocfc_stats_query(bfa);
804
Jing Huangf8ceafd2009-09-25 12:29:54 -0700805 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700806}
807
808bfa_status_t
809bfa_iocfc_clear_stats(struct bfa_s *bfa, bfa_cb_ioc_t cbfn, void *cbarg)
810{
811 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
812
813 if (iocfc->stats_busy) {
814 bfa_trc(bfa, iocfc->stats_busy);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700815 return BFA_STATUS_DEVBUSY;
Jing Huang7725ccf2009-09-23 17:46:15 -0700816 }
817
Krishna Gudipati13cc20c2010-03-05 19:37:29 -0800818 if (!bfa_iocfc_is_operational(bfa)) {
819 bfa_trc(bfa, 0);
820 return BFA_STATUS_IOC_NON_OP;
821 }
822
Jing Huang7725ccf2009-09-23 17:46:15 -0700823 iocfc->stats_busy = BFA_TRUE;
824 iocfc->stats_cbfn = cbfn;
825 iocfc->stats_cbarg = cbarg;
826
827 bfa_iocfc_stats_clear(bfa);
Jing Huangf8ceafd2009-09-25 12:29:54 -0700828 return BFA_STATUS_OK;
Jing Huang7725ccf2009-09-23 17:46:15 -0700829}
830
831/**
832 * Enable IOC after it is disabled.
833 */
834void
835bfa_iocfc_enable(struct bfa_s *bfa)
836{
837 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
838 "IOC Enable");
839 bfa_ioc_enable(&bfa->ioc);
840}
841
842void
843bfa_iocfc_disable(struct bfa_s *bfa)
844{
845 bfa_plog_str(bfa->plog, BFA_PL_MID_HAL, BFA_PL_EID_MISC, 0,
846 "IOC Disable");
847 bfa->iocfc.action = BFA_IOCFC_ACT_DISABLE;
848
849 bfa->rme_process = BFA_FALSE;
850 bfa_ioc_disable(&bfa->ioc);
851}
852
853
854bfa_boolean_t
855bfa_iocfc_is_operational(struct bfa_s *bfa)
856{
857 return bfa_ioc_is_operational(&bfa->ioc) && bfa->iocfc.cfgdone;
858}
859
860/**
861 * Return boot target port wwns -- read from boot information in flash.
862 */
863void
Jing Huang15b64a82010-07-08 19:48:12 -0700864bfa_iocfc_get_bootwwns(struct bfa_s *bfa, u8 *nwwns, wwn_t *wwns)
Jing Huang7725ccf2009-09-23 17:46:15 -0700865{
Jing Huang15b64a82010-07-08 19:48:12 -0700866 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
867 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
868 int i;
869
870 if (cfgrsp->pbc_cfg.boot_enabled && cfgrsp->pbc_cfg.nbluns) {
871 bfa_trc(bfa, cfgrsp->pbc_cfg.nbluns);
872 *nwwns = cfgrsp->pbc_cfg.nbluns;
873 for (i = 0; i < cfgrsp->pbc_cfg.nbluns; i++)
874 wwns[i] = cfgrsp->pbc_cfg.blun[i].tgt_pwwn;
875
876 return;
877 }
Jing Huang7725ccf2009-09-23 17:46:15 -0700878
879 *nwwns = cfgrsp->bootwwns.nwwns;
Jing Huang15b64a82010-07-08 19:48:12 -0700880 memcpy(wwns, cfgrsp->bootwwns.wwn, sizeof(cfgrsp->bootwwns.wwn));
Jing Huang7725ccf2009-09-23 17:46:15 -0700881}
882
Jing Huanged969322010-07-08 19:45:56 -0700883void
884bfa_iocfc_get_pbc_boot_cfg(struct bfa_s *bfa, struct bfa_boot_pbc_s *pbcfg)
885{
886 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
887 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
888
889 pbcfg->enable = cfgrsp->pbc_cfg.boot_enabled;
890 pbcfg->nbluns = cfgrsp->pbc_cfg.nbluns;
891 pbcfg->speed = cfgrsp->pbc_cfg.port_speed;
892 memcpy(pbcfg->pblun, cfgrsp->pbc_cfg.blun, sizeof(pbcfg->pblun));
893}
894
Jing Huangd9883542010-07-08 19:46:26 -0700895int
896bfa_iocfc_get_pbc_vports(struct bfa_s *bfa, struct bfi_pbc_vport_s *pbc_vport)
897{
898 struct bfa_iocfc_s *iocfc = &bfa->iocfc;
899 struct bfi_iocfc_cfgrsp_s *cfgrsp = iocfc->cfgrsp;
900
901 memcpy(pbc_vport, cfgrsp->pbc_cfg.vport, sizeof(cfgrsp->pbc_cfg.vport));
902 return cfgrsp->pbc_cfg.nvports;
903}
904
905
Jing Huang7725ccf2009-09-23 17:46:15 -0700906#endif
907
908