aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/bfa
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/bfa')
-rw-r--r--drivers/scsi/bfa/bfa_cb_ioim_macros.h29
-rw-r--r--drivers/scsi/bfa/bfa_ioim.c22
-rw-r--r--drivers/scsi/bfa/bfa_os_inc.h23
-rw-r--r--drivers/scsi/bfa/bfad.c21
-rw-r--r--drivers/scsi/bfa/bfad_attr.c201
-rw-r--r--drivers/scsi/bfa/bfad_drv.h4
-rw-r--r--drivers/scsi/bfa/bfad_im.c67
-rw-r--r--drivers/scsi/bfa/bfad_im.h6
8 files changed, 287 insertions, 86 deletions
diff --git a/drivers/scsi/bfa/bfa_cb_ioim_macros.h b/drivers/scsi/bfa/bfa_cb_ioim_macros.h
index 961fe439daad..53a616f5f50d 100644
--- a/drivers/scsi/bfa/bfa_cb_ioim_macros.h
+++ b/drivers/scsi/bfa/bfa_cb_ioim_macros.h
@@ -117,35 +117,6 @@ bfa_cb_ioim_get_timeout(struct bfad_ioim_s *dio)
117} 117}
118 118
119/** 119/**
120 * Get SG element for the I/O request given the SG element index
121 */
122static inline union bfi_addr_u
123bfa_cb_ioim_get_sgaddr(struct bfad_ioim_s *dio, int sgeid)
124{
125 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
126 struct scatterlist *sge;
127 u64 addr;
128
129 sge = (struct scatterlist *)scsi_sglist(cmnd) + sgeid;
130 addr = (u64) sg_dma_address(sge);
131
132 return *((union bfi_addr_u *) &addr);
133}
134
135static inline u32
136bfa_cb_ioim_get_sglen(struct bfad_ioim_s *dio, int sgeid)
137{
138 struct scsi_cmnd *cmnd = (struct scsi_cmnd *)dio;
139 struct scatterlist *sge;
140 u32 len;
141
142 sge = (struct scatterlist *)scsi_sglist(cmnd) + sgeid;
143 len = sg_dma_len(sge);
144
145 return len;
146}
147
148/**
149 * Get Command Reference Number for the I/O request. 0 if none. 120 * Get Command Reference Number for the I/O request. 0 if none.
150 */ 121 */
151static inline u8 122static inline u8
diff --git a/drivers/scsi/bfa/bfa_ioim.c b/drivers/scsi/bfa/bfa_ioim.c
index 5b107abe46e5..687f3d6e252b 100644
--- a/drivers/scsi/bfa/bfa_ioim.c
+++ b/drivers/scsi/bfa/bfa_ioim.c
@@ -731,6 +731,9 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
731 static struct fcp_cmnd_s cmnd_z0 = { 0 }; 731 static struct fcp_cmnd_s cmnd_z0 = { 0 };
732 struct bfi_sge_s *sge; 732 struct bfi_sge_s *sge;
733 u32 pgdlen = 0; 733 u32 pgdlen = 0;
734 u64 addr;
735 struct scatterlist *sg;
736 struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
734 737
735 /** 738 /**
736 * check for room in queue to send request now 739 * check for room in queue to send request now
@@ -754,8 +757,10 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
754 */ 757 */
755 sge = &m->sges[0]; 758 sge = &m->sges[0];
756 if (ioim->nsges) { 759 if (ioim->nsges) {
757 sge->sga = bfa_cb_ioim_get_sgaddr(ioim->dio, 0); 760 sg = (struct scatterlist *)scsi_sglist(cmnd);
758 pgdlen = bfa_cb_ioim_get_sglen(ioim->dio, 0); 761 addr = bfa_os_sgaddr(sg_dma_address(sg));
762 sge->sga = *(union bfi_addr_u *) &addr;
763 pgdlen = sg_dma_len(sg);
759 sge->sg_len = pgdlen; 764 sge->sg_len = pgdlen;
760 sge->flags = (ioim->nsges > BFI_SGE_INLINE) ? 765 sge->flags = (ioim->nsges > BFI_SGE_INLINE) ?
761 BFI_SGE_DATA_CPL : BFI_SGE_DATA_LAST; 766 BFI_SGE_DATA_CPL : BFI_SGE_DATA_LAST;
@@ -868,10 +873,16 @@ bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim)
868 struct bfi_sge_s *sge; 873 struct bfi_sge_s *sge;
869 struct bfa_sgpg_s *sgpg; 874 struct bfa_sgpg_s *sgpg;
870 u32 pgcumsz; 875 u32 pgcumsz;
876 u64 addr;
877 struct scatterlist *sg;
878 struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
871 879
872 sgeid = BFI_SGE_INLINE; 880 sgeid = BFI_SGE_INLINE;
873 ioim->sgpg = sgpg = bfa_q_first(&ioim->sgpg_q); 881 ioim->sgpg = sgpg = bfa_q_first(&ioim->sgpg_q);
874 882
883 sg = scsi_sglist(cmnd);
884 sg = sg_next(sg);
885
875 do { 886 do {
876 sge = sgpg->sgpg->sges; 887 sge = sgpg->sgpg->sges;
877 nsges = ioim->nsges - sgeid; 888 nsges = ioim->nsges - sgeid;
@@ -879,9 +890,10 @@ bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim)
879 nsges = BFI_SGPG_DATA_SGES; 890 nsges = BFI_SGPG_DATA_SGES;
880 891
881 pgcumsz = 0; 892 pgcumsz = 0;
882 for (i = 0; i < nsges; i++, sge++, sgeid++) { 893 for (i = 0; i < nsges; i++, sge++, sgeid++, sg = sg_next(sg)) {
883 sge->sga = bfa_cb_ioim_get_sgaddr(ioim->dio, sgeid); 894 addr = bfa_os_sgaddr(sg_dma_address(sg));
884 sge->sg_len = bfa_cb_ioim_get_sglen(ioim->dio, sgeid); 895 sge->sga = *(union bfi_addr_u *) &addr;
896 sge->sg_len = sg_dma_len(sg);
885 pgcumsz += sge->sg_len; 897 pgcumsz += sge->sg_len;
886 898
887 /** 899 /**
diff --git a/drivers/scsi/bfa/bfa_os_inc.h b/drivers/scsi/bfa/bfa_os_inc.h
index 10a89f75fa94..bd1cd3ee3022 100644
--- a/drivers/scsi/bfa/bfa_os_inc.h
+++ b/drivers/scsi/bfa/bfa_os_inc.h
@@ -50,6 +50,10 @@
50#include <scsi/scsi_transport_fc.h> 50#include <scsi/scsi_transport_fc.h>
51#include <scsi/scsi_transport.h> 51#include <scsi/scsi_transport.h>
52 52
53#ifdef __BIG_ENDIAN
54#define __BIGENDIAN
55#endif
56
53#define BFA_ERR KERN_ERR 57#define BFA_ERR KERN_ERR
54#define BFA_WARNING KERN_WARNING 58#define BFA_WARNING KERN_WARNING
55#define BFA_NOTICE KERN_NOTICE 59#define BFA_NOTICE KERN_NOTICE
@@ -123,6 +127,15 @@ int bfa_os_MWB(void *);
123 (((_x) & 0x00ff0000) >> 8) | \ 127 (((_x) & 0x00ff0000) >> 8) | \
124 (((_x) & 0xff000000) >> 24)) 128 (((_x) & 0xff000000) >> 24))
125 129
130#define bfa_os_swap_sgaddr(_x) ((u64)( \
131 (((u64)(_x) & (u64)0x00000000000000ffull) << 32) | \
132 (((u64)(_x) & (u64)0x000000000000ff00ull) << 32) | \
133 (((u64)(_x) & (u64)0x0000000000ff0000ull) << 32) | \
134 (((u64)(_x) & (u64)0x00000000ff000000ull) << 32) | \
135 (((u64)(_x) & (u64)0x000000ff00000000ull) >> 32) | \
136 (((u64)(_x) & (u64)0x0000ff0000000000ull) >> 32) | \
137 (((u64)(_x) & (u64)0x00ff000000000000ull) >> 32) | \
138 (((u64)(_x) & (u64)0xff00000000000000ull) >> 32)))
126 139
127#ifndef __BIGENDIAN 140#ifndef __BIGENDIAN
128#define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \ 141#define bfa_os_htons(_x) ((u16)((((_x) & 0xff00) >> 8) | \
@@ -133,6 +146,7 @@ int bfa_os_MWB(void *);
133#define bfa_os_hton3b(_x) bfa_swap_3b(_x) 146#define bfa_os_hton3b(_x) bfa_swap_3b(_x)
134 147
135#define bfa_os_wtole(_x) (_x) 148#define bfa_os_wtole(_x) (_x)
149#define bfa_os_sgaddr(_x) (_x)
136 150
137#else 151#else
138 152
@@ -141,6 +155,7 @@ int bfa_os_MWB(void *);
141#define bfa_os_hton3b(_x) (_x) 155#define bfa_os_hton3b(_x) (_x)
142#define bfa_os_htonll(_x) (_x) 156#define bfa_os_htonll(_x) (_x)
143#define bfa_os_wtole(_x) bfa_os_swap32(_x) 157#define bfa_os_wtole(_x) bfa_os_swap32(_x)
158#define bfa_os_sgaddr(_x) bfa_os_swap_sgaddr(_x)
144 159
145#endif 160#endif
146 161
@@ -161,12 +176,12 @@ int bfa_os_MWB(void *);
161#define bfa_os_addr_t char __iomem * 176#define bfa_os_addr_t char __iomem *
162#define bfa_os_panic() 177#define bfa_os_panic()
163 178
164#define bfa_os_reg_read(_raddr) bfa_os_wtole(readl(_raddr)) 179#define bfa_os_reg_read(_raddr) readl(_raddr)
165#define bfa_os_reg_write(_raddr, _val) writel(bfa_os_wtole((_val)), (_raddr)) 180#define bfa_os_reg_write(_raddr, _val) writel((_val), (_raddr))
166#define bfa_os_mem_read(_raddr, _off) \ 181#define bfa_os_mem_read(_raddr, _off) \
167 bfa_os_ntohl(readl(((_raddr) + (_off)))) 182 bfa_os_swap32(readl(((_raddr) + (_off))))
168#define bfa_os_mem_write(_raddr, _off, _val) \ 183#define bfa_os_mem_write(_raddr, _off, _val) \
169 writel(bfa_os_htonl((_val)), ((_raddr) + (_off))) 184 writel(bfa_os_swap32((_val)), ((_raddr) + (_off)))
170 185
171#define BFA_TRC_TS(_trcm) \ 186#define BFA_TRC_TS(_trcm) \
172 ({ \ 187 ({ \
diff --git a/drivers/scsi/bfa/bfad.c b/drivers/scsi/bfa/bfad.c
index 13f5feb308c2..d4fc4287ebd3 100644
--- a/drivers/scsi/bfa/bfad.c
+++ b/drivers/scsi/bfa/bfad.c
@@ -33,7 +33,7 @@
33#include <fcb/bfa_fcb.h> 33#include <fcb/bfa_fcb.h>
34 34
35BFA_TRC_FILE(LDRV, BFAD); 35BFA_TRC_FILE(LDRV, BFAD);
36static DEFINE_MUTEX(bfad_mutex); 36DEFINE_MUTEX(bfad_mutex);
37LIST_HEAD(bfad_list); 37LIST_HEAD(bfad_list);
38static int bfad_inst; 38static int bfad_inst;
39int bfad_supported_fc4s; 39int bfad_supported_fc4s;
@@ -299,8 +299,6 @@ bfa_fcb_vport_delete(struct bfad_vport_s *vport_drv)
299 complete(vport_drv->comp_del); 299 complete(vport_drv->comp_del);
300 return; 300 return;
301 } 301 }
302
303 kfree(vport_drv);
304} 302}
305 303
306/** 304/**
@@ -483,7 +481,7 @@ ext:
483 */ 481 */
484bfa_status_t 482bfa_status_t
485bfad_vport_create(struct bfad_s *bfad, u16 vf_id, 483bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
486 struct bfa_port_cfg_s *port_cfg) 484 struct bfa_port_cfg_s *port_cfg, struct device *dev)
487{ 485{
488 struct bfad_vport_s *vport; 486 struct bfad_vport_s *vport;
489 int rc = BFA_STATUS_OK; 487 int rc = BFA_STATUS_OK;
@@ -506,7 +504,8 @@ bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
506 goto ext_free_vport; 504 goto ext_free_vport;
507 505
508 if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) { 506 if (port_cfg->roles & BFA_PORT_ROLE_FCP_IM) {
509 rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port); 507 rc = bfad_im_scsi_host_alloc(bfad, vport->drv_port.im_port,
508 dev);
510 if (rc != BFA_STATUS_OK) 509 if (rc != BFA_STATUS_OK)
511 goto ext_free_fcs_vport; 510 goto ext_free_fcs_vport;
512 } 511 }
@@ -591,7 +590,6 @@ bfad_init_timer(struct bfad_s *bfad)
591int 590int
592bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad) 591bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
593{ 592{
594 unsigned long bar0_len;
595 int rc = -ENODEV; 593 int rc = -ENODEV;
596 594
597 if (pci_enable_device(pdev)) { 595 if (pci_enable_device(pdev)) {
@@ -611,9 +609,7 @@ bfad_pci_init(struct pci_dev *pdev, struct bfad_s *bfad)
611 goto out_release_region; 609 goto out_release_region;
612 } 610 }
613 611
614 bfad->pci_bar0_map = pci_resource_start(pdev, 0); 612 bfad->pci_bar0_kva = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
615 bar0_len = pci_resource_len(pdev, 0);
616 bfad->pci_bar0_kva = ioremap(bfad->pci_bar0_map, bar0_len);
617 613
618 if (bfad->pci_bar0_kva == NULL) { 614 if (bfad->pci_bar0_kva == NULL) {
619 BFA_PRINTF(BFA_ERR, "Fail to map bar0\n"); 615 BFA_PRINTF(BFA_ERR, "Fail to map bar0\n");
@@ -646,11 +642,7 @@ out:
646void 642void
647bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad) 643bfad_pci_uninit(struct pci_dev *pdev, struct bfad_s *bfad)
648{ 644{
649#if defined(__ia64__)
650 pci_iounmap(pdev, bfad->pci_bar0_kva); 645 pci_iounmap(pdev, bfad->pci_bar0_kva);
651#else
652 iounmap(bfad->pci_bar0_kva);
653#endif
654 pci_release_regions(pdev); 646 pci_release_regions(pdev);
655 pci_disable_device(pdev); 647 pci_disable_device(pdev);
656 pci_set_drvdata(pdev, NULL); 648 pci_set_drvdata(pdev, NULL);
@@ -848,7 +840,8 @@ bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role)
848 goto out; 840 goto out;
849 } 841 }
850 842
851 rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port); 843 rc = bfad_im_scsi_host_alloc(bfad, bfad->pport.im_port,
844 &bfad->pcidev->dev);
852 if (rc != BFA_STATUS_OK) 845 if (rc != BFA_STATUS_OK)
853 goto out; 846 goto out;
854 847
diff --git a/drivers/scsi/bfa/bfad_attr.c b/drivers/scsi/bfa/bfad_attr.c
index 6a2efdd5ef24..e477bfbfa7d8 100644
--- a/drivers/scsi/bfa/bfad_attr.c
+++ b/drivers/scsi/bfa/bfad_attr.c
@@ -364,6 +364,152 @@ bfad_im_set_rport_loss_tmo(struct fc_rport *rport, u32 timeout)
364 364
365} 365}
366 366
367static int
368bfad_im_vport_create(struct fc_vport *fc_vport, bool disable)
369{
370 char *vname = fc_vport->symbolic_name;
371 struct Scsi_Host *shost = fc_vport->shost;
372 struct bfad_im_port_s *im_port =
373 (struct bfad_im_port_s *) shost->hostdata[0];
374 struct bfad_s *bfad = im_port->bfad;
375 struct bfa_port_cfg_s port_cfg;
376 int status = 0, rc;
377 unsigned long flags;
378
379 memset(&port_cfg, 0, sizeof(port_cfg));
380
381 port_cfg.pwwn = wwn_to_u64((u8 *) &fc_vport->port_name);
382 port_cfg.nwwn = wwn_to_u64((u8 *) &fc_vport->node_name);
383
384 if (strlen(vname) > 0)
385 strcpy((char *)&port_cfg.sym_name, vname);
386
387 port_cfg.roles = BFA_PORT_ROLE_FCP_IM;
388 rc = bfad_vport_create(bfad, 0, &port_cfg, &fc_vport->dev);
389
390 if (rc == BFA_STATUS_OK) {
391 struct bfad_vport_s *vport;
392 struct bfa_fcs_vport_s *fcs_vport;
393 struct Scsi_Host *vshost;
394
395 spin_lock_irqsave(&bfad->bfad_lock, flags);
396 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0,
397 port_cfg.pwwn);
398 if (fcs_vport == NULL) {
399 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
400 return VPCERR_BAD_WWN;
401 }
402
403 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
404 if (disable) {
405 bfa_fcs_vport_stop(fcs_vport);
406 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
407 }
408 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
409
410 vport = fcs_vport->vport_drv;
411 vshost = vport->drv_port.im_port->shost;
412 fc_host_node_name(vshost) = wwn_to_u64((u8 *) &port_cfg.nwwn);
413 fc_host_port_name(vshost) = wwn_to_u64((u8 *) &port_cfg.pwwn);
414 fc_vport->dd_data = vport;
415 vport->drv_port.im_port->fc_vport = fc_vport;
416
417 } else if (rc == BFA_STATUS_INVALID_WWN)
418 return VPCERR_BAD_WWN;
419 else if (rc == BFA_STATUS_VPORT_EXISTS)
420 return VPCERR_BAD_WWN;
421 else if (rc == BFA_STATUS_VPORT_MAX)
422 return VPCERR_NO_FABRIC_SUPP;
423 else if (rc == BFA_STATUS_VPORT_WWN_BP)
424 return VPCERR_BAD_WWN;
425 else
426 return FC_VPORT_FAILED;
427
428 return status;
429}
430
431static int
432bfad_im_vport_delete(struct fc_vport *fc_vport)
433{
434 struct bfad_vport_s *vport = (struct bfad_vport_s *)fc_vport->dd_data;
435 struct bfad_im_port_s *im_port =
436 (struct bfad_im_port_s *) vport->drv_port.im_port;
437 struct bfad_s *bfad = im_port->bfad;
438 struct bfad_port_s *port;
439 struct bfa_fcs_vport_s *fcs_vport;
440 struct Scsi_Host *vshost;
441 wwn_t pwwn;
442 int rc;
443 unsigned long flags;
444 struct completion fcomp;
445
446 if (im_port->flags & BFAD_PORT_DELETE)
447 goto free_scsi_host;
448
449 port = im_port->port;
450
451 vshost = vport->drv_port.im_port->shost;
452 pwwn = wwn_to_u64((u8 *) &fc_host_port_name(vshost));
453
454 spin_lock_irqsave(&bfad->bfad_lock, flags);
455 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
456 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
457
458 if (fcs_vport == NULL)
459 return VPCERR_BAD_WWN;
460
461 vport->drv_port.flags |= BFAD_PORT_DELETE;
462
463 vport->comp_del = &fcomp;
464 init_completion(vport->comp_del);
465
466 spin_lock_irqsave(&bfad->bfad_lock, flags);
467 rc = bfa_fcs_vport_delete(&vport->fcs_vport);
468 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
469
470 wait_for_completion(vport->comp_del);
471
472free_scsi_host:
473 bfad_os_scsi_host_free(bfad, im_port);
474
475 kfree(vport);
476
477 return 0;
478}
479
480static int
481bfad_im_vport_disable(struct fc_vport *fc_vport, bool disable)
482{
483 struct bfad_vport_s *vport;
484 struct bfad_s *bfad;
485 struct bfa_fcs_vport_s *fcs_vport;
486 struct Scsi_Host *vshost;
487 wwn_t pwwn;
488 unsigned long flags;
489
490 vport = (struct bfad_vport_s *)fc_vport->dd_data;
491 bfad = vport->drv_port.bfad;
492 vshost = vport->drv_port.im_port->shost;
493 pwwn = wwn_to_u64((u8 *) &fc_vport->port_name);
494
495 spin_lock_irqsave(&bfad->bfad_lock, flags);
496 fcs_vport = bfa_fcs_vport_lookup(&bfad->bfa_fcs, 0, pwwn);
497 spin_unlock_irqrestore(&bfad->bfad_lock, flags);
498
499 if (fcs_vport == NULL)
500 return VPCERR_BAD_WWN;
501
502 if (disable) {
503 bfa_fcs_vport_stop(fcs_vport);
504 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
505 } else {
506 bfa_fcs_vport_start(fcs_vport);
507 fc_vport_set_state(fc_vport, FC_VPORT_ACTIVE);
508 }
509
510 return 0;
511}
512
367struct fc_function_template bfad_im_fc_function_template = { 513struct fc_function_template bfad_im_fc_function_template = {
368 514
369 /* Target dynamic attributes */ 515 /* Target dynamic attributes */
@@ -413,6 +559,61 @@ struct fc_function_template bfad_im_fc_function_template = {
413 .show_rport_dev_loss_tmo = 1, 559 .show_rport_dev_loss_tmo = 1,
414 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo, 560 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
415 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo, 561 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
562
563 .vport_create = bfad_im_vport_create,
564 .vport_delete = bfad_im_vport_delete,
565 .vport_disable = bfad_im_vport_disable,
566};
567
568struct fc_function_template bfad_im_vport_fc_function_template = {
569
570 /* Target dynamic attributes */
571 .get_starget_port_id = bfad_im_get_starget_port_id,
572 .show_starget_port_id = 1,
573 .get_starget_node_name = bfad_im_get_starget_node_name,
574 .show_starget_node_name = 1,
575 .get_starget_port_name = bfad_im_get_starget_port_name,
576 .show_starget_port_name = 1,
577
578 /* Host dynamic attribute */
579 .get_host_port_id = bfad_im_get_host_port_id,
580 .show_host_port_id = 1,
581
582 /* Host fixed attributes */
583 .show_host_node_name = 1,
584 .show_host_port_name = 1,
585 .show_host_supported_classes = 1,
586 .show_host_supported_fc4s = 1,
587 .show_host_supported_speeds = 1,
588 .show_host_maxframe_size = 1,
589
590 /* More host dynamic attributes */
591 .show_host_port_type = 1,
592 .get_host_port_type = bfad_im_get_host_port_type,
593 .show_host_port_state = 1,
594 .get_host_port_state = bfad_im_get_host_port_state,
595 .show_host_active_fc4s = 1,
596 .get_host_active_fc4s = bfad_im_get_host_active_fc4s,
597 .show_host_speed = 1,
598 .get_host_speed = bfad_im_get_host_speed,
599 .show_host_fabric_name = 1,
600 .get_host_fabric_name = bfad_im_get_host_fabric_name,
601
602 .show_host_symbolic_name = 1,
603
604 /* Statistics */
605 .get_fc_host_stats = bfad_im_get_stats,
606 .reset_fc_host_stats = bfad_im_reset_stats,
607
608 /* Allocation length for host specific data */
609 .dd_fcrport_size = sizeof(struct bfad_itnim_data_s *),
610
611 /* Remote port fixed attributes */
612 .show_rport_maxframe_size = 1,
613 .show_rport_supported_classes = 1,
614 .show_rport_dev_loss_tmo = 1,
615 .get_rport_dev_loss_tmo = bfad_im_get_rport_loss_tmo,
616 .set_rport_dev_loss_tmo = bfad_im_set_rport_loss_tmo,
416}; 617};
417 618
418/** 619/**
diff --git a/drivers/scsi/bfa/bfad_drv.h b/drivers/scsi/bfa/bfad_drv.h
index 107848cd3b6d..6c920c1b53a4 100644
--- a/drivers/scsi/bfa/bfad_drv.h
+++ b/drivers/scsi/bfa/bfad_drv.h
@@ -162,7 +162,6 @@ struct bfad_s {
162 const char *pci_name; 162 const char *pci_name;
163 struct bfa_pcidev_s hal_pcidev; 163 struct bfa_pcidev_s hal_pcidev;
164 struct bfa_ioc_pci_attr_s pci_attr; 164 struct bfa_ioc_pci_attr_s pci_attr;
165 unsigned long pci_bar0_map;
166 void __iomem *pci_bar0_kva; 165 void __iomem *pci_bar0_kva;
167 struct completion comp; 166 struct completion comp;
168 struct completion suspend; 167 struct completion suspend;
@@ -254,7 +253,7 @@ do { \
254 253
255 254
256bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id, 255bfa_status_t bfad_vport_create(struct bfad_s *bfad, u16 vf_id,
257 struct bfa_port_cfg_s *port_cfg); 256 struct bfa_port_cfg_s *port_cfg, struct device *dev);
258bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id, 257bfa_status_t bfad_vf_create(struct bfad_s *bfad, u16 vf_id,
259 struct bfa_port_cfg_s *port_cfg); 258 struct bfa_port_cfg_s *port_cfg);
260bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role); 259bfa_status_t bfad_cfg_pport(struct bfad_s *bfad, enum bfa_port_role role);
@@ -294,5 +293,6 @@ extern struct list_head bfad_list;
294extern int bfa_lun_queue_depth; 293extern int bfa_lun_queue_depth;
295extern int bfad_supported_fc4s; 294extern int bfad_supported_fc4s;
296extern int bfa_linkup_delay; 295extern int bfa_linkup_delay;
296extern struct mutex bfad_mutex;
297 297
298#endif /* __BFAD_DRV_H__ */ 298#endif /* __BFAD_DRV_H__ */
diff --git a/drivers/scsi/bfa/bfad_im.c b/drivers/scsi/bfa/bfad_im.c
index 78f42aa57369..5b7cf539e50b 100644
--- a/drivers/scsi/bfa/bfad_im.c
+++ b/drivers/scsi/bfa/bfad_im.c
@@ -30,6 +30,7 @@ BFA_TRC_FILE(LDRV, IM);
30 30
31DEFINE_IDR(bfad_im_port_index); 31DEFINE_IDR(bfad_im_port_index);
32struct scsi_transport_template *bfad_im_scsi_transport_template; 32struct scsi_transport_template *bfad_im_scsi_transport_template;
33struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
33static void bfad_im_itnim_work_handler(struct work_struct *work); 34static void bfad_im_itnim_work_handler(struct work_struct *work);
34static int bfad_im_queuecommand(struct scsi_cmnd *cmnd, 35static int bfad_im_queuecommand(struct scsi_cmnd *cmnd,
35 void (*done)(struct scsi_cmnd *)); 36 void (*done)(struct scsi_cmnd *));
@@ -252,7 +253,6 @@ bfad_im_target_reset_send(struct bfad_s *bfad, struct scsi_cmnd *cmnd,
252 struct bfa_itnim_s *bfa_itnim; 253 struct bfa_itnim_s *bfa_itnim;
253 bfa_status_t rc = BFA_STATUS_OK; 254 bfa_status_t rc = BFA_STATUS_OK;
254 255
255 bfa_itnim = bfa_fcs_itnim_get_halitn(&itnim->fcs_itnim);
256 tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd); 256 tskim = bfa_tskim_alloc(&bfad->bfa, (struct bfad_tskim_s *) cmnd);
257 if (!tskim) { 257 if (!tskim) {
258 BFA_DEV_PRINTF(bfad, BFA_ERR, 258 BFA_DEV_PRINTF(bfad, BFA_ERR,
@@ -513,11 +513,14 @@ void bfa_fcb_itnim_tov(struct bfad_itnim_s *itnim)
513 * Allocate a Scsi_Host for a port. 513 * Allocate a Scsi_Host for a port.
514 */ 514 */
515int 515int
516bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port) 516bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port,
517 struct device *dev)
517{ 518{
518 int error = 1; 519 int error = 1;
519 520
521 mutex_lock(&bfad_mutex);
520 if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) { 522 if (!idr_pre_get(&bfad_im_port_index, GFP_KERNEL)) {
523 mutex_unlock(&bfad_mutex);
521 printk(KERN_WARNING "idr_pre_get failure\n"); 524 printk(KERN_WARNING "idr_pre_get failure\n");
522 goto out; 525 goto out;
523 } 526 }
@@ -525,10 +528,13 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
525 error = idr_get_new(&bfad_im_port_index, im_port, 528 error = idr_get_new(&bfad_im_port_index, im_port,
526 &im_port->idr_id); 529 &im_port->idr_id);
527 if (error) { 530 if (error) {
531 mutex_unlock(&bfad_mutex);
528 printk(KERN_WARNING "idr_get_new failure\n"); 532 printk(KERN_WARNING "idr_get_new failure\n");
529 goto out; 533 goto out;
530 } 534 }
531 535
536 mutex_unlock(&bfad_mutex);
537
532 im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad); 538 im_port->shost = bfad_os_scsi_host_alloc(im_port, bfad);
533 if (!im_port->shost) { 539 if (!im_port->shost) {
534 error = 1; 540 error = 1;
@@ -542,12 +548,15 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
542 im_port->shost->max_lun = MAX_FCP_LUN; 548 im_port->shost->max_lun = MAX_FCP_LUN;
543 im_port->shost->max_cmd_len = 16; 549 im_port->shost->max_cmd_len = 16;
544 im_port->shost->can_queue = bfad->cfg_data.ioc_queue_depth; 550 im_port->shost->can_queue = bfad->cfg_data.ioc_queue_depth;
545 im_port->shost->transportt = bfad_im_scsi_transport_template; 551 if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
552 im_port->shost->transportt = bfad_im_scsi_transport_template;
553 else
554 im_port->shost->transportt =
555 bfad_im_scsi_vport_transport_template;
546 556
547 error = bfad_os_scsi_add_host(im_port->shost, im_port, bfad); 557 error = scsi_add_host(im_port->shost, dev);
548 if (error) { 558 if (error) {
549 printk(KERN_WARNING "bfad_os_scsi_add_host failure %d\n", 559 printk(KERN_WARNING "scsi_add_host failure %d\n", error);
550 error);
551 goto out_fc_rel; 560 goto out_fc_rel;
552 } 561 }
553 562
@@ -559,7 +568,9 @@ bfad_im_scsi_host_alloc(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
559out_fc_rel: 568out_fc_rel:
560 scsi_host_put(im_port->shost); 569 scsi_host_put(im_port->shost);
561out_free_idr: 570out_free_idr:
571 mutex_lock(&bfad_mutex);
562 idr_remove(&bfad_im_port_index, im_port->idr_id); 572 idr_remove(&bfad_im_port_index, im_port->idr_id);
573 mutex_unlock(&bfad_mutex);
563out: 574out:
564 return error; 575 return error;
565} 576}
@@ -567,8 +578,6 @@ out:
567void 578void
568bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port) 579bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
569{ 580{
570 unsigned long flags;
571
572 bfa_trc(bfad, bfad->inst_no); 581 bfa_trc(bfad, bfad->inst_no);
573 bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE, 582 bfa_log(bfad->logmod, BFA_LOG_LINUX_SCSI_HOST_FREE,
574 im_port->shost->host_no); 583 im_port->shost->host_no);
@@ -578,9 +587,9 @@ bfad_im_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
578 scsi_remove_host(im_port->shost); 587 scsi_remove_host(im_port->shost);
579 scsi_host_put(im_port->shost); 588 scsi_host_put(im_port->shost);
580 589
581 spin_lock_irqsave(&bfad->bfad_lock, flags); 590 mutex_lock(&bfad_mutex);
582 idr_remove(&bfad_im_port_index, im_port->idr_id); 591 idr_remove(&bfad_im_port_index, im_port->idr_id);
583 spin_unlock_irqrestore(&bfad->bfad_lock, flags); 592 mutex_unlock(&bfad_mutex);
584} 593}
585 594
586static void 595static void
@@ -589,9 +598,11 @@ bfad_im_port_delete_handler(struct work_struct *work)
589 struct bfad_im_port_s *im_port = 598 struct bfad_im_port_s *im_port =
590 container_of(work, struct bfad_im_port_s, port_delete_work); 599 container_of(work, struct bfad_im_port_s, port_delete_work);
591 600
592 bfad_im_scsi_host_free(im_port->bfad, im_port); 601 if (im_port->port->pvb_type != BFAD_PORT_PHYS_BASE) {
593 bfad_im_port_clean(im_port); 602 im_port->flags |= BFAD_PORT_DELETE;
594 kfree(im_port); 603 fc_vport_terminate(im_port->fc_vport);
604 }
605
595} 606}
596 607
597bfa_status_t 608bfa_status_t
@@ -690,23 +701,6 @@ bfad_im_probe_undo(struct bfad_s *bfad)
690 } 701 }
691} 702}
692 703
693
694
695
696int
697bfad_os_scsi_add_host(struct Scsi_Host *shost, struct bfad_im_port_s *im_port,
698 struct bfad_s *bfad)
699{
700 struct device *dev;
701
702 if (im_port->port->pvb_type == BFAD_PORT_PHYS_BASE)
703 dev = &bfad->pcidev->dev;
704 else
705 dev = &bfad->pport.im_port->shost->shost_gendev;
706
707 return scsi_add_host(shost, dev);
708}
709
710struct Scsi_Host * 704struct Scsi_Host *
711bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad) 705bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
712{ 706{
@@ -725,7 +719,8 @@ bfad_os_scsi_host_alloc(struct bfad_im_port_s *im_port, struct bfad_s *bfad)
725void 719void
726bfad_os_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port) 720bfad_os_scsi_host_free(struct bfad_s *bfad, struct bfad_im_port_s *im_port)
727{ 721{
728 flush_workqueue(bfad->im->drv_workq); 722 if (!(im_port->flags & BFAD_PORT_DELETE))
723 flush_workqueue(bfad->im->drv_workq);
729 bfad_im_scsi_host_free(im_port->bfad, im_port); 724 bfad_im_scsi_host_free(im_port->bfad, im_port);
730 bfad_im_port_clean(im_port); 725 bfad_im_port_clean(im_port);
731 kfree(im_port); 726 kfree(im_port);
@@ -830,6 +825,13 @@ bfad_im_module_init(void)
830 if (!bfad_im_scsi_transport_template) 825 if (!bfad_im_scsi_transport_template)
831 return BFA_STATUS_ENOMEM; 826 return BFA_STATUS_ENOMEM;
832 827
828 bfad_im_scsi_vport_transport_template =
829 fc_attach_transport(&bfad_im_vport_fc_function_template);
830 if (!bfad_im_scsi_vport_transport_template) {
831 fc_release_transport(bfad_im_scsi_transport_template);
832 return BFA_STATUS_ENOMEM;
833 }
834
833 return BFA_STATUS_OK; 835 return BFA_STATUS_OK;
834} 836}
835 837
@@ -838,6 +840,8 @@ bfad_im_module_exit(void)
838{ 840{
839 if (bfad_im_scsi_transport_template) 841 if (bfad_im_scsi_transport_template)
840 fc_release_transport(bfad_im_scsi_transport_template); 842 fc_release_transport(bfad_im_scsi_transport_template);
843 if (bfad_im_scsi_vport_transport_template)
844 fc_release_transport(bfad_im_scsi_vport_transport_template);
841} 845}
842 846
843void 847void
@@ -938,6 +942,7 @@ bfad_os_fc_host_init(struct bfad_im_port_s *im_port)
938 bfa_os_htonll((bfa_fcs_port_get_nwwn(port->fcs_port))); 942 bfa_os_htonll((bfa_fcs_port_get_nwwn(port->fcs_port)));
939 fc_host_port_name(host) = 943 fc_host_port_name(host) =
940 bfa_os_htonll((bfa_fcs_port_get_pwwn(port->fcs_port))); 944 bfa_os_htonll((bfa_fcs_port_get_pwwn(port->fcs_port)));
945 fc_host_max_npiv_vports(host) = bfa_lps_get_max_vport(&bfad->bfa);
941 946
942 fc_host_supported_classes(host) = FC_COS_CLASS3; 947 fc_host_supported_classes(host) = FC_COS_CLASS3;
943 948
diff --git a/drivers/scsi/bfa/bfad_im.h b/drivers/scsi/bfa/bfad_im.h
index 85ab2da21321..973cab4d09c7 100644
--- a/drivers/scsi/bfa/bfad_im.h
+++ b/drivers/scsi/bfa/bfad_im.h
@@ -34,7 +34,7 @@ void bfad_im_port_online(struct bfad_s *bfad, struct bfad_port_s *port);
34void bfad_im_port_offline(struct bfad_s *bfad, struct bfad_port_s *port); 34void bfad_im_port_offline(struct bfad_s *bfad, struct bfad_port_s *port);
35void bfad_im_port_clean(struct bfad_im_port_s *im_port); 35void bfad_im_port_clean(struct bfad_im_port_s *im_port);
36int bfad_im_scsi_host_alloc(struct bfad_s *bfad, 36int bfad_im_scsi_host_alloc(struct bfad_s *bfad,
37 struct bfad_im_port_s *im_port); 37 struct bfad_im_port_s *im_port, struct device *dev);
38void bfad_im_scsi_host_free(struct bfad_s *bfad, 38void bfad_im_scsi_host_free(struct bfad_s *bfad,
39 struct bfad_im_port_s *im_port); 39 struct bfad_im_port_s *im_port);
40 40
@@ -64,9 +64,11 @@ struct bfad_im_port_s {
64 struct work_struct port_delete_work; 64 struct work_struct port_delete_work;
65 int idr_id; 65 int idr_id;
66 u16 cur_scsi_id; 66 u16 cur_scsi_id;
67 u16 flags;
67 struct list_head binding_list; 68 struct list_head binding_list;
68 struct Scsi_Host *shost; 69 struct Scsi_Host *shost;
69 struct list_head itnim_mapped_list; 70 struct list_head itnim_mapped_list;
71 struct fc_vport *fc_vport;
70}; 72};
71 73
72enum bfad_itnim_state { 74enum bfad_itnim_state {
@@ -140,6 +142,8 @@ void bfad_im_itnim_unmap(struct bfad_im_port_s *im_port,
140extern struct scsi_host_template bfad_im_scsi_host_template; 142extern struct scsi_host_template bfad_im_scsi_host_template;
141extern struct scsi_host_template bfad_im_vport_template; 143extern struct scsi_host_template bfad_im_vport_template;
142extern struct fc_function_template bfad_im_fc_function_template; 144extern struct fc_function_template bfad_im_fc_function_template;
145extern struct fc_function_template bfad_im_vport_fc_function_template;
143extern struct scsi_transport_template *bfad_im_scsi_transport_template; 146extern struct scsi_transport_template *bfad_im_scsi_transport_template;
147extern struct scsi_transport_template *bfad_im_scsi_vport_transport_template;
144 148
145#endif 149#endif