aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/lpfc/lpfc_init.c
diff options
context:
space:
mode:
authorJames Smart <James.Smart@Emulex.Com>2009-05-22 14:51:39 -0400
committerJames Bottomley <James.Bottomley@HansenPartnership.com>2009-06-08 12:21:29 -0400
commitda0436e915a5c17ee79e72c1bf978a4ebb1cbf4d (patch)
tree7784646b7627117fa7849a901c85294fae905505 /drivers/scsi/lpfc/lpfc_init.c
parent3772a99175f5378b5001e8da364341a8b8226a4a (diff)
[SCSI] lpfc 8.3.2 : Addition of SLI4 Interface - Base Support
Adds new hardware and interface definitions. Adds new interface routines - utilizing the reorganized layout of the driver. Adds SLI-4 specific functions for attachment, initialization, teardown, etc. 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_init.c')
-rw-r--r--drivers/scsi/lpfc/lpfc_init.c3800
1 files changed, 3645 insertions, 155 deletions
diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 3f06ce2becf5..e9e4a1df8989 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -34,8 +34,10 @@
34#include <scsi/scsi_host.h> 34#include <scsi/scsi_host.h>
35#include <scsi/scsi_transport_fc.h> 35#include <scsi/scsi_transport_fc.h>
36 36
37#include "lpfc_hw4.h"
37#include "lpfc_hw.h" 38#include "lpfc_hw.h"
38#include "lpfc_sli.h" 39#include "lpfc_sli.h"
40#include "lpfc_sli4.h"
39#include "lpfc_nl.h" 41#include "lpfc_nl.h"
40#include "lpfc_disc.h" 42#include "lpfc_disc.h"
41#include "lpfc_scsi.h" 43#include "lpfc_scsi.h"
@@ -51,9 +53,23 @@ char *_dump_buf_dif;
51unsigned long _dump_buf_dif_order; 53unsigned long _dump_buf_dif_order;
52spinlock_t _dump_buf_lock; 54spinlock_t _dump_buf_lock;
53 55
54static int lpfc_parse_vpd(struct lpfc_hba *, uint8_t *, int);
55static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *); 56static void lpfc_get_hba_model_desc(struct lpfc_hba *, uint8_t *, uint8_t *);
56static int lpfc_post_rcv_buf(struct lpfc_hba *); 57static int lpfc_post_rcv_buf(struct lpfc_hba *);
58static int lpfc_sli4_queue_create(struct lpfc_hba *);
59static void lpfc_sli4_queue_destroy(struct lpfc_hba *);
60static int lpfc_create_bootstrap_mbox(struct lpfc_hba *);
61static int lpfc_setup_endian_order(struct lpfc_hba *);
62static int lpfc_sli4_read_config(struct lpfc_hba *);
63static void lpfc_destroy_bootstrap_mbox(struct lpfc_hba *);
64static void lpfc_free_sgl_list(struct lpfc_hba *);
65static int lpfc_init_sgl_list(struct lpfc_hba *);
66static int lpfc_init_active_sgl_array(struct lpfc_hba *);
67static void lpfc_free_active_sgl(struct lpfc_hba *);
68static int lpfc_hba_down_post_s3(struct lpfc_hba *phba);
69static int lpfc_hba_down_post_s4(struct lpfc_hba *phba);
70static int lpfc_sli4_cq_event_pool_create(struct lpfc_hba *);
71static void lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *);
72static void lpfc_sli4_cq_event_release_all(struct lpfc_hba *);
57 73
58static struct scsi_transport_template *lpfc_transport_template = NULL; 74static struct scsi_transport_template *lpfc_transport_template = NULL;
59static struct scsi_transport_template *lpfc_vport_transport_template = NULL; 75static struct scsi_transport_template *lpfc_vport_transport_template = NULL;
@@ -646,6 +662,77 @@ lpfc_hba_down_post_s3(struct lpfc_hba *phba)
646 662
647 return 0; 663 return 0;
648} 664}
665/**
666 * lpfc_hba_down_post_s4 - Perform lpfc uninitialization after HBA reset
667 * @phba: pointer to lpfc HBA data structure.
668 *
669 * This routine will do uninitialization after the HBA is reset when bring
670 * down the SLI Layer.
671 *
672 * Return codes
673 * 0 - sucess.
674 * Any other value - error.
675 **/
676static int
677lpfc_hba_down_post_s4(struct lpfc_hba *phba)
678{
679 struct lpfc_scsi_buf *psb, *psb_next;
680 LIST_HEAD(aborts);
681 int ret;
682 unsigned long iflag = 0;
683 ret = lpfc_hba_down_post_s3(phba);
684 if (ret)
685 return ret;
686 /* At this point in time the HBA is either reset or DOA. Either
687 * way, nothing should be on lpfc_abts_els_sgl_list, it needs to be
688 * on the lpfc_sgl_list so that it can either be freed if the
689 * driver is unloading or reposted if the driver is restarting
690 * the port.
691 */
692 spin_lock_irq(&phba->hbalock); /* required for lpfc_sgl_list and */
693 /* scsl_buf_list */
694 /* abts_sgl_list_lock required because worker thread uses this
695 * list.
696 */
697 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
698 list_splice_init(&phba->sli4_hba.lpfc_abts_els_sgl_list,
699 &phba->sli4_hba.lpfc_sgl_list);
700 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
701 /* abts_scsi_buf_list_lock required because worker thread uses this
702 * list.
703 */
704 spin_lock(&phba->sli4_hba.abts_scsi_buf_list_lock);
705 list_splice_init(&phba->sli4_hba.lpfc_abts_scsi_buf_list,
706 &aborts);
707 spin_unlock(&phba->sli4_hba.abts_scsi_buf_list_lock);
708 spin_unlock_irq(&phba->hbalock);
709
710 list_for_each_entry_safe(psb, psb_next, &aborts, list) {
711 psb->pCmd = NULL;
712 psb->status = IOSTAT_SUCCESS;
713 }
714 spin_lock_irqsave(&phba->scsi_buf_list_lock, iflag);
715 list_splice(&aborts, &phba->lpfc_scsi_buf_list);
716 spin_unlock_irqrestore(&phba->scsi_buf_list_lock, iflag);
717 return 0;
718}
719
720/**
721 * lpfc_hba_down_post - Wrapper func for hba down post routine
722 * @phba: pointer to lpfc HBA data structure.
723 *
724 * This routine wraps the actual SLI3 or SLI4 routine for performing
725 * uninitialization after the HBA is reset when bring down the SLI Layer.
726 *
727 * Return codes
728 * 0 - sucess.
729 * Any other value - error.
730 **/
731int
732lpfc_hba_down_post(struct lpfc_hba *phba)
733{
734 return (*phba->lpfc_hba_down_post)(phba);
735}
649 736
650/** 737/**
651 * lpfc_hb_timeout - The HBA-timer timeout handler 738 * lpfc_hb_timeout - The HBA-timer timeout handler
@@ -853,6 +940,25 @@ lpfc_offline_eratt(struct lpfc_hba *phba)
853} 940}
854 941
855/** 942/**
943 * lpfc_sli4_offline_eratt - Bring lpfc offline on SLI4 hardware error attention
944 * @phba: pointer to lpfc hba data structure.
945 *
946 * This routine is called to bring a SLI4 HBA offline when HBA hardware error
947 * other than Port Error 6 has been detected.
948 **/
949static void
950lpfc_sli4_offline_eratt(struct lpfc_hba *phba)
951{
952 lpfc_offline_prep(phba);
953 lpfc_offline(phba);
954 lpfc_sli4_brdreset(phba);
955 lpfc_hba_down_post(phba);
956 lpfc_sli4_post_status_check(phba);
957 lpfc_unblock_mgmt_io(phba);
958 phba->link_state = LPFC_HBA_ERROR;
959}
960
961/**
856 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler 962 * lpfc_handle_deferred_eratt - The HBA hardware deferred error handler
857 * @phba: pointer to lpfc hba data structure. 963 * @phba: pointer to lpfc hba data structure.
858 * 964 *
@@ -1057,6 +1163,65 @@ lpfc_handle_eratt_s3(struct lpfc_hba *phba)
1057} 1163}
1058 1164
1059/** 1165/**
1166 * lpfc_handle_eratt_s4 - The SLI4 HBA hardware error handler
1167 * @phba: pointer to lpfc hba data structure.
1168 *
1169 * This routine is invoked to handle the SLI4 HBA hardware error attention
1170 * conditions.
1171 **/
1172static void
1173lpfc_handle_eratt_s4(struct lpfc_hba *phba)
1174{
1175 struct lpfc_vport *vport = phba->pport;
1176 uint32_t event_data;
1177 struct Scsi_Host *shost;
1178
1179 /* If the pci channel is offline, ignore possible errors, since
1180 * we cannot communicate with the pci card anyway.
1181 */
1182 if (pci_channel_offline(phba->pcidev))
1183 return;
1184 /* If resets are disabled then leave the HBA alone and return */
1185 if (!phba->cfg_enable_hba_reset)
1186 return;
1187
1188 /* Send an internal error event to mgmt application */
1189 lpfc_board_errevt_to_mgmt(phba);
1190
1191 /* For now, the actual action for SLI4 device handling is not
1192 * specified yet, just treated it as adaptor hardware failure
1193 */
1194 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
1195 "0143 SLI4 Adapter Hardware Error Data: x%x x%x\n",
1196 phba->work_status[0], phba->work_status[1]);
1197
1198 event_data = FC_REG_DUMP_EVENT;
1199 shost = lpfc_shost_from_vport(vport);
1200 fc_host_post_vendor_event(shost, fc_get_event_number(),
1201 sizeof(event_data), (char *) &event_data,
1202 SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_EMULEX);
1203
1204 lpfc_sli4_offline_eratt(phba);
1205}
1206
1207/**
1208 * lpfc_handle_eratt - Wrapper func for handling hba error attention
1209 * @phba: pointer to lpfc HBA data structure.
1210 *
1211 * This routine wraps the actual SLI3 or SLI4 hba error attention handling
1212 * routine from the API jump table function pointer from the lpfc_hba struct.
1213 *
1214 * Return codes
1215 * 0 - sucess.
1216 * Any other value - error.
1217 **/
1218void
1219lpfc_handle_eratt(struct lpfc_hba *phba)
1220{
1221 (*phba->lpfc_handle_eratt)(phba);
1222}
1223
1224/**
1060 * lpfc_handle_latt - The HBA link event handler 1225 * lpfc_handle_latt - The HBA link event handler
1061 * @phba: pointer to lpfc hba data structure. 1226 * @phba: pointer to lpfc hba data structure.
1062 * 1227 *
@@ -1312,6 +1477,7 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1312 uint16_t dev_id = phba->pcidev->device; 1477 uint16_t dev_id = phba->pcidev->device;
1313 int max_speed; 1478 int max_speed;
1314 int GE = 0; 1479 int GE = 0;
1480 int oneConnect = 0; /* default is not a oneConnect */
1315 struct { 1481 struct {
1316 char * name; 1482 char * name;
1317 int max_speed; 1483 int max_speed;
@@ -1457,6 +1623,14 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1457 case PCI_DEVICE_ID_PROTEUS_S: 1623 case PCI_DEVICE_ID_PROTEUS_S:
1458 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"}; 1624 m = (typeof(m)) {"LPemv12002-S", max_speed, "PCIe IOV"};
1459 break; 1625 break;
1626 case PCI_DEVICE_ID_TIGERSHARK:
1627 oneConnect = 1;
1628 m = (typeof(m)) {"OCe10100-F", max_speed, "PCIe"};
1629 break;
1630 case PCI_DEVICE_ID_TIGERSHARK_S:
1631 oneConnect = 1;
1632 m = (typeof(m)) {"OCe10100-F-S", max_speed, "PCIe"};
1633 break;
1460 default: 1634 default:
1461 m = (typeof(m)){ NULL }; 1635 m = (typeof(m)){ NULL };
1462 break; 1636 break;
@@ -1464,13 +1638,24 @@ lpfc_get_hba_model_desc(struct lpfc_hba *phba, uint8_t *mdp, uint8_t *descp)
1464 1638
1465 if (mdp && mdp[0] == '\0') 1639 if (mdp && mdp[0] == '\0')
1466 snprintf(mdp, 79,"%s", m.name); 1640 snprintf(mdp, 79,"%s", m.name);
1467 if (descp && descp[0] == '\0') 1641 /* oneConnect hba requires special processing, they are all initiators
1468 snprintf(descp, 255, 1642 * and we put the port number on the end
1469 "Emulex %s %d%s %s %s", 1643 */
1470 m.name, m.max_speed, 1644 if (descp && descp[0] == '\0') {
1471 (GE) ? "GE" : "Gb", 1645 if (oneConnect)
1472 m.bus, 1646 snprintf(descp, 255,
1473 (GE) ? "FCoE Adapter" : "Fibre Channel Adapter"); 1647 "Emulex OneConnect %s, FCoE Initiator, Port %s",
1648 m.name,
1649 phba->Port);
1650 else
1651 snprintf(descp, 255,
1652 "Emulex %s %d%s %s %s",
1653 m.name, m.max_speed,
1654 (GE) ? "GE" : "Gb",
1655 m.bus,
1656 (GE) ? "FCoE Adapter" :
1657 "Fibre Channel Adapter");
1658 }
1474} 1659}
1475 1660
1476/** 1661/**
@@ -1911,14 +2096,21 @@ lpfc_online(struct lpfc_hba *phba)
1911 return 1; 2096 return 1;
1912 } 2097 }
1913 2098
1914 if (lpfc_sli_hba_setup(phba)) { /* Initialize the HBA */ 2099 if (phba->sli_rev == LPFC_SLI_REV4) {
1915 lpfc_unblock_mgmt_io(phba); 2100 if (lpfc_sli4_hba_setup(phba)) { /* Initialize SLI4 HBA */
1916 return 1; 2101 lpfc_unblock_mgmt_io(phba);
2102 return 1;
2103 }
2104 } else {
2105 if (lpfc_sli_hba_setup(phba)) { /* Initialize SLI2/SLI3 HBA */
2106 lpfc_unblock_mgmt_io(phba);
2107 return 1;
2108 }
1917 } 2109 }
1918 2110
1919 vports = lpfc_create_vport_work_array(phba); 2111 vports = lpfc_create_vport_work_array(phba);
1920 if (vports != NULL) 2112 if (vports != NULL)
1921 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { 2113 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1922 struct Scsi_Host *shost; 2114 struct Scsi_Host *shost;
1923 shost = lpfc_shost_from_vport(vports[i]); 2115 shost = lpfc_shost_from_vport(vports[i]);
1924 spin_lock_irq(shost->host_lock); 2116 spin_lock_irq(shost->host_lock);
@@ -1980,11 +2172,12 @@ lpfc_offline_prep(struct lpfc_hba * phba)
1980 /* Issue an unreg_login to all nodes on all vports */ 2172 /* Issue an unreg_login to all nodes on all vports */
1981 vports = lpfc_create_vport_work_array(phba); 2173 vports = lpfc_create_vport_work_array(phba);
1982 if (vports != NULL) { 2174 if (vports != NULL) {
1983 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { 2175 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
1984 struct Scsi_Host *shost; 2176 struct Scsi_Host *shost;
1985 2177
1986 if (vports[i]->load_flag & FC_UNLOADING) 2178 if (vports[i]->load_flag & FC_UNLOADING)
1987 continue; 2179 continue;
2180 vports[i]->vfi_state &= ~LPFC_VFI_REGISTERED;
1988 shost = lpfc_shost_from_vport(vports[i]); 2181 shost = lpfc_shost_from_vport(vports[i]);
1989 list_for_each_entry_safe(ndlp, next_ndlp, 2182 list_for_each_entry_safe(ndlp, next_ndlp,
1990 &vports[i]->fc_nodes, 2183 &vports[i]->fc_nodes,
@@ -2029,11 +2222,11 @@ lpfc_offline(struct lpfc_hba *phba)
2029 if (phba->pport->fc_flag & FC_OFFLINE_MODE) 2222 if (phba->pport->fc_flag & FC_OFFLINE_MODE)
2030 return; 2223 return;
2031 2224
2032 /* stop all timers associated with this hba */ 2225 /* stop port and all timers associated with this hba */
2033 lpfc_stop_phba_timers(phba); 2226 lpfc_stop_port(phba);
2034 vports = lpfc_create_vport_work_array(phba); 2227 vports = lpfc_create_vport_work_array(phba);
2035 if (vports != NULL) 2228 if (vports != NULL)
2036 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) 2229 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
2037 lpfc_stop_vport_timers(vports[i]); 2230 lpfc_stop_vport_timers(vports[i]);
2038 lpfc_destroy_vport_work_array(phba, vports); 2231 lpfc_destroy_vport_work_array(phba, vports);
2039 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 2232 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
@@ -2046,7 +2239,7 @@ lpfc_offline(struct lpfc_hba *phba)
2046 spin_unlock_irq(&phba->hbalock); 2239 spin_unlock_irq(&phba->hbalock);
2047 vports = lpfc_create_vport_work_array(phba); 2240 vports = lpfc_create_vport_work_array(phba);
2048 if (vports != NULL) 2241 if (vports != NULL)
2049 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) { 2242 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2050 shost = lpfc_shost_from_vport(vports[i]); 2243 shost = lpfc_shost_from_vport(vports[i]);
2051 spin_lock_irq(shost->host_lock); 2244 spin_lock_irq(shost->host_lock);
2052 vports[i]->work_port_events = 0; 2245 vports[i]->work_port_events = 0;
@@ -2139,6 +2332,10 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
2139 shost->max_lun = vport->cfg_max_luns; 2332 shost->max_lun = vport->cfg_max_luns;
2140 shost->this_id = -1; 2333 shost->this_id = -1;
2141 shost->max_cmd_len = 16; 2334 shost->max_cmd_len = 16;
2335 if (phba->sli_rev == LPFC_SLI_REV4) {
2336 shost->dma_boundary = LPFC_SLI4_MAX_SEGMENT_SIZE;
2337 shost->sg_tablesize = phba->cfg_sg_seg_cnt;
2338 }
2142 2339
2143 /* 2340 /*
2144 * Set initial can_queue value since 0 is no longer supported and 2341 * Set initial can_queue value since 0 is no longer supported and
@@ -2156,6 +2353,7 @@ lpfc_create_port(struct lpfc_hba *phba, int instance, struct device *dev)
2156 2353
2157 /* Initialize all internally managed lists. */ 2354 /* Initialize all internally managed lists. */
2158 INIT_LIST_HEAD(&vport->fc_nodes); 2355 INIT_LIST_HEAD(&vport->fc_nodes);
2356 INIT_LIST_HEAD(&vport->rcv_buffer_list);
2159 spin_lock_init(&vport->work_port_lock); 2357 spin_lock_init(&vport->work_port_lock);
2160 2358
2161 init_timer(&vport->fc_disctmo); 2359 init_timer(&vport->fc_disctmo);
@@ -2347,192 +2545,501 @@ void lpfc_host_attrib_init(struct Scsi_Host *shost)
2347} 2545}
2348 2546
2349/** 2547/**
2350 * lpfc_enable_msix - Enable MSI-X interrupt mode 2548 * lpfc_stop_port_s3 - Stop SLI3 device port
2351 * @phba: pointer to lpfc hba data structure. 2549 * @phba: pointer to lpfc hba data structure.
2352 * 2550 *
2353 * This routine is invoked to enable the MSI-X interrupt vectors. The kernel 2551 * This routine is invoked to stop an SLI3 device port, it stops the device
2354 * function pci_enable_msix() is called to enable the MSI-X vectors. Note that 2552 * from generating interrupts and stops the device driver's timers for the
2355 * pci_enable_msix(), once invoked, enables either all or nothing, depending 2553 * device.
2356 * on the current availability of PCI vector resources. The device driver is 2554 **/
2357 * responsible for calling the individual request_irq() to register each MSI-X 2555static void
2358 * vector with a interrupt handler, which is done in this function. Note that 2556lpfc_stop_port_s3(struct lpfc_hba *phba)
2359 * later when device is unloading, the driver should always call free_irq() 2557{
2360 * on all MSI-X vectors it has done request_irq() on before calling 2558 /* Clear all interrupt enable conditions */
2361 * pci_disable_msix(). Failure to do so results in a BUG_ON() and a device 2559 writel(0, phba->HCregaddr);
2362 * will be left with MSI-X enabled and leaks its vectors. 2560 readl(phba->HCregaddr); /* flush */
2561 /* Clear all pending interrupts */
2562 writel(0xffffffff, phba->HAregaddr);
2563 readl(phba->HAregaddr); /* flush */
2564
2565 /* Reset some HBA SLI setup states */
2566 lpfc_stop_hba_timers(phba);
2567 phba->pport->work_port_events = 0;
2568}
2569
2570/**
2571 * lpfc_stop_port_s4 - Stop SLI4 device port
2572 * @phba: pointer to lpfc hba data structure.
2363 * 2573 *
2364 * Return codes 2574 * This routine is invoked to stop an SLI4 device port, it stops the device
2365 * 0 - sucessful 2575 * from generating interrupts and stops the device driver's timers for the
2366 * other values - error 2576 * device.
2367 **/ 2577 **/
2368static int 2578static void
2369lpfc_enable_msix(struct lpfc_hba *phba) 2579lpfc_stop_port_s4(struct lpfc_hba *phba)
2370{ 2580{
2371 int rc, i; 2581 /* Reset some HBA SLI4 setup states */
2372 LPFC_MBOXQ_t *pmb; 2582 lpfc_stop_hba_timers(phba);
2583 phba->pport->work_port_events = 0;
2584 phba->sli4_hba.intr_enable = 0;
2585 /* Hard clear it for now, shall have more graceful way to wait later */
2586 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
2587}
2373 2588
2374 /* Set up MSI-X multi-message vectors */ 2589/**
2375 for (i = 0; i < LPFC_MSIX_VECTORS; i++) 2590 * lpfc_stop_port - Wrapper function for stopping hba port
2376 phba->msix_entries[i].entry = i; 2591 * @phba: Pointer to HBA context object.
2592 *
2593 * This routine wraps the actual SLI3 or SLI4 hba stop port routine from
2594 * the API jump table function pointer from the lpfc_hba struct.
2595 **/
2596void
2597lpfc_stop_port(struct lpfc_hba *phba)
2598{
2599 phba->lpfc_stop_port(phba);
2600}
2377 2601
2378 /* Configure MSI-X capability structure */ 2602/**
2379 rc = pci_enable_msix(phba->pcidev, phba->msix_entries, 2603 * lpfc_sli4_remove_dflt_fcf - Remove the driver default fcf record from the port.
2380 ARRAY_SIZE(phba->msix_entries)); 2604 * @phba: pointer to lpfc hba data structure.
2381 if (rc) { 2605 *
2382 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 2606 * This routine is invoked to remove the driver default fcf record from
2383 "0420 PCI enable MSI-X failed (%d)\n", rc); 2607 * the port. This routine currently acts on FCF Index 0.
2384 goto msi_fail_out; 2608 *
2385 } else 2609 **/
2386 for (i = 0; i < LPFC_MSIX_VECTORS; i++) 2610void
2387 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 2611lpfc_sli_remove_dflt_fcf(struct lpfc_hba *phba)
2388 "0477 MSI-X entry[%d]: vector=x%x " 2612{
2389 "message=%d\n", i, 2613 int rc = 0;
2390 phba->msix_entries[i].vector, 2614 LPFC_MBOXQ_t *mboxq;
2391 phba->msix_entries[i].entry); 2615 struct lpfc_mbx_del_fcf_tbl_entry *del_fcf_record;
2616 uint32_t mbox_tmo, req_len;
2617 uint32_t shdr_status, shdr_add_status;
2618
2619 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2620 if (!mboxq) {
2621 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2622 "2020 Failed to allocate mbox for ADD_FCF cmd\n");
2623 return;
2624 }
2625
2626 req_len = sizeof(struct lpfc_mbx_del_fcf_tbl_entry) -
2627 sizeof(struct lpfc_sli4_cfg_mhdr);
2628 rc = lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_FCOE,
2629 LPFC_MBOX_OPCODE_FCOE_DELETE_FCF,
2630 req_len, LPFC_SLI4_MBX_EMBED);
2392 /* 2631 /*
2393 * Assign MSI-X vectors to interrupt handlers 2632 * In phase 1, there is a single FCF index, 0. In phase2, the driver
2633 * supports multiple FCF indices.
2394 */ 2634 */
2635 del_fcf_record = &mboxq->u.mqe.un.del_fcf_entry;
2636 bf_set(lpfc_mbx_del_fcf_tbl_count, del_fcf_record, 1);
2637 bf_set(lpfc_mbx_del_fcf_tbl_index, del_fcf_record,
2638 phba->fcf.fcf_indx);
2395 2639
2396 /* vector-0 is associated to slow-path handler */ 2640 if (!phba->sli4_hba.intr_enable)
2397 rc = request_irq(phba->msix_entries[0].vector, &lpfc_sp_intr_handler, 2641 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
2398 IRQF_SHARED, LPFC_SP_DRIVER_HANDLER_NAME, phba); 2642 else {
2399 if (rc) { 2643 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
2400 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 2644 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
2401 "0421 MSI-X slow-path request_irq failed " 2645 }
2402 "(%d)\n", rc); 2646 /* The IOCTL status is embedded in the mailbox subheader. */
2403 goto msi_fail_out; 2647 shdr_status = bf_get(lpfc_mbox_hdr_status,
2648 &del_fcf_record->header.cfg_shdr.response);
2649 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
2650 &del_fcf_record->header.cfg_shdr.response);
2651 if (shdr_status || shdr_add_status || rc != MBX_SUCCESS) {
2652 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2653 "2516 DEL FCF of default FCF Index failed "
2654 "mbx status x%x, status x%x add_status x%x\n",
2655 rc, shdr_status, shdr_add_status);
2404 } 2656 }
2657 if (rc != MBX_TIMEOUT)
2658 mempool_free(mboxq, phba->mbox_mem_pool);
2659}
2405 2660
2406 /* vector-1 is associated to fast-path handler */ 2661/**
2407 rc = request_irq(phba->msix_entries[1].vector, &lpfc_fp_intr_handler, 2662 * lpfc_sli4_parse_latt_fault - Parse sli4 link-attention link fault code
2408 IRQF_SHARED, LPFC_FP_DRIVER_HANDLER_NAME, phba); 2663 * @phba: pointer to lpfc hba data structure.
2664 * @acqe_link: pointer to the async link completion queue entry.
2665 *
2666 * This routine is to parse the SLI4 link-attention link fault code and
2667 * translate it into the base driver's read link attention mailbox command
2668 * status.
2669 *
2670 * Return: Link-attention status in terms of base driver's coding.
2671 **/
2672static uint16_t
2673lpfc_sli4_parse_latt_fault(struct lpfc_hba *phba,
2674 struct lpfc_acqe_link *acqe_link)
2675{
2676 uint16_t latt_fault;
2409 2677
2410 if (rc) { 2678 switch (bf_get(lpfc_acqe_link_fault, acqe_link)) {
2411 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 2679 case LPFC_ASYNC_LINK_FAULT_NONE:
2412 "0429 MSI-X fast-path request_irq failed " 2680 case LPFC_ASYNC_LINK_FAULT_LOCAL:
2413 "(%d)\n", rc); 2681 case LPFC_ASYNC_LINK_FAULT_REMOTE:
2414 goto irq_fail_out; 2682 latt_fault = 0;
2683 break;
2684 default:
2685 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2686 "0398 Invalid link fault code: x%x\n",
2687 bf_get(lpfc_acqe_link_fault, acqe_link));
2688 latt_fault = MBXERR_ERROR;
2689 break;
2415 } 2690 }
2691 return latt_fault;
2692}
2416 2693
2417 /* 2694/**
2418 * Configure HBA MSI-X attention conditions to messages 2695 * lpfc_sli4_parse_latt_type - Parse sli4 link attention type
2419 */ 2696 * @phba: pointer to lpfc hba data structure.
2420 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL); 2697 * @acqe_link: pointer to the async link completion queue entry.
2698 *
2699 * This routine is to parse the SLI4 link attention type and translate it
2700 * into the base driver's link attention type coding.
2701 *
2702 * Return: Link attention type in terms of base driver's coding.
2703 **/
2704static uint8_t
2705lpfc_sli4_parse_latt_type(struct lpfc_hba *phba,
2706 struct lpfc_acqe_link *acqe_link)
2707{
2708 uint8_t att_type;
2421 2709
2422 if (!pmb) { 2710 switch (bf_get(lpfc_acqe_link_status, acqe_link)) {
2423 rc = -ENOMEM; 2711 case LPFC_ASYNC_LINK_STATUS_DOWN:
2712 case LPFC_ASYNC_LINK_STATUS_LOGICAL_DOWN:
2713 att_type = AT_LINK_DOWN;
2714 break;
2715 case LPFC_ASYNC_LINK_STATUS_UP:
2716 /* Ignore physical link up events - wait for logical link up */
2717 att_type = AT_RESERVED;
2718 break;
2719 case LPFC_ASYNC_LINK_STATUS_LOGICAL_UP:
2720 att_type = AT_LINK_UP;
2721 break;
2722 default:
2424 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 2723 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2425 "0474 Unable to allocate memory for issuing " 2724 "0399 Invalid link attention type: x%x\n",
2426 "MBOX_CONFIG_MSI command\n"); 2725 bf_get(lpfc_acqe_link_status, acqe_link));
2427 goto mem_fail_out; 2726 att_type = AT_RESERVED;
2727 break;
2428 } 2728 }
2429 rc = lpfc_config_msi(phba, pmb); 2729 return att_type;
2430 if (rc) 2730}
2431 goto mbx_fail_out; 2731
2432 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL); 2732/**
2433 if (rc != MBX_SUCCESS) { 2733 * lpfc_sli4_parse_latt_link_speed - Parse sli4 link-attention link speed
2434 lpfc_printf_log(phba, KERN_WARNING, LOG_MBOX, 2734 * @phba: pointer to lpfc hba data structure.
2435 "0351 Config MSI mailbox command failed, " 2735 * @acqe_link: pointer to the async link completion queue entry.
2436 "mbxCmd x%x, mbxStatus x%x\n", 2736 *
2437 pmb->mb.mbxCommand, pmb->mb.mbxStatus); 2737 * This routine is to parse the SLI4 link-attention link speed and translate
2438 goto mbx_fail_out; 2738 * it into the base driver's link-attention link speed coding.
2739 *
2740 * Return: Link-attention link speed in terms of base driver's coding.
2741 **/
2742static uint8_t
2743lpfc_sli4_parse_latt_link_speed(struct lpfc_hba *phba,
2744 struct lpfc_acqe_link *acqe_link)
2745{
2746 uint8_t link_speed;
2747
2748 switch (bf_get(lpfc_acqe_link_speed, acqe_link)) {
2749 case LPFC_ASYNC_LINK_SPEED_ZERO:
2750 link_speed = LA_UNKNW_LINK;
2751 break;
2752 case LPFC_ASYNC_LINK_SPEED_10MBPS:
2753 link_speed = LA_UNKNW_LINK;
2754 break;
2755 case LPFC_ASYNC_LINK_SPEED_100MBPS:
2756 link_speed = LA_UNKNW_LINK;
2757 break;
2758 case LPFC_ASYNC_LINK_SPEED_1GBPS:
2759 link_speed = LA_1GHZ_LINK;
2760 break;
2761 case LPFC_ASYNC_LINK_SPEED_10GBPS:
2762 link_speed = LA_10GHZ_LINK;
2763 break;
2764 default:
2765 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2766 "0483 Invalid link-attention link speed: x%x\n",
2767 bf_get(lpfc_acqe_link_speed, acqe_link));
2768 link_speed = LA_UNKNW_LINK;
2769 break;
2439 } 2770 }
2771 return link_speed;
2772}
2440 2773
2441 /* Free memory allocated for mailbox command */ 2774/**
2442 mempool_free(pmb, phba->mbox_mem_pool); 2775 * lpfc_sli4_async_link_evt - Process the asynchronous link event
2443 return rc; 2776 * @phba: pointer to lpfc hba data structure.
2777 * @acqe_link: pointer to the async link completion queue entry.
2778 *
2779 * This routine is to handle the SLI4 asynchronous link event.
2780 **/
2781static void
2782lpfc_sli4_async_link_evt(struct lpfc_hba *phba,
2783 struct lpfc_acqe_link *acqe_link)
2784{
2785 struct lpfc_dmabuf *mp;
2786 LPFC_MBOXQ_t *pmb;
2787 MAILBOX_t *mb;
2788 READ_LA_VAR *la;
2789 uint8_t att_type;
2444 2790
2445mbx_fail_out: 2791 att_type = lpfc_sli4_parse_latt_type(phba, acqe_link);
2446 /* Free memory allocated for mailbox command */ 2792 if (att_type != AT_LINK_DOWN && att_type != AT_LINK_UP)
2447 mempool_free(pmb, phba->mbox_mem_pool); 2793 return;
2794 pmb = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2795 if (!pmb) {
2796 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2797 "0395 The mboxq allocation failed\n");
2798 return;
2799 }
2800 mp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
2801 if (!mp) {
2802 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2803 "0396 The lpfc_dmabuf allocation failed\n");
2804 goto out_free_pmb;
2805 }
2806 mp->virt = lpfc_mbuf_alloc(phba, 0, &mp->phys);
2807 if (!mp->virt) {
2808 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2809 "0397 The mbuf allocation failed\n");
2810 goto out_free_dmabuf;
2811 }
2448 2812
2449mem_fail_out: 2813 /* Cleanup any outstanding ELS commands */
2450 /* free the irq already requested */ 2814 lpfc_els_flush_all_cmd(phba);
2451 free_irq(phba->msix_entries[1].vector, phba);
2452 2815
2453irq_fail_out: 2816 /* Block ELS IOCBs until we have done process link event */
2454 /* free the irq already requested */ 2817 phba->sli.ring[LPFC_ELS_RING].flag |= LPFC_STOP_IOCB_EVENT;
2455 free_irq(phba->msix_entries[0].vector, phba);
2456 2818
2457msi_fail_out: 2819 /* Update link event statistics */
2458 /* Unconfigure MSI-X capability structure */ 2820 phba->sli.slistat.link_event++;
2459 pci_disable_msix(phba->pcidev); 2821
2460 return rc; 2822 /* Create pseudo lpfc_handle_latt mailbox command from link ACQE */
2823 lpfc_read_la(phba, pmb, mp);
2824 pmb->vport = phba->pport;
2825
2826 /* Parse and translate status field */
2827 mb = &pmb->u.mb;
2828 mb->mbxStatus = lpfc_sli4_parse_latt_fault(phba, acqe_link);
2829
2830 /* Parse and translate link attention fields */
2831 la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
2832 la->eventTag = acqe_link->event_tag;
2833 la->attType = att_type;
2834 la->UlnkSpeed = lpfc_sli4_parse_latt_link_speed(phba, acqe_link);
2835
2836 /* Fake the the following irrelvant fields */
2837 la->topology = TOPOLOGY_PT_PT;
2838 la->granted_AL_PA = 0;
2839 la->il = 0;
2840 la->pb = 0;
2841 la->fa = 0;
2842 la->mm = 0;
2843
2844 /* Keep the link status for extra SLI4 state machine reference */
2845 phba->sli4_hba.link_state.speed =
2846 bf_get(lpfc_acqe_link_speed, acqe_link);
2847 phba->sli4_hba.link_state.duplex =
2848 bf_get(lpfc_acqe_link_duplex, acqe_link);
2849 phba->sli4_hba.link_state.status =
2850 bf_get(lpfc_acqe_link_status, acqe_link);
2851 phba->sli4_hba.link_state.physical =
2852 bf_get(lpfc_acqe_link_physical, acqe_link);
2853 phba->sli4_hba.link_state.fault =
2854 bf_get(lpfc_acqe_link_fault, acqe_link);
2855
2856 /* Invoke the lpfc_handle_latt mailbox command callback function */
2857 lpfc_mbx_cmpl_read_la(phba, pmb);
2858
2859 return;
2860
2861out_free_dmabuf:
2862 kfree(mp);
2863out_free_pmb:
2864 mempool_free(pmb, phba->mbox_mem_pool);
2461} 2865}
2462 2866
2463/** 2867/**
2464 * lpfc_disable_msix - Disable MSI-X interrupt mode 2868 * lpfc_sli4_async_fcoe_evt - Process the asynchronous fcoe event
2465 * @phba: pointer to lpfc hba data structure. 2869 * @phba: pointer to lpfc hba data structure.
2870 * @acqe_link: pointer to the async fcoe completion queue entry.
2466 * 2871 *
2467 * This routine is invoked to release the MSI-X vectors and then disable the 2872 * This routine is to handle the SLI4 asynchronous fcoe event.
2468 * MSI-X interrupt mode.
2469 **/ 2873 **/
2470static void 2874static void
2471lpfc_disable_msix(struct lpfc_hba *phba) 2875lpfc_sli4_async_fcoe_evt(struct lpfc_hba *phba,
2876 struct lpfc_acqe_fcoe *acqe_fcoe)
2472{ 2877{
2473 int i; 2878 uint8_t event_type = bf_get(lpfc_acqe_fcoe_event_type, acqe_fcoe);
2879 int rc;
2474 2880
2475 /* Free up MSI-X multi-message vectors */ 2881 switch (event_type) {
2476 for (i = 0; i < LPFC_MSIX_VECTORS; i++) 2882 case LPFC_FCOE_EVENT_TYPE_NEW_FCF:
2477 free_irq(phba->msix_entries[i].vector, phba); 2883 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2478 /* Disable MSI-X */ 2884 "2546 New FCF found index 0x%x tag 0x%x \n",
2479 pci_disable_msix(phba->pcidev); 2885 acqe_fcoe->fcf_index,
2886 acqe_fcoe->event_tag);
2887 /*
2888 * If the current FCF is in discovered state,
2889 * do nothing.
2890 */
2891 spin_lock_irq(&phba->hbalock);
2892 if (phba->fcf.fcf_flag & FCF_DISCOVERED) {
2893 spin_unlock_irq(&phba->hbalock);
2894 break;
2895 }
2896 spin_unlock_irq(&phba->hbalock);
2897
2898 /* Read the FCF table and re-discover SAN. */
2899 rc = lpfc_sli4_read_fcf_record(phba,
2900 LPFC_FCOE_FCF_GET_FIRST);
2901 if (rc)
2902 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2903 "2547 Read FCF record failed 0x%x\n",
2904 rc);
2905 break;
2906
2907 case LPFC_FCOE_EVENT_TYPE_FCF_TABLE_FULL:
2908 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2909 "2548 FCF Table full count 0x%x tag 0x%x \n",
2910 bf_get(lpfc_acqe_fcoe_fcf_count, acqe_fcoe),
2911 acqe_fcoe->event_tag);
2912 break;
2913
2914 case LPFC_FCOE_EVENT_TYPE_FCF_DEAD:
2915 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2916 "2549 FCF disconnected fron network index 0x%x"
2917 " tag 0x%x \n", acqe_fcoe->fcf_index,
2918 acqe_fcoe->event_tag);
2919 /* If the event is not for currently used fcf do nothing */
2920 if (phba->fcf.fcf_indx != acqe_fcoe->fcf_index)
2921 break;
2922 /*
2923 * Currently, driver support only one FCF - so treat this as
2924 * a link down.
2925 */
2926 lpfc_linkdown(phba);
2927 /* Unregister FCF if no devices connected to it */
2928 lpfc_unregister_unused_fcf(phba);
2929 break;
2930
2931 default:
2932 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2933 "0288 Unknown FCoE event type 0x%x event tag "
2934 "0x%x\n", event_type, acqe_fcoe->event_tag);
2935 break;
2936 }
2480} 2937}
2481 2938
2482/** 2939/**
2483 * lpfc_enable_msi - Enable MSI interrupt mode 2940 * lpfc_sli4_async_dcbx_evt - Process the asynchronous dcbx event
2484 * @phba: pointer to lpfc hba data structure. 2941 * @phba: pointer to lpfc hba data structure.
2942 * @acqe_link: pointer to the async dcbx completion queue entry.
2485 * 2943 *
2486 * This routine is invoked to enable the MSI interrupt mode. The kernel 2944 * This routine is to handle the SLI4 asynchronous dcbx event.
2487 * function pci_enable_msi() is called to enable the MSI vector. The 2945 **/
2488 * device driver is responsible for calling the request_irq() to register 2946static void
2489 * MSI vector with a interrupt the handler, which is done in this function. 2947lpfc_sli4_async_dcbx_evt(struct lpfc_hba *phba,
2490 * 2948 struct lpfc_acqe_dcbx *acqe_dcbx)
2491 * Return codes
2492 * 0 - sucessful
2493 * other values - error
2494 */
2495static int
2496lpfc_enable_msi(struct lpfc_hba *phba)
2497{ 2949{
2498 int rc; 2950 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2951 "0290 The SLI4 DCBX asynchronous event is not "
2952 "handled yet\n");
2953}
2499 2954
2500 rc = pci_enable_msi(phba->pcidev); 2955/**
2501 if (!rc) 2956 * lpfc_sli4_async_event_proc - Process all the pending asynchronous event
2502 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 2957 * @phba: pointer to lpfc hba data structure.
2503 "0462 PCI enable MSI mode success.\n"); 2958 *
2504 else { 2959 * This routine is invoked by the worker thread to process all the pending
2505 lpfc_printf_log(phba, KERN_INFO, LOG_INIT, 2960 * SLI4 asynchronous events.
2506 "0471 PCI enable MSI mode failed (%d)\n", rc); 2961 **/
2507 return rc; 2962void lpfc_sli4_async_event_proc(struct lpfc_hba *phba)
2508 } 2963{
2964 struct lpfc_cq_event *cq_event;
2509 2965
2510 rc = request_irq(phba->pcidev->irq, lpfc_intr_handler, 2966 /* First, declare the async event has been handled */
2511 IRQF_SHARED, LPFC_DRIVER_NAME, phba); 2967 spin_lock_irq(&phba->hbalock);
2512 if (rc) { 2968 phba->hba_flag &= ~ASYNC_EVENT;
2513 pci_disable_msi(phba->pcidev); 2969 spin_unlock_irq(&phba->hbalock);
2514 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT, 2970 /* Now, handle all the async events */
2515 "0478 MSI request_irq failed (%d)\n", rc); 2971 while (!list_empty(&phba->sli4_hba.sp_asynce_work_queue)) {
2972 /* Get the first event from the head of the event queue */
2973 spin_lock_irq(&phba->hbalock);
2974 list_remove_head(&phba->sli4_hba.sp_asynce_work_queue,
2975 cq_event, struct lpfc_cq_event, list);
2976 spin_unlock_irq(&phba->hbalock);
2977 /* Process the asynchronous event */
2978 switch (bf_get(lpfc_trailer_code, &cq_event->cqe.mcqe_cmpl)) {
2979 case LPFC_TRAILER_CODE_LINK:
2980 lpfc_sli4_async_link_evt(phba,
2981 &cq_event->cqe.acqe_link);
2982 break;
2983 case LPFC_TRAILER_CODE_FCOE:
2984 lpfc_sli4_async_fcoe_evt(phba,
2985 &cq_event->cqe.acqe_fcoe);
2986 break;
2987 case LPFC_TRAILER_CODE_DCBX:
2988 lpfc_sli4_async_dcbx_evt(phba,
2989 &cq_event->cqe.acqe_dcbx);
2990 break;
2991 default:
2992 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
2993 "1804 Invalid asynchrous event code: "
2994 "x%x\n", bf_get(lpfc_trailer_code,
2995 &cq_event->cqe.mcqe_cmpl));
2996 break;
2997 }
2998 /* Free the completion event processed to the free pool */
2999 lpfc_sli4_cq_event_release(phba, cq_event);
2516 } 3000 }
2517 return rc;
2518} 3001}
2519 3002
2520/** 3003/**
2521 * lpfc_disable_msi - Disable MSI interrupt mode 3004 * lpfc_api_table_setup - Set up per hba pci-device group func api jump table
2522 * @phba: pointer to lpfc hba data structure. 3005 * @phba: pointer to lpfc hba data structure.
3006 * @dev_grp: The HBA PCI-Device group number.
2523 * 3007 *
2524 * This routine is invoked to disable the MSI interrupt mode. The driver 3008 * This routine is invoked to set up the per HBA PCI-Device group function
2525 * calls free_irq() on MSI vector it has done request_irq() on before 3009 * API jump table entries.
2526 * calling pci_disable_msi(). Failure to do so results in a BUG_ON() and 3010 *
2527 * a device will be left with MSI enabled and leaks its vector. 3011 * Return: 0 if success, otherwise -ENODEV
2528 */ 3012 **/
2529 3013int
2530static void 3014lpfc_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2531lpfc_disable_msi(struct lpfc_hba *phba)
2532{ 3015{
2533 free_irq(phba->pcidev->irq, phba); 3016 int rc;
2534 pci_disable_msi(phba->pcidev); 3017
2535 return; 3018 /* Set up lpfc PCI-device group */
3019 phba->pci_dev_grp = dev_grp;
3020
3021 /* The LPFC_PCI_DEV_OC uses SLI4 */
3022 if (dev_grp == LPFC_PCI_DEV_OC)
3023 phba->sli_rev = LPFC_SLI_REV4;
3024
3025 /* Set up device INIT API function jump table */
3026 rc = lpfc_init_api_table_setup(phba, dev_grp);
3027 if (rc)
3028 return -ENODEV;
3029 /* Set up SCSI API function jump table */
3030 rc = lpfc_scsi_api_table_setup(phba, dev_grp);
3031 if (rc)
3032 return -ENODEV;
3033 /* Set up SLI API function jump table */
3034 rc = lpfc_sli_api_table_setup(phba, dev_grp);
3035 if (rc)
3036 return -ENODEV;
3037 /* Set up MBOX API function jump table */
3038 rc = lpfc_mbox_api_table_setup(phba, dev_grp);
3039 if (rc)
3040 return -ENODEV;
3041
3042 return 0;
2536} 3043}
2537 3044
2538/** 3045/**
@@ -2764,6 +3271,292 @@ lpfc_sli_driver_resource_unset(struct lpfc_hba *phba)
2764} 3271}
2765 3272
2766/** 3273/**
3274 * lpfc_sli4_driver_resource_setup - Setup drvr internal resources for SLI4 dev
3275 * @phba: pointer to lpfc hba data structure.
3276 *
3277 * This routine is invoked to set up the driver internal resources specific to
3278 * support the SLI-4 HBA device it attached to.
3279 *
3280 * Return codes
3281 * 0 - sucessful
3282 * other values - error
3283 **/
3284static int
3285lpfc_sli4_driver_resource_setup(struct lpfc_hba *phba)
3286{
3287 struct lpfc_sli *psli;
3288 int rc;
3289 int i, hbq_count;
3290
3291 /* Before proceed, wait for POST done and device ready */
3292 rc = lpfc_sli4_post_status_check(phba);
3293 if (rc)
3294 return -ENODEV;
3295
3296 /*
3297 * Initialize timers used by driver
3298 */
3299
3300 /* Heartbeat timer */
3301 init_timer(&phba->hb_tmofunc);
3302 phba->hb_tmofunc.function = lpfc_hb_timeout;
3303 phba->hb_tmofunc.data = (unsigned long)phba;
3304
3305 psli = &phba->sli;
3306 /* MBOX heartbeat timer */
3307 init_timer(&psli->mbox_tmo);
3308 psli->mbox_tmo.function = lpfc_mbox_timeout;
3309 psli->mbox_tmo.data = (unsigned long) phba;
3310 /* Fabric block timer */
3311 init_timer(&phba->fabric_block_timer);
3312 phba->fabric_block_timer.function = lpfc_fabric_block_timeout;
3313 phba->fabric_block_timer.data = (unsigned long) phba;
3314 /* EA polling mode timer */
3315 init_timer(&phba->eratt_poll);
3316 phba->eratt_poll.function = lpfc_poll_eratt;
3317 phba->eratt_poll.data = (unsigned long) phba;
3318 /*
3319 * We need to do a READ_CONFIG mailbox command here before
3320 * calling lpfc_get_cfgparam. For VFs this will report the
3321 * MAX_XRI, MAX_VPI, MAX_RPI, MAX_IOCB, and MAX_VFI settings.
3322 * All of the resources allocated
3323 * for this Port are tied to these values.
3324 */
3325 /* Get all the module params for configuring this host */
3326 lpfc_get_cfgparam(phba);
3327 phba->max_vpi = LPFC_MAX_VPI;
3328 /* This will be set to correct value after the read_config mbox */
3329 phba->max_vports = 0;
3330
3331 /* Program the default value of vlan_id and fc_map */
3332 phba->valid_vlan = 0;
3333 phba->fc_map[0] = LPFC_FCOE_FCF_MAP0;
3334 phba->fc_map[1] = LPFC_FCOE_FCF_MAP1;
3335 phba->fc_map[2] = LPFC_FCOE_FCF_MAP2;
3336
3337 /*
3338 * Since the sg_tablesize is module parameter, the sg_dma_buf_size
3339 * used to create the sg_dma_buf_pool must be dynamically calculated.
3340 * 2 segments are added since the IOCB needs a command and response bde.
3341 * To insure that the scsi sgl does not cross a 4k page boundary only
3342 * sgl sizes of 1k, 2k, 4k, and 8k are supported.
3343 * Table of sgl sizes and seg_cnt:
3344 * sgl size, sg_seg_cnt total seg
3345 * 1k 50 52
3346 * 2k 114 116
3347 * 4k 242 244
3348 * 8k 498 500
3349 * cmd(32) + rsp(160) + (52 * sizeof(sli4_sge)) = 1024
3350 * cmd(32) + rsp(160) + (116 * sizeof(sli4_sge)) = 2048
3351 * cmd(32) + rsp(160) + (244 * sizeof(sli4_sge)) = 4096
3352 * cmd(32) + rsp(160) + (500 * sizeof(sli4_sge)) = 8192
3353 */
3354 if (phba->cfg_sg_seg_cnt <= LPFC_DEFAULT_SG_SEG_CNT)
3355 phba->cfg_sg_seg_cnt = 50;
3356 else if (phba->cfg_sg_seg_cnt <= 114)
3357 phba->cfg_sg_seg_cnt = 114;
3358 else if (phba->cfg_sg_seg_cnt <= 242)
3359 phba->cfg_sg_seg_cnt = 242;
3360 else
3361 phba->cfg_sg_seg_cnt = 498;
3362
3363 phba->cfg_sg_dma_buf_size = sizeof(struct fcp_cmnd)
3364 + sizeof(struct fcp_rsp);
3365 phba->cfg_sg_dma_buf_size +=
3366 ((phba->cfg_sg_seg_cnt + 2) * sizeof(struct sli4_sge));
3367
3368 /* Initialize buffer queue management fields */
3369 hbq_count = lpfc_sli_hbq_count();
3370 for (i = 0; i < hbq_count; ++i)
3371 INIT_LIST_HEAD(&phba->hbqs[i].hbq_buffer_list);
3372 INIT_LIST_HEAD(&phba->rb_pend_list);
3373 phba->hbqs[LPFC_ELS_HBQ].hbq_alloc_buffer = lpfc_sli4_rb_alloc;
3374 phba->hbqs[LPFC_ELS_HBQ].hbq_free_buffer = lpfc_sli4_rb_free;
3375
3376 /*
3377 * Initialize the SLI Layer to run with lpfc SLI4 HBAs.
3378 */
3379 /* Initialize the Abort scsi buffer list used by driver */
3380 spin_lock_init(&phba->sli4_hba.abts_scsi_buf_list_lock);
3381 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_scsi_buf_list);
3382 /* This abort list used by worker thread */
3383 spin_lock_init(&phba->sli4_hba.abts_sgl_list_lock);
3384
3385 /*
3386 * Initialize dirver internal slow-path work queues
3387 */
3388
3389 /* Driver internel slow-path CQ Event pool */
3390 INIT_LIST_HEAD(&phba->sli4_hba.sp_cqe_event_pool);
3391 /* Response IOCB work queue list */
3392 INIT_LIST_HEAD(&phba->sli4_hba.sp_rspiocb_work_queue);
3393 /* Asynchronous event CQ Event work queue list */
3394 INIT_LIST_HEAD(&phba->sli4_hba.sp_asynce_work_queue);
3395 /* Fast-path XRI aborted CQ Event work queue list */
3396 INIT_LIST_HEAD(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue);
3397 /* Slow-path XRI aborted CQ Event work queue list */
3398 INIT_LIST_HEAD(&phba->sli4_hba.sp_els_xri_aborted_work_queue);
3399 /* Receive queue CQ Event work queue list */
3400 INIT_LIST_HEAD(&phba->sli4_hba.sp_unsol_work_queue);
3401
3402 /* Initialize the driver internal SLI layer lists. */
3403 lpfc_sli_setup(phba);
3404 lpfc_sli_queue_setup(phba);
3405
3406 /* Allocate device driver memory */
3407 rc = lpfc_mem_alloc(phba, SGL_ALIGN_SZ);
3408 if (rc)
3409 return -ENOMEM;
3410
3411 /* Create the bootstrap mailbox command */
3412 rc = lpfc_create_bootstrap_mbox(phba);
3413 if (unlikely(rc))
3414 goto out_free_mem;
3415
3416 /* Set up the host's endian order with the device. */
3417 rc = lpfc_setup_endian_order(phba);
3418 if (unlikely(rc))
3419 goto out_free_bsmbx;
3420
3421 /* Set up the hba's configuration parameters. */
3422 rc = lpfc_sli4_read_config(phba);
3423 if (unlikely(rc))
3424 goto out_free_bsmbx;
3425
3426 /* Perform a function reset */
3427 rc = lpfc_pci_function_reset(phba);
3428 if (unlikely(rc))
3429 goto out_free_bsmbx;
3430
3431 /* Create all the SLI4 queues */
3432 rc = lpfc_sli4_queue_create(phba);
3433 if (rc)
3434 goto out_free_bsmbx;
3435
3436 /* Create driver internal CQE event pool */
3437 rc = lpfc_sli4_cq_event_pool_create(phba);
3438 if (rc)
3439 goto out_destroy_queue;
3440
3441 /* Initialize and populate the iocb list per host */
3442 rc = lpfc_init_sgl_list(phba);
3443 if (rc) {
3444 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3445 "1400 Failed to initialize sgl list.\n");
3446 goto out_destroy_cq_event_pool;
3447 }
3448 rc = lpfc_init_active_sgl_array(phba);
3449 if (rc) {
3450 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3451 "1430 Failed to initialize sgl list.\n");
3452 goto out_free_sgl_list;
3453 }
3454
3455 rc = lpfc_sli4_init_rpi_hdrs(phba);
3456 if (rc) {
3457 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3458 "1432 Failed to initialize rpi headers.\n");
3459 goto out_free_active_sgl;
3460 }
3461
3462 phba->sli4_hba.fcp_eq_hdl = kzalloc((sizeof(struct lpfc_fcp_eq_hdl) *
3463 phba->cfg_fcp_eq_count), GFP_KERNEL);
3464 if (!phba->sli4_hba.fcp_eq_hdl) {
3465 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3466 "2572 Failed allocate memory for fast-path "
3467 "per-EQ handle array\n");
3468 goto out_remove_rpi_hdrs;
3469 }
3470
3471 phba->sli4_hba.msix_entries = kzalloc((sizeof(struct msix_entry) *
3472 phba->sli4_hba.cfg_eqn), GFP_KERNEL);
3473 if (!phba->sli4_hba.msix_entries) {
3474 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3475 "2573 Failed allocate memory for msi-x "
3476 "interrupt vector entries\n");
3477 goto out_free_fcp_eq_hdl;
3478 }
3479
3480 return rc;
3481
3482out_free_fcp_eq_hdl:
3483 kfree(phba->sli4_hba.fcp_eq_hdl);
3484out_remove_rpi_hdrs:
3485 lpfc_sli4_remove_rpi_hdrs(phba);
3486out_free_active_sgl:
3487 lpfc_free_active_sgl(phba);
3488out_free_sgl_list:
3489 lpfc_free_sgl_list(phba);
3490out_destroy_cq_event_pool:
3491 lpfc_sli4_cq_event_pool_destroy(phba);
3492out_destroy_queue:
3493 lpfc_sli4_queue_destroy(phba);
3494out_free_bsmbx:
3495 lpfc_destroy_bootstrap_mbox(phba);
3496out_free_mem:
3497 lpfc_mem_free(phba);
3498 return rc;
3499}
3500
3501/**
3502 * lpfc_sli4_driver_resource_unset - Unset drvr internal resources for SLI4 dev
3503 * @phba: pointer to lpfc hba data structure.
3504 *
3505 * This routine is invoked to unset the driver internal resources set up
3506 * specific for supporting the SLI-4 HBA device it attached to.
3507 **/
3508static void
3509lpfc_sli4_driver_resource_unset(struct lpfc_hba *phba)
3510{
3511 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
3512
3513 /* unregister default FCFI from the HBA */
3514 lpfc_sli4_fcfi_unreg(phba, phba->fcf.fcfi);
3515
3516 /* Free the default FCR table */
3517 lpfc_sli_remove_dflt_fcf(phba);
3518
3519 /* Free memory allocated for msi-x interrupt vector entries */
3520 kfree(phba->sli4_hba.msix_entries);
3521
3522 /* Free memory allocated for fast-path work queue handles */
3523 kfree(phba->sli4_hba.fcp_eq_hdl);
3524
3525 /* Free the allocated rpi headers. */
3526 lpfc_sli4_remove_rpi_hdrs(phba);
3527
3528 /* Free the ELS sgl list */
3529 lpfc_free_active_sgl(phba);
3530 lpfc_free_sgl_list(phba);
3531
3532 /* Free the SCSI sgl management array */
3533 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
3534
3535 /* Free the SLI4 queues */
3536 lpfc_sli4_queue_destroy(phba);
3537
3538 /* Free the completion queue EQ event pool */
3539 lpfc_sli4_cq_event_release_all(phba);
3540 lpfc_sli4_cq_event_pool_destroy(phba);
3541
3542 /* Reset SLI4 HBA FCoE function */
3543 lpfc_pci_function_reset(phba);
3544
3545 /* Free the bsmbx region. */
3546 lpfc_destroy_bootstrap_mbox(phba);
3547
3548 /* Free the SLI Layer memory with SLI4 HBAs */
3549 lpfc_mem_free_all(phba);
3550
3551 /* Free the current connect table */
3552 list_for_each_entry_safe(conn_entry, next_conn_entry,
3553 &phba->fcf_conn_rec_list, list)
3554 kfree(conn_entry);
3555
3556 return;
3557}
3558
3559/**
2767 * lpfc_init_api_table_setup - Set up init api fucntion jump table 3560 * lpfc_init_api_table_setup - Set up init api fucntion jump table
2768 * @phba: The hba struct for which this call is being executed. 3561 * @phba: The hba struct for which this call is being executed.
2769 * @dev_grp: The HBA PCI-Device group number. 3562 * @dev_grp: The HBA PCI-Device group number.
@@ -2782,6 +3575,11 @@ lpfc_init_api_table_setup(struct lpfc_hba *phba, uint8_t dev_grp)
2782 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3; 3575 phba->lpfc_handle_eratt = lpfc_handle_eratt_s3;
2783 phba->lpfc_stop_port = lpfc_stop_port_s3; 3576 phba->lpfc_stop_port = lpfc_stop_port_s3;
2784 break; 3577 break;
3578 case LPFC_PCI_DEV_OC:
3579 phba->lpfc_hba_down_post = lpfc_hba_down_post_s4;
3580 phba->lpfc_handle_eratt = lpfc_handle_eratt_s4;
3581 phba->lpfc_stop_port = lpfc_stop_port_s4;
3582 break;
2785 default: 3583 default:
2786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 3584 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
2787 "1431 Invalid HBA PCI-device group: 0x%x\n", 3585 "1431 Invalid HBA PCI-device group: 0x%x\n",
@@ -2956,6 +3754,346 @@ out_free_iocbq:
2956} 3754}
2957 3755
2958/** 3756/**
3757 * lpfc_free_sgl_list - Free sgl list.
3758 * @phba: pointer to lpfc hba data structure.
3759 *
3760 * This routine is invoked to free the driver's sgl list and memory.
3761 **/
3762static void
3763lpfc_free_sgl_list(struct lpfc_hba *phba)
3764{
3765 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
3766 LIST_HEAD(sglq_list);
3767 int rc = 0;
3768
3769 spin_lock_irq(&phba->hbalock);
3770 list_splice_init(&phba->sli4_hba.lpfc_sgl_list, &sglq_list);
3771 spin_unlock_irq(&phba->hbalock);
3772
3773 list_for_each_entry_safe(sglq_entry, sglq_next,
3774 &sglq_list, list) {
3775 list_del(&sglq_entry->list);
3776 lpfc_mbuf_free(phba, sglq_entry->virt, sglq_entry->phys);
3777 kfree(sglq_entry);
3778 phba->sli4_hba.total_sglq_bufs--;
3779 }
3780 rc = lpfc_sli4_remove_all_sgl_pages(phba);
3781 if (rc) {
3782 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3783 "2005 Unable to deregister pages from HBA: %x", rc);
3784 }
3785 kfree(phba->sli4_hba.lpfc_els_sgl_array);
3786}
3787
3788/**
3789 * lpfc_init_active_sgl_array - Allocate the buf to track active ELS XRIs.
3790 * @phba: pointer to lpfc hba data structure.
3791 *
3792 * This routine is invoked to allocate the driver's active sgl memory.
3793 * This array will hold the sglq_entry's for active IOs.
3794 **/
3795static int
3796lpfc_init_active_sgl_array(struct lpfc_hba *phba)
3797{
3798 int size;
3799 size = sizeof(struct lpfc_sglq *);
3800 size *= phba->sli4_hba.max_cfg_param.max_xri;
3801
3802 phba->sli4_hba.lpfc_sglq_active_list =
3803 kzalloc(size, GFP_KERNEL);
3804 if (!phba->sli4_hba.lpfc_sglq_active_list)
3805 return -ENOMEM;
3806 return 0;
3807}
3808
3809/**
3810 * lpfc_free_active_sgl - Free the buf that tracks active ELS XRIs.
3811 * @phba: pointer to lpfc hba data structure.
3812 *
3813 * This routine is invoked to walk through the array of active sglq entries
3814 * and free all of the resources.
3815 * This is just a place holder for now.
3816 **/
3817static void
3818lpfc_free_active_sgl(struct lpfc_hba *phba)
3819{
3820 kfree(phba->sli4_hba.lpfc_sglq_active_list);
3821}
3822
3823/**
3824 * lpfc_init_sgl_list - Allocate and initialize sgl list.
3825 * @phba: pointer to lpfc hba data structure.
3826 *
3827 * This routine is invoked to allocate and initizlize the driver's sgl
3828 * list and set up the sgl xritag tag array accordingly.
3829 *
3830 * Return codes
3831 * 0 - sucessful
3832 * other values - error
3833 **/
3834static int
3835lpfc_init_sgl_list(struct lpfc_hba *phba)
3836{
3837 struct lpfc_sglq *sglq_entry = NULL;
3838 int i;
3839 int els_xri_cnt;
3840
3841 els_xri_cnt = lpfc_sli4_get_els_iocb_cnt(phba);
3842 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
3843 "2400 lpfc_init_sgl_list els %d.\n",
3844 els_xri_cnt);
3845 /* Initialize and populate the sglq list per host/VF. */
3846 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_sgl_list);
3847 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_abts_els_sgl_list);
3848
3849 /* Sanity check on XRI management */
3850 if (phba->sli4_hba.max_cfg_param.max_xri <= els_xri_cnt) {
3851 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3852 "2562 No room left for SCSI XRI allocation: "
3853 "max_xri=%d, els_xri=%d\n",
3854 phba->sli4_hba.max_cfg_param.max_xri,
3855 els_xri_cnt);
3856 return -ENOMEM;
3857 }
3858
3859 /* Allocate memory for the ELS XRI management array */
3860 phba->sli4_hba.lpfc_els_sgl_array =
3861 kzalloc((sizeof(struct lpfc_sglq *) * els_xri_cnt),
3862 GFP_KERNEL);
3863
3864 if (!phba->sli4_hba.lpfc_els_sgl_array) {
3865 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3866 "2401 Failed to allocate memory for ELS "
3867 "XRI management array of size %d.\n",
3868 els_xri_cnt);
3869 return -ENOMEM;
3870 }
3871
3872 /* Keep the SCSI XRI into the XRI management array */
3873 phba->sli4_hba.scsi_xri_max =
3874 phba->sli4_hba.max_cfg_param.max_xri - els_xri_cnt;
3875 phba->sli4_hba.scsi_xri_cnt = 0;
3876
3877 phba->sli4_hba.lpfc_scsi_psb_array =
3878 kzalloc((sizeof(struct lpfc_scsi_buf *) *
3879 phba->sli4_hba.scsi_xri_max), GFP_KERNEL);
3880
3881 if (!phba->sli4_hba.lpfc_scsi_psb_array) {
3882 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
3883 "2563 Failed to allocate memory for SCSI "
3884 "XRI management array of size %d.\n",
3885 phba->sli4_hba.scsi_xri_max);
3886 kfree(phba->sli4_hba.lpfc_els_sgl_array);
3887 return -ENOMEM;
3888 }
3889
3890 for (i = 0; i < els_xri_cnt; i++) {
3891 sglq_entry = kzalloc(sizeof(struct lpfc_sglq), GFP_KERNEL);
3892 if (sglq_entry == NULL) {
3893 printk(KERN_ERR "%s: only allocated %d sgls of "
3894 "expected %d count. Unloading driver.\n",
3895 __func__, i, els_xri_cnt);
3896 goto out_free_mem;
3897 }
3898
3899 sglq_entry->sli4_xritag = lpfc_sli4_next_xritag(phba);
3900 if (sglq_entry->sli4_xritag == NO_XRI) {
3901 kfree(sglq_entry);
3902 printk(KERN_ERR "%s: failed to allocate XRI.\n"
3903 "Unloading driver.\n", __func__);
3904 goto out_free_mem;
3905 }
3906 sglq_entry->buff_type = GEN_BUFF_TYPE;
3907 sglq_entry->virt = lpfc_mbuf_alloc(phba, 0, &sglq_entry->phys);
3908 if (sglq_entry->virt == NULL) {
3909 kfree(sglq_entry);
3910 printk(KERN_ERR "%s: failed to allocate mbuf.\n"
3911 "Unloading driver.\n", __func__);
3912 goto out_free_mem;
3913 }
3914 sglq_entry->sgl = sglq_entry->virt;
3915 memset(sglq_entry->sgl, 0, LPFC_BPL_SIZE);
3916
3917 /* The list order is used by later block SGL registraton */
3918 spin_lock_irq(&phba->hbalock);
3919 list_add_tail(&sglq_entry->list, &phba->sli4_hba.lpfc_sgl_list);
3920 phba->sli4_hba.lpfc_els_sgl_array[i] = sglq_entry;
3921 phba->sli4_hba.total_sglq_bufs++;
3922 spin_unlock_irq(&phba->hbalock);
3923 }
3924 return 0;
3925
3926out_free_mem:
3927 kfree(phba->sli4_hba.lpfc_scsi_psb_array);
3928 lpfc_free_sgl_list(phba);
3929 return -ENOMEM;
3930}
3931
3932/**
3933 * lpfc_sli4_init_rpi_hdrs - Post the rpi header memory region to the port
3934 * @phba: pointer to lpfc hba data structure.
3935 *
3936 * This routine is invoked to post rpi header templates to the
3937 * HBA consistent with the SLI-4 interface spec. This routine
3938 * posts a PAGE_SIZE memory region to the port to hold up to
3939 * PAGE_SIZE modulo 64 rpi context headers.
3940 * No locks are held here because this is an initialization routine
3941 * called only from probe or lpfc_online when interrupts are not
3942 * enabled and the driver is reinitializing the device.
3943 *
3944 * Return codes
3945 * 0 - sucessful
3946 * ENOMEM - No availble memory
3947 * EIO - The mailbox failed to complete successfully.
3948 **/
3949int
3950lpfc_sli4_init_rpi_hdrs(struct lpfc_hba *phba)
3951{
3952 int rc = 0;
3953 int longs;
3954 uint16_t rpi_count;
3955 struct lpfc_rpi_hdr *rpi_hdr;
3956
3957 INIT_LIST_HEAD(&phba->sli4_hba.lpfc_rpi_hdr_list);
3958
3959 /*
3960 * Provision an rpi bitmask range for discovery. The total count
3961 * is the difference between max and base + 1.
3962 */
3963 rpi_count = phba->sli4_hba.max_cfg_param.rpi_base +
3964 phba->sli4_hba.max_cfg_param.max_rpi - 1;
3965
3966 longs = ((rpi_count) + BITS_PER_LONG - 1) / BITS_PER_LONG;
3967 phba->sli4_hba.rpi_bmask = kzalloc(longs * sizeof(unsigned long),
3968 GFP_KERNEL);
3969 if (!phba->sli4_hba.rpi_bmask)
3970 return -ENOMEM;
3971
3972 rpi_hdr = lpfc_sli4_create_rpi_hdr(phba);
3973 if (!rpi_hdr) {
3974 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_SLI,
3975 "0391 Error during rpi post operation\n");
3976 lpfc_sli4_remove_rpis(phba);
3977 rc = -ENODEV;
3978 }
3979
3980 return rc;
3981}
3982
3983/**
3984 * lpfc_sli4_create_rpi_hdr - Allocate an rpi header memory region
3985 * @phba: pointer to lpfc hba data structure.
3986 *
3987 * This routine is invoked to allocate a single 4KB memory region to
3988 * support rpis and stores them in the phba. This single region
3989 * provides support for up to 64 rpis. The region is used globally
3990 * by the device.
3991 *
3992 * Returns:
3993 * A valid rpi hdr on success.
3994 * A NULL pointer on any failure.
3995 **/
3996struct lpfc_rpi_hdr *
3997lpfc_sli4_create_rpi_hdr(struct lpfc_hba *phba)
3998{
3999 uint16_t rpi_limit, curr_rpi_range;
4000 struct lpfc_dmabuf *dmabuf;
4001 struct lpfc_rpi_hdr *rpi_hdr;
4002
4003 rpi_limit = phba->sli4_hba.max_cfg_param.rpi_base +
4004 phba->sli4_hba.max_cfg_param.max_rpi - 1;
4005
4006 spin_lock_irq(&phba->hbalock);
4007 curr_rpi_range = phba->sli4_hba.next_rpi;
4008 spin_unlock_irq(&phba->hbalock);
4009
4010 /*
4011 * The port has a limited number of rpis. The increment here
4012 * is LPFC_RPI_HDR_COUNT - 1 to account for the starting value
4013 * and to allow the full max_rpi range per port.
4014 */
4015 if ((curr_rpi_range + (LPFC_RPI_HDR_COUNT - 1)) > rpi_limit)
4016 return NULL;
4017
4018 /*
4019 * First allocate the protocol header region for the port. The
4020 * port expects a 4KB DMA-mapped memory region that is 4K aligned.
4021 */
4022 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4023 if (!dmabuf)
4024 return NULL;
4025
4026 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4027 LPFC_HDR_TEMPLATE_SIZE,
4028 &dmabuf->phys,
4029 GFP_KERNEL);
4030 if (!dmabuf->virt) {
4031 rpi_hdr = NULL;
4032 goto err_free_dmabuf;
4033 }
4034
4035 memset(dmabuf->virt, 0, LPFC_HDR_TEMPLATE_SIZE);
4036 if (!IS_ALIGNED(dmabuf->phys, LPFC_HDR_TEMPLATE_SIZE)) {
4037 rpi_hdr = NULL;
4038 goto err_free_coherent;
4039 }
4040
4041 /* Save the rpi header data for cleanup later. */
4042 rpi_hdr = kzalloc(sizeof(struct lpfc_rpi_hdr), GFP_KERNEL);
4043 if (!rpi_hdr)
4044 goto err_free_coherent;
4045
4046 rpi_hdr->dmabuf = dmabuf;
4047 rpi_hdr->len = LPFC_HDR_TEMPLATE_SIZE;
4048 rpi_hdr->page_count = 1;
4049 spin_lock_irq(&phba->hbalock);
4050 rpi_hdr->start_rpi = phba->sli4_hba.next_rpi;
4051 list_add_tail(&rpi_hdr->list, &phba->sli4_hba.lpfc_rpi_hdr_list);
4052
4053 /*
4054 * The next_rpi stores the next module-64 rpi value to post
4055 * in any subsequent rpi memory region postings.
4056 */
4057 phba->sli4_hba.next_rpi += LPFC_RPI_HDR_COUNT;
4058 spin_unlock_irq(&phba->hbalock);
4059 return rpi_hdr;
4060
4061 err_free_coherent:
4062 dma_free_coherent(&phba->pcidev->dev, LPFC_HDR_TEMPLATE_SIZE,
4063 dmabuf->virt, dmabuf->phys);
4064 err_free_dmabuf:
4065 kfree(dmabuf);
4066 return NULL;
4067}
4068
4069/**
4070 * lpfc_sli4_remove_rpi_hdrs - Remove all rpi header memory regions
4071 * @phba: pointer to lpfc hba data structure.
4072 *
4073 * This routine is invoked to remove all memory resources allocated
4074 * to support rpis. This routine presumes the caller has released all
4075 * rpis consumed by fabric or port logins and is prepared to have
4076 * the header pages removed.
4077 **/
4078void
4079lpfc_sli4_remove_rpi_hdrs(struct lpfc_hba *phba)
4080{
4081 struct lpfc_rpi_hdr *rpi_hdr, *next_rpi_hdr;
4082
4083 list_for_each_entry_safe(rpi_hdr, next_rpi_hdr,
4084 &phba->sli4_hba.lpfc_rpi_hdr_list, list) {
4085 list_del(&rpi_hdr->list);
4086 dma_free_coherent(&phba->pcidev->dev, rpi_hdr->len,
4087 rpi_hdr->dmabuf->virt, rpi_hdr->dmabuf->phys);
4088 kfree(rpi_hdr->dmabuf);
4089 kfree(rpi_hdr);
4090 }
4091
4092 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
4093 memset(phba->sli4_hba.rpi_bmask, 0, sizeof(*phba->sli4_hba.rpi_bmask));
4094}
4095
4096/**
2959 * lpfc_hba_alloc - Allocate driver hba data structure for a device. 4097 * lpfc_hba_alloc - Allocate driver hba data structure for a device.
2960 * @pdev: pointer to pci device data structure. 4098 * @pdev: pointer to pci device data structure.
2961 * 4099 *
@@ -3316,6 +4454,1542 @@ lpfc_sli_pci_mem_unset(struct lpfc_hba *phba)
3316} 4454}
3317 4455
3318/** 4456/**
4457 * lpfc_sli4_post_status_check - Wait for SLI4 POST done and check status
4458 * @phba: pointer to lpfc hba data structure.
4459 *
4460 * This routine is invoked to wait for SLI4 device Power On Self Test (POST)
4461 * done and check status.
4462 *
4463 * Return 0 if successful, otherwise -ENODEV.
4464 **/
4465int
4466lpfc_sli4_post_status_check(struct lpfc_hba *phba)
4467{
4468 struct lpfc_register sta_reg, uerrlo_reg, uerrhi_reg, scratchpad;
4469 uint32_t onlnreg0, onlnreg1;
4470 int i, port_error = -ENODEV;
4471
4472 if (!phba->sli4_hba.STAregaddr)
4473 return -ENODEV;
4474
4475 /* With uncoverable error, log the error message and return error */
4476 onlnreg0 = readl(phba->sli4_hba.ONLINE0regaddr);
4477 onlnreg1 = readl(phba->sli4_hba.ONLINE1regaddr);
4478 if ((onlnreg0 != LPFC_ONLINE_NERR) || (onlnreg1 != LPFC_ONLINE_NERR)) {
4479 uerrlo_reg.word0 = readl(phba->sli4_hba.UERRLOregaddr);
4480 uerrhi_reg.word0 = readl(phba->sli4_hba.UERRHIregaddr);
4481 if (uerrlo_reg.word0 || uerrhi_reg.word0) {
4482 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4483 "1422 HBA Unrecoverable error: "
4484 "uerr_lo_reg=0x%x, uerr_hi_reg=0x%x, "
4485 "online0_reg=0x%x, online1_reg=0x%x\n",
4486 uerrlo_reg.word0, uerrhi_reg.word0,
4487 onlnreg0, onlnreg1);
4488 }
4489 return -ENODEV;
4490 }
4491
4492 /* Wait up to 30 seconds for the SLI Port POST done and ready */
4493 for (i = 0; i < 3000; i++) {
4494 sta_reg.word0 = readl(phba->sli4_hba.STAregaddr);
4495 /* Encounter fatal POST error, break out */
4496 if (bf_get(lpfc_hst_state_perr, &sta_reg)) {
4497 port_error = -ENODEV;
4498 break;
4499 }
4500 if (LPFC_POST_STAGE_ARMFW_READY ==
4501 bf_get(lpfc_hst_state_port_status, &sta_reg)) {
4502 port_error = 0;
4503 break;
4504 }
4505 msleep(10);
4506 }
4507
4508 if (port_error)
4509 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4510 "1408 Failure HBA POST Status: sta_reg=0x%x, "
4511 "perr=x%x, sfi=x%x, nip=x%x, ipc=x%x, xrom=x%x, "
4512 "dl=x%x, pstatus=x%x\n", sta_reg.word0,
4513 bf_get(lpfc_hst_state_perr, &sta_reg),
4514 bf_get(lpfc_hst_state_sfi, &sta_reg),
4515 bf_get(lpfc_hst_state_nip, &sta_reg),
4516 bf_get(lpfc_hst_state_ipc, &sta_reg),
4517 bf_get(lpfc_hst_state_xrom, &sta_reg),
4518 bf_get(lpfc_hst_state_dl, &sta_reg),
4519 bf_get(lpfc_hst_state_port_status, &sta_reg));
4520
4521 /* Log device information */
4522 scratchpad.word0 = readl(phba->sli4_hba.SCRATCHPADregaddr);
4523 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
4524 "2534 Device Info: ChipType=0x%x, SliRev=0x%x, "
4525 "FeatureL1=0x%x, FeatureL2=0x%x\n",
4526 bf_get(lpfc_scratchpad_chiptype, &scratchpad),
4527 bf_get(lpfc_scratchpad_slirev, &scratchpad),
4528 bf_get(lpfc_scratchpad_featurelevel1, &scratchpad),
4529 bf_get(lpfc_scratchpad_featurelevel2, &scratchpad));
4530
4531 return port_error;
4532}
4533
4534/**
4535 * lpfc_sli4_bar0_register_memmap - Set up SLI4 BAR0 register memory map.
4536 * @phba: pointer to lpfc hba data structure.
4537 *
4538 * This routine is invoked to set up SLI4 BAR0 PCI config space register
4539 * memory map.
4540 **/
4541static void
4542lpfc_sli4_bar0_register_memmap(struct lpfc_hba *phba)
4543{
4544 phba->sli4_hba.UERRLOregaddr = phba->sli4_hba.conf_regs_memmap_p +
4545 LPFC_UERR_STATUS_LO;
4546 phba->sli4_hba.UERRHIregaddr = phba->sli4_hba.conf_regs_memmap_p +
4547 LPFC_UERR_STATUS_HI;
4548 phba->sli4_hba.ONLINE0regaddr = phba->sli4_hba.conf_regs_memmap_p +
4549 LPFC_ONLINE0;
4550 phba->sli4_hba.ONLINE1regaddr = phba->sli4_hba.conf_regs_memmap_p +
4551 LPFC_ONLINE1;
4552 phba->sli4_hba.SCRATCHPADregaddr = phba->sli4_hba.conf_regs_memmap_p +
4553 LPFC_SCRATCHPAD;
4554}
4555
4556/**
4557 * lpfc_sli4_bar1_register_memmap - Set up SLI4 BAR1 register memory map.
4558 * @phba: pointer to lpfc hba data structure.
4559 *
4560 * This routine is invoked to set up SLI4 BAR1 control status register (CSR)
4561 * memory map.
4562 **/
4563static void
4564lpfc_sli4_bar1_register_memmap(struct lpfc_hba *phba)
4565{
4566
4567 phba->sli4_hba.STAregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4568 LPFC_HST_STATE;
4569 phba->sli4_hba.ISRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4570 LPFC_HST_ISR0;
4571 phba->sli4_hba.IMRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4572 LPFC_HST_IMR0;
4573 phba->sli4_hba.ISCRregaddr = phba->sli4_hba.ctrl_regs_memmap_p +
4574 LPFC_HST_ISCR0;
4575 return;
4576}
4577
4578/**
4579 * lpfc_sli4_bar2_register_memmap - Set up SLI4 BAR2 register memory map.
4580 * @phba: pointer to lpfc hba data structure.
4581 * @vf: virtual function number
4582 *
4583 * This routine is invoked to set up SLI4 BAR2 doorbell register memory map
4584 * based on the given viftual function number, @vf.
4585 *
4586 * Return 0 if successful, otherwise -ENODEV.
4587 **/
4588static int
4589lpfc_sli4_bar2_register_memmap(struct lpfc_hba *phba, uint32_t vf)
4590{
4591 if (vf > LPFC_VIR_FUNC_MAX)
4592 return -ENODEV;
4593
4594 phba->sli4_hba.RQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4595 vf * LPFC_VFR_PAGE_SIZE + LPFC_RQ_DOORBELL);
4596 phba->sli4_hba.WQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4597 vf * LPFC_VFR_PAGE_SIZE + LPFC_WQ_DOORBELL);
4598 phba->sli4_hba.EQCQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4599 vf * LPFC_VFR_PAGE_SIZE + LPFC_EQCQ_DOORBELL);
4600 phba->sli4_hba.MQDBregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4601 vf * LPFC_VFR_PAGE_SIZE + LPFC_MQ_DOORBELL);
4602 phba->sli4_hba.BMBXregaddr = (phba->sli4_hba.drbl_regs_memmap_p +
4603 vf * LPFC_VFR_PAGE_SIZE + LPFC_BMBX);
4604 return 0;
4605}
4606
4607/**
4608 * lpfc_create_bootstrap_mbox - Create the bootstrap mailbox
4609 * @phba: pointer to lpfc hba data structure.
4610 *
4611 * This routine is invoked to create the bootstrap mailbox
4612 * region consistent with the SLI-4 interface spec. This
4613 * routine allocates all memory necessary to communicate
4614 * mailbox commands to the port and sets up all alignment
4615 * needs. No locks are expected to be held when calling
4616 * this routine.
4617 *
4618 * Return codes
4619 * 0 - sucessful
4620 * ENOMEM - could not allocated memory.
4621 **/
4622static int
4623lpfc_create_bootstrap_mbox(struct lpfc_hba *phba)
4624{
4625 uint32_t bmbx_size;
4626 struct lpfc_dmabuf *dmabuf;
4627 struct dma_address *dma_address;
4628 uint32_t pa_addr;
4629 uint64_t phys_addr;
4630
4631 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
4632 if (!dmabuf)
4633 return -ENOMEM;
4634
4635 /*
4636 * The bootstrap mailbox region is comprised of 2 parts
4637 * plus an alignment restriction of 16 bytes.
4638 */
4639 bmbx_size = sizeof(struct lpfc_bmbx_create) + (LPFC_ALIGN_16_BYTE - 1);
4640 dmabuf->virt = dma_alloc_coherent(&phba->pcidev->dev,
4641 bmbx_size,
4642 &dmabuf->phys,
4643 GFP_KERNEL);
4644 if (!dmabuf->virt) {
4645 kfree(dmabuf);
4646 return -ENOMEM;
4647 }
4648 memset(dmabuf->virt, 0, bmbx_size);
4649
4650 /*
4651 * Initialize the bootstrap mailbox pointers now so that the register
4652 * operations are simple later. The mailbox dma address is required
4653 * to be 16-byte aligned. Also align the virtual memory as each
4654 * maibox is copied into the bmbx mailbox region before issuing the
4655 * command to the port.
4656 */
4657 phba->sli4_hba.bmbx.dmabuf = dmabuf;
4658 phba->sli4_hba.bmbx.bmbx_size = bmbx_size;
4659
4660 phba->sli4_hba.bmbx.avirt = PTR_ALIGN(dmabuf->virt,
4661 LPFC_ALIGN_16_BYTE);
4662 phba->sli4_hba.bmbx.aphys = ALIGN(dmabuf->phys,
4663 LPFC_ALIGN_16_BYTE);
4664
4665 /*
4666 * Set the high and low physical addresses now. The SLI4 alignment
4667 * requirement is 16 bytes and the mailbox is posted to the port
4668 * as two 30-bit addresses. The other data is a bit marking whether
4669 * the 30-bit address is the high or low address.
4670 * Upcast bmbx aphys to 64bits so shift instruction compiles
4671 * clean on 32 bit machines.
4672 */
4673 dma_address = &phba->sli4_hba.bmbx.dma_address;
4674 phys_addr = (uint64_t)phba->sli4_hba.bmbx.aphys;
4675 pa_addr = (uint32_t) ((phys_addr >> 34) & 0x3fffffff);
4676 dma_address->addr_hi = (uint32_t) ((pa_addr << 2) |
4677 LPFC_BMBX_BIT1_ADDR_HI);
4678
4679 pa_addr = (uint32_t) ((phba->sli4_hba.bmbx.aphys >> 4) & 0x3fffffff);
4680 dma_address->addr_lo = (uint32_t) ((pa_addr << 2) |
4681 LPFC_BMBX_BIT1_ADDR_LO);
4682 return 0;
4683}
4684
4685/**
4686 * lpfc_destroy_bootstrap_mbox - Destroy all bootstrap mailbox resources
4687 * @phba: pointer to lpfc hba data structure.
4688 *
4689 * This routine is invoked to teardown the bootstrap mailbox
4690 * region and release all host resources. This routine requires
4691 * the caller to ensure all mailbox commands recovered, no
4692 * additional mailbox comands are sent, and interrupts are disabled
4693 * before calling this routine.
4694 *
4695 **/
4696static void
4697lpfc_destroy_bootstrap_mbox(struct lpfc_hba *phba)
4698{
4699 dma_free_coherent(&phba->pcidev->dev,
4700 phba->sli4_hba.bmbx.bmbx_size,
4701 phba->sli4_hba.bmbx.dmabuf->virt,
4702 phba->sli4_hba.bmbx.dmabuf->phys);
4703
4704 kfree(phba->sli4_hba.bmbx.dmabuf);
4705 memset(&phba->sli4_hba.bmbx, 0, sizeof(struct lpfc_bmbx));
4706}
4707
4708/**
4709 * lpfc_sli4_read_config - Get the config parameters.
4710 * @phba: pointer to lpfc hba data structure.
4711 *
4712 * This routine is invoked to read the configuration parameters from the HBA.
4713 * The configuration parameters are used to set the base and maximum values
4714 * for RPI's XRI's VPI's VFI's and FCFIs. These values also affect the resource
4715 * allocation for the port.
4716 *
4717 * Return codes
4718 * 0 - sucessful
4719 * ENOMEM - No availble memory
4720 * EIO - The mailbox failed to complete successfully.
4721 **/
4722static int
4723lpfc_sli4_read_config(struct lpfc_hba *phba)
4724{
4725 LPFC_MBOXQ_t *pmb;
4726 struct lpfc_mbx_read_config *rd_config;
4727 uint32_t rc = 0;
4728
4729 pmb = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4730 if (!pmb) {
4731 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4732 "2011 Unable to allocate memory for issuing "
4733 "SLI_CONFIG_SPECIAL mailbox command\n");
4734 return -ENOMEM;
4735 }
4736
4737 lpfc_read_config(phba, pmb);
4738
4739 rc = lpfc_sli_issue_mbox(phba, pmb, MBX_POLL);
4740 if (rc != MBX_SUCCESS) {
4741 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
4742 "2012 Mailbox failed , mbxCmd x%x "
4743 "READ_CONFIG, mbxStatus x%x\n",
4744 bf_get(lpfc_mqe_command, &pmb->u.mqe),
4745 bf_get(lpfc_mqe_status, &pmb->u.mqe));
4746 rc = -EIO;
4747 } else {
4748 rd_config = &pmb->u.mqe.un.rd_config;
4749 phba->sli4_hba.max_cfg_param.max_xri =
4750 bf_get(lpfc_mbx_rd_conf_xri_count, rd_config);
4751 phba->sli4_hba.max_cfg_param.xri_base =
4752 bf_get(lpfc_mbx_rd_conf_xri_base, rd_config);
4753 phba->sli4_hba.max_cfg_param.max_vpi =
4754 bf_get(lpfc_mbx_rd_conf_vpi_count, rd_config);
4755 phba->sli4_hba.max_cfg_param.vpi_base =
4756 bf_get(lpfc_mbx_rd_conf_vpi_base, rd_config);
4757 phba->sli4_hba.max_cfg_param.max_rpi =
4758 bf_get(lpfc_mbx_rd_conf_rpi_count, rd_config);
4759 phba->sli4_hba.max_cfg_param.rpi_base =
4760 bf_get(lpfc_mbx_rd_conf_rpi_base, rd_config);
4761 phba->sli4_hba.max_cfg_param.max_vfi =
4762 bf_get(lpfc_mbx_rd_conf_vfi_count, rd_config);
4763 phba->sli4_hba.max_cfg_param.vfi_base =
4764 bf_get(lpfc_mbx_rd_conf_vfi_base, rd_config);
4765 phba->sli4_hba.max_cfg_param.max_fcfi =
4766 bf_get(lpfc_mbx_rd_conf_fcfi_count, rd_config);
4767 phba->sli4_hba.max_cfg_param.fcfi_base =
4768 bf_get(lpfc_mbx_rd_conf_fcfi_base, rd_config);
4769 phba->sli4_hba.max_cfg_param.max_eq =
4770 bf_get(lpfc_mbx_rd_conf_eq_count, rd_config);
4771 phba->sli4_hba.max_cfg_param.max_rq =
4772 bf_get(lpfc_mbx_rd_conf_rq_count, rd_config);
4773 phba->sli4_hba.max_cfg_param.max_wq =
4774 bf_get(lpfc_mbx_rd_conf_wq_count, rd_config);
4775 phba->sli4_hba.max_cfg_param.max_cq =
4776 bf_get(lpfc_mbx_rd_conf_cq_count, rd_config);
4777 phba->lmt = bf_get(lpfc_mbx_rd_conf_lmt, rd_config);
4778 phba->sli4_hba.next_xri = phba->sli4_hba.max_cfg_param.xri_base;
4779 phba->vpi_base = phba->sli4_hba.max_cfg_param.vpi_base;
4780 phba->vfi_base = phba->sli4_hba.max_cfg_param.vfi_base;
4781 phba->sli4_hba.next_rpi = phba->sli4_hba.max_cfg_param.rpi_base;
4782 phba->max_vpi = phba->sli4_hba.max_cfg_param.max_vpi;
4783 phba->max_vports = phba->max_vpi;
4784 lpfc_printf_log(phba, KERN_INFO, LOG_SLI,
4785 "2003 cfg params XRI(B:%d M:%d), "
4786 "VPI(B:%d M:%d) "
4787 "VFI(B:%d M:%d) "
4788 "RPI(B:%d M:%d) "
4789 "FCFI(B:%d M:%d)\n",
4790 phba->sli4_hba.max_cfg_param.xri_base,
4791 phba->sli4_hba.max_cfg_param.max_xri,
4792 phba->sli4_hba.max_cfg_param.vpi_base,
4793 phba->sli4_hba.max_cfg_param.max_vpi,
4794 phba->sli4_hba.max_cfg_param.vfi_base,
4795 phba->sli4_hba.max_cfg_param.max_vfi,
4796 phba->sli4_hba.max_cfg_param.rpi_base,
4797 phba->sli4_hba.max_cfg_param.max_rpi,
4798 phba->sli4_hba.max_cfg_param.fcfi_base,
4799 phba->sli4_hba.max_cfg_param.max_fcfi);
4800 }
4801 mempool_free(pmb, phba->mbox_mem_pool);
4802
4803 /* Reset the DFT_HBA_Q_DEPTH to the max xri */
4804 if (phba->cfg_hba_queue_depth > (phba->sli4_hba.max_cfg_param.max_xri))
4805 phba->cfg_hba_queue_depth =
4806 phba->sli4_hba.max_cfg_param.max_xri;
4807 return rc;
4808}
4809
4810/**
4811 * lpfc_dev_endian_order_setup - Notify the port of the host's endian order.
4812 * @phba: pointer to lpfc hba data structure.
4813 *
4814 * This routine is invoked to setup the host-side endian order to the
4815 * HBA consistent with the SLI-4 interface spec.
4816 *
4817 * Return codes
4818 * 0 - sucessful
4819 * ENOMEM - No availble memory
4820 * EIO - The mailbox failed to complete successfully.
4821 **/
4822static int
4823lpfc_setup_endian_order(struct lpfc_hba *phba)
4824{
4825 LPFC_MBOXQ_t *mboxq;
4826 uint32_t rc = 0;
4827 uint32_t endian_mb_data[2] = {HOST_ENDIAN_LOW_WORD0,
4828 HOST_ENDIAN_HIGH_WORD1};
4829
4830 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4831 if (!mboxq) {
4832 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4833 "0492 Unable to allocate memory for issuing "
4834 "SLI_CONFIG_SPECIAL mailbox command\n");
4835 return -ENOMEM;
4836 }
4837
4838 /*
4839 * The SLI4_CONFIG_SPECIAL mailbox command requires the first two
4840 * words to contain special data values and no other data.
4841 */
4842 memset(mboxq, 0, sizeof(LPFC_MBOXQ_t));
4843 memcpy(&mboxq->u.mqe, &endian_mb_data, sizeof(endian_mb_data));
4844 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
4845 if (rc != MBX_SUCCESS) {
4846 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4847 "0493 SLI_CONFIG_SPECIAL mailbox failed with "
4848 "status x%x\n",
4849 rc);
4850 rc = -EIO;
4851 }
4852
4853 mempool_free(mboxq, phba->mbox_mem_pool);
4854 return rc;
4855}
4856
4857/**
4858 * lpfc_sli4_queue_create - Create all the SLI4 queues
4859 * @phba: pointer to lpfc hba data structure.
4860 *
4861 * This routine is invoked to allocate all the SLI4 queues for the FCoE HBA
4862 * operation. For each SLI4 queue type, the parameters such as queue entry
4863 * count (queue depth) shall be taken from the module parameter. For now,
4864 * we just use some constant number as place holder.
4865 *
4866 * Return codes
4867 * 0 - sucessful
4868 * ENOMEM - No availble memory
4869 * EIO - The mailbox failed to complete successfully.
4870 **/
4871static int
4872lpfc_sli4_queue_create(struct lpfc_hba *phba)
4873{
4874 struct lpfc_queue *qdesc;
4875 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
4876 int cfg_fcp_wq_count;
4877 int cfg_fcp_eq_count;
4878
4879 /*
4880 * Sanity check for confiugred queue parameters against the run-time
4881 * device parameters
4882 */
4883
4884 /* Sanity check on FCP fast-path WQ parameters */
4885 cfg_fcp_wq_count = phba->cfg_fcp_wq_count;
4886 if (cfg_fcp_wq_count >
4887 (phba->sli4_hba.max_cfg_param.max_wq - LPFC_SP_WQN_DEF)) {
4888 cfg_fcp_wq_count = phba->sli4_hba.max_cfg_param.max_wq -
4889 LPFC_SP_WQN_DEF;
4890 if (cfg_fcp_wq_count < LPFC_FP_WQN_MIN) {
4891 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4892 "2581 Not enough WQs (%d) from "
4893 "the pci function for supporting "
4894 "FCP WQs (%d)\n",
4895 phba->sli4_hba.max_cfg_param.max_wq,
4896 phba->cfg_fcp_wq_count);
4897 goto out_error;
4898 }
4899 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4900 "2582 Not enough WQs (%d) from the pci "
4901 "function for supporting the requested "
4902 "FCP WQs (%d), the actual FCP WQs can "
4903 "be supported: %d\n",
4904 phba->sli4_hba.max_cfg_param.max_wq,
4905 phba->cfg_fcp_wq_count, cfg_fcp_wq_count);
4906 }
4907 /* The actual number of FCP work queues adopted */
4908 phba->cfg_fcp_wq_count = cfg_fcp_wq_count;
4909
4910 /* Sanity check on FCP fast-path EQ parameters */
4911 cfg_fcp_eq_count = phba->cfg_fcp_eq_count;
4912 if (cfg_fcp_eq_count >
4913 (phba->sli4_hba.max_cfg_param.max_eq - LPFC_SP_EQN_DEF)) {
4914 cfg_fcp_eq_count = phba->sli4_hba.max_cfg_param.max_eq -
4915 LPFC_SP_EQN_DEF;
4916 if (cfg_fcp_eq_count < LPFC_FP_EQN_MIN) {
4917 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4918 "2574 Not enough EQs (%d) from the "
4919 "pci function for supporting FCP "
4920 "EQs (%d)\n",
4921 phba->sli4_hba.max_cfg_param.max_eq,
4922 phba->cfg_fcp_eq_count);
4923 goto out_error;
4924 }
4925 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4926 "2575 Not enough EQs (%d) from the pci "
4927 "function for supporting the requested "
4928 "FCP EQs (%d), the actual FCP EQs can "
4929 "be supported: %d\n",
4930 phba->sli4_hba.max_cfg_param.max_eq,
4931 phba->cfg_fcp_eq_count, cfg_fcp_eq_count);
4932 }
4933 /* It does not make sense to have more EQs than WQs */
4934 if (cfg_fcp_eq_count > phba->cfg_fcp_wq_count) {
4935 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
4936 "2593 The number of FCP EQs (%d) is more "
4937 "than the number of FCP WQs (%d), take "
4938 "the number of FCP EQs same as than of "
4939 "WQs (%d)\n", cfg_fcp_eq_count,
4940 phba->cfg_fcp_wq_count,
4941 phba->cfg_fcp_wq_count);
4942 cfg_fcp_eq_count = phba->cfg_fcp_wq_count;
4943 }
4944 /* The actual number of FCP event queues adopted */
4945 phba->cfg_fcp_eq_count = cfg_fcp_eq_count;
4946 /* The overall number of event queues used */
4947 phba->sli4_hba.cfg_eqn = phba->cfg_fcp_eq_count + LPFC_SP_EQN_DEF;
4948
4949 /*
4950 * Create Event Queues (EQs)
4951 */
4952
4953 /* Get EQ depth from module parameter, fake the default for now */
4954 phba->sli4_hba.eq_esize = LPFC_EQE_SIZE_4B;
4955 phba->sli4_hba.eq_ecount = LPFC_EQE_DEF_COUNT;
4956
4957 /* Create slow path event queue */
4958 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
4959 phba->sli4_hba.eq_ecount);
4960 if (!qdesc) {
4961 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4962 "0496 Failed allocate slow-path EQ\n");
4963 goto out_error;
4964 }
4965 phba->sli4_hba.sp_eq = qdesc;
4966
4967 /* Create fast-path FCP Event Queue(s) */
4968 phba->sli4_hba.fp_eq = kzalloc((sizeof(struct lpfc_queue *) *
4969 phba->cfg_fcp_eq_count), GFP_KERNEL);
4970 if (!phba->sli4_hba.fp_eq) {
4971 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4972 "2576 Failed allocate memory for fast-path "
4973 "EQ record array\n");
4974 goto out_free_sp_eq;
4975 }
4976 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
4977 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.eq_esize,
4978 phba->sli4_hba.eq_ecount);
4979 if (!qdesc) {
4980 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4981 "0497 Failed allocate fast-path EQ\n");
4982 goto out_free_fp_eq;
4983 }
4984 phba->sli4_hba.fp_eq[fcp_eqidx] = qdesc;
4985 }
4986
4987 /*
4988 * Create Complete Queues (CQs)
4989 */
4990
4991 /* Get CQ depth from module parameter, fake the default for now */
4992 phba->sli4_hba.cq_esize = LPFC_CQE_SIZE;
4993 phba->sli4_hba.cq_ecount = LPFC_CQE_DEF_COUNT;
4994
4995 /* Create slow-path Mailbox Command Complete Queue */
4996 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
4997 phba->sli4_hba.cq_ecount);
4998 if (!qdesc) {
4999 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5000 "0500 Failed allocate slow-path mailbox CQ\n");
5001 goto out_free_fp_eq;
5002 }
5003 phba->sli4_hba.mbx_cq = qdesc;
5004
5005 /* Create slow-path ELS Complete Queue */
5006 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5007 phba->sli4_hba.cq_ecount);
5008 if (!qdesc) {
5009 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5010 "0501 Failed allocate slow-path ELS CQ\n");
5011 goto out_free_mbx_cq;
5012 }
5013 phba->sli4_hba.els_cq = qdesc;
5014
5015 /* Create slow-path Unsolicited Receive Complete Queue */
5016 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5017 phba->sli4_hba.cq_ecount);
5018 if (!qdesc) {
5019 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5020 "0502 Failed allocate slow-path USOL RX CQ\n");
5021 goto out_free_els_cq;
5022 }
5023 phba->sli4_hba.rxq_cq = qdesc;
5024
5025 /* Create fast-path FCP Completion Queue(s), one-to-one with EQs */
5026 phba->sli4_hba.fcp_cq = kzalloc((sizeof(struct lpfc_queue *) *
5027 phba->cfg_fcp_eq_count), GFP_KERNEL);
5028 if (!phba->sli4_hba.fcp_cq) {
5029 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5030 "2577 Failed allocate memory for fast-path "
5031 "CQ record array\n");
5032 goto out_free_rxq_cq;
5033 }
5034 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
5035 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.cq_esize,
5036 phba->sli4_hba.cq_ecount);
5037 if (!qdesc) {
5038 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5039 "0499 Failed allocate fast-path FCP "
5040 "CQ (%d)\n", fcp_cqidx);
5041 goto out_free_fcp_cq;
5042 }
5043 phba->sli4_hba.fcp_cq[fcp_cqidx] = qdesc;
5044 }
5045
5046 /* Create Mailbox Command Queue */
5047 phba->sli4_hba.mq_esize = LPFC_MQE_SIZE;
5048 phba->sli4_hba.mq_ecount = LPFC_MQE_DEF_COUNT;
5049
5050 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.mq_esize,
5051 phba->sli4_hba.mq_ecount);
5052 if (!qdesc) {
5053 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5054 "0505 Failed allocate slow-path MQ\n");
5055 goto out_free_fcp_cq;
5056 }
5057 phba->sli4_hba.mbx_wq = qdesc;
5058
5059 /*
5060 * Create all the Work Queues (WQs)
5061 */
5062 phba->sli4_hba.wq_esize = LPFC_WQE_SIZE;
5063 phba->sli4_hba.wq_ecount = LPFC_WQE_DEF_COUNT;
5064
5065 /* Create slow-path ELS Work Queue */
5066 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
5067 phba->sli4_hba.wq_ecount);
5068 if (!qdesc) {
5069 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5070 "0504 Failed allocate slow-path ELS WQ\n");
5071 goto out_free_mbx_wq;
5072 }
5073 phba->sli4_hba.els_wq = qdesc;
5074
5075 /* Create fast-path FCP Work Queue(s) */
5076 phba->sli4_hba.fcp_wq = kzalloc((sizeof(struct lpfc_queue *) *
5077 phba->cfg_fcp_wq_count), GFP_KERNEL);
5078 if (!phba->sli4_hba.fcp_wq) {
5079 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5080 "2578 Failed allocate memory for fast-path "
5081 "WQ record array\n");
5082 goto out_free_els_wq;
5083 }
5084 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
5085 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.wq_esize,
5086 phba->sli4_hba.wq_ecount);
5087 if (!qdesc) {
5088 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5089 "0503 Failed allocate fast-path FCP "
5090 "WQ (%d)\n", fcp_wqidx);
5091 goto out_free_fcp_wq;
5092 }
5093 phba->sli4_hba.fcp_wq[fcp_wqidx] = qdesc;
5094 }
5095
5096 /*
5097 * Create Receive Queue (RQ)
5098 */
5099 phba->sli4_hba.rq_esize = LPFC_RQE_SIZE;
5100 phba->sli4_hba.rq_ecount = LPFC_RQE_DEF_COUNT;
5101
5102 /* Create Receive Queue for header */
5103 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
5104 phba->sli4_hba.rq_ecount);
5105 if (!qdesc) {
5106 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5107 "0506 Failed allocate receive HRQ\n");
5108 goto out_free_fcp_wq;
5109 }
5110 phba->sli4_hba.hdr_rq = qdesc;
5111
5112 /* Create Receive Queue for data */
5113 qdesc = lpfc_sli4_queue_alloc(phba, phba->sli4_hba.rq_esize,
5114 phba->sli4_hba.rq_ecount);
5115 if (!qdesc) {
5116 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5117 "0507 Failed allocate receive DRQ\n");
5118 goto out_free_hdr_rq;
5119 }
5120 phba->sli4_hba.dat_rq = qdesc;
5121
5122 return 0;
5123
5124out_free_hdr_rq:
5125 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
5126 phba->sli4_hba.hdr_rq = NULL;
5127out_free_fcp_wq:
5128 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--) {
5129 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_wqidx]);
5130 phba->sli4_hba.fcp_wq[fcp_wqidx] = NULL;
5131 }
5132 kfree(phba->sli4_hba.fcp_wq);
5133out_free_els_wq:
5134 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
5135 phba->sli4_hba.els_wq = NULL;
5136out_free_mbx_wq:
5137 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
5138 phba->sli4_hba.mbx_wq = NULL;
5139out_free_fcp_cq:
5140 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--) {
5141 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_cqidx]);
5142 phba->sli4_hba.fcp_cq[fcp_cqidx] = NULL;
5143 }
5144 kfree(phba->sli4_hba.fcp_cq);
5145out_free_rxq_cq:
5146 lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
5147 phba->sli4_hba.rxq_cq = NULL;
5148out_free_els_cq:
5149 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
5150 phba->sli4_hba.els_cq = NULL;
5151out_free_mbx_cq:
5152 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
5153 phba->sli4_hba.mbx_cq = NULL;
5154out_free_fp_eq:
5155 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--) {
5156 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_eqidx]);
5157 phba->sli4_hba.fp_eq[fcp_eqidx] = NULL;
5158 }
5159 kfree(phba->sli4_hba.fp_eq);
5160out_free_sp_eq:
5161 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
5162 phba->sli4_hba.sp_eq = NULL;
5163out_error:
5164 return -ENOMEM;
5165}
5166
5167/**
5168 * lpfc_sli4_queue_destroy - Destroy all the SLI4 queues
5169 * @phba: pointer to lpfc hba data structure.
5170 *
5171 * This routine is invoked to release all the SLI4 queues with the FCoE HBA
5172 * operation.
5173 *
5174 * Return codes
5175 * 0 - sucessful
5176 * ENOMEM - No availble memory
5177 * EIO - The mailbox failed to complete successfully.
5178 **/
5179static void
5180lpfc_sli4_queue_destroy(struct lpfc_hba *phba)
5181{
5182 int fcp_qidx;
5183
5184 /* Release mailbox command work queue */
5185 lpfc_sli4_queue_free(phba->sli4_hba.mbx_wq);
5186 phba->sli4_hba.mbx_wq = NULL;
5187
5188 /* Release ELS work queue */
5189 lpfc_sli4_queue_free(phba->sli4_hba.els_wq);
5190 phba->sli4_hba.els_wq = NULL;
5191
5192 /* Release FCP work queue */
5193 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
5194 lpfc_sli4_queue_free(phba->sli4_hba.fcp_wq[fcp_qidx]);
5195 kfree(phba->sli4_hba.fcp_wq);
5196 phba->sli4_hba.fcp_wq = NULL;
5197
5198 /* Release unsolicited receive queue */
5199 lpfc_sli4_queue_free(phba->sli4_hba.hdr_rq);
5200 phba->sli4_hba.hdr_rq = NULL;
5201 lpfc_sli4_queue_free(phba->sli4_hba.dat_rq);
5202 phba->sli4_hba.dat_rq = NULL;
5203
5204 /* Release unsolicited receive complete queue */
5205 lpfc_sli4_queue_free(phba->sli4_hba.rxq_cq);
5206 phba->sli4_hba.rxq_cq = NULL;
5207
5208 /* Release ELS complete queue */
5209 lpfc_sli4_queue_free(phba->sli4_hba.els_cq);
5210 phba->sli4_hba.els_cq = NULL;
5211
5212 /* Release mailbox command complete queue */
5213 lpfc_sli4_queue_free(phba->sli4_hba.mbx_cq);
5214 phba->sli4_hba.mbx_cq = NULL;
5215
5216 /* Release FCP response complete queue */
5217 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5218 lpfc_sli4_queue_free(phba->sli4_hba.fcp_cq[fcp_qidx]);
5219 kfree(phba->sli4_hba.fcp_cq);
5220 phba->sli4_hba.fcp_cq = NULL;
5221
5222 /* Release fast-path event queue */
5223 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5224 lpfc_sli4_queue_free(phba->sli4_hba.fp_eq[fcp_qidx]);
5225 kfree(phba->sli4_hba.fp_eq);
5226 phba->sli4_hba.fp_eq = NULL;
5227
5228 /* Release slow-path event queue */
5229 lpfc_sli4_queue_free(phba->sli4_hba.sp_eq);
5230 phba->sli4_hba.sp_eq = NULL;
5231
5232 return;
5233}
5234
5235/**
5236 * lpfc_sli4_queue_setup - Set up all the SLI4 queues
5237 * @phba: pointer to lpfc hba data structure.
5238 *
5239 * This routine is invoked to set up all the SLI4 queues for the FCoE HBA
5240 * operation.
5241 *
5242 * Return codes
5243 * 0 - sucessful
5244 * ENOMEM - No availble memory
5245 * EIO - The mailbox failed to complete successfully.
5246 **/
5247int
5248lpfc_sli4_queue_setup(struct lpfc_hba *phba)
5249{
5250 int rc = -ENOMEM;
5251 int fcp_eqidx, fcp_cqidx, fcp_wqidx;
5252 int fcp_cq_index = 0;
5253
5254 /*
5255 * Set up Event Queues (EQs)
5256 */
5257
5258 /* Set up slow-path event queue */
5259 if (!phba->sli4_hba.sp_eq) {
5260 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5261 "0520 Slow-path EQ not allocated\n");
5262 goto out_error;
5263 }
5264 rc = lpfc_eq_create(phba, phba->sli4_hba.sp_eq,
5265 LPFC_SP_DEF_IMAX);
5266 if (rc) {
5267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5268 "0521 Failed setup of slow-path EQ: "
5269 "rc = 0x%x\n", rc);
5270 goto out_error;
5271 }
5272 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5273 "2583 Slow-path EQ setup: queue-id=%d\n",
5274 phba->sli4_hba.sp_eq->queue_id);
5275
5276 /* Set up fast-path event queue */
5277 for (fcp_eqidx = 0; fcp_eqidx < phba->cfg_fcp_eq_count; fcp_eqidx++) {
5278 if (!phba->sli4_hba.fp_eq[fcp_eqidx]) {
5279 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5280 "0522 Fast-path EQ (%d) not "
5281 "allocated\n", fcp_eqidx);
5282 goto out_destroy_fp_eq;
5283 }
5284 rc = lpfc_eq_create(phba, phba->sli4_hba.fp_eq[fcp_eqidx],
5285 phba->cfg_fcp_imax);
5286 if (rc) {
5287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5288 "0523 Failed setup of fast-path EQ "
5289 "(%d), rc = 0x%x\n", fcp_eqidx, rc);
5290 goto out_destroy_fp_eq;
5291 }
5292 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5293 "2584 Fast-path EQ setup: "
5294 "queue[%d]-id=%d\n", fcp_eqidx,
5295 phba->sli4_hba.fp_eq[fcp_eqidx]->queue_id);
5296 }
5297
5298 /*
5299 * Set up Complete Queues (CQs)
5300 */
5301
5302 /* Set up slow-path MBOX Complete Queue as the first CQ */
5303 if (!phba->sli4_hba.mbx_cq) {
5304 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5305 "0528 Mailbox CQ not allocated\n");
5306 goto out_destroy_fp_eq;
5307 }
5308 rc = lpfc_cq_create(phba, phba->sli4_hba.mbx_cq, phba->sli4_hba.sp_eq,
5309 LPFC_MCQ, LPFC_MBOX);
5310 if (rc) {
5311 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5312 "0529 Failed setup of slow-path mailbox CQ: "
5313 "rc = 0x%x\n", rc);
5314 goto out_destroy_fp_eq;
5315 }
5316 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5317 "2585 MBX CQ setup: cq-id=%d, parent eq-id=%d\n",
5318 phba->sli4_hba.mbx_cq->queue_id,
5319 phba->sli4_hba.sp_eq->queue_id);
5320
5321 /* Set up slow-path ELS Complete Queue */
5322 if (!phba->sli4_hba.els_cq) {
5323 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5324 "0530 ELS CQ not allocated\n");
5325 goto out_destroy_mbx_cq;
5326 }
5327 rc = lpfc_cq_create(phba, phba->sli4_hba.els_cq, phba->sli4_hba.sp_eq,
5328 LPFC_WCQ, LPFC_ELS);
5329 if (rc) {
5330 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5331 "0531 Failed setup of slow-path ELS CQ: "
5332 "rc = 0x%x\n", rc);
5333 goto out_destroy_mbx_cq;
5334 }
5335 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5336 "2586 ELS CQ setup: cq-id=%d, parent eq-id=%d\n",
5337 phba->sli4_hba.els_cq->queue_id,
5338 phba->sli4_hba.sp_eq->queue_id);
5339
5340 /* Set up slow-path Unsolicited Receive Complete Queue */
5341 if (!phba->sli4_hba.rxq_cq) {
5342 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5343 "0532 USOL RX CQ not allocated\n");
5344 goto out_destroy_els_cq;
5345 }
5346 rc = lpfc_cq_create(phba, phba->sli4_hba.rxq_cq, phba->sli4_hba.sp_eq,
5347 LPFC_RCQ, LPFC_USOL);
5348 if (rc) {
5349 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5350 "0533 Failed setup of slow-path USOL RX CQ: "
5351 "rc = 0x%x\n", rc);
5352 goto out_destroy_els_cq;
5353 }
5354 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5355 "2587 USL CQ setup: cq-id=%d, parent eq-id=%d\n",
5356 phba->sli4_hba.rxq_cq->queue_id,
5357 phba->sli4_hba.sp_eq->queue_id);
5358
5359 /* Set up fast-path FCP Response Complete Queue */
5360 for (fcp_cqidx = 0; fcp_cqidx < phba->cfg_fcp_eq_count; fcp_cqidx++) {
5361 if (!phba->sli4_hba.fcp_cq[fcp_cqidx]) {
5362 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5363 "0526 Fast-path FCP CQ (%d) not "
5364 "allocated\n", fcp_cqidx);
5365 goto out_destroy_fcp_cq;
5366 }
5367 rc = lpfc_cq_create(phba, phba->sli4_hba.fcp_cq[fcp_cqidx],
5368 phba->sli4_hba.fp_eq[fcp_cqidx],
5369 LPFC_WCQ, LPFC_FCP);
5370 if (rc) {
5371 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5372 "0527 Failed setup of fast-path FCP "
5373 "CQ (%d), rc = 0x%x\n", fcp_cqidx, rc);
5374 goto out_destroy_fcp_cq;
5375 }
5376 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5377 "2588 FCP CQ setup: cq[%d]-id=%d, "
5378 "parent eq[%d]-id=%d\n",
5379 fcp_cqidx,
5380 phba->sli4_hba.fcp_cq[fcp_cqidx]->queue_id,
5381 fcp_cqidx,
5382 phba->sli4_hba.fp_eq[fcp_cqidx]->queue_id);
5383 }
5384
5385 /*
5386 * Set up all the Work Queues (WQs)
5387 */
5388
5389 /* Set up Mailbox Command Queue */
5390 if (!phba->sli4_hba.mbx_wq) {
5391 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5392 "0538 Slow-path MQ not allocated\n");
5393 goto out_destroy_fcp_cq;
5394 }
5395 rc = lpfc_mq_create(phba, phba->sli4_hba.mbx_wq,
5396 phba->sli4_hba.mbx_cq, LPFC_MBOX);
5397 if (rc) {
5398 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5399 "0539 Failed setup of slow-path MQ: "
5400 "rc = 0x%x\n", rc);
5401 goto out_destroy_fcp_cq;
5402 }
5403 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5404 "2589 MBX MQ setup: wq-id=%d, parent cq-id=%d\n",
5405 phba->sli4_hba.mbx_wq->queue_id,
5406 phba->sli4_hba.mbx_cq->queue_id);
5407
5408 /* Set up slow-path ELS Work Queue */
5409 if (!phba->sli4_hba.els_wq) {
5410 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5411 "0536 Slow-path ELS WQ not allocated\n");
5412 goto out_destroy_mbx_wq;
5413 }
5414 rc = lpfc_wq_create(phba, phba->sli4_hba.els_wq,
5415 phba->sli4_hba.els_cq, LPFC_ELS);
5416 if (rc) {
5417 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5418 "0537 Failed setup of slow-path ELS WQ: "
5419 "rc = 0x%x\n", rc);
5420 goto out_destroy_mbx_wq;
5421 }
5422 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5423 "2590 ELS WQ setup: wq-id=%d, parent cq-id=%d\n",
5424 phba->sli4_hba.els_wq->queue_id,
5425 phba->sli4_hba.els_cq->queue_id);
5426
5427 /* Set up fast-path FCP Work Queue */
5428 for (fcp_wqidx = 0; fcp_wqidx < phba->cfg_fcp_wq_count; fcp_wqidx++) {
5429 if (!phba->sli4_hba.fcp_wq[fcp_wqidx]) {
5430 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5431 "0534 Fast-path FCP WQ (%d) not "
5432 "allocated\n", fcp_wqidx);
5433 goto out_destroy_fcp_wq;
5434 }
5435 rc = lpfc_wq_create(phba, phba->sli4_hba.fcp_wq[fcp_wqidx],
5436 phba->sli4_hba.fcp_cq[fcp_cq_index],
5437 LPFC_FCP);
5438 if (rc) {
5439 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5440 "0535 Failed setup of fast-path FCP "
5441 "WQ (%d), rc = 0x%x\n", fcp_wqidx, rc);
5442 goto out_destroy_fcp_wq;
5443 }
5444 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5445 "2591 FCP WQ setup: wq[%d]-id=%d, "
5446 "parent cq[%d]-id=%d\n",
5447 fcp_wqidx,
5448 phba->sli4_hba.fcp_wq[fcp_wqidx]->queue_id,
5449 fcp_cq_index,
5450 phba->sli4_hba.fcp_cq[fcp_cq_index]->queue_id);
5451 /* Round robin FCP Work Queue's Completion Queue assignment */
5452 fcp_cq_index = ((fcp_cq_index + 1) % phba->cfg_fcp_eq_count);
5453 }
5454
5455 /*
5456 * Create Receive Queue (RQ)
5457 */
5458 if (!phba->sli4_hba.hdr_rq || !phba->sli4_hba.dat_rq) {
5459 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5460 "0540 Receive Queue not allocated\n");
5461 goto out_destroy_fcp_wq;
5462 }
5463 rc = lpfc_rq_create(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq,
5464 phba->sli4_hba.rxq_cq, LPFC_USOL);
5465 if (rc) {
5466 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5467 "0541 Failed setup of Receive Queue: "
5468 "rc = 0x%x\n", rc);
5469 goto out_destroy_fcp_wq;
5470 }
5471 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
5472 "2592 USL RQ setup: hdr-rq-id=%d, dat-rq-id=%d "
5473 "parent cq-id=%d\n",
5474 phba->sli4_hba.hdr_rq->queue_id,
5475 phba->sli4_hba.dat_rq->queue_id,
5476 phba->sli4_hba.rxq_cq->queue_id);
5477 return 0;
5478
5479out_destroy_fcp_wq:
5480 for (--fcp_wqidx; fcp_wqidx >= 0; fcp_wqidx--)
5481 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_wqidx]);
5482 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
5483out_destroy_mbx_wq:
5484 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
5485out_destroy_fcp_cq:
5486 for (--fcp_cqidx; fcp_cqidx >= 0; fcp_cqidx--)
5487 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_cqidx]);
5488 lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
5489out_destroy_els_cq:
5490 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
5491out_destroy_mbx_cq:
5492 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
5493out_destroy_fp_eq:
5494 for (--fcp_eqidx; fcp_eqidx >= 0; fcp_eqidx--)
5495 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_eqidx]);
5496 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
5497out_error:
5498 return rc;
5499}
5500
5501/**
5502 * lpfc_sli4_queue_unset - Unset all the SLI4 queues
5503 * @phba: pointer to lpfc hba data structure.
5504 *
5505 * This routine is invoked to unset all the SLI4 queues with the FCoE HBA
5506 * operation.
5507 *
5508 * Return codes
5509 * 0 - sucessful
5510 * ENOMEM - No availble memory
5511 * EIO - The mailbox failed to complete successfully.
5512 **/
5513void
5514lpfc_sli4_queue_unset(struct lpfc_hba *phba)
5515{
5516 int fcp_qidx;
5517
5518 /* Unset mailbox command work queue */
5519 lpfc_mq_destroy(phba, phba->sli4_hba.mbx_wq);
5520 /* Unset ELS work queue */
5521 lpfc_wq_destroy(phba, phba->sli4_hba.els_wq);
5522 /* Unset unsolicited receive queue */
5523 lpfc_rq_destroy(phba, phba->sli4_hba.hdr_rq, phba->sli4_hba.dat_rq);
5524 /* Unset FCP work queue */
5525 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_wq_count; fcp_qidx++)
5526 lpfc_wq_destroy(phba, phba->sli4_hba.fcp_wq[fcp_qidx]);
5527 /* Unset mailbox command complete queue */
5528 lpfc_cq_destroy(phba, phba->sli4_hba.mbx_cq);
5529 /* Unset ELS complete queue */
5530 lpfc_cq_destroy(phba, phba->sli4_hba.els_cq);
5531 /* Unset unsolicited receive complete queue */
5532 lpfc_cq_destroy(phba, phba->sli4_hba.rxq_cq);
5533 /* Unset FCP response complete queue */
5534 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5535 lpfc_cq_destroy(phba, phba->sli4_hba.fcp_cq[fcp_qidx]);
5536 /* Unset fast-path event queue */
5537 for (fcp_qidx = 0; fcp_qidx < phba->cfg_fcp_eq_count; fcp_qidx++)
5538 lpfc_eq_destroy(phba, phba->sli4_hba.fp_eq[fcp_qidx]);
5539 /* Unset slow-path event queue */
5540 lpfc_eq_destroy(phba, phba->sli4_hba.sp_eq);
5541}
5542
5543/**
5544 * lpfc_sli4_cq_event_pool_create - Create completion-queue event free pool
5545 * @phba: pointer to lpfc hba data structure.
5546 *
5547 * This routine is invoked to allocate and set up a pool of completion queue
5548 * events. The body of the completion queue event is a completion queue entry
5549 * CQE. For now, this pool is used for the interrupt service routine to queue
5550 * the following HBA completion queue events for the worker thread to process:
5551 * - Mailbox asynchronous events
5552 * - Receive queue completion unsolicited events
5553 * Later, this can be used for all the slow-path events.
5554 *
5555 * Return codes
5556 * 0 - sucessful
5557 * -ENOMEM - No availble memory
5558 **/
5559static int
5560lpfc_sli4_cq_event_pool_create(struct lpfc_hba *phba)
5561{
5562 struct lpfc_cq_event *cq_event;
5563 int i;
5564
5565 for (i = 0; i < (4 * phba->sli4_hba.cq_ecount); i++) {
5566 cq_event = kmalloc(sizeof(struct lpfc_cq_event), GFP_KERNEL);
5567 if (!cq_event)
5568 goto out_pool_create_fail;
5569 list_add_tail(&cq_event->list,
5570 &phba->sli4_hba.sp_cqe_event_pool);
5571 }
5572 return 0;
5573
5574out_pool_create_fail:
5575 lpfc_sli4_cq_event_pool_destroy(phba);
5576 return -ENOMEM;
5577}
5578
5579/**
5580 * lpfc_sli4_cq_event_pool_destroy - Free completion-queue event free pool
5581 * @phba: pointer to lpfc hba data structure.
5582 *
5583 * This routine is invoked to free the pool of completion queue events at
5584 * driver unload time. Note that, it is the responsibility of the driver
5585 * cleanup routine to free all the outstanding completion-queue events
5586 * allocated from this pool back into the pool before invoking this routine
5587 * to destroy the pool.
5588 **/
5589static void
5590lpfc_sli4_cq_event_pool_destroy(struct lpfc_hba *phba)
5591{
5592 struct lpfc_cq_event *cq_event, *next_cq_event;
5593
5594 list_for_each_entry_safe(cq_event, next_cq_event,
5595 &phba->sli4_hba.sp_cqe_event_pool, list) {
5596 list_del(&cq_event->list);
5597 kfree(cq_event);
5598 }
5599}
5600
5601/**
5602 * __lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5603 * @phba: pointer to lpfc hba data structure.
5604 *
5605 * This routine is the lock free version of the API invoked to allocate a
5606 * completion-queue event from the free pool.
5607 *
5608 * Return: Pointer to the newly allocated completion-queue event if successful
5609 * NULL otherwise.
5610 **/
5611struct lpfc_cq_event *
5612__lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
5613{
5614 struct lpfc_cq_event *cq_event = NULL;
5615
5616 list_remove_head(&phba->sli4_hba.sp_cqe_event_pool, cq_event,
5617 struct lpfc_cq_event, list);
5618 return cq_event;
5619}
5620
5621/**
5622 * lpfc_sli4_cq_event_alloc - Allocate a completion-queue event from free pool
5623 * @phba: pointer to lpfc hba data structure.
5624 *
5625 * This routine is the lock version of the API invoked to allocate a
5626 * completion-queue event from the free pool.
5627 *
5628 * Return: Pointer to the newly allocated completion-queue event if successful
5629 * NULL otherwise.
5630 **/
5631struct lpfc_cq_event *
5632lpfc_sli4_cq_event_alloc(struct lpfc_hba *phba)
5633{
5634 struct lpfc_cq_event *cq_event;
5635 unsigned long iflags;
5636
5637 spin_lock_irqsave(&phba->hbalock, iflags);
5638 cq_event = __lpfc_sli4_cq_event_alloc(phba);
5639 spin_unlock_irqrestore(&phba->hbalock, iflags);
5640 return cq_event;
5641}
5642
5643/**
5644 * __lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5645 * @phba: pointer to lpfc hba data structure.
5646 * @cq_event: pointer to the completion queue event to be freed.
5647 *
5648 * This routine is the lock free version of the API invoked to release a
5649 * completion-queue event back into the free pool.
5650 **/
5651void
5652__lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
5653 struct lpfc_cq_event *cq_event)
5654{
5655 list_add_tail(&cq_event->list, &phba->sli4_hba.sp_cqe_event_pool);
5656}
5657
5658/**
5659 * lpfc_sli4_cq_event_release - Release a completion-queue event to free pool
5660 * @phba: pointer to lpfc hba data structure.
5661 * @cq_event: pointer to the completion queue event to be freed.
5662 *
5663 * This routine is the lock version of the API invoked to release a
5664 * completion-queue event back into the free pool.
5665 **/
5666void
5667lpfc_sli4_cq_event_release(struct lpfc_hba *phba,
5668 struct lpfc_cq_event *cq_event)
5669{
5670 unsigned long iflags;
5671 spin_lock_irqsave(&phba->hbalock, iflags);
5672 __lpfc_sli4_cq_event_release(phba, cq_event);
5673 spin_unlock_irqrestore(&phba->hbalock, iflags);
5674}
5675
5676/**
5677 * lpfc_sli4_cq_event_release_all - Release all cq events to the free pool
5678 * @phba: pointer to lpfc hba data structure.
5679 *
5680 * This routine is to free all the pending completion-queue events to the
5681 * back into the free pool for device reset.
5682 **/
5683static void
5684lpfc_sli4_cq_event_release_all(struct lpfc_hba *phba)
5685{
5686 LIST_HEAD(cqelist);
5687 struct lpfc_cq_event *cqe;
5688 unsigned long iflags;
5689
5690 /* Retrieve all the pending WCQEs from pending WCQE lists */
5691 spin_lock_irqsave(&phba->hbalock, iflags);
5692 /* Pending FCP XRI abort events */
5693 list_splice_init(&phba->sli4_hba.sp_fcp_xri_aborted_work_queue,
5694 &cqelist);
5695 /* Pending ELS XRI abort events */
5696 list_splice_init(&phba->sli4_hba.sp_els_xri_aborted_work_queue,
5697 &cqelist);
5698 /* Pending asynnc events */
5699 list_splice_init(&phba->sli4_hba.sp_asynce_work_queue,
5700 &cqelist);
5701 spin_unlock_irqrestore(&phba->hbalock, iflags);
5702
5703 while (!list_empty(&cqelist)) {
5704 list_remove_head(&cqelist, cqe, struct lpfc_cq_event, list);
5705 lpfc_sli4_cq_event_release(phba, cqe);
5706 }
5707}
5708
5709/**
5710 * lpfc_pci_function_reset - Reset pci function.
5711 * @phba: pointer to lpfc hba data structure.
5712 *
5713 * This routine is invoked to request a PCI function reset. It will destroys
5714 * all resources assigned to the PCI function which originates this request.
5715 *
5716 * Return codes
5717 * 0 - sucessful
5718 * ENOMEM - No availble memory
5719 * EIO - The mailbox failed to complete successfully.
5720 **/
5721int
5722lpfc_pci_function_reset(struct lpfc_hba *phba)
5723{
5724 LPFC_MBOXQ_t *mboxq;
5725 uint32_t rc = 0;
5726 uint32_t shdr_status, shdr_add_status;
5727 union lpfc_sli4_cfg_shdr *shdr;
5728
5729 mboxq = (LPFC_MBOXQ_t *) mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5730 if (!mboxq) {
5731 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5732 "0494 Unable to allocate memory for issuing "
5733 "SLI_FUNCTION_RESET mailbox command\n");
5734 return -ENOMEM;
5735 }
5736
5737 /* Set up PCI function reset SLI4_CONFIG mailbox-ioctl command */
5738 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5739 LPFC_MBOX_OPCODE_FUNCTION_RESET, 0,
5740 LPFC_SLI4_MBX_EMBED);
5741 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5742 shdr = (union lpfc_sli4_cfg_shdr *)
5743 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
5744 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5745 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
5746 if (rc != MBX_TIMEOUT)
5747 mempool_free(mboxq, phba->mbox_mem_pool);
5748 if (shdr_status || shdr_add_status || rc) {
5749 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5750 "0495 SLI_FUNCTION_RESET mailbox failed with "
5751 "status x%x add_status x%x, mbx status x%x\n",
5752 shdr_status, shdr_add_status, rc);
5753 rc = -ENXIO;
5754 }
5755 return rc;
5756}
5757
5758/**
5759 * lpfc_sli4_send_nop_mbox_cmds - Send sli-4 nop mailbox commands
5760 * @phba: pointer to lpfc hba data structure.
5761 * @cnt: number of nop mailbox commands to send.
5762 *
5763 * This routine is invoked to send a number @cnt of NOP mailbox command and
5764 * wait for each command to complete.
5765 *
5766 * Return: the number of NOP mailbox command completed.
5767 **/
5768static int
5769lpfc_sli4_send_nop_mbox_cmds(struct lpfc_hba *phba, uint32_t cnt)
5770{
5771 LPFC_MBOXQ_t *mboxq;
5772 int length, cmdsent;
5773 uint32_t mbox_tmo;
5774 uint32_t rc = 0;
5775 uint32_t shdr_status, shdr_add_status;
5776 union lpfc_sli4_cfg_shdr *shdr;
5777
5778 if (cnt == 0) {
5779 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5780 "2518 Requested to send 0 NOP mailbox cmd\n");
5781 return cnt;
5782 }
5783
5784 mboxq = (LPFC_MBOXQ_t *)mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5785 if (!mboxq) {
5786 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5787 "2519 Unable to allocate memory for issuing "
5788 "NOP mailbox command\n");
5789 return 0;
5790 }
5791
5792 /* Set up NOP SLI4_CONFIG mailbox-ioctl command */
5793 length = (sizeof(struct lpfc_mbx_nop) -
5794 sizeof(struct lpfc_sli4_cfg_mhdr));
5795 lpfc_sli4_config(phba, mboxq, LPFC_MBOX_SUBSYSTEM_COMMON,
5796 LPFC_MBOX_OPCODE_NOP, length, LPFC_SLI4_MBX_EMBED);
5797
5798 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
5799 for (cmdsent = 0; cmdsent < cnt; cmdsent++) {
5800 if (!phba->sli4_hba.intr_enable)
5801 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_POLL);
5802 else
5803 rc = lpfc_sli_issue_mbox_wait(phba, mboxq, mbox_tmo);
5804 if (rc == MBX_TIMEOUT)
5805 break;
5806 /* Check return status */
5807 shdr = (union lpfc_sli4_cfg_shdr *)
5808 &mboxq->u.mqe.un.sli4_config.header.cfg_shdr;
5809 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
5810 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status,
5811 &shdr->response);
5812 if (shdr_status || shdr_add_status || rc) {
5813 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
5814 "2520 NOP mailbox command failed "
5815 "status x%x add_status x%x mbx "
5816 "status x%x\n", shdr_status,
5817 shdr_add_status, rc);
5818 break;
5819 }
5820 }
5821
5822 if (rc != MBX_TIMEOUT)
5823 mempool_free(mboxq, phba->mbox_mem_pool);
5824
5825 return cmdsent;
5826}
5827
5828/**
5829 * lpfc_sli4_fcfi_unreg - Unregister fcfi to device
5830 * @phba: pointer to lpfc hba data structure.
5831 * @fcfi: fcf index.
5832 *
5833 * This routine is invoked to unregister a FCFI from device.
5834 **/
5835void
5836lpfc_sli4_fcfi_unreg(struct lpfc_hba *phba, uint16_t fcfi)
5837{
5838 LPFC_MBOXQ_t *mbox;
5839 uint32_t mbox_tmo;
5840 int rc;
5841 unsigned long flags;
5842
5843 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5844
5845 if (!mbox)
5846 return;
5847
5848 lpfc_unreg_fcfi(mbox, fcfi);
5849
5850 if (!phba->sli4_hba.intr_enable)
5851 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_POLL);
5852 else {
5853 mbox_tmo = lpfc_mbox_tmo_val(phba, MBX_SLI4_CONFIG);
5854 rc = lpfc_sli_issue_mbox_wait(phba, mbox, mbox_tmo);
5855 }
5856 if (rc != MBX_TIMEOUT)
5857 mempool_free(mbox, phba->mbox_mem_pool);
5858 if (rc != MBX_SUCCESS)
5859 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5860 "2517 Unregister FCFI command failed "
5861 "status %d, mbxStatus x%x\n", rc,
5862 bf_get(lpfc_mqe_status, &mbox->u.mqe));
5863 else {
5864 spin_lock_irqsave(&phba->hbalock, flags);
5865 /* Mark the FCFI is no longer registered */
5866 phba->fcf.fcf_flag &=
5867 ~(FCF_AVAILABLE | FCF_REGISTERED | FCF_DISCOVERED);
5868 spin_unlock_irqrestore(&phba->hbalock, flags);
5869 }
5870}
5871
5872/**
5873 * lpfc_sli4_pci_mem_setup - Setup SLI4 HBA PCI memory space.
5874 * @phba: pointer to lpfc hba data structure.
5875 *
5876 * This routine is invoked to set up the PCI device memory space for device
5877 * with SLI-4 interface spec.
5878 *
5879 * Return codes
5880 * 0 - sucessful
5881 * other values - error
5882 **/
5883static int
5884lpfc_sli4_pci_mem_setup(struct lpfc_hba *phba)
5885{
5886 struct pci_dev *pdev;
5887 unsigned long bar0map_len, bar1map_len, bar2map_len;
5888 int error = -ENODEV;
5889
5890 /* Obtain PCI device reference */
5891 if (!phba->pcidev)
5892 return error;
5893 else
5894 pdev = phba->pcidev;
5895
5896 /* Set the device DMA mask size */
5897 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0)
5898 if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0)
5899 return error;
5900
5901 /* Get the bus address of SLI4 device Bar0, Bar1, and Bar2 and the
5902 * number of bytes required by each mapping. They are actually
5903 * mapping to the PCI BAR regions 1, 2, and 4 by the SLI4 device.
5904 */
5905 phba->pci_bar0_map = pci_resource_start(pdev, LPFC_SLI4_BAR0);
5906 bar0map_len = pci_resource_len(pdev, LPFC_SLI4_BAR0);
5907
5908 phba->pci_bar1_map = pci_resource_start(pdev, LPFC_SLI4_BAR1);
5909 bar1map_len = pci_resource_len(pdev, LPFC_SLI4_BAR1);
5910
5911 phba->pci_bar2_map = pci_resource_start(pdev, LPFC_SLI4_BAR2);
5912 bar2map_len = pci_resource_len(pdev, LPFC_SLI4_BAR2);
5913
5914 /* Map SLI4 PCI Config Space Register base to a kernel virtual addr */
5915 phba->sli4_hba.conf_regs_memmap_p =
5916 ioremap(phba->pci_bar0_map, bar0map_len);
5917 if (!phba->sli4_hba.conf_regs_memmap_p) {
5918 dev_printk(KERN_ERR, &pdev->dev,
5919 "ioremap failed for SLI4 PCI config registers.\n");
5920 goto out;
5921 }
5922
5923 /* Map SLI4 HBA Control Register base to a kernel virtual address. */
5924 phba->sli4_hba.ctrl_regs_memmap_p =
5925 ioremap(phba->pci_bar1_map, bar1map_len);
5926 if (!phba->sli4_hba.ctrl_regs_memmap_p) {
5927 dev_printk(KERN_ERR, &pdev->dev,
5928 "ioremap failed for SLI4 HBA control registers.\n");
5929 goto out_iounmap_conf;
5930 }
5931
5932 /* Map SLI4 HBA Doorbell Register base to a kernel virtual address. */
5933 phba->sli4_hba.drbl_regs_memmap_p =
5934 ioremap(phba->pci_bar2_map, bar2map_len);
5935 if (!phba->sli4_hba.drbl_regs_memmap_p) {
5936 dev_printk(KERN_ERR, &pdev->dev,
5937 "ioremap failed for SLI4 HBA doorbell registers.\n");
5938 goto out_iounmap_ctrl;
5939 }
5940
5941 /* Set up BAR0 PCI config space register memory map */
5942 lpfc_sli4_bar0_register_memmap(phba);
5943
5944 /* Set up BAR1 register memory map */
5945 lpfc_sli4_bar1_register_memmap(phba);
5946
5947 /* Set up BAR2 register memory map */
5948 error = lpfc_sli4_bar2_register_memmap(phba, LPFC_VF0);
5949 if (error)
5950 goto out_iounmap_all;
5951
5952 return 0;
5953
5954out_iounmap_all:
5955 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
5956out_iounmap_ctrl:
5957 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
5958out_iounmap_conf:
5959 iounmap(phba->sli4_hba.conf_regs_memmap_p);
5960out:
5961 return error;
5962}
5963
5964/**
5965 * lpfc_sli4_pci_mem_unset - Unset SLI4 HBA PCI memory space.
5966 * @phba: pointer to lpfc hba data structure.
5967 *
5968 * This routine is invoked to unset the PCI device memory space for device
5969 * with SLI-4 interface spec.
5970 **/
5971static void
5972lpfc_sli4_pci_mem_unset(struct lpfc_hba *phba)
5973{
5974 struct pci_dev *pdev;
5975
5976 /* Obtain PCI device reference */
5977 if (!phba->pcidev)
5978 return;
5979 else
5980 pdev = phba->pcidev;
5981
5982 /* Free coherent DMA memory allocated */
5983
5984 /* Unmap I/O memory space */
5985 iounmap(phba->sli4_hba.drbl_regs_memmap_p);
5986 iounmap(phba->sli4_hba.ctrl_regs_memmap_p);
5987 iounmap(phba->sli4_hba.conf_regs_memmap_p);
5988
5989 return;
5990}
5991
5992/**
3319 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device 5993 * lpfc_sli_enable_msix - Enable MSI-X interrupt mode on SLI-3 device
3320 * @phba: pointer to lpfc hba data structure. 5994 * @phba: pointer to lpfc hba data structure.
3321 * 5995 *
@@ -3597,6 +6271,276 @@ lpfc_sli_disable_intr(struct lpfc_hba *phba)
3597} 6271}
3598 6272
3599/** 6273/**
6274 * lpfc_sli4_enable_msix - Enable MSI-X interrupt mode to SLI-4 device
6275 * @phba: pointer to lpfc hba data structure.
6276 *
6277 * This routine is invoked to enable the MSI-X interrupt vectors to device
6278 * with SLI-4 interface spec. The kernel function pci_enable_msix() is called
6279 * to enable the MSI-X vectors. Note that pci_enable_msix(), once invoked,
6280 * enables either all or nothing, depending on the current availability of
6281 * PCI vector resources. The device driver is responsible for calling the
6282 * individual request_irq() to register each MSI-X vector with a interrupt
6283 * handler, which is done in this function. Note that later when device is
6284 * unloading, the driver should always call free_irq() on all MSI-X vectors
6285 * it has done request_irq() on before calling pci_disable_msix(). Failure
6286 * to do so results in a BUG_ON() and a device will be left with MSI-X
6287 * enabled and leaks its vectors.
6288 *
6289 * Return codes
6290 * 0 - sucessful
6291 * other values - error
6292 **/
6293static int
6294lpfc_sli4_enable_msix(struct lpfc_hba *phba)
6295{
6296 int rc, index;
6297
6298 /* Set up MSI-X multi-message vectors */
6299 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
6300 phba->sli4_hba.msix_entries[index].entry = index;
6301
6302 /* Configure MSI-X capability structure */
6303 rc = pci_enable_msix(phba->pcidev, phba->sli4_hba.msix_entries,
6304 phba->sli4_hba.cfg_eqn);
6305 if (rc) {
6306 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6307 "0484 PCI enable MSI-X failed (%d)\n", rc);
6308 goto msi_fail_out;
6309 }
6310 /* Log MSI-X vector assignment */
6311 for (index = 0; index < phba->sli4_hba.cfg_eqn; index++)
6312 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6313 "0489 MSI-X entry[%d]: vector=x%x "
6314 "message=%d\n", index,
6315 phba->sli4_hba.msix_entries[index].vector,
6316 phba->sli4_hba.msix_entries[index].entry);
6317 /*
6318 * Assign MSI-X vectors to interrupt handlers
6319 */
6320
6321 /* The first vector must associated to slow-path handler for MQ */
6322 rc = request_irq(phba->sli4_hba.msix_entries[0].vector,
6323 &lpfc_sli4_sp_intr_handler, IRQF_SHARED,
6324 LPFC_SP_DRIVER_HANDLER_NAME, phba);
6325 if (rc) {
6326 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6327 "0485 MSI-X slow-path request_irq failed "
6328 "(%d)\n", rc);
6329 goto msi_fail_out;
6330 }
6331
6332 /* The rest of the vector(s) are associated to fast-path handler(s) */
6333 for (index = 1; index < phba->sli4_hba.cfg_eqn; index++) {
6334 phba->sli4_hba.fcp_eq_hdl[index - 1].idx = index - 1;
6335 phba->sli4_hba.fcp_eq_hdl[index - 1].phba = phba;
6336 rc = request_irq(phba->sli4_hba.msix_entries[index].vector,
6337 &lpfc_sli4_fp_intr_handler, IRQF_SHARED,
6338 LPFC_FP_DRIVER_HANDLER_NAME,
6339 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6340 if (rc) {
6341 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6342 "0486 MSI-X fast-path (%d) "
6343 "request_irq failed (%d)\n", index, rc);
6344 goto cfg_fail_out;
6345 }
6346 }
6347
6348 return rc;
6349
6350cfg_fail_out:
6351 /* free the irq already requested */
6352 for (--index; index >= 1; index--)
6353 free_irq(phba->sli4_hba.msix_entries[index - 1].vector,
6354 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6355
6356 /* free the irq already requested */
6357 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
6358
6359msi_fail_out:
6360 /* Unconfigure MSI-X capability structure */
6361 pci_disable_msix(phba->pcidev);
6362 return rc;
6363}
6364
6365/**
6366 * lpfc_sli4_disable_msix - Disable MSI-X interrupt mode to SLI-4 device
6367 * @phba: pointer to lpfc hba data structure.
6368 *
6369 * This routine is invoked to release the MSI-X vectors and then disable the
6370 * MSI-X interrupt mode to device with SLI-4 interface spec.
6371 **/
6372static void
6373lpfc_sli4_disable_msix(struct lpfc_hba *phba)
6374{
6375 int index;
6376
6377 /* Free up MSI-X multi-message vectors */
6378 free_irq(phba->sli4_hba.msix_entries[0].vector, phba);
6379
6380 for (index = 1; index < phba->sli4_hba.cfg_eqn; index++)
6381 free_irq(phba->sli4_hba.msix_entries[index].vector,
6382 &phba->sli4_hba.fcp_eq_hdl[index - 1]);
6383 /* Disable MSI-X */
6384 pci_disable_msix(phba->pcidev);
6385
6386 return;
6387}
6388
6389/**
6390 * lpfc_sli4_enable_msi - Enable MSI interrupt mode to SLI-4 device
6391 * @phba: pointer to lpfc hba data structure.
6392 *
6393 * This routine is invoked to enable the MSI interrupt mode to device with
6394 * SLI-4 interface spec. The kernel function pci_enable_msi() is called
6395 * to enable the MSI vector. The device driver is responsible for calling
6396 * the request_irq() to register MSI vector with a interrupt the handler,
6397 * which is done in this function.
6398 *
6399 * Return codes
6400 * 0 - sucessful
6401 * other values - error
6402 **/
6403static int
6404lpfc_sli4_enable_msi(struct lpfc_hba *phba)
6405{
6406 int rc, index;
6407
6408 rc = pci_enable_msi(phba->pcidev);
6409 if (!rc)
6410 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6411 "0487 PCI enable MSI mode success.\n");
6412 else {
6413 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
6414 "0488 PCI enable MSI mode failed (%d)\n", rc);
6415 return rc;
6416 }
6417
6418 rc = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
6419 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6420 if (rc) {
6421 pci_disable_msi(phba->pcidev);
6422 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
6423 "0490 MSI request_irq failed (%d)\n", rc);
6424 }
6425
6426 for (index = 0; index < phba->cfg_fcp_eq_count; index++) {
6427 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
6428 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
6429 }
6430
6431 return rc;
6432}
6433
6434/**
6435 * lpfc_sli4_disable_msi - Disable MSI interrupt mode to SLI-4 device
6436 * @phba: pointer to lpfc hba data structure.
6437 *
6438 * This routine is invoked to disable the MSI interrupt mode to device with
6439 * SLI-4 interface spec. The driver calls free_irq() on MSI vector it has
6440 * done request_irq() on before calling pci_disable_msi(). Failure to do so
6441 * results in a BUG_ON() and a device will be left with MSI enabled and leaks
6442 * its vector.
6443 **/
6444static void
6445lpfc_sli4_disable_msi(struct lpfc_hba *phba)
6446{
6447 free_irq(phba->pcidev->irq, phba);
6448 pci_disable_msi(phba->pcidev);
6449 return;
6450}
6451
6452/**
6453 * lpfc_sli4_enable_intr - Enable device interrupt to SLI-4 device
6454 * @phba: pointer to lpfc hba data structure.
6455 *
6456 * This routine is invoked to enable device interrupt and associate driver's
6457 * interrupt handler(s) to interrupt vector(s) to device with SLI-4
6458 * interface spec. Depends on the interrupt mode configured to the driver,
6459 * the driver will try to fallback from the configured interrupt mode to an
6460 * interrupt mode which is supported by the platform, kernel, and device in
6461 * the order of:
6462 * MSI-X -> MSI -> IRQ.
6463 *
6464 * Return codes
6465 * 0 - sucessful
6466 * other values - error
6467 **/
6468static uint32_t
6469lpfc_sli4_enable_intr(struct lpfc_hba *phba, uint32_t cfg_mode)
6470{
6471 uint32_t intr_mode = LPFC_INTR_ERROR;
6472 int retval, index;
6473
6474 if (cfg_mode == 2) {
6475 /* Preparation before conf_msi mbox cmd */
6476 retval = 0;
6477 if (!retval) {
6478 /* Now, try to enable MSI-X interrupt mode */
6479 retval = lpfc_sli4_enable_msix(phba);
6480 if (!retval) {
6481 /* Indicate initialization to MSI-X mode */
6482 phba->intr_type = MSIX;
6483 intr_mode = 2;
6484 }
6485 }
6486 }
6487
6488 /* Fallback to MSI if MSI-X initialization failed */
6489 if (cfg_mode >= 1 && phba->intr_type == NONE) {
6490 retval = lpfc_sli4_enable_msi(phba);
6491 if (!retval) {
6492 /* Indicate initialization to MSI mode */
6493 phba->intr_type = MSI;
6494 intr_mode = 1;
6495 }
6496 }
6497
6498 /* Fallback to INTx if both MSI-X/MSI initalization failed */
6499 if (phba->intr_type == NONE) {
6500 retval = request_irq(phba->pcidev->irq, lpfc_sli4_intr_handler,
6501 IRQF_SHARED, LPFC_DRIVER_NAME, phba);
6502 if (!retval) {
6503 /* Indicate initialization to INTx mode */
6504 phba->intr_type = INTx;
6505 intr_mode = 0;
6506 for (index = 0; index < phba->cfg_fcp_eq_count;
6507 index++) {
6508 phba->sli4_hba.fcp_eq_hdl[index].idx = index;
6509 phba->sli4_hba.fcp_eq_hdl[index].phba = phba;
6510 }
6511 }
6512 }
6513 return intr_mode;
6514}
6515
6516/**
6517 * lpfc_sli4_disable_intr - Disable device interrupt to SLI-4 device
6518 * @phba: pointer to lpfc hba data structure.
6519 *
6520 * This routine is invoked to disable device interrupt and disassociate
6521 * the driver's interrupt handler(s) from interrupt vector(s) to device
6522 * with SLI-4 interface spec. Depending on the interrupt mode, the driver
6523 * will release the interrupt vector(s) for the message signaled interrupt.
6524 **/
6525static void
6526lpfc_sli4_disable_intr(struct lpfc_hba *phba)
6527{
6528 /* Disable the currently initialized interrupt mode */
6529 if (phba->intr_type == MSIX)
6530 lpfc_sli4_disable_msix(phba);
6531 else if (phba->intr_type == MSI)
6532 lpfc_sli4_disable_msi(phba);
6533 else if (phba->intr_type == INTx)
6534 free_irq(phba->pcidev->irq, phba);
6535
6536 /* Reset interrupt management states */
6537 phba->intr_type = NONE;
6538 phba->sli.slistat.sli_intr = 0;
6539
6540 return;
6541}
6542
6543/**
3600 * lpfc_unset_hba - Unset SLI3 hba device initialization 6544 * lpfc_unset_hba - Unset SLI3 hba device initialization
3601 * @phba: pointer to lpfc hba data structure. 6545 * @phba: pointer to lpfc hba data structure.
3602 * 6546 *
@@ -3627,6 +6571,90 @@ lpfc_unset_hba(struct lpfc_hba *phba)
3627} 6571}
3628 6572
3629/** 6573/**
6574 * lpfc_sli4_unset_hba - Unset SLI4 hba device initialization.
6575 * @phba: pointer to lpfc hba data structure.
6576 *
6577 * This routine is invoked to unset the HBA device initialization steps to
6578 * a device with SLI-4 interface spec.
6579 **/
6580static void
6581lpfc_sli4_unset_hba(struct lpfc_hba *phba)
6582{
6583 struct lpfc_vport *vport = phba->pport;
6584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6585
6586 spin_lock_irq(shost->host_lock);
6587 vport->load_flag |= FC_UNLOADING;
6588 spin_unlock_irq(shost->host_lock);
6589
6590 phba->pport->work_port_events = 0;
6591
6592 lpfc_sli4_hba_down(phba);
6593
6594 lpfc_sli4_disable_intr(phba);
6595
6596 return;
6597}
6598
6599/**
6600 * lpfc_sli4_hba_unset - Unset the fcoe hba
6601 * @phba: Pointer to HBA context object.
6602 *
6603 * This function is called in the SLI4 code path to reset the HBA's FCoE
6604 * function. The caller is not required to hold any lock. This routine
6605 * issues PCI function reset mailbox command to reset the FCoE function.
6606 * At the end of the function, it calls lpfc_hba_down_post function to
6607 * free any pending commands.
6608 **/
6609static void
6610lpfc_sli4_hba_unset(struct lpfc_hba *phba)
6611{
6612 int wait_cnt = 0;
6613 LPFC_MBOXQ_t *mboxq;
6614
6615 lpfc_stop_hba_timers(phba);
6616 phba->sli4_hba.intr_enable = 0;
6617
6618 /*
6619 * Gracefully wait out the potential current outstanding asynchronous
6620 * mailbox command.
6621 */
6622
6623 /* First, block any pending async mailbox command from posted */
6624 spin_lock_irq(&phba->hbalock);
6625 phba->sli.sli_flag |= LPFC_SLI_ASYNC_MBX_BLK;
6626 spin_unlock_irq(&phba->hbalock);
6627 /* Now, trying to wait it out if we can */
6628 while (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6629 msleep(10);
6630 if (++wait_cnt > LPFC_ACTIVE_MBOX_WAIT_CNT)
6631 break;
6632 }
6633 /* Forcefully release the outstanding mailbox command if timed out */
6634 if (phba->sli.sli_flag & LPFC_SLI_MBOX_ACTIVE) {
6635 spin_lock_irq(&phba->hbalock);
6636 mboxq = phba->sli.mbox_active;
6637 mboxq->u.mb.mbxStatus = MBX_NOT_FINISHED;
6638 __lpfc_mbox_cmpl_put(phba, mboxq);
6639 phba->sli.sli_flag &= ~LPFC_SLI_MBOX_ACTIVE;
6640 phba->sli.mbox_active = NULL;
6641 spin_unlock_irq(&phba->hbalock);
6642 }
6643
6644 /* Tear down the queues in the HBA */
6645 lpfc_sli4_queue_unset(phba);
6646
6647 /* Disable PCI subsystem interrupt */
6648 lpfc_sli4_disable_intr(phba);
6649
6650 /* Stop kthread signal shall trigger work_done one more time */
6651 kthread_stop(phba->worker_thread);
6652
6653 /* Stop the SLI4 device port */
6654 phba->pport->work_port_events = 0;
6655}
6656
6657/**
3630 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem. 6658 * lpfc_pci_probe_one_s3 - PCI probe func to reg SLI-3 device to PCI subsystem.
3631 * @pdev: pointer to PCI device 6659 * @pdev: pointer to PCI device
3632 * @pid: pointer to PCI device identifier 6660 * @pid: pointer to PCI device identifier
@@ -4127,6 +7155,446 @@ lpfc_io_resume_s3(struct pci_dev *pdev)
4127} 7155}
4128 7156
4129/** 7157/**
7158 * lpfc_sli4_get_els_iocb_cnt - Calculate the # of ELS IOCBs to reserve
7159 * @phba: pointer to lpfc hba data structure.
7160 *
7161 * returns the number of ELS/CT IOCBs to reserve
7162 **/
7163int
7164lpfc_sli4_get_els_iocb_cnt(struct lpfc_hba *phba)
7165{
7166 int max_xri = phba->sli4_hba.max_cfg_param.max_xri;
7167
7168 if (max_xri <= 100)
7169 return 4;
7170 else if (max_xri <= 256)
7171 return 8;
7172 else if (max_xri <= 512)
7173 return 16;
7174 else if (max_xri <= 1024)
7175 return 32;
7176 else
7177 return 48;
7178}
7179
7180/**
7181 * lpfc_pci_probe_one_s4 - PCI probe func to reg SLI-4 device to PCI subsys
7182 * @pdev: pointer to PCI device
7183 * @pid: pointer to PCI device identifier
7184 *
7185 * This routine is called from the kernel's PCI subsystem to device with
7186 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7187 * presented on PCI bus, the kernel PCI subsystem looks at PCI device-specific
7188 * information of the device and driver to see if the driver state that it
7189 * can support this kind of device. If the match is successful, the driver
7190 * core invokes this routine. If this routine determines it can claim the HBA,
7191 * it does all the initialization that it needs to do to handle the HBA
7192 * properly.
7193 *
7194 * Return code
7195 * 0 - driver can claim the device
7196 * negative value - driver can not claim the device
7197 **/
7198static int __devinit
7199lpfc_pci_probe_one_s4(struct pci_dev *pdev, const struct pci_device_id *pid)
7200{
7201 struct lpfc_hba *phba;
7202 struct lpfc_vport *vport = NULL;
7203 int error;
7204 uint32_t cfg_mode, intr_mode;
7205 int mcnt;
7206
7207 /* Allocate memory for HBA structure */
7208 phba = lpfc_hba_alloc(pdev);
7209 if (!phba)
7210 return -ENOMEM;
7211
7212 /* Perform generic PCI device enabling operation */
7213 error = lpfc_enable_pci_dev(phba);
7214 if (error) {
7215 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7216 "1409 Failed to enable pci device.\n");
7217 goto out_free_phba;
7218 }
7219
7220 /* Set up SLI API function jump table for PCI-device group-1 HBAs */
7221 error = lpfc_api_table_setup(phba, LPFC_PCI_DEV_OC);
7222 if (error)
7223 goto out_disable_pci_dev;
7224
7225 /* Set up SLI-4 specific device PCI memory space */
7226 error = lpfc_sli4_pci_mem_setup(phba);
7227 if (error) {
7228 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7229 "1410 Failed to set up pci memory space.\n");
7230 goto out_disable_pci_dev;
7231 }
7232
7233 /* Set up phase-1 common device driver resources */
7234 error = lpfc_setup_driver_resource_phase1(phba);
7235 if (error) {
7236 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7237 "1411 Failed to set up driver resource.\n");
7238 goto out_unset_pci_mem_s4;
7239 }
7240
7241 /* Set up SLI-4 Specific device driver resources */
7242 error = lpfc_sli4_driver_resource_setup(phba);
7243 if (error) {
7244 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7245 "1412 Failed to set up driver resource.\n");
7246 goto out_unset_pci_mem_s4;
7247 }
7248
7249 /* Initialize and populate the iocb list per host */
7250 error = lpfc_init_iocb_list(phba,
7251 phba->sli4_hba.max_cfg_param.max_xri);
7252 if (error) {
7253 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7254 "1413 Failed to initialize iocb list.\n");
7255 goto out_unset_driver_resource_s4;
7256 }
7257
7258 /* Set up common device driver resources */
7259 error = lpfc_setup_driver_resource_phase2(phba);
7260 if (error) {
7261 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7262 "1414 Failed to set up driver resource.\n");
7263 goto out_free_iocb_list;
7264 }
7265
7266 /* Create SCSI host to the physical port */
7267 error = lpfc_create_shost(phba);
7268 if (error) {
7269 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7270 "1415 Failed to create scsi host.\n");
7271 goto out_unset_driver_resource;
7272 }
7273
7274 /* Configure sysfs attributes */
7275 vport = phba->pport;
7276 error = lpfc_alloc_sysfs_attr(vport);
7277 if (error) {
7278 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7279 "1416 Failed to allocate sysfs attr\n");
7280 goto out_destroy_shost;
7281 }
7282
7283 /* Now, trying to enable interrupt and bring up the device */
7284 cfg_mode = phba->cfg_use_msi;
7285 while (true) {
7286 /* Put device to a known state before enabling interrupt */
7287 lpfc_stop_port(phba);
7288 /* Configure and enable interrupt */
7289 intr_mode = lpfc_sli4_enable_intr(phba, cfg_mode);
7290 if (intr_mode == LPFC_INTR_ERROR) {
7291 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7292 "0426 Failed to enable interrupt.\n");
7293 error = -ENODEV;
7294 goto out_free_sysfs_attr;
7295 }
7296 /* Set up SLI-4 HBA */
7297 if (lpfc_sli4_hba_setup(phba)) {
7298 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7299 "1421 Failed to set up hba\n");
7300 error = -ENODEV;
7301 goto out_disable_intr;
7302 }
7303
7304 /* Send NOP mbx cmds for non-INTx mode active interrupt test */
7305 if (intr_mode != 0)
7306 mcnt = lpfc_sli4_send_nop_mbox_cmds(phba,
7307 LPFC_ACT_INTR_CNT);
7308
7309 /* Check active interrupts received only for MSI/MSI-X */
7310 if (intr_mode == 0 ||
7311 phba->sli.slistat.sli_intr >= LPFC_ACT_INTR_CNT) {
7312 /* Log the current active interrupt mode */
7313 phba->intr_mode = intr_mode;
7314 lpfc_log_intr_mode(phba, intr_mode);
7315 break;
7316 }
7317 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7318 "0451 Configure interrupt mode (%d) "
7319 "failed active interrupt test.\n",
7320 intr_mode);
7321 /* Unset the preivous SLI-4 HBA setup */
7322 lpfc_sli4_unset_hba(phba);
7323 /* Try next level of interrupt mode */
7324 cfg_mode = --intr_mode;
7325 }
7326
7327 /* Perform post initialization setup */
7328 lpfc_post_init_setup(phba);
7329
7330 return 0;
7331
7332out_disable_intr:
7333 lpfc_sli4_disable_intr(phba);
7334out_free_sysfs_attr:
7335 lpfc_free_sysfs_attr(vport);
7336out_destroy_shost:
7337 lpfc_destroy_shost(phba);
7338out_unset_driver_resource:
7339 lpfc_unset_driver_resource_phase2(phba);
7340out_free_iocb_list:
7341 lpfc_free_iocb_list(phba);
7342out_unset_driver_resource_s4:
7343 lpfc_sli4_driver_resource_unset(phba);
7344out_unset_pci_mem_s4:
7345 lpfc_sli4_pci_mem_unset(phba);
7346out_disable_pci_dev:
7347 lpfc_disable_pci_dev(phba);
7348out_free_phba:
7349 lpfc_hba_free(phba);
7350 return error;
7351}
7352
7353/**
7354 * lpfc_pci_remove_one_s4 - PCI func to unreg SLI-4 device from PCI subsystem
7355 * @pdev: pointer to PCI device
7356 *
7357 * This routine is called from the kernel's PCI subsystem to device with
7358 * SLI-4 interface spec. When an Emulex HBA with SLI-4 interface spec is
7359 * removed from PCI bus, it performs all the necessary cleanup for the HBA
7360 * device to be removed from the PCI subsystem properly.
7361 **/
7362static void __devexit
7363lpfc_pci_remove_one_s4(struct pci_dev *pdev)
7364{
7365 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7366 struct lpfc_vport *vport = (struct lpfc_vport *) shost->hostdata;
7367 struct lpfc_vport **vports;
7368 struct lpfc_hba *phba = vport->phba;
7369 int i;
7370
7371 /* Mark the device unloading flag */
7372 spin_lock_irq(&phba->hbalock);
7373 vport->load_flag |= FC_UNLOADING;
7374 spin_unlock_irq(&phba->hbalock);
7375
7376 /* Free the HBA sysfs attributes */
7377 lpfc_free_sysfs_attr(vport);
7378
7379 /* Release all the vports against this physical port */
7380 vports = lpfc_create_vport_work_array(phba);
7381 if (vports != NULL)
7382 for (i = 1; i <= phba->max_vports && vports[i] != NULL; i++)
7383 fc_vport_terminate(vports[i]->fc_vport);
7384 lpfc_destroy_vport_work_array(phba, vports);
7385
7386 /* Remove FC host and then SCSI host with the physical port */
7387 fc_remove_host(shost);
7388 scsi_remove_host(shost);
7389
7390 /* Perform cleanup on the physical port */
7391 lpfc_cleanup(vport);
7392
7393 /*
7394 * Bring down the SLI Layer. This step disables all interrupts,
7395 * clears the rings, discards all mailbox commands, and resets
7396 * the HBA FCoE function.
7397 */
7398 lpfc_debugfs_terminate(vport);
7399 lpfc_sli4_hba_unset(phba);
7400
7401 spin_lock_irq(&phba->hbalock);
7402 list_del_init(&vport->listentry);
7403 spin_unlock_irq(&phba->hbalock);
7404
7405 /* Call scsi_free before lpfc_sli4_driver_resource_unset since scsi
7406 * buffers are released to their corresponding pools here.
7407 */
7408 lpfc_scsi_free(phba);
7409 lpfc_sli4_driver_resource_unset(phba);
7410
7411 /* Unmap adapter Control and Doorbell registers */
7412 lpfc_sli4_pci_mem_unset(phba);
7413
7414 /* Release PCI resources and disable device's PCI function */
7415 scsi_host_put(shost);
7416 lpfc_disable_pci_dev(phba);
7417
7418 /* Finally, free the driver's device data structure */
7419 lpfc_hba_free(phba);
7420
7421 return;
7422}
7423
7424/**
7425 * lpfc_pci_suspend_one_s4 - PCI func to suspend SLI-4 device for power mgmnt
7426 * @pdev: pointer to PCI device
7427 * @msg: power management message
7428 *
7429 * This routine is called from the kernel's PCI subsystem to support system
7430 * Power Management (PM) to device with SLI-4 interface spec. When PM invokes
7431 * this method, it quiesces the device by stopping the driver's worker
7432 * thread for the device, turning off device's interrupt and DMA, and bring
7433 * the device offline. Note that as the driver implements the minimum PM
7434 * requirements to a power-aware driver's PM support for suspend/resume -- all
7435 * the possible PM messages (SUSPEND, HIBERNATE, FREEZE) to the suspend()
7436 * method call will be treated as SUSPEND and the driver will fully
7437 * reinitialize its device during resume() method call, the driver will set
7438 * device to PCI_D3hot state in PCI config space instead of setting it
7439 * according to the @msg provided by the PM.
7440 *
7441 * Return code
7442 * 0 - driver suspended the device
7443 * Error otherwise
7444 **/
7445static int
7446lpfc_pci_suspend_one_s4(struct pci_dev *pdev, pm_message_t msg)
7447{
7448 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7449 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7450
7451 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7452 "0298 PCI device Power Management suspend.\n");
7453
7454 /* Bring down the device */
7455 lpfc_offline_prep(phba);
7456 lpfc_offline(phba);
7457 kthread_stop(phba->worker_thread);
7458
7459 /* Disable interrupt from device */
7460 lpfc_sli4_disable_intr(phba);
7461
7462 /* Save device state to PCI config space */
7463 pci_save_state(pdev);
7464 pci_set_power_state(pdev, PCI_D3hot);
7465
7466 return 0;
7467}
7468
7469/**
7470 * lpfc_pci_resume_one_s4 - PCI func to resume SLI-4 device for power mgmnt
7471 * @pdev: pointer to PCI device
7472 *
7473 * This routine is called from the kernel's PCI subsystem to support system
7474 * Power Management (PM) to device with SLI-4 interface spac. When PM invokes
7475 * this method, it restores the device's PCI config space state and fully
7476 * reinitializes the device and brings it online. Note that as the driver
7477 * implements the minimum PM requirements to a power-aware driver's PM for
7478 * suspend/resume -- all the possible PM messages (SUSPEND, HIBERNATE, FREEZE)
7479 * to the suspend() method call will be treated as SUSPEND and the driver
7480 * will fully reinitialize its device during resume() method call, the device
7481 * will be set to PCI_D0 directly in PCI config space before restoring the
7482 * state.
7483 *
7484 * Return code
7485 * 0 - driver suspended the device
7486 * Error otherwise
7487 **/
7488static int
7489lpfc_pci_resume_one_s4(struct pci_dev *pdev)
7490{
7491 struct Scsi_Host *shost = pci_get_drvdata(pdev);
7492 struct lpfc_hba *phba = ((struct lpfc_vport *)shost->hostdata)->phba;
7493 uint32_t intr_mode;
7494 int error;
7495
7496 lpfc_printf_log(phba, KERN_INFO, LOG_INIT,
7497 "0292 PCI device Power Management resume.\n");
7498
7499 /* Restore device state from PCI config space */
7500 pci_set_power_state(pdev, PCI_D0);
7501 pci_restore_state(pdev);
7502 if (pdev->is_busmaster)
7503 pci_set_master(pdev);
7504
7505 /* Startup the kernel thread for this host adapter. */
7506 phba->worker_thread = kthread_run(lpfc_do_work, phba,
7507 "lpfc_worker_%d", phba->brd_no);
7508 if (IS_ERR(phba->worker_thread)) {
7509 error = PTR_ERR(phba->worker_thread);
7510 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7511 "0293 PM resume failed to start worker "
7512 "thread: error=x%x.\n", error);
7513 return error;
7514 }
7515
7516 /* Configure and enable interrupt */
7517 intr_mode = lpfc_sli4_enable_intr(phba, phba->intr_mode);
7518 if (intr_mode == LPFC_INTR_ERROR) {
7519 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
7520 "0294 PM resume Failed to enable interrupt\n");
7521 return -EIO;
7522 } else
7523 phba->intr_mode = intr_mode;
7524
7525 /* Restart HBA and bring it online */
7526 lpfc_sli_brdrestart(phba);
7527 lpfc_online(phba);
7528
7529 /* Log the current active interrupt mode */
7530 lpfc_log_intr_mode(phba, phba->intr_mode);
7531
7532 return 0;
7533}
7534
7535/**
7536 * lpfc_io_error_detected_s4 - Method for handling PCI I/O error to SLI-4 device
7537 * @pdev: pointer to PCI device.
7538 * @state: the current PCI connection state.
7539 *
7540 * This routine is called from the PCI subsystem for error handling to device
7541 * with SLI-4 interface spec. This function is called by the PCI subsystem
7542 * after a PCI bus error affecting this device has been detected. When this
7543 * function is invoked, it will need to stop all the I/Os and interrupt(s)
7544 * to the device. Once that is done, it will return PCI_ERS_RESULT_NEED_RESET
7545 * for the PCI subsystem to perform proper recovery as desired.
7546 *
7547 * Return codes
7548 * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery
7549 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7550 **/
7551static pci_ers_result_t
7552lpfc_io_error_detected_s4(struct pci_dev *pdev, pci_channel_state_t state)
7553{
7554 return PCI_ERS_RESULT_NEED_RESET;
7555}
7556
7557/**
7558 * lpfc_io_slot_reset_s4 - Method for restart PCI SLI-4 device from scratch
7559 * @pdev: pointer to PCI device.
7560 *
7561 * This routine is called from the PCI subsystem for error handling to device
7562 * with SLI-4 interface spec. It is called after PCI bus has been reset to
7563 * restart the PCI card from scratch, as if from a cold-boot. During the
7564 * PCI subsystem error recovery, after the driver returns
7565 * PCI_ERS_RESULT_NEED_RESET, the PCI subsystem will perform proper error
7566 * recovery and then call this routine before calling the .resume method to
7567 * recover the device. This function will initialize the HBA device, enable
7568 * the interrupt, but it will just put the HBA to offline state without
7569 * passing any I/O traffic.
7570 *
7571 * Return codes
7572 * PCI_ERS_RESULT_RECOVERED - the device has been recovered
7573 * PCI_ERS_RESULT_DISCONNECT - device could not be recovered
7574 */
7575static pci_ers_result_t
7576lpfc_io_slot_reset_s4(struct pci_dev *pdev)
7577{
7578 return PCI_ERS_RESULT_RECOVERED;
7579}
7580
7581/**
7582 * lpfc_io_resume_s4 - Method for resuming PCI I/O operation to SLI-4 device
7583 * @pdev: pointer to PCI device
7584 *
7585 * This routine is called from the PCI subsystem for error handling to device
7586 * with SLI-4 interface spec. It is called when kernel error recovery tells
7587 * the lpfc driver that it is ok to resume normal PCI operation after PCI bus
7588 * error recovery. After this call, traffic can start to flow from this device
7589 * again.
7590 **/
7591static void
7592lpfc_io_resume_s4(struct pci_dev *pdev)
7593{
7594 return;
7595}
7596
7597/**
4130 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem 7598 * lpfc_pci_probe_one - lpfc PCI probe func to reg dev to PCI subsystem
4131 * @pdev: pointer to PCI device 7599 * @pdev: pointer to PCI device
4132 * @pid: pointer to PCI device identifier 7600 * @pid: pointer to PCI device identifier
@@ -4154,6 +7622,10 @@ lpfc_pci_probe_one(struct pci_dev *pdev, const struct pci_device_id *pid)
4154 return -ENODEV; 7622 return -ENODEV;
4155 7623
4156 switch (dev_id) { 7624 switch (dev_id) {
7625 case PCI_DEVICE_ID_TIGERSHARK:
7626 case PCI_DEVICE_ID_TIGERSHARK_S:
7627 rc = lpfc_pci_probe_one_s4(pdev, pid);
7628 break;
4157 default: 7629 default:
4158 rc = lpfc_pci_probe_one_s3(pdev, pid); 7630 rc = lpfc_pci_probe_one_s3(pdev, pid);
4159 break; 7631 break;
@@ -4181,6 +7653,9 @@ lpfc_pci_remove_one(struct pci_dev *pdev)
4181 case LPFC_PCI_DEV_LP: 7653 case LPFC_PCI_DEV_LP:
4182 lpfc_pci_remove_one_s3(pdev); 7654 lpfc_pci_remove_one_s3(pdev);
4183 break; 7655 break;
7656 case LPFC_PCI_DEV_OC:
7657 lpfc_pci_remove_one_s4(pdev);
7658 break;
4184 default: 7659 default:
4185 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7660 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4186 "1424 Invalid PCI device group: 0x%x\n", 7661 "1424 Invalid PCI device group: 0x%x\n",
@@ -4215,6 +7690,9 @@ lpfc_pci_suspend_one(struct pci_dev *pdev, pm_message_t msg)
4215 case LPFC_PCI_DEV_LP: 7690 case LPFC_PCI_DEV_LP:
4216 rc = lpfc_pci_suspend_one_s3(pdev, msg); 7691 rc = lpfc_pci_suspend_one_s3(pdev, msg);
4217 break; 7692 break;
7693 case LPFC_PCI_DEV_OC:
7694 rc = lpfc_pci_suspend_one_s4(pdev, msg);
7695 break;
4218 default: 7696 default:
4219 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7697 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4220 "1425 Invalid PCI device group: 0x%x\n", 7698 "1425 Invalid PCI device group: 0x%x\n",
@@ -4248,6 +7726,9 @@ lpfc_pci_resume_one(struct pci_dev *pdev)
4248 case LPFC_PCI_DEV_LP: 7726 case LPFC_PCI_DEV_LP:
4249 rc = lpfc_pci_resume_one_s3(pdev); 7727 rc = lpfc_pci_resume_one_s3(pdev);
4250 break; 7728 break;
7729 case LPFC_PCI_DEV_OC:
7730 rc = lpfc_pci_resume_one_s4(pdev);
7731 break;
4251 default: 7732 default:
4252 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7733 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4253 "1426 Invalid PCI device group: 0x%x\n", 7734 "1426 Invalid PCI device group: 0x%x\n",
@@ -4283,6 +7764,9 @@ lpfc_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4283 case LPFC_PCI_DEV_LP: 7764 case LPFC_PCI_DEV_LP:
4284 rc = lpfc_io_error_detected_s3(pdev, state); 7765 rc = lpfc_io_error_detected_s3(pdev, state);
4285 break; 7766 break;
7767 case LPFC_PCI_DEV_OC:
7768 rc = lpfc_io_error_detected_s4(pdev, state);
7769 break;
4286 default: 7770 default:
4287 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7771 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4288 "1427 Invalid PCI device group: 0x%x\n", 7772 "1427 Invalid PCI device group: 0x%x\n",
@@ -4317,6 +7801,9 @@ lpfc_io_slot_reset(struct pci_dev *pdev)
4317 case LPFC_PCI_DEV_LP: 7801 case LPFC_PCI_DEV_LP:
4318 rc = lpfc_io_slot_reset_s3(pdev); 7802 rc = lpfc_io_slot_reset_s3(pdev);
4319 break; 7803 break;
7804 case LPFC_PCI_DEV_OC:
7805 rc = lpfc_io_slot_reset_s4(pdev);
7806 break;
4320 default: 7807 default:
4321 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7808 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4322 "1428 Invalid PCI device group: 0x%x\n", 7809 "1428 Invalid PCI device group: 0x%x\n",
@@ -4346,6 +7833,9 @@ lpfc_io_resume(struct pci_dev *pdev)
4346 case LPFC_PCI_DEV_LP: 7833 case LPFC_PCI_DEV_LP:
4347 lpfc_io_resume_s3(pdev); 7834 lpfc_io_resume_s3(pdev);
4348 break; 7835 break;
7836 case LPFC_PCI_DEV_OC:
7837 lpfc_io_resume_s4(pdev);
7838 break;
4349 default: 7839 default:
4350 lpfc_printf_log(phba, KERN_ERR, LOG_INIT, 7840 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
4351 "1429 Invalid PCI device group: 0x%x\n", 7841 "1429 Invalid PCI device group: 0x%x\n",