Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1 | /* |
| 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 | /** |
| 19 | * bfa_fcs.c BFA FCS main |
| 20 | */ |
| 21 | |
| 22 | #include <fcs/bfa_fcs.h> |
| 23 | #include "fcs_port.h" |
| 24 | #include "fcs_uf.h" |
| 25 | #include "fcs_vport.h" |
| 26 | #include "fcs_rport.h" |
| 27 | #include "fcs_fabric.h" |
| 28 | #include "fcs_fcpim.h" |
| 29 | #include "fcs_fcptm.h" |
| 30 | #include "fcbuild.h" |
| 31 | #include "fcs.h" |
| 32 | #include "bfad_drv.h" |
| 33 | #include <fcb/bfa_fcb.h> |
| 34 | |
| 35 | /** |
| 36 | * FCS sub-modules |
| 37 | */ |
| 38 | struct bfa_fcs_mod_s { |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 39 | void (*attach) (struct bfa_fcs_s *fcs); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 40 | void (*modinit) (struct bfa_fcs_s *fcs); |
| 41 | void (*modexit) (struct bfa_fcs_s *fcs); |
| 42 | }; |
| 43 | |
| 44 | #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit } |
| 45 | |
| 46 | static struct bfa_fcs_mod_s fcs_modules[] = { |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 47 | { bfa_fcs_pport_attach, NULL, NULL }, |
| 48 | { bfa_fcs_uf_attach, NULL, NULL }, |
| 49 | { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit, |
| 50 | bfa_fcs_fabric_modexit }, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * fcs_api BFA FCS API |
| 55 | */ |
| 56 | |
| 57 | static void |
| 58 | bfa_fcs_exit_comp(void *fcs_cbarg) |
| 59 | { |
| 60 | struct bfa_fcs_s *fcs = fcs_cbarg; |
| 61 | struct bfad_s *bfad = fcs->bfad; |
| 62 | |
| 63 | complete(&bfad->comp); |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | /** |
| 69 | * fcs_api BFA FCS API |
| 70 | */ |
| 71 | |
| 72 | /** |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 73 | * fcs attach -- called once to initialize data structures at driver attach time |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 74 | */ |
| 75 | void |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 76 | bfa_fcs_attach(struct bfa_fcs_s *fcs, struct bfa_s *bfa, struct bfad_s *bfad, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 77 | bfa_boolean_t min_cfg) |
| 78 | { |
| 79 | int i; |
| 80 | struct bfa_fcs_mod_s *mod; |
| 81 | |
| 82 | fcs->bfa = bfa; |
| 83 | fcs->bfad = bfad; |
| 84 | fcs->min_cfg = min_cfg; |
| 85 | |
| 86 | bfa_attach_fcs(bfa); |
| 87 | fcbuild_init(); |
| 88 | |
Kulikov Vasiliy | 501af8d | 2010-06-28 15:55:04 +0400 | [diff] [blame] | 89 | for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 90 | mod = &fcs_modules[i]; |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 91 | if (mod->attach) |
| 92 | mod->attach(fcs); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * fcs initialization, called once after bfa initialization is complete |
| 98 | */ |
| 99 | void |
| 100 | bfa_fcs_init(struct bfa_fcs_s *fcs) |
| 101 | { |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 102 | int i, npbc_vports; |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 103 | struct bfa_fcs_mod_s *mod; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 104 | struct bfi_pbc_vport_s pbc_vports[BFI_PBC_MAX_VPORTS]; |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 105 | |
Kulikov Vasiliy | 501af8d | 2010-06-28 15:55:04 +0400 | [diff] [blame] | 106 | for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) { |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 107 | mod = &fcs_modules[i]; |
| 108 | if (mod->modinit) |
| 109 | mod->modinit(fcs); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 110 | } |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 111 | /* Initialize pbc vports */ |
| 112 | if (!fcs->min_cfg) { |
| 113 | npbc_vports = |
| 114 | bfa_iocfc_get_pbc_vports(fcs->bfa, pbc_vports); |
| 115 | for (i = 0; i < npbc_vports; i++) |
| 116 | bfa_fcb_pbc_vport_create(fcs->bfa->bfad, pbc_vports[i]); |
| 117 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
| 121 | * Start FCS operations. |
| 122 | */ |
| 123 | void |
| 124 | bfa_fcs_start(struct bfa_fcs_s *fcs) |
| 125 | { |
| 126 | bfa_fcs_fabric_modstart(fcs); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * FCS driver details initialization. |
| 131 | * |
| 132 | * param[in] fcs FCS instance |
| 133 | * param[in] driver_info Driver Details |
| 134 | * |
| 135 | * return None |
| 136 | */ |
| 137 | void |
| 138 | bfa_fcs_driver_info_init(struct bfa_fcs_s *fcs, |
| 139 | struct bfa_fcs_driver_info_s *driver_info) |
| 140 | { |
| 141 | |
| 142 | fcs->driver_info = *driver_info; |
| 143 | |
| 144 | bfa_fcs_fabric_psymb_init(&fcs->fabric); |
| 145 | } |
| 146 | |
| 147 | /** |
Krishna Gudipati | 5b09808 | 2010-03-03 17:43:19 -0800 | [diff] [blame] | 148 | * @brief |
| 149 | * FCS FDMI Driver Parameter Initialization |
| 150 | * |
| 151 | * @param[in] fcs FCS instance |
| 152 | * @param[in] fdmi_enable TRUE/FALSE |
| 153 | * |
| 154 | * @return None |
| 155 | */ |
| 156 | void |
| 157 | bfa_fcs_set_fdmi_param(struct bfa_fcs_s *fcs, bfa_boolean_t fdmi_enable) |
| 158 | { |
| 159 | |
| 160 | fcs->fdmi_enabled = fdmi_enable; |
| 161 | |
| 162 | } |
| 163 | |
| 164 | /** |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 165 | * FCS instance cleanup and exit. |
| 166 | * |
| 167 | * param[in] fcs FCS instance |
| 168 | * return None |
| 169 | */ |
| 170 | void |
| 171 | bfa_fcs_exit(struct bfa_fcs_s *fcs) |
| 172 | { |
| 173 | struct bfa_fcs_mod_s *mod; |
Kulikov Vasiliy | 501af8d | 2010-06-28 15:55:04 +0400 | [diff] [blame] | 174 | int i; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 175 | |
| 176 | bfa_wc_init(&fcs->wc, bfa_fcs_exit_comp, fcs); |
| 177 | |
Kulikov Vasiliy | 501af8d | 2010-06-28 15:55:04 +0400 | [diff] [blame] | 178 | for (i = 0; i < ARRAY_SIZE(fcs_modules); i++) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 179 | |
| 180 | mod = &fcs_modules[i]; |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 181 | if (mod->modexit) { |
| 182 | bfa_wc_up(&fcs->wc); |
| 183 | mod->modexit(fcs); |
| 184 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | bfa_wc_wait(&fcs->wc); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | void |
| 192 | bfa_fcs_trc_init(struct bfa_fcs_s *fcs, struct bfa_trc_mod_s *trcmod) |
| 193 | { |
| 194 | fcs->trcmod = trcmod; |
| 195 | } |
| 196 | |
| 197 | |
| 198 | void |
| 199 | bfa_fcs_log_init(struct bfa_fcs_s *fcs, struct bfa_log_mod_s *logmod) |
| 200 | { |
| 201 | fcs->logm = logmod; |
| 202 | } |
| 203 | |
| 204 | |
| 205 | void |
| 206 | bfa_fcs_aen_init(struct bfa_fcs_s *fcs, struct bfa_aen_s *aen) |
| 207 | { |
| 208 | fcs->aen = aen; |
| 209 | } |
| 210 | |
| 211 | void |
| 212 | bfa_fcs_modexit_comp(struct bfa_fcs_s *fcs) |
| 213 | { |
| 214 | bfa_wc_down(&fcs->wc); |
| 215 | } |
| 216 | |
| 217 | |