GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / scsi / bfa / bfa_core.c
blob76fa5c5b40dde33f6700e0a66b2d0cde846c8088
1 /*
2 * Copyright (c) 2005-2009 Brocade Communications Systems, Inc.
3 * All rights reserved
4 * www.brocade.com
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.h>
19 #include <defs/bfa_defs_pci.h>
20 #include <cs/bfa_debug.h>
21 #include <bfa_iocfc.h>
23 #define DEF_CFG_NUM_FABRICS 1
24 #define DEF_CFG_NUM_LPORTS 256
25 #define DEF_CFG_NUM_CQS 4
26 #define DEF_CFG_NUM_IOIM_REQS (BFA_IOIM_MAX)
27 #define DEF_CFG_NUM_TSKIM_REQS 128
28 #define DEF_CFG_NUM_FCXP_REQS 64
29 #define DEF_CFG_NUM_UF_BUFS 64
30 #define DEF_CFG_NUM_RPORTS 1024
31 #define DEF_CFG_NUM_ITNIMS (DEF_CFG_NUM_RPORTS)
32 #define DEF_CFG_NUM_TINS 256
34 #define DEF_CFG_NUM_SGPGS 2048
35 #define DEF_CFG_NUM_REQQ_ELEMS 256
36 #define DEF_CFG_NUM_RSPQ_ELEMS 64
37 #define DEF_CFG_NUM_SBOOT_TGTS 16
38 #define DEF_CFG_NUM_SBOOT_LUNS 16
40 /**
41 * Use this function query the memory requirement of the BFA library.
42 * This function needs to be called before bfa_attach() to get the
43 * memory required of the BFA layer for a given driver configuration.
45 * This call will fail, if the cap is out of range compared to pre-defined
46 * values within the BFA library
48 * @param[in] cfg - pointer to bfa_ioc_cfg_t. Driver layer should indicate
49 * its configuration in this structure.
50 * The default values for struct bfa_iocfc_cfg_s can be
51 * fetched using bfa_cfg_get_default() API.
53 * If cap's boundary check fails, the library will use
54 * the default bfa_cap_t values (and log a warning msg).
56 * @param[out] meminfo - pointer to bfa_meminfo_t. This content
57 * indicates the memory type (see bfa_mem_type_t) and
58 * amount of memory required.
60 * Driver should allocate the memory, populate the
61 * starting address for each block and provide the same
62 * structure as input parameter to bfa_attach() call.
64 * @return void
66 * Special Considerations: @note
68 void
69 bfa_cfg_get_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *meminfo)
71 int i;
72 u32 km_len = 0, dm_len = 0;
74 bfa_assert((cfg != NULL) && (meminfo != NULL));
76 bfa_os_memset((void *)meminfo, 0, sizeof(struct bfa_meminfo_s));
77 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_type =
78 BFA_MEM_TYPE_KVA;
79 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_type =
80 BFA_MEM_TYPE_DMA;
82 bfa_iocfc_meminfo(cfg, &km_len, &dm_len);
84 for (i = 0; hal_mods[i]; i++)
85 hal_mods[i]->meminfo(cfg, &km_len, &dm_len);
87 dm_len += bfa_port_meminfo();
89 meminfo->meminfo[BFA_MEM_TYPE_KVA - 1].mem_len = km_len;
90 meminfo->meminfo[BFA_MEM_TYPE_DMA - 1].mem_len = dm_len;
93 static void
94 bfa_com_port_attach(struct bfa_s *bfa, struct bfa_meminfo_s *mi)
96 struct bfa_port_s *port = &bfa->modules.port;
97 uint32_t dm_len;
98 uint8_t *dm_kva;
99 uint64_t dm_pa;
101 dm_len = bfa_port_meminfo();
102 dm_kva = bfa_meminfo_dma_virt(mi);
103 dm_pa = bfa_meminfo_dma_phys(mi);
105 memset(port, 0, sizeof(struct bfa_port_s));
106 bfa_port_attach(port, &bfa->ioc, bfa, bfa->trcmod, bfa->logm);
107 bfa_port_mem_claim(port, dm_kva, dm_pa);
109 bfa_meminfo_dma_virt(mi) = dm_kva + dm_len;
110 bfa_meminfo_dma_phys(mi) = dm_pa + dm_len;
114 * Use this function to do attach the driver instance with the BFA
115 * library. This function will not trigger any HW initialization
116 * process (which will be done in bfa_init() call)
118 * This call will fail, if the cap is out of range compared to
119 * pre-defined values within the BFA library
121 * @param[out] bfa Pointer to bfa_t.
122 * @param[in] bfad Opaque handle back to the driver's IOC structure
123 * @param[in] cfg Pointer to bfa_ioc_cfg_t. Should be same structure
124 * that was used in bfa_cfg_get_meminfo().
125 * @param[in] meminfo Pointer to bfa_meminfo_t. The driver should
126 * use the bfa_cfg_get_meminfo() call to
127 * find the memory blocks required, allocate the
128 * required memory and provide the starting addresses.
129 * @param[in] pcidev pointer to struct bfa_pcidev_s
131 * @return
132 * void
134 * Special Considerations:
136 * @note
139 void
140 bfa_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
141 struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev)
143 int i;
144 struct bfa_mem_elem_s *melem;
146 bfa->fcs = BFA_FALSE;
148 bfa_assert((cfg != NULL) && (meminfo != NULL));
151 * initialize all memory pointers for iterative allocation
153 for (i = 0; i < BFA_MEM_TYPE_MAX; i++) {
154 melem = meminfo->meminfo + i;
155 melem->kva_curp = melem->kva;
156 melem->dma_curp = melem->dma;
159 bfa_iocfc_attach(bfa, bfad, cfg, meminfo, pcidev);
161 for (i = 0; hal_mods[i]; i++)
162 hal_mods[i]->attach(bfa, bfad, cfg, meminfo, pcidev);
164 bfa_com_port_attach(bfa, meminfo);
168 * Use this function to delete a BFA IOC. IOC should be stopped (by
169 * calling bfa_stop()) before this function call.
171 * @param[in] bfa - pointer to bfa_t.
173 * @return
174 * void
176 * Special Considerations:
178 * @note
180 void
181 bfa_detach(struct bfa_s *bfa)
183 int i;
185 for (i = 0; hal_mods[i]; i++)
186 hal_mods[i]->detach(bfa);
188 bfa_iocfc_detach(bfa);
192 void
193 bfa_init_trc(struct bfa_s *bfa, struct bfa_trc_mod_s *trcmod)
195 bfa->trcmod = trcmod;
199 void
200 bfa_init_log(struct bfa_s *bfa, struct bfa_log_mod_s *logmod)
202 bfa->logm = logmod;
206 void
207 bfa_init_aen(struct bfa_s *bfa, struct bfa_aen_s *aen)
209 bfa->aen = aen;
212 void
213 bfa_init_plog(struct bfa_s *bfa, struct bfa_plog_s *plog)
215 bfa->plog = plog;
219 * Initialize IOC.
221 * This function will return immediately, when the IOC initialization is
222 * completed, the bfa_cb_init() will be called.
224 * @param[in] bfa instance
226 * @return void
228 * Special Considerations:
230 * @note
231 * When this function returns, the driver should register the interrupt service
232 * routine(s) and enable the device interrupts. If this is not done,
233 * bfa_cb_init() will never get called
235 void
236 bfa_init(struct bfa_s *bfa)
238 bfa_iocfc_init(bfa);
242 * Use this function initiate the IOC configuration setup. This function
243 * will return immediately.
245 * @param[in] bfa instance
247 * @return None
249 void
250 bfa_start(struct bfa_s *bfa)
252 bfa_iocfc_start(bfa);
256 * Use this function quiese the IOC. This function will return immediately,
257 * when the IOC is actually stopped, the bfa_cb_stop() will be called.
259 * @param[in] bfa - pointer to bfa_t.
261 * @return None
263 * Special Considerations:
264 * bfa_cb_stop() could be called before or after bfa_stop() returns.
266 * @note
267 * In case of any failure, we could handle it automatically by doing a
268 * reset and then succeed the bfa_stop() call.
270 void
271 bfa_stop(struct bfa_s *bfa)
273 bfa_iocfc_stop(bfa);
276 void
277 bfa_comp_deq(struct bfa_s *bfa, struct list_head *comp_q)
279 INIT_LIST_HEAD(comp_q);
280 list_splice_tail_init(&bfa->comp_q, comp_q);
283 void
284 bfa_comp_process(struct bfa_s *bfa, struct list_head *comp_q)
286 struct list_head *qe;
287 struct list_head *qen;
288 struct bfa_cb_qe_s *hcb_qe;
290 list_for_each_safe(qe, qen, comp_q) {
291 hcb_qe = (struct bfa_cb_qe_s *) qe;
292 hcb_qe->cbfn(hcb_qe->cbarg, BFA_TRUE);
296 void
297 bfa_comp_free(struct bfa_s *bfa, struct list_head *comp_q)
299 struct list_head *qe;
300 struct bfa_cb_qe_s *hcb_qe;
302 while (!list_empty(comp_q)) {
303 bfa_q_deq(comp_q, &qe);
304 hcb_qe = (struct bfa_cb_qe_s *) qe;
305 hcb_qe->cbfn(hcb_qe->cbarg, BFA_FALSE);
309 void
310 bfa_attach_fcs(struct bfa_s *bfa)
312 bfa->fcs = BFA_TRUE;
316 * Periodic timer heart beat from driver
318 void
319 bfa_timer_tick(struct bfa_s *bfa)
321 bfa_timer_beat(&bfa->timer_mod);
324 #ifndef BFA_BIOS_BUILD
326 * Return the list of PCI vendor/device id lists supported by this
327 * BFA instance.
329 void
330 bfa_get_pciids(struct bfa_pciid_s **pciids, int *npciids)
332 static struct bfa_pciid_s __pciids[] = {
333 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G2P},
334 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_FC_8G1P},
335 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT},
336 {BFA_PCI_VENDOR_ID_BROCADE, BFA_PCI_DEVICE_ID_CT_FC},
339 *npciids = ARRAY_SIZE(__pciids);
340 *pciids = __pciids;
344 * Use this function query the default struct bfa_iocfc_cfg_s value (compiled
345 * into BFA layer). The OS driver can then turn back and overwrite entries that
346 * have been configured by the user.
348 * @param[in] cfg - pointer to bfa_ioc_cfg_t
350 * @return
351 * void
353 * Special Considerations:
354 * note
356 void
357 bfa_cfg_get_default(struct bfa_iocfc_cfg_s *cfg)
359 cfg->fwcfg.num_fabrics = DEF_CFG_NUM_FABRICS;
360 cfg->fwcfg.num_lports = DEF_CFG_NUM_LPORTS;
361 cfg->fwcfg.num_rports = DEF_CFG_NUM_RPORTS;
362 cfg->fwcfg.num_ioim_reqs = DEF_CFG_NUM_IOIM_REQS;
363 cfg->fwcfg.num_tskim_reqs = DEF_CFG_NUM_TSKIM_REQS;
364 cfg->fwcfg.num_fcxp_reqs = DEF_CFG_NUM_FCXP_REQS;
365 cfg->fwcfg.num_uf_bufs = DEF_CFG_NUM_UF_BUFS;
366 cfg->fwcfg.num_cqs = DEF_CFG_NUM_CQS;
368 cfg->drvcfg.num_reqq_elems = DEF_CFG_NUM_REQQ_ELEMS;
369 cfg->drvcfg.num_rspq_elems = DEF_CFG_NUM_RSPQ_ELEMS;
370 cfg->drvcfg.num_sgpgs = DEF_CFG_NUM_SGPGS;
371 cfg->drvcfg.num_sboot_tgts = DEF_CFG_NUM_SBOOT_TGTS;
372 cfg->drvcfg.num_sboot_luns = DEF_CFG_NUM_SBOOT_LUNS;
373 cfg->drvcfg.path_tov = BFA_FCPIM_PATHTOV_DEF;
374 cfg->drvcfg.ioc_recover = BFA_FALSE;
375 cfg->drvcfg.delay_comp = BFA_FALSE;
379 void
380 bfa_cfg_get_min(struct bfa_iocfc_cfg_s *cfg)
382 bfa_cfg_get_default(cfg);
383 cfg->fwcfg.num_ioim_reqs = BFA_IOIM_MIN;
384 cfg->fwcfg.num_tskim_reqs = BFA_TSKIM_MIN;
385 cfg->fwcfg.num_fcxp_reqs = BFA_FCXP_MIN;
386 cfg->fwcfg.num_uf_bufs = BFA_UF_MIN;
387 cfg->fwcfg.num_rports = BFA_RPORT_MIN;
389 cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN;
390 cfg->drvcfg.num_reqq_elems = BFA_REQQ_NELEMS_MIN;
391 cfg->drvcfg.num_rspq_elems = BFA_RSPQ_NELEMS_MIN;
392 cfg->drvcfg.min_cfg = BFA_TRUE;
395 void
396 bfa_get_attr(struct bfa_s *bfa, struct bfa_ioc_attr_s *ioc_attr)
398 bfa_ioc_get_attr(&bfa->ioc, ioc_attr);
402 * Retrieve firmware trace information on IOC failure.
404 bfa_status_t
405 bfa_debug_fwsave(struct bfa_s *bfa, void *trcdata, int *trclen)
407 return bfa_ioc_debug_fwsave(&bfa->ioc, trcdata, trclen);
411 * Clear the saved firmware trace information of an IOC.
413 void
414 bfa_debug_fwsave_clear(struct bfa_s *bfa)
416 bfa_ioc_debug_fwsave_clear(&bfa->ioc);
420 * Fetch firmware trace data.
422 * @param[in] bfa BFA instance
423 * @param[out] trcdata Firmware trace buffer
424 * @param[in,out] trclen Firmware trace buffer len
426 * @retval BFA_STATUS_OK Firmware trace is fetched.
427 * @retval BFA_STATUS_INPROGRESS Firmware trace fetch is in progress.
429 bfa_status_t
430 bfa_debug_fwtrc(struct bfa_s *bfa, void *trcdata, int *trclen)
432 return bfa_ioc_debug_fwtrc(&bfa->ioc, trcdata, trclen);
436 * Reset hw semaphore & usage cnt regs and initialize.
438 void
439 bfa_chip_reset(struct bfa_s *bfa)
441 bfa_ioc_ownership_reset(&bfa->ioc);
442 bfa_ioc_pll_init(&bfa->ioc);
444 #endif