blob: a299f7bca7ba78df5261953f2c3e95b71062ed8f [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volamd19261b2015-05-06 05:30:39 -04002 * Copyright (C) 2005 - 2015 Emulex
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
10 * Contact Information:
Ajit Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
Parav Pandit6a4ab662012-03-26 14:27:12 +000018#include <linux/module.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070019#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000020#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070021
Vasundhara Volam21252372015-02-06 08:18:42 -050022static char *be_port_misconfig_evt_desc[] = {
23 "A valid SFP module detected",
24 "Optics faulted/ incorrectly installed/ not installed.",
25 "Optics of two types installed.",
26 "Incompatible optics.",
27 "Unknown port SFP status"
28};
29
30static char *be_port_misconfig_remedy_desc[] = {
31 "",
32 "Reseat optics. If issue not resolved, replace",
33 "Remove one optic or install matching pair of optics",
34 "Replace with compatible optics for card to function",
35 ""
36};
37
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000038static struct be_cmd_priv_map cmd_priv_map[] = {
39 {
40 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
41 CMD_SUBSYSTEM_ETH,
42 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
43 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
44 },
45 {
46 OPCODE_COMMON_GET_FLOW_CONTROL,
47 CMD_SUBSYSTEM_COMMON,
48 BE_PRIV_LNKQUERY | BE_PRIV_VHADM |
49 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
50 },
51 {
52 OPCODE_COMMON_SET_FLOW_CONTROL,
53 CMD_SUBSYSTEM_COMMON,
54 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
55 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
56 },
57 {
58 OPCODE_ETH_GET_PPORT_STATS,
59 CMD_SUBSYSTEM_ETH,
60 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
61 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
62 },
63 {
64 OPCODE_COMMON_GET_PHY_DETAILS,
65 CMD_SUBSYSTEM_COMMON,
66 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
67 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
68 }
69};
70
Sathya Perlaa2cc4e02014-05-09 13:29:14 +053071static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem)
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000072{
73 int i;
74 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
75 u32 cmd_privileges = adapter->cmd_privileges;
76
77 for (i = 0; i < num_entries; i++)
78 if (opcode == cmd_priv_map[i].opcode &&
79 subsystem == cmd_priv_map[i].subsystem)
80 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
81 return false;
82
83 return true;
84}
85
Somnath Kotur3de09452011-09-30 07:25:05 +000086static inline void *embedded_payload(struct be_mcc_wrb *wrb)
87{
88 return wrb->payload.embedded_payload;
89}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000090
Suresh Reddyefaa4082015-07-10 05:32:48 -040091static int be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000092{
Sathya Perla8788fdc2009-07-27 22:52:03 +000093 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000094 u32 val = 0;
95
Venkata Duvvuru954f6822015-05-13 13:00:13 +053096 if (be_check_error(adapter, BE_ERROR_ANY))
Suresh Reddyefaa4082015-07-10 05:32:48 -040097 return -EIO;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000098
Sathya Perla5fb379e2009-06-18 00:02:59 +000099 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
100 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000101
102 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +0000103 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Suresh Reddyefaa4082015-07-10 05:32:48 -0400104
105 return 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000106}
107
108/* To check if valid bit is set, check the entire word as we don't know
109 * the endianness of the data (old entry is host endian while a new entry is
110 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000111static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000112{
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000113 u32 flags;
114
Sathya Perla5fb379e2009-06-18 00:02:59 +0000115 if (compl->flags != 0) {
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000116 flags = le32_to_cpu(compl->flags);
117 if (flags & CQE_FLAGS_VALID_MASK) {
118 compl->flags = flags;
119 return true;
120 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000121 }
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000122 return false;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000123}
124
125/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000126static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000127{
128 compl->flags = 0;
129}
130
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000131static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
132{
133 unsigned long addr;
134
135 addr = tag1;
136 addr = ((addr << 16) << 16) | tag0;
137 return (void *)addr;
138}
139
Kalesh AP4c600052014-05-30 19:06:26 +0530140static bool be_skip_err_log(u8 opcode, u16 base_status, u16 addl_status)
141{
142 if (base_status == MCC_STATUS_NOT_SUPPORTED ||
143 base_status == MCC_STATUS_ILLEGAL_REQUEST ||
144 addl_status == MCC_ADDL_STATUS_TOO_MANY_INTERFACES ||
Kalesh AP77be8c12015-05-06 05:30:35 -0400145 addl_status == MCC_ADDL_STATUS_INSUFFICIENT_VLANS ||
Kalesh AP4c600052014-05-30 19:06:26 +0530146 (opcode == OPCODE_COMMON_WRITE_FLASHROM &&
147 (base_status == MCC_STATUS_ILLEGAL_FIELD ||
148 addl_status == MCC_ADDL_STATUS_FLASH_IMAGE_CRC_MISMATCH)))
149 return true;
150 else
151 return false;
152}
153
Sathya Perla559b6332014-05-30 19:06:27 +0530154/* Place holder for all the async MCC cmds wherein the caller is not in a busy
155 * loop (has not issued be_mcc_notify_wait())
156 */
157static void be_async_cmd_process(struct be_adapter *adapter,
158 struct be_mcc_compl *compl,
159 struct be_cmd_resp_hdr *resp_hdr)
160{
161 enum mcc_base_status base_status = base_status(compl->status);
162 u8 opcode = 0, subsystem = 0;
163
164 if (resp_hdr) {
165 opcode = resp_hdr->opcode;
166 subsystem = resp_hdr->subsystem;
167 }
168
169 if (opcode == OPCODE_LOWLEVEL_LOOPBACK_TEST &&
170 subsystem == CMD_SUBSYSTEM_LOWLEVEL) {
171 complete(&adapter->et_cmd_compl);
172 return;
173 }
174
175 if ((opcode == OPCODE_COMMON_WRITE_FLASHROM ||
176 opcode == OPCODE_COMMON_WRITE_OBJECT) &&
177 subsystem == CMD_SUBSYSTEM_COMMON) {
178 adapter->flash_status = compl->status;
179 complete(&adapter->et_cmd_compl);
180 return;
181 }
182
183 if ((opcode == OPCODE_ETH_GET_STATISTICS ||
184 opcode == OPCODE_ETH_GET_PPORT_STATS) &&
185 subsystem == CMD_SUBSYSTEM_ETH &&
186 base_status == MCC_STATUS_SUCCESS) {
187 be_parse_stats(adapter);
188 adapter->stats_cmd_sent = false;
189 return;
190 }
191
192 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
193 subsystem == CMD_SUBSYSTEM_COMMON) {
194 if (base_status == MCC_STATUS_SUCCESS) {
195 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
196 (void *)resp_hdr;
Venkata Duvvuru29e91222015-05-13 13:00:12 +0530197 adapter->hwmon_info.be_on_die_temp =
Sathya Perla559b6332014-05-30 19:06:27 +0530198 resp->on_die_temperature;
199 } else {
200 adapter->be_get_temp_freq = 0;
Venkata Duvvuru29e91222015-05-13 13:00:12 +0530201 adapter->hwmon_info.be_on_die_temp =
202 BE_INVALID_DIE_TEMP;
Sathya Perla559b6332014-05-30 19:06:27 +0530203 }
204 return;
205 }
206}
207
Sathya Perla8788fdc2009-07-27 22:52:03 +0000208static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000209 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000210{
Kalesh AP4c600052014-05-30 19:06:26 +0530211 enum mcc_base_status base_status;
212 enum mcc_addl_status addl_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000213 struct be_cmd_resp_hdr *resp_hdr;
214 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000215
216 /* Just swap the status to host endian; mcc tag is opaquely copied
217 * from mcc_wrb */
218 be_dws_le_to_cpu(compl, 4);
219
Kalesh AP4c600052014-05-30 19:06:26 +0530220 base_status = base_status(compl->status);
221 addl_status = addl_status(compl->status);
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +0530222
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000223 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000224 if (resp_hdr) {
225 opcode = resp_hdr->opcode;
226 subsystem = resp_hdr->subsystem;
227 }
228
Sathya Perla559b6332014-05-30 19:06:27 +0530229 be_async_cmd_process(adapter, compl, resp_hdr);
Suresh Reddy5eeff632014-01-06 13:02:24 +0530230
Sathya Perla559b6332014-05-30 19:06:27 +0530231 if (base_status != MCC_STATUS_SUCCESS &&
232 !be_skip_err_log(opcode, base_status, addl_status)) {
Kalesh AP4c600052014-05-30 19:06:26 +0530233 if (base_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000234 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000235 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000236 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000237 } else {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000238 dev_err(&adapter->pdev->dev,
239 "opcode %d-%d failed:status %d-%d\n",
Kalesh AP4c600052014-05-30 19:06:26 +0530240 opcode, subsystem, base_status, addl_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000241 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000242 }
Kalesh AP4c600052014-05-30 19:06:26 +0530243 return compl->status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000244}
245
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000246/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000247static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530248 struct be_mcc_compl *compl)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000249{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530250 struct be_async_event_link_state *evt =
251 (struct be_async_event_link_state *)compl;
252
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000253 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000254 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000255
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530256 /* On BEx the FW does not send a separate link status
257 * notification for physical and logical link.
258 * On other chips just process the logical link
259 * status notification
260 */
261 if (!BEx_chip(adapter) &&
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000262 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
263 return;
264
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000265 /* For the initial link status do not rely on the ASYNC event as
266 * it may not be received in some cases.
267 */
268 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530269 be_link_status_update(adapter,
270 evt->port_link_status & LINK_STATUS_MASK);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000271}
272
Vasundhara Volam21252372015-02-06 08:18:42 -0500273static void be_async_port_misconfig_event_process(struct be_adapter *adapter,
274 struct be_mcc_compl *compl)
275{
276 struct be_async_event_misconfig_port *evt =
277 (struct be_async_event_misconfig_port *)compl;
278 u32 sfp_mismatch_evt = le32_to_cpu(evt->event_data_word1);
279 struct device *dev = &adapter->pdev->dev;
280 u8 port_misconfig_evt;
281
282 port_misconfig_evt =
283 ((sfp_mismatch_evt >> (adapter->hba_port_num * 8)) & 0xff);
284
285 /* Log an error message that would allow a user to determine
286 * whether the SFPs have an issue
287 */
288 dev_info(dev, "Port %c: %s %s", adapter->port_name,
289 be_port_misconfig_evt_desc[port_misconfig_evt],
290 be_port_misconfig_remedy_desc[port_misconfig_evt]);
291
292 if (port_misconfig_evt == INCOMPATIBLE_SFP)
293 adapter->flags |= BE_FLAGS_EVT_INCOMPATIBLE_SFP;
294}
295
Somnath Koturcc4ce022010-10-21 07:11:14 -0700296/* Grp5 CoS Priority evt */
297static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530298 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700299{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530300 struct be_async_event_grp5_cos_priority *evt =
301 (struct be_async_event_grp5_cos_priority *)compl;
302
Somnath Koturcc4ce022010-10-21 07:11:14 -0700303 if (evt->valid) {
304 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000305 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700306 adapter->recommended_prio =
307 evt->reco_default_priority << VLAN_PRIO_SHIFT;
308 }
309}
310
Sathya Perla323ff712012-09-28 04:39:43 +0000311/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700312static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530313 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700314{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530315 struct be_async_event_grp5_qos_link_speed *evt =
316 (struct be_async_event_grp5_qos_link_speed *)compl;
317
Sathya Perla323ff712012-09-28 04:39:43 +0000318 if (adapter->phy.link_speed >= 0 &&
319 evt->physical_port == adapter->port_num)
320 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700321}
322
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000323/*Grp5 PVID evt*/
324static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530325 struct be_mcc_compl *compl)
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000326{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530327 struct be_async_event_grp5_pvid_state *evt =
328 (struct be_async_event_grp5_pvid_state *)compl;
329
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530330 if (evt->enabled) {
Somnath Kotur939cf302011-08-18 21:51:49 -0700331 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530332 dev_info(&adapter->pdev->dev, "LPVID: %d\n", adapter->pvid);
333 } else {
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000334 adapter->pvid = 0;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530335 }
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000336}
337
Venkata Duvvuru760c2952015-05-13 13:00:14 +0530338#define MGMT_ENABLE_MASK 0x4
339static void be_async_grp5_fw_control_process(struct be_adapter *adapter,
340 struct be_mcc_compl *compl)
341{
342 struct be_async_fw_control *evt = (struct be_async_fw_control *)compl;
343 u32 evt_dw1 = le32_to_cpu(evt->event_data_word1);
344
345 if (evt_dw1 & MGMT_ENABLE_MASK) {
346 adapter->flags |= BE_FLAGS_OS2BMC;
347 adapter->bmc_filt_mask = le32_to_cpu(evt->event_data_word2);
348 } else {
349 adapter->flags &= ~BE_FLAGS_OS2BMC;
350 }
351}
352
Somnath Koturcc4ce022010-10-21 07:11:14 -0700353static void be_async_grp5_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530354 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700355{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530356 u8 event_type = (compl->flags >> ASYNC_EVENT_TYPE_SHIFT) &
357 ASYNC_EVENT_TYPE_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700358
359 switch (event_type) {
360 case ASYNC_EVENT_COS_PRIORITY:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530361 be_async_grp5_cos_priority_process(adapter, compl);
362 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700363 case ASYNC_EVENT_QOS_SPEED:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530364 be_async_grp5_qos_speed_process(adapter, compl);
365 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000366 case ASYNC_EVENT_PVID_STATE:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530367 be_async_grp5_pvid_state_process(adapter, compl);
368 break;
Venkata Duvvuru760c2952015-05-13 13:00:14 +0530369 /* Async event to disable/enable os2bmc and/or mac-learning */
370 case ASYNC_EVENT_FW_CONTROL:
371 be_async_grp5_fw_control_process(adapter, compl);
372 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700373 default:
Somnath Koturcc4ce022010-10-21 07:11:14 -0700374 break;
375 }
376}
377
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000378static void be_async_dbg_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530379 struct be_mcc_compl *cmp)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000380{
381 u8 event_type = 0;
Kalesh AP504fbf12014-09-19 15:47:00 +0530382 struct be_async_event_qnq *evt = (struct be_async_event_qnq *)cmp;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000383
Sathya Perla3acf19d2014-05-30 19:06:28 +0530384 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
385 ASYNC_EVENT_TYPE_MASK;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000386
387 switch (event_type) {
388 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
389 if (evt->valid)
390 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
391 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
392 break;
393 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530394 dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n",
395 event_type);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000396 break;
397 }
398}
399
Vasundhara Volam21252372015-02-06 08:18:42 -0500400static void be_async_sliport_evt_process(struct be_adapter *adapter,
401 struct be_mcc_compl *cmp)
402{
403 u8 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
404 ASYNC_EVENT_TYPE_MASK;
405
406 if (event_type == ASYNC_EVENT_PORT_MISCONFIG)
407 be_async_port_misconfig_event_process(adapter, cmp);
408}
409
Sathya Perla3acf19d2014-05-30 19:06:28 +0530410static inline bool is_link_state_evt(u32 flags)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000411{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530412 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
413 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000414}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000415
Sathya Perla3acf19d2014-05-30 19:06:28 +0530416static inline bool is_grp5_evt(u32 flags)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700417{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530418 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
419 ASYNC_EVENT_CODE_GRP_5;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700420}
421
Sathya Perla3acf19d2014-05-30 19:06:28 +0530422static inline bool is_dbg_evt(u32 flags)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000423{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530424 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
425 ASYNC_EVENT_CODE_QNQ;
426}
427
Vasundhara Volam21252372015-02-06 08:18:42 -0500428static inline bool is_sliport_evt(u32 flags)
429{
430 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
431 ASYNC_EVENT_CODE_SLIPORT;
432}
433
Sathya Perla3acf19d2014-05-30 19:06:28 +0530434static void be_mcc_event_process(struct be_adapter *adapter,
435 struct be_mcc_compl *compl)
436{
437 if (is_link_state_evt(compl->flags))
438 be_async_link_state_process(adapter, compl);
439 else if (is_grp5_evt(compl->flags))
440 be_async_grp5_evt_process(adapter, compl);
441 else if (is_dbg_evt(compl->flags))
442 be_async_dbg_evt_process(adapter, compl);
Vasundhara Volam21252372015-02-06 08:18:42 -0500443 else if (is_sliport_evt(compl->flags))
444 be_async_sliport_evt_process(adapter, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000445}
446
Sathya Perlaefd2e402009-07-27 22:53:10 +0000447static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000448{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000449 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000450 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000451
452 if (be_mcc_compl_is_new(compl)) {
453 queue_tail_inc(mcc_cq);
454 return compl;
455 }
456 return NULL;
457}
458
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000459void be_async_mcc_enable(struct be_adapter *adapter)
460{
461 spin_lock_bh(&adapter->mcc_cq_lock);
462
463 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
464 adapter->mcc_obj.rearm_cq = true;
465
466 spin_unlock_bh(&adapter->mcc_cq_lock);
467}
468
469void be_async_mcc_disable(struct be_adapter *adapter)
470{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000471 spin_lock_bh(&adapter->mcc_cq_lock);
472
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000473 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000474 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
475
476 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000477}
478
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000479int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000480{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000481 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000482 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000483 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000484
Amerigo Wang072a9c42012-08-24 21:41:11 +0000485 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla3acf19d2014-05-30 19:06:28 +0530486
Sathya Perla8788fdc2009-07-27 22:52:03 +0000487 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000488 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530489 be_mcc_event_process(adapter, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700490 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530491 status = be_mcc_compl_process(adapter, compl);
492 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000493 }
494 be_mcc_compl_use(compl);
495 num++;
496 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700497
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000498 if (num)
499 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
500
Amerigo Wang072a9c42012-08-24 21:41:11 +0000501 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000502 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000503}
504
Sathya Perla6ac7b682009-06-18 00:05:54 +0000505/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700506static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000507{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700508#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000509 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800510 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700511
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800512 for (i = 0; i < mcc_timeout; i++) {
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530513 if (be_check_error(adapter, BE_ERROR_ANY))
Sathya Perla6589ade2011-11-10 19:18:00 +0000514 return -EIO;
515
Amerigo Wang072a9c42012-08-24 21:41:11 +0000516 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000517 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000518 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800519
520 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000521 break;
522 udelay(100);
523 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700524 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000525 dev_err(&adapter->pdev->dev, "FW not responding\n");
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530526 be_set_error(adapter, BE_ERROR_FW);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000527 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700528 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800529 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000530}
531
532/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700533static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000534{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000535 int status;
536 struct be_mcc_wrb *wrb;
537 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
538 u16 index = mcc_obj->q.head;
539 struct be_cmd_resp_hdr *resp;
540
541 index_dec(&index, mcc_obj->q.len);
542 wrb = queue_index_node(&mcc_obj->q, index);
543
544 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
545
Suresh Reddyefaa4082015-07-10 05:32:48 -0400546 status = be_mcc_notify(adapter);
547 if (status)
548 goto out;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000549
550 status = be_mcc_wait_compl(adapter);
551 if (status == -EIO)
552 goto out;
553
Kalesh AP4c600052014-05-30 19:06:26 +0530554 status = (resp->base_status |
555 ((resp->addl_status & CQE_ADDL_STATUS_MASK) <<
556 CQE_ADDL_STATUS_SHIFT));
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000557out:
558 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000559}
560
Sathya Perla5f0b8492009-07-27 22:52:56 +0000561static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700562{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000563 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700564 u32 ready;
565
566 do {
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530567 if (be_check_error(adapter, BE_ERROR_ANY))
Sathya Perla6589ade2011-11-10 19:18:00 +0000568 return -EIO;
569
Sathya Perlacf588472010-02-14 21:22:01 +0000570 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000571 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000572 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000573
574 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700575 if (ready)
576 break;
577
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000578 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000579 dev_err(&adapter->pdev->dev, "FW not responding\n");
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530580 be_set_error(adapter, BE_ERROR_FW);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000581 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700582 return -1;
583 }
584
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000585 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000586 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700587 } while (true);
588
589 return 0;
590}
591
592/*
593 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000594 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700595 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700596static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700597{
598 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700599 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000600 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
601 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700602 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000603 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700604
Sathya Perlacf588472010-02-14 21:22:01 +0000605 /* wait for ready to be set */
606 status = be_mbox_db_ready_wait(adapter, db);
607 if (status != 0)
608 return status;
609
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700610 val |= MPU_MAILBOX_DB_HI_MASK;
611 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
612 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
613 iowrite32(val, db);
614
615 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000616 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700617 if (status != 0)
618 return status;
619
620 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700621 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
622 val |= (u32)(mbox_mem->dma >> 4) << 2;
623 iowrite32(val, db);
624
Sathya Perla5f0b8492009-07-27 22:52:56 +0000625 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700626 if (status != 0)
627 return status;
628
Sathya Perla5fb379e2009-06-18 00:02:59 +0000629 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000630 if (be_mcc_compl_is_new(compl)) {
631 status = be_mcc_compl_process(adapter, &mbox->compl);
632 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000633 if (status)
634 return status;
635 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000636 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700637 return -1;
638 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000639 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700640}
641
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000642static u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700643{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000644 u32 sem;
645
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000646 if (BEx_chip(adapter))
647 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700648 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000649 pci_read_config_dword(adapter->pdev,
650 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
651
652 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700653}
654
Gavin Shan87f20c22013-10-29 17:30:57 +0800655static int lancer_wait_ready(struct be_adapter *adapter)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000656{
657#define SLIPORT_READY_TIMEOUT 30
658 u32 sliport_status;
Kalesh APe6732442015-01-20 03:51:46 -0500659 int i;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000660
661 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
662 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
663 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
Sathya Perla9fa465c2015-02-23 04:20:13 -0500664 return 0;
665
666 if (sliport_status & SLIPORT_STATUS_ERR_MASK &&
667 !(sliport_status & SLIPORT_STATUS_RN_MASK))
668 return -EIO;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000669
670 msleep(1000);
671 }
672
Sathya Perla9fa465c2015-02-23 04:20:13 -0500673 return sliport_status ? : -1;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000674}
675
676int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000678 u16 stage;
679 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000680 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700681
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000682 if (lancer_chip(adapter)) {
683 status = lancer_wait_ready(adapter);
Kalesh APe6732442015-01-20 03:51:46 -0500684 if (status) {
685 stage = status;
686 goto err;
687 }
688 return 0;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000689 }
690
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000691 do {
Sathya Perlaca3de6b2015-02-23 04:20:10 -0500692 /* There's no means to poll POST state on BE2/3 VFs */
693 if (BEx_chip(adapter) && be_virtfn(adapter))
694 return 0;
695
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000696 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000697 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000698 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000699
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530700 dev_info(dev, "Waiting for POST, %ds elapsed\n", timeout);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000701 if (msleep_interruptible(2000)) {
702 dev_err(dev, "Waiting for POST aborted\n");
703 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000704 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000705 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000706 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700707
Kalesh APe6732442015-01-20 03:51:46 -0500708err:
709 dev_err(dev, "POST timeout; stage=%#x\n", stage);
Sathya Perla9fa465c2015-02-23 04:20:13 -0500710 return -ETIMEDOUT;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700711}
712
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700713static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
714{
715 return &wrb->payload.sgl[0];
716}
717
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530718static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, unsigned long addr)
Sathya Perlabea50982013-08-27 16:57:33 +0530719{
720 wrb->tag0 = addr & 0xFFFFFFFF;
721 wrb->tag1 = upper_32_bits(addr);
722}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700723
724/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000725/* mem will be NULL for embedded commands */
726static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530727 u8 subsystem, u8 opcode, int cmd_len,
728 struct be_mcc_wrb *wrb,
729 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700730{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000731 struct be_sge *sge;
732
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700733 req_hdr->opcode = opcode;
734 req_hdr->subsystem = subsystem;
735 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000736 req_hdr->version = 0;
Sathya Perlabea50982013-08-27 16:57:33 +0530737 fill_wrb_tags(wrb, (ulong) req_hdr);
Somnath Kotur106df1e2011-10-27 07:12:13 +0000738 wrb->payload_length = cmd_len;
739 if (mem) {
740 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
741 MCC_WRB_SGE_CNT_SHIFT;
742 sge = nonembedded_sgl(wrb);
743 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
744 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
745 sge->len = cpu_to_le32(mem->size);
746 } else
747 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
748 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700749}
750
751static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530752 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700753{
754 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
755 u64 dma = (u64)mem->dma;
756
757 for (i = 0; i < buf_pages; i++) {
758 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
759 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
760 dma += PAGE_SIZE_4K;
761 }
762}
763
Sathya Perlab31c50a2009-09-17 10:30:13 -0700764static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700765{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700766 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
767 struct be_mcc_wrb *wrb
768 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
769 memset(wrb, 0, sizeof(*wrb));
770 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700771}
772
Sathya Perlab31c50a2009-09-17 10:30:13 -0700773static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000774{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700775 struct be_queue_info *mccq = &adapter->mcc_obj.q;
776 struct be_mcc_wrb *wrb;
777
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000778 if (!mccq->created)
779 return NULL;
780
Vasundhara Volam4d277122013-04-21 23:28:15 +0000781 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000782 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000783
Sathya Perlab31c50a2009-09-17 10:30:13 -0700784 wrb = queue_head_node(mccq);
785 queue_head_inc(mccq);
786 atomic_inc(&mccq->used);
787 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000788 return wrb;
789}
790
Sathya Perlabea50982013-08-27 16:57:33 +0530791static bool use_mcc(struct be_adapter *adapter)
792{
793 return adapter->mcc_obj.q.created;
794}
795
796/* Must be used only in process context */
797static int be_cmd_lock(struct be_adapter *adapter)
798{
799 if (use_mcc(adapter)) {
800 spin_lock_bh(&adapter->mcc_lock);
801 return 0;
802 } else {
803 return mutex_lock_interruptible(&adapter->mbox_lock);
804 }
805}
806
807/* Must be used only in process context */
808static void be_cmd_unlock(struct be_adapter *adapter)
809{
810 if (use_mcc(adapter))
811 spin_unlock_bh(&adapter->mcc_lock);
812 else
813 return mutex_unlock(&adapter->mbox_lock);
814}
815
816static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter,
817 struct be_mcc_wrb *wrb)
818{
819 struct be_mcc_wrb *dest_wrb;
820
821 if (use_mcc(adapter)) {
822 dest_wrb = wrb_from_mccq(adapter);
823 if (!dest_wrb)
824 return NULL;
825 } else {
826 dest_wrb = wrb_from_mbox(adapter);
827 }
828
829 memcpy(dest_wrb, wrb, sizeof(*wrb));
830 if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK))
831 fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb));
832
833 return dest_wrb;
834}
835
836/* Must be used only in process context */
837static int be_cmd_notify_wait(struct be_adapter *adapter,
838 struct be_mcc_wrb *wrb)
839{
840 struct be_mcc_wrb *dest_wrb;
841 int status;
842
843 status = be_cmd_lock(adapter);
844 if (status)
845 return status;
846
847 dest_wrb = be_cmd_copy(adapter, wrb);
848 if (!dest_wrb)
849 return -EBUSY;
850
851 if (use_mcc(adapter))
852 status = be_mcc_notify_wait(adapter);
853 else
854 status = be_mbox_notify_wait(adapter);
855
856 if (!status)
857 memcpy(wrb, dest_wrb, sizeof(*wrb));
858
859 be_cmd_unlock(adapter);
860 return status;
861}
862
Sathya Perla2243e2e2009-11-22 22:02:03 +0000863/* Tell fw we're about to start firing cmds by writing a
864 * special pattern across the wrb hdr; uses mbox
865 */
866int be_cmd_fw_init(struct be_adapter *adapter)
867{
868 u8 *wrb;
869 int status;
870
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000871 if (lancer_chip(adapter))
872 return 0;
873
Ivan Vecera29849612010-12-14 05:43:19 +0000874 if (mutex_lock_interruptible(&adapter->mbox_lock))
875 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000876
877 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000878 *wrb++ = 0xFF;
879 *wrb++ = 0x12;
880 *wrb++ = 0x34;
881 *wrb++ = 0xFF;
882 *wrb++ = 0xFF;
883 *wrb++ = 0x56;
884 *wrb++ = 0x78;
885 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000886
887 status = be_mbox_notify_wait(adapter);
888
Ivan Vecera29849612010-12-14 05:43:19 +0000889 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000890 return status;
891}
892
893/* Tell fw we're done with firing cmds by writing a
894 * special pattern across the wrb hdr; uses mbox
895 */
896int be_cmd_fw_clean(struct be_adapter *adapter)
897{
898 u8 *wrb;
899 int status;
900
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000901 if (lancer_chip(adapter))
902 return 0;
903
Ivan Vecera29849612010-12-14 05:43:19 +0000904 if (mutex_lock_interruptible(&adapter->mbox_lock))
905 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000906
907 wrb = (u8 *)wrb_from_mbox(adapter);
908 *wrb++ = 0xFF;
909 *wrb++ = 0xAA;
910 *wrb++ = 0xBB;
911 *wrb++ = 0xFF;
912 *wrb++ = 0xFF;
913 *wrb++ = 0xCC;
914 *wrb++ = 0xDD;
915 *wrb = 0xFF;
916
917 status = be_mbox_notify_wait(adapter);
918
Ivan Vecera29849612010-12-14 05:43:19 +0000919 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000920 return status;
921}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000922
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530923int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700924{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700925 struct be_mcc_wrb *wrb;
926 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530927 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
928 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700929
Ivan Vecera29849612010-12-14 05:43:19 +0000930 if (mutex_lock_interruptible(&adapter->mbox_lock))
931 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700932
933 wrb = wrb_from_mbox(adapter);
934 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700935
Somnath Kotur106df1e2011-10-27 07:12:13 +0000936 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530937 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb,
938 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700939
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530940 /* Support for EQ_CREATEv2 available only SH-R onwards */
941 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
942 ver = 2;
943
944 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700945 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
946
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700947 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
948 /* 4byte eqe*/
949 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
950 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530951 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700952 be_dws_cpu_to_le(req->context, sizeof(req->context));
953
954 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
955
Sathya Perlab31c50a2009-09-17 10:30:13 -0700956 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700957 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700958 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +0530959
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530960 eqo->q.id = le16_to_cpu(resp->eq_id);
961 eqo->msix_idx =
962 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
963 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700964 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700965
Ivan Vecera29849612010-12-14 05:43:19 +0000966 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700967 return status;
968}
969
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000970/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000971int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000972 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700973{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700974 struct be_mcc_wrb *wrb;
975 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700976 int status;
977
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000978 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700979
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000980 wrb = wrb_from_mccq(adapter);
981 if (!wrb) {
982 status = -EBUSY;
983 goto err;
984 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700985 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700986
Somnath Kotur106df1e2011-10-27 07:12:13 +0000987 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530988 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb,
989 NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000990 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700991 if (permanent) {
992 req->permanent = 1;
993 } else {
Kalesh AP504fbf12014-09-19 15:47:00 +0530994 req->if_id = cpu_to_le16((u16)if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000995 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700996 req->permanent = 0;
997 }
998
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000999 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001000 if (!status) {
1001 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301002
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001003 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001004 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001005
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001006err:
1007 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001008 return status;
1009}
1010
Sathya Perlab31c50a2009-09-17 10:30:13 -07001011/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001012int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301013 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001014{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001015 struct be_mcc_wrb *wrb;
1016 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001017 int status;
1018
Sathya Perlab31c50a2009-09-17 10:30:13 -07001019 spin_lock_bh(&adapter->mcc_lock);
1020
1021 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001022 if (!wrb) {
1023 status = -EBUSY;
1024 goto err;
1025 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001026 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027
Somnath Kotur106df1e2011-10-27 07:12:13 +00001028 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301029 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb,
1030 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001031
Ajit Khapardef8617e02011-02-11 13:36:37 +00001032 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001033 req->if_id = cpu_to_le32(if_id);
1034 memcpy(req->mac_address, mac_addr, ETH_ALEN);
1035
Sathya Perlab31c50a2009-09-17 10:30:13 -07001036 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001037 if (!status) {
1038 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301039
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001040 *pmac_id = le32_to_cpu(resp->pmac_id);
1041 }
1042
Sathya Perla713d03942009-11-22 22:02:45 +00001043err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001044 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +00001045
1046 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
1047 status = -EPERM;
1048
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001049 return status;
1050}
1051
Sathya Perlab31c50a2009-09-17 10:30:13 -07001052/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001053int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001054{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001055 struct be_mcc_wrb *wrb;
1056 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001057 int status;
1058
Sathya Perla30128032011-11-10 19:17:57 +00001059 if (pmac_id == -1)
1060 return 0;
1061
Sathya Perlab31c50a2009-09-17 10:30:13 -07001062 spin_lock_bh(&adapter->mcc_lock);
1063
1064 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001065 if (!wrb) {
1066 status = -EBUSY;
1067 goto err;
1068 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001069 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001070
Somnath Kotur106df1e2011-10-27 07:12:13 +00001071 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Kalesh APcd3307aa2014-09-19 15:47:02 +05301072 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req),
1073 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001074
Ajit Khapardef8617e02011-02-11 13:36:37 +00001075 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001076 req->if_id = cpu_to_le32(if_id);
1077 req->pmac_id = cpu_to_le32(pmac_id);
1078
Sathya Perlab31c50a2009-09-17 10:30:13 -07001079 status = be_mcc_notify_wait(adapter);
1080
Sathya Perla713d03942009-11-22 22:02:45 +00001081err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001082 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001083 return status;
1084}
1085
Sathya Perlab31c50a2009-09-17 10:30:13 -07001086/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001087int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301088 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001089{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001090 struct be_mcc_wrb *wrb;
1091 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001092 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001093 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001094 int status;
1095
Ivan Vecera29849612010-12-14 05:43:19 +00001096 if (mutex_lock_interruptible(&adapter->mbox_lock))
1097 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001098
1099 wrb = wrb_from_mbox(adapter);
1100 req = embedded_payload(wrb);
1101 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102
Somnath Kotur106df1e2011-10-27 07:12:13 +00001103 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301104 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb,
1105 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001106
1107 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001108
1109 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001110 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301111 coalesce_wm);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001112 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301113 ctxt, no_delay);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001114 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301115 __ilog2_u32(cq->len / 256));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001116 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001117 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
1118 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001119 } else {
1120 req->hdr.version = 2;
1121 req->page_size = 1; /* 1 for 4K */
Ajit Khaparde09e83a92013-11-22 12:51:20 -06001122
1123 /* coalesce-wm field in this cmd is not relevant to Lancer.
1124 * Lancer uses COMMON_MODIFY_CQ to set this field
1125 */
1126 if (!lancer_chip(adapter))
1127 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1128 ctxt, coalesce_wm);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001129 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301130 no_delay);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001131 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301132 __ilog2_u32(cq->len / 256));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001133 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301134 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1135 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001136 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001137
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001138 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1139
1140 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1141
Sathya Perlab31c50a2009-09-17 10:30:13 -07001142 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001143 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001144 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301145
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001146 cq->id = le16_to_cpu(resp->cq_id);
1147 cq->created = true;
1148 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001149
Ivan Vecera29849612010-12-14 05:43:19 +00001150 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001151
1152 return status;
1153}
1154
1155static u32 be_encoded_q_len(int q_len)
1156{
1157 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
Kalesh AP03d28ff2014-09-19 15:46:56 +05301158
Sathya Perla5fb379e2009-06-18 00:02:59 +00001159 if (len_encoded == 16)
1160 len_encoded = 0;
1161 return len_encoded;
1162}
1163
Jingoo Han4188e7d2013-08-05 18:02:02 +09001164static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301165 struct be_queue_info *mccq,
1166 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001167{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001168 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001169 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001170 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001171 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001172 int status;
1173
Ivan Vecera29849612010-12-14 05:43:19 +00001174 if (mutex_lock_interruptible(&adapter->mbox_lock))
1175 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001176
1177 wrb = wrb_from_mbox(adapter);
1178 req = embedded_payload(wrb);
1179 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001180
Somnath Kotur106df1e2011-10-27 07:12:13 +00001181 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301182 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb,
1183 NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001184
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001185 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301186 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001187 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1188 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301189 be_encoded_q_len(mccq->len));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001190 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301191 } else {
1192 req->hdr.version = 1;
1193 req->cq_id = cpu_to_le16(cq->id);
1194
1195 AMAP_SET_BITS(struct amap_mcc_context_v1, ring_size, ctxt,
1196 be_encoded_q_len(mccq->len));
1197 AMAP_SET_BITS(struct amap_mcc_context_v1, valid, ctxt, 1);
1198 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_id,
1199 ctxt, cq->id);
1200 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_valid,
1201 ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001202 }
1203
Vasundhara Volam21252372015-02-06 08:18:42 -05001204 /* Subscribe to Link State, Sliport Event and Group 5 Events
1205 * (bits 1, 5 and 17 set)
1206 */
1207 req->async_event_bitmap[0] =
1208 cpu_to_le32(BIT(ASYNC_EVENT_CODE_LINK_STATE) |
1209 BIT(ASYNC_EVENT_CODE_GRP_5) |
1210 BIT(ASYNC_EVENT_CODE_QNQ) |
1211 BIT(ASYNC_EVENT_CODE_SLIPORT));
1212
Sathya Perla5fb379e2009-06-18 00:02:59 +00001213 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1214
1215 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1216
Sathya Perlab31c50a2009-09-17 10:30:13 -07001217 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001218 if (!status) {
1219 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301220
Sathya Perla5fb379e2009-06-18 00:02:59 +00001221 mccq->id = le16_to_cpu(resp->id);
1222 mccq->created = true;
1223 }
Ivan Vecera29849612010-12-14 05:43:19 +00001224 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001225
1226 return status;
1227}
1228
Jingoo Han4188e7d2013-08-05 18:02:02 +09001229static int be_cmd_mccq_org_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301230 struct be_queue_info *mccq,
1231 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001232{
1233 struct be_mcc_wrb *wrb;
1234 struct be_cmd_req_mcc_create *req;
1235 struct be_dma_mem *q_mem = &mccq->dma_mem;
1236 void *ctxt;
1237 int status;
1238
1239 if (mutex_lock_interruptible(&adapter->mbox_lock))
1240 return -1;
1241
1242 wrb = wrb_from_mbox(adapter);
1243 req = embedded_payload(wrb);
1244 ctxt = &req->context;
1245
Somnath Kotur106df1e2011-10-27 07:12:13 +00001246 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301247 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb,
1248 NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001249
1250 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1251
1252 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1253 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301254 be_encoded_q_len(mccq->len));
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001255 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1256
1257 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1258
1259 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1260
1261 status = be_mbox_notify_wait(adapter);
1262 if (!status) {
1263 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301264
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001265 mccq->id = le16_to_cpu(resp->id);
1266 mccq->created = true;
1267 }
1268
1269 mutex_unlock(&adapter->mbox_lock);
1270 return status;
1271}
1272
1273int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301274 struct be_queue_info *mccq, struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001275{
1276 int status;
1277
1278 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301279 if (status && BEx_chip(adapter)) {
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001280 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1281 "or newer to avoid conflicting priorities between NIC "
1282 "and FCoE traffic");
1283 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1284 }
1285 return status;
1286}
1287
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001288int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001289{
Sathya Perla77071332013-08-27 16:57:34 +05301290 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001291 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001292 struct be_queue_info *txq = &txo->q;
1293 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001294 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001295 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001296
Sathya Perla77071332013-08-27 16:57:34 +05301297 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001298 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301299 OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001301 if (lancer_chip(adapter)) {
1302 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001303 } else if (BEx_chip(adapter)) {
1304 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1305 req->hdr.version = 2;
1306 } else { /* For SH */
1307 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001308 }
1309
Vasundhara Volam81b02652013-10-01 15:59:57 +05301310 if (req->hdr.version > 0)
1311 req->if_id = cpu_to_le16(adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001312 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1313 req->ulp_num = BE_ULP1_NUM;
1314 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001315 req->cq_id = cpu_to_le16(cq->id);
1316 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001317 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001318 ver = req->hdr.version;
1319
Sathya Perla77071332013-08-27 16:57:34 +05301320 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001321 if (!status) {
Sathya Perla77071332013-08-27 16:57:34 +05301322 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301323
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001324 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001325 if (ver == 2)
1326 txo->db_offset = le32_to_cpu(resp->db_offset);
1327 else
1328 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001329 txq->created = true;
1330 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001331
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001332 return status;
1333}
1334
Sathya Perla482c9e72011-06-29 23:33:17 +00001335/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001336int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301337 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
1338 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001339{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001340 struct be_mcc_wrb *wrb;
1341 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001342 struct be_dma_mem *q_mem = &rxq->dma_mem;
1343 int status;
1344
Sathya Perla482c9e72011-06-29 23:33:17 +00001345 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001346
Sathya Perla482c9e72011-06-29 23:33:17 +00001347 wrb = wrb_from_mccq(adapter);
1348 if (!wrb) {
1349 status = -EBUSY;
1350 goto err;
1351 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001352 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001353
Somnath Kotur106df1e2011-10-27 07:12:13 +00001354 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301355 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001356
1357 req->cq_id = cpu_to_le16(cq_id);
1358 req->frag_size = fls(frag_size) - 1;
1359 req->num_pages = 2;
1360 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1361 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001362 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001363 req->rss_queue = cpu_to_le32(rss);
1364
Sathya Perla482c9e72011-06-29 23:33:17 +00001365 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001366 if (!status) {
1367 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301368
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369 rxq->id = le16_to_cpu(resp->id);
1370 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001371 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001372 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001373
Sathya Perla482c9e72011-06-29 23:33:17 +00001374err:
1375 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001376 return status;
1377}
1378
Sathya Perlab31c50a2009-09-17 10:30:13 -07001379/* Generic destroyer function for all types of queues
1380 * Uses Mbox
1381 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001382int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301383 int queue_type)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001384{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001385 struct be_mcc_wrb *wrb;
1386 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001387 u8 subsys = 0, opcode = 0;
1388 int status;
1389
Ivan Vecera29849612010-12-14 05:43:19 +00001390 if (mutex_lock_interruptible(&adapter->mbox_lock))
1391 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001392
Sathya Perlab31c50a2009-09-17 10:30:13 -07001393 wrb = wrb_from_mbox(adapter);
1394 req = embedded_payload(wrb);
1395
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001396 switch (queue_type) {
1397 case QTYPE_EQ:
1398 subsys = CMD_SUBSYSTEM_COMMON;
1399 opcode = OPCODE_COMMON_EQ_DESTROY;
1400 break;
1401 case QTYPE_CQ:
1402 subsys = CMD_SUBSYSTEM_COMMON;
1403 opcode = OPCODE_COMMON_CQ_DESTROY;
1404 break;
1405 case QTYPE_TXQ:
1406 subsys = CMD_SUBSYSTEM_ETH;
1407 opcode = OPCODE_ETH_TX_DESTROY;
1408 break;
1409 case QTYPE_RXQ:
1410 subsys = CMD_SUBSYSTEM_ETH;
1411 opcode = OPCODE_ETH_RX_DESTROY;
1412 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001413 case QTYPE_MCCQ:
1414 subsys = CMD_SUBSYSTEM_COMMON;
1415 opcode = OPCODE_COMMON_MCC_DESTROY;
1416 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001417 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001418 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001419 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001420
Somnath Kotur106df1e2011-10-27 07:12:13 +00001421 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301422 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001423 req->id = cpu_to_le16(q->id);
1424
Sathya Perlab31c50a2009-09-17 10:30:13 -07001425 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001426 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001427
Ivan Vecera29849612010-12-14 05:43:19 +00001428 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001429 return status;
1430}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001431
Sathya Perla482c9e72011-06-29 23:33:17 +00001432/* Uses MCC */
1433int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1434{
1435 struct be_mcc_wrb *wrb;
1436 struct be_cmd_req_q_destroy *req;
1437 int status;
1438
1439 spin_lock_bh(&adapter->mcc_lock);
1440
1441 wrb = wrb_from_mccq(adapter);
1442 if (!wrb) {
1443 status = -EBUSY;
1444 goto err;
1445 }
1446 req = embedded_payload(wrb);
1447
Somnath Kotur106df1e2011-10-27 07:12:13 +00001448 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301449 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001450 req->id = cpu_to_le16(q->id);
1451
1452 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001453 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001454
1455err:
1456 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001457 return status;
1458}
1459
Sathya Perlab31c50a2009-09-17 10:30:13 -07001460/* Create an rx filtering policy configuration on an i/f
Sathya Perlabea50982013-08-27 16:57:33 +05301461 * Will use MBOX only if MCCQ has not been created.
Sathya Perlab31c50a2009-09-17 10:30:13 -07001462 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001463int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001464 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001465{
Sathya Perlabea50982013-08-27 16:57:33 +05301466 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001467 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001468 int status;
1469
Sathya Perlabea50982013-08-27 16:57:33 +05301470 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001471 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301472 OPCODE_COMMON_NTWK_INTERFACE_CREATE,
1473 sizeof(*req), &wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001474 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001475 req->capability_flags = cpu_to_le32(cap_flags);
1476 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001477 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001478
Sathya Perlabea50982013-08-27 16:57:33 +05301479 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001480 if (!status) {
Sathya Perlabea50982013-08-27 16:57:33 +05301481 struct be_cmd_resp_if_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301482
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001483 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301484
1485 /* Hack to retrieve VF's pmac-id on BE3 */
Kalesh AP18c57c72015-05-06 05:30:38 -04001486 if (BE3_chip(adapter) && be_virtfn(adapter))
Sathya Perlab5bb9772013-07-23 15:25:01 +05301487 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001488 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001489 return status;
1490}
1491
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001492/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001493int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001494{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001495 struct be_mcc_wrb *wrb;
1496 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001497 int status;
1498
Sathya Perla30128032011-11-10 19:17:57 +00001499 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001500 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001501
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001502 spin_lock_bh(&adapter->mcc_lock);
1503
1504 wrb = wrb_from_mccq(adapter);
1505 if (!wrb) {
1506 status = -EBUSY;
1507 goto err;
1508 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001509 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001510
Somnath Kotur106df1e2011-10-27 07:12:13 +00001511 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301512 OPCODE_COMMON_NTWK_INTERFACE_DESTROY,
1513 sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001514 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001515 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001516
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001517 status = be_mcc_notify_wait(adapter);
1518err:
1519 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001520 return status;
1521}
1522
1523/* Get stats is a non embedded command: the request is not embedded inside
1524 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001525 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001526 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001527int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001528{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001529 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001530 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001531 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001532
Sathya Perlab31c50a2009-09-17 10:30:13 -07001533 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001534
Sathya Perlab31c50a2009-09-17 10:30:13 -07001535 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001536 if (!wrb) {
1537 status = -EBUSY;
1538 goto err;
1539 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001540 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001541
Somnath Kotur106df1e2011-10-27 07:12:13 +00001542 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301543 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb,
1544 nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001545
Sathya Perlaca34fe32012-11-06 17:48:56 +00001546 /* version 1 of the cmd is not supported only by BE2 */
Ajit Khaparde61000862013-10-03 16:16:33 -05001547 if (BE2_chip(adapter))
1548 hdr->version = 0;
1549 if (BE3_chip(adapter) || lancer_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001550 hdr->version = 1;
Ajit Khaparde61000862013-10-03 16:16:33 -05001551 else
1552 hdr->version = 2;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001553
Suresh Reddyefaa4082015-07-10 05:32:48 -04001554 status = be_mcc_notify(adapter);
1555 if (status)
1556 goto err;
1557
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001558 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001559
Sathya Perla713d03942009-11-22 22:02:45 +00001560err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001561 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001562 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001563}
1564
Selvin Xavier005d5692011-05-16 07:36:35 +00001565/* Lancer Stats */
1566int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301567 struct be_dma_mem *nonemb_cmd)
Selvin Xavier005d5692011-05-16 07:36:35 +00001568{
Selvin Xavier005d5692011-05-16 07:36:35 +00001569 struct be_mcc_wrb *wrb;
1570 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001571 int status = 0;
1572
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001573 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1574 CMD_SUBSYSTEM_ETH))
1575 return -EPERM;
1576
Selvin Xavier005d5692011-05-16 07:36:35 +00001577 spin_lock_bh(&adapter->mcc_lock);
1578
1579 wrb = wrb_from_mccq(adapter);
1580 if (!wrb) {
1581 status = -EBUSY;
1582 goto err;
1583 }
1584 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001585
Somnath Kotur106df1e2011-10-27 07:12:13 +00001586 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301587 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size,
1588 wrb, nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001589
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001590 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001591 req->cmd_params.params.reset_stats = 0;
1592
Suresh Reddyefaa4082015-07-10 05:32:48 -04001593 status = be_mcc_notify(adapter);
1594 if (status)
1595 goto err;
1596
Selvin Xavier005d5692011-05-16 07:36:35 +00001597 adapter->stats_cmd_sent = true;
1598
1599err:
1600 spin_unlock_bh(&adapter->mcc_lock);
1601 return status;
1602}
1603
Sathya Perla323ff712012-09-28 04:39:43 +00001604static int be_mac_to_link_speed(int mac_speed)
1605{
1606 switch (mac_speed) {
1607 case PHY_LINK_SPEED_ZERO:
1608 return 0;
1609 case PHY_LINK_SPEED_10MBPS:
1610 return 10;
1611 case PHY_LINK_SPEED_100MBPS:
1612 return 100;
1613 case PHY_LINK_SPEED_1GBPS:
1614 return 1000;
1615 case PHY_LINK_SPEED_10GBPS:
1616 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301617 case PHY_LINK_SPEED_20GBPS:
1618 return 20000;
1619 case PHY_LINK_SPEED_25GBPS:
1620 return 25000;
1621 case PHY_LINK_SPEED_40GBPS:
1622 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001623 }
1624 return 0;
1625}
1626
1627/* Uses synchronous mcc
1628 * Returns link_speed in Mbps
1629 */
1630int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1631 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001632{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001633 struct be_mcc_wrb *wrb;
1634 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001635 int status;
1636
Sathya Perlab31c50a2009-09-17 10:30:13 -07001637 spin_lock_bh(&adapter->mcc_lock);
1638
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001639 if (link_status)
1640 *link_status = LINK_DOWN;
1641
Sathya Perlab31c50a2009-09-17 10:30:13 -07001642 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001643 if (!wrb) {
1644 status = -EBUSY;
1645 goto err;
1646 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001647 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001648
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001649 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301650 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1651 sizeof(*req), wrb, NULL);
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001652
Sathya Perlaca34fe32012-11-06 17:48:56 +00001653 /* version 1 of the cmd is not supported only by BE2 */
1654 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001655 req->hdr.version = 1;
1656
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001657 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001658
Sathya Perlab31c50a2009-09-17 10:30:13 -07001659 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001660 if (!status) {
1661 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301662
Sathya Perla323ff712012-09-28 04:39:43 +00001663 if (link_speed) {
1664 *link_speed = resp->link_speed ?
1665 le16_to_cpu(resp->link_speed) * 10 :
1666 be_mac_to_link_speed(resp->mac_speed);
1667
1668 if (!resp->logical_link_status)
1669 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001670 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001671 if (link_status)
1672 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001673 }
1674
Sathya Perla713d03942009-11-22 22:02:45 +00001675err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001676 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001677 return status;
1678}
1679
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001680/* Uses synchronous mcc */
1681int be_cmd_get_die_temperature(struct be_adapter *adapter)
1682{
1683 struct be_mcc_wrb *wrb;
1684 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301685 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001686
1687 spin_lock_bh(&adapter->mcc_lock);
1688
1689 wrb = wrb_from_mccq(adapter);
1690 if (!wrb) {
1691 status = -EBUSY;
1692 goto err;
1693 }
1694 req = embedded_payload(wrb);
1695
Somnath Kotur106df1e2011-10-27 07:12:13 +00001696 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301697 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES,
1698 sizeof(*req), wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001699
Suresh Reddyefaa4082015-07-10 05:32:48 -04001700 status = be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001701err:
1702 spin_unlock_bh(&adapter->mcc_lock);
1703 return status;
1704}
1705
Somnath Kotur311fddc2011-03-16 21:22:43 +00001706/* Uses synchronous mcc */
1707int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1708{
1709 struct be_mcc_wrb *wrb;
1710 struct be_cmd_req_get_fat *req;
1711 int status;
1712
1713 spin_lock_bh(&adapter->mcc_lock);
1714
1715 wrb = wrb_from_mccq(adapter);
1716 if (!wrb) {
1717 status = -EBUSY;
1718 goto err;
1719 }
1720 req = embedded_payload(wrb);
1721
Somnath Kotur106df1e2011-10-27 07:12:13 +00001722 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301723 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb,
1724 NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001725 req->fat_operation = cpu_to_le32(QUERY_FAT);
1726 status = be_mcc_notify_wait(adapter);
1727 if (!status) {
1728 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301729
Somnath Kotur311fddc2011-03-16 21:22:43 +00001730 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001731 *log_size = le32_to_cpu(resp->log_size) -
1732 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001733 }
1734err:
1735 spin_unlock_bh(&adapter->mcc_lock);
1736 return status;
1737}
1738
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301739int be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
Somnath Kotur311fddc2011-03-16 21:22:43 +00001740{
1741 struct be_dma_mem get_fat_cmd;
1742 struct be_mcc_wrb *wrb;
1743 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001744 u32 offset = 0, total_size, buf_size,
1745 log_offset = sizeof(u32), payload_len;
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301746 int status = 0;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001747
1748 if (buf_len == 0)
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301749 return -EIO;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001750
1751 total_size = buf_len;
1752
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001753 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05301754 get_fat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
1755 get_fat_cmd.size,
1756 &get_fat_cmd.dma, GFP_ATOMIC);
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001757 if (!get_fat_cmd.va) {
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001758 dev_err(&adapter->pdev->dev,
Kalesh APcd3307aa2014-09-19 15:47:02 +05301759 "Memory allocation failure while reading FAT data\n");
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301760 return -ENOMEM;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001761 }
1762
Somnath Kotur311fddc2011-03-16 21:22:43 +00001763 spin_lock_bh(&adapter->mcc_lock);
1764
Somnath Kotur311fddc2011-03-16 21:22:43 +00001765 while (total_size) {
1766 buf_size = min(total_size, (u32)60*1024);
1767 total_size -= buf_size;
1768
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001769 wrb = wrb_from_mccq(adapter);
1770 if (!wrb) {
1771 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001772 goto err;
1773 }
1774 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001775
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001776 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001777 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301778 OPCODE_COMMON_MANAGE_FAT, payload_len,
1779 wrb, &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001780
1781 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1782 req->read_log_offset = cpu_to_le32(log_offset);
1783 req->read_log_length = cpu_to_le32(buf_size);
1784 req->data_buffer_size = cpu_to_le32(buf_size);
1785
1786 status = be_mcc_notify_wait(adapter);
1787 if (!status) {
1788 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
Kalesh AP03d28ff2014-09-19 15:46:56 +05301789
Somnath Kotur311fddc2011-03-16 21:22:43 +00001790 memcpy(buf + offset,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301791 resp->data_buffer,
1792 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001793 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001794 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001795 goto err;
1796 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001797 offset += buf_size;
1798 log_offset += buf_size;
1799 }
1800err:
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05301801 dma_free_coherent(&adapter->pdev->dev, get_fat_cmd.size,
1802 get_fat_cmd.va, get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001803 spin_unlock_bh(&adapter->mcc_lock);
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301804 return status;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001805}
1806
Sathya Perla04b71172011-09-27 13:30:27 -04001807/* Uses synchronous mcc */
Kalesh APe97e3cd2014-07-17 16:20:26 +05301808int be_cmd_get_fw_ver(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001809{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001810 struct be_mcc_wrb *wrb;
1811 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001812 int status;
1813
Sathya Perla04b71172011-09-27 13:30:27 -04001814 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001815
Sathya Perla04b71172011-09-27 13:30:27 -04001816 wrb = wrb_from_mccq(adapter);
1817 if (!wrb) {
1818 status = -EBUSY;
1819 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001820 }
1821
Sathya Perla04b71172011-09-27 13:30:27 -04001822 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001823
Somnath Kotur106df1e2011-10-27 07:12:13 +00001824 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301825 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb,
1826 NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001827 status = be_mcc_notify_wait(adapter);
1828 if (!status) {
1829 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
Sathya Perlaacbafeb2014-09-02 09:56:46 +05301830
Vasundhara Volam242eb472014-09-12 17:39:15 +05301831 strlcpy(adapter->fw_ver, resp->firmware_version_string,
1832 sizeof(adapter->fw_ver));
1833 strlcpy(adapter->fw_on_flash, resp->fw_on_flash_version_string,
1834 sizeof(adapter->fw_on_flash));
Sathya Perla04b71172011-09-27 13:30:27 -04001835 }
1836err:
1837 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001838 return status;
1839}
1840
Sathya Perlab31c50a2009-09-17 10:30:13 -07001841/* set the EQ delay interval of an EQ to specified value
1842 * Uses async mcc
1843 */
Kalesh APb502ae82014-09-19 15:46:51 +05301844static int __be_cmd_modify_eqd(struct be_adapter *adapter,
1845 struct be_set_eqd *set_eqd, int num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001846{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001847 struct be_mcc_wrb *wrb;
1848 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla2632baf2013-10-01 16:00:00 +05301849 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001850
Sathya Perlab31c50a2009-09-17 10:30:13 -07001851 spin_lock_bh(&adapter->mcc_lock);
1852
1853 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001854 if (!wrb) {
1855 status = -EBUSY;
1856 goto err;
1857 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001858 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001859
Somnath Kotur106df1e2011-10-27 07:12:13 +00001860 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301861 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb,
1862 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001863
Sathya Perla2632baf2013-10-01 16:00:00 +05301864 req->num_eq = cpu_to_le32(num);
1865 for (i = 0; i < num; i++) {
1866 req->set_eqd[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
1867 req->set_eqd[i].phase = 0;
1868 req->set_eqd[i].delay_multiplier =
1869 cpu_to_le32(set_eqd[i].delay_multiplier);
1870 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001871
Suresh Reddyefaa4082015-07-10 05:32:48 -04001872 status = be_mcc_notify(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001873err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001874 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001875 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001876}
1877
Kalesh AP93676702014-09-12 17:39:20 +05301878int be_cmd_modify_eqd(struct be_adapter *adapter, struct be_set_eqd *set_eqd,
1879 int num)
1880{
1881 int num_eqs, i = 0;
1882
Suresh Reddyc8ba4ad02015-03-20 06:28:24 -04001883 while (num) {
1884 num_eqs = min(num, 8);
1885 __be_cmd_modify_eqd(adapter, &set_eqd[i], num_eqs);
1886 i += num_eqs;
1887 num -= num_eqs;
Kalesh AP93676702014-09-12 17:39:20 +05301888 }
1889
1890 return 0;
1891}
1892
Sathya Perlab31c50a2009-09-17 10:30:13 -07001893/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001894int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Vasundhara Volam435452a2015-03-20 06:28:23 -04001895 u32 num, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001896{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001897 struct be_mcc_wrb *wrb;
1898 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001899 int status;
1900
Sathya Perlab31c50a2009-09-17 10:30:13 -07001901 spin_lock_bh(&adapter->mcc_lock);
1902
1903 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001904 if (!wrb) {
1905 status = -EBUSY;
1906 goto err;
1907 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001908 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001909
Somnath Kotur106df1e2011-10-27 07:12:13 +00001910 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301911 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req),
1912 wrb, NULL);
Vasundhara Volam435452a2015-03-20 06:28:23 -04001913 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001914
1915 req->interface_id = if_id;
Ajit Khaparde012bd382013-11-18 10:44:24 -06001916 req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001917 req->num_vlan = num;
Kalesh AP4d567d92014-05-09 13:29:17 +05301918 memcpy(req->normal_vlan, vtag_array,
1919 req->num_vlan * sizeof(vtag_array[0]));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001920
Sathya Perlab31c50a2009-09-17 10:30:13 -07001921 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001922err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001923 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001924 return status;
1925}
1926
Sathya Perlaac34b742015-02-06 08:18:40 -05001927static int __be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001928{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001929 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001930 struct be_dma_mem *mem = &adapter->rx_filter;
1931 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001932 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001933
Sathya Perla8788fdc2009-07-27 22:52:03 +00001934 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001935
Sathya Perlab31c50a2009-09-17 10:30:13 -07001936 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001937 if (!wrb) {
1938 status = -EBUSY;
1939 goto err;
1940 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001941 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001942 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301943 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1944 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001945
Sathya Perla5b8821b2011-08-02 19:57:44 +00001946 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perlaac34b742015-02-06 08:18:40 -05001947 req->if_flags_mask = cpu_to_le32(flags);
1948 req->if_flags = (value == ON) ? req->if_flags_mask : 0;
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001949
Sathya Perlaac34b742015-02-06 08:18:40 -05001950 if (flags & BE_IF_FLAGS_MULTICAST) {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001951 struct netdev_hw_addr *ha;
1952 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001953
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001954 /* Reset mcast promisc mode if already set by setting mask
1955 * and not setting flags field
1956 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001957 req->if_flags_mask |=
1958 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05301959 be_if_cap_flags(adapter));
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001960 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001961 netdev_for_each_mc_addr(ha, adapter->netdev)
1962 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1963 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001964
Sathya Perla0d1d5872011-08-03 05:19:27 -07001965 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001966err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001967 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001968 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001969}
1970
Sathya Perlaac34b742015-02-06 08:18:40 -05001971int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
1972{
1973 struct device *dev = &adapter->pdev->dev;
1974
1975 if ((flags & be_if_cap_flags(adapter)) != flags) {
1976 dev_warn(dev, "Cannot set rx filter flags 0x%x\n", flags);
1977 dev_warn(dev, "Interface is capable of 0x%x flags only\n",
1978 be_if_cap_flags(adapter));
1979 }
1980 flags &= be_if_cap_flags(adapter);
1981
1982 return __be_cmd_rx_filter(adapter, flags, value);
1983}
1984
Sathya Perlab31c50a2009-09-17 10:30:13 -07001985/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001986int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001987{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001988 struct be_mcc_wrb *wrb;
1989 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001990 int status;
1991
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001992 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1993 CMD_SUBSYSTEM_COMMON))
1994 return -EPERM;
1995
Sathya Perlab31c50a2009-09-17 10:30:13 -07001996 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001997
Sathya Perlab31c50a2009-09-17 10:30:13 -07001998 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001999 if (!wrb) {
2000 status = -EBUSY;
2001 goto err;
2002 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002003 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002004
Somnath Kotur106df1e2011-10-27 07:12:13 +00002005 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302006 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req),
2007 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002008
Suresh Reddyb29812c2014-09-12 17:39:17 +05302009 req->hdr.version = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002010 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
2011 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
2012
Sathya Perlab31c50a2009-09-17 10:30:13 -07002013 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002014
Sathya Perla713d03942009-11-22 22:02:45 +00002015err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07002016 spin_unlock_bh(&adapter->mcc_lock);
Suresh Reddyb29812c2014-09-12 17:39:17 +05302017
2018 if (base_status(status) == MCC_STATUS_FEATURE_NOT_SUPPORTED)
2019 return -EOPNOTSUPP;
2020
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002021 return status;
2022}
2023
Sathya Perlab31c50a2009-09-17 10:30:13 -07002024/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002025int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002026{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002027 struct be_mcc_wrb *wrb;
2028 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002029 int status;
2030
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002031 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
2032 CMD_SUBSYSTEM_COMMON))
2033 return -EPERM;
2034
Sathya Perlab31c50a2009-09-17 10:30:13 -07002035 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002036
Sathya Perlab31c50a2009-09-17 10:30:13 -07002037 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002038 if (!wrb) {
2039 status = -EBUSY;
2040 goto err;
2041 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002042 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002043
Somnath Kotur106df1e2011-10-27 07:12:13 +00002044 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302045 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req),
2046 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002047
Sathya Perlab31c50a2009-09-17 10:30:13 -07002048 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002049 if (!status) {
2050 struct be_cmd_resp_get_flow_control *resp =
2051 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302052
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002053 *tx_fc = le16_to_cpu(resp->tx_flow_control);
2054 *rx_fc = le16_to_cpu(resp->rx_flow_control);
2055 }
2056
Sathya Perla713d03942009-11-22 22:02:45 +00002057err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07002058 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002059 return status;
2060}
2061
Sathya Perlab31c50a2009-09-17 10:30:13 -07002062/* Uses mbox */
Kalesh APe97e3cd2014-07-17 16:20:26 +05302063int be_cmd_query_fw_cfg(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002064{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002065 struct be_mcc_wrb *wrb;
2066 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002067 int status;
2068
Ivan Vecera29849612010-12-14 05:43:19 +00002069 if (mutex_lock_interruptible(&adapter->mbox_lock))
2070 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002071
Sathya Perlab31c50a2009-09-17 10:30:13 -07002072 wrb = wrb_from_mbox(adapter);
2073 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002074
Somnath Kotur106df1e2011-10-27 07:12:13 +00002075 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302076 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
2077 sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002078
Sathya Perlab31c50a2009-09-17 10:30:13 -07002079 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002080 if (!status) {
2081 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302082
Kalesh APe97e3cd2014-07-17 16:20:26 +05302083 adapter->port_num = le32_to_cpu(resp->phys_port);
2084 adapter->function_mode = le32_to_cpu(resp->function_mode);
2085 adapter->function_caps = le32_to_cpu(resp->function_caps);
2086 adapter->asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perlaacbafeb2014-09-02 09:56:46 +05302087 dev_info(&adapter->pdev->dev,
2088 "FW config: function_mode=0x%x, function_caps=0x%x\n",
2089 adapter->function_mode, adapter->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002090 }
2091
Ivan Vecera29849612010-12-14 05:43:19 +00002092 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002093 return status;
2094}
sarveshwarb14074ea2009-08-05 13:05:24 -07002095
Sathya Perlab31c50a2009-09-17 10:30:13 -07002096/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07002097int be_cmd_reset_function(struct be_adapter *adapter)
2098{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002099 struct be_mcc_wrb *wrb;
2100 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07002101 int status;
2102
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002103 if (lancer_chip(adapter)) {
Sathya Perla9fa465c2015-02-23 04:20:13 -05002104 iowrite32(SLI_PORT_CONTROL_IP_MASK,
2105 adapter->db + SLIPORT_CONTROL_OFFSET);
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002106 status = lancer_wait_ready(adapter);
Sathya Perla9fa465c2015-02-23 04:20:13 -05002107 if (status)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002108 dev_err(&adapter->pdev->dev,
2109 "Adapter in non recoverable error\n");
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002110 return status;
2111 }
2112
Ivan Vecera29849612010-12-14 05:43:19 +00002113 if (mutex_lock_interruptible(&adapter->mbox_lock))
2114 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07002115
Sathya Perlab31c50a2009-09-17 10:30:13 -07002116 wrb = wrb_from_mbox(adapter);
2117 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07002118
Somnath Kotur106df1e2011-10-27 07:12:13 +00002119 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302120 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb,
2121 NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07002122
Sathya Perlab31c50a2009-09-17 10:30:13 -07002123 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07002124
Ivan Vecera29849612010-12-14 05:43:19 +00002125 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07002126 return status;
2127}
Ajit Khaparde84517482009-09-04 03:12:16 +00002128
Suresh Reddy594ad542013-04-25 23:03:20 +00002129int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01002130 u32 rss_hash_opts, u16 table_size, const u8 *rss_hkey)
Sathya Perla3abcded2010-10-03 22:12:27 -07002131{
2132 struct be_mcc_wrb *wrb;
2133 struct be_cmd_req_rss_config *req;
Sathya Perla3abcded2010-10-03 22:12:27 -07002134 int status;
2135
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302136 if (!(be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS))
2137 return 0;
2138
Kalesh APb51aa362014-05-09 13:29:19 +05302139 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002140
Kalesh APb51aa362014-05-09 13:29:19 +05302141 wrb = wrb_from_mccq(adapter);
2142 if (!wrb) {
2143 status = -EBUSY;
2144 goto err;
2145 }
Sathya Perla3abcded2010-10-03 22:12:27 -07002146 req = embedded_payload(wrb);
2147
Somnath Kotur106df1e2011-10-27 07:12:13 +00002148 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302149 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07002150
2151 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00002152 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07002153 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00002154
Kalesh APb51aa362014-05-09 13:29:19 +05302155 if (!BEx_chip(adapter))
Suresh Reddy594ad542013-04-25 23:03:20 +00002156 req->hdr.version = 1;
2157
Sathya Perla3abcded2010-10-03 22:12:27 -07002158 memcpy(req->cpu_table, rsstable, table_size);
Venkata Duvvurue2557872014-04-21 15:38:00 +05302159 memcpy(req->hash, rss_hkey, RSS_HASH_KEY_LEN);
Sathya Perla3abcded2010-10-03 22:12:27 -07002160 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
2161
Kalesh APb51aa362014-05-09 13:29:19 +05302162 status = be_mcc_notify_wait(adapter);
2163err:
2164 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002165 return status;
2166}
2167
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002168/* Uses sync mcc */
2169int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302170 u8 bcn, u8 sts, u8 state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002171{
2172 struct be_mcc_wrb *wrb;
2173 struct be_cmd_req_enable_disable_beacon *req;
2174 int status;
2175
2176 spin_lock_bh(&adapter->mcc_lock);
2177
2178 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002179 if (!wrb) {
2180 status = -EBUSY;
2181 goto err;
2182 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002183 req = embedded_payload(wrb);
2184
Somnath Kotur106df1e2011-10-27 07:12:13 +00002185 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302186 OPCODE_COMMON_ENABLE_DISABLE_BEACON,
2187 sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002188
2189 req->port_num = port_num;
2190 req->beacon_state = state;
2191 req->beacon_duration = bcn;
2192 req->status_duration = sts;
2193
2194 status = be_mcc_notify_wait(adapter);
2195
Sathya Perla713d03942009-11-22 22:02:45 +00002196err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002197 spin_unlock_bh(&adapter->mcc_lock);
2198 return status;
2199}
2200
2201/* Uses sync mcc */
2202int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2203{
2204 struct be_mcc_wrb *wrb;
2205 struct be_cmd_req_get_beacon_state *req;
2206 int status;
2207
2208 spin_lock_bh(&adapter->mcc_lock);
2209
2210 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002211 if (!wrb) {
2212 status = -EBUSY;
2213 goto err;
2214 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002215 req = embedded_payload(wrb);
2216
Somnath Kotur106df1e2011-10-27 07:12:13 +00002217 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302218 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req),
2219 wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002220
2221 req->port_num = port_num;
2222
2223 status = be_mcc_notify_wait(adapter);
2224 if (!status) {
2225 struct be_cmd_resp_get_beacon_state *resp =
2226 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302227
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002228 *state = resp->beacon_state;
2229 }
2230
Sathya Perla713d03942009-11-22 22:02:45 +00002231err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002232 spin_unlock_bh(&adapter->mcc_lock);
2233 return status;
2234}
2235
Mark Leonarde36edd92014-09-12 17:39:18 +05302236/* Uses sync mcc */
2237int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2238 u8 page_num, u8 *data)
2239{
2240 struct be_dma_mem cmd;
2241 struct be_mcc_wrb *wrb;
2242 struct be_cmd_req_port_type *req;
2243 int status;
2244
2245 if (page_num > TR_PAGE_A2)
2246 return -EINVAL;
2247
2248 cmd.size = sizeof(struct be_cmd_resp_port_type);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302249 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
2250 GFP_ATOMIC);
Mark Leonarde36edd92014-09-12 17:39:18 +05302251 if (!cmd.va) {
2252 dev_err(&adapter->pdev->dev, "Memory allocation failed\n");
2253 return -ENOMEM;
2254 }
Mark Leonarde36edd92014-09-12 17:39:18 +05302255
2256 spin_lock_bh(&adapter->mcc_lock);
2257
2258 wrb = wrb_from_mccq(adapter);
2259 if (!wrb) {
2260 status = -EBUSY;
2261 goto err;
2262 }
2263 req = cmd.va;
2264
2265 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2266 OPCODE_COMMON_READ_TRANSRECV_DATA,
2267 cmd.size, wrb, &cmd);
2268
2269 req->port = cpu_to_le32(adapter->hba_port_num);
2270 req->page_num = cpu_to_le32(page_num);
2271 status = be_mcc_notify_wait(adapter);
2272 if (!status) {
2273 struct be_cmd_resp_port_type *resp = cmd.va;
2274
2275 memcpy(data, resp->page_data, PAGE_DATA_LEN);
2276 }
2277err:
2278 spin_unlock_bh(&adapter->mcc_lock);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302279 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Mark Leonarde36edd92014-09-12 17:39:18 +05302280 return status;
2281}
2282
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002283int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002284 u32 data_size, u32 data_offset,
2285 const char *obj_name, u32 *data_written,
2286 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002287{
2288 struct be_mcc_wrb *wrb;
2289 struct lancer_cmd_req_write_object *req;
2290 struct lancer_cmd_resp_write_object *resp;
2291 void *ctxt = NULL;
2292 int status;
2293
2294 spin_lock_bh(&adapter->mcc_lock);
2295 adapter->flash_status = 0;
2296
2297 wrb = wrb_from_mccq(adapter);
2298 if (!wrb) {
2299 status = -EBUSY;
2300 goto err_unlock;
2301 }
2302
2303 req = embedded_payload(wrb);
2304
Somnath Kotur106df1e2011-10-27 07:12:13 +00002305 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302306 OPCODE_COMMON_WRITE_OBJECT,
2307 sizeof(struct lancer_cmd_req_write_object), wrb,
2308 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002309
2310 ctxt = &req->context;
2311 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302312 write_length, ctxt, data_size);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002313
2314 if (data_size == 0)
2315 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302316 eof, ctxt, 1);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002317 else
2318 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302319 eof, ctxt, 0);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002320
2321 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2322 req->write_offset = cpu_to_le32(data_offset);
Vasundhara Volam242eb472014-09-12 17:39:15 +05302323 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002324 req->descriptor_count = cpu_to_le32(1);
2325 req->buf_len = cpu_to_le32(data_size);
2326 req->addr_low = cpu_to_le32((cmd->dma +
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302327 sizeof(struct lancer_cmd_req_write_object))
2328 & 0xFFFFFFFF);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002329 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2330 sizeof(struct lancer_cmd_req_write_object)));
2331
Suresh Reddyefaa4082015-07-10 05:32:48 -04002332 status = be_mcc_notify(adapter);
2333 if (status)
2334 goto err_unlock;
2335
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002336 spin_unlock_bh(&adapter->mcc_lock);
2337
Suresh Reddy5eeff632014-01-06 13:02:24 +05302338 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002339 msecs_to_jiffies(60000)))
Kalesh APfd451602014-07-17 16:20:21 +05302340 status = -ETIMEDOUT;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002341 else
2342 status = adapter->flash_status;
2343
2344 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002345 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002346 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002347 *change_status = resp->change_status;
2348 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002349 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002350 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002351
2352 return status;
2353
2354err_unlock:
2355 spin_unlock_bh(&adapter->mcc_lock);
2356 return status;
2357}
2358
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +05302359int be_cmd_query_cable_type(struct be_adapter *adapter)
2360{
2361 u8 page_data[PAGE_DATA_LEN];
2362 int status;
2363
2364 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2365 page_data);
2366 if (!status) {
2367 switch (adapter->phy.interface_type) {
2368 case PHY_TYPE_QSFP:
2369 adapter->phy.cable_type =
2370 page_data[QSFP_PLUS_CABLE_TYPE_OFFSET];
2371 break;
2372 case PHY_TYPE_SFP_PLUS_10GB:
2373 adapter->phy.cable_type =
2374 page_data[SFP_PLUS_CABLE_TYPE_OFFSET];
2375 break;
2376 default:
2377 adapter->phy.cable_type = 0;
2378 break;
2379 }
2380 }
2381 return status;
2382}
2383
Vasundhara Volam21252372015-02-06 08:18:42 -05002384int be_cmd_query_sfp_info(struct be_adapter *adapter)
2385{
2386 u8 page_data[PAGE_DATA_LEN];
2387 int status;
2388
2389 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2390 page_data);
2391 if (!status) {
2392 strlcpy(adapter->phy.vendor_name, page_data +
2393 SFP_VENDOR_NAME_OFFSET, SFP_VENDOR_NAME_LEN - 1);
2394 strlcpy(adapter->phy.vendor_pn,
2395 page_data + SFP_VENDOR_PN_OFFSET,
2396 SFP_VENDOR_NAME_LEN - 1);
2397 }
2398
2399 return status;
2400}
2401
Kalesh APf0613382014-08-01 17:47:32 +05302402int lancer_cmd_delete_object(struct be_adapter *adapter, const char *obj_name)
2403{
2404 struct lancer_cmd_req_delete_object *req;
2405 struct be_mcc_wrb *wrb;
2406 int status;
2407
2408 spin_lock_bh(&adapter->mcc_lock);
2409
2410 wrb = wrb_from_mccq(adapter);
2411 if (!wrb) {
2412 status = -EBUSY;
2413 goto err;
2414 }
2415
2416 req = embedded_payload(wrb);
2417
2418 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2419 OPCODE_COMMON_DELETE_OBJECT,
2420 sizeof(*req), wrb, NULL);
2421
Vasundhara Volam242eb472014-09-12 17:39:15 +05302422 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Kalesh APf0613382014-08-01 17:47:32 +05302423
2424 status = be_mcc_notify_wait(adapter);
2425err:
2426 spin_unlock_bh(&adapter->mcc_lock);
2427 return status;
2428}
2429
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002430int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302431 u32 data_size, u32 data_offset, const char *obj_name,
2432 u32 *data_read, u32 *eof, u8 *addn_status)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002433{
2434 struct be_mcc_wrb *wrb;
2435 struct lancer_cmd_req_read_object *req;
2436 struct lancer_cmd_resp_read_object *resp;
2437 int status;
2438
2439 spin_lock_bh(&adapter->mcc_lock);
2440
2441 wrb = wrb_from_mccq(adapter);
2442 if (!wrb) {
2443 status = -EBUSY;
2444 goto err_unlock;
2445 }
2446
2447 req = embedded_payload(wrb);
2448
2449 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302450 OPCODE_COMMON_READ_OBJECT,
2451 sizeof(struct lancer_cmd_req_read_object), wrb,
2452 NULL);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002453
2454 req->desired_read_len = cpu_to_le32(data_size);
2455 req->read_offset = cpu_to_le32(data_offset);
2456 strcpy(req->object_name, obj_name);
2457 req->descriptor_count = cpu_to_le32(1);
2458 req->buf_len = cpu_to_le32(data_size);
2459 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2460 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2461
2462 status = be_mcc_notify_wait(adapter);
2463
2464 resp = embedded_payload(wrb);
2465 if (!status) {
2466 *data_read = le32_to_cpu(resp->actual_read_len);
2467 *eof = le32_to_cpu(resp->eof);
2468 } else {
2469 *addn_status = resp->additional_status;
2470 }
2471
2472err_unlock:
2473 spin_unlock_bh(&adapter->mcc_lock);
2474 return status;
2475}
2476
Ajit Khaparde84517482009-09-04 03:12:16 +00002477int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002478 u32 flash_type, u32 flash_opcode, u32 img_offset,
2479 u32 buf_size)
Ajit Khaparde84517482009-09-04 03:12:16 +00002480{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002481 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002482 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002483 int status;
2484
Sathya Perlab31c50a2009-09-17 10:30:13 -07002485 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002486 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002487
2488 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002489 if (!wrb) {
2490 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002491 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002492 }
2493 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002494
Somnath Kotur106df1e2011-10-27 07:12:13 +00002495 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302496 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb,
2497 cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002498
2499 req->params.op_type = cpu_to_le32(flash_type);
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002500 if (flash_type == OPTYPE_OFFSET_SPECIFIED)
2501 req->params.offset = cpu_to_le32(img_offset);
2502
Ajit Khaparde84517482009-09-04 03:12:16 +00002503 req->params.op_code = cpu_to_le32(flash_opcode);
2504 req->params.data_buf_size = cpu_to_le32(buf_size);
2505
Suresh Reddyefaa4082015-07-10 05:32:48 -04002506 status = be_mcc_notify(adapter);
2507 if (status)
2508 goto err_unlock;
2509
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002510 spin_unlock_bh(&adapter->mcc_lock);
2511
Suresh Reddy5eeff632014-01-06 13:02:24 +05302512 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
2513 msecs_to_jiffies(40000)))
Kalesh APfd451602014-07-17 16:20:21 +05302514 status = -ETIMEDOUT;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002515 else
2516 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002517
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002518 return status;
2519
2520err_unlock:
2521 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002522 return status;
2523}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002524
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002525int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002526 u16 img_optype, u32 img_offset, u32 crc_offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002527{
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002528 struct be_cmd_read_flash_crc *req;
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002529 struct be_mcc_wrb *wrb;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002530 int status;
2531
2532 spin_lock_bh(&adapter->mcc_lock);
2533
2534 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002535 if (!wrb) {
2536 status = -EBUSY;
2537 goto err;
2538 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002539 req = embedded_payload(wrb);
2540
Somnath Kotur106df1e2011-10-27 07:12:13 +00002541 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002542 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2543 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002544
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002545 req->params.op_type = cpu_to_le32(img_optype);
2546 if (img_optype == OPTYPE_OFFSET_SPECIFIED)
2547 req->params.offset = cpu_to_le32(img_offset + crc_offset);
2548 else
2549 req->params.offset = cpu_to_le32(crc_offset);
2550
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002551 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002552 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002553
2554 status = be_mcc_notify_wait(adapter);
2555 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002556 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002557
Sathya Perla713d03942009-11-22 22:02:45 +00002558err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002559 spin_unlock_bh(&adapter->mcc_lock);
2560 return status;
2561}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002562
Dan Carpenterc196b022010-05-26 04:47:39 +00002563int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302564 struct be_dma_mem *nonemb_cmd)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002565{
2566 struct be_mcc_wrb *wrb;
2567 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002568 int status;
2569
2570 spin_lock_bh(&adapter->mcc_lock);
2571
2572 wrb = wrb_from_mccq(adapter);
2573 if (!wrb) {
2574 status = -EBUSY;
2575 goto err;
2576 }
2577 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002578
Somnath Kotur106df1e2011-10-27 07:12:13 +00002579 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302580 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req),
2581 wrb, nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002582 memcpy(req->magic_mac, mac, ETH_ALEN);
2583
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002584 status = be_mcc_notify_wait(adapter);
2585
2586err:
2587 spin_unlock_bh(&adapter->mcc_lock);
2588 return status;
2589}
Suresh Rff33a6e2009-12-03 16:15:52 -08002590
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002591int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2592 u8 loopback_type, u8 enable)
2593{
2594 struct be_mcc_wrb *wrb;
2595 struct be_cmd_req_set_lmode *req;
2596 int status;
2597
2598 spin_lock_bh(&adapter->mcc_lock);
2599
2600 wrb = wrb_from_mccq(adapter);
2601 if (!wrb) {
2602 status = -EBUSY;
2603 goto err;
2604 }
2605
2606 req = embedded_payload(wrb);
2607
Somnath Kotur106df1e2011-10-27 07:12:13 +00002608 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302609 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req),
2610 wrb, NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002611
2612 req->src_port = port_num;
2613 req->dest_port = port_num;
2614 req->loopback_type = loopback_type;
2615 req->loopback_state = enable;
2616
2617 status = be_mcc_notify_wait(adapter);
2618err:
2619 spin_unlock_bh(&adapter->mcc_lock);
2620 return status;
2621}
2622
Suresh Rff33a6e2009-12-03 16:15:52 -08002623int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302624 u32 loopback_type, u32 pkt_size, u32 num_pkts,
2625 u64 pattern)
Suresh Rff33a6e2009-12-03 16:15:52 -08002626{
2627 struct be_mcc_wrb *wrb;
2628 struct be_cmd_req_loopback_test *req;
Suresh Reddy5eeff632014-01-06 13:02:24 +05302629 struct be_cmd_resp_loopback_test *resp;
Suresh Rff33a6e2009-12-03 16:15:52 -08002630 int status;
2631
2632 spin_lock_bh(&adapter->mcc_lock);
2633
2634 wrb = wrb_from_mccq(adapter);
2635 if (!wrb) {
2636 status = -EBUSY;
2637 goto err;
2638 }
2639
2640 req = embedded_payload(wrb);
2641
Somnath Kotur106df1e2011-10-27 07:12:13 +00002642 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302643 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb,
2644 NULL);
Suresh Rff33a6e2009-12-03 16:15:52 -08002645
Suresh Reddy5eeff632014-01-06 13:02:24 +05302646 req->hdr.timeout = cpu_to_le32(15);
Suresh Rff33a6e2009-12-03 16:15:52 -08002647 req->pattern = cpu_to_le64(pattern);
2648 req->src_port = cpu_to_le32(port_num);
2649 req->dest_port = cpu_to_le32(port_num);
2650 req->pkt_size = cpu_to_le32(pkt_size);
2651 req->num_pkts = cpu_to_le32(num_pkts);
2652 req->loopback_type = cpu_to_le32(loopback_type);
2653
Suresh Reddyefaa4082015-07-10 05:32:48 -04002654 status = be_mcc_notify(adapter);
2655 if (status)
2656 goto err;
Suresh Rff33a6e2009-12-03 16:15:52 -08002657
Suresh Reddy5eeff632014-01-06 13:02:24 +05302658 spin_unlock_bh(&adapter->mcc_lock);
2659
2660 wait_for_completion(&adapter->et_cmd_compl);
2661 resp = embedded_payload(wrb);
2662 status = le32_to_cpu(resp->status);
2663
2664 return status;
Suresh Rff33a6e2009-12-03 16:15:52 -08002665err:
2666 spin_unlock_bh(&adapter->mcc_lock);
2667 return status;
2668}
2669
2670int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302671 u32 byte_cnt, struct be_dma_mem *cmd)
Suresh Rff33a6e2009-12-03 16:15:52 -08002672{
2673 struct be_mcc_wrb *wrb;
2674 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002675 int status;
2676 int i, j = 0;
2677
2678 spin_lock_bh(&adapter->mcc_lock);
2679
2680 wrb = wrb_from_mccq(adapter);
2681 if (!wrb) {
2682 status = -EBUSY;
2683 goto err;
2684 }
2685 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002686 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302687 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb,
2688 cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002689
2690 req->pattern = cpu_to_le64(pattern);
2691 req->byte_count = cpu_to_le32(byte_cnt);
2692 for (i = 0; i < byte_cnt; i++) {
2693 req->snd_buff[i] = (u8)(pattern >> (j*8));
2694 j++;
2695 if (j > 7)
2696 j = 0;
2697 }
2698
2699 status = be_mcc_notify_wait(adapter);
2700
2701 if (!status) {
2702 struct be_cmd_resp_ddrdma_test *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05302703
Suresh Rff33a6e2009-12-03 16:15:52 -08002704 resp = cmd->va;
2705 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
Kalesh APcd3307aa2014-09-19 15:47:02 +05302706 resp->snd_err) {
Suresh Rff33a6e2009-12-03 16:15:52 -08002707 status = -1;
2708 }
2709 }
2710
2711err:
2712 spin_unlock_bh(&adapter->mcc_lock);
2713 return status;
2714}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002715
Dan Carpenterc196b022010-05-26 04:47:39 +00002716int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302717 struct be_dma_mem *nonemb_cmd)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002718{
2719 struct be_mcc_wrb *wrb;
2720 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002721 int status;
2722
2723 spin_lock_bh(&adapter->mcc_lock);
2724
2725 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002726 if (!wrb) {
2727 status = -EBUSY;
2728 goto err;
2729 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002730 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002731
Somnath Kotur106df1e2011-10-27 07:12:13 +00002732 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302733 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2734 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002735
2736 status = be_mcc_notify_wait(adapter);
2737
Ajit Khapardee45ff012011-02-04 17:18:28 +00002738err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002739 spin_unlock_bh(&adapter->mcc_lock);
2740 return status;
2741}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002742
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002743int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002744{
2745 struct be_mcc_wrb *wrb;
2746 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002747 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002748 int status;
2749
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002750 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2751 CMD_SUBSYSTEM_COMMON))
2752 return -EPERM;
2753
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002754 spin_lock_bh(&adapter->mcc_lock);
2755
2756 wrb = wrb_from_mccq(adapter);
2757 if (!wrb) {
2758 status = -EBUSY;
2759 goto err;
2760 }
Sathya Perla306f1342011-08-02 19:57:45 +00002761 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302762 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
2763 GFP_ATOMIC);
Sathya Perla306f1342011-08-02 19:57:45 +00002764 if (!cmd.va) {
2765 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2766 status = -ENOMEM;
2767 goto err;
2768 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002769
Sathya Perla306f1342011-08-02 19:57:45 +00002770 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002771
Somnath Kotur106df1e2011-10-27 07:12:13 +00002772 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302773 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2774 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002775
2776 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002777 if (!status) {
2778 struct be_phy_info *resp_phy_info =
2779 cmd.va + sizeof(struct be_cmd_req_hdr);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302780
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002781 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2782 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002783 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002784 adapter->phy.auto_speeds_supported =
2785 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2786 adapter->phy.fixed_speeds_supported =
2787 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2788 adapter->phy.misc_params =
2789 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05302790
2791 if (BE2_chip(adapter)) {
2792 adapter->phy.fixed_speeds_supported =
2793 BE_SUPPORTED_SPEED_10GBPS |
2794 BE_SUPPORTED_SPEED_1GBPS;
2795 }
Sathya Perla306f1342011-08-02 19:57:45 +00002796 }
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302797 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002798err:
2799 spin_unlock_bh(&adapter->mcc_lock);
2800 return status;
2801}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002802
Lad, Prabhakarbc0ee162015-02-05 15:24:43 +00002803static int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
Ajit Khapardee1d18732010-07-23 01:52:13 +00002804{
2805 struct be_mcc_wrb *wrb;
2806 struct be_cmd_req_set_qos *req;
2807 int status;
2808
2809 spin_lock_bh(&adapter->mcc_lock);
2810
2811 wrb = wrb_from_mccq(adapter);
2812 if (!wrb) {
2813 status = -EBUSY;
2814 goto err;
2815 }
2816
2817 req = embedded_payload(wrb);
2818
Somnath Kotur106df1e2011-10-27 07:12:13 +00002819 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302820 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002821
2822 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002823 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2824 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002825
2826 status = be_mcc_notify_wait(adapter);
2827
2828err:
2829 spin_unlock_bh(&adapter->mcc_lock);
2830 return status;
2831}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002832
2833int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2834{
2835 struct be_mcc_wrb *wrb;
2836 struct be_cmd_req_cntl_attribs *req;
2837 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002838 int status;
2839 int payload_len = max(sizeof(*req), sizeof(*resp));
2840 struct mgmt_controller_attrib *attribs;
2841 struct be_dma_mem attribs_cmd;
2842
Suresh Reddyd98ef502013-04-25 00:56:55 +00002843 if (mutex_lock_interruptible(&adapter->mbox_lock))
2844 return -1;
2845
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002846 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2847 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302848 attribs_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
2849 attribs_cmd.size,
2850 &attribs_cmd.dma, GFP_ATOMIC);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002851 if (!attribs_cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302852 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002853 status = -ENOMEM;
2854 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002855 }
2856
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002857 wrb = wrb_from_mbox(adapter);
2858 if (!wrb) {
2859 status = -EBUSY;
2860 goto err;
2861 }
2862 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002863
Somnath Kotur106df1e2011-10-27 07:12:13 +00002864 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302865 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len,
2866 wrb, &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002867
2868 status = be_mbox_notify_wait(adapter);
2869 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002870 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002871 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2872 }
2873
2874err:
2875 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002876 if (attribs_cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302877 dma_free_coherent(&adapter->pdev->dev, attribs_cmd.size,
2878 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002879 return status;
2880}
Sathya Perla2e588f82011-03-11 02:49:26 +00002881
2882/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002883int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002884{
2885 struct be_mcc_wrb *wrb;
2886 struct be_cmd_req_set_func_cap *req;
2887 int status;
2888
2889 if (mutex_lock_interruptible(&adapter->mbox_lock))
2890 return -1;
2891
2892 wrb = wrb_from_mbox(adapter);
2893 if (!wrb) {
2894 status = -EBUSY;
2895 goto err;
2896 }
2897
2898 req = embedded_payload(wrb);
2899
Somnath Kotur106df1e2011-10-27 07:12:13 +00002900 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302901 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP,
2902 sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002903
2904 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2905 CAPABILITY_BE3_NATIVE_ERX_API);
2906 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2907
2908 status = be_mbox_notify_wait(adapter);
2909 if (!status) {
2910 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302911
Sathya Perla2e588f82011-03-11 02:49:26 +00002912 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2913 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002914 if (!adapter->be3_native)
2915 dev_warn(&adapter->pdev->dev,
2916 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002917 }
2918err:
2919 mutex_unlock(&adapter->mbox_lock);
2920 return status;
2921}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002922
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002923/* Get privilege(s) for a function */
2924int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2925 u32 domain)
2926{
2927 struct be_mcc_wrb *wrb;
2928 struct be_cmd_req_get_fn_privileges *req;
2929 int status;
2930
2931 spin_lock_bh(&adapter->mcc_lock);
2932
2933 wrb = wrb_from_mccq(adapter);
2934 if (!wrb) {
2935 status = -EBUSY;
2936 goto err;
2937 }
2938
2939 req = embedded_payload(wrb);
2940
2941 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2942 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2943 wrb, NULL);
2944
2945 req->hdr.domain = domain;
2946
2947 status = be_mcc_notify_wait(adapter);
2948 if (!status) {
2949 struct be_cmd_resp_get_fn_privileges *resp =
2950 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302951
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002952 *privilege = le32_to_cpu(resp->privilege_mask);
Suresh Reddy02308d72014-01-15 13:23:36 +05302953
2954 /* In UMC mode FW does not return right privileges.
2955 * Override with correct privilege equivalent to PF.
2956 */
2957 if (BEx_chip(adapter) && be_is_mc(adapter) &&
2958 be_physfn(adapter))
2959 *privilege = MAX_PRIVILEGES;
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002960 }
2961
2962err:
2963 spin_unlock_bh(&adapter->mcc_lock);
2964 return status;
2965}
2966
Sathya Perla04a06022013-07-23 15:25:00 +05302967/* Set privilege(s) for a function */
2968int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
2969 u32 domain)
2970{
2971 struct be_mcc_wrb *wrb;
2972 struct be_cmd_req_set_fn_privileges *req;
2973 int status;
2974
2975 spin_lock_bh(&adapter->mcc_lock);
2976
2977 wrb = wrb_from_mccq(adapter);
2978 if (!wrb) {
2979 status = -EBUSY;
2980 goto err;
2981 }
2982
2983 req = embedded_payload(wrb);
2984 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2985 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
2986 wrb, NULL);
2987 req->hdr.domain = domain;
2988 if (lancer_chip(adapter))
2989 req->privileges_lancer = cpu_to_le32(privileges);
2990 else
2991 req->privileges = cpu_to_le32(privileges);
2992
2993 status = be_mcc_notify_wait(adapter);
2994err:
2995 spin_unlock_bh(&adapter->mcc_lock);
2996 return status;
2997}
2998
Sathya Perla5a712c12013-07-23 15:24:59 +05302999/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
3000 * pmac_id_valid: false => pmac_id or MAC address is requested.
3001 * If pmac_id is returned, pmac_id_valid is returned as true
3002 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003003int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303004 bool *pmac_id_valid, u32 *pmac_id, u32 if_handle,
3005 u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003006{
3007 struct be_mcc_wrb *wrb;
3008 struct be_cmd_req_get_mac_list *req;
3009 int status;
3010 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003011 struct be_dma_mem get_mac_list_cmd;
3012 int i;
3013
3014 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
3015 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303016 get_mac_list_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
3017 get_mac_list_cmd.size,
3018 &get_mac_list_cmd.dma,
3019 GFP_ATOMIC);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003020
3021 if (!get_mac_list_cmd.va) {
3022 dev_err(&adapter->pdev->dev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303023 "Memory allocation failure during GET_MAC_LIST\n");
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003024 return -ENOMEM;
3025 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003026
3027 spin_lock_bh(&adapter->mcc_lock);
3028
3029 wrb = wrb_from_mccq(adapter);
3030 if (!wrb) {
3031 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003032 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003033 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003034
3035 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003036
3037 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00003038 OPCODE_COMMON_GET_MAC_LIST,
3039 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003040 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003041 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05303042 if (*pmac_id_valid) {
3043 req->mac_id = cpu_to_le32(*pmac_id);
Suresh Reddyb188f092014-01-15 13:23:39 +05303044 req->iface_id = cpu_to_le16(if_handle);
Sathya Perla5a712c12013-07-23 15:24:59 +05303045 req->perm_override = 0;
3046 } else {
3047 req->perm_override = 1;
3048 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003049
3050 status = be_mcc_notify_wait(adapter);
3051 if (!status) {
3052 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003053 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05303054
3055 if (*pmac_id_valid) {
3056 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
3057 ETH_ALEN);
3058 goto out;
3059 }
3060
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003061 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
3062 /* Mac list returned could contain one or more active mac_ids
Joe Perchesdbedd442015-03-06 20:49:12 -08003063 * or one or more true or pseudo permanent mac addresses.
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003064 * If an active mac_id is present, return first active mac_id
3065 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003066 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003067 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003068 struct get_list_macaddr *mac_entry;
3069 u16 mac_addr_size;
3070 u32 mac_id;
3071
3072 mac_entry = &resp->macaddr_list[i];
3073 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
3074 /* mac_id is a 32 bit value and mac_addr size
3075 * is 6 bytes
3076 */
3077 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05303078 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003079 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
3080 *pmac_id = le32_to_cpu(mac_id);
3081 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003082 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003083 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003084 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05303085 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003086 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303087 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003088 }
3089
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003090out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003091 spin_unlock_bh(&adapter->mcc_lock);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303092 dma_free_coherent(&adapter->pdev->dev, get_mac_list_cmd.size,
3093 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003094 return status;
3095}
3096
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303097int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id,
3098 u8 *mac, u32 if_handle, bool active, u32 domain)
Sathya Perla5a712c12013-07-23 15:24:59 +05303099{
Suresh Reddyb188f092014-01-15 13:23:39 +05303100 if (!active)
3101 be_cmd_get_mac_from_list(adapter, mac, &active, &curr_pmac_id,
3102 if_handle, domain);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303103 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05303104 return be_cmd_mac_addr_query(adapter, mac, false,
Suresh Reddyb188f092014-01-15 13:23:39 +05303105 if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303106 else
3107 /* Fetch the MAC address using pmac_id */
3108 return be_cmd_get_mac_from_list(adapter, mac, &active,
Suresh Reddyb188f092014-01-15 13:23:39 +05303109 &curr_pmac_id,
3110 if_handle, domain);
Sathya Perla5a712c12013-07-23 15:24:59 +05303111}
3112
Sathya Perla95046b92013-07-23 15:25:02 +05303113int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
3114{
3115 int status;
3116 bool pmac_valid = false;
3117
Joe Perchesc7bf7162015-03-02 19:54:47 -08003118 eth_zero_addr(mac);
Sathya Perla95046b92013-07-23 15:25:02 +05303119
Sathya Perla3175d8c2013-07-23 15:25:03 +05303120 if (BEx_chip(adapter)) {
3121 if (be_physfn(adapter))
3122 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
3123 0);
3124 else
3125 status = be_cmd_mac_addr_query(adapter, mac, false,
3126 adapter->if_handle, 0);
3127 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05303128 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
Suresh Reddyb188f092014-01-15 13:23:39 +05303129 NULL, adapter->if_handle, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303130 }
3131
Sathya Perla95046b92013-07-23 15:25:02 +05303132 return status;
3133}
3134
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003135/* Uses synchronous MCCQ */
3136int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
3137 u8 mac_count, u32 domain)
3138{
3139 struct be_mcc_wrb *wrb;
3140 struct be_cmd_req_set_mac_list *req;
3141 int status;
3142 struct be_dma_mem cmd;
3143
3144 memset(&cmd, 0, sizeof(struct be_dma_mem));
3145 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303146 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3147 GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00003148 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003149 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003150
3151 spin_lock_bh(&adapter->mcc_lock);
3152
3153 wrb = wrb_from_mccq(adapter);
3154 if (!wrb) {
3155 status = -EBUSY;
3156 goto err;
3157 }
3158
3159 req = cmd.va;
3160 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303161 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
3162 wrb, &cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003163
3164 req->hdr.domain = domain;
3165 req->mac_count = mac_count;
3166 if (mac_count)
3167 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
3168
3169 status = be_mcc_notify_wait(adapter);
3170
3171err:
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303172 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003173 spin_unlock_bh(&adapter->mcc_lock);
3174 return status;
3175}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003176
Sathya Perla3175d8c2013-07-23 15:25:03 +05303177/* Wrapper to delete any active MACs and provision the new mac.
3178 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
3179 * current list are active.
3180 */
3181int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
3182{
3183 bool active_mac = false;
3184 u8 old_mac[ETH_ALEN];
3185 u32 pmac_id;
3186 int status;
3187
3188 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303189 &pmac_id, if_id, dom);
3190
Sathya Perla3175d8c2013-07-23 15:25:03 +05303191 if (!status && active_mac)
3192 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
3193
3194 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
3195}
3196
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003197int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
Kalesh APe7bcbd72015-05-06 05:30:32 -04003198 u32 domain, u16 intf_id, u16 hsw_mode, u8 spoofchk)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003199{
3200 struct be_mcc_wrb *wrb;
3201 struct be_cmd_req_set_hsw_config *req;
3202 void *ctxt;
3203 int status;
3204
3205 spin_lock_bh(&adapter->mcc_lock);
3206
3207 wrb = wrb_from_mccq(adapter);
3208 if (!wrb) {
3209 status = -EBUSY;
3210 goto err;
3211 }
3212
3213 req = embedded_payload(wrb);
3214 ctxt = &req->context;
3215
3216 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303217 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb,
3218 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003219
3220 req->hdr.domain = domain;
3221 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
3222 if (pvid) {
3223 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
3224 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
3225 }
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003226 if (!BEx_chip(adapter) && hsw_mode) {
3227 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id,
3228 ctxt, adapter->hba_port_num);
3229 AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1);
3230 AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type,
3231 ctxt, hsw_mode);
3232 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003233
Kalesh APe7bcbd72015-05-06 05:30:32 -04003234 /* Enable/disable both mac and vlan spoof checking */
3235 if (!BEx_chip(adapter) && spoofchk) {
3236 AMAP_SET_BITS(struct amap_set_hsw_context, mac_spoofchk,
3237 ctxt, spoofchk);
3238 AMAP_SET_BITS(struct amap_set_hsw_context, vlan_spoofchk,
3239 ctxt, spoofchk);
3240 }
3241
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003242 be_dws_cpu_to_le(req->context, sizeof(req->context));
3243 status = be_mcc_notify_wait(adapter);
3244
3245err:
3246 spin_unlock_bh(&adapter->mcc_lock);
3247 return status;
3248}
3249
3250/* Get Hyper switch config */
3251int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
Kalesh APe7bcbd72015-05-06 05:30:32 -04003252 u32 domain, u16 intf_id, u8 *mode, bool *spoofchk)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003253{
3254 struct be_mcc_wrb *wrb;
3255 struct be_cmd_req_get_hsw_config *req;
3256 void *ctxt;
3257 int status;
3258 u16 vid;
3259
3260 spin_lock_bh(&adapter->mcc_lock);
3261
3262 wrb = wrb_from_mccq(adapter);
3263 if (!wrb) {
3264 status = -EBUSY;
3265 goto err;
3266 }
3267
3268 req = embedded_payload(wrb);
3269 ctxt = &req->context;
3270
3271 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303272 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb,
3273 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003274
3275 req->hdr.domain = domain;
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003276 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3277 ctxt, intf_id);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003278 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003279
Vasundhara Volam2c07c1d2014-01-15 13:23:32 +05303280 if (!BEx_chip(adapter) && mode) {
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003281 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3282 ctxt, adapter->hba_port_num);
3283 AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1);
3284 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003285 be_dws_cpu_to_le(req->context, sizeof(req->context));
3286
3287 status = be_mcc_notify_wait(adapter);
3288 if (!status) {
3289 struct be_cmd_resp_get_hsw_config *resp =
3290 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303291
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303292 be_dws_le_to_cpu(&resp->context, sizeof(resp->context));
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003293 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303294 pvid, &resp->context);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003295 if (pvid)
3296 *pvid = le16_to_cpu(vid);
3297 if (mode)
3298 *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3299 port_fwd_type, &resp->context);
Kalesh APe7bcbd72015-05-06 05:30:32 -04003300 if (spoofchk)
3301 *spoofchk =
3302 AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3303 spoofchk, &resp->context);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003304 }
3305
3306err:
3307 spin_unlock_bh(&adapter->mcc_lock);
3308 return status;
3309}
3310
Sathya Perlaf7062ee2015-02-06 08:18:35 -05003311static bool be_is_wol_excluded(struct be_adapter *adapter)
3312{
3313 struct pci_dev *pdev = adapter->pdev;
3314
Kalesh AP18c57c72015-05-06 05:30:38 -04003315 if (be_virtfn(adapter))
Sathya Perlaf7062ee2015-02-06 08:18:35 -05003316 return true;
3317
3318 switch (pdev->subsystem_device) {
3319 case OC_SUBSYS_DEVICE_ID1:
3320 case OC_SUBSYS_DEVICE_ID2:
3321 case OC_SUBSYS_DEVICE_ID3:
3322 case OC_SUBSYS_DEVICE_ID4:
3323 return true;
3324 default:
3325 return false;
3326 }
3327}
3328
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003329int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
3330{
3331 struct be_mcc_wrb *wrb;
3332 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303333 int status = 0;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003334 struct be_dma_mem cmd;
3335
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003336 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
3337 CMD_SUBSYSTEM_ETH))
3338 return -EPERM;
3339
Suresh Reddy76a9e082014-01-15 13:23:40 +05303340 if (be_is_wol_excluded(adapter))
3341 return status;
3342
Suresh Reddyd98ef502013-04-25 00:56:55 +00003343 if (mutex_lock_interruptible(&adapter->mbox_lock))
3344 return -1;
3345
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003346 memset(&cmd, 0, sizeof(struct be_dma_mem));
3347 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303348 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3349 GFP_ATOMIC);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003350 if (!cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303351 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003352 status = -ENOMEM;
3353 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003354 }
3355
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003356 wrb = wrb_from_mbox(adapter);
3357 if (!wrb) {
3358 status = -EBUSY;
3359 goto err;
3360 }
3361
3362 req = cmd.va;
3363
3364 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
3365 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
Suresh Reddy76a9e082014-01-15 13:23:40 +05303366 sizeof(*req), wrb, &cmd);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003367
3368 req->hdr.version = 1;
3369 req->query_options = BE_GET_WOL_CAP;
3370
3371 status = be_mbox_notify_wait(adapter);
3372 if (!status) {
3373 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05303374
Kalesh AP504fbf12014-09-19 15:47:00 +05303375 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *)cmd.va;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003376
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003377 adapter->wol_cap = resp->wol_settings;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303378 if (adapter->wol_cap & BE_WOL_CAP)
3379 adapter->wol_en = true;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003380 }
3381err:
3382 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003383 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303384 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
3385 cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003386 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00003387
3388}
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303389
3390int be_cmd_set_fw_log_level(struct be_adapter *adapter, u32 level)
3391{
3392 struct be_dma_mem extfat_cmd;
3393 struct be_fat_conf_params *cfgs;
3394 int status;
3395 int i, j;
3396
3397 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3398 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303399 extfat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
3400 extfat_cmd.size, &extfat_cmd.dma,
3401 GFP_ATOMIC);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303402 if (!extfat_cmd.va)
3403 return -ENOMEM;
3404
3405 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3406 if (status)
3407 goto err;
3408
3409 cfgs = (struct be_fat_conf_params *)
3410 (extfat_cmd.va + sizeof(struct be_cmd_resp_hdr));
3411 for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
3412 u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303413
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303414 for (j = 0; j < num_modes; j++) {
3415 if (cfgs->module[i].trace_lvl[j].mode == MODE_UART)
3416 cfgs->module[i].trace_lvl[j].dbg_lvl =
3417 cpu_to_le32(level);
3418 }
3419 }
3420
3421 status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd, cfgs);
3422err:
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303423 dma_free_coherent(&adapter->pdev->dev, extfat_cmd.size, extfat_cmd.va,
3424 extfat_cmd.dma);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303425 return status;
3426}
3427
3428int be_cmd_get_fw_log_level(struct be_adapter *adapter)
3429{
3430 struct be_dma_mem extfat_cmd;
3431 struct be_fat_conf_params *cfgs;
3432 int status, j;
3433 int level = 0;
3434
3435 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3436 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303437 extfat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
3438 extfat_cmd.size, &extfat_cmd.dma,
3439 GFP_ATOMIC);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303440
3441 if (!extfat_cmd.va) {
3442 dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
3443 __func__);
3444 goto err;
3445 }
3446
3447 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3448 if (!status) {
3449 cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
3450 sizeof(struct be_cmd_resp_hdr));
Kalesh AP03d28ff2014-09-19 15:46:56 +05303451
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303452 for (j = 0; j < le32_to_cpu(cfgs->module[0].num_modes); j++) {
3453 if (cfgs->module[0].trace_lvl[j].mode == MODE_UART)
3454 level = cfgs->module[0].trace_lvl[j].dbg_lvl;
3455 }
3456 }
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303457 dma_free_coherent(&adapter->pdev->dev, extfat_cmd.size, extfat_cmd.va,
3458 extfat_cmd.dma);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303459err:
3460 return level;
3461}
3462
Somnath Kotur941a77d2012-05-17 22:59:03 +00003463int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
3464 struct be_dma_mem *cmd)
3465{
3466 struct be_mcc_wrb *wrb;
3467 struct be_cmd_req_get_ext_fat_caps *req;
3468 int status;
3469
3470 if (mutex_lock_interruptible(&adapter->mbox_lock))
3471 return -1;
3472
3473 wrb = wrb_from_mbox(adapter);
3474 if (!wrb) {
3475 status = -EBUSY;
3476 goto err;
3477 }
3478
3479 req = cmd->va;
3480 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3481 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
3482 cmd->size, wrb, cmd);
3483 req->parameter_type = cpu_to_le32(1);
3484
3485 status = be_mbox_notify_wait(adapter);
3486err:
3487 mutex_unlock(&adapter->mbox_lock);
3488 return status;
3489}
3490
3491int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
3492 struct be_dma_mem *cmd,
3493 struct be_fat_conf_params *configs)
3494{
3495 struct be_mcc_wrb *wrb;
3496 struct be_cmd_req_set_ext_fat_caps *req;
3497 int status;
3498
3499 spin_lock_bh(&adapter->mcc_lock);
3500
3501 wrb = wrb_from_mccq(adapter);
3502 if (!wrb) {
3503 status = -EBUSY;
3504 goto err;
3505 }
3506
3507 req = cmd->va;
3508 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
3509 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3510 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
3511 cmd->size, wrb, cmd);
3512
3513 status = be_mcc_notify_wait(adapter);
3514err:
3515 spin_unlock_bh(&adapter->mcc_lock);
3516 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003517}
Parav Pandit6a4ab662012-03-26 14:27:12 +00003518
Vasundhara Volam21252372015-02-06 08:18:42 -05003519int be_cmd_query_port_name(struct be_adapter *adapter)
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003520{
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003521 struct be_cmd_req_get_port_name *req;
Vasundhara Volam21252372015-02-06 08:18:42 -05003522 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003523 int status;
3524
Vasundhara Volam21252372015-02-06 08:18:42 -05003525 if (mutex_lock_interruptible(&adapter->mbox_lock))
3526 return -1;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003527
Vasundhara Volam21252372015-02-06 08:18:42 -05003528 wrb = wrb_from_mbox(adapter);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003529 req = embedded_payload(wrb);
3530
3531 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3532 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
3533 NULL);
Vasundhara Volam21252372015-02-06 08:18:42 -05003534 if (!BEx_chip(adapter))
3535 req->hdr.version = 1;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003536
Vasundhara Volam21252372015-02-06 08:18:42 -05003537 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003538 if (!status) {
3539 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303540
Vasundhara Volam21252372015-02-06 08:18:42 -05003541 adapter->port_name = resp->port_name[adapter->hba_port_num];
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003542 } else {
Vasundhara Volam21252372015-02-06 08:18:42 -05003543 adapter->port_name = adapter->hba_port_num + '0';
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003544 }
Vasundhara Volam21252372015-02-06 08:18:42 -05003545
3546 mutex_unlock(&adapter->mbox_lock);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003547 return status;
3548}
3549
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303550/* Descriptor type */
3551enum {
3552 FUNC_DESC = 1,
3553 VFT_DESC = 2
3554};
3555
3556static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
3557 int desc_type)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003558{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303559 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303560 struct be_nic_res_desc *nic;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003561 int i;
3562
3563 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303564 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303565 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) {
3566 nic = (struct be_nic_res_desc *)hdr;
3567 if (desc_type == FUNC_DESC ||
3568 (desc_type == VFT_DESC &&
3569 nic->flags & (1 << VFT_SHIFT)))
3570 return nic;
3571 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003572
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303573 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3574 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003575 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303576 return NULL;
3577}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003578
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303579static struct be_nic_res_desc *be_get_vft_desc(u8 *buf, u32 desc_count)
3580{
3581 return be_get_nic_desc(buf, desc_count, VFT_DESC);
3582}
3583
3584static struct be_nic_res_desc *be_get_func_nic_desc(u8 *buf, u32 desc_count)
3585{
3586 return be_get_nic_desc(buf, desc_count, FUNC_DESC);
3587}
3588
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303589static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3590 u32 desc_count)
3591{
3592 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3593 struct be_pcie_res_desc *pcie;
3594 int i;
3595
3596 for (i = 0; i < desc_count; i++) {
3597 if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
3598 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) {
3599 pcie = (struct be_pcie_res_desc *)hdr;
3600 if (pcie->pf_num == devfn)
3601 return pcie;
3602 }
3603
3604 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3605 hdr = (void *)hdr + hdr->desc_len;
3606 }
Wei Yang950e2952013-05-22 15:58:22 +00003607 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003608}
3609
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303610static struct be_port_res_desc *be_get_port_desc(u8 *buf, u32 desc_count)
3611{
3612 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3613 int i;
3614
3615 for (i = 0; i < desc_count; i++) {
3616 if (hdr->desc_type == PORT_RESOURCE_DESC_TYPE_V1)
3617 return (struct be_port_res_desc *)hdr;
3618
3619 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3620 hdr = (void *)hdr + hdr->desc_len;
3621 }
3622 return NULL;
3623}
3624
Sathya Perla92bf14a2013-08-27 16:57:32 +05303625static void be_copy_nic_desc(struct be_resources *res,
3626 struct be_nic_res_desc *desc)
3627{
3628 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3629 res->max_vlans = le16_to_cpu(desc->vlan_count);
3630 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3631 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3632 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3633 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3634 res->max_evt_qs = le16_to_cpu(desc->eq_count);
Vasundhara Volamf2858732015-03-04 00:44:33 -05003635 res->max_cq_count = le16_to_cpu(desc->cq_count);
3636 res->max_iface_count = le16_to_cpu(desc->iface_count);
3637 res->max_mcc_count = le16_to_cpu(desc->mcc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303638 /* Clear flags that driver is not interested in */
3639 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3640 BE_IF_CAP_FLAGS_WANT;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303641}
3642
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003643/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303644int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003645{
3646 struct be_mcc_wrb *wrb;
3647 struct be_cmd_req_get_func_config *req;
3648 int status;
3649 struct be_dma_mem cmd;
3650
Suresh Reddyd98ef502013-04-25 00:56:55 +00003651 if (mutex_lock_interruptible(&adapter->mbox_lock))
3652 return -1;
3653
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003654 memset(&cmd, 0, sizeof(struct be_dma_mem));
3655 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303656 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3657 GFP_ATOMIC);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003658 if (!cmd.va) {
3659 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003660 status = -ENOMEM;
3661 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003662 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003663
3664 wrb = wrb_from_mbox(adapter);
3665 if (!wrb) {
3666 status = -EBUSY;
3667 goto err;
3668 }
3669
3670 req = cmd.va;
3671
3672 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3673 OPCODE_COMMON_GET_FUNC_CONFIG,
3674 cmd.size, wrb, &cmd);
3675
Kalesh AP28710c52013-04-28 22:21:13 +00003676 if (skyhawk_chip(adapter))
3677 req->hdr.version = 1;
3678
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003679 status = be_mbox_notify_wait(adapter);
3680 if (!status) {
3681 struct be_cmd_resp_get_func_config *resp = cmd.va;
3682 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303683 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003684
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303685 desc = be_get_func_nic_desc(resp->func_param, desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003686 if (!desc) {
3687 status = -EINVAL;
3688 goto err;
3689 }
3690
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003691 adapter->pf_number = desc->pf_num;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303692 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003693 }
3694err:
3695 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003696 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303697 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
3698 cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003699 return status;
3700}
3701
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303702/* Will use MBOX only if MCCQ has not been created */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303703int be_cmd_get_profile_config(struct be_adapter *adapter,
Vasundhara Volamf2858732015-03-04 00:44:33 -05003704 struct be_resources *res, u8 query, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003705{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303706 struct be_cmd_resp_get_profile_config *resp;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303707 struct be_cmd_req_get_profile_config *req;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303708 struct be_nic_res_desc *vf_res;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303709 struct be_pcie_res_desc *pcie;
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303710 struct be_port_res_desc *port;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303711 struct be_nic_res_desc *nic;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303712 struct be_mcc_wrb wrb = {0};
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003713 struct be_dma_mem cmd;
Vasundhara Volamf2858732015-03-04 00:44:33 -05003714 u16 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003715 int status;
3716
3717 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303718 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303719 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3720 GFP_ATOMIC);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303721 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003722 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003723
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303724 req = cmd.va;
3725 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3726 OPCODE_COMMON_GET_PROFILE_CONFIG,
3727 cmd.size, &wrb, &cmd);
3728
3729 req->hdr.domain = domain;
3730 if (!lancer_chip(adapter))
3731 req->hdr.version = 1;
3732 req->type = ACTIVE_PROFILE_TYPE;
3733
Vasundhara Volamf2858732015-03-04 00:44:33 -05003734 /* When QUERY_MODIFIABLE_FIELDS_TYPE bit is set, cmd returns the
3735 * descriptors with all bits set to "1" for the fields which can be
3736 * modified using SET_PROFILE_CONFIG cmd.
3737 */
3738 if (query == RESOURCE_MODIFIABLE)
3739 req->type |= QUERY_MODIFIABLE_FIELDS_TYPE;
3740
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303741 status = be_cmd_notify_wait(adapter, &wrb);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303742 if (status)
3743 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003744
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303745 resp = cmd.va;
Vasundhara Volamf2858732015-03-04 00:44:33 -05003746 desc_count = le16_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003747
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303748 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3749 desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303750 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303751 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303752
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303753 port = be_get_port_desc(resp->func_param, desc_count);
3754 if (port)
3755 adapter->mc_type = port->mc_type;
3756
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303757 nic = be_get_func_nic_desc(resp->func_param, desc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303758 if (nic)
3759 be_copy_nic_desc(res, nic);
3760
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303761 vf_res = be_get_vft_desc(resp->func_param, desc_count);
3762 if (vf_res)
3763 res->vf_if_cap_flags = vf_res->cap_flags;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003764err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003765 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303766 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
3767 cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003768 return status;
3769}
3770
Vasundhara Volambec84e62014-06-30 13:01:32 +05303771/* Will use MBOX only if MCCQ has not been created */
3772static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc,
3773 int size, int count, u8 version, u8 domain)
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003774{
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003775 struct be_cmd_req_set_profile_config *req;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303776 struct be_mcc_wrb wrb = {0};
3777 struct be_dma_mem cmd;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003778 int status;
3779
Vasundhara Volambec84e62014-06-30 13:01:32 +05303780 memset(&cmd, 0, sizeof(struct be_dma_mem));
3781 cmd.size = sizeof(struct be_cmd_req_set_profile_config);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303782 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3783 GFP_ATOMIC);
Vasundhara Volambec84e62014-06-30 13:01:32 +05303784 if (!cmd.va)
3785 return -ENOMEM;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003786
Vasundhara Volambec84e62014-06-30 13:01:32 +05303787 req = cmd.va;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003788 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303789 OPCODE_COMMON_SET_PROFILE_CONFIG, cmd.size,
3790 &wrb, &cmd);
Sathya Perlaa4018012014-03-27 10:46:18 +05303791 req->hdr.version = version;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003792 req->hdr.domain = domain;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303793 req->desc_count = cpu_to_le32(count);
Sathya Perlaa4018012014-03-27 10:46:18 +05303794 memcpy(req->desc, desc, size);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003795
Vasundhara Volambec84e62014-06-30 13:01:32 +05303796 status = be_cmd_notify_wait(adapter, &wrb);
3797
3798 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303799 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
3800 cmd.dma);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003801 return status;
3802}
3803
Sathya Perlaa4018012014-03-27 10:46:18 +05303804/* Mark all fields invalid */
Vasundhara Volambec84e62014-06-30 13:01:32 +05303805static void be_reset_nic_desc(struct be_nic_res_desc *nic)
Sathya Perlaa4018012014-03-27 10:46:18 +05303806{
3807 memset(nic, 0, sizeof(*nic));
3808 nic->unicast_mac_count = 0xFFFF;
3809 nic->mcc_count = 0xFFFF;
3810 nic->vlan_count = 0xFFFF;
3811 nic->mcast_mac_count = 0xFFFF;
3812 nic->txq_count = 0xFFFF;
3813 nic->rq_count = 0xFFFF;
3814 nic->rssq_count = 0xFFFF;
3815 nic->lro_count = 0xFFFF;
3816 nic->cq_count = 0xFFFF;
3817 nic->toe_conn_count = 0xFFFF;
3818 nic->eq_count = 0xFFFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303819 nic->iface_count = 0xFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303820 nic->link_param = 0xFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303821 nic->channel_id_param = cpu_to_le16(0xF000);
Sathya Perlaa4018012014-03-27 10:46:18 +05303822 nic->acpi_params = 0xFF;
3823 nic->wol_param = 0x0F;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303824 nic->tunnel_iface_count = 0xFFFF;
3825 nic->direct_tenant_iface_count = 0xFFFF;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303826 nic->bw_min = 0xFFFFFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303827 nic->bw_max = 0xFFFFFFFF;
3828}
3829
Vasundhara Volambec84e62014-06-30 13:01:32 +05303830/* Mark all fields invalid */
3831static void be_reset_pcie_desc(struct be_pcie_res_desc *pcie)
3832{
3833 memset(pcie, 0, sizeof(*pcie));
3834 pcie->sriov_state = 0xFF;
3835 pcie->pf_state = 0xFF;
3836 pcie->pf_type = 0xFF;
3837 pcie->num_vfs = 0xFFFF;
3838}
3839
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303840int be_cmd_config_qos(struct be_adapter *adapter, u32 max_rate, u16 link_speed,
3841 u8 domain)
Sathya Perlaa4018012014-03-27 10:46:18 +05303842{
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303843 struct be_nic_res_desc nic_desc;
3844 u32 bw_percent;
3845 u16 version = 0;
Sathya Perlaa4018012014-03-27 10:46:18 +05303846
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303847 if (BE3_chip(adapter))
3848 return be_cmd_set_qos(adapter, max_rate / 10, domain);
3849
3850 be_reset_nic_desc(&nic_desc);
3851 nic_desc.pf_num = adapter->pf_number;
3852 nic_desc.vf_num = domain;
Kalesh AP58bdeaa2015-01-20 03:51:49 -05003853 nic_desc.bw_min = 0;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303854 if (lancer_chip(adapter)) {
Sathya Perlaa4018012014-03-27 10:46:18 +05303855 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
3856 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
3857 nic_desc.flags = (1 << QUN_SHIFT) | (1 << IMM_SHIFT) |
3858 (1 << NOSV_SHIFT);
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303859 nic_desc.bw_max = cpu_to_le32(max_rate / 10);
Sathya Perlaa4018012014-03-27 10:46:18 +05303860 } else {
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303861 version = 1;
3862 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3863 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3864 nic_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3865 bw_percent = max_rate ? (max_rate * 100) / link_speed : 100;
3866 nic_desc.bw_max = cpu_to_le32(bw_percent);
Sathya Perlaa4018012014-03-27 10:46:18 +05303867 }
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303868
3869 return be_cmd_set_profile_config(adapter, &nic_desc,
3870 nic_desc.hdr.desc_len,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303871 1, version, domain);
3872}
3873
Vasundhara Volamf2858732015-03-04 00:44:33 -05003874static void be_fill_vf_res_template(struct be_adapter *adapter,
3875 struct be_resources pool_res,
3876 u16 num_vfs, u16 num_vf_qs,
3877 struct be_nic_res_desc *nic_vft)
3878{
3879 u32 vf_if_cap_flags = pool_res.vf_if_cap_flags;
3880 struct be_resources res_mod = {0};
3881
3882 /* Resource with fields set to all '1's by GET_PROFILE_CONFIG cmd,
3883 * which are modifiable using SET_PROFILE_CONFIG cmd.
3884 */
3885 be_cmd_get_profile_config(adapter, &res_mod, RESOURCE_MODIFIABLE, 0);
3886
3887 /* If RSS IFACE capability flags are modifiable for a VF, set the
3888 * capability flag as valid and set RSS and DEFQ_RSS IFACE flags if
3889 * more than 1 RSSQ is available for a VF.
3890 * Otherwise, provision only 1 queue pair for VF.
3891 */
3892 if (res_mod.vf_if_cap_flags & BE_IF_FLAGS_RSS) {
3893 nic_vft->flags |= BIT(IF_CAPS_FLAGS_VALID_SHIFT);
3894 if (num_vf_qs > 1) {
3895 vf_if_cap_flags |= BE_IF_FLAGS_RSS;
3896 if (pool_res.if_cap_flags & BE_IF_FLAGS_DEFQ_RSS)
3897 vf_if_cap_flags |= BE_IF_FLAGS_DEFQ_RSS;
3898 } else {
3899 vf_if_cap_flags &= ~(BE_IF_FLAGS_RSS |
3900 BE_IF_FLAGS_DEFQ_RSS);
3901 }
3902
3903 nic_vft->cap_flags = cpu_to_le32(vf_if_cap_flags);
3904 } else {
3905 num_vf_qs = 1;
3906 }
3907
3908 nic_vft->rq_count = cpu_to_le16(num_vf_qs);
3909 nic_vft->txq_count = cpu_to_le16(num_vf_qs);
3910 nic_vft->rssq_count = cpu_to_le16(num_vf_qs);
3911 nic_vft->cq_count = cpu_to_le16(pool_res.max_cq_count /
3912 (num_vfs + 1));
3913
3914 /* Distribute unicast MACs, VLANs, IFACE count and MCCQ count equally
3915 * among the PF and it's VFs, if the fields are changeable
3916 */
3917 if (res_mod.max_uc_mac == FIELD_MODIFIABLE)
3918 nic_vft->unicast_mac_count = cpu_to_le16(pool_res.max_uc_mac /
3919 (num_vfs + 1));
3920
3921 if (res_mod.max_vlans == FIELD_MODIFIABLE)
3922 nic_vft->vlan_count = cpu_to_le16(pool_res.max_vlans /
3923 (num_vfs + 1));
3924
3925 if (res_mod.max_iface_count == FIELD_MODIFIABLE)
3926 nic_vft->iface_count = cpu_to_le16(pool_res.max_iface_count /
3927 (num_vfs + 1));
3928
3929 if (res_mod.max_mcc_count == FIELD_MODIFIABLE)
3930 nic_vft->mcc_count = cpu_to_le16(pool_res.max_mcc_count /
3931 (num_vfs + 1));
3932}
3933
Vasundhara Volambec84e62014-06-30 13:01:32 +05303934int be_cmd_set_sriov_config(struct be_adapter *adapter,
Vasundhara Volamf2858732015-03-04 00:44:33 -05003935 struct be_resources pool_res, u16 num_vfs,
3936 u16 num_vf_qs)
Vasundhara Volambec84e62014-06-30 13:01:32 +05303937{
3938 struct {
3939 struct be_pcie_res_desc pcie;
3940 struct be_nic_res_desc nic_vft;
3941 } __packed desc;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303942
Vasundhara Volambec84e62014-06-30 13:01:32 +05303943 /* PF PCIE descriptor */
3944 be_reset_pcie_desc(&desc.pcie);
3945 desc.pcie.hdr.desc_type = PCIE_RESOURCE_DESC_TYPE_V1;
3946 desc.pcie.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
Vasundhara Volamf2858732015-03-04 00:44:33 -05003947 desc.pcie.flags = BIT(IMM_SHIFT) | BIT(NOSV_SHIFT);
Vasundhara Volambec84e62014-06-30 13:01:32 +05303948 desc.pcie.pf_num = adapter->pdev->devfn;
3949 desc.pcie.sriov_state = num_vfs ? 1 : 0;
3950 desc.pcie.num_vfs = cpu_to_le16(num_vfs);
3951
3952 /* VF NIC Template descriptor */
3953 be_reset_nic_desc(&desc.nic_vft);
3954 desc.nic_vft.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3955 desc.nic_vft.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
Vasundhara Volamf2858732015-03-04 00:44:33 -05003956 desc.nic_vft.flags = BIT(VFT_SHIFT) | BIT(IMM_SHIFT) | BIT(NOSV_SHIFT);
Vasundhara Volambec84e62014-06-30 13:01:32 +05303957 desc.nic_vft.pf_num = adapter->pdev->devfn;
3958 desc.nic_vft.vf_num = 0;
3959
Vasundhara Volamf2858732015-03-04 00:44:33 -05003960 be_fill_vf_res_template(adapter, pool_res, num_vfs, num_vf_qs,
3961 &desc.nic_vft);
Vasundhara Volambec84e62014-06-30 13:01:32 +05303962
3963 return be_cmd_set_profile_config(adapter, &desc,
3964 2 * RESOURCE_DESC_SIZE_V1, 2, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303965}
3966
3967int be_cmd_manage_iface(struct be_adapter *adapter, u32 iface, u8 op)
3968{
3969 struct be_mcc_wrb *wrb;
3970 struct be_cmd_req_manage_iface_filters *req;
3971 int status;
3972
3973 if (iface == 0xFFFFFFFF)
3974 return -1;
3975
3976 spin_lock_bh(&adapter->mcc_lock);
3977
3978 wrb = wrb_from_mccq(adapter);
3979 if (!wrb) {
3980 status = -EBUSY;
3981 goto err;
3982 }
3983 req = embedded_payload(wrb);
3984
3985 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3986 OPCODE_COMMON_MANAGE_IFACE_FILTERS, sizeof(*req),
3987 wrb, NULL);
3988 req->op = op;
3989 req->target_iface_id = cpu_to_le32(iface);
3990
3991 status = be_mcc_notify_wait(adapter);
3992err:
3993 spin_unlock_bh(&adapter->mcc_lock);
3994 return status;
3995}
3996
3997int be_cmd_set_vxlan_port(struct be_adapter *adapter, __be16 port)
3998{
3999 struct be_port_res_desc port_desc;
4000
4001 memset(&port_desc, 0, sizeof(port_desc));
4002 port_desc.hdr.desc_type = PORT_RESOURCE_DESC_TYPE_V1;
4003 port_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
4004 port_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
4005 port_desc.link_num = adapter->hba_port_num;
4006 if (port) {
4007 port_desc.nv_flags = NV_TYPE_VXLAN | (1 << SOCVID_SHIFT) |
4008 (1 << RCVID_SHIFT);
4009 port_desc.nv_port = swab16(port);
4010 } else {
4011 port_desc.nv_flags = NV_TYPE_DISABLED;
4012 port_desc.nv_port = 0;
4013 }
4014
4015 return be_cmd_set_profile_config(adapter, &port_desc,
Vasundhara Volambec84e62014-06-30 13:01:32 +05304016 RESOURCE_DESC_SIZE_V1, 1, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05304017}
4018
Sathya Perla4c876612013-02-03 20:30:11 +00004019int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
4020 int vf_num)
4021{
4022 struct be_mcc_wrb *wrb;
4023 struct be_cmd_req_get_iface_list *req;
4024 struct be_cmd_resp_get_iface_list *resp;
4025 int status;
4026
4027 spin_lock_bh(&adapter->mcc_lock);
4028
4029 wrb = wrb_from_mccq(adapter);
4030 if (!wrb) {
4031 status = -EBUSY;
4032 goto err;
4033 }
4034 req = embedded_payload(wrb);
4035
4036 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4037 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
4038 wrb, NULL);
4039 req->hdr.domain = vf_num + 1;
4040
4041 status = be_mcc_notify_wait(adapter);
4042 if (!status) {
4043 resp = (struct be_cmd_resp_get_iface_list *)req;
4044 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
4045 }
4046
4047err:
4048 spin_unlock_bh(&adapter->mcc_lock);
4049 return status;
4050}
4051
Somnath Kotur5c510812013-05-30 02:52:23 +00004052static int lancer_wait_idle(struct be_adapter *adapter)
4053{
4054#define SLIPORT_IDLE_TIMEOUT 30
4055 u32 reg_val;
4056 int status = 0, i;
4057
4058 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
4059 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
4060 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
4061 break;
4062
4063 ssleep(1);
4064 }
4065
4066 if (i == SLIPORT_IDLE_TIMEOUT)
4067 status = -1;
4068
4069 return status;
4070}
4071
4072int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
4073{
4074 int status = 0;
4075
4076 status = lancer_wait_idle(adapter);
4077 if (status)
4078 return status;
4079
4080 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
4081
4082 return status;
4083}
4084
4085/* Routine to check whether dump image is present or not */
4086bool dump_present(struct be_adapter *adapter)
4087{
4088 u32 sliport_status = 0;
4089
4090 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
4091 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
4092}
4093
4094int lancer_initiate_dump(struct be_adapter *adapter)
4095{
Kalesh APf0613382014-08-01 17:47:32 +05304096 struct device *dev = &adapter->pdev->dev;
Somnath Kotur5c510812013-05-30 02:52:23 +00004097 int status;
4098
Kalesh APf0613382014-08-01 17:47:32 +05304099 if (dump_present(adapter)) {
4100 dev_info(dev, "Previous dump not cleared, not forcing dump\n");
4101 return -EEXIST;
4102 }
4103
Somnath Kotur5c510812013-05-30 02:52:23 +00004104 /* give firmware reset and diagnostic dump */
4105 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
4106 PHYSDEV_CONTROL_DD_MASK);
4107 if (status < 0) {
Kalesh APf0613382014-08-01 17:47:32 +05304108 dev_err(dev, "FW reset failed\n");
Somnath Kotur5c510812013-05-30 02:52:23 +00004109 return status;
4110 }
4111
4112 status = lancer_wait_idle(adapter);
4113 if (status)
4114 return status;
4115
4116 if (!dump_present(adapter)) {
Kalesh APf0613382014-08-01 17:47:32 +05304117 dev_err(dev, "FW dump not generated\n");
4118 return -EIO;
Somnath Kotur5c510812013-05-30 02:52:23 +00004119 }
4120
4121 return 0;
4122}
4123
Kalesh APf0613382014-08-01 17:47:32 +05304124int lancer_delete_dump(struct be_adapter *adapter)
4125{
4126 int status;
4127
4128 status = lancer_cmd_delete_object(adapter, LANCER_FW_DUMP_FILE);
4129 return be_cmd_status(status);
4130}
4131
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004132/* Uses sync mcc */
4133int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
4134{
4135 struct be_mcc_wrb *wrb;
4136 struct be_cmd_enable_disable_vf *req;
4137 int status;
4138
Vasundhara Volam05998632013-10-01 15:59:59 +05304139 if (BEx_chip(adapter))
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004140 return 0;
4141
4142 spin_lock_bh(&adapter->mcc_lock);
4143
4144 wrb = wrb_from_mccq(adapter);
4145 if (!wrb) {
4146 status = -EBUSY;
4147 goto err;
4148 }
4149
4150 req = embedded_payload(wrb);
4151
4152 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4153 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
4154 wrb, NULL);
4155
4156 req->hdr.domain = domain;
4157 req->enable = 1;
4158 status = be_mcc_notify_wait(adapter);
4159err:
4160 spin_unlock_bh(&adapter->mcc_lock);
4161 return status;
4162}
4163
Somnath Kotur68c45a22013-03-14 02:42:07 +00004164int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
4165{
4166 struct be_mcc_wrb *wrb;
4167 struct be_cmd_req_intr_set *req;
4168 int status;
4169
4170 if (mutex_lock_interruptible(&adapter->mbox_lock))
4171 return -1;
4172
4173 wrb = wrb_from_mbox(adapter);
4174
4175 req = embedded_payload(wrb);
4176
4177 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4178 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
4179 wrb, NULL);
4180
4181 req->intr_enabled = intr_enable;
4182
4183 status = be_mbox_notify_wait(adapter);
4184
4185 mutex_unlock(&adapter->mbox_lock);
4186 return status;
4187}
4188
Vasundhara Volam542963b2014-01-15 13:23:33 +05304189/* Uses MBOX */
4190int be_cmd_get_active_profile(struct be_adapter *adapter, u16 *profile_id)
4191{
4192 struct be_cmd_req_get_active_profile *req;
4193 struct be_mcc_wrb *wrb;
4194 int status;
4195
4196 if (mutex_lock_interruptible(&adapter->mbox_lock))
4197 return -1;
4198
4199 wrb = wrb_from_mbox(adapter);
4200 if (!wrb) {
4201 status = -EBUSY;
4202 goto err;
4203 }
4204
4205 req = embedded_payload(wrb);
4206
4207 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4208 OPCODE_COMMON_GET_ACTIVE_PROFILE, sizeof(*req),
4209 wrb, NULL);
4210
4211 status = be_mbox_notify_wait(adapter);
4212 if (!status) {
4213 struct be_cmd_resp_get_active_profile *resp =
4214 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304215
Vasundhara Volam542963b2014-01-15 13:23:33 +05304216 *profile_id = le16_to_cpu(resp->active_profile_id);
4217 }
4218
4219err:
4220 mutex_unlock(&adapter->mbox_lock);
4221 return status;
4222}
4223
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304224int be_cmd_set_logical_link_config(struct be_adapter *adapter,
4225 int link_state, u8 domain)
4226{
4227 struct be_mcc_wrb *wrb;
4228 struct be_cmd_req_set_ll_link *req;
4229 int status;
4230
4231 if (BEx_chip(adapter) || lancer_chip(adapter))
Kalesh AP18fd6022015-01-20 03:51:45 -05004232 return -EOPNOTSUPP;
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304233
4234 spin_lock_bh(&adapter->mcc_lock);
4235
4236 wrb = wrb_from_mccq(adapter);
4237 if (!wrb) {
4238 status = -EBUSY;
4239 goto err;
4240 }
4241
4242 req = embedded_payload(wrb);
4243
4244 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4245 OPCODE_COMMON_SET_LOGICAL_LINK_CONFIG,
4246 sizeof(*req), wrb, NULL);
4247
4248 req->hdr.version = 1;
4249 req->hdr.domain = domain;
4250
4251 if (link_state == IFLA_VF_LINK_STATE_ENABLE)
4252 req->link_config |= 1;
4253
4254 if (link_state == IFLA_VF_LINK_STATE_AUTO)
4255 req->link_config |= 1 << PLINK_TRACK_SHIFT;
4256
4257 status = be_mcc_notify_wait(adapter);
4258err:
4259 spin_unlock_bh(&adapter->mcc_lock);
4260 return status;
4261}
4262
Parav Pandit6a4ab662012-03-26 14:27:12 +00004263int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05304264 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
Parav Pandit6a4ab662012-03-26 14:27:12 +00004265{
4266 struct be_adapter *adapter = netdev_priv(netdev_handle);
4267 struct be_mcc_wrb *wrb;
Kalesh AP504fbf12014-09-19 15:47:00 +05304268 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *)wrb_payload;
Parav Pandit6a4ab662012-03-26 14:27:12 +00004269 struct be_cmd_req_hdr *req;
4270 struct be_cmd_resp_hdr *resp;
4271 int status;
4272
4273 spin_lock_bh(&adapter->mcc_lock);
4274
4275 wrb = wrb_from_mccq(adapter);
4276 if (!wrb) {
4277 status = -EBUSY;
4278 goto err;
4279 }
4280 req = embedded_payload(wrb);
4281 resp = embedded_payload(wrb);
4282
4283 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
4284 hdr->opcode, wrb_payload_size, wrb, NULL);
4285 memcpy(req, wrb_payload, wrb_payload_size);
4286 be_dws_cpu_to_le(req, wrb_payload_size);
4287
4288 status = be_mcc_notify_wait(adapter);
4289 if (cmd_status)
4290 *cmd_status = (status & 0xffff);
4291 if (ext_status)
4292 *ext_status = 0;
4293 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
4294 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
4295err:
4296 spin_unlock_bh(&adapter->mcc_lock);
4297 return status;
4298}
4299EXPORT_SYMBOL(be_roce_mcc_cmd);