blob: 8dd4975e7b2243a57a67ef406e874376fac8f893 [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)) {
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +0530212
Kalesh AP4c600052014-05-30 19:06:26 +0530213 if (base_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000214 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000215 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000216 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000217 } else {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000218 dev_err(&adapter->pdev->dev,
219 "opcode %d-%d failed:status %d-%d\n",
Kalesh AP4c600052014-05-30 19:06:26 +0530220 opcode, subsystem, base_status, addl_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000221 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000222 }
Kalesh AP4c600052014-05-30 19:06:26 +0530223 return compl->status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000224}
225
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000226/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000227static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530228 struct be_mcc_compl *compl)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000229{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530230 struct be_async_event_link_state *evt =
231 (struct be_async_event_link_state *)compl;
232
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000233 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000234 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000235
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530236 /* On BEx the FW does not send a separate link status
237 * notification for physical and logical link.
238 * On other chips just process the logical link
239 * status notification
240 */
241 if (!BEx_chip(adapter) &&
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000242 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
243 return;
244
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000245 /* For the initial link status do not rely on the ASYNC event as
246 * it may not be received in some cases.
247 */
248 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530249 be_link_status_update(adapter,
250 evt->port_link_status & LINK_STATUS_MASK);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000251}
252
Somnath Koturcc4ce022010-10-21 07:11:14 -0700253/* Grp5 CoS Priority evt */
254static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530255 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700256{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530257 struct be_async_event_grp5_cos_priority *evt =
258 (struct be_async_event_grp5_cos_priority *)compl;
259
Somnath Koturcc4ce022010-10-21 07:11:14 -0700260 if (evt->valid) {
261 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000262 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700263 adapter->recommended_prio =
264 evt->reco_default_priority << VLAN_PRIO_SHIFT;
265 }
266}
267
Sathya Perla323ff712012-09-28 04:39:43 +0000268/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700269static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530270 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700271{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530272 struct be_async_event_grp5_qos_link_speed *evt =
273 (struct be_async_event_grp5_qos_link_speed *)compl;
274
Sathya Perla323ff712012-09-28 04:39:43 +0000275 if (adapter->phy.link_speed >= 0 &&
276 evt->physical_port == adapter->port_num)
277 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700278}
279
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000280/*Grp5 PVID evt*/
281static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530282 struct be_mcc_compl *compl)
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000283{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530284 struct be_async_event_grp5_pvid_state *evt =
285 (struct be_async_event_grp5_pvid_state *)compl;
286
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530287 if (evt->enabled) {
Somnath Kotur939cf302011-08-18 21:51:49 -0700288 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530289 dev_info(&adapter->pdev->dev, "LPVID: %d\n", adapter->pvid);
290 } else {
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000291 adapter->pvid = 0;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530292 }
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000293}
294
Somnath Koturcc4ce022010-10-21 07:11:14 -0700295static void be_async_grp5_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530296 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700297{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530298 u8 event_type = (compl->flags >> ASYNC_EVENT_TYPE_SHIFT) &
299 ASYNC_EVENT_TYPE_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700300
301 switch (event_type) {
302 case ASYNC_EVENT_COS_PRIORITY:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530303 be_async_grp5_cos_priority_process(adapter, compl);
304 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700305 case ASYNC_EVENT_QOS_SPEED:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530306 be_async_grp5_qos_speed_process(adapter, compl);
307 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000308 case ASYNC_EVENT_PVID_STATE:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530309 be_async_grp5_pvid_state_process(adapter, compl);
310 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700311 default:
Somnath Koturcc4ce022010-10-21 07:11:14 -0700312 break;
313 }
314}
315
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000316static void be_async_dbg_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530317 struct be_mcc_compl *cmp)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000318{
319 u8 event_type = 0;
320 struct be_async_event_qnq *evt = (struct be_async_event_qnq *) cmp;
321
Sathya Perla3acf19d2014-05-30 19:06:28 +0530322 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
323 ASYNC_EVENT_TYPE_MASK;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000324
325 switch (event_type) {
326 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
327 if (evt->valid)
328 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
329 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
330 break;
331 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530332 dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n",
333 event_type);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000334 break;
335 }
336}
337
Sathya Perla3acf19d2014-05-30 19:06:28 +0530338static inline bool is_link_state_evt(u32 flags)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000339{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530340 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
341 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000342}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000343
Sathya Perla3acf19d2014-05-30 19:06:28 +0530344static inline bool is_grp5_evt(u32 flags)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700345{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530346 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
347 ASYNC_EVENT_CODE_GRP_5;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700348}
349
Sathya Perla3acf19d2014-05-30 19:06:28 +0530350static inline bool is_dbg_evt(u32 flags)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000351{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530352 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
353 ASYNC_EVENT_CODE_QNQ;
354}
355
356static void be_mcc_event_process(struct be_adapter *adapter,
357 struct be_mcc_compl *compl)
358{
359 if (is_link_state_evt(compl->flags))
360 be_async_link_state_process(adapter, compl);
361 else if (is_grp5_evt(compl->flags))
362 be_async_grp5_evt_process(adapter, compl);
363 else if (is_dbg_evt(compl->flags))
364 be_async_dbg_evt_process(adapter, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000365}
366
Sathya Perlaefd2e402009-07-27 22:53:10 +0000367static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000368{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000369 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000370 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000371
372 if (be_mcc_compl_is_new(compl)) {
373 queue_tail_inc(mcc_cq);
374 return compl;
375 }
376 return NULL;
377}
378
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000379void be_async_mcc_enable(struct be_adapter *adapter)
380{
381 spin_lock_bh(&adapter->mcc_cq_lock);
382
383 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
384 adapter->mcc_obj.rearm_cq = true;
385
386 spin_unlock_bh(&adapter->mcc_cq_lock);
387}
388
389void be_async_mcc_disable(struct be_adapter *adapter)
390{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000391 spin_lock_bh(&adapter->mcc_cq_lock);
392
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000393 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000394 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
395
396 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000397}
398
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000399int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000400{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000401 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000402 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000403 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000404
Amerigo Wang072a9c42012-08-24 21:41:11 +0000405 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla3acf19d2014-05-30 19:06:28 +0530406
Sathya Perla8788fdc2009-07-27 22:52:03 +0000407 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000408 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530409 be_mcc_event_process(adapter, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700410 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530411 status = be_mcc_compl_process(adapter, compl);
412 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000413 }
414 be_mcc_compl_use(compl);
415 num++;
416 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700417
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000418 if (num)
419 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
420
Amerigo Wang072a9c42012-08-24 21:41:11 +0000421 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000422 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000423}
424
Sathya Perla6ac7b682009-06-18 00:05:54 +0000425/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700426static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000427{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700428#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000429 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800430 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700431
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800432 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000433 if (be_error(adapter))
434 return -EIO;
435
Amerigo Wang072a9c42012-08-24 21:41:11 +0000436 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000437 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000438 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800439
440 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000441 break;
442 udelay(100);
443 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700444 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000445 dev_err(&adapter->pdev->dev, "FW not responding\n");
446 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000447 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700448 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800449 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000450}
451
452/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700453static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000454{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000455 int status;
456 struct be_mcc_wrb *wrb;
457 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
458 u16 index = mcc_obj->q.head;
459 struct be_cmd_resp_hdr *resp;
460
461 index_dec(&index, mcc_obj->q.len);
462 wrb = queue_index_node(&mcc_obj->q, index);
463
464 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
465
Sathya Perla8788fdc2009-07-27 22:52:03 +0000466 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000467
468 status = be_mcc_wait_compl(adapter);
469 if (status == -EIO)
470 goto out;
471
Kalesh AP4c600052014-05-30 19:06:26 +0530472 status = (resp->base_status |
473 ((resp->addl_status & CQE_ADDL_STATUS_MASK) <<
474 CQE_ADDL_STATUS_SHIFT));
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000475out:
476 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000477}
478
Sathya Perla5f0b8492009-07-27 22:52:56 +0000479static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700480{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000481 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700482 u32 ready;
483
484 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000485 if (be_error(adapter))
486 return -EIO;
487
Sathya Perlacf588472010-02-14 21:22:01 +0000488 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000489 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000490 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000491
492 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700493 if (ready)
494 break;
495
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000496 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000497 dev_err(&adapter->pdev->dev, "FW not responding\n");
498 adapter->fw_timeout = true;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000499 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700500 return -1;
501 }
502
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000503 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000504 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700505 } while (true);
506
507 return 0;
508}
509
510/*
511 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000512 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700513 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700514static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700515{
516 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700517 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000518 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
519 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700520 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000521 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700522
Sathya Perlacf588472010-02-14 21:22:01 +0000523 /* wait for ready to be set */
524 status = be_mbox_db_ready_wait(adapter, db);
525 if (status != 0)
526 return status;
527
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700528 val |= MPU_MAILBOX_DB_HI_MASK;
529 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
530 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
531 iowrite32(val, db);
532
533 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000534 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700535 if (status != 0)
536 return status;
537
538 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700539 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
540 val |= (u32)(mbox_mem->dma >> 4) << 2;
541 iowrite32(val, db);
542
Sathya Perla5f0b8492009-07-27 22:52:56 +0000543 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700544 if (status != 0)
545 return status;
546
Sathya Perla5fb379e2009-06-18 00:02:59 +0000547 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000548 if (be_mcc_compl_is_new(compl)) {
549 status = be_mcc_compl_process(adapter, &mbox->compl);
550 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000551 if (status)
552 return status;
553 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000554 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700555 return -1;
556 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000557 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700558}
559
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000560static u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700561{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000562 u32 sem;
563
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000564 if (BEx_chip(adapter))
565 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700566 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000567 pci_read_config_dword(adapter->pdev,
568 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
569
570 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700571}
572
Gavin Shan87f20c22013-10-29 17:30:57 +0800573static int lancer_wait_ready(struct be_adapter *adapter)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000574{
575#define SLIPORT_READY_TIMEOUT 30
576 u32 sliport_status;
577 int status = 0, i;
578
579 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
580 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
581 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
582 break;
583
584 msleep(1000);
585 }
586
587 if (i == SLIPORT_READY_TIMEOUT)
588 status = -1;
589
590 return status;
591}
592
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000593static bool lancer_provisioning_error(struct be_adapter *adapter)
594{
595 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
Kalesh AP03d28ff2014-09-19 15:46:56 +0530596
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000597 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
598 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530599 sliport_err1 = ioread32(adapter->db + SLIPORT_ERROR1_OFFSET);
600 sliport_err2 = ioread32(adapter->db + SLIPORT_ERROR2_OFFSET);
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000601
602 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
603 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
604 return true;
605 }
606 return false;
607}
608
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000609int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
610{
611 int status;
612 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000613 bool resource_error;
614
615 resource_error = lancer_provisioning_error(adapter);
616 if (resource_error)
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000617 return -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000618
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000619 status = lancer_wait_ready(adapter);
620 if (!status) {
621 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
622 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
623 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
624 if (err && reset_needed) {
625 iowrite32(SLI_PORT_CONTROL_IP_MASK,
626 adapter->db + SLIPORT_CONTROL_OFFSET);
627
628 /* check adapter has corrected the error */
629 status = lancer_wait_ready(adapter);
630 sliport_status = ioread32(adapter->db +
631 SLIPORT_STATUS_OFFSET);
632 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
633 SLIPORT_STATUS_RN_MASK);
634 if (status || sliport_status)
635 status = -1;
636 } else if (err || reset_needed) {
637 status = -1;
638 }
639 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000640 /* Stop error recovery if error is not recoverable.
641 * No resource error is temporary errors and will go away
642 * when PF provisions resources.
643 */
644 resource_error = lancer_provisioning_error(adapter);
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000645 if (resource_error)
646 status = -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000647
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000648 return status;
649}
650
651int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700652{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000653 u16 stage;
654 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000655 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700656
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000657 if (lancer_chip(adapter)) {
658 status = lancer_wait_ready(adapter);
659 return status;
660 }
661
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000662 do {
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000663 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000664 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000665 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000666
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530667 dev_info(dev, "Waiting for POST, %ds elapsed\n", timeout);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000668 if (msleep_interruptible(2000)) {
669 dev_err(dev, "Waiting for POST aborted\n");
670 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000671 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000672 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000673 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700674
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000675 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000676 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677}
678
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700679
680static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
681{
682 return &wrb->payload.sgl[0];
683}
684
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530685static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, unsigned long addr)
Sathya Perlabea50982013-08-27 16:57:33 +0530686{
687 wrb->tag0 = addr & 0xFFFFFFFF;
688 wrb->tag1 = upper_32_bits(addr);
689}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700690
691/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000692/* mem will be NULL for embedded commands */
693static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530694 u8 subsystem, u8 opcode, int cmd_len,
695 struct be_mcc_wrb *wrb,
696 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700697{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000698 struct be_sge *sge;
699
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700700 req_hdr->opcode = opcode;
701 req_hdr->subsystem = subsystem;
702 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000703 req_hdr->version = 0;
Sathya Perlabea50982013-08-27 16:57:33 +0530704 fill_wrb_tags(wrb, (ulong) req_hdr);
Somnath Kotur106df1e2011-10-27 07:12:13 +0000705 wrb->payload_length = cmd_len;
706 if (mem) {
707 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
708 MCC_WRB_SGE_CNT_SHIFT;
709 sge = nonembedded_sgl(wrb);
710 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
711 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
712 sge->len = cpu_to_le32(mem->size);
713 } else
714 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
715 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700716}
717
718static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530719 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700720{
721 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
722 u64 dma = (u64)mem->dma;
723
724 for (i = 0; i < buf_pages; i++) {
725 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
726 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
727 dma += PAGE_SIZE_4K;
728 }
729}
730
Sathya Perlab31c50a2009-09-17 10:30:13 -0700731static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700732{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700733 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
734 struct be_mcc_wrb *wrb
735 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
736 memset(wrb, 0, sizeof(*wrb));
737 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700738}
739
Sathya Perlab31c50a2009-09-17 10:30:13 -0700740static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000741{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700742 struct be_queue_info *mccq = &adapter->mcc_obj.q;
743 struct be_mcc_wrb *wrb;
744
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000745 if (!mccq->created)
746 return NULL;
747
Vasundhara Volam4d277122013-04-21 23:28:15 +0000748 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000749 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000750
Sathya Perlab31c50a2009-09-17 10:30:13 -0700751 wrb = queue_head_node(mccq);
752 queue_head_inc(mccq);
753 atomic_inc(&mccq->used);
754 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000755 return wrb;
756}
757
Sathya Perlabea50982013-08-27 16:57:33 +0530758static bool use_mcc(struct be_adapter *adapter)
759{
760 return adapter->mcc_obj.q.created;
761}
762
763/* Must be used only in process context */
764static int be_cmd_lock(struct be_adapter *adapter)
765{
766 if (use_mcc(adapter)) {
767 spin_lock_bh(&adapter->mcc_lock);
768 return 0;
769 } else {
770 return mutex_lock_interruptible(&adapter->mbox_lock);
771 }
772}
773
774/* Must be used only in process context */
775static void be_cmd_unlock(struct be_adapter *adapter)
776{
777 if (use_mcc(adapter))
778 spin_unlock_bh(&adapter->mcc_lock);
779 else
780 return mutex_unlock(&adapter->mbox_lock);
781}
782
783static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter,
784 struct be_mcc_wrb *wrb)
785{
786 struct be_mcc_wrb *dest_wrb;
787
788 if (use_mcc(adapter)) {
789 dest_wrb = wrb_from_mccq(adapter);
790 if (!dest_wrb)
791 return NULL;
792 } else {
793 dest_wrb = wrb_from_mbox(adapter);
794 }
795
796 memcpy(dest_wrb, wrb, sizeof(*wrb));
797 if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK))
798 fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb));
799
800 return dest_wrb;
801}
802
803/* Must be used only in process context */
804static int be_cmd_notify_wait(struct be_adapter *adapter,
805 struct be_mcc_wrb *wrb)
806{
807 struct be_mcc_wrb *dest_wrb;
808 int status;
809
810 status = be_cmd_lock(adapter);
811 if (status)
812 return status;
813
814 dest_wrb = be_cmd_copy(adapter, wrb);
815 if (!dest_wrb)
816 return -EBUSY;
817
818 if (use_mcc(adapter))
819 status = be_mcc_notify_wait(adapter);
820 else
821 status = be_mbox_notify_wait(adapter);
822
823 if (!status)
824 memcpy(wrb, dest_wrb, sizeof(*wrb));
825
826 be_cmd_unlock(adapter);
827 return status;
828}
829
Sathya Perla2243e2e2009-11-22 22:02:03 +0000830/* Tell fw we're about to start firing cmds by writing a
831 * special pattern across the wrb hdr; uses mbox
832 */
833int be_cmd_fw_init(struct be_adapter *adapter)
834{
835 u8 *wrb;
836 int status;
837
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000838 if (lancer_chip(adapter))
839 return 0;
840
Ivan Vecera29849612010-12-14 05:43:19 +0000841 if (mutex_lock_interruptible(&adapter->mbox_lock))
842 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000843
844 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000845 *wrb++ = 0xFF;
846 *wrb++ = 0x12;
847 *wrb++ = 0x34;
848 *wrb++ = 0xFF;
849 *wrb++ = 0xFF;
850 *wrb++ = 0x56;
851 *wrb++ = 0x78;
852 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000853
854 status = be_mbox_notify_wait(adapter);
855
Ivan Vecera29849612010-12-14 05:43:19 +0000856 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000857 return status;
858}
859
860/* Tell fw we're done with firing cmds by writing a
861 * special pattern across the wrb hdr; uses mbox
862 */
863int be_cmd_fw_clean(struct be_adapter *adapter)
864{
865 u8 *wrb;
866 int status;
867
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000868 if (lancer_chip(adapter))
869 return 0;
870
Ivan Vecera29849612010-12-14 05:43:19 +0000871 if (mutex_lock_interruptible(&adapter->mbox_lock))
872 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000873
874 wrb = (u8 *)wrb_from_mbox(adapter);
875 *wrb++ = 0xFF;
876 *wrb++ = 0xAA;
877 *wrb++ = 0xBB;
878 *wrb++ = 0xFF;
879 *wrb++ = 0xFF;
880 *wrb++ = 0xCC;
881 *wrb++ = 0xDD;
882 *wrb = 0xFF;
883
884 status = be_mbox_notify_wait(adapter);
885
Ivan Vecera29849612010-12-14 05:43:19 +0000886 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000887 return status;
888}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000889
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530890int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700891{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700892 struct be_mcc_wrb *wrb;
893 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530894 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
895 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700896
Ivan Vecera29849612010-12-14 05:43:19 +0000897 if (mutex_lock_interruptible(&adapter->mbox_lock))
898 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700899
900 wrb = wrb_from_mbox(adapter);
901 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700902
Somnath Kotur106df1e2011-10-27 07:12:13 +0000903 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530904 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb,
905 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700906
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530907 /* Support for EQ_CREATEv2 available only SH-R onwards */
908 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
909 ver = 2;
910
911 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700912 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
913
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700914 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
915 /* 4byte eqe*/
916 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
917 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530918 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700919 be_dws_cpu_to_le(req->context, sizeof(req->context));
920
921 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
922
Sathya Perlab31c50a2009-09-17 10:30:13 -0700923 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700924 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700925 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +0530926
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530927 eqo->q.id = le16_to_cpu(resp->eq_id);
928 eqo->msix_idx =
929 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
930 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700931 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700932
Ivan Vecera29849612010-12-14 05:43:19 +0000933 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700934 return status;
935}
936
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000937/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000938int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000939 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700940{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700941 struct be_mcc_wrb *wrb;
942 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700943 int status;
944
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000945 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700946
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000947 wrb = wrb_from_mccq(adapter);
948 if (!wrb) {
949 status = -EBUSY;
950 goto err;
951 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700952 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700953
Somnath Kotur106df1e2011-10-27 07:12:13 +0000954 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530955 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb,
956 NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000957 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700958 if (permanent) {
959 req->permanent = 1;
960 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700961 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000962 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700963 req->permanent = 0;
964 }
965
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000966 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700967 if (!status) {
968 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +0530969
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700970 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700971 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700972
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000973err:
974 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700975 return status;
976}
977
Sathya Perlab31c50a2009-09-17 10:30:13 -0700978/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000979int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530980 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700981{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700982 struct be_mcc_wrb *wrb;
983 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700984 int status;
985
Sathya Perlab31c50a2009-09-17 10:30:13 -0700986 spin_lock_bh(&adapter->mcc_lock);
987
988 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000989 if (!wrb) {
990 status = -EBUSY;
991 goto err;
992 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700993 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700994
Somnath Kotur106df1e2011-10-27 07:12:13 +0000995 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530996 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb,
997 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700998
Ajit Khapardef8617e02011-02-11 13:36:37 +0000999 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001000 req->if_id = cpu_to_le32(if_id);
1001 memcpy(req->mac_address, mac_addr, ETH_ALEN);
1002
Sathya Perlab31c50a2009-09-17 10:30:13 -07001003 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001004 if (!status) {
1005 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301006
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001007 *pmac_id = le32_to_cpu(resp->pmac_id);
1008 }
1009
Sathya Perla713d03942009-11-22 22:02:45 +00001010err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001011 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +00001012
1013 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
1014 status = -EPERM;
1015
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001016 return status;
1017}
1018
Sathya Perlab31c50a2009-09-17 10:30:13 -07001019/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001020int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001021{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001022 struct be_mcc_wrb *wrb;
1023 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001024 int status;
1025
Sathya Perla30128032011-11-10 19:17:57 +00001026 if (pmac_id == -1)
1027 return 0;
1028
Sathya Perlab31c50a2009-09-17 10:30:13 -07001029 spin_lock_bh(&adapter->mcc_lock);
1030
1031 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001032 if (!wrb) {
1033 status = -EBUSY;
1034 goto err;
1035 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001036 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001037
Somnath Kotur106df1e2011-10-27 07:12:13 +00001038 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1039 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001040
Ajit Khapardef8617e02011-02-11 13:36:37 +00001041 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001042 req->if_id = cpu_to_le32(if_id);
1043 req->pmac_id = cpu_to_le32(pmac_id);
1044
Sathya Perlab31c50a2009-09-17 10:30:13 -07001045 status = be_mcc_notify_wait(adapter);
1046
Sathya Perla713d03942009-11-22 22:02:45 +00001047err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001048 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001049 return status;
1050}
1051
Sathya Perlab31c50a2009-09-17 10:30:13 -07001052/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001053int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301054 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001055{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001056 struct be_mcc_wrb *wrb;
1057 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001058 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001059 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001060 int status;
1061
Ivan Vecera29849612010-12-14 05:43:19 +00001062 if (mutex_lock_interruptible(&adapter->mbox_lock))
1063 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001064
1065 wrb = wrb_from_mbox(adapter);
1066 req = embedded_payload(wrb);
1067 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001068
Somnath Kotur106df1e2011-10-27 07:12:13 +00001069 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301070 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb,
1071 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001072
1073 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001074
1075 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001076 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301077 coalesce_wm);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001078 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301079 ctxt, no_delay);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001080 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301081 __ilog2_u32(cq->len / 256));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001082 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001083 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
1084 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001085 } else {
1086 req->hdr.version = 2;
1087 req->page_size = 1; /* 1 for 4K */
Ajit Khaparde09e83a92013-11-22 12:51:20 -06001088
1089 /* coalesce-wm field in this cmd is not relevant to Lancer.
1090 * Lancer uses COMMON_MODIFY_CQ to set this field
1091 */
1092 if (!lancer_chip(adapter))
1093 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1094 ctxt, coalesce_wm);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001095 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301096 no_delay);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001097 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301098 __ilog2_u32(cq->len / 256));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001099 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301100 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1101 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001102 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001103
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001104 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1105
1106 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1107
Sathya Perlab31c50a2009-09-17 10:30:13 -07001108 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001109 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001110 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301111
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001112 cq->id = le16_to_cpu(resp->cq_id);
1113 cq->created = true;
1114 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001115
Ivan Vecera29849612010-12-14 05:43:19 +00001116 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001117
1118 return status;
1119}
1120
1121static u32 be_encoded_q_len(int q_len)
1122{
1123 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
Kalesh AP03d28ff2014-09-19 15:46:56 +05301124
Sathya Perla5fb379e2009-06-18 00:02:59 +00001125 if (len_encoded == 16)
1126 len_encoded = 0;
1127 return len_encoded;
1128}
1129
Jingoo Han4188e7d2013-08-05 18:02:02 +09001130static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301131 struct be_queue_info *mccq,
1132 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001133{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001134 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001135 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001136 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001137 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001138 int status;
1139
Ivan Vecera29849612010-12-14 05:43:19 +00001140 if (mutex_lock_interruptible(&adapter->mbox_lock))
1141 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001142
1143 wrb = wrb_from_mbox(adapter);
1144 req = embedded_payload(wrb);
1145 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001146
Somnath Kotur106df1e2011-10-27 07:12:13 +00001147 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301148 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb,
1149 NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001150
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001151 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301152 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001153 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1154 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301155 be_encoded_q_len(mccq->len));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001156 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301157 } else {
1158 req->hdr.version = 1;
1159 req->cq_id = cpu_to_le16(cq->id);
1160
1161 AMAP_SET_BITS(struct amap_mcc_context_v1, ring_size, ctxt,
1162 be_encoded_q_len(mccq->len));
1163 AMAP_SET_BITS(struct amap_mcc_context_v1, valid, ctxt, 1);
1164 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_id,
1165 ctxt, cq->id);
1166 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_valid,
1167 ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001168 }
1169
Somnath Koturcc4ce022010-10-21 07:11:14 -07001170 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001171 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001172 req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001173 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1174
1175 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1176
Sathya Perlab31c50a2009-09-17 10:30:13 -07001177 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001178 if (!status) {
1179 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301180
Sathya Perla5fb379e2009-06-18 00:02:59 +00001181 mccq->id = le16_to_cpu(resp->id);
1182 mccq->created = true;
1183 }
Ivan Vecera29849612010-12-14 05:43:19 +00001184 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001185
1186 return status;
1187}
1188
Jingoo Han4188e7d2013-08-05 18:02:02 +09001189static int be_cmd_mccq_org_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301190 struct be_queue_info *mccq,
1191 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001192{
1193 struct be_mcc_wrb *wrb;
1194 struct be_cmd_req_mcc_create *req;
1195 struct be_dma_mem *q_mem = &mccq->dma_mem;
1196 void *ctxt;
1197 int status;
1198
1199 if (mutex_lock_interruptible(&adapter->mbox_lock))
1200 return -1;
1201
1202 wrb = wrb_from_mbox(adapter);
1203 req = embedded_payload(wrb);
1204 ctxt = &req->context;
1205
Somnath Kotur106df1e2011-10-27 07:12:13 +00001206 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301207 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb,
1208 NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001209
1210 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1211
1212 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1213 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301214 be_encoded_q_len(mccq->len));
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001215 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1216
1217 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1218
1219 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1220
1221 status = be_mbox_notify_wait(adapter);
1222 if (!status) {
1223 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301224
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001225 mccq->id = le16_to_cpu(resp->id);
1226 mccq->created = true;
1227 }
1228
1229 mutex_unlock(&adapter->mbox_lock);
1230 return status;
1231}
1232
1233int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301234 struct be_queue_info *mccq, struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001235{
1236 int status;
1237
1238 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301239 if (status && BEx_chip(adapter)) {
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001240 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1241 "or newer to avoid conflicting priorities between NIC "
1242 "and FCoE traffic");
1243 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1244 }
1245 return status;
1246}
1247
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001248int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001249{
Sathya Perla77071332013-08-27 16:57:34 +05301250 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001251 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001252 struct be_queue_info *txq = &txo->q;
1253 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001254 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001255 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001256
Sathya Perla77071332013-08-27 16:57:34 +05301257 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001258 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301259 OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001260
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001261 if (lancer_chip(adapter)) {
1262 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001263 } else if (BEx_chip(adapter)) {
1264 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1265 req->hdr.version = 2;
1266 } else { /* For SH */
1267 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001268 }
1269
Vasundhara Volam81b02652013-10-01 15:59:57 +05301270 if (req->hdr.version > 0)
1271 req->if_id = cpu_to_le16(adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001272 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1273 req->ulp_num = BE_ULP1_NUM;
1274 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001275 req->cq_id = cpu_to_le16(cq->id);
1276 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001277 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001278 ver = req->hdr.version;
1279
Sathya Perla77071332013-08-27 16:57:34 +05301280 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001281 if (!status) {
Sathya Perla77071332013-08-27 16:57:34 +05301282 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301283
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001284 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001285 if (ver == 2)
1286 txo->db_offset = le32_to_cpu(resp->db_offset);
1287 else
1288 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001289 txq->created = true;
1290 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001291
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001292 return status;
1293}
1294
Sathya Perla482c9e72011-06-29 23:33:17 +00001295/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001296int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301297 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
1298 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001299{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001300 struct be_mcc_wrb *wrb;
1301 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001302 struct be_dma_mem *q_mem = &rxq->dma_mem;
1303 int status;
1304
Sathya Perla482c9e72011-06-29 23:33:17 +00001305 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001306
Sathya Perla482c9e72011-06-29 23:33:17 +00001307 wrb = wrb_from_mccq(adapter);
1308 if (!wrb) {
1309 status = -EBUSY;
1310 goto err;
1311 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001312 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001313
Somnath Kotur106df1e2011-10-27 07:12:13 +00001314 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301315 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001316
1317 req->cq_id = cpu_to_le16(cq_id);
1318 req->frag_size = fls(frag_size) - 1;
1319 req->num_pages = 2;
1320 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1321 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001322 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001323 req->rss_queue = cpu_to_le32(rss);
1324
Sathya Perla482c9e72011-06-29 23:33:17 +00001325 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001326 if (!status) {
1327 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301328
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001329 rxq->id = le16_to_cpu(resp->id);
1330 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001331 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001332 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001333
Sathya Perla482c9e72011-06-29 23:33:17 +00001334err:
1335 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001336 return status;
1337}
1338
Sathya Perlab31c50a2009-09-17 10:30:13 -07001339/* Generic destroyer function for all types of queues
1340 * Uses Mbox
1341 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001342int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301343 int queue_type)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001344{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001345 struct be_mcc_wrb *wrb;
1346 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001347 u8 subsys = 0, opcode = 0;
1348 int status;
1349
Ivan Vecera29849612010-12-14 05:43:19 +00001350 if (mutex_lock_interruptible(&adapter->mbox_lock))
1351 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001352
Sathya Perlab31c50a2009-09-17 10:30:13 -07001353 wrb = wrb_from_mbox(adapter);
1354 req = embedded_payload(wrb);
1355
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001356 switch (queue_type) {
1357 case QTYPE_EQ:
1358 subsys = CMD_SUBSYSTEM_COMMON;
1359 opcode = OPCODE_COMMON_EQ_DESTROY;
1360 break;
1361 case QTYPE_CQ:
1362 subsys = CMD_SUBSYSTEM_COMMON;
1363 opcode = OPCODE_COMMON_CQ_DESTROY;
1364 break;
1365 case QTYPE_TXQ:
1366 subsys = CMD_SUBSYSTEM_ETH;
1367 opcode = OPCODE_ETH_TX_DESTROY;
1368 break;
1369 case QTYPE_RXQ:
1370 subsys = CMD_SUBSYSTEM_ETH;
1371 opcode = OPCODE_ETH_RX_DESTROY;
1372 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001373 case QTYPE_MCCQ:
1374 subsys = CMD_SUBSYSTEM_COMMON;
1375 opcode = OPCODE_COMMON_MCC_DESTROY;
1376 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001377 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001378 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001379 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001380
Somnath Kotur106df1e2011-10-27 07:12:13 +00001381 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301382 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001383 req->id = cpu_to_le16(q->id);
1384
Sathya Perlab31c50a2009-09-17 10:30:13 -07001385 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001386 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001387
Ivan Vecera29849612010-12-14 05:43:19 +00001388 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001389 return status;
1390}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001391
Sathya Perla482c9e72011-06-29 23:33:17 +00001392/* Uses MCC */
1393int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1394{
1395 struct be_mcc_wrb *wrb;
1396 struct be_cmd_req_q_destroy *req;
1397 int status;
1398
1399 spin_lock_bh(&adapter->mcc_lock);
1400
1401 wrb = wrb_from_mccq(adapter);
1402 if (!wrb) {
1403 status = -EBUSY;
1404 goto err;
1405 }
1406 req = embedded_payload(wrb);
1407
Somnath Kotur106df1e2011-10-27 07:12:13 +00001408 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301409 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001410 req->id = cpu_to_le16(q->id);
1411
1412 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001413 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001414
1415err:
1416 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001417 return status;
1418}
1419
Sathya Perlab31c50a2009-09-17 10:30:13 -07001420/* Create an rx filtering policy configuration on an i/f
Sathya Perlabea50982013-08-27 16:57:33 +05301421 * Will use MBOX only if MCCQ has not been created.
Sathya Perlab31c50a2009-09-17 10:30:13 -07001422 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001423int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001424 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001425{
Sathya Perlabea50982013-08-27 16:57:33 +05301426 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001427 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001428 int status;
1429
Sathya Perlabea50982013-08-27 16:57:33 +05301430 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001431 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301432 OPCODE_COMMON_NTWK_INTERFACE_CREATE,
1433 sizeof(*req), &wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001434 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001435 req->capability_flags = cpu_to_le32(cap_flags);
1436 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001437 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001438
Sathya Perlabea50982013-08-27 16:57:33 +05301439 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001440 if (!status) {
Sathya Perlabea50982013-08-27 16:57:33 +05301441 struct be_cmd_resp_if_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301442
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001443 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301444
1445 /* Hack to retrieve VF's pmac-id on BE3 */
1446 if (BE3_chip(adapter) && !be_physfn(adapter))
1447 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001448 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001449 return status;
1450}
1451
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001452/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001453int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001454{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001455 struct be_mcc_wrb *wrb;
1456 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001457 int status;
1458
Sathya Perla30128032011-11-10 19:17:57 +00001459 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001460 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001461
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001462 spin_lock_bh(&adapter->mcc_lock);
1463
1464 wrb = wrb_from_mccq(adapter);
1465 if (!wrb) {
1466 status = -EBUSY;
1467 goto err;
1468 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001469 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001470
Somnath Kotur106df1e2011-10-27 07:12:13 +00001471 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301472 OPCODE_COMMON_NTWK_INTERFACE_DESTROY,
1473 sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001474 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001475 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001476
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001477 status = be_mcc_notify_wait(adapter);
1478err:
1479 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001480 return status;
1481}
1482
1483/* Get stats is a non embedded command: the request is not embedded inside
1484 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001485 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001486 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001487int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001488{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001489 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001490 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001491 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001492
Sathya Perlab31c50a2009-09-17 10:30:13 -07001493 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001494
Sathya Perlab31c50a2009-09-17 10:30:13 -07001495 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001496 if (!wrb) {
1497 status = -EBUSY;
1498 goto err;
1499 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001500 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001501
Somnath Kotur106df1e2011-10-27 07:12:13 +00001502 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301503 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb,
1504 nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001505
Sathya Perlaca34fe32012-11-06 17:48:56 +00001506 /* version 1 of the cmd is not supported only by BE2 */
Ajit Khaparde61000862013-10-03 16:16:33 -05001507 if (BE2_chip(adapter))
1508 hdr->version = 0;
1509 if (BE3_chip(adapter) || lancer_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001510 hdr->version = 1;
Ajit Khaparde61000862013-10-03 16:16:33 -05001511 else
1512 hdr->version = 2;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001513
Sathya Perlab31c50a2009-09-17 10:30:13 -07001514 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001515 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001516
Sathya Perla713d03942009-11-22 22:02:45 +00001517err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001518 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001519 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001520}
1521
Selvin Xavier005d5692011-05-16 07:36:35 +00001522/* Lancer Stats */
1523int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301524 struct be_dma_mem *nonemb_cmd)
Selvin Xavier005d5692011-05-16 07:36:35 +00001525{
1526
1527 struct be_mcc_wrb *wrb;
1528 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001529 int status = 0;
1530
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001531 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1532 CMD_SUBSYSTEM_ETH))
1533 return -EPERM;
1534
Selvin Xavier005d5692011-05-16 07:36:35 +00001535 spin_lock_bh(&adapter->mcc_lock);
1536
1537 wrb = wrb_from_mccq(adapter);
1538 if (!wrb) {
1539 status = -EBUSY;
1540 goto err;
1541 }
1542 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001543
Somnath Kotur106df1e2011-10-27 07:12:13 +00001544 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301545 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size,
1546 wrb, nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001547
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001548 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001549 req->cmd_params.params.reset_stats = 0;
1550
Selvin Xavier005d5692011-05-16 07:36:35 +00001551 be_mcc_notify(adapter);
1552 adapter->stats_cmd_sent = true;
1553
1554err:
1555 spin_unlock_bh(&adapter->mcc_lock);
1556 return status;
1557}
1558
Sathya Perla323ff712012-09-28 04:39:43 +00001559static int be_mac_to_link_speed(int mac_speed)
1560{
1561 switch (mac_speed) {
1562 case PHY_LINK_SPEED_ZERO:
1563 return 0;
1564 case PHY_LINK_SPEED_10MBPS:
1565 return 10;
1566 case PHY_LINK_SPEED_100MBPS:
1567 return 100;
1568 case PHY_LINK_SPEED_1GBPS:
1569 return 1000;
1570 case PHY_LINK_SPEED_10GBPS:
1571 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301572 case PHY_LINK_SPEED_20GBPS:
1573 return 20000;
1574 case PHY_LINK_SPEED_25GBPS:
1575 return 25000;
1576 case PHY_LINK_SPEED_40GBPS:
1577 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001578 }
1579 return 0;
1580}
1581
1582/* Uses synchronous mcc
1583 * Returns link_speed in Mbps
1584 */
1585int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1586 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001587{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001588 struct be_mcc_wrb *wrb;
1589 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001590 int status;
1591
Sathya Perlab31c50a2009-09-17 10:30:13 -07001592 spin_lock_bh(&adapter->mcc_lock);
1593
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001594 if (link_status)
1595 *link_status = LINK_DOWN;
1596
Sathya Perlab31c50a2009-09-17 10:30:13 -07001597 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001598 if (!wrb) {
1599 status = -EBUSY;
1600 goto err;
1601 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001602 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001603
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001604 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301605 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1606 sizeof(*req), wrb, NULL);
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001607
Sathya Perlaca34fe32012-11-06 17:48:56 +00001608 /* version 1 of the cmd is not supported only by BE2 */
1609 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001610 req->hdr.version = 1;
1611
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001612 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001613
Sathya Perlab31c50a2009-09-17 10:30:13 -07001614 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001615 if (!status) {
1616 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301617
Sathya Perla323ff712012-09-28 04:39:43 +00001618 if (link_speed) {
1619 *link_speed = resp->link_speed ?
1620 le16_to_cpu(resp->link_speed) * 10 :
1621 be_mac_to_link_speed(resp->mac_speed);
1622
1623 if (!resp->logical_link_status)
1624 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001625 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001626 if (link_status)
1627 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001628 }
1629
Sathya Perla713d03942009-11-22 22:02:45 +00001630err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001631 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001632 return status;
1633}
1634
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001635/* Uses synchronous mcc */
1636int be_cmd_get_die_temperature(struct be_adapter *adapter)
1637{
1638 struct be_mcc_wrb *wrb;
1639 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301640 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001641
1642 spin_lock_bh(&adapter->mcc_lock);
1643
1644 wrb = wrb_from_mccq(adapter);
1645 if (!wrb) {
1646 status = -EBUSY;
1647 goto err;
1648 }
1649 req = embedded_payload(wrb);
1650
Somnath Kotur106df1e2011-10-27 07:12:13 +00001651 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301652 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES,
1653 sizeof(*req), wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001654
Somnath Kotur3de09452011-09-30 07:25:05 +00001655 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001656
1657err:
1658 spin_unlock_bh(&adapter->mcc_lock);
1659 return status;
1660}
1661
Somnath Kotur311fddc2011-03-16 21:22:43 +00001662/* Uses synchronous mcc */
1663int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1664{
1665 struct be_mcc_wrb *wrb;
1666 struct be_cmd_req_get_fat *req;
1667 int status;
1668
1669 spin_lock_bh(&adapter->mcc_lock);
1670
1671 wrb = wrb_from_mccq(adapter);
1672 if (!wrb) {
1673 status = -EBUSY;
1674 goto err;
1675 }
1676 req = embedded_payload(wrb);
1677
Somnath Kotur106df1e2011-10-27 07:12:13 +00001678 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301679 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb,
1680 NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001681 req->fat_operation = cpu_to_le32(QUERY_FAT);
1682 status = be_mcc_notify_wait(adapter);
1683 if (!status) {
1684 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301685
Somnath Kotur311fddc2011-03-16 21:22:43 +00001686 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001687 *log_size = le32_to_cpu(resp->log_size) -
1688 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001689 }
1690err:
1691 spin_unlock_bh(&adapter->mcc_lock);
1692 return status;
1693}
1694
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301695int be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
Somnath Kotur311fddc2011-03-16 21:22:43 +00001696{
1697 struct be_dma_mem get_fat_cmd;
1698 struct be_mcc_wrb *wrb;
1699 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001700 u32 offset = 0, total_size, buf_size,
1701 log_offset = sizeof(u32), payload_len;
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301702 int status = 0;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001703
1704 if (buf_len == 0)
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301705 return -EIO;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001706
1707 total_size = buf_len;
1708
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001709 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1710 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301711 get_fat_cmd.size,
1712 &get_fat_cmd.dma);
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001713 if (!get_fat_cmd.va) {
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001714 dev_err(&adapter->pdev->dev,
1715 "Memory allocation failure while retrieving FAT data\n");
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301716 return -ENOMEM;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001717 }
1718
Somnath Kotur311fddc2011-03-16 21:22:43 +00001719 spin_lock_bh(&adapter->mcc_lock);
1720
Somnath Kotur311fddc2011-03-16 21:22:43 +00001721 while (total_size) {
1722 buf_size = min(total_size, (u32)60*1024);
1723 total_size -= buf_size;
1724
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001725 wrb = wrb_from_mccq(adapter);
1726 if (!wrb) {
1727 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001728 goto err;
1729 }
1730 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001731
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001732 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001733 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301734 OPCODE_COMMON_MANAGE_FAT, payload_len,
1735 wrb, &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001736
1737 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1738 req->read_log_offset = cpu_to_le32(log_offset);
1739 req->read_log_length = cpu_to_le32(buf_size);
1740 req->data_buffer_size = cpu_to_le32(buf_size);
1741
1742 status = be_mcc_notify_wait(adapter);
1743 if (!status) {
1744 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
Kalesh AP03d28ff2014-09-19 15:46:56 +05301745
Somnath Kotur311fddc2011-03-16 21:22:43 +00001746 memcpy(buf + offset,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301747 resp->data_buffer,
1748 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001749 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001750 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001751 goto err;
1752 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001753 offset += buf_size;
1754 log_offset += buf_size;
1755 }
1756err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001757 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301758 get_fat_cmd.va, get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001759 spin_unlock_bh(&adapter->mcc_lock);
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301760 return status;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001761}
1762
Sathya Perla04b71172011-09-27 13:30:27 -04001763/* Uses synchronous mcc */
Kalesh APe97e3cd2014-07-17 16:20:26 +05301764int be_cmd_get_fw_ver(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001765{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001766 struct be_mcc_wrb *wrb;
1767 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001768 int status;
1769
Sathya Perla04b71172011-09-27 13:30:27 -04001770 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001771
Sathya Perla04b71172011-09-27 13:30:27 -04001772 wrb = wrb_from_mccq(adapter);
1773 if (!wrb) {
1774 status = -EBUSY;
1775 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001776 }
1777
Sathya Perla04b71172011-09-27 13:30:27 -04001778 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001779
Somnath Kotur106df1e2011-10-27 07:12:13 +00001780 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301781 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb,
1782 NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001783 status = be_mcc_notify_wait(adapter);
1784 if (!status) {
1785 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
Sathya Perlaacbafeb2014-09-02 09:56:46 +05301786
Vasundhara Volam242eb472014-09-12 17:39:15 +05301787 strlcpy(adapter->fw_ver, resp->firmware_version_string,
1788 sizeof(adapter->fw_ver));
1789 strlcpy(adapter->fw_on_flash, resp->fw_on_flash_version_string,
1790 sizeof(adapter->fw_on_flash));
Sathya Perla04b71172011-09-27 13:30:27 -04001791 }
1792err:
1793 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001794 return status;
1795}
1796
Sathya Perlab31c50a2009-09-17 10:30:13 -07001797/* set the EQ delay interval of an EQ to specified value
1798 * Uses async mcc
1799 */
Kalesh APb502ae82014-09-19 15:46:51 +05301800static int __be_cmd_modify_eqd(struct be_adapter *adapter,
1801 struct be_set_eqd *set_eqd, int num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001802{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001803 struct be_mcc_wrb *wrb;
1804 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla2632baf2013-10-01 16:00:00 +05301805 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001806
Sathya Perlab31c50a2009-09-17 10:30:13 -07001807 spin_lock_bh(&adapter->mcc_lock);
1808
1809 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001810 if (!wrb) {
1811 status = -EBUSY;
1812 goto err;
1813 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001814 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001815
Somnath Kotur106df1e2011-10-27 07:12:13 +00001816 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301817 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb,
1818 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001819
Sathya Perla2632baf2013-10-01 16:00:00 +05301820 req->num_eq = cpu_to_le32(num);
1821 for (i = 0; i < num; i++) {
1822 req->set_eqd[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
1823 req->set_eqd[i].phase = 0;
1824 req->set_eqd[i].delay_multiplier =
1825 cpu_to_le32(set_eqd[i].delay_multiplier);
1826 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001827
Sathya Perlab31c50a2009-09-17 10:30:13 -07001828 be_mcc_notify(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001829err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001830 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001831 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001832}
1833
Kalesh AP93676702014-09-12 17:39:20 +05301834int be_cmd_modify_eqd(struct be_adapter *adapter, struct be_set_eqd *set_eqd,
1835 int num)
1836{
1837 int num_eqs, i = 0;
1838
1839 if (lancer_chip(adapter) && num > 8) {
1840 while (num) {
1841 num_eqs = min(num, 8);
1842 __be_cmd_modify_eqd(adapter, &set_eqd[i], num_eqs);
1843 i += num_eqs;
1844 num -= num_eqs;
1845 }
1846 } else {
1847 __be_cmd_modify_eqd(adapter, set_eqd, num);
1848 }
1849
1850 return 0;
1851}
1852
Sathya Perlab31c50a2009-09-17 10:30:13 -07001853/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001854int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Kalesh AP4d567d92014-05-09 13:29:17 +05301855 u32 num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001856{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001857 struct be_mcc_wrb *wrb;
1858 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001859 int status;
1860
Sathya Perlab31c50a2009-09-17 10:30:13 -07001861 spin_lock_bh(&adapter->mcc_lock);
1862
1863 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001864 if (!wrb) {
1865 status = -EBUSY;
1866 goto err;
1867 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001868 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001869
Somnath Kotur106df1e2011-10-27 07:12:13 +00001870 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301871 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req),
1872 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001873
1874 req->interface_id = if_id;
Ajit Khaparde012bd382013-11-18 10:44:24 -06001875 req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001876 req->num_vlan = num;
Kalesh AP4d567d92014-05-09 13:29:17 +05301877 memcpy(req->normal_vlan, vtag_array,
1878 req->num_vlan * sizeof(vtag_array[0]));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001879
Sathya Perlab31c50a2009-09-17 10:30:13 -07001880 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001881err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001882 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001883 return status;
1884}
1885
Sathya Perla5b8821b2011-08-02 19:57:44 +00001886int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001887{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001888 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001889 struct be_dma_mem *mem = &adapter->rx_filter;
1890 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001891 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001892
Sathya Perla8788fdc2009-07-27 22:52:03 +00001893 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001894
Sathya Perlab31c50a2009-09-17 10:30:13 -07001895 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001896 if (!wrb) {
1897 status = -EBUSY;
1898 goto err;
1899 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001900 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001901 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301902 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1903 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001904
Sathya Perla5b8821b2011-08-02 19:57:44 +00001905 req->if_id = cpu_to_le32(adapter->if_handle);
1906 if (flags & IFF_PROMISC) {
1907 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301908 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1909 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001910 if (value == ON)
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301911 req->if_flags =
1912 cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1913 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1914 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001915 } else if (flags & IFF_ALLMULTI) {
1916 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001917 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001918 } else if (flags & BE_FLAGS_VLAN_PROMISC) {
1919 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_VLAN_PROMISCUOUS);
1920
1921 if (value == ON)
1922 req->if_flags =
1923 cpu_to_le32(BE_IF_FLAGS_VLAN_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001924 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001925 struct netdev_hw_addr *ha;
1926 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001927
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001928 req->if_flags_mask = req->if_flags =
1929 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001930
1931 /* Reset mcast promisc mode if already set by setting mask
1932 * and not setting flags field
1933 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001934 req->if_flags_mask |=
1935 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05301936 be_if_cap_flags(adapter));
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001937 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001938 netdev_for_each_mc_addr(ha, adapter->netdev)
1939 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1940 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001941
Ajit Khaparde012bd382013-11-18 10:44:24 -06001942 if ((req->if_flags_mask & cpu_to_le32(be_if_cap_flags(adapter))) !=
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301943 req->if_flags_mask) {
Ajit Khaparde012bd382013-11-18 10:44:24 -06001944 dev_warn(&adapter->pdev->dev,
1945 "Cannot set rx filter flags 0x%x\n",
1946 req->if_flags_mask);
1947 dev_warn(&adapter->pdev->dev,
1948 "Interface is capable of 0x%x flags only\n",
1949 be_if_cap_flags(adapter));
1950 }
1951 req->if_flags_mask &= cpu_to_le32(be_if_cap_flags(adapter));
1952
Sathya Perla0d1d5872011-08-03 05:19:27 -07001953 status = be_mcc_notify_wait(adapter);
Ajit Khaparde012bd382013-11-18 10:44:24 -06001954
Sathya Perla713d03942009-11-22 22:02:45 +00001955err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001956 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001957 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001958}
1959
Sathya Perlab31c50a2009-09-17 10:30:13 -07001960/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001961int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001962{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001963 struct be_mcc_wrb *wrb;
1964 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001965 int status;
1966
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001967 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1968 CMD_SUBSYSTEM_COMMON))
1969 return -EPERM;
1970
Sathya Perlab31c50a2009-09-17 10:30:13 -07001971 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001972
Sathya Perlab31c50a2009-09-17 10:30:13 -07001973 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001974 if (!wrb) {
1975 status = -EBUSY;
1976 goto err;
1977 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001978 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001979
Somnath Kotur106df1e2011-10-27 07:12:13 +00001980 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301981 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req),
1982 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001983
Suresh Reddyb29812c2014-09-12 17:39:17 +05301984 req->hdr.version = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001985 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1986 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1987
Sathya Perlab31c50a2009-09-17 10:30:13 -07001988 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001989
Sathya Perla713d03942009-11-22 22:02:45 +00001990err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001991 spin_unlock_bh(&adapter->mcc_lock);
Suresh Reddyb29812c2014-09-12 17:39:17 +05301992
1993 if (base_status(status) == MCC_STATUS_FEATURE_NOT_SUPPORTED)
1994 return -EOPNOTSUPP;
1995
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001996 return status;
1997}
1998
Sathya Perlab31c50a2009-09-17 10:30:13 -07001999/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002000int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002001{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002002 struct be_mcc_wrb *wrb;
2003 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002004 int status;
2005
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002006 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
2007 CMD_SUBSYSTEM_COMMON))
2008 return -EPERM;
2009
Sathya Perlab31c50a2009-09-17 10:30:13 -07002010 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002011
Sathya Perlab31c50a2009-09-17 10:30:13 -07002012 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002013 if (!wrb) {
2014 status = -EBUSY;
2015 goto err;
2016 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002017 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002018
Somnath Kotur106df1e2011-10-27 07:12:13 +00002019 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302020 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req),
2021 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002022
Sathya Perlab31c50a2009-09-17 10:30:13 -07002023 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002024 if (!status) {
2025 struct be_cmd_resp_get_flow_control *resp =
2026 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302027
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002028 *tx_fc = le16_to_cpu(resp->tx_flow_control);
2029 *rx_fc = le16_to_cpu(resp->rx_flow_control);
2030 }
2031
Sathya Perla713d03942009-11-22 22:02:45 +00002032err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07002033 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002034 return status;
2035}
2036
Sathya Perlab31c50a2009-09-17 10:30:13 -07002037/* Uses mbox */
Kalesh APe97e3cd2014-07-17 16:20:26 +05302038int be_cmd_query_fw_cfg(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002039{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002040 struct be_mcc_wrb *wrb;
2041 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002042 int status;
2043
Ivan Vecera29849612010-12-14 05:43:19 +00002044 if (mutex_lock_interruptible(&adapter->mbox_lock))
2045 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002046
Sathya Perlab31c50a2009-09-17 10:30:13 -07002047 wrb = wrb_from_mbox(adapter);
2048 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002049
Somnath Kotur106df1e2011-10-27 07:12:13 +00002050 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302051 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
2052 sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002053
Sathya Perlab31c50a2009-09-17 10:30:13 -07002054 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002055 if (!status) {
2056 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302057
Kalesh APe97e3cd2014-07-17 16:20:26 +05302058 adapter->port_num = le32_to_cpu(resp->phys_port);
2059 adapter->function_mode = le32_to_cpu(resp->function_mode);
2060 adapter->function_caps = le32_to_cpu(resp->function_caps);
2061 adapter->asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perlaacbafeb2014-09-02 09:56:46 +05302062 dev_info(&adapter->pdev->dev,
2063 "FW config: function_mode=0x%x, function_caps=0x%x\n",
2064 adapter->function_mode, adapter->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002065 }
2066
Ivan Vecera29849612010-12-14 05:43:19 +00002067 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002068 return status;
2069}
sarveshwarb14074ea2009-08-05 13:05:24 -07002070
Sathya Perlab31c50a2009-09-17 10:30:13 -07002071/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07002072int be_cmd_reset_function(struct be_adapter *adapter)
2073{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002074 struct be_mcc_wrb *wrb;
2075 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07002076 int status;
2077
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002078 if (lancer_chip(adapter)) {
2079 status = lancer_wait_ready(adapter);
2080 if (!status) {
2081 iowrite32(SLI_PORT_CONTROL_IP_MASK,
2082 adapter->db + SLIPORT_CONTROL_OFFSET);
2083 status = lancer_test_and_set_rdy_state(adapter);
2084 }
2085 if (status) {
2086 dev_err(&adapter->pdev->dev,
2087 "Adapter in non recoverable error\n");
2088 }
2089 return status;
2090 }
2091
Ivan Vecera29849612010-12-14 05:43:19 +00002092 if (mutex_lock_interruptible(&adapter->mbox_lock))
2093 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07002094
Sathya Perlab31c50a2009-09-17 10:30:13 -07002095 wrb = wrb_from_mbox(adapter);
2096 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07002097
Somnath Kotur106df1e2011-10-27 07:12:13 +00002098 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302099 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb,
2100 NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07002101
Sathya Perlab31c50a2009-09-17 10:30:13 -07002102 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07002103
Ivan Vecera29849612010-12-14 05:43:19 +00002104 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07002105 return status;
2106}
Ajit Khaparde84517482009-09-04 03:12:16 +00002107
Suresh Reddy594ad542013-04-25 23:03:20 +00002108int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01002109 u32 rss_hash_opts, u16 table_size, const u8 *rss_hkey)
Sathya Perla3abcded2010-10-03 22:12:27 -07002110{
2111 struct be_mcc_wrb *wrb;
2112 struct be_cmd_req_rss_config *req;
Sathya Perla3abcded2010-10-03 22:12:27 -07002113 int status;
2114
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302115 if (!(be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS))
2116 return 0;
2117
Kalesh APb51aa362014-05-09 13:29:19 +05302118 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002119
Kalesh APb51aa362014-05-09 13:29:19 +05302120 wrb = wrb_from_mccq(adapter);
2121 if (!wrb) {
2122 status = -EBUSY;
2123 goto err;
2124 }
Sathya Perla3abcded2010-10-03 22:12:27 -07002125 req = embedded_payload(wrb);
2126
Somnath Kotur106df1e2011-10-27 07:12:13 +00002127 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302128 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07002129
2130 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00002131 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07002132 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00002133
Kalesh APb51aa362014-05-09 13:29:19 +05302134 if (!BEx_chip(adapter))
Suresh Reddy594ad542013-04-25 23:03:20 +00002135 req->hdr.version = 1;
2136
Sathya Perla3abcded2010-10-03 22:12:27 -07002137 memcpy(req->cpu_table, rsstable, table_size);
Venkata Duvvurue2557872014-04-21 15:38:00 +05302138 memcpy(req->hash, rss_hkey, RSS_HASH_KEY_LEN);
Sathya Perla3abcded2010-10-03 22:12:27 -07002139 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
2140
Kalesh APb51aa362014-05-09 13:29:19 +05302141 status = be_mcc_notify_wait(adapter);
2142err:
2143 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002144 return status;
2145}
2146
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002147/* Uses sync mcc */
2148int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302149 u8 bcn, u8 sts, u8 state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002150{
2151 struct be_mcc_wrb *wrb;
2152 struct be_cmd_req_enable_disable_beacon *req;
2153 int status;
2154
2155 spin_lock_bh(&adapter->mcc_lock);
2156
2157 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002158 if (!wrb) {
2159 status = -EBUSY;
2160 goto err;
2161 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002162 req = embedded_payload(wrb);
2163
Somnath Kotur106df1e2011-10-27 07:12:13 +00002164 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302165 OPCODE_COMMON_ENABLE_DISABLE_BEACON,
2166 sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002167
2168 req->port_num = port_num;
2169 req->beacon_state = state;
2170 req->beacon_duration = bcn;
2171 req->status_duration = sts;
2172
2173 status = be_mcc_notify_wait(adapter);
2174
Sathya Perla713d03942009-11-22 22:02:45 +00002175err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002176 spin_unlock_bh(&adapter->mcc_lock);
2177 return status;
2178}
2179
2180/* Uses sync mcc */
2181int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2182{
2183 struct be_mcc_wrb *wrb;
2184 struct be_cmd_req_get_beacon_state *req;
2185 int status;
2186
2187 spin_lock_bh(&adapter->mcc_lock);
2188
2189 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002190 if (!wrb) {
2191 status = -EBUSY;
2192 goto err;
2193 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002194 req = embedded_payload(wrb);
2195
Somnath Kotur106df1e2011-10-27 07:12:13 +00002196 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302197 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req),
2198 wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002199
2200 req->port_num = port_num;
2201
2202 status = be_mcc_notify_wait(adapter);
2203 if (!status) {
2204 struct be_cmd_resp_get_beacon_state *resp =
2205 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302206
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002207 *state = resp->beacon_state;
2208 }
2209
Sathya Perla713d03942009-11-22 22:02:45 +00002210err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002211 spin_unlock_bh(&adapter->mcc_lock);
2212 return status;
2213}
2214
Mark Leonarde36edd92014-09-12 17:39:18 +05302215/* Uses sync mcc */
2216int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2217 u8 page_num, u8 *data)
2218{
2219 struct be_dma_mem cmd;
2220 struct be_mcc_wrb *wrb;
2221 struct be_cmd_req_port_type *req;
2222 int status;
2223
2224 if (page_num > TR_PAGE_A2)
2225 return -EINVAL;
2226
2227 cmd.size = sizeof(struct be_cmd_resp_port_type);
2228 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
2229 if (!cmd.va) {
2230 dev_err(&adapter->pdev->dev, "Memory allocation failed\n");
2231 return -ENOMEM;
2232 }
2233 memset(cmd.va, 0, cmd.size);
2234
2235 spin_lock_bh(&adapter->mcc_lock);
2236
2237 wrb = wrb_from_mccq(adapter);
2238 if (!wrb) {
2239 status = -EBUSY;
2240 goto err;
2241 }
2242 req = cmd.va;
2243
2244 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2245 OPCODE_COMMON_READ_TRANSRECV_DATA,
2246 cmd.size, wrb, &cmd);
2247
2248 req->port = cpu_to_le32(adapter->hba_port_num);
2249 req->page_num = cpu_to_le32(page_num);
2250 status = be_mcc_notify_wait(adapter);
2251 if (!status) {
2252 struct be_cmd_resp_port_type *resp = cmd.va;
2253
2254 memcpy(data, resp->page_data, PAGE_DATA_LEN);
2255 }
2256err:
2257 spin_unlock_bh(&adapter->mcc_lock);
2258 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2259 return status;
2260}
2261
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002262int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002263 u32 data_size, u32 data_offset,
2264 const char *obj_name, u32 *data_written,
2265 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002266{
2267 struct be_mcc_wrb *wrb;
2268 struct lancer_cmd_req_write_object *req;
2269 struct lancer_cmd_resp_write_object *resp;
2270 void *ctxt = NULL;
2271 int status;
2272
2273 spin_lock_bh(&adapter->mcc_lock);
2274 adapter->flash_status = 0;
2275
2276 wrb = wrb_from_mccq(adapter);
2277 if (!wrb) {
2278 status = -EBUSY;
2279 goto err_unlock;
2280 }
2281
2282 req = embedded_payload(wrb);
2283
Somnath Kotur106df1e2011-10-27 07:12:13 +00002284 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302285 OPCODE_COMMON_WRITE_OBJECT,
2286 sizeof(struct lancer_cmd_req_write_object), wrb,
2287 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002288
2289 ctxt = &req->context;
2290 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302291 write_length, ctxt, data_size);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002292
2293 if (data_size == 0)
2294 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302295 eof, ctxt, 1);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002296 else
2297 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302298 eof, ctxt, 0);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002299
2300 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2301 req->write_offset = cpu_to_le32(data_offset);
Vasundhara Volam242eb472014-09-12 17:39:15 +05302302 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002303 req->descriptor_count = cpu_to_le32(1);
2304 req->buf_len = cpu_to_le32(data_size);
2305 req->addr_low = cpu_to_le32((cmd->dma +
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302306 sizeof(struct lancer_cmd_req_write_object))
2307 & 0xFFFFFFFF);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002308 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2309 sizeof(struct lancer_cmd_req_write_object)));
2310
2311 be_mcc_notify(adapter);
2312 spin_unlock_bh(&adapter->mcc_lock);
2313
Suresh Reddy5eeff632014-01-06 13:02:24 +05302314 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002315 msecs_to_jiffies(60000)))
Kalesh APfd451602014-07-17 16:20:21 +05302316 status = -ETIMEDOUT;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002317 else
2318 status = adapter->flash_status;
2319
2320 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002321 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002322 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002323 *change_status = resp->change_status;
2324 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002325 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002326 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002327
2328 return status;
2329
2330err_unlock:
2331 spin_unlock_bh(&adapter->mcc_lock);
2332 return status;
2333}
2334
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +05302335int be_cmd_query_cable_type(struct be_adapter *adapter)
2336{
2337 u8 page_data[PAGE_DATA_LEN];
2338 int status;
2339
2340 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2341 page_data);
2342 if (!status) {
2343 switch (adapter->phy.interface_type) {
2344 case PHY_TYPE_QSFP:
2345 adapter->phy.cable_type =
2346 page_data[QSFP_PLUS_CABLE_TYPE_OFFSET];
2347 break;
2348 case PHY_TYPE_SFP_PLUS_10GB:
2349 adapter->phy.cable_type =
2350 page_data[SFP_PLUS_CABLE_TYPE_OFFSET];
2351 break;
2352 default:
2353 adapter->phy.cable_type = 0;
2354 break;
2355 }
2356 }
2357 return status;
2358}
2359
Kalesh APf0613382014-08-01 17:47:32 +05302360int lancer_cmd_delete_object(struct be_adapter *adapter, const char *obj_name)
2361{
2362 struct lancer_cmd_req_delete_object *req;
2363 struct be_mcc_wrb *wrb;
2364 int status;
2365
2366 spin_lock_bh(&adapter->mcc_lock);
2367
2368 wrb = wrb_from_mccq(adapter);
2369 if (!wrb) {
2370 status = -EBUSY;
2371 goto err;
2372 }
2373
2374 req = embedded_payload(wrb);
2375
2376 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2377 OPCODE_COMMON_DELETE_OBJECT,
2378 sizeof(*req), wrb, NULL);
2379
Vasundhara Volam242eb472014-09-12 17:39:15 +05302380 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Kalesh APf0613382014-08-01 17:47:32 +05302381
2382 status = be_mcc_notify_wait(adapter);
2383err:
2384 spin_unlock_bh(&adapter->mcc_lock);
2385 return status;
2386}
2387
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002388int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302389 u32 data_size, u32 data_offset, const char *obj_name,
2390 u32 *data_read, u32 *eof, u8 *addn_status)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002391{
2392 struct be_mcc_wrb *wrb;
2393 struct lancer_cmd_req_read_object *req;
2394 struct lancer_cmd_resp_read_object *resp;
2395 int status;
2396
2397 spin_lock_bh(&adapter->mcc_lock);
2398
2399 wrb = wrb_from_mccq(adapter);
2400 if (!wrb) {
2401 status = -EBUSY;
2402 goto err_unlock;
2403 }
2404
2405 req = embedded_payload(wrb);
2406
2407 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302408 OPCODE_COMMON_READ_OBJECT,
2409 sizeof(struct lancer_cmd_req_read_object), wrb,
2410 NULL);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002411
2412 req->desired_read_len = cpu_to_le32(data_size);
2413 req->read_offset = cpu_to_le32(data_offset);
2414 strcpy(req->object_name, obj_name);
2415 req->descriptor_count = cpu_to_le32(1);
2416 req->buf_len = cpu_to_le32(data_size);
2417 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2418 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2419
2420 status = be_mcc_notify_wait(adapter);
2421
2422 resp = embedded_payload(wrb);
2423 if (!status) {
2424 *data_read = le32_to_cpu(resp->actual_read_len);
2425 *eof = le32_to_cpu(resp->eof);
2426 } else {
2427 *addn_status = resp->additional_status;
2428 }
2429
2430err_unlock:
2431 spin_unlock_bh(&adapter->mcc_lock);
2432 return status;
2433}
2434
Ajit Khaparde84517482009-09-04 03:12:16 +00002435int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302436 u32 flash_type, u32 flash_opcode, u32 buf_size)
Ajit Khaparde84517482009-09-04 03:12:16 +00002437{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002438 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002439 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002440 int status;
2441
Sathya Perlab31c50a2009-09-17 10:30:13 -07002442 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002443 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002444
2445 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002446 if (!wrb) {
2447 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002448 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002449 }
2450 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002451
Somnath Kotur106df1e2011-10-27 07:12:13 +00002452 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302453 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb,
2454 cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002455
2456 req->params.op_type = cpu_to_le32(flash_type);
2457 req->params.op_code = cpu_to_le32(flash_opcode);
2458 req->params.data_buf_size = cpu_to_le32(buf_size);
2459
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002460 be_mcc_notify(adapter);
2461 spin_unlock_bh(&adapter->mcc_lock);
2462
Suresh Reddy5eeff632014-01-06 13:02:24 +05302463 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
2464 msecs_to_jiffies(40000)))
Kalesh APfd451602014-07-17 16:20:21 +05302465 status = -ETIMEDOUT;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002466 else
2467 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002468
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002469 return status;
2470
2471err_unlock:
2472 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002473 return status;
2474}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002475
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002476int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +05302477 u16 optype, int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002478{
2479 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002480 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002481 int status;
2482
2483 spin_lock_bh(&adapter->mcc_lock);
2484
2485 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002486 if (!wrb) {
2487 status = -EBUSY;
2488 goto err;
2489 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002490 req = embedded_payload(wrb);
2491
Somnath Kotur106df1e2011-10-27 07:12:13 +00002492 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002493 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2494 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002495
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +05302496 req->params.op_type = cpu_to_le32(optype);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002497 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002498 req->params.offset = cpu_to_le32(offset);
2499 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002500
2501 status = be_mcc_notify_wait(adapter);
2502 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002503 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002504
Sathya Perla713d03942009-11-22 22:02:45 +00002505err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002506 spin_unlock_bh(&adapter->mcc_lock);
2507 return status;
2508}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002509
Dan Carpenterc196b022010-05-26 04:47:39 +00002510int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302511 struct be_dma_mem *nonemb_cmd)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002512{
2513 struct be_mcc_wrb *wrb;
2514 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002515 int status;
2516
2517 spin_lock_bh(&adapter->mcc_lock);
2518
2519 wrb = wrb_from_mccq(adapter);
2520 if (!wrb) {
2521 status = -EBUSY;
2522 goto err;
2523 }
2524 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002525
Somnath Kotur106df1e2011-10-27 07:12:13 +00002526 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302527 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req),
2528 wrb, nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002529 memcpy(req->magic_mac, mac, ETH_ALEN);
2530
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002531 status = be_mcc_notify_wait(adapter);
2532
2533err:
2534 spin_unlock_bh(&adapter->mcc_lock);
2535 return status;
2536}
Suresh Rff33a6e2009-12-03 16:15:52 -08002537
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002538int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2539 u8 loopback_type, u8 enable)
2540{
2541 struct be_mcc_wrb *wrb;
2542 struct be_cmd_req_set_lmode *req;
2543 int status;
2544
2545 spin_lock_bh(&adapter->mcc_lock);
2546
2547 wrb = wrb_from_mccq(adapter);
2548 if (!wrb) {
2549 status = -EBUSY;
2550 goto err;
2551 }
2552
2553 req = embedded_payload(wrb);
2554
Somnath Kotur106df1e2011-10-27 07:12:13 +00002555 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302556 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req),
2557 wrb, NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002558
2559 req->src_port = port_num;
2560 req->dest_port = port_num;
2561 req->loopback_type = loopback_type;
2562 req->loopback_state = enable;
2563
2564 status = be_mcc_notify_wait(adapter);
2565err:
2566 spin_unlock_bh(&adapter->mcc_lock);
2567 return status;
2568}
2569
Suresh Rff33a6e2009-12-03 16:15:52 -08002570int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302571 u32 loopback_type, u32 pkt_size, u32 num_pkts,
2572 u64 pattern)
Suresh Rff33a6e2009-12-03 16:15:52 -08002573{
2574 struct be_mcc_wrb *wrb;
2575 struct be_cmd_req_loopback_test *req;
Suresh Reddy5eeff632014-01-06 13:02:24 +05302576 struct be_cmd_resp_loopback_test *resp;
Suresh Rff33a6e2009-12-03 16:15:52 -08002577 int status;
2578
2579 spin_lock_bh(&adapter->mcc_lock);
2580
2581 wrb = wrb_from_mccq(adapter);
2582 if (!wrb) {
2583 status = -EBUSY;
2584 goto err;
2585 }
2586
2587 req = embedded_payload(wrb);
2588
Somnath Kotur106df1e2011-10-27 07:12:13 +00002589 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302590 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb,
2591 NULL);
Suresh Rff33a6e2009-12-03 16:15:52 -08002592
Suresh Reddy5eeff632014-01-06 13:02:24 +05302593 req->hdr.timeout = cpu_to_le32(15);
Suresh Rff33a6e2009-12-03 16:15:52 -08002594 req->pattern = cpu_to_le64(pattern);
2595 req->src_port = cpu_to_le32(port_num);
2596 req->dest_port = cpu_to_le32(port_num);
2597 req->pkt_size = cpu_to_le32(pkt_size);
2598 req->num_pkts = cpu_to_le32(num_pkts);
2599 req->loopback_type = cpu_to_le32(loopback_type);
2600
Suresh Reddy5eeff632014-01-06 13:02:24 +05302601 be_mcc_notify(adapter);
Suresh Rff33a6e2009-12-03 16:15:52 -08002602
Suresh Reddy5eeff632014-01-06 13:02:24 +05302603 spin_unlock_bh(&adapter->mcc_lock);
2604
2605 wait_for_completion(&adapter->et_cmd_compl);
2606 resp = embedded_payload(wrb);
2607 status = le32_to_cpu(resp->status);
2608
2609 return status;
Suresh Rff33a6e2009-12-03 16:15:52 -08002610err:
2611 spin_unlock_bh(&adapter->mcc_lock);
2612 return status;
2613}
2614
2615int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302616 u32 byte_cnt, struct be_dma_mem *cmd)
Suresh Rff33a6e2009-12-03 16:15:52 -08002617{
2618 struct be_mcc_wrb *wrb;
2619 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002620 int status;
2621 int i, j = 0;
2622
2623 spin_lock_bh(&adapter->mcc_lock);
2624
2625 wrb = wrb_from_mccq(adapter);
2626 if (!wrb) {
2627 status = -EBUSY;
2628 goto err;
2629 }
2630 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002631 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302632 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb,
2633 cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002634
2635 req->pattern = cpu_to_le64(pattern);
2636 req->byte_count = cpu_to_le32(byte_cnt);
2637 for (i = 0; i < byte_cnt; i++) {
2638 req->snd_buff[i] = (u8)(pattern >> (j*8));
2639 j++;
2640 if (j > 7)
2641 j = 0;
2642 }
2643
2644 status = be_mcc_notify_wait(adapter);
2645
2646 if (!status) {
2647 struct be_cmd_resp_ddrdma_test *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05302648
Suresh Rff33a6e2009-12-03 16:15:52 -08002649 resp = cmd->va;
2650 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2651 resp->snd_err) {
2652 status = -1;
2653 }
2654 }
2655
2656err:
2657 spin_unlock_bh(&adapter->mcc_lock);
2658 return status;
2659}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002660
Dan Carpenterc196b022010-05-26 04:47:39 +00002661int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302662 struct be_dma_mem *nonemb_cmd)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002663{
2664 struct be_mcc_wrb *wrb;
2665 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002666 int status;
2667
2668 spin_lock_bh(&adapter->mcc_lock);
2669
2670 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002671 if (!wrb) {
2672 status = -EBUSY;
2673 goto err;
2674 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002675 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002676
Somnath Kotur106df1e2011-10-27 07:12:13 +00002677 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302678 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2679 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002680
2681 status = be_mcc_notify_wait(adapter);
2682
Ajit Khapardee45ff012011-02-04 17:18:28 +00002683err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002684 spin_unlock_bh(&adapter->mcc_lock);
2685 return status;
2686}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002687
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002688int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002689{
2690 struct be_mcc_wrb *wrb;
2691 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002692 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002693 int status;
2694
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002695 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2696 CMD_SUBSYSTEM_COMMON))
2697 return -EPERM;
2698
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002699 spin_lock_bh(&adapter->mcc_lock);
2700
2701 wrb = wrb_from_mccq(adapter);
2702 if (!wrb) {
2703 status = -EBUSY;
2704 goto err;
2705 }
Sathya Perla306f1342011-08-02 19:57:45 +00002706 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302707 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Sathya Perla306f1342011-08-02 19:57:45 +00002708 if (!cmd.va) {
2709 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2710 status = -ENOMEM;
2711 goto err;
2712 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002713
Sathya Perla306f1342011-08-02 19:57:45 +00002714 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002715
Somnath Kotur106df1e2011-10-27 07:12:13 +00002716 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302717 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2718 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002719
2720 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002721 if (!status) {
2722 struct be_phy_info *resp_phy_info =
2723 cmd.va + sizeof(struct be_cmd_req_hdr);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302724
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002725 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2726 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002727 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002728 adapter->phy.auto_speeds_supported =
2729 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2730 adapter->phy.fixed_speeds_supported =
2731 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2732 adapter->phy.misc_params =
2733 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05302734
2735 if (BE2_chip(adapter)) {
2736 adapter->phy.fixed_speeds_supported =
2737 BE_SUPPORTED_SPEED_10GBPS |
2738 BE_SUPPORTED_SPEED_1GBPS;
2739 }
Sathya Perla306f1342011-08-02 19:57:45 +00002740 }
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302741 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002742err:
2743 spin_unlock_bh(&adapter->mcc_lock);
2744 return status;
2745}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002746
2747int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2748{
2749 struct be_mcc_wrb *wrb;
2750 struct be_cmd_req_set_qos *req;
2751 int status;
2752
2753 spin_lock_bh(&adapter->mcc_lock);
2754
2755 wrb = wrb_from_mccq(adapter);
2756 if (!wrb) {
2757 status = -EBUSY;
2758 goto err;
2759 }
2760
2761 req = embedded_payload(wrb);
2762
Somnath Kotur106df1e2011-10-27 07:12:13 +00002763 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302764 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002765
2766 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002767 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2768 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002769
2770 status = be_mcc_notify_wait(adapter);
2771
2772err:
2773 spin_unlock_bh(&adapter->mcc_lock);
2774 return status;
2775}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002776
2777int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2778{
2779 struct be_mcc_wrb *wrb;
2780 struct be_cmd_req_cntl_attribs *req;
2781 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002782 int status;
2783 int payload_len = max(sizeof(*req), sizeof(*resp));
2784 struct mgmt_controller_attrib *attribs;
2785 struct be_dma_mem attribs_cmd;
2786
Suresh Reddyd98ef502013-04-25 00:56:55 +00002787 if (mutex_lock_interruptible(&adapter->mbox_lock))
2788 return -1;
2789
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002790 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2791 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2792 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302793 &attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002794 if (!attribs_cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302795 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002796 status = -ENOMEM;
2797 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002798 }
2799
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002800 wrb = wrb_from_mbox(adapter);
2801 if (!wrb) {
2802 status = -EBUSY;
2803 goto err;
2804 }
2805 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002806
Somnath Kotur106df1e2011-10-27 07:12:13 +00002807 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302808 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len,
2809 wrb, &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002810
2811 status = be_mbox_notify_wait(adapter);
2812 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002813 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002814 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2815 }
2816
2817err:
2818 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002819 if (attribs_cmd.va)
2820 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2821 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002822 return status;
2823}
Sathya Perla2e588f82011-03-11 02:49:26 +00002824
2825/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002826int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002827{
2828 struct be_mcc_wrb *wrb;
2829 struct be_cmd_req_set_func_cap *req;
2830 int status;
2831
2832 if (mutex_lock_interruptible(&adapter->mbox_lock))
2833 return -1;
2834
2835 wrb = wrb_from_mbox(adapter);
2836 if (!wrb) {
2837 status = -EBUSY;
2838 goto err;
2839 }
2840
2841 req = embedded_payload(wrb);
2842
Somnath Kotur106df1e2011-10-27 07:12:13 +00002843 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302844 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP,
2845 sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002846
2847 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2848 CAPABILITY_BE3_NATIVE_ERX_API);
2849 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2850
2851 status = be_mbox_notify_wait(adapter);
2852 if (!status) {
2853 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302854
Sathya Perla2e588f82011-03-11 02:49:26 +00002855 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2856 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002857 if (!adapter->be3_native)
2858 dev_warn(&adapter->pdev->dev,
2859 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002860 }
2861err:
2862 mutex_unlock(&adapter->mbox_lock);
2863 return status;
2864}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002865
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002866/* Get privilege(s) for a function */
2867int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2868 u32 domain)
2869{
2870 struct be_mcc_wrb *wrb;
2871 struct be_cmd_req_get_fn_privileges *req;
2872 int status;
2873
2874 spin_lock_bh(&adapter->mcc_lock);
2875
2876 wrb = wrb_from_mccq(adapter);
2877 if (!wrb) {
2878 status = -EBUSY;
2879 goto err;
2880 }
2881
2882 req = embedded_payload(wrb);
2883
2884 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2885 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2886 wrb, NULL);
2887
2888 req->hdr.domain = domain;
2889
2890 status = be_mcc_notify_wait(adapter);
2891 if (!status) {
2892 struct be_cmd_resp_get_fn_privileges *resp =
2893 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302894
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002895 *privilege = le32_to_cpu(resp->privilege_mask);
Suresh Reddy02308d72014-01-15 13:23:36 +05302896
2897 /* In UMC mode FW does not return right privileges.
2898 * Override with correct privilege equivalent to PF.
2899 */
2900 if (BEx_chip(adapter) && be_is_mc(adapter) &&
2901 be_physfn(adapter))
2902 *privilege = MAX_PRIVILEGES;
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002903 }
2904
2905err:
2906 spin_unlock_bh(&adapter->mcc_lock);
2907 return status;
2908}
2909
Sathya Perla04a06022013-07-23 15:25:00 +05302910/* Set privilege(s) for a function */
2911int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
2912 u32 domain)
2913{
2914 struct be_mcc_wrb *wrb;
2915 struct be_cmd_req_set_fn_privileges *req;
2916 int status;
2917
2918 spin_lock_bh(&adapter->mcc_lock);
2919
2920 wrb = wrb_from_mccq(adapter);
2921 if (!wrb) {
2922 status = -EBUSY;
2923 goto err;
2924 }
2925
2926 req = embedded_payload(wrb);
2927 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2928 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
2929 wrb, NULL);
2930 req->hdr.domain = domain;
2931 if (lancer_chip(adapter))
2932 req->privileges_lancer = cpu_to_le32(privileges);
2933 else
2934 req->privileges = cpu_to_le32(privileges);
2935
2936 status = be_mcc_notify_wait(adapter);
2937err:
2938 spin_unlock_bh(&adapter->mcc_lock);
2939 return status;
2940}
2941
Sathya Perla5a712c12013-07-23 15:24:59 +05302942/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
2943 * pmac_id_valid: false => pmac_id or MAC address is requested.
2944 * If pmac_id is returned, pmac_id_valid is returned as true
2945 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002946int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05302947 bool *pmac_id_valid, u32 *pmac_id, u32 if_handle,
2948 u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002949{
2950 struct be_mcc_wrb *wrb;
2951 struct be_cmd_req_get_mac_list *req;
2952 int status;
2953 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002954 struct be_dma_mem get_mac_list_cmd;
2955 int i;
2956
2957 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2958 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2959 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302960 get_mac_list_cmd.size,
2961 &get_mac_list_cmd.dma);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002962
2963 if (!get_mac_list_cmd.va) {
2964 dev_err(&adapter->pdev->dev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302965 "Memory allocation failure during GET_MAC_LIST\n");
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002966 return -ENOMEM;
2967 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002968
2969 spin_lock_bh(&adapter->mcc_lock);
2970
2971 wrb = wrb_from_mccq(adapter);
2972 if (!wrb) {
2973 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002974 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002975 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002976
2977 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002978
2979 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00002980 OPCODE_COMMON_GET_MAC_LIST,
2981 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002982 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002983 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05302984 if (*pmac_id_valid) {
2985 req->mac_id = cpu_to_le32(*pmac_id);
Suresh Reddyb188f092014-01-15 13:23:39 +05302986 req->iface_id = cpu_to_le16(if_handle);
Sathya Perla5a712c12013-07-23 15:24:59 +05302987 req->perm_override = 0;
2988 } else {
2989 req->perm_override = 1;
2990 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002991
2992 status = be_mcc_notify_wait(adapter);
2993 if (!status) {
2994 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002995 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05302996
2997 if (*pmac_id_valid) {
2998 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
2999 ETH_ALEN);
3000 goto out;
3001 }
3002
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003003 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
3004 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003005 * or one or more true or pseudo permanant mac addresses.
3006 * If an active mac_id is present, return first active mac_id
3007 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003008 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003009 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003010 struct get_list_macaddr *mac_entry;
3011 u16 mac_addr_size;
3012 u32 mac_id;
3013
3014 mac_entry = &resp->macaddr_list[i];
3015 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
3016 /* mac_id is a 32 bit value and mac_addr size
3017 * is 6 bytes
3018 */
3019 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05303020 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003021 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
3022 *pmac_id = le32_to_cpu(mac_id);
3023 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003024 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003025 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003026 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05303027 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003028 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303029 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003030 }
3031
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003032out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003033 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003034 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303035 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003036 return status;
3037}
3038
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303039int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id,
3040 u8 *mac, u32 if_handle, bool active, u32 domain)
Sathya Perla5a712c12013-07-23 15:24:59 +05303041{
Sathya Perla5a712c12013-07-23 15:24:59 +05303042
Suresh Reddyb188f092014-01-15 13:23:39 +05303043 if (!active)
3044 be_cmd_get_mac_from_list(adapter, mac, &active, &curr_pmac_id,
3045 if_handle, domain);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303046 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05303047 return be_cmd_mac_addr_query(adapter, mac, false,
Suresh Reddyb188f092014-01-15 13:23:39 +05303048 if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303049 else
3050 /* Fetch the MAC address using pmac_id */
3051 return be_cmd_get_mac_from_list(adapter, mac, &active,
Suresh Reddyb188f092014-01-15 13:23:39 +05303052 &curr_pmac_id,
3053 if_handle, domain);
Sathya Perla5a712c12013-07-23 15:24:59 +05303054}
3055
Sathya Perla95046b92013-07-23 15:25:02 +05303056int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
3057{
3058 int status;
3059 bool pmac_valid = false;
3060
3061 memset(mac, 0, ETH_ALEN);
3062
Sathya Perla3175d8c2013-07-23 15:25:03 +05303063 if (BEx_chip(adapter)) {
3064 if (be_physfn(adapter))
3065 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
3066 0);
3067 else
3068 status = be_cmd_mac_addr_query(adapter, mac, false,
3069 adapter->if_handle, 0);
3070 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05303071 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
Suresh Reddyb188f092014-01-15 13:23:39 +05303072 NULL, adapter->if_handle, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303073 }
3074
Sathya Perla95046b92013-07-23 15:25:02 +05303075 return status;
3076}
3077
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003078/* Uses synchronous MCCQ */
3079int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
3080 u8 mac_count, u32 domain)
3081{
3082 struct be_mcc_wrb *wrb;
3083 struct be_cmd_req_set_mac_list *req;
3084 int status;
3085 struct be_dma_mem cmd;
3086
3087 memset(&cmd, 0, sizeof(struct be_dma_mem));
3088 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
3089 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303090 &cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00003091 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003092 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003093
3094 spin_lock_bh(&adapter->mcc_lock);
3095
3096 wrb = wrb_from_mccq(adapter);
3097 if (!wrb) {
3098 status = -EBUSY;
3099 goto err;
3100 }
3101
3102 req = cmd.va;
3103 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303104 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
3105 wrb, &cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003106
3107 req->hdr.domain = domain;
3108 req->mac_count = mac_count;
3109 if (mac_count)
3110 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
3111
3112 status = be_mcc_notify_wait(adapter);
3113
3114err:
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303115 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003116 spin_unlock_bh(&adapter->mcc_lock);
3117 return status;
3118}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003119
Sathya Perla3175d8c2013-07-23 15:25:03 +05303120/* Wrapper to delete any active MACs and provision the new mac.
3121 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
3122 * current list are active.
3123 */
3124int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
3125{
3126 bool active_mac = false;
3127 u8 old_mac[ETH_ALEN];
3128 u32 pmac_id;
3129 int status;
3130
3131 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303132 &pmac_id, if_id, dom);
3133
Sathya Perla3175d8c2013-07-23 15:25:03 +05303134 if (!status && active_mac)
3135 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
3136
3137 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
3138}
3139
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003140int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003141 u32 domain, u16 intf_id, u16 hsw_mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003142{
3143 struct be_mcc_wrb *wrb;
3144 struct be_cmd_req_set_hsw_config *req;
3145 void *ctxt;
3146 int status;
3147
3148 spin_lock_bh(&adapter->mcc_lock);
3149
3150 wrb = wrb_from_mccq(adapter);
3151 if (!wrb) {
3152 status = -EBUSY;
3153 goto err;
3154 }
3155
3156 req = embedded_payload(wrb);
3157 ctxt = &req->context;
3158
3159 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303160 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb,
3161 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003162
3163 req->hdr.domain = domain;
3164 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
3165 if (pvid) {
3166 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
3167 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
3168 }
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003169 if (!BEx_chip(adapter) && hsw_mode) {
3170 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id,
3171 ctxt, adapter->hba_port_num);
3172 AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1);
3173 AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type,
3174 ctxt, hsw_mode);
3175 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003176
3177 be_dws_cpu_to_le(req->context, sizeof(req->context));
3178 status = be_mcc_notify_wait(adapter);
3179
3180err:
3181 spin_unlock_bh(&adapter->mcc_lock);
3182 return status;
3183}
3184
3185/* Get Hyper switch config */
3186int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003187 u32 domain, u16 intf_id, u8 *mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003188{
3189 struct be_mcc_wrb *wrb;
3190 struct be_cmd_req_get_hsw_config *req;
3191 void *ctxt;
3192 int status;
3193 u16 vid;
3194
3195 spin_lock_bh(&adapter->mcc_lock);
3196
3197 wrb = wrb_from_mccq(adapter);
3198 if (!wrb) {
3199 status = -EBUSY;
3200 goto err;
3201 }
3202
3203 req = embedded_payload(wrb);
3204 ctxt = &req->context;
3205
3206 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303207 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb,
3208 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003209
3210 req->hdr.domain = domain;
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003211 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3212 ctxt, intf_id);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003213 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003214
Vasundhara Volam2c07c1d2014-01-15 13:23:32 +05303215 if (!BEx_chip(adapter) && mode) {
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003216 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3217 ctxt, adapter->hba_port_num);
3218 AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1);
3219 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003220 be_dws_cpu_to_le(req->context, sizeof(req->context));
3221
3222 status = be_mcc_notify_wait(adapter);
3223 if (!status) {
3224 struct be_cmd_resp_get_hsw_config *resp =
3225 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303226
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303227 be_dws_le_to_cpu(&resp->context, sizeof(resp->context));
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003228 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303229 pvid, &resp->context);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003230 if (pvid)
3231 *pvid = le16_to_cpu(vid);
3232 if (mode)
3233 *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3234 port_fwd_type, &resp->context);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003235 }
3236
3237err:
3238 spin_unlock_bh(&adapter->mcc_lock);
3239 return status;
3240}
3241
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003242int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
3243{
3244 struct be_mcc_wrb *wrb;
3245 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303246 int status = 0;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003247 struct be_dma_mem cmd;
3248
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003249 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
3250 CMD_SUBSYSTEM_ETH))
3251 return -EPERM;
3252
Suresh Reddy76a9e082014-01-15 13:23:40 +05303253 if (be_is_wol_excluded(adapter))
3254 return status;
3255
Suresh Reddyd98ef502013-04-25 00:56:55 +00003256 if (mutex_lock_interruptible(&adapter->mbox_lock))
3257 return -1;
3258
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003259 memset(&cmd, 0, sizeof(struct be_dma_mem));
3260 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303261 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003262 if (!cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303263 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003264 status = -ENOMEM;
3265 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003266 }
3267
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003268 wrb = wrb_from_mbox(adapter);
3269 if (!wrb) {
3270 status = -EBUSY;
3271 goto err;
3272 }
3273
3274 req = cmd.va;
3275
3276 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
3277 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
Suresh Reddy76a9e082014-01-15 13:23:40 +05303278 sizeof(*req), wrb, &cmd);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003279
3280 req->hdr.version = 1;
3281 req->query_options = BE_GET_WOL_CAP;
3282
3283 status = be_mbox_notify_wait(adapter);
3284 if (!status) {
3285 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05303286
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003287 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
3288
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003289 adapter->wol_cap = resp->wol_settings;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303290 if (adapter->wol_cap & BE_WOL_CAP)
3291 adapter->wol_en = true;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003292 }
3293err:
3294 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003295 if (cmd.va)
3296 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003297 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00003298
3299}
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303300
3301int be_cmd_set_fw_log_level(struct be_adapter *adapter, u32 level)
3302{
3303 struct be_dma_mem extfat_cmd;
3304 struct be_fat_conf_params *cfgs;
3305 int status;
3306 int i, j;
3307
3308 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3309 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
3310 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
3311 &extfat_cmd.dma);
3312 if (!extfat_cmd.va)
3313 return -ENOMEM;
3314
3315 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3316 if (status)
3317 goto err;
3318
3319 cfgs = (struct be_fat_conf_params *)
3320 (extfat_cmd.va + sizeof(struct be_cmd_resp_hdr));
3321 for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
3322 u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303323
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303324 for (j = 0; j < num_modes; j++) {
3325 if (cfgs->module[i].trace_lvl[j].mode == MODE_UART)
3326 cfgs->module[i].trace_lvl[j].dbg_lvl =
3327 cpu_to_le32(level);
3328 }
3329 }
3330
3331 status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd, cfgs);
3332err:
3333 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
3334 extfat_cmd.dma);
3335 return status;
3336}
3337
3338int be_cmd_get_fw_log_level(struct be_adapter *adapter)
3339{
3340 struct be_dma_mem extfat_cmd;
3341 struct be_fat_conf_params *cfgs;
3342 int status, j;
3343 int level = 0;
3344
3345 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3346 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
3347 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
3348 &extfat_cmd.dma);
3349
3350 if (!extfat_cmd.va) {
3351 dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
3352 __func__);
3353 goto err;
3354 }
3355
3356 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3357 if (!status) {
3358 cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
3359 sizeof(struct be_cmd_resp_hdr));
Kalesh AP03d28ff2014-09-19 15:46:56 +05303360
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303361 for (j = 0; j < le32_to_cpu(cfgs->module[0].num_modes); j++) {
3362 if (cfgs->module[0].trace_lvl[j].mode == MODE_UART)
3363 level = cfgs->module[0].trace_lvl[j].dbg_lvl;
3364 }
3365 }
3366 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
3367 extfat_cmd.dma);
3368err:
3369 return level;
3370}
3371
Somnath Kotur941a77d2012-05-17 22:59:03 +00003372int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
3373 struct be_dma_mem *cmd)
3374{
3375 struct be_mcc_wrb *wrb;
3376 struct be_cmd_req_get_ext_fat_caps *req;
3377 int status;
3378
3379 if (mutex_lock_interruptible(&adapter->mbox_lock))
3380 return -1;
3381
3382 wrb = wrb_from_mbox(adapter);
3383 if (!wrb) {
3384 status = -EBUSY;
3385 goto err;
3386 }
3387
3388 req = cmd->va;
3389 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3390 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
3391 cmd->size, wrb, cmd);
3392 req->parameter_type = cpu_to_le32(1);
3393
3394 status = be_mbox_notify_wait(adapter);
3395err:
3396 mutex_unlock(&adapter->mbox_lock);
3397 return status;
3398}
3399
3400int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
3401 struct be_dma_mem *cmd,
3402 struct be_fat_conf_params *configs)
3403{
3404 struct be_mcc_wrb *wrb;
3405 struct be_cmd_req_set_ext_fat_caps *req;
3406 int status;
3407
3408 spin_lock_bh(&adapter->mcc_lock);
3409
3410 wrb = wrb_from_mccq(adapter);
3411 if (!wrb) {
3412 status = -EBUSY;
3413 goto err;
3414 }
3415
3416 req = cmd->va;
3417 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
3418 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3419 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
3420 cmd->size, wrb, cmd);
3421
3422 status = be_mcc_notify_wait(adapter);
3423err:
3424 spin_unlock_bh(&adapter->mcc_lock);
3425 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003426}
Parav Pandit6a4ab662012-03-26 14:27:12 +00003427
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003428int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
3429{
3430 struct be_mcc_wrb *wrb;
3431 struct be_cmd_req_get_port_name *req;
3432 int status;
3433
3434 if (!lancer_chip(adapter)) {
3435 *port_name = adapter->hba_port_num + '0';
3436 return 0;
3437 }
3438
3439 spin_lock_bh(&adapter->mcc_lock);
3440
3441 wrb = wrb_from_mccq(adapter);
3442 if (!wrb) {
3443 status = -EBUSY;
3444 goto err;
3445 }
3446
3447 req = embedded_payload(wrb);
3448
3449 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3450 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
3451 NULL);
3452 req->hdr.version = 1;
3453
3454 status = be_mcc_notify_wait(adapter);
3455 if (!status) {
3456 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303457
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003458 *port_name = resp->port_name[adapter->hba_port_num];
3459 } else {
3460 *port_name = adapter->hba_port_num + '0';
3461 }
3462err:
3463 spin_unlock_bh(&adapter->mcc_lock);
3464 return status;
3465}
3466
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303467/* Descriptor type */
3468enum {
3469 FUNC_DESC = 1,
3470 VFT_DESC = 2
3471};
3472
3473static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
3474 int desc_type)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003475{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303476 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303477 struct be_nic_res_desc *nic;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003478 int i;
3479
3480 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303481 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303482 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) {
3483 nic = (struct be_nic_res_desc *)hdr;
3484 if (desc_type == FUNC_DESC ||
3485 (desc_type == VFT_DESC &&
3486 nic->flags & (1 << VFT_SHIFT)))
3487 return nic;
3488 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003489
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303490 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3491 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003492 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303493 return NULL;
3494}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003495
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303496static struct be_nic_res_desc *be_get_vft_desc(u8 *buf, u32 desc_count)
3497{
3498 return be_get_nic_desc(buf, desc_count, VFT_DESC);
3499}
3500
3501static struct be_nic_res_desc *be_get_func_nic_desc(u8 *buf, u32 desc_count)
3502{
3503 return be_get_nic_desc(buf, desc_count, FUNC_DESC);
3504}
3505
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303506static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3507 u32 desc_count)
3508{
3509 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3510 struct be_pcie_res_desc *pcie;
3511 int i;
3512
3513 for (i = 0; i < desc_count; i++) {
3514 if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
3515 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) {
3516 pcie = (struct be_pcie_res_desc *)hdr;
3517 if (pcie->pf_num == devfn)
3518 return pcie;
3519 }
3520
3521 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3522 hdr = (void *)hdr + hdr->desc_len;
3523 }
Wei Yang950e2952013-05-22 15:58:22 +00003524 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003525}
3526
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303527static struct be_port_res_desc *be_get_port_desc(u8 *buf, u32 desc_count)
3528{
3529 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3530 int i;
3531
3532 for (i = 0; i < desc_count; i++) {
3533 if (hdr->desc_type == PORT_RESOURCE_DESC_TYPE_V1)
3534 return (struct be_port_res_desc *)hdr;
3535
3536 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3537 hdr = (void *)hdr + hdr->desc_len;
3538 }
3539 return NULL;
3540}
3541
Sathya Perla92bf14a2013-08-27 16:57:32 +05303542static void be_copy_nic_desc(struct be_resources *res,
3543 struct be_nic_res_desc *desc)
3544{
3545 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3546 res->max_vlans = le16_to_cpu(desc->vlan_count);
3547 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3548 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3549 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3550 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3551 res->max_evt_qs = le16_to_cpu(desc->eq_count);
3552 /* Clear flags that driver is not interested in */
3553 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3554 BE_IF_CAP_FLAGS_WANT;
3555 /* Need 1 RXQ as the default RXQ */
3556 if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs)
3557 res->max_rss_qs -= 1;
3558}
3559
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003560/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303561int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003562{
3563 struct be_mcc_wrb *wrb;
3564 struct be_cmd_req_get_func_config *req;
3565 int status;
3566 struct be_dma_mem cmd;
3567
Suresh Reddyd98ef502013-04-25 00:56:55 +00003568 if (mutex_lock_interruptible(&adapter->mbox_lock))
3569 return -1;
3570
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003571 memset(&cmd, 0, sizeof(struct be_dma_mem));
3572 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303573 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003574 if (!cmd.va) {
3575 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003576 status = -ENOMEM;
3577 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003578 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003579
3580 wrb = wrb_from_mbox(adapter);
3581 if (!wrb) {
3582 status = -EBUSY;
3583 goto err;
3584 }
3585
3586 req = cmd.va;
3587
3588 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3589 OPCODE_COMMON_GET_FUNC_CONFIG,
3590 cmd.size, wrb, &cmd);
3591
Kalesh AP28710c52013-04-28 22:21:13 +00003592 if (skyhawk_chip(adapter))
3593 req->hdr.version = 1;
3594
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003595 status = be_mbox_notify_wait(adapter);
3596 if (!status) {
3597 struct be_cmd_resp_get_func_config *resp = cmd.va;
3598 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303599 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003600
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303601 desc = be_get_func_nic_desc(resp->func_param, desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003602 if (!desc) {
3603 status = -EINVAL;
3604 goto err;
3605 }
3606
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003607 adapter->pf_number = desc->pf_num;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303608 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003609 }
3610err:
3611 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003612 if (cmd.va)
3613 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003614 return status;
3615}
3616
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303617/* Will use MBOX only if MCCQ has not been created */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303618int be_cmd_get_profile_config(struct be_adapter *adapter,
3619 struct be_resources *res, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003620{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303621 struct be_cmd_resp_get_profile_config *resp;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303622 struct be_cmd_req_get_profile_config *req;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303623 struct be_nic_res_desc *vf_res;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303624 struct be_pcie_res_desc *pcie;
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303625 struct be_port_res_desc *port;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303626 struct be_nic_res_desc *nic;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303627 struct be_mcc_wrb wrb = {0};
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003628 struct be_dma_mem cmd;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303629 u32 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003630 int status;
3631
3632 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303633 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3634 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3635 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003636 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003637
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303638 req = cmd.va;
3639 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3640 OPCODE_COMMON_GET_PROFILE_CONFIG,
3641 cmd.size, &wrb, &cmd);
3642
3643 req->hdr.domain = domain;
3644 if (!lancer_chip(adapter))
3645 req->hdr.version = 1;
3646 req->type = ACTIVE_PROFILE_TYPE;
3647
3648 status = be_cmd_notify_wait(adapter, &wrb);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303649 if (status)
3650 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003651
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303652 resp = cmd.va;
3653 desc_count = le32_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003654
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303655 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3656 desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303657 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303658 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303659
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303660 port = be_get_port_desc(resp->func_param, desc_count);
3661 if (port)
3662 adapter->mc_type = port->mc_type;
3663
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303664 nic = be_get_func_nic_desc(resp->func_param, desc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303665 if (nic)
3666 be_copy_nic_desc(res, nic);
3667
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303668 vf_res = be_get_vft_desc(resp->func_param, desc_count);
3669 if (vf_res)
3670 res->vf_if_cap_flags = vf_res->cap_flags;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003671err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003672 if (cmd.va)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303673 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003674 return status;
3675}
3676
Vasundhara Volambec84e62014-06-30 13:01:32 +05303677/* Will use MBOX only if MCCQ has not been created */
3678static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc,
3679 int size, int count, u8 version, u8 domain)
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003680{
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003681 struct be_cmd_req_set_profile_config *req;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303682 struct be_mcc_wrb wrb = {0};
3683 struct be_dma_mem cmd;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003684 int status;
3685
Vasundhara Volambec84e62014-06-30 13:01:32 +05303686 memset(&cmd, 0, sizeof(struct be_dma_mem));
3687 cmd.size = sizeof(struct be_cmd_req_set_profile_config);
3688 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3689 if (!cmd.va)
3690 return -ENOMEM;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003691
Vasundhara Volambec84e62014-06-30 13:01:32 +05303692 req = cmd.va;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003693 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303694 OPCODE_COMMON_SET_PROFILE_CONFIG, cmd.size,
3695 &wrb, &cmd);
Sathya Perlaa4018012014-03-27 10:46:18 +05303696 req->hdr.version = version;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003697 req->hdr.domain = domain;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303698 req->desc_count = cpu_to_le32(count);
Sathya Perlaa4018012014-03-27 10:46:18 +05303699 memcpy(req->desc, desc, size);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003700
Vasundhara Volambec84e62014-06-30 13:01:32 +05303701 status = be_cmd_notify_wait(adapter, &wrb);
3702
3703 if (cmd.va)
3704 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003705 return status;
3706}
3707
Sathya Perlaa4018012014-03-27 10:46:18 +05303708/* Mark all fields invalid */
Vasundhara Volambec84e62014-06-30 13:01:32 +05303709static void be_reset_nic_desc(struct be_nic_res_desc *nic)
Sathya Perlaa4018012014-03-27 10:46:18 +05303710{
3711 memset(nic, 0, sizeof(*nic));
3712 nic->unicast_mac_count = 0xFFFF;
3713 nic->mcc_count = 0xFFFF;
3714 nic->vlan_count = 0xFFFF;
3715 nic->mcast_mac_count = 0xFFFF;
3716 nic->txq_count = 0xFFFF;
3717 nic->rq_count = 0xFFFF;
3718 nic->rssq_count = 0xFFFF;
3719 nic->lro_count = 0xFFFF;
3720 nic->cq_count = 0xFFFF;
3721 nic->toe_conn_count = 0xFFFF;
3722 nic->eq_count = 0xFFFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303723 nic->iface_count = 0xFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303724 nic->link_param = 0xFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303725 nic->channel_id_param = cpu_to_le16(0xF000);
Sathya Perlaa4018012014-03-27 10:46:18 +05303726 nic->acpi_params = 0xFF;
3727 nic->wol_param = 0x0F;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303728 nic->tunnel_iface_count = 0xFFFF;
3729 nic->direct_tenant_iface_count = 0xFFFF;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303730 nic->bw_min = 0xFFFFFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303731 nic->bw_max = 0xFFFFFFFF;
3732}
3733
Vasundhara Volambec84e62014-06-30 13:01:32 +05303734/* Mark all fields invalid */
3735static void be_reset_pcie_desc(struct be_pcie_res_desc *pcie)
3736{
3737 memset(pcie, 0, sizeof(*pcie));
3738 pcie->sriov_state = 0xFF;
3739 pcie->pf_state = 0xFF;
3740 pcie->pf_type = 0xFF;
3741 pcie->num_vfs = 0xFFFF;
3742}
3743
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303744int be_cmd_config_qos(struct be_adapter *adapter, u32 max_rate, u16 link_speed,
3745 u8 domain)
Sathya Perlaa4018012014-03-27 10:46:18 +05303746{
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303747 struct be_nic_res_desc nic_desc;
3748 u32 bw_percent;
3749 u16 version = 0;
Sathya Perlaa4018012014-03-27 10:46:18 +05303750
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303751 if (BE3_chip(adapter))
3752 return be_cmd_set_qos(adapter, max_rate / 10, domain);
3753
3754 be_reset_nic_desc(&nic_desc);
3755 nic_desc.pf_num = adapter->pf_number;
3756 nic_desc.vf_num = domain;
3757 if (lancer_chip(adapter)) {
Sathya Perlaa4018012014-03-27 10:46:18 +05303758 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
3759 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
3760 nic_desc.flags = (1 << QUN_SHIFT) | (1 << IMM_SHIFT) |
3761 (1 << NOSV_SHIFT);
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303762 nic_desc.bw_max = cpu_to_le32(max_rate / 10);
Sathya Perlaa4018012014-03-27 10:46:18 +05303763 } else {
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303764 version = 1;
3765 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3766 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3767 nic_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3768 bw_percent = max_rate ? (max_rate * 100) / link_speed : 100;
3769 nic_desc.bw_max = cpu_to_le32(bw_percent);
Sathya Perlaa4018012014-03-27 10:46:18 +05303770 }
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303771
3772 return be_cmd_set_profile_config(adapter, &nic_desc,
3773 nic_desc.hdr.desc_len,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303774 1, version, domain);
3775}
3776
3777int be_cmd_set_sriov_config(struct be_adapter *adapter,
3778 struct be_resources res, u16 num_vfs)
3779{
3780 struct {
3781 struct be_pcie_res_desc pcie;
3782 struct be_nic_res_desc nic_vft;
3783 } __packed desc;
3784 u16 vf_q_count;
3785
3786 if (BEx_chip(adapter) || lancer_chip(adapter))
3787 return 0;
3788
3789 /* PF PCIE descriptor */
3790 be_reset_pcie_desc(&desc.pcie);
3791 desc.pcie.hdr.desc_type = PCIE_RESOURCE_DESC_TYPE_V1;
3792 desc.pcie.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3793 desc.pcie.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3794 desc.pcie.pf_num = adapter->pdev->devfn;
3795 desc.pcie.sriov_state = num_vfs ? 1 : 0;
3796 desc.pcie.num_vfs = cpu_to_le16(num_vfs);
3797
3798 /* VF NIC Template descriptor */
3799 be_reset_nic_desc(&desc.nic_vft);
3800 desc.nic_vft.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3801 desc.nic_vft.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3802 desc.nic_vft.flags = (1 << VFT_SHIFT) | (1 << IMM_SHIFT) |
3803 (1 << NOSV_SHIFT);
3804 desc.nic_vft.pf_num = adapter->pdev->devfn;
3805 desc.nic_vft.vf_num = 0;
3806
3807 if (num_vfs && res.vf_if_cap_flags & BE_IF_FLAGS_RSS) {
3808 /* If number of VFs requested is 8 less than max supported,
3809 * assign 8 queue pairs to the PF and divide the remaining
3810 * resources evenly among the VFs
3811 */
3812 if (num_vfs < (be_max_vfs(adapter) - 8))
3813 vf_q_count = (res.max_rss_qs - 8) / num_vfs;
3814 else
3815 vf_q_count = res.max_rss_qs / num_vfs;
3816
3817 desc.nic_vft.rq_count = cpu_to_le16(vf_q_count);
3818 desc.nic_vft.txq_count = cpu_to_le16(vf_q_count);
3819 desc.nic_vft.rssq_count = cpu_to_le16(vf_q_count - 1);
3820 desc.nic_vft.cq_count = cpu_to_le16(3 * vf_q_count);
3821 } else {
3822 desc.nic_vft.txq_count = cpu_to_le16(1);
3823 desc.nic_vft.rq_count = cpu_to_le16(1);
3824 desc.nic_vft.rssq_count = cpu_to_le16(0);
3825 /* One CQ for each TX, RX and MCCQ */
3826 desc.nic_vft.cq_count = cpu_to_le16(3);
3827 }
3828
3829 return be_cmd_set_profile_config(adapter, &desc,
3830 2 * RESOURCE_DESC_SIZE_V1, 2, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303831}
3832
3833int be_cmd_manage_iface(struct be_adapter *adapter, u32 iface, u8 op)
3834{
3835 struct be_mcc_wrb *wrb;
3836 struct be_cmd_req_manage_iface_filters *req;
3837 int status;
3838
3839 if (iface == 0xFFFFFFFF)
3840 return -1;
3841
3842 spin_lock_bh(&adapter->mcc_lock);
3843
3844 wrb = wrb_from_mccq(adapter);
3845 if (!wrb) {
3846 status = -EBUSY;
3847 goto err;
3848 }
3849 req = embedded_payload(wrb);
3850
3851 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3852 OPCODE_COMMON_MANAGE_IFACE_FILTERS, sizeof(*req),
3853 wrb, NULL);
3854 req->op = op;
3855 req->target_iface_id = cpu_to_le32(iface);
3856
3857 status = be_mcc_notify_wait(adapter);
3858err:
3859 spin_unlock_bh(&adapter->mcc_lock);
3860 return status;
3861}
3862
3863int be_cmd_set_vxlan_port(struct be_adapter *adapter, __be16 port)
3864{
3865 struct be_port_res_desc port_desc;
3866
3867 memset(&port_desc, 0, sizeof(port_desc));
3868 port_desc.hdr.desc_type = PORT_RESOURCE_DESC_TYPE_V1;
3869 port_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3870 port_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3871 port_desc.link_num = adapter->hba_port_num;
3872 if (port) {
3873 port_desc.nv_flags = NV_TYPE_VXLAN | (1 << SOCVID_SHIFT) |
3874 (1 << RCVID_SHIFT);
3875 port_desc.nv_port = swab16(port);
3876 } else {
3877 port_desc.nv_flags = NV_TYPE_DISABLED;
3878 port_desc.nv_port = 0;
3879 }
3880
3881 return be_cmd_set_profile_config(adapter, &port_desc,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303882 RESOURCE_DESC_SIZE_V1, 1, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303883}
3884
Sathya Perla4c876612013-02-03 20:30:11 +00003885int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3886 int vf_num)
3887{
3888 struct be_mcc_wrb *wrb;
3889 struct be_cmd_req_get_iface_list *req;
3890 struct be_cmd_resp_get_iface_list *resp;
3891 int status;
3892
3893 spin_lock_bh(&adapter->mcc_lock);
3894
3895 wrb = wrb_from_mccq(adapter);
3896 if (!wrb) {
3897 status = -EBUSY;
3898 goto err;
3899 }
3900 req = embedded_payload(wrb);
3901
3902 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3903 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3904 wrb, NULL);
3905 req->hdr.domain = vf_num + 1;
3906
3907 status = be_mcc_notify_wait(adapter);
3908 if (!status) {
3909 resp = (struct be_cmd_resp_get_iface_list *)req;
3910 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3911 }
3912
3913err:
3914 spin_unlock_bh(&adapter->mcc_lock);
3915 return status;
3916}
3917
Somnath Kotur5c510812013-05-30 02:52:23 +00003918static int lancer_wait_idle(struct be_adapter *adapter)
3919{
3920#define SLIPORT_IDLE_TIMEOUT 30
3921 u32 reg_val;
3922 int status = 0, i;
3923
3924 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
3925 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
3926 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
3927 break;
3928
3929 ssleep(1);
3930 }
3931
3932 if (i == SLIPORT_IDLE_TIMEOUT)
3933 status = -1;
3934
3935 return status;
3936}
3937
3938int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
3939{
3940 int status = 0;
3941
3942 status = lancer_wait_idle(adapter);
3943 if (status)
3944 return status;
3945
3946 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
3947
3948 return status;
3949}
3950
3951/* Routine to check whether dump image is present or not */
3952bool dump_present(struct be_adapter *adapter)
3953{
3954 u32 sliport_status = 0;
3955
3956 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
3957 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
3958}
3959
3960int lancer_initiate_dump(struct be_adapter *adapter)
3961{
Kalesh APf0613382014-08-01 17:47:32 +05303962 struct device *dev = &adapter->pdev->dev;
Somnath Kotur5c510812013-05-30 02:52:23 +00003963 int status;
3964
Kalesh APf0613382014-08-01 17:47:32 +05303965 if (dump_present(adapter)) {
3966 dev_info(dev, "Previous dump not cleared, not forcing dump\n");
3967 return -EEXIST;
3968 }
3969
Somnath Kotur5c510812013-05-30 02:52:23 +00003970 /* give firmware reset and diagnostic dump */
3971 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
3972 PHYSDEV_CONTROL_DD_MASK);
3973 if (status < 0) {
Kalesh APf0613382014-08-01 17:47:32 +05303974 dev_err(dev, "FW reset failed\n");
Somnath Kotur5c510812013-05-30 02:52:23 +00003975 return status;
3976 }
3977
3978 status = lancer_wait_idle(adapter);
3979 if (status)
3980 return status;
3981
3982 if (!dump_present(adapter)) {
Kalesh APf0613382014-08-01 17:47:32 +05303983 dev_err(dev, "FW dump not generated\n");
3984 return -EIO;
Somnath Kotur5c510812013-05-30 02:52:23 +00003985 }
3986
3987 return 0;
3988}
3989
Kalesh APf0613382014-08-01 17:47:32 +05303990int lancer_delete_dump(struct be_adapter *adapter)
3991{
3992 int status;
3993
3994 status = lancer_cmd_delete_object(adapter, LANCER_FW_DUMP_FILE);
3995 return be_cmd_status(status);
3996}
3997
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003998/* Uses sync mcc */
3999int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
4000{
4001 struct be_mcc_wrb *wrb;
4002 struct be_cmd_enable_disable_vf *req;
4003 int status;
4004
Vasundhara Volam05998632013-10-01 15:59:59 +05304005 if (BEx_chip(adapter))
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004006 return 0;
4007
4008 spin_lock_bh(&adapter->mcc_lock);
4009
4010 wrb = wrb_from_mccq(adapter);
4011 if (!wrb) {
4012 status = -EBUSY;
4013 goto err;
4014 }
4015
4016 req = embedded_payload(wrb);
4017
4018 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4019 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
4020 wrb, NULL);
4021
4022 req->hdr.domain = domain;
4023 req->enable = 1;
4024 status = be_mcc_notify_wait(adapter);
4025err:
4026 spin_unlock_bh(&adapter->mcc_lock);
4027 return status;
4028}
4029
Somnath Kotur68c45a22013-03-14 02:42:07 +00004030int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
4031{
4032 struct be_mcc_wrb *wrb;
4033 struct be_cmd_req_intr_set *req;
4034 int status;
4035
4036 if (mutex_lock_interruptible(&adapter->mbox_lock))
4037 return -1;
4038
4039 wrb = wrb_from_mbox(adapter);
4040
4041 req = embedded_payload(wrb);
4042
4043 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4044 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
4045 wrb, NULL);
4046
4047 req->intr_enabled = intr_enable;
4048
4049 status = be_mbox_notify_wait(adapter);
4050
4051 mutex_unlock(&adapter->mbox_lock);
4052 return status;
4053}
4054
Vasundhara Volam542963b2014-01-15 13:23:33 +05304055/* Uses MBOX */
4056int be_cmd_get_active_profile(struct be_adapter *adapter, u16 *profile_id)
4057{
4058 struct be_cmd_req_get_active_profile *req;
4059 struct be_mcc_wrb *wrb;
4060 int status;
4061
4062 if (mutex_lock_interruptible(&adapter->mbox_lock))
4063 return -1;
4064
4065 wrb = wrb_from_mbox(adapter);
4066 if (!wrb) {
4067 status = -EBUSY;
4068 goto err;
4069 }
4070
4071 req = embedded_payload(wrb);
4072
4073 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4074 OPCODE_COMMON_GET_ACTIVE_PROFILE, sizeof(*req),
4075 wrb, NULL);
4076
4077 status = be_mbox_notify_wait(adapter);
4078 if (!status) {
4079 struct be_cmd_resp_get_active_profile *resp =
4080 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304081
Vasundhara Volam542963b2014-01-15 13:23:33 +05304082 *profile_id = le16_to_cpu(resp->active_profile_id);
4083 }
4084
4085err:
4086 mutex_unlock(&adapter->mbox_lock);
4087 return status;
4088}
4089
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304090int be_cmd_set_logical_link_config(struct be_adapter *adapter,
4091 int link_state, u8 domain)
4092{
4093 struct be_mcc_wrb *wrb;
4094 struct be_cmd_req_set_ll_link *req;
4095 int status;
4096
4097 if (BEx_chip(adapter) || lancer_chip(adapter))
4098 return 0;
4099
4100 spin_lock_bh(&adapter->mcc_lock);
4101
4102 wrb = wrb_from_mccq(adapter);
4103 if (!wrb) {
4104 status = -EBUSY;
4105 goto err;
4106 }
4107
4108 req = embedded_payload(wrb);
4109
4110 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4111 OPCODE_COMMON_SET_LOGICAL_LINK_CONFIG,
4112 sizeof(*req), wrb, NULL);
4113
4114 req->hdr.version = 1;
4115 req->hdr.domain = domain;
4116
4117 if (link_state == IFLA_VF_LINK_STATE_ENABLE)
4118 req->link_config |= 1;
4119
4120 if (link_state == IFLA_VF_LINK_STATE_AUTO)
4121 req->link_config |= 1 << PLINK_TRACK_SHIFT;
4122
4123 status = be_mcc_notify_wait(adapter);
4124err:
4125 spin_unlock_bh(&adapter->mcc_lock);
4126 return status;
4127}
4128
Parav Pandit6a4ab662012-03-26 14:27:12 +00004129int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05304130 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
Parav Pandit6a4ab662012-03-26 14:27:12 +00004131{
4132 struct be_adapter *adapter = netdev_priv(netdev_handle);
4133 struct be_mcc_wrb *wrb;
4134 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
4135 struct be_cmd_req_hdr *req;
4136 struct be_cmd_resp_hdr *resp;
4137 int status;
4138
4139 spin_lock_bh(&adapter->mcc_lock);
4140
4141 wrb = wrb_from_mccq(adapter);
4142 if (!wrb) {
4143 status = -EBUSY;
4144 goto err;
4145 }
4146 req = embedded_payload(wrb);
4147 resp = embedded_payload(wrb);
4148
4149 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
4150 hdr->opcode, wrb_payload_size, wrb, NULL);
4151 memcpy(req, wrb_payload, wrb_payload_size);
4152 be_dws_cpu_to_le(req, wrb_payload_size);
4153
4154 status = be_mcc_notify_wait(adapter);
4155 if (cmd_status)
4156 *cmd_status = (status & 0xffff);
4157 if (ext_status)
4158 *ext_status = 0;
4159 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
4160 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
4161err:
4162 spin_unlock_bh(&adapter->mcc_lock);
4163 return status;
4164}
4165EXPORT_SYMBOL(be_roce_mcc_cmd);