19aebddd1SJeff Kirsher /*
29aebddd1SJeff Kirsher  * Copyright (C) 2005 - 2011 Emulex
39aebddd1SJeff Kirsher  * All rights reserved.
49aebddd1SJeff Kirsher  *
59aebddd1SJeff Kirsher  * This program is free software; you can redistribute it and/or
69aebddd1SJeff Kirsher  * modify it under the terms of the GNU General Public License version 2
79aebddd1SJeff Kirsher  * as published by the Free Software Foundation.  The full GNU General
89aebddd1SJeff Kirsher  * Public License is included in this distribution in the file called COPYING.
99aebddd1SJeff Kirsher  *
109aebddd1SJeff Kirsher  * Contact Information:
119aebddd1SJeff Kirsher  * linux-drivers@emulex.com
129aebddd1SJeff Kirsher  *
139aebddd1SJeff Kirsher  * Emulex
149aebddd1SJeff Kirsher  * 3333 Susan Street
159aebddd1SJeff Kirsher  * Costa Mesa, CA 92626
169aebddd1SJeff Kirsher  */
179aebddd1SJeff Kirsher 
189aebddd1SJeff Kirsher #include "be.h"
199aebddd1SJeff Kirsher #include "be_cmds.h"
209aebddd1SJeff Kirsher 
219aebddd1SJeff Kirsher /* Must be a power of 2 or else MODULO will BUG_ON */
223de09455SSomnath Kotur static int be_get_temp_freq = 64;
233de09455SSomnath Kotur 
243de09455SSomnath Kotur static inline void *embedded_payload(struct be_mcc_wrb *wrb)
253de09455SSomnath Kotur {
263de09455SSomnath Kotur 	return wrb->payload.embedded_payload;
273de09455SSomnath Kotur }
289aebddd1SJeff Kirsher 
299aebddd1SJeff Kirsher static void be_mcc_notify(struct be_adapter *adapter)
309aebddd1SJeff Kirsher {
319aebddd1SJeff Kirsher 	struct be_queue_info *mccq = &adapter->mcc_obj.q;
329aebddd1SJeff Kirsher 	u32 val = 0;
339aebddd1SJeff Kirsher 
346589ade0SSathya Perla 	if (be_error(adapter))
359aebddd1SJeff Kirsher 		return;
369aebddd1SJeff Kirsher 
379aebddd1SJeff Kirsher 	val |= mccq->id & DB_MCCQ_RING_ID_MASK;
389aebddd1SJeff Kirsher 	val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
399aebddd1SJeff Kirsher 
409aebddd1SJeff Kirsher 	wmb();
419aebddd1SJeff Kirsher 	iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
429aebddd1SJeff Kirsher }
439aebddd1SJeff Kirsher 
449aebddd1SJeff Kirsher /* To check if valid bit is set, check the entire word as we don't know
459aebddd1SJeff Kirsher  * the endianness of the data (old entry is host endian while a new entry is
469aebddd1SJeff Kirsher  * little endian) */
479aebddd1SJeff Kirsher static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
489aebddd1SJeff Kirsher {
499aebddd1SJeff Kirsher 	if (compl->flags != 0) {
509aebddd1SJeff Kirsher 		compl->flags = le32_to_cpu(compl->flags);
519aebddd1SJeff Kirsher 		BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
529aebddd1SJeff Kirsher 		return true;
539aebddd1SJeff Kirsher 	} else {
549aebddd1SJeff Kirsher 		return false;
559aebddd1SJeff Kirsher 	}
569aebddd1SJeff Kirsher }
579aebddd1SJeff Kirsher 
589aebddd1SJeff Kirsher /* Need to reset the entire word that houses the valid bit */
599aebddd1SJeff Kirsher static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
609aebddd1SJeff Kirsher {
619aebddd1SJeff Kirsher 	compl->flags = 0;
629aebddd1SJeff Kirsher }
639aebddd1SJeff Kirsher 
649aebddd1SJeff Kirsher static int be_mcc_compl_process(struct be_adapter *adapter,
659aebddd1SJeff Kirsher 	struct be_mcc_compl *compl)
669aebddd1SJeff Kirsher {
679aebddd1SJeff Kirsher 	u16 compl_status, extd_status;
689aebddd1SJeff Kirsher 
699aebddd1SJeff Kirsher 	/* Just swap the status to host endian; mcc tag is opaquely copied
709aebddd1SJeff Kirsher 	 * from mcc_wrb */
719aebddd1SJeff Kirsher 	be_dws_le_to_cpu(compl, 4);
729aebddd1SJeff Kirsher 
739aebddd1SJeff Kirsher 	compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
749aebddd1SJeff Kirsher 				CQE_STATUS_COMPL_MASK;
759aebddd1SJeff Kirsher 
769aebddd1SJeff Kirsher 	if (((compl->tag0 == OPCODE_COMMON_WRITE_FLASHROM) ||
779aebddd1SJeff Kirsher 		(compl->tag0 == OPCODE_COMMON_WRITE_OBJECT)) &&
789aebddd1SJeff Kirsher 		(compl->tag1 == CMD_SUBSYSTEM_COMMON)) {
799aebddd1SJeff Kirsher 		adapter->flash_status = compl_status;
809aebddd1SJeff Kirsher 		complete(&adapter->flash_compl);
819aebddd1SJeff Kirsher 	}
829aebddd1SJeff Kirsher 
839aebddd1SJeff Kirsher 	if (compl_status == MCC_STATUS_SUCCESS) {
849aebddd1SJeff Kirsher 		if (((compl->tag0 == OPCODE_ETH_GET_STATISTICS) ||
859aebddd1SJeff Kirsher 			 (compl->tag0 == OPCODE_ETH_GET_PPORT_STATS)) &&
869aebddd1SJeff Kirsher 			(compl->tag1 == CMD_SUBSYSTEM_ETH)) {
879aebddd1SJeff Kirsher 			be_parse_stats(adapter);
889aebddd1SJeff Kirsher 			adapter->stats_cmd_sent = false;
899aebddd1SJeff Kirsher 		}
903de09455SSomnath Kotur 		if (compl->tag0 ==
913de09455SSomnath Kotur 				OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES) {
923de09455SSomnath Kotur 			struct be_mcc_wrb *mcc_wrb =
933de09455SSomnath Kotur 				queue_index_node(&adapter->mcc_obj.q,
943de09455SSomnath Kotur 						compl->tag1);
953de09455SSomnath Kotur 			struct be_cmd_resp_get_cntl_addnl_attribs *resp =
963de09455SSomnath Kotur 				embedded_payload(mcc_wrb);
973de09455SSomnath Kotur 			adapter->drv_stats.be_on_die_temperature =
983de09455SSomnath Kotur 				resp->on_die_temperature;
993de09455SSomnath Kotur 		}
1009aebddd1SJeff Kirsher 	} else {
1013de09455SSomnath Kotur 		if (compl->tag0 == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES)
1023de09455SSomnath Kotur 			be_get_temp_freq = 0;
1033de09455SSomnath Kotur 
1049aebddd1SJeff Kirsher 		if (compl_status == MCC_STATUS_NOT_SUPPORTED ||
1059aebddd1SJeff Kirsher 			compl_status == MCC_STATUS_ILLEGAL_REQUEST)
1069aebddd1SJeff Kirsher 			goto done;
1079aebddd1SJeff Kirsher 
1089aebddd1SJeff Kirsher 		if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
1099aebddd1SJeff Kirsher 			dev_warn(&adapter->pdev->dev, "This domain(VM) is not "
1109aebddd1SJeff Kirsher 				"permitted to execute this cmd (opcode %d)\n",
1119aebddd1SJeff Kirsher 				compl->tag0);
1129aebddd1SJeff Kirsher 		} else {
1139aebddd1SJeff Kirsher 			extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
1149aebddd1SJeff Kirsher 					CQE_STATUS_EXTD_MASK;
1159aebddd1SJeff Kirsher 			dev_err(&adapter->pdev->dev, "Cmd (opcode %d) failed:"
1169aebddd1SJeff Kirsher 				"status %d, extd-status %d\n",
1179aebddd1SJeff Kirsher 				compl->tag0, compl_status, extd_status);
1189aebddd1SJeff Kirsher 		}
1199aebddd1SJeff Kirsher 	}
1209aebddd1SJeff Kirsher done:
1219aebddd1SJeff Kirsher 	return compl_status;
1229aebddd1SJeff Kirsher }
1239aebddd1SJeff Kirsher 
1249aebddd1SJeff Kirsher /* Link state evt is a string of bytes; no need for endian swapping */
1259aebddd1SJeff Kirsher static void be_async_link_state_process(struct be_adapter *adapter,
1269aebddd1SJeff Kirsher 		struct be_async_event_link_state *evt)
1279aebddd1SJeff Kirsher {
1289aebddd1SJeff Kirsher 	be_link_status_update(adapter, evt->port_link_status);
1299aebddd1SJeff Kirsher }
1309aebddd1SJeff Kirsher 
1319aebddd1SJeff Kirsher /* Grp5 CoS Priority evt */
1329aebddd1SJeff Kirsher static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
1339aebddd1SJeff Kirsher 		struct be_async_event_grp5_cos_priority *evt)
1349aebddd1SJeff Kirsher {
1359aebddd1SJeff Kirsher 	if (evt->valid) {
1369aebddd1SJeff Kirsher 		adapter->vlan_prio_bmap = evt->available_priority_bmap;
1379aebddd1SJeff Kirsher 		adapter->recommended_prio &= ~VLAN_PRIO_MASK;
1389aebddd1SJeff Kirsher 		adapter->recommended_prio =
1399aebddd1SJeff Kirsher 			evt->reco_default_priority << VLAN_PRIO_SHIFT;
1409aebddd1SJeff Kirsher 	}
1419aebddd1SJeff Kirsher }
1429aebddd1SJeff Kirsher 
1439aebddd1SJeff Kirsher /* Grp5 QOS Speed evt */
1449aebddd1SJeff Kirsher static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
1459aebddd1SJeff Kirsher 		struct be_async_event_grp5_qos_link_speed *evt)
1469aebddd1SJeff Kirsher {
1479aebddd1SJeff Kirsher 	if (evt->physical_port == adapter->port_num) {
1489aebddd1SJeff Kirsher 		/* qos_link_speed is in units of 10 Mbps */
1499aebddd1SJeff Kirsher 		adapter->link_speed = evt->qos_link_speed * 10;
1509aebddd1SJeff Kirsher 	}
1519aebddd1SJeff Kirsher }
1529aebddd1SJeff Kirsher 
1539aebddd1SJeff Kirsher /*Grp5 PVID evt*/
1549aebddd1SJeff Kirsher static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
1559aebddd1SJeff Kirsher 		struct be_async_event_grp5_pvid_state *evt)
1569aebddd1SJeff Kirsher {
1579aebddd1SJeff Kirsher 	if (evt->enabled)
158939cf306SSomnath Kotur 		adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
1599aebddd1SJeff Kirsher 	else
1609aebddd1SJeff Kirsher 		adapter->pvid = 0;
1619aebddd1SJeff Kirsher }
1629aebddd1SJeff Kirsher 
1639aebddd1SJeff Kirsher static void be_async_grp5_evt_process(struct be_adapter *adapter,
1649aebddd1SJeff Kirsher 		u32 trailer, struct be_mcc_compl *evt)
1659aebddd1SJeff Kirsher {
1669aebddd1SJeff Kirsher 	u8 event_type = 0;
1679aebddd1SJeff Kirsher 
1689aebddd1SJeff Kirsher 	event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
1699aebddd1SJeff Kirsher 		ASYNC_TRAILER_EVENT_TYPE_MASK;
1709aebddd1SJeff Kirsher 
1719aebddd1SJeff Kirsher 	switch (event_type) {
1729aebddd1SJeff Kirsher 	case ASYNC_EVENT_COS_PRIORITY:
1739aebddd1SJeff Kirsher 		be_async_grp5_cos_priority_process(adapter,
1749aebddd1SJeff Kirsher 		(struct be_async_event_grp5_cos_priority *)evt);
1759aebddd1SJeff Kirsher 	break;
1769aebddd1SJeff Kirsher 	case ASYNC_EVENT_QOS_SPEED:
1779aebddd1SJeff Kirsher 		be_async_grp5_qos_speed_process(adapter,
1789aebddd1SJeff Kirsher 		(struct be_async_event_grp5_qos_link_speed *)evt);
1799aebddd1SJeff Kirsher 	break;
1809aebddd1SJeff Kirsher 	case ASYNC_EVENT_PVID_STATE:
1819aebddd1SJeff Kirsher 		be_async_grp5_pvid_state_process(adapter,
1829aebddd1SJeff Kirsher 		(struct be_async_event_grp5_pvid_state *)evt);
1839aebddd1SJeff Kirsher 	break;
1849aebddd1SJeff Kirsher 	default:
1859aebddd1SJeff Kirsher 		dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
1869aebddd1SJeff Kirsher 		break;
1879aebddd1SJeff Kirsher 	}
1889aebddd1SJeff Kirsher }
1899aebddd1SJeff Kirsher 
1909aebddd1SJeff Kirsher static inline bool is_link_state_evt(u32 trailer)
1919aebddd1SJeff Kirsher {
1929aebddd1SJeff Kirsher 	return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
1939aebddd1SJeff Kirsher 		ASYNC_TRAILER_EVENT_CODE_MASK) ==
1949aebddd1SJeff Kirsher 				ASYNC_EVENT_CODE_LINK_STATE;
1959aebddd1SJeff Kirsher }
1969aebddd1SJeff Kirsher 
1979aebddd1SJeff Kirsher static inline bool is_grp5_evt(u32 trailer)
1989aebddd1SJeff Kirsher {
1999aebddd1SJeff Kirsher 	return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
2009aebddd1SJeff Kirsher 		ASYNC_TRAILER_EVENT_CODE_MASK) ==
2019aebddd1SJeff Kirsher 				ASYNC_EVENT_CODE_GRP_5);
2029aebddd1SJeff Kirsher }
2039aebddd1SJeff Kirsher 
2049aebddd1SJeff Kirsher static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
2059aebddd1SJeff Kirsher {
2069aebddd1SJeff Kirsher 	struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
2079aebddd1SJeff Kirsher 	struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
2089aebddd1SJeff Kirsher 
2099aebddd1SJeff Kirsher 	if (be_mcc_compl_is_new(compl)) {
2109aebddd1SJeff Kirsher 		queue_tail_inc(mcc_cq);
2119aebddd1SJeff Kirsher 		return compl;
2129aebddd1SJeff Kirsher 	}
2139aebddd1SJeff Kirsher 	return NULL;
2149aebddd1SJeff Kirsher }
2159aebddd1SJeff Kirsher 
2169aebddd1SJeff Kirsher void be_async_mcc_enable(struct be_adapter *adapter)
2179aebddd1SJeff Kirsher {
2189aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_cq_lock);
2199aebddd1SJeff Kirsher 
2209aebddd1SJeff Kirsher 	be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
2219aebddd1SJeff Kirsher 	adapter->mcc_obj.rearm_cq = true;
2229aebddd1SJeff Kirsher 
2239aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_cq_lock);
2249aebddd1SJeff Kirsher }
2259aebddd1SJeff Kirsher 
2269aebddd1SJeff Kirsher void be_async_mcc_disable(struct be_adapter *adapter)
2279aebddd1SJeff Kirsher {
2289aebddd1SJeff Kirsher 	adapter->mcc_obj.rearm_cq = false;
2299aebddd1SJeff Kirsher }
2309aebddd1SJeff Kirsher 
2319aebddd1SJeff Kirsher int be_process_mcc(struct be_adapter *adapter, int *status)
2329aebddd1SJeff Kirsher {
2339aebddd1SJeff Kirsher 	struct be_mcc_compl *compl;
2349aebddd1SJeff Kirsher 	int num = 0;
2359aebddd1SJeff Kirsher 	struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
2369aebddd1SJeff Kirsher 
2379aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_cq_lock);
2389aebddd1SJeff Kirsher 	while ((compl = be_mcc_compl_get(adapter))) {
2399aebddd1SJeff Kirsher 		if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
2409aebddd1SJeff Kirsher 			/* Interpret flags as an async trailer */
2419aebddd1SJeff Kirsher 			if (is_link_state_evt(compl->flags))
2429aebddd1SJeff Kirsher 				be_async_link_state_process(adapter,
2439aebddd1SJeff Kirsher 				(struct be_async_event_link_state *) compl);
2449aebddd1SJeff Kirsher 			else if (is_grp5_evt(compl->flags))
2459aebddd1SJeff Kirsher 				be_async_grp5_evt_process(adapter,
2469aebddd1SJeff Kirsher 				compl->flags, compl);
2479aebddd1SJeff Kirsher 		} else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
2489aebddd1SJeff Kirsher 				*status = be_mcc_compl_process(adapter, compl);
2499aebddd1SJeff Kirsher 				atomic_dec(&mcc_obj->q.used);
2509aebddd1SJeff Kirsher 		}
2519aebddd1SJeff Kirsher 		be_mcc_compl_use(compl);
2529aebddd1SJeff Kirsher 		num++;
2539aebddd1SJeff Kirsher 	}
2549aebddd1SJeff Kirsher 
2559aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_cq_lock);
2569aebddd1SJeff Kirsher 	return num;
2579aebddd1SJeff Kirsher }
2589aebddd1SJeff Kirsher 
2599aebddd1SJeff Kirsher /* Wait till no more pending mcc requests are present */
2609aebddd1SJeff Kirsher static int be_mcc_wait_compl(struct be_adapter *adapter)
2619aebddd1SJeff Kirsher {
2629aebddd1SJeff Kirsher #define mcc_timeout		120000 /* 12s timeout */
2639aebddd1SJeff Kirsher 	int i, num, status = 0;
2649aebddd1SJeff Kirsher 	struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
2659aebddd1SJeff Kirsher 
2666589ade0SSathya Perla 	for (i = 0; i < mcc_timeout; i++) {
2676589ade0SSathya Perla 		if (be_error(adapter))
2689aebddd1SJeff Kirsher 			return -EIO;
2699aebddd1SJeff Kirsher 
2709aebddd1SJeff Kirsher 		num = be_process_mcc(adapter, &status);
2719aebddd1SJeff Kirsher 		if (num)
2729aebddd1SJeff Kirsher 			be_cq_notify(adapter, mcc_obj->cq.id,
2739aebddd1SJeff Kirsher 				mcc_obj->rearm_cq, num);
2749aebddd1SJeff Kirsher 
2759aebddd1SJeff Kirsher 		if (atomic_read(&mcc_obj->q.used) == 0)
2769aebddd1SJeff Kirsher 			break;
2779aebddd1SJeff Kirsher 		udelay(100);
2789aebddd1SJeff Kirsher 	}
2799aebddd1SJeff Kirsher 	if (i == mcc_timeout) {
2806589ade0SSathya Perla 		dev_err(&adapter->pdev->dev, "FW not responding\n");
2816589ade0SSathya Perla 		adapter->fw_timeout = true;
2829aebddd1SJeff Kirsher 		return -1;
2839aebddd1SJeff Kirsher 	}
2849aebddd1SJeff Kirsher 	return status;
2859aebddd1SJeff Kirsher }
2869aebddd1SJeff Kirsher 
2879aebddd1SJeff Kirsher /* Notify MCC requests and wait for completion */
2889aebddd1SJeff Kirsher static int be_mcc_notify_wait(struct be_adapter *adapter)
2899aebddd1SJeff Kirsher {
2909aebddd1SJeff Kirsher 	be_mcc_notify(adapter);
2919aebddd1SJeff Kirsher 	return be_mcc_wait_compl(adapter);
2929aebddd1SJeff Kirsher }
2939aebddd1SJeff Kirsher 
2949aebddd1SJeff Kirsher static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
2959aebddd1SJeff Kirsher {
2969aebddd1SJeff Kirsher 	int msecs = 0;
2979aebddd1SJeff Kirsher 	u32 ready;
2989aebddd1SJeff Kirsher 
2996589ade0SSathya Perla 	do {
3006589ade0SSathya Perla 		if (be_error(adapter))
3019aebddd1SJeff Kirsher 			return -EIO;
3029aebddd1SJeff Kirsher 
3039aebddd1SJeff Kirsher 		ready = ioread32(db);
304434b3648SSathya Perla 		if (ready == 0xffffffff)
3059aebddd1SJeff Kirsher 			return -1;
3069aebddd1SJeff Kirsher 
3079aebddd1SJeff Kirsher 		ready &= MPU_MAILBOX_DB_RDY_MASK;
3089aebddd1SJeff Kirsher 		if (ready)
3099aebddd1SJeff Kirsher 			break;
3109aebddd1SJeff Kirsher 
3119aebddd1SJeff Kirsher 		if (msecs > 4000) {
3126589ade0SSathya Perla 			dev_err(&adapter->pdev->dev, "FW not responding\n");
3136589ade0SSathya Perla 			adapter->fw_timeout = true;
3149aebddd1SJeff Kirsher 			be_detect_dump_ue(adapter);
3159aebddd1SJeff Kirsher 			return -1;
3169aebddd1SJeff Kirsher 		}
3179aebddd1SJeff Kirsher 
3189aebddd1SJeff Kirsher 		msleep(1);
3199aebddd1SJeff Kirsher 		msecs++;
3209aebddd1SJeff Kirsher 	} while (true);
3219aebddd1SJeff Kirsher 
3229aebddd1SJeff Kirsher 	return 0;
3239aebddd1SJeff Kirsher }
3249aebddd1SJeff Kirsher 
3259aebddd1SJeff Kirsher /*
3269aebddd1SJeff Kirsher  * Insert the mailbox address into the doorbell in two steps
3279aebddd1SJeff Kirsher  * Polls on the mbox doorbell till a command completion (or a timeout) occurs
3289aebddd1SJeff Kirsher  */
3299aebddd1SJeff Kirsher static int be_mbox_notify_wait(struct be_adapter *adapter)
3309aebddd1SJeff Kirsher {
3319aebddd1SJeff Kirsher 	int status;
3329aebddd1SJeff Kirsher 	u32 val = 0;
3339aebddd1SJeff Kirsher 	void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
3349aebddd1SJeff Kirsher 	struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
3359aebddd1SJeff Kirsher 	struct be_mcc_mailbox *mbox = mbox_mem->va;
3369aebddd1SJeff Kirsher 	struct be_mcc_compl *compl = &mbox->compl;
3379aebddd1SJeff Kirsher 
3389aebddd1SJeff Kirsher 	/* wait for ready to be set */
3399aebddd1SJeff Kirsher 	status = be_mbox_db_ready_wait(adapter, db);
3409aebddd1SJeff Kirsher 	if (status != 0)
3419aebddd1SJeff Kirsher 		return status;
3429aebddd1SJeff Kirsher 
3439aebddd1SJeff Kirsher 	val |= MPU_MAILBOX_DB_HI_MASK;
3449aebddd1SJeff Kirsher 	/* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
3459aebddd1SJeff Kirsher 	val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
3469aebddd1SJeff Kirsher 	iowrite32(val, db);
3479aebddd1SJeff Kirsher 
3489aebddd1SJeff Kirsher 	/* wait for ready to be set */
3499aebddd1SJeff Kirsher 	status = be_mbox_db_ready_wait(adapter, db);
3509aebddd1SJeff Kirsher 	if (status != 0)
3519aebddd1SJeff Kirsher 		return status;
3529aebddd1SJeff Kirsher 
3539aebddd1SJeff Kirsher 	val = 0;
3549aebddd1SJeff Kirsher 	/* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
3559aebddd1SJeff Kirsher 	val |= (u32)(mbox_mem->dma >> 4) << 2;
3569aebddd1SJeff Kirsher 	iowrite32(val, db);
3579aebddd1SJeff Kirsher 
3589aebddd1SJeff Kirsher 	status = be_mbox_db_ready_wait(adapter, db);
3599aebddd1SJeff Kirsher 	if (status != 0)
3609aebddd1SJeff Kirsher 		return status;
3619aebddd1SJeff Kirsher 
3629aebddd1SJeff Kirsher 	/* A cq entry has been made now */
3639aebddd1SJeff Kirsher 	if (be_mcc_compl_is_new(compl)) {
3649aebddd1SJeff Kirsher 		status = be_mcc_compl_process(adapter, &mbox->compl);
3659aebddd1SJeff Kirsher 		be_mcc_compl_use(compl);
3669aebddd1SJeff Kirsher 		if (status)
3679aebddd1SJeff Kirsher 			return status;
3689aebddd1SJeff Kirsher 	} else {
3699aebddd1SJeff Kirsher 		dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
3709aebddd1SJeff Kirsher 		return -1;
3719aebddd1SJeff Kirsher 	}
3729aebddd1SJeff Kirsher 	return 0;
3739aebddd1SJeff Kirsher }
3749aebddd1SJeff Kirsher 
3759aebddd1SJeff Kirsher static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
3769aebddd1SJeff Kirsher {
3779aebddd1SJeff Kirsher 	u32 sem;
3789aebddd1SJeff Kirsher 
3799aebddd1SJeff Kirsher 	if (lancer_chip(adapter))
3809aebddd1SJeff Kirsher 		sem  = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
3819aebddd1SJeff Kirsher 	else
3829aebddd1SJeff Kirsher 		sem  = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
3839aebddd1SJeff Kirsher 
3849aebddd1SJeff Kirsher 	*stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
3859aebddd1SJeff Kirsher 	if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
3869aebddd1SJeff Kirsher 		return -1;
3879aebddd1SJeff Kirsher 	else
3889aebddd1SJeff Kirsher 		return 0;
3899aebddd1SJeff Kirsher }
3909aebddd1SJeff Kirsher 
3919aebddd1SJeff Kirsher int be_cmd_POST(struct be_adapter *adapter)
3929aebddd1SJeff Kirsher {
3939aebddd1SJeff Kirsher 	u16 stage;
3949aebddd1SJeff Kirsher 	int status, timeout = 0;
3959aebddd1SJeff Kirsher 	struct device *dev = &adapter->pdev->dev;
3969aebddd1SJeff Kirsher 
3979aebddd1SJeff Kirsher 	do {
3989aebddd1SJeff Kirsher 		status = be_POST_stage_get(adapter, &stage);
3999aebddd1SJeff Kirsher 		if (status) {
4009aebddd1SJeff Kirsher 			dev_err(dev, "POST error; stage=0x%x\n", stage);
4019aebddd1SJeff Kirsher 			return -1;
4029aebddd1SJeff Kirsher 		} else if (stage != POST_STAGE_ARMFW_RDY) {
4039aebddd1SJeff Kirsher 			if (msleep_interruptible(2000)) {
4049aebddd1SJeff Kirsher 				dev_err(dev, "Waiting for POST aborted\n");
4059aebddd1SJeff Kirsher 				return -EINTR;
4069aebddd1SJeff Kirsher 			}
4079aebddd1SJeff Kirsher 			timeout += 2;
4089aebddd1SJeff Kirsher 		} else {
4099aebddd1SJeff Kirsher 			return 0;
4109aebddd1SJeff Kirsher 		}
4113ab81b5fSSomnath Kotur 	} while (timeout < 60);
4129aebddd1SJeff Kirsher 
4139aebddd1SJeff Kirsher 	dev_err(dev, "POST timeout; stage=0x%x\n", stage);
4149aebddd1SJeff Kirsher 	return -1;
4159aebddd1SJeff Kirsher }
4169aebddd1SJeff Kirsher 
4179aebddd1SJeff Kirsher 
4189aebddd1SJeff Kirsher static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
4199aebddd1SJeff Kirsher {
4209aebddd1SJeff Kirsher 	return &wrb->payload.sgl[0];
4219aebddd1SJeff Kirsher }
4229aebddd1SJeff Kirsher 
4239aebddd1SJeff Kirsher 
4249aebddd1SJeff Kirsher /* Don't touch the hdr after it's prepared */
425106df1e3SSomnath Kotur /* mem will be NULL for embedded commands */
426106df1e3SSomnath Kotur static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
427106df1e3SSomnath Kotur 				u8 subsystem, u8 opcode, int cmd_len,
428106df1e3SSomnath Kotur 				struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
4299aebddd1SJeff Kirsher {
430106df1e3SSomnath Kotur 	struct be_sge *sge;
431106df1e3SSomnath Kotur 
4329aebddd1SJeff Kirsher 	req_hdr->opcode = opcode;
4339aebddd1SJeff Kirsher 	req_hdr->subsystem = subsystem;
4349aebddd1SJeff Kirsher 	req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
4359aebddd1SJeff Kirsher 	req_hdr->version = 0;
436106df1e3SSomnath Kotur 
437106df1e3SSomnath Kotur 	wrb->tag0 = opcode;
438106df1e3SSomnath Kotur 	wrb->tag1 = subsystem;
439106df1e3SSomnath Kotur 	wrb->payload_length = cmd_len;
440106df1e3SSomnath Kotur 	if (mem) {
441106df1e3SSomnath Kotur 		wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
442106df1e3SSomnath Kotur 			MCC_WRB_SGE_CNT_SHIFT;
443106df1e3SSomnath Kotur 		sge = nonembedded_sgl(wrb);
444106df1e3SSomnath Kotur 		sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
445106df1e3SSomnath Kotur 		sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
446106df1e3SSomnath Kotur 		sge->len = cpu_to_le32(mem->size);
447106df1e3SSomnath Kotur 	} else
448106df1e3SSomnath Kotur 		wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
449106df1e3SSomnath Kotur 	be_dws_cpu_to_le(wrb, 8);
4509aebddd1SJeff Kirsher }
4519aebddd1SJeff Kirsher 
4529aebddd1SJeff Kirsher static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
4539aebddd1SJeff Kirsher 			struct be_dma_mem *mem)
4549aebddd1SJeff Kirsher {
4559aebddd1SJeff Kirsher 	int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
4569aebddd1SJeff Kirsher 	u64 dma = (u64)mem->dma;
4579aebddd1SJeff Kirsher 
4589aebddd1SJeff Kirsher 	for (i = 0; i < buf_pages; i++) {
4599aebddd1SJeff Kirsher 		pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
4609aebddd1SJeff Kirsher 		pages[i].hi = cpu_to_le32(upper_32_bits(dma));
4619aebddd1SJeff Kirsher 		dma += PAGE_SIZE_4K;
4629aebddd1SJeff Kirsher 	}
4639aebddd1SJeff Kirsher }
4649aebddd1SJeff Kirsher 
4659aebddd1SJeff Kirsher /* Converts interrupt delay in microseconds to multiplier value */
4669aebddd1SJeff Kirsher static u32 eq_delay_to_mult(u32 usec_delay)
4679aebddd1SJeff Kirsher {
4689aebddd1SJeff Kirsher #define MAX_INTR_RATE			651042
4699aebddd1SJeff Kirsher 	const u32 round = 10;
4709aebddd1SJeff Kirsher 	u32 multiplier;
4719aebddd1SJeff Kirsher 
4729aebddd1SJeff Kirsher 	if (usec_delay == 0)
4739aebddd1SJeff Kirsher 		multiplier = 0;
4749aebddd1SJeff Kirsher 	else {
4759aebddd1SJeff Kirsher 		u32 interrupt_rate = 1000000 / usec_delay;
4769aebddd1SJeff Kirsher 		/* Max delay, corresponding to the lowest interrupt rate */
4779aebddd1SJeff Kirsher 		if (interrupt_rate == 0)
4789aebddd1SJeff Kirsher 			multiplier = 1023;
4799aebddd1SJeff Kirsher 		else {
4809aebddd1SJeff Kirsher 			multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
4819aebddd1SJeff Kirsher 			multiplier /= interrupt_rate;
4829aebddd1SJeff Kirsher 			/* Round the multiplier to the closest value.*/
4839aebddd1SJeff Kirsher 			multiplier = (multiplier + round/2) / round;
4849aebddd1SJeff Kirsher 			multiplier = min(multiplier, (u32)1023);
4859aebddd1SJeff Kirsher 		}
4869aebddd1SJeff Kirsher 	}
4879aebddd1SJeff Kirsher 	return multiplier;
4889aebddd1SJeff Kirsher }
4899aebddd1SJeff Kirsher 
4909aebddd1SJeff Kirsher static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
4919aebddd1SJeff Kirsher {
4929aebddd1SJeff Kirsher 	struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
4939aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb
4949aebddd1SJeff Kirsher 		= &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
4959aebddd1SJeff Kirsher 	memset(wrb, 0, sizeof(*wrb));
4969aebddd1SJeff Kirsher 	return wrb;
4979aebddd1SJeff Kirsher }
4989aebddd1SJeff Kirsher 
4999aebddd1SJeff Kirsher static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
5009aebddd1SJeff Kirsher {
5019aebddd1SJeff Kirsher 	struct be_queue_info *mccq = &adapter->mcc_obj.q;
5029aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
5039aebddd1SJeff Kirsher 
5049aebddd1SJeff Kirsher 	if (atomic_read(&mccq->used) >= mccq->len) {
5059aebddd1SJeff Kirsher 		dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
5069aebddd1SJeff Kirsher 		return NULL;
5079aebddd1SJeff Kirsher 	}
5089aebddd1SJeff Kirsher 
5099aebddd1SJeff Kirsher 	wrb = queue_head_node(mccq);
5109aebddd1SJeff Kirsher 	queue_head_inc(mccq);
5119aebddd1SJeff Kirsher 	atomic_inc(&mccq->used);
5129aebddd1SJeff Kirsher 	memset(wrb, 0, sizeof(*wrb));
5139aebddd1SJeff Kirsher 	return wrb;
5149aebddd1SJeff Kirsher }
5159aebddd1SJeff Kirsher 
5169aebddd1SJeff Kirsher /* Tell fw we're about to start firing cmds by writing a
5179aebddd1SJeff Kirsher  * special pattern across the wrb hdr; uses mbox
5189aebddd1SJeff Kirsher  */
5199aebddd1SJeff Kirsher int be_cmd_fw_init(struct be_adapter *adapter)
5209aebddd1SJeff Kirsher {
5219aebddd1SJeff Kirsher 	u8 *wrb;
5229aebddd1SJeff Kirsher 	int status;
5239aebddd1SJeff Kirsher 
5249aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
5259aebddd1SJeff Kirsher 		return -1;
5269aebddd1SJeff Kirsher 
5279aebddd1SJeff Kirsher 	wrb = (u8 *)wrb_from_mbox(adapter);
5289aebddd1SJeff Kirsher 	*wrb++ = 0xFF;
5299aebddd1SJeff Kirsher 	*wrb++ = 0x12;
5309aebddd1SJeff Kirsher 	*wrb++ = 0x34;
5319aebddd1SJeff Kirsher 	*wrb++ = 0xFF;
5329aebddd1SJeff Kirsher 	*wrb++ = 0xFF;
5339aebddd1SJeff Kirsher 	*wrb++ = 0x56;
5349aebddd1SJeff Kirsher 	*wrb++ = 0x78;
5359aebddd1SJeff Kirsher 	*wrb = 0xFF;
5369aebddd1SJeff Kirsher 
5379aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
5389aebddd1SJeff Kirsher 
5399aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
5409aebddd1SJeff Kirsher 	return status;
5419aebddd1SJeff Kirsher }
5429aebddd1SJeff Kirsher 
5439aebddd1SJeff Kirsher /* Tell fw we're done with firing cmds by writing a
5449aebddd1SJeff Kirsher  * special pattern across the wrb hdr; uses mbox
5459aebddd1SJeff Kirsher  */
5469aebddd1SJeff Kirsher int be_cmd_fw_clean(struct be_adapter *adapter)
5479aebddd1SJeff Kirsher {
5489aebddd1SJeff Kirsher 	u8 *wrb;
5499aebddd1SJeff Kirsher 	int status;
5509aebddd1SJeff Kirsher 
5519aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
5529aebddd1SJeff Kirsher 		return -1;
5539aebddd1SJeff Kirsher 
5549aebddd1SJeff Kirsher 	wrb = (u8 *)wrb_from_mbox(adapter);
5559aebddd1SJeff Kirsher 	*wrb++ = 0xFF;
5569aebddd1SJeff Kirsher 	*wrb++ = 0xAA;
5579aebddd1SJeff Kirsher 	*wrb++ = 0xBB;
5589aebddd1SJeff Kirsher 	*wrb++ = 0xFF;
5599aebddd1SJeff Kirsher 	*wrb++ = 0xFF;
5609aebddd1SJeff Kirsher 	*wrb++ = 0xCC;
5619aebddd1SJeff Kirsher 	*wrb++ = 0xDD;
5629aebddd1SJeff Kirsher 	*wrb = 0xFF;
5639aebddd1SJeff Kirsher 
5649aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
5659aebddd1SJeff Kirsher 
5669aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
5679aebddd1SJeff Kirsher 	return status;
5689aebddd1SJeff Kirsher }
5699aebddd1SJeff Kirsher int be_cmd_eq_create(struct be_adapter *adapter,
5709aebddd1SJeff Kirsher 		struct be_queue_info *eq, int eq_delay)
5719aebddd1SJeff Kirsher {
5729aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
5739aebddd1SJeff Kirsher 	struct be_cmd_req_eq_create *req;
5749aebddd1SJeff Kirsher 	struct be_dma_mem *q_mem = &eq->dma_mem;
5759aebddd1SJeff Kirsher 	int status;
5769aebddd1SJeff Kirsher 
5779aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
5789aebddd1SJeff Kirsher 		return -1;
5799aebddd1SJeff Kirsher 
5809aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
5819aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
5829aebddd1SJeff Kirsher 
583106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
584106df1e3SSomnath Kotur 		OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
5859aebddd1SJeff Kirsher 
5869aebddd1SJeff Kirsher 	req->num_pages =  cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
5879aebddd1SJeff Kirsher 
5889aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
5899aebddd1SJeff Kirsher 	/* 4byte eqe*/
5909aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
5919aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_eq_context, count, req->context,
5929aebddd1SJeff Kirsher 			__ilog2_u32(eq->len/256));
5939aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
5949aebddd1SJeff Kirsher 			eq_delay_to_mult(eq_delay));
5959aebddd1SJeff Kirsher 	be_dws_cpu_to_le(req->context, sizeof(req->context));
5969aebddd1SJeff Kirsher 
5979aebddd1SJeff Kirsher 	be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
5989aebddd1SJeff Kirsher 
5999aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
6009aebddd1SJeff Kirsher 	if (!status) {
6019aebddd1SJeff Kirsher 		struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
6029aebddd1SJeff Kirsher 		eq->id = le16_to_cpu(resp->eq_id);
6039aebddd1SJeff Kirsher 		eq->created = true;
6049aebddd1SJeff Kirsher 	}
6059aebddd1SJeff Kirsher 
6069aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
6079aebddd1SJeff Kirsher 	return status;
6089aebddd1SJeff Kirsher }
6099aebddd1SJeff Kirsher 
610f9449ab7SSathya Perla /* Use MCC */
6119aebddd1SJeff Kirsher int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
612590c391dSPadmanabh Ratnakar 			u8 type, bool permanent, u32 if_handle, u32 pmac_id)
6139aebddd1SJeff Kirsher {
6149aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
6159aebddd1SJeff Kirsher 	struct be_cmd_req_mac_query *req;
6169aebddd1SJeff Kirsher 	int status;
6179aebddd1SJeff Kirsher 
618f9449ab7SSathya Perla 	spin_lock_bh(&adapter->mcc_lock);
6199aebddd1SJeff Kirsher 
620f9449ab7SSathya Perla 	wrb = wrb_from_mccq(adapter);
621f9449ab7SSathya Perla 	if (!wrb) {
622f9449ab7SSathya Perla 		status = -EBUSY;
623f9449ab7SSathya Perla 		goto err;
624f9449ab7SSathya Perla 	}
6259aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
6269aebddd1SJeff Kirsher 
627106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
628106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
6299aebddd1SJeff Kirsher 	req->type = type;
6309aebddd1SJeff Kirsher 	if (permanent) {
6319aebddd1SJeff Kirsher 		req->permanent = 1;
6329aebddd1SJeff Kirsher 	} else {
6339aebddd1SJeff Kirsher 		req->if_id = cpu_to_le16((u16) if_handle);
634590c391dSPadmanabh Ratnakar 		req->pmac_id = cpu_to_le32(pmac_id);
6359aebddd1SJeff Kirsher 		req->permanent = 0;
6369aebddd1SJeff Kirsher 	}
6379aebddd1SJeff Kirsher 
638f9449ab7SSathya Perla 	status = be_mcc_notify_wait(adapter);
6399aebddd1SJeff Kirsher 	if (!status) {
6409aebddd1SJeff Kirsher 		struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
6419aebddd1SJeff Kirsher 		memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
6429aebddd1SJeff Kirsher 	}
6439aebddd1SJeff Kirsher 
644f9449ab7SSathya Perla err:
645f9449ab7SSathya Perla 	spin_unlock_bh(&adapter->mcc_lock);
6469aebddd1SJeff Kirsher 	return status;
6479aebddd1SJeff Kirsher }
6489aebddd1SJeff Kirsher 
6499aebddd1SJeff Kirsher /* Uses synchronous MCCQ */
6509aebddd1SJeff Kirsher int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
6519aebddd1SJeff Kirsher 		u32 if_id, u32 *pmac_id, u32 domain)
6529aebddd1SJeff Kirsher {
6539aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
6549aebddd1SJeff Kirsher 	struct be_cmd_req_pmac_add *req;
6559aebddd1SJeff Kirsher 	int status;
6569aebddd1SJeff Kirsher 
6579aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
6589aebddd1SJeff Kirsher 
6599aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
6609aebddd1SJeff Kirsher 	if (!wrb) {
6619aebddd1SJeff Kirsher 		status = -EBUSY;
6629aebddd1SJeff Kirsher 		goto err;
6639aebddd1SJeff Kirsher 	}
6649aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
6659aebddd1SJeff Kirsher 
666106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
667106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
6689aebddd1SJeff Kirsher 
6699aebddd1SJeff Kirsher 	req->hdr.domain = domain;
6709aebddd1SJeff Kirsher 	req->if_id = cpu_to_le32(if_id);
6719aebddd1SJeff Kirsher 	memcpy(req->mac_address, mac_addr, ETH_ALEN);
6729aebddd1SJeff Kirsher 
6739aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
6749aebddd1SJeff Kirsher 	if (!status) {
6759aebddd1SJeff Kirsher 		struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
6769aebddd1SJeff Kirsher 		*pmac_id = le32_to_cpu(resp->pmac_id);
6779aebddd1SJeff Kirsher 	}
6789aebddd1SJeff Kirsher 
6799aebddd1SJeff Kirsher err:
6809aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
681e3a7ae2cSSomnath Kotur 
682e3a7ae2cSSomnath Kotur 	 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
683e3a7ae2cSSomnath Kotur 		status = -EPERM;
684e3a7ae2cSSomnath Kotur 
6859aebddd1SJeff Kirsher 	return status;
6869aebddd1SJeff Kirsher }
6879aebddd1SJeff Kirsher 
6889aebddd1SJeff Kirsher /* Uses synchronous MCCQ */
68930128031SSathya Perla int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
6909aebddd1SJeff Kirsher {
6919aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
6929aebddd1SJeff Kirsher 	struct be_cmd_req_pmac_del *req;
6939aebddd1SJeff Kirsher 	int status;
6949aebddd1SJeff Kirsher 
69530128031SSathya Perla 	if (pmac_id == -1)
69630128031SSathya Perla 		return 0;
69730128031SSathya Perla 
6989aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
6999aebddd1SJeff Kirsher 
7009aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
7019aebddd1SJeff Kirsher 	if (!wrb) {
7029aebddd1SJeff Kirsher 		status = -EBUSY;
7039aebddd1SJeff Kirsher 		goto err;
7049aebddd1SJeff Kirsher 	}
7059aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
7069aebddd1SJeff Kirsher 
707106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
708106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
7099aebddd1SJeff Kirsher 
7109aebddd1SJeff Kirsher 	req->hdr.domain = dom;
7119aebddd1SJeff Kirsher 	req->if_id = cpu_to_le32(if_id);
7129aebddd1SJeff Kirsher 	req->pmac_id = cpu_to_le32(pmac_id);
7139aebddd1SJeff Kirsher 
7149aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
7159aebddd1SJeff Kirsher 
7169aebddd1SJeff Kirsher err:
7179aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
7189aebddd1SJeff Kirsher 	return status;
7199aebddd1SJeff Kirsher }
7209aebddd1SJeff Kirsher 
7219aebddd1SJeff Kirsher /* Uses Mbox */
7229aebddd1SJeff Kirsher int be_cmd_cq_create(struct be_adapter *adapter,
7239aebddd1SJeff Kirsher 		struct be_queue_info *cq, struct be_queue_info *eq,
7249aebddd1SJeff Kirsher 		bool sol_evts, bool no_delay, int coalesce_wm)
7259aebddd1SJeff Kirsher {
7269aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
7279aebddd1SJeff Kirsher 	struct be_cmd_req_cq_create *req;
7289aebddd1SJeff Kirsher 	struct be_dma_mem *q_mem = &cq->dma_mem;
7299aebddd1SJeff Kirsher 	void *ctxt;
7309aebddd1SJeff Kirsher 	int status;
7319aebddd1SJeff Kirsher 
7329aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
7339aebddd1SJeff Kirsher 		return -1;
7349aebddd1SJeff Kirsher 
7359aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
7369aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
7379aebddd1SJeff Kirsher 	ctxt = &req->context;
7389aebddd1SJeff Kirsher 
739106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
740106df1e3SSomnath Kotur 		OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
7419aebddd1SJeff Kirsher 
7429aebddd1SJeff Kirsher 	req->num_pages =  cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
7439aebddd1SJeff Kirsher 	if (lancer_chip(adapter)) {
7449aebddd1SJeff Kirsher 		req->hdr.version = 2;
7459aebddd1SJeff Kirsher 		req->page_size = 1; /* 1 for 4K */
7469aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
7479aebddd1SJeff Kirsher 								no_delay);
7489aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
7499aebddd1SJeff Kirsher 						__ilog2_u32(cq->len/256));
7509aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
7519aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
7529aebddd1SJeff Kirsher 								ctxt, 1);
7539aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
7549aebddd1SJeff Kirsher 								ctxt, eq->id);
7559aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_lancer, armed, ctxt, 1);
7569aebddd1SJeff Kirsher 	} else {
7579aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
7589aebddd1SJeff Kirsher 								coalesce_wm);
7599aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
7609aebddd1SJeff Kirsher 								ctxt, no_delay);
7619aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
7629aebddd1SJeff Kirsher 						__ilog2_u32(cq->len/256));
7639aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
7649aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, solevent,
7659aebddd1SJeff Kirsher 								ctxt, sol_evts);
7669aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
7679aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
7689aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_cq_context_be, armed, ctxt, 1);
7699aebddd1SJeff Kirsher 	}
7709aebddd1SJeff Kirsher 
7719aebddd1SJeff Kirsher 	be_dws_cpu_to_le(ctxt, sizeof(req->context));
7729aebddd1SJeff Kirsher 
7739aebddd1SJeff Kirsher 	be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
7749aebddd1SJeff Kirsher 
7759aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
7769aebddd1SJeff Kirsher 	if (!status) {
7779aebddd1SJeff Kirsher 		struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
7789aebddd1SJeff Kirsher 		cq->id = le16_to_cpu(resp->cq_id);
7799aebddd1SJeff Kirsher 		cq->created = true;
7809aebddd1SJeff Kirsher 	}
7819aebddd1SJeff Kirsher 
7829aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
7839aebddd1SJeff Kirsher 
7849aebddd1SJeff Kirsher 	return status;
7859aebddd1SJeff Kirsher }
7869aebddd1SJeff Kirsher 
7879aebddd1SJeff Kirsher static u32 be_encoded_q_len(int q_len)
7889aebddd1SJeff Kirsher {
7899aebddd1SJeff Kirsher 	u32 len_encoded = fls(q_len); /* log2(len) + 1 */
7909aebddd1SJeff Kirsher 	if (len_encoded == 16)
7919aebddd1SJeff Kirsher 		len_encoded = 0;
7929aebddd1SJeff Kirsher 	return len_encoded;
7939aebddd1SJeff Kirsher }
7949aebddd1SJeff Kirsher 
7959aebddd1SJeff Kirsher int be_cmd_mccq_ext_create(struct be_adapter *adapter,
7969aebddd1SJeff Kirsher 			struct be_queue_info *mccq,
7979aebddd1SJeff Kirsher 			struct be_queue_info *cq)
7989aebddd1SJeff Kirsher {
7999aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
8009aebddd1SJeff Kirsher 	struct be_cmd_req_mcc_ext_create *req;
8019aebddd1SJeff Kirsher 	struct be_dma_mem *q_mem = &mccq->dma_mem;
8029aebddd1SJeff Kirsher 	void *ctxt;
8039aebddd1SJeff Kirsher 	int status;
8049aebddd1SJeff Kirsher 
8059aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
8069aebddd1SJeff Kirsher 		return -1;
8079aebddd1SJeff Kirsher 
8089aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
8099aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
8109aebddd1SJeff Kirsher 	ctxt = &req->context;
8119aebddd1SJeff Kirsher 
812106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
813106df1e3SSomnath Kotur 			OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
8149aebddd1SJeff Kirsher 
8159aebddd1SJeff Kirsher 	req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
8169aebddd1SJeff Kirsher 	if (lancer_chip(adapter)) {
8179aebddd1SJeff Kirsher 		req->hdr.version = 1;
8189aebddd1SJeff Kirsher 		req->cq_id = cpu_to_le16(cq->id);
8199aebddd1SJeff Kirsher 
8209aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
8219aebddd1SJeff Kirsher 						be_encoded_q_len(mccq->len));
8229aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
8239aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
8249aebddd1SJeff Kirsher 								ctxt, cq->id);
8259aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
8269aebddd1SJeff Kirsher 								 ctxt, 1);
8279aebddd1SJeff Kirsher 
8289aebddd1SJeff Kirsher 	} else {
8299aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
8309aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
8319aebddd1SJeff Kirsher 						be_encoded_q_len(mccq->len));
8329aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
8339aebddd1SJeff Kirsher 	}
8349aebddd1SJeff Kirsher 
8359aebddd1SJeff Kirsher 	/* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
8369aebddd1SJeff Kirsher 	req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
8379aebddd1SJeff Kirsher 	be_dws_cpu_to_le(ctxt, sizeof(req->context));
8389aebddd1SJeff Kirsher 
8399aebddd1SJeff Kirsher 	be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
8409aebddd1SJeff Kirsher 
8419aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
8429aebddd1SJeff Kirsher 	if (!status) {
8439aebddd1SJeff Kirsher 		struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
8449aebddd1SJeff Kirsher 		mccq->id = le16_to_cpu(resp->id);
8459aebddd1SJeff Kirsher 		mccq->created = true;
8469aebddd1SJeff Kirsher 	}
8479aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
8489aebddd1SJeff Kirsher 
8499aebddd1SJeff Kirsher 	return status;
8509aebddd1SJeff Kirsher }
8519aebddd1SJeff Kirsher 
8529aebddd1SJeff Kirsher int be_cmd_mccq_org_create(struct be_adapter *adapter,
8539aebddd1SJeff Kirsher 			struct be_queue_info *mccq,
8549aebddd1SJeff Kirsher 			struct be_queue_info *cq)
8559aebddd1SJeff Kirsher {
8569aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
8579aebddd1SJeff Kirsher 	struct be_cmd_req_mcc_create *req;
8589aebddd1SJeff Kirsher 	struct be_dma_mem *q_mem = &mccq->dma_mem;
8599aebddd1SJeff Kirsher 	void *ctxt;
8609aebddd1SJeff Kirsher 	int status;
8619aebddd1SJeff Kirsher 
8629aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
8639aebddd1SJeff Kirsher 		return -1;
8649aebddd1SJeff Kirsher 
8659aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
8669aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
8679aebddd1SJeff Kirsher 	ctxt = &req->context;
8689aebddd1SJeff Kirsher 
869106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
870106df1e3SSomnath Kotur 			OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
8719aebddd1SJeff Kirsher 
8729aebddd1SJeff Kirsher 	req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
8739aebddd1SJeff Kirsher 
8749aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
8759aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
8769aebddd1SJeff Kirsher 			be_encoded_q_len(mccq->len));
8779aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
8789aebddd1SJeff Kirsher 
8799aebddd1SJeff Kirsher 	be_dws_cpu_to_le(ctxt, sizeof(req->context));
8809aebddd1SJeff Kirsher 
8819aebddd1SJeff Kirsher 	be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
8829aebddd1SJeff Kirsher 
8839aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
8849aebddd1SJeff Kirsher 	if (!status) {
8859aebddd1SJeff Kirsher 		struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
8869aebddd1SJeff Kirsher 		mccq->id = le16_to_cpu(resp->id);
8879aebddd1SJeff Kirsher 		mccq->created = true;
8889aebddd1SJeff Kirsher 	}
8899aebddd1SJeff Kirsher 
8909aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
8919aebddd1SJeff Kirsher 	return status;
8929aebddd1SJeff Kirsher }
8939aebddd1SJeff Kirsher 
8949aebddd1SJeff Kirsher int be_cmd_mccq_create(struct be_adapter *adapter,
8959aebddd1SJeff Kirsher 			struct be_queue_info *mccq,
8969aebddd1SJeff Kirsher 			struct be_queue_info *cq)
8979aebddd1SJeff Kirsher {
8989aebddd1SJeff Kirsher 	int status;
8999aebddd1SJeff Kirsher 
9009aebddd1SJeff Kirsher 	status = be_cmd_mccq_ext_create(adapter, mccq, cq);
9019aebddd1SJeff Kirsher 	if (status && !lancer_chip(adapter)) {
9029aebddd1SJeff Kirsher 		dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
9039aebddd1SJeff Kirsher 			"or newer to avoid conflicting priorities between NIC "
9049aebddd1SJeff Kirsher 			"and FCoE traffic");
9059aebddd1SJeff Kirsher 		status = be_cmd_mccq_org_create(adapter, mccq, cq);
9069aebddd1SJeff Kirsher 	}
9079aebddd1SJeff Kirsher 	return status;
9089aebddd1SJeff Kirsher }
9099aebddd1SJeff Kirsher 
9109aebddd1SJeff Kirsher int be_cmd_txq_create(struct be_adapter *adapter,
9119aebddd1SJeff Kirsher 			struct be_queue_info *txq,
9129aebddd1SJeff Kirsher 			struct be_queue_info *cq)
9139aebddd1SJeff Kirsher {
9149aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
9159aebddd1SJeff Kirsher 	struct be_cmd_req_eth_tx_create *req;
9169aebddd1SJeff Kirsher 	struct be_dma_mem *q_mem = &txq->dma_mem;
9179aebddd1SJeff Kirsher 	void *ctxt;
9189aebddd1SJeff Kirsher 	int status;
9199aebddd1SJeff Kirsher 
920293c4a7dSPadmanabh Ratnakar 	spin_lock_bh(&adapter->mcc_lock);
9219aebddd1SJeff Kirsher 
922293c4a7dSPadmanabh Ratnakar 	wrb = wrb_from_mccq(adapter);
923293c4a7dSPadmanabh Ratnakar 	if (!wrb) {
924293c4a7dSPadmanabh Ratnakar 		status = -EBUSY;
925293c4a7dSPadmanabh Ratnakar 		goto err;
926293c4a7dSPadmanabh Ratnakar 	}
927293c4a7dSPadmanabh Ratnakar 
9289aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
9299aebddd1SJeff Kirsher 	ctxt = &req->context;
9309aebddd1SJeff Kirsher 
931106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
932106df1e3SSomnath Kotur 		OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
9339aebddd1SJeff Kirsher 
9349aebddd1SJeff Kirsher 	if (lancer_chip(adapter)) {
9359aebddd1SJeff Kirsher 		req->hdr.version = 1;
9369aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
9379aebddd1SJeff Kirsher 					adapter->if_handle);
9389aebddd1SJeff Kirsher 	}
9399aebddd1SJeff Kirsher 
9409aebddd1SJeff Kirsher 	req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
9419aebddd1SJeff Kirsher 	req->ulp_num = BE_ULP1_NUM;
9429aebddd1SJeff Kirsher 	req->type = BE_ETH_TX_RING_TYPE_STANDARD;
9439aebddd1SJeff Kirsher 
9449aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
9459aebddd1SJeff Kirsher 		be_encoded_q_len(txq->len));
9469aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
9479aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
9489aebddd1SJeff Kirsher 
9499aebddd1SJeff Kirsher 	be_dws_cpu_to_le(ctxt, sizeof(req->context));
9509aebddd1SJeff Kirsher 
9519aebddd1SJeff Kirsher 	be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
9529aebddd1SJeff Kirsher 
953293c4a7dSPadmanabh Ratnakar 	status = be_mcc_notify_wait(adapter);
9549aebddd1SJeff Kirsher 	if (!status) {
9559aebddd1SJeff Kirsher 		struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
9569aebddd1SJeff Kirsher 		txq->id = le16_to_cpu(resp->cid);
9579aebddd1SJeff Kirsher 		txq->created = true;
9589aebddd1SJeff Kirsher 	}
9599aebddd1SJeff Kirsher 
960293c4a7dSPadmanabh Ratnakar err:
961293c4a7dSPadmanabh Ratnakar 	spin_unlock_bh(&adapter->mcc_lock);
9629aebddd1SJeff Kirsher 
9639aebddd1SJeff Kirsher 	return status;
9649aebddd1SJeff Kirsher }
9659aebddd1SJeff Kirsher 
9669aebddd1SJeff Kirsher /* Uses MCC */
9679aebddd1SJeff Kirsher int be_cmd_rxq_create(struct be_adapter *adapter,
9689aebddd1SJeff Kirsher 		struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
9699aebddd1SJeff Kirsher 		u16 max_frame_size, u32 if_id, u32 rss, u8 *rss_id)
9709aebddd1SJeff Kirsher {
9719aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
9729aebddd1SJeff Kirsher 	struct be_cmd_req_eth_rx_create *req;
9739aebddd1SJeff Kirsher 	struct be_dma_mem *q_mem = &rxq->dma_mem;
9749aebddd1SJeff Kirsher 	int status;
9759aebddd1SJeff Kirsher 
9769aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
9779aebddd1SJeff Kirsher 
9789aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
9799aebddd1SJeff Kirsher 	if (!wrb) {
9809aebddd1SJeff Kirsher 		status = -EBUSY;
9819aebddd1SJeff Kirsher 		goto err;
9829aebddd1SJeff Kirsher 	}
9839aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
9849aebddd1SJeff Kirsher 
985106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
986106df1e3SSomnath Kotur 				OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
9879aebddd1SJeff Kirsher 
9889aebddd1SJeff Kirsher 	req->cq_id = cpu_to_le16(cq_id);
9899aebddd1SJeff Kirsher 	req->frag_size = fls(frag_size) - 1;
9909aebddd1SJeff Kirsher 	req->num_pages = 2;
9919aebddd1SJeff Kirsher 	be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
9929aebddd1SJeff Kirsher 	req->interface_id = cpu_to_le32(if_id);
9939aebddd1SJeff Kirsher 	req->max_frame_size = cpu_to_le16(max_frame_size);
9949aebddd1SJeff Kirsher 	req->rss_queue = cpu_to_le32(rss);
9959aebddd1SJeff Kirsher 
9969aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
9979aebddd1SJeff Kirsher 	if (!status) {
9989aebddd1SJeff Kirsher 		struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
9999aebddd1SJeff Kirsher 		rxq->id = le16_to_cpu(resp->id);
10009aebddd1SJeff Kirsher 		rxq->created = true;
10019aebddd1SJeff Kirsher 		*rss_id = resp->rss_id;
10029aebddd1SJeff Kirsher 	}
10039aebddd1SJeff Kirsher 
10049aebddd1SJeff Kirsher err:
10059aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
10069aebddd1SJeff Kirsher 	return status;
10079aebddd1SJeff Kirsher }
10089aebddd1SJeff Kirsher 
10099aebddd1SJeff Kirsher /* Generic destroyer function for all types of queues
10109aebddd1SJeff Kirsher  * Uses Mbox
10119aebddd1SJeff Kirsher  */
10129aebddd1SJeff Kirsher int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
10139aebddd1SJeff Kirsher 		int queue_type)
10149aebddd1SJeff Kirsher {
10159aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
10169aebddd1SJeff Kirsher 	struct be_cmd_req_q_destroy *req;
10179aebddd1SJeff Kirsher 	u8 subsys = 0, opcode = 0;
10189aebddd1SJeff Kirsher 	int status;
10199aebddd1SJeff Kirsher 
10209aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
10219aebddd1SJeff Kirsher 		return -1;
10229aebddd1SJeff Kirsher 
10239aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
10249aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
10259aebddd1SJeff Kirsher 
10269aebddd1SJeff Kirsher 	switch (queue_type) {
10279aebddd1SJeff Kirsher 	case QTYPE_EQ:
10289aebddd1SJeff Kirsher 		subsys = CMD_SUBSYSTEM_COMMON;
10299aebddd1SJeff Kirsher 		opcode = OPCODE_COMMON_EQ_DESTROY;
10309aebddd1SJeff Kirsher 		break;
10319aebddd1SJeff Kirsher 	case QTYPE_CQ:
10329aebddd1SJeff Kirsher 		subsys = CMD_SUBSYSTEM_COMMON;
10339aebddd1SJeff Kirsher 		opcode = OPCODE_COMMON_CQ_DESTROY;
10349aebddd1SJeff Kirsher 		break;
10359aebddd1SJeff Kirsher 	case QTYPE_TXQ:
10369aebddd1SJeff Kirsher 		subsys = CMD_SUBSYSTEM_ETH;
10379aebddd1SJeff Kirsher 		opcode = OPCODE_ETH_TX_DESTROY;
10389aebddd1SJeff Kirsher 		break;
10399aebddd1SJeff Kirsher 	case QTYPE_RXQ:
10409aebddd1SJeff Kirsher 		subsys = CMD_SUBSYSTEM_ETH;
10419aebddd1SJeff Kirsher 		opcode = OPCODE_ETH_RX_DESTROY;
10429aebddd1SJeff Kirsher 		break;
10439aebddd1SJeff Kirsher 	case QTYPE_MCCQ:
10449aebddd1SJeff Kirsher 		subsys = CMD_SUBSYSTEM_COMMON;
10459aebddd1SJeff Kirsher 		opcode = OPCODE_COMMON_MCC_DESTROY;
10469aebddd1SJeff Kirsher 		break;
10479aebddd1SJeff Kirsher 	default:
10489aebddd1SJeff Kirsher 		BUG();
10499aebddd1SJeff Kirsher 	}
10509aebddd1SJeff Kirsher 
1051106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1052106df1e3SSomnath Kotur 				NULL);
10539aebddd1SJeff Kirsher 	req->id = cpu_to_le16(q->id);
10549aebddd1SJeff Kirsher 
10559aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
10569aebddd1SJeff Kirsher 	if (!status)
10579aebddd1SJeff Kirsher 		q->created = false;
10589aebddd1SJeff Kirsher 
10599aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
10609aebddd1SJeff Kirsher 	return status;
10619aebddd1SJeff Kirsher }
10629aebddd1SJeff Kirsher 
10639aebddd1SJeff Kirsher /* Uses MCC */
10649aebddd1SJeff Kirsher int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
10659aebddd1SJeff Kirsher {
10669aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
10679aebddd1SJeff Kirsher 	struct be_cmd_req_q_destroy *req;
10689aebddd1SJeff Kirsher 	int status;
10699aebddd1SJeff Kirsher 
10709aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
10719aebddd1SJeff Kirsher 
10729aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
10739aebddd1SJeff Kirsher 	if (!wrb) {
10749aebddd1SJeff Kirsher 		status = -EBUSY;
10759aebddd1SJeff Kirsher 		goto err;
10769aebddd1SJeff Kirsher 	}
10779aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
10789aebddd1SJeff Kirsher 
1079106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1080106df1e3SSomnath Kotur 			OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
10819aebddd1SJeff Kirsher 	req->id = cpu_to_le16(q->id);
10829aebddd1SJeff Kirsher 
10839aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
10849aebddd1SJeff Kirsher 	if (!status)
10859aebddd1SJeff Kirsher 		q->created = false;
10869aebddd1SJeff Kirsher 
10879aebddd1SJeff Kirsher err:
10889aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
10899aebddd1SJeff Kirsher 	return status;
10909aebddd1SJeff Kirsher }
10919aebddd1SJeff Kirsher 
10929aebddd1SJeff Kirsher /* Create an rx filtering policy configuration on an i/f
1093f9449ab7SSathya Perla  * Uses MCCQ
10949aebddd1SJeff Kirsher  */
10959aebddd1SJeff Kirsher int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
1096f9449ab7SSathya Perla 		u8 *mac, u32 *if_handle, u32 *pmac_id, u32 domain)
10979aebddd1SJeff Kirsher {
10989aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
10999aebddd1SJeff Kirsher 	struct be_cmd_req_if_create *req;
11009aebddd1SJeff Kirsher 	int status;
11019aebddd1SJeff Kirsher 
1102f9449ab7SSathya Perla 	spin_lock_bh(&adapter->mcc_lock);
11039aebddd1SJeff Kirsher 
1104f9449ab7SSathya Perla 	wrb = wrb_from_mccq(adapter);
1105f9449ab7SSathya Perla 	if (!wrb) {
1106f9449ab7SSathya Perla 		status = -EBUSY;
1107f9449ab7SSathya Perla 		goto err;
1108f9449ab7SSathya Perla 	}
11099aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
11109aebddd1SJeff Kirsher 
1111106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1112106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
11139aebddd1SJeff Kirsher 	req->hdr.domain = domain;
11149aebddd1SJeff Kirsher 	req->capability_flags = cpu_to_le32(cap_flags);
11159aebddd1SJeff Kirsher 	req->enable_flags = cpu_to_le32(en_flags);
1116f9449ab7SSathya Perla 	if (mac)
11179aebddd1SJeff Kirsher 		memcpy(req->mac_addr, mac, ETH_ALEN);
1118f9449ab7SSathya Perla 	else
1119f9449ab7SSathya Perla 		req->pmac_invalid = true;
11209aebddd1SJeff Kirsher 
1121f9449ab7SSathya Perla 	status = be_mcc_notify_wait(adapter);
11229aebddd1SJeff Kirsher 	if (!status) {
11239aebddd1SJeff Kirsher 		struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
11249aebddd1SJeff Kirsher 		*if_handle = le32_to_cpu(resp->interface_id);
1125f9449ab7SSathya Perla 		if (mac)
11269aebddd1SJeff Kirsher 			*pmac_id = le32_to_cpu(resp->pmac_id);
11279aebddd1SJeff Kirsher 	}
11289aebddd1SJeff Kirsher 
1129f9449ab7SSathya Perla err:
1130f9449ab7SSathya Perla 	spin_unlock_bh(&adapter->mcc_lock);
11319aebddd1SJeff Kirsher 	return status;
11329aebddd1SJeff Kirsher }
11339aebddd1SJeff Kirsher 
1134f9449ab7SSathya Perla /* Uses MCCQ */
113530128031SSathya Perla int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
11369aebddd1SJeff Kirsher {
11379aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
11389aebddd1SJeff Kirsher 	struct be_cmd_req_if_destroy *req;
11399aebddd1SJeff Kirsher 	int status;
11409aebddd1SJeff Kirsher 
114130128031SSathya Perla 	if (interface_id == -1)
1142f9449ab7SSathya Perla 		return 0;
11439aebddd1SJeff Kirsher 
1144f9449ab7SSathya Perla 	spin_lock_bh(&adapter->mcc_lock);
1145f9449ab7SSathya Perla 
1146f9449ab7SSathya Perla 	wrb = wrb_from_mccq(adapter);
1147f9449ab7SSathya Perla 	if (!wrb) {
1148f9449ab7SSathya Perla 		status = -EBUSY;
1149f9449ab7SSathya Perla 		goto err;
1150f9449ab7SSathya Perla 	}
11519aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
11529aebddd1SJeff Kirsher 
1153106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1154106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
11559aebddd1SJeff Kirsher 	req->hdr.domain = domain;
11569aebddd1SJeff Kirsher 	req->interface_id = cpu_to_le32(interface_id);
11579aebddd1SJeff Kirsher 
1158f9449ab7SSathya Perla 	status = be_mcc_notify_wait(adapter);
1159f9449ab7SSathya Perla err:
1160f9449ab7SSathya Perla 	spin_unlock_bh(&adapter->mcc_lock);
11619aebddd1SJeff Kirsher 	return status;
11629aebddd1SJeff Kirsher }
11639aebddd1SJeff Kirsher 
11649aebddd1SJeff Kirsher /* Get stats is a non embedded command: the request is not embedded inside
11659aebddd1SJeff Kirsher  * WRB but is a separate dma memory block
11669aebddd1SJeff Kirsher  * Uses asynchronous MCC
11679aebddd1SJeff Kirsher  */
11689aebddd1SJeff Kirsher int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
11699aebddd1SJeff Kirsher {
11709aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
11719aebddd1SJeff Kirsher 	struct be_cmd_req_hdr *hdr;
11729aebddd1SJeff Kirsher 	int status = 0;
11739aebddd1SJeff Kirsher 
11749aebddd1SJeff Kirsher 	if (MODULO(adapter->work_counter, be_get_temp_freq) == 0)
11759aebddd1SJeff Kirsher 		be_cmd_get_die_temperature(adapter);
11769aebddd1SJeff Kirsher 
11779aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
11789aebddd1SJeff Kirsher 
11799aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
11809aebddd1SJeff Kirsher 	if (!wrb) {
11819aebddd1SJeff Kirsher 		status = -EBUSY;
11829aebddd1SJeff Kirsher 		goto err;
11839aebddd1SJeff Kirsher 	}
11849aebddd1SJeff Kirsher 	hdr = nonemb_cmd->va;
11859aebddd1SJeff Kirsher 
1186106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1187106df1e3SSomnath Kotur 		OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
11889aebddd1SJeff Kirsher 
11899aebddd1SJeff Kirsher 	if (adapter->generation == BE_GEN3)
11909aebddd1SJeff Kirsher 		hdr->version = 1;
11919aebddd1SJeff Kirsher 
11929aebddd1SJeff Kirsher 	be_mcc_notify(adapter);
11939aebddd1SJeff Kirsher 	adapter->stats_cmd_sent = true;
11949aebddd1SJeff Kirsher 
11959aebddd1SJeff Kirsher err:
11969aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
11979aebddd1SJeff Kirsher 	return status;
11989aebddd1SJeff Kirsher }
11999aebddd1SJeff Kirsher 
12009aebddd1SJeff Kirsher /* Lancer Stats */
12019aebddd1SJeff Kirsher int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
12029aebddd1SJeff Kirsher 				struct be_dma_mem *nonemb_cmd)
12039aebddd1SJeff Kirsher {
12049aebddd1SJeff Kirsher 
12059aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
12069aebddd1SJeff Kirsher 	struct lancer_cmd_req_pport_stats *req;
12079aebddd1SJeff Kirsher 	int status = 0;
12089aebddd1SJeff Kirsher 
12099aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
12109aebddd1SJeff Kirsher 
12119aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
12129aebddd1SJeff Kirsher 	if (!wrb) {
12139aebddd1SJeff Kirsher 		status = -EBUSY;
12149aebddd1SJeff Kirsher 		goto err;
12159aebddd1SJeff Kirsher 	}
12169aebddd1SJeff Kirsher 	req = nonemb_cmd->va;
12179aebddd1SJeff Kirsher 
1218106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1219106df1e3SSomnath Kotur 			OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1220106df1e3SSomnath Kotur 			nonemb_cmd);
12219aebddd1SJeff Kirsher 
12229aebddd1SJeff Kirsher 	req->cmd_params.params.pport_num = cpu_to_le16(adapter->port_num);
12239aebddd1SJeff Kirsher 	req->cmd_params.params.reset_stats = 0;
12249aebddd1SJeff Kirsher 
12259aebddd1SJeff Kirsher 	be_mcc_notify(adapter);
12269aebddd1SJeff Kirsher 	adapter->stats_cmd_sent = true;
12279aebddd1SJeff Kirsher 
12289aebddd1SJeff Kirsher err:
12299aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
12309aebddd1SJeff Kirsher 	return status;
12319aebddd1SJeff Kirsher }
12329aebddd1SJeff Kirsher 
12339aebddd1SJeff Kirsher /* Uses synchronous mcc */
12349aebddd1SJeff Kirsher int be_cmd_link_status_query(struct be_adapter *adapter, u8 *mac_speed,
12359aebddd1SJeff Kirsher 			u16 *link_speed, u32 dom)
12369aebddd1SJeff Kirsher {
12379aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
12389aebddd1SJeff Kirsher 	struct be_cmd_req_link_status *req;
12399aebddd1SJeff Kirsher 	int status;
12409aebddd1SJeff Kirsher 
12419aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
12429aebddd1SJeff Kirsher 
12439aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
12449aebddd1SJeff Kirsher 	if (!wrb) {
12459aebddd1SJeff Kirsher 		status = -EBUSY;
12469aebddd1SJeff Kirsher 		goto err;
12479aebddd1SJeff Kirsher 	}
12489aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
12499aebddd1SJeff Kirsher 
1250daad6167SPadmanabh Ratnakar 	if (lancer_chip(adapter))
1251daad6167SPadmanabh Ratnakar 		req->hdr.version = 1;
1252daad6167SPadmanabh Ratnakar 
1253106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1254106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
12559aebddd1SJeff Kirsher 
12569aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
12579aebddd1SJeff Kirsher 	if (!status) {
12589aebddd1SJeff Kirsher 		struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
12599aebddd1SJeff Kirsher 		if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
12609aebddd1SJeff Kirsher 			*link_speed = le16_to_cpu(resp->link_speed);
1261f9449ab7SSathya Perla 			if (mac_speed)
12629aebddd1SJeff Kirsher 				*mac_speed = resp->mac_speed;
12639aebddd1SJeff Kirsher 		}
12649aebddd1SJeff Kirsher 	}
12659aebddd1SJeff Kirsher 
12669aebddd1SJeff Kirsher err:
12679aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
12689aebddd1SJeff Kirsher 	return status;
12699aebddd1SJeff Kirsher }
12709aebddd1SJeff Kirsher 
12719aebddd1SJeff Kirsher /* Uses synchronous mcc */
12729aebddd1SJeff Kirsher int be_cmd_get_die_temperature(struct be_adapter *adapter)
12739aebddd1SJeff Kirsher {
12749aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
12759aebddd1SJeff Kirsher 	struct be_cmd_req_get_cntl_addnl_attribs *req;
12763de09455SSomnath Kotur 	u16 mccq_index;
12779aebddd1SJeff Kirsher 	int status;
12789aebddd1SJeff Kirsher 
12799aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
12809aebddd1SJeff Kirsher 
12813de09455SSomnath Kotur 	mccq_index = adapter->mcc_obj.q.head;
12823de09455SSomnath Kotur 
12839aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
12849aebddd1SJeff Kirsher 	if (!wrb) {
12859aebddd1SJeff Kirsher 		status = -EBUSY;
12869aebddd1SJeff Kirsher 		goto err;
12879aebddd1SJeff Kirsher 	}
12889aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
12899aebddd1SJeff Kirsher 
1290106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1291106df1e3SSomnath Kotur 		OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1292106df1e3SSomnath Kotur 		wrb, NULL);
12939aebddd1SJeff Kirsher 
12943de09455SSomnath Kotur 	wrb->tag1 = mccq_index;
12953de09455SSomnath Kotur 
12963de09455SSomnath Kotur 	be_mcc_notify(adapter);
12979aebddd1SJeff Kirsher 
12989aebddd1SJeff Kirsher err:
12999aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
13009aebddd1SJeff Kirsher 	return status;
13019aebddd1SJeff Kirsher }
13029aebddd1SJeff Kirsher 
13039aebddd1SJeff Kirsher /* Uses synchronous mcc */
13049aebddd1SJeff Kirsher int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
13059aebddd1SJeff Kirsher {
13069aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
13079aebddd1SJeff Kirsher 	struct be_cmd_req_get_fat *req;
13089aebddd1SJeff Kirsher 	int status;
13099aebddd1SJeff Kirsher 
13109aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
13119aebddd1SJeff Kirsher 
13129aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
13139aebddd1SJeff Kirsher 	if (!wrb) {
13149aebddd1SJeff Kirsher 		status = -EBUSY;
13159aebddd1SJeff Kirsher 		goto err;
13169aebddd1SJeff Kirsher 	}
13179aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
13189aebddd1SJeff Kirsher 
1319106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1320106df1e3SSomnath Kotur 		OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
13219aebddd1SJeff Kirsher 	req->fat_operation = cpu_to_le32(QUERY_FAT);
13229aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
13239aebddd1SJeff Kirsher 	if (!status) {
13249aebddd1SJeff Kirsher 		struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
13259aebddd1SJeff Kirsher 		if (log_size && resp->log_size)
13269aebddd1SJeff Kirsher 			*log_size = le32_to_cpu(resp->log_size) -
13279aebddd1SJeff Kirsher 					sizeof(u32);
13289aebddd1SJeff Kirsher 	}
13299aebddd1SJeff Kirsher err:
13309aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
13319aebddd1SJeff Kirsher 	return status;
13329aebddd1SJeff Kirsher }
13339aebddd1SJeff Kirsher 
13349aebddd1SJeff Kirsher void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
13359aebddd1SJeff Kirsher {
13369aebddd1SJeff Kirsher 	struct be_dma_mem get_fat_cmd;
13379aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
13389aebddd1SJeff Kirsher 	struct be_cmd_req_get_fat *req;
13399aebddd1SJeff Kirsher 	u32 offset = 0, total_size, buf_size,
13409aebddd1SJeff Kirsher 				log_offset = sizeof(u32), payload_len;
13419aebddd1SJeff Kirsher 	int status;
13429aebddd1SJeff Kirsher 
13439aebddd1SJeff Kirsher 	if (buf_len == 0)
13449aebddd1SJeff Kirsher 		return;
13459aebddd1SJeff Kirsher 
13469aebddd1SJeff Kirsher 	total_size = buf_len;
13479aebddd1SJeff Kirsher 
13489aebddd1SJeff Kirsher 	get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
13499aebddd1SJeff Kirsher 	get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
13509aebddd1SJeff Kirsher 			get_fat_cmd.size,
13519aebddd1SJeff Kirsher 			&get_fat_cmd.dma);
13529aebddd1SJeff Kirsher 	if (!get_fat_cmd.va) {
13539aebddd1SJeff Kirsher 		status = -ENOMEM;
13549aebddd1SJeff Kirsher 		dev_err(&adapter->pdev->dev,
13559aebddd1SJeff Kirsher 		"Memory allocation failure while retrieving FAT data\n");
13569aebddd1SJeff Kirsher 		return;
13579aebddd1SJeff Kirsher 	}
13589aebddd1SJeff Kirsher 
13599aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
13609aebddd1SJeff Kirsher 
13619aebddd1SJeff Kirsher 	while (total_size) {
13629aebddd1SJeff Kirsher 		buf_size = min(total_size, (u32)60*1024);
13639aebddd1SJeff Kirsher 		total_size -= buf_size;
13649aebddd1SJeff Kirsher 
13659aebddd1SJeff Kirsher 		wrb = wrb_from_mccq(adapter);
13669aebddd1SJeff Kirsher 		if (!wrb) {
13679aebddd1SJeff Kirsher 			status = -EBUSY;
13689aebddd1SJeff Kirsher 			goto err;
13699aebddd1SJeff Kirsher 		}
13709aebddd1SJeff Kirsher 		req = get_fat_cmd.va;
13719aebddd1SJeff Kirsher 
13729aebddd1SJeff Kirsher 		payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
1373106df1e3SSomnath Kotur 		be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1374106df1e3SSomnath Kotur 				OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1375106df1e3SSomnath Kotur 				&get_fat_cmd);
13769aebddd1SJeff Kirsher 
13779aebddd1SJeff Kirsher 		req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
13789aebddd1SJeff Kirsher 		req->read_log_offset = cpu_to_le32(log_offset);
13799aebddd1SJeff Kirsher 		req->read_log_length = cpu_to_le32(buf_size);
13809aebddd1SJeff Kirsher 		req->data_buffer_size = cpu_to_le32(buf_size);
13819aebddd1SJeff Kirsher 
13829aebddd1SJeff Kirsher 		status = be_mcc_notify_wait(adapter);
13839aebddd1SJeff Kirsher 		if (!status) {
13849aebddd1SJeff Kirsher 			struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
13859aebddd1SJeff Kirsher 			memcpy(buf + offset,
13869aebddd1SJeff Kirsher 				resp->data_buffer,
138792aa9214SSomnath Kotur 				le32_to_cpu(resp->read_log_length));
13889aebddd1SJeff Kirsher 		} else {
13899aebddd1SJeff Kirsher 			dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
13909aebddd1SJeff Kirsher 			goto err;
13919aebddd1SJeff Kirsher 		}
13929aebddd1SJeff Kirsher 		offset += buf_size;
13939aebddd1SJeff Kirsher 		log_offset += buf_size;
13949aebddd1SJeff Kirsher 	}
13959aebddd1SJeff Kirsher err:
13969aebddd1SJeff Kirsher 	pci_free_consistent(adapter->pdev, get_fat_cmd.size,
13979aebddd1SJeff Kirsher 			get_fat_cmd.va,
13989aebddd1SJeff Kirsher 			get_fat_cmd.dma);
13999aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
14009aebddd1SJeff Kirsher }
14019aebddd1SJeff Kirsher 
140204b71175SSathya Perla /* Uses synchronous mcc */
140304b71175SSathya Perla int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
140404b71175SSathya Perla 			char *fw_on_flash)
14059aebddd1SJeff Kirsher {
14069aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
14079aebddd1SJeff Kirsher 	struct be_cmd_req_get_fw_version *req;
14089aebddd1SJeff Kirsher 	int status;
14099aebddd1SJeff Kirsher 
141004b71175SSathya Perla 	spin_lock_bh(&adapter->mcc_lock);
14119aebddd1SJeff Kirsher 
141204b71175SSathya Perla 	wrb = wrb_from_mccq(adapter);
141304b71175SSathya Perla 	if (!wrb) {
141404b71175SSathya Perla 		status = -EBUSY;
141504b71175SSathya Perla 		goto err;
141604b71175SSathya Perla 	}
141704b71175SSathya Perla 
14189aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
14199aebddd1SJeff Kirsher 
1420106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1421106df1e3SSomnath Kotur 		OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
142204b71175SSathya Perla 	status = be_mcc_notify_wait(adapter);
14239aebddd1SJeff Kirsher 	if (!status) {
14249aebddd1SJeff Kirsher 		struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
142504b71175SSathya Perla 		strcpy(fw_ver, resp->firmware_version_string);
142604b71175SSathya Perla 		if (fw_on_flash)
142704b71175SSathya Perla 			strcpy(fw_on_flash, resp->fw_on_flash_version_string);
14289aebddd1SJeff Kirsher 	}
142904b71175SSathya Perla err:
143004b71175SSathya Perla 	spin_unlock_bh(&adapter->mcc_lock);
14319aebddd1SJeff Kirsher 	return status;
14329aebddd1SJeff Kirsher }
14339aebddd1SJeff Kirsher 
14349aebddd1SJeff Kirsher /* set the EQ delay interval of an EQ to specified value
14359aebddd1SJeff Kirsher  * Uses async mcc
14369aebddd1SJeff Kirsher  */
14379aebddd1SJeff Kirsher int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
14389aebddd1SJeff Kirsher {
14399aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
14409aebddd1SJeff Kirsher 	struct be_cmd_req_modify_eq_delay *req;
14419aebddd1SJeff Kirsher 	int status = 0;
14429aebddd1SJeff Kirsher 
14439aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
14449aebddd1SJeff Kirsher 
14459aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
14469aebddd1SJeff Kirsher 	if (!wrb) {
14479aebddd1SJeff Kirsher 		status = -EBUSY;
14489aebddd1SJeff Kirsher 		goto err;
14499aebddd1SJeff Kirsher 	}
14509aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
14519aebddd1SJeff Kirsher 
1452106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1453106df1e3SSomnath Kotur 		OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
14549aebddd1SJeff Kirsher 
14559aebddd1SJeff Kirsher 	req->num_eq = cpu_to_le32(1);
14569aebddd1SJeff Kirsher 	req->delay[0].eq_id = cpu_to_le32(eq_id);
14579aebddd1SJeff Kirsher 	req->delay[0].phase = 0;
14589aebddd1SJeff Kirsher 	req->delay[0].delay_multiplier = cpu_to_le32(eqd);
14599aebddd1SJeff Kirsher 
14609aebddd1SJeff Kirsher 	be_mcc_notify(adapter);
14619aebddd1SJeff Kirsher 
14629aebddd1SJeff Kirsher err:
14639aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
14649aebddd1SJeff Kirsher 	return status;
14659aebddd1SJeff Kirsher }
14669aebddd1SJeff Kirsher 
14679aebddd1SJeff Kirsher /* Uses sycnhronous mcc */
14689aebddd1SJeff Kirsher int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
14699aebddd1SJeff Kirsher 			u32 num, bool untagged, bool promiscuous)
14709aebddd1SJeff Kirsher {
14719aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
14729aebddd1SJeff Kirsher 	struct be_cmd_req_vlan_config *req;
14739aebddd1SJeff Kirsher 	int status;
14749aebddd1SJeff Kirsher 
14759aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
14769aebddd1SJeff Kirsher 
14779aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
14789aebddd1SJeff Kirsher 	if (!wrb) {
14799aebddd1SJeff Kirsher 		status = -EBUSY;
14809aebddd1SJeff Kirsher 		goto err;
14819aebddd1SJeff Kirsher 	}
14829aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
14839aebddd1SJeff Kirsher 
1484106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1485106df1e3SSomnath Kotur 		OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
14869aebddd1SJeff Kirsher 
14879aebddd1SJeff Kirsher 	req->interface_id = if_id;
14889aebddd1SJeff Kirsher 	req->promiscuous = promiscuous;
14899aebddd1SJeff Kirsher 	req->untagged = untagged;
14909aebddd1SJeff Kirsher 	req->num_vlan = num;
14919aebddd1SJeff Kirsher 	if (!promiscuous) {
14929aebddd1SJeff Kirsher 		memcpy(req->normal_vlan, vtag_array,
14939aebddd1SJeff Kirsher 			req->num_vlan * sizeof(vtag_array[0]));
14949aebddd1SJeff Kirsher 	}
14959aebddd1SJeff Kirsher 
14969aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
14979aebddd1SJeff Kirsher 
14989aebddd1SJeff Kirsher err:
14999aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
15009aebddd1SJeff Kirsher 	return status;
15019aebddd1SJeff Kirsher }
15029aebddd1SJeff Kirsher 
15039aebddd1SJeff Kirsher int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
15049aebddd1SJeff Kirsher {
15059aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
15069aebddd1SJeff Kirsher 	struct be_dma_mem *mem = &adapter->rx_filter;
15079aebddd1SJeff Kirsher 	struct be_cmd_req_rx_filter *req = mem->va;
15089aebddd1SJeff Kirsher 	int status;
15099aebddd1SJeff Kirsher 
15109aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
15119aebddd1SJeff Kirsher 
15129aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
15139aebddd1SJeff Kirsher 	if (!wrb) {
15149aebddd1SJeff Kirsher 		status = -EBUSY;
15159aebddd1SJeff Kirsher 		goto err;
15169aebddd1SJeff Kirsher 	}
15179aebddd1SJeff Kirsher 	memset(req, 0, sizeof(*req));
1518106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1519106df1e3SSomnath Kotur 				OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1520106df1e3SSomnath Kotur 				wrb, mem);
15219aebddd1SJeff Kirsher 
15229aebddd1SJeff Kirsher 	req->if_id = cpu_to_le32(adapter->if_handle);
15239aebddd1SJeff Kirsher 	if (flags & IFF_PROMISC) {
15249aebddd1SJeff Kirsher 		req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
15259aebddd1SJeff Kirsher 					BE_IF_FLAGS_VLAN_PROMISCUOUS);
15269aebddd1SJeff Kirsher 		if (value == ON)
15279aebddd1SJeff Kirsher 			req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
15289aebddd1SJeff Kirsher 						BE_IF_FLAGS_VLAN_PROMISCUOUS);
15299aebddd1SJeff Kirsher 	} else if (flags & IFF_ALLMULTI) {
15309aebddd1SJeff Kirsher 		req->if_flags_mask = req->if_flags =
15319aebddd1SJeff Kirsher 				cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
15329aebddd1SJeff Kirsher 	} else {
15339aebddd1SJeff Kirsher 		struct netdev_hw_addr *ha;
15349aebddd1SJeff Kirsher 		int i = 0;
15359aebddd1SJeff Kirsher 
15368e7d3f68SSathya Perla 		req->if_flags_mask = req->if_flags =
15378e7d3f68SSathya Perla 				cpu_to_le32(BE_IF_FLAGS_MULTICAST);
15381610c79fSPadmanabh Ratnakar 
15391610c79fSPadmanabh Ratnakar 		/* Reset mcast promisc mode if already set by setting mask
15401610c79fSPadmanabh Ratnakar 		 * and not setting flags field
15411610c79fSPadmanabh Ratnakar 		 */
15421610c79fSPadmanabh Ratnakar 		req->if_flags_mask |=
15431610c79fSPadmanabh Ratnakar 				cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
15441610c79fSPadmanabh Ratnakar 
1545016f97b1SPadmanabh Ratnakar 		req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
15469aebddd1SJeff Kirsher 		netdev_for_each_mc_addr(ha, adapter->netdev)
15479aebddd1SJeff Kirsher 			memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
15489aebddd1SJeff Kirsher 	}
15499aebddd1SJeff Kirsher 
15509aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
15519aebddd1SJeff Kirsher err:
15529aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
15539aebddd1SJeff Kirsher 	return status;
15549aebddd1SJeff Kirsher }
15559aebddd1SJeff Kirsher 
15569aebddd1SJeff Kirsher /* Uses synchrounous mcc */
15579aebddd1SJeff Kirsher int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
15589aebddd1SJeff Kirsher {
15599aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
15609aebddd1SJeff Kirsher 	struct be_cmd_req_set_flow_control *req;
15619aebddd1SJeff Kirsher 	int status;
15629aebddd1SJeff Kirsher 
15639aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
15649aebddd1SJeff Kirsher 
15659aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
15669aebddd1SJeff Kirsher 	if (!wrb) {
15679aebddd1SJeff Kirsher 		status = -EBUSY;
15689aebddd1SJeff Kirsher 		goto err;
15699aebddd1SJeff Kirsher 	}
15709aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
15719aebddd1SJeff Kirsher 
1572106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1573106df1e3SSomnath Kotur 		OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
15749aebddd1SJeff Kirsher 
15759aebddd1SJeff Kirsher 	req->tx_flow_control = cpu_to_le16((u16)tx_fc);
15769aebddd1SJeff Kirsher 	req->rx_flow_control = cpu_to_le16((u16)rx_fc);
15779aebddd1SJeff Kirsher 
15789aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
15799aebddd1SJeff Kirsher 
15809aebddd1SJeff Kirsher err:
15819aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
15829aebddd1SJeff Kirsher 	return status;
15839aebddd1SJeff Kirsher }
15849aebddd1SJeff Kirsher 
15859aebddd1SJeff Kirsher /* Uses sycn mcc */
15869aebddd1SJeff Kirsher int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
15879aebddd1SJeff Kirsher {
15889aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
15899aebddd1SJeff Kirsher 	struct be_cmd_req_get_flow_control *req;
15909aebddd1SJeff Kirsher 	int status;
15919aebddd1SJeff Kirsher 
15929aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
15939aebddd1SJeff Kirsher 
15949aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
15959aebddd1SJeff Kirsher 	if (!wrb) {
15969aebddd1SJeff Kirsher 		status = -EBUSY;
15979aebddd1SJeff Kirsher 		goto err;
15989aebddd1SJeff Kirsher 	}
15999aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
16009aebddd1SJeff Kirsher 
1601106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1602106df1e3SSomnath Kotur 		OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
16039aebddd1SJeff Kirsher 
16049aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
16059aebddd1SJeff Kirsher 	if (!status) {
16069aebddd1SJeff Kirsher 		struct be_cmd_resp_get_flow_control *resp =
16079aebddd1SJeff Kirsher 						embedded_payload(wrb);
16089aebddd1SJeff Kirsher 		*tx_fc = le16_to_cpu(resp->tx_flow_control);
16099aebddd1SJeff Kirsher 		*rx_fc = le16_to_cpu(resp->rx_flow_control);
16109aebddd1SJeff Kirsher 	}
16119aebddd1SJeff Kirsher 
16129aebddd1SJeff Kirsher err:
16139aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
16149aebddd1SJeff Kirsher 	return status;
16159aebddd1SJeff Kirsher }
16169aebddd1SJeff Kirsher 
16179aebddd1SJeff Kirsher /* Uses mbox */
16189aebddd1SJeff Kirsher int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
16199aebddd1SJeff Kirsher 		u32 *mode, u32 *caps)
16209aebddd1SJeff Kirsher {
16219aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
16229aebddd1SJeff Kirsher 	struct be_cmd_req_query_fw_cfg *req;
16239aebddd1SJeff Kirsher 	int status;
16249aebddd1SJeff Kirsher 
16259aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
16269aebddd1SJeff Kirsher 		return -1;
16279aebddd1SJeff Kirsher 
16289aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
16299aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
16309aebddd1SJeff Kirsher 
1631106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1632106df1e3SSomnath Kotur 		OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
16339aebddd1SJeff Kirsher 
16349aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
16359aebddd1SJeff Kirsher 	if (!status) {
16369aebddd1SJeff Kirsher 		struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
16379aebddd1SJeff Kirsher 		*port_num = le32_to_cpu(resp->phys_port);
16389aebddd1SJeff Kirsher 		*mode = le32_to_cpu(resp->function_mode);
16399aebddd1SJeff Kirsher 		*caps = le32_to_cpu(resp->function_caps);
16409aebddd1SJeff Kirsher 	}
16419aebddd1SJeff Kirsher 
16429aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
16439aebddd1SJeff Kirsher 	return status;
16449aebddd1SJeff Kirsher }
16459aebddd1SJeff Kirsher 
16469aebddd1SJeff Kirsher /* Uses mbox */
16479aebddd1SJeff Kirsher int be_cmd_reset_function(struct be_adapter *adapter)
16489aebddd1SJeff Kirsher {
16499aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
16509aebddd1SJeff Kirsher 	struct be_cmd_req_hdr *req;
16519aebddd1SJeff Kirsher 	int status;
16529aebddd1SJeff Kirsher 
16539aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
16549aebddd1SJeff Kirsher 		return -1;
16559aebddd1SJeff Kirsher 
16569aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
16579aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
16589aebddd1SJeff Kirsher 
1659106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1660106df1e3SSomnath Kotur 		OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
16619aebddd1SJeff Kirsher 
16629aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
16639aebddd1SJeff Kirsher 
16649aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
16659aebddd1SJeff Kirsher 	return status;
16669aebddd1SJeff Kirsher }
16679aebddd1SJeff Kirsher 
16689aebddd1SJeff Kirsher int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
16699aebddd1SJeff Kirsher {
16709aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
16719aebddd1SJeff Kirsher 	struct be_cmd_req_rss_config *req;
16729aebddd1SJeff Kirsher 	u32 myhash[10] = {0x0123, 0x4567, 0x89AB, 0xCDEF, 0x01EF,
16739aebddd1SJeff Kirsher 			0x0123, 0x4567, 0x89AB, 0xCDEF, 0x01EF};
16749aebddd1SJeff Kirsher 	int status;
16759aebddd1SJeff Kirsher 
16769aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
16779aebddd1SJeff Kirsher 		return -1;
16789aebddd1SJeff Kirsher 
16799aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
16809aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
16819aebddd1SJeff Kirsher 
1682106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1683106df1e3SSomnath Kotur 		OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
16849aebddd1SJeff Kirsher 
16859aebddd1SJeff Kirsher 	req->if_id = cpu_to_le32(adapter->if_handle);
16869aebddd1SJeff Kirsher 	req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4);
16879aebddd1SJeff Kirsher 	req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
16889aebddd1SJeff Kirsher 	memcpy(req->cpu_table, rsstable, table_size);
16899aebddd1SJeff Kirsher 	memcpy(req->hash, myhash, sizeof(myhash));
16909aebddd1SJeff Kirsher 	be_dws_cpu_to_le(req->hash, sizeof(req->hash));
16919aebddd1SJeff Kirsher 
16929aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
16939aebddd1SJeff Kirsher 
16949aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
16959aebddd1SJeff Kirsher 	return status;
16969aebddd1SJeff Kirsher }
16979aebddd1SJeff Kirsher 
16989aebddd1SJeff Kirsher /* Uses sync mcc */
16999aebddd1SJeff Kirsher int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
17009aebddd1SJeff Kirsher 			u8 bcn, u8 sts, u8 state)
17019aebddd1SJeff Kirsher {
17029aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
17039aebddd1SJeff Kirsher 	struct be_cmd_req_enable_disable_beacon *req;
17049aebddd1SJeff Kirsher 	int status;
17059aebddd1SJeff Kirsher 
17069aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
17079aebddd1SJeff Kirsher 
17089aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
17099aebddd1SJeff Kirsher 	if (!wrb) {
17109aebddd1SJeff Kirsher 		status = -EBUSY;
17119aebddd1SJeff Kirsher 		goto err;
17129aebddd1SJeff Kirsher 	}
17139aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
17149aebddd1SJeff Kirsher 
1715106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1716106df1e3SSomnath Kotur 		OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
17179aebddd1SJeff Kirsher 
17189aebddd1SJeff Kirsher 	req->port_num = port_num;
17199aebddd1SJeff Kirsher 	req->beacon_state = state;
17209aebddd1SJeff Kirsher 	req->beacon_duration = bcn;
17219aebddd1SJeff Kirsher 	req->status_duration = sts;
17229aebddd1SJeff Kirsher 
17239aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
17249aebddd1SJeff Kirsher 
17259aebddd1SJeff Kirsher err:
17269aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
17279aebddd1SJeff Kirsher 	return status;
17289aebddd1SJeff Kirsher }
17299aebddd1SJeff Kirsher 
17309aebddd1SJeff Kirsher /* Uses sync mcc */
17319aebddd1SJeff Kirsher int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
17329aebddd1SJeff Kirsher {
17339aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
17349aebddd1SJeff Kirsher 	struct be_cmd_req_get_beacon_state *req;
17359aebddd1SJeff Kirsher 	int status;
17369aebddd1SJeff Kirsher 
17379aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
17389aebddd1SJeff Kirsher 
17399aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
17409aebddd1SJeff Kirsher 	if (!wrb) {
17419aebddd1SJeff Kirsher 		status = -EBUSY;
17429aebddd1SJeff Kirsher 		goto err;
17439aebddd1SJeff Kirsher 	}
17449aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
17459aebddd1SJeff Kirsher 
1746106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1747106df1e3SSomnath Kotur 		OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
17489aebddd1SJeff Kirsher 
17499aebddd1SJeff Kirsher 	req->port_num = port_num;
17509aebddd1SJeff Kirsher 
17519aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
17529aebddd1SJeff Kirsher 	if (!status) {
17539aebddd1SJeff Kirsher 		struct be_cmd_resp_get_beacon_state *resp =
17549aebddd1SJeff Kirsher 						embedded_payload(wrb);
17559aebddd1SJeff Kirsher 		*state = resp->beacon_state;
17569aebddd1SJeff Kirsher 	}
17579aebddd1SJeff Kirsher 
17589aebddd1SJeff Kirsher err:
17599aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
17609aebddd1SJeff Kirsher 	return status;
17619aebddd1SJeff Kirsher }
17629aebddd1SJeff Kirsher 
17639aebddd1SJeff Kirsher int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
17649aebddd1SJeff Kirsher 			u32 data_size, u32 data_offset, const char *obj_name,
17659aebddd1SJeff Kirsher 			u32 *data_written, u8 *addn_status)
17669aebddd1SJeff Kirsher {
17679aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
17689aebddd1SJeff Kirsher 	struct lancer_cmd_req_write_object *req;
17699aebddd1SJeff Kirsher 	struct lancer_cmd_resp_write_object *resp;
17709aebddd1SJeff Kirsher 	void *ctxt = NULL;
17719aebddd1SJeff Kirsher 	int status;
17729aebddd1SJeff Kirsher 
17739aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
17749aebddd1SJeff Kirsher 	adapter->flash_status = 0;
17759aebddd1SJeff Kirsher 
17769aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
17779aebddd1SJeff Kirsher 	if (!wrb) {
17789aebddd1SJeff Kirsher 		status = -EBUSY;
17799aebddd1SJeff Kirsher 		goto err_unlock;
17809aebddd1SJeff Kirsher 	}
17819aebddd1SJeff Kirsher 
17829aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
17839aebddd1SJeff Kirsher 
1784106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
17859aebddd1SJeff Kirsher 				OPCODE_COMMON_WRITE_OBJECT,
1786106df1e3SSomnath Kotur 				sizeof(struct lancer_cmd_req_write_object), wrb,
1787106df1e3SSomnath Kotur 				NULL);
17889aebddd1SJeff Kirsher 
17899aebddd1SJeff Kirsher 	ctxt = &req->context;
17909aebddd1SJeff Kirsher 	AMAP_SET_BITS(struct amap_lancer_write_obj_context,
17919aebddd1SJeff Kirsher 			write_length, ctxt, data_size);
17929aebddd1SJeff Kirsher 
17939aebddd1SJeff Kirsher 	if (data_size == 0)
17949aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_lancer_write_obj_context,
17959aebddd1SJeff Kirsher 				eof, ctxt, 1);
17969aebddd1SJeff Kirsher 	else
17979aebddd1SJeff Kirsher 		AMAP_SET_BITS(struct amap_lancer_write_obj_context,
17989aebddd1SJeff Kirsher 				eof, ctxt, 0);
17999aebddd1SJeff Kirsher 
18009aebddd1SJeff Kirsher 	be_dws_cpu_to_le(ctxt, sizeof(req->context));
18019aebddd1SJeff Kirsher 	req->write_offset = cpu_to_le32(data_offset);
18029aebddd1SJeff Kirsher 	strcpy(req->object_name, obj_name);
18039aebddd1SJeff Kirsher 	req->descriptor_count = cpu_to_le32(1);
18049aebddd1SJeff Kirsher 	req->buf_len = cpu_to_le32(data_size);
18059aebddd1SJeff Kirsher 	req->addr_low = cpu_to_le32((cmd->dma +
18069aebddd1SJeff Kirsher 				sizeof(struct lancer_cmd_req_write_object))
18079aebddd1SJeff Kirsher 				& 0xFFFFFFFF);
18089aebddd1SJeff Kirsher 	req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
18099aebddd1SJeff Kirsher 				sizeof(struct lancer_cmd_req_write_object)));
18109aebddd1SJeff Kirsher 
18119aebddd1SJeff Kirsher 	be_mcc_notify(adapter);
18129aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
18139aebddd1SJeff Kirsher 
18149aebddd1SJeff Kirsher 	if (!wait_for_completion_timeout(&adapter->flash_compl,
18159aebddd1SJeff Kirsher 			msecs_to_jiffies(12000)))
18169aebddd1SJeff Kirsher 		status = -1;
18179aebddd1SJeff Kirsher 	else
18189aebddd1SJeff Kirsher 		status = adapter->flash_status;
18199aebddd1SJeff Kirsher 
18209aebddd1SJeff Kirsher 	resp = embedded_payload(wrb);
18219aebddd1SJeff Kirsher 	if (!status) {
18229aebddd1SJeff Kirsher 		*data_written = le32_to_cpu(resp->actual_write_len);
18239aebddd1SJeff Kirsher 	} else {
18249aebddd1SJeff Kirsher 		*addn_status = resp->additional_status;
18259aebddd1SJeff Kirsher 		status = resp->status;
18269aebddd1SJeff Kirsher 	}
18279aebddd1SJeff Kirsher 
18289aebddd1SJeff Kirsher 	return status;
18299aebddd1SJeff Kirsher 
18309aebddd1SJeff Kirsher err_unlock:
18319aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
18329aebddd1SJeff Kirsher 	return status;
18339aebddd1SJeff Kirsher }
18349aebddd1SJeff Kirsher 
1835de49bd5aSPadmanabh Ratnakar int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
1836de49bd5aSPadmanabh Ratnakar 		u32 data_size, u32 data_offset, const char *obj_name,
1837de49bd5aSPadmanabh Ratnakar 		u32 *data_read, u32 *eof, u8 *addn_status)
1838de49bd5aSPadmanabh Ratnakar {
1839de49bd5aSPadmanabh Ratnakar 	struct be_mcc_wrb *wrb;
1840de49bd5aSPadmanabh Ratnakar 	struct lancer_cmd_req_read_object *req;
1841de49bd5aSPadmanabh Ratnakar 	struct lancer_cmd_resp_read_object *resp;
1842de49bd5aSPadmanabh Ratnakar 	int status;
1843de49bd5aSPadmanabh Ratnakar 
1844de49bd5aSPadmanabh Ratnakar 	spin_lock_bh(&adapter->mcc_lock);
1845de49bd5aSPadmanabh Ratnakar 
1846de49bd5aSPadmanabh Ratnakar 	wrb = wrb_from_mccq(adapter);
1847de49bd5aSPadmanabh Ratnakar 	if (!wrb) {
1848de49bd5aSPadmanabh Ratnakar 		status = -EBUSY;
1849de49bd5aSPadmanabh Ratnakar 		goto err_unlock;
1850de49bd5aSPadmanabh Ratnakar 	}
1851de49bd5aSPadmanabh Ratnakar 
1852de49bd5aSPadmanabh Ratnakar 	req = embedded_payload(wrb);
1853de49bd5aSPadmanabh Ratnakar 
1854de49bd5aSPadmanabh Ratnakar 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1855de49bd5aSPadmanabh Ratnakar 			OPCODE_COMMON_READ_OBJECT,
1856de49bd5aSPadmanabh Ratnakar 			sizeof(struct lancer_cmd_req_read_object), wrb,
1857de49bd5aSPadmanabh Ratnakar 			NULL);
1858de49bd5aSPadmanabh Ratnakar 
1859de49bd5aSPadmanabh Ratnakar 	req->desired_read_len = cpu_to_le32(data_size);
1860de49bd5aSPadmanabh Ratnakar 	req->read_offset = cpu_to_le32(data_offset);
1861de49bd5aSPadmanabh Ratnakar 	strcpy(req->object_name, obj_name);
1862de49bd5aSPadmanabh Ratnakar 	req->descriptor_count = cpu_to_le32(1);
1863de49bd5aSPadmanabh Ratnakar 	req->buf_len = cpu_to_le32(data_size);
1864de49bd5aSPadmanabh Ratnakar 	req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
1865de49bd5aSPadmanabh Ratnakar 	req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
1866de49bd5aSPadmanabh Ratnakar 
1867de49bd5aSPadmanabh Ratnakar 	status = be_mcc_notify_wait(adapter);
1868de49bd5aSPadmanabh Ratnakar 
1869de49bd5aSPadmanabh Ratnakar 	resp = embedded_payload(wrb);
1870de49bd5aSPadmanabh Ratnakar 	if (!status) {
1871de49bd5aSPadmanabh Ratnakar 		*data_read = le32_to_cpu(resp->actual_read_len);
1872de49bd5aSPadmanabh Ratnakar 		*eof = le32_to_cpu(resp->eof);
1873de49bd5aSPadmanabh Ratnakar 	} else {
1874de49bd5aSPadmanabh Ratnakar 		*addn_status = resp->additional_status;
1875de49bd5aSPadmanabh Ratnakar 	}
1876de49bd5aSPadmanabh Ratnakar 
1877de49bd5aSPadmanabh Ratnakar err_unlock:
1878de49bd5aSPadmanabh Ratnakar 	spin_unlock_bh(&adapter->mcc_lock);
1879de49bd5aSPadmanabh Ratnakar 	return status;
1880de49bd5aSPadmanabh Ratnakar }
1881de49bd5aSPadmanabh Ratnakar 
18829aebddd1SJeff Kirsher int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
18839aebddd1SJeff Kirsher 			u32 flash_type, u32 flash_opcode, u32 buf_size)
18849aebddd1SJeff Kirsher {
18859aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
18869aebddd1SJeff Kirsher 	struct be_cmd_write_flashrom *req;
18879aebddd1SJeff Kirsher 	int status;
18889aebddd1SJeff Kirsher 
18899aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
18909aebddd1SJeff Kirsher 	adapter->flash_status = 0;
18919aebddd1SJeff Kirsher 
18929aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
18939aebddd1SJeff Kirsher 	if (!wrb) {
18949aebddd1SJeff Kirsher 		status = -EBUSY;
18959aebddd1SJeff Kirsher 		goto err_unlock;
18969aebddd1SJeff Kirsher 	}
18979aebddd1SJeff Kirsher 	req = cmd->va;
18989aebddd1SJeff Kirsher 
1899106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1900106df1e3SSomnath Kotur 		OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
19019aebddd1SJeff Kirsher 
19029aebddd1SJeff Kirsher 	req->params.op_type = cpu_to_le32(flash_type);
19039aebddd1SJeff Kirsher 	req->params.op_code = cpu_to_le32(flash_opcode);
19049aebddd1SJeff Kirsher 	req->params.data_buf_size = cpu_to_le32(buf_size);
19059aebddd1SJeff Kirsher 
19069aebddd1SJeff Kirsher 	be_mcc_notify(adapter);
19079aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
19089aebddd1SJeff Kirsher 
19099aebddd1SJeff Kirsher 	if (!wait_for_completion_timeout(&adapter->flash_compl,
1910e2edb7d5SSathya Perla 			msecs_to_jiffies(40000)))
19119aebddd1SJeff Kirsher 		status = -1;
19129aebddd1SJeff Kirsher 	else
19139aebddd1SJeff Kirsher 		status = adapter->flash_status;
19149aebddd1SJeff Kirsher 
19159aebddd1SJeff Kirsher 	return status;
19169aebddd1SJeff Kirsher 
19179aebddd1SJeff Kirsher err_unlock:
19189aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
19199aebddd1SJeff Kirsher 	return status;
19209aebddd1SJeff Kirsher }
19219aebddd1SJeff Kirsher 
19229aebddd1SJeff Kirsher int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
19239aebddd1SJeff Kirsher 			 int offset)
19249aebddd1SJeff Kirsher {
19259aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
19269aebddd1SJeff Kirsher 	struct be_cmd_write_flashrom *req;
19279aebddd1SJeff Kirsher 	int status;
19289aebddd1SJeff Kirsher 
19299aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
19309aebddd1SJeff Kirsher 
19319aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
19329aebddd1SJeff Kirsher 	if (!wrb) {
19339aebddd1SJeff Kirsher 		status = -EBUSY;
19349aebddd1SJeff Kirsher 		goto err;
19359aebddd1SJeff Kirsher 	}
19369aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
19379aebddd1SJeff Kirsher 
1938106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1939106df1e3SSomnath Kotur 		OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4, wrb, NULL);
19409aebddd1SJeff Kirsher 
19419aebddd1SJeff Kirsher 	req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
19429aebddd1SJeff Kirsher 	req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
19439aebddd1SJeff Kirsher 	req->params.offset = cpu_to_le32(offset);
19449aebddd1SJeff Kirsher 	req->params.data_buf_size = cpu_to_le32(0x4);
19459aebddd1SJeff Kirsher 
19469aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
19479aebddd1SJeff Kirsher 	if (!status)
19489aebddd1SJeff Kirsher 		memcpy(flashed_crc, req->params.data_buf, 4);
19499aebddd1SJeff Kirsher 
19509aebddd1SJeff Kirsher err:
19519aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
19529aebddd1SJeff Kirsher 	return status;
19539aebddd1SJeff Kirsher }
19549aebddd1SJeff Kirsher 
19559aebddd1SJeff Kirsher int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
19569aebddd1SJeff Kirsher 				struct be_dma_mem *nonemb_cmd)
19579aebddd1SJeff Kirsher {
19589aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
19599aebddd1SJeff Kirsher 	struct be_cmd_req_acpi_wol_magic_config *req;
19609aebddd1SJeff Kirsher 	int status;
19619aebddd1SJeff Kirsher 
19629aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
19639aebddd1SJeff Kirsher 
19649aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
19659aebddd1SJeff Kirsher 	if (!wrb) {
19669aebddd1SJeff Kirsher 		status = -EBUSY;
19679aebddd1SJeff Kirsher 		goto err;
19689aebddd1SJeff Kirsher 	}
19699aebddd1SJeff Kirsher 	req = nonemb_cmd->va;
19709aebddd1SJeff Kirsher 
1971106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1972106df1e3SSomnath Kotur 		OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
1973106df1e3SSomnath Kotur 		nonemb_cmd);
19749aebddd1SJeff Kirsher 	memcpy(req->magic_mac, mac, ETH_ALEN);
19759aebddd1SJeff Kirsher 
19769aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
19779aebddd1SJeff Kirsher 
19789aebddd1SJeff Kirsher err:
19799aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
19809aebddd1SJeff Kirsher 	return status;
19819aebddd1SJeff Kirsher }
19829aebddd1SJeff Kirsher 
19839aebddd1SJeff Kirsher int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
19849aebddd1SJeff Kirsher 			u8 loopback_type, u8 enable)
19859aebddd1SJeff Kirsher {
19869aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
19879aebddd1SJeff Kirsher 	struct be_cmd_req_set_lmode *req;
19889aebddd1SJeff Kirsher 	int status;
19899aebddd1SJeff Kirsher 
19909aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
19919aebddd1SJeff Kirsher 
19929aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
19939aebddd1SJeff Kirsher 	if (!wrb) {
19949aebddd1SJeff Kirsher 		status = -EBUSY;
19959aebddd1SJeff Kirsher 		goto err;
19969aebddd1SJeff Kirsher 	}
19979aebddd1SJeff Kirsher 
19989aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
19999aebddd1SJeff Kirsher 
2000106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2001106df1e3SSomnath Kotur 			OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2002106df1e3SSomnath Kotur 			NULL);
20039aebddd1SJeff Kirsher 
20049aebddd1SJeff Kirsher 	req->src_port = port_num;
20059aebddd1SJeff Kirsher 	req->dest_port = port_num;
20069aebddd1SJeff Kirsher 	req->loopback_type = loopback_type;
20079aebddd1SJeff Kirsher 	req->loopback_state = enable;
20089aebddd1SJeff Kirsher 
20099aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
20109aebddd1SJeff Kirsher err:
20119aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
20129aebddd1SJeff Kirsher 	return status;
20139aebddd1SJeff Kirsher }
20149aebddd1SJeff Kirsher 
20159aebddd1SJeff Kirsher int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
20169aebddd1SJeff Kirsher 		u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
20179aebddd1SJeff Kirsher {
20189aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
20199aebddd1SJeff Kirsher 	struct be_cmd_req_loopback_test *req;
20209aebddd1SJeff Kirsher 	int status;
20219aebddd1SJeff Kirsher 
20229aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
20239aebddd1SJeff Kirsher 
20249aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
20259aebddd1SJeff Kirsher 	if (!wrb) {
20269aebddd1SJeff Kirsher 		status = -EBUSY;
20279aebddd1SJeff Kirsher 		goto err;
20289aebddd1SJeff Kirsher 	}
20299aebddd1SJeff Kirsher 
20309aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
20319aebddd1SJeff Kirsher 
2032106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2033106df1e3SSomnath Kotur 			OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
20349aebddd1SJeff Kirsher 	req->hdr.timeout = cpu_to_le32(4);
20359aebddd1SJeff Kirsher 
20369aebddd1SJeff Kirsher 	req->pattern = cpu_to_le64(pattern);
20379aebddd1SJeff Kirsher 	req->src_port = cpu_to_le32(port_num);
20389aebddd1SJeff Kirsher 	req->dest_port = cpu_to_le32(port_num);
20399aebddd1SJeff Kirsher 	req->pkt_size = cpu_to_le32(pkt_size);
20409aebddd1SJeff Kirsher 	req->num_pkts = cpu_to_le32(num_pkts);
20419aebddd1SJeff Kirsher 	req->loopback_type = cpu_to_le32(loopback_type);
20429aebddd1SJeff Kirsher 
20439aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
20449aebddd1SJeff Kirsher 	if (!status) {
20459aebddd1SJeff Kirsher 		struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
20469aebddd1SJeff Kirsher 		status = le32_to_cpu(resp->status);
20479aebddd1SJeff Kirsher 	}
20489aebddd1SJeff Kirsher 
20499aebddd1SJeff Kirsher err:
20509aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
20519aebddd1SJeff Kirsher 	return status;
20529aebddd1SJeff Kirsher }
20539aebddd1SJeff Kirsher 
20549aebddd1SJeff Kirsher int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
20559aebddd1SJeff Kirsher 				u32 byte_cnt, struct be_dma_mem *cmd)
20569aebddd1SJeff Kirsher {
20579aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
20589aebddd1SJeff Kirsher 	struct be_cmd_req_ddrdma_test *req;
20599aebddd1SJeff Kirsher 	int status;
20609aebddd1SJeff Kirsher 	int i, j = 0;
20619aebddd1SJeff Kirsher 
20629aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
20639aebddd1SJeff Kirsher 
20649aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
20659aebddd1SJeff Kirsher 	if (!wrb) {
20669aebddd1SJeff Kirsher 		status = -EBUSY;
20679aebddd1SJeff Kirsher 		goto err;
20689aebddd1SJeff Kirsher 	}
20699aebddd1SJeff Kirsher 	req = cmd->va;
2070106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2071106df1e3SSomnath Kotur 			OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
20729aebddd1SJeff Kirsher 
20739aebddd1SJeff Kirsher 	req->pattern = cpu_to_le64(pattern);
20749aebddd1SJeff Kirsher 	req->byte_count = cpu_to_le32(byte_cnt);
20759aebddd1SJeff Kirsher 	for (i = 0; i < byte_cnt; i++) {
20769aebddd1SJeff Kirsher 		req->snd_buff[i] = (u8)(pattern >> (j*8));
20779aebddd1SJeff Kirsher 		j++;
20789aebddd1SJeff Kirsher 		if (j > 7)
20799aebddd1SJeff Kirsher 			j = 0;
20809aebddd1SJeff Kirsher 	}
20819aebddd1SJeff Kirsher 
20829aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
20839aebddd1SJeff Kirsher 
20849aebddd1SJeff Kirsher 	if (!status) {
20859aebddd1SJeff Kirsher 		struct be_cmd_resp_ddrdma_test *resp;
20869aebddd1SJeff Kirsher 		resp = cmd->va;
20879aebddd1SJeff Kirsher 		if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
20889aebddd1SJeff Kirsher 				resp->snd_err) {
20899aebddd1SJeff Kirsher 			status = -1;
20909aebddd1SJeff Kirsher 		}
20919aebddd1SJeff Kirsher 	}
20929aebddd1SJeff Kirsher 
20939aebddd1SJeff Kirsher err:
20949aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
20959aebddd1SJeff Kirsher 	return status;
20969aebddd1SJeff Kirsher }
20979aebddd1SJeff Kirsher 
20989aebddd1SJeff Kirsher int be_cmd_get_seeprom_data(struct be_adapter *adapter,
20999aebddd1SJeff Kirsher 				struct be_dma_mem *nonemb_cmd)
21009aebddd1SJeff Kirsher {
21019aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
21029aebddd1SJeff Kirsher 	struct be_cmd_req_seeprom_read *req;
21039aebddd1SJeff Kirsher 	struct be_sge *sge;
21049aebddd1SJeff Kirsher 	int status;
21059aebddd1SJeff Kirsher 
21069aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
21079aebddd1SJeff Kirsher 
21089aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
21099aebddd1SJeff Kirsher 	if (!wrb) {
21109aebddd1SJeff Kirsher 		status = -EBUSY;
21119aebddd1SJeff Kirsher 		goto err;
21129aebddd1SJeff Kirsher 	}
21139aebddd1SJeff Kirsher 	req = nonemb_cmd->va;
21149aebddd1SJeff Kirsher 	sge = nonembedded_sgl(wrb);
21159aebddd1SJeff Kirsher 
2116106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2117106df1e3SSomnath Kotur 			OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2118106df1e3SSomnath Kotur 			nonemb_cmd);
21199aebddd1SJeff Kirsher 
21209aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
21219aebddd1SJeff Kirsher 
21229aebddd1SJeff Kirsher err:
21239aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
21249aebddd1SJeff Kirsher 	return status;
21259aebddd1SJeff Kirsher }
21269aebddd1SJeff Kirsher 
21279aebddd1SJeff Kirsher int be_cmd_get_phy_info(struct be_adapter *adapter,
21289aebddd1SJeff Kirsher 				struct be_phy_info *phy_info)
21299aebddd1SJeff Kirsher {
21309aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
21319aebddd1SJeff Kirsher 	struct be_cmd_req_get_phy_info *req;
21329aebddd1SJeff Kirsher 	struct be_dma_mem cmd;
21339aebddd1SJeff Kirsher 	int status;
21349aebddd1SJeff Kirsher 
21359aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
21369aebddd1SJeff Kirsher 
21379aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
21389aebddd1SJeff Kirsher 	if (!wrb) {
21399aebddd1SJeff Kirsher 		status = -EBUSY;
21409aebddd1SJeff Kirsher 		goto err;
21419aebddd1SJeff Kirsher 	}
21429aebddd1SJeff Kirsher 	cmd.size = sizeof(struct be_cmd_req_get_phy_info);
21439aebddd1SJeff Kirsher 	cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
21449aebddd1SJeff Kirsher 					&cmd.dma);
21459aebddd1SJeff Kirsher 	if (!cmd.va) {
21469aebddd1SJeff Kirsher 		dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
21479aebddd1SJeff Kirsher 		status = -ENOMEM;
21489aebddd1SJeff Kirsher 		goto err;
21499aebddd1SJeff Kirsher 	}
21509aebddd1SJeff Kirsher 
21519aebddd1SJeff Kirsher 	req = cmd.va;
21529aebddd1SJeff Kirsher 
2153106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2154106df1e3SSomnath Kotur 			OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2155106df1e3SSomnath Kotur 			wrb, &cmd);
21569aebddd1SJeff Kirsher 
21579aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
21589aebddd1SJeff Kirsher 	if (!status) {
21599aebddd1SJeff Kirsher 		struct be_phy_info *resp_phy_info =
21609aebddd1SJeff Kirsher 				cmd.va + sizeof(struct be_cmd_req_hdr);
21619aebddd1SJeff Kirsher 		phy_info->phy_type = le16_to_cpu(resp_phy_info->phy_type);
21629aebddd1SJeff Kirsher 		phy_info->interface_type =
21639aebddd1SJeff Kirsher 			le16_to_cpu(resp_phy_info->interface_type);
21649aebddd1SJeff Kirsher 	}
21659aebddd1SJeff Kirsher 	pci_free_consistent(adapter->pdev, cmd.size,
21669aebddd1SJeff Kirsher 				cmd.va, cmd.dma);
21679aebddd1SJeff Kirsher err:
21689aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
21699aebddd1SJeff Kirsher 	return status;
21709aebddd1SJeff Kirsher }
21719aebddd1SJeff Kirsher 
21729aebddd1SJeff Kirsher int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
21739aebddd1SJeff Kirsher {
21749aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
21759aebddd1SJeff Kirsher 	struct be_cmd_req_set_qos *req;
21769aebddd1SJeff Kirsher 	int status;
21779aebddd1SJeff Kirsher 
21789aebddd1SJeff Kirsher 	spin_lock_bh(&adapter->mcc_lock);
21799aebddd1SJeff Kirsher 
21809aebddd1SJeff Kirsher 	wrb = wrb_from_mccq(adapter);
21819aebddd1SJeff Kirsher 	if (!wrb) {
21829aebddd1SJeff Kirsher 		status = -EBUSY;
21839aebddd1SJeff Kirsher 		goto err;
21849aebddd1SJeff Kirsher 	}
21859aebddd1SJeff Kirsher 
21869aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
21879aebddd1SJeff Kirsher 
2188106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2189106df1e3SSomnath Kotur 			OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
21909aebddd1SJeff Kirsher 
21919aebddd1SJeff Kirsher 	req->hdr.domain = domain;
21929aebddd1SJeff Kirsher 	req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
21939aebddd1SJeff Kirsher 	req->max_bps_nic = cpu_to_le32(bps);
21949aebddd1SJeff Kirsher 
21959aebddd1SJeff Kirsher 	status = be_mcc_notify_wait(adapter);
21969aebddd1SJeff Kirsher 
21979aebddd1SJeff Kirsher err:
21989aebddd1SJeff Kirsher 	spin_unlock_bh(&adapter->mcc_lock);
21999aebddd1SJeff Kirsher 	return status;
22009aebddd1SJeff Kirsher }
22019aebddd1SJeff Kirsher 
22029aebddd1SJeff Kirsher int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
22039aebddd1SJeff Kirsher {
22049aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
22059aebddd1SJeff Kirsher 	struct be_cmd_req_cntl_attribs *req;
22069aebddd1SJeff Kirsher 	struct be_cmd_resp_cntl_attribs *resp;
22079aebddd1SJeff Kirsher 	int status;
22089aebddd1SJeff Kirsher 	int payload_len = max(sizeof(*req), sizeof(*resp));
22099aebddd1SJeff Kirsher 	struct mgmt_controller_attrib *attribs;
22109aebddd1SJeff Kirsher 	struct be_dma_mem attribs_cmd;
22119aebddd1SJeff Kirsher 
22129aebddd1SJeff Kirsher 	memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
22139aebddd1SJeff Kirsher 	attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
22149aebddd1SJeff Kirsher 	attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
22159aebddd1SJeff Kirsher 						&attribs_cmd.dma);
22169aebddd1SJeff Kirsher 	if (!attribs_cmd.va) {
22179aebddd1SJeff Kirsher 		dev_err(&adapter->pdev->dev,
22189aebddd1SJeff Kirsher 				"Memory allocation failure\n");
22199aebddd1SJeff Kirsher 		return -ENOMEM;
22209aebddd1SJeff Kirsher 	}
22219aebddd1SJeff Kirsher 
22229aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
22239aebddd1SJeff Kirsher 		return -1;
22249aebddd1SJeff Kirsher 
22259aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
22269aebddd1SJeff Kirsher 	if (!wrb) {
22279aebddd1SJeff Kirsher 		status = -EBUSY;
22289aebddd1SJeff Kirsher 		goto err;
22299aebddd1SJeff Kirsher 	}
22309aebddd1SJeff Kirsher 	req = attribs_cmd.va;
22319aebddd1SJeff Kirsher 
2232106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2233106df1e3SSomnath Kotur 			 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2234106df1e3SSomnath Kotur 			&attribs_cmd);
22359aebddd1SJeff Kirsher 
22369aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
22379aebddd1SJeff Kirsher 	if (!status) {
22389aebddd1SJeff Kirsher 		attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
22399aebddd1SJeff Kirsher 		adapter->hba_port_num = attribs->hba_attribs.phy_port;
22409aebddd1SJeff Kirsher 	}
22419aebddd1SJeff Kirsher 
22429aebddd1SJeff Kirsher err:
22439aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
22449aebddd1SJeff Kirsher 	pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
22459aebddd1SJeff Kirsher 					attribs_cmd.dma);
22469aebddd1SJeff Kirsher 	return status;
22479aebddd1SJeff Kirsher }
22489aebddd1SJeff Kirsher 
22499aebddd1SJeff Kirsher /* Uses mbox */
22509aebddd1SJeff Kirsher int be_cmd_req_native_mode(struct be_adapter *adapter)
22519aebddd1SJeff Kirsher {
22529aebddd1SJeff Kirsher 	struct be_mcc_wrb *wrb;
22539aebddd1SJeff Kirsher 	struct be_cmd_req_set_func_cap *req;
22549aebddd1SJeff Kirsher 	int status;
22559aebddd1SJeff Kirsher 
22569aebddd1SJeff Kirsher 	if (mutex_lock_interruptible(&adapter->mbox_lock))
22579aebddd1SJeff Kirsher 		return -1;
22589aebddd1SJeff Kirsher 
22599aebddd1SJeff Kirsher 	wrb = wrb_from_mbox(adapter);
22609aebddd1SJeff Kirsher 	if (!wrb) {
22619aebddd1SJeff Kirsher 		status = -EBUSY;
22629aebddd1SJeff Kirsher 		goto err;
22639aebddd1SJeff Kirsher 	}
22649aebddd1SJeff Kirsher 
22659aebddd1SJeff Kirsher 	req = embedded_payload(wrb);
22669aebddd1SJeff Kirsher 
2267106df1e3SSomnath Kotur 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2268106df1e3SSomnath Kotur 		OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
22699aebddd1SJeff Kirsher 
22709aebddd1SJeff Kirsher 	req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
22719aebddd1SJeff Kirsher 				CAPABILITY_BE3_NATIVE_ERX_API);
22729aebddd1SJeff Kirsher 	req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
22739aebddd1SJeff Kirsher 
22749aebddd1SJeff Kirsher 	status = be_mbox_notify_wait(adapter);
22759aebddd1SJeff Kirsher 	if (!status) {
22769aebddd1SJeff Kirsher 		struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
22779aebddd1SJeff Kirsher 		adapter->be3_native = le32_to_cpu(resp->cap_flags) &
22789aebddd1SJeff Kirsher 					CAPABILITY_BE3_NATIVE_ERX_API;
22799aebddd1SJeff Kirsher 	}
22809aebddd1SJeff Kirsher err:
22819aebddd1SJeff Kirsher 	mutex_unlock(&adapter->mbox_lock);
22829aebddd1SJeff Kirsher 	return status;
22839aebddd1SJeff Kirsher }
2284590c391dSPadmanabh Ratnakar 
2285590c391dSPadmanabh Ratnakar /* Uses synchronous MCCQ */
2286590c391dSPadmanabh Ratnakar int be_cmd_get_mac_from_list(struct be_adapter *adapter, u32 domain,
2287590c391dSPadmanabh Ratnakar 							u32 *pmac_id)
2288590c391dSPadmanabh Ratnakar {
2289590c391dSPadmanabh Ratnakar 	struct be_mcc_wrb *wrb;
2290590c391dSPadmanabh Ratnakar 	struct be_cmd_req_get_mac_list *req;
2291590c391dSPadmanabh Ratnakar 	int status;
2292590c391dSPadmanabh Ratnakar 	int mac_count;
2293590c391dSPadmanabh Ratnakar 
2294590c391dSPadmanabh Ratnakar 	spin_lock_bh(&adapter->mcc_lock);
2295590c391dSPadmanabh Ratnakar 
2296590c391dSPadmanabh Ratnakar 	wrb = wrb_from_mccq(adapter);
2297590c391dSPadmanabh Ratnakar 	if (!wrb) {
2298590c391dSPadmanabh Ratnakar 		status = -EBUSY;
2299590c391dSPadmanabh Ratnakar 		goto err;
2300590c391dSPadmanabh Ratnakar 	}
2301590c391dSPadmanabh Ratnakar 	req = embedded_payload(wrb);
2302590c391dSPadmanabh Ratnakar 
2303590c391dSPadmanabh Ratnakar 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2304590c391dSPadmanabh Ratnakar 				OPCODE_COMMON_GET_MAC_LIST, sizeof(*req),
2305590c391dSPadmanabh Ratnakar 				wrb, NULL);
2306590c391dSPadmanabh Ratnakar 
2307590c391dSPadmanabh Ratnakar 	req->hdr.domain = domain;
2308590c391dSPadmanabh Ratnakar 
2309590c391dSPadmanabh Ratnakar 	status = be_mcc_notify_wait(adapter);
2310590c391dSPadmanabh Ratnakar 	if (!status) {
2311590c391dSPadmanabh Ratnakar 		struct be_cmd_resp_get_mac_list *resp =
2312590c391dSPadmanabh Ratnakar 						embedded_payload(wrb);
2313590c391dSPadmanabh Ratnakar 		int i;
2314590c391dSPadmanabh Ratnakar 		u8 *ctxt = &resp->context[0][0];
2315590c391dSPadmanabh Ratnakar 		status = -EIO;
2316590c391dSPadmanabh Ratnakar 		mac_count = resp->mac_count;
2317590c391dSPadmanabh Ratnakar 		be_dws_le_to_cpu(&resp->context, sizeof(resp->context));
2318590c391dSPadmanabh Ratnakar 		for (i = 0; i < mac_count; i++) {
2319590c391dSPadmanabh Ratnakar 			if (!AMAP_GET_BITS(struct amap_get_mac_list_context,
2320590c391dSPadmanabh Ratnakar 					   act, ctxt)) {
2321590c391dSPadmanabh Ratnakar 				*pmac_id = AMAP_GET_BITS
2322590c391dSPadmanabh Ratnakar 					(struct amap_get_mac_list_context,
2323590c391dSPadmanabh Ratnakar 					 macid, ctxt);
2324590c391dSPadmanabh Ratnakar 				status = 0;
2325590c391dSPadmanabh Ratnakar 				break;
2326590c391dSPadmanabh Ratnakar 			}
2327590c391dSPadmanabh Ratnakar 			ctxt += sizeof(struct amap_get_mac_list_context) / 8;
2328590c391dSPadmanabh Ratnakar 		}
2329590c391dSPadmanabh Ratnakar 	}
2330590c391dSPadmanabh Ratnakar 
2331590c391dSPadmanabh Ratnakar err:
2332590c391dSPadmanabh Ratnakar 	spin_unlock_bh(&adapter->mcc_lock);
2333590c391dSPadmanabh Ratnakar 	return status;
2334590c391dSPadmanabh Ratnakar }
2335590c391dSPadmanabh Ratnakar 
2336590c391dSPadmanabh Ratnakar /* Uses synchronous MCCQ */
2337590c391dSPadmanabh Ratnakar int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2338590c391dSPadmanabh Ratnakar 			u8 mac_count, u32 domain)
2339590c391dSPadmanabh Ratnakar {
2340590c391dSPadmanabh Ratnakar 	struct be_mcc_wrb *wrb;
2341590c391dSPadmanabh Ratnakar 	struct be_cmd_req_set_mac_list *req;
2342590c391dSPadmanabh Ratnakar 	int status;
2343590c391dSPadmanabh Ratnakar 	struct be_dma_mem cmd;
2344590c391dSPadmanabh Ratnakar 
2345590c391dSPadmanabh Ratnakar 	memset(&cmd, 0, sizeof(struct be_dma_mem));
2346590c391dSPadmanabh Ratnakar 	cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2347590c391dSPadmanabh Ratnakar 	cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2348590c391dSPadmanabh Ratnakar 			&cmd.dma, GFP_KERNEL);
2349590c391dSPadmanabh Ratnakar 	if (!cmd.va) {
2350590c391dSPadmanabh Ratnakar 		dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2351590c391dSPadmanabh Ratnakar 		return -ENOMEM;
2352590c391dSPadmanabh Ratnakar 	}
2353590c391dSPadmanabh Ratnakar 
2354590c391dSPadmanabh Ratnakar 	spin_lock_bh(&adapter->mcc_lock);
2355590c391dSPadmanabh Ratnakar 
2356590c391dSPadmanabh Ratnakar 	wrb = wrb_from_mccq(adapter);
2357590c391dSPadmanabh Ratnakar 	if (!wrb) {
2358590c391dSPadmanabh Ratnakar 		status = -EBUSY;
2359590c391dSPadmanabh Ratnakar 		goto err;
2360590c391dSPadmanabh Ratnakar 	}
2361590c391dSPadmanabh Ratnakar 
2362590c391dSPadmanabh Ratnakar 	req = cmd.va;
2363590c391dSPadmanabh Ratnakar 	be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2364590c391dSPadmanabh Ratnakar 				OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2365590c391dSPadmanabh Ratnakar 				wrb, &cmd);
2366590c391dSPadmanabh Ratnakar 
2367590c391dSPadmanabh Ratnakar 	req->hdr.domain = domain;
2368590c391dSPadmanabh Ratnakar 	req->mac_count = mac_count;
2369590c391dSPadmanabh Ratnakar 	if (mac_count)
2370590c391dSPadmanabh Ratnakar 		memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2371590c391dSPadmanabh Ratnakar 
2372590c391dSPadmanabh Ratnakar 	status = be_mcc_notify_wait(adapter);
2373590c391dSPadmanabh Ratnakar 
2374590c391dSPadmanabh Ratnakar err:
2375590c391dSPadmanabh Ratnakar 	dma_free_coherent(&adapter->pdev->dev, cmd.size,
2376590c391dSPadmanabh Ratnakar 				cmd.va, cmd.dma);
2377590c391dSPadmanabh Ratnakar 	spin_unlock_bh(&adapter->mcc_lock);
2378590c391dSPadmanabh Ratnakar 	return status;
2379590c391dSPadmanabh Ratnakar }
2380