aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/bfa/bfa_port.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/scsi/bfa/bfa_port.c')
-rw-r--r--drivers/scsi/bfa/bfa_port.c428
1 files changed, 408 insertions, 20 deletions
diff --git a/drivers/scsi/bfa/bfa_port.c b/drivers/scsi/bfa/bfa_port.c
index 3f8e9d6066ec..95e4ad8759ac 100644
--- a/drivers/scsi/bfa/bfa_port.c
+++ b/drivers/scsi/bfa/bfa_port.c
@@ -24,8 +24,6 @@
24 24
25BFA_TRC_FILE(CNA, PORT); 25BFA_TRC_FILE(CNA, PORT);
26 26
27#define bfa_ioc_portid(__ioc) ((__ioc)->port_id)
28
29static void 27static void
30bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats) 28bfa_port_stats_swap(struct bfa_port_s *port, union bfa_port_stats_u *stats)
31{ 29{
@@ -236,6 +234,12 @@ bfa_port_enable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
236{ 234{
237 struct bfi_port_generic_req_s *m; 235 struct bfi_port_generic_req_s *m;
238 236
237 /* If port is PBC disabled, return error */
238 if (port->pbc_disabled) {
239 bfa_trc(port, BFA_STATUS_PBC);
240 return BFA_STATUS_PBC;
241 }
242
239 if (bfa_ioc_is_disabled(port->ioc)) { 243 if (bfa_ioc_is_disabled(port->ioc)) {
240 bfa_trc(port, BFA_STATUS_IOC_DISABLED); 244 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
241 return BFA_STATUS_IOC_DISABLED; 245 return BFA_STATUS_IOC_DISABLED;
@@ -280,6 +284,12 @@ bfa_port_disable(struct bfa_port_s *port, bfa_port_endis_cbfn_t cbfn,
280{ 284{
281 struct bfi_port_generic_req_s *m; 285 struct bfi_port_generic_req_s *m;
282 286
287 /* If port is PBC disabled, return error */
288 if (port->pbc_disabled) {
289 bfa_trc(port, BFA_STATUS_PBC);
290 return BFA_STATUS_PBC;
291 }
292
283 if (bfa_ioc_is_disabled(port->ioc)) { 293 if (bfa_ioc_is_disabled(port->ioc)) {
284 bfa_trc(port, BFA_STATUS_IOC_DISABLED); 294 bfa_trc(port, BFA_STATUS_IOC_DISABLED);
285 return BFA_STATUS_IOC_DISABLED; 295 return BFA_STATUS_IOC_DISABLED;
@@ -387,32 +397,43 @@ bfa_port_clear_stats(struct bfa_port_s *port, bfa_port_stats_cbfn_t cbfn,
387} 397}
388 398
389/* 399/*
390 * bfa_port_hbfail() 400 * bfa_port_notify()
391 * 401 *
402 * Port module IOC event handler
392 * 403 *
393 * @param[in] Pointer to the Port module data structure. 404 * @param[in] Pointer to the Port module data structure.
405 * @param[in] IOC event structure
394 * 406 *
395 * @return void 407 * @return void
396 */ 408 */
397void 409void
398bfa_port_hbfail(void *arg) 410bfa_port_notify(void *arg, enum bfa_ioc_event_e event)
399{ 411{
400 struct bfa_port_s *port = (struct bfa_port_s *) arg; 412 struct bfa_port_s *port = (struct bfa_port_s *) arg;
401 413
402 /* Fail any pending get_stats/clear_stats requests */ 414 switch (event) {
403 if (port->stats_busy) { 415 case BFA_IOC_E_DISABLED:
404 if (port->stats_cbfn) 416 case BFA_IOC_E_FAILED:
405 port->stats_cbfn(port->stats_cbarg, BFA_STATUS_FAILED); 417 /* Fail any pending get_stats/clear_stats requests */
406 port->stats_cbfn = NULL; 418 if (port->stats_busy) {
407 port->stats_busy = BFA_FALSE; 419 if (port->stats_cbfn)
408 } 420 port->stats_cbfn(port->stats_cbarg,
409 421 BFA_STATUS_FAILED);
410 /* Clear any enable/disable is pending */ 422 port->stats_cbfn = NULL;
411 if (port->endis_pending) { 423 port->stats_busy = BFA_FALSE;
412 if (port->endis_cbfn) 424 }
413 port->endis_cbfn(port->endis_cbarg, BFA_STATUS_FAILED); 425
414 port->endis_cbfn = NULL; 426 /* Clear any enable/disable is pending */
415 port->endis_pending = BFA_FALSE; 427 if (port->endis_pending) {
428 if (port->endis_cbfn)
429 port->endis_cbfn(port->endis_cbarg,
430 BFA_STATUS_FAILED);
431 port->endis_cbfn = NULL;
432 port->endis_pending = BFA_FALSE;
433 }
434 break;
435 default:
436 break;
416 } 437 }
417} 438}
418 439
@@ -445,10 +466,12 @@ bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
445 port->endis_pending = BFA_FALSE; 466 port->endis_pending = BFA_FALSE;
446 port->stats_cbfn = NULL; 467 port->stats_cbfn = NULL;
447 port->endis_cbfn = NULL; 468 port->endis_cbfn = NULL;
469 port->pbc_disabled = BFA_FALSE;
448 470
449 bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port); 471 bfa_ioc_mbox_regisr(port->ioc, BFI_MC_PORT, bfa_port_isr, port);
450 bfa_ioc_hbfail_init(&port->hbfail, bfa_port_hbfail, port); 472 bfa_q_qe_init(&port->ioc_notify);
451 list_add_tail(&port->hbfail.qe, &port->ioc->hb_notify_q); 473 bfa_ioc_notify_init(&port->ioc_notify, bfa_port_notify, port);
474 list_add_tail(&port->ioc_notify.qe, &port->ioc->notify_q);
452 475
453 /* 476 /*
454 * initialize time stamp for stats reset 477 * initialize time stamp for stats reset
@@ -458,3 +481,368 @@ bfa_port_attach(struct bfa_port_s *port, struct bfa_ioc_s *ioc,
458 481
459 bfa_trc(port, 0); 482 bfa_trc(port, 0);
460} 483}
484
485/*
486 * CEE module specific definitions
487 */
488
489/*
490 * bfa_cee_get_attr_isr()
491 *
492 * @brief CEE ISR for get-attributes responses from f/w
493 *
494 * @param[in] cee - Pointer to the CEE module
495 * status - Return status from the f/w
496 *
497 * @return void
498 */
499static void
500bfa_cee_get_attr_isr(struct bfa_cee_s *cee, bfa_status_t status)
501{
502 struct bfa_cee_lldp_cfg_s *lldp_cfg = &cee->attr->lldp_remote;
503
504 cee->get_attr_status = status;
505 bfa_trc(cee, 0);
506 if (status == BFA_STATUS_OK) {
507 bfa_trc(cee, 0);
508 memcpy(cee->attr, cee->attr_dma.kva,
509 sizeof(struct bfa_cee_attr_s));
510 lldp_cfg->time_to_live = be16_to_cpu(lldp_cfg->time_to_live);
511 lldp_cfg->enabled_system_cap =
512 be16_to_cpu(lldp_cfg->enabled_system_cap);
513 }
514 cee->get_attr_pending = BFA_FALSE;
515 if (cee->cbfn.get_attr_cbfn) {
516 bfa_trc(cee, 0);
517 cee->cbfn.get_attr_cbfn(cee->cbfn.get_attr_cbarg, status);
518 }
519}
520
521/*
522 * bfa_cee_get_stats_isr()
523 *
524 * @brief CEE ISR for get-stats responses from f/w
525 *
526 * @param[in] cee - Pointer to the CEE module
527 * status - Return status from the f/w
528 *
529 * @return void
530 */
531static void
532bfa_cee_get_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
533{
534 u32 *buffer;
535 int i;
536
537 cee->get_stats_status = status;
538 bfa_trc(cee, 0);
539 if (status == BFA_STATUS_OK) {
540 bfa_trc(cee, 0);
541 memcpy(cee->stats, cee->stats_dma.kva,
542 sizeof(struct bfa_cee_stats_s));
543 /* swap the cee stats */
544 buffer = (u32 *)cee->stats;
545 for (i = 0; i < (sizeof(struct bfa_cee_stats_s) /
546 sizeof(u32)); i++)
547 buffer[i] = cpu_to_be32(buffer[i]);
548 }
549 cee->get_stats_pending = BFA_FALSE;
550 bfa_trc(cee, 0);
551 if (cee->cbfn.get_stats_cbfn) {
552 bfa_trc(cee, 0);
553 cee->cbfn.get_stats_cbfn(cee->cbfn.get_stats_cbarg, status);
554 }
555}
556
557/*
558 * bfa_cee_reset_stats_isr()
559 *
560 * @brief CEE ISR for reset-stats responses from f/w
561 *
562 * @param[in] cee - Pointer to the CEE module
563 * status - Return status from the f/w
564 *
565 * @return void
566 */
567static void
568bfa_cee_reset_stats_isr(struct bfa_cee_s *cee, bfa_status_t status)
569{
570 cee->reset_stats_status = status;
571 cee->reset_stats_pending = BFA_FALSE;
572 if (cee->cbfn.reset_stats_cbfn)
573 cee->cbfn.reset_stats_cbfn(cee->cbfn.reset_stats_cbarg, status);
574}
575
576/*
577 * bfa_cee_meminfo()
578 *
579 * @brief Returns the size of the DMA memory needed by CEE module
580 *
581 * @param[in] void
582 *
583 * @return Size of DMA region
584 */
585u32
586bfa_cee_meminfo(void)
587{
588 return BFA_ROUNDUP(sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ) +
589 BFA_ROUNDUP(sizeof(struct bfa_cee_stats_s), BFA_DMA_ALIGN_SZ);
590}
591
592/*
593 * bfa_cee_mem_claim()
594 *
595 * @brief Initialized CEE DMA Memory
596 *
597 * @param[in] cee CEE module pointer
598 * dma_kva Kernel Virtual Address of CEE DMA Memory
599 * dma_pa Physical Address of CEE DMA Memory
600 *
601 * @return void
602 */
603void
604bfa_cee_mem_claim(struct bfa_cee_s *cee, u8 *dma_kva, u64 dma_pa)
605{
606 cee->attr_dma.kva = dma_kva;
607 cee->attr_dma.pa = dma_pa;
608 cee->stats_dma.kva = dma_kva + BFA_ROUNDUP(
609 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
610 cee->stats_dma.pa = dma_pa + BFA_ROUNDUP(
611 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ);
612 cee->attr = (struct bfa_cee_attr_s *) dma_kva;
613 cee->stats = (struct bfa_cee_stats_s *) (dma_kva + BFA_ROUNDUP(
614 sizeof(struct bfa_cee_attr_s), BFA_DMA_ALIGN_SZ));
615}
616
617/*
618 * bfa_cee_get_attr()
619 *
620 * @brief
621 * Send the request to the f/w to fetch CEE attributes.
622 *
623 * @param[in] Pointer to the CEE module data structure.
624 *
625 * @return Status
626 */
627
628bfa_status_t
629bfa_cee_get_attr(struct bfa_cee_s *cee, struct bfa_cee_attr_s *attr,
630 bfa_cee_get_attr_cbfn_t cbfn, void *cbarg)
631{
632 struct bfi_cee_get_req_s *cmd;
633
634 WARN_ON((cee == NULL) || (cee->ioc == NULL));
635 bfa_trc(cee, 0);
636 if (!bfa_ioc_is_operational(cee->ioc)) {
637 bfa_trc(cee, 0);
638 return BFA_STATUS_IOC_FAILURE;
639 }
640 if (cee->get_attr_pending == BFA_TRUE) {
641 bfa_trc(cee, 0);
642 return BFA_STATUS_DEVBUSY;
643 }
644 cee->get_attr_pending = BFA_TRUE;
645 cmd = (struct bfi_cee_get_req_s *) cee->get_cfg_mb.msg;
646 cee->attr = attr;
647 cee->cbfn.get_attr_cbfn = cbfn;
648 cee->cbfn.get_attr_cbarg = cbarg;
649 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_CFG_REQ,
650 bfa_ioc_portid(cee->ioc));
651 bfa_dma_be_addr_set(cmd->dma_addr, cee->attr_dma.pa);
652 bfa_ioc_mbox_queue(cee->ioc, &cee->get_cfg_mb);
653
654 return BFA_STATUS_OK;
655}
656
657/*
658 * bfa_cee_get_stats()
659 *
660 * @brief
661 * Send the request to the f/w to fetch CEE statistics.
662 *
663 * @param[in] Pointer to the CEE module data structure.
664 *
665 * @return Status
666 */
667
668bfa_status_t
669bfa_cee_get_stats(struct bfa_cee_s *cee, struct bfa_cee_stats_s *stats,
670 bfa_cee_get_stats_cbfn_t cbfn, void *cbarg)
671{
672 struct bfi_cee_get_req_s *cmd;
673
674 WARN_ON((cee == NULL) || (cee->ioc == NULL));
675
676 if (!bfa_ioc_is_operational(cee->ioc)) {
677 bfa_trc(cee, 0);
678 return BFA_STATUS_IOC_FAILURE;
679 }
680 if (cee->get_stats_pending == BFA_TRUE) {
681 bfa_trc(cee, 0);
682 return BFA_STATUS_DEVBUSY;
683 }
684 cee->get_stats_pending = BFA_TRUE;
685 cmd = (struct bfi_cee_get_req_s *) cee->get_stats_mb.msg;
686 cee->stats = stats;
687 cee->cbfn.get_stats_cbfn = cbfn;
688 cee->cbfn.get_stats_cbarg = cbarg;
689 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_GET_STATS_REQ,
690 bfa_ioc_portid(cee->ioc));
691 bfa_dma_be_addr_set(cmd->dma_addr, cee->stats_dma.pa);
692 bfa_ioc_mbox_queue(cee->ioc, &cee->get_stats_mb);
693
694 return BFA_STATUS_OK;
695}
696
697/*
698 * bfa_cee_reset_stats()
699 *
700 * @brief Clears CEE Stats in the f/w.
701 *
702 * @param[in] Pointer to the CEE module data structure.
703 *
704 * @return Status
705 */
706
707bfa_status_t
708bfa_cee_reset_stats(struct bfa_cee_s *cee,
709 bfa_cee_reset_stats_cbfn_t cbfn, void *cbarg)
710{
711 struct bfi_cee_reset_stats_s *cmd;
712
713 WARN_ON((cee == NULL) || (cee->ioc == NULL));
714 if (!bfa_ioc_is_operational(cee->ioc)) {
715 bfa_trc(cee, 0);
716 return BFA_STATUS_IOC_FAILURE;
717 }
718 if (cee->reset_stats_pending == BFA_TRUE) {
719 bfa_trc(cee, 0);
720 return BFA_STATUS_DEVBUSY;
721 }
722 cee->reset_stats_pending = BFA_TRUE;
723 cmd = (struct bfi_cee_reset_stats_s *) cee->reset_stats_mb.msg;
724 cee->cbfn.reset_stats_cbfn = cbfn;
725 cee->cbfn.reset_stats_cbarg = cbarg;
726 bfi_h2i_set(cmd->mh, BFI_MC_CEE, BFI_CEE_H2I_RESET_STATS,
727 bfa_ioc_portid(cee->ioc));
728 bfa_ioc_mbox_queue(cee->ioc, &cee->reset_stats_mb);
729
730 return BFA_STATUS_OK;
731}
732
733/*
734 * bfa_cee_isrs()
735 *
736 * @brief Handles Mail-box interrupts for CEE module.
737 *
738 * @param[in] Pointer to the CEE module data structure.
739 *
740 * @return void
741 */
742
743void
744bfa_cee_isr(void *cbarg, struct bfi_mbmsg_s *m)
745{
746 union bfi_cee_i2h_msg_u *msg;
747 struct bfi_cee_get_rsp_s *get_rsp;
748 struct bfa_cee_s *cee = (struct bfa_cee_s *) cbarg;
749 msg = (union bfi_cee_i2h_msg_u *) m;
750 get_rsp = (struct bfi_cee_get_rsp_s *) m;
751 bfa_trc(cee, msg->mh.msg_id);
752 switch (msg->mh.msg_id) {
753 case BFI_CEE_I2H_GET_CFG_RSP:
754 bfa_trc(cee, get_rsp->cmd_status);
755 bfa_cee_get_attr_isr(cee, get_rsp->cmd_status);
756 break;
757 case BFI_CEE_I2H_GET_STATS_RSP:
758 bfa_cee_get_stats_isr(cee, get_rsp->cmd_status);
759 break;
760 case BFI_CEE_I2H_RESET_STATS_RSP:
761 bfa_cee_reset_stats_isr(cee, get_rsp->cmd_status);
762 break;
763 default:
764 WARN_ON(1);
765 }
766}
767
768/*
769 * bfa_cee_notify()
770 *
771 * @brief CEE module IOC event handler.
772 *
773 * @param[in] Pointer to the CEE module data structure.
774 * @param[in] IOC event type
775 *
776 * @return void
777 */
778
779void
780bfa_cee_notify(void *arg, enum bfa_ioc_event_e event)
781{
782 struct bfa_cee_s *cee = (struct bfa_cee_s *) arg;
783
784 bfa_trc(cee, event);
785
786 switch (event) {
787 case BFA_IOC_E_DISABLED:
788 case BFA_IOC_E_FAILED:
789 if (cee->get_attr_pending == BFA_TRUE) {
790 cee->get_attr_status = BFA_STATUS_FAILED;
791 cee->get_attr_pending = BFA_FALSE;
792 if (cee->cbfn.get_attr_cbfn) {
793 cee->cbfn.get_attr_cbfn(
794 cee->cbfn.get_attr_cbarg,
795 BFA_STATUS_FAILED);
796 }
797 }
798 if (cee->get_stats_pending == BFA_TRUE) {
799 cee->get_stats_status = BFA_STATUS_FAILED;
800 cee->get_stats_pending = BFA_FALSE;
801 if (cee->cbfn.get_stats_cbfn) {
802 cee->cbfn.get_stats_cbfn(
803 cee->cbfn.get_stats_cbarg,
804 BFA_STATUS_FAILED);
805 }
806 }
807 if (cee->reset_stats_pending == BFA_TRUE) {
808 cee->reset_stats_status = BFA_STATUS_FAILED;
809 cee->reset_stats_pending = BFA_FALSE;
810 if (cee->cbfn.reset_stats_cbfn) {
811 cee->cbfn.reset_stats_cbfn(
812 cee->cbfn.reset_stats_cbarg,
813 BFA_STATUS_FAILED);
814 }
815 }
816 break;
817
818 default:
819 break;
820 }
821}
822
823/*
824 * bfa_cee_attach()
825 *
826 * @brief CEE module-attach API
827 *
828 * @param[in] cee - Pointer to the CEE module data structure
829 * ioc - Pointer to the ioc module data structure
830 * dev - Pointer to the device driver module data structure
831 * The device driver specific mbox ISR functions have
832 * this pointer as one of the parameters.
833 *
834 * @return void
835 */
836void
837bfa_cee_attach(struct bfa_cee_s *cee, struct bfa_ioc_s *ioc,
838 void *dev)
839{
840 WARN_ON(cee == NULL);
841 cee->dev = dev;
842 cee->ioc = ioc;
843
844 bfa_ioc_mbox_regisr(cee->ioc, BFI_MC_CEE, bfa_cee_isr, cee);
845 bfa_q_qe_init(&cee->ioc_notify);
846 bfa_ioc_notify_init(&cee->ioc_notify, bfa_cee_notify, cee);
847 list_add_tail(&cee->ioc_notify.qe, &cee->ioc->notify_q);
848}