blob: 9ec09a8e7b00b2c5a689f5c97badb36034a035c8 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volam40263822014-02-12 16:09:07 +05302 * Copyright (C) 2005 - 2014 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
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000022static struct be_cmd_priv_map cmd_priv_map[] = {
23 {
24 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
25 CMD_SUBSYSTEM_ETH,
26 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
27 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
28 },
29 {
30 OPCODE_COMMON_GET_FLOW_CONTROL,
31 CMD_SUBSYSTEM_COMMON,
32 BE_PRIV_LNKQUERY | BE_PRIV_VHADM |
33 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
34 },
35 {
36 OPCODE_COMMON_SET_FLOW_CONTROL,
37 CMD_SUBSYSTEM_COMMON,
38 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
39 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
40 },
41 {
42 OPCODE_ETH_GET_PPORT_STATS,
43 CMD_SUBSYSTEM_ETH,
44 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
45 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
46 },
47 {
48 OPCODE_COMMON_GET_PHY_DETAILS,
49 CMD_SUBSYSTEM_COMMON,
50 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
51 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
52 }
53};
54
Sathya Perlaa2cc4e02014-05-09 13:29:14 +053055static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem)
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000056{
57 int i;
58 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
59 u32 cmd_privileges = adapter->cmd_privileges;
60
61 for (i = 0; i < num_entries; i++)
62 if (opcode == cmd_priv_map[i].opcode &&
63 subsystem == cmd_priv_map[i].subsystem)
64 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
65 return false;
66
67 return true;
68}
69
Somnath Kotur3de09452011-09-30 07:25:05 +000070static inline void *embedded_payload(struct be_mcc_wrb *wrb)
71{
72 return wrb->payload.embedded_payload;
73}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000074
Sathya Perla8788fdc2009-07-27 22:52:03 +000075static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000076{
Sathya Perla8788fdc2009-07-27 22:52:03 +000077 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000078 u32 val = 0;
79
Sathya Perla6589ade2011-11-10 19:18:00 +000080 if (be_error(adapter))
Ajit Khaparde7acc2082011-02-11 13:38:17 +000081 return;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000082
Sathya Perla5fb379e2009-06-18 00:02:59 +000083 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
84 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000085
86 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000087 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000088}
89
90/* To check if valid bit is set, check the entire word as we don't know
91 * the endianness of the data (old entry is host endian while a new entry is
92 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000093static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000094{
Sathya Perla9e9ff4b2013-02-12 23:05:19 +000095 u32 flags;
96
Sathya Perla5fb379e2009-06-18 00:02:59 +000097 if (compl->flags != 0) {
Sathya Perla9e9ff4b2013-02-12 23:05:19 +000098 flags = le32_to_cpu(compl->flags);
99 if (flags & CQE_FLAGS_VALID_MASK) {
100 compl->flags = flags;
101 return true;
102 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000103 }
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000104 return false;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000105}
106
107/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000108static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000109{
110 compl->flags = 0;
111}
112
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000113static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
114{
115 unsigned long addr;
116
117 addr = tag1;
118 addr = ((addr << 16) << 16) | tag0;
119 return (void *)addr;
120}
121
Kalesh AP4c600052014-05-30 19:06:26 +0530122static bool be_skip_err_log(u8 opcode, u16 base_status, u16 addl_status)
123{
124 if (base_status == MCC_STATUS_NOT_SUPPORTED ||
125 base_status == MCC_STATUS_ILLEGAL_REQUEST ||
126 addl_status == MCC_ADDL_STATUS_TOO_MANY_INTERFACES ||
127 (opcode == OPCODE_COMMON_WRITE_FLASHROM &&
128 (base_status == MCC_STATUS_ILLEGAL_FIELD ||
129 addl_status == MCC_ADDL_STATUS_FLASH_IMAGE_CRC_MISMATCH)))
130 return true;
131 else
132 return false;
133}
134
Sathya Perla559b6332014-05-30 19:06:27 +0530135/* Place holder for all the async MCC cmds wherein the caller is not in a busy
136 * loop (has not issued be_mcc_notify_wait())
137 */
138static void be_async_cmd_process(struct be_adapter *adapter,
139 struct be_mcc_compl *compl,
140 struct be_cmd_resp_hdr *resp_hdr)
141{
142 enum mcc_base_status base_status = base_status(compl->status);
143 u8 opcode = 0, subsystem = 0;
144
145 if (resp_hdr) {
146 opcode = resp_hdr->opcode;
147 subsystem = resp_hdr->subsystem;
148 }
149
150 if (opcode == OPCODE_LOWLEVEL_LOOPBACK_TEST &&
151 subsystem == CMD_SUBSYSTEM_LOWLEVEL) {
152 complete(&adapter->et_cmd_compl);
153 return;
154 }
155
156 if ((opcode == OPCODE_COMMON_WRITE_FLASHROM ||
157 opcode == OPCODE_COMMON_WRITE_OBJECT) &&
158 subsystem == CMD_SUBSYSTEM_COMMON) {
159 adapter->flash_status = compl->status;
160 complete(&adapter->et_cmd_compl);
161 return;
162 }
163
164 if ((opcode == OPCODE_ETH_GET_STATISTICS ||
165 opcode == OPCODE_ETH_GET_PPORT_STATS) &&
166 subsystem == CMD_SUBSYSTEM_ETH &&
167 base_status == MCC_STATUS_SUCCESS) {
168 be_parse_stats(adapter);
169 adapter->stats_cmd_sent = false;
170 return;
171 }
172
173 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
174 subsystem == CMD_SUBSYSTEM_COMMON) {
175 if (base_status == MCC_STATUS_SUCCESS) {
176 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
177 (void *)resp_hdr;
178 adapter->drv_stats.be_on_die_temperature =
179 resp->on_die_temperature;
180 } else {
181 adapter->be_get_temp_freq = 0;
182 }
183 return;
184 }
185}
186
Sathya Perla8788fdc2009-07-27 22:52:03 +0000187static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000188 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000189{
Kalesh AP4c600052014-05-30 19:06:26 +0530190 enum mcc_base_status base_status;
191 enum mcc_addl_status addl_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000192 struct be_cmd_resp_hdr *resp_hdr;
193 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000194
195 /* Just swap the status to host endian; mcc tag is opaquely copied
196 * from mcc_wrb */
197 be_dws_le_to_cpu(compl, 4);
198
Kalesh AP4c600052014-05-30 19:06:26 +0530199 base_status = base_status(compl->status);
200 addl_status = addl_status(compl->status);
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +0530201
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000202 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000203 if (resp_hdr) {
204 opcode = resp_hdr->opcode;
205 subsystem = resp_hdr->subsystem;
206 }
207
Sathya Perla559b6332014-05-30 19:06:27 +0530208 be_async_cmd_process(adapter, compl, resp_hdr);
Suresh Reddy5eeff632014-01-06 13:02:24 +0530209
Sathya Perla559b6332014-05-30 19:06:27 +0530210 if (base_status != MCC_STATUS_SUCCESS &&
211 !be_skip_err_log(opcode, base_status, addl_status)) {
Kalesh AP4c600052014-05-30 19:06:26 +0530212 if (base_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000213 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000214 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000215 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000216 } else {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000217 dev_err(&adapter->pdev->dev,
218 "opcode %d-%d failed:status %d-%d\n",
Kalesh AP4c600052014-05-30 19:06:26 +0530219 opcode, subsystem, base_status, addl_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000220 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000221 }
Kalesh AP4c600052014-05-30 19:06:26 +0530222 return compl->status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000223}
224
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000225/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000226static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530227 struct be_mcc_compl *compl)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000228{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530229 struct be_async_event_link_state *evt =
230 (struct be_async_event_link_state *)compl;
231
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000232 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000233 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000234
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530235 /* On BEx the FW does not send a separate link status
236 * notification for physical and logical link.
237 * On other chips just process the logical link
238 * status notification
239 */
240 if (!BEx_chip(adapter) &&
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000241 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
242 return;
243
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000244 /* For the initial link status do not rely on the ASYNC event as
245 * it may not be received in some cases.
246 */
247 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530248 be_link_status_update(adapter,
249 evt->port_link_status & LINK_STATUS_MASK);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000250}
251
Somnath Koturcc4ce022010-10-21 07:11:14 -0700252/* Grp5 CoS Priority evt */
253static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530254 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700255{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530256 struct be_async_event_grp5_cos_priority *evt =
257 (struct be_async_event_grp5_cos_priority *)compl;
258
Somnath Koturcc4ce022010-10-21 07:11:14 -0700259 if (evt->valid) {
260 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000261 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700262 adapter->recommended_prio =
263 evt->reco_default_priority << VLAN_PRIO_SHIFT;
264 }
265}
266
Sathya Perla323ff712012-09-28 04:39:43 +0000267/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700268static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530269 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700270{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530271 struct be_async_event_grp5_qos_link_speed *evt =
272 (struct be_async_event_grp5_qos_link_speed *)compl;
273
Sathya Perla323ff712012-09-28 04:39:43 +0000274 if (adapter->phy.link_speed >= 0 &&
275 evt->physical_port == adapter->port_num)
276 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700277}
278
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000279/*Grp5 PVID evt*/
280static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530281 struct be_mcc_compl *compl)
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000282{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530283 struct be_async_event_grp5_pvid_state *evt =
284 (struct be_async_event_grp5_pvid_state *)compl;
285
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530286 if (evt->enabled) {
Somnath Kotur939cf302011-08-18 21:51:49 -0700287 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530288 dev_info(&adapter->pdev->dev, "LPVID: %d\n", adapter->pvid);
289 } else {
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000290 adapter->pvid = 0;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530291 }
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000292}
293
Somnath Koturcc4ce022010-10-21 07:11:14 -0700294static void be_async_grp5_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530295 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700296{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530297 u8 event_type = (compl->flags >> ASYNC_EVENT_TYPE_SHIFT) &
298 ASYNC_EVENT_TYPE_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700299
300 switch (event_type) {
301 case ASYNC_EVENT_COS_PRIORITY:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530302 be_async_grp5_cos_priority_process(adapter, compl);
303 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700304 case ASYNC_EVENT_QOS_SPEED:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530305 be_async_grp5_qos_speed_process(adapter, compl);
306 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000307 case ASYNC_EVENT_PVID_STATE:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530308 be_async_grp5_pvid_state_process(adapter, compl);
309 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700310 default:
Somnath Koturcc4ce022010-10-21 07:11:14 -0700311 break;
312 }
313}
314
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000315static void be_async_dbg_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530316 struct be_mcc_compl *cmp)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000317{
318 u8 event_type = 0;
319 struct be_async_event_qnq *evt = (struct be_async_event_qnq *) cmp;
320
Sathya Perla3acf19d2014-05-30 19:06:28 +0530321 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
322 ASYNC_EVENT_TYPE_MASK;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000323
324 switch (event_type) {
325 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
326 if (evt->valid)
327 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
328 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
329 break;
330 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530331 dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n",
332 event_type);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000333 break;
334 }
335}
336
Sathya Perla3acf19d2014-05-30 19:06:28 +0530337static inline bool is_link_state_evt(u32 flags)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000338{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530339 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
340 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000341}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000342
Sathya Perla3acf19d2014-05-30 19:06:28 +0530343static inline bool is_grp5_evt(u32 flags)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700344{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530345 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
346 ASYNC_EVENT_CODE_GRP_5;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700347}
348
Sathya Perla3acf19d2014-05-30 19:06:28 +0530349static inline bool is_dbg_evt(u32 flags)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000350{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530351 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
352 ASYNC_EVENT_CODE_QNQ;
353}
354
355static void be_mcc_event_process(struct be_adapter *adapter,
356 struct be_mcc_compl *compl)
357{
358 if (is_link_state_evt(compl->flags))
359 be_async_link_state_process(adapter, compl);
360 else if (is_grp5_evt(compl->flags))
361 be_async_grp5_evt_process(adapter, compl);
362 else if (is_dbg_evt(compl->flags))
363 be_async_dbg_evt_process(adapter, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000364}
365
Sathya Perlaefd2e402009-07-27 22:53:10 +0000366static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000367{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000368 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000369 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000370
371 if (be_mcc_compl_is_new(compl)) {
372 queue_tail_inc(mcc_cq);
373 return compl;
374 }
375 return NULL;
376}
377
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000378void be_async_mcc_enable(struct be_adapter *adapter)
379{
380 spin_lock_bh(&adapter->mcc_cq_lock);
381
382 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
383 adapter->mcc_obj.rearm_cq = true;
384
385 spin_unlock_bh(&adapter->mcc_cq_lock);
386}
387
388void be_async_mcc_disable(struct be_adapter *adapter)
389{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000390 spin_lock_bh(&adapter->mcc_cq_lock);
391
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000392 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000393 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
394
395 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000396}
397
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000398int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000399{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000400 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000401 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000402 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000403
Amerigo Wang072a9c42012-08-24 21:41:11 +0000404 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla3acf19d2014-05-30 19:06:28 +0530405
Sathya Perla8788fdc2009-07-27 22:52:03 +0000406 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000407 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530408 be_mcc_event_process(adapter, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700409 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530410 status = be_mcc_compl_process(adapter, compl);
411 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000412 }
413 be_mcc_compl_use(compl);
414 num++;
415 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700416
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000417 if (num)
418 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
419
Amerigo Wang072a9c42012-08-24 21:41:11 +0000420 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000421 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000422}
423
Sathya Perla6ac7b682009-06-18 00:05:54 +0000424/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700425static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000426{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700427#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000428 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800429 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700430
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800431 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000432 if (be_error(adapter))
433 return -EIO;
434
Amerigo Wang072a9c42012-08-24 21:41:11 +0000435 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000436 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000437 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800438
439 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000440 break;
441 udelay(100);
442 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700443 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000444 dev_err(&adapter->pdev->dev, "FW not responding\n");
445 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000446 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700447 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800448 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000449}
450
451/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700452static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000453{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000454 int status;
455 struct be_mcc_wrb *wrb;
456 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
457 u16 index = mcc_obj->q.head;
458 struct be_cmd_resp_hdr *resp;
459
460 index_dec(&index, mcc_obj->q.len);
461 wrb = queue_index_node(&mcc_obj->q, index);
462
463 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
464
Sathya Perla8788fdc2009-07-27 22:52:03 +0000465 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000466
467 status = be_mcc_wait_compl(adapter);
468 if (status == -EIO)
469 goto out;
470
Kalesh AP4c600052014-05-30 19:06:26 +0530471 status = (resp->base_status |
472 ((resp->addl_status & CQE_ADDL_STATUS_MASK) <<
473 CQE_ADDL_STATUS_SHIFT));
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000474out:
475 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000476}
477
Sathya Perla5f0b8492009-07-27 22:52:56 +0000478static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700479{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000480 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700481 u32 ready;
482
483 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000484 if (be_error(adapter))
485 return -EIO;
486
Sathya Perlacf588472010-02-14 21:22:01 +0000487 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000488 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000489 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000490
491 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700492 if (ready)
493 break;
494
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000495 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000496 dev_err(&adapter->pdev->dev, "FW not responding\n");
497 adapter->fw_timeout = true;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000498 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700499 return -1;
500 }
501
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000502 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000503 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700504 } while (true);
505
506 return 0;
507}
508
509/*
510 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000511 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700512 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700513static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700514{
515 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700516 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000517 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
518 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700519 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000520 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700521
Sathya Perlacf588472010-02-14 21:22:01 +0000522 /* wait for ready to be set */
523 status = be_mbox_db_ready_wait(adapter, db);
524 if (status != 0)
525 return status;
526
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700527 val |= MPU_MAILBOX_DB_HI_MASK;
528 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
529 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
530 iowrite32(val, db);
531
532 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000533 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700534 if (status != 0)
535 return status;
536
537 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700538 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
539 val |= (u32)(mbox_mem->dma >> 4) << 2;
540 iowrite32(val, db);
541
Sathya Perla5f0b8492009-07-27 22:52:56 +0000542 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700543 if (status != 0)
544 return status;
545
Sathya Perla5fb379e2009-06-18 00:02:59 +0000546 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000547 if (be_mcc_compl_is_new(compl)) {
548 status = be_mcc_compl_process(adapter, &mbox->compl);
549 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000550 if (status)
551 return status;
552 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000553 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700554 return -1;
555 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000556 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700557}
558
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000559static u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700560{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000561 u32 sem;
562
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000563 if (BEx_chip(adapter))
564 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700565 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000566 pci_read_config_dword(adapter->pdev,
567 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
568
569 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700570}
571
Gavin Shan87f20c22013-10-29 17:30:57 +0800572static int lancer_wait_ready(struct be_adapter *adapter)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000573{
574#define SLIPORT_READY_TIMEOUT 30
575 u32 sliport_status;
576 int status = 0, i;
577
578 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
579 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
580 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
581 break;
582
583 msleep(1000);
584 }
585
586 if (i == SLIPORT_READY_TIMEOUT)
587 status = -1;
588
589 return status;
590}
591
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000592static bool lancer_provisioning_error(struct be_adapter *adapter)
593{
594 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
Kalesh AP03d28ff2014-09-19 15:46:56 +0530595
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000596 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
597 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530598 sliport_err1 = ioread32(adapter->db + SLIPORT_ERROR1_OFFSET);
599 sliport_err2 = ioread32(adapter->db + SLIPORT_ERROR2_OFFSET);
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000600
601 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
602 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
603 return true;
604 }
605 return false;
606}
607
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000608int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
609{
610 int status;
611 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000612 bool resource_error;
613
614 resource_error = lancer_provisioning_error(adapter);
615 if (resource_error)
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000616 return -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000617
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000618 status = lancer_wait_ready(adapter);
619 if (!status) {
620 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
621 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
622 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
623 if (err && reset_needed) {
624 iowrite32(SLI_PORT_CONTROL_IP_MASK,
625 adapter->db + SLIPORT_CONTROL_OFFSET);
626
627 /* check adapter has corrected the error */
628 status = lancer_wait_ready(adapter);
629 sliport_status = ioread32(adapter->db +
630 SLIPORT_STATUS_OFFSET);
631 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
632 SLIPORT_STATUS_RN_MASK);
633 if (status || sliport_status)
634 status = -1;
635 } else if (err || reset_needed) {
636 status = -1;
637 }
638 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000639 /* Stop error recovery if error is not recoverable.
640 * No resource error is temporary errors and will go away
641 * when PF provisions resources.
642 */
643 resource_error = lancer_provisioning_error(adapter);
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000644 if (resource_error)
645 status = -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000646
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000647 return status;
648}
649
650int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700651{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000652 u16 stage;
653 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000654 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700655
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000656 if (lancer_chip(adapter)) {
657 status = lancer_wait_ready(adapter);
658 return status;
659 }
660
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000661 do {
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000662 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000663 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000664 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000665
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530666 dev_info(dev, "Waiting for POST, %ds elapsed\n", timeout);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000667 if (msleep_interruptible(2000)) {
668 dev_err(dev, "Waiting for POST aborted\n");
669 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000670 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000671 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000672 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700673
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000674 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000675 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700676}
677
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700678static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
679{
680 return &wrb->payload.sgl[0];
681}
682
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530683static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, unsigned long addr)
Sathya Perlabea50982013-08-27 16:57:33 +0530684{
685 wrb->tag0 = addr & 0xFFFFFFFF;
686 wrb->tag1 = upper_32_bits(addr);
687}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700688
689/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000690/* mem will be NULL for embedded commands */
691static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530692 u8 subsystem, u8 opcode, int cmd_len,
693 struct be_mcc_wrb *wrb,
694 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700695{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000696 struct be_sge *sge;
697
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700698 req_hdr->opcode = opcode;
699 req_hdr->subsystem = subsystem;
700 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000701 req_hdr->version = 0;
Sathya Perlabea50982013-08-27 16:57:33 +0530702 fill_wrb_tags(wrb, (ulong) req_hdr);
Somnath Kotur106df1e2011-10-27 07:12:13 +0000703 wrb->payload_length = cmd_len;
704 if (mem) {
705 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
706 MCC_WRB_SGE_CNT_SHIFT;
707 sge = nonembedded_sgl(wrb);
708 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
709 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
710 sge->len = cpu_to_le32(mem->size);
711 } else
712 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
713 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700714}
715
716static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530717 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700718{
719 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
720 u64 dma = (u64)mem->dma;
721
722 for (i = 0; i < buf_pages; i++) {
723 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
724 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
725 dma += PAGE_SIZE_4K;
726 }
727}
728
Sathya Perlab31c50a2009-09-17 10:30:13 -0700729static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700730{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700731 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
732 struct be_mcc_wrb *wrb
733 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
734 memset(wrb, 0, sizeof(*wrb));
735 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700736}
737
Sathya Perlab31c50a2009-09-17 10:30:13 -0700738static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000739{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700740 struct be_queue_info *mccq = &adapter->mcc_obj.q;
741 struct be_mcc_wrb *wrb;
742
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000743 if (!mccq->created)
744 return NULL;
745
Vasundhara Volam4d277122013-04-21 23:28:15 +0000746 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000747 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000748
Sathya Perlab31c50a2009-09-17 10:30:13 -0700749 wrb = queue_head_node(mccq);
750 queue_head_inc(mccq);
751 atomic_inc(&mccq->used);
752 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000753 return wrb;
754}
755
Sathya Perlabea50982013-08-27 16:57:33 +0530756static bool use_mcc(struct be_adapter *adapter)
757{
758 return adapter->mcc_obj.q.created;
759}
760
761/* Must be used only in process context */
762static int be_cmd_lock(struct be_adapter *adapter)
763{
764 if (use_mcc(adapter)) {
765 spin_lock_bh(&adapter->mcc_lock);
766 return 0;
767 } else {
768 return mutex_lock_interruptible(&adapter->mbox_lock);
769 }
770}
771
772/* Must be used only in process context */
773static void be_cmd_unlock(struct be_adapter *adapter)
774{
775 if (use_mcc(adapter))
776 spin_unlock_bh(&adapter->mcc_lock);
777 else
778 return mutex_unlock(&adapter->mbox_lock);
779}
780
781static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter,
782 struct be_mcc_wrb *wrb)
783{
784 struct be_mcc_wrb *dest_wrb;
785
786 if (use_mcc(adapter)) {
787 dest_wrb = wrb_from_mccq(adapter);
788 if (!dest_wrb)
789 return NULL;
790 } else {
791 dest_wrb = wrb_from_mbox(adapter);
792 }
793
794 memcpy(dest_wrb, wrb, sizeof(*wrb));
795 if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK))
796 fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb));
797
798 return dest_wrb;
799}
800
801/* Must be used only in process context */
802static int be_cmd_notify_wait(struct be_adapter *adapter,
803 struct be_mcc_wrb *wrb)
804{
805 struct be_mcc_wrb *dest_wrb;
806 int status;
807
808 status = be_cmd_lock(adapter);
809 if (status)
810 return status;
811
812 dest_wrb = be_cmd_copy(adapter, wrb);
813 if (!dest_wrb)
814 return -EBUSY;
815
816 if (use_mcc(adapter))
817 status = be_mcc_notify_wait(adapter);
818 else
819 status = be_mbox_notify_wait(adapter);
820
821 if (!status)
822 memcpy(wrb, dest_wrb, sizeof(*wrb));
823
824 be_cmd_unlock(adapter);
825 return status;
826}
827
Sathya Perla2243e2e2009-11-22 22:02:03 +0000828/* Tell fw we're about to start firing cmds by writing a
829 * special pattern across the wrb hdr; uses mbox
830 */
831int be_cmd_fw_init(struct be_adapter *adapter)
832{
833 u8 *wrb;
834 int status;
835
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000836 if (lancer_chip(adapter))
837 return 0;
838
Ivan Vecera29849612010-12-14 05:43:19 +0000839 if (mutex_lock_interruptible(&adapter->mbox_lock))
840 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000841
842 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000843 *wrb++ = 0xFF;
844 *wrb++ = 0x12;
845 *wrb++ = 0x34;
846 *wrb++ = 0xFF;
847 *wrb++ = 0xFF;
848 *wrb++ = 0x56;
849 *wrb++ = 0x78;
850 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000851
852 status = be_mbox_notify_wait(adapter);
853
Ivan Vecera29849612010-12-14 05:43:19 +0000854 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000855 return status;
856}
857
858/* Tell fw we're done with firing cmds by writing a
859 * special pattern across the wrb hdr; uses mbox
860 */
861int be_cmd_fw_clean(struct be_adapter *adapter)
862{
863 u8 *wrb;
864 int status;
865
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000866 if (lancer_chip(adapter))
867 return 0;
868
Ivan Vecera29849612010-12-14 05:43:19 +0000869 if (mutex_lock_interruptible(&adapter->mbox_lock))
870 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000871
872 wrb = (u8 *)wrb_from_mbox(adapter);
873 *wrb++ = 0xFF;
874 *wrb++ = 0xAA;
875 *wrb++ = 0xBB;
876 *wrb++ = 0xFF;
877 *wrb++ = 0xFF;
878 *wrb++ = 0xCC;
879 *wrb++ = 0xDD;
880 *wrb = 0xFF;
881
882 status = be_mbox_notify_wait(adapter);
883
Ivan Vecera29849612010-12-14 05:43:19 +0000884 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000885 return status;
886}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000887
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530888int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700889{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700890 struct be_mcc_wrb *wrb;
891 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530892 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
893 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700894
Ivan Vecera29849612010-12-14 05:43:19 +0000895 if (mutex_lock_interruptible(&adapter->mbox_lock))
896 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700897
898 wrb = wrb_from_mbox(adapter);
899 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700900
Somnath Kotur106df1e2011-10-27 07:12:13 +0000901 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530902 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb,
903 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700904
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530905 /* Support for EQ_CREATEv2 available only SH-R onwards */
906 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
907 ver = 2;
908
909 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700910 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
911
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700912 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
913 /* 4byte eqe*/
914 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
915 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530916 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700917 be_dws_cpu_to_le(req->context, sizeof(req->context));
918
919 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
920
Sathya Perlab31c50a2009-09-17 10:30:13 -0700921 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700922 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700923 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +0530924
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530925 eqo->q.id = le16_to_cpu(resp->eq_id);
926 eqo->msix_idx =
927 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
928 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700929 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700930
Ivan Vecera29849612010-12-14 05:43:19 +0000931 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700932 return status;
933}
934
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000935/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000936int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000937 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700938{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700939 struct be_mcc_wrb *wrb;
940 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700941 int status;
942
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000943 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700944
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000945 wrb = wrb_from_mccq(adapter);
946 if (!wrb) {
947 status = -EBUSY;
948 goto err;
949 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700950 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700951
Somnath Kotur106df1e2011-10-27 07:12:13 +0000952 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530953 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb,
954 NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000955 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700956 if (permanent) {
957 req->permanent = 1;
958 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700959 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000960 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700961 req->permanent = 0;
962 }
963
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000964 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700965 if (!status) {
966 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +0530967
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700968 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700969 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700970
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000971err:
972 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700973 return status;
974}
975
Sathya Perlab31c50a2009-09-17 10:30:13 -0700976/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000977int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530978 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700979{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700980 struct be_mcc_wrb *wrb;
981 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700982 int status;
983
Sathya Perlab31c50a2009-09-17 10:30:13 -0700984 spin_lock_bh(&adapter->mcc_lock);
985
986 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000987 if (!wrb) {
988 status = -EBUSY;
989 goto err;
990 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700991 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700992
Somnath Kotur106df1e2011-10-27 07:12:13 +0000993 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530994 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb,
995 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700996
Ajit Khapardef8617e02011-02-11 13:36:37 +0000997 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700998 req->if_id = cpu_to_le32(if_id);
999 memcpy(req->mac_address, mac_addr, ETH_ALEN);
1000
Sathya Perlab31c50a2009-09-17 10:30:13 -07001001 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001002 if (!status) {
1003 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301004
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001005 *pmac_id = le32_to_cpu(resp->pmac_id);
1006 }
1007
Sathya Perla713d03942009-11-22 22:02:45 +00001008err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001009 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +00001010
1011 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
1012 status = -EPERM;
1013
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001014 return status;
1015}
1016
Sathya Perlab31c50a2009-09-17 10:30:13 -07001017/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001018int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001019{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001020 struct be_mcc_wrb *wrb;
1021 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001022 int status;
1023
Sathya Perla30128032011-11-10 19:17:57 +00001024 if (pmac_id == -1)
1025 return 0;
1026
Sathya Perlab31c50a2009-09-17 10:30:13 -07001027 spin_lock_bh(&adapter->mcc_lock);
1028
1029 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001030 if (!wrb) {
1031 status = -EBUSY;
1032 goto err;
1033 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001034 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001035
Somnath Kotur106df1e2011-10-27 07:12:13 +00001036 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1037 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001038
Ajit Khapardef8617e02011-02-11 13:36:37 +00001039 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001040 req->if_id = cpu_to_le32(if_id);
1041 req->pmac_id = cpu_to_le32(pmac_id);
1042
Sathya Perlab31c50a2009-09-17 10:30:13 -07001043 status = be_mcc_notify_wait(adapter);
1044
Sathya Perla713d03942009-11-22 22:02:45 +00001045err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001046 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001047 return status;
1048}
1049
Sathya Perlab31c50a2009-09-17 10:30:13 -07001050/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001051int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301052 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001053{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001054 struct be_mcc_wrb *wrb;
1055 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001056 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001057 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001058 int status;
1059
Ivan Vecera29849612010-12-14 05:43:19 +00001060 if (mutex_lock_interruptible(&adapter->mbox_lock))
1061 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001062
1063 wrb = wrb_from_mbox(adapter);
1064 req = embedded_payload(wrb);
1065 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001066
Somnath Kotur106df1e2011-10-27 07:12:13 +00001067 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301068 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb,
1069 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001070
1071 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001072
1073 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001074 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301075 coalesce_wm);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001076 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301077 ctxt, no_delay);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001078 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301079 __ilog2_u32(cq->len / 256));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001080 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001081 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
1082 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001083 } else {
1084 req->hdr.version = 2;
1085 req->page_size = 1; /* 1 for 4K */
Ajit Khaparde09e83a92013-11-22 12:51:20 -06001086
1087 /* coalesce-wm field in this cmd is not relevant to Lancer.
1088 * Lancer uses COMMON_MODIFY_CQ to set this field
1089 */
1090 if (!lancer_chip(adapter))
1091 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1092 ctxt, coalesce_wm);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001093 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301094 no_delay);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001095 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301096 __ilog2_u32(cq->len / 256));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001097 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301098 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1099 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001100 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001101
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1103
1104 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1105
Sathya Perlab31c50a2009-09-17 10:30:13 -07001106 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001107 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001108 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301109
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001110 cq->id = le16_to_cpu(resp->cq_id);
1111 cq->created = true;
1112 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001113
Ivan Vecera29849612010-12-14 05:43:19 +00001114 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001115
1116 return status;
1117}
1118
1119static u32 be_encoded_q_len(int q_len)
1120{
1121 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
Kalesh AP03d28ff2014-09-19 15:46:56 +05301122
Sathya Perla5fb379e2009-06-18 00:02:59 +00001123 if (len_encoded == 16)
1124 len_encoded = 0;
1125 return len_encoded;
1126}
1127
Jingoo Han4188e7d2013-08-05 18:02:02 +09001128static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301129 struct be_queue_info *mccq,
1130 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001131{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001132 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001133 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001134 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001135 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001136 int status;
1137
Ivan Vecera29849612010-12-14 05:43:19 +00001138 if (mutex_lock_interruptible(&adapter->mbox_lock))
1139 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001140
1141 wrb = wrb_from_mbox(adapter);
1142 req = embedded_payload(wrb);
1143 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001144
Somnath Kotur106df1e2011-10-27 07:12:13 +00001145 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301146 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb,
1147 NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001148
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001149 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301150 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001151 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1152 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301153 be_encoded_q_len(mccq->len));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001154 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301155 } else {
1156 req->hdr.version = 1;
1157 req->cq_id = cpu_to_le16(cq->id);
1158
1159 AMAP_SET_BITS(struct amap_mcc_context_v1, ring_size, ctxt,
1160 be_encoded_q_len(mccq->len));
1161 AMAP_SET_BITS(struct amap_mcc_context_v1, valid, ctxt, 1);
1162 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_id,
1163 ctxt, cq->id);
1164 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_valid,
1165 ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001166 }
1167
Somnath Koturcc4ce022010-10-21 07:11:14 -07001168 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001169 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001170 req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001171 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1172
1173 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1174
Sathya Perlab31c50a2009-09-17 10:30:13 -07001175 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001176 if (!status) {
1177 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301178
Sathya Perla5fb379e2009-06-18 00:02:59 +00001179 mccq->id = le16_to_cpu(resp->id);
1180 mccq->created = true;
1181 }
Ivan Vecera29849612010-12-14 05:43:19 +00001182 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001183
1184 return status;
1185}
1186
Jingoo Han4188e7d2013-08-05 18:02:02 +09001187static int be_cmd_mccq_org_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301188 struct be_queue_info *mccq,
1189 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001190{
1191 struct be_mcc_wrb *wrb;
1192 struct be_cmd_req_mcc_create *req;
1193 struct be_dma_mem *q_mem = &mccq->dma_mem;
1194 void *ctxt;
1195 int status;
1196
1197 if (mutex_lock_interruptible(&adapter->mbox_lock))
1198 return -1;
1199
1200 wrb = wrb_from_mbox(adapter);
1201 req = embedded_payload(wrb);
1202 ctxt = &req->context;
1203
Somnath Kotur106df1e2011-10-27 07:12:13 +00001204 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301205 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb,
1206 NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001207
1208 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1209
1210 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1211 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301212 be_encoded_q_len(mccq->len));
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001213 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1214
1215 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1216
1217 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1218
1219 status = be_mbox_notify_wait(adapter);
1220 if (!status) {
1221 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301222
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001223 mccq->id = le16_to_cpu(resp->id);
1224 mccq->created = true;
1225 }
1226
1227 mutex_unlock(&adapter->mbox_lock);
1228 return status;
1229}
1230
1231int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301232 struct be_queue_info *mccq, struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001233{
1234 int status;
1235
1236 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301237 if (status && BEx_chip(adapter)) {
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001238 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1239 "or newer to avoid conflicting priorities between NIC "
1240 "and FCoE traffic");
1241 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1242 }
1243 return status;
1244}
1245
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001246int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001247{
Sathya Perla77071332013-08-27 16:57:34 +05301248 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001249 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001250 struct be_queue_info *txq = &txo->q;
1251 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001252 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001253 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001254
Sathya Perla77071332013-08-27 16:57:34 +05301255 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001256 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301257 OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001258
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001259 if (lancer_chip(adapter)) {
1260 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001261 } else if (BEx_chip(adapter)) {
1262 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1263 req->hdr.version = 2;
1264 } else { /* For SH */
1265 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001266 }
1267
Vasundhara Volam81b02652013-10-01 15:59:57 +05301268 if (req->hdr.version > 0)
1269 req->if_id = cpu_to_le16(adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001270 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1271 req->ulp_num = BE_ULP1_NUM;
1272 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001273 req->cq_id = cpu_to_le16(cq->id);
1274 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001275 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001276 ver = req->hdr.version;
1277
Sathya Perla77071332013-08-27 16:57:34 +05301278 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001279 if (!status) {
Sathya Perla77071332013-08-27 16:57:34 +05301280 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301281
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001282 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001283 if (ver == 2)
1284 txo->db_offset = le32_to_cpu(resp->db_offset);
1285 else
1286 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001287 txq->created = true;
1288 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001289
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001290 return status;
1291}
1292
Sathya Perla482c9e72011-06-29 23:33:17 +00001293/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001294int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301295 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
1296 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001297{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001298 struct be_mcc_wrb *wrb;
1299 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300 struct be_dma_mem *q_mem = &rxq->dma_mem;
1301 int status;
1302
Sathya Perla482c9e72011-06-29 23:33:17 +00001303 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001304
Sathya Perla482c9e72011-06-29 23:33:17 +00001305 wrb = wrb_from_mccq(adapter);
1306 if (!wrb) {
1307 status = -EBUSY;
1308 goto err;
1309 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001310 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001311
Somnath Kotur106df1e2011-10-27 07:12:13 +00001312 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301313 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001314
1315 req->cq_id = cpu_to_le16(cq_id);
1316 req->frag_size = fls(frag_size) - 1;
1317 req->num_pages = 2;
1318 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1319 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001320 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001321 req->rss_queue = cpu_to_le32(rss);
1322
Sathya Perla482c9e72011-06-29 23:33:17 +00001323 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001324 if (!status) {
1325 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301326
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001327 rxq->id = le16_to_cpu(resp->id);
1328 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001329 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001330 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001331
Sathya Perla482c9e72011-06-29 23:33:17 +00001332err:
1333 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001334 return status;
1335}
1336
Sathya Perlab31c50a2009-09-17 10:30:13 -07001337/* Generic destroyer function for all types of queues
1338 * Uses Mbox
1339 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001340int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301341 int queue_type)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001342{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001343 struct be_mcc_wrb *wrb;
1344 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001345 u8 subsys = 0, opcode = 0;
1346 int status;
1347
Ivan Vecera29849612010-12-14 05:43:19 +00001348 if (mutex_lock_interruptible(&adapter->mbox_lock))
1349 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001350
Sathya Perlab31c50a2009-09-17 10:30:13 -07001351 wrb = wrb_from_mbox(adapter);
1352 req = embedded_payload(wrb);
1353
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001354 switch (queue_type) {
1355 case QTYPE_EQ:
1356 subsys = CMD_SUBSYSTEM_COMMON;
1357 opcode = OPCODE_COMMON_EQ_DESTROY;
1358 break;
1359 case QTYPE_CQ:
1360 subsys = CMD_SUBSYSTEM_COMMON;
1361 opcode = OPCODE_COMMON_CQ_DESTROY;
1362 break;
1363 case QTYPE_TXQ:
1364 subsys = CMD_SUBSYSTEM_ETH;
1365 opcode = OPCODE_ETH_TX_DESTROY;
1366 break;
1367 case QTYPE_RXQ:
1368 subsys = CMD_SUBSYSTEM_ETH;
1369 opcode = OPCODE_ETH_RX_DESTROY;
1370 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001371 case QTYPE_MCCQ:
1372 subsys = CMD_SUBSYSTEM_COMMON;
1373 opcode = OPCODE_COMMON_MCC_DESTROY;
1374 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001375 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001376 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001377 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001378
Somnath Kotur106df1e2011-10-27 07:12:13 +00001379 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301380 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001381 req->id = cpu_to_le16(q->id);
1382
Sathya Perlab31c50a2009-09-17 10:30:13 -07001383 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001384 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001385
Ivan Vecera29849612010-12-14 05:43:19 +00001386 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001387 return status;
1388}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001389
Sathya Perla482c9e72011-06-29 23:33:17 +00001390/* Uses MCC */
1391int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1392{
1393 struct be_mcc_wrb *wrb;
1394 struct be_cmd_req_q_destroy *req;
1395 int status;
1396
1397 spin_lock_bh(&adapter->mcc_lock);
1398
1399 wrb = wrb_from_mccq(adapter);
1400 if (!wrb) {
1401 status = -EBUSY;
1402 goto err;
1403 }
1404 req = embedded_payload(wrb);
1405
Somnath Kotur106df1e2011-10-27 07:12:13 +00001406 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301407 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001408 req->id = cpu_to_le16(q->id);
1409
1410 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001411 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001412
1413err:
1414 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001415 return status;
1416}
1417
Sathya Perlab31c50a2009-09-17 10:30:13 -07001418/* Create an rx filtering policy configuration on an i/f
Sathya Perlabea50982013-08-27 16:57:33 +05301419 * Will use MBOX only if MCCQ has not been created.
Sathya Perlab31c50a2009-09-17 10:30:13 -07001420 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001421int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001422 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001423{
Sathya Perlabea50982013-08-27 16:57:33 +05301424 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001425 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001426 int status;
1427
Sathya Perlabea50982013-08-27 16:57:33 +05301428 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001429 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301430 OPCODE_COMMON_NTWK_INTERFACE_CREATE,
1431 sizeof(*req), &wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001432 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001433 req->capability_flags = cpu_to_le32(cap_flags);
1434 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001435 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001436
Sathya Perlabea50982013-08-27 16:57:33 +05301437 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001438 if (!status) {
Sathya Perlabea50982013-08-27 16:57:33 +05301439 struct be_cmd_resp_if_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301440
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001441 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301442
1443 /* Hack to retrieve VF's pmac-id on BE3 */
1444 if (BE3_chip(adapter) && !be_physfn(adapter))
1445 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001446 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001447 return status;
1448}
1449
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001450/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001451int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001452{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001453 struct be_mcc_wrb *wrb;
1454 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001455 int status;
1456
Sathya Perla30128032011-11-10 19:17:57 +00001457 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001458 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001459
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001460 spin_lock_bh(&adapter->mcc_lock);
1461
1462 wrb = wrb_from_mccq(adapter);
1463 if (!wrb) {
1464 status = -EBUSY;
1465 goto err;
1466 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001467 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001468
Somnath Kotur106df1e2011-10-27 07:12:13 +00001469 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301470 OPCODE_COMMON_NTWK_INTERFACE_DESTROY,
1471 sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001472 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001473 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001474
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001475 status = be_mcc_notify_wait(adapter);
1476err:
1477 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001478 return status;
1479}
1480
1481/* Get stats is a non embedded command: the request is not embedded inside
1482 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001483 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001484 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001485int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001486{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001487 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001488 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001489 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001490
Sathya Perlab31c50a2009-09-17 10:30:13 -07001491 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001492
Sathya Perlab31c50a2009-09-17 10:30:13 -07001493 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001494 if (!wrb) {
1495 status = -EBUSY;
1496 goto err;
1497 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001498 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001499
Somnath Kotur106df1e2011-10-27 07:12:13 +00001500 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301501 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb,
1502 nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001503
Sathya Perlaca34fe32012-11-06 17:48:56 +00001504 /* version 1 of the cmd is not supported only by BE2 */
Ajit Khaparde61000862013-10-03 16:16:33 -05001505 if (BE2_chip(adapter))
1506 hdr->version = 0;
1507 if (BE3_chip(adapter) || lancer_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001508 hdr->version = 1;
Ajit Khaparde61000862013-10-03 16:16:33 -05001509 else
1510 hdr->version = 2;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001511
Sathya Perlab31c50a2009-09-17 10:30:13 -07001512 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001513 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001514
Sathya Perla713d03942009-11-22 22:02:45 +00001515err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001516 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001517 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001518}
1519
Selvin Xavier005d5692011-05-16 07:36:35 +00001520/* Lancer Stats */
1521int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301522 struct be_dma_mem *nonemb_cmd)
Selvin Xavier005d5692011-05-16 07:36:35 +00001523{
Selvin Xavier005d5692011-05-16 07:36:35 +00001524 struct be_mcc_wrb *wrb;
1525 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001526 int status = 0;
1527
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001528 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1529 CMD_SUBSYSTEM_ETH))
1530 return -EPERM;
1531
Selvin Xavier005d5692011-05-16 07:36:35 +00001532 spin_lock_bh(&adapter->mcc_lock);
1533
1534 wrb = wrb_from_mccq(adapter);
1535 if (!wrb) {
1536 status = -EBUSY;
1537 goto err;
1538 }
1539 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001540
Somnath Kotur106df1e2011-10-27 07:12:13 +00001541 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301542 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size,
1543 wrb, nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001544
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001545 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001546 req->cmd_params.params.reset_stats = 0;
1547
Selvin Xavier005d5692011-05-16 07:36:35 +00001548 be_mcc_notify(adapter);
1549 adapter->stats_cmd_sent = true;
1550
1551err:
1552 spin_unlock_bh(&adapter->mcc_lock);
1553 return status;
1554}
1555
Sathya Perla323ff712012-09-28 04:39:43 +00001556static int be_mac_to_link_speed(int mac_speed)
1557{
1558 switch (mac_speed) {
1559 case PHY_LINK_SPEED_ZERO:
1560 return 0;
1561 case PHY_LINK_SPEED_10MBPS:
1562 return 10;
1563 case PHY_LINK_SPEED_100MBPS:
1564 return 100;
1565 case PHY_LINK_SPEED_1GBPS:
1566 return 1000;
1567 case PHY_LINK_SPEED_10GBPS:
1568 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301569 case PHY_LINK_SPEED_20GBPS:
1570 return 20000;
1571 case PHY_LINK_SPEED_25GBPS:
1572 return 25000;
1573 case PHY_LINK_SPEED_40GBPS:
1574 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001575 }
1576 return 0;
1577}
1578
1579/* Uses synchronous mcc
1580 * Returns link_speed in Mbps
1581 */
1582int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1583 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001584{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001585 struct be_mcc_wrb *wrb;
1586 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001587 int status;
1588
Sathya Perlab31c50a2009-09-17 10:30:13 -07001589 spin_lock_bh(&adapter->mcc_lock);
1590
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001591 if (link_status)
1592 *link_status = LINK_DOWN;
1593
Sathya Perlab31c50a2009-09-17 10:30:13 -07001594 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001595 if (!wrb) {
1596 status = -EBUSY;
1597 goto err;
1598 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001599 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001600
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001601 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301602 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1603 sizeof(*req), wrb, NULL);
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001604
Sathya Perlaca34fe32012-11-06 17:48:56 +00001605 /* version 1 of the cmd is not supported only by BE2 */
1606 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001607 req->hdr.version = 1;
1608
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001609 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001610
Sathya Perlab31c50a2009-09-17 10:30:13 -07001611 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001612 if (!status) {
1613 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301614
Sathya Perla323ff712012-09-28 04:39:43 +00001615 if (link_speed) {
1616 *link_speed = resp->link_speed ?
1617 le16_to_cpu(resp->link_speed) * 10 :
1618 be_mac_to_link_speed(resp->mac_speed);
1619
1620 if (!resp->logical_link_status)
1621 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001622 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001623 if (link_status)
1624 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001625 }
1626
Sathya Perla713d03942009-11-22 22:02:45 +00001627err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001628 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001629 return status;
1630}
1631
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001632/* Uses synchronous mcc */
1633int be_cmd_get_die_temperature(struct be_adapter *adapter)
1634{
1635 struct be_mcc_wrb *wrb;
1636 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301637 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001638
1639 spin_lock_bh(&adapter->mcc_lock);
1640
1641 wrb = wrb_from_mccq(adapter);
1642 if (!wrb) {
1643 status = -EBUSY;
1644 goto err;
1645 }
1646 req = embedded_payload(wrb);
1647
Somnath Kotur106df1e2011-10-27 07:12:13 +00001648 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301649 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES,
1650 sizeof(*req), wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001651
Somnath Kotur3de09452011-09-30 07:25:05 +00001652 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001653
1654err:
1655 spin_unlock_bh(&adapter->mcc_lock);
1656 return status;
1657}
1658
Somnath Kotur311fddc2011-03-16 21:22:43 +00001659/* Uses synchronous mcc */
1660int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1661{
1662 struct be_mcc_wrb *wrb;
1663 struct be_cmd_req_get_fat *req;
1664 int status;
1665
1666 spin_lock_bh(&adapter->mcc_lock);
1667
1668 wrb = wrb_from_mccq(adapter);
1669 if (!wrb) {
1670 status = -EBUSY;
1671 goto err;
1672 }
1673 req = embedded_payload(wrb);
1674
Somnath Kotur106df1e2011-10-27 07:12:13 +00001675 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301676 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb,
1677 NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001678 req->fat_operation = cpu_to_le32(QUERY_FAT);
1679 status = be_mcc_notify_wait(adapter);
1680 if (!status) {
1681 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301682
Somnath Kotur311fddc2011-03-16 21:22:43 +00001683 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001684 *log_size = le32_to_cpu(resp->log_size) -
1685 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001686 }
1687err:
1688 spin_unlock_bh(&adapter->mcc_lock);
1689 return status;
1690}
1691
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301692int be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
Somnath Kotur311fddc2011-03-16 21:22:43 +00001693{
1694 struct be_dma_mem get_fat_cmd;
1695 struct be_mcc_wrb *wrb;
1696 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001697 u32 offset = 0, total_size, buf_size,
1698 log_offset = sizeof(u32), payload_len;
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301699 int status = 0;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001700
1701 if (buf_len == 0)
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301702 return -EIO;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001703
1704 total_size = buf_len;
1705
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001706 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1707 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301708 get_fat_cmd.size,
1709 &get_fat_cmd.dma);
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001710 if (!get_fat_cmd.va) {
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001711 dev_err(&adapter->pdev->dev,
1712 "Memory allocation failure while retrieving FAT data\n");
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301713 return -ENOMEM;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001714 }
1715
Somnath Kotur311fddc2011-03-16 21:22:43 +00001716 spin_lock_bh(&adapter->mcc_lock);
1717
Somnath Kotur311fddc2011-03-16 21:22:43 +00001718 while (total_size) {
1719 buf_size = min(total_size, (u32)60*1024);
1720 total_size -= buf_size;
1721
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001722 wrb = wrb_from_mccq(adapter);
1723 if (!wrb) {
1724 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001725 goto err;
1726 }
1727 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001728
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001729 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001730 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301731 OPCODE_COMMON_MANAGE_FAT, payload_len,
1732 wrb, &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001733
1734 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1735 req->read_log_offset = cpu_to_le32(log_offset);
1736 req->read_log_length = cpu_to_le32(buf_size);
1737 req->data_buffer_size = cpu_to_le32(buf_size);
1738
1739 status = be_mcc_notify_wait(adapter);
1740 if (!status) {
1741 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
Kalesh AP03d28ff2014-09-19 15:46:56 +05301742
Somnath Kotur311fddc2011-03-16 21:22:43 +00001743 memcpy(buf + offset,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301744 resp->data_buffer,
1745 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001746 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001747 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001748 goto err;
1749 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001750 offset += buf_size;
1751 log_offset += buf_size;
1752 }
1753err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001754 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301755 get_fat_cmd.va, get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001756 spin_unlock_bh(&adapter->mcc_lock);
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301757 return status;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001758}
1759
Sathya Perla04b71172011-09-27 13:30:27 -04001760/* Uses synchronous mcc */
Kalesh APe97e3cd2014-07-17 16:20:26 +05301761int be_cmd_get_fw_ver(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001762{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001763 struct be_mcc_wrb *wrb;
1764 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001765 int status;
1766
Sathya Perla04b71172011-09-27 13:30:27 -04001767 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001768
Sathya Perla04b71172011-09-27 13:30:27 -04001769 wrb = wrb_from_mccq(adapter);
1770 if (!wrb) {
1771 status = -EBUSY;
1772 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001773 }
1774
Sathya Perla04b71172011-09-27 13:30:27 -04001775 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001776
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_GET_FW_VERSION, sizeof(*req), wrb,
1779 NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001780 status = be_mcc_notify_wait(adapter);
1781 if (!status) {
1782 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
Sathya Perlaacbafeb2014-09-02 09:56:46 +05301783
Vasundhara Volam242eb472014-09-12 17:39:15 +05301784 strlcpy(adapter->fw_ver, resp->firmware_version_string,
1785 sizeof(adapter->fw_ver));
1786 strlcpy(adapter->fw_on_flash, resp->fw_on_flash_version_string,
1787 sizeof(adapter->fw_on_flash));
Sathya Perla04b71172011-09-27 13:30:27 -04001788 }
1789err:
1790 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001791 return status;
1792}
1793
Sathya Perlab31c50a2009-09-17 10:30:13 -07001794/* set the EQ delay interval of an EQ to specified value
1795 * Uses async mcc
1796 */
Kalesh APb502ae82014-09-19 15:46:51 +05301797static int __be_cmd_modify_eqd(struct be_adapter *adapter,
1798 struct be_set_eqd *set_eqd, int num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001799{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001800 struct be_mcc_wrb *wrb;
1801 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla2632baf2013-10-01 16:00:00 +05301802 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001803
Sathya Perlab31c50a2009-09-17 10:30:13 -07001804 spin_lock_bh(&adapter->mcc_lock);
1805
1806 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001807 if (!wrb) {
1808 status = -EBUSY;
1809 goto err;
1810 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001811 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001812
Somnath Kotur106df1e2011-10-27 07:12:13 +00001813 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301814 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb,
1815 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001816
Sathya Perla2632baf2013-10-01 16:00:00 +05301817 req->num_eq = cpu_to_le32(num);
1818 for (i = 0; i < num; i++) {
1819 req->set_eqd[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
1820 req->set_eqd[i].phase = 0;
1821 req->set_eqd[i].delay_multiplier =
1822 cpu_to_le32(set_eqd[i].delay_multiplier);
1823 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001824
Sathya Perlab31c50a2009-09-17 10:30:13 -07001825 be_mcc_notify(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001826err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001827 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001828 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001829}
1830
Kalesh AP93676702014-09-12 17:39:20 +05301831int be_cmd_modify_eqd(struct be_adapter *adapter, struct be_set_eqd *set_eqd,
1832 int num)
1833{
1834 int num_eqs, i = 0;
1835
1836 if (lancer_chip(adapter) && num > 8) {
1837 while (num) {
1838 num_eqs = min(num, 8);
1839 __be_cmd_modify_eqd(adapter, &set_eqd[i], num_eqs);
1840 i += num_eqs;
1841 num -= num_eqs;
1842 }
1843 } else {
1844 __be_cmd_modify_eqd(adapter, set_eqd, num);
1845 }
1846
1847 return 0;
1848}
1849
Sathya Perlab31c50a2009-09-17 10:30:13 -07001850/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001851int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Kalesh AP4d567d92014-05-09 13:29:17 +05301852 u32 num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001853{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001854 struct be_mcc_wrb *wrb;
1855 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001856 int status;
1857
Sathya Perlab31c50a2009-09-17 10:30:13 -07001858 spin_lock_bh(&adapter->mcc_lock);
1859
1860 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001861 if (!wrb) {
1862 status = -EBUSY;
1863 goto err;
1864 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001865 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001866
Somnath Kotur106df1e2011-10-27 07:12:13 +00001867 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301868 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req),
1869 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001870
1871 req->interface_id = if_id;
Ajit Khaparde012bd382013-11-18 10:44:24 -06001872 req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001873 req->num_vlan = num;
Kalesh AP4d567d92014-05-09 13:29:17 +05301874 memcpy(req->normal_vlan, vtag_array,
1875 req->num_vlan * sizeof(vtag_array[0]));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001876
Sathya Perlab31c50a2009-09-17 10:30:13 -07001877 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001878err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001879 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001880 return status;
1881}
1882
Sathya Perla5b8821b2011-08-02 19:57:44 +00001883int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001884{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001885 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001886 struct be_dma_mem *mem = &adapter->rx_filter;
1887 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001888 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001889
Sathya Perla8788fdc2009-07-27 22:52:03 +00001890 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001891
Sathya Perlab31c50a2009-09-17 10:30:13 -07001892 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001893 if (!wrb) {
1894 status = -EBUSY;
1895 goto err;
1896 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001897 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001898 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301899 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1900 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001901
Sathya Perla5b8821b2011-08-02 19:57:44 +00001902 req->if_id = cpu_to_le32(adapter->if_handle);
1903 if (flags & IFF_PROMISC) {
1904 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301905 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1906 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001907 if (value == ON)
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301908 req->if_flags =
1909 cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1910 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1911 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001912 } else if (flags & IFF_ALLMULTI) {
1913 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001914 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001915 } else if (flags & BE_FLAGS_VLAN_PROMISC) {
1916 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_VLAN_PROMISCUOUS);
1917
1918 if (value == ON)
1919 req->if_flags =
1920 cpu_to_le32(BE_IF_FLAGS_VLAN_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001921 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001922 struct netdev_hw_addr *ha;
1923 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001924
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001925 req->if_flags_mask = req->if_flags =
1926 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001927
1928 /* Reset mcast promisc mode if already set by setting mask
1929 * and not setting flags field
1930 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001931 req->if_flags_mask |=
1932 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05301933 be_if_cap_flags(adapter));
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001934 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001935 netdev_for_each_mc_addr(ha, adapter->netdev)
1936 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1937 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001938
Ajit Khaparde012bd382013-11-18 10:44:24 -06001939 if ((req->if_flags_mask & cpu_to_le32(be_if_cap_flags(adapter))) !=
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301940 req->if_flags_mask) {
Ajit Khaparde012bd382013-11-18 10:44:24 -06001941 dev_warn(&adapter->pdev->dev,
1942 "Cannot set rx filter flags 0x%x\n",
1943 req->if_flags_mask);
1944 dev_warn(&adapter->pdev->dev,
1945 "Interface is capable of 0x%x flags only\n",
1946 be_if_cap_flags(adapter));
1947 }
1948 req->if_flags_mask &= cpu_to_le32(be_if_cap_flags(adapter));
1949
Sathya Perla0d1d5872011-08-03 05:19:27 -07001950 status = be_mcc_notify_wait(adapter);
Ajit Khaparde012bd382013-11-18 10:44:24 -06001951
Sathya Perla713d03942009-11-22 22:02:45 +00001952err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001953 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001954 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001955}
1956
Sathya Perlab31c50a2009-09-17 10:30:13 -07001957/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001958int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001959{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001960 struct be_mcc_wrb *wrb;
1961 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001962 int status;
1963
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001964 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1965 CMD_SUBSYSTEM_COMMON))
1966 return -EPERM;
1967
Sathya Perlab31c50a2009-09-17 10:30:13 -07001968 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001969
Sathya Perlab31c50a2009-09-17 10:30:13 -07001970 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001971 if (!wrb) {
1972 status = -EBUSY;
1973 goto err;
1974 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001975 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001976
Somnath Kotur106df1e2011-10-27 07:12:13 +00001977 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301978 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req),
1979 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001980
Suresh Reddyb29812c2014-09-12 17:39:17 +05301981 req->hdr.version = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001982 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1983 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1984
Sathya Perlab31c50a2009-09-17 10:30:13 -07001985 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001986
Sathya Perla713d03942009-11-22 22:02:45 +00001987err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001988 spin_unlock_bh(&adapter->mcc_lock);
Suresh Reddyb29812c2014-09-12 17:39:17 +05301989
1990 if (base_status(status) == MCC_STATUS_FEATURE_NOT_SUPPORTED)
1991 return -EOPNOTSUPP;
1992
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001993 return status;
1994}
1995
Sathya Perlab31c50a2009-09-17 10:30:13 -07001996/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001997int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001998{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001999 struct be_mcc_wrb *wrb;
2000 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002001 int status;
2002
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002003 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
2004 CMD_SUBSYSTEM_COMMON))
2005 return -EPERM;
2006
Sathya Perlab31c50a2009-09-17 10:30:13 -07002007 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002008
Sathya Perlab31c50a2009-09-17 10:30:13 -07002009 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002010 if (!wrb) {
2011 status = -EBUSY;
2012 goto err;
2013 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002014 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002015
Somnath Kotur106df1e2011-10-27 07:12:13 +00002016 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302017 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req),
2018 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002019
Sathya Perlab31c50a2009-09-17 10:30:13 -07002020 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002021 if (!status) {
2022 struct be_cmd_resp_get_flow_control *resp =
2023 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302024
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002025 *tx_fc = le16_to_cpu(resp->tx_flow_control);
2026 *rx_fc = le16_to_cpu(resp->rx_flow_control);
2027 }
2028
Sathya Perla713d03942009-11-22 22:02:45 +00002029err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07002030 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002031 return status;
2032}
2033
Sathya Perlab31c50a2009-09-17 10:30:13 -07002034/* Uses mbox */
Kalesh APe97e3cd2014-07-17 16:20:26 +05302035int be_cmd_query_fw_cfg(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002036{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002037 struct be_mcc_wrb *wrb;
2038 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002039 int status;
2040
Ivan Vecera29849612010-12-14 05:43:19 +00002041 if (mutex_lock_interruptible(&adapter->mbox_lock))
2042 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002043
Sathya Perlab31c50a2009-09-17 10:30:13 -07002044 wrb = wrb_from_mbox(adapter);
2045 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002046
Somnath Kotur106df1e2011-10-27 07:12:13 +00002047 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302048 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
2049 sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002050
Sathya Perlab31c50a2009-09-17 10:30:13 -07002051 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002052 if (!status) {
2053 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302054
Kalesh APe97e3cd2014-07-17 16:20:26 +05302055 adapter->port_num = le32_to_cpu(resp->phys_port);
2056 adapter->function_mode = le32_to_cpu(resp->function_mode);
2057 adapter->function_caps = le32_to_cpu(resp->function_caps);
2058 adapter->asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perlaacbafeb2014-09-02 09:56:46 +05302059 dev_info(&adapter->pdev->dev,
2060 "FW config: function_mode=0x%x, function_caps=0x%x\n",
2061 adapter->function_mode, adapter->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002062 }
2063
Ivan Vecera29849612010-12-14 05:43:19 +00002064 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002065 return status;
2066}
sarveshwarb14074ea2009-08-05 13:05:24 -07002067
Sathya Perlab31c50a2009-09-17 10:30:13 -07002068/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07002069int be_cmd_reset_function(struct be_adapter *adapter)
2070{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002071 struct be_mcc_wrb *wrb;
2072 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07002073 int status;
2074
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002075 if (lancer_chip(adapter)) {
2076 status = lancer_wait_ready(adapter);
2077 if (!status) {
2078 iowrite32(SLI_PORT_CONTROL_IP_MASK,
2079 adapter->db + SLIPORT_CONTROL_OFFSET);
2080 status = lancer_test_and_set_rdy_state(adapter);
2081 }
2082 if (status) {
2083 dev_err(&adapter->pdev->dev,
2084 "Adapter in non recoverable error\n");
2085 }
2086 return status;
2087 }
2088
Ivan Vecera29849612010-12-14 05:43:19 +00002089 if (mutex_lock_interruptible(&adapter->mbox_lock))
2090 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07002091
Sathya Perlab31c50a2009-09-17 10:30:13 -07002092 wrb = wrb_from_mbox(adapter);
2093 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07002094
Somnath Kotur106df1e2011-10-27 07:12:13 +00002095 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302096 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb,
2097 NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07002098
Sathya Perlab31c50a2009-09-17 10:30:13 -07002099 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07002100
Ivan Vecera29849612010-12-14 05:43:19 +00002101 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07002102 return status;
2103}
Ajit Khaparde84517482009-09-04 03:12:16 +00002104
Suresh Reddy594ad542013-04-25 23:03:20 +00002105int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01002106 u32 rss_hash_opts, u16 table_size, const u8 *rss_hkey)
Sathya Perla3abcded2010-10-03 22:12:27 -07002107{
2108 struct be_mcc_wrb *wrb;
2109 struct be_cmd_req_rss_config *req;
Sathya Perla3abcded2010-10-03 22:12:27 -07002110 int status;
2111
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302112 if (!(be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS))
2113 return 0;
2114
Kalesh APb51aa362014-05-09 13:29:19 +05302115 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002116
Kalesh APb51aa362014-05-09 13:29:19 +05302117 wrb = wrb_from_mccq(adapter);
2118 if (!wrb) {
2119 status = -EBUSY;
2120 goto err;
2121 }
Sathya Perla3abcded2010-10-03 22:12:27 -07002122 req = embedded_payload(wrb);
2123
Somnath Kotur106df1e2011-10-27 07:12:13 +00002124 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302125 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07002126
2127 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00002128 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07002129 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00002130
Kalesh APb51aa362014-05-09 13:29:19 +05302131 if (!BEx_chip(adapter))
Suresh Reddy594ad542013-04-25 23:03:20 +00002132 req->hdr.version = 1;
2133
Sathya Perla3abcded2010-10-03 22:12:27 -07002134 memcpy(req->cpu_table, rsstable, table_size);
Venkata Duvvurue2557872014-04-21 15:38:00 +05302135 memcpy(req->hash, rss_hkey, RSS_HASH_KEY_LEN);
Sathya Perla3abcded2010-10-03 22:12:27 -07002136 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
2137
Kalesh APb51aa362014-05-09 13:29:19 +05302138 status = be_mcc_notify_wait(adapter);
2139err:
2140 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002141 return status;
2142}
2143
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002144/* Uses sync mcc */
2145int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302146 u8 bcn, u8 sts, u8 state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002147{
2148 struct be_mcc_wrb *wrb;
2149 struct be_cmd_req_enable_disable_beacon *req;
2150 int status;
2151
2152 spin_lock_bh(&adapter->mcc_lock);
2153
2154 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002155 if (!wrb) {
2156 status = -EBUSY;
2157 goto err;
2158 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002159 req = embedded_payload(wrb);
2160
Somnath Kotur106df1e2011-10-27 07:12:13 +00002161 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302162 OPCODE_COMMON_ENABLE_DISABLE_BEACON,
2163 sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002164
2165 req->port_num = port_num;
2166 req->beacon_state = state;
2167 req->beacon_duration = bcn;
2168 req->status_duration = sts;
2169
2170 status = be_mcc_notify_wait(adapter);
2171
Sathya Perla713d03942009-11-22 22:02:45 +00002172err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002173 spin_unlock_bh(&adapter->mcc_lock);
2174 return status;
2175}
2176
2177/* Uses sync mcc */
2178int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2179{
2180 struct be_mcc_wrb *wrb;
2181 struct be_cmd_req_get_beacon_state *req;
2182 int status;
2183
2184 spin_lock_bh(&adapter->mcc_lock);
2185
2186 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002187 if (!wrb) {
2188 status = -EBUSY;
2189 goto err;
2190 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002191 req = embedded_payload(wrb);
2192
Somnath Kotur106df1e2011-10-27 07:12:13 +00002193 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302194 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req),
2195 wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002196
2197 req->port_num = port_num;
2198
2199 status = be_mcc_notify_wait(adapter);
2200 if (!status) {
2201 struct be_cmd_resp_get_beacon_state *resp =
2202 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302203
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002204 *state = resp->beacon_state;
2205 }
2206
Sathya Perla713d03942009-11-22 22:02:45 +00002207err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002208 spin_unlock_bh(&adapter->mcc_lock);
2209 return status;
2210}
2211
Mark Leonarde36edd92014-09-12 17:39:18 +05302212/* Uses sync mcc */
2213int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2214 u8 page_num, u8 *data)
2215{
2216 struct be_dma_mem cmd;
2217 struct be_mcc_wrb *wrb;
2218 struct be_cmd_req_port_type *req;
2219 int status;
2220
2221 if (page_num > TR_PAGE_A2)
2222 return -EINVAL;
2223
2224 cmd.size = sizeof(struct be_cmd_resp_port_type);
2225 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
2226 if (!cmd.va) {
2227 dev_err(&adapter->pdev->dev, "Memory allocation failed\n");
2228 return -ENOMEM;
2229 }
2230 memset(cmd.va, 0, cmd.size);
2231
2232 spin_lock_bh(&adapter->mcc_lock);
2233
2234 wrb = wrb_from_mccq(adapter);
2235 if (!wrb) {
2236 status = -EBUSY;
2237 goto err;
2238 }
2239 req = cmd.va;
2240
2241 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2242 OPCODE_COMMON_READ_TRANSRECV_DATA,
2243 cmd.size, wrb, &cmd);
2244
2245 req->port = cpu_to_le32(adapter->hba_port_num);
2246 req->page_num = cpu_to_le32(page_num);
2247 status = be_mcc_notify_wait(adapter);
2248 if (!status) {
2249 struct be_cmd_resp_port_type *resp = cmd.va;
2250
2251 memcpy(data, resp->page_data, PAGE_DATA_LEN);
2252 }
2253err:
2254 spin_unlock_bh(&adapter->mcc_lock);
2255 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2256 return status;
2257}
2258
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002259int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002260 u32 data_size, u32 data_offset,
2261 const char *obj_name, u32 *data_written,
2262 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002263{
2264 struct be_mcc_wrb *wrb;
2265 struct lancer_cmd_req_write_object *req;
2266 struct lancer_cmd_resp_write_object *resp;
2267 void *ctxt = NULL;
2268 int status;
2269
2270 spin_lock_bh(&adapter->mcc_lock);
2271 adapter->flash_status = 0;
2272
2273 wrb = wrb_from_mccq(adapter);
2274 if (!wrb) {
2275 status = -EBUSY;
2276 goto err_unlock;
2277 }
2278
2279 req = embedded_payload(wrb);
2280
Somnath Kotur106df1e2011-10-27 07:12:13 +00002281 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302282 OPCODE_COMMON_WRITE_OBJECT,
2283 sizeof(struct lancer_cmd_req_write_object), wrb,
2284 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002285
2286 ctxt = &req->context;
2287 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302288 write_length, ctxt, data_size);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002289
2290 if (data_size == 0)
2291 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302292 eof, ctxt, 1);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002293 else
2294 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302295 eof, ctxt, 0);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002296
2297 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2298 req->write_offset = cpu_to_le32(data_offset);
Vasundhara Volam242eb472014-09-12 17:39:15 +05302299 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002300 req->descriptor_count = cpu_to_le32(1);
2301 req->buf_len = cpu_to_le32(data_size);
2302 req->addr_low = cpu_to_le32((cmd->dma +
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302303 sizeof(struct lancer_cmd_req_write_object))
2304 & 0xFFFFFFFF);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002305 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2306 sizeof(struct lancer_cmd_req_write_object)));
2307
2308 be_mcc_notify(adapter);
2309 spin_unlock_bh(&adapter->mcc_lock);
2310
Suresh Reddy5eeff632014-01-06 13:02:24 +05302311 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002312 msecs_to_jiffies(60000)))
Kalesh APfd451602014-07-17 16:20:21 +05302313 status = -ETIMEDOUT;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002314 else
2315 status = adapter->flash_status;
2316
2317 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002318 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002319 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002320 *change_status = resp->change_status;
2321 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002322 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002323 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002324
2325 return status;
2326
2327err_unlock:
2328 spin_unlock_bh(&adapter->mcc_lock);
2329 return status;
2330}
2331
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +05302332int be_cmd_query_cable_type(struct be_adapter *adapter)
2333{
2334 u8 page_data[PAGE_DATA_LEN];
2335 int status;
2336
2337 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2338 page_data);
2339 if (!status) {
2340 switch (adapter->phy.interface_type) {
2341 case PHY_TYPE_QSFP:
2342 adapter->phy.cable_type =
2343 page_data[QSFP_PLUS_CABLE_TYPE_OFFSET];
2344 break;
2345 case PHY_TYPE_SFP_PLUS_10GB:
2346 adapter->phy.cable_type =
2347 page_data[SFP_PLUS_CABLE_TYPE_OFFSET];
2348 break;
2349 default:
2350 adapter->phy.cable_type = 0;
2351 break;
2352 }
2353 }
2354 return status;
2355}
2356
Kalesh APf0613382014-08-01 17:47:32 +05302357int lancer_cmd_delete_object(struct be_adapter *adapter, const char *obj_name)
2358{
2359 struct lancer_cmd_req_delete_object *req;
2360 struct be_mcc_wrb *wrb;
2361 int status;
2362
2363 spin_lock_bh(&adapter->mcc_lock);
2364
2365 wrb = wrb_from_mccq(adapter);
2366 if (!wrb) {
2367 status = -EBUSY;
2368 goto err;
2369 }
2370
2371 req = embedded_payload(wrb);
2372
2373 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2374 OPCODE_COMMON_DELETE_OBJECT,
2375 sizeof(*req), wrb, NULL);
2376
Vasundhara Volam242eb472014-09-12 17:39:15 +05302377 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Kalesh APf0613382014-08-01 17:47:32 +05302378
2379 status = be_mcc_notify_wait(adapter);
2380err:
2381 spin_unlock_bh(&adapter->mcc_lock);
2382 return status;
2383}
2384
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002385int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302386 u32 data_size, u32 data_offset, const char *obj_name,
2387 u32 *data_read, u32 *eof, u8 *addn_status)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002388{
2389 struct be_mcc_wrb *wrb;
2390 struct lancer_cmd_req_read_object *req;
2391 struct lancer_cmd_resp_read_object *resp;
2392 int status;
2393
2394 spin_lock_bh(&adapter->mcc_lock);
2395
2396 wrb = wrb_from_mccq(adapter);
2397 if (!wrb) {
2398 status = -EBUSY;
2399 goto err_unlock;
2400 }
2401
2402 req = embedded_payload(wrb);
2403
2404 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302405 OPCODE_COMMON_READ_OBJECT,
2406 sizeof(struct lancer_cmd_req_read_object), wrb,
2407 NULL);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002408
2409 req->desired_read_len = cpu_to_le32(data_size);
2410 req->read_offset = cpu_to_le32(data_offset);
2411 strcpy(req->object_name, obj_name);
2412 req->descriptor_count = cpu_to_le32(1);
2413 req->buf_len = cpu_to_le32(data_size);
2414 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2415 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2416
2417 status = be_mcc_notify_wait(adapter);
2418
2419 resp = embedded_payload(wrb);
2420 if (!status) {
2421 *data_read = le32_to_cpu(resp->actual_read_len);
2422 *eof = le32_to_cpu(resp->eof);
2423 } else {
2424 *addn_status = resp->additional_status;
2425 }
2426
2427err_unlock:
2428 spin_unlock_bh(&adapter->mcc_lock);
2429 return status;
2430}
2431
Ajit Khaparde84517482009-09-04 03:12:16 +00002432int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302433 u32 flash_type, u32 flash_opcode, u32 buf_size)
Ajit Khaparde84517482009-09-04 03:12:16 +00002434{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002435 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002436 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002437 int status;
2438
Sathya Perlab31c50a2009-09-17 10:30:13 -07002439 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002440 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002441
2442 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002443 if (!wrb) {
2444 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002445 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002446 }
2447 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002448
Somnath Kotur106df1e2011-10-27 07:12:13 +00002449 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302450 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb,
2451 cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002452
2453 req->params.op_type = cpu_to_le32(flash_type);
2454 req->params.op_code = cpu_to_le32(flash_opcode);
2455 req->params.data_buf_size = cpu_to_le32(buf_size);
2456
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002457 be_mcc_notify(adapter);
2458 spin_unlock_bh(&adapter->mcc_lock);
2459
Suresh Reddy5eeff632014-01-06 13:02:24 +05302460 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
2461 msecs_to_jiffies(40000)))
Kalesh APfd451602014-07-17 16:20:21 +05302462 status = -ETIMEDOUT;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002463 else
2464 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002465
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002466 return status;
2467
2468err_unlock:
2469 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002470 return status;
2471}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002472
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002473int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +05302474 u16 optype, int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002475{
2476 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002477 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002478 int status;
2479
2480 spin_lock_bh(&adapter->mcc_lock);
2481
2482 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002483 if (!wrb) {
2484 status = -EBUSY;
2485 goto err;
2486 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002487 req = embedded_payload(wrb);
2488
Somnath Kotur106df1e2011-10-27 07:12:13 +00002489 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002490 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2491 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002492
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +05302493 req->params.op_type = cpu_to_le32(optype);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002494 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002495 req->params.offset = cpu_to_le32(offset);
2496 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002497
2498 status = be_mcc_notify_wait(adapter);
2499 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002500 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002501
Sathya Perla713d03942009-11-22 22:02:45 +00002502err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002503 spin_unlock_bh(&adapter->mcc_lock);
2504 return status;
2505}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002506
Dan Carpenterc196b022010-05-26 04:47:39 +00002507int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302508 struct be_dma_mem *nonemb_cmd)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002509{
2510 struct be_mcc_wrb *wrb;
2511 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002512 int status;
2513
2514 spin_lock_bh(&adapter->mcc_lock);
2515
2516 wrb = wrb_from_mccq(adapter);
2517 if (!wrb) {
2518 status = -EBUSY;
2519 goto err;
2520 }
2521 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002522
Somnath Kotur106df1e2011-10-27 07:12:13 +00002523 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302524 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req),
2525 wrb, nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002526 memcpy(req->magic_mac, mac, ETH_ALEN);
2527
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002528 status = be_mcc_notify_wait(adapter);
2529
2530err:
2531 spin_unlock_bh(&adapter->mcc_lock);
2532 return status;
2533}
Suresh Rff33a6e2009-12-03 16:15:52 -08002534
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002535int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2536 u8 loopback_type, u8 enable)
2537{
2538 struct be_mcc_wrb *wrb;
2539 struct be_cmd_req_set_lmode *req;
2540 int status;
2541
2542 spin_lock_bh(&adapter->mcc_lock);
2543
2544 wrb = wrb_from_mccq(adapter);
2545 if (!wrb) {
2546 status = -EBUSY;
2547 goto err;
2548 }
2549
2550 req = embedded_payload(wrb);
2551
Somnath Kotur106df1e2011-10-27 07:12:13 +00002552 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302553 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req),
2554 wrb, NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002555
2556 req->src_port = port_num;
2557 req->dest_port = port_num;
2558 req->loopback_type = loopback_type;
2559 req->loopback_state = enable;
2560
2561 status = be_mcc_notify_wait(adapter);
2562err:
2563 spin_unlock_bh(&adapter->mcc_lock);
2564 return status;
2565}
2566
Suresh Rff33a6e2009-12-03 16:15:52 -08002567int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302568 u32 loopback_type, u32 pkt_size, u32 num_pkts,
2569 u64 pattern)
Suresh Rff33a6e2009-12-03 16:15:52 -08002570{
2571 struct be_mcc_wrb *wrb;
2572 struct be_cmd_req_loopback_test *req;
Suresh Reddy5eeff632014-01-06 13:02:24 +05302573 struct be_cmd_resp_loopback_test *resp;
Suresh Rff33a6e2009-12-03 16:15:52 -08002574 int status;
2575
2576 spin_lock_bh(&adapter->mcc_lock);
2577
2578 wrb = wrb_from_mccq(adapter);
2579 if (!wrb) {
2580 status = -EBUSY;
2581 goto err;
2582 }
2583
2584 req = embedded_payload(wrb);
2585
Somnath Kotur106df1e2011-10-27 07:12:13 +00002586 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302587 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb,
2588 NULL);
Suresh Rff33a6e2009-12-03 16:15:52 -08002589
Suresh Reddy5eeff632014-01-06 13:02:24 +05302590 req->hdr.timeout = cpu_to_le32(15);
Suresh Rff33a6e2009-12-03 16:15:52 -08002591 req->pattern = cpu_to_le64(pattern);
2592 req->src_port = cpu_to_le32(port_num);
2593 req->dest_port = cpu_to_le32(port_num);
2594 req->pkt_size = cpu_to_le32(pkt_size);
2595 req->num_pkts = cpu_to_le32(num_pkts);
2596 req->loopback_type = cpu_to_le32(loopback_type);
2597
Suresh Reddy5eeff632014-01-06 13:02:24 +05302598 be_mcc_notify(adapter);
Suresh Rff33a6e2009-12-03 16:15:52 -08002599
Suresh Reddy5eeff632014-01-06 13:02:24 +05302600 spin_unlock_bh(&adapter->mcc_lock);
2601
2602 wait_for_completion(&adapter->et_cmd_compl);
2603 resp = embedded_payload(wrb);
2604 status = le32_to_cpu(resp->status);
2605
2606 return status;
Suresh Rff33a6e2009-12-03 16:15:52 -08002607err:
2608 spin_unlock_bh(&adapter->mcc_lock);
2609 return status;
2610}
2611
2612int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302613 u32 byte_cnt, struct be_dma_mem *cmd)
Suresh Rff33a6e2009-12-03 16:15:52 -08002614{
2615 struct be_mcc_wrb *wrb;
2616 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002617 int status;
2618 int i, j = 0;
2619
2620 spin_lock_bh(&adapter->mcc_lock);
2621
2622 wrb = wrb_from_mccq(adapter);
2623 if (!wrb) {
2624 status = -EBUSY;
2625 goto err;
2626 }
2627 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002628 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302629 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb,
2630 cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002631
2632 req->pattern = cpu_to_le64(pattern);
2633 req->byte_count = cpu_to_le32(byte_cnt);
2634 for (i = 0; i < byte_cnt; i++) {
2635 req->snd_buff[i] = (u8)(pattern >> (j*8));
2636 j++;
2637 if (j > 7)
2638 j = 0;
2639 }
2640
2641 status = be_mcc_notify_wait(adapter);
2642
2643 if (!status) {
2644 struct be_cmd_resp_ddrdma_test *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05302645
Suresh Rff33a6e2009-12-03 16:15:52 -08002646 resp = cmd->va;
2647 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2648 resp->snd_err) {
2649 status = -1;
2650 }
2651 }
2652
2653err:
2654 spin_unlock_bh(&adapter->mcc_lock);
2655 return status;
2656}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002657
Dan Carpenterc196b022010-05-26 04:47:39 +00002658int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302659 struct be_dma_mem *nonemb_cmd)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002660{
2661 struct be_mcc_wrb *wrb;
2662 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002663 int status;
2664
2665 spin_lock_bh(&adapter->mcc_lock);
2666
2667 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002668 if (!wrb) {
2669 status = -EBUSY;
2670 goto err;
2671 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002672 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002673
Somnath Kotur106df1e2011-10-27 07:12:13 +00002674 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302675 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2676 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002677
2678 status = be_mcc_notify_wait(adapter);
2679
Ajit Khapardee45ff012011-02-04 17:18:28 +00002680err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002681 spin_unlock_bh(&adapter->mcc_lock);
2682 return status;
2683}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002684
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002685int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002686{
2687 struct be_mcc_wrb *wrb;
2688 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002689 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002690 int status;
2691
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002692 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2693 CMD_SUBSYSTEM_COMMON))
2694 return -EPERM;
2695
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002696 spin_lock_bh(&adapter->mcc_lock);
2697
2698 wrb = wrb_from_mccq(adapter);
2699 if (!wrb) {
2700 status = -EBUSY;
2701 goto err;
2702 }
Sathya Perla306f1342011-08-02 19:57:45 +00002703 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302704 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Sathya Perla306f1342011-08-02 19:57:45 +00002705 if (!cmd.va) {
2706 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2707 status = -ENOMEM;
2708 goto err;
2709 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002710
Sathya Perla306f1342011-08-02 19:57:45 +00002711 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002712
Somnath Kotur106df1e2011-10-27 07:12:13 +00002713 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302714 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2715 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002716
2717 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002718 if (!status) {
2719 struct be_phy_info *resp_phy_info =
2720 cmd.va + sizeof(struct be_cmd_req_hdr);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302721
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002722 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2723 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002724 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002725 adapter->phy.auto_speeds_supported =
2726 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2727 adapter->phy.fixed_speeds_supported =
2728 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2729 adapter->phy.misc_params =
2730 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05302731
2732 if (BE2_chip(adapter)) {
2733 adapter->phy.fixed_speeds_supported =
2734 BE_SUPPORTED_SPEED_10GBPS |
2735 BE_SUPPORTED_SPEED_1GBPS;
2736 }
Sathya Perla306f1342011-08-02 19:57:45 +00002737 }
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302738 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002739err:
2740 spin_unlock_bh(&adapter->mcc_lock);
2741 return status;
2742}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002743
2744int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2745{
2746 struct be_mcc_wrb *wrb;
2747 struct be_cmd_req_set_qos *req;
2748 int status;
2749
2750 spin_lock_bh(&adapter->mcc_lock);
2751
2752 wrb = wrb_from_mccq(adapter);
2753 if (!wrb) {
2754 status = -EBUSY;
2755 goto err;
2756 }
2757
2758 req = embedded_payload(wrb);
2759
Somnath Kotur106df1e2011-10-27 07:12:13 +00002760 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302761 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002762
2763 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002764 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2765 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002766
2767 status = be_mcc_notify_wait(adapter);
2768
2769err:
2770 spin_unlock_bh(&adapter->mcc_lock);
2771 return status;
2772}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002773
2774int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2775{
2776 struct be_mcc_wrb *wrb;
2777 struct be_cmd_req_cntl_attribs *req;
2778 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002779 int status;
2780 int payload_len = max(sizeof(*req), sizeof(*resp));
2781 struct mgmt_controller_attrib *attribs;
2782 struct be_dma_mem attribs_cmd;
2783
Suresh Reddyd98ef502013-04-25 00:56:55 +00002784 if (mutex_lock_interruptible(&adapter->mbox_lock))
2785 return -1;
2786
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002787 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2788 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2789 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302790 &attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002791 if (!attribs_cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302792 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002793 status = -ENOMEM;
2794 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002795 }
2796
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002797 wrb = wrb_from_mbox(adapter);
2798 if (!wrb) {
2799 status = -EBUSY;
2800 goto err;
2801 }
2802 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002803
Somnath Kotur106df1e2011-10-27 07:12:13 +00002804 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302805 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len,
2806 wrb, &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002807
2808 status = be_mbox_notify_wait(adapter);
2809 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002810 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002811 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2812 }
2813
2814err:
2815 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002816 if (attribs_cmd.va)
2817 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2818 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002819 return status;
2820}
Sathya Perla2e588f82011-03-11 02:49:26 +00002821
2822/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002823int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002824{
2825 struct be_mcc_wrb *wrb;
2826 struct be_cmd_req_set_func_cap *req;
2827 int status;
2828
2829 if (mutex_lock_interruptible(&adapter->mbox_lock))
2830 return -1;
2831
2832 wrb = wrb_from_mbox(adapter);
2833 if (!wrb) {
2834 status = -EBUSY;
2835 goto err;
2836 }
2837
2838 req = embedded_payload(wrb);
2839
Somnath Kotur106df1e2011-10-27 07:12:13 +00002840 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302841 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP,
2842 sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002843
2844 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2845 CAPABILITY_BE3_NATIVE_ERX_API);
2846 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2847
2848 status = be_mbox_notify_wait(adapter);
2849 if (!status) {
2850 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302851
Sathya Perla2e588f82011-03-11 02:49:26 +00002852 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2853 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002854 if (!adapter->be3_native)
2855 dev_warn(&adapter->pdev->dev,
2856 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002857 }
2858err:
2859 mutex_unlock(&adapter->mbox_lock);
2860 return status;
2861}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002862
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002863/* Get privilege(s) for a function */
2864int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2865 u32 domain)
2866{
2867 struct be_mcc_wrb *wrb;
2868 struct be_cmd_req_get_fn_privileges *req;
2869 int status;
2870
2871 spin_lock_bh(&adapter->mcc_lock);
2872
2873 wrb = wrb_from_mccq(adapter);
2874 if (!wrb) {
2875 status = -EBUSY;
2876 goto err;
2877 }
2878
2879 req = embedded_payload(wrb);
2880
2881 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2882 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2883 wrb, NULL);
2884
2885 req->hdr.domain = domain;
2886
2887 status = be_mcc_notify_wait(adapter);
2888 if (!status) {
2889 struct be_cmd_resp_get_fn_privileges *resp =
2890 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302891
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002892 *privilege = le32_to_cpu(resp->privilege_mask);
Suresh Reddy02308d72014-01-15 13:23:36 +05302893
2894 /* In UMC mode FW does not return right privileges.
2895 * Override with correct privilege equivalent to PF.
2896 */
2897 if (BEx_chip(adapter) && be_is_mc(adapter) &&
2898 be_physfn(adapter))
2899 *privilege = MAX_PRIVILEGES;
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002900 }
2901
2902err:
2903 spin_unlock_bh(&adapter->mcc_lock);
2904 return status;
2905}
2906
Sathya Perla04a06022013-07-23 15:25:00 +05302907/* Set privilege(s) for a function */
2908int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
2909 u32 domain)
2910{
2911 struct be_mcc_wrb *wrb;
2912 struct be_cmd_req_set_fn_privileges *req;
2913 int status;
2914
2915 spin_lock_bh(&adapter->mcc_lock);
2916
2917 wrb = wrb_from_mccq(adapter);
2918 if (!wrb) {
2919 status = -EBUSY;
2920 goto err;
2921 }
2922
2923 req = embedded_payload(wrb);
2924 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2925 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
2926 wrb, NULL);
2927 req->hdr.domain = domain;
2928 if (lancer_chip(adapter))
2929 req->privileges_lancer = cpu_to_le32(privileges);
2930 else
2931 req->privileges = cpu_to_le32(privileges);
2932
2933 status = be_mcc_notify_wait(adapter);
2934err:
2935 spin_unlock_bh(&adapter->mcc_lock);
2936 return status;
2937}
2938
Sathya Perla5a712c12013-07-23 15:24:59 +05302939/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
2940 * pmac_id_valid: false => pmac_id or MAC address is requested.
2941 * If pmac_id is returned, pmac_id_valid is returned as true
2942 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002943int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05302944 bool *pmac_id_valid, u32 *pmac_id, u32 if_handle,
2945 u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002946{
2947 struct be_mcc_wrb *wrb;
2948 struct be_cmd_req_get_mac_list *req;
2949 int status;
2950 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002951 struct be_dma_mem get_mac_list_cmd;
2952 int i;
2953
2954 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2955 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2956 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302957 get_mac_list_cmd.size,
2958 &get_mac_list_cmd.dma);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002959
2960 if (!get_mac_list_cmd.va) {
2961 dev_err(&adapter->pdev->dev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302962 "Memory allocation failure during GET_MAC_LIST\n");
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002963 return -ENOMEM;
2964 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002965
2966 spin_lock_bh(&adapter->mcc_lock);
2967
2968 wrb = wrb_from_mccq(adapter);
2969 if (!wrb) {
2970 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002971 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002972 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002973
2974 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002975
2976 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00002977 OPCODE_COMMON_GET_MAC_LIST,
2978 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002979 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002980 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05302981 if (*pmac_id_valid) {
2982 req->mac_id = cpu_to_le32(*pmac_id);
Suresh Reddyb188f092014-01-15 13:23:39 +05302983 req->iface_id = cpu_to_le16(if_handle);
Sathya Perla5a712c12013-07-23 15:24:59 +05302984 req->perm_override = 0;
2985 } else {
2986 req->perm_override = 1;
2987 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002988
2989 status = be_mcc_notify_wait(adapter);
2990 if (!status) {
2991 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002992 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05302993
2994 if (*pmac_id_valid) {
2995 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
2996 ETH_ALEN);
2997 goto out;
2998 }
2999
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003000 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
3001 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003002 * or one or more true or pseudo permanant mac addresses.
3003 * If an active mac_id is present, return first active mac_id
3004 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003005 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003006 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003007 struct get_list_macaddr *mac_entry;
3008 u16 mac_addr_size;
3009 u32 mac_id;
3010
3011 mac_entry = &resp->macaddr_list[i];
3012 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
3013 /* mac_id is a 32 bit value and mac_addr size
3014 * is 6 bytes
3015 */
3016 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05303017 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003018 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
3019 *pmac_id = le32_to_cpu(mac_id);
3020 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003021 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003022 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003023 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05303024 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003025 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303026 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003027 }
3028
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003029out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003030 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003031 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303032 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003033 return status;
3034}
3035
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303036int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id,
3037 u8 *mac, u32 if_handle, bool active, u32 domain)
Sathya Perla5a712c12013-07-23 15:24:59 +05303038{
Suresh Reddyb188f092014-01-15 13:23:39 +05303039 if (!active)
3040 be_cmd_get_mac_from_list(adapter, mac, &active, &curr_pmac_id,
3041 if_handle, domain);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303042 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05303043 return be_cmd_mac_addr_query(adapter, mac, false,
Suresh Reddyb188f092014-01-15 13:23:39 +05303044 if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303045 else
3046 /* Fetch the MAC address using pmac_id */
3047 return be_cmd_get_mac_from_list(adapter, mac, &active,
Suresh Reddyb188f092014-01-15 13:23:39 +05303048 &curr_pmac_id,
3049 if_handle, domain);
Sathya Perla5a712c12013-07-23 15:24:59 +05303050}
3051
Sathya Perla95046b92013-07-23 15:25:02 +05303052int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
3053{
3054 int status;
3055 bool pmac_valid = false;
3056
3057 memset(mac, 0, ETH_ALEN);
3058
Sathya Perla3175d8c2013-07-23 15:25:03 +05303059 if (BEx_chip(adapter)) {
3060 if (be_physfn(adapter))
3061 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
3062 0);
3063 else
3064 status = be_cmd_mac_addr_query(adapter, mac, false,
3065 adapter->if_handle, 0);
3066 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05303067 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
Suresh Reddyb188f092014-01-15 13:23:39 +05303068 NULL, adapter->if_handle, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303069 }
3070
Sathya Perla95046b92013-07-23 15:25:02 +05303071 return status;
3072}
3073
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003074/* Uses synchronous MCCQ */
3075int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
3076 u8 mac_count, u32 domain)
3077{
3078 struct be_mcc_wrb *wrb;
3079 struct be_cmd_req_set_mac_list *req;
3080 int status;
3081 struct be_dma_mem cmd;
3082
3083 memset(&cmd, 0, sizeof(struct be_dma_mem));
3084 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
3085 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303086 &cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00003087 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003088 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003089
3090 spin_lock_bh(&adapter->mcc_lock);
3091
3092 wrb = wrb_from_mccq(adapter);
3093 if (!wrb) {
3094 status = -EBUSY;
3095 goto err;
3096 }
3097
3098 req = cmd.va;
3099 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303100 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
3101 wrb, &cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003102
3103 req->hdr.domain = domain;
3104 req->mac_count = mac_count;
3105 if (mac_count)
3106 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
3107
3108 status = be_mcc_notify_wait(adapter);
3109
3110err:
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303111 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003112 spin_unlock_bh(&adapter->mcc_lock);
3113 return status;
3114}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003115
Sathya Perla3175d8c2013-07-23 15:25:03 +05303116/* Wrapper to delete any active MACs and provision the new mac.
3117 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
3118 * current list are active.
3119 */
3120int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
3121{
3122 bool active_mac = false;
3123 u8 old_mac[ETH_ALEN];
3124 u32 pmac_id;
3125 int status;
3126
3127 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303128 &pmac_id, if_id, dom);
3129
Sathya Perla3175d8c2013-07-23 15:25:03 +05303130 if (!status && active_mac)
3131 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
3132
3133 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
3134}
3135
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003136int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003137 u32 domain, u16 intf_id, u16 hsw_mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003138{
3139 struct be_mcc_wrb *wrb;
3140 struct be_cmd_req_set_hsw_config *req;
3141 void *ctxt;
3142 int status;
3143
3144 spin_lock_bh(&adapter->mcc_lock);
3145
3146 wrb = wrb_from_mccq(adapter);
3147 if (!wrb) {
3148 status = -EBUSY;
3149 goto err;
3150 }
3151
3152 req = embedded_payload(wrb);
3153 ctxt = &req->context;
3154
3155 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303156 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb,
3157 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003158
3159 req->hdr.domain = domain;
3160 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
3161 if (pvid) {
3162 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
3163 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
3164 }
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003165 if (!BEx_chip(adapter) && hsw_mode) {
3166 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id,
3167 ctxt, adapter->hba_port_num);
3168 AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1);
3169 AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type,
3170 ctxt, hsw_mode);
3171 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003172
3173 be_dws_cpu_to_le(req->context, sizeof(req->context));
3174 status = be_mcc_notify_wait(adapter);
3175
3176err:
3177 spin_unlock_bh(&adapter->mcc_lock);
3178 return status;
3179}
3180
3181/* Get Hyper switch config */
3182int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003183 u32 domain, u16 intf_id, u8 *mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003184{
3185 struct be_mcc_wrb *wrb;
3186 struct be_cmd_req_get_hsw_config *req;
3187 void *ctxt;
3188 int status;
3189 u16 vid;
3190
3191 spin_lock_bh(&adapter->mcc_lock);
3192
3193 wrb = wrb_from_mccq(adapter);
3194 if (!wrb) {
3195 status = -EBUSY;
3196 goto err;
3197 }
3198
3199 req = embedded_payload(wrb);
3200 ctxt = &req->context;
3201
3202 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303203 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb,
3204 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003205
3206 req->hdr.domain = domain;
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003207 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3208 ctxt, intf_id);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003209 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003210
Vasundhara Volam2c07c1d2014-01-15 13:23:32 +05303211 if (!BEx_chip(adapter) && mode) {
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003212 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3213 ctxt, adapter->hba_port_num);
3214 AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1);
3215 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003216 be_dws_cpu_to_le(req->context, sizeof(req->context));
3217
3218 status = be_mcc_notify_wait(adapter);
3219 if (!status) {
3220 struct be_cmd_resp_get_hsw_config *resp =
3221 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303222
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303223 be_dws_le_to_cpu(&resp->context, sizeof(resp->context));
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003224 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303225 pvid, &resp->context);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003226 if (pvid)
3227 *pvid = le16_to_cpu(vid);
3228 if (mode)
3229 *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3230 port_fwd_type, &resp->context);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003231 }
3232
3233err:
3234 spin_unlock_bh(&adapter->mcc_lock);
3235 return status;
3236}
3237
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003238int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
3239{
3240 struct be_mcc_wrb *wrb;
3241 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303242 int status = 0;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003243 struct be_dma_mem cmd;
3244
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003245 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
3246 CMD_SUBSYSTEM_ETH))
3247 return -EPERM;
3248
Suresh Reddy76a9e082014-01-15 13:23:40 +05303249 if (be_is_wol_excluded(adapter))
3250 return status;
3251
Suresh Reddyd98ef502013-04-25 00:56:55 +00003252 if (mutex_lock_interruptible(&adapter->mbox_lock))
3253 return -1;
3254
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003255 memset(&cmd, 0, sizeof(struct be_dma_mem));
3256 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303257 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003258 if (!cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303259 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003260 status = -ENOMEM;
3261 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003262 }
3263
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003264 wrb = wrb_from_mbox(adapter);
3265 if (!wrb) {
3266 status = -EBUSY;
3267 goto err;
3268 }
3269
3270 req = cmd.va;
3271
3272 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
3273 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
Suresh Reddy76a9e082014-01-15 13:23:40 +05303274 sizeof(*req), wrb, &cmd);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003275
3276 req->hdr.version = 1;
3277 req->query_options = BE_GET_WOL_CAP;
3278
3279 status = be_mbox_notify_wait(adapter);
3280 if (!status) {
3281 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05303282
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003283 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
3284
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003285 adapter->wol_cap = resp->wol_settings;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303286 if (adapter->wol_cap & BE_WOL_CAP)
3287 adapter->wol_en = true;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003288 }
3289err:
3290 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003291 if (cmd.va)
3292 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003293 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00003294
3295}
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303296
3297int be_cmd_set_fw_log_level(struct be_adapter *adapter, u32 level)
3298{
3299 struct be_dma_mem extfat_cmd;
3300 struct be_fat_conf_params *cfgs;
3301 int status;
3302 int i, j;
3303
3304 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3305 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
3306 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
3307 &extfat_cmd.dma);
3308 if (!extfat_cmd.va)
3309 return -ENOMEM;
3310
3311 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3312 if (status)
3313 goto err;
3314
3315 cfgs = (struct be_fat_conf_params *)
3316 (extfat_cmd.va + sizeof(struct be_cmd_resp_hdr));
3317 for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
3318 u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303319
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303320 for (j = 0; j < num_modes; j++) {
3321 if (cfgs->module[i].trace_lvl[j].mode == MODE_UART)
3322 cfgs->module[i].trace_lvl[j].dbg_lvl =
3323 cpu_to_le32(level);
3324 }
3325 }
3326
3327 status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd, cfgs);
3328err:
3329 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
3330 extfat_cmd.dma);
3331 return status;
3332}
3333
3334int be_cmd_get_fw_log_level(struct be_adapter *adapter)
3335{
3336 struct be_dma_mem extfat_cmd;
3337 struct be_fat_conf_params *cfgs;
3338 int status, j;
3339 int level = 0;
3340
3341 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3342 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
3343 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
3344 &extfat_cmd.dma);
3345
3346 if (!extfat_cmd.va) {
3347 dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
3348 __func__);
3349 goto err;
3350 }
3351
3352 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3353 if (!status) {
3354 cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
3355 sizeof(struct be_cmd_resp_hdr));
Kalesh AP03d28ff2014-09-19 15:46:56 +05303356
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303357 for (j = 0; j < le32_to_cpu(cfgs->module[0].num_modes); j++) {
3358 if (cfgs->module[0].trace_lvl[j].mode == MODE_UART)
3359 level = cfgs->module[0].trace_lvl[j].dbg_lvl;
3360 }
3361 }
3362 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
3363 extfat_cmd.dma);
3364err:
3365 return level;
3366}
3367
Somnath Kotur941a77d2012-05-17 22:59:03 +00003368int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
3369 struct be_dma_mem *cmd)
3370{
3371 struct be_mcc_wrb *wrb;
3372 struct be_cmd_req_get_ext_fat_caps *req;
3373 int status;
3374
3375 if (mutex_lock_interruptible(&adapter->mbox_lock))
3376 return -1;
3377
3378 wrb = wrb_from_mbox(adapter);
3379 if (!wrb) {
3380 status = -EBUSY;
3381 goto err;
3382 }
3383
3384 req = cmd->va;
3385 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3386 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
3387 cmd->size, wrb, cmd);
3388 req->parameter_type = cpu_to_le32(1);
3389
3390 status = be_mbox_notify_wait(adapter);
3391err:
3392 mutex_unlock(&adapter->mbox_lock);
3393 return status;
3394}
3395
3396int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
3397 struct be_dma_mem *cmd,
3398 struct be_fat_conf_params *configs)
3399{
3400 struct be_mcc_wrb *wrb;
3401 struct be_cmd_req_set_ext_fat_caps *req;
3402 int status;
3403
3404 spin_lock_bh(&adapter->mcc_lock);
3405
3406 wrb = wrb_from_mccq(adapter);
3407 if (!wrb) {
3408 status = -EBUSY;
3409 goto err;
3410 }
3411
3412 req = cmd->va;
3413 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
3414 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3415 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
3416 cmd->size, wrb, cmd);
3417
3418 status = be_mcc_notify_wait(adapter);
3419err:
3420 spin_unlock_bh(&adapter->mcc_lock);
3421 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003422}
Parav Pandit6a4ab662012-03-26 14:27:12 +00003423
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003424int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
3425{
3426 struct be_mcc_wrb *wrb;
3427 struct be_cmd_req_get_port_name *req;
3428 int status;
3429
3430 if (!lancer_chip(adapter)) {
3431 *port_name = adapter->hba_port_num + '0';
3432 return 0;
3433 }
3434
3435 spin_lock_bh(&adapter->mcc_lock);
3436
3437 wrb = wrb_from_mccq(adapter);
3438 if (!wrb) {
3439 status = -EBUSY;
3440 goto err;
3441 }
3442
3443 req = embedded_payload(wrb);
3444
3445 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3446 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
3447 NULL);
3448 req->hdr.version = 1;
3449
3450 status = be_mcc_notify_wait(adapter);
3451 if (!status) {
3452 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303453
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003454 *port_name = resp->port_name[adapter->hba_port_num];
3455 } else {
3456 *port_name = adapter->hba_port_num + '0';
3457 }
3458err:
3459 spin_unlock_bh(&adapter->mcc_lock);
3460 return status;
3461}
3462
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303463/* Descriptor type */
3464enum {
3465 FUNC_DESC = 1,
3466 VFT_DESC = 2
3467};
3468
3469static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
3470 int desc_type)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003471{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303472 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303473 struct be_nic_res_desc *nic;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003474 int i;
3475
3476 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303477 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303478 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) {
3479 nic = (struct be_nic_res_desc *)hdr;
3480 if (desc_type == FUNC_DESC ||
3481 (desc_type == VFT_DESC &&
3482 nic->flags & (1 << VFT_SHIFT)))
3483 return nic;
3484 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003485
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303486 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3487 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003488 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303489 return NULL;
3490}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003491
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303492static struct be_nic_res_desc *be_get_vft_desc(u8 *buf, u32 desc_count)
3493{
3494 return be_get_nic_desc(buf, desc_count, VFT_DESC);
3495}
3496
3497static struct be_nic_res_desc *be_get_func_nic_desc(u8 *buf, u32 desc_count)
3498{
3499 return be_get_nic_desc(buf, desc_count, FUNC_DESC);
3500}
3501
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303502static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3503 u32 desc_count)
3504{
3505 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3506 struct be_pcie_res_desc *pcie;
3507 int i;
3508
3509 for (i = 0; i < desc_count; i++) {
3510 if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
3511 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) {
3512 pcie = (struct be_pcie_res_desc *)hdr;
3513 if (pcie->pf_num == devfn)
3514 return pcie;
3515 }
3516
3517 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3518 hdr = (void *)hdr + hdr->desc_len;
3519 }
Wei Yang950e2952013-05-22 15:58:22 +00003520 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003521}
3522
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303523static struct be_port_res_desc *be_get_port_desc(u8 *buf, u32 desc_count)
3524{
3525 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3526 int i;
3527
3528 for (i = 0; i < desc_count; i++) {
3529 if (hdr->desc_type == PORT_RESOURCE_DESC_TYPE_V1)
3530 return (struct be_port_res_desc *)hdr;
3531
3532 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3533 hdr = (void *)hdr + hdr->desc_len;
3534 }
3535 return NULL;
3536}
3537
Sathya Perla92bf14a2013-08-27 16:57:32 +05303538static void be_copy_nic_desc(struct be_resources *res,
3539 struct be_nic_res_desc *desc)
3540{
3541 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3542 res->max_vlans = le16_to_cpu(desc->vlan_count);
3543 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3544 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3545 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3546 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3547 res->max_evt_qs = le16_to_cpu(desc->eq_count);
3548 /* Clear flags that driver is not interested in */
3549 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3550 BE_IF_CAP_FLAGS_WANT;
3551 /* Need 1 RXQ as the default RXQ */
3552 if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs)
3553 res->max_rss_qs -= 1;
3554}
3555
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003556/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303557int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003558{
3559 struct be_mcc_wrb *wrb;
3560 struct be_cmd_req_get_func_config *req;
3561 int status;
3562 struct be_dma_mem cmd;
3563
Suresh Reddyd98ef502013-04-25 00:56:55 +00003564 if (mutex_lock_interruptible(&adapter->mbox_lock))
3565 return -1;
3566
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003567 memset(&cmd, 0, sizeof(struct be_dma_mem));
3568 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303569 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003570 if (!cmd.va) {
3571 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003572 status = -ENOMEM;
3573 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003574 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003575
3576 wrb = wrb_from_mbox(adapter);
3577 if (!wrb) {
3578 status = -EBUSY;
3579 goto err;
3580 }
3581
3582 req = cmd.va;
3583
3584 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3585 OPCODE_COMMON_GET_FUNC_CONFIG,
3586 cmd.size, wrb, &cmd);
3587
Kalesh AP28710c52013-04-28 22:21:13 +00003588 if (skyhawk_chip(adapter))
3589 req->hdr.version = 1;
3590
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003591 status = be_mbox_notify_wait(adapter);
3592 if (!status) {
3593 struct be_cmd_resp_get_func_config *resp = cmd.va;
3594 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303595 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003596
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303597 desc = be_get_func_nic_desc(resp->func_param, desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003598 if (!desc) {
3599 status = -EINVAL;
3600 goto err;
3601 }
3602
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003603 adapter->pf_number = desc->pf_num;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303604 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003605 }
3606err:
3607 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003608 if (cmd.va)
3609 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003610 return status;
3611}
3612
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303613/* Will use MBOX only if MCCQ has not been created */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303614int be_cmd_get_profile_config(struct be_adapter *adapter,
3615 struct be_resources *res, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003616{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303617 struct be_cmd_resp_get_profile_config *resp;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303618 struct be_cmd_req_get_profile_config *req;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303619 struct be_nic_res_desc *vf_res;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303620 struct be_pcie_res_desc *pcie;
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303621 struct be_port_res_desc *port;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303622 struct be_nic_res_desc *nic;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303623 struct be_mcc_wrb wrb = {0};
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003624 struct be_dma_mem cmd;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303625 u32 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003626 int status;
3627
3628 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303629 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3630 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3631 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003632 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003633
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303634 req = cmd.va;
3635 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3636 OPCODE_COMMON_GET_PROFILE_CONFIG,
3637 cmd.size, &wrb, &cmd);
3638
3639 req->hdr.domain = domain;
3640 if (!lancer_chip(adapter))
3641 req->hdr.version = 1;
3642 req->type = ACTIVE_PROFILE_TYPE;
3643
3644 status = be_cmd_notify_wait(adapter, &wrb);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303645 if (status)
3646 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003647
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303648 resp = cmd.va;
3649 desc_count = le32_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003650
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303651 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3652 desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303653 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303654 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303655
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303656 port = be_get_port_desc(resp->func_param, desc_count);
3657 if (port)
3658 adapter->mc_type = port->mc_type;
3659
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303660 nic = be_get_func_nic_desc(resp->func_param, desc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303661 if (nic)
3662 be_copy_nic_desc(res, nic);
3663
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303664 vf_res = be_get_vft_desc(resp->func_param, desc_count);
3665 if (vf_res)
3666 res->vf_if_cap_flags = vf_res->cap_flags;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003667err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003668 if (cmd.va)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303669 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003670 return status;
3671}
3672
Vasundhara Volambec84e62014-06-30 13:01:32 +05303673/* Will use MBOX only if MCCQ has not been created */
3674static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc,
3675 int size, int count, u8 version, u8 domain)
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003676{
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003677 struct be_cmd_req_set_profile_config *req;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303678 struct be_mcc_wrb wrb = {0};
3679 struct be_dma_mem cmd;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003680 int status;
3681
Vasundhara Volambec84e62014-06-30 13:01:32 +05303682 memset(&cmd, 0, sizeof(struct be_dma_mem));
3683 cmd.size = sizeof(struct be_cmd_req_set_profile_config);
3684 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3685 if (!cmd.va)
3686 return -ENOMEM;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003687
Vasundhara Volambec84e62014-06-30 13:01:32 +05303688 req = cmd.va;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003689 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303690 OPCODE_COMMON_SET_PROFILE_CONFIG, cmd.size,
3691 &wrb, &cmd);
Sathya Perlaa4018012014-03-27 10:46:18 +05303692 req->hdr.version = version;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003693 req->hdr.domain = domain;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303694 req->desc_count = cpu_to_le32(count);
Sathya Perlaa4018012014-03-27 10:46:18 +05303695 memcpy(req->desc, desc, size);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003696
Vasundhara Volambec84e62014-06-30 13:01:32 +05303697 status = be_cmd_notify_wait(adapter, &wrb);
3698
3699 if (cmd.va)
3700 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003701 return status;
3702}
3703
Sathya Perlaa4018012014-03-27 10:46:18 +05303704/* Mark all fields invalid */
Vasundhara Volambec84e62014-06-30 13:01:32 +05303705static void be_reset_nic_desc(struct be_nic_res_desc *nic)
Sathya Perlaa4018012014-03-27 10:46:18 +05303706{
3707 memset(nic, 0, sizeof(*nic));
3708 nic->unicast_mac_count = 0xFFFF;
3709 nic->mcc_count = 0xFFFF;
3710 nic->vlan_count = 0xFFFF;
3711 nic->mcast_mac_count = 0xFFFF;
3712 nic->txq_count = 0xFFFF;
3713 nic->rq_count = 0xFFFF;
3714 nic->rssq_count = 0xFFFF;
3715 nic->lro_count = 0xFFFF;
3716 nic->cq_count = 0xFFFF;
3717 nic->toe_conn_count = 0xFFFF;
3718 nic->eq_count = 0xFFFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303719 nic->iface_count = 0xFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303720 nic->link_param = 0xFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303721 nic->channel_id_param = cpu_to_le16(0xF000);
Sathya Perlaa4018012014-03-27 10:46:18 +05303722 nic->acpi_params = 0xFF;
3723 nic->wol_param = 0x0F;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303724 nic->tunnel_iface_count = 0xFFFF;
3725 nic->direct_tenant_iface_count = 0xFFFF;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303726 nic->bw_min = 0xFFFFFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303727 nic->bw_max = 0xFFFFFFFF;
3728}
3729
Vasundhara Volambec84e62014-06-30 13:01:32 +05303730/* Mark all fields invalid */
3731static void be_reset_pcie_desc(struct be_pcie_res_desc *pcie)
3732{
3733 memset(pcie, 0, sizeof(*pcie));
3734 pcie->sriov_state = 0xFF;
3735 pcie->pf_state = 0xFF;
3736 pcie->pf_type = 0xFF;
3737 pcie->num_vfs = 0xFFFF;
3738}
3739
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303740int be_cmd_config_qos(struct be_adapter *adapter, u32 max_rate, u16 link_speed,
3741 u8 domain)
Sathya Perlaa4018012014-03-27 10:46:18 +05303742{
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303743 struct be_nic_res_desc nic_desc;
3744 u32 bw_percent;
3745 u16 version = 0;
Sathya Perlaa4018012014-03-27 10:46:18 +05303746
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303747 if (BE3_chip(adapter))
3748 return be_cmd_set_qos(adapter, max_rate / 10, domain);
3749
3750 be_reset_nic_desc(&nic_desc);
3751 nic_desc.pf_num = adapter->pf_number;
3752 nic_desc.vf_num = domain;
3753 if (lancer_chip(adapter)) {
Sathya Perlaa4018012014-03-27 10:46:18 +05303754 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
3755 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
3756 nic_desc.flags = (1 << QUN_SHIFT) | (1 << IMM_SHIFT) |
3757 (1 << NOSV_SHIFT);
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303758 nic_desc.bw_max = cpu_to_le32(max_rate / 10);
Sathya Perlaa4018012014-03-27 10:46:18 +05303759 } else {
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303760 version = 1;
3761 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3762 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3763 nic_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3764 bw_percent = max_rate ? (max_rate * 100) / link_speed : 100;
3765 nic_desc.bw_max = cpu_to_le32(bw_percent);
Sathya Perlaa4018012014-03-27 10:46:18 +05303766 }
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303767
3768 return be_cmd_set_profile_config(adapter, &nic_desc,
3769 nic_desc.hdr.desc_len,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303770 1, version, domain);
3771}
3772
3773int be_cmd_set_sriov_config(struct be_adapter *adapter,
3774 struct be_resources res, u16 num_vfs)
3775{
3776 struct {
3777 struct be_pcie_res_desc pcie;
3778 struct be_nic_res_desc nic_vft;
3779 } __packed desc;
3780 u16 vf_q_count;
3781
3782 if (BEx_chip(adapter) || lancer_chip(adapter))
3783 return 0;
3784
3785 /* PF PCIE descriptor */
3786 be_reset_pcie_desc(&desc.pcie);
3787 desc.pcie.hdr.desc_type = PCIE_RESOURCE_DESC_TYPE_V1;
3788 desc.pcie.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3789 desc.pcie.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3790 desc.pcie.pf_num = adapter->pdev->devfn;
3791 desc.pcie.sriov_state = num_vfs ? 1 : 0;
3792 desc.pcie.num_vfs = cpu_to_le16(num_vfs);
3793
3794 /* VF NIC Template descriptor */
3795 be_reset_nic_desc(&desc.nic_vft);
3796 desc.nic_vft.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3797 desc.nic_vft.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3798 desc.nic_vft.flags = (1 << VFT_SHIFT) | (1 << IMM_SHIFT) |
3799 (1 << NOSV_SHIFT);
3800 desc.nic_vft.pf_num = adapter->pdev->devfn;
3801 desc.nic_vft.vf_num = 0;
3802
3803 if (num_vfs && res.vf_if_cap_flags & BE_IF_FLAGS_RSS) {
3804 /* If number of VFs requested is 8 less than max supported,
3805 * assign 8 queue pairs to the PF and divide the remaining
3806 * resources evenly among the VFs
3807 */
3808 if (num_vfs < (be_max_vfs(adapter) - 8))
3809 vf_q_count = (res.max_rss_qs - 8) / num_vfs;
3810 else
3811 vf_q_count = res.max_rss_qs / num_vfs;
3812
3813 desc.nic_vft.rq_count = cpu_to_le16(vf_q_count);
3814 desc.nic_vft.txq_count = cpu_to_le16(vf_q_count);
3815 desc.nic_vft.rssq_count = cpu_to_le16(vf_q_count - 1);
3816 desc.nic_vft.cq_count = cpu_to_le16(3 * vf_q_count);
3817 } else {
3818 desc.nic_vft.txq_count = cpu_to_le16(1);
3819 desc.nic_vft.rq_count = cpu_to_le16(1);
3820 desc.nic_vft.rssq_count = cpu_to_le16(0);
3821 /* One CQ for each TX, RX and MCCQ */
3822 desc.nic_vft.cq_count = cpu_to_le16(3);
3823 }
3824
3825 return be_cmd_set_profile_config(adapter, &desc,
3826 2 * RESOURCE_DESC_SIZE_V1, 2, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303827}
3828
3829int be_cmd_manage_iface(struct be_adapter *adapter, u32 iface, u8 op)
3830{
3831 struct be_mcc_wrb *wrb;
3832 struct be_cmd_req_manage_iface_filters *req;
3833 int status;
3834
3835 if (iface == 0xFFFFFFFF)
3836 return -1;
3837
3838 spin_lock_bh(&adapter->mcc_lock);
3839
3840 wrb = wrb_from_mccq(adapter);
3841 if (!wrb) {
3842 status = -EBUSY;
3843 goto err;
3844 }
3845 req = embedded_payload(wrb);
3846
3847 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3848 OPCODE_COMMON_MANAGE_IFACE_FILTERS, sizeof(*req),
3849 wrb, NULL);
3850 req->op = op;
3851 req->target_iface_id = cpu_to_le32(iface);
3852
3853 status = be_mcc_notify_wait(adapter);
3854err:
3855 spin_unlock_bh(&adapter->mcc_lock);
3856 return status;
3857}
3858
3859int be_cmd_set_vxlan_port(struct be_adapter *adapter, __be16 port)
3860{
3861 struct be_port_res_desc port_desc;
3862
3863 memset(&port_desc, 0, sizeof(port_desc));
3864 port_desc.hdr.desc_type = PORT_RESOURCE_DESC_TYPE_V1;
3865 port_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3866 port_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3867 port_desc.link_num = adapter->hba_port_num;
3868 if (port) {
3869 port_desc.nv_flags = NV_TYPE_VXLAN | (1 << SOCVID_SHIFT) |
3870 (1 << RCVID_SHIFT);
3871 port_desc.nv_port = swab16(port);
3872 } else {
3873 port_desc.nv_flags = NV_TYPE_DISABLED;
3874 port_desc.nv_port = 0;
3875 }
3876
3877 return be_cmd_set_profile_config(adapter, &port_desc,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303878 RESOURCE_DESC_SIZE_V1, 1, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303879}
3880
Sathya Perla4c876612013-02-03 20:30:11 +00003881int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3882 int vf_num)
3883{
3884 struct be_mcc_wrb *wrb;
3885 struct be_cmd_req_get_iface_list *req;
3886 struct be_cmd_resp_get_iface_list *resp;
3887 int status;
3888
3889 spin_lock_bh(&adapter->mcc_lock);
3890
3891 wrb = wrb_from_mccq(adapter);
3892 if (!wrb) {
3893 status = -EBUSY;
3894 goto err;
3895 }
3896 req = embedded_payload(wrb);
3897
3898 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3899 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3900 wrb, NULL);
3901 req->hdr.domain = vf_num + 1;
3902
3903 status = be_mcc_notify_wait(adapter);
3904 if (!status) {
3905 resp = (struct be_cmd_resp_get_iface_list *)req;
3906 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3907 }
3908
3909err:
3910 spin_unlock_bh(&adapter->mcc_lock);
3911 return status;
3912}
3913
Somnath Kotur5c510812013-05-30 02:52:23 +00003914static int lancer_wait_idle(struct be_adapter *adapter)
3915{
3916#define SLIPORT_IDLE_TIMEOUT 30
3917 u32 reg_val;
3918 int status = 0, i;
3919
3920 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
3921 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
3922 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
3923 break;
3924
3925 ssleep(1);
3926 }
3927
3928 if (i == SLIPORT_IDLE_TIMEOUT)
3929 status = -1;
3930
3931 return status;
3932}
3933
3934int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
3935{
3936 int status = 0;
3937
3938 status = lancer_wait_idle(adapter);
3939 if (status)
3940 return status;
3941
3942 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
3943
3944 return status;
3945}
3946
3947/* Routine to check whether dump image is present or not */
3948bool dump_present(struct be_adapter *adapter)
3949{
3950 u32 sliport_status = 0;
3951
3952 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
3953 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
3954}
3955
3956int lancer_initiate_dump(struct be_adapter *adapter)
3957{
Kalesh APf0613382014-08-01 17:47:32 +05303958 struct device *dev = &adapter->pdev->dev;
Somnath Kotur5c510812013-05-30 02:52:23 +00003959 int status;
3960
Kalesh APf0613382014-08-01 17:47:32 +05303961 if (dump_present(adapter)) {
3962 dev_info(dev, "Previous dump not cleared, not forcing dump\n");
3963 return -EEXIST;
3964 }
3965
Somnath Kotur5c510812013-05-30 02:52:23 +00003966 /* give firmware reset and diagnostic dump */
3967 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
3968 PHYSDEV_CONTROL_DD_MASK);
3969 if (status < 0) {
Kalesh APf0613382014-08-01 17:47:32 +05303970 dev_err(dev, "FW reset failed\n");
Somnath Kotur5c510812013-05-30 02:52:23 +00003971 return status;
3972 }
3973
3974 status = lancer_wait_idle(adapter);
3975 if (status)
3976 return status;
3977
3978 if (!dump_present(adapter)) {
Kalesh APf0613382014-08-01 17:47:32 +05303979 dev_err(dev, "FW dump not generated\n");
3980 return -EIO;
Somnath Kotur5c510812013-05-30 02:52:23 +00003981 }
3982
3983 return 0;
3984}
3985
Kalesh APf0613382014-08-01 17:47:32 +05303986int lancer_delete_dump(struct be_adapter *adapter)
3987{
3988 int status;
3989
3990 status = lancer_cmd_delete_object(adapter, LANCER_FW_DUMP_FILE);
3991 return be_cmd_status(status);
3992}
3993
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003994/* Uses sync mcc */
3995int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
3996{
3997 struct be_mcc_wrb *wrb;
3998 struct be_cmd_enable_disable_vf *req;
3999 int status;
4000
Vasundhara Volam05998632013-10-01 15:59:59 +05304001 if (BEx_chip(adapter))
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004002 return 0;
4003
4004 spin_lock_bh(&adapter->mcc_lock);
4005
4006 wrb = wrb_from_mccq(adapter);
4007 if (!wrb) {
4008 status = -EBUSY;
4009 goto err;
4010 }
4011
4012 req = embedded_payload(wrb);
4013
4014 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4015 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
4016 wrb, NULL);
4017
4018 req->hdr.domain = domain;
4019 req->enable = 1;
4020 status = be_mcc_notify_wait(adapter);
4021err:
4022 spin_unlock_bh(&adapter->mcc_lock);
4023 return status;
4024}
4025
Somnath Kotur68c45a22013-03-14 02:42:07 +00004026int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
4027{
4028 struct be_mcc_wrb *wrb;
4029 struct be_cmd_req_intr_set *req;
4030 int status;
4031
4032 if (mutex_lock_interruptible(&adapter->mbox_lock))
4033 return -1;
4034
4035 wrb = wrb_from_mbox(adapter);
4036
4037 req = embedded_payload(wrb);
4038
4039 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4040 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
4041 wrb, NULL);
4042
4043 req->intr_enabled = intr_enable;
4044
4045 status = be_mbox_notify_wait(adapter);
4046
4047 mutex_unlock(&adapter->mbox_lock);
4048 return status;
4049}
4050
Vasundhara Volam542963b2014-01-15 13:23:33 +05304051/* Uses MBOX */
4052int be_cmd_get_active_profile(struct be_adapter *adapter, u16 *profile_id)
4053{
4054 struct be_cmd_req_get_active_profile *req;
4055 struct be_mcc_wrb *wrb;
4056 int status;
4057
4058 if (mutex_lock_interruptible(&adapter->mbox_lock))
4059 return -1;
4060
4061 wrb = wrb_from_mbox(adapter);
4062 if (!wrb) {
4063 status = -EBUSY;
4064 goto err;
4065 }
4066
4067 req = embedded_payload(wrb);
4068
4069 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4070 OPCODE_COMMON_GET_ACTIVE_PROFILE, sizeof(*req),
4071 wrb, NULL);
4072
4073 status = be_mbox_notify_wait(adapter);
4074 if (!status) {
4075 struct be_cmd_resp_get_active_profile *resp =
4076 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304077
Vasundhara Volam542963b2014-01-15 13:23:33 +05304078 *profile_id = le16_to_cpu(resp->active_profile_id);
4079 }
4080
4081err:
4082 mutex_unlock(&adapter->mbox_lock);
4083 return status;
4084}
4085
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304086int be_cmd_set_logical_link_config(struct be_adapter *adapter,
4087 int link_state, u8 domain)
4088{
4089 struct be_mcc_wrb *wrb;
4090 struct be_cmd_req_set_ll_link *req;
4091 int status;
4092
4093 if (BEx_chip(adapter) || lancer_chip(adapter))
4094 return 0;
4095
4096 spin_lock_bh(&adapter->mcc_lock);
4097
4098 wrb = wrb_from_mccq(adapter);
4099 if (!wrb) {
4100 status = -EBUSY;
4101 goto err;
4102 }
4103
4104 req = embedded_payload(wrb);
4105
4106 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4107 OPCODE_COMMON_SET_LOGICAL_LINK_CONFIG,
4108 sizeof(*req), wrb, NULL);
4109
4110 req->hdr.version = 1;
4111 req->hdr.domain = domain;
4112
4113 if (link_state == IFLA_VF_LINK_STATE_ENABLE)
4114 req->link_config |= 1;
4115
4116 if (link_state == IFLA_VF_LINK_STATE_AUTO)
4117 req->link_config |= 1 << PLINK_TRACK_SHIFT;
4118
4119 status = be_mcc_notify_wait(adapter);
4120err:
4121 spin_unlock_bh(&adapter->mcc_lock);
4122 return status;
4123}
4124
Parav Pandit6a4ab662012-03-26 14:27:12 +00004125int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05304126 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
Parav Pandit6a4ab662012-03-26 14:27:12 +00004127{
4128 struct be_adapter *adapter = netdev_priv(netdev_handle);
4129 struct be_mcc_wrb *wrb;
4130 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
4131 struct be_cmd_req_hdr *req;
4132 struct be_cmd_resp_hdr *resp;
4133 int status;
4134
4135 spin_lock_bh(&adapter->mcc_lock);
4136
4137 wrb = wrb_from_mccq(adapter);
4138 if (!wrb) {
4139 status = -EBUSY;
4140 goto err;
4141 }
4142 req = embedded_payload(wrb);
4143 resp = embedded_payload(wrb);
4144
4145 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
4146 hdr->opcode, wrb_payload_size, wrb, NULL);
4147 memcpy(req, wrb_payload, wrb_payload_size);
4148 be_dws_cpu_to_le(req, wrb_payload_size);
4149
4150 status = be_mcc_notify_wait(adapter);
4151 if (cmd_status)
4152 *cmd_status = (status & 0xffff);
4153 if (ext_status)
4154 *ext_status = 0;
4155 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
4156 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
4157err:
4158 spin_unlock_bh(&adapter->mcc_lock);
4159 return status;
4160}
4161EXPORT_SYMBOL(be_roce_mcc_cmd);