aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_mbox.c
diff options
context:
space:
mode:
authorJames Smart <James.Smart@Emulex.Com>2009-05-22 14:52:52 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2009-06-08 12:24:50 -0400
commit04c684968487eb4f98728363a97b8da48f3bb958 (patch)
tree33f59839ca26a1904c4e2d2895598f543266feb0 /drivers/scsi/lpfc/lpfc_mbox.c
parent4f774513f7b3fe96648b8936f60f835e6ceaa88e (diff)
[SCSI] lpfc 8.3.2 : Addition of SLI4 Interface - Mailbox handling
The mailbox commands themselves are the same, or very similar to their SLI3 counterparts. This patch genericizes mailbox command handling and adds support for the new SLI4 mailbox queue. Signed-off-by: James Smart <james.smart@emulex.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
Diffstat (limited to 'drivers/scsi/lpfc/lpfc_mbox.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_mbox.c632
1 files changed, 590 insertions, 42 deletions
diff --git a/drivers/scsi/lpfc/lpfc_mbox.c b/drivers/scsi/lpfc/lpfc_mbox.c
index 7f5899b70bd2..6aeb1c668e22 100644
--- a/drivers/scsi/lpfc/lpfc_mbox.c
+++ b/drivers/scsi/lpfc/lpfc_mbox.c
@@ -60,7 +60,7 @@ lpfc_dump_mem(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, uint16_t offset)
60 MAILBOX_t *mb; 60 MAILBOX_t *mb;
61 void *ctx; 61 void *ctx;
62 62
63 mb = &pmb->mb; 63 mb = &pmb->u.mb;
64 ctx = pmb->context2; 64 ctx = pmb->context2;
65 65
66 /* Setup to dump VPD region */ 66 /* Setup to dump VPD region */
@@ -92,7 +92,7 @@ lpfc_dump_wakeup_param(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
92 MAILBOX_t *mb; 92 MAILBOX_t *mb;
93 void *ctx; 93 void *ctx;
94 94
95 mb = &pmb->mb; 95 mb = &pmb->u.mb;
96 /* Save context so that we can restore after memset */ 96 /* Save context so that we can restore after memset */
97 ctx = pmb->context2; 97 ctx = pmb->context2;
98 98
@@ -127,7 +127,7 @@ lpfc_read_nv(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
127{ 127{
128 MAILBOX_t *mb; 128 MAILBOX_t *mb;
129 129
130 mb = &pmb->mb; 130 mb = &pmb->u.mb;
131 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 131 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
132 mb->mbxCommand = MBX_READ_NV; 132 mb->mbxCommand = MBX_READ_NV;
133 mb->mbxOwner = OWN_HOST; 133 mb->mbxOwner = OWN_HOST;
@@ -153,7 +153,7 @@ lpfc_config_async(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb,
153{ 153{
154 MAILBOX_t *mb; 154 MAILBOX_t *mb;
155 155
156 mb = &pmb->mb; 156 mb = &pmb->u.mb;
157 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 157 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
158 mb->mbxCommand = MBX_ASYNCEVT_ENABLE; 158 mb->mbxCommand = MBX_ASYNCEVT_ENABLE;
159 mb->un.varCfgAsyncEvent.ring = ring; 159 mb->un.varCfgAsyncEvent.ring = ring;
@@ -179,7 +179,7 @@ lpfc_heart_beat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
179{ 179{
180 MAILBOX_t *mb; 180 MAILBOX_t *mb;
181 181
182 mb = &pmb->mb; 182 mb = &pmb->u.mb;
183 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 183 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
184 mb->mbxCommand = MBX_HEARTBEAT; 184 mb->mbxCommand = MBX_HEARTBEAT;
185 mb->mbxOwner = OWN_HOST; 185 mb->mbxOwner = OWN_HOST;
@@ -213,7 +213,7 @@ lpfc_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb, struct lpfc_dmabuf *mp)
213 struct lpfc_sli *psli; 213 struct lpfc_sli *psli;
214 214
215 psli = &phba->sli; 215 psli = &phba->sli;
216 mb = &pmb->mb; 216 mb = &pmb->u.mb;
217 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 217 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
218 218
219 INIT_LIST_HEAD(&mp->list); 219 INIT_LIST_HEAD(&mp->list);
@@ -250,7 +250,7 @@ lpfc_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
250{ 250{
251 MAILBOX_t *mb; 251 MAILBOX_t *mb;
252 252
253 mb = &pmb->mb; 253 mb = &pmb->u.mb;
254 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 254 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
255 255
256 mb->un.varClearLA.eventTag = phba->fc_eventTag; 256 mb->un.varClearLA.eventTag = phba->fc_eventTag;
@@ -277,7 +277,7 @@ void
277lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 277lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
278{ 278{
279 struct lpfc_vport *vport = phba->pport; 279 struct lpfc_vport *vport = phba->pport;
280 MAILBOX_t *mb = &pmb->mb; 280 MAILBOX_t *mb = &pmb->u.mb;
281 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 281 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
282 282
283 /* NEW_FEATURE 283 /* NEW_FEATURE
@@ -323,7 +323,7 @@ lpfc_config_link(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
323int 323int
324lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 324lpfc_config_msi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
325{ 325{
326 MAILBOX_t *mb = &pmb->mb; 326 MAILBOX_t *mb = &pmb->u.mb;
327 uint32_t attentionConditions[2]; 327 uint32_t attentionConditions[2];
328 328
329 /* Sanity check */ 329 /* Sanity check */
@@ -407,7 +407,7 @@ lpfc_init_link(struct lpfc_hba * phba,
407 struct lpfc_sli *psli; 407 struct lpfc_sli *psli;
408 MAILBOX_t *mb; 408 MAILBOX_t *mb;
409 409
410 mb = &pmb->mb; 410 mb = &pmb->u.mb;
411 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 411 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
412 412
413 psli = &phba->sli; 413 psli = &phba->sli;
@@ -494,7 +494,7 @@ lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
494 struct lpfc_sli *psli; 494 struct lpfc_sli *psli;
495 495
496 psli = &phba->sli; 496 psli = &phba->sli;
497 mb = &pmb->mb; 497 mb = &pmb->u.mb;
498 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 498 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
499 499
500 mb->mbxOwner = OWN_HOST; 500 mb->mbxOwner = OWN_HOST;
@@ -517,7 +517,7 @@ lpfc_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb, int vpi)
517 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm); 517 mb->un.varRdSparm.un.sp64.tus.f.bdeSize = sizeof (struct serv_parm);
518 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys); 518 mb->un.varRdSparm.un.sp64.addrHigh = putPaddrHigh(mp->phys);
519 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys); 519 mb->un.varRdSparm.un.sp64.addrLow = putPaddrLow(mp->phys);
520 mb->un.varRdSparm.vpi = vpi; 520 mb->un.varRdSparm.vpi = vpi + phba->vpi_base;
521 521
522 /* save address for completion */ 522 /* save address for completion */
523 pmb->context1 = mp; 523 pmb->context1 = mp;
@@ -546,10 +546,12 @@ lpfc_unreg_did(struct lpfc_hba * phba, uint16_t vpi, uint32_t did,
546{ 546{
547 MAILBOX_t *mb; 547 MAILBOX_t *mb;
548 548
549 mb = &pmb->mb; 549 mb = &pmb->u.mb;
550 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 550 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
551 551
552 mb->un.varUnregDID.did = did; 552 mb->un.varUnregDID.did = did;
553 if (vpi != 0xffff)
554 vpi += phba->vpi_base;
553 mb->un.varUnregDID.vpi = vpi; 555 mb->un.varUnregDID.vpi = vpi;
554 556
555 mb->mbxCommand = MBX_UNREG_D_ID; 557 mb->mbxCommand = MBX_UNREG_D_ID;
@@ -575,7 +577,7 @@ lpfc_read_config(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
575{ 577{
576 MAILBOX_t *mb; 578 MAILBOX_t *mb;
577 579
578 mb = &pmb->mb; 580 mb = &pmb->u.mb;
579 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 581 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
580 582
581 mb->mbxCommand = MBX_READ_CONFIG; 583 mb->mbxCommand = MBX_READ_CONFIG;
@@ -600,7 +602,7 @@ lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
600{ 602{
601 MAILBOX_t *mb; 603 MAILBOX_t *mb;
602 604
603 mb = &pmb->mb; 605 mb = &pmb->u.mb;
604 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 606 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
605 607
606 mb->mbxCommand = MBX_READ_LNK_STAT; 608 mb->mbxCommand = MBX_READ_LNK_STAT;
@@ -609,7 +611,7 @@ lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
609} 611}
610 612
611/** 613/**
612 * lpfc_reg_login - Prepare a mailbox command for registering remote login 614 * lpfc_reg_rpi - Prepare a mailbox command for registering remote login
613 * @phba: pointer to lpfc hba data structure. 615 * @phba: pointer to lpfc hba data structure.
614 * @vpi: virtual N_Port identifier. 616 * @vpi: virtual N_Port identifier.
615 * @did: remote port identifier. 617 * @did: remote port identifier.
@@ -633,17 +635,23 @@ lpfc_read_lnk_stat(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
633 * 1 - DMA memory allocation failed 635 * 1 - DMA memory allocation failed
634 **/ 636 **/
635int 637int
636lpfc_reg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t did, 638lpfc_reg_rpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t did,
637 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag) 639 uint8_t *param, LPFC_MBOXQ_t *pmb, uint32_t flag)
638{ 640{
639 MAILBOX_t *mb = &pmb->mb; 641 MAILBOX_t *mb = &pmb->u.mb;
640 uint8_t *sparam; 642 uint8_t *sparam;
641 struct lpfc_dmabuf *mp; 643 struct lpfc_dmabuf *mp;
642 644
643 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 645 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
644 646
645 mb->un.varRegLogin.rpi = 0; 647 mb->un.varRegLogin.rpi = 0;
646 mb->un.varRegLogin.vpi = vpi; 648 if (phba->sli_rev == LPFC_SLI_REV4) {
649 mb->un.varRegLogin.rpi = lpfc_sli4_alloc_rpi(phba);
650 if (mb->un.varRegLogin.rpi == LPFC_RPI_ALLOC_ERROR)
651 return 1;
652 }
653
654 mb->un.varRegLogin.vpi = vpi + phba->vpi_base;
647 mb->un.varRegLogin.did = did; 655 mb->un.varRegLogin.did = did;
648 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */ 656 mb->un.varWords[30] = flag; /* Set flag to issue action on cmpl */
649 657
@@ -699,15 +707,16 @@ lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
699{ 707{
700 MAILBOX_t *mb; 708 MAILBOX_t *mb;
701 709
702 mb = &pmb->mb; 710 mb = &pmb->u.mb;
703 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 711 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
704 712
705 mb->un.varUnregLogin.rpi = (uint16_t) rpi; 713 mb->un.varUnregLogin.rpi = (uint16_t) rpi;
706 mb->un.varUnregLogin.rsvd1 = 0; 714 mb->un.varUnregLogin.rsvd1 = 0;
707 mb->un.varUnregLogin.vpi = vpi; 715 mb->un.varUnregLogin.vpi = vpi + phba->vpi_base;
708 716
709 mb->mbxCommand = MBX_UNREG_LOGIN; 717 mb->mbxCommand = MBX_UNREG_LOGIN;
710 mb->mbxOwner = OWN_HOST; 718 mb->mbxOwner = OWN_HOST;
719
711 return; 720 return;
712} 721}
713 722
@@ -727,15 +736,15 @@ lpfc_unreg_login(struct lpfc_hba *phba, uint16_t vpi, uint32_t rpi,
727 * This routine prepares the mailbox command for registering a virtual N_Port. 736 * This routine prepares the mailbox command for registering a virtual N_Port.
728 **/ 737 **/
729void 738void
730lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid, 739lpfc_reg_vpi(struct lpfc_vport *vport, LPFC_MBOXQ_t *pmb)
731 LPFC_MBOXQ_t *pmb)
732{ 740{
733 MAILBOX_t *mb = &pmb->mb; 741 MAILBOX_t *mb = &pmb->u.mb;
734 742
735 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 743 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
736 744
737 mb->un.varRegVpi.vpi = vpi; 745 mb->un.varRegVpi.vpi = vport->vpi + vport->phba->vpi_base;
738 mb->un.varRegVpi.sid = sid; 746 mb->un.varRegVpi.sid = vport->fc_myDID;
747 mb->un.varRegVpi.vfi = vport->vfi + vport->phba->vfi_base;
739 748
740 mb->mbxCommand = MBX_REG_VPI; 749 mb->mbxCommand = MBX_REG_VPI;
741 mb->mbxOwner = OWN_HOST; 750 mb->mbxOwner = OWN_HOST;
@@ -762,10 +771,10 @@ lpfc_reg_vpi(struct lpfc_hba *phba, uint16_t vpi, uint32_t sid,
762void 771void
763lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb) 772lpfc_unreg_vpi(struct lpfc_hba *phba, uint16_t vpi, LPFC_MBOXQ_t *pmb)
764{ 773{
765 MAILBOX_t *mb = &pmb->mb; 774 MAILBOX_t *mb = &pmb->u.mb;
766 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 775 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
767 776
768 mb->un.varUnregVpi.vpi = vpi; 777 mb->un.varUnregVpi.vpi = vpi + phba->vpi_base;
769 778
770 mb->mbxCommand = MBX_UNREG_VPI; 779 mb->mbxCommand = MBX_UNREG_VPI;
771 mb->mbxOwner = OWN_HOST; 780 mb->mbxOwner = OWN_HOST;
@@ -854,7 +863,7 @@ lpfc_config_pcb_setup(struct lpfc_hba * phba)
854void 863void
855lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 864lpfc_read_rev(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
856{ 865{
857 MAILBOX_t *mb = &pmb->mb; 866 MAILBOX_t *mb = &pmb->u.mb;
858 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 867 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
859 mb->un.varRdRev.cv = 1; 868 mb->un.varRdRev.cv = 1;
860 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */ 869 mb->un.varRdRev.v3req = 1; /* Request SLI3 info */
@@ -947,7 +956,7 @@ lpfc_config_hbq(struct lpfc_hba *phba, uint32_t id,
947 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb) 956 uint32_t hbq_entry_index, LPFC_MBOXQ_t *pmb)
948{ 957{
949 int i; 958 int i;
950 MAILBOX_t *mb = &pmb->mb; 959 MAILBOX_t *mb = &pmb->u.mb;
951 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq; 960 struct config_hbq_var *hbqmb = &mb->un.varCfgHbq;
952 961
953 memset(pmb, 0, sizeof (LPFC_MBOXQ_t)); 962 memset(pmb, 0, sizeof (LPFC_MBOXQ_t));
@@ -1022,7 +1031,7 @@ void
1022lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb) 1031lpfc_config_ring(struct lpfc_hba * phba, int ring, LPFC_MBOXQ_t * pmb)
1023{ 1032{
1024 int i; 1033 int i;
1025 MAILBOX_t *mb = &pmb->mb; 1034 MAILBOX_t *mb = &pmb->u.mb;
1026 struct lpfc_sli *psli; 1035 struct lpfc_sli *psli;
1027 struct lpfc_sli_ring *pring; 1036 struct lpfc_sli_ring *pring;
1028 1037
@@ -1077,7 +1086,7 @@ void
1077lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb) 1086lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1078{ 1087{
1079 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr; 1088 MAILBOX_t __iomem *mb_slim = (MAILBOX_t __iomem *) phba->MBslimaddr;
1080 MAILBOX_t *mb = &pmb->mb; 1089 MAILBOX_t *mb = &pmb->u.mb;
1081 dma_addr_t pdma_addr; 1090 dma_addr_t pdma_addr;
1082 uint32_t bar_low, bar_high; 1091 uint32_t bar_low, bar_high;
1083 size_t offset; 1092 size_t offset;
@@ -1101,21 +1110,22 @@ lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1101 1110
1102 /* If HBA supports SLI=3 ask for it */ 1111 /* If HBA supports SLI=3 ask for it */
1103 1112
1104 if (phba->sli_rev == 3 && phba->vpd.sli3Feat.cerbm) { 1113 if (phba->sli_rev == LPFC_SLI_REV3 && phba->vpd.sli3Feat.cerbm) {
1105 if (phba->cfg_enable_bg) 1114 if (phba->cfg_enable_bg)
1106 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */ 1115 mb->un.varCfgPort.cbg = 1; /* configure BlockGuard */
1116 mb->un.varCfgPort.cdss = 1; /* Configure Security */
1107 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */ 1117 mb->un.varCfgPort.cerbm = 1; /* Request HBQs */
1108 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */ 1118 mb->un.varCfgPort.ccrp = 1; /* Command Ring Polling */
1109 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */ 1119 mb->un.varCfgPort.cinb = 1; /* Interrupt Notification Block */
1110 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count(); 1120 mb->un.varCfgPort.max_hbq = lpfc_sli_hbq_count();
1111 if (phba->max_vpi && phba->cfg_enable_npiv && 1121 if (phba->max_vpi && phba->cfg_enable_npiv &&
1112 phba->vpd.sli3Feat.cmv) { 1122 phba->vpd.sli3Feat.cmv) {
1113 mb->un.varCfgPort.max_vpi = phba->max_vpi; 1123 mb->un.varCfgPort.max_vpi = LPFC_MAX_VPI;
1114 mb->un.varCfgPort.cmv = 1; 1124 mb->un.varCfgPort.cmv = 1;
1115 } else 1125 } else
1116 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0; 1126 mb->un.varCfgPort.max_vpi = phba->max_vpi = 0;
1117 } else 1127 } else
1118 phba->sli_rev = 2; 1128 phba->sli_rev = LPFC_SLI_REV2;
1119 mb->un.varCfgPort.sli_mode = phba->sli_rev; 1129 mb->un.varCfgPort.sli_mode = phba->sli_rev;
1120 1130
1121 /* Now setup pcb */ 1131 /* Now setup pcb */
@@ -1247,7 +1257,7 @@ lpfc_config_port(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1247void 1257void
1248lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb) 1258lpfc_kill_board(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
1249{ 1259{
1250 MAILBOX_t *mb = &pmb->mb; 1260 MAILBOX_t *mb = &pmb->u.mb;
1251 1261
1252 memset(pmb, 0, sizeof(LPFC_MBOXQ_t)); 1262 memset(pmb, 0, sizeof(LPFC_MBOXQ_t));
1253 mb->mbxCommand = MBX_KILL_BOARD; 1263 mb->mbxCommand = MBX_KILL_BOARD;
@@ -1307,29 +1317,98 @@ lpfc_mbox_get(struct lpfc_hba * phba)
1307} 1317}
1308 1318
1309/** 1319/**
1320 * __lpfc_mbox_cmpl_put - Put mailbox cmd into mailbox cmd complete list
1321 * @phba: pointer to lpfc hba data structure.
1322 * @mbq: pointer to the driver internal queue element for mailbox command.
1323 *
1324 * This routine put the completed mailbox command into the mailbox command
1325 * complete list. This is the unlocked version of the routine. The mailbox
1326 * complete list is used by the driver worker thread to process mailbox
1327 * complete callback functions outside the driver interrupt handler.
1328 **/
1329void
1330__lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1331{
1332 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl);
1333}
1334
1335/**
1310 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list 1336 * lpfc_mbox_cmpl_put - Put mailbox command into mailbox command complete list
1311 * @phba: pointer to lpfc hba data structure. 1337 * @phba: pointer to lpfc hba data structure.
1312 * @mbq: pointer to the driver internal queue element for mailbox command. 1338 * @mbq: pointer to the driver internal queue element for mailbox command.
1313 * 1339 *
1314 * This routine put the completed mailbox command into the mailbox command 1340 * This routine put the completed mailbox command into the mailbox command
1315 * complete list. This routine is called from driver interrupt handler 1341 * complete list. This is the locked version of the routine. The mailbox
1316 * context.The mailbox complete list is used by the driver worker thread 1342 * complete list is used by the driver worker thread to process mailbox
1317 * to process mailbox complete callback functions outside the driver interrupt 1343 * complete callback functions outside the driver interrupt handler.
1318 * handler.
1319 **/ 1344 **/
1320void 1345void
1321lpfc_mbox_cmpl_put(struct lpfc_hba * phba, LPFC_MBOXQ_t * mbq) 1346lpfc_mbox_cmpl_put(struct lpfc_hba *phba, LPFC_MBOXQ_t *mbq)
1322{ 1347{
1323 unsigned long iflag; 1348 unsigned long iflag;
1324 1349
1325 /* This function expects to be called from interrupt context */ 1350 /* This function expects to be called from interrupt context */
1326 spin_lock_irqsave(&phba->hbalock, iflag); 1351 spin_lock_irqsave(&phba->hbalock, iflag);
1327 list_add_tail(&mbq->list, &phba->sli.mboxq_cmpl); 1352 __lpfc_mbox_cmpl_put(phba, mbq);
1328 spin_unlock_irqrestore(&phba->hbalock, iflag); 1353 spin_unlock_irqrestore(&phba->hbalock, iflag);
1329 return; 1354 return;
1330} 1355}
1331 1356
1332/** 1357/**
1358 * lpfc_mbox_cmd_check - Check the validality of a mailbox command
1359 * @phba: pointer to lpfc hba data structure.
1360 * @mboxq: pointer to the driver internal queue element for mailbox command.
1361 *
1362 * This routine is to check whether a mailbox command is valid to be issued.
1363 * This check will be performed by both the mailbox issue API when a client
1364 * is to issue a mailbox command to the mailbox transport.
1365 *
1366 * Return 0 - pass the check, -ENODEV - fail the check
1367 **/
1368int
1369lpfc_mbox_cmd_check(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1370{
1371 /* Mailbox command that have a completion handler must also have a
1372 * vport specified.
1373 */
1374 if (mboxq->mbox_cmpl && mboxq->mbox_cmpl != lpfc_sli_def_mbox_cmpl &&
1375 mboxq->mbox_cmpl != lpfc_sli_wake_mbox_wait) {
1376 if (!mboxq->vport) {
1377 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1378 "1814 Mbox x%x failed, no vport\n",
1379 mboxq->u.mb.mbxCommand);
1380 dump_stack();
1381 return -ENODEV;
1382 }
1383 }
1384 return 0;
1385}
1386
1387/**
1388 * lpfc_mbox_dev_check - Check the device state for issuing a mailbox command
1389 * @phba: pointer to lpfc hba data structure.
1390 *
1391 * This routine is to check whether the HBA device is ready for posting a
1392 * mailbox command. It is used by the mailbox transport API at the time the
1393 * to post a mailbox command to the device.
1394 *
1395 * Return 0 - pass the check, -ENODEV - fail the check
1396 **/
1397int
1398lpfc_mbox_dev_check(struct lpfc_hba *phba)
1399{
1400 /* If the PCI channel is in offline state, do not issue mbox */
1401 if (unlikely(pci_channel_offline(phba->pcidev)))
1402 return -ENODEV;
1403
1404 /* If the HBA is in error state, do not issue mbox */
1405 if (phba->link_state == LPFC_HBA_ERROR)
1406 return -ENODEV;
1407
1408 return 0;
1409}
1410
1411/**
1333 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value 1412 * lpfc_mbox_tmo_val - Retrieve mailbox command timeout value
1334 * @phba: pointer to lpfc hba data structure. 1413 * @phba: pointer to lpfc hba data structure.
1335 * @cmd: mailbox command code. 1414 * @cmd: mailbox command code.
@@ -1352,6 +1431,475 @@ lpfc_mbox_tmo_val(struct lpfc_hba *phba, int cmd)
1352 case MBX_WRITE_WWN: /* 0x98 */ 1431 case MBX_WRITE_WWN: /* 0x98 */
1353 case MBX_LOAD_EXP_ROM: /* 0x9C */ 1432 case MBX_LOAD_EXP_ROM: /* 0x9C */
1354 return LPFC_MBOX_TMO_FLASH_CMD; 1433 return LPFC_MBOX_TMO_FLASH_CMD;
1434 case MBX_SLI4_CONFIG: /* 0x9b */
1435 return LPFC_MBOX_SLI4_CONFIG_TMO;
1355 } 1436 }
1356 return LPFC_MBOX_TMO; 1437 return LPFC_MBOX_TMO;
1357} 1438}
1439
1440/**
1441 * lpfc_sli4_mbx_sge_set - Set a sge entry in non-embedded mailbox command
1442 * @mbox: pointer to lpfc mbox command.
1443 * @sgentry: sge entry index.
1444 * @phyaddr: physical address for the sge
1445 * @length: Length of the sge.
1446 *
1447 * This routine sets up an entry in the non-embedded mailbox command at the sge
1448 * index location.
1449 **/
1450void
1451lpfc_sli4_mbx_sge_set(struct lpfcMboxq *mbox, uint32_t sgentry,
1452 dma_addr_t phyaddr, uint32_t length)
1453{
1454 struct lpfc_mbx_nembed_cmd *nembed_sge;
1455
1456 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1457 &mbox->u.mqe.un.nembed_cmd;
1458 nembed_sge->sge[sgentry].pa_lo = putPaddrLow(phyaddr);
1459 nembed_sge->sge[sgentry].pa_hi = putPaddrHigh(phyaddr);
1460 nembed_sge->sge[sgentry].length = length;
1461}
1462
1463/**
1464 * lpfc_sli4_mbx_sge_get - Get a sge entry from non-embedded mailbox command
1465 * @mbox: pointer to lpfc mbox command.
1466 * @sgentry: sge entry index.
1467 *
1468 * This routine gets an entry from the non-embedded mailbox command at the sge
1469 * index location.
1470 **/
1471void
1472lpfc_sli4_mbx_sge_get(struct lpfcMboxq *mbox, uint32_t sgentry,
1473 struct lpfc_mbx_sge *sge)
1474{
1475 struct lpfc_mbx_nembed_cmd *nembed_sge;
1476
1477 nembed_sge = (struct lpfc_mbx_nembed_cmd *)
1478 &mbox->u.mqe.un.nembed_cmd;
1479 sge->pa_lo = nembed_sge->sge[sgentry].pa_lo;
1480 sge->pa_hi = nembed_sge->sge[sgentry].pa_hi;
1481 sge->length = nembed_sge->sge[sgentry].length;
1482}
1483
1484/**
1485 * lpfc_sli4_mbox_cmd_free - Free a sli4 mailbox command
1486 * @phba: pointer to lpfc hba data structure.
1487 * @mbox: pointer to lpfc mbox command.
1488 *
1489 * This routine frees SLI4 specific mailbox command for sending IOCTL command.
1490 **/
1491void
1492lpfc_sli4_mbox_cmd_free(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1493{
1494 struct lpfc_mbx_sli4_config *sli4_cfg;
1495 struct lpfc_mbx_sge sge;
1496 dma_addr_t phyaddr;
1497 uint32_t sgecount, sgentry;
1498
1499 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1500
1501 /* For embedded mbox command, just free the mbox command */
1502 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1503 mempool_free(mbox, phba->mbox_mem_pool);
1504 return;
1505 }
1506
1507 /* For non-embedded mbox command, we need to free the pages first */
1508 sgecount = bf_get(lpfc_mbox_hdr_sge_cnt, &sli4_cfg->header.cfg_mhdr);
1509 /* There is nothing we can do if there is no sge address array */
1510 if (unlikely(!mbox->sge_array)) {
1511 mempool_free(mbox, phba->mbox_mem_pool);
1512 return;
1513 }
1514 /* Each non-embedded DMA memory was allocated in the length of a page */
1515 for (sgentry = 0; sgentry < sgecount; sgentry++) {
1516 lpfc_sli4_mbx_sge_get(mbox, sgentry, &sge);
1517 phyaddr = getPaddr(sge.pa_hi, sge.pa_lo);
1518 dma_free_coherent(&phba->pcidev->dev, PAGE_SIZE,
1519 mbox->sge_array->addr[sgentry], phyaddr);
1520 }
1521 /* Free the sge address array memory */
1522 kfree(mbox->sge_array);
1523 /* Finally, free the mailbox command itself */
1524 mempool_free(mbox, phba->mbox_mem_pool);
1525}
1526
1527/**
1528 * lpfc_sli4_config - Initialize the SLI4 Config Mailbox command
1529 * @phba: pointer to lpfc hba data structure.
1530 * @mbox: pointer to lpfc mbox command.
1531 * @subsystem: The sli4 config sub mailbox subsystem.
1532 * @opcode: The sli4 config sub mailbox command opcode.
1533 * @length: Length of the sli4 config mailbox command.
1534 *
1535 * This routine sets up the header fields of SLI4 specific mailbox command
1536 * for sending IOCTL command.
1537 *
1538 * Return: the actual length of the mbox command allocated (mostly useful
1539 * for none embedded mailbox command).
1540 **/
1541int
1542lpfc_sli4_config(struct lpfc_hba *phba, struct lpfcMboxq *mbox,
1543 uint8_t subsystem, uint8_t opcode, uint32_t length, bool emb)
1544{
1545 struct lpfc_mbx_sli4_config *sli4_config;
1546 union lpfc_sli4_cfg_shdr *cfg_shdr = NULL;
1547 uint32_t alloc_len;
1548 uint32_t resid_len;
1549 uint32_t pagen, pcount;
1550 void *viraddr;
1551 dma_addr_t phyaddr;
1552
1553 /* Set up SLI4 mailbox command header fields */
1554 memset(mbox, 0, sizeof(*mbox));
1555 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_SLI4_CONFIG);
1556
1557 /* Set up SLI4 ioctl command header fields */
1558 sli4_config = &mbox->u.mqe.un.sli4_config;
1559
1560 /* Setup for the embedded mbox command */
1561 if (emb) {
1562 /* Set up main header fields */
1563 bf_set(lpfc_mbox_hdr_emb, &sli4_config->header.cfg_mhdr, 1);
1564 sli4_config->header.cfg_mhdr.payload_length =
1565 LPFC_MBX_CMD_HDR_LENGTH + length;
1566 /* Set up sub-header fields following main header */
1567 bf_set(lpfc_mbox_hdr_opcode,
1568 &sli4_config->header.cfg_shdr.request, opcode);
1569 bf_set(lpfc_mbox_hdr_subsystem,
1570 &sli4_config->header.cfg_shdr.request, subsystem);
1571 sli4_config->header.cfg_shdr.request.request_length = length;
1572 return length;
1573 }
1574
1575 /* Setup for the none-embedded mbox command */
1576 pcount = (PAGE_ALIGN(length))/PAGE_SIZE;
1577 pcount = (pcount > LPFC_SLI4_MBX_SGE_MAX_PAGES) ?
1578 LPFC_SLI4_MBX_SGE_MAX_PAGES : pcount;
1579 /* Allocate record for keeping SGE virtual addresses */
1580 mbox->sge_array = kmalloc(sizeof(struct lpfc_mbx_nembed_sge_virt),
1581 GFP_KERNEL);
1582 if (!mbox->sge_array)
1583 return 0;
1584
1585 for (pagen = 0, alloc_len = 0; pagen < pcount; pagen++) {
1586 /* The DMA memory is always allocated in the length of a
1587 * page even though the last SGE might not fill up to a
1588 * page, this is used as a priori size of PAGE_SIZE for
1589 * the later DMA memory free.
1590 */
1591 viraddr = dma_alloc_coherent(&phba->pcidev->dev, PAGE_SIZE,
1592 &phyaddr, GFP_KERNEL);
1593 /* In case of malloc fails, proceed with whatever we have */
1594 if (!viraddr)
1595 break;
1596 mbox->sge_array->addr[pagen] = viraddr;
1597 /* Keep the first page for later sub-header construction */
1598 if (pagen == 0)
1599 cfg_shdr = (union lpfc_sli4_cfg_shdr *)viraddr;
1600 resid_len = length - alloc_len;
1601 if (resid_len > PAGE_SIZE) {
1602 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1603 PAGE_SIZE);
1604 alloc_len += PAGE_SIZE;
1605 } else {
1606 lpfc_sli4_mbx_sge_set(mbox, pagen, phyaddr,
1607 resid_len);
1608 alloc_len = length;
1609 }
1610 }
1611
1612 /* Set up main header fields in mailbox command */
1613 sli4_config->header.cfg_mhdr.payload_length = alloc_len;
1614 bf_set(lpfc_mbox_hdr_sge_cnt, &sli4_config->header.cfg_mhdr, pagen);
1615
1616 /* Set up sub-header fields into the first page */
1617 if (pagen > 0) {
1618 bf_set(lpfc_mbox_hdr_opcode, &cfg_shdr->request, opcode);
1619 bf_set(lpfc_mbox_hdr_subsystem, &cfg_shdr->request, subsystem);
1620 cfg_shdr->request.request_length =
1621 alloc_len - sizeof(union lpfc_sli4_cfg_shdr);
1622 }
1623 /* The sub-header is in DMA memory, which needs endian converstion */
1624 lpfc_sli_pcimem_bcopy(cfg_shdr, cfg_shdr,
1625 sizeof(union lpfc_sli4_cfg_shdr));
1626
1627 return alloc_len;
1628}
1629
1630/**
1631 * lpfc_sli4_mbox_opcode_get - Get the opcode from a sli4 mailbox command
1632 * @phba: pointer to lpfc hba data structure.
1633 * @mbox: pointer to lpfc mbox command.
1634 *
1635 * This routine gets the opcode from a SLI4 specific mailbox command for
1636 * sending IOCTL command. If the mailbox command is not MBX_SLI4_CONFIG
1637 * (0x9B) or if the IOCTL sub-header is not present, opcode 0x0 shall be
1638 * returned.
1639 **/
1640uint8_t
1641lpfc_sli4_mbox_opcode_get(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1642{
1643 struct lpfc_mbx_sli4_config *sli4_cfg;
1644 union lpfc_sli4_cfg_shdr *cfg_shdr;
1645
1646 if (mbox->u.mb.mbxCommand != MBX_SLI4_CONFIG)
1647 return 0;
1648 sli4_cfg = &mbox->u.mqe.un.sli4_config;
1649
1650 /* For embedded mbox command, get opcode from embedded sub-header*/
1651 if (bf_get(lpfc_mbox_hdr_emb, &sli4_cfg->header.cfg_mhdr)) {
1652 cfg_shdr = &mbox->u.mqe.un.sli4_config.header.cfg_shdr;
1653 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1654 }
1655
1656 /* For non-embedded mbox command, get opcode from first dma page */
1657 if (unlikely(!mbox->sge_array))
1658 return 0;
1659 cfg_shdr = (union lpfc_sli4_cfg_shdr *)mbox->sge_array->addr[0];
1660 return bf_get(lpfc_mbox_hdr_opcode, &cfg_shdr->request);
1661}
1662
1663/**
1664 * lpfc_request_features: Configure SLI4 REQUEST_FEATURES mailbox
1665 * @mboxq: pointer to lpfc mbox command.
1666 *
1667 * This routine sets up the mailbox for an SLI4 REQUEST_FEATURES
1668 * mailbox command.
1669 **/
1670void
1671lpfc_request_features(struct lpfc_hba *phba, struct lpfcMboxq *mboxq)
1672{
1673 /* Set up SLI4 mailbox command header fields */
1674 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
1675 bf_set(lpfc_mqe_command, &mboxq->u.mqe, MBX_SLI4_REQ_FTRS);
1676
1677 /* Set up host requested features. */
1678 bf_set(lpfc_mbx_rq_ftr_rq_fcpi, &mboxq->u.mqe.un.req_ftrs, 1);
1679
1680 /* Virtual fabrics and FIPs are not supported yet. */
1681 bf_set(lpfc_mbx_rq_ftr_rq_ifip, &mboxq->u.mqe.un.req_ftrs, 0);
1682
1683 /* Enable DIF (block guard) only if configured to do so. */
1684 if (phba->cfg_enable_bg)
1685 bf_set(lpfc_mbx_rq_ftr_rq_dif, &mboxq->u.mqe.un.req_ftrs, 1);
1686
1687 /* Enable NPIV only if configured to do so. */
1688 if (phba->max_vpi && phba->cfg_enable_npiv)
1689 bf_set(lpfc_mbx_rq_ftr_rq_npiv, &mboxq->u.mqe.un.req_ftrs, 1);
1690
1691 return;
1692}
1693
1694/**
1695 * lpfc_init_vfi - Initialize the INIT_VFI mailbox command
1696 * @mbox: pointer to lpfc mbox command to initialize.
1697 * @vport: Vport associated with the VF.
1698 *
1699 * This routine initializes @mbox to all zeros and then fills in the mailbox
1700 * fields from @vport. INIT_VFI configures virtual fabrics identified by VFI
1701 * in the context of an FCF. The driver issues this command to setup a VFI
1702 * before issuing a FLOGI to login to the VSAN. The driver should also issue a
1703 * REG_VFI after a successful VSAN login.
1704 **/
1705void
1706lpfc_init_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport)
1707{
1708 struct lpfc_mbx_init_vfi *init_vfi;
1709
1710 memset(mbox, 0, sizeof(*mbox));
1711 init_vfi = &mbox->u.mqe.un.init_vfi;
1712 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VFI);
1713 bf_set(lpfc_init_vfi_vr, init_vfi, 1);
1714 bf_set(lpfc_init_vfi_vt, init_vfi, 1);
1715 bf_set(lpfc_init_vfi_vfi, init_vfi, vport->vfi + vport->phba->vfi_base);
1716 bf_set(lpfc_init_vfi_fcfi, init_vfi, vport->phba->fcf.fcfi);
1717}
1718
1719/**
1720 * lpfc_reg_vfi - Initialize the REG_VFI mailbox command
1721 * @mbox: pointer to lpfc mbox command to initialize.
1722 * @vport: vport associated with the VF.
1723 * @phys: BDE DMA bus address used to send the service parameters to the HBA.
1724 *
1725 * This routine initializes @mbox to all zeros and then fills in the mailbox
1726 * fields from @vport, and uses @buf as a DMAable buffer to send the vport's
1727 * fc service parameters to the HBA for this VFI. REG_VFI configures virtual
1728 * fabrics identified by VFI in the context of an FCF.
1729 **/
1730void
1731lpfc_reg_vfi(struct lpfcMboxq *mbox, struct lpfc_vport *vport, dma_addr_t phys)
1732{
1733 struct lpfc_mbx_reg_vfi *reg_vfi;
1734
1735 memset(mbox, 0, sizeof(*mbox));
1736 reg_vfi = &mbox->u.mqe.un.reg_vfi;
1737 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_VFI);
1738 bf_set(lpfc_reg_vfi_vp, reg_vfi, 1);
1739 bf_set(lpfc_reg_vfi_vfi, reg_vfi, vport->vfi + vport->phba->vfi_base);
1740 bf_set(lpfc_reg_vfi_fcfi, reg_vfi, vport->phba->fcf.fcfi);
1741 bf_set(lpfc_reg_vfi_vpi, reg_vfi, vport->vpi + vport->phba->vpi_base);
1742 reg_vfi->bde.addrHigh = putPaddrHigh(phys);
1743 reg_vfi->bde.addrLow = putPaddrLow(phys);
1744 reg_vfi->bde.tus.f.bdeSize = sizeof(vport->fc_sparam);
1745 reg_vfi->bde.tus.f.bdeFlags = BUFF_TYPE_BDE_64;
1746 bf_set(lpfc_reg_vfi_nport_id, reg_vfi, vport->fc_myDID);
1747}
1748
1749/**
1750 * lpfc_init_vpi - Initialize the INIT_VPI mailbox command
1751 * @mbox: pointer to lpfc mbox command to initialize.
1752 * @vpi: VPI to be initialized.
1753 *
1754 * The INIT_VPI mailbox command supports virtual N_Ports. The driver uses the
1755 * command to activate a virtual N_Port. The HBA assigns a MAC address to use
1756 * with the virtual N Port. The SLI Host issues this command before issuing a
1757 * FDISC to connect to the Fabric. The SLI Host should issue a REG_VPI after a
1758 * successful virtual NPort login.
1759 **/
1760void
1761lpfc_init_vpi(struct lpfcMboxq *mbox, uint16_t vpi)
1762{
1763 memset(mbox, 0, sizeof(*mbox));
1764 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_INIT_VPI);
1765 bf_set(lpfc_init_vpi_vpi, &mbox->u.mqe.un.init_vpi, vpi);
1766}
1767
1768/**
1769 * lpfc_unreg_vfi - Initialize the UNREG_VFI mailbox command
1770 * @mbox: pointer to lpfc mbox command to initialize.
1771 * @vfi: VFI to be unregistered.
1772 *
1773 * The UNREG_VFI mailbox command causes the SLI Host to put a virtual fabric
1774 * (logical NPort) into the inactive state. The SLI Host must have logged out
1775 * and unregistered all remote N_Ports to abort any activity on the virtual
1776 * fabric. The SLI Port posts the mailbox response after marking the virtual
1777 * fabric inactive.
1778 **/
1779void
1780lpfc_unreg_vfi(struct lpfcMboxq *mbox, uint16_t vfi)
1781{
1782 memset(mbox, 0, sizeof(*mbox));
1783 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_VFI);
1784 bf_set(lpfc_unreg_vfi_vfi, &mbox->u.mqe.un.unreg_vfi, vfi);
1785}
1786
1787/**
1788 * lpfc_dump_fcoe_param - Dump config region 23 to get FCoe parameters.
1789 * @phba: pointer to the hba structure containing.
1790 * @mbox: pointer to lpfc mbox command to initialize.
1791 *
1792 * This function create a SLI4 dump mailbox command to dump FCoE
1793 * parameters stored in region 23.
1794 **/
1795int
1796lpfc_dump_fcoe_param(struct lpfc_hba *phba,
1797 struct lpfcMboxq *mbox)
1798{
1799 struct lpfc_dmabuf *mp = NULL;
1800 MAILBOX_t *mb;
1801
1802 memset(mbox, 0, sizeof(*mbox));
1803 mb = &mbox->u.mb;
1804
1805 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
1806 if (mp)
1807 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
1808
1809 if (!mp || !mp->virt) {
1810 kfree(mp);
1811 /* dump_fcoe_param failed to allocate memory */
1812 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX,
1813 "2569 lpfc_dump_fcoe_param: memory"
1814 " allocation failed \n");
1815 return 1;
1816 }
1817
1818 memset(mp->virt, 0, LPFC_BPL_SIZE);
1819 INIT_LIST_HEAD(&mp->list);
1820
1821 /* save address for completion */
1822 mbox->context1 = (uint8_t *) mp;
1823
1824 mb->mbxCommand = MBX_DUMP_MEMORY;
1825 mb->un.varDmp.type = DMP_NV_PARAMS;
1826 mb->un.varDmp.region_id = DMP_REGION_FCOEPARAM;
1827 mb->un.varDmp.sli4_length = DMP_FCOEPARAM_RGN_SIZE;
1828 mb->un.varWords[3] = putPaddrLow(mp->phys);
1829 mb->un.varWords[4] = putPaddrHigh(mp->phys);
1830 return 0;
1831}
1832
1833/**
1834 * lpfc_reg_fcfi - Initialize the REG_FCFI mailbox command
1835 * @phba: pointer to the hba structure containing the FCF index and RQ ID.
1836 * @mbox: pointer to lpfc mbox command to initialize.
1837 *
1838 * The REG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs). The
1839 * SLI Host uses the command to activate an FCF after it has acquired FCF
1840 * information via a READ_FCF mailbox command. This mailbox command also is used
1841 * to indicate where received unsolicited frames from this FCF will be sent. By
1842 * default this routine will set up the FCF to forward all unsolicited frames
1843 * the the RQ ID passed in the @phba. This can be overridden by the caller for
1844 * more complicated setups.
1845 **/
1846void
1847lpfc_reg_fcfi(struct lpfc_hba *phba, struct lpfcMboxq *mbox)
1848{
1849 struct lpfc_mbx_reg_fcfi *reg_fcfi;
1850
1851 memset(mbox, 0, sizeof(*mbox));
1852 reg_fcfi = &mbox->u.mqe.un.reg_fcfi;
1853 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_REG_FCFI);
1854 bf_set(lpfc_reg_fcfi_rq_id0, reg_fcfi, phba->sli4_hba.hdr_rq->queue_id);
1855 bf_set(lpfc_reg_fcfi_rq_id1, reg_fcfi, REG_FCF_INVALID_QID);
1856 bf_set(lpfc_reg_fcfi_rq_id2, reg_fcfi, REG_FCF_INVALID_QID);
1857 bf_set(lpfc_reg_fcfi_rq_id3, reg_fcfi, REG_FCF_INVALID_QID);
1858 bf_set(lpfc_reg_fcfi_info_index, reg_fcfi, phba->fcf.fcf_indx);
1859 /* reg_fcf addr mode is bit wise inverted value of fcf addr_mode */
1860 bf_set(lpfc_reg_fcfi_mam, reg_fcfi,
1861 (~phba->fcf.addr_mode) & 0x3);
1862 if (phba->fcf.fcf_flag & FCF_VALID_VLAN) {
1863 bf_set(lpfc_reg_fcfi_vv, reg_fcfi, 1);
1864 bf_set(lpfc_reg_fcfi_vlan_tag, reg_fcfi, phba->fcf.vlan_id);
1865 }
1866}
1867
1868/**
1869 * lpfc_unreg_fcfi - Initialize the UNREG_FCFI mailbox command
1870 * @mbox: pointer to lpfc mbox command to initialize.
1871 * @fcfi: FCFI to be unregistered.
1872 *
1873 * The UNREG_FCFI mailbox command supports Fibre Channel Forwarders (FCFs).
1874 * The SLI Host uses the command to inactivate an FCFI.
1875 **/
1876void
1877lpfc_unreg_fcfi(struct lpfcMboxq *mbox, uint16_t fcfi)
1878{
1879 memset(mbox, 0, sizeof(*mbox));
1880 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_UNREG_FCFI);
1881 bf_set(lpfc_unreg_fcfi, &mbox->u.mqe.un.unreg_fcfi, fcfi);
1882}
1883
1884/**
1885 * lpfc_resume_rpi - Initialize the RESUME_RPI mailbox command
1886 * @mbox: pointer to lpfc mbox command to initialize.
1887 * @ndlp: The nodelist structure that describes the RPI to resume.
1888 *
1889 * The RESUME_RPI mailbox command is used to restart I/O to an RPI after a
1890 * link event.
1891 **/
1892void
1893lpfc_resume_rpi(struct lpfcMboxq *mbox, struct lpfc_nodelist *ndlp)
1894{
1895 struct lpfc_mbx_resume_rpi *resume_rpi;
1896
1897 memset(mbox, 0, sizeof(*mbox));
1898 resume_rpi = &mbox->u.mqe.un.resume_rpi;
1899 bf_set(lpfc_mqe_command, &mbox->u.mqe, MBX_RESUME_RPI);
1900 bf_set(lpfc_resume_rpi_rpi, resume_rpi, ndlp->nlp_rpi);
1901 bf_set(lpfc_resume_rpi_vpi, resume_rpi,
1902 ndlp->vport->vpi + ndlp->vport->phba->vpi_base);
1903 bf_set(lpfc_resume_rpi_vfi, resume_rpi,
1904 ndlp->vport->vfi + ndlp->vport->phba->vfi_base);
1905}