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