182527734SSukumar Swaminathan /*
282527734SSukumar Swaminathan  * CDDL HEADER START
382527734SSukumar Swaminathan  *
482527734SSukumar Swaminathan  * The contents of this file are subject to the terms of the
582527734SSukumar Swaminathan  * Common Development and Distribution License (the "License").
682527734SSukumar Swaminathan  * You may not use this file except in compliance with the License.
782527734SSukumar Swaminathan  *
88f23e9faSHans Rosenfeld  * You can obtain a copy of the license at
98f23e9faSHans Rosenfeld  * http://www.opensource.org/licenses/cddl1.txt.
1082527734SSukumar Swaminathan  * See the License for the specific language governing permissions
1182527734SSukumar Swaminathan  * and limitations under the License.
1282527734SSukumar Swaminathan  *
1382527734SSukumar Swaminathan  * When distributing Covered Code, include this CDDL HEADER in each
1482527734SSukumar Swaminathan  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1582527734SSukumar Swaminathan  * If applicable, add the following below this CDDL HEADER, with the
1682527734SSukumar Swaminathan  * fields enclosed by brackets "[]" replaced with your own identifying
1782527734SSukumar Swaminathan  * information: Portions Copyright [yyyy] [name of copyright owner]
1882527734SSukumar Swaminathan  *
1982527734SSukumar Swaminathan  * CDDL HEADER END
2082527734SSukumar Swaminathan  */
2182527734SSukumar Swaminathan 
2282527734SSukumar Swaminathan /*
238f23e9faSHans Rosenfeld  * Copyright (c) 2004-2012 Emulex. All rights reserved.
2482527734SSukumar Swaminathan  * Use is subject to license terms.
25*a3170057SPaul Winder  * Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
26*a3170057SPaul Winder  * Copyright 2020 RackTop Systems, Inc.
2782527734SSukumar Swaminathan  */
2882527734SSukumar Swaminathan 
2982527734SSukumar Swaminathan #include <emlxs.h>
3082527734SSukumar Swaminathan 
318f23e9faSHans Rosenfeld 
3282527734SSukumar Swaminathan /* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
3382527734SSukumar Swaminathan EMLXS_MSG_DEF(EMLXS_SLI4_C);
3482527734SSukumar Swaminathan 
358f23e9faSHans Rosenfeld static int		emlxs_sli4_init_extents(emlxs_hba_t *hba,
368f23e9faSHans Rosenfeld 				MAILBOXQ *mbq);
378f23e9faSHans Rosenfeld static uint32_t		emlxs_sli4_read_status(emlxs_hba_t *hba);
388f23e9faSHans Rosenfeld 
398f23e9faSHans Rosenfeld static int		emlxs_init_bootstrap_mb(emlxs_hba_t *hba);
408f23e9faSHans Rosenfeld 
418f23e9faSHans Rosenfeld static uint32_t		emlxs_sli4_read_sema(emlxs_hba_t *hba);
428f23e9faSHans Rosenfeld 
438f23e9faSHans Rosenfeld static uint32_t		emlxs_sli4_read_mbdb(emlxs_hba_t *hba);
448f23e9faSHans Rosenfeld 
45*a3170057SPaul Winder static void		emlxs_sli4_write_mbdb(emlxs_hba_t *hba, uint64_t phys,
46*a3170057SPaul Winder 				boolean_t high);
478f23e9faSHans Rosenfeld 
48*a3170057SPaul Winder static void		emlxs_sli4_write_wqdb(emlxs_hba_t *hba, uint16_t qid,
49*a3170057SPaul Winder 				uint_t posted, uint_t index);
508f23e9faSHans Rosenfeld 
51*a3170057SPaul Winder static void		emlxs_sli4_write_mqdb(emlxs_hba_t *hba, uint16_t qid,
52*a3170057SPaul Winder 				uint_t count);
538f23e9faSHans Rosenfeld 
54*a3170057SPaul Winder static void		emlxs_sli4_write_rqdb(emlxs_hba_t *hba, uint16_t qid,
55*a3170057SPaul Winder 				uint_t count);
568f23e9faSHans Rosenfeld 
57*a3170057SPaul Winder static void		emlxs_sli4_write_eqdb(emlxs_hba_t *hba, uint16_t qid,
58*a3170057SPaul Winder 				uint32_t count, boolean_t arm);
59*a3170057SPaul Winder static void		emlxs_sli4_write_cqdb(emlxs_hba_t *hba, uint16_t qid,
60*a3170057SPaul Winder 				uint32_t count, boolean_t arm);
618f23e9faSHans Rosenfeld 
6282527734SSukumar Swaminathan static int		emlxs_sli4_create_queues(emlxs_hba_t *hba,
6382527734SSukumar Swaminathan 				MAILBOXQ *mbq);
6482527734SSukumar Swaminathan static int		emlxs_sli4_post_hdr_tmplates(emlxs_hba_t *hba,
6582527734SSukumar Swaminathan 				MAILBOXQ *mbq);
6682527734SSukumar Swaminathan static int		emlxs_sli4_post_sgl_pages(emlxs_hba_t *hba,
6782527734SSukumar Swaminathan 				MAILBOXQ *mbq);
6882527734SSukumar Swaminathan 
69a9800bebSGarrett D'Amore static int		emlxs_sli4_read_eq(emlxs_hba_t *hba, EQ_DESC_t *eq);
7082527734SSukumar Swaminathan 
7182527734SSukumar Swaminathan static int		emlxs_sli4_map_hdw(emlxs_hba_t *hba);
7282527734SSukumar Swaminathan 
7382527734SSukumar Swaminathan static void		emlxs_sli4_unmap_hdw(emlxs_hba_t *hba);
7482527734SSukumar Swaminathan 
7582527734SSukumar Swaminathan static int32_t		emlxs_sli4_online(emlxs_hba_t *hba);
7682527734SSukumar Swaminathan 
778f23e9faSHans Rosenfeld static void		emlxs_sli4_offline(emlxs_hba_t *hba,
788f23e9faSHans Rosenfeld 				uint32_t reset_requested);
7982527734SSukumar Swaminathan 
8082527734SSukumar Swaminathan static uint32_t		emlxs_sli4_hba_reset(emlxs_hba_t *hba, uint32_t restart,
8182527734SSukumar Swaminathan 				uint32_t skip_post, uint32_t quiesce);
8282527734SSukumar Swaminathan static void		emlxs_sli4_hba_kill(emlxs_hba_t *hba);
8382527734SSukumar Swaminathan 
8482527734SSukumar Swaminathan static uint32_t		emlxs_sli4_hba_init(emlxs_hba_t *hba);
8582527734SSukumar Swaminathan 
8682527734SSukumar Swaminathan static uint32_t		emlxs_sli4_bde_setup(emlxs_port_t *port,
8782527734SSukumar Swaminathan 				emlxs_buf_t *sbp);
88a9800bebSGarrett D'Amore 
8982527734SSukumar Swaminathan static void		emlxs_sli4_issue_iocb_cmd(emlxs_hba_t *hba,
90a9800bebSGarrett D'Amore 				CHANNEL *cp, IOCBQ *iocb_cmd);
9182527734SSukumar Swaminathan static uint32_t		emlxs_sli4_issue_mbox_cmd(emlxs_hba_t *hba,
9282527734SSukumar Swaminathan 				MAILBOXQ *mbq, int32_t flg, uint32_t tmo);
9382527734SSukumar Swaminathan static uint32_t		emlxs_sli4_issue_mbox_cmd4quiesce(emlxs_hba_t *hba,
9482527734SSukumar Swaminathan 				MAILBOXQ *mbq, int32_t flg, uint32_t tmo);
9582527734SSukumar Swaminathan #ifdef SFCT_SUPPORT
9682527734SSukumar Swaminathan static uint32_t		emlxs_sli4_prep_fct_iocb(emlxs_port_t *port,
9782527734SSukumar Swaminathan 				emlxs_buf_t *cmd_sbp, int channel);
988f23e9faSHans Rosenfeld static uint32_t		emlxs_sli4_fct_bde_setup(emlxs_port_t *port,
998f23e9faSHans Rosenfeld 				emlxs_buf_t *sbp);
10082527734SSukumar Swaminathan #endif /* SFCT_SUPPORT */
10182527734SSukumar Swaminathan 
10282527734SSukumar Swaminathan static uint32_t		emlxs_sli4_prep_fcp_iocb(emlxs_port_t *port,
10382527734SSukumar Swaminathan 				emlxs_buf_t *sbp, int ring);
10482527734SSukumar Swaminathan static uint32_t		emlxs_sli4_prep_ip_iocb(emlxs_port_t *port,
10582527734SSukumar Swaminathan 				emlxs_buf_t *sbp);
10682527734SSukumar Swaminathan static uint32_t		emlxs_sli4_prep_els_iocb(emlxs_port_t *port,
10782527734SSukumar Swaminathan 				emlxs_buf_t *sbp);
10882527734SSukumar Swaminathan static uint32_t		emlxs_sli4_prep_ct_iocb(emlxs_port_t *port,
10982527734SSukumar Swaminathan 				emlxs_buf_t *sbp);
1108f23e9faSHans Rosenfeld static void		emlxs_sli4_poll_intr(emlxs_hba_t *hba);
11182527734SSukumar Swaminathan static int32_t		emlxs_sli4_intx_intr(char *arg);
11282527734SSukumar Swaminathan 
11382527734SSukumar Swaminathan #ifdef MSI_SUPPORT
11482527734SSukumar Swaminathan static uint32_t		emlxs_sli4_msi_intr(char *arg1, char *arg2);
11582527734SSukumar Swaminathan #endif /* MSI_SUPPORT */
11682527734SSukumar Swaminathan 
11782527734SSukumar Swaminathan static void		emlxs_sli4_resource_free(emlxs_hba_t *hba);
11882527734SSukumar Swaminathan 
11982527734SSukumar Swaminathan static int		emlxs_sli4_resource_alloc(emlxs_hba_t *hba);
1208f23e9faSHans Rosenfeld extern void		emlxs_sli4_zero_queue_stat(emlxs_hba_t *hba);
12182527734SSukumar Swaminathan 
1228f23e9faSHans Rosenfeld static XRIobj_t		*emlxs_sli4_alloc_xri(emlxs_port_t *port,
1238f23e9faSHans Rosenfeld 				emlxs_buf_t *sbp, RPIobj_t *rpip,
1248f23e9faSHans Rosenfeld 				uint32_t type);
12582527734SSukumar Swaminathan static void		emlxs_sli4_enable_intr(emlxs_hba_t *hba);
12682527734SSukumar Swaminathan 
12782527734SSukumar Swaminathan static void		emlxs_sli4_disable_intr(emlxs_hba_t *hba, uint32_t att);
12882527734SSukumar Swaminathan 
1298f23e9faSHans Rosenfeld static void		emlxs_sli4_timer(emlxs_hba_t *hba);
13082527734SSukumar Swaminathan 
13182527734SSukumar Swaminathan static void		emlxs_sli4_timer_check_mbox(emlxs_hba_t *hba);
13282527734SSukumar Swaminathan 
133a9800bebSGarrett D'Amore static void		emlxs_sli4_poll_erratt(emlxs_hba_t *hba);
13482527734SSukumar Swaminathan 
135*a3170057SPaul Winder extern XRIobj_t		*emlxs_sli4_reserve_xri(emlxs_port_t *port,
1368f23e9faSHans Rosenfeld 				RPIobj_t *rpip, uint32_t type, uint16_t rx_id);
13782527734SSukumar Swaminathan static int		emlxs_check_hdw_ready(emlxs_hba_t *);
13882527734SSukumar Swaminathan 
1398f23e9faSHans Rosenfeld static uint32_t		emlxs_sli4_reg_did(emlxs_port_t *port,
1408f23e9faSHans Rosenfeld 				uint32_t did, SERV_PARM *param,
1418f23e9faSHans Rosenfeld 				emlxs_buf_t *sbp, fc_unsol_buf_t *ubp,
1428f23e9faSHans Rosenfeld 				IOCBQ *iocbq);
1438f23e9faSHans Rosenfeld 
1448f23e9faSHans Rosenfeld static uint32_t		emlxs_sli4_unreg_node(emlxs_port_t *port,
1458f23e9faSHans Rosenfeld 				emlxs_node_t *node, emlxs_buf_t *sbp,
1468f23e9faSHans Rosenfeld 				fc_unsol_buf_t *ubp, IOCBQ *iocbq);
1478f23e9faSHans Rosenfeld 
1488f23e9faSHans Rosenfeld static void		emlxs_sli4_handle_fc_link_att(emlxs_hba_t *hba,
1498f23e9faSHans Rosenfeld 				CQE_ASYNC_t *cqe);
1508f23e9faSHans Rosenfeld static void		emlxs_sli4_handle_fcoe_link_event(emlxs_hba_t *hba,
1518f23e9faSHans Rosenfeld 				CQE_ASYNC_t *cqe);
1528f23e9faSHans Rosenfeld 
1538f23e9faSHans Rosenfeld 
1548f23e9faSHans Rosenfeld static uint16_t		emlxs_sli4_rqid_to_index(emlxs_hba_t *hba,
1558f23e9faSHans Rosenfeld 				uint16_t rqid);
1568f23e9faSHans Rosenfeld static uint16_t		emlxs_sli4_wqid_to_index(emlxs_hba_t *hba,
1578f23e9faSHans Rosenfeld 				uint16_t wqid);
1588f23e9faSHans Rosenfeld static uint16_t		emlxs_sli4_cqid_to_index(emlxs_hba_t *hba,
1598f23e9faSHans Rosenfeld 				uint16_t cqid);
160a9800bebSGarrett D'Amore 
16182527734SSukumar Swaminathan /* Define SLI4 API functions */
16282527734SSukumar Swaminathan emlxs_sli_api_t emlxs_sli4_api = {
16382527734SSukumar Swaminathan 	emlxs_sli4_map_hdw,
16482527734SSukumar Swaminathan 	emlxs_sli4_unmap_hdw,
16582527734SSukumar Swaminathan 	emlxs_sli4_online,
16682527734SSukumar Swaminathan 	emlxs_sli4_offline,
16782527734SSukumar Swaminathan 	emlxs_sli4_hba_reset,
16882527734SSukumar Swaminathan 	emlxs_sli4_hba_kill,
16982527734SSukumar Swaminathan 	emlxs_sli4_issue_iocb_cmd,
17082527734SSukumar Swaminathan 	emlxs_sli4_issue_mbox_cmd,
17182527734SSukumar Swaminathan #ifdef SFCT_SUPPORT
17282527734SSukumar Swaminathan 	emlxs_sli4_prep_fct_iocb,
17382527734SSukumar Swaminathan #else
17482527734SSukumar Swaminathan 	NULL,
17582527734SSukumar Swaminathan #endif /* SFCT_SUPPORT */
17682527734SSukumar Swaminathan 	emlxs_sli4_prep_fcp_iocb,
17782527734SSukumar Swaminathan 	emlxs_sli4_prep_ip_iocb,
17882527734SSukumar Swaminathan 	emlxs_sli4_prep_els_iocb,
17982527734SSukumar Swaminathan 	emlxs_sli4_prep_ct_iocb,
18082527734SSukumar Swaminathan 	emlxs_sli4_poll_intr,
18182527734SSukumar Swaminathan 	emlxs_sli4_intx_intr,
18282527734SSukumar Swaminathan 	emlxs_sli4_msi_intr,
18382527734SSukumar Swaminathan 	emlxs_sli4_disable_intr,
18482527734SSukumar Swaminathan 	emlxs_sli4_timer,
1858f23e9faSHans Rosenfeld 	emlxs_sli4_poll_erratt,
1868f23e9faSHans Rosenfeld 	emlxs_sli4_reg_did,
1878f23e9faSHans Rosenfeld 	emlxs_sli4_unreg_node
18882527734SSukumar Swaminathan };
18982527734SSukumar Swaminathan 
19082527734SSukumar Swaminathan 
19182527734SSukumar Swaminathan /* ************************************************************************** */
19282527734SSukumar Swaminathan 
1938f23e9faSHans Rosenfeld static void
emlxs_sli4_set_default_params(emlxs_hba_t * hba)1948f23e9faSHans Rosenfeld emlxs_sli4_set_default_params(emlxs_hba_t *hba)
1958f23e9faSHans Rosenfeld {
1968f23e9faSHans Rosenfeld 	emlxs_port_t *port = &PPORT;
1978f23e9faSHans Rosenfeld 
1988f23e9faSHans Rosenfeld 	bzero((char *)&hba->sli.sli4.param, sizeof (sli_params_t));
1998f23e9faSHans Rosenfeld 
2008f23e9faSHans Rosenfeld 	hba->sli.sli4.param.ProtocolType = 0x3; /* FC/FCoE */
2018f23e9faSHans Rosenfeld 
2028f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SliHint2 = 0;
2038f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SliHint1 = 0;
2048f23e9faSHans Rosenfeld 	hba->sli.sli4.param.IfType = 0;
2058f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SliFamily = 0;
2068f23e9faSHans Rosenfeld 	hba->sli.sli4.param.Revision = 0x4; /* SLI4 */
2078f23e9faSHans Rosenfeld 	hba->sli.sli4.param.FT = 0;
2088f23e9faSHans Rosenfeld 
2098f23e9faSHans Rosenfeld 	hba->sli.sli4.param.EqeCntMethod = 0x1; /* Bit pattern */
2108f23e9faSHans Rosenfeld 	hba->sli.sli4.param.EqPageSize = 0x1; /* 4096 */
2118f23e9faSHans Rosenfeld 	hba->sli.sli4.param.EqeSize = 0x1; /* 4 byte */
2128f23e9faSHans Rosenfeld 	hba->sli.sli4.param.EqPageCnt = 8;
2138f23e9faSHans Rosenfeld 	hba->sli.sli4.param.EqeCntMask = 0x1F; /* 256-4096 elements */
2148f23e9faSHans Rosenfeld 
2158f23e9faSHans Rosenfeld 	hba->sli.sli4.param.CqeCntMethod = 0x1; /* Bit pattern */
2168f23e9faSHans Rosenfeld 	hba->sli.sli4.param.CqPageSize = 0x1; /* 4096 */
2178f23e9faSHans Rosenfeld 	hba->sli.sli4.param.CQV = 0;
2188f23e9faSHans Rosenfeld 	hba->sli.sli4.param.CqeSize = 0x3; /* 16 byte */
2198f23e9faSHans Rosenfeld 	hba->sli.sli4.param.CqPageCnt = 4;
2208f23e9faSHans Rosenfeld 	hba->sli.sli4.param.CqeCntMask = 0x70; /* 256-1024 elements */
2218f23e9faSHans Rosenfeld 
2228f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MqeCntMethod = 0x1; /* Bit pattern */
2238f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MqPageSize = 0x1; /* 4096 */
2248f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MQV = 0;
2258f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MqPageCnt = 8;
2268f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MqeCntMask = 0x0F; /* 16-128 elements */
2278f23e9faSHans Rosenfeld 
2288f23e9faSHans Rosenfeld 	hba->sli.sli4.param.WqeCntMethod = 0; /* Page Count */
2298f23e9faSHans Rosenfeld 	hba->sli.sli4.param.WqPageSize = 0x1; /* 4096 */
2308f23e9faSHans Rosenfeld 	hba->sli.sli4.param.WQV = 0;
2318f23e9faSHans Rosenfeld 	hba->sli.sli4.param.WqeSize = 0x5; /* 64 byte */
2328f23e9faSHans Rosenfeld 	hba->sli.sli4.param.WqPageCnt = 4;
2338f23e9faSHans Rosenfeld 	hba->sli.sli4.param.WqeCntMask = 0x10; /* 256 elements */
2348f23e9faSHans Rosenfeld 
2358f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RqeCntMethod = 0; /* Page Count */
2368f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RqPageSize = 0x1; /* 4096 */
2378f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RQV = 0;
2388f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RqeSize = 0x2; /* 8 byte */
2398f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RqPageCnt = 8;
2408f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RqDbWin = 1;
2418f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RqeCntMask = 0x100; /* 4096 elements */
2428f23e9faSHans Rosenfeld 
2438f23e9faSHans Rosenfeld 	hba->sli.sli4.param.Loopback = 0xf; /* unsupported */
2448f23e9faSHans Rosenfeld 	hba->sli.sli4.param.PHWQ = 0;
2458f23e9faSHans Rosenfeld 	hba->sli.sli4.param.PHON = 0;
2468f23e9faSHans Rosenfeld 	hba->sli.sli4.param.TRIR = 0;
2478f23e9faSHans Rosenfeld 	hba->sli.sli4.param.TRTY = 0;
2488f23e9faSHans Rosenfeld 	hba->sli.sli4.param.TCCA = 0;
2498f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MWQE = 0;
2508f23e9faSHans Rosenfeld 	hba->sli.sli4.param.ASSI = 0;
2518f23e9faSHans Rosenfeld 	hba->sli.sli4.param.TERP = 0;
2528f23e9faSHans Rosenfeld 	hba->sli.sli4.param.TGT  = 0;
2538f23e9faSHans Rosenfeld 	hba->sli.sli4.param.AREG = 0;
2548f23e9faSHans Rosenfeld 	hba->sli.sli4.param.FBRR = 0;
2558f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SGLR = 1;
2568f23e9faSHans Rosenfeld 	hba->sli.sli4.param.HDRR = 1;
2578f23e9faSHans Rosenfeld 	hba->sli.sli4.param.EXT  = 0;
2588f23e9faSHans Rosenfeld 	hba->sli.sli4.param.FCOE = 1;
2598f23e9faSHans Rosenfeld 
2608f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SgeLength = (64 * 1024);
2618f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SglAlign = 0x7 /* 4096 */;
2628f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SglPageSize = 0x1; /* 4096 */
2638f23e9faSHans Rosenfeld 	hba->sli.sli4.param.SglPageCnt = 2;
2648f23e9faSHans Rosenfeld 
2658f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MinRqSize = 128;
2668f23e9faSHans Rosenfeld 	hba->sli.sli4.param.MaxRqSize = 2048;
2678f23e9faSHans Rosenfeld 
2688f23e9faSHans Rosenfeld 	hba->sli.sli4.param.RPIMax = 0x3ff;
2698f23e9faSHans Rosenfeld 	hba->sli.sli4.param.XRIMax = 0x3ff;
2708f23e9faSHans Rosenfeld 	hba->sli.sli4.param.VFIMax = 0xff;
2718f23e9faSHans Rosenfeld 	hba->sli.sli4.param.VPIMax = 0xff;
2728f23e9faSHans Rosenfeld 
2738f23e9faSHans Rosenfeld 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_init_debug_msg,
2748f23e9faSHans Rosenfeld 	    "Default SLI4 parameters set.");
2758f23e9faSHans Rosenfeld 
2768f23e9faSHans Rosenfeld } /* emlxs_sli4_set_default_params() */
2778f23e9faSHans Rosenfeld 
27882527734SSukumar Swaminathan 
27982527734SSukumar Swaminathan /*
28082527734SSukumar Swaminathan  * emlxs_sli4_online()
28182527734SSukumar Swaminathan  *
28282527734SSukumar Swaminathan  * This routine will start initialization of the SLI4 HBA.
28382527734SSukumar Swaminathan  */
28482527734SSukumar Swaminathan static int32_t
emlxs_sli4_online(emlxs_hba_t * hba)28582527734SSukumar Swaminathan emlxs_sli4_online(emlxs_hba_t *hba)
28682527734SSukumar Swaminathan {
28782527734SSukumar Swaminathan 	emlxs_port_t *port = &PPORT;
28882527734SSukumar Swaminathan 	emlxs_config_t *cfg;
28982527734SSukumar Swaminathan 	emlxs_vpd_t *vpd;
29082527734SSukumar Swaminathan 	MAILBOXQ *mbq = NULL;
29182527734SSukumar Swaminathan 	MAILBOX4 *mb  = NULL;
29282527734SSukumar Swaminathan 	MATCHMAP *mp  = NULL;
29382527734SSukumar Swaminathan 	uint32_t i;
29482527734SSukumar Swaminathan 	uint32_t j;
29582527734SSukumar Swaminathan 	uint32_t rval = 0;
29682527734SSukumar Swaminathan 	uint8_t *vpd_data;
29782527734SSukumar Swaminathan 	uint32_t sli_mode;
29882527734SSukumar Swaminathan 	uint8_t *outptr;
29982527734SSukumar Swaminathan 	uint32_t status;
30082527734SSukumar Swaminathan 	uint32_t fw_check;
3016a573d82SSukumar Swaminathan 	uint32_t kern_update = 0;
30282527734SSukumar Swaminathan 	emlxs_firmware_t hba_fw;
30382527734SSukumar Swaminathan 	emlxs_firmware_t *fw;
304a9800bebSGarrett D'Amore 	uint16_t ssvid;
3058f23e9faSHans Rosenfeld 	char buf[64];
30682527734SSukumar Swaminathan 
30782527734SSukumar Swaminathan 	cfg = &CFG;
30882527734SSukumar Swaminathan 	vpd = &VPD;
30982527734SSukumar Swaminathan 
31082527734SSukumar Swaminathan 	sli_mode = EMLXS_HBA_SLI4_MODE;
31182527734SSukumar Swaminathan 	hba->sli_mode = sli_mode;
31282527734SSukumar Swaminathan 
31382527734SSukumar Swaminathan 	/* Set the fw_check flag */
31482527734SSukumar Swaminathan 	fw_check = cfg[CFG_FW_CHECK].current;
31582527734SSukumar Swaminathan 
3166a573d82SSukumar Swaminathan 	if ((fw_check & 0x04) ||
3176a573d82SSukumar Swaminathan 	    (hba->fw_flag & FW_UPDATE_KERNEL)) {
3186a573d82SSukumar Swaminathan 		kern_update = 1;
3196a573d82SSukumar Swaminathan 	}
3206a573d82SSukumar Swaminathan 
32182527734SSukumar Swaminathan 	hba->mbox_queue_flag = 0;
32282527734SSukumar Swaminathan 	hba->fc_edtov = FF_DEF_EDTOV;
32382527734SSukumar Swaminathan 	hba->fc_ratov = FF_DEF_RATOV;
32482527734SSukumar Swaminathan 	hba->fc_altov = FF_DEF_ALTOV;
32582527734SSukumar Swaminathan 	hba->fc_arbtov = FF_DEF_ARBTOV;
32682527734SSukumar Swaminathan 
32782527734SSukumar Swaminathan 	/* Networking not supported */
32882527734SSukumar Swaminathan 	if (cfg[CFG_NETWORK_ON].current) {
32982527734SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_init_msg,
3308f23e9faSHans Rosenfeld 		    "Networking is not supported in SLI4, turning it off");
33182527734SSukumar Swaminathan 		cfg[CFG_NETWORK_ON].current = 0;
33282527734SSukumar Swaminathan 	}
33382527734SSukumar Swaminathan 
33482527734SSukumar Swaminathan 	hba->chan_count = hba->intr_count * cfg[CFG_NUM_WQ].current;
33582527734SSukumar Swaminathan 	if (hba->chan_count > MAX_CHANNEL) {
33682527734SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_init_failed_msg,
33782527734SSukumar Swaminathan 		    "Max channels exceeded, dropping num-wq from %d to 1",
33882527734SSukumar Swaminathan 		    cfg[CFG_NUM_WQ].current);
33982527734SSukumar Swaminathan 		cfg[CFG_NUM_WQ].current = 1;
34082527734SSukumar Swaminathan 		hba->chan_count = hba->intr_count * cfg[CFG_NUM_WQ].current;
34182527734SSukumar Swaminathan 	}
34282527734SSukumar Swaminathan 	hba->channel_fcp = 0; /* First channel */
34382527734SSukumar Swaminathan 
34482527734SSukumar Swaminathan 	/* Default channel for everything else is the last channel */
34582527734SSukumar Swaminathan 	hba->channel_ip = hba->chan_count - 1;
34682527734SSukumar Swaminathan 	hba->channel_els = hba->chan_count - 1;
34782527734SSukumar Swaminathan 	hba->channel_ct = hba->chan_count - 1;
34882527734SSukumar Swaminathan 
34982527734SSukumar Swaminathan 	hba->fc_iotag = 1;
35082527734SSukumar Swaminathan 	hba->io_count = 0;
35182527734SSukumar Swaminathan 	hba->channel_tx_count = 0;
35282527734SSukumar Swaminathan 
35382527734SSukumar Swaminathan 	/* Initialize the local dump region buffer */
35482527734SSukumar Swaminathan 	bzero(&hba->sli.sli4.dump_region, sizeof (MBUF_INFO));
35582527734SSukumar Swaminathan 	hba->sli.sli4.dump_region.size = EMLXS_DUMP_REGION_SIZE;
356*a3170057SPaul Winder 	hba->sli.sli4.dump_region.flags = FC_MBUF_DMA | FC_MBUF_SNGLSG;
35782527734SSukumar Swaminathan 	hba->sli.sli4.dump_region.align = ddi_ptob(hba->dip, 1L);
35882527734SSukumar Swaminathan 
35982527734SSukumar Swaminathan 	(void) emlxs_mem_alloc(hba, &hba->sli.sli4.dump_region);
36082527734SSukumar Swaminathan 
36182527734SSukumar Swaminathan 	if (hba->sli.sli4.dump_region.virt == NULL) {
36282527734SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_init_failed_msg,
36382527734SSukumar Swaminathan 		    "Unable to allocate dump region buffer.");
36482527734SSukumar Swaminathan 
36582527734SSukumar Swaminathan 		return (ENOMEM);
36682527734SSukumar Swaminathan 	}
36782527734SSukumar Swaminathan 
36882527734SSukumar Swaminathan 	/*
36982527734SSukumar Swaminathan 	 * Get a buffer which will be used repeatedly for mailbox commands
37082527734SSukumar Swaminathan 	 */
37182527734SSukumar Swaminathan 	mbq = (MAILBOXQ *) kmem_zalloc((sizeof (MAILBOXQ)), KM_SLEEP);
37282527734SSukumar Swaminathan 
37382527734SSukumar Swaminathan 	mb = (MAILBOX4 *)mbq;
37482527734SSukumar Swaminathan 
37582527734SSukumar Swaminathan reset:
37682527734SSukumar Swaminathan 	/* Reset & Initialize the adapter */
37782527734SSukumar Swaminathan 	if (emlxs_sli4_hba_init(hba)) {
37882527734SSukumar Swaminathan 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_init_failed_msg,
37982527734SSukumar Swaminathan 		    "Unable to init hba.");
38082527734SSukumar Swaminathan 
38182527734SSukumar Swaminathan 		rval = EIO;
38282527734SSukumar Swaminathan 		goto failed1;
38382527734SSukumar Swaminathan 	}
38482527734SSukumar Swaminathan 
38582527734SSukumar Swaminathan #ifdef FMA_SUPPORT
38682527734SSukumar Swaminathan 	/* Access handle validation */
3878f23e9faSHans Rosenfeld 	switch (hba->sli_intf & SLI_INTF_IF_TYPE_MASK) {
3888f23e9faSHans Rosenfeld 	case SLI_INTF_IF_TYPE_2:
3898f23e9faSHans Rosenfeld 		if ((emlxs_fm_check_acc_handle(hba,
3908f23e9faSHans Rosenfeld 		    hba->pci_acc_handle) != DDI_FM_OK) ||
3918f23e9faSHans Rosenfeld 		    (emlxs_fm_check_acc_handle(hba,
3928f23e9faSHans Rosenfeld 		    hba->sli.sli4.bar0_acc_handle) != DDI_FM_OK)) {
3938f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT,
3948f23e9faSHans Rosenfeld 			    &emlxs_invalid_access_handle_msg, NULL);
39582527734SSukumar Swaminathan 
3968f23e9faSHans Rosenfeld 			rval = EIO;
3978f23e9faSHans Rosenfeld 			goto failed1;
3988f23e9faSHans Rosenfeld 		}
3998f23e9faSHans Rosenfeld 		break;
4008f23e9faSHans Rosenfeld 
4018f23e9faSHans Rosenfeld 	default :
4028f23e9faSHans Rosenfeld 		if ((emlxs_fm_check_acc_handle(hba,
4038f23e9faSHans Rosenfeld 		    hba->pci_acc_handle) != DDI_FM_OK) ||
4048f23e9faSHans Rosenfeld 		    (emlxs_fm_check_acc_handle(hba,
4058f23e9faSHans Rosenfeld 		    hba->sli.sli4.bar1_acc_handle) != DDI_FM_OK) ||
4068f23e9faSHans Rosenfeld 		    (emlxs_fm_check_acc_handle(hba,
4078f23e9faSHans Rosenfeld 		    hba->sli.sli4.bar2_acc_handle) != DDI_FM_OK)) {
4088f23e9faSHans Rosenfeld 			EMLXS_MSGF(EMLXS_CONTEXT,
4098f23e9faSHans Rosenfeld 			    &emlxs_invalid_access_handle_msg, NULL);
4108f23e9faSHans Rosenfeld 
4118f23e9faSHans Rosenfeld 			rval = EIO;
4128f23e9faSHans Rosenfeld 			goto failed1;
4138f23e9faSHans Rosenfeld 		}
4148f23e9faSHans Rosenfeld 		break;
41582527734SSukumar Swaminathan 	}
416