blob: 24c80d1d70bab59dd21c7e71d6513a174b681dd2 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparded2145cd2011-03-16 08:20:46 +00002 * Copyright (C) 2005 - 2011 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);
513 else
514 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
Sathya Perla713d03942009-11-22 22:02:45 +0000721 if (atomic_read(&mccq->used) >= mccq->len) {
722 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
723 return NULL;
724 }
725
Sathya Perlab31c50a2009-09-17 10:30:13 -0700726 wrb = queue_head_node(mccq);
727 queue_head_inc(mccq);
728 atomic_inc(&mccq->used);
729 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000730 return wrb;
731}
732
Sathya Perla2243e2e2009-11-22 22:02:03 +0000733/* Tell fw we're about to start firing cmds by writing a
734 * special pattern across the wrb hdr; uses mbox
735 */
736int be_cmd_fw_init(struct be_adapter *adapter)
737{
738 u8 *wrb;
739 int status;
740
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000741 if (lancer_chip(adapter))
742 return 0;
743
Ivan Vecera29849612010-12-14 05:43:19 +0000744 if (mutex_lock_interruptible(&adapter->mbox_lock))
745 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000746
747 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000748 *wrb++ = 0xFF;
749 *wrb++ = 0x12;
750 *wrb++ = 0x34;
751 *wrb++ = 0xFF;
752 *wrb++ = 0xFF;
753 *wrb++ = 0x56;
754 *wrb++ = 0x78;
755 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000756
757 status = be_mbox_notify_wait(adapter);
758
Ivan Vecera29849612010-12-14 05:43:19 +0000759 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000760 return status;
761}
762
763/* Tell fw we're done with firing cmds by writing a
764 * special pattern across the wrb hdr; uses mbox
765 */
766int be_cmd_fw_clean(struct be_adapter *adapter)
767{
768 u8 *wrb;
769 int status;
770
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000771 if (lancer_chip(adapter))
772 return 0;
773
Ivan Vecera29849612010-12-14 05:43:19 +0000774 if (mutex_lock_interruptible(&adapter->mbox_lock))
775 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000776
777 wrb = (u8 *)wrb_from_mbox(adapter);
778 *wrb++ = 0xFF;
779 *wrb++ = 0xAA;
780 *wrb++ = 0xBB;
781 *wrb++ = 0xFF;
782 *wrb++ = 0xFF;
783 *wrb++ = 0xCC;
784 *wrb++ = 0xDD;
785 *wrb = 0xFF;
786
787 status = be_mbox_notify_wait(adapter);
788
Ivan Vecera29849612010-12-14 05:43:19 +0000789 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000790 return status;
791}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000792
Sathya Perla8788fdc2009-07-27 22:52:03 +0000793int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700794 struct be_queue_info *eq, int eq_delay)
795{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700796 struct be_mcc_wrb *wrb;
797 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700798 struct be_dma_mem *q_mem = &eq->dma_mem;
799 int status;
800
Ivan Vecera29849612010-12-14 05:43:19 +0000801 if (mutex_lock_interruptible(&adapter->mbox_lock))
802 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700803
804 wrb = wrb_from_mbox(adapter);
805 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700806
Somnath Kotur106df1e2011-10-27 07:12:13 +0000807 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
808 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700809
810 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
811
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700812 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
813 /* 4byte eqe*/
814 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
815 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
816 __ilog2_u32(eq->len/256));
817 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
818 eq_delay_to_mult(eq_delay));
819 be_dws_cpu_to_le(req->context, sizeof(req->context));
820
821 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
822
Sathya Perlab31c50a2009-09-17 10:30:13 -0700823 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700824 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700825 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700826 eq->id = le16_to_cpu(resp->eq_id);
827 eq->created = true;
828 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700829
Ivan Vecera29849612010-12-14 05:43:19 +0000830 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700831 return status;
832}
833
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000834/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000835int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000836 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700837{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700838 struct be_mcc_wrb *wrb;
839 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700840 int status;
841
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000842 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700843
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000844 wrb = wrb_from_mccq(adapter);
845 if (!wrb) {
846 status = -EBUSY;
847 goto err;
848 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700849 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700850
Somnath Kotur106df1e2011-10-27 07:12:13 +0000851 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
852 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000853 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700854 if (permanent) {
855 req->permanent = 1;
856 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700857 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000858 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700859 req->permanent = 0;
860 }
861
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000862 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700863 if (!status) {
864 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700865 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700866 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700867
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000868err:
869 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700870 return status;
871}
872
Sathya Perlab31c50a2009-09-17 10:30:13 -0700873/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000874int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000875 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700876{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700877 struct be_mcc_wrb *wrb;
878 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700879 int status;
880
Sathya Perlab31c50a2009-09-17 10:30:13 -0700881 spin_lock_bh(&adapter->mcc_lock);
882
883 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000884 if (!wrb) {
885 status = -EBUSY;
886 goto err;
887 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700888 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700889
Somnath Kotur106df1e2011-10-27 07:12:13 +0000890 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
891 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700892
Ajit Khapardef8617e02011-02-11 13:36:37 +0000893 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700894 req->if_id = cpu_to_le32(if_id);
895 memcpy(req->mac_address, mac_addr, ETH_ALEN);
896
Sathya Perlab31c50a2009-09-17 10:30:13 -0700897 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700898 if (!status) {
899 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
900 *pmac_id = le32_to_cpu(resp->pmac_id);
901 }
902
Sathya Perla713d03942009-11-22 22:02:45 +0000903err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700904 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000905
906 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
907 status = -EPERM;
908
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700909 return status;
910}
911
Sathya Perlab31c50a2009-09-17 10:30:13 -0700912/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000913int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700914{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700915 struct be_mcc_wrb *wrb;
916 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700917 int status;
918
Sathya Perla30128032011-11-10 19:17:57 +0000919 if (pmac_id == -1)
920 return 0;
921
Sathya Perlab31c50a2009-09-17 10:30:13 -0700922 spin_lock_bh(&adapter->mcc_lock);
923
924 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000925 if (!wrb) {
926 status = -EBUSY;
927 goto err;
928 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700929 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700930
Somnath Kotur106df1e2011-10-27 07:12:13 +0000931 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
932 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700933
Ajit Khapardef8617e02011-02-11 13:36:37 +0000934 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700935 req->if_id = cpu_to_le32(if_id);
936 req->pmac_id = cpu_to_le32(pmac_id);
937
Sathya Perlab31c50a2009-09-17 10:30:13 -0700938 status = be_mcc_notify_wait(adapter);
939
Sathya Perla713d03942009-11-22 22:02:45 +0000940err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700941 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700942 return status;
943}
944
Sathya Perlab31c50a2009-09-17 10:30:13 -0700945/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000946int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
947 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700948{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700949 struct be_mcc_wrb *wrb;
950 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700951 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700952 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700953 int status;
954
Ivan Vecera29849612010-12-14 05:43:19 +0000955 if (mutex_lock_interruptible(&adapter->mbox_lock))
956 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700957
958 wrb = wrb_from_mbox(adapter);
959 req = embedded_payload(wrb);
960 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700961
Somnath Kotur106df1e2011-10-27 07:12:13 +0000962 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
963 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700964
965 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000966 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000967 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000968 req->page_size = 1; /* 1 for 4K */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000969 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
970 no_delay);
971 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
972 __ilog2_u32(cq->len/256));
973 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
974 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
975 ctxt, 1);
976 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
977 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000978 } else {
979 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
980 coalesce_wm);
981 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
982 ctxt, no_delay);
983 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
984 __ilog2_u32(cq->len/256));
985 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000986 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
987 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000988 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700989
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700990 be_dws_cpu_to_le(ctxt, sizeof(req->context));
991
992 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
993
Sathya Perlab31c50a2009-09-17 10:30:13 -0700994 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700995 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700996 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700997 cq->id = le16_to_cpu(resp->cq_id);
998 cq->created = true;
999 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001000
Ivan Vecera29849612010-12-14 05:43:19 +00001001 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001002
1003 return status;
1004}
1005
1006static u32 be_encoded_q_len(int q_len)
1007{
1008 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
1009 if (len_encoded == 16)
1010 len_encoded = 0;
1011 return len_encoded;
1012}
1013
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001014int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +00001015 struct be_queue_info *mccq,
1016 struct be_queue_info *cq)
1017{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001018 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001019 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001020 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001021 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001022 int status;
1023
Ivan Vecera29849612010-12-14 05:43:19 +00001024 if (mutex_lock_interruptible(&adapter->mbox_lock))
1025 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001026
1027 wrb = wrb_from_mbox(adapter);
1028 req = embedded_payload(wrb);
1029 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001030
Somnath Kotur106df1e2011-10-27 07:12:13 +00001031 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1032 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001033
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001034 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001035 if (lancer_chip(adapter)) {
1036 req->hdr.version = 1;
1037 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001038
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001039 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
1040 be_encoded_q_len(mccq->len));
1041 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
1042 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
1043 ctxt, cq->id);
1044 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
1045 ctxt, 1);
1046
1047 } else {
1048 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1049 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1050 be_encoded_q_len(mccq->len));
1051 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1052 }
1053
Somnath Koturcc4ce022010-10-21 07:11:14 -07001054 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001055 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001056 req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001057 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1058
1059 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1060
Sathya Perlab31c50a2009-09-17 10:30:13 -07001061 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001062 if (!status) {
1063 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1064 mccq->id = le16_to_cpu(resp->id);
1065 mccq->created = true;
1066 }
Ivan Vecera29849612010-12-14 05:43:19 +00001067 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001068
1069 return status;
1070}
1071
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001072int be_cmd_mccq_org_create(struct be_adapter *adapter,
1073 struct be_queue_info *mccq,
1074 struct be_queue_info *cq)
1075{
1076 struct be_mcc_wrb *wrb;
1077 struct be_cmd_req_mcc_create *req;
1078 struct be_dma_mem *q_mem = &mccq->dma_mem;
1079 void *ctxt;
1080 int status;
1081
1082 if (mutex_lock_interruptible(&adapter->mbox_lock))
1083 return -1;
1084
1085 wrb = wrb_from_mbox(adapter);
1086 req = embedded_payload(wrb);
1087 ctxt = &req->context;
1088
Somnath Kotur106df1e2011-10-27 07:12:13 +00001089 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1090 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001091
1092 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1093
1094 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1095 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1096 be_encoded_q_len(mccq->len));
1097 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1098
1099 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1100
1101 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1102
1103 status = be_mbox_notify_wait(adapter);
1104 if (!status) {
1105 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1106 mccq->id = le16_to_cpu(resp->id);
1107 mccq->created = true;
1108 }
1109
1110 mutex_unlock(&adapter->mbox_lock);
1111 return status;
1112}
1113
1114int be_cmd_mccq_create(struct be_adapter *adapter,
1115 struct be_queue_info *mccq,
1116 struct be_queue_info *cq)
1117{
1118 int status;
1119
1120 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
1121 if (status && !lancer_chip(adapter)) {
1122 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1123 "or newer to avoid conflicting priorities between NIC "
1124 "and FCoE traffic");
1125 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1126 }
1127 return status;
1128}
1129
Sathya Perla8788fdc2009-07-27 22:52:03 +00001130int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001131 struct be_queue_info *txq,
1132 struct be_queue_info *cq)
1133{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001134 struct be_mcc_wrb *wrb;
1135 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001136 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001137 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001138 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001139
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001140 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001141
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001142 wrb = wrb_from_mccq(adapter);
1143 if (!wrb) {
1144 status = -EBUSY;
1145 goto err;
1146 }
1147
Sathya Perlab31c50a2009-09-17 10:30:13 -07001148 req = embedded_payload(wrb);
1149 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001150
Somnath Kotur106df1e2011-10-27 07:12:13 +00001151 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1152 OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001153
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001154 if (lancer_chip(adapter)) {
1155 req->hdr.version = 1;
1156 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
1157 adapter->if_handle);
1158 }
1159
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001160 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1161 req->ulp_num = BE_ULP1_NUM;
1162 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
1163
Sathya Perlab31c50a2009-09-17 10:30:13 -07001164 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
1165 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001166 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
1167 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
1168
1169 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1170
1171 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1172
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001173 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001174 if (!status) {
1175 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
1176 txq->id = le16_to_cpu(resp->cid);
1177 txq->created = true;
1178 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001179
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001180err:
1181 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001182
1183 return status;
1184}
1185
Sathya Perla482c9e72011-06-29 23:33:17 +00001186/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001187int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001188 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001189 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001190{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001191 struct be_mcc_wrb *wrb;
1192 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001193 struct be_dma_mem *q_mem = &rxq->dma_mem;
1194 int status;
1195
Sathya Perla482c9e72011-06-29 23:33:17 +00001196 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001197
Sathya Perla482c9e72011-06-29 23:33:17 +00001198 wrb = wrb_from_mccq(adapter);
1199 if (!wrb) {
1200 status = -EBUSY;
1201 goto err;
1202 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001203 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001204
Somnath Kotur106df1e2011-10-27 07:12:13 +00001205 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1206 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001207
1208 req->cq_id = cpu_to_le16(cq_id);
1209 req->frag_size = fls(frag_size) - 1;
1210 req->num_pages = 2;
1211 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1212 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001213 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001214 req->rss_queue = cpu_to_le32(rss);
1215
Sathya Perla482c9e72011-06-29 23:33:17 +00001216 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001217 if (!status) {
1218 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1219 rxq->id = le16_to_cpu(resp->id);
1220 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001221 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001222 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001223
Sathya Perla482c9e72011-06-29 23:33:17 +00001224err:
1225 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001226 return status;
1227}
1228
Sathya Perlab31c50a2009-09-17 10:30:13 -07001229/* Generic destroyer function for all types of queues
1230 * Uses Mbox
1231 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001232int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001233 int queue_type)
1234{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001235 struct be_mcc_wrb *wrb;
1236 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001237 u8 subsys = 0, opcode = 0;
1238 int status;
1239
Ivan Vecera29849612010-12-14 05:43:19 +00001240 if (mutex_lock_interruptible(&adapter->mbox_lock))
1241 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001242
Sathya Perlab31c50a2009-09-17 10:30:13 -07001243 wrb = wrb_from_mbox(adapter);
1244 req = embedded_payload(wrb);
1245
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001246 switch (queue_type) {
1247 case QTYPE_EQ:
1248 subsys = CMD_SUBSYSTEM_COMMON;
1249 opcode = OPCODE_COMMON_EQ_DESTROY;
1250 break;
1251 case QTYPE_CQ:
1252 subsys = CMD_SUBSYSTEM_COMMON;
1253 opcode = OPCODE_COMMON_CQ_DESTROY;
1254 break;
1255 case QTYPE_TXQ:
1256 subsys = CMD_SUBSYSTEM_ETH;
1257 opcode = OPCODE_ETH_TX_DESTROY;
1258 break;
1259 case QTYPE_RXQ:
1260 subsys = CMD_SUBSYSTEM_ETH;
1261 opcode = OPCODE_ETH_RX_DESTROY;
1262 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001263 case QTYPE_MCCQ:
1264 subsys = CMD_SUBSYSTEM_COMMON;
1265 opcode = OPCODE_COMMON_MCC_DESTROY;
1266 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001267 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001268 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001269 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001270
Somnath Kotur106df1e2011-10-27 07:12:13 +00001271 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1272 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001273 req->id = cpu_to_le16(q->id);
1274
Sathya Perlab31c50a2009-09-17 10:30:13 -07001275 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001276 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001277
Ivan Vecera29849612010-12-14 05:43:19 +00001278 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001279 return status;
1280}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001281
Sathya Perla482c9e72011-06-29 23:33:17 +00001282/* Uses MCC */
1283int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1284{
1285 struct be_mcc_wrb *wrb;
1286 struct be_cmd_req_q_destroy *req;
1287 int status;
1288
1289 spin_lock_bh(&adapter->mcc_lock);
1290
1291 wrb = wrb_from_mccq(adapter);
1292 if (!wrb) {
1293 status = -EBUSY;
1294 goto err;
1295 }
1296 req = embedded_payload(wrb);
1297
Somnath Kotur106df1e2011-10-27 07:12:13 +00001298 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1299 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001300 req->id = cpu_to_le16(q->id);
1301
1302 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001303 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001304
1305err:
1306 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001307 return status;
1308}
1309
Sathya Perlab31c50a2009-09-17 10:30:13 -07001310/* Create an rx filtering policy configuration on an i/f
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001311 * Uses MCCQ
Sathya Perlab31c50a2009-09-17 10:30:13 -07001312 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001313int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001314 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001315{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001316 struct be_mcc_wrb *wrb;
1317 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001318 int status;
1319
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001320 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001321
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001322 wrb = wrb_from_mccq(adapter);
1323 if (!wrb) {
1324 status = -EBUSY;
1325 goto err;
1326 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001327 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001328
Somnath Kotur106df1e2011-10-27 07:12:13 +00001329 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1330 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001331 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001332 req->capability_flags = cpu_to_le32(cap_flags);
1333 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001334
1335 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001336
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001337 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001338 if (!status) {
1339 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1340 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001341 }
1342
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001343err:
1344 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001345 return status;
1346}
1347
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001348/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001349int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001350{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001351 struct be_mcc_wrb *wrb;
1352 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001353 int status;
1354
Sathya Perla30128032011-11-10 19:17:57 +00001355 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001356 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001357
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001358 spin_lock_bh(&adapter->mcc_lock);
1359
1360 wrb = wrb_from_mccq(adapter);
1361 if (!wrb) {
1362 status = -EBUSY;
1363 goto err;
1364 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001365 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001366
Somnath Kotur106df1e2011-10-27 07:12:13 +00001367 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1368 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001369 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001370 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001371
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001372 status = be_mcc_notify_wait(adapter);
1373err:
1374 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001375 return status;
1376}
1377
1378/* Get stats is a non embedded command: the request is not embedded inside
1379 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001380 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001381 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001382int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001383{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001384 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001385 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001386 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001387
Sathya Perlab31c50a2009-09-17 10:30:13 -07001388 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001389
Sathya Perlab31c50a2009-09-17 10:30:13 -07001390 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001391 if (!wrb) {
1392 status = -EBUSY;
1393 goto err;
1394 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001395 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001396
Somnath Kotur106df1e2011-10-27 07:12:13 +00001397 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1398 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001399
Sathya Perlaca34fe32012-11-06 17:48:56 +00001400 /* version 1 of the cmd is not supported only by BE2 */
1401 if (!BE2_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001402 hdr->version = 1;
1403
Sathya Perlab31c50a2009-09-17 10:30:13 -07001404 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001405 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001406
Sathya Perla713d03942009-11-22 22:02:45 +00001407err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001408 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001409 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001410}
1411
Selvin Xavier005d5692011-05-16 07:36:35 +00001412/* Lancer Stats */
1413int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1414 struct be_dma_mem *nonemb_cmd)
1415{
1416
1417 struct be_mcc_wrb *wrb;
1418 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001419 int status = 0;
1420
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001421 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1422 CMD_SUBSYSTEM_ETH))
1423 return -EPERM;
1424
Selvin Xavier005d5692011-05-16 07:36:35 +00001425 spin_lock_bh(&adapter->mcc_lock);
1426
1427 wrb = wrb_from_mccq(adapter);
1428 if (!wrb) {
1429 status = -EBUSY;
1430 goto err;
1431 }
1432 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001433
Somnath Kotur106df1e2011-10-27 07:12:13 +00001434 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1435 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1436 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001437
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001438 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001439 req->cmd_params.params.reset_stats = 0;
1440
Selvin Xavier005d5692011-05-16 07:36:35 +00001441 be_mcc_notify(adapter);
1442 adapter->stats_cmd_sent = true;
1443
1444err:
1445 spin_unlock_bh(&adapter->mcc_lock);
1446 return status;
1447}
1448
Sathya Perla323ff712012-09-28 04:39:43 +00001449static int be_mac_to_link_speed(int mac_speed)
1450{
1451 switch (mac_speed) {
1452 case PHY_LINK_SPEED_ZERO:
1453 return 0;
1454 case PHY_LINK_SPEED_10MBPS:
1455 return 10;
1456 case PHY_LINK_SPEED_100MBPS:
1457 return 100;
1458 case PHY_LINK_SPEED_1GBPS:
1459 return 1000;
1460 case PHY_LINK_SPEED_10GBPS:
1461 return 10000;
1462 }
1463 return 0;
1464}
1465
1466/* Uses synchronous mcc
1467 * Returns link_speed in Mbps
1468 */
1469int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1470 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001471{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001472 struct be_mcc_wrb *wrb;
1473 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001474 int status;
1475
Sathya Perlab31c50a2009-09-17 10:30:13 -07001476 spin_lock_bh(&adapter->mcc_lock);
1477
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001478 if (link_status)
1479 *link_status = LINK_DOWN;
1480
Sathya Perlab31c50a2009-09-17 10:30:13 -07001481 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001482 if (!wrb) {
1483 status = -EBUSY;
1484 goto err;
1485 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001486 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001487
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001488 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1489 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1490
Sathya Perlaca34fe32012-11-06 17:48:56 +00001491 /* version 1 of the cmd is not supported only by BE2 */
1492 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001493 req->hdr.version = 1;
1494
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001495 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001496
Sathya Perlab31c50a2009-09-17 10:30:13 -07001497 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001498 if (!status) {
1499 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sathya Perla323ff712012-09-28 04:39:43 +00001500 if (link_speed) {
1501 *link_speed = resp->link_speed ?
1502 le16_to_cpu(resp->link_speed) * 10 :
1503 be_mac_to_link_speed(resp->mac_speed);
1504
1505 if (!resp->logical_link_status)
1506 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001507 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001508 if (link_status)
1509 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001510 }
1511
Sathya Perla713d03942009-11-22 22:02:45 +00001512err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001513 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001514 return status;
1515}
1516
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001517/* Uses synchronous mcc */
1518int be_cmd_get_die_temperature(struct be_adapter *adapter)
1519{
1520 struct be_mcc_wrb *wrb;
1521 struct be_cmd_req_get_cntl_addnl_attribs *req;
1522 int status;
1523
1524 spin_lock_bh(&adapter->mcc_lock);
1525
1526 wrb = wrb_from_mccq(adapter);
1527 if (!wrb) {
1528 status = -EBUSY;
1529 goto err;
1530 }
1531 req = embedded_payload(wrb);
1532
Somnath Kotur106df1e2011-10-27 07:12:13 +00001533 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1534 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1535 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001536
Somnath Kotur3de09452011-09-30 07:25:05 +00001537 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001538
1539err:
1540 spin_unlock_bh(&adapter->mcc_lock);
1541 return status;
1542}
1543
Somnath Kotur311fddc2011-03-16 21:22:43 +00001544/* Uses synchronous mcc */
1545int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1546{
1547 struct be_mcc_wrb *wrb;
1548 struct be_cmd_req_get_fat *req;
1549 int status;
1550
1551 spin_lock_bh(&adapter->mcc_lock);
1552
1553 wrb = wrb_from_mccq(adapter);
1554 if (!wrb) {
1555 status = -EBUSY;
1556 goto err;
1557 }
1558 req = embedded_payload(wrb);
1559
Somnath Kotur106df1e2011-10-27 07:12:13 +00001560 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1561 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001562 req->fat_operation = cpu_to_le32(QUERY_FAT);
1563 status = be_mcc_notify_wait(adapter);
1564 if (!status) {
1565 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1566 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001567 *log_size = le32_to_cpu(resp->log_size) -
1568 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001569 }
1570err:
1571 spin_unlock_bh(&adapter->mcc_lock);
1572 return status;
1573}
1574
1575void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1576{
1577 struct be_dma_mem get_fat_cmd;
1578 struct be_mcc_wrb *wrb;
1579 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001580 u32 offset = 0, total_size, buf_size,
1581 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001582 int status;
1583
1584 if (buf_len == 0)
1585 return;
1586
1587 total_size = buf_len;
1588
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001589 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1590 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1591 get_fat_cmd.size,
1592 &get_fat_cmd.dma);
1593 if (!get_fat_cmd.va) {
1594 status = -ENOMEM;
1595 dev_err(&adapter->pdev->dev,
1596 "Memory allocation failure while retrieving FAT data\n");
1597 return;
1598 }
1599
Somnath Kotur311fddc2011-03-16 21:22:43 +00001600 spin_lock_bh(&adapter->mcc_lock);
1601
Somnath Kotur311fddc2011-03-16 21:22:43 +00001602 while (total_size) {
1603 buf_size = min(total_size, (u32)60*1024);
1604 total_size -= buf_size;
1605
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001606 wrb = wrb_from_mccq(adapter);
1607 if (!wrb) {
1608 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001609 goto err;
1610 }
1611 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001612
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001613 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001614 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1615 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1616 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001617
1618 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1619 req->read_log_offset = cpu_to_le32(log_offset);
1620 req->read_log_length = cpu_to_le32(buf_size);
1621 req->data_buffer_size = cpu_to_le32(buf_size);
1622
1623 status = be_mcc_notify_wait(adapter);
1624 if (!status) {
1625 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1626 memcpy(buf + offset,
1627 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001628 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001629 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001630 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001631 goto err;
1632 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001633 offset += buf_size;
1634 log_offset += buf_size;
1635 }
1636err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001637 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1638 get_fat_cmd.va,
1639 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001640 spin_unlock_bh(&adapter->mcc_lock);
1641}
1642
Sathya Perla04b71172011-09-27 13:30:27 -04001643/* Uses synchronous mcc */
1644int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1645 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001646{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001647 struct be_mcc_wrb *wrb;
1648 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001649 int status;
1650
Sathya Perla04b71172011-09-27 13:30:27 -04001651 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001652
Sathya Perla04b71172011-09-27 13:30:27 -04001653 wrb = wrb_from_mccq(adapter);
1654 if (!wrb) {
1655 status = -EBUSY;
1656 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001657 }
1658
Sathya Perla04b71172011-09-27 13:30:27 -04001659 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001660
Somnath Kotur106df1e2011-10-27 07:12:13 +00001661 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1662 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001663 status = be_mcc_notify_wait(adapter);
1664 if (!status) {
1665 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1666 strcpy(fw_ver, resp->firmware_version_string);
1667 if (fw_on_flash)
1668 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1669 }
1670err:
1671 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001672 return status;
1673}
1674
Sathya Perlab31c50a2009-09-17 10:30:13 -07001675/* set the EQ delay interval of an EQ to specified value
1676 * Uses async mcc
1677 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001678int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001679{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001680 struct be_mcc_wrb *wrb;
1681 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001682 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001683
Sathya Perlab31c50a2009-09-17 10:30:13 -07001684 spin_lock_bh(&adapter->mcc_lock);
1685
1686 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001687 if (!wrb) {
1688 status = -EBUSY;
1689 goto err;
1690 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001691 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001692
Somnath Kotur106df1e2011-10-27 07:12:13 +00001693 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1694 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001695
1696 req->num_eq = cpu_to_le32(1);
1697 req->delay[0].eq_id = cpu_to_le32(eq_id);
1698 req->delay[0].phase = 0;
1699 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1700
Sathya Perlab31c50a2009-09-17 10:30:13 -07001701 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001702
Sathya Perla713d03942009-11-22 22:02:45 +00001703err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001704 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001705 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001706}
1707
Sathya Perlab31c50a2009-09-17 10:30:13 -07001708/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001709int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001710 u32 num, bool untagged, bool promiscuous)
1711{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001712 struct be_mcc_wrb *wrb;
1713 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001714 int status;
1715
Sathya Perlab31c50a2009-09-17 10:30:13 -07001716 spin_lock_bh(&adapter->mcc_lock);
1717
1718 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001719 if (!wrb) {
1720 status = -EBUSY;
1721 goto err;
1722 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001723 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001724
Somnath Kotur106df1e2011-10-27 07:12:13 +00001725 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1726 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001727
1728 req->interface_id = if_id;
1729 req->promiscuous = promiscuous;
1730 req->untagged = untagged;
1731 req->num_vlan = num;
1732 if (!promiscuous) {
1733 memcpy(req->normal_vlan, vtag_array,
1734 req->num_vlan * sizeof(vtag_array[0]));
1735 }
1736
Sathya Perlab31c50a2009-09-17 10:30:13 -07001737 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001738
Sathya Perla713d03942009-11-22 22:02:45 +00001739err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001740 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001741 return status;
1742}
1743
Sathya Perla5b8821b2011-08-02 19:57:44 +00001744int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001745{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001746 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001747 struct be_dma_mem *mem = &adapter->rx_filter;
1748 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001749 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001750
Sathya Perla8788fdc2009-07-27 22:52:03 +00001751 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001752
Sathya Perlab31c50a2009-09-17 10:30:13 -07001753 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001754 if (!wrb) {
1755 status = -EBUSY;
1756 goto err;
1757 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001758 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001759 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1760 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1761 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001762
Sathya Perla5b8821b2011-08-02 19:57:44 +00001763 req->if_id = cpu_to_le32(adapter->if_handle);
1764 if (flags & IFF_PROMISC) {
1765 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1766 BE_IF_FLAGS_VLAN_PROMISCUOUS);
1767 if (value == ON)
1768 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001769 BE_IF_FLAGS_VLAN_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001770 } else if (flags & IFF_ALLMULTI) {
1771 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001772 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001773 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001774 struct netdev_hw_addr *ha;
1775 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001776
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001777 req->if_flags_mask = req->if_flags =
1778 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001779
1780 /* Reset mcast promisc mode if already set by setting mask
1781 * and not setting flags field
1782 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001783 req->if_flags_mask |=
1784 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
1785 adapter->if_cap_flags);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001786
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001787 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001788 netdev_for_each_mc_addr(ha, adapter->netdev)
1789 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1790 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001791
Sathya Perla0d1d5872011-08-03 05:19:27 -07001792 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001793err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001794 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001795 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001796}
1797
Sathya Perlab31c50a2009-09-17 10:30:13 -07001798/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001799int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001800{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001801 struct be_mcc_wrb *wrb;
1802 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001803 int status;
1804
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001805 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1806 CMD_SUBSYSTEM_COMMON))
1807 return -EPERM;
1808
Sathya Perlab31c50a2009-09-17 10:30:13 -07001809 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001810
Sathya Perlab31c50a2009-09-17 10:30:13 -07001811 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001812 if (!wrb) {
1813 status = -EBUSY;
1814 goto err;
1815 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001816 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001817
Somnath Kotur106df1e2011-10-27 07:12:13 +00001818 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1819 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001820
1821 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1822 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1823
Sathya Perlab31c50a2009-09-17 10:30:13 -07001824 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001825
Sathya Perla713d03942009-11-22 22:02:45 +00001826err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001827 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001828 return status;
1829}
1830
Sathya Perlab31c50a2009-09-17 10:30:13 -07001831/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001832int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001833{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001834 struct be_mcc_wrb *wrb;
1835 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001836 int status;
1837
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001838 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
1839 CMD_SUBSYSTEM_COMMON))
1840 return -EPERM;
1841
Sathya Perlab31c50a2009-09-17 10:30:13 -07001842 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001843
Sathya Perlab31c50a2009-09-17 10:30:13 -07001844 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001845 if (!wrb) {
1846 status = -EBUSY;
1847 goto err;
1848 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001849 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001850
Somnath Kotur106df1e2011-10-27 07:12:13 +00001851 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1852 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001853
Sathya Perlab31c50a2009-09-17 10:30:13 -07001854 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001855 if (!status) {
1856 struct be_cmd_resp_get_flow_control *resp =
1857 embedded_payload(wrb);
1858 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1859 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1860 }
1861
Sathya Perla713d03942009-11-22 22:02:45 +00001862err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001863 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001864 return status;
1865}
1866
Sathya Perlab31c50a2009-09-17 10:30:13 -07001867/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001868int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1869 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001870{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001871 struct be_mcc_wrb *wrb;
1872 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001873 int status;
1874
Ivan Vecera29849612010-12-14 05:43:19 +00001875 if (mutex_lock_interruptible(&adapter->mbox_lock))
1876 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001877
Sathya Perlab31c50a2009-09-17 10:30:13 -07001878 wrb = wrb_from_mbox(adapter);
1879 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001880
Somnath Kotur106df1e2011-10-27 07:12:13 +00001881 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1882 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001883
Sathya Perlab31c50a2009-09-17 10:30:13 -07001884 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001885 if (!status) {
1886 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1887 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001888 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001889 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001890 }
1891
Ivan Vecera29849612010-12-14 05:43:19 +00001892 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001893 return status;
1894}
sarveshwarb14074ea2009-08-05 13:05:24 -07001895
Sathya Perlab31c50a2009-09-17 10:30:13 -07001896/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001897int be_cmd_reset_function(struct be_adapter *adapter)
1898{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001899 struct be_mcc_wrb *wrb;
1900 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001901 int status;
1902
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00001903 if (lancer_chip(adapter)) {
1904 status = lancer_wait_ready(adapter);
1905 if (!status) {
1906 iowrite32(SLI_PORT_CONTROL_IP_MASK,
1907 adapter->db + SLIPORT_CONTROL_OFFSET);
1908 status = lancer_test_and_set_rdy_state(adapter);
1909 }
1910 if (status) {
1911 dev_err(&adapter->pdev->dev,
1912 "Adapter in non recoverable error\n");
1913 }
1914 return status;
1915 }
1916
Ivan Vecera29849612010-12-14 05:43:19 +00001917 if (mutex_lock_interruptible(&adapter->mbox_lock))
1918 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001919
Sathya Perlab31c50a2009-09-17 10:30:13 -07001920 wrb = wrb_from_mbox(adapter);
1921 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001922
Somnath Kotur106df1e2011-10-27 07:12:13 +00001923 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1924 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001925
Sathya Perlab31c50a2009-09-17 10:30:13 -07001926 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001927
Ivan Vecera29849612010-12-14 05:43:19 +00001928 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001929 return status;
1930}
Ajit Khaparde84517482009-09-04 03:12:16 +00001931
Sathya Perla3abcded2010-10-03 22:12:27 -07001932int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1933{
1934 struct be_mcc_wrb *wrb;
1935 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001936 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1937 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1938 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001939 int status;
1940
Ivan Vecera29849612010-12-14 05:43:19 +00001941 if (mutex_lock_interruptible(&adapter->mbox_lock))
1942 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001943
1944 wrb = wrb_from_mbox(adapter);
1945 req = embedded_payload(wrb);
1946
Somnath Kotur106df1e2011-10-27 07:12:13 +00001947 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1948 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001949
1950 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perla1ca7ba92012-02-23 18:50:16 +00001951 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 |
1952 RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6);
Padmanabh Ratnakard3bd3a52012-07-12 03:57:47 +00001953
1954 if (lancer_chip(adapter) || skyhawk_chip(adapter)) {
1955 req->hdr.version = 1;
1956 req->enable_rss |= cpu_to_le16(RSS_ENABLE_UDP_IPV4 |
1957 RSS_ENABLE_UDP_IPV6);
1958 }
1959
Sathya Perla3abcded2010-10-03 22:12:27 -07001960 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1961 memcpy(req->cpu_table, rsstable, table_size);
1962 memcpy(req->hash, myhash, sizeof(myhash));
1963 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1964
1965 status = be_mbox_notify_wait(adapter);
1966
Ivan Vecera29849612010-12-14 05:43:19 +00001967 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001968 return status;
1969}
1970
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001971/* Uses sync mcc */
1972int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1973 u8 bcn, u8 sts, u8 state)
1974{
1975 struct be_mcc_wrb *wrb;
1976 struct be_cmd_req_enable_disable_beacon *req;
1977 int status;
1978
1979 spin_lock_bh(&adapter->mcc_lock);
1980
1981 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001982 if (!wrb) {
1983 status = -EBUSY;
1984 goto err;
1985 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001986 req = embedded_payload(wrb);
1987
Somnath Kotur106df1e2011-10-27 07:12:13 +00001988 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1989 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001990
1991 req->port_num = port_num;
1992 req->beacon_state = state;
1993 req->beacon_duration = bcn;
1994 req->status_duration = sts;
1995
1996 status = be_mcc_notify_wait(adapter);
1997
Sathya Perla713d03942009-11-22 22:02:45 +00001998err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001999 spin_unlock_bh(&adapter->mcc_lock);
2000 return status;
2001}
2002
2003/* Uses sync mcc */
2004int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2005{
2006 struct be_mcc_wrb *wrb;
2007 struct be_cmd_req_get_beacon_state *req;
2008 int status;
2009
2010 spin_lock_bh(&adapter->mcc_lock);
2011
2012 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002013 if (!wrb) {
2014 status = -EBUSY;
2015 goto err;
2016 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002017 req = embedded_payload(wrb);
2018
Somnath Kotur106df1e2011-10-27 07:12:13 +00002019 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2020 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002021
2022 req->port_num = port_num;
2023
2024 status = be_mcc_notify_wait(adapter);
2025 if (!status) {
2026 struct be_cmd_resp_get_beacon_state *resp =
2027 embedded_payload(wrb);
2028 *state = resp->beacon_state;
2029 }
2030
Sathya Perla713d03942009-11-22 22:02:45 +00002031err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002032 spin_unlock_bh(&adapter->mcc_lock);
2033 return status;
2034}
2035
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002036int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002037 u32 data_size, u32 data_offset,
2038 const char *obj_name, u32 *data_written,
2039 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002040{
2041 struct be_mcc_wrb *wrb;
2042 struct lancer_cmd_req_write_object *req;
2043 struct lancer_cmd_resp_write_object *resp;
2044 void *ctxt = NULL;
2045 int status;
2046
2047 spin_lock_bh(&adapter->mcc_lock);
2048 adapter->flash_status = 0;
2049
2050 wrb = wrb_from_mccq(adapter);
2051 if (!wrb) {
2052 status = -EBUSY;
2053 goto err_unlock;
2054 }
2055
2056 req = embedded_payload(wrb);
2057
Somnath Kotur106df1e2011-10-27 07:12:13 +00002058 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002059 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00002060 sizeof(struct lancer_cmd_req_write_object), wrb,
2061 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002062
2063 ctxt = &req->context;
2064 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2065 write_length, ctxt, data_size);
2066
2067 if (data_size == 0)
2068 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2069 eof, ctxt, 1);
2070 else
2071 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2072 eof, ctxt, 0);
2073
2074 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2075 req->write_offset = cpu_to_le32(data_offset);
2076 strcpy(req->object_name, obj_name);
2077 req->descriptor_count = cpu_to_le32(1);
2078 req->buf_len = cpu_to_le32(data_size);
2079 req->addr_low = cpu_to_le32((cmd->dma +
2080 sizeof(struct lancer_cmd_req_write_object))
2081 & 0xFFFFFFFF);
2082 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2083 sizeof(struct lancer_cmd_req_write_object)));
2084
2085 be_mcc_notify(adapter);
2086 spin_unlock_bh(&adapter->mcc_lock);
2087
2088 if (!wait_for_completion_timeout(&adapter->flash_compl,
Padmanabh Ratnakar804c7512012-04-25 01:46:18 +00002089 msecs_to_jiffies(30000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002090 status = -1;
2091 else
2092 status = adapter->flash_status;
2093
2094 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002095 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002096 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002097 *change_status = resp->change_status;
2098 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002099 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002100 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002101
2102 return status;
2103
2104err_unlock:
2105 spin_unlock_bh(&adapter->mcc_lock);
2106 return status;
2107}
2108
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002109int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
2110 u32 data_size, u32 data_offset, const char *obj_name,
2111 u32 *data_read, u32 *eof, u8 *addn_status)
2112{
2113 struct be_mcc_wrb *wrb;
2114 struct lancer_cmd_req_read_object *req;
2115 struct lancer_cmd_resp_read_object *resp;
2116 int status;
2117
2118 spin_lock_bh(&adapter->mcc_lock);
2119
2120 wrb = wrb_from_mccq(adapter);
2121 if (!wrb) {
2122 status = -EBUSY;
2123 goto err_unlock;
2124 }
2125
2126 req = embedded_payload(wrb);
2127
2128 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2129 OPCODE_COMMON_READ_OBJECT,
2130 sizeof(struct lancer_cmd_req_read_object), wrb,
2131 NULL);
2132
2133 req->desired_read_len = cpu_to_le32(data_size);
2134 req->read_offset = cpu_to_le32(data_offset);
2135 strcpy(req->object_name, obj_name);
2136 req->descriptor_count = cpu_to_le32(1);
2137 req->buf_len = cpu_to_le32(data_size);
2138 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2139 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2140
2141 status = be_mcc_notify_wait(adapter);
2142
2143 resp = embedded_payload(wrb);
2144 if (!status) {
2145 *data_read = le32_to_cpu(resp->actual_read_len);
2146 *eof = le32_to_cpu(resp->eof);
2147 } else {
2148 *addn_status = resp->additional_status;
2149 }
2150
2151err_unlock:
2152 spin_unlock_bh(&adapter->mcc_lock);
2153 return status;
2154}
2155
Ajit Khaparde84517482009-09-04 03:12:16 +00002156int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
2157 u32 flash_type, u32 flash_opcode, u32 buf_size)
2158{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002159 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002160 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002161 int status;
2162
Sathya Perlab31c50a2009-09-17 10:30:13 -07002163 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002164 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002165
2166 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002167 if (!wrb) {
2168 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002169 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002170 }
2171 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002172
Somnath Kotur106df1e2011-10-27 07:12:13 +00002173 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2174 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002175
2176 req->params.op_type = cpu_to_le32(flash_type);
2177 req->params.op_code = cpu_to_le32(flash_opcode);
2178 req->params.data_buf_size = cpu_to_le32(buf_size);
2179
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002180 be_mcc_notify(adapter);
2181 spin_unlock_bh(&adapter->mcc_lock);
2182
2183 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00002184 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002185 status = -1;
2186 else
2187 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002188
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002189 return status;
2190
2191err_unlock:
2192 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002193 return status;
2194}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002195
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002196int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2197 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002198{
2199 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002200 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002201 int status;
2202
2203 spin_lock_bh(&adapter->mcc_lock);
2204
2205 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002206 if (!wrb) {
2207 status = -EBUSY;
2208 goto err;
2209 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002210 req = embedded_payload(wrb);
2211
Somnath Kotur106df1e2011-10-27 07:12:13 +00002212 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002213 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2214 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002215
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00002216 req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002217 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002218 req->params.offset = cpu_to_le32(offset);
2219 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002220
2221 status = be_mcc_notify_wait(adapter);
2222 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002223 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002224
Sathya Perla713d03942009-11-22 22:02:45 +00002225err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002226 spin_unlock_bh(&adapter->mcc_lock);
2227 return status;
2228}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002229
Dan Carpenterc196b022010-05-26 04:47:39 +00002230int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002231 struct be_dma_mem *nonemb_cmd)
2232{
2233 struct be_mcc_wrb *wrb;
2234 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002235 int status;
2236
2237 spin_lock_bh(&adapter->mcc_lock);
2238
2239 wrb = wrb_from_mccq(adapter);
2240 if (!wrb) {
2241 status = -EBUSY;
2242 goto err;
2243 }
2244 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002245
Somnath Kotur106df1e2011-10-27 07:12:13 +00002246 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2247 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2248 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002249 memcpy(req->magic_mac, mac, ETH_ALEN);
2250
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002251 status = be_mcc_notify_wait(adapter);
2252
2253err:
2254 spin_unlock_bh(&adapter->mcc_lock);
2255 return status;
2256}
Suresh Rff33a6e2009-12-03 16:15:52 -08002257
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002258int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2259 u8 loopback_type, u8 enable)
2260{
2261 struct be_mcc_wrb *wrb;
2262 struct be_cmd_req_set_lmode *req;
2263 int status;
2264
2265 spin_lock_bh(&adapter->mcc_lock);
2266
2267 wrb = wrb_from_mccq(adapter);
2268 if (!wrb) {
2269 status = -EBUSY;
2270 goto err;
2271 }
2272
2273 req = embedded_payload(wrb);
2274
Somnath Kotur106df1e2011-10-27 07:12:13 +00002275 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2276 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2277 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002278
2279 req->src_port = port_num;
2280 req->dest_port = port_num;
2281 req->loopback_type = loopback_type;
2282 req->loopback_state = enable;
2283
2284 status = be_mcc_notify_wait(adapter);
2285err:
2286 spin_unlock_bh(&adapter->mcc_lock);
2287 return status;
2288}
2289
Suresh Rff33a6e2009-12-03 16:15:52 -08002290int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2291 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2292{
2293 struct be_mcc_wrb *wrb;
2294 struct be_cmd_req_loopback_test *req;
2295 int status;
2296
2297 spin_lock_bh(&adapter->mcc_lock);
2298
2299 wrb = wrb_from_mccq(adapter);
2300 if (!wrb) {
2301 status = -EBUSY;
2302 goto err;
2303 }
2304
2305 req = embedded_payload(wrb);
2306
Somnath Kotur106df1e2011-10-27 07:12:13 +00002307 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2308 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002309 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002310
2311 req->pattern = cpu_to_le64(pattern);
2312 req->src_port = cpu_to_le32(port_num);
2313 req->dest_port = cpu_to_le32(port_num);
2314 req->pkt_size = cpu_to_le32(pkt_size);
2315 req->num_pkts = cpu_to_le32(num_pkts);
2316 req->loopback_type = cpu_to_le32(loopback_type);
2317
2318 status = be_mcc_notify_wait(adapter);
2319 if (!status) {
2320 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2321 status = le32_to_cpu(resp->status);
2322 }
2323
2324err:
2325 spin_unlock_bh(&adapter->mcc_lock);
2326 return status;
2327}
2328
2329int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2330 u32 byte_cnt, struct be_dma_mem *cmd)
2331{
2332 struct be_mcc_wrb *wrb;
2333 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002334 int status;
2335 int i, j = 0;
2336
2337 spin_lock_bh(&adapter->mcc_lock);
2338
2339 wrb = wrb_from_mccq(adapter);
2340 if (!wrb) {
2341 status = -EBUSY;
2342 goto err;
2343 }
2344 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002345 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2346 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002347
2348 req->pattern = cpu_to_le64(pattern);
2349 req->byte_count = cpu_to_le32(byte_cnt);
2350 for (i = 0; i < byte_cnt; i++) {
2351 req->snd_buff[i] = (u8)(pattern >> (j*8));
2352 j++;
2353 if (j > 7)
2354 j = 0;
2355 }
2356
2357 status = be_mcc_notify_wait(adapter);
2358
2359 if (!status) {
2360 struct be_cmd_resp_ddrdma_test *resp;
2361 resp = cmd->va;
2362 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2363 resp->snd_err) {
2364 status = -1;
2365 }
2366 }
2367
2368err:
2369 spin_unlock_bh(&adapter->mcc_lock);
2370 return status;
2371}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002372
Dan Carpenterc196b022010-05-26 04:47:39 +00002373int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002374 struct be_dma_mem *nonemb_cmd)
2375{
2376 struct be_mcc_wrb *wrb;
2377 struct be_cmd_req_seeprom_read *req;
2378 struct be_sge *sge;
2379 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;
2389 sge = nonembedded_sgl(wrb);
2390
Somnath Kotur106df1e2011-10-27 07:12:13 +00002391 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2392 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2393 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002394
2395 status = be_mcc_notify_wait(adapter);
2396
Ajit Khapardee45ff012011-02-04 17:18:28 +00002397err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002398 spin_unlock_bh(&adapter->mcc_lock);
2399 return status;
2400}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002401
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002402int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002403{
2404 struct be_mcc_wrb *wrb;
2405 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002406 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002407 int status;
2408
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002409 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2410 CMD_SUBSYSTEM_COMMON))
2411 return -EPERM;
2412
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002413 spin_lock_bh(&adapter->mcc_lock);
2414
2415 wrb = wrb_from_mccq(adapter);
2416 if (!wrb) {
2417 status = -EBUSY;
2418 goto err;
2419 }
Sathya Perla306f1342011-08-02 19:57:45 +00002420 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2421 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2422 &cmd.dma);
2423 if (!cmd.va) {
2424 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2425 status = -ENOMEM;
2426 goto err;
2427 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002428
Sathya Perla306f1342011-08-02 19:57:45 +00002429 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002430
Somnath Kotur106df1e2011-10-27 07:12:13 +00002431 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2432 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2433 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002434
2435 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002436 if (!status) {
2437 struct be_phy_info *resp_phy_info =
2438 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002439 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2440 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002441 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002442 adapter->phy.auto_speeds_supported =
2443 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2444 adapter->phy.fixed_speeds_supported =
2445 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2446 adapter->phy.misc_params =
2447 le32_to_cpu(resp_phy_info->misc_params);
Sathya Perla306f1342011-08-02 19:57:45 +00002448 }
2449 pci_free_consistent(adapter->pdev, cmd.size,
2450 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002451err:
2452 spin_unlock_bh(&adapter->mcc_lock);
2453 return status;
2454}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002455
2456int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2457{
2458 struct be_mcc_wrb *wrb;
2459 struct be_cmd_req_set_qos *req;
2460 int status;
2461
2462 spin_lock_bh(&adapter->mcc_lock);
2463
2464 wrb = wrb_from_mccq(adapter);
2465 if (!wrb) {
2466 status = -EBUSY;
2467 goto err;
2468 }
2469
2470 req = embedded_payload(wrb);
2471
Somnath Kotur106df1e2011-10-27 07:12:13 +00002472 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2473 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002474
2475 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002476 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2477 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002478
2479 status = be_mcc_notify_wait(adapter);
2480
2481err:
2482 spin_unlock_bh(&adapter->mcc_lock);
2483 return status;
2484}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002485
2486int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2487{
2488 struct be_mcc_wrb *wrb;
2489 struct be_cmd_req_cntl_attribs *req;
2490 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002491 int status;
2492 int payload_len = max(sizeof(*req), sizeof(*resp));
2493 struct mgmt_controller_attrib *attribs;
2494 struct be_dma_mem attribs_cmd;
2495
Suresh Reddyd98ef502013-04-25 00:56:55 +00002496 if (mutex_lock_interruptible(&adapter->mbox_lock))
2497 return -1;
2498
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002499 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2500 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2501 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2502 &attribs_cmd.dma);
2503 if (!attribs_cmd.va) {
2504 dev_err(&adapter->pdev->dev,
2505 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002506 status = -ENOMEM;
2507 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002508 }
2509
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002510 wrb = wrb_from_mbox(adapter);
2511 if (!wrb) {
2512 status = -EBUSY;
2513 goto err;
2514 }
2515 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002516
Somnath Kotur106df1e2011-10-27 07:12:13 +00002517 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2518 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2519 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002520
2521 status = be_mbox_notify_wait(adapter);
2522 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002523 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002524 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2525 }
2526
2527err:
2528 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002529 if (attribs_cmd.va)
2530 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2531 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002532 return status;
2533}
Sathya Perla2e588f82011-03-11 02:49:26 +00002534
2535/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002536int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002537{
2538 struct be_mcc_wrb *wrb;
2539 struct be_cmd_req_set_func_cap *req;
2540 int status;
2541
2542 if (mutex_lock_interruptible(&adapter->mbox_lock))
2543 return -1;
2544
2545 wrb = wrb_from_mbox(adapter);
2546 if (!wrb) {
2547 status = -EBUSY;
2548 goto err;
2549 }
2550
2551 req = embedded_payload(wrb);
2552
Somnath Kotur106df1e2011-10-27 07:12:13 +00002553 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2554 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002555
2556 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2557 CAPABILITY_BE3_NATIVE_ERX_API);
2558 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2559
2560 status = be_mbox_notify_wait(adapter);
2561 if (!status) {
2562 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2563 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2564 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002565 if (!adapter->be3_native)
2566 dev_warn(&adapter->pdev->dev,
2567 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002568 }
2569err:
2570 mutex_unlock(&adapter->mbox_lock);
2571 return status;
2572}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002573
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002574/* Get privilege(s) for a function */
2575int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2576 u32 domain)
2577{
2578 struct be_mcc_wrb *wrb;
2579 struct be_cmd_req_get_fn_privileges *req;
2580 int status;
2581
2582 spin_lock_bh(&adapter->mcc_lock);
2583
2584 wrb = wrb_from_mccq(adapter);
2585 if (!wrb) {
2586 status = -EBUSY;
2587 goto err;
2588 }
2589
2590 req = embedded_payload(wrb);
2591
2592 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2593 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2594 wrb, NULL);
2595
2596 req->hdr.domain = domain;
2597
2598 status = be_mcc_notify_wait(adapter);
2599 if (!status) {
2600 struct be_cmd_resp_get_fn_privileges *resp =
2601 embedded_payload(wrb);
2602 *privilege = le32_to_cpu(resp->privilege_mask);
2603 }
2604
2605err:
2606 spin_unlock_bh(&adapter->mcc_lock);
2607 return status;
2608}
2609
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002610/* Uses synchronous MCCQ */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002611int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
2612 bool *pmac_id_active, u32 *pmac_id, u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002613{
2614 struct be_mcc_wrb *wrb;
2615 struct be_cmd_req_get_mac_list *req;
2616 int status;
2617 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002618 struct be_dma_mem get_mac_list_cmd;
2619 int i;
2620
2621 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2622 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2623 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2624 get_mac_list_cmd.size,
2625 &get_mac_list_cmd.dma);
2626
2627 if (!get_mac_list_cmd.va) {
2628 dev_err(&adapter->pdev->dev,
2629 "Memory allocation failure during GET_MAC_LIST\n");
2630 return -ENOMEM;
2631 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002632
2633 spin_lock_bh(&adapter->mcc_lock);
2634
2635 wrb = wrb_from_mccq(adapter);
2636 if (!wrb) {
2637 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002638 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002639 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002640
2641 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002642
2643 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2644 OPCODE_COMMON_GET_MAC_LIST, sizeof(*req),
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002645 wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002646
2647 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002648 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
2649 req->perm_override = 1;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002650
2651 status = be_mcc_notify_wait(adapter);
2652 if (!status) {
2653 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002654 get_mac_list_cmd.va;
2655 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2656 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002657 * or one or more true or pseudo permanant mac addresses.
2658 * If an active mac_id is present, return first active mac_id
2659 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002660 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002661 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002662 struct get_list_macaddr *mac_entry;
2663 u16 mac_addr_size;
2664 u32 mac_id;
2665
2666 mac_entry = &resp->macaddr_list[i];
2667 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2668 /* mac_id is a 32 bit value and mac_addr size
2669 * is 6 bytes
2670 */
2671 if (mac_addr_size == sizeof(u32)) {
2672 *pmac_id_active = true;
2673 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2674 *pmac_id = le32_to_cpu(mac_id);
2675 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002676 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002677 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002678 /* If no active mac_id found, return first mac addr */
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002679 *pmac_id_active = false;
2680 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2681 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002682 }
2683
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002684out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002685 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002686 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2687 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002688 return status;
2689}
2690
2691/* Uses synchronous MCCQ */
2692int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2693 u8 mac_count, u32 domain)
2694{
2695 struct be_mcc_wrb *wrb;
2696 struct be_cmd_req_set_mac_list *req;
2697 int status;
2698 struct be_dma_mem cmd;
2699
2700 memset(&cmd, 0, sizeof(struct be_dma_mem));
2701 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2702 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2703 &cmd.dma, GFP_KERNEL);
2704 if (!cmd.va) {
2705 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2706 return -ENOMEM;
2707 }
2708
2709 spin_lock_bh(&adapter->mcc_lock);
2710
2711 wrb = wrb_from_mccq(adapter);
2712 if (!wrb) {
2713 status = -EBUSY;
2714 goto err;
2715 }
2716
2717 req = cmd.va;
2718 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2719 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2720 wrb, &cmd);
2721
2722 req->hdr.domain = domain;
2723 req->mac_count = mac_count;
2724 if (mac_count)
2725 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2726
2727 status = be_mcc_notify_wait(adapter);
2728
2729err:
2730 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2731 cmd.va, cmd.dma);
2732 spin_unlock_bh(&adapter->mcc_lock);
2733 return status;
2734}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002735
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002736int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
2737 u32 domain, u16 intf_id)
2738{
2739 struct be_mcc_wrb *wrb;
2740 struct be_cmd_req_set_hsw_config *req;
2741 void *ctxt;
2742 int status;
2743
2744 spin_lock_bh(&adapter->mcc_lock);
2745
2746 wrb = wrb_from_mccq(adapter);
2747 if (!wrb) {
2748 status = -EBUSY;
2749 goto err;
2750 }
2751
2752 req = embedded_payload(wrb);
2753 ctxt = &req->context;
2754
2755 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2756 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2757
2758 req->hdr.domain = domain;
2759 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2760 if (pvid) {
2761 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2762 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2763 }
2764
2765 be_dws_cpu_to_le(req->context, sizeof(req->context));
2766 status = be_mcc_notify_wait(adapter);
2767
2768err:
2769 spin_unlock_bh(&adapter->mcc_lock);
2770 return status;
2771}
2772
2773/* Get Hyper switch config */
2774int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
2775 u32 domain, u16 intf_id)
2776{
2777 struct be_mcc_wrb *wrb;
2778 struct be_cmd_req_get_hsw_config *req;
2779 void *ctxt;
2780 int status;
2781 u16 vid;
2782
2783 spin_lock_bh(&adapter->mcc_lock);
2784
2785 wrb = wrb_from_mccq(adapter);
2786 if (!wrb) {
2787 status = -EBUSY;
2788 goto err;
2789 }
2790
2791 req = embedded_payload(wrb);
2792 ctxt = &req->context;
2793
2794 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2795 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2796
2797 req->hdr.domain = domain;
2798 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, ctxt,
2799 intf_id);
2800 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
2801 be_dws_cpu_to_le(req->context, sizeof(req->context));
2802
2803 status = be_mcc_notify_wait(adapter);
2804 if (!status) {
2805 struct be_cmd_resp_get_hsw_config *resp =
2806 embedded_payload(wrb);
2807 be_dws_le_to_cpu(&resp->context,
2808 sizeof(resp->context));
2809 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2810 pvid, &resp->context);
2811 *pvid = le16_to_cpu(vid);
2812 }
2813
2814err:
2815 spin_unlock_bh(&adapter->mcc_lock);
2816 return status;
2817}
2818
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002819int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2820{
2821 struct be_mcc_wrb *wrb;
2822 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2823 int status;
2824 int payload_len = sizeof(*req);
2825 struct be_dma_mem cmd;
2826
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002827 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2828 CMD_SUBSYSTEM_ETH))
2829 return -EPERM;
2830
Suresh Reddyd98ef502013-04-25 00:56:55 +00002831 if (mutex_lock_interruptible(&adapter->mbox_lock))
2832 return -1;
2833
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002834 memset(&cmd, 0, sizeof(struct be_dma_mem));
2835 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2836 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2837 &cmd.dma);
2838 if (!cmd.va) {
2839 dev_err(&adapter->pdev->dev,
2840 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002841 status = -ENOMEM;
2842 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002843 }
2844
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002845 wrb = wrb_from_mbox(adapter);
2846 if (!wrb) {
2847 status = -EBUSY;
2848 goto err;
2849 }
2850
2851 req = cmd.va;
2852
2853 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2854 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2855 payload_len, wrb, &cmd);
2856
2857 req->hdr.version = 1;
2858 req->query_options = BE_GET_WOL_CAP;
2859
2860 status = be_mbox_notify_wait(adapter);
2861 if (!status) {
2862 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
2863 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
2864
2865 /* the command could succeed misleadingly on old f/w
2866 * which is not aware of the V1 version. fake an error. */
2867 if (resp->hdr.response_length < payload_len) {
2868 status = -1;
2869 goto err;
2870 }
2871 adapter->wol_cap = resp->wol_settings;
2872 }
2873err:
2874 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002875 if (cmd.va)
2876 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002877 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00002878
2879}
2880int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
2881 struct be_dma_mem *cmd)
2882{
2883 struct be_mcc_wrb *wrb;
2884 struct be_cmd_req_get_ext_fat_caps *req;
2885 int status;
2886
2887 if (mutex_lock_interruptible(&adapter->mbox_lock))
2888 return -1;
2889
2890 wrb = wrb_from_mbox(adapter);
2891 if (!wrb) {
2892 status = -EBUSY;
2893 goto err;
2894 }
2895
2896 req = cmd->va;
2897 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2898 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
2899 cmd->size, wrb, cmd);
2900 req->parameter_type = cpu_to_le32(1);
2901
2902 status = be_mbox_notify_wait(adapter);
2903err:
2904 mutex_unlock(&adapter->mbox_lock);
2905 return status;
2906}
2907
2908int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
2909 struct be_dma_mem *cmd,
2910 struct be_fat_conf_params *configs)
2911{
2912 struct be_mcc_wrb *wrb;
2913 struct be_cmd_req_set_ext_fat_caps *req;
2914 int status;
2915
2916 spin_lock_bh(&adapter->mcc_lock);
2917
2918 wrb = wrb_from_mccq(adapter);
2919 if (!wrb) {
2920 status = -EBUSY;
2921 goto err;
2922 }
2923
2924 req = cmd->va;
2925 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
2926 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2927 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
2928 cmd->size, wrb, cmd);
2929
2930 status = be_mcc_notify_wait(adapter);
2931err:
2932 spin_unlock_bh(&adapter->mcc_lock);
2933 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002934}
Parav Pandit6a4ab662012-03-26 14:27:12 +00002935
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00002936int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
2937{
2938 struct be_mcc_wrb *wrb;
2939 struct be_cmd_req_get_port_name *req;
2940 int status;
2941
2942 if (!lancer_chip(adapter)) {
2943 *port_name = adapter->hba_port_num + '0';
2944 return 0;
2945 }
2946
2947 spin_lock_bh(&adapter->mcc_lock);
2948
2949 wrb = wrb_from_mccq(adapter);
2950 if (!wrb) {
2951 status = -EBUSY;
2952 goto err;
2953 }
2954
2955 req = embedded_payload(wrb);
2956
2957 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2958 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
2959 NULL);
2960 req->hdr.version = 1;
2961
2962 status = be_mcc_notify_wait(adapter);
2963 if (!status) {
2964 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
2965 *port_name = resp->port_name[adapter->hba_port_num];
2966 } else {
2967 *port_name = adapter->hba_port_num + '0';
2968 }
2969err:
2970 spin_unlock_bh(&adapter->mcc_lock);
2971 return status;
2972}
2973
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002974static struct be_nic_resource_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
2975 u32 max_buf_size)
2976{
2977 struct be_nic_resource_desc *desc = (struct be_nic_resource_desc *)buf;
2978 int i;
2979
2980 for (i = 0; i < desc_count; i++) {
2981 desc->desc_len = RESOURCE_DESC_SIZE;
2982 if (((void *)desc + desc->desc_len) >
2983 (void *)(buf + max_buf_size)) {
2984 desc = NULL;
2985 break;
2986 }
2987
2988 if (desc->desc_type == NIC_RESOURCE_DESC_TYPE_ID)
2989 break;
2990
2991 desc = (void *)desc + desc->desc_len;
2992 }
2993
2994 if (!desc || i == MAX_RESOURCE_DESC)
2995 return NULL;
2996
2997 return desc;
2998}
2999
3000/* Uses Mbox */
3001int be_cmd_get_func_config(struct be_adapter *adapter)
3002{
3003 struct be_mcc_wrb *wrb;
3004 struct be_cmd_req_get_func_config *req;
3005 int status;
3006 struct be_dma_mem cmd;
3007
Suresh Reddyd98ef502013-04-25 00:56:55 +00003008 if (mutex_lock_interruptible(&adapter->mbox_lock))
3009 return -1;
3010
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003011 memset(&cmd, 0, sizeof(struct be_dma_mem));
3012 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
3013 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3014 &cmd.dma);
3015 if (!cmd.va) {
3016 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003017 status = -ENOMEM;
3018 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003019 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003020
3021 wrb = wrb_from_mbox(adapter);
3022 if (!wrb) {
3023 status = -EBUSY;
3024 goto err;
3025 }
3026
3027 req = cmd.va;
3028
3029 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3030 OPCODE_COMMON_GET_FUNC_CONFIG,
3031 cmd.size, wrb, &cmd);
3032
3033 status = be_mbox_notify_wait(adapter);
3034 if (!status) {
3035 struct be_cmd_resp_get_func_config *resp = cmd.va;
3036 u32 desc_count = le32_to_cpu(resp->desc_count);
3037 struct be_nic_resource_desc *desc;
3038
3039 desc = be_get_nic_desc(resp->func_param, desc_count,
3040 sizeof(resp->func_param));
3041 if (!desc) {
3042 status = -EINVAL;
3043 goto err;
3044 }
3045
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003046 adapter->pf_number = desc->pf_num;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003047 adapter->max_pmac_cnt = le16_to_cpu(desc->unicast_mac_count);
3048 adapter->max_vlans = le16_to_cpu(desc->vlan_count);
3049 adapter->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3050 adapter->max_tx_queues = le16_to_cpu(desc->txq_count);
3051 adapter->max_rss_queues = le16_to_cpu(desc->rssq_count);
3052 adapter->max_rx_queues = le16_to_cpu(desc->rq_count);
3053
3054 adapter->max_event_queues = le16_to_cpu(desc->eq_count);
3055 adapter->if_cap_flags = le32_to_cpu(desc->cap_flags);
3056 }
3057err:
3058 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003059 if (cmd.va)
3060 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003061 return status;
3062}
3063
3064 /* Uses sync mcc */
3065int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags,
3066 u8 domain)
3067{
3068 struct be_mcc_wrb *wrb;
3069 struct be_cmd_req_get_profile_config *req;
3070 int status;
3071 struct be_dma_mem cmd;
3072
3073 memset(&cmd, 0, sizeof(struct be_dma_mem));
3074 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3075 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3076 &cmd.dma);
3077 if (!cmd.va) {
3078 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
3079 return -ENOMEM;
3080 }
3081
3082 spin_lock_bh(&adapter->mcc_lock);
3083
3084 wrb = wrb_from_mccq(adapter);
3085 if (!wrb) {
3086 status = -EBUSY;
3087 goto err;
3088 }
3089
3090 req = cmd.va;
3091
3092 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3093 OPCODE_COMMON_GET_PROFILE_CONFIG,
3094 cmd.size, wrb, &cmd);
3095
3096 req->type = ACTIVE_PROFILE_TYPE;
3097 req->hdr.domain = domain;
3098
3099 status = be_mcc_notify_wait(adapter);
3100 if (!status) {
3101 struct be_cmd_resp_get_profile_config *resp = cmd.va;
3102 u32 desc_count = le32_to_cpu(resp->desc_count);
3103 struct be_nic_resource_desc *desc;
3104
3105 desc = be_get_nic_desc(resp->func_param, desc_count,
3106 sizeof(resp->func_param));
3107
3108 if (!desc) {
3109 status = -EINVAL;
3110 goto err;
3111 }
3112 *cap_flags = le32_to_cpu(desc->cap_flags);
3113 }
3114err:
3115 spin_unlock_bh(&adapter->mcc_lock);
3116 pci_free_consistent(adapter->pdev, cmd.size,
3117 cmd.va, cmd.dma);
3118 return status;
3119}
3120
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003121/* Uses sync mcc */
3122int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
3123 u8 domain)
3124{
3125 struct be_mcc_wrb *wrb;
3126 struct be_cmd_req_set_profile_config *req;
3127 int status;
3128
3129 spin_lock_bh(&adapter->mcc_lock);
3130
3131 wrb = wrb_from_mccq(adapter);
3132 if (!wrb) {
3133 status = -EBUSY;
3134 goto err;
3135 }
3136
3137 req = embedded_payload(wrb);
3138
3139 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3140 OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req),
3141 wrb, NULL);
3142
3143 req->hdr.domain = domain;
3144 req->desc_count = cpu_to_le32(1);
3145
3146 req->nic_desc.desc_type = NIC_RESOURCE_DESC_TYPE_ID;
3147 req->nic_desc.desc_len = RESOURCE_DESC_SIZE;
3148 req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV);
3149 req->nic_desc.pf_num = adapter->pf_number;
3150 req->nic_desc.vf_num = domain;
3151
3152 /* Mark fields invalid */
3153 req->nic_desc.unicast_mac_count = 0xFFFF;
3154 req->nic_desc.mcc_count = 0xFFFF;
3155 req->nic_desc.vlan_count = 0xFFFF;
3156 req->nic_desc.mcast_mac_count = 0xFFFF;
3157 req->nic_desc.txq_count = 0xFFFF;
3158 req->nic_desc.rq_count = 0xFFFF;
3159 req->nic_desc.rssq_count = 0xFFFF;
3160 req->nic_desc.lro_count = 0xFFFF;
3161 req->nic_desc.cq_count = 0xFFFF;
3162 req->nic_desc.toe_conn_count = 0xFFFF;
3163 req->nic_desc.eq_count = 0xFFFF;
3164 req->nic_desc.link_param = 0xFF;
3165 req->nic_desc.bw_min = 0xFFFFFFFF;
3166 req->nic_desc.acpi_params = 0xFF;
3167 req->nic_desc.wol_param = 0x0F;
3168
3169 /* Change BW */
3170 req->nic_desc.bw_min = cpu_to_le32(bps);
3171 req->nic_desc.bw_max = cpu_to_le32(bps);
3172 status = be_mcc_notify_wait(adapter);
3173err:
3174 spin_unlock_bh(&adapter->mcc_lock);
3175 return status;
3176}
3177
Sathya Perla4c876612013-02-03 20:30:11 +00003178int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3179 int vf_num)
3180{
3181 struct be_mcc_wrb *wrb;
3182 struct be_cmd_req_get_iface_list *req;
3183 struct be_cmd_resp_get_iface_list *resp;
3184 int status;
3185
3186 spin_lock_bh(&adapter->mcc_lock);
3187
3188 wrb = wrb_from_mccq(adapter);
3189 if (!wrb) {
3190 status = -EBUSY;
3191 goto err;
3192 }
3193 req = embedded_payload(wrb);
3194
3195 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3196 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3197 wrb, NULL);
3198 req->hdr.domain = vf_num + 1;
3199
3200 status = be_mcc_notify_wait(adapter);
3201 if (!status) {
3202 resp = (struct be_cmd_resp_get_iface_list *)req;
3203 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3204 }
3205
3206err:
3207 spin_unlock_bh(&adapter->mcc_lock);
3208 return status;
3209}
3210
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003211/* Uses sync mcc */
3212int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
3213{
3214 struct be_mcc_wrb *wrb;
3215 struct be_cmd_enable_disable_vf *req;
3216 int status;
3217
3218 if (!lancer_chip(adapter))
3219 return 0;
3220
3221 spin_lock_bh(&adapter->mcc_lock);
3222
3223 wrb = wrb_from_mccq(adapter);
3224 if (!wrb) {
3225 status = -EBUSY;
3226 goto err;
3227 }
3228
3229 req = embedded_payload(wrb);
3230
3231 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3232 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
3233 wrb, NULL);
3234
3235 req->hdr.domain = domain;
3236 req->enable = 1;
3237 status = be_mcc_notify_wait(adapter);
3238err:
3239 spin_unlock_bh(&adapter->mcc_lock);
3240 return status;
3241}
3242
Parav Pandit6a4ab662012-03-26 14:27:12 +00003243int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
3244 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
3245{
3246 struct be_adapter *adapter = netdev_priv(netdev_handle);
3247 struct be_mcc_wrb *wrb;
3248 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
3249 struct be_cmd_req_hdr *req;
3250 struct be_cmd_resp_hdr *resp;
3251 int status;
3252
3253 spin_lock_bh(&adapter->mcc_lock);
3254
3255 wrb = wrb_from_mccq(adapter);
3256 if (!wrb) {
3257 status = -EBUSY;
3258 goto err;
3259 }
3260 req = embedded_payload(wrb);
3261 resp = embedded_payload(wrb);
3262
3263 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
3264 hdr->opcode, wrb_payload_size, wrb, NULL);
3265 memcpy(req, wrb_payload, wrb_payload_size);
3266 be_dws_cpu_to_le(req, wrb_payload_size);
3267
3268 status = be_mcc_notify_wait(adapter);
3269 if (cmd_status)
3270 *cmd_status = (status & 0xffff);
3271 if (ext_status)
3272 *ext_status = 0;
3273 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
3274 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
3275err:
3276 spin_unlock_bh(&adapter->mcc_lock);
3277 return status;
3278}
3279EXPORT_SYMBOL(be_roce_mcc_cmd);