blob: 5458a4357ae046dc8b0109de6e50ad5db0240400 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volamc7bb15a2013-03-06 20:05:05 +00002 * Copyright (C) 2005 - 2013 Emulex
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
10 * Contact Information:
Ajit Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
Parav Pandit6a4ab662012-03-26 14:27:12 +000018#include <linux/module.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070019#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000020#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070021
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000022static struct be_cmd_priv_map cmd_priv_map[] = {
23 {
24 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
25 CMD_SUBSYSTEM_ETH,
26 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
27 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
28 },
29 {
30 OPCODE_COMMON_GET_FLOW_CONTROL,
31 CMD_SUBSYSTEM_COMMON,
32 BE_PRIV_LNKQUERY | BE_PRIV_VHADM |
33 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
34 },
35 {
36 OPCODE_COMMON_SET_FLOW_CONTROL,
37 CMD_SUBSYSTEM_COMMON,
38 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
39 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
40 },
41 {
42 OPCODE_ETH_GET_PPORT_STATS,
43 CMD_SUBSYSTEM_ETH,
44 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
45 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
46 },
47 {
48 OPCODE_COMMON_GET_PHY_DETAILS,
49 CMD_SUBSYSTEM_COMMON,
50 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
51 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
52 }
53};
54
55static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode,
56 u8 subsystem)
57{
58 int i;
59 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
60 u32 cmd_privileges = adapter->cmd_privileges;
61
62 for (i = 0; i < num_entries; i++)
63 if (opcode == cmd_priv_map[i].opcode &&
64 subsystem == cmd_priv_map[i].subsystem)
65 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
66 return false;
67
68 return true;
69}
70
Somnath Kotur3de09452011-09-30 07:25:05 +000071static inline void *embedded_payload(struct be_mcc_wrb *wrb)
72{
73 return wrb->payload.embedded_payload;
74}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000075
Sathya Perla8788fdc2009-07-27 22:52:03 +000076static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000077{
Sathya Perla8788fdc2009-07-27 22:52:03 +000078 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000079 u32 val = 0;
80
Sathya Perla6589ade2011-11-10 19:18:00 +000081 if (be_error(adapter))
Ajit Khaparde7acc2082011-02-11 13:38:17 +000082 return;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000083
Sathya Perla5fb379e2009-06-18 00:02:59 +000084 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
85 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000086
87 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000088 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000089}
90
91/* To check if valid bit is set, check the entire word as we don't know
92 * the endianness of the data (old entry is host endian while a new entry is
93 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000094static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000095{
Sathya Perla9e9ff4b2013-02-12 23:05:19 +000096 u32 flags;
97
Sathya Perla5fb379e2009-06-18 00:02:59 +000098 if (compl->flags != 0) {
Sathya Perla9e9ff4b2013-02-12 23:05:19 +000099 flags = le32_to_cpu(compl->flags);
100 if (flags & CQE_FLAGS_VALID_MASK) {
101 compl->flags = flags;
102 return true;
103 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000104 }
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000105 return false;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000106}
107
108/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000109static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000110{
111 compl->flags = 0;
112}
113
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000114static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
115{
116 unsigned long addr;
117
118 addr = tag1;
119 addr = ((addr << 16) << 16) | tag0;
120 return (void *)addr;
121}
122
Sathya Perla8788fdc2009-07-27 22:52:03 +0000123static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000124 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000125{
126 u16 compl_status, extd_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000127 struct be_cmd_resp_hdr *resp_hdr;
128 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000129
130 /* Just swap the status to host endian; mcc tag is opaquely copied
131 * from mcc_wrb */
132 be_dws_le_to_cpu(compl, 4);
133
134 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
135 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -0700136
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000137 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
138
139 if (resp_hdr) {
140 opcode = resp_hdr->opcode;
141 subsystem = resp_hdr->subsystem;
142 }
143
144 if (((opcode == OPCODE_COMMON_WRITE_FLASHROM) ||
145 (opcode == OPCODE_COMMON_WRITE_OBJECT)) &&
146 (subsystem == CMD_SUBSYSTEM_COMMON)) {
Sarveshwar Bandidd131e72010-05-25 16:16:32 -0700147 adapter->flash_status = compl_status;
148 complete(&adapter->flash_compl);
149 }
150
Sathya Perlab31c50a2009-09-17 10:30:13 -0700151 if (compl_status == MCC_STATUS_SUCCESS) {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000152 if (((opcode == OPCODE_ETH_GET_STATISTICS) ||
153 (opcode == OPCODE_ETH_GET_PPORT_STATS)) &&
154 (subsystem == CMD_SUBSYSTEM_ETH)) {
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000155 be_parse_stats(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +0000156 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700157 }
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000158 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
159 subsystem == CMD_SUBSYSTEM_COMMON) {
Somnath Kotur3de09452011-09-30 07:25:05 +0000160 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000161 (void *)resp_hdr;
Somnath Kotur3de09452011-09-30 07:25:05 +0000162 adapter->drv_stats.be_on_die_temperature =
163 resp->on_die_temperature;
164 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000165 } else {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000166 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES)
Padmanabh Ratnakar7aeb2152012-07-12 03:56:46 +0000167 adapter->be_get_temp_freq = 0;
Somnath Kotur3de09452011-09-30 07:25:05 +0000168
Sathya Perla2b3f2912011-06-29 23:32:56 +0000169 if (compl_status == MCC_STATUS_NOT_SUPPORTED ||
170 compl_status == MCC_STATUS_ILLEGAL_REQUEST)
171 goto done;
172
173 if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000174 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000175 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000176 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000177 } else {
178 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
179 CQE_STATUS_EXTD_MASK;
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000180 dev_err(&adapter->pdev->dev,
181 "opcode %d-%d failed:status %d-%d\n",
182 opcode, subsystem, compl_status, extd_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000183 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000184 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000185done:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700186 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000187}
188
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000189/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000190static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000191 struct be_async_event_link_state *evt)
192{
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000193 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000194 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000195
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000196 /* Ignore physical link event */
197 if (lancer_chip(adapter) &&
198 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
199 return;
200
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000201 /* For the initial link status do not rely on the ASYNC event as
202 * it may not be received in some cases.
203 */
204 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
205 be_link_status_update(adapter, evt->port_link_status);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000206}
207
Somnath Koturcc4ce022010-10-21 07:11:14 -0700208/* Grp5 CoS Priority evt */
209static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
210 struct be_async_event_grp5_cos_priority *evt)
211{
212 if (evt->valid) {
213 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000214 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700215 adapter->recommended_prio =
216 evt->reco_default_priority << VLAN_PRIO_SHIFT;
217 }
218}
219
Sathya Perla323ff712012-09-28 04:39:43 +0000220/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700221static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
222 struct be_async_event_grp5_qos_link_speed *evt)
223{
Sathya Perla323ff712012-09-28 04:39:43 +0000224 if (adapter->phy.link_speed >= 0 &&
225 evt->physical_port == adapter->port_num)
226 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700227}
228
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000229/*Grp5 PVID evt*/
230static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
231 struct be_async_event_grp5_pvid_state *evt)
232{
233 if (evt->enabled)
Somnath Kotur939cf302011-08-18 21:51:49 -0700234 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000235 else
236 adapter->pvid = 0;
237}
238
Somnath Koturcc4ce022010-10-21 07:11:14 -0700239static void be_async_grp5_evt_process(struct be_adapter *adapter,
240 u32 trailer, struct be_mcc_compl *evt)
241{
242 u8 event_type = 0;
243
244 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
245 ASYNC_TRAILER_EVENT_TYPE_MASK;
246
247 switch (event_type) {
248 case ASYNC_EVENT_COS_PRIORITY:
249 be_async_grp5_cos_priority_process(adapter,
250 (struct be_async_event_grp5_cos_priority *)evt);
251 break;
252 case ASYNC_EVENT_QOS_SPEED:
253 be_async_grp5_qos_speed_process(adapter,
254 (struct be_async_event_grp5_qos_link_speed *)evt);
255 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000256 case ASYNC_EVENT_PVID_STATE:
257 be_async_grp5_pvid_state_process(adapter,
258 (struct be_async_event_grp5_pvid_state *)evt);
259 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700260 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530261 dev_warn(&adapter->pdev->dev, "Unknown grp5 event 0x%x!\n",
262 event_type);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700263 break;
264 }
265}
266
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000267static void be_async_dbg_evt_process(struct be_adapter *adapter,
268 u32 trailer, struct be_mcc_compl *cmp)
269{
270 u8 event_type = 0;
271 struct be_async_event_qnq *evt = (struct be_async_event_qnq *) cmp;
272
273 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
274 ASYNC_TRAILER_EVENT_TYPE_MASK;
275
276 switch (event_type) {
277 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
278 if (evt->valid)
279 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
280 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
281 break;
282 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530283 dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n",
284 event_type);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000285 break;
286 }
287}
288
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000289static inline bool is_link_state_evt(u32 trailer)
290{
Eric Dumazet807540b2010-09-23 05:40:09 +0000291 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000292 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000293 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000294}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000295
Somnath Koturcc4ce022010-10-21 07:11:14 -0700296static inline bool is_grp5_evt(u32 trailer)
297{
298 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
299 ASYNC_TRAILER_EVENT_CODE_MASK) ==
300 ASYNC_EVENT_CODE_GRP_5);
301}
302
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000303static inline bool is_dbg_evt(u32 trailer)
304{
305 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
306 ASYNC_TRAILER_EVENT_CODE_MASK) ==
307 ASYNC_EVENT_CODE_QNQ);
308}
309
Sathya Perlaefd2e402009-07-27 22:53:10 +0000310static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000311{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000312 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000313 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000314
315 if (be_mcc_compl_is_new(compl)) {
316 queue_tail_inc(mcc_cq);
317 return compl;
318 }
319 return NULL;
320}
321
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000322void be_async_mcc_enable(struct be_adapter *adapter)
323{
324 spin_lock_bh(&adapter->mcc_cq_lock);
325
326 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
327 adapter->mcc_obj.rearm_cq = true;
328
329 spin_unlock_bh(&adapter->mcc_cq_lock);
330}
331
332void be_async_mcc_disable(struct be_adapter *adapter)
333{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000334 spin_lock_bh(&adapter->mcc_cq_lock);
335
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000336 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000337 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
338
339 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000340}
341
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000342int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000343{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000344 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000345 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000346 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000347
Amerigo Wang072a9c42012-08-24 21:41:11 +0000348 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla8788fdc2009-07-27 22:52:03 +0000349 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000350 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
351 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000352 if (is_link_state_evt(compl->flags))
353 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000354 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700355 else if (is_grp5_evt(compl->flags))
356 be_async_grp5_evt_process(adapter,
357 compl->flags, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000358 else if (is_dbg_evt(compl->flags))
359 be_async_dbg_evt_process(adapter,
360 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700361 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000362 status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000363 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000364 }
365 be_mcc_compl_use(compl);
366 num++;
367 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700368
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000369 if (num)
370 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
371
Amerigo Wang072a9c42012-08-24 21:41:11 +0000372 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000373 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000374}
375
Sathya Perla6ac7b682009-06-18 00:05:54 +0000376/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700377static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000378{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700379#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000380 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800381 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700382
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800383 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000384 if (be_error(adapter))
385 return -EIO;
386
Amerigo Wang072a9c42012-08-24 21:41:11 +0000387 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000388 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000389 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800390
391 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000392 break;
393 udelay(100);
394 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700395 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000396 dev_err(&adapter->pdev->dev, "FW not responding\n");
397 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000398 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700399 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800400 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000401}
402
403/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700404static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000405{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000406 int status;
407 struct be_mcc_wrb *wrb;
408 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
409 u16 index = mcc_obj->q.head;
410 struct be_cmd_resp_hdr *resp;
411
412 index_dec(&index, mcc_obj->q.len);
413 wrb = queue_index_node(&mcc_obj->q, index);
414
415 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
416
Sathya Perla8788fdc2009-07-27 22:52:03 +0000417 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000418
419 status = be_mcc_wait_compl(adapter);
420 if (status == -EIO)
421 goto out;
422
423 status = resp->status;
424out:
425 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000426}
427
Sathya Perla5f0b8492009-07-27 22:52:56 +0000428static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700429{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000430 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700431 u32 ready;
432
433 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000434 if (be_error(adapter))
435 return -EIO;
436
Sathya Perlacf588472010-02-14 21:22:01 +0000437 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000438 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000439 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000440
441 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700442 if (ready)
443 break;
444
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000445 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000446 dev_err(&adapter->pdev->dev, "FW not responding\n");
447 adapter->fw_timeout = true;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000448 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700449 return -1;
450 }
451
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000452 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000453 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700454 } while (true);
455
456 return 0;
457}
458
459/*
460 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000461 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700462 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700463static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700464{
465 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700466 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000467 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
468 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700469 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000470 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700471
Sathya Perlacf588472010-02-14 21:22:01 +0000472 /* wait for ready to be set */
473 status = be_mbox_db_ready_wait(adapter, db);
474 if (status != 0)
475 return status;
476
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700477 val |= MPU_MAILBOX_DB_HI_MASK;
478 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
479 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
480 iowrite32(val, db);
481
482 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000483 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700484 if (status != 0)
485 return status;
486
487 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700488 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
489 val |= (u32)(mbox_mem->dma >> 4) << 2;
490 iowrite32(val, db);
491
Sathya Perla5f0b8492009-07-27 22:52:56 +0000492 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700493 if (status != 0)
494 return status;
495
Sathya Perla5fb379e2009-06-18 00:02:59 +0000496 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000497 if (be_mcc_compl_is_new(compl)) {
498 status = be_mcc_compl_process(adapter, &mbox->compl);
499 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000500 if (status)
501 return status;
502 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000503 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700504 return -1;
505 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000506 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700507}
508
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000509static u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700510{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000511 u32 sem;
512
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000513 if (BEx_chip(adapter))
514 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700515 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000516 pci_read_config_dword(adapter->pdev,
517 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
518
519 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700520}
521
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000522int lancer_wait_ready(struct be_adapter *adapter)
523{
524#define SLIPORT_READY_TIMEOUT 30
525 u32 sliport_status;
526 int status = 0, i;
527
528 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
529 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
530 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
531 break;
532
533 msleep(1000);
534 }
535
536 if (i == SLIPORT_READY_TIMEOUT)
537 status = -1;
538
539 return status;
540}
541
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000542static bool lancer_provisioning_error(struct be_adapter *adapter)
543{
544 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
545 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
546 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
547 sliport_err1 = ioread32(adapter->db +
548 SLIPORT_ERROR1_OFFSET);
549 sliport_err2 = ioread32(adapter->db +
550 SLIPORT_ERROR2_OFFSET);
551
552 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
553 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
554 return true;
555 }
556 return false;
557}
558
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000559int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
560{
561 int status;
562 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000563 bool resource_error;
564
565 resource_error = lancer_provisioning_error(adapter);
566 if (resource_error)
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000567 return -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000568
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000569 status = lancer_wait_ready(adapter);
570 if (!status) {
571 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
572 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
573 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
574 if (err && reset_needed) {
575 iowrite32(SLI_PORT_CONTROL_IP_MASK,
576 adapter->db + SLIPORT_CONTROL_OFFSET);
577
578 /* check adapter has corrected the error */
579 status = lancer_wait_ready(adapter);
580 sliport_status = ioread32(adapter->db +
581 SLIPORT_STATUS_OFFSET);
582 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
583 SLIPORT_STATUS_RN_MASK);
584 if (status || sliport_status)
585 status = -1;
586 } else if (err || reset_needed) {
587 status = -1;
588 }
589 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000590 /* Stop error recovery if error is not recoverable.
591 * No resource error is temporary errors and will go away
592 * when PF provisions resources.
593 */
594 resource_error = lancer_provisioning_error(adapter);
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000595 if (resource_error)
596 status = -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000597
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000598 return status;
599}
600
601int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700602{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000603 u16 stage;
604 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000605 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700606
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000607 if (lancer_chip(adapter)) {
608 status = lancer_wait_ready(adapter);
609 return status;
610 }
611
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000612 do {
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000613 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000614 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000615 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000616
617 dev_info(dev, "Waiting for POST, %ds elapsed\n",
618 timeout);
619 if (msleep_interruptible(2000)) {
620 dev_err(dev, "Waiting for POST aborted\n");
621 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000622 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000623 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000624 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700625
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000626 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000627 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700628}
629
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700630
631static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
632{
633 return &wrb->payload.sgl[0];
634}
635
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700636
637/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000638/* mem will be NULL for embedded commands */
639static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
640 u8 subsystem, u8 opcode, int cmd_len,
641 struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700642{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000643 struct be_sge *sge;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000644 unsigned long addr = (unsigned long)req_hdr;
645 u64 req_addr = addr;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000646
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700647 req_hdr->opcode = opcode;
648 req_hdr->subsystem = subsystem;
649 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000650 req_hdr->version = 0;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000651
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000652 wrb->tag0 = req_addr & 0xFFFFFFFF;
653 wrb->tag1 = upper_32_bits(req_addr);
654
Somnath Kotur106df1e2011-10-27 07:12:13 +0000655 wrb->payload_length = cmd_len;
656 if (mem) {
657 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
658 MCC_WRB_SGE_CNT_SHIFT;
659 sge = nonembedded_sgl(wrb);
660 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
661 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
662 sge->len = cpu_to_le32(mem->size);
663 } else
664 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
665 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700666}
667
668static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
669 struct be_dma_mem *mem)
670{
671 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
672 u64 dma = (u64)mem->dma;
673
674 for (i = 0; i < buf_pages; i++) {
675 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
676 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
677 dma += PAGE_SIZE_4K;
678 }
679}
680
Sathya Perlab31c50a2009-09-17 10:30:13 -0700681static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700682{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700683 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
684 struct be_mcc_wrb *wrb
685 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
686 memset(wrb, 0, sizeof(*wrb));
687 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700688}
689
Sathya Perlab31c50a2009-09-17 10:30:13 -0700690static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000691{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700692 struct be_queue_info *mccq = &adapter->mcc_obj.q;
693 struct be_mcc_wrb *wrb;
694
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000695 if (!mccq->created)
696 return NULL;
697
Vasundhara Volam4d277122013-04-21 23:28:15 +0000698 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000699 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000700
Sathya Perlab31c50a2009-09-17 10:30:13 -0700701 wrb = queue_head_node(mccq);
702 queue_head_inc(mccq);
703 atomic_inc(&mccq->used);
704 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000705 return wrb;
706}
707
Sathya Perla2243e2e2009-11-22 22:02:03 +0000708/* Tell fw we're about to start firing cmds by writing a
709 * special pattern across the wrb hdr; uses mbox
710 */
711int be_cmd_fw_init(struct be_adapter *adapter)
712{
713 u8 *wrb;
714 int status;
715
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000716 if (lancer_chip(adapter))
717 return 0;
718
Ivan Vecera29849612010-12-14 05:43:19 +0000719 if (mutex_lock_interruptible(&adapter->mbox_lock))
720 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000721
722 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000723 *wrb++ = 0xFF;
724 *wrb++ = 0x12;
725 *wrb++ = 0x34;
726 *wrb++ = 0xFF;
727 *wrb++ = 0xFF;
728 *wrb++ = 0x56;
729 *wrb++ = 0x78;
730 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000731
732 status = be_mbox_notify_wait(adapter);
733
Ivan Vecera29849612010-12-14 05:43:19 +0000734 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000735 return status;
736}
737
738/* Tell fw we're done with firing cmds by writing a
739 * special pattern across the wrb hdr; uses mbox
740 */
741int be_cmd_fw_clean(struct be_adapter *adapter)
742{
743 u8 *wrb;
744 int status;
745
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000746 if (lancer_chip(adapter))
747 return 0;
748
Ivan Vecera29849612010-12-14 05:43:19 +0000749 if (mutex_lock_interruptible(&adapter->mbox_lock))
750 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000751
752 wrb = (u8 *)wrb_from_mbox(adapter);
753 *wrb++ = 0xFF;
754 *wrb++ = 0xAA;
755 *wrb++ = 0xBB;
756 *wrb++ = 0xFF;
757 *wrb++ = 0xFF;
758 *wrb++ = 0xCC;
759 *wrb++ = 0xDD;
760 *wrb = 0xFF;
761
762 status = be_mbox_notify_wait(adapter);
763
Ivan Vecera29849612010-12-14 05:43:19 +0000764 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000765 return status;
766}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000767
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530768int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700769{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700770 struct be_mcc_wrb *wrb;
771 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530772 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
773 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700774
Ivan Vecera29849612010-12-14 05:43:19 +0000775 if (mutex_lock_interruptible(&adapter->mbox_lock))
776 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700777
778 wrb = wrb_from_mbox(adapter);
779 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700780
Somnath Kotur106df1e2011-10-27 07:12:13 +0000781 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
782 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700783
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530784 /* Support for EQ_CREATEv2 available only SH-R onwards */
785 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
786 ver = 2;
787
788 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700789 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
790
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700791 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
792 /* 4byte eqe*/
793 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
794 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530795 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700796 be_dws_cpu_to_le(req->context, sizeof(req->context));
797
798 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
799
Sathya Perlab31c50a2009-09-17 10:30:13 -0700800 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700801 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700802 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530803 eqo->q.id = le16_to_cpu(resp->eq_id);
804 eqo->msix_idx =
805 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
806 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700807 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700808
Ivan Vecera29849612010-12-14 05:43:19 +0000809 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700810 return status;
811}
812
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000813/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000814int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000815 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700816{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700817 struct be_mcc_wrb *wrb;
818 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700819 int status;
820
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000821 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700822
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000823 wrb = wrb_from_mccq(adapter);
824 if (!wrb) {
825 status = -EBUSY;
826 goto err;
827 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700828 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700829
Somnath Kotur106df1e2011-10-27 07:12:13 +0000830 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
831 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000832 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700833 if (permanent) {
834 req->permanent = 1;
835 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700836 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000837 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700838 req->permanent = 0;
839 }
840
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000841 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700842 if (!status) {
843 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700844 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700845 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700846
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000847err:
848 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700849 return status;
850}
851
Sathya Perlab31c50a2009-09-17 10:30:13 -0700852/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000853int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000854 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700855{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700856 struct be_mcc_wrb *wrb;
857 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700858 int status;
859
Sathya Perlab31c50a2009-09-17 10:30:13 -0700860 spin_lock_bh(&adapter->mcc_lock);
861
862 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000863 if (!wrb) {
864 status = -EBUSY;
865 goto err;
866 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700867 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700868
Somnath Kotur106df1e2011-10-27 07:12:13 +0000869 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
870 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700871
Ajit Khapardef8617e02011-02-11 13:36:37 +0000872 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700873 req->if_id = cpu_to_le32(if_id);
874 memcpy(req->mac_address, mac_addr, ETH_ALEN);
875
Sathya Perlab31c50a2009-09-17 10:30:13 -0700876 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700877 if (!status) {
878 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
879 *pmac_id = le32_to_cpu(resp->pmac_id);
880 }
881
Sathya Perla713d03942009-11-22 22:02:45 +0000882err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700883 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000884
885 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
886 status = -EPERM;
887
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700888 return status;
889}
890
Sathya Perlab31c50a2009-09-17 10:30:13 -0700891/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000892int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700893{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700894 struct be_mcc_wrb *wrb;
895 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700896 int status;
897
Sathya Perla30128032011-11-10 19:17:57 +0000898 if (pmac_id == -1)
899 return 0;
900
Sathya Perlab31c50a2009-09-17 10:30:13 -0700901 spin_lock_bh(&adapter->mcc_lock);
902
903 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000904 if (!wrb) {
905 status = -EBUSY;
906 goto err;
907 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700908 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700909
Somnath Kotur106df1e2011-10-27 07:12:13 +0000910 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
911 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700912
Ajit Khapardef8617e02011-02-11 13:36:37 +0000913 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700914 req->if_id = cpu_to_le32(if_id);
915 req->pmac_id = cpu_to_le32(pmac_id);
916
Sathya Perlab31c50a2009-09-17 10:30:13 -0700917 status = be_mcc_notify_wait(adapter);
918
Sathya Perla713d03942009-11-22 22:02:45 +0000919err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700920 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700921 return status;
922}
923
Sathya Perlab31c50a2009-09-17 10:30:13 -0700924/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000925int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
926 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700927{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700928 struct be_mcc_wrb *wrb;
929 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700930 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700931 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700932 int status;
933
Ivan Vecera29849612010-12-14 05:43:19 +0000934 if (mutex_lock_interruptible(&adapter->mbox_lock))
935 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700936
937 wrb = wrb_from_mbox(adapter);
938 req = embedded_payload(wrb);
939 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700940
Somnath Kotur106df1e2011-10-27 07:12:13 +0000941 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
942 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700943
944 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +0000945
946 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000947 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
948 coalesce_wm);
949 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
950 ctxt, no_delay);
951 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
952 __ilog2_u32(cq->len/256));
953 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000954 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
955 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +0000956 } else {
957 req->hdr.version = 2;
958 req->page_size = 1; /* 1 for 4K */
959 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
960 no_delay);
961 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
962 __ilog2_u32(cq->len/256));
963 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
964 AMAP_SET_BITS(struct amap_cq_context_v2, eventable,
965 ctxt, 1);
966 AMAP_SET_BITS(struct amap_cq_context_v2, eqid,
967 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000968 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700969
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700970 be_dws_cpu_to_le(ctxt, sizeof(req->context));
971
972 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
973
Sathya Perlab31c50a2009-09-17 10:30:13 -0700974 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700975 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700976 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700977 cq->id = le16_to_cpu(resp->cq_id);
978 cq->created = true;
979 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700980
Ivan Vecera29849612010-12-14 05:43:19 +0000981 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000982
983 return status;
984}
985
986static u32 be_encoded_q_len(int q_len)
987{
988 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
989 if (len_encoded == 16)
990 len_encoded = 0;
991 return len_encoded;
992}
993
Jingoo Han4188e7d2013-08-05 18:02:02 +0900994static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
995 struct be_queue_info *mccq,
996 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000997{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700998 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000999 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001000 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001001 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001002 int status;
1003
Ivan Vecera29849612010-12-14 05:43:19 +00001004 if (mutex_lock_interruptible(&adapter->mbox_lock))
1005 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001006
1007 wrb = wrb_from_mbox(adapter);
1008 req = embedded_payload(wrb);
1009 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001010
Somnath Kotur106df1e2011-10-27 07:12:13 +00001011 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1012 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001013
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001014 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001015 if (lancer_chip(adapter)) {
1016 req->hdr.version = 1;
1017 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001018
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001019 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
1020 be_encoded_q_len(mccq->len));
1021 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
1022 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
1023 ctxt, cq->id);
1024 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
1025 ctxt, 1);
1026
1027 } else {
1028 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1029 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1030 be_encoded_q_len(mccq->len));
1031 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1032 }
1033
Somnath Koturcc4ce022010-10-21 07:11:14 -07001034 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001035 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001036 req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001037 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1038
1039 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1040
Sathya Perlab31c50a2009-09-17 10:30:13 -07001041 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001042 if (!status) {
1043 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1044 mccq->id = le16_to_cpu(resp->id);
1045 mccq->created = true;
1046 }
Ivan Vecera29849612010-12-14 05:43:19 +00001047 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001048
1049 return status;
1050}
1051
Jingoo Han4188e7d2013-08-05 18:02:02 +09001052static int be_cmd_mccq_org_create(struct be_adapter *adapter,
1053 struct be_queue_info *mccq,
1054 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001055{
1056 struct be_mcc_wrb *wrb;
1057 struct be_cmd_req_mcc_create *req;
1058 struct be_dma_mem *q_mem = &mccq->dma_mem;
1059 void *ctxt;
1060 int status;
1061
1062 if (mutex_lock_interruptible(&adapter->mbox_lock))
1063 return -1;
1064
1065 wrb = wrb_from_mbox(adapter);
1066 req = embedded_payload(wrb);
1067 ctxt = &req->context;
1068
Somnath Kotur106df1e2011-10-27 07:12:13 +00001069 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1070 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001071
1072 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1073
1074 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1075 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1076 be_encoded_q_len(mccq->len));
1077 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1078
1079 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1080
1081 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1082
1083 status = be_mbox_notify_wait(adapter);
1084 if (!status) {
1085 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1086 mccq->id = le16_to_cpu(resp->id);
1087 mccq->created = true;
1088 }
1089
1090 mutex_unlock(&adapter->mbox_lock);
1091 return status;
1092}
1093
1094int be_cmd_mccq_create(struct be_adapter *adapter,
1095 struct be_queue_info *mccq,
1096 struct be_queue_info *cq)
1097{
1098 int status;
1099
1100 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
1101 if (status && !lancer_chip(adapter)) {
1102 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1103 "or newer to avoid conflicting priorities between NIC "
1104 "and FCoE traffic");
1105 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1106 }
1107 return status;
1108}
1109
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001110int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001111{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001112 struct be_mcc_wrb *wrb;
1113 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001114 struct be_queue_info *txq = &txo->q;
1115 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001116 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001117 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001118
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001119 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001120
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001121 wrb = wrb_from_mccq(adapter);
1122 if (!wrb) {
1123 status = -EBUSY;
1124 goto err;
1125 }
1126
Sathya Perlab31c50a2009-09-17 10:30:13 -07001127 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001128
Somnath Kotur106df1e2011-10-27 07:12:13 +00001129 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1130 OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001131
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001132 if (lancer_chip(adapter)) {
1133 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001134 req->if_id = cpu_to_le16(adapter->if_handle);
1135 } else if (BEx_chip(adapter)) {
1136 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1137 req->hdr.version = 2;
1138 } else { /* For SH */
1139 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001140 }
1141
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001142 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1143 req->ulp_num = BE_ULP1_NUM;
1144 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001145 req->cq_id = cpu_to_le16(cq->id);
1146 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001147 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1148
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001149 ver = req->hdr.version;
1150
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001151 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001152 if (!status) {
1153 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
1154 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001155 if (ver == 2)
1156 txo->db_offset = le32_to_cpu(resp->db_offset);
1157 else
1158 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001159 txq->created = true;
1160 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001161
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001162err:
1163 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001164
1165 return status;
1166}
1167
Sathya Perla482c9e72011-06-29 23:33:17 +00001168/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001169int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001170 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001171 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001172{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001173 struct be_mcc_wrb *wrb;
1174 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001175 struct be_dma_mem *q_mem = &rxq->dma_mem;
1176 int status;
1177
Sathya Perla482c9e72011-06-29 23:33:17 +00001178 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001179
Sathya Perla482c9e72011-06-29 23:33:17 +00001180 wrb = wrb_from_mccq(adapter);
1181 if (!wrb) {
1182 status = -EBUSY;
1183 goto err;
1184 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001185 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001186
Somnath Kotur106df1e2011-10-27 07:12:13 +00001187 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1188 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001189
1190 req->cq_id = cpu_to_le16(cq_id);
1191 req->frag_size = fls(frag_size) - 1;
1192 req->num_pages = 2;
1193 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1194 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001195 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001196 req->rss_queue = cpu_to_le32(rss);
1197
Sathya Perla482c9e72011-06-29 23:33:17 +00001198 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001199 if (!status) {
1200 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1201 rxq->id = le16_to_cpu(resp->id);
1202 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001203 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001204 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001205
Sathya Perla482c9e72011-06-29 23:33:17 +00001206err:
1207 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001208 return status;
1209}
1210
Sathya Perlab31c50a2009-09-17 10:30:13 -07001211/* Generic destroyer function for all types of queues
1212 * Uses Mbox
1213 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001214int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001215 int queue_type)
1216{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001217 struct be_mcc_wrb *wrb;
1218 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001219 u8 subsys = 0, opcode = 0;
1220 int status;
1221
Ivan Vecera29849612010-12-14 05:43:19 +00001222 if (mutex_lock_interruptible(&adapter->mbox_lock))
1223 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001224
Sathya Perlab31c50a2009-09-17 10:30:13 -07001225 wrb = wrb_from_mbox(adapter);
1226 req = embedded_payload(wrb);
1227
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001228 switch (queue_type) {
1229 case QTYPE_EQ:
1230 subsys = CMD_SUBSYSTEM_COMMON;
1231 opcode = OPCODE_COMMON_EQ_DESTROY;
1232 break;
1233 case QTYPE_CQ:
1234 subsys = CMD_SUBSYSTEM_COMMON;
1235 opcode = OPCODE_COMMON_CQ_DESTROY;
1236 break;
1237 case QTYPE_TXQ:
1238 subsys = CMD_SUBSYSTEM_ETH;
1239 opcode = OPCODE_ETH_TX_DESTROY;
1240 break;
1241 case QTYPE_RXQ:
1242 subsys = CMD_SUBSYSTEM_ETH;
1243 opcode = OPCODE_ETH_RX_DESTROY;
1244 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001245 case QTYPE_MCCQ:
1246 subsys = CMD_SUBSYSTEM_COMMON;
1247 opcode = OPCODE_COMMON_MCC_DESTROY;
1248 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001249 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001250 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001251 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001252
Somnath Kotur106df1e2011-10-27 07:12:13 +00001253 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1254 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001255 req->id = cpu_to_le16(q->id);
1256
Sathya Perlab31c50a2009-09-17 10:30:13 -07001257 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001258 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001259
Ivan Vecera29849612010-12-14 05:43:19 +00001260 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001261 return status;
1262}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001263
Sathya Perla482c9e72011-06-29 23:33:17 +00001264/* Uses MCC */
1265int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1266{
1267 struct be_mcc_wrb *wrb;
1268 struct be_cmd_req_q_destroy *req;
1269 int status;
1270
1271 spin_lock_bh(&adapter->mcc_lock);
1272
1273 wrb = wrb_from_mccq(adapter);
1274 if (!wrb) {
1275 status = -EBUSY;
1276 goto err;
1277 }
1278 req = embedded_payload(wrb);
1279
Somnath Kotur106df1e2011-10-27 07:12:13 +00001280 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1281 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001282 req->id = cpu_to_le16(q->id);
1283
1284 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001285 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001286
1287err:
1288 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001289 return status;
1290}
1291
Sathya Perlab31c50a2009-09-17 10:30:13 -07001292/* Create an rx filtering policy configuration on an i/f
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001293 * Uses MCCQ
Sathya Perlab31c50a2009-09-17 10:30:13 -07001294 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001295int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001296 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001297{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001298 struct be_mcc_wrb *wrb;
1299 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300 int status;
1301
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001302 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001303
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001304 wrb = wrb_from_mccq(adapter);
1305 if (!wrb) {
1306 status = -EBUSY;
1307 goto err;
1308 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001309 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001310
Somnath Kotur106df1e2011-10-27 07:12:13 +00001311 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1312 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001313 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001314 req->capability_flags = cpu_to_le32(cap_flags);
1315 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001316
1317 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001318
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001319 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001320 if (!status) {
1321 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1322 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301323
1324 /* Hack to retrieve VF's pmac-id on BE3 */
1325 if (BE3_chip(adapter) && !be_physfn(adapter))
1326 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001327 }
1328
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001329err:
1330 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001331 return status;
1332}
1333
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001334/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001335int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001336{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001337 struct be_mcc_wrb *wrb;
1338 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001339 int status;
1340
Sathya Perla30128032011-11-10 19:17:57 +00001341 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001342 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001343
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001344 spin_lock_bh(&adapter->mcc_lock);
1345
1346 wrb = wrb_from_mccq(adapter);
1347 if (!wrb) {
1348 status = -EBUSY;
1349 goto err;
1350 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001351 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001352
Somnath Kotur106df1e2011-10-27 07:12:13 +00001353 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1354 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001355 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001356 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001357
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001358 status = be_mcc_notify_wait(adapter);
1359err:
1360 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001361 return status;
1362}
1363
1364/* Get stats is a non embedded command: the request is not embedded inside
1365 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001366 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001367 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001368int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001370 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001371 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001372 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001373
Sathya Perlab31c50a2009-09-17 10:30:13 -07001374 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001375
Sathya Perlab31c50a2009-09-17 10:30:13 -07001376 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001377 if (!wrb) {
1378 status = -EBUSY;
1379 goto err;
1380 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001381 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001382
Somnath Kotur106df1e2011-10-27 07:12:13 +00001383 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1384 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001385
Sathya Perlaca34fe32012-11-06 17:48:56 +00001386 /* version 1 of the cmd is not supported only by BE2 */
1387 if (!BE2_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001388 hdr->version = 1;
1389
Sathya Perlab31c50a2009-09-17 10:30:13 -07001390 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001391 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001392
Sathya Perla713d03942009-11-22 22:02:45 +00001393err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001394 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001395 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001396}
1397
Selvin Xavier005d5692011-05-16 07:36:35 +00001398/* Lancer Stats */
1399int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1400 struct be_dma_mem *nonemb_cmd)
1401{
1402
1403 struct be_mcc_wrb *wrb;
1404 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001405 int status = 0;
1406
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001407 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1408 CMD_SUBSYSTEM_ETH))
1409 return -EPERM;
1410
Selvin Xavier005d5692011-05-16 07:36:35 +00001411 spin_lock_bh(&adapter->mcc_lock);
1412
1413 wrb = wrb_from_mccq(adapter);
1414 if (!wrb) {
1415 status = -EBUSY;
1416 goto err;
1417 }
1418 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001419
Somnath Kotur106df1e2011-10-27 07:12:13 +00001420 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1421 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1422 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001423
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001424 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001425 req->cmd_params.params.reset_stats = 0;
1426
Selvin Xavier005d5692011-05-16 07:36:35 +00001427 be_mcc_notify(adapter);
1428 adapter->stats_cmd_sent = true;
1429
1430err:
1431 spin_unlock_bh(&adapter->mcc_lock);
1432 return status;
1433}
1434
Sathya Perla323ff712012-09-28 04:39:43 +00001435static int be_mac_to_link_speed(int mac_speed)
1436{
1437 switch (mac_speed) {
1438 case PHY_LINK_SPEED_ZERO:
1439 return 0;
1440 case PHY_LINK_SPEED_10MBPS:
1441 return 10;
1442 case PHY_LINK_SPEED_100MBPS:
1443 return 100;
1444 case PHY_LINK_SPEED_1GBPS:
1445 return 1000;
1446 case PHY_LINK_SPEED_10GBPS:
1447 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301448 case PHY_LINK_SPEED_20GBPS:
1449 return 20000;
1450 case PHY_LINK_SPEED_25GBPS:
1451 return 25000;
1452 case PHY_LINK_SPEED_40GBPS:
1453 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001454 }
1455 return 0;
1456}
1457
1458/* Uses synchronous mcc
1459 * Returns link_speed in Mbps
1460 */
1461int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1462 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001463{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001464 struct be_mcc_wrb *wrb;
1465 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001466 int status;
1467
Sathya Perlab31c50a2009-09-17 10:30:13 -07001468 spin_lock_bh(&adapter->mcc_lock);
1469
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001470 if (link_status)
1471 *link_status = LINK_DOWN;
1472
Sathya Perlab31c50a2009-09-17 10:30:13 -07001473 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001474 if (!wrb) {
1475 status = -EBUSY;
1476 goto err;
1477 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001478 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001479
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001480 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1481 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1482
Sathya Perlaca34fe32012-11-06 17:48:56 +00001483 /* version 1 of the cmd is not supported only by BE2 */
1484 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001485 req->hdr.version = 1;
1486
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001487 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001488
Sathya Perlab31c50a2009-09-17 10:30:13 -07001489 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001490 if (!status) {
1491 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sathya Perla323ff712012-09-28 04:39:43 +00001492 if (link_speed) {
1493 *link_speed = resp->link_speed ?
1494 le16_to_cpu(resp->link_speed) * 10 :
1495 be_mac_to_link_speed(resp->mac_speed);
1496
1497 if (!resp->logical_link_status)
1498 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001499 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001500 if (link_status)
1501 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001502 }
1503
Sathya Perla713d03942009-11-22 22:02:45 +00001504err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001505 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001506 return status;
1507}
1508
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001509/* Uses synchronous mcc */
1510int be_cmd_get_die_temperature(struct be_adapter *adapter)
1511{
1512 struct be_mcc_wrb *wrb;
1513 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301514 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001515
1516 spin_lock_bh(&adapter->mcc_lock);
1517
1518 wrb = wrb_from_mccq(adapter);
1519 if (!wrb) {
1520 status = -EBUSY;
1521 goto err;
1522 }
1523 req = embedded_payload(wrb);
1524
Somnath Kotur106df1e2011-10-27 07:12:13 +00001525 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1526 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1527 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001528
Somnath Kotur3de09452011-09-30 07:25:05 +00001529 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001530
1531err:
1532 spin_unlock_bh(&adapter->mcc_lock);
1533 return status;
1534}
1535
Somnath Kotur311fddc2011-03-16 21:22:43 +00001536/* Uses synchronous mcc */
1537int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1538{
1539 struct be_mcc_wrb *wrb;
1540 struct be_cmd_req_get_fat *req;
1541 int status;
1542
1543 spin_lock_bh(&adapter->mcc_lock);
1544
1545 wrb = wrb_from_mccq(adapter);
1546 if (!wrb) {
1547 status = -EBUSY;
1548 goto err;
1549 }
1550 req = embedded_payload(wrb);
1551
Somnath Kotur106df1e2011-10-27 07:12:13 +00001552 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1553 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001554 req->fat_operation = cpu_to_le32(QUERY_FAT);
1555 status = be_mcc_notify_wait(adapter);
1556 if (!status) {
1557 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1558 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001559 *log_size = le32_to_cpu(resp->log_size) -
1560 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001561 }
1562err:
1563 spin_unlock_bh(&adapter->mcc_lock);
1564 return status;
1565}
1566
1567void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1568{
1569 struct be_dma_mem get_fat_cmd;
1570 struct be_mcc_wrb *wrb;
1571 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001572 u32 offset = 0, total_size, buf_size,
1573 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001574 int status;
1575
1576 if (buf_len == 0)
1577 return;
1578
1579 total_size = buf_len;
1580
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001581 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1582 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1583 get_fat_cmd.size,
1584 &get_fat_cmd.dma);
1585 if (!get_fat_cmd.va) {
1586 status = -ENOMEM;
1587 dev_err(&adapter->pdev->dev,
1588 "Memory allocation failure while retrieving FAT data\n");
1589 return;
1590 }
1591
Somnath Kotur311fddc2011-03-16 21:22:43 +00001592 spin_lock_bh(&adapter->mcc_lock);
1593
Somnath Kotur311fddc2011-03-16 21:22:43 +00001594 while (total_size) {
1595 buf_size = min(total_size, (u32)60*1024);
1596 total_size -= buf_size;
1597
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001598 wrb = wrb_from_mccq(adapter);
1599 if (!wrb) {
1600 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001601 goto err;
1602 }
1603 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001604
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001605 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001606 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1607 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1608 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001609
1610 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1611 req->read_log_offset = cpu_to_le32(log_offset);
1612 req->read_log_length = cpu_to_le32(buf_size);
1613 req->data_buffer_size = cpu_to_le32(buf_size);
1614
1615 status = be_mcc_notify_wait(adapter);
1616 if (!status) {
1617 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1618 memcpy(buf + offset,
1619 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001620 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001621 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001622 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001623 goto err;
1624 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001625 offset += buf_size;
1626 log_offset += buf_size;
1627 }
1628err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001629 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1630 get_fat_cmd.va,
1631 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001632 spin_unlock_bh(&adapter->mcc_lock);
1633}
1634
Sathya Perla04b71172011-09-27 13:30:27 -04001635/* Uses synchronous mcc */
1636int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1637 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001638{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001639 struct be_mcc_wrb *wrb;
1640 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001641 int status;
1642
Sathya Perla04b71172011-09-27 13:30:27 -04001643 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001644
Sathya Perla04b71172011-09-27 13:30:27 -04001645 wrb = wrb_from_mccq(adapter);
1646 if (!wrb) {
1647 status = -EBUSY;
1648 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001649 }
1650
Sathya Perla04b71172011-09-27 13:30:27 -04001651 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001652
Somnath Kotur106df1e2011-10-27 07:12:13 +00001653 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1654 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001655 status = be_mcc_notify_wait(adapter);
1656 if (!status) {
1657 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1658 strcpy(fw_ver, resp->firmware_version_string);
1659 if (fw_on_flash)
1660 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1661 }
1662err:
1663 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001664 return status;
1665}
1666
Sathya Perlab31c50a2009-09-17 10:30:13 -07001667/* set the EQ delay interval of an EQ to specified value
1668 * Uses async mcc
1669 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001670int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001671{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001672 struct be_mcc_wrb *wrb;
1673 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001674 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001675
Sathya Perlab31c50a2009-09-17 10:30:13 -07001676 spin_lock_bh(&adapter->mcc_lock);
1677
1678 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001679 if (!wrb) {
1680 status = -EBUSY;
1681 goto err;
1682 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001683 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001684
Somnath Kotur106df1e2011-10-27 07:12:13 +00001685 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1686 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001687
1688 req->num_eq = cpu_to_le32(1);
1689 req->delay[0].eq_id = cpu_to_le32(eq_id);
1690 req->delay[0].phase = 0;
1691 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1692
Sathya Perlab31c50a2009-09-17 10:30:13 -07001693 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001694
Sathya Perla713d03942009-11-22 22:02:45 +00001695err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001696 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001697 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001698}
1699
Sathya Perlab31c50a2009-09-17 10:30:13 -07001700/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001701int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001702 u32 num, bool untagged, bool promiscuous)
1703{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001704 struct be_mcc_wrb *wrb;
1705 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001706 int status;
1707
Sathya Perlab31c50a2009-09-17 10:30:13 -07001708 spin_lock_bh(&adapter->mcc_lock);
1709
1710 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001711 if (!wrb) {
1712 status = -EBUSY;
1713 goto err;
1714 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001715 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001716
Somnath Kotur106df1e2011-10-27 07:12:13 +00001717 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1718 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001719
1720 req->interface_id = if_id;
1721 req->promiscuous = promiscuous;
1722 req->untagged = untagged;
1723 req->num_vlan = num;
1724 if (!promiscuous) {
1725 memcpy(req->normal_vlan, vtag_array,
1726 req->num_vlan * sizeof(vtag_array[0]));
1727 }
1728
Sathya Perlab31c50a2009-09-17 10:30:13 -07001729 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001730
Sathya Perla713d03942009-11-22 22:02:45 +00001731err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001732 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001733 return status;
1734}
1735
Sathya Perla5b8821b2011-08-02 19:57:44 +00001736int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001737{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001738 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001739 struct be_dma_mem *mem = &adapter->rx_filter;
1740 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001741 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001742
Sathya Perla8788fdc2009-07-27 22:52:03 +00001743 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001744
Sathya Perlab31c50a2009-09-17 10:30:13 -07001745 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001746 if (!wrb) {
1747 status = -EBUSY;
1748 goto err;
1749 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001750 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001751 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1752 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1753 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001754
Sathya Perla5b8821b2011-08-02 19:57:44 +00001755 req->if_id = cpu_to_le32(adapter->if_handle);
1756 if (flags & IFF_PROMISC) {
1757 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Ajit Khapardec5dae582013-05-01 09:38:24 +00001758 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1759 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001760 if (value == ON)
1761 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Ajit Khapardec5dae582013-05-01 09:38:24 +00001762 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1763 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001764 } else if (flags & IFF_ALLMULTI) {
1765 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001766 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001767 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001768 struct netdev_hw_addr *ha;
1769 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001770
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001771 req->if_flags_mask = req->if_flags =
1772 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001773
1774 /* Reset mcast promisc mode if already set by setting mask
1775 * and not setting flags field
1776 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001777 req->if_flags_mask |=
1778 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05301779 be_if_cap_flags(adapter));
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001780 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001781 netdev_for_each_mc_addr(ha, adapter->netdev)
1782 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1783 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001784
Sathya Perla0d1d5872011-08-03 05:19:27 -07001785 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001786err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001787 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001788 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001789}
1790
Sathya Perlab31c50a2009-09-17 10:30:13 -07001791/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001792int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001793{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001794 struct be_mcc_wrb *wrb;
1795 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001796 int status;
1797
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001798 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1799 CMD_SUBSYSTEM_COMMON))
1800 return -EPERM;
1801
Sathya Perlab31c50a2009-09-17 10:30:13 -07001802 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001803
Sathya Perlab31c50a2009-09-17 10:30:13 -07001804 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001805 if (!wrb) {
1806 status = -EBUSY;
1807 goto err;
1808 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001809 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001810
Somnath Kotur106df1e2011-10-27 07:12:13 +00001811 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1812 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001813
1814 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1815 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1816
Sathya Perlab31c50a2009-09-17 10:30:13 -07001817 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001818
Sathya Perla713d03942009-11-22 22:02:45 +00001819err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001820 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001821 return status;
1822}
1823
Sathya Perlab31c50a2009-09-17 10:30:13 -07001824/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001825int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001826{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001827 struct be_mcc_wrb *wrb;
1828 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001829 int status;
1830
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001831 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
1832 CMD_SUBSYSTEM_COMMON))
1833 return -EPERM;
1834
Sathya Perlab31c50a2009-09-17 10:30:13 -07001835 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001836
Sathya Perlab31c50a2009-09-17 10:30:13 -07001837 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001838 if (!wrb) {
1839 status = -EBUSY;
1840 goto err;
1841 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001842 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001843
Somnath Kotur106df1e2011-10-27 07:12:13 +00001844 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1845 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001846
Sathya Perlab31c50a2009-09-17 10:30:13 -07001847 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001848 if (!status) {
1849 struct be_cmd_resp_get_flow_control *resp =
1850 embedded_payload(wrb);
1851 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1852 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1853 }
1854
Sathya Perla713d03942009-11-22 22:02:45 +00001855err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001856 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001857 return status;
1858}
1859
Sathya Perlab31c50a2009-09-17 10:30:13 -07001860/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001861int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
Vasundhara Volam0ad31572013-04-21 23:28:16 +00001862 u32 *mode, u32 *caps, u16 *asic_rev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001863{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001864 struct be_mcc_wrb *wrb;
1865 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001866 int status;
1867
Ivan Vecera29849612010-12-14 05:43:19 +00001868 if (mutex_lock_interruptible(&adapter->mbox_lock))
1869 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001870
Sathya Perlab31c50a2009-09-17 10:30:13 -07001871 wrb = wrb_from_mbox(adapter);
1872 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001873
Somnath Kotur106df1e2011-10-27 07:12:13 +00001874 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1875 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001876
Sathya Perlab31c50a2009-09-17 10:30:13 -07001877 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001878 if (!status) {
1879 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1880 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001881 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001882 *caps = le32_to_cpu(resp->function_caps);
Vasundhara Volam0ad31572013-04-21 23:28:16 +00001883 *asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001884 }
1885
Ivan Vecera29849612010-12-14 05:43:19 +00001886 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001887 return status;
1888}
sarveshwarb14074ea2009-08-05 13:05:24 -07001889
Sathya Perlab31c50a2009-09-17 10:30:13 -07001890/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001891int be_cmd_reset_function(struct be_adapter *adapter)
1892{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001893 struct be_mcc_wrb *wrb;
1894 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001895 int status;
1896
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00001897 if (lancer_chip(adapter)) {
1898 status = lancer_wait_ready(adapter);
1899 if (!status) {
1900 iowrite32(SLI_PORT_CONTROL_IP_MASK,
1901 adapter->db + SLIPORT_CONTROL_OFFSET);
1902 status = lancer_test_and_set_rdy_state(adapter);
1903 }
1904 if (status) {
1905 dev_err(&adapter->pdev->dev,
1906 "Adapter in non recoverable error\n");
1907 }
1908 return status;
1909 }
1910
Ivan Vecera29849612010-12-14 05:43:19 +00001911 if (mutex_lock_interruptible(&adapter->mbox_lock))
1912 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001913
Sathya Perlab31c50a2009-09-17 10:30:13 -07001914 wrb = wrb_from_mbox(adapter);
1915 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001916
Somnath Kotur106df1e2011-10-27 07:12:13 +00001917 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1918 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001919
Sathya Perlab31c50a2009-09-17 10:30:13 -07001920 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001921
Ivan Vecera29849612010-12-14 05:43:19 +00001922 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001923 return status;
1924}
Ajit Khaparde84517482009-09-04 03:12:16 +00001925
Suresh Reddy594ad542013-04-25 23:03:20 +00001926int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
1927 u32 rss_hash_opts, u16 table_size)
Sathya Perla3abcded2010-10-03 22:12:27 -07001928{
1929 struct be_mcc_wrb *wrb;
1930 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001931 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1932 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1933 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001934 int status;
1935
Ivan Vecera29849612010-12-14 05:43:19 +00001936 if (mutex_lock_interruptible(&adapter->mbox_lock))
1937 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001938
1939 wrb = wrb_from_mbox(adapter);
1940 req = embedded_payload(wrb);
1941
Somnath Kotur106df1e2011-10-27 07:12:13 +00001942 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1943 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001944
1945 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00001946 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07001947 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00001948
1949 if (lancer_chip(adapter) || skyhawk_chip(adapter))
1950 req->hdr.version = 1;
1951
Sathya Perla3abcded2010-10-03 22:12:27 -07001952 memcpy(req->cpu_table, rsstable, table_size);
1953 memcpy(req->hash, myhash, sizeof(myhash));
1954 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1955
1956 status = be_mbox_notify_wait(adapter);
1957
Ivan Vecera29849612010-12-14 05:43:19 +00001958 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001959 return status;
1960}
1961
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001962/* Uses sync mcc */
1963int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1964 u8 bcn, u8 sts, u8 state)
1965{
1966 struct be_mcc_wrb *wrb;
1967 struct be_cmd_req_enable_disable_beacon *req;
1968 int status;
1969
1970 spin_lock_bh(&adapter->mcc_lock);
1971
1972 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001973 if (!wrb) {
1974 status = -EBUSY;
1975 goto err;
1976 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001977 req = embedded_payload(wrb);
1978
Somnath Kotur106df1e2011-10-27 07:12:13 +00001979 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1980 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001981
1982 req->port_num = port_num;
1983 req->beacon_state = state;
1984 req->beacon_duration = bcn;
1985 req->status_duration = sts;
1986
1987 status = be_mcc_notify_wait(adapter);
1988
Sathya Perla713d03942009-11-22 22:02:45 +00001989err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001990 spin_unlock_bh(&adapter->mcc_lock);
1991 return status;
1992}
1993
1994/* Uses sync mcc */
1995int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1996{
1997 struct be_mcc_wrb *wrb;
1998 struct be_cmd_req_get_beacon_state *req;
1999 int status;
2000
2001 spin_lock_bh(&adapter->mcc_lock);
2002
2003 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002004 if (!wrb) {
2005 status = -EBUSY;
2006 goto err;
2007 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002008 req = embedded_payload(wrb);
2009
Somnath Kotur106df1e2011-10-27 07:12:13 +00002010 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2011 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002012
2013 req->port_num = port_num;
2014
2015 status = be_mcc_notify_wait(adapter);
2016 if (!status) {
2017 struct be_cmd_resp_get_beacon_state *resp =
2018 embedded_payload(wrb);
2019 *state = resp->beacon_state;
2020 }
2021
Sathya Perla713d03942009-11-22 22:02:45 +00002022err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002023 spin_unlock_bh(&adapter->mcc_lock);
2024 return status;
2025}
2026
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002027int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002028 u32 data_size, u32 data_offset,
2029 const char *obj_name, u32 *data_written,
2030 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002031{
2032 struct be_mcc_wrb *wrb;
2033 struct lancer_cmd_req_write_object *req;
2034 struct lancer_cmd_resp_write_object *resp;
2035 void *ctxt = NULL;
2036 int status;
2037
2038 spin_lock_bh(&adapter->mcc_lock);
2039 adapter->flash_status = 0;
2040
2041 wrb = wrb_from_mccq(adapter);
2042 if (!wrb) {
2043 status = -EBUSY;
2044 goto err_unlock;
2045 }
2046
2047 req = embedded_payload(wrb);
2048
Somnath Kotur106df1e2011-10-27 07:12:13 +00002049 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002050 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00002051 sizeof(struct lancer_cmd_req_write_object), wrb,
2052 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002053
2054 ctxt = &req->context;
2055 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2056 write_length, ctxt, data_size);
2057
2058 if (data_size == 0)
2059 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2060 eof, ctxt, 1);
2061 else
2062 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2063 eof, ctxt, 0);
2064
2065 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2066 req->write_offset = cpu_to_le32(data_offset);
2067 strcpy(req->object_name, obj_name);
2068 req->descriptor_count = cpu_to_le32(1);
2069 req->buf_len = cpu_to_le32(data_size);
2070 req->addr_low = cpu_to_le32((cmd->dma +
2071 sizeof(struct lancer_cmd_req_write_object))
2072 & 0xFFFFFFFF);
2073 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2074 sizeof(struct lancer_cmd_req_write_object)));
2075
2076 be_mcc_notify(adapter);
2077 spin_unlock_bh(&adapter->mcc_lock);
2078
2079 if (!wait_for_completion_timeout(&adapter->flash_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002080 msecs_to_jiffies(60000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002081 status = -1;
2082 else
2083 status = adapter->flash_status;
2084
2085 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002086 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002087 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002088 *change_status = resp->change_status;
2089 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002090 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002091 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002092
2093 return status;
2094
2095err_unlock:
2096 spin_unlock_bh(&adapter->mcc_lock);
2097 return status;
2098}
2099
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002100int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
2101 u32 data_size, u32 data_offset, const char *obj_name,
2102 u32 *data_read, u32 *eof, u8 *addn_status)
2103{
2104 struct be_mcc_wrb *wrb;
2105 struct lancer_cmd_req_read_object *req;
2106 struct lancer_cmd_resp_read_object *resp;
2107 int status;
2108
2109 spin_lock_bh(&adapter->mcc_lock);
2110
2111 wrb = wrb_from_mccq(adapter);
2112 if (!wrb) {
2113 status = -EBUSY;
2114 goto err_unlock;
2115 }
2116
2117 req = embedded_payload(wrb);
2118
2119 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2120 OPCODE_COMMON_READ_OBJECT,
2121 sizeof(struct lancer_cmd_req_read_object), wrb,
2122 NULL);
2123
2124 req->desired_read_len = cpu_to_le32(data_size);
2125 req->read_offset = cpu_to_le32(data_offset);
2126 strcpy(req->object_name, obj_name);
2127 req->descriptor_count = cpu_to_le32(1);
2128 req->buf_len = cpu_to_le32(data_size);
2129 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2130 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2131
2132 status = be_mcc_notify_wait(adapter);
2133
2134 resp = embedded_payload(wrb);
2135 if (!status) {
2136 *data_read = le32_to_cpu(resp->actual_read_len);
2137 *eof = le32_to_cpu(resp->eof);
2138 } else {
2139 *addn_status = resp->additional_status;
2140 }
2141
2142err_unlock:
2143 spin_unlock_bh(&adapter->mcc_lock);
2144 return status;
2145}
2146
Ajit Khaparde84517482009-09-04 03:12:16 +00002147int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
2148 u32 flash_type, u32 flash_opcode, u32 buf_size)
2149{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002150 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002151 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002152 int status;
2153
Sathya Perlab31c50a2009-09-17 10:30:13 -07002154 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002155 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002156
2157 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002158 if (!wrb) {
2159 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002160 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002161 }
2162 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002163
Somnath Kotur106df1e2011-10-27 07:12:13 +00002164 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2165 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002166
2167 req->params.op_type = cpu_to_le32(flash_type);
2168 req->params.op_code = cpu_to_le32(flash_opcode);
2169 req->params.data_buf_size = cpu_to_le32(buf_size);
2170
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002171 be_mcc_notify(adapter);
2172 spin_unlock_bh(&adapter->mcc_lock);
2173
2174 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00002175 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002176 status = -1;
2177 else
2178 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002179
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002180 return status;
2181
2182err_unlock:
2183 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002184 return status;
2185}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002186
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002187int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2188 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002189{
2190 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002191 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002192 int status;
2193
2194 spin_lock_bh(&adapter->mcc_lock);
2195
2196 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002197 if (!wrb) {
2198 status = -EBUSY;
2199 goto err;
2200 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002201 req = embedded_payload(wrb);
2202
Somnath Kotur106df1e2011-10-27 07:12:13 +00002203 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002204 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2205 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002206
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00002207 req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002208 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002209 req->params.offset = cpu_to_le32(offset);
2210 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002211
2212 status = be_mcc_notify_wait(adapter);
2213 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002214 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002215
Sathya Perla713d03942009-11-22 22:02:45 +00002216err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002217 spin_unlock_bh(&adapter->mcc_lock);
2218 return status;
2219}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002220
Dan Carpenterc196b022010-05-26 04:47:39 +00002221int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002222 struct be_dma_mem *nonemb_cmd)
2223{
2224 struct be_mcc_wrb *wrb;
2225 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002226 int status;
2227
2228 spin_lock_bh(&adapter->mcc_lock);
2229
2230 wrb = wrb_from_mccq(adapter);
2231 if (!wrb) {
2232 status = -EBUSY;
2233 goto err;
2234 }
2235 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002236
Somnath Kotur106df1e2011-10-27 07:12:13 +00002237 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2238 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2239 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002240 memcpy(req->magic_mac, mac, ETH_ALEN);
2241
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002242 status = be_mcc_notify_wait(adapter);
2243
2244err:
2245 spin_unlock_bh(&adapter->mcc_lock);
2246 return status;
2247}
Suresh Rff33a6e2009-12-03 16:15:52 -08002248
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002249int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2250 u8 loopback_type, u8 enable)
2251{
2252 struct be_mcc_wrb *wrb;
2253 struct be_cmd_req_set_lmode *req;
2254 int status;
2255
2256 spin_lock_bh(&adapter->mcc_lock);
2257
2258 wrb = wrb_from_mccq(adapter);
2259 if (!wrb) {
2260 status = -EBUSY;
2261 goto err;
2262 }
2263
2264 req = embedded_payload(wrb);
2265
Somnath Kotur106df1e2011-10-27 07:12:13 +00002266 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2267 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2268 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002269
2270 req->src_port = port_num;
2271 req->dest_port = port_num;
2272 req->loopback_type = loopback_type;
2273 req->loopback_state = enable;
2274
2275 status = be_mcc_notify_wait(adapter);
2276err:
2277 spin_unlock_bh(&adapter->mcc_lock);
2278 return status;
2279}
2280
Suresh Rff33a6e2009-12-03 16:15:52 -08002281int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2282 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2283{
2284 struct be_mcc_wrb *wrb;
2285 struct be_cmd_req_loopback_test *req;
2286 int status;
2287
2288 spin_lock_bh(&adapter->mcc_lock);
2289
2290 wrb = wrb_from_mccq(adapter);
2291 if (!wrb) {
2292 status = -EBUSY;
2293 goto err;
2294 }
2295
2296 req = embedded_payload(wrb);
2297
Somnath Kotur106df1e2011-10-27 07:12:13 +00002298 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2299 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002300 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002301
2302 req->pattern = cpu_to_le64(pattern);
2303 req->src_port = cpu_to_le32(port_num);
2304 req->dest_port = cpu_to_le32(port_num);
2305 req->pkt_size = cpu_to_le32(pkt_size);
2306 req->num_pkts = cpu_to_le32(num_pkts);
2307 req->loopback_type = cpu_to_le32(loopback_type);
2308
2309 status = be_mcc_notify_wait(adapter);
2310 if (!status) {
2311 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2312 status = le32_to_cpu(resp->status);
2313 }
2314
2315err:
2316 spin_unlock_bh(&adapter->mcc_lock);
2317 return status;
2318}
2319
2320int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2321 u32 byte_cnt, struct be_dma_mem *cmd)
2322{
2323 struct be_mcc_wrb *wrb;
2324 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002325 int status;
2326 int i, j = 0;
2327
2328 spin_lock_bh(&adapter->mcc_lock);
2329
2330 wrb = wrb_from_mccq(adapter);
2331 if (!wrb) {
2332 status = -EBUSY;
2333 goto err;
2334 }
2335 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002336 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2337 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002338
2339 req->pattern = cpu_to_le64(pattern);
2340 req->byte_count = cpu_to_le32(byte_cnt);
2341 for (i = 0; i < byte_cnt; i++) {
2342 req->snd_buff[i] = (u8)(pattern >> (j*8));
2343 j++;
2344 if (j > 7)
2345 j = 0;
2346 }
2347
2348 status = be_mcc_notify_wait(adapter);
2349
2350 if (!status) {
2351 struct be_cmd_resp_ddrdma_test *resp;
2352 resp = cmd->va;
2353 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2354 resp->snd_err) {
2355 status = -1;
2356 }
2357 }
2358
2359err:
2360 spin_unlock_bh(&adapter->mcc_lock);
2361 return status;
2362}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002363
Dan Carpenterc196b022010-05-26 04:47:39 +00002364int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002365 struct be_dma_mem *nonemb_cmd)
2366{
2367 struct be_mcc_wrb *wrb;
2368 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002369 int status;
2370
2371 spin_lock_bh(&adapter->mcc_lock);
2372
2373 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002374 if (!wrb) {
2375 status = -EBUSY;
2376 goto err;
2377 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002378 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002379
Somnath Kotur106df1e2011-10-27 07:12:13 +00002380 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2381 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2382 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002383
2384 status = be_mcc_notify_wait(adapter);
2385
Ajit Khapardee45ff012011-02-04 17:18:28 +00002386err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002387 spin_unlock_bh(&adapter->mcc_lock);
2388 return status;
2389}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002390
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002391int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002392{
2393 struct be_mcc_wrb *wrb;
2394 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002395 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002396 int status;
2397
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002398 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2399 CMD_SUBSYSTEM_COMMON))
2400 return -EPERM;
2401
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002402 spin_lock_bh(&adapter->mcc_lock);
2403
2404 wrb = wrb_from_mccq(adapter);
2405 if (!wrb) {
2406 status = -EBUSY;
2407 goto err;
2408 }
Sathya Perla306f1342011-08-02 19:57:45 +00002409 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2410 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2411 &cmd.dma);
2412 if (!cmd.va) {
2413 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2414 status = -ENOMEM;
2415 goto err;
2416 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002417
Sathya Perla306f1342011-08-02 19:57:45 +00002418 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002419
Somnath Kotur106df1e2011-10-27 07:12:13 +00002420 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2421 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2422 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002423
2424 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002425 if (!status) {
2426 struct be_phy_info *resp_phy_info =
2427 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002428 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2429 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002430 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002431 adapter->phy.auto_speeds_supported =
2432 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2433 adapter->phy.fixed_speeds_supported =
2434 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2435 adapter->phy.misc_params =
2436 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05302437
2438 if (BE2_chip(adapter)) {
2439 adapter->phy.fixed_speeds_supported =
2440 BE_SUPPORTED_SPEED_10GBPS |
2441 BE_SUPPORTED_SPEED_1GBPS;
2442 }
Sathya Perla306f1342011-08-02 19:57:45 +00002443 }
2444 pci_free_consistent(adapter->pdev, cmd.size,
2445 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002446err:
2447 spin_unlock_bh(&adapter->mcc_lock);
2448 return status;
2449}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002450
2451int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2452{
2453 struct be_mcc_wrb *wrb;
2454 struct be_cmd_req_set_qos *req;
2455 int status;
2456
2457 spin_lock_bh(&adapter->mcc_lock);
2458
2459 wrb = wrb_from_mccq(adapter);
2460 if (!wrb) {
2461 status = -EBUSY;
2462 goto err;
2463 }
2464
2465 req = embedded_payload(wrb);
2466
Somnath Kotur106df1e2011-10-27 07:12:13 +00002467 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2468 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002469
2470 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002471 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2472 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002473
2474 status = be_mcc_notify_wait(adapter);
2475
2476err:
2477 spin_unlock_bh(&adapter->mcc_lock);
2478 return status;
2479}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002480
2481int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2482{
2483 struct be_mcc_wrb *wrb;
2484 struct be_cmd_req_cntl_attribs *req;
2485 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002486 int status;
2487 int payload_len = max(sizeof(*req), sizeof(*resp));
2488 struct mgmt_controller_attrib *attribs;
2489 struct be_dma_mem attribs_cmd;
2490
Suresh Reddyd98ef502013-04-25 00:56:55 +00002491 if (mutex_lock_interruptible(&adapter->mbox_lock))
2492 return -1;
2493
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002494 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2495 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2496 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2497 &attribs_cmd.dma);
2498 if (!attribs_cmd.va) {
2499 dev_err(&adapter->pdev->dev,
2500 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002501 status = -ENOMEM;
2502 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002503 }
2504
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002505 wrb = wrb_from_mbox(adapter);
2506 if (!wrb) {
2507 status = -EBUSY;
2508 goto err;
2509 }
2510 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002511
Somnath Kotur106df1e2011-10-27 07:12:13 +00002512 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2513 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2514 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002515
2516 status = be_mbox_notify_wait(adapter);
2517 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002518 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002519 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2520 }
2521
2522err:
2523 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002524 if (attribs_cmd.va)
2525 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2526 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002527 return status;
2528}
Sathya Perla2e588f82011-03-11 02:49:26 +00002529
2530/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002531int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002532{
2533 struct be_mcc_wrb *wrb;
2534 struct be_cmd_req_set_func_cap *req;
2535 int status;
2536
2537 if (mutex_lock_interruptible(&adapter->mbox_lock))
2538 return -1;
2539
2540 wrb = wrb_from_mbox(adapter);
2541 if (!wrb) {
2542 status = -EBUSY;
2543 goto err;
2544 }
2545
2546 req = embedded_payload(wrb);
2547
Somnath Kotur106df1e2011-10-27 07:12:13 +00002548 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2549 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002550
2551 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2552 CAPABILITY_BE3_NATIVE_ERX_API);
2553 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2554
2555 status = be_mbox_notify_wait(adapter);
2556 if (!status) {
2557 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2558 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2559 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002560 if (!adapter->be3_native)
2561 dev_warn(&adapter->pdev->dev,
2562 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002563 }
2564err:
2565 mutex_unlock(&adapter->mbox_lock);
2566 return status;
2567}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002568
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002569/* Get privilege(s) for a function */
2570int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2571 u32 domain)
2572{
2573 struct be_mcc_wrb *wrb;
2574 struct be_cmd_req_get_fn_privileges *req;
2575 int status;
2576
2577 spin_lock_bh(&adapter->mcc_lock);
2578
2579 wrb = wrb_from_mccq(adapter);
2580 if (!wrb) {
2581 status = -EBUSY;
2582 goto err;
2583 }
2584
2585 req = embedded_payload(wrb);
2586
2587 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2588 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2589 wrb, NULL);
2590
2591 req->hdr.domain = domain;
2592
2593 status = be_mcc_notify_wait(adapter);
2594 if (!status) {
2595 struct be_cmd_resp_get_fn_privileges *resp =
2596 embedded_payload(wrb);
2597 *privilege = le32_to_cpu(resp->privilege_mask);
2598 }
2599
2600err:
2601 spin_unlock_bh(&adapter->mcc_lock);
2602 return status;
2603}
2604
Sathya Perla04a06022013-07-23 15:25:00 +05302605/* Set privilege(s) for a function */
2606int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
2607 u32 domain)
2608{
2609 struct be_mcc_wrb *wrb;
2610 struct be_cmd_req_set_fn_privileges *req;
2611 int status;
2612
2613 spin_lock_bh(&adapter->mcc_lock);
2614
2615 wrb = wrb_from_mccq(adapter);
2616 if (!wrb) {
2617 status = -EBUSY;
2618 goto err;
2619 }
2620
2621 req = embedded_payload(wrb);
2622 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2623 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
2624 wrb, NULL);
2625 req->hdr.domain = domain;
2626 if (lancer_chip(adapter))
2627 req->privileges_lancer = cpu_to_le32(privileges);
2628 else
2629 req->privileges = cpu_to_le32(privileges);
2630
2631 status = be_mcc_notify_wait(adapter);
2632err:
2633 spin_unlock_bh(&adapter->mcc_lock);
2634 return status;
2635}
2636
Sathya Perla5a712c12013-07-23 15:24:59 +05302637/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
2638 * pmac_id_valid: false => pmac_id or MAC address is requested.
2639 * If pmac_id is returned, pmac_id_valid is returned as true
2640 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002641int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Sathya Perla5a712c12013-07-23 15:24:59 +05302642 bool *pmac_id_valid, u32 *pmac_id, u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002643{
2644 struct be_mcc_wrb *wrb;
2645 struct be_cmd_req_get_mac_list *req;
2646 int status;
2647 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002648 struct be_dma_mem get_mac_list_cmd;
2649 int i;
2650
2651 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2652 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2653 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2654 get_mac_list_cmd.size,
2655 &get_mac_list_cmd.dma);
2656
2657 if (!get_mac_list_cmd.va) {
2658 dev_err(&adapter->pdev->dev,
2659 "Memory allocation failure during GET_MAC_LIST\n");
2660 return -ENOMEM;
2661 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002662
2663 spin_lock_bh(&adapter->mcc_lock);
2664
2665 wrb = wrb_from_mccq(adapter);
2666 if (!wrb) {
2667 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002668 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002669 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002670
2671 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002672
2673 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00002674 OPCODE_COMMON_GET_MAC_LIST,
2675 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002676 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002677 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05302678 if (*pmac_id_valid) {
2679 req->mac_id = cpu_to_le32(*pmac_id);
2680 req->iface_id = cpu_to_le16(adapter->if_handle);
2681 req->perm_override = 0;
2682 } else {
2683 req->perm_override = 1;
2684 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002685
2686 status = be_mcc_notify_wait(adapter);
2687 if (!status) {
2688 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002689 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05302690
2691 if (*pmac_id_valid) {
2692 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
2693 ETH_ALEN);
2694 goto out;
2695 }
2696
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002697 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2698 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002699 * or one or more true or pseudo permanant mac addresses.
2700 * If an active mac_id is present, return first active mac_id
2701 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002702 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002703 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002704 struct get_list_macaddr *mac_entry;
2705 u16 mac_addr_size;
2706 u32 mac_id;
2707
2708 mac_entry = &resp->macaddr_list[i];
2709 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2710 /* mac_id is a 32 bit value and mac_addr size
2711 * is 6 bytes
2712 */
2713 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05302714 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002715 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2716 *pmac_id = le32_to_cpu(mac_id);
2717 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002718 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002719 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002720 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05302721 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002722 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2723 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002724 }
2725
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002726out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002727 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002728 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2729 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002730 return status;
2731}
2732
Sathya Perla5a712c12013-07-23 15:24:59 +05302733int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id, u8 *mac)
2734{
Sathya Perla5a712c12013-07-23 15:24:59 +05302735 bool active = true;
2736
Sathya Perla3175d8c2013-07-23 15:25:03 +05302737 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05302738 return be_cmd_mac_addr_query(adapter, mac, false,
2739 adapter->if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05302740 else
2741 /* Fetch the MAC address using pmac_id */
2742 return be_cmd_get_mac_from_list(adapter, mac, &active,
2743 &curr_pmac_id, 0);
Sathya Perla5a712c12013-07-23 15:24:59 +05302744}
2745
Sathya Perla95046b92013-07-23 15:25:02 +05302746int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
2747{
2748 int status;
2749 bool pmac_valid = false;
2750
2751 memset(mac, 0, ETH_ALEN);
2752
Sathya Perla3175d8c2013-07-23 15:25:03 +05302753 if (BEx_chip(adapter)) {
2754 if (be_physfn(adapter))
2755 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
2756 0);
2757 else
2758 status = be_cmd_mac_addr_query(adapter, mac, false,
2759 adapter->if_handle, 0);
2760 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05302761 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
2762 NULL, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05302763 }
2764
Sathya Perla95046b92013-07-23 15:25:02 +05302765 return status;
2766}
2767
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002768/* Uses synchronous MCCQ */
2769int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2770 u8 mac_count, u32 domain)
2771{
2772 struct be_mcc_wrb *wrb;
2773 struct be_cmd_req_set_mac_list *req;
2774 int status;
2775 struct be_dma_mem cmd;
2776
2777 memset(&cmd, 0, sizeof(struct be_dma_mem));
2778 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2779 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2780 &cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00002781 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002782 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002783
2784 spin_lock_bh(&adapter->mcc_lock);
2785
2786 wrb = wrb_from_mccq(adapter);
2787 if (!wrb) {
2788 status = -EBUSY;
2789 goto err;
2790 }
2791
2792 req = cmd.va;
2793 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2794 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2795 wrb, &cmd);
2796
2797 req->hdr.domain = domain;
2798 req->mac_count = mac_count;
2799 if (mac_count)
2800 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2801
2802 status = be_mcc_notify_wait(adapter);
2803
2804err:
2805 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2806 cmd.va, cmd.dma);
2807 spin_unlock_bh(&adapter->mcc_lock);
2808 return status;
2809}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002810
Sathya Perla3175d8c2013-07-23 15:25:03 +05302811/* Wrapper to delete any active MACs and provision the new mac.
2812 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
2813 * current list are active.
2814 */
2815int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
2816{
2817 bool active_mac = false;
2818 u8 old_mac[ETH_ALEN];
2819 u32 pmac_id;
2820 int status;
2821
2822 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
2823 &pmac_id, dom);
2824 if (!status && active_mac)
2825 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
2826
2827 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
2828}
2829
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002830int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
2831 u32 domain, u16 intf_id)
2832{
2833 struct be_mcc_wrb *wrb;
2834 struct be_cmd_req_set_hsw_config *req;
2835 void *ctxt;
2836 int status;
2837
2838 spin_lock_bh(&adapter->mcc_lock);
2839
2840 wrb = wrb_from_mccq(adapter);
2841 if (!wrb) {
2842 status = -EBUSY;
2843 goto err;
2844 }
2845
2846 req = embedded_payload(wrb);
2847 ctxt = &req->context;
2848
2849 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2850 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2851
2852 req->hdr.domain = domain;
2853 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2854 if (pvid) {
2855 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2856 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2857 }
2858
2859 be_dws_cpu_to_le(req->context, sizeof(req->context));
2860 status = be_mcc_notify_wait(adapter);
2861
2862err:
2863 spin_unlock_bh(&adapter->mcc_lock);
2864 return status;
2865}
2866
2867/* Get Hyper switch config */
2868int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
2869 u32 domain, u16 intf_id)
2870{
2871 struct be_mcc_wrb *wrb;
2872 struct be_cmd_req_get_hsw_config *req;
2873 void *ctxt;
2874 int status;
2875 u16 vid;
2876
2877 spin_lock_bh(&adapter->mcc_lock);
2878
2879 wrb = wrb_from_mccq(adapter);
2880 if (!wrb) {
2881 status = -EBUSY;
2882 goto err;
2883 }
2884
2885 req = embedded_payload(wrb);
2886 ctxt = &req->context;
2887
2888 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2889 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2890
2891 req->hdr.domain = domain;
2892 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, ctxt,
2893 intf_id);
2894 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
2895 be_dws_cpu_to_le(req->context, sizeof(req->context));
2896
2897 status = be_mcc_notify_wait(adapter);
2898 if (!status) {
2899 struct be_cmd_resp_get_hsw_config *resp =
2900 embedded_payload(wrb);
2901 be_dws_le_to_cpu(&resp->context,
2902 sizeof(resp->context));
2903 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2904 pvid, &resp->context);
2905 *pvid = le16_to_cpu(vid);
2906 }
2907
2908err:
2909 spin_unlock_bh(&adapter->mcc_lock);
2910 return status;
2911}
2912
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002913int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2914{
2915 struct be_mcc_wrb *wrb;
2916 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2917 int status;
2918 int payload_len = sizeof(*req);
2919 struct be_dma_mem cmd;
2920
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002921 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2922 CMD_SUBSYSTEM_ETH))
2923 return -EPERM;
2924
Suresh Reddyd98ef502013-04-25 00:56:55 +00002925 if (mutex_lock_interruptible(&adapter->mbox_lock))
2926 return -1;
2927
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002928 memset(&cmd, 0, sizeof(struct be_dma_mem));
2929 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2930 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2931 &cmd.dma);
2932 if (!cmd.va) {
2933 dev_err(&adapter->pdev->dev,
2934 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002935 status = -ENOMEM;
2936 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002937 }
2938
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002939 wrb = wrb_from_mbox(adapter);
2940 if (!wrb) {
2941 status = -EBUSY;
2942 goto err;
2943 }
2944
2945 req = cmd.va;
2946
2947 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2948 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2949 payload_len, wrb, &cmd);
2950
2951 req->hdr.version = 1;
2952 req->query_options = BE_GET_WOL_CAP;
2953
2954 status = be_mbox_notify_wait(adapter);
2955 if (!status) {
2956 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
2957 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
2958
2959 /* the command could succeed misleadingly on old f/w
2960 * which is not aware of the V1 version. fake an error. */
2961 if (resp->hdr.response_length < payload_len) {
2962 status = -1;
2963 goto err;
2964 }
2965 adapter->wol_cap = resp->wol_settings;
2966 }
2967err:
2968 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002969 if (cmd.va)
2970 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002971 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00002972
2973}
2974int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
2975 struct be_dma_mem *cmd)
2976{
2977 struct be_mcc_wrb *wrb;
2978 struct be_cmd_req_get_ext_fat_caps *req;
2979 int status;
2980
2981 if (mutex_lock_interruptible(&adapter->mbox_lock))
2982 return -1;
2983
2984 wrb = wrb_from_mbox(adapter);
2985 if (!wrb) {
2986 status = -EBUSY;
2987 goto err;
2988 }
2989
2990 req = cmd->va;
2991 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2992 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
2993 cmd->size, wrb, cmd);
2994 req->parameter_type = cpu_to_le32(1);
2995
2996 status = be_mbox_notify_wait(adapter);
2997err:
2998 mutex_unlock(&adapter->mbox_lock);
2999 return status;
3000}
3001
3002int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
3003 struct be_dma_mem *cmd,
3004 struct be_fat_conf_params *configs)
3005{
3006 struct be_mcc_wrb *wrb;
3007 struct be_cmd_req_set_ext_fat_caps *req;
3008 int status;
3009
3010 spin_lock_bh(&adapter->mcc_lock);
3011
3012 wrb = wrb_from_mccq(adapter);
3013 if (!wrb) {
3014 status = -EBUSY;
3015 goto err;
3016 }
3017
3018 req = cmd->va;
3019 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
3020 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3021 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
3022 cmd->size, wrb, cmd);
3023
3024 status = be_mcc_notify_wait(adapter);
3025err:
3026 spin_unlock_bh(&adapter->mcc_lock);
3027 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003028}
Parav Pandit6a4ab662012-03-26 14:27:12 +00003029
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003030int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
3031{
3032 struct be_mcc_wrb *wrb;
3033 struct be_cmd_req_get_port_name *req;
3034 int status;
3035
3036 if (!lancer_chip(adapter)) {
3037 *port_name = adapter->hba_port_num + '0';
3038 return 0;
3039 }
3040
3041 spin_lock_bh(&adapter->mcc_lock);
3042
3043 wrb = wrb_from_mccq(adapter);
3044 if (!wrb) {
3045 status = -EBUSY;
3046 goto err;
3047 }
3048
3049 req = embedded_payload(wrb);
3050
3051 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3052 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
3053 NULL);
3054 req->hdr.version = 1;
3055
3056 status = be_mcc_notify_wait(adapter);
3057 if (!status) {
3058 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
3059 *port_name = resp->port_name[adapter->hba_port_num];
3060 } else {
3061 *port_name = adapter->hba_port_num + '0';
3062 }
3063err:
3064 spin_unlock_bh(&adapter->mcc_lock);
3065 return status;
3066}
3067
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303068static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003069{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303070 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003071 int i;
3072
3073 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303074 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
3075 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1)
3076 return (struct be_nic_res_desc *)hdr;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003077
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303078 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3079 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003080 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303081 return NULL;
3082}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003083
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303084static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3085 u32 desc_count)
3086{
3087 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3088 struct be_pcie_res_desc *pcie;
3089 int i;
3090
3091 for (i = 0; i < desc_count; i++) {
3092 if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
3093 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) {
3094 pcie = (struct be_pcie_res_desc *)hdr;
3095 if (pcie->pf_num == devfn)
3096 return pcie;
3097 }
3098
3099 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3100 hdr = (void *)hdr + hdr->desc_len;
3101 }
Wei Yang950e2952013-05-22 15:58:22 +00003102 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003103}
3104
Sathya Perla92bf14a2013-08-27 16:57:32 +05303105static void be_copy_nic_desc(struct be_resources *res,
3106 struct be_nic_res_desc *desc)
3107{
3108 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3109 res->max_vlans = le16_to_cpu(desc->vlan_count);
3110 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3111 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3112 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3113 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3114 res->max_evt_qs = le16_to_cpu(desc->eq_count);
3115 /* Clear flags that driver is not interested in */
3116 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3117 BE_IF_CAP_FLAGS_WANT;
3118 /* Need 1 RXQ as the default RXQ */
3119 if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs)
3120 res->max_rss_qs -= 1;
3121}
3122
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003123/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303124int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003125{
3126 struct be_mcc_wrb *wrb;
3127 struct be_cmd_req_get_func_config *req;
3128 int status;
3129 struct be_dma_mem cmd;
3130
Suresh Reddyd98ef502013-04-25 00:56:55 +00003131 if (mutex_lock_interruptible(&adapter->mbox_lock))
3132 return -1;
3133
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003134 memset(&cmd, 0, sizeof(struct be_dma_mem));
3135 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
3136 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3137 &cmd.dma);
3138 if (!cmd.va) {
3139 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003140 status = -ENOMEM;
3141 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003142 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003143
3144 wrb = wrb_from_mbox(adapter);
3145 if (!wrb) {
3146 status = -EBUSY;
3147 goto err;
3148 }
3149
3150 req = cmd.va;
3151
3152 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3153 OPCODE_COMMON_GET_FUNC_CONFIG,
3154 cmd.size, wrb, &cmd);
3155
Kalesh AP28710c52013-04-28 22:21:13 +00003156 if (skyhawk_chip(adapter))
3157 req->hdr.version = 1;
3158
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003159 status = be_mbox_notify_wait(adapter);
3160 if (!status) {
3161 struct be_cmd_resp_get_func_config *resp = cmd.va;
3162 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303163 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003164
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303165 desc = be_get_nic_desc(resp->func_param, desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003166 if (!desc) {
3167 status = -EINVAL;
3168 goto err;
3169 }
3170
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003171 adapter->pf_number = desc->pf_num;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303172 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003173 }
3174err:
3175 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003176 if (cmd.va)
3177 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003178 return status;
3179}
3180
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003181/* Uses mbox */
Jingoo Han4188e7d2013-08-05 18:02:02 +09003182static int be_cmd_get_profile_config_mbox(struct be_adapter *adapter,
3183 u8 domain, struct be_dma_mem *cmd)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003184{
3185 struct be_mcc_wrb *wrb;
3186 struct be_cmd_req_get_profile_config *req;
3187 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003188
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003189 if (mutex_lock_interruptible(&adapter->mbox_lock))
3190 return -1;
3191 wrb = wrb_from_mbox(adapter);
3192
3193 req = cmd->va;
3194 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3195 OPCODE_COMMON_GET_PROFILE_CONFIG,
3196 cmd->size, wrb, cmd);
3197
3198 req->type = ACTIVE_PROFILE_TYPE;
3199 req->hdr.domain = domain;
3200 if (!lancer_chip(adapter))
3201 req->hdr.version = 1;
3202
3203 status = be_mbox_notify_wait(adapter);
3204
3205 mutex_unlock(&adapter->mbox_lock);
3206 return status;
3207}
3208
3209/* Uses sync mcc */
Jingoo Han4188e7d2013-08-05 18:02:02 +09003210static int be_cmd_get_profile_config_mccq(struct be_adapter *adapter,
3211 u8 domain, struct be_dma_mem *cmd)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003212{
3213 struct be_mcc_wrb *wrb;
3214 struct be_cmd_req_get_profile_config *req;
3215 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003216
3217 spin_lock_bh(&adapter->mcc_lock);
3218
3219 wrb = wrb_from_mccq(adapter);
3220 if (!wrb) {
3221 status = -EBUSY;
3222 goto err;
3223 }
3224
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003225 req = cmd->va;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003226 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3227 OPCODE_COMMON_GET_PROFILE_CONFIG,
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003228 cmd->size, wrb, cmd);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003229
3230 req->type = ACTIVE_PROFILE_TYPE;
3231 req->hdr.domain = domain;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003232 if (!lancer_chip(adapter))
3233 req->hdr.version = 1;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003234
3235 status = be_mcc_notify_wait(adapter);
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003236
3237err:
3238 spin_unlock_bh(&adapter->mcc_lock);
3239 return status;
3240}
3241
3242/* Uses sync mcc, if MCCQ is already created otherwise mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303243int be_cmd_get_profile_config(struct be_adapter *adapter,
3244 struct be_resources *res, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003245{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303246 struct be_cmd_resp_get_profile_config *resp;
3247 struct be_pcie_res_desc *pcie;
3248 struct be_nic_res_desc *nic;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003249 struct be_queue_info *mccq = &adapter->mcc_obj.q;
3250 struct be_dma_mem cmd;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303251 u32 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003252 int status;
3253
3254 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303255 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3256 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3257 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003258 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003259
3260 if (!mccq->created)
3261 status = be_cmd_get_profile_config_mbox(adapter, domain, &cmd);
3262 else
3263 status = be_cmd_get_profile_config_mccq(adapter, domain, &cmd);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303264 if (status)
3265 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003266
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303267 resp = cmd.va;
3268 desc_count = le32_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003269
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303270 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3271 desc_count);
3272 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303273 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303274
3275 nic = be_get_nic_desc(resp->func_param, desc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303276 if (nic)
3277 be_copy_nic_desc(res, nic);
3278
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003279err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003280 if (cmd.va)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303281 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003282 return status;
3283}
3284
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303285/* Currently only Lancer uses this command and it supports version 0 only
3286 * Uses sync mcc
3287 */
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003288int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
3289 u8 domain)
3290{
3291 struct be_mcc_wrb *wrb;
3292 struct be_cmd_req_set_profile_config *req;
3293 int status;
3294
3295 spin_lock_bh(&adapter->mcc_lock);
3296
3297 wrb = wrb_from_mccq(adapter);
3298 if (!wrb) {
3299 status = -EBUSY;
3300 goto err;
3301 }
3302
3303 req = embedded_payload(wrb);
3304
3305 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3306 OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req),
3307 wrb, NULL);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003308 req->hdr.domain = domain;
3309 req->desc_count = cpu_to_le32(1);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303310 req->nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
3311 req->nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003312 req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV);
3313 req->nic_desc.pf_num = adapter->pf_number;
3314 req->nic_desc.vf_num = domain;
3315
3316 /* Mark fields invalid */
3317 req->nic_desc.unicast_mac_count = 0xFFFF;
3318 req->nic_desc.mcc_count = 0xFFFF;
3319 req->nic_desc.vlan_count = 0xFFFF;
3320 req->nic_desc.mcast_mac_count = 0xFFFF;
3321 req->nic_desc.txq_count = 0xFFFF;
3322 req->nic_desc.rq_count = 0xFFFF;
3323 req->nic_desc.rssq_count = 0xFFFF;
3324 req->nic_desc.lro_count = 0xFFFF;
3325 req->nic_desc.cq_count = 0xFFFF;
3326 req->nic_desc.toe_conn_count = 0xFFFF;
3327 req->nic_desc.eq_count = 0xFFFF;
3328 req->nic_desc.link_param = 0xFF;
3329 req->nic_desc.bw_min = 0xFFFFFFFF;
3330 req->nic_desc.acpi_params = 0xFF;
3331 req->nic_desc.wol_param = 0x0F;
3332
3333 /* Change BW */
3334 req->nic_desc.bw_min = cpu_to_le32(bps);
3335 req->nic_desc.bw_max = cpu_to_le32(bps);
3336 status = be_mcc_notify_wait(adapter);
3337err:
3338 spin_unlock_bh(&adapter->mcc_lock);
3339 return status;
3340}
3341
Sathya Perla4c876612013-02-03 20:30:11 +00003342int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3343 int vf_num)
3344{
3345 struct be_mcc_wrb *wrb;
3346 struct be_cmd_req_get_iface_list *req;
3347 struct be_cmd_resp_get_iface_list *resp;
3348 int status;
3349
3350 spin_lock_bh(&adapter->mcc_lock);
3351
3352 wrb = wrb_from_mccq(adapter);
3353 if (!wrb) {
3354 status = -EBUSY;
3355 goto err;
3356 }
3357 req = embedded_payload(wrb);
3358
3359 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3360 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3361 wrb, NULL);
3362 req->hdr.domain = vf_num + 1;
3363
3364 status = be_mcc_notify_wait(adapter);
3365 if (!status) {
3366 resp = (struct be_cmd_resp_get_iface_list *)req;
3367 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3368 }
3369
3370err:
3371 spin_unlock_bh(&adapter->mcc_lock);
3372 return status;
3373}
3374
Somnath Kotur5c510812013-05-30 02:52:23 +00003375static int lancer_wait_idle(struct be_adapter *adapter)
3376{
3377#define SLIPORT_IDLE_TIMEOUT 30
3378 u32 reg_val;
3379 int status = 0, i;
3380
3381 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
3382 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
3383 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
3384 break;
3385
3386 ssleep(1);
3387 }
3388
3389 if (i == SLIPORT_IDLE_TIMEOUT)
3390 status = -1;
3391
3392 return status;
3393}
3394
3395int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
3396{
3397 int status = 0;
3398
3399 status = lancer_wait_idle(adapter);
3400 if (status)
3401 return status;
3402
3403 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
3404
3405 return status;
3406}
3407
3408/* Routine to check whether dump image is present or not */
3409bool dump_present(struct be_adapter *adapter)
3410{
3411 u32 sliport_status = 0;
3412
3413 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
3414 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
3415}
3416
3417int lancer_initiate_dump(struct be_adapter *adapter)
3418{
3419 int status;
3420
3421 /* give firmware reset and diagnostic dump */
3422 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
3423 PHYSDEV_CONTROL_DD_MASK);
3424 if (status < 0) {
3425 dev_err(&adapter->pdev->dev, "Firmware reset failed\n");
3426 return status;
3427 }
3428
3429 status = lancer_wait_idle(adapter);
3430 if (status)
3431 return status;
3432
3433 if (!dump_present(adapter)) {
3434 dev_err(&adapter->pdev->dev, "Dump image not present\n");
3435 return -1;
3436 }
3437
3438 return 0;
3439}
3440
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003441/* Uses sync mcc */
3442int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
3443{
3444 struct be_mcc_wrb *wrb;
3445 struct be_cmd_enable_disable_vf *req;
3446 int status;
3447
3448 if (!lancer_chip(adapter))
3449 return 0;
3450
3451 spin_lock_bh(&adapter->mcc_lock);
3452
3453 wrb = wrb_from_mccq(adapter);
3454 if (!wrb) {
3455 status = -EBUSY;
3456 goto err;
3457 }
3458
3459 req = embedded_payload(wrb);
3460
3461 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3462 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
3463 wrb, NULL);
3464
3465 req->hdr.domain = domain;
3466 req->enable = 1;
3467 status = be_mcc_notify_wait(adapter);
3468err:
3469 spin_unlock_bh(&adapter->mcc_lock);
3470 return status;
3471}
3472
Somnath Kotur68c45a22013-03-14 02:42:07 +00003473int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
3474{
3475 struct be_mcc_wrb *wrb;
3476 struct be_cmd_req_intr_set *req;
3477 int status;
3478
3479 if (mutex_lock_interruptible(&adapter->mbox_lock))
3480 return -1;
3481
3482 wrb = wrb_from_mbox(adapter);
3483
3484 req = embedded_payload(wrb);
3485
3486 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3487 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
3488 wrb, NULL);
3489
3490 req->intr_enabled = intr_enable;
3491
3492 status = be_mbox_notify_wait(adapter);
3493
3494 mutex_unlock(&adapter->mbox_lock);
3495 return status;
3496}
3497
Parav Pandit6a4ab662012-03-26 14:27:12 +00003498int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
3499 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
3500{
3501 struct be_adapter *adapter = netdev_priv(netdev_handle);
3502 struct be_mcc_wrb *wrb;
3503 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
3504 struct be_cmd_req_hdr *req;
3505 struct be_cmd_resp_hdr *resp;
3506 int status;
3507
3508 spin_lock_bh(&adapter->mcc_lock);
3509
3510 wrb = wrb_from_mccq(adapter);
3511 if (!wrb) {
3512 status = -EBUSY;
3513 goto err;
3514 }
3515 req = embedded_payload(wrb);
3516 resp = embedded_payload(wrb);
3517
3518 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
3519 hdr->opcode, wrb_payload_size, wrb, NULL);
3520 memcpy(req, wrb_payload, wrb_payload_size);
3521 be_dws_cpu_to_le(req, wrb_payload_size);
3522
3523 status = be_mcc_notify_wait(adapter);
3524 if (cmd_status)
3525 *cmd_status = (status & 0xffff);
3526 if (ext_status)
3527 *ext_status = 0;
3528 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
3529 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
3530err:
3531 spin_unlock_bh(&adapter->mcc_lock);
3532 return status;
3533}
3534EXPORT_SYMBOL(be_roce_mcc_cmd);