blob: 4d0ec3649a632dcb9e6fcf67eb638823f281b094 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volamc7bb15a2013-03-06 20:05:05 +00002 * Copyright (C) 2005 - 2013 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
55static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode,
56 u8 subsystem)
57{
58 int i;
59 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
60 u32 cmd_privileges = adapter->cmd_privileges;
61
62 for (i = 0; i < num_entries; i++)
63 if (opcode == cmd_priv_map[i].opcode &&
64 subsystem == cmd_priv_map[i].subsystem)
65 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
66 return false;
67
68 return true;
69}
70
Somnath Kotur3de09452011-09-30 07:25:05 +000071static inline void *embedded_payload(struct be_mcc_wrb *wrb)
72{
73 return wrb->payload.embedded_payload;
74}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000075
Sathya Perla8788fdc2009-07-27 22:52:03 +000076static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000077{
Sathya Perla8788fdc2009-07-27 22:52:03 +000078 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000079 u32 val = 0;
80
Sathya Perla6589ade2011-11-10 19:18:00 +000081 if (be_error(adapter))
Ajit Khaparde7acc2082011-02-11 13:38:17 +000082 return;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000083
Sathya Perla5fb379e2009-06-18 00:02:59 +000084 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
85 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000086
87 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000088 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000089}
90
91/* To check if valid bit is set, check the entire word as we don't know
92 * the endianness of the data (old entry is host endian while a new entry is
93 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000094static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000095{
Sathya Perla9e9ff4b2013-02-12 23:05:19 +000096 u32 flags;
97
Sathya Perla5fb379e2009-06-18 00:02:59 +000098 if (compl->flags != 0) {
Sathya Perla9e9ff4b2013-02-12 23:05:19 +000099 flags = le32_to_cpu(compl->flags);
100 if (flags & CQE_FLAGS_VALID_MASK) {
101 compl->flags = flags;
102 return true;
103 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000104 }
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000105 return false;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000106}
107
108/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000109static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000110{
111 compl->flags = 0;
112}
113
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000114static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
115{
116 unsigned long addr;
117
118 addr = tag1;
119 addr = ((addr << 16) << 16) | tag0;
120 return (void *)addr;
121}
122
Sathya Perla8788fdc2009-07-27 22:52:03 +0000123static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000124 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000125{
126 u16 compl_status, extd_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000127 struct be_cmd_resp_hdr *resp_hdr;
128 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000129
130 /* Just swap the status to host endian; mcc tag is opaquely copied
131 * from mcc_wrb */
132 be_dws_le_to_cpu(compl, 4);
133
134 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
135 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -0700136
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000137 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
138
139 if (resp_hdr) {
140 opcode = resp_hdr->opcode;
141 subsystem = resp_hdr->subsystem;
142 }
143
144 if (((opcode == OPCODE_COMMON_WRITE_FLASHROM) ||
145 (opcode == OPCODE_COMMON_WRITE_OBJECT)) &&
146 (subsystem == CMD_SUBSYSTEM_COMMON)) {
Sarveshwar Bandidd131e72010-05-25 16:16:32 -0700147 adapter->flash_status = compl_status;
148 complete(&adapter->flash_compl);
149 }
150
Sathya Perlab31c50a2009-09-17 10:30:13 -0700151 if (compl_status == MCC_STATUS_SUCCESS) {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000152 if (((opcode == OPCODE_ETH_GET_STATISTICS) ||
153 (opcode == OPCODE_ETH_GET_PPORT_STATS)) &&
154 (subsystem == CMD_SUBSYSTEM_ETH)) {
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000155 be_parse_stats(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +0000156 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700157 }
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000158 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
159 subsystem == CMD_SUBSYSTEM_COMMON) {
Somnath Kotur3de09452011-09-30 07:25:05 +0000160 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000161 (void *)resp_hdr;
Somnath Kotur3de09452011-09-30 07:25:05 +0000162 adapter->drv_stats.be_on_die_temperature =
163 resp->on_die_temperature;
164 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000165 } else {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000166 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES)
Padmanabh Ratnakar7aeb2152012-07-12 03:56:46 +0000167 adapter->be_get_temp_freq = 0;
Somnath Kotur3de09452011-09-30 07:25:05 +0000168
Sathya Perla2b3f2912011-06-29 23:32:56 +0000169 if (compl_status == MCC_STATUS_NOT_SUPPORTED ||
170 compl_status == MCC_STATUS_ILLEGAL_REQUEST)
171 goto done;
172
173 if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000174 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000175 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000176 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000177 } else {
178 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
179 CQE_STATUS_EXTD_MASK;
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000180 dev_err(&adapter->pdev->dev,
181 "opcode %d-%d failed:status %d-%d\n",
182 opcode, subsystem, compl_status, extd_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000183 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000184 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000185done:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700186 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000187}
188
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000189/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000190static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000191 struct be_async_event_link_state *evt)
192{
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000193 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000194 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000195
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000196 /* Ignore physical link event */
197 if (lancer_chip(adapter) &&
198 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
199 return;
200
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000201 /* For the initial link status do not rely on the ASYNC event as
202 * it may not be received in some cases.
203 */
204 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
205 be_link_status_update(adapter, evt->port_link_status);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000206}
207
Somnath Koturcc4ce022010-10-21 07:11:14 -0700208/* Grp5 CoS Priority evt */
209static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
210 struct be_async_event_grp5_cos_priority *evt)
211{
212 if (evt->valid) {
213 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000214 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700215 adapter->recommended_prio =
216 evt->reco_default_priority << VLAN_PRIO_SHIFT;
217 }
218}
219
Sathya Perla323ff712012-09-28 04:39:43 +0000220/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700221static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
222 struct be_async_event_grp5_qos_link_speed *evt)
223{
Sathya Perla323ff712012-09-28 04:39:43 +0000224 if (adapter->phy.link_speed >= 0 &&
225 evt->physical_port == adapter->port_num)
226 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700227}
228
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000229/*Grp5 PVID evt*/
230static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
231 struct be_async_event_grp5_pvid_state *evt)
232{
233 if (evt->enabled)
Somnath Kotur939cf302011-08-18 21:51:49 -0700234 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000235 else
236 adapter->pvid = 0;
237}
238
Somnath Koturcc4ce022010-10-21 07:11:14 -0700239static void be_async_grp5_evt_process(struct be_adapter *adapter,
240 u32 trailer, struct be_mcc_compl *evt)
241{
242 u8 event_type = 0;
243
244 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
245 ASYNC_TRAILER_EVENT_TYPE_MASK;
246
247 switch (event_type) {
248 case ASYNC_EVENT_COS_PRIORITY:
249 be_async_grp5_cos_priority_process(adapter,
250 (struct be_async_event_grp5_cos_priority *)evt);
251 break;
252 case ASYNC_EVENT_QOS_SPEED:
253 be_async_grp5_qos_speed_process(adapter,
254 (struct be_async_event_grp5_qos_link_speed *)evt);
255 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000256 case ASYNC_EVENT_PVID_STATE:
257 be_async_grp5_pvid_state_process(adapter,
258 (struct be_async_event_grp5_pvid_state *)evt);
259 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700260 default:
261 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
262 break;
263 }
264}
265
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000266static void be_async_dbg_evt_process(struct be_adapter *adapter,
267 u32 trailer, struct be_mcc_compl *cmp)
268{
269 u8 event_type = 0;
270 struct be_async_event_qnq *evt = (struct be_async_event_qnq *) cmp;
271
272 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
273 ASYNC_TRAILER_EVENT_TYPE_MASK;
274
275 switch (event_type) {
276 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
277 if (evt->valid)
278 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
279 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
280 break;
281 default:
282 dev_warn(&adapter->pdev->dev, "Unknown debug event\n");
283 break;
284 }
285}
286
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000287static inline bool is_link_state_evt(u32 trailer)
288{
Eric Dumazet807540b2010-09-23 05:40:09 +0000289 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000290 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000291 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000292}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000293
Somnath Koturcc4ce022010-10-21 07:11:14 -0700294static inline bool is_grp5_evt(u32 trailer)
295{
296 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
297 ASYNC_TRAILER_EVENT_CODE_MASK) ==
298 ASYNC_EVENT_CODE_GRP_5);
299}
300
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000301static inline bool is_dbg_evt(u32 trailer)
302{
303 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
304 ASYNC_TRAILER_EVENT_CODE_MASK) ==
305 ASYNC_EVENT_CODE_QNQ);
306}
307
Sathya Perlaefd2e402009-07-27 22:53:10 +0000308static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000309{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000310 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000311 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000312
313 if (be_mcc_compl_is_new(compl)) {
314 queue_tail_inc(mcc_cq);
315 return compl;
316 }
317 return NULL;
318}
319
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000320void be_async_mcc_enable(struct be_adapter *adapter)
321{
322 spin_lock_bh(&adapter->mcc_cq_lock);
323
324 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
325 adapter->mcc_obj.rearm_cq = true;
326
327 spin_unlock_bh(&adapter->mcc_cq_lock);
328}
329
330void be_async_mcc_disable(struct be_adapter *adapter)
331{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000332 spin_lock_bh(&adapter->mcc_cq_lock);
333
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000334 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000335 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
336
337 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000338}
339
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000340int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000341{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000342 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000343 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000344 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000345
Amerigo Wang072a9c42012-08-24 21:41:11 +0000346 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla8788fdc2009-07-27 22:52:03 +0000347 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000348 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
349 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000350 if (is_link_state_evt(compl->flags))
351 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000352 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700353 else if (is_grp5_evt(compl->flags))
354 be_async_grp5_evt_process(adapter,
355 compl->flags, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000356 else if (is_dbg_evt(compl->flags))
357 be_async_dbg_evt_process(adapter,
358 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700359 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000360 status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000361 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000362 }
363 be_mcc_compl_use(compl);
364 num++;
365 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700366
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000367 if (num)
368 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
369
Amerigo Wang072a9c42012-08-24 21:41:11 +0000370 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000371 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000372}
373
Sathya Perla6ac7b682009-06-18 00:05:54 +0000374/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700375static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000376{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700377#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000378 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800379 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700380
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800381 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000382 if (be_error(adapter))
383 return -EIO;
384
Amerigo Wang072a9c42012-08-24 21:41:11 +0000385 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000386 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000387 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800388
389 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000390 break;
391 udelay(100);
392 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700393 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000394 dev_err(&adapter->pdev->dev, "FW not responding\n");
395 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000396 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700397 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800398 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000399}
400
401/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700402static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000403{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000404 int status;
405 struct be_mcc_wrb *wrb;
406 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
407 u16 index = mcc_obj->q.head;
408 struct be_cmd_resp_hdr *resp;
409
410 index_dec(&index, mcc_obj->q.len);
411 wrb = queue_index_node(&mcc_obj->q, index);
412
413 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
414
Sathya Perla8788fdc2009-07-27 22:52:03 +0000415 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000416
417 status = be_mcc_wait_compl(adapter);
418 if (status == -EIO)
419 goto out;
420
421 status = resp->status;
422out:
423 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000424}
425
Sathya Perla5f0b8492009-07-27 22:52:56 +0000426static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700427{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000428 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700429 u32 ready;
430
431 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000432 if (be_error(adapter))
433 return -EIO;
434
Sathya Perlacf588472010-02-14 21:22:01 +0000435 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000436 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000437 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000438
439 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700440 if (ready)
441 break;
442
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000443 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000444 dev_err(&adapter->pdev->dev, "FW not responding\n");
445 adapter->fw_timeout = true;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000446 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700447 return -1;
448 }
449
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000450 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000451 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452 } while (true);
453
454 return 0;
455}
456
457/*
458 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000459 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700460 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700461static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700462{
463 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700464 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000465 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
466 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700467 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000468 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700469
Sathya Perlacf588472010-02-14 21:22:01 +0000470 /* wait for ready to be set */
471 status = be_mbox_db_ready_wait(adapter, db);
472 if (status != 0)
473 return status;
474
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700475 val |= MPU_MAILBOX_DB_HI_MASK;
476 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
477 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
478 iowrite32(val, db);
479
480 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000481 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700482 if (status != 0)
483 return status;
484
485 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700486 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
487 val |= (u32)(mbox_mem->dma >> 4) << 2;
488 iowrite32(val, db);
489
Sathya Perla5f0b8492009-07-27 22:52:56 +0000490 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700491 if (status != 0)
492 return status;
493
Sathya Perla5fb379e2009-06-18 00:02:59 +0000494 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000495 if (be_mcc_compl_is_new(compl)) {
496 status = be_mcc_compl_process(adapter, &mbox->compl);
497 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000498 if (status)
499 return status;
500 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000501 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700502 return -1;
503 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000504 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700505}
506
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000507static u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700508{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000509 u32 sem;
510
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000511 if (BEx_chip(adapter))
512 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700513 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000514 pci_read_config_dword(adapter->pdev,
515 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
516
517 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700518}
519
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000520int lancer_wait_ready(struct be_adapter *adapter)
521{
522#define SLIPORT_READY_TIMEOUT 30
523 u32 sliport_status;
524 int status = 0, i;
525
526 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
527 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
528 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
529 break;
530
531 msleep(1000);
532 }
533
534 if (i == SLIPORT_READY_TIMEOUT)
535 status = -1;
536
537 return status;
538}
539
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000540static bool lancer_provisioning_error(struct be_adapter *adapter)
541{
542 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
543 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
544 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
545 sliport_err1 = ioread32(adapter->db +
546 SLIPORT_ERROR1_OFFSET);
547 sliport_err2 = ioread32(adapter->db +
548 SLIPORT_ERROR2_OFFSET);
549
550 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
551 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
552 return true;
553 }
554 return false;
555}
556
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000557int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
558{
559 int status;
560 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000561 bool resource_error;
562
563 resource_error = lancer_provisioning_error(adapter);
564 if (resource_error)
565 return -1;
566
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000567 status = lancer_wait_ready(adapter);
568 if (!status) {
569 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
570 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
571 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
572 if (err && reset_needed) {
573 iowrite32(SLI_PORT_CONTROL_IP_MASK,
574 adapter->db + SLIPORT_CONTROL_OFFSET);
575
576 /* check adapter has corrected the error */
577 status = lancer_wait_ready(adapter);
578 sliport_status = ioread32(adapter->db +
579 SLIPORT_STATUS_OFFSET);
580 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
581 SLIPORT_STATUS_RN_MASK);
582 if (status || sliport_status)
583 status = -1;
584 } else if (err || reset_needed) {
585 status = -1;
586 }
587 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000588 /* Stop error recovery if error is not recoverable.
589 * No resource error is temporary errors and will go away
590 * when PF provisions resources.
591 */
592 resource_error = lancer_provisioning_error(adapter);
593 if (status == -1 && !resource_error)
594 adapter->eeh_error = true;
595
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000596 return status;
597}
598
599int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700600{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000601 u16 stage;
602 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000603 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700604
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000605 if (lancer_chip(adapter)) {
606 status = lancer_wait_ready(adapter);
607 return status;
608 }
609
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000610 do {
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000611 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000612 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000613 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000614
615 dev_info(dev, "Waiting for POST, %ds elapsed\n",
616 timeout);
617 if (msleep_interruptible(2000)) {
618 dev_err(dev, "Waiting for POST aborted\n");
619 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000620 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000621 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000622 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700623
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000624 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000625 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700626}
627
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700628
629static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
630{
631 return &wrb->payload.sgl[0];
632}
633
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700634
635/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000636/* mem will be NULL for embedded commands */
637static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
638 u8 subsystem, u8 opcode, int cmd_len,
639 struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700640{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000641 struct be_sge *sge;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000642 unsigned long addr = (unsigned long)req_hdr;
643 u64 req_addr = addr;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000644
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700645 req_hdr->opcode = opcode;
646 req_hdr->subsystem = subsystem;
647 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000648 req_hdr->version = 0;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000649
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000650 wrb->tag0 = req_addr & 0xFFFFFFFF;
651 wrb->tag1 = upper_32_bits(req_addr);
652
Somnath Kotur106df1e2011-10-27 07:12:13 +0000653 wrb->payload_length = cmd_len;
654 if (mem) {
655 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
656 MCC_WRB_SGE_CNT_SHIFT;
657 sge = nonembedded_sgl(wrb);
658 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
659 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
660 sge->len = cpu_to_le32(mem->size);
661 } else
662 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
663 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700664}
665
666static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
667 struct be_dma_mem *mem)
668{
669 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
670 u64 dma = (u64)mem->dma;
671
672 for (i = 0; i < buf_pages; i++) {
673 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
674 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
675 dma += PAGE_SIZE_4K;
676 }
677}
678
679/* Converts interrupt delay in microseconds to multiplier value */
680static u32 eq_delay_to_mult(u32 usec_delay)
681{
682#define MAX_INTR_RATE 651042
683 const u32 round = 10;
684 u32 multiplier;
685
686 if (usec_delay == 0)
687 multiplier = 0;
688 else {
689 u32 interrupt_rate = 1000000 / usec_delay;
690 /* Max delay, corresponding to the lowest interrupt rate */
691 if (interrupt_rate == 0)
692 multiplier = 1023;
693 else {
694 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
695 multiplier /= interrupt_rate;
696 /* Round the multiplier to the closest value.*/
697 multiplier = (multiplier + round/2) / round;
698 multiplier = min(multiplier, (u32)1023);
699 }
700 }
701 return multiplier;
702}
703
Sathya Perlab31c50a2009-09-17 10:30:13 -0700704static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700705{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700706 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
707 struct be_mcc_wrb *wrb
708 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
709 memset(wrb, 0, sizeof(*wrb));
710 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700711}
712
Sathya Perlab31c50a2009-09-17 10:30:13 -0700713static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000714{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700715 struct be_queue_info *mccq = &adapter->mcc_obj.q;
716 struct be_mcc_wrb *wrb;
717
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000718 if (!mccq->created)
719 return NULL;
720
Vasundhara Volam4d277122013-04-21 23:28:15 +0000721 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000722 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000723
Sathya Perlab31c50a2009-09-17 10:30:13 -0700724 wrb = queue_head_node(mccq);
725 queue_head_inc(mccq);
726 atomic_inc(&mccq->used);
727 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000728 return wrb;
729}
730
Sathya Perla2243e2e2009-11-22 22:02:03 +0000731/* Tell fw we're about to start firing cmds by writing a
732 * special pattern across the wrb hdr; uses mbox
733 */
734int be_cmd_fw_init(struct be_adapter *adapter)
735{
736 u8 *wrb;
737 int status;
738
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000739 if (lancer_chip(adapter))
740 return 0;
741
Ivan Vecera29849612010-12-14 05:43:19 +0000742 if (mutex_lock_interruptible(&adapter->mbox_lock))
743 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000744
745 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000746 *wrb++ = 0xFF;
747 *wrb++ = 0x12;
748 *wrb++ = 0x34;
749 *wrb++ = 0xFF;
750 *wrb++ = 0xFF;
751 *wrb++ = 0x56;
752 *wrb++ = 0x78;
753 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000754
755 status = be_mbox_notify_wait(adapter);
756
Ivan Vecera29849612010-12-14 05:43:19 +0000757 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000758 return status;
759}
760
761/* Tell fw we're done with firing cmds by writing a
762 * special pattern across the wrb hdr; uses mbox
763 */
764int be_cmd_fw_clean(struct be_adapter *adapter)
765{
766 u8 *wrb;
767 int status;
768
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000769 if (lancer_chip(adapter))
770 return 0;
771
Ivan Vecera29849612010-12-14 05:43:19 +0000772 if (mutex_lock_interruptible(&adapter->mbox_lock))
773 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000774
775 wrb = (u8 *)wrb_from_mbox(adapter);
776 *wrb++ = 0xFF;
777 *wrb++ = 0xAA;
778 *wrb++ = 0xBB;
779 *wrb++ = 0xFF;
780 *wrb++ = 0xFF;
781 *wrb++ = 0xCC;
782 *wrb++ = 0xDD;
783 *wrb = 0xFF;
784
785 status = be_mbox_notify_wait(adapter);
786
Ivan Vecera29849612010-12-14 05:43:19 +0000787 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000788 return status;
789}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000790
Sathya Perla8788fdc2009-07-27 22:52:03 +0000791int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700792 struct be_queue_info *eq, int eq_delay)
793{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700794 struct be_mcc_wrb *wrb;
795 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700796 struct be_dma_mem *q_mem = &eq->dma_mem;
797 int status;
798
Ivan Vecera29849612010-12-14 05:43:19 +0000799 if (mutex_lock_interruptible(&adapter->mbox_lock))
800 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700801
802 wrb = wrb_from_mbox(adapter);
803 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700804
Somnath Kotur106df1e2011-10-27 07:12:13 +0000805 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
806 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700807
808 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
809
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700810 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
811 /* 4byte eqe*/
812 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
813 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
814 __ilog2_u32(eq->len/256));
815 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
816 eq_delay_to_mult(eq_delay));
817 be_dws_cpu_to_le(req->context, sizeof(req->context));
818
819 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
820
Sathya Perlab31c50a2009-09-17 10:30:13 -0700821 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700822 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700823 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700824 eq->id = le16_to_cpu(resp->eq_id);
825 eq->created = true;
826 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700827
Ivan Vecera29849612010-12-14 05:43:19 +0000828 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700829 return status;
830}
831
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000832/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000833int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000834 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700835{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700836 struct be_mcc_wrb *wrb;
837 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700838 int status;
839
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000840 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700841
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000842 wrb = wrb_from_mccq(adapter);
843 if (!wrb) {
844 status = -EBUSY;
845 goto err;
846 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700847 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700848
Somnath Kotur106df1e2011-10-27 07:12:13 +0000849 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
850 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000851 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700852 if (permanent) {
853 req->permanent = 1;
854 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700855 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000856 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700857 req->permanent = 0;
858 }
859
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000860 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700861 if (!status) {
862 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700863 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700864 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700865
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000866err:
867 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700868 return status;
869}
870
Sathya Perlab31c50a2009-09-17 10:30:13 -0700871/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000872int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000873 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700874{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700875 struct be_mcc_wrb *wrb;
876 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700877 int status;
878
Sathya Perlab31c50a2009-09-17 10:30:13 -0700879 spin_lock_bh(&adapter->mcc_lock);
880
881 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000882 if (!wrb) {
883 status = -EBUSY;
884 goto err;
885 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700886 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700887
Somnath Kotur106df1e2011-10-27 07:12:13 +0000888 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
889 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700890
Ajit Khapardef8617e02011-02-11 13:36:37 +0000891 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700892 req->if_id = cpu_to_le32(if_id);
893 memcpy(req->mac_address, mac_addr, ETH_ALEN);
894
Sathya Perlab31c50a2009-09-17 10:30:13 -0700895 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700896 if (!status) {
897 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
898 *pmac_id = le32_to_cpu(resp->pmac_id);
899 }
900
Sathya Perla713d03942009-11-22 22:02:45 +0000901err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700902 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000903
904 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
905 status = -EPERM;
906
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700907 return status;
908}
909
Sathya Perlab31c50a2009-09-17 10:30:13 -0700910/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000911int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700912{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700913 struct be_mcc_wrb *wrb;
914 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700915 int status;
916
Sathya Perla30128032011-11-10 19:17:57 +0000917 if (pmac_id == -1)
918 return 0;
919
Sathya Perlab31c50a2009-09-17 10:30:13 -0700920 spin_lock_bh(&adapter->mcc_lock);
921
922 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000923 if (!wrb) {
924 status = -EBUSY;
925 goto err;
926 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700927 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700928
Somnath Kotur106df1e2011-10-27 07:12:13 +0000929 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
930 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700931
Ajit Khapardef8617e02011-02-11 13:36:37 +0000932 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700933 req->if_id = cpu_to_le32(if_id);
934 req->pmac_id = cpu_to_le32(pmac_id);
935
Sathya Perlab31c50a2009-09-17 10:30:13 -0700936 status = be_mcc_notify_wait(adapter);
937
Sathya Perla713d03942009-11-22 22:02:45 +0000938err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700939 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700940 return status;
941}
942
Sathya Perlab31c50a2009-09-17 10:30:13 -0700943/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000944int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
945 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700946{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700947 struct be_mcc_wrb *wrb;
948 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700949 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700950 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700951 int status;
952
Ivan Vecera29849612010-12-14 05:43:19 +0000953 if (mutex_lock_interruptible(&adapter->mbox_lock))
954 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700955
956 wrb = wrb_from_mbox(adapter);
957 req = embedded_payload(wrb);
958 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700959
Somnath Kotur106df1e2011-10-27 07:12:13 +0000960 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
961 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700962
963 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +0000964
965 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000966 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
967 coalesce_wm);
968 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
969 ctxt, no_delay);
970 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
971 __ilog2_u32(cq->len/256));
972 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000973 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
974 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +0000975 } else {
976 req->hdr.version = 2;
977 req->page_size = 1; /* 1 for 4K */
978 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
979 no_delay);
980 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
981 __ilog2_u32(cq->len/256));
982 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
983 AMAP_SET_BITS(struct amap_cq_context_v2, eventable,
984 ctxt, 1);
985 AMAP_SET_BITS(struct amap_cq_context_v2, eqid,
986 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000987 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700988
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700989 be_dws_cpu_to_le(ctxt, sizeof(req->context));
990
991 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
992
Sathya Perlab31c50a2009-09-17 10:30:13 -0700993 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700994 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700995 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700996 cq->id = le16_to_cpu(resp->cq_id);
997 cq->created = true;
998 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700999
Ivan Vecera29849612010-12-14 05:43:19 +00001000 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001001
1002 return status;
1003}
1004
1005static u32 be_encoded_q_len(int q_len)
1006{
1007 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
1008 if (len_encoded == 16)
1009 len_encoded = 0;
1010 return len_encoded;
1011}
1012
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001013int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +00001014 struct be_queue_info *mccq,
1015 struct be_queue_info *cq)
1016{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001017 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001018 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001019 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001020 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001021 int status;
1022
Ivan Vecera29849612010-12-14 05:43:19 +00001023 if (mutex_lock_interruptible(&adapter->mbox_lock))
1024 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001025
1026 wrb = wrb_from_mbox(adapter);
1027 req = embedded_payload(wrb);
1028 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001029
Somnath Kotur106df1e2011-10-27 07:12:13 +00001030 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1031 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001032
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001033 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001034 if (lancer_chip(adapter)) {
1035 req->hdr.version = 1;
1036 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001037
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001038 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
1039 be_encoded_q_len(mccq->len));
1040 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
1041 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
1042 ctxt, cq->id);
1043 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
1044 ctxt, 1);
1045
1046 } else {
1047 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1048 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1049 be_encoded_q_len(mccq->len));
1050 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1051 }
1052
Somnath Koturcc4ce022010-10-21 07:11:14 -07001053 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001054 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001055 req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001056 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1057
1058 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1059
Sathya Perlab31c50a2009-09-17 10:30:13 -07001060 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001061 if (!status) {
1062 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1063 mccq->id = le16_to_cpu(resp->id);
1064 mccq->created = true;
1065 }
Ivan Vecera29849612010-12-14 05:43:19 +00001066 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001067
1068 return status;
1069}
1070
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001071int be_cmd_mccq_org_create(struct be_adapter *adapter,
1072 struct be_queue_info *mccq,
1073 struct be_queue_info *cq)
1074{
1075 struct be_mcc_wrb *wrb;
1076 struct be_cmd_req_mcc_create *req;
1077 struct be_dma_mem *q_mem = &mccq->dma_mem;
1078 void *ctxt;
1079 int status;
1080
1081 if (mutex_lock_interruptible(&adapter->mbox_lock))
1082 return -1;
1083
1084 wrb = wrb_from_mbox(adapter);
1085 req = embedded_payload(wrb);
1086 ctxt = &req->context;
1087
Somnath Kotur106df1e2011-10-27 07:12:13 +00001088 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1089 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001090
1091 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1092
1093 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1094 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1095 be_encoded_q_len(mccq->len));
1096 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1097
1098 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1099
1100 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1101
1102 status = be_mbox_notify_wait(adapter);
1103 if (!status) {
1104 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1105 mccq->id = le16_to_cpu(resp->id);
1106 mccq->created = true;
1107 }
1108
1109 mutex_unlock(&adapter->mbox_lock);
1110 return status;
1111}
1112
1113int be_cmd_mccq_create(struct be_adapter *adapter,
1114 struct be_queue_info *mccq,
1115 struct be_queue_info *cq)
1116{
1117 int status;
1118
1119 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
1120 if (status && !lancer_chip(adapter)) {
1121 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1122 "or newer to avoid conflicting priorities between NIC "
1123 "and FCoE traffic");
1124 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1125 }
1126 return status;
1127}
1128
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001129int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001130{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001131 struct be_mcc_wrb *wrb;
1132 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001133 struct be_queue_info *txq = &txo->q;
1134 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001135 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001136 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001137
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001138 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001139
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001140 wrb = wrb_from_mccq(adapter);
1141 if (!wrb) {
1142 status = -EBUSY;
1143 goto err;
1144 }
1145
Sathya Perlab31c50a2009-09-17 10:30:13 -07001146 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001147
Somnath Kotur106df1e2011-10-27 07:12:13 +00001148 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1149 OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001150
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001151 if (lancer_chip(adapter)) {
1152 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001153 req->if_id = cpu_to_le16(adapter->if_handle);
1154 } else if (BEx_chip(adapter)) {
1155 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1156 req->hdr.version = 2;
1157 } else { /* For SH */
1158 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001159 }
1160
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001161 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1162 req->ulp_num = BE_ULP1_NUM;
1163 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001164 req->cq_id = cpu_to_le16(cq->id);
1165 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001166 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1167
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001168 ver = req->hdr.version;
1169
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001170 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001171 if (!status) {
1172 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
1173 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001174 if (ver == 2)
1175 txo->db_offset = le32_to_cpu(resp->db_offset);
1176 else
1177 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001178 txq->created = true;
1179 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001180
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001181err:
1182 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001183
1184 return status;
1185}
1186
Sathya Perla482c9e72011-06-29 23:33:17 +00001187/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001188int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001189 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001190 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001191{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001192 struct be_mcc_wrb *wrb;
1193 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001194 struct be_dma_mem *q_mem = &rxq->dma_mem;
1195 int status;
1196
Sathya Perla482c9e72011-06-29 23:33:17 +00001197 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001198
Sathya Perla482c9e72011-06-29 23:33:17 +00001199 wrb = wrb_from_mccq(adapter);
1200 if (!wrb) {
1201 status = -EBUSY;
1202 goto err;
1203 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001204 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001205
Somnath Kotur106df1e2011-10-27 07:12:13 +00001206 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1207 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001208
1209 req->cq_id = cpu_to_le16(cq_id);
1210 req->frag_size = fls(frag_size) - 1;
1211 req->num_pages = 2;
1212 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1213 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001214 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001215 req->rss_queue = cpu_to_le32(rss);
1216
Sathya Perla482c9e72011-06-29 23:33:17 +00001217 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001218 if (!status) {
1219 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1220 rxq->id = le16_to_cpu(resp->id);
1221 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001222 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001223 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001224
Sathya Perla482c9e72011-06-29 23:33:17 +00001225err:
1226 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001227 return status;
1228}
1229
Sathya Perlab31c50a2009-09-17 10:30:13 -07001230/* Generic destroyer function for all types of queues
1231 * Uses Mbox
1232 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001233int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001234 int queue_type)
1235{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001236 struct be_mcc_wrb *wrb;
1237 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001238 u8 subsys = 0, opcode = 0;
1239 int status;
1240
Ivan Vecera29849612010-12-14 05:43:19 +00001241 if (mutex_lock_interruptible(&adapter->mbox_lock))
1242 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001243
Sathya Perlab31c50a2009-09-17 10:30:13 -07001244 wrb = wrb_from_mbox(adapter);
1245 req = embedded_payload(wrb);
1246
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001247 switch (queue_type) {
1248 case QTYPE_EQ:
1249 subsys = CMD_SUBSYSTEM_COMMON;
1250 opcode = OPCODE_COMMON_EQ_DESTROY;
1251 break;
1252 case QTYPE_CQ:
1253 subsys = CMD_SUBSYSTEM_COMMON;
1254 opcode = OPCODE_COMMON_CQ_DESTROY;
1255 break;
1256 case QTYPE_TXQ:
1257 subsys = CMD_SUBSYSTEM_ETH;
1258 opcode = OPCODE_ETH_TX_DESTROY;
1259 break;
1260 case QTYPE_RXQ:
1261 subsys = CMD_SUBSYSTEM_ETH;
1262 opcode = OPCODE_ETH_RX_DESTROY;
1263 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001264 case QTYPE_MCCQ:
1265 subsys = CMD_SUBSYSTEM_COMMON;
1266 opcode = OPCODE_COMMON_MCC_DESTROY;
1267 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001268 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001269 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001270 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001271
Somnath Kotur106df1e2011-10-27 07:12:13 +00001272 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1273 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001274 req->id = cpu_to_le16(q->id);
1275
Sathya Perlab31c50a2009-09-17 10:30:13 -07001276 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001277 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001278
Ivan Vecera29849612010-12-14 05:43:19 +00001279 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001280 return status;
1281}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001282
Sathya Perla482c9e72011-06-29 23:33:17 +00001283/* Uses MCC */
1284int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1285{
1286 struct be_mcc_wrb *wrb;
1287 struct be_cmd_req_q_destroy *req;
1288 int status;
1289
1290 spin_lock_bh(&adapter->mcc_lock);
1291
1292 wrb = wrb_from_mccq(adapter);
1293 if (!wrb) {
1294 status = -EBUSY;
1295 goto err;
1296 }
1297 req = embedded_payload(wrb);
1298
Somnath Kotur106df1e2011-10-27 07:12:13 +00001299 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1300 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001301 req->id = cpu_to_le16(q->id);
1302
1303 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001304 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001305
1306err:
1307 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001308 return status;
1309}
1310
Sathya Perlab31c50a2009-09-17 10:30:13 -07001311/* Create an rx filtering policy configuration on an i/f
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001312 * Uses MCCQ
Sathya Perlab31c50a2009-09-17 10:30:13 -07001313 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001314int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001315 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001316{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001317 struct be_mcc_wrb *wrb;
1318 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001319 int status;
1320
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001321 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001322
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001323 wrb = wrb_from_mccq(adapter);
1324 if (!wrb) {
1325 status = -EBUSY;
1326 goto err;
1327 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001328 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001329
Somnath Kotur106df1e2011-10-27 07:12:13 +00001330 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1331 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001332 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001333 req->capability_flags = cpu_to_le32(cap_flags);
1334 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001335
1336 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001337
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001338 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001339 if (!status) {
1340 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1341 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001342 }
1343
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001344err:
1345 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001346 return status;
1347}
1348
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001349/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001350int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001351{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001352 struct be_mcc_wrb *wrb;
1353 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001354 int status;
1355
Sathya Perla30128032011-11-10 19:17:57 +00001356 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001357 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001358
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001359 spin_lock_bh(&adapter->mcc_lock);
1360
1361 wrb = wrb_from_mccq(adapter);
1362 if (!wrb) {
1363 status = -EBUSY;
1364 goto err;
1365 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001366 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001367
Somnath Kotur106df1e2011-10-27 07:12:13 +00001368 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1369 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001370 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001371 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001372
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001373 status = be_mcc_notify_wait(adapter);
1374err:
1375 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001376 return status;
1377}
1378
1379/* Get stats is a non embedded command: the request is not embedded inside
1380 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001381 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001382 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001383int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001384{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001385 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001386 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001387 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001388
Sathya Perlab31c50a2009-09-17 10:30:13 -07001389 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001390
Sathya Perlab31c50a2009-09-17 10:30:13 -07001391 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001392 if (!wrb) {
1393 status = -EBUSY;
1394 goto err;
1395 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001396 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001397
Somnath Kotur106df1e2011-10-27 07:12:13 +00001398 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1399 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001400
Sathya Perlaca34fe32012-11-06 17:48:56 +00001401 /* version 1 of the cmd is not supported only by BE2 */
1402 if (!BE2_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001403 hdr->version = 1;
1404
Sathya Perlab31c50a2009-09-17 10:30:13 -07001405 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001406 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001407
Sathya Perla713d03942009-11-22 22:02:45 +00001408err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001409 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001410 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001411}
1412
Selvin Xavier005d5692011-05-16 07:36:35 +00001413/* Lancer Stats */
1414int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1415 struct be_dma_mem *nonemb_cmd)
1416{
1417
1418 struct be_mcc_wrb *wrb;
1419 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001420 int status = 0;
1421
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001422 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1423 CMD_SUBSYSTEM_ETH))
1424 return -EPERM;
1425
Selvin Xavier005d5692011-05-16 07:36:35 +00001426 spin_lock_bh(&adapter->mcc_lock);
1427
1428 wrb = wrb_from_mccq(adapter);
1429 if (!wrb) {
1430 status = -EBUSY;
1431 goto err;
1432 }
1433 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001434
Somnath Kotur106df1e2011-10-27 07:12:13 +00001435 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1436 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1437 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001438
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001439 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001440 req->cmd_params.params.reset_stats = 0;
1441
Selvin Xavier005d5692011-05-16 07:36:35 +00001442 be_mcc_notify(adapter);
1443 adapter->stats_cmd_sent = true;
1444
1445err:
1446 spin_unlock_bh(&adapter->mcc_lock);
1447 return status;
1448}
1449
Sathya Perla323ff712012-09-28 04:39:43 +00001450static int be_mac_to_link_speed(int mac_speed)
1451{
1452 switch (mac_speed) {
1453 case PHY_LINK_SPEED_ZERO:
1454 return 0;
1455 case PHY_LINK_SPEED_10MBPS:
1456 return 10;
1457 case PHY_LINK_SPEED_100MBPS:
1458 return 100;
1459 case PHY_LINK_SPEED_1GBPS:
1460 return 1000;
1461 case PHY_LINK_SPEED_10GBPS:
1462 return 10000;
1463 }
1464 return 0;
1465}
1466
1467/* Uses synchronous mcc
1468 * Returns link_speed in Mbps
1469 */
1470int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1471 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001472{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001473 struct be_mcc_wrb *wrb;
1474 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001475 int status;
1476
Sathya Perlab31c50a2009-09-17 10:30:13 -07001477 spin_lock_bh(&adapter->mcc_lock);
1478
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001479 if (link_status)
1480 *link_status = LINK_DOWN;
1481
Sathya Perlab31c50a2009-09-17 10:30:13 -07001482 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001483 if (!wrb) {
1484 status = -EBUSY;
1485 goto err;
1486 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001487 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001488
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001489 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1490 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1491
Sathya Perlaca34fe32012-11-06 17:48:56 +00001492 /* version 1 of the cmd is not supported only by BE2 */
1493 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001494 req->hdr.version = 1;
1495
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001496 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001497
Sathya Perlab31c50a2009-09-17 10:30:13 -07001498 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001499 if (!status) {
1500 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sathya Perla323ff712012-09-28 04:39:43 +00001501 if (link_speed) {
1502 *link_speed = resp->link_speed ?
1503 le16_to_cpu(resp->link_speed) * 10 :
1504 be_mac_to_link_speed(resp->mac_speed);
1505
1506 if (!resp->logical_link_status)
1507 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001508 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001509 if (link_status)
1510 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001511 }
1512
Sathya Perla713d03942009-11-22 22:02:45 +00001513err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001514 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001515 return status;
1516}
1517
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001518/* Uses synchronous mcc */
1519int be_cmd_get_die_temperature(struct be_adapter *adapter)
1520{
1521 struct be_mcc_wrb *wrb;
1522 struct be_cmd_req_get_cntl_addnl_attribs *req;
1523 int status;
1524
1525 spin_lock_bh(&adapter->mcc_lock);
1526
1527 wrb = wrb_from_mccq(adapter);
1528 if (!wrb) {
1529 status = -EBUSY;
1530 goto err;
1531 }
1532 req = embedded_payload(wrb);
1533
Somnath Kotur106df1e2011-10-27 07:12:13 +00001534 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1535 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1536 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001537
Somnath Kotur3de09452011-09-30 07:25:05 +00001538 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001539
1540err:
1541 spin_unlock_bh(&adapter->mcc_lock);
1542 return status;
1543}
1544
Somnath Kotur311fddc2011-03-16 21:22:43 +00001545/* Uses synchronous mcc */
1546int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1547{
1548 struct be_mcc_wrb *wrb;
1549 struct be_cmd_req_get_fat *req;
1550 int status;
1551
1552 spin_lock_bh(&adapter->mcc_lock);
1553
1554 wrb = wrb_from_mccq(adapter);
1555 if (!wrb) {
1556 status = -EBUSY;
1557 goto err;
1558 }
1559 req = embedded_payload(wrb);
1560
Somnath Kotur106df1e2011-10-27 07:12:13 +00001561 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1562 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001563 req->fat_operation = cpu_to_le32(QUERY_FAT);
1564 status = be_mcc_notify_wait(adapter);
1565 if (!status) {
1566 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1567 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001568 *log_size = le32_to_cpu(resp->log_size) -
1569 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001570 }
1571err:
1572 spin_unlock_bh(&adapter->mcc_lock);
1573 return status;
1574}
1575
1576void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1577{
1578 struct be_dma_mem get_fat_cmd;
1579 struct be_mcc_wrb *wrb;
1580 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001581 u32 offset = 0, total_size, buf_size,
1582 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001583 int status;
1584
1585 if (buf_len == 0)
1586 return;
1587
1588 total_size = buf_len;
1589
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001590 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1591 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1592 get_fat_cmd.size,
1593 &get_fat_cmd.dma);
1594 if (!get_fat_cmd.va) {
1595 status = -ENOMEM;
1596 dev_err(&adapter->pdev->dev,
1597 "Memory allocation failure while retrieving FAT data\n");
1598 return;
1599 }
1600
Somnath Kotur311fddc2011-03-16 21:22:43 +00001601 spin_lock_bh(&adapter->mcc_lock);
1602
Somnath Kotur311fddc2011-03-16 21:22:43 +00001603 while (total_size) {
1604 buf_size = min(total_size, (u32)60*1024);
1605 total_size -= buf_size;
1606
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001607 wrb = wrb_from_mccq(adapter);
1608 if (!wrb) {
1609 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001610 goto err;
1611 }
1612 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001613
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001614 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001615 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1616 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1617 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001618
1619 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1620 req->read_log_offset = cpu_to_le32(log_offset);
1621 req->read_log_length = cpu_to_le32(buf_size);
1622 req->data_buffer_size = cpu_to_le32(buf_size);
1623
1624 status = be_mcc_notify_wait(adapter);
1625 if (!status) {
1626 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1627 memcpy(buf + offset,
1628 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001629 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001630 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001631 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001632 goto err;
1633 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001634 offset += buf_size;
1635 log_offset += buf_size;
1636 }
1637err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001638 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1639 get_fat_cmd.va,
1640 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001641 spin_unlock_bh(&adapter->mcc_lock);
1642}
1643
Sathya Perla04b71172011-09-27 13:30:27 -04001644/* Uses synchronous mcc */
1645int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1646 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001647{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001648 struct be_mcc_wrb *wrb;
1649 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001650 int status;
1651
Sathya Perla04b71172011-09-27 13:30:27 -04001652 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001653
Sathya Perla04b71172011-09-27 13:30:27 -04001654 wrb = wrb_from_mccq(adapter);
1655 if (!wrb) {
1656 status = -EBUSY;
1657 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001658 }
1659
Sathya Perla04b71172011-09-27 13:30:27 -04001660 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001661
Somnath Kotur106df1e2011-10-27 07:12:13 +00001662 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1663 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001664 status = be_mcc_notify_wait(adapter);
1665 if (!status) {
1666 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1667 strcpy(fw_ver, resp->firmware_version_string);
1668 if (fw_on_flash)
1669 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1670 }
1671err:
1672 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001673 return status;
1674}
1675
Sathya Perlab31c50a2009-09-17 10:30:13 -07001676/* set the EQ delay interval of an EQ to specified value
1677 * Uses async mcc
1678 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001679int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001680{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001681 struct be_mcc_wrb *wrb;
1682 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001683 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001684
Sathya Perlab31c50a2009-09-17 10:30:13 -07001685 spin_lock_bh(&adapter->mcc_lock);
1686
1687 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001688 if (!wrb) {
1689 status = -EBUSY;
1690 goto err;
1691 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001692 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001693
Somnath Kotur106df1e2011-10-27 07:12:13 +00001694 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1695 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001696
1697 req->num_eq = cpu_to_le32(1);
1698 req->delay[0].eq_id = cpu_to_le32(eq_id);
1699 req->delay[0].phase = 0;
1700 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1701
Sathya Perlab31c50a2009-09-17 10:30:13 -07001702 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001703
Sathya Perla713d03942009-11-22 22:02:45 +00001704err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001705 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001706 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001707}
1708
Sathya Perlab31c50a2009-09-17 10:30:13 -07001709/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001710int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001711 u32 num, bool untagged, bool promiscuous)
1712{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001713 struct be_mcc_wrb *wrb;
1714 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001715 int status;
1716
Sathya Perlab31c50a2009-09-17 10:30:13 -07001717 spin_lock_bh(&adapter->mcc_lock);
1718
1719 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001720 if (!wrb) {
1721 status = -EBUSY;
1722 goto err;
1723 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001724 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001725
Somnath Kotur106df1e2011-10-27 07:12:13 +00001726 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1727 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001728
1729 req->interface_id = if_id;
1730 req->promiscuous = promiscuous;
1731 req->untagged = untagged;
1732 req->num_vlan = num;
1733 if (!promiscuous) {
1734 memcpy(req->normal_vlan, vtag_array,
1735 req->num_vlan * sizeof(vtag_array[0]));
1736 }
1737
Sathya Perlab31c50a2009-09-17 10:30:13 -07001738 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001739
Sathya Perla713d03942009-11-22 22:02:45 +00001740err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001741 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001742 return status;
1743}
1744
Sathya Perla5b8821b2011-08-02 19:57:44 +00001745int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001746{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001747 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001748 struct be_dma_mem *mem = &adapter->rx_filter;
1749 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001750 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001751
Sathya Perla8788fdc2009-07-27 22:52:03 +00001752 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001753
Sathya Perlab31c50a2009-09-17 10:30:13 -07001754 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001755 if (!wrb) {
1756 status = -EBUSY;
1757 goto err;
1758 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001759 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001760 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1761 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1762 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001763
Sathya Perla5b8821b2011-08-02 19:57:44 +00001764 req->if_id = cpu_to_le32(adapter->if_handle);
1765 if (flags & IFF_PROMISC) {
1766 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Ajit Khapardec5dae582013-05-01 09:38:24 +00001767 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1768 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001769 if (value == ON)
1770 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Ajit Khapardec5dae582013-05-01 09:38:24 +00001771 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1772 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001773 } else if (flags & IFF_ALLMULTI) {
1774 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001775 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001776 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001777 struct netdev_hw_addr *ha;
1778 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001779
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001780 req->if_flags_mask = req->if_flags =
1781 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001782
1783 /* Reset mcast promisc mode if already set by setting mask
1784 * and not setting flags field
1785 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001786 req->if_flags_mask |=
1787 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
1788 adapter->if_cap_flags);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001789
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001790 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001791 netdev_for_each_mc_addr(ha, adapter->netdev)
1792 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1793 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001794
Sathya Perla0d1d5872011-08-03 05:19:27 -07001795 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001796err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001797 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001798 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001799}
1800
Sathya Perlab31c50a2009-09-17 10:30:13 -07001801/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001802int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001803{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001804 struct be_mcc_wrb *wrb;
1805 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001806 int status;
1807
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001808 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1809 CMD_SUBSYSTEM_COMMON))
1810 return -EPERM;
1811
Sathya Perlab31c50a2009-09-17 10:30:13 -07001812 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001813
Sathya Perlab31c50a2009-09-17 10:30:13 -07001814 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001815 if (!wrb) {
1816 status = -EBUSY;
1817 goto err;
1818 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001819 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001820
Somnath Kotur106df1e2011-10-27 07:12:13 +00001821 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1822 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001823
1824 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1825 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1826
Sathya Perlab31c50a2009-09-17 10:30:13 -07001827 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001828
Sathya Perla713d03942009-11-22 22:02:45 +00001829err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001830 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001831 return status;
1832}
1833
Sathya Perlab31c50a2009-09-17 10:30:13 -07001834/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001835int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001836{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001837 struct be_mcc_wrb *wrb;
1838 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001839 int status;
1840
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001841 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
1842 CMD_SUBSYSTEM_COMMON))
1843 return -EPERM;
1844
Sathya Perlab31c50a2009-09-17 10:30:13 -07001845 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001846
Sathya Perlab31c50a2009-09-17 10:30:13 -07001847 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001848 if (!wrb) {
1849 status = -EBUSY;
1850 goto err;
1851 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001852 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001853
Somnath Kotur106df1e2011-10-27 07:12:13 +00001854 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1855 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001856
Sathya Perlab31c50a2009-09-17 10:30:13 -07001857 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001858 if (!status) {
1859 struct be_cmd_resp_get_flow_control *resp =
1860 embedded_payload(wrb);
1861 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1862 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1863 }
1864
Sathya Perla713d03942009-11-22 22:02:45 +00001865err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001866 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001867 return status;
1868}
1869
Sathya Perlab31c50a2009-09-17 10:30:13 -07001870/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001871int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
Vasundhara Volam0ad31572013-04-21 23:28:16 +00001872 u32 *mode, u32 *caps, u16 *asic_rev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001873{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001874 struct be_mcc_wrb *wrb;
1875 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001876 int status;
1877
Ivan Vecera29849612010-12-14 05:43:19 +00001878 if (mutex_lock_interruptible(&adapter->mbox_lock))
1879 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001880
Sathya Perlab31c50a2009-09-17 10:30:13 -07001881 wrb = wrb_from_mbox(adapter);
1882 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001883
Somnath Kotur106df1e2011-10-27 07:12:13 +00001884 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1885 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001886
Sathya Perlab31c50a2009-09-17 10:30:13 -07001887 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001888 if (!status) {
1889 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1890 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001891 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001892 *caps = le32_to_cpu(resp->function_caps);
Vasundhara Volam0ad31572013-04-21 23:28:16 +00001893 *asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001894 }
1895
Ivan Vecera29849612010-12-14 05:43:19 +00001896 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001897 return status;
1898}
sarveshwarb14074ea2009-08-05 13:05:24 -07001899
Sathya Perlab31c50a2009-09-17 10:30:13 -07001900/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001901int be_cmd_reset_function(struct be_adapter *adapter)
1902{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001903 struct be_mcc_wrb *wrb;
1904 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001905 int status;
1906
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00001907 if (lancer_chip(adapter)) {
1908 status = lancer_wait_ready(adapter);
1909 if (!status) {
1910 iowrite32(SLI_PORT_CONTROL_IP_MASK,
1911 adapter->db + SLIPORT_CONTROL_OFFSET);
1912 status = lancer_test_and_set_rdy_state(adapter);
1913 }
1914 if (status) {
1915 dev_err(&adapter->pdev->dev,
1916 "Adapter in non recoverable error\n");
1917 }
1918 return status;
1919 }
1920
Ivan Vecera29849612010-12-14 05:43:19 +00001921 if (mutex_lock_interruptible(&adapter->mbox_lock))
1922 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001923
Sathya Perlab31c50a2009-09-17 10:30:13 -07001924 wrb = wrb_from_mbox(adapter);
1925 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001926
Somnath Kotur106df1e2011-10-27 07:12:13 +00001927 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1928 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001929
Sathya Perlab31c50a2009-09-17 10:30:13 -07001930 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001931
Ivan Vecera29849612010-12-14 05:43:19 +00001932 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001933 return status;
1934}
Ajit Khaparde84517482009-09-04 03:12:16 +00001935
Suresh Reddy594ad542013-04-25 23:03:20 +00001936int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
1937 u32 rss_hash_opts, u16 table_size)
Sathya Perla3abcded2010-10-03 22:12:27 -07001938{
1939 struct be_mcc_wrb *wrb;
1940 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001941 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1942 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1943 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001944 int status;
1945
Ivan Vecera29849612010-12-14 05:43:19 +00001946 if (mutex_lock_interruptible(&adapter->mbox_lock))
1947 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001948
1949 wrb = wrb_from_mbox(adapter);
1950 req = embedded_payload(wrb);
1951
Somnath Kotur106df1e2011-10-27 07:12:13 +00001952 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1953 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001954
1955 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00001956 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07001957 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00001958
1959 if (lancer_chip(adapter) || skyhawk_chip(adapter))
1960 req->hdr.version = 1;
1961
Sathya Perla3abcded2010-10-03 22:12:27 -07001962 memcpy(req->cpu_table, rsstable, table_size);
1963 memcpy(req->hash, myhash, sizeof(myhash));
1964 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1965
1966 status = be_mbox_notify_wait(adapter);
1967
Ivan Vecera29849612010-12-14 05:43:19 +00001968 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001969 return status;
1970}
1971
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001972/* Uses sync mcc */
1973int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1974 u8 bcn, u8 sts, u8 state)
1975{
1976 struct be_mcc_wrb *wrb;
1977 struct be_cmd_req_enable_disable_beacon *req;
1978 int status;
1979
1980 spin_lock_bh(&adapter->mcc_lock);
1981
1982 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001983 if (!wrb) {
1984 status = -EBUSY;
1985 goto err;
1986 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001987 req = embedded_payload(wrb);
1988
Somnath Kotur106df1e2011-10-27 07:12:13 +00001989 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1990 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001991
1992 req->port_num = port_num;
1993 req->beacon_state = state;
1994 req->beacon_duration = bcn;
1995 req->status_duration = sts;
1996
1997 status = be_mcc_notify_wait(adapter);
1998
Sathya Perla713d03942009-11-22 22:02:45 +00001999err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002000 spin_unlock_bh(&adapter->mcc_lock);
2001 return status;
2002}
2003
2004/* Uses sync mcc */
2005int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2006{
2007 struct be_mcc_wrb *wrb;
2008 struct be_cmd_req_get_beacon_state *req;
2009 int status;
2010
2011 spin_lock_bh(&adapter->mcc_lock);
2012
2013 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002014 if (!wrb) {
2015 status = -EBUSY;
2016 goto err;
2017 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002018 req = embedded_payload(wrb);
2019
Somnath Kotur106df1e2011-10-27 07:12:13 +00002020 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2021 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002022
2023 req->port_num = port_num;
2024
2025 status = be_mcc_notify_wait(adapter);
2026 if (!status) {
2027 struct be_cmd_resp_get_beacon_state *resp =
2028 embedded_payload(wrb);
2029 *state = resp->beacon_state;
2030 }
2031
Sathya Perla713d03942009-11-22 22:02:45 +00002032err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002033 spin_unlock_bh(&adapter->mcc_lock);
2034 return status;
2035}
2036
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002037int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002038 u32 data_size, u32 data_offset,
2039 const char *obj_name, u32 *data_written,
2040 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002041{
2042 struct be_mcc_wrb *wrb;
2043 struct lancer_cmd_req_write_object *req;
2044 struct lancer_cmd_resp_write_object *resp;
2045 void *ctxt = NULL;
2046 int status;
2047
2048 spin_lock_bh(&adapter->mcc_lock);
2049 adapter->flash_status = 0;
2050
2051 wrb = wrb_from_mccq(adapter);
2052 if (!wrb) {
2053 status = -EBUSY;
2054 goto err_unlock;
2055 }
2056
2057 req = embedded_payload(wrb);
2058
Somnath Kotur106df1e2011-10-27 07:12:13 +00002059 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002060 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00002061 sizeof(struct lancer_cmd_req_write_object), wrb,
2062 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002063
2064 ctxt = &req->context;
2065 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2066 write_length, ctxt, data_size);
2067
2068 if (data_size == 0)
2069 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2070 eof, ctxt, 1);
2071 else
2072 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2073 eof, ctxt, 0);
2074
2075 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2076 req->write_offset = cpu_to_le32(data_offset);
2077 strcpy(req->object_name, obj_name);
2078 req->descriptor_count = cpu_to_le32(1);
2079 req->buf_len = cpu_to_le32(data_size);
2080 req->addr_low = cpu_to_le32((cmd->dma +
2081 sizeof(struct lancer_cmd_req_write_object))
2082 & 0xFFFFFFFF);
2083 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2084 sizeof(struct lancer_cmd_req_write_object)));
2085
2086 be_mcc_notify(adapter);
2087 spin_unlock_bh(&adapter->mcc_lock);
2088
2089 if (!wait_for_completion_timeout(&adapter->flash_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002090 msecs_to_jiffies(60000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002091 status = -1;
2092 else
2093 status = adapter->flash_status;
2094
2095 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002096 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002097 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002098 *change_status = resp->change_status;
2099 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002100 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002101 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002102
2103 return status;
2104
2105err_unlock:
2106 spin_unlock_bh(&adapter->mcc_lock);
2107 return status;
2108}
2109
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002110int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
2111 u32 data_size, u32 data_offset, const char *obj_name,
2112 u32 *data_read, u32 *eof, u8 *addn_status)
2113{
2114 struct be_mcc_wrb *wrb;
2115 struct lancer_cmd_req_read_object *req;
2116 struct lancer_cmd_resp_read_object *resp;
2117 int status;
2118
2119 spin_lock_bh(&adapter->mcc_lock);
2120
2121 wrb = wrb_from_mccq(adapter);
2122 if (!wrb) {
2123 status = -EBUSY;
2124 goto err_unlock;
2125 }
2126
2127 req = embedded_payload(wrb);
2128
2129 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2130 OPCODE_COMMON_READ_OBJECT,
2131 sizeof(struct lancer_cmd_req_read_object), wrb,
2132 NULL);
2133
2134 req->desired_read_len = cpu_to_le32(data_size);
2135 req->read_offset = cpu_to_le32(data_offset);
2136 strcpy(req->object_name, obj_name);
2137 req->descriptor_count = cpu_to_le32(1);
2138 req->buf_len = cpu_to_le32(data_size);
2139 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2140 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2141
2142 status = be_mcc_notify_wait(adapter);
2143
2144 resp = embedded_payload(wrb);
2145 if (!status) {
2146 *data_read = le32_to_cpu(resp->actual_read_len);
2147 *eof = le32_to_cpu(resp->eof);
2148 } else {
2149 *addn_status = resp->additional_status;
2150 }
2151
2152err_unlock:
2153 spin_unlock_bh(&adapter->mcc_lock);
2154 return status;
2155}
2156
Ajit Khaparde84517482009-09-04 03:12:16 +00002157int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
2158 u32 flash_type, u32 flash_opcode, u32 buf_size)
2159{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002160 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002161 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002162 int status;
2163
Sathya Perlab31c50a2009-09-17 10:30:13 -07002164 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002165 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002166
2167 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002168 if (!wrb) {
2169 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002170 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002171 }
2172 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002173
Somnath Kotur106df1e2011-10-27 07:12:13 +00002174 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2175 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002176
2177 req->params.op_type = cpu_to_le32(flash_type);
2178 req->params.op_code = cpu_to_le32(flash_opcode);
2179 req->params.data_buf_size = cpu_to_le32(buf_size);
2180
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002181 be_mcc_notify(adapter);
2182 spin_unlock_bh(&adapter->mcc_lock);
2183
2184 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00002185 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002186 status = -1;
2187 else
2188 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002189
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002190 return status;
2191
2192err_unlock:
2193 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002194 return status;
2195}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002196
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002197int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2198 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002199{
2200 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002201 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002202 int status;
2203
2204 spin_lock_bh(&adapter->mcc_lock);
2205
2206 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002207 if (!wrb) {
2208 status = -EBUSY;
2209 goto err;
2210 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002211 req = embedded_payload(wrb);
2212
Somnath Kotur106df1e2011-10-27 07:12:13 +00002213 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002214 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2215 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002216
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00002217 req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002218 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002219 req->params.offset = cpu_to_le32(offset);
2220 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002221
2222 status = be_mcc_notify_wait(adapter);
2223 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002224 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002225
Sathya Perla713d03942009-11-22 22:02:45 +00002226err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002227 spin_unlock_bh(&adapter->mcc_lock);
2228 return status;
2229}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002230
Dan Carpenterc196b022010-05-26 04:47:39 +00002231int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002232 struct be_dma_mem *nonemb_cmd)
2233{
2234 struct be_mcc_wrb *wrb;
2235 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002236 int status;
2237
2238 spin_lock_bh(&adapter->mcc_lock);
2239
2240 wrb = wrb_from_mccq(adapter);
2241 if (!wrb) {
2242 status = -EBUSY;
2243 goto err;
2244 }
2245 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002246
Somnath Kotur106df1e2011-10-27 07:12:13 +00002247 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2248 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2249 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002250 memcpy(req->magic_mac, mac, ETH_ALEN);
2251
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002252 status = be_mcc_notify_wait(adapter);
2253
2254err:
2255 spin_unlock_bh(&adapter->mcc_lock);
2256 return status;
2257}
Suresh Rff33a6e2009-12-03 16:15:52 -08002258
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002259int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2260 u8 loopback_type, u8 enable)
2261{
2262 struct be_mcc_wrb *wrb;
2263 struct be_cmd_req_set_lmode *req;
2264 int status;
2265
2266 spin_lock_bh(&adapter->mcc_lock);
2267
2268 wrb = wrb_from_mccq(adapter);
2269 if (!wrb) {
2270 status = -EBUSY;
2271 goto err;
2272 }
2273
2274 req = embedded_payload(wrb);
2275
Somnath Kotur106df1e2011-10-27 07:12:13 +00002276 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2277 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2278 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002279
2280 req->src_port = port_num;
2281 req->dest_port = port_num;
2282 req->loopback_type = loopback_type;
2283 req->loopback_state = enable;
2284
2285 status = be_mcc_notify_wait(adapter);
2286err:
2287 spin_unlock_bh(&adapter->mcc_lock);
2288 return status;
2289}
2290
Suresh Rff33a6e2009-12-03 16:15:52 -08002291int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2292 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2293{
2294 struct be_mcc_wrb *wrb;
2295 struct be_cmd_req_loopback_test *req;
2296 int status;
2297
2298 spin_lock_bh(&adapter->mcc_lock);
2299
2300 wrb = wrb_from_mccq(adapter);
2301 if (!wrb) {
2302 status = -EBUSY;
2303 goto err;
2304 }
2305
2306 req = embedded_payload(wrb);
2307
Somnath Kotur106df1e2011-10-27 07:12:13 +00002308 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2309 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002310 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002311
2312 req->pattern = cpu_to_le64(pattern);
2313 req->src_port = cpu_to_le32(port_num);
2314 req->dest_port = cpu_to_le32(port_num);
2315 req->pkt_size = cpu_to_le32(pkt_size);
2316 req->num_pkts = cpu_to_le32(num_pkts);
2317 req->loopback_type = cpu_to_le32(loopback_type);
2318
2319 status = be_mcc_notify_wait(adapter);
2320 if (!status) {
2321 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2322 status = le32_to_cpu(resp->status);
2323 }
2324
2325err:
2326 spin_unlock_bh(&adapter->mcc_lock);
2327 return status;
2328}
2329
2330int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2331 u32 byte_cnt, struct be_dma_mem *cmd)
2332{
2333 struct be_mcc_wrb *wrb;
2334 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002335 int status;
2336 int i, j = 0;
2337
2338 spin_lock_bh(&adapter->mcc_lock);
2339
2340 wrb = wrb_from_mccq(adapter);
2341 if (!wrb) {
2342 status = -EBUSY;
2343 goto err;
2344 }
2345 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002346 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2347 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002348
2349 req->pattern = cpu_to_le64(pattern);
2350 req->byte_count = cpu_to_le32(byte_cnt);
2351 for (i = 0; i < byte_cnt; i++) {
2352 req->snd_buff[i] = (u8)(pattern >> (j*8));
2353 j++;
2354 if (j > 7)
2355 j = 0;
2356 }
2357
2358 status = be_mcc_notify_wait(adapter);
2359
2360 if (!status) {
2361 struct be_cmd_resp_ddrdma_test *resp;
2362 resp = cmd->va;
2363 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2364 resp->snd_err) {
2365 status = -1;
2366 }
2367 }
2368
2369err:
2370 spin_unlock_bh(&adapter->mcc_lock);
2371 return status;
2372}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002373
Dan Carpenterc196b022010-05-26 04:47:39 +00002374int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002375 struct be_dma_mem *nonemb_cmd)
2376{
2377 struct be_mcc_wrb *wrb;
2378 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002379 int status;
2380
2381 spin_lock_bh(&adapter->mcc_lock);
2382
2383 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002384 if (!wrb) {
2385 status = -EBUSY;
2386 goto err;
2387 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002388 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002389
Somnath Kotur106df1e2011-10-27 07:12:13 +00002390 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2391 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2392 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002393
2394 status = be_mcc_notify_wait(adapter);
2395
Ajit Khapardee45ff012011-02-04 17:18:28 +00002396err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002397 spin_unlock_bh(&adapter->mcc_lock);
2398 return status;
2399}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002400
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002401int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002402{
2403 struct be_mcc_wrb *wrb;
2404 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002405 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002406 int status;
2407
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002408 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2409 CMD_SUBSYSTEM_COMMON))
2410 return -EPERM;
2411
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002412 spin_lock_bh(&adapter->mcc_lock);
2413
2414 wrb = wrb_from_mccq(adapter);
2415 if (!wrb) {
2416 status = -EBUSY;
2417 goto err;
2418 }
Sathya Perla306f1342011-08-02 19:57:45 +00002419 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2420 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2421 &cmd.dma);
2422 if (!cmd.va) {
2423 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2424 status = -ENOMEM;
2425 goto err;
2426 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002427
Sathya Perla306f1342011-08-02 19:57:45 +00002428 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002429
Somnath Kotur106df1e2011-10-27 07:12:13 +00002430 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2431 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2432 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002433
2434 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002435 if (!status) {
2436 struct be_phy_info *resp_phy_info =
2437 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002438 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2439 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002440 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002441 adapter->phy.auto_speeds_supported =
2442 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2443 adapter->phy.fixed_speeds_supported =
2444 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2445 adapter->phy.misc_params =
2446 le32_to_cpu(resp_phy_info->misc_params);
Sathya Perla306f1342011-08-02 19:57:45 +00002447 }
2448 pci_free_consistent(adapter->pdev, cmd.size,
2449 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002450err:
2451 spin_unlock_bh(&adapter->mcc_lock);
2452 return status;
2453}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002454
2455int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2456{
2457 struct be_mcc_wrb *wrb;
2458 struct be_cmd_req_set_qos *req;
2459 int status;
2460
2461 spin_lock_bh(&adapter->mcc_lock);
2462
2463 wrb = wrb_from_mccq(adapter);
2464 if (!wrb) {
2465 status = -EBUSY;
2466 goto err;
2467 }
2468
2469 req = embedded_payload(wrb);
2470
Somnath Kotur106df1e2011-10-27 07:12:13 +00002471 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2472 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002473
2474 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002475 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2476 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002477
2478 status = be_mcc_notify_wait(adapter);
2479
2480err:
2481 spin_unlock_bh(&adapter->mcc_lock);
2482 return status;
2483}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002484
2485int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2486{
2487 struct be_mcc_wrb *wrb;
2488 struct be_cmd_req_cntl_attribs *req;
2489 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002490 int status;
2491 int payload_len = max(sizeof(*req), sizeof(*resp));
2492 struct mgmt_controller_attrib *attribs;
2493 struct be_dma_mem attribs_cmd;
2494
Suresh Reddyd98ef502013-04-25 00:56:55 +00002495 if (mutex_lock_interruptible(&adapter->mbox_lock))
2496 return -1;
2497
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002498 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2499 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2500 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2501 &attribs_cmd.dma);
2502 if (!attribs_cmd.va) {
2503 dev_err(&adapter->pdev->dev,
2504 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002505 status = -ENOMEM;
2506 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002507 }
2508
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002509 wrb = wrb_from_mbox(adapter);
2510 if (!wrb) {
2511 status = -EBUSY;
2512 goto err;
2513 }
2514 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002515
Somnath Kotur106df1e2011-10-27 07:12:13 +00002516 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2517 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2518 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002519
2520 status = be_mbox_notify_wait(adapter);
2521 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002522 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002523 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2524 }
2525
2526err:
2527 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002528 if (attribs_cmd.va)
2529 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2530 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002531 return status;
2532}
Sathya Perla2e588f82011-03-11 02:49:26 +00002533
2534/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002535int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002536{
2537 struct be_mcc_wrb *wrb;
2538 struct be_cmd_req_set_func_cap *req;
2539 int status;
2540
2541 if (mutex_lock_interruptible(&adapter->mbox_lock))
2542 return -1;
2543
2544 wrb = wrb_from_mbox(adapter);
2545 if (!wrb) {
2546 status = -EBUSY;
2547 goto err;
2548 }
2549
2550 req = embedded_payload(wrb);
2551
Somnath Kotur106df1e2011-10-27 07:12:13 +00002552 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2553 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002554
2555 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2556 CAPABILITY_BE3_NATIVE_ERX_API);
2557 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2558
2559 status = be_mbox_notify_wait(adapter);
2560 if (!status) {
2561 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2562 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2563 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002564 if (!adapter->be3_native)
2565 dev_warn(&adapter->pdev->dev,
2566 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002567 }
2568err:
2569 mutex_unlock(&adapter->mbox_lock);
2570 return status;
2571}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002572
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002573/* Get privilege(s) for a function */
2574int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2575 u32 domain)
2576{
2577 struct be_mcc_wrb *wrb;
2578 struct be_cmd_req_get_fn_privileges *req;
2579 int status;
2580
2581 spin_lock_bh(&adapter->mcc_lock);
2582
2583 wrb = wrb_from_mccq(adapter);
2584 if (!wrb) {
2585 status = -EBUSY;
2586 goto err;
2587 }
2588
2589 req = embedded_payload(wrb);
2590
2591 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2592 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2593 wrb, NULL);
2594
2595 req->hdr.domain = domain;
2596
2597 status = be_mcc_notify_wait(adapter);
2598 if (!status) {
2599 struct be_cmd_resp_get_fn_privileges *resp =
2600 embedded_payload(wrb);
2601 *privilege = le32_to_cpu(resp->privilege_mask);
2602 }
2603
2604err:
2605 spin_unlock_bh(&adapter->mcc_lock);
2606 return status;
2607}
2608
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002609/* Uses synchronous MCCQ */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002610int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
2611 bool *pmac_id_active, u32 *pmac_id, u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002612{
2613 struct be_mcc_wrb *wrb;
2614 struct be_cmd_req_get_mac_list *req;
2615 int status;
2616 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002617 struct be_dma_mem get_mac_list_cmd;
2618 int i;
2619
2620 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2621 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2622 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2623 get_mac_list_cmd.size,
2624 &get_mac_list_cmd.dma);
2625
2626 if (!get_mac_list_cmd.va) {
2627 dev_err(&adapter->pdev->dev,
2628 "Memory allocation failure during GET_MAC_LIST\n");
2629 return -ENOMEM;
2630 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002631
2632 spin_lock_bh(&adapter->mcc_lock);
2633
2634 wrb = wrb_from_mccq(adapter);
2635 if (!wrb) {
2636 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002637 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002638 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002639
2640 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002641
2642 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00002643 OPCODE_COMMON_GET_MAC_LIST,
2644 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002645 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002646 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
2647 req->perm_override = 1;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002648
2649 status = be_mcc_notify_wait(adapter);
2650 if (!status) {
2651 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002652 get_mac_list_cmd.va;
2653 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2654 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002655 * or one or more true or pseudo permanant mac addresses.
2656 * If an active mac_id is present, return first active mac_id
2657 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002658 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002659 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002660 struct get_list_macaddr *mac_entry;
2661 u16 mac_addr_size;
2662 u32 mac_id;
2663
2664 mac_entry = &resp->macaddr_list[i];
2665 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2666 /* mac_id is a 32 bit value and mac_addr size
2667 * is 6 bytes
2668 */
2669 if (mac_addr_size == sizeof(u32)) {
2670 *pmac_id_active = true;
2671 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2672 *pmac_id = le32_to_cpu(mac_id);
2673 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002674 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002675 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002676 /* If no active mac_id found, return first mac addr */
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002677 *pmac_id_active = false;
2678 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2679 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002680 }
2681
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002682out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002683 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002684 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2685 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002686 return status;
2687}
2688
2689/* Uses synchronous MCCQ */
2690int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2691 u8 mac_count, u32 domain)
2692{
2693 struct be_mcc_wrb *wrb;
2694 struct be_cmd_req_set_mac_list *req;
2695 int status;
2696 struct be_dma_mem cmd;
2697
2698 memset(&cmd, 0, sizeof(struct be_dma_mem));
2699 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2700 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2701 &cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00002702 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002703 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002704
2705 spin_lock_bh(&adapter->mcc_lock);
2706
2707 wrb = wrb_from_mccq(adapter);
2708 if (!wrb) {
2709 status = -EBUSY;
2710 goto err;
2711 }
2712
2713 req = cmd.va;
2714 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2715 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2716 wrb, &cmd);
2717
2718 req->hdr.domain = domain;
2719 req->mac_count = mac_count;
2720 if (mac_count)
2721 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2722
2723 status = be_mcc_notify_wait(adapter);
2724
2725err:
2726 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2727 cmd.va, cmd.dma);
2728 spin_unlock_bh(&adapter->mcc_lock);
2729 return status;
2730}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002731
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002732int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
2733 u32 domain, u16 intf_id)
2734{
2735 struct be_mcc_wrb *wrb;
2736 struct be_cmd_req_set_hsw_config *req;
2737 void *ctxt;
2738 int status;
2739
2740 spin_lock_bh(&adapter->mcc_lock);
2741
2742 wrb = wrb_from_mccq(adapter);
2743 if (!wrb) {
2744 status = -EBUSY;
2745 goto err;
2746 }
2747
2748 req = embedded_payload(wrb);
2749 ctxt = &req->context;
2750
2751 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2752 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2753
2754 req->hdr.domain = domain;
2755 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2756 if (pvid) {
2757 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2758 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2759 }
2760
2761 be_dws_cpu_to_le(req->context, sizeof(req->context));
2762 status = be_mcc_notify_wait(adapter);
2763
2764err:
2765 spin_unlock_bh(&adapter->mcc_lock);
2766 return status;
2767}
2768
2769/* Get Hyper switch config */
2770int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
2771 u32 domain, u16 intf_id)
2772{
2773 struct be_mcc_wrb *wrb;
2774 struct be_cmd_req_get_hsw_config *req;
2775 void *ctxt;
2776 int status;
2777 u16 vid;
2778
2779 spin_lock_bh(&adapter->mcc_lock);
2780
2781 wrb = wrb_from_mccq(adapter);
2782 if (!wrb) {
2783 status = -EBUSY;
2784 goto err;
2785 }
2786
2787 req = embedded_payload(wrb);
2788 ctxt = &req->context;
2789
2790 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2791 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2792
2793 req->hdr.domain = domain;
2794 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, ctxt,
2795 intf_id);
2796 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
2797 be_dws_cpu_to_le(req->context, sizeof(req->context));
2798
2799 status = be_mcc_notify_wait(adapter);
2800 if (!status) {
2801 struct be_cmd_resp_get_hsw_config *resp =
2802 embedded_payload(wrb);
2803 be_dws_le_to_cpu(&resp->context,
2804 sizeof(resp->context));
2805 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2806 pvid, &resp->context);
2807 *pvid = le16_to_cpu(vid);
2808 }
2809
2810err:
2811 spin_unlock_bh(&adapter->mcc_lock);
2812 return status;
2813}
2814
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002815int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2816{
2817 struct be_mcc_wrb *wrb;
2818 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2819 int status;
2820 int payload_len = sizeof(*req);
2821 struct be_dma_mem cmd;
2822
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002823 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2824 CMD_SUBSYSTEM_ETH))
2825 return -EPERM;
2826
Suresh Reddyd98ef502013-04-25 00:56:55 +00002827 if (mutex_lock_interruptible(&adapter->mbox_lock))
2828 return -1;
2829
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002830 memset(&cmd, 0, sizeof(struct be_dma_mem));
2831 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2832 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2833 &cmd.dma);
2834 if (!cmd.va) {
2835 dev_err(&adapter->pdev->dev,
2836 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002837 status = -ENOMEM;
2838 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002839 }
2840
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002841 wrb = wrb_from_mbox(adapter);
2842 if (!wrb) {
2843 status = -EBUSY;
2844 goto err;
2845 }
2846
2847 req = cmd.va;
2848
2849 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2850 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2851 payload_len, wrb, &cmd);
2852
2853 req->hdr.version = 1;
2854 req->query_options = BE_GET_WOL_CAP;
2855
2856 status = be_mbox_notify_wait(adapter);
2857 if (!status) {
2858 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
2859 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
2860
2861 /* the command could succeed misleadingly on old f/w
2862 * which is not aware of the V1 version. fake an error. */
2863 if (resp->hdr.response_length < payload_len) {
2864 status = -1;
2865 goto err;
2866 }
2867 adapter->wol_cap = resp->wol_settings;
2868 }
2869err:
2870 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002871 if (cmd.va)
2872 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002873 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00002874
2875}
2876int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
2877 struct be_dma_mem *cmd)
2878{
2879 struct be_mcc_wrb *wrb;
2880 struct be_cmd_req_get_ext_fat_caps *req;
2881 int status;
2882
2883 if (mutex_lock_interruptible(&adapter->mbox_lock))
2884 return -1;
2885
2886 wrb = wrb_from_mbox(adapter);
2887 if (!wrb) {
2888 status = -EBUSY;
2889 goto err;
2890 }
2891
2892 req = cmd->va;
2893 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2894 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
2895 cmd->size, wrb, cmd);
2896 req->parameter_type = cpu_to_le32(1);
2897
2898 status = be_mbox_notify_wait(adapter);
2899err:
2900 mutex_unlock(&adapter->mbox_lock);
2901 return status;
2902}
2903
2904int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
2905 struct be_dma_mem *cmd,
2906 struct be_fat_conf_params *configs)
2907{
2908 struct be_mcc_wrb *wrb;
2909 struct be_cmd_req_set_ext_fat_caps *req;
2910 int status;
2911
2912 spin_lock_bh(&adapter->mcc_lock);
2913
2914 wrb = wrb_from_mccq(adapter);
2915 if (!wrb) {
2916 status = -EBUSY;
2917 goto err;
2918 }
2919
2920 req = cmd->va;
2921 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
2922 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2923 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
2924 cmd->size, wrb, cmd);
2925
2926 status = be_mcc_notify_wait(adapter);
2927err:
2928 spin_unlock_bh(&adapter->mcc_lock);
2929 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002930}
Parav Pandit6a4ab662012-03-26 14:27:12 +00002931
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00002932int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
2933{
2934 struct be_mcc_wrb *wrb;
2935 struct be_cmd_req_get_port_name *req;
2936 int status;
2937
2938 if (!lancer_chip(adapter)) {
2939 *port_name = adapter->hba_port_num + '0';
2940 return 0;
2941 }
2942
2943 spin_lock_bh(&adapter->mcc_lock);
2944
2945 wrb = wrb_from_mccq(adapter);
2946 if (!wrb) {
2947 status = -EBUSY;
2948 goto err;
2949 }
2950
2951 req = embedded_payload(wrb);
2952
2953 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2954 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
2955 NULL);
2956 req->hdr.version = 1;
2957
2958 status = be_mcc_notify_wait(adapter);
2959 if (!status) {
2960 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
2961 *port_name = resp->port_name[adapter->hba_port_num];
2962 } else {
2963 *port_name = adapter->hba_port_num + '0';
2964 }
2965err:
2966 spin_unlock_bh(&adapter->mcc_lock);
2967 return status;
2968}
2969
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002970static struct be_nic_resource_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
2971 u32 max_buf_size)
2972{
2973 struct be_nic_resource_desc *desc = (struct be_nic_resource_desc *)buf;
2974 int i;
2975
2976 for (i = 0; i < desc_count; i++) {
Kalesh AP28710c52013-04-28 22:21:13 +00002977 desc->desc_len = desc->desc_len ? : RESOURCE_DESC_SIZE;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002978 if (((void *)desc + desc->desc_len) >
Wei Yang950e2952013-05-22 15:58:22 +00002979 (void *)(buf + max_buf_size))
2980 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002981
Vasundhara Volama05f99d2013-04-21 23:28:17 +00002982 if (desc->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
2983 desc->desc_type == NIC_RESOURCE_DESC_TYPE_V1)
Wei Yang950e2952013-05-22 15:58:22 +00002984 return desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002985
2986 desc = (void *)desc + desc->desc_len;
2987 }
2988
Wei Yang950e2952013-05-22 15:58:22 +00002989 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002990}
2991
2992/* Uses Mbox */
2993int be_cmd_get_func_config(struct be_adapter *adapter)
2994{
2995 struct be_mcc_wrb *wrb;
2996 struct be_cmd_req_get_func_config *req;
2997 int status;
2998 struct be_dma_mem cmd;
2999
Suresh Reddyd98ef502013-04-25 00:56:55 +00003000 if (mutex_lock_interruptible(&adapter->mbox_lock))
3001 return -1;
3002
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003003 memset(&cmd, 0, sizeof(struct be_dma_mem));
3004 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
3005 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3006 &cmd.dma);
3007 if (!cmd.va) {
3008 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003009 status = -ENOMEM;
3010 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003011 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003012
3013 wrb = wrb_from_mbox(adapter);
3014 if (!wrb) {
3015 status = -EBUSY;
3016 goto err;
3017 }
3018
3019 req = cmd.va;
3020
3021 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3022 OPCODE_COMMON_GET_FUNC_CONFIG,
3023 cmd.size, wrb, &cmd);
3024
Kalesh AP28710c52013-04-28 22:21:13 +00003025 if (skyhawk_chip(adapter))
3026 req->hdr.version = 1;
3027
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003028 status = be_mbox_notify_wait(adapter);
3029 if (!status) {
3030 struct be_cmd_resp_get_func_config *resp = cmd.va;
3031 u32 desc_count = le32_to_cpu(resp->desc_count);
3032 struct be_nic_resource_desc *desc;
3033
3034 desc = be_get_nic_desc(resp->func_param, desc_count,
3035 sizeof(resp->func_param));
3036 if (!desc) {
3037 status = -EINVAL;
3038 goto err;
3039 }
3040
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003041 adapter->pf_number = desc->pf_num;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003042 adapter->max_pmac_cnt = le16_to_cpu(desc->unicast_mac_count);
3043 adapter->max_vlans = le16_to_cpu(desc->vlan_count);
3044 adapter->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3045 adapter->max_tx_queues = le16_to_cpu(desc->txq_count);
3046 adapter->max_rss_queues = le16_to_cpu(desc->rssq_count);
3047 adapter->max_rx_queues = le16_to_cpu(desc->rq_count);
3048
3049 adapter->max_event_queues = le16_to_cpu(desc->eq_count);
3050 adapter->if_cap_flags = le32_to_cpu(desc->cap_flags);
3051 }
3052err:
3053 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003054 if (cmd.va)
3055 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003056 return status;
3057}
3058
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003059/* Uses mbox */
3060int be_cmd_get_profile_config_mbox(struct be_adapter *adapter,
3061 u8 domain, struct be_dma_mem *cmd)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003062{
3063 struct be_mcc_wrb *wrb;
3064 struct be_cmd_req_get_profile_config *req;
3065 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003066
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003067 if (mutex_lock_interruptible(&adapter->mbox_lock))
3068 return -1;
3069 wrb = wrb_from_mbox(adapter);
3070
3071 req = cmd->va;
3072 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3073 OPCODE_COMMON_GET_PROFILE_CONFIG,
3074 cmd->size, wrb, cmd);
3075
3076 req->type = ACTIVE_PROFILE_TYPE;
3077 req->hdr.domain = domain;
3078 if (!lancer_chip(adapter))
3079 req->hdr.version = 1;
3080
3081 status = be_mbox_notify_wait(adapter);
3082
3083 mutex_unlock(&adapter->mbox_lock);
3084 return status;
3085}
3086
3087/* Uses sync mcc */
3088int be_cmd_get_profile_config_mccq(struct be_adapter *adapter,
3089 u8 domain, struct be_dma_mem *cmd)
3090{
3091 struct be_mcc_wrb *wrb;
3092 struct be_cmd_req_get_profile_config *req;
3093 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003094
3095 spin_lock_bh(&adapter->mcc_lock);
3096
3097 wrb = wrb_from_mccq(adapter);
3098 if (!wrb) {
3099 status = -EBUSY;
3100 goto err;
3101 }
3102
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003103 req = cmd->va;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003104 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3105 OPCODE_COMMON_GET_PROFILE_CONFIG,
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003106 cmd->size, wrb, cmd);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003107
3108 req->type = ACTIVE_PROFILE_TYPE;
3109 req->hdr.domain = domain;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003110 if (!lancer_chip(adapter))
3111 req->hdr.version = 1;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003112
3113 status = be_mcc_notify_wait(adapter);
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003114
3115err:
3116 spin_unlock_bh(&adapter->mcc_lock);
3117 return status;
3118}
3119
3120/* Uses sync mcc, if MCCQ is already created otherwise mbox */
3121int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags,
3122 u16 *txq_count, u8 domain)
3123{
3124 struct be_queue_info *mccq = &adapter->mcc_obj.q;
3125 struct be_dma_mem cmd;
3126 int status;
3127
3128 memset(&cmd, 0, sizeof(struct be_dma_mem));
3129 if (!lancer_chip(adapter))
3130 cmd.size = sizeof(struct be_cmd_resp_get_profile_config_v1);
3131 else
3132 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3133 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3134 &cmd.dma);
3135 if (!cmd.va) {
3136 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
3137 return -ENOMEM;
3138 }
3139
3140 if (!mccq->created)
3141 status = be_cmd_get_profile_config_mbox(adapter, domain, &cmd);
3142 else
3143 status = be_cmd_get_profile_config_mccq(adapter, domain, &cmd);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003144 if (!status) {
3145 struct be_cmd_resp_get_profile_config *resp = cmd.va;
3146 u32 desc_count = le32_to_cpu(resp->desc_count);
3147 struct be_nic_resource_desc *desc;
3148
3149 desc = be_get_nic_desc(resp->func_param, desc_count,
3150 sizeof(resp->func_param));
3151
3152 if (!desc) {
3153 status = -EINVAL;
3154 goto err;
3155 }
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003156 if (cap_flags)
3157 *cap_flags = le32_to_cpu(desc->cap_flags);
3158 if (txq_count)
3159 *txq_count = le32_to_cpu(desc->txq_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003160 }
3161err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003162 if (cmd.va)
3163 pci_free_consistent(adapter->pdev, cmd.size,
3164 cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003165 return status;
3166}
3167
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003168/* Uses sync mcc */
3169int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
3170 u8 domain)
3171{
3172 struct be_mcc_wrb *wrb;
3173 struct be_cmd_req_set_profile_config *req;
3174 int status;
3175
3176 spin_lock_bh(&adapter->mcc_lock);
3177
3178 wrb = wrb_from_mccq(adapter);
3179 if (!wrb) {
3180 status = -EBUSY;
3181 goto err;
3182 }
3183
3184 req = embedded_payload(wrb);
3185
3186 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3187 OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req),
3188 wrb, NULL);
3189
3190 req->hdr.domain = domain;
3191 req->desc_count = cpu_to_le32(1);
3192
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003193 req->nic_desc.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003194 req->nic_desc.desc_len = RESOURCE_DESC_SIZE;
3195 req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV);
3196 req->nic_desc.pf_num = adapter->pf_number;
3197 req->nic_desc.vf_num = domain;
3198
3199 /* Mark fields invalid */
3200 req->nic_desc.unicast_mac_count = 0xFFFF;
3201 req->nic_desc.mcc_count = 0xFFFF;
3202 req->nic_desc.vlan_count = 0xFFFF;
3203 req->nic_desc.mcast_mac_count = 0xFFFF;
3204 req->nic_desc.txq_count = 0xFFFF;
3205 req->nic_desc.rq_count = 0xFFFF;
3206 req->nic_desc.rssq_count = 0xFFFF;
3207 req->nic_desc.lro_count = 0xFFFF;
3208 req->nic_desc.cq_count = 0xFFFF;
3209 req->nic_desc.toe_conn_count = 0xFFFF;
3210 req->nic_desc.eq_count = 0xFFFF;
3211 req->nic_desc.link_param = 0xFF;
3212 req->nic_desc.bw_min = 0xFFFFFFFF;
3213 req->nic_desc.acpi_params = 0xFF;
3214 req->nic_desc.wol_param = 0x0F;
3215
3216 /* Change BW */
3217 req->nic_desc.bw_min = cpu_to_le32(bps);
3218 req->nic_desc.bw_max = cpu_to_le32(bps);
3219 status = be_mcc_notify_wait(adapter);
3220err:
3221 spin_unlock_bh(&adapter->mcc_lock);
3222 return status;
3223}
3224
Sathya Perla4c876612013-02-03 20:30:11 +00003225int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3226 int vf_num)
3227{
3228 struct be_mcc_wrb *wrb;
3229 struct be_cmd_req_get_iface_list *req;
3230 struct be_cmd_resp_get_iface_list *resp;
3231 int status;
3232
3233 spin_lock_bh(&adapter->mcc_lock);
3234
3235 wrb = wrb_from_mccq(adapter);
3236 if (!wrb) {
3237 status = -EBUSY;
3238 goto err;
3239 }
3240 req = embedded_payload(wrb);
3241
3242 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3243 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3244 wrb, NULL);
3245 req->hdr.domain = vf_num + 1;
3246
3247 status = be_mcc_notify_wait(adapter);
3248 if (!status) {
3249 resp = (struct be_cmd_resp_get_iface_list *)req;
3250 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3251 }
3252
3253err:
3254 spin_unlock_bh(&adapter->mcc_lock);
3255 return status;
3256}
3257
Somnath Kotur5c510812013-05-30 02:52:23 +00003258static int lancer_wait_idle(struct be_adapter *adapter)
3259{
3260#define SLIPORT_IDLE_TIMEOUT 30
3261 u32 reg_val;
3262 int status = 0, i;
3263
3264 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
3265 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
3266 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
3267 break;
3268
3269 ssleep(1);
3270 }
3271
3272 if (i == SLIPORT_IDLE_TIMEOUT)
3273 status = -1;
3274
3275 return status;
3276}
3277
3278int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
3279{
3280 int status = 0;
3281
3282 status = lancer_wait_idle(adapter);
3283 if (status)
3284 return status;
3285
3286 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
3287
3288 return status;
3289}
3290
3291/* Routine to check whether dump image is present or not */
3292bool dump_present(struct be_adapter *adapter)
3293{
3294 u32 sliport_status = 0;
3295
3296 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
3297 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
3298}
3299
3300int lancer_initiate_dump(struct be_adapter *adapter)
3301{
3302 int status;
3303
3304 /* give firmware reset and diagnostic dump */
3305 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
3306 PHYSDEV_CONTROL_DD_MASK);
3307 if (status < 0) {
3308 dev_err(&adapter->pdev->dev, "Firmware reset failed\n");
3309 return status;
3310 }
3311
3312 status = lancer_wait_idle(adapter);
3313 if (status)
3314 return status;
3315
3316 if (!dump_present(adapter)) {
3317 dev_err(&adapter->pdev->dev, "Dump image not present\n");
3318 return -1;
3319 }
3320
3321 return 0;
3322}
3323
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003324/* Uses sync mcc */
3325int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
3326{
3327 struct be_mcc_wrb *wrb;
3328 struct be_cmd_enable_disable_vf *req;
3329 int status;
3330
3331 if (!lancer_chip(adapter))
3332 return 0;
3333
3334 spin_lock_bh(&adapter->mcc_lock);
3335
3336 wrb = wrb_from_mccq(adapter);
3337 if (!wrb) {
3338 status = -EBUSY;
3339 goto err;
3340 }
3341
3342 req = embedded_payload(wrb);
3343
3344 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3345 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
3346 wrb, NULL);
3347
3348 req->hdr.domain = domain;
3349 req->enable = 1;
3350 status = be_mcc_notify_wait(adapter);
3351err:
3352 spin_unlock_bh(&adapter->mcc_lock);
3353 return status;
3354}
3355
Somnath Kotur68c45a22013-03-14 02:42:07 +00003356int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
3357{
3358 struct be_mcc_wrb *wrb;
3359 struct be_cmd_req_intr_set *req;
3360 int status;
3361
3362 if (mutex_lock_interruptible(&adapter->mbox_lock))
3363 return -1;
3364
3365 wrb = wrb_from_mbox(adapter);
3366
3367 req = embedded_payload(wrb);
3368
3369 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3370 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
3371 wrb, NULL);
3372
3373 req->intr_enabled = intr_enable;
3374
3375 status = be_mbox_notify_wait(adapter);
3376
3377 mutex_unlock(&adapter->mbox_lock);
3378 return status;
3379}
3380
Parav Pandit6a4ab662012-03-26 14:27:12 +00003381int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
3382 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
3383{
3384 struct be_adapter *adapter = netdev_priv(netdev_handle);
3385 struct be_mcc_wrb *wrb;
3386 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
3387 struct be_cmd_req_hdr *req;
3388 struct be_cmd_resp_hdr *resp;
3389 int status;
3390
3391 spin_lock_bh(&adapter->mcc_lock);
3392
3393 wrb = wrb_from_mccq(adapter);
3394 if (!wrb) {
3395 status = -EBUSY;
3396 goto err;
3397 }
3398 req = embedded_payload(wrb);
3399 resp = embedded_payload(wrb);
3400
3401 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
3402 hdr->opcode, wrb_payload_size, wrb, NULL);
3403 memcpy(req, wrb_payload, wrb_payload_size);
3404 be_dws_cpu_to_le(req, wrb_payload_size);
3405
3406 status = be_mcc_notify_wait(adapter);
3407 if (cmd_status)
3408 *cmd_status = (status & 0xffff);
3409 if (ext_status)
3410 *ext_status = 0;
3411 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
3412 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
3413err:
3414 spin_unlock_bh(&adapter->mcc_lock);
3415 return status;
3416}
3417EXPORT_SYMBOL(be_roce_mcc_cmd);