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 | * bfad.c Linux driver PCI interface module. |
| 20 | */ |
| 21 | |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 24 | #include <linux/kthread.h> |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 25 | #include "bfad_drv.h" |
| 26 | #include "bfad_im.h" |
| 27 | #include "bfad_tm.h" |
| 28 | #include "bfad_ipfc.h" |
| 29 | #include "bfad_trcmod.h" |
| 30 | #include <fcb/bfa_fcb_vf.h> |
| 31 | #include <fcb/bfa_fcb_rport.h> |
| 32 | #include <fcb/bfa_fcb_port.h> |
| 33 | #include <fcb/bfa_fcb.h> |
| 34 | |
| 35 | BFA_TRC_FILE(LDRV, BFAD); |
Jing Huang | 42b426e | 2010-03-19 11:07:09 -0700 | [diff] [blame] | 36 | DEFINE_MUTEX(bfad_mutex); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 37 | LIST_HEAD(bfad_list); |
| 38 | static int bfad_inst; |
| 39 | int bfad_supported_fc4s; |
| 40 | |
| 41 | static char *host_name; |
| 42 | static char *os_name; |
| 43 | static char *os_patch; |
| 44 | static int num_rports; |
| 45 | static int num_ios; |
| 46 | static int num_tms; |
| 47 | static int num_fcxps; |
| 48 | static int num_ufbufs; |
| 49 | static int reqq_size; |
| 50 | static int rspq_size; |
| 51 | static int num_sgpgs; |
| 52 | static int rport_del_timeout = BFA_FCS_RPORT_DEF_DEL_TIMEOUT; |
| 53 | static int bfa_io_max_sge = BFAD_IO_MAX_SGE; |
| 54 | static int log_level = BFA_LOG_WARNING; |
| 55 | static int ioc_auto_recover = BFA_TRUE; |
| 56 | static int ipfc_enable = BFA_FALSE; |
Krishna Gudipati | 5b09808 | 2010-03-03 17:43:19 -0800 | [diff] [blame] | 57 | static int fdmi_enable = BFA_TRUE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 58 | int bfa_lun_queue_depth = BFAD_LUN_QUEUE_DEPTH; |
| 59 | int bfa_linkup_delay = -1; |
| 60 | |
| 61 | module_param(os_name, charp, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 62 | MODULE_PARM_DESC(os_name, "OS name of the hba host machine"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 63 | module_param(os_patch, charp, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 64 | MODULE_PARM_DESC(os_patch, "OS patch level of the hba host machine"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 65 | module_param(host_name, charp, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 66 | MODULE_PARM_DESC(host_name, "Hostname of the hba host machine"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 67 | module_param(num_rports, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 68 | MODULE_PARM_DESC(num_rports, "Max number of rports supported per port" |
| 69 | " (physical/logical), default=1024"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 70 | module_param(num_ios, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 71 | MODULE_PARM_DESC(num_ios, "Max number of ioim requests, default=2000"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 72 | module_param(num_tms, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 73 | MODULE_PARM_DESC(num_tms, "Max number of task im requests, default=128"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 74 | module_param(num_fcxps, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 75 | MODULE_PARM_DESC(num_fcxps, "Max number of fcxp requests, default=64"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 76 | module_param(num_ufbufs, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 77 | MODULE_PARM_DESC(num_ufbufs, "Max number of unsolicited frame buffers," |
| 78 | " default=64"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 79 | module_param(reqq_size, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 80 | MODULE_PARM_DESC(reqq_size, "Max number of request queue elements," |
| 81 | " default=256"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 82 | module_param(rspq_size, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 83 | MODULE_PARM_DESC(rspq_size, "Max number of response queue elements," |
| 84 | " default=64"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 85 | module_param(num_sgpgs, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 86 | MODULE_PARM_DESC(num_sgpgs, "Number of scatter/gather pages, default=2048"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 87 | module_param(rport_del_timeout, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 88 | MODULE_PARM_DESC(rport_del_timeout, "Rport delete timeout, default=90 secs," |
| 89 | " Range[>0]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 90 | module_param(bfa_lun_queue_depth, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 91 | MODULE_PARM_DESC(bfa_lun_queue_depth, "Lun queue depth, default=32," |
| 92 | " Range[>0]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 93 | module_param(bfa_io_max_sge, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 94 | MODULE_PARM_DESC(bfa_io_max_sge, "Max io scatter/gather elements, default=255"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 95 | module_param(log_level, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 96 | MODULE_PARM_DESC(log_level, "Driver log level, default=3," |
| 97 | " Range[Critical:1|Error:2|Warning:3|Info:4]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 98 | module_param(ioc_auto_recover, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 99 | MODULE_PARM_DESC(ioc_auto_recover, "IOC auto recovery, default=1," |
| 100 | " Range[off:0|on:1]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 101 | module_param(ipfc_enable, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 102 | MODULE_PARM_DESC(ipfc_enable, "Enable IPoFC, default=0, Range[off:0|on:1]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 103 | module_param(bfa_linkup_delay, int, S_IRUGO | S_IWUSR); |
Jing Huang | 604158ad | 2010-07-08 19:59:49 -0700 | [diff] [blame^] | 104 | MODULE_PARM_DESC(bfa_linkup_delay, "Link up delay, default=30 secs for boot" |
| 105 | " port. Otherwise Range[>0]"); |
| 106 | module_param(fdmi_enable, int, S_IRUGO | S_IWUSR); |
| 107 | MODULE_PARM_DESC(fdmi_enable, "Enables fdmi registration, default=1," |
| 108 | " Range[false:0|true:1]"); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 109 | |
| 110 | /* |
| 111 | * Stores the module parm num_sgpgs value; |
| 112 | * used to reset for bfad next instance. |
| 113 | */ |
| 114 | static int num_sgpgs_parm; |
| 115 | |
| 116 | static bfa_status_t |
| 117 | bfad_fc4_probe(struct bfad_s *bfad) |
| 118 | { |
| 119 | int rc; |
| 120 | |
| 121 | rc = bfad_im_probe(bfad); |
| 122 | if (rc != BFA_STATUS_OK) |
| 123 | goto ext; |
| 124 | |
| 125 | bfad_tm_probe(bfad); |
| 126 | |
| 127 | if (ipfc_enable) |
| 128 | bfad_ipfc_probe(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 129 | |
| 130 | bfad->bfad_flags |= BFAD_FC4_PROBE_DONE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 131 | ext: |
| 132 | return rc; |
| 133 | } |
| 134 | |
| 135 | static void |
| 136 | bfad_fc4_probe_undo(struct bfad_s *bfad) |
| 137 | { |
| 138 | bfad_im_probe_undo(bfad); |
| 139 | bfad_tm_probe_undo(bfad); |
| 140 | if (ipfc_enable) |
| 141 | bfad_ipfc_probe_undo(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 142 | bfad->bfad_flags &= ~BFAD_FC4_PROBE_DONE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static void |
| 146 | bfad_fc4_probe_post(struct bfad_s *bfad) |
| 147 | { |
| 148 | if (bfad->im) |
| 149 | bfad_im_probe_post(bfad->im); |
| 150 | |
| 151 | bfad_tm_probe_post(bfad); |
| 152 | if (ipfc_enable) |
| 153 | bfad_ipfc_probe_post(bfad); |
| 154 | } |
| 155 | |
| 156 | static bfa_status_t |
| 157 | bfad_fc4_port_new(struct bfad_s *bfad, struct bfad_port_s *port, int roles) |
| 158 | { |
| 159 | int rc = BFA_STATUS_FAILED; |
| 160 | |
| 161 | if (roles & BFA_PORT_ROLE_FCP_IM) |
| 162 | rc = bfad_im_port_new(bfad, port); |
| 163 | if (rc != BFA_STATUS_OK) |
| 164 | goto ext; |
| 165 | |
| 166 | if (roles & BFA_PORT_ROLE_FCP_TM) |
| 167 | rc = bfad_tm_port_new(bfad, port); |
| 168 | if (rc != BFA_STATUS_OK) |
| 169 | goto ext; |
| 170 | |
| 171 | if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) |
| 172 | rc = bfad_ipfc_port_new(bfad, port, port->pvb_type); |
| 173 | ext: |
| 174 | return rc; |
| 175 | } |
| 176 | |
| 177 | static void |
| 178 | bfad_fc4_port_delete(struct bfad_s *bfad, struct bfad_port_s *port, int roles) |
| 179 | { |
| 180 | if (roles & BFA_PORT_ROLE_FCP_IM) |
| 181 | bfad_im_port_delete(bfad, port); |
| 182 | |
| 183 | if (roles & BFA_PORT_ROLE_FCP_TM) |
| 184 | bfad_tm_port_delete(bfad, port); |
| 185 | |
| 186 | if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) |
| 187 | bfad_ipfc_port_delete(bfad, port); |
| 188 | } |
| 189 | |
| 190 | /** |
| 191 | * BFA callbacks |
| 192 | */ |
| 193 | void |
| 194 | bfad_hcb_comp(void *arg, bfa_status_t status) |
| 195 | { |
| 196 | struct bfad_hal_comp *fcomp = (struct bfad_hal_comp *)arg; |
| 197 | |
| 198 | fcomp->status = status; |
| 199 | complete(&fcomp->comp); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * bfa_init callback |
| 204 | */ |
| 205 | void |
| 206 | bfa_cb_init(void *drv, bfa_status_t init_status) |
| 207 | { |
| 208 | struct bfad_s *bfad = drv; |
| 209 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 210 | if (init_status == BFA_STATUS_OK) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 211 | bfad->bfad_flags |= BFAD_HAL_INIT_DONE; |
| 212 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 213 | /* If BFAD_HAL_INIT_FAIL flag is set: |
| 214 | * Wake up the kernel thread to start |
| 215 | * the bfad operations after HAL init done |
| 216 | */ |
| 217 | if ((bfad->bfad_flags & BFAD_HAL_INIT_FAIL)) { |
| 218 | bfad->bfad_flags &= ~BFAD_HAL_INIT_FAIL; |
| 219 | wake_up_process(bfad->bfad_tsk); |
| 220 | } |
| 221 | } |
| 222 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 223 | complete(&bfad->comp); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | |
| 228 | /** |
| 229 | * BFA_FCS callbacks |
| 230 | */ |
| 231 | static struct bfad_port_s * |
| 232 | bfad_get_drv_port(struct bfad_s *bfad, struct bfad_vf_s *vf_drv, |
| 233 | struct bfad_vport_s *vp_drv) |
| 234 | { |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 235 | return (vp_drv) ? (&(vp_drv)->drv_port) |
| 236 | : ((vf_drv) ? (&(vf_drv)->base_port) : (&(bfad)->pport)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | struct bfad_port_s * |
| 240 | bfa_fcb_port_new(struct bfad_s *bfad, struct bfa_fcs_port_s *port, |
| 241 | enum bfa_port_role roles, struct bfad_vf_s *vf_drv, |
| 242 | struct bfad_vport_s *vp_drv) |
| 243 | { |
| 244 | bfa_status_t rc; |
| 245 | struct bfad_port_s *port_drv; |
| 246 | |
| 247 | if (!vp_drv && !vf_drv) { |
| 248 | port_drv = &bfad->pport; |
| 249 | port_drv->pvb_type = BFAD_PORT_PHYS_BASE; |
| 250 | } else if (!vp_drv && vf_drv) { |
| 251 | port_drv = &vf_drv->base_port; |
| 252 | port_drv->pvb_type = BFAD_PORT_VF_BASE; |
| 253 | } else if (vp_drv && !vf_drv) { |
| 254 | port_drv = &vp_drv->drv_port; |
| 255 | port_drv->pvb_type = BFAD_PORT_PHYS_VPORT; |
| 256 | } else { |
| 257 | port_drv = &vp_drv->drv_port; |
| 258 | port_drv->pvb_type = BFAD_PORT_VF_VPORT; |
| 259 | } |
| 260 | |
| 261 | port_drv->fcs_port = port; |
| 262 | port_drv->roles = roles; |
| 263 | rc = bfad_fc4_port_new(bfad, port_drv, roles); |
| 264 | if (rc != BFA_STATUS_OK) { |
| 265 | bfad_fc4_port_delete(bfad, port_drv, roles); |
| 266 | port_drv = NULL; |
| 267 | } |
| 268 | |
| 269 | return port_drv; |
| 270 | } |
| 271 | |
| 272 | void |
| 273 | bfa_fcb_port_delete(struct bfad_s *bfad, enum bfa_port_role roles, |
| 274 | struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv) |
| 275 | { |
| 276 | struct bfad_port_s *port_drv; |
| 277 | |
| 278 | /* |
| 279 | * this will be only called from rmmod context |
| 280 | */ |
| 281 | if (vp_drv && !vp_drv->comp_del) { |
| 282 | port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv); |
| 283 | bfa_trc(bfad, roles); |
| 284 | bfad_fc4_port_delete(bfad, port_drv, roles); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void |
| 289 | bfa_fcb_port_online(struct bfad_s *bfad, enum bfa_port_role roles, |
| 290 | struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv) |
| 291 | { |
| 292 | struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv); |
| 293 | |
| 294 | if (roles & BFA_PORT_ROLE_FCP_IM) |
| 295 | bfad_im_port_online(bfad, port_drv); |
| 296 | |
| 297 | if (roles & BFA_PORT_ROLE_FCP_TM) |
| 298 | bfad_tm_port_online(bfad, port_drv); |
| 299 | |
| 300 | if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) |
| 301 | bfad_ipfc_port_online(bfad, port_drv); |
| 302 | |
| 303 | bfad->bfad_flags |= BFAD_PORT_ONLINE; |
| 304 | } |
| 305 | |
| 306 | void |
| 307 | bfa_fcb_port_offline(struct bfad_s *bfad, enum bfa_port_role roles, |
| 308 | struct bfad_vf_s *vf_drv, struct bfad_vport_s *vp_drv) |
| 309 | { |
| 310 | struct bfad_port_s *port_drv = bfad_get_drv_port(bfad, vf_drv, vp_drv); |
| 311 | |
| 312 | if (roles & BFA_PORT_ROLE_FCP_IM) |
| 313 | bfad_im_port_offline(bfad, port_drv); |
| 314 | |
| 315 | if (roles & BFA_PORT_ROLE_FCP_TM) |
| 316 | bfad_tm_port_offline(bfad, port_drv); |
| 317 | |
| 318 | if ((roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) |
| 319 | bfad_ipfc_port_offline(bfad, port_drv); |
| 320 | } |
| 321 | |
| 322 | void |
| 323 | bfa_fcb_vport_delete(struct bfad_vport_s *vport_drv) |
| 324 | { |
| 325 | if (vport_drv->comp_del) { |
| 326 | complete(vport_drv->comp_del); |
| 327 | return; |
| 328 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | /** |
| 332 | * FCS RPORT alloc callback, after successful PLOGI by FCS |
| 333 | */ |
| 334 | bfa_status_t |
| 335 | bfa_fcb_rport_alloc(struct bfad_s *bfad, struct bfa_fcs_rport_s **rport, |
| 336 | struct bfad_rport_s **rport_drv) |
| 337 | { |
| 338 | bfa_status_t rc = BFA_STATUS_OK; |
| 339 | |
| 340 | *rport_drv = kzalloc(sizeof(struct bfad_rport_s), GFP_ATOMIC); |
| 341 | if (*rport_drv == NULL) { |
| 342 | rc = BFA_STATUS_ENOMEM; |
| 343 | goto ext; |
| 344 | } |
| 345 | |
| 346 | *rport = &(*rport_drv)->fcs_rport; |
| 347 | |
| 348 | ext: |
| 349 | return rc; |
| 350 | } |
| 351 | |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 352 | /** |
| 353 | * @brief |
| 354 | * FCS PBC VPORT Create |
| 355 | */ |
| 356 | void |
| 357 | bfa_fcb_pbc_vport_create(struct bfad_s *bfad, struct bfi_pbc_vport_s pbc_vport) |
| 358 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 359 | |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 360 | struct bfad_pcfg_s *pcfg; |
| 361 | |
| 362 | pcfg = kzalloc(sizeof(struct bfad_pcfg_s), GFP_ATOMIC); |
| 363 | if (!pcfg) { |
| 364 | bfa_trc(bfad, 0); |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | pcfg->port_cfg.roles = BFA_PORT_ROLE_FCP_IM; |
| 369 | pcfg->port_cfg.pwwn = pbc_vport.vp_pwwn; |
| 370 | pcfg->port_cfg.nwwn = pbc_vport.vp_nwwn; |
| 371 | pcfg->port_cfg.preboot_vp = BFA_TRUE; |
| 372 | |
| 373 | list_add_tail(&pcfg->list_entry, &bfad->pbc_pcfg_list); |
| 374 | |
| 375 | return; |
| 376 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 377 | |
| 378 | void |
| 379 | bfad_hal_mem_release(struct bfad_s *bfad) |
| 380 | { |
| 381 | int i; |
| 382 | struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo; |
| 383 | struct bfa_mem_elem_s *meminfo_elem; |
| 384 | |
| 385 | for (i = 0; i < BFA_MEM_TYPE_MAX; i++) { |
| 386 | meminfo_elem = &hal_meminfo->meminfo[i]; |
| 387 | if (meminfo_elem->kva != NULL) { |
| 388 | switch (meminfo_elem->mem_type) { |
| 389 | case BFA_MEM_TYPE_KVA: |
| 390 | vfree(meminfo_elem->kva); |
| 391 | break; |
| 392 | case BFA_MEM_TYPE_DMA: |
| 393 | dma_free_coherent(&bfad->pcidev->dev, |
| 394 | meminfo_elem->mem_len, |
| 395 | meminfo_elem->kva, |
| 396 | (dma_addr_t) meminfo_elem->dma); |
| 397 | break; |
| 398 | default: |
| 399 | bfa_assert(0); |
| 400 | break; |
| 401 | } |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | memset(hal_meminfo, 0, sizeof(struct bfa_meminfo_s)); |
| 406 | } |
| 407 | |
| 408 | void |
| 409 | bfad_update_hal_cfg(struct bfa_iocfc_cfg_s *bfa_cfg) |
| 410 | { |
| 411 | if (num_rports > 0) |
| 412 | bfa_cfg->fwcfg.num_rports = num_rports; |
| 413 | if (num_ios > 0) |
| 414 | bfa_cfg->fwcfg.num_ioim_reqs = num_ios; |
| 415 | if (num_tms > 0) |
| 416 | bfa_cfg->fwcfg.num_tskim_reqs = num_tms; |
| 417 | if (num_fcxps > 0) |
| 418 | bfa_cfg->fwcfg.num_fcxp_reqs = num_fcxps; |
| 419 | if (num_ufbufs > 0) |
| 420 | bfa_cfg->fwcfg.num_uf_bufs = num_ufbufs; |
| 421 | if (reqq_size > 0) |
| 422 | bfa_cfg->drvcfg.num_reqq_elems = reqq_size; |
| 423 | if (rspq_size > 0) |
| 424 | bfa_cfg->drvcfg.num_rspq_elems = rspq_size; |
| 425 | if (num_sgpgs > 0) |
| 426 | bfa_cfg->drvcfg.num_sgpgs = num_sgpgs; |
| 427 | |
| 428 | /* |
| 429 | * populate the hal values back to the driver for sysfs use. |
| 430 | * otherwise, the default values will be shown as 0 in sysfs |
| 431 | */ |
| 432 | num_rports = bfa_cfg->fwcfg.num_rports; |
| 433 | num_ios = bfa_cfg->fwcfg.num_ioim_reqs; |
| 434 | num_tms = bfa_cfg->fwcfg.num_tskim_reqs; |
| 435 | num_fcxps = bfa_cfg->fwcfg.num_fcxp_reqs; |
| 436 | num_ufbufs = bfa_cfg->fwcfg.num_uf_bufs; |
| 437 | reqq_size = bfa_cfg->drvcfg.num_reqq_elems; |
| 438 | rspq_size = bfa_cfg->drvcfg.num_rspq_elems; |
| 439 | num_sgpgs = bfa_cfg->drvcfg.num_sgpgs; |
| 440 | } |
| 441 | |
| 442 | bfa_status_t |
| 443 | bfad_hal_mem_alloc(struct bfad_s *bfad) |
| 444 | { |
| 445 | struct bfa_meminfo_s *hal_meminfo = &bfad->meminfo; |
| 446 | struct bfa_mem_elem_s *meminfo_elem; |
| 447 | bfa_status_t rc = BFA_STATUS_OK; |
| 448 | dma_addr_t phys_addr; |
| 449 | int retry_count = 0; |
| 450 | int reset_value = 1; |
| 451 | int min_num_sgpgs = 512; |
| 452 | void *kva; |
| 453 | int i; |
| 454 | |
| 455 | bfa_cfg_get_default(&bfad->ioc_cfg); |
| 456 | |
| 457 | retry: |
| 458 | bfad_update_hal_cfg(&bfad->ioc_cfg); |
| 459 | bfad->cfg_data.ioc_queue_depth = bfad->ioc_cfg.fwcfg.num_ioim_reqs; |
| 460 | bfa_cfg_get_meminfo(&bfad->ioc_cfg, hal_meminfo); |
| 461 | |
| 462 | for (i = 0; i < BFA_MEM_TYPE_MAX; i++) { |
| 463 | meminfo_elem = &hal_meminfo->meminfo[i]; |
| 464 | switch (meminfo_elem->mem_type) { |
| 465 | case BFA_MEM_TYPE_KVA: |
| 466 | kva = vmalloc(meminfo_elem->mem_len); |
| 467 | if (kva == NULL) { |
| 468 | bfad_hal_mem_release(bfad); |
| 469 | rc = BFA_STATUS_ENOMEM; |
| 470 | goto ext; |
| 471 | } |
| 472 | memset(kva, 0, meminfo_elem->mem_len); |
| 473 | meminfo_elem->kva = kva; |
| 474 | break; |
| 475 | case BFA_MEM_TYPE_DMA: |
| 476 | kva = dma_alloc_coherent(&bfad->pcidev->dev, |
| 477 | meminfo_elem->mem_len, |
| 478 | &phys_addr, GFP_KERNEL); |
| 479 | if (kva == NULL) { |
| 480 | bfad_hal_mem_release(bfad); |
| 481 | /* |
| 482 | * If we cannot allocate with default |
| 483 | * num_sgpages try with half the value. |
| 484 | */ |
| 485 | if (num_sgpgs > min_num_sgpgs) { |
| 486 | printk(KERN_INFO "bfad[%d]: memory" |
| 487 | " allocation failed with" |
| 488 | " num_sgpgs: %d\n", |
| 489 | bfad->inst_no, num_sgpgs); |
| 490 | nextLowerInt(&num_sgpgs); |
| 491 | printk(KERN_INFO "bfad[%d]: trying to" |
| 492 | " allocate memory with" |
| 493 | " num_sgpgs: %d\n", |
| 494 | bfad->inst_no, num_sgpgs); |
| 495 | retry_count++; |
| 496 | goto retry; |
| 497 | } else { |
| 498 | if (num_sgpgs_parm > 0) |
| 499 | num_sgpgs = num_sgpgs_parm; |
| 500 | else { |
| 501 | reset_value = |
| 502 | (1 << retry_count); |
| 503 | num_sgpgs *= reset_value; |
| 504 | } |
| 505 | rc = BFA_STATUS_ENOMEM; |
| 506 | goto ext; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | if (num_sgpgs_parm > 0) |
| 511 | num_sgpgs = num_sgpgs_parm; |
| 512 | else { |
| 513 | reset_value = (1 << retry_count); |
| 514 | num_sgpgs *= reset_value; |
| 515 | } |
| 516 | |
| 517 | memset(kva, 0, meminfo_elem->mem_len); |
| 518 | meminfo_elem->kva = kva; |
| 519 | meminfo_elem->dma = phys_addr; |
| 520 | break; |
| 521 | default: |
| 522 | break; |
| 523 | |
| 524 | } |
| 525 | } |
| 526 | ext: |
| 527 | return rc; |
| 528 | } |
| 529 | |
| 530 | /** |
| 531 | * Create a vport under a vf. |
| 532 | */ |
| 533 | bfa_status_t |
| 534 | bfad_vport_create(struct bfad_s *bfad, u16 vf_id, |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 535 | struct bfa_port_cfg_s *port_cfg, struct device *dev) |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 536 | { |
| 537 | struct bfad_vport_s *vport; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 538 | int rc = BFA_STATUS_OK; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 539 | unsigned long flags; |
| 540 | struct completion fcomp; |
| 541 | |
| 542 | vport = kzalloc(sizeof(struct bfad_vport_s), GFP_KERNEL); |
| 543 | if (!vport) { |
| 544 | rc = BFA_STATUS_ENOMEM; |
| 545 | goto ext; |
| 546 | } |
| 547 | |
| 548 | vport->drv_port.bfad = bfad; |
| 549 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 550 | if (port_cfg->preboot_vp == BFA_TRUE) |
| 551 | rc = bfa_fcs_pbc_vport_create(&vport->fcs_vport, |
| 552 | &bfad->bfa_fcs, vf_id, port_cfg, vport); |
| 553 | else |
| 554 | rc = bfa_fcs_vport_create(&vport->fcs_vport, |
| 555 | &bfad->bfa_fcs, vf_id, port_cfg, vport); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 556 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 557 | |
| 558 | if (rc != BFA_STATUS_OK) |
| 559 | goto ext_free_vport; |
| 560 | |
| 561 | if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) { |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 562 | rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port, |
| 563 | dev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 564 | if (rc != BFA_STATUS_OK) |
| 565 | goto ext_free_fcs_vport; |
| 566 | } |
| 567 | |
| 568 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 569 | bfa_fcs_vport_start(&vport->fcs_vport); |
| 570 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 571 | |
| 572 | return BFA_STATUS_OK; |
| 573 | |
| 574 | ext_free_fcs_vport: |
| 575 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 576 | vport->comp_del = &fcomp; |
| 577 | init_completion(vport->comp_del); |
| 578 | bfa_fcs_vport_delete(&vport->fcs_vport); |
| 579 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 580 | wait_for_completion(vport->comp_del); |
| 581 | ext_free_vport: |
| 582 | kfree(vport); |
| 583 | ext: |
| 584 | return rc; |
| 585 | } |
| 586 | |
| 587 | /** |
| 588 | * Create a vf and its base vport implicitely. |
| 589 | */ |
| 590 | bfa_status_t |
| 591 | bfad_vf_create(struct bfad_s *bfad, u16 vf_id, |
| 592 | struct bfa_port_cfg_s *port_cfg) |
| 593 | { |
| 594 | struct bfad_vf_s *vf; |
| 595 | int rc = BFA_STATUS_OK; |
| 596 | |
| 597 | vf = kzalloc(sizeof(struct bfad_vf_s), GFP_KERNEL); |
| 598 | if (!vf) { |
| 599 | rc = BFA_STATUS_FAILED; |
| 600 | goto ext; |
| 601 | } |
| 602 | |
| 603 | rc = bfa_fcs_vf_create(&vf->fcs_vf, &bfad->bfa_fcs, vf_id, port_cfg, |
| 604 | vf); |
| 605 | if (rc != BFA_STATUS_OK) |
| 606 | kfree(vf); |
| 607 | ext: |
| 608 | return rc; |
| 609 | } |
| 610 | |
| 611 | void |
| 612 | bfad_bfa_tmo(unsigned long data) |
| 613 | { |
| 614 | struct bfad_s *bfad = (struct bfad_s *)data; |
| 615 | unsigned long flags; |
| 616 | struct list_head doneq; |
| 617 | |
| 618 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 619 | |
| 620 | bfa_timer_tick(&bfad->bfa); |
| 621 | |
| 622 | bfa_comp_deq(&bfad->bfa, &doneq); |
| 623 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 624 | |
| 625 | if (!list_empty(&doneq)) { |
| 626 | bfa_comp_process(&bfad->bfa, &doneq); |
| 627 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 628 | bfa_comp_free(&bfad->bfa, &doneq); |
| 629 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 630 | } |
| 631 | |
| 632 | mod_timer(&bfad->hal_tmo, jiffies + msecs_to_jiffies(BFA_TIMER_FREQ)); |
| 633 | } |
| 634 | |
| 635 | void |
| 636 | bfad_init_timer(struct bfad_s *bfad) |
| 637 | { |
| 638 | init_timer(&bfad->hal_tmo); |
| 639 | bfad->hal_tmo.function = bfad_bfa_tmo; |
| 640 | bfad->hal_tmo.data = (unsigned long)bfad; |
| 641 | |
| 642 | mod_timer(&bfad->hal_tmo, jiffies + msecs_to_jiffies(BFA_TIMER_FREQ)); |
| 643 | } |
| 644 | |
| 645 | int |
| 646 | bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad) |
| 647 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 648 | int rc = -ENODEV; |
| 649 | |
| 650 | if (pci_enable_device(pdev)) { |
| 651 | BFA_PRINTF(BFA_ERR, "pci_enable_device fail %p\n", pdev); |
| 652 | goto out; |
| 653 | } |
| 654 | |
| 655 | if (pci_request_regions(pdev, BFAD_DRIVER_NAME)) |
| 656 | goto out_disable_device; |
| 657 | |
| 658 | pci_set_master(pdev); |
| 659 | |
| 660 | |
| 661 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) |
| 662 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { |
| 663 | BFA_PRINTF(BFA_ERR, "pci_set_dma_mask fail %p\n", pdev); |
| 664 | goto out_release_region; |
| 665 | } |
| 666 | |
Jing Huang | b3522f0 | 2010-03-19 11:06:44 -0700 | [diff] [blame] | 667 | bfad->pci_bar0_kva = pci_iomap(pdev, 0, pci_resource_len(pdev, 0)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 668 | |
| 669 | if (bfad->pci_bar0_kva == NULL) { |
| 670 | BFA_PRINTF(BFA_ERR, "Fail to map bar0\n"); |
| 671 | goto out_release_region; |
| 672 | } |
| 673 | |
| 674 | bfad->hal_pcidev.pci_slot = PCI_SLOT(pdev->devfn); |
| 675 | bfad->hal_pcidev.pci_func = PCI_FUNC(pdev->devfn); |
| 676 | bfad->hal_pcidev.pci_bar_kva = bfad->pci_bar0_kva; |
| 677 | bfad->hal_pcidev.device_id = pdev->device; |
| 678 | bfad->pci_name = pci_name(pdev); |
| 679 | |
| 680 | bfad->pci_attr.vendor_id = pdev->vendor; |
| 681 | bfad->pci_attr.device_id = pdev->device; |
| 682 | bfad->pci_attr.ssid = pdev->subsystem_device; |
| 683 | bfad->pci_attr.ssvid = pdev->subsystem_vendor; |
| 684 | bfad->pci_attr.pcifn = PCI_FUNC(pdev->devfn); |
| 685 | |
| 686 | bfad->pcidev = pdev; |
| 687 | return 0; |
| 688 | |
| 689 | out_release_region: |
| 690 | pci_release_regions(pdev); |
| 691 | out_disable_device: |
| 692 | pci_disable_device(pdev); |
| 693 | out: |
| 694 | return rc; |
| 695 | } |
| 696 | |
| 697 | void |
| 698 | bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad) |
| 699 | { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 700 | pci_iounmap(pdev, bfad->pci_bar0_kva); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 701 | pci_release_regions(pdev); |
| 702 | pci_disable_device(pdev); |
| 703 | pci_set_drvdata(pdev, NULL); |
| 704 | } |
| 705 | |
| 706 | void |
| 707 | bfad_fcs_port_cfg(struct bfad_s *bfad) |
| 708 | { |
| 709 | struct bfa_port_cfg_s port_cfg; |
| 710 | struct bfa_pport_attr_s attr; |
| 711 | char symname[BFA_SYMNAME_MAXLEN]; |
| 712 | |
| 713 | sprintf(symname, "%s-%d", BFAD_DRIVER_NAME, bfad->inst_no); |
| 714 | memcpy(port_cfg.sym_name.symname, symname, strlen(symname)); |
Krishna Gudipati | 1c8a4c3 | 2010-03-05 19:37:37 -0800 | [diff] [blame] | 715 | bfa_fcport_get_attr(&bfad->bfa, &attr); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 716 | port_cfg.nwwn = attr.nwwn; |
| 717 | port_cfg.pwwn = attr.pwwn; |
| 718 | |
| 719 | bfa_fcs_cfg_base_port(&bfad->bfa_fcs, &port_cfg); |
| 720 | } |
| 721 | |
| 722 | bfa_status_t |
| 723 | bfad_drv_init(struct bfad_s *bfad) |
| 724 | { |
| 725 | bfa_status_t rc; |
| 726 | unsigned long flags; |
| 727 | struct bfa_fcs_driver_info_s driver_info; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 728 | |
| 729 | bfad->cfg_data.rport_del_timeout = rport_del_timeout; |
| 730 | bfad->cfg_data.lun_queue_depth = bfa_lun_queue_depth; |
| 731 | bfad->cfg_data.io_max_sge = bfa_io_max_sge; |
| 732 | bfad->cfg_data.binding_method = FCP_PWWN_BINDING; |
| 733 | |
| 734 | rc = bfad_hal_mem_alloc(bfad); |
| 735 | if (rc != BFA_STATUS_OK) { |
| 736 | printk(KERN_WARNING "bfad%d bfad_hal_mem_alloc failure\n", |
| 737 | bfad->inst_no); |
| 738 | printk(KERN_WARNING |
| 739 | "Not enough memory to attach all Brocade HBA ports," |
| 740 | " System may need more memory.\n"); |
| 741 | goto out_hal_mem_alloc_failure; |
| 742 | } |
| 743 | |
| 744 | bfa_init_log(&bfad->bfa, bfad->logmod); |
| 745 | bfa_init_trc(&bfad->bfa, bfad->trcmod); |
| 746 | bfa_init_aen(&bfad->bfa, bfad->aen); |
Krishna Gudipati | 2993cc7 | 2010-03-05 19:36:47 -0800 | [diff] [blame] | 747 | memset(bfad->file_map, 0, sizeof(bfad->file_map)); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 748 | bfa_init_plog(&bfad->bfa, &bfad->plog_buf); |
| 749 | bfa_plog_init(&bfad->plog_buf); |
| 750 | bfa_plog_str(&bfad->plog_buf, BFA_PL_MID_DRVR, BFA_PL_EID_DRIVER_START, |
| 751 | 0, "Driver Attach"); |
| 752 | |
| 753 | bfa_attach(&bfad->bfa, bfad, &bfad->ioc_cfg, &bfad->meminfo, |
| 754 | &bfad->hal_pcidev); |
| 755 | |
| 756 | init_completion(&bfad->comp); |
| 757 | |
| 758 | /* |
| 759 | * Enable Interrupt and wait bfa_init completion |
| 760 | */ |
| 761 | if (bfad_setup_intr(bfad)) { |
| 762 | printk(KERN_WARNING "bfad%d: bfad_setup_intr failed\n", |
| 763 | bfad->inst_no); |
| 764 | goto out_setup_intr_failure; |
| 765 | } |
| 766 | |
| 767 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 768 | bfa_init(&bfad->bfa); |
| 769 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 770 | |
| 771 | /* |
| 772 | * Set up interrupt handler for each vectors |
| 773 | */ |
| 774 | if ((bfad->bfad_flags & BFAD_MSIX_ON) |
| 775 | && bfad_install_msix_handler(bfad)) { |
| 776 | printk(KERN_WARNING "%s: install_msix failed, bfad%d\n", |
Jing Huang | f8ceafd | 2009-09-25 12:29:54 -0700 | [diff] [blame] | 777 | __func__, bfad->inst_no); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | bfad_init_timer(bfad); |
| 781 | |
| 782 | wait_for_completion(&bfad->comp); |
| 783 | |
| 784 | memset(&driver_info, 0, sizeof(driver_info)); |
| 785 | strncpy(driver_info.version, BFAD_DRIVER_VERSION, |
| 786 | sizeof(driver_info.version) - 1); |
| 787 | if (host_name) |
| 788 | strncpy(driver_info.host_machine_name, host_name, |
| 789 | sizeof(driver_info.host_machine_name) - 1); |
| 790 | if (os_name) |
| 791 | strncpy(driver_info.host_os_name, os_name, |
| 792 | sizeof(driver_info.host_os_name) - 1); |
| 793 | if (os_patch) |
| 794 | strncpy(driver_info.host_os_patch, os_patch, |
| 795 | sizeof(driver_info.host_os_patch) - 1); |
| 796 | |
| 797 | strncpy(driver_info.os_device_name, bfad->pci_name, |
| 798 | sizeof(driver_info.os_device_name - 1)); |
| 799 | |
| 800 | /* |
| 801 | * FCS INIT |
| 802 | */ |
| 803 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 804 | bfa_fcs_log_init(&bfad->bfa_fcs, bfad->logmod); |
| 805 | bfa_fcs_trc_init(&bfad->bfa_fcs, bfad->trcmod); |
| 806 | bfa_fcs_aen_init(&bfad->bfa_fcs, bfad->aen); |
Krishna Gudipati | 82794a2 | 2010-03-03 17:43:30 -0800 | [diff] [blame] | 807 | bfa_fcs_attach(&bfad->bfa_fcs, &bfad->bfa, bfad, BFA_FALSE); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 808 | |
| 809 | /* Do FCS init only when HAL init is done */ |
| 810 | if ((bfad->bfad_flags & BFAD_HAL_INIT_DONE)) { |
| 811 | bfa_fcs_init(&bfad->bfa_fcs); |
| 812 | bfad->bfad_flags |= BFAD_FCS_INIT_DONE; |
| 813 | } |
| 814 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 815 | bfa_fcs_driver_info_init(&bfad->bfa_fcs, &driver_info); |
Krishna Gudipati | 5b09808 | 2010-03-03 17:43:19 -0800 | [diff] [blame] | 816 | bfa_fcs_set_fdmi_param(&bfad->bfa_fcs, fdmi_enable); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 817 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 818 | |
| 819 | bfad->bfad_flags |= BFAD_DRV_INIT_DONE; |
| 820 | return BFA_STATUS_OK; |
| 821 | |
| 822 | out_setup_intr_failure: |
| 823 | bfa_detach(&bfad->bfa); |
| 824 | bfad_hal_mem_release(bfad); |
| 825 | out_hal_mem_alloc_failure: |
| 826 | return BFA_STATUS_FAILED; |
| 827 | } |
| 828 | |
| 829 | void |
| 830 | bfad_drv_uninit(struct bfad_s *bfad) |
| 831 | { |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 832 | unsigned long flags; |
| 833 | |
| 834 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 835 | init_completion(&bfad->comp); |
| 836 | bfa_stop(&bfad->bfa); |
| 837 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 838 | wait_for_completion(&bfad->comp); |
| 839 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 840 | del_timer_sync(&bfad->hal_tmo); |
| 841 | bfa_isr_disable(&bfad->bfa); |
| 842 | bfa_detach(&bfad->bfa); |
| 843 | bfad_remove_intr(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 844 | bfad_hal_mem_release(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 845 | |
| 846 | bfad->bfad_flags &= ~BFAD_DRV_INIT_DONE; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 847 | } |
| 848 | |
| 849 | void |
| 850 | bfad_drv_start(struct bfad_s *bfad) |
| 851 | { |
| 852 | unsigned long flags; |
| 853 | |
| 854 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 855 | bfa_start(&bfad->bfa); |
| 856 | bfa_fcs_start(&bfad->bfa_fcs); |
| 857 | bfad->bfad_flags |= BFAD_HAL_START_DONE; |
| 858 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 859 | |
| 860 | bfad_fc4_probe_post(bfad); |
| 861 | } |
| 862 | |
| 863 | void |
| 864 | bfad_drv_stop(struct bfad_s *bfad) |
| 865 | { |
| 866 | unsigned long flags; |
| 867 | |
| 868 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 869 | init_completion(&bfad->comp); |
| 870 | bfad->pport.flags |= BFAD_PORT_DELETE; |
| 871 | bfa_fcs_exit(&bfad->bfa_fcs); |
| 872 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 873 | wait_for_completion(&bfad->comp); |
| 874 | |
| 875 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 876 | init_completion(&bfad->comp); |
| 877 | bfa_stop(&bfad->bfa); |
| 878 | bfad->bfad_flags &= ~BFAD_HAL_START_DONE; |
| 879 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 880 | wait_for_completion(&bfad->comp); |
| 881 | } |
| 882 | |
| 883 | bfa_status_t |
| 884 | bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role) |
| 885 | { |
| 886 | int rc = BFA_STATUS_OK; |
| 887 | |
| 888 | /* |
| 889 | * Allocate scsi_host for the physical port |
| 890 | */ |
| 891 | if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM) |
| 892 | && (role & BFA_PORT_ROLE_FCP_IM)) { |
| 893 | if (bfad->pport.im_port == NULL) { |
| 894 | rc = BFA_STATUS_FAILED; |
| 895 | goto out; |
| 896 | } |
| 897 | |
Jing Huang | b504293 | 2010-03-19 11:05:39 -0700 | [diff] [blame] | 898 | rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port, |
| 899 | &bfad->pcidev->dev); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 900 | if (rc != BFA_STATUS_OK) |
| 901 | goto out; |
| 902 | |
| 903 | bfad->pport.roles |= BFA_PORT_ROLE_FCP_IM; |
| 904 | } |
| 905 | |
| 906 | bfad->bfad_flags |= BFAD_CFG_PPORT_DONE; |
| 907 | |
| 908 | out: |
| 909 | return rc; |
| 910 | } |
| 911 | |
| 912 | void |
| 913 | bfad_uncfg_pport(struct bfad_s *bfad) |
| 914 | { |
| 915 | if ((bfad->pport.roles & BFA_PORT_ROLE_FCP_IPFC) && ipfc_enable) { |
| 916 | bfad_ipfc_port_delete(bfad, &bfad->pport); |
| 917 | bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IPFC; |
| 918 | } |
| 919 | |
| 920 | if ((bfad_supported_fc4s & BFA_PORT_ROLE_FCP_IM) |
| 921 | && (bfad->pport.roles & BFA_PORT_ROLE_FCP_IM)) { |
| 922 | bfad_im_scsi_host_free(bfad, bfad->pport.im_port); |
| 923 | bfad_im_port_clean(bfad->pport.im_port); |
| 924 | kfree(bfad->pport.im_port); |
| 925 | bfad->pport.roles &= ~BFA_PORT_ROLE_FCP_IM; |
| 926 | } |
| 927 | |
| 928 | bfad->bfad_flags &= ~BFAD_CFG_PPORT_DONE; |
| 929 | } |
| 930 | |
| 931 | void |
| 932 | bfad_drv_log_level_set(struct bfad_s *bfad) |
| 933 | { |
| 934 | if (log_level > BFA_LOG_INVALID && log_level <= BFA_LOG_LEVEL_MAX) |
| 935 | bfa_log_set_level_all(&bfad->log_data, log_level); |
| 936 | } |
| 937 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 938 | bfa_status_t |
| 939 | bfad_start_ops(struct bfad_s *bfad) |
| 940 | { |
| 941 | int retval; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 942 | struct bfad_pcfg_s *pcfg, *pcfg_new; |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 943 | |
| 944 | /* PPORT FCS config */ |
| 945 | bfad_fcs_port_cfg(bfad); |
| 946 | |
| 947 | retval = bfad_cfg_pport(bfad, BFA_PORT_ROLE_FCP_IM); |
| 948 | if (retval != BFA_STATUS_OK) |
| 949 | goto out_cfg_pport_failure; |
| 950 | |
| 951 | /* BFAD level FC4 (IM/TM/IPFC) specific resource allocation */ |
| 952 | retval = bfad_fc4_probe(bfad); |
| 953 | if (retval != BFA_STATUS_OK) { |
| 954 | printk(KERN_WARNING "bfad_fc4_probe failed\n"); |
| 955 | goto out_fc4_probe_failure; |
| 956 | } |
| 957 | |
| 958 | bfad_drv_start(bfad); |
| 959 | |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 960 | /* pbc vport creation */ |
| 961 | list_for_each_entry_safe(pcfg, pcfg_new, &bfad->pbc_pcfg_list, |
| 962 | list_entry) { |
| 963 | struct fc_vport_identifiers vid; |
| 964 | struct fc_vport *fc_vport; |
| 965 | |
| 966 | memset(&vid, 0, sizeof(vid)); |
| 967 | vid.roles = FC_PORT_ROLE_FCP_INITIATOR; |
| 968 | vid.vport_type = FC_PORTTYPE_NPIV; |
| 969 | vid.disable = false; |
| 970 | vid.node_name = wwn_to_u64((u8 *)&pcfg->port_cfg.nwwn); |
| 971 | vid.port_name = wwn_to_u64((u8 *)&pcfg->port_cfg.pwwn); |
| 972 | fc_vport = fc_vport_create(bfad->pport.im_port->shost, 0, &vid); |
| 973 | if (!fc_vport) |
| 974 | printk(KERN_WARNING "bfad%d: failed to create pbc vport" |
| 975 | " %llx\n", bfad->inst_no, vid.port_name); |
| 976 | list_del(&pcfg->list_entry); |
| 977 | kfree(pcfg); |
| 978 | |
| 979 | } |
| 980 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 981 | /* |
| 982 | * If bfa_linkup_delay is set to -1 default; try to retrive the |
| 983 | * value using the bfad_os_get_linkup_delay(); else use the |
| 984 | * passed in module param value as the bfa_linkup_delay. |
| 985 | */ |
| 986 | if (bfa_linkup_delay < 0) { |
| 987 | |
| 988 | bfa_linkup_delay = bfad_os_get_linkup_delay(bfad); |
| 989 | bfad_os_rport_online_wait(bfad); |
| 990 | bfa_linkup_delay = -1; |
| 991 | |
| 992 | } else { |
| 993 | bfad_os_rport_online_wait(bfad); |
| 994 | } |
| 995 | |
| 996 | bfa_log(bfad->logmod, BFA_LOG_LINUX_DEVICE_CLAIMED, bfad->pci_name); |
| 997 | |
| 998 | return BFA_STATUS_OK; |
| 999 | |
| 1000 | out_fc4_probe_failure: |
| 1001 | bfad_fc4_probe_undo(bfad); |
| 1002 | bfad_uncfg_pport(bfad); |
| 1003 | out_cfg_pport_failure: |
| 1004 | return BFA_STATUS_FAILED; |
| 1005 | } |
| 1006 | |
| 1007 | int |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1008 | bfad_worker(void *ptr) |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1009 | { |
| 1010 | struct bfad_s *bfad; |
| 1011 | unsigned long flags; |
| 1012 | |
| 1013 | bfad = (struct bfad_s *)ptr; |
| 1014 | |
| 1015 | while (!kthread_should_stop()) { |
| 1016 | |
| 1017 | /* Check if the FCS init is done from bfad_drv_init; |
| 1018 | * if not done do FCS init and set the flag. |
| 1019 | */ |
| 1020 | if (!(bfad->bfad_flags & BFAD_FCS_INIT_DONE)) { |
| 1021 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1022 | bfa_fcs_init(&bfad->bfa_fcs); |
| 1023 | bfad->bfad_flags |= BFAD_FCS_INIT_DONE; |
| 1024 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1025 | } |
| 1026 | |
| 1027 | /* Start the bfad operations after HAL init done */ |
| 1028 | bfad_start_ops(bfad); |
| 1029 | |
| 1030 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1031 | bfad->bfad_tsk = NULL; |
| 1032 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1033 | |
| 1034 | break; |
| 1035 | } |
| 1036 | |
| 1037 | return 0; |
| 1038 | } |
| 1039 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1040 | /* |
| 1041 | * PCI_entry PCI driver entries * { |
| 1042 | */ |
| 1043 | |
| 1044 | /** |
| 1045 | * PCI probe entry. |
| 1046 | */ |
| 1047 | int |
| 1048 | bfad_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pid) |
| 1049 | { |
| 1050 | struct bfad_s *bfad; |
| 1051 | int error = -ENODEV, retval; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1052 | |
| 1053 | /* |
| 1054 | * For single port cards - only claim function 0 |
| 1055 | */ |
| 1056 | if ((pdev->device == BFA_PCI_DEVICE_ID_FC_8G1P) |
| 1057 | && (PCI_FUNC(pdev->devfn) != 0)) |
| 1058 | return -ENODEV; |
| 1059 | |
| 1060 | BFA_TRACE(BFA_INFO, "bfad_pci_probe entry"); |
| 1061 | |
| 1062 | bfad = kzalloc(sizeof(struct bfad_s), GFP_KERNEL); |
| 1063 | if (!bfad) { |
| 1064 | error = -ENOMEM; |
| 1065 | goto out; |
| 1066 | } |
| 1067 | |
| 1068 | bfad->trcmod = kzalloc(sizeof(struct bfa_trc_mod_s), GFP_KERNEL); |
| 1069 | if (!bfad->trcmod) { |
| 1070 | printk(KERN_WARNING "Error alloc trace buffer!\n"); |
| 1071 | error = -ENOMEM; |
| 1072 | goto out_alloc_trace_failure; |
| 1073 | } |
| 1074 | |
| 1075 | /* |
| 1076 | * LOG/TRACE INIT |
| 1077 | */ |
| 1078 | bfa_trc_init(bfad->trcmod); |
| 1079 | bfa_trc(bfad, bfad_inst); |
| 1080 | |
| 1081 | bfad->logmod = &bfad->log_data; |
Krishna Gudipati | 0a4b1fc | 2010-03-05 19:37:57 -0800 | [diff] [blame] | 1082 | bfa_log_init(bfad->logmod, (char *)pci_name(pdev), bfa_os_printf); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1083 | |
| 1084 | bfad_drv_log_level_set(bfad); |
| 1085 | |
| 1086 | bfad->aen = &bfad->aen_buf; |
| 1087 | |
| 1088 | if (!(bfad_load_fwimg(pdev))) { |
| 1089 | printk(KERN_WARNING "bfad_load_fwimg failure!\n"); |
| 1090 | kfree(bfad->trcmod); |
| 1091 | goto out_alloc_trace_failure; |
| 1092 | } |
| 1093 | |
| 1094 | retval = bfad_pci_init(pdev, bfad); |
| 1095 | if (retval) { |
| 1096 | printk(KERN_WARNING "bfad_pci_init failure!\n"); |
| 1097 | error = retval; |
| 1098 | goto out_pci_init_failure; |
| 1099 | } |
| 1100 | |
| 1101 | mutex_lock(&bfad_mutex); |
| 1102 | bfad->inst_no = bfad_inst++; |
| 1103 | list_add_tail(&bfad->list_entry, &bfad_list); |
| 1104 | mutex_unlock(&bfad_mutex); |
| 1105 | |
| 1106 | spin_lock_init(&bfad->bfad_lock); |
| 1107 | pci_set_drvdata(pdev, bfad); |
| 1108 | |
| 1109 | bfad->ref_count = 0; |
| 1110 | bfad->pport.bfad = bfad; |
Jing Huang | d988354 | 2010-07-08 19:46:26 -0700 | [diff] [blame] | 1111 | INIT_LIST_HEAD(&bfad->pbc_pcfg_list); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1112 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1113 | bfad->bfad_tsk = kthread_create(bfad_worker, (void *) bfad, "%s", |
| 1114 | "bfad_worker"); |
| 1115 | if (IS_ERR(bfad->bfad_tsk)) { |
| 1116 | printk(KERN_INFO "bfad[%d]: Kernel thread" |
| 1117 | " creation failed!\n", |
| 1118 | bfad->inst_no); |
| 1119 | goto out_kthread_create_failure; |
| 1120 | } |
| 1121 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1122 | retval = bfad_drv_init(bfad); |
| 1123 | if (retval != BFA_STATUS_OK) |
| 1124 | goto out_drv_init_failure; |
| 1125 | if (!(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) { |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1126 | bfad->bfad_flags |= BFAD_HAL_INIT_FAIL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1127 | printk(KERN_WARNING "bfad%d: hal init failed\n", bfad->inst_no); |
| 1128 | goto ok; |
| 1129 | } |
| 1130 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1131 | retval = bfad_start_ops(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1132 | if (retval != BFA_STATUS_OK) |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1133 | goto out_start_ops_failure; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1134 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1135 | kthread_stop(bfad->bfad_tsk); |
| 1136 | bfad->bfad_tsk = NULL; |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1137 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1138 | ok: |
| 1139 | return 0; |
| 1140 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1141 | out_start_ops_failure: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1142 | bfad_drv_uninit(bfad); |
| 1143 | out_drv_init_failure: |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1144 | kthread_stop(bfad->bfad_tsk); |
| 1145 | out_kthread_create_failure: |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1146 | mutex_lock(&bfad_mutex); |
| 1147 | bfad_inst--; |
| 1148 | list_del(&bfad->list_entry); |
| 1149 | mutex_unlock(&bfad_mutex); |
| 1150 | bfad_pci_uninit(pdev, bfad); |
| 1151 | out_pci_init_failure: |
| 1152 | kfree(bfad->trcmod); |
| 1153 | out_alloc_trace_failure: |
| 1154 | kfree(bfad); |
| 1155 | out: |
| 1156 | return error; |
| 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * PCI remove entry. |
| 1161 | */ |
| 1162 | void |
| 1163 | bfad_pci_remove(struct pci_dev *pdev) |
| 1164 | { |
| 1165 | struct bfad_s *bfad = pci_get_drvdata(pdev); |
| 1166 | unsigned long flags; |
| 1167 | |
| 1168 | bfa_trc(bfad, bfad->inst_no); |
| 1169 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1170 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1171 | if (bfad->bfad_tsk != NULL) |
| 1172 | kthread_stop(bfad->bfad_tsk); |
| 1173 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1174 | |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1175 | if ((bfad->bfad_flags & BFAD_DRV_INIT_DONE) |
| 1176 | && !(bfad->bfad_flags & BFAD_HAL_INIT_DONE)) { |
| 1177 | |
| 1178 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1179 | init_completion(&bfad->comp); |
| 1180 | bfa_stop(&bfad->bfa); |
| 1181 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1182 | wait_for_completion(&bfad->comp); |
| 1183 | |
| 1184 | bfad_remove_intr(bfad); |
| 1185 | del_timer_sync(&bfad->hal_tmo); |
| 1186 | goto hal_detach; |
| 1187 | } else if (!(bfad->bfad_flags & BFAD_DRV_INIT_DONE)) { |
| 1188 | goto remove_sysfs; |
| 1189 | } |
| 1190 | |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1191 | if (bfad->bfad_flags & BFAD_HAL_START_DONE) { |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1192 | bfad_drv_stop(bfad); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1193 | } else if (bfad->bfad_flags & BFAD_DRV_INIT_DONE) { |
| 1194 | /* Invoking bfa_stop() before bfa_detach |
| 1195 | * when HAL and DRV init are success |
| 1196 | * but HAL start did not occur. |
| 1197 | */ |
| 1198 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1199 | init_completion(&bfad->comp); |
| 1200 | bfa_stop(&bfad->bfa); |
| 1201 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1202 | wait_for_completion(&bfad->comp); |
| 1203 | } |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1204 | |
| 1205 | bfad_remove_intr(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1206 | del_timer_sync(&bfad->hal_tmo); |
Krishna Gudipati | e671432 | 2010-03-03 17:44:02 -0800 | [diff] [blame] | 1207 | |
| 1208 | if (bfad->bfad_flags & BFAD_FC4_PROBE_DONE) |
| 1209 | bfad_fc4_probe_undo(bfad); |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1210 | |
| 1211 | if (bfad->bfad_flags & BFAD_CFG_PPORT_DONE) |
| 1212 | bfad_uncfg_pport(bfad); |
| 1213 | |
| 1214 | hal_detach: |
| 1215 | spin_lock_irqsave(&bfad->bfad_lock, flags); |
| 1216 | bfa_detach(&bfad->bfa); |
| 1217 | spin_unlock_irqrestore(&bfad->bfad_lock, flags); |
| 1218 | bfad_hal_mem_release(bfad); |
| 1219 | remove_sysfs: |
| 1220 | |
| 1221 | mutex_lock(&bfad_mutex); |
| 1222 | bfad_inst--; |
| 1223 | list_del(&bfad->list_entry); |
| 1224 | mutex_unlock(&bfad_mutex); |
| 1225 | bfad_pci_uninit(pdev, bfad); |
| 1226 | |
| 1227 | kfree(bfad->trcmod); |
| 1228 | kfree(bfad); |
| 1229 | } |
| 1230 | |
| 1231 | |
| 1232 | static struct pci_device_id bfad_id_table[] = { |
| 1233 | { |
| 1234 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1235 | .device = BFA_PCI_DEVICE_ID_FC_8G2P, |
| 1236 | .subvendor = PCI_ANY_ID, |
| 1237 | .subdevice = PCI_ANY_ID, |
| 1238 | }, |
| 1239 | { |
| 1240 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1241 | .device = BFA_PCI_DEVICE_ID_FC_8G1P, |
| 1242 | .subvendor = PCI_ANY_ID, |
| 1243 | .subdevice = PCI_ANY_ID, |
| 1244 | }, |
| 1245 | { |
| 1246 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1247 | .device = BFA_PCI_DEVICE_ID_CT, |
| 1248 | .subvendor = PCI_ANY_ID, |
| 1249 | .subdevice = PCI_ANY_ID, |
| 1250 | .class = (PCI_CLASS_SERIAL_FIBER << 8), |
| 1251 | .class_mask = ~0, |
| 1252 | }, |
Jing Huang | 293f82d | 2010-07-08 19:45:20 -0700 | [diff] [blame] | 1253 | { |
| 1254 | .vendor = BFA_PCI_VENDOR_ID_BROCADE, |
| 1255 | .device = BFA_PCI_DEVICE_ID_CT_FC, |
| 1256 | .subvendor = PCI_ANY_ID, |
| 1257 | .subdevice = PCI_ANY_ID, |
| 1258 | .class = (PCI_CLASS_SERIAL_FIBER << 8), |
| 1259 | .class_mask = ~0, |
| 1260 | }, |
Jing Huang | 7725ccf | 2009-09-23 17:46:15 -0700 | [diff] [blame] | 1261 | |
| 1262 | {0, 0}, |
| 1263 | }; |
| 1264 | |
| 1265 | MODULE_DEVICE_TABLE(pci, bfad_id_table); |
| 1266 | |
| 1267 | static struct pci_driver bfad_pci_driver = { |
| 1268 | .name = BFAD_DRIVER_NAME, |
| 1269 | .id_table = bfad_id_table, |
| 1270 | .probe = bfad_pci_probe, |
| 1271 | .remove = __devexit_p(bfad_pci_remove), |
| 1272 | }; |
| 1273 | |
| 1274 | /** |
| 1275 | * Linux driver module functions |
| 1276 | */ |
| 1277 | bfa_status_t |
| 1278 | bfad_fc4_module_init(void) |
| 1279 | { |
| 1280 | int rc; |
| 1281 | |
| 1282 | rc = bfad_im_module_init(); |
| 1283 | if (rc != BFA_STATUS_OK) |
| 1284 | goto ext; |
| 1285 | |
| 1286 | bfad_tm_module_init(); |
| 1287 | if (ipfc_enable) |
| 1288 | bfad_ipfc_module_init(); |
| 1289 | ext: |
| 1290 | return rc; |
| 1291 | } |
| 1292 | |
| 1293 | void |
| 1294 | bfad_fc4_module_exit(void) |
| 1295 | { |
| 1296 | if (ipfc_enable) |
| 1297 | bfad_ipfc_module_exit(); |
| 1298 | bfad_tm_module_exit(); |
| 1299 | bfad_im_module_exit(); |
| 1300 | } |
| 1301 | |
| 1302 | /** |
| 1303 | * Driver module init. |
| 1304 | */ |
| 1305 | static int __init |
| 1306 | bfad_init(void) |
| 1307 | { |
| 1308 | int error = 0; |
| 1309 | |
| 1310 | printk(KERN_INFO "Brocade BFA FC/FCOE SCSI driver - version: %s\n", |
| 1311 | BFAD_DRIVER_VERSION); |
| 1312 | |
| 1313 | if (num_sgpgs > 0) |
| 1314 | num_sgpgs_parm = num_sgpgs; |
| 1315 | |
| 1316 | error = bfad_fc4_module_init(); |
| 1317 | if (error) { |
| 1318 | error = -ENOMEM; |
| 1319 | printk(KERN_WARNING "bfad_fc4_module_init failure\n"); |
| 1320 | goto ext; |
| 1321 | } |
| 1322 | |
| 1323 | if (!strcmp(FCPI_NAME, " fcpim")) |
| 1324 | bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IM; |
| 1325 | if (!strcmp(FCPT_NAME, " fcptm")) |
| 1326 | bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_TM; |
| 1327 | if (!strcmp(IPFC_NAME, " ipfc")) |
| 1328 | bfad_supported_fc4s |= BFA_PORT_ROLE_FCP_IPFC; |
| 1329 | |
| 1330 | bfa_ioc_auto_recover(ioc_auto_recover); |
| 1331 | bfa_fcs_rport_set_del_timeout(rport_del_timeout); |
| 1332 | error = pci_register_driver(&bfad_pci_driver); |
| 1333 | |
| 1334 | if (error) { |
| 1335 | printk(KERN_WARNING "bfad pci_register_driver failure\n"); |
| 1336 | goto ext; |
| 1337 | } |
| 1338 | |
| 1339 | return 0; |
| 1340 | |
| 1341 | ext: |
| 1342 | bfad_fc4_module_exit(); |
| 1343 | return error; |
| 1344 | } |
| 1345 | |
| 1346 | /** |
| 1347 | * Driver module exit. |
| 1348 | */ |
| 1349 | static void __exit |
| 1350 | bfad_exit(void) |
| 1351 | { |
| 1352 | pci_unregister_driver(&bfad_pci_driver); |
| 1353 | bfad_fc4_module_exit(); |
| 1354 | bfad_free_fwimg(); |
| 1355 | } |
| 1356 | |
| 1357 | #define BFAD_PROTO_NAME FCPI_NAME FCPT_NAME IPFC_NAME |
| 1358 | |
| 1359 | module_init(bfad_init); |
| 1360 | module_exit(bfad_exit); |
| 1361 | MODULE_LICENSE("GPL"); |
| 1362 | MODULE_DESCRIPTION("Brocade Fibre Channel HBA Driver" BFAD_PROTO_NAME); |
| 1363 | MODULE_AUTHOR("Brocade Communications Systems, Inc."); |
| 1364 | MODULE_VERSION(BFAD_DRIVER_VERSION); |
| 1365 | |
| 1366 | |