blob: 1ab5dab11eff07ab349a0cc795ef5986fe1e9010 [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 Perlabea50982013-08-27 16:57:33 +0530636static inline void fill_wrb_tags(struct be_mcc_wrb *wrb,
637 unsigned long addr)
638{
639 wrb->tag0 = addr & 0xFFFFFFFF;
640 wrb->tag1 = upper_32_bits(addr);
641}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700642
643/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000644/* mem will be NULL for embedded commands */
645static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
646 u8 subsystem, u8 opcode, int cmd_len,
647 struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700648{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000649 struct be_sge *sge;
650
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700651 req_hdr->opcode = opcode;
652 req_hdr->subsystem = subsystem;
653 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000654 req_hdr->version = 0;
Sathya Perlabea50982013-08-27 16:57:33 +0530655 fill_wrb_tags(wrb, (ulong) req_hdr);
Somnath Kotur106df1e2011-10-27 07:12:13 +0000656 wrb->payload_length = cmd_len;
657 if (mem) {
658 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
659 MCC_WRB_SGE_CNT_SHIFT;
660 sge = nonembedded_sgl(wrb);
661 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
662 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
663 sge->len = cpu_to_le32(mem->size);
664 } else
665 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
666 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700667}
668
669static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
670 struct be_dma_mem *mem)
671{
672 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
673 u64 dma = (u64)mem->dma;
674
675 for (i = 0; i < buf_pages; i++) {
676 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
677 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
678 dma += PAGE_SIZE_4K;
679 }
680}
681
Sathya Perlab31c50a2009-09-17 10:30:13 -0700682static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700683{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700684 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
685 struct be_mcc_wrb *wrb
686 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
687 memset(wrb, 0, sizeof(*wrb));
688 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700689}
690
Sathya Perlab31c50a2009-09-17 10:30:13 -0700691static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000692{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700693 struct be_queue_info *mccq = &adapter->mcc_obj.q;
694 struct be_mcc_wrb *wrb;
695
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000696 if (!mccq->created)
697 return NULL;
698
Vasundhara Volam4d277122013-04-21 23:28:15 +0000699 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000700 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000701
Sathya Perlab31c50a2009-09-17 10:30:13 -0700702 wrb = queue_head_node(mccq);
703 queue_head_inc(mccq);
704 atomic_inc(&mccq->used);
705 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000706 return wrb;
707}
708
Sathya Perlabea50982013-08-27 16:57:33 +0530709static bool use_mcc(struct be_adapter *adapter)
710{
711 return adapter->mcc_obj.q.created;
712}
713
714/* Must be used only in process context */
715static int be_cmd_lock(struct be_adapter *adapter)
716{
717 if (use_mcc(adapter)) {
718 spin_lock_bh(&adapter->mcc_lock);
719 return 0;
720 } else {
721 return mutex_lock_interruptible(&adapter->mbox_lock);
722 }
723}
724
725/* Must be used only in process context */
726static void be_cmd_unlock(struct be_adapter *adapter)
727{
728 if (use_mcc(adapter))
729 spin_unlock_bh(&adapter->mcc_lock);
730 else
731 return mutex_unlock(&adapter->mbox_lock);
732}
733
734static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter,
735 struct be_mcc_wrb *wrb)
736{
737 struct be_mcc_wrb *dest_wrb;
738
739 if (use_mcc(adapter)) {
740 dest_wrb = wrb_from_mccq(adapter);
741 if (!dest_wrb)
742 return NULL;
743 } else {
744 dest_wrb = wrb_from_mbox(adapter);
745 }
746
747 memcpy(dest_wrb, wrb, sizeof(*wrb));
748 if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK))
749 fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb));
750
751 return dest_wrb;
752}
753
754/* Must be used only in process context */
755static int be_cmd_notify_wait(struct be_adapter *adapter,
756 struct be_mcc_wrb *wrb)
757{
758 struct be_mcc_wrb *dest_wrb;
759 int status;
760
761 status = be_cmd_lock(adapter);
762 if (status)
763 return status;
764
765 dest_wrb = be_cmd_copy(adapter, wrb);
766 if (!dest_wrb)
767 return -EBUSY;
768
769 if (use_mcc(adapter))
770 status = be_mcc_notify_wait(adapter);
771 else
772 status = be_mbox_notify_wait(adapter);
773
774 if (!status)
775 memcpy(wrb, dest_wrb, sizeof(*wrb));
776
777 be_cmd_unlock(adapter);
778 return status;
779}
780
Sathya Perla2243e2e2009-11-22 22:02:03 +0000781/* Tell fw we're about to start firing cmds by writing a
782 * special pattern across the wrb hdr; uses mbox
783 */
784int be_cmd_fw_init(struct be_adapter *adapter)
785{
786 u8 *wrb;
787 int status;
788
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000789 if (lancer_chip(adapter))
790 return 0;
791
Ivan Vecera29849612010-12-14 05:43:19 +0000792 if (mutex_lock_interruptible(&adapter->mbox_lock))
793 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000794
795 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000796 *wrb++ = 0xFF;
797 *wrb++ = 0x12;
798 *wrb++ = 0x34;
799 *wrb++ = 0xFF;
800 *wrb++ = 0xFF;
801 *wrb++ = 0x56;
802 *wrb++ = 0x78;
803 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000804
805 status = be_mbox_notify_wait(adapter);
806
Ivan Vecera29849612010-12-14 05:43:19 +0000807 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000808 return status;
809}
810
811/* Tell fw we're done with firing cmds by writing a
812 * special pattern across the wrb hdr; uses mbox
813 */
814int be_cmd_fw_clean(struct be_adapter *adapter)
815{
816 u8 *wrb;
817 int status;
818
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000819 if (lancer_chip(adapter))
820 return 0;
821
Ivan Vecera29849612010-12-14 05:43:19 +0000822 if (mutex_lock_interruptible(&adapter->mbox_lock))
823 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000824
825 wrb = (u8 *)wrb_from_mbox(adapter);
826 *wrb++ = 0xFF;
827 *wrb++ = 0xAA;
828 *wrb++ = 0xBB;
829 *wrb++ = 0xFF;
830 *wrb++ = 0xFF;
831 *wrb++ = 0xCC;
832 *wrb++ = 0xDD;
833 *wrb = 0xFF;
834
835 status = be_mbox_notify_wait(adapter);
836
Ivan Vecera29849612010-12-14 05:43:19 +0000837 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000838 return status;
839}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000840
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530841int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700842{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700843 struct be_mcc_wrb *wrb;
844 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530845 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
846 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700847
Ivan Vecera29849612010-12-14 05:43:19 +0000848 if (mutex_lock_interruptible(&adapter->mbox_lock))
849 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700850
851 wrb = wrb_from_mbox(adapter);
852 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700853
Somnath Kotur106df1e2011-10-27 07:12:13 +0000854 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
855 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700856
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530857 /* Support for EQ_CREATEv2 available only SH-R onwards */
858 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
859 ver = 2;
860
861 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700862 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
863
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700864 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
865 /* 4byte eqe*/
866 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
867 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530868 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700869 be_dws_cpu_to_le(req->context, sizeof(req->context));
870
871 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
872
Sathya Perlab31c50a2009-09-17 10:30:13 -0700873 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700874 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700875 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530876 eqo->q.id = le16_to_cpu(resp->eq_id);
877 eqo->msix_idx =
878 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
879 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700880 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700881
Ivan Vecera29849612010-12-14 05:43:19 +0000882 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700883 return status;
884}
885
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000886/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000887int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000888 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700889{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700890 struct be_mcc_wrb *wrb;
891 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700892 int status;
893
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000894 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700895
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000896 wrb = wrb_from_mccq(adapter);
897 if (!wrb) {
898 status = -EBUSY;
899 goto err;
900 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700901 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700902
Somnath Kotur106df1e2011-10-27 07:12:13 +0000903 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
904 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000905 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700906 if (permanent) {
907 req->permanent = 1;
908 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700909 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000910 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700911 req->permanent = 0;
912 }
913
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000914 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700915 if (!status) {
916 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700917 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700918 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700919
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000920err:
921 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700922 return status;
923}
924
Sathya Perlab31c50a2009-09-17 10:30:13 -0700925/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000926int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000927 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700928{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700929 struct be_mcc_wrb *wrb;
930 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700931 int status;
932
Sathya Perlab31c50a2009-09-17 10:30:13 -0700933 spin_lock_bh(&adapter->mcc_lock);
934
935 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000936 if (!wrb) {
937 status = -EBUSY;
938 goto err;
939 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700940 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700941
Somnath Kotur106df1e2011-10-27 07:12:13 +0000942 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
943 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700944
Ajit Khapardef8617e02011-02-11 13:36:37 +0000945 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700946 req->if_id = cpu_to_le32(if_id);
947 memcpy(req->mac_address, mac_addr, ETH_ALEN);
948
Sathya Perlab31c50a2009-09-17 10:30:13 -0700949 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700950 if (!status) {
951 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
952 *pmac_id = le32_to_cpu(resp->pmac_id);
953 }
954
Sathya Perla713d03942009-11-22 22:02:45 +0000955err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700956 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000957
958 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
959 status = -EPERM;
960
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700961 return status;
962}
963
Sathya Perlab31c50a2009-09-17 10:30:13 -0700964/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000965int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700966{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700967 struct be_mcc_wrb *wrb;
968 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700969 int status;
970
Sathya Perla30128032011-11-10 19:17:57 +0000971 if (pmac_id == -1)
972 return 0;
973
Sathya Perlab31c50a2009-09-17 10:30:13 -0700974 spin_lock_bh(&adapter->mcc_lock);
975
976 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000977 if (!wrb) {
978 status = -EBUSY;
979 goto err;
980 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700981 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700982
Somnath Kotur106df1e2011-10-27 07:12:13 +0000983 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
984 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700985
Ajit Khapardef8617e02011-02-11 13:36:37 +0000986 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700987 req->if_id = cpu_to_le32(if_id);
988 req->pmac_id = cpu_to_le32(pmac_id);
989
Sathya Perlab31c50a2009-09-17 10:30:13 -0700990 status = be_mcc_notify_wait(adapter);
991
Sathya Perla713d03942009-11-22 22:02:45 +0000992err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700993 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700994 return status;
995}
996
Sathya Perlab31c50a2009-09-17 10:30:13 -0700997/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000998int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
999 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001000{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001001 struct be_mcc_wrb *wrb;
1002 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001003 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001004 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001005 int status;
1006
Ivan Vecera29849612010-12-14 05:43:19 +00001007 if (mutex_lock_interruptible(&adapter->mbox_lock))
1008 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001009
1010 wrb = wrb_from_mbox(adapter);
1011 req = embedded_payload(wrb);
1012 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001013
Somnath Kotur106df1e2011-10-27 07:12:13 +00001014 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1015 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001016
1017 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001018
1019 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001020 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
1021 coalesce_wm);
1022 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
1023 ctxt, no_delay);
1024 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
1025 __ilog2_u32(cq->len/256));
1026 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001027 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
1028 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001029 } else {
1030 req->hdr.version = 2;
1031 req->page_size = 1; /* 1 for 4K */
1032 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
1033 no_delay);
1034 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
1035 __ilog2_u32(cq->len/256));
1036 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
1037 AMAP_SET_BITS(struct amap_cq_context_v2, eventable,
1038 ctxt, 1);
1039 AMAP_SET_BITS(struct amap_cq_context_v2, eqid,
1040 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001041 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001042
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001043 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1044
1045 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1046
Sathya Perlab31c50a2009-09-17 10:30:13 -07001047 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001048 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001049 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001050 cq->id = le16_to_cpu(resp->cq_id);
1051 cq->created = true;
1052 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001053
Ivan Vecera29849612010-12-14 05:43:19 +00001054 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001055
1056 return status;
1057}
1058
1059static u32 be_encoded_q_len(int q_len)
1060{
1061 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
1062 if (len_encoded == 16)
1063 len_encoded = 0;
1064 return len_encoded;
1065}
1066
Jingoo Han4188e7d2013-08-05 18:02:02 +09001067static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
1068 struct be_queue_info *mccq,
1069 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001070{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001071 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001072 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001073 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001074 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001075 int status;
1076
Ivan Vecera29849612010-12-14 05:43:19 +00001077 if (mutex_lock_interruptible(&adapter->mbox_lock))
1078 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001079
1080 wrb = wrb_from_mbox(adapter);
1081 req = embedded_payload(wrb);
1082 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001083
Somnath Kotur106df1e2011-10-27 07:12:13 +00001084 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1085 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001086
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001087 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001088 if (lancer_chip(adapter)) {
1089 req->hdr.version = 1;
1090 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001091
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001092 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
1093 be_encoded_q_len(mccq->len));
1094 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
1095 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
1096 ctxt, cq->id);
1097 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
1098 ctxt, 1);
1099
1100 } else {
1101 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1102 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1103 be_encoded_q_len(mccq->len));
1104 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1105 }
1106
Somnath Koturcc4ce022010-10-21 07:11:14 -07001107 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001108 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Ajit Khapardebc0c3402013-04-24 11:52:50 +00001109 req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001110 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1111
1112 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1113
Sathya Perlab31c50a2009-09-17 10:30:13 -07001114 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001115 if (!status) {
1116 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1117 mccq->id = le16_to_cpu(resp->id);
1118 mccq->created = true;
1119 }
Ivan Vecera29849612010-12-14 05:43:19 +00001120 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001121
1122 return status;
1123}
1124
Jingoo Han4188e7d2013-08-05 18:02:02 +09001125static int be_cmd_mccq_org_create(struct be_adapter *adapter,
1126 struct be_queue_info *mccq,
1127 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001128{
1129 struct be_mcc_wrb *wrb;
1130 struct be_cmd_req_mcc_create *req;
1131 struct be_dma_mem *q_mem = &mccq->dma_mem;
1132 void *ctxt;
1133 int status;
1134
1135 if (mutex_lock_interruptible(&adapter->mbox_lock))
1136 return -1;
1137
1138 wrb = wrb_from_mbox(adapter);
1139 req = embedded_payload(wrb);
1140 ctxt = &req->context;
1141
Somnath Kotur106df1e2011-10-27 07:12:13 +00001142 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1143 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001144
1145 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1146
1147 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1148 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1149 be_encoded_q_len(mccq->len));
1150 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1151
1152 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1153
1154 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1155
1156 status = be_mbox_notify_wait(adapter);
1157 if (!status) {
1158 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1159 mccq->id = le16_to_cpu(resp->id);
1160 mccq->created = true;
1161 }
1162
1163 mutex_unlock(&adapter->mbox_lock);
1164 return status;
1165}
1166
1167int be_cmd_mccq_create(struct be_adapter *adapter,
1168 struct be_queue_info *mccq,
1169 struct be_queue_info *cq)
1170{
1171 int status;
1172
1173 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
1174 if (status && !lancer_chip(adapter)) {
1175 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1176 "or newer to avoid conflicting priorities between NIC "
1177 "and FCoE traffic");
1178 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1179 }
1180 return status;
1181}
1182
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001183int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001184{
Sathya Perla77071332013-08-27 16:57:34 +05301185 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001186 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001187 struct be_queue_info *txq = &txo->q;
1188 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001189 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001190 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001191
Sathya Perla77071332013-08-27 16:57:34 +05301192 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001193 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perla77071332013-08-27 16:57:34 +05301194 OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001195
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001196 if (lancer_chip(adapter)) {
1197 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001198 req->if_id = cpu_to_le16(adapter->if_handle);
1199 } else if (BEx_chip(adapter)) {
1200 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1201 req->hdr.version = 2;
1202 } else { /* For SH */
1203 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001204 }
1205
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001206 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1207 req->ulp_num = BE_ULP1_NUM;
1208 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001209 req->cq_id = cpu_to_le16(cq->id);
1210 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001211 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001212 ver = req->hdr.version;
1213
Sathya Perla77071332013-08-27 16:57:34 +05301214 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001215 if (!status) {
Sathya Perla77071332013-08-27 16:57:34 +05301216 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001217 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001218 if (ver == 2)
1219 txo->db_offset = le32_to_cpu(resp->db_offset);
1220 else
1221 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001222 txq->created = true;
1223 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001224
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001225 return status;
1226}
1227
Sathya Perla482c9e72011-06-29 23:33:17 +00001228/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001229int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001230 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001231 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001232{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001233 struct be_mcc_wrb *wrb;
1234 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001235 struct be_dma_mem *q_mem = &rxq->dma_mem;
1236 int status;
1237
Sathya Perla482c9e72011-06-29 23:33:17 +00001238 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001239
Sathya Perla482c9e72011-06-29 23:33:17 +00001240 wrb = wrb_from_mccq(adapter);
1241 if (!wrb) {
1242 status = -EBUSY;
1243 goto err;
1244 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001245 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001246
Somnath Kotur106df1e2011-10-27 07:12:13 +00001247 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1248 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001249
1250 req->cq_id = cpu_to_le16(cq_id);
1251 req->frag_size = fls(frag_size) - 1;
1252 req->num_pages = 2;
1253 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1254 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001255 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001256 req->rss_queue = cpu_to_le32(rss);
1257
Sathya Perla482c9e72011-06-29 23:33:17 +00001258 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001259 if (!status) {
1260 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1261 rxq->id = le16_to_cpu(resp->id);
1262 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001263 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001264 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001265
Sathya Perla482c9e72011-06-29 23:33:17 +00001266err:
1267 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001268 return status;
1269}
1270
Sathya Perlab31c50a2009-09-17 10:30:13 -07001271/* Generic destroyer function for all types of queues
1272 * Uses Mbox
1273 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001274int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001275 int queue_type)
1276{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001277 struct be_mcc_wrb *wrb;
1278 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001279 u8 subsys = 0, opcode = 0;
1280 int status;
1281
Ivan Vecera29849612010-12-14 05:43:19 +00001282 if (mutex_lock_interruptible(&adapter->mbox_lock))
1283 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001284
Sathya Perlab31c50a2009-09-17 10:30:13 -07001285 wrb = wrb_from_mbox(adapter);
1286 req = embedded_payload(wrb);
1287
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001288 switch (queue_type) {
1289 case QTYPE_EQ:
1290 subsys = CMD_SUBSYSTEM_COMMON;
1291 opcode = OPCODE_COMMON_EQ_DESTROY;
1292 break;
1293 case QTYPE_CQ:
1294 subsys = CMD_SUBSYSTEM_COMMON;
1295 opcode = OPCODE_COMMON_CQ_DESTROY;
1296 break;
1297 case QTYPE_TXQ:
1298 subsys = CMD_SUBSYSTEM_ETH;
1299 opcode = OPCODE_ETH_TX_DESTROY;
1300 break;
1301 case QTYPE_RXQ:
1302 subsys = CMD_SUBSYSTEM_ETH;
1303 opcode = OPCODE_ETH_RX_DESTROY;
1304 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001305 case QTYPE_MCCQ:
1306 subsys = CMD_SUBSYSTEM_COMMON;
1307 opcode = OPCODE_COMMON_MCC_DESTROY;
1308 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001309 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001310 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001311 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001312
Somnath Kotur106df1e2011-10-27 07:12:13 +00001313 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1314 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001315 req->id = cpu_to_le16(q->id);
1316
Sathya Perlab31c50a2009-09-17 10:30:13 -07001317 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001318 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001319
Ivan Vecera29849612010-12-14 05:43:19 +00001320 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001321 return status;
1322}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001323
Sathya Perla482c9e72011-06-29 23:33:17 +00001324/* Uses MCC */
1325int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1326{
1327 struct be_mcc_wrb *wrb;
1328 struct be_cmd_req_q_destroy *req;
1329 int status;
1330
1331 spin_lock_bh(&adapter->mcc_lock);
1332
1333 wrb = wrb_from_mccq(adapter);
1334 if (!wrb) {
1335 status = -EBUSY;
1336 goto err;
1337 }
1338 req = embedded_payload(wrb);
1339
Somnath Kotur106df1e2011-10-27 07:12:13 +00001340 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1341 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001342 req->id = cpu_to_le16(q->id);
1343
1344 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001345 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001346
1347err:
1348 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001349 return status;
1350}
1351
Sathya Perlab31c50a2009-09-17 10:30:13 -07001352/* Create an rx filtering policy configuration on an i/f
Sathya Perlabea50982013-08-27 16:57:33 +05301353 * Will use MBOX only if MCCQ has not been created.
Sathya Perlab31c50a2009-09-17 10:30:13 -07001354 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001355int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001356 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001357{
Sathya Perlabea50982013-08-27 16:57:33 +05301358 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001359 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001360 int status;
1361
Sathya Perlabea50982013-08-27 16:57:33 +05301362 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001363 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabea50982013-08-27 16:57:33 +05301364 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), &wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001365 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001366 req->capability_flags = cpu_to_le32(cap_flags);
1367 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001368 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369
Sathya Perlabea50982013-08-27 16:57:33 +05301370 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001371 if (!status) {
Sathya Perlabea50982013-08-27 16:57:33 +05301372 struct be_cmd_resp_if_create *resp = embedded_payload(&wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001373 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301374
1375 /* Hack to retrieve VF's pmac-id on BE3 */
1376 if (BE3_chip(adapter) && !be_physfn(adapter))
1377 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001378 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001379 return status;
1380}
1381
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001382/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001383int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001384{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001385 struct be_mcc_wrb *wrb;
1386 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001387 int status;
1388
Sathya Perla30128032011-11-10 19:17:57 +00001389 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001390 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001391
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001392 spin_lock_bh(&adapter->mcc_lock);
1393
1394 wrb = wrb_from_mccq(adapter);
1395 if (!wrb) {
1396 status = -EBUSY;
1397 goto err;
1398 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001399 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001400
Somnath Kotur106df1e2011-10-27 07:12:13 +00001401 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1402 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001403 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001404 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001405
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001406 status = be_mcc_notify_wait(adapter);
1407err:
1408 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001409 return status;
1410}
1411
1412/* Get stats is a non embedded command: the request is not embedded inside
1413 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001414 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001415 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001416int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001417{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001418 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001419 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001420 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001421
Sathya Perlab31c50a2009-09-17 10:30:13 -07001422 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001423
Sathya Perlab31c50a2009-09-17 10:30:13 -07001424 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001425 if (!wrb) {
1426 status = -EBUSY;
1427 goto err;
1428 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001429 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001430
Somnath Kotur106df1e2011-10-27 07:12:13 +00001431 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1432 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001433
Sathya Perlaca34fe32012-11-06 17:48:56 +00001434 /* version 1 of the cmd is not supported only by BE2 */
1435 if (!BE2_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001436 hdr->version = 1;
1437
Sathya Perlab31c50a2009-09-17 10:30:13 -07001438 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001439 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001440
Sathya Perla713d03942009-11-22 22:02:45 +00001441err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001442 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001443 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001444}
1445
Selvin Xavier005d5692011-05-16 07:36:35 +00001446/* Lancer Stats */
1447int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1448 struct be_dma_mem *nonemb_cmd)
1449{
1450
1451 struct be_mcc_wrb *wrb;
1452 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001453 int status = 0;
1454
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001455 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1456 CMD_SUBSYSTEM_ETH))
1457 return -EPERM;
1458
Selvin Xavier005d5692011-05-16 07:36:35 +00001459 spin_lock_bh(&adapter->mcc_lock);
1460
1461 wrb = wrb_from_mccq(adapter);
1462 if (!wrb) {
1463 status = -EBUSY;
1464 goto err;
1465 }
1466 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001467
Somnath Kotur106df1e2011-10-27 07:12:13 +00001468 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1469 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1470 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001471
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001472 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001473 req->cmd_params.params.reset_stats = 0;
1474
Selvin Xavier005d5692011-05-16 07:36:35 +00001475 be_mcc_notify(adapter);
1476 adapter->stats_cmd_sent = true;
1477
1478err:
1479 spin_unlock_bh(&adapter->mcc_lock);
1480 return status;
1481}
1482
Sathya Perla323ff712012-09-28 04:39:43 +00001483static int be_mac_to_link_speed(int mac_speed)
1484{
1485 switch (mac_speed) {
1486 case PHY_LINK_SPEED_ZERO:
1487 return 0;
1488 case PHY_LINK_SPEED_10MBPS:
1489 return 10;
1490 case PHY_LINK_SPEED_100MBPS:
1491 return 100;
1492 case PHY_LINK_SPEED_1GBPS:
1493 return 1000;
1494 case PHY_LINK_SPEED_10GBPS:
1495 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301496 case PHY_LINK_SPEED_20GBPS:
1497 return 20000;
1498 case PHY_LINK_SPEED_25GBPS:
1499 return 25000;
1500 case PHY_LINK_SPEED_40GBPS:
1501 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001502 }
1503 return 0;
1504}
1505
1506/* Uses synchronous mcc
1507 * Returns link_speed in Mbps
1508 */
1509int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1510 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001511{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001512 struct be_mcc_wrb *wrb;
1513 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001514 int status;
1515
Sathya Perlab31c50a2009-09-17 10:30:13 -07001516 spin_lock_bh(&adapter->mcc_lock);
1517
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001518 if (link_status)
1519 *link_status = LINK_DOWN;
1520
Sathya Perlab31c50a2009-09-17 10:30:13 -07001521 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001522 if (!wrb) {
1523 status = -EBUSY;
1524 goto err;
1525 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001526 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001527
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001528 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1529 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1530
Sathya Perlaca34fe32012-11-06 17:48:56 +00001531 /* version 1 of the cmd is not supported only by BE2 */
1532 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001533 req->hdr.version = 1;
1534
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001535 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001536
Sathya Perlab31c50a2009-09-17 10:30:13 -07001537 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001538 if (!status) {
1539 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sathya Perla323ff712012-09-28 04:39:43 +00001540 if (link_speed) {
1541 *link_speed = resp->link_speed ?
1542 le16_to_cpu(resp->link_speed) * 10 :
1543 be_mac_to_link_speed(resp->mac_speed);
1544
1545 if (!resp->logical_link_status)
1546 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001547 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001548 if (link_status)
1549 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001550 }
1551
Sathya Perla713d03942009-11-22 22:02:45 +00001552err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001553 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001554 return status;
1555}
1556
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001557/* Uses synchronous mcc */
1558int be_cmd_get_die_temperature(struct be_adapter *adapter)
1559{
1560 struct be_mcc_wrb *wrb;
1561 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301562 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001563
1564 spin_lock_bh(&adapter->mcc_lock);
1565
1566 wrb = wrb_from_mccq(adapter);
1567 if (!wrb) {
1568 status = -EBUSY;
1569 goto err;
1570 }
1571 req = embedded_payload(wrb);
1572
Somnath Kotur106df1e2011-10-27 07:12:13 +00001573 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1574 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1575 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001576
Somnath Kotur3de09452011-09-30 07:25:05 +00001577 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001578
1579err:
1580 spin_unlock_bh(&adapter->mcc_lock);
1581 return status;
1582}
1583
Somnath Kotur311fddc2011-03-16 21:22:43 +00001584/* Uses synchronous mcc */
1585int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1586{
1587 struct be_mcc_wrb *wrb;
1588 struct be_cmd_req_get_fat *req;
1589 int status;
1590
1591 spin_lock_bh(&adapter->mcc_lock);
1592
1593 wrb = wrb_from_mccq(adapter);
1594 if (!wrb) {
1595 status = -EBUSY;
1596 goto err;
1597 }
1598 req = embedded_payload(wrb);
1599
Somnath Kotur106df1e2011-10-27 07:12:13 +00001600 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1601 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001602 req->fat_operation = cpu_to_le32(QUERY_FAT);
1603 status = be_mcc_notify_wait(adapter);
1604 if (!status) {
1605 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1606 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001607 *log_size = le32_to_cpu(resp->log_size) -
1608 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001609 }
1610err:
1611 spin_unlock_bh(&adapter->mcc_lock);
1612 return status;
1613}
1614
1615void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1616{
1617 struct be_dma_mem get_fat_cmd;
1618 struct be_mcc_wrb *wrb;
1619 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001620 u32 offset = 0, total_size, buf_size,
1621 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001622 int status;
1623
1624 if (buf_len == 0)
1625 return;
1626
1627 total_size = buf_len;
1628
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001629 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1630 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1631 get_fat_cmd.size,
1632 &get_fat_cmd.dma);
1633 if (!get_fat_cmd.va) {
1634 status = -ENOMEM;
1635 dev_err(&adapter->pdev->dev,
1636 "Memory allocation failure while retrieving FAT data\n");
1637 return;
1638 }
1639
Somnath Kotur311fddc2011-03-16 21:22:43 +00001640 spin_lock_bh(&adapter->mcc_lock);
1641
Somnath Kotur311fddc2011-03-16 21:22:43 +00001642 while (total_size) {
1643 buf_size = min(total_size, (u32)60*1024);
1644 total_size -= buf_size;
1645
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001646 wrb = wrb_from_mccq(adapter);
1647 if (!wrb) {
1648 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001649 goto err;
1650 }
1651 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001652
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001653 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001654 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1655 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1656 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001657
1658 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1659 req->read_log_offset = cpu_to_le32(log_offset);
1660 req->read_log_length = cpu_to_le32(buf_size);
1661 req->data_buffer_size = cpu_to_le32(buf_size);
1662
1663 status = be_mcc_notify_wait(adapter);
1664 if (!status) {
1665 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1666 memcpy(buf + offset,
1667 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001668 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001669 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001670 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001671 goto err;
1672 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001673 offset += buf_size;
1674 log_offset += buf_size;
1675 }
1676err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001677 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1678 get_fat_cmd.va,
1679 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001680 spin_unlock_bh(&adapter->mcc_lock);
1681}
1682
Sathya Perla04b71172011-09-27 13:30:27 -04001683/* Uses synchronous mcc */
1684int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1685 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001686{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001687 struct be_mcc_wrb *wrb;
1688 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001689 int status;
1690
Sathya Perla04b71172011-09-27 13:30:27 -04001691 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001692
Sathya Perla04b71172011-09-27 13:30:27 -04001693 wrb = wrb_from_mccq(adapter);
1694 if (!wrb) {
1695 status = -EBUSY;
1696 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001697 }
1698
Sathya Perla04b71172011-09-27 13:30:27 -04001699 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001700
Somnath Kotur106df1e2011-10-27 07:12:13 +00001701 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1702 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001703 status = be_mcc_notify_wait(adapter);
1704 if (!status) {
1705 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1706 strcpy(fw_ver, resp->firmware_version_string);
1707 if (fw_on_flash)
1708 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1709 }
1710err:
1711 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001712 return status;
1713}
1714
Sathya Perlab31c50a2009-09-17 10:30:13 -07001715/* set the EQ delay interval of an EQ to specified value
1716 * Uses async mcc
1717 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001718int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001719{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001720 struct be_mcc_wrb *wrb;
1721 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001722 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001723
Sathya Perlab31c50a2009-09-17 10:30:13 -07001724 spin_lock_bh(&adapter->mcc_lock);
1725
1726 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001727 if (!wrb) {
1728 status = -EBUSY;
1729 goto err;
1730 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001731 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001732
Somnath Kotur106df1e2011-10-27 07:12:13 +00001733 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1734 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001735
1736 req->num_eq = cpu_to_le32(1);
1737 req->delay[0].eq_id = cpu_to_le32(eq_id);
1738 req->delay[0].phase = 0;
1739 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1740
Sathya Perlab31c50a2009-09-17 10:30:13 -07001741 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001742
Sathya Perla713d03942009-11-22 22:02:45 +00001743err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001744 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001745 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001746}
1747
Sathya Perlab31c50a2009-09-17 10:30:13 -07001748/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001749int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001750 u32 num, bool untagged, bool promiscuous)
1751{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001752 struct be_mcc_wrb *wrb;
1753 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001754 int status;
1755
Sathya Perlab31c50a2009-09-17 10:30:13 -07001756 spin_lock_bh(&adapter->mcc_lock);
1757
1758 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001759 if (!wrb) {
1760 status = -EBUSY;
1761 goto err;
1762 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001763 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001764
Somnath Kotur106df1e2011-10-27 07:12:13 +00001765 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1766 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001767
1768 req->interface_id = if_id;
1769 req->promiscuous = promiscuous;
1770 req->untagged = untagged;
1771 req->num_vlan = num;
1772 if (!promiscuous) {
1773 memcpy(req->normal_vlan, vtag_array,
1774 req->num_vlan * sizeof(vtag_array[0]));
1775 }
1776
Sathya Perlab31c50a2009-09-17 10:30:13 -07001777 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001778
Sathya Perla713d03942009-11-22 22:02:45 +00001779err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001780 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001781 return status;
1782}
1783
Sathya Perla5b8821b2011-08-02 19:57:44 +00001784int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001785{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001786 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001787 struct be_dma_mem *mem = &adapter->rx_filter;
1788 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001789 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001790
Sathya Perla8788fdc2009-07-27 22:52:03 +00001791 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001792
Sathya Perlab31c50a2009-09-17 10:30:13 -07001793 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001794 if (!wrb) {
1795 status = -EBUSY;
1796 goto err;
1797 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001798 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001799 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1800 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1801 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001802
Sathya Perla5b8821b2011-08-02 19:57:44 +00001803 req->if_id = cpu_to_le32(adapter->if_handle);
1804 if (flags & IFF_PROMISC) {
1805 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Ajit Khapardec5dae582013-05-01 09:38:24 +00001806 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1807 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001808 if (value == ON)
1809 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Ajit Khapardec5dae582013-05-01 09:38:24 +00001810 BE_IF_FLAGS_VLAN_PROMISCUOUS |
1811 BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001812 } else if (flags & IFF_ALLMULTI) {
1813 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001814 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001815 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001816 struct netdev_hw_addr *ha;
1817 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001818
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001819 req->if_flags_mask = req->if_flags =
1820 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001821
1822 /* Reset mcast promisc mode if already set by setting mask
1823 * and not setting flags field
1824 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001825 req->if_flags_mask |=
1826 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05301827 be_if_cap_flags(adapter));
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001828 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001829 netdev_for_each_mc_addr(ha, adapter->netdev)
1830 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1831 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001832
Sathya Perla0d1d5872011-08-03 05:19:27 -07001833 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001834err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001835 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001836 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001837}
1838
Sathya Perlab31c50a2009-09-17 10:30:13 -07001839/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001840int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001841{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001842 struct be_mcc_wrb *wrb;
1843 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001844 int status;
1845
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001846 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1847 CMD_SUBSYSTEM_COMMON))
1848 return -EPERM;
1849
Sathya Perlab31c50a2009-09-17 10:30:13 -07001850 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001851
Sathya Perlab31c50a2009-09-17 10:30:13 -07001852 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001853 if (!wrb) {
1854 status = -EBUSY;
1855 goto err;
1856 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001857 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001858
Somnath Kotur106df1e2011-10-27 07:12:13 +00001859 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1860 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001861
1862 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1863 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1864
Sathya Perlab31c50a2009-09-17 10:30:13 -07001865 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001866
Sathya Perla713d03942009-11-22 22:02:45 +00001867err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001868 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001869 return status;
1870}
1871
Sathya Perlab31c50a2009-09-17 10:30:13 -07001872/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001873int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001874{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001875 struct be_mcc_wrb *wrb;
1876 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001877 int status;
1878
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001879 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
1880 CMD_SUBSYSTEM_COMMON))
1881 return -EPERM;
1882
Sathya Perlab31c50a2009-09-17 10:30:13 -07001883 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001884
Sathya Perlab31c50a2009-09-17 10:30:13 -07001885 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001886 if (!wrb) {
1887 status = -EBUSY;
1888 goto err;
1889 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001890 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001891
Somnath Kotur106df1e2011-10-27 07:12:13 +00001892 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1893 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001894
Sathya Perlab31c50a2009-09-17 10:30:13 -07001895 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001896 if (!status) {
1897 struct be_cmd_resp_get_flow_control *resp =
1898 embedded_payload(wrb);
1899 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1900 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1901 }
1902
Sathya Perla713d03942009-11-22 22:02:45 +00001903err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001904 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001905 return status;
1906}
1907
Sathya Perlab31c50a2009-09-17 10:30:13 -07001908/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001909int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
Vasundhara Volam0ad31572013-04-21 23:28:16 +00001910 u32 *mode, u32 *caps, u16 *asic_rev)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001911{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001912 struct be_mcc_wrb *wrb;
1913 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001914 int status;
1915
Ivan Vecera29849612010-12-14 05:43:19 +00001916 if (mutex_lock_interruptible(&adapter->mbox_lock))
1917 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001918
Sathya Perlab31c50a2009-09-17 10:30:13 -07001919 wrb = wrb_from_mbox(adapter);
1920 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001921
Somnath Kotur106df1e2011-10-27 07:12:13 +00001922 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1923 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001924
Sathya Perlab31c50a2009-09-17 10:30:13 -07001925 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001926 if (!status) {
1927 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1928 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001929 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001930 *caps = le32_to_cpu(resp->function_caps);
Vasundhara Volam0ad31572013-04-21 23:28:16 +00001931 *asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001932 }
1933
Ivan Vecera29849612010-12-14 05:43:19 +00001934 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001935 return status;
1936}
sarveshwarb14074ea2009-08-05 13:05:24 -07001937
Sathya Perlab31c50a2009-09-17 10:30:13 -07001938/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001939int be_cmd_reset_function(struct be_adapter *adapter)
1940{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001941 struct be_mcc_wrb *wrb;
1942 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001943 int status;
1944
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00001945 if (lancer_chip(adapter)) {
1946 status = lancer_wait_ready(adapter);
1947 if (!status) {
1948 iowrite32(SLI_PORT_CONTROL_IP_MASK,
1949 adapter->db + SLIPORT_CONTROL_OFFSET);
1950 status = lancer_test_and_set_rdy_state(adapter);
1951 }
1952 if (status) {
1953 dev_err(&adapter->pdev->dev,
1954 "Adapter in non recoverable error\n");
1955 }
1956 return status;
1957 }
1958
Ivan Vecera29849612010-12-14 05:43:19 +00001959 if (mutex_lock_interruptible(&adapter->mbox_lock))
1960 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001961
Sathya Perlab31c50a2009-09-17 10:30:13 -07001962 wrb = wrb_from_mbox(adapter);
1963 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001964
Somnath Kotur106df1e2011-10-27 07:12:13 +00001965 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1966 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001967
Sathya Perlab31c50a2009-09-17 10:30:13 -07001968 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001969
Ivan Vecera29849612010-12-14 05:43:19 +00001970 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001971 return status;
1972}
Ajit Khaparde84517482009-09-04 03:12:16 +00001973
Suresh Reddy594ad542013-04-25 23:03:20 +00001974int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
1975 u32 rss_hash_opts, u16 table_size)
Sathya Perla3abcded2010-10-03 22:12:27 -07001976{
1977 struct be_mcc_wrb *wrb;
1978 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001979 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1980 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1981 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001982 int status;
1983
Ivan Vecera29849612010-12-14 05:43:19 +00001984 if (mutex_lock_interruptible(&adapter->mbox_lock))
1985 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001986
1987 wrb = wrb_from_mbox(adapter);
1988 req = embedded_payload(wrb);
1989
Somnath Kotur106df1e2011-10-27 07:12:13 +00001990 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1991 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001992
1993 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00001994 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07001995 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00001996
1997 if (lancer_chip(adapter) || skyhawk_chip(adapter))
1998 req->hdr.version = 1;
1999
Sathya Perla3abcded2010-10-03 22:12:27 -07002000 memcpy(req->cpu_table, rsstable, table_size);
2001 memcpy(req->hash, myhash, sizeof(myhash));
2002 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
2003
2004 status = be_mbox_notify_wait(adapter);
2005
Ivan Vecera29849612010-12-14 05:43:19 +00002006 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002007 return status;
2008}
2009
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002010/* Uses sync mcc */
2011int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
2012 u8 bcn, u8 sts, u8 state)
2013{
2014 struct be_mcc_wrb *wrb;
2015 struct be_cmd_req_enable_disable_beacon *req;
2016 int status;
2017
2018 spin_lock_bh(&adapter->mcc_lock);
2019
2020 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002021 if (!wrb) {
2022 status = -EBUSY;
2023 goto err;
2024 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002025 req = embedded_payload(wrb);
2026
Somnath Kotur106df1e2011-10-27 07:12:13 +00002027 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2028 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002029
2030 req->port_num = port_num;
2031 req->beacon_state = state;
2032 req->beacon_duration = bcn;
2033 req->status_duration = sts;
2034
2035 status = be_mcc_notify_wait(adapter);
2036
Sathya Perla713d03942009-11-22 22:02:45 +00002037err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002038 spin_unlock_bh(&adapter->mcc_lock);
2039 return status;
2040}
2041
2042/* Uses sync mcc */
2043int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2044{
2045 struct be_mcc_wrb *wrb;
2046 struct be_cmd_req_get_beacon_state *req;
2047 int status;
2048
2049 spin_lock_bh(&adapter->mcc_lock);
2050
2051 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002052 if (!wrb) {
2053 status = -EBUSY;
2054 goto err;
2055 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002056 req = embedded_payload(wrb);
2057
Somnath Kotur106df1e2011-10-27 07:12:13 +00002058 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2059 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002060
2061 req->port_num = port_num;
2062
2063 status = be_mcc_notify_wait(adapter);
2064 if (!status) {
2065 struct be_cmd_resp_get_beacon_state *resp =
2066 embedded_payload(wrb);
2067 *state = resp->beacon_state;
2068 }
2069
Sathya Perla713d03942009-11-22 22:02:45 +00002070err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002071 spin_unlock_bh(&adapter->mcc_lock);
2072 return status;
2073}
2074
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002075int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002076 u32 data_size, u32 data_offset,
2077 const char *obj_name, u32 *data_written,
2078 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002079{
2080 struct be_mcc_wrb *wrb;
2081 struct lancer_cmd_req_write_object *req;
2082 struct lancer_cmd_resp_write_object *resp;
2083 void *ctxt = NULL;
2084 int status;
2085
2086 spin_lock_bh(&adapter->mcc_lock);
2087 adapter->flash_status = 0;
2088
2089 wrb = wrb_from_mccq(adapter);
2090 if (!wrb) {
2091 status = -EBUSY;
2092 goto err_unlock;
2093 }
2094
2095 req = embedded_payload(wrb);
2096
Somnath Kotur106df1e2011-10-27 07:12:13 +00002097 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002098 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00002099 sizeof(struct lancer_cmd_req_write_object), wrb,
2100 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002101
2102 ctxt = &req->context;
2103 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2104 write_length, ctxt, data_size);
2105
2106 if (data_size == 0)
2107 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2108 eof, ctxt, 1);
2109 else
2110 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2111 eof, ctxt, 0);
2112
2113 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2114 req->write_offset = cpu_to_le32(data_offset);
2115 strcpy(req->object_name, obj_name);
2116 req->descriptor_count = cpu_to_le32(1);
2117 req->buf_len = cpu_to_le32(data_size);
2118 req->addr_low = cpu_to_le32((cmd->dma +
2119 sizeof(struct lancer_cmd_req_write_object))
2120 & 0xFFFFFFFF);
2121 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2122 sizeof(struct lancer_cmd_req_write_object)));
2123
2124 be_mcc_notify(adapter);
2125 spin_unlock_bh(&adapter->mcc_lock);
2126
2127 if (!wait_for_completion_timeout(&adapter->flash_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002128 msecs_to_jiffies(60000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002129 status = -1;
2130 else
2131 status = adapter->flash_status;
2132
2133 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002134 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002135 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002136 *change_status = resp->change_status;
2137 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002138 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002139 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002140
2141 return status;
2142
2143err_unlock:
2144 spin_unlock_bh(&adapter->mcc_lock);
2145 return status;
2146}
2147
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002148int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
2149 u32 data_size, u32 data_offset, const char *obj_name,
2150 u32 *data_read, u32 *eof, u8 *addn_status)
2151{
2152 struct be_mcc_wrb *wrb;
2153 struct lancer_cmd_req_read_object *req;
2154 struct lancer_cmd_resp_read_object *resp;
2155 int status;
2156
2157 spin_lock_bh(&adapter->mcc_lock);
2158
2159 wrb = wrb_from_mccq(adapter);
2160 if (!wrb) {
2161 status = -EBUSY;
2162 goto err_unlock;
2163 }
2164
2165 req = embedded_payload(wrb);
2166
2167 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2168 OPCODE_COMMON_READ_OBJECT,
2169 sizeof(struct lancer_cmd_req_read_object), wrb,
2170 NULL);
2171
2172 req->desired_read_len = cpu_to_le32(data_size);
2173 req->read_offset = cpu_to_le32(data_offset);
2174 strcpy(req->object_name, obj_name);
2175 req->descriptor_count = cpu_to_le32(1);
2176 req->buf_len = cpu_to_le32(data_size);
2177 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2178 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2179
2180 status = be_mcc_notify_wait(adapter);
2181
2182 resp = embedded_payload(wrb);
2183 if (!status) {
2184 *data_read = le32_to_cpu(resp->actual_read_len);
2185 *eof = le32_to_cpu(resp->eof);
2186 } else {
2187 *addn_status = resp->additional_status;
2188 }
2189
2190err_unlock:
2191 spin_unlock_bh(&adapter->mcc_lock);
2192 return status;
2193}
2194
Ajit Khaparde84517482009-09-04 03:12:16 +00002195int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
2196 u32 flash_type, u32 flash_opcode, u32 buf_size)
2197{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002198 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002199 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002200 int status;
2201
Sathya Perlab31c50a2009-09-17 10:30:13 -07002202 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002203 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002204
2205 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002206 if (!wrb) {
2207 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002208 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002209 }
2210 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002211
Somnath Kotur106df1e2011-10-27 07:12:13 +00002212 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2213 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002214
2215 req->params.op_type = cpu_to_le32(flash_type);
2216 req->params.op_code = cpu_to_le32(flash_opcode);
2217 req->params.data_buf_size = cpu_to_le32(buf_size);
2218
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002219 be_mcc_notify(adapter);
2220 spin_unlock_bh(&adapter->mcc_lock);
2221
2222 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00002223 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002224 status = -1;
2225 else
2226 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002227
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002228 return status;
2229
2230err_unlock:
2231 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002232 return status;
2233}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002234
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002235int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2236 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002237{
2238 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002239 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002240 int status;
2241
2242 spin_lock_bh(&adapter->mcc_lock);
2243
2244 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002245 if (!wrb) {
2246 status = -EBUSY;
2247 goto err;
2248 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002249 req = embedded_payload(wrb);
2250
Somnath Kotur106df1e2011-10-27 07:12:13 +00002251 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002252 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2253 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002254
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00002255 req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002256 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002257 req->params.offset = cpu_to_le32(offset);
2258 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002259
2260 status = be_mcc_notify_wait(adapter);
2261 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002262 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002263
Sathya Perla713d03942009-11-22 22:02:45 +00002264err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002265 spin_unlock_bh(&adapter->mcc_lock);
2266 return status;
2267}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002268
Dan Carpenterc196b022010-05-26 04:47:39 +00002269int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002270 struct be_dma_mem *nonemb_cmd)
2271{
2272 struct be_mcc_wrb *wrb;
2273 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002274 int status;
2275
2276 spin_lock_bh(&adapter->mcc_lock);
2277
2278 wrb = wrb_from_mccq(adapter);
2279 if (!wrb) {
2280 status = -EBUSY;
2281 goto err;
2282 }
2283 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002284
Somnath Kotur106df1e2011-10-27 07:12:13 +00002285 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2286 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2287 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002288 memcpy(req->magic_mac, mac, ETH_ALEN);
2289
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002290 status = be_mcc_notify_wait(adapter);
2291
2292err:
2293 spin_unlock_bh(&adapter->mcc_lock);
2294 return status;
2295}
Suresh Rff33a6e2009-12-03 16:15:52 -08002296
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002297int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2298 u8 loopback_type, u8 enable)
2299{
2300 struct be_mcc_wrb *wrb;
2301 struct be_cmd_req_set_lmode *req;
2302 int status;
2303
2304 spin_lock_bh(&adapter->mcc_lock);
2305
2306 wrb = wrb_from_mccq(adapter);
2307 if (!wrb) {
2308 status = -EBUSY;
2309 goto err;
2310 }
2311
2312 req = embedded_payload(wrb);
2313
Somnath Kotur106df1e2011-10-27 07:12:13 +00002314 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2315 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2316 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002317
2318 req->src_port = port_num;
2319 req->dest_port = port_num;
2320 req->loopback_type = loopback_type;
2321 req->loopback_state = enable;
2322
2323 status = be_mcc_notify_wait(adapter);
2324err:
2325 spin_unlock_bh(&adapter->mcc_lock);
2326 return status;
2327}
2328
Suresh Rff33a6e2009-12-03 16:15:52 -08002329int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2330 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2331{
2332 struct be_mcc_wrb *wrb;
2333 struct be_cmd_req_loopback_test *req;
2334 int status;
2335
2336 spin_lock_bh(&adapter->mcc_lock);
2337
2338 wrb = wrb_from_mccq(adapter);
2339 if (!wrb) {
2340 status = -EBUSY;
2341 goto err;
2342 }
2343
2344 req = embedded_payload(wrb);
2345
Somnath Kotur106df1e2011-10-27 07:12:13 +00002346 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2347 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002348 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002349
2350 req->pattern = cpu_to_le64(pattern);
2351 req->src_port = cpu_to_le32(port_num);
2352 req->dest_port = cpu_to_le32(port_num);
2353 req->pkt_size = cpu_to_le32(pkt_size);
2354 req->num_pkts = cpu_to_le32(num_pkts);
2355 req->loopback_type = cpu_to_le32(loopback_type);
2356
2357 status = be_mcc_notify_wait(adapter);
2358 if (!status) {
2359 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2360 status = le32_to_cpu(resp->status);
2361 }
2362
2363err:
2364 spin_unlock_bh(&adapter->mcc_lock);
2365 return status;
2366}
2367
2368int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2369 u32 byte_cnt, struct be_dma_mem *cmd)
2370{
2371 struct be_mcc_wrb *wrb;
2372 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002373 int status;
2374 int i, j = 0;
2375
2376 spin_lock_bh(&adapter->mcc_lock);
2377
2378 wrb = wrb_from_mccq(adapter);
2379 if (!wrb) {
2380 status = -EBUSY;
2381 goto err;
2382 }
2383 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002384 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2385 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002386
2387 req->pattern = cpu_to_le64(pattern);
2388 req->byte_count = cpu_to_le32(byte_cnt);
2389 for (i = 0; i < byte_cnt; i++) {
2390 req->snd_buff[i] = (u8)(pattern >> (j*8));
2391 j++;
2392 if (j > 7)
2393 j = 0;
2394 }
2395
2396 status = be_mcc_notify_wait(adapter);
2397
2398 if (!status) {
2399 struct be_cmd_resp_ddrdma_test *resp;
2400 resp = cmd->va;
2401 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2402 resp->snd_err) {
2403 status = -1;
2404 }
2405 }
2406
2407err:
2408 spin_unlock_bh(&adapter->mcc_lock);
2409 return status;
2410}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002411
Dan Carpenterc196b022010-05-26 04:47:39 +00002412int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002413 struct be_dma_mem *nonemb_cmd)
2414{
2415 struct be_mcc_wrb *wrb;
2416 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002417 int status;
2418
2419 spin_lock_bh(&adapter->mcc_lock);
2420
2421 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002422 if (!wrb) {
2423 status = -EBUSY;
2424 goto err;
2425 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002426 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002427
Somnath Kotur106df1e2011-10-27 07:12:13 +00002428 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2429 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2430 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002431
2432 status = be_mcc_notify_wait(adapter);
2433
Ajit Khapardee45ff012011-02-04 17:18:28 +00002434err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002435 spin_unlock_bh(&adapter->mcc_lock);
2436 return status;
2437}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002438
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002439int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002440{
2441 struct be_mcc_wrb *wrb;
2442 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002443 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002444 int status;
2445
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002446 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2447 CMD_SUBSYSTEM_COMMON))
2448 return -EPERM;
2449
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002450 spin_lock_bh(&adapter->mcc_lock);
2451
2452 wrb = wrb_from_mccq(adapter);
2453 if (!wrb) {
2454 status = -EBUSY;
2455 goto err;
2456 }
Sathya Perla306f1342011-08-02 19:57:45 +00002457 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2458 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2459 &cmd.dma);
2460 if (!cmd.va) {
2461 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2462 status = -ENOMEM;
2463 goto err;
2464 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002465
Sathya Perla306f1342011-08-02 19:57:45 +00002466 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002467
Somnath Kotur106df1e2011-10-27 07:12:13 +00002468 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2469 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2470 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002471
2472 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002473 if (!status) {
2474 struct be_phy_info *resp_phy_info =
2475 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002476 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2477 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002478 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002479 adapter->phy.auto_speeds_supported =
2480 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2481 adapter->phy.fixed_speeds_supported =
2482 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2483 adapter->phy.misc_params =
2484 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05302485
2486 if (BE2_chip(adapter)) {
2487 adapter->phy.fixed_speeds_supported =
2488 BE_SUPPORTED_SPEED_10GBPS |
2489 BE_SUPPORTED_SPEED_1GBPS;
2490 }
Sathya Perla306f1342011-08-02 19:57:45 +00002491 }
2492 pci_free_consistent(adapter->pdev, cmd.size,
2493 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002494err:
2495 spin_unlock_bh(&adapter->mcc_lock);
2496 return status;
2497}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002498
2499int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2500{
2501 struct be_mcc_wrb *wrb;
2502 struct be_cmd_req_set_qos *req;
2503 int status;
2504
2505 spin_lock_bh(&adapter->mcc_lock);
2506
2507 wrb = wrb_from_mccq(adapter);
2508 if (!wrb) {
2509 status = -EBUSY;
2510 goto err;
2511 }
2512
2513 req = embedded_payload(wrb);
2514
Somnath Kotur106df1e2011-10-27 07:12:13 +00002515 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2516 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002517
2518 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002519 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2520 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002521
2522 status = be_mcc_notify_wait(adapter);
2523
2524err:
2525 spin_unlock_bh(&adapter->mcc_lock);
2526 return status;
2527}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002528
2529int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2530{
2531 struct be_mcc_wrb *wrb;
2532 struct be_cmd_req_cntl_attribs *req;
2533 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002534 int status;
2535 int payload_len = max(sizeof(*req), sizeof(*resp));
2536 struct mgmt_controller_attrib *attribs;
2537 struct be_dma_mem attribs_cmd;
2538
Suresh Reddyd98ef502013-04-25 00:56:55 +00002539 if (mutex_lock_interruptible(&adapter->mbox_lock))
2540 return -1;
2541
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002542 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2543 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2544 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2545 &attribs_cmd.dma);
2546 if (!attribs_cmd.va) {
2547 dev_err(&adapter->pdev->dev,
2548 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002549 status = -ENOMEM;
2550 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002551 }
2552
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002553 wrb = wrb_from_mbox(adapter);
2554 if (!wrb) {
2555 status = -EBUSY;
2556 goto err;
2557 }
2558 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002559
Somnath Kotur106df1e2011-10-27 07:12:13 +00002560 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2561 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2562 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002563
2564 status = be_mbox_notify_wait(adapter);
2565 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002566 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002567 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2568 }
2569
2570err:
2571 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002572 if (attribs_cmd.va)
2573 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2574 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002575 return status;
2576}
Sathya Perla2e588f82011-03-11 02:49:26 +00002577
2578/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002579int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002580{
2581 struct be_mcc_wrb *wrb;
2582 struct be_cmd_req_set_func_cap *req;
2583 int status;
2584
2585 if (mutex_lock_interruptible(&adapter->mbox_lock))
2586 return -1;
2587
2588 wrb = wrb_from_mbox(adapter);
2589 if (!wrb) {
2590 status = -EBUSY;
2591 goto err;
2592 }
2593
2594 req = embedded_payload(wrb);
2595
Somnath Kotur106df1e2011-10-27 07:12:13 +00002596 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2597 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002598
2599 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2600 CAPABILITY_BE3_NATIVE_ERX_API);
2601 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2602
2603 status = be_mbox_notify_wait(adapter);
2604 if (!status) {
2605 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2606 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2607 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002608 if (!adapter->be3_native)
2609 dev_warn(&adapter->pdev->dev,
2610 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002611 }
2612err:
2613 mutex_unlock(&adapter->mbox_lock);
2614 return status;
2615}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002616
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002617/* Get privilege(s) for a function */
2618int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2619 u32 domain)
2620{
2621 struct be_mcc_wrb *wrb;
2622 struct be_cmd_req_get_fn_privileges *req;
2623 int status;
2624
2625 spin_lock_bh(&adapter->mcc_lock);
2626
2627 wrb = wrb_from_mccq(adapter);
2628 if (!wrb) {
2629 status = -EBUSY;
2630 goto err;
2631 }
2632
2633 req = embedded_payload(wrb);
2634
2635 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2636 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2637 wrb, NULL);
2638
2639 req->hdr.domain = domain;
2640
2641 status = be_mcc_notify_wait(adapter);
2642 if (!status) {
2643 struct be_cmd_resp_get_fn_privileges *resp =
2644 embedded_payload(wrb);
2645 *privilege = le32_to_cpu(resp->privilege_mask);
2646 }
2647
2648err:
2649 spin_unlock_bh(&adapter->mcc_lock);
2650 return status;
2651}
2652
Sathya Perla04a06022013-07-23 15:25:00 +05302653/* Set privilege(s) for a function */
2654int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
2655 u32 domain)
2656{
2657 struct be_mcc_wrb *wrb;
2658 struct be_cmd_req_set_fn_privileges *req;
2659 int status;
2660
2661 spin_lock_bh(&adapter->mcc_lock);
2662
2663 wrb = wrb_from_mccq(adapter);
2664 if (!wrb) {
2665 status = -EBUSY;
2666 goto err;
2667 }
2668
2669 req = embedded_payload(wrb);
2670 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2671 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
2672 wrb, NULL);
2673 req->hdr.domain = domain;
2674 if (lancer_chip(adapter))
2675 req->privileges_lancer = cpu_to_le32(privileges);
2676 else
2677 req->privileges = cpu_to_le32(privileges);
2678
2679 status = be_mcc_notify_wait(adapter);
2680err:
2681 spin_unlock_bh(&adapter->mcc_lock);
2682 return status;
2683}
2684
Sathya Perla5a712c12013-07-23 15:24:59 +05302685/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
2686 * pmac_id_valid: false => pmac_id or MAC address is requested.
2687 * If pmac_id is returned, pmac_id_valid is returned as true
2688 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002689int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Sathya Perla5a712c12013-07-23 15:24:59 +05302690 bool *pmac_id_valid, u32 *pmac_id, u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002691{
2692 struct be_mcc_wrb *wrb;
2693 struct be_cmd_req_get_mac_list *req;
2694 int status;
2695 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002696 struct be_dma_mem get_mac_list_cmd;
2697 int i;
2698
2699 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2700 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2701 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2702 get_mac_list_cmd.size,
2703 &get_mac_list_cmd.dma);
2704
2705 if (!get_mac_list_cmd.va) {
2706 dev_err(&adapter->pdev->dev,
2707 "Memory allocation failure during GET_MAC_LIST\n");
2708 return -ENOMEM;
2709 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002710
2711 spin_lock_bh(&adapter->mcc_lock);
2712
2713 wrb = wrb_from_mccq(adapter);
2714 if (!wrb) {
2715 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002716 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002717 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002718
2719 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002720
2721 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00002722 OPCODE_COMMON_GET_MAC_LIST,
2723 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002724 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002725 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05302726 if (*pmac_id_valid) {
2727 req->mac_id = cpu_to_le32(*pmac_id);
2728 req->iface_id = cpu_to_le16(adapter->if_handle);
2729 req->perm_override = 0;
2730 } else {
2731 req->perm_override = 1;
2732 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002733
2734 status = be_mcc_notify_wait(adapter);
2735 if (!status) {
2736 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002737 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05302738
2739 if (*pmac_id_valid) {
2740 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
2741 ETH_ALEN);
2742 goto out;
2743 }
2744
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002745 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2746 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002747 * or one or more true or pseudo permanant mac addresses.
2748 * If an active mac_id is present, return first active mac_id
2749 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002750 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002751 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002752 struct get_list_macaddr *mac_entry;
2753 u16 mac_addr_size;
2754 u32 mac_id;
2755
2756 mac_entry = &resp->macaddr_list[i];
2757 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2758 /* mac_id is a 32 bit value and mac_addr size
2759 * is 6 bytes
2760 */
2761 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05302762 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002763 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2764 *pmac_id = le32_to_cpu(mac_id);
2765 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002766 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002767 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002768 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05302769 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002770 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2771 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002772 }
2773
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002774out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002775 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002776 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2777 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002778 return status;
2779}
2780
Sathya Perla5a712c12013-07-23 15:24:59 +05302781int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id, u8 *mac)
2782{
Sathya Perla5a712c12013-07-23 15:24:59 +05302783 bool active = true;
2784
Sathya Perla3175d8c2013-07-23 15:25:03 +05302785 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05302786 return be_cmd_mac_addr_query(adapter, mac, false,
2787 adapter->if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05302788 else
2789 /* Fetch the MAC address using pmac_id */
2790 return be_cmd_get_mac_from_list(adapter, mac, &active,
2791 &curr_pmac_id, 0);
Sathya Perla5a712c12013-07-23 15:24:59 +05302792}
2793
Sathya Perla95046b92013-07-23 15:25:02 +05302794int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
2795{
2796 int status;
2797 bool pmac_valid = false;
2798
2799 memset(mac, 0, ETH_ALEN);
2800
Sathya Perla3175d8c2013-07-23 15:25:03 +05302801 if (BEx_chip(adapter)) {
2802 if (be_physfn(adapter))
2803 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
2804 0);
2805 else
2806 status = be_cmd_mac_addr_query(adapter, mac, false,
2807 adapter->if_handle, 0);
2808 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05302809 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
2810 NULL, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05302811 }
2812
Sathya Perla95046b92013-07-23 15:25:02 +05302813 return status;
2814}
2815
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002816/* Uses synchronous MCCQ */
2817int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2818 u8 mac_count, u32 domain)
2819{
2820 struct be_mcc_wrb *wrb;
2821 struct be_cmd_req_set_mac_list *req;
2822 int status;
2823 struct be_dma_mem cmd;
2824
2825 memset(&cmd, 0, sizeof(struct be_dma_mem));
2826 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2827 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2828 &cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00002829 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002830 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002831
2832 spin_lock_bh(&adapter->mcc_lock);
2833
2834 wrb = wrb_from_mccq(adapter);
2835 if (!wrb) {
2836 status = -EBUSY;
2837 goto err;
2838 }
2839
2840 req = cmd.va;
2841 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2842 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2843 wrb, &cmd);
2844
2845 req->hdr.domain = domain;
2846 req->mac_count = mac_count;
2847 if (mac_count)
2848 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2849
2850 status = be_mcc_notify_wait(adapter);
2851
2852err:
2853 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2854 cmd.va, cmd.dma);
2855 spin_unlock_bh(&adapter->mcc_lock);
2856 return status;
2857}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002858
Sathya Perla3175d8c2013-07-23 15:25:03 +05302859/* Wrapper to delete any active MACs and provision the new mac.
2860 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
2861 * current list are active.
2862 */
2863int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
2864{
2865 bool active_mac = false;
2866 u8 old_mac[ETH_ALEN];
2867 u32 pmac_id;
2868 int status;
2869
2870 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
2871 &pmac_id, dom);
2872 if (!status && active_mac)
2873 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
2874
2875 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
2876}
2877
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002878int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05002879 u32 domain, u16 intf_id, u16 hsw_mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002880{
2881 struct be_mcc_wrb *wrb;
2882 struct be_cmd_req_set_hsw_config *req;
2883 void *ctxt;
2884 int status;
2885
2886 spin_lock_bh(&adapter->mcc_lock);
2887
2888 wrb = wrb_from_mccq(adapter);
2889 if (!wrb) {
2890 status = -EBUSY;
2891 goto err;
2892 }
2893
2894 req = embedded_payload(wrb);
2895 ctxt = &req->context;
2896
2897 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2898 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2899
2900 req->hdr.domain = domain;
2901 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2902 if (pvid) {
2903 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2904 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2905 }
Ajit Khapardea77dcb82013-08-30 15:01:16 -05002906 if (!BEx_chip(adapter) && hsw_mode) {
2907 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id,
2908 ctxt, adapter->hba_port_num);
2909 AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1);
2910 AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type,
2911 ctxt, hsw_mode);
2912 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002913
2914 be_dws_cpu_to_le(req->context, sizeof(req->context));
2915 status = be_mcc_notify_wait(adapter);
2916
2917err:
2918 spin_unlock_bh(&adapter->mcc_lock);
2919 return status;
2920}
2921
2922/* Get Hyper switch config */
2923int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05002924 u32 domain, u16 intf_id, u8 *mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002925{
2926 struct be_mcc_wrb *wrb;
2927 struct be_cmd_req_get_hsw_config *req;
2928 void *ctxt;
2929 int status;
2930 u16 vid;
2931
2932 spin_lock_bh(&adapter->mcc_lock);
2933
2934 wrb = wrb_from_mccq(adapter);
2935 if (!wrb) {
2936 status = -EBUSY;
2937 goto err;
2938 }
2939
2940 req = embedded_payload(wrb);
2941 ctxt = &req->context;
2942
2943 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2944 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2945
2946 req->hdr.domain = domain;
Ajit Khapardea77dcb82013-08-30 15:01:16 -05002947 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
2948 ctxt, intf_id);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002949 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05002950
2951 if (!BEx_chip(adapter)) {
2952 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
2953 ctxt, adapter->hba_port_num);
2954 AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1);
2955 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002956 be_dws_cpu_to_le(req->context, sizeof(req->context));
2957
2958 status = be_mcc_notify_wait(adapter);
2959 if (!status) {
2960 struct be_cmd_resp_get_hsw_config *resp =
2961 embedded_payload(wrb);
2962 be_dws_le_to_cpu(&resp->context,
2963 sizeof(resp->context));
2964 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2965 pvid, &resp->context);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05002966 if (pvid)
2967 *pvid = le16_to_cpu(vid);
2968 if (mode)
2969 *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2970 port_fwd_type, &resp->context);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002971 }
2972
2973err:
2974 spin_unlock_bh(&adapter->mcc_lock);
2975 return status;
2976}
2977
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002978int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2979{
2980 struct be_mcc_wrb *wrb;
2981 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2982 int status;
2983 int payload_len = sizeof(*req);
2984 struct be_dma_mem cmd;
2985
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002986 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2987 CMD_SUBSYSTEM_ETH))
2988 return -EPERM;
2989
Suresh Reddyd98ef502013-04-25 00:56:55 +00002990 if (mutex_lock_interruptible(&adapter->mbox_lock))
2991 return -1;
2992
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002993 memset(&cmd, 0, sizeof(struct be_dma_mem));
2994 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2995 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2996 &cmd.dma);
2997 if (!cmd.va) {
2998 dev_err(&adapter->pdev->dev,
2999 "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003000 status = -ENOMEM;
3001 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003002 }
3003
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003004 wrb = wrb_from_mbox(adapter);
3005 if (!wrb) {
3006 status = -EBUSY;
3007 goto err;
3008 }
3009
3010 req = cmd.va;
3011
3012 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
3013 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
3014 payload_len, wrb, &cmd);
3015
3016 req->hdr.version = 1;
3017 req->query_options = BE_GET_WOL_CAP;
3018
3019 status = be_mbox_notify_wait(adapter);
3020 if (!status) {
3021 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
3022 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
3023
3024 /* the command could succeed misleadingly on old f/w
3025 * which is not aware of the V1 version. fake an error. */
3026 if (resp->hdr.response_length < payload_len) {
3027 status = -1;
3028 goto err;
3029 }
3030 adapter->wol_cap = resp->wol_settings;
3031 }
3032err:
3033 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003034 if (cmd.va)
3035 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003036 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00003037
3038}
3039int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
3040 struct be_dma_mem *cmd)
3041{
3042 struct be_mcc_wrb *wrb;
3043 struct be_cmd_req_get_ext_fat_caps *req;
3044 int status;
3045
3046 if (mutex_lock_interruptible(&adapter->mbox_lock))
3047 return -1;
3048
3049 wrb = wrb_from_mbox(adapter);
3050 if (!wrb) {
3051 status = -EBUSY;
3052 goto err;
3053 }
3054
3055 req = cmd->va;
3056 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3057 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
3058 cmd->size, wrb, cmd);
3059 req->parameter_type = cpu_to_le32(1);
3060
3061 status = be_mbox_notify_wait(adapter);
3062err:
3063 mutex_unlock(&adapter->mbox_lock);
3064 return status;
3065}
3066
3067int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
3068 struct be_dma_mem *cmd,
3069 struct be_fat_conf_params *configs)
3070{
3071 struct be_mcc_wrb *wrb;
3072 struct be_cmd_req_set_ext_fat_caps *req;
3073 int status;
3074
3075 spin_lock_bh(&adapter->mcc_lock);
3076
3077 wrb = wrb_from_mccq(adapter);
3078 if (!wrb) {
3079 status = -EBUSY;
3080 goto err;
3081 }
3082
3083 req = cmd->va;
3084 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
3085 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3086 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
3087 cmd->size, wrb, cmd);
3088
3089 status = be_mcc_notify_wait(adapter);
3090err:
3091 spin_unlock_bh(&adapter->mcc_lock);
3092 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003093}
Parav Pandit6a4ab662012-03-26 14:27:12 +00003094
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003095int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
3096{
3097 struct be_mcc_wrb *wrb;
3098 struct be_cmd_req_get_port_name *req;
3099 int status;
3100
3101 if (!lancer_chip(adapter)) {
3102 *port_name = adapter->hba_port_num + '0';
3103 return 0;
3104 }
3105
3106 spin_lock_bh(&adapter->mcc_lock);
3107
3108 wrb = wrb_from_mccq(adapter);
3109 if (!wrb) {
3110 status = -EBUSY;
3111 goto err;
3112 }
3113
3114 req = embedded_payload(wrb);
3115
3116 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3117 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
3118 NULL);
3119 req->hdr.version = 1;
3120
3121 status = be_mcc_notify_wait(adapter);
3122 if (!status) {
3123 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
3124 *port_name = resp->port_name[adapter->hba_port_num];
3125 } else {
3126 *port_name = adapter->hba_port_num + '0';
3127 }
3128err:
3129 spin_unlock_bh(&adapter->mcc_lock);
3130 return status;
3131}
3132
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303133static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003134{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303135 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003136 int i;
3137
3138 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303139 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
3140 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1)
3141 return (struct be_nic_res_desc *)hdr;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003142
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303143 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3144 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003145 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303146 return NULL;
3147}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003148
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303149static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3150 u32 desc_count)
3151{
3152 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3153 struct be_pcie_res_desc *pcie;
3154 int i;
3155
3156 for (i = 0; i < desc_count; i++) {
3157 if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
3158 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) {
3159 pcie = (struct be_pcie_res_desc *)hdr;
3160 if (pcie->pf_num == devfn)
3161 return pcie;
3162 }
3163
3164 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3165 hdr = (void *)hdr + hdr->desc_len;
3166 }
Wei Yang950e2952013-05-22 15:58:22 +00003167 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003168}
3169
Sathya Perla92bf14a2013-08-27 16:57:32 +05303170static void be_copy_nic_desc(struct be_resources *res,
3171 struct be_nic_res_desc *desc)
3172{
3173 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3174 res->max_vlans = le16_to_cpu(desc->vlan_count);
3175 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3176 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3177 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3178 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3179 res->max_evt_qs = le16_to_cpu(desc->eq_count);
3180 /* Clear flags that driver is not interested in */
3181 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3182 BE_IF_CAP_FLAGS_WANT;
3183 /* Need 1 RXQ as the default RXQ */
3184 if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs)
3185 res->max_rss_qs -= 1;
3186}
3187
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003188/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303189int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003190{
3191 struct be_mcc_wrb *wrb;
3192 struct be_cmd_req_get_func_config *req;
3193 int status;
3194 struct be_dma_mem cmd;
3195
Suresh Reddyd98ef502013-04-25 00:56:55 +00003196 if (mutex_lock_interruptible(&adapter->mbox_lock))
3197 return -1;
3198
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003199 memset(&cmd, 0, sizeof(struct be_dma_mem));
3200 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
3201 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3202 &cmd.dma);
3203 if (!cmd.va) {
3204 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003205 status = -ENOMEM;
3206 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003207 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003208
3209 wrb = wrb_from_mbox(adapter);
3210 if (!wrb) {
3211 status = -EBUSY;
3212 goto err;
3213 }
3214
3215 req = cmd.va;
3216
3217 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3218 OPCODE_COMMON_GET_FUNC_CONFIG,
3219 cmd.size, wrb, &cmd);
3220
Kalesh AP28710c52013-04-28 22:21:13 +00003221 if (skyhawk_chip(adapter))
3222 req->hdr.version = 1;
3223
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003224 status = be_mbox_notify_wait(adapter);
3225 if (!status) {
3226 struct be_cmd_resp_get_func_config *resp = cmd.va;
3227 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303228 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003229
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303230 desc = be_get_nic_desc(resp->func_param, desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003231 if (!desc) {
3232 status = -EINVAL;
3233 goto err;
3234 }
3235
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003236 adapter->pf_number = desc->pf_num;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303237 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003238 }
3239err:
3240 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003241 if (cmd.va)
3242 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003243 return status;
3244}
3245
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003246/* Uses mbox */
Jingoo Han4188e7d2013-08-05 18:02:02 +09003247static int be_cmd_get_profile_config_mbox(struct be_adapter *adapter,
3248 u8 domain, struct be_dma_mem *cmd)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003249{
3250 struct be_mcc_wrb *wrb;
3251 struct be_cmd_req_get_profile_config *req;
3252 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003253
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003254 if (mutex_lock_interruptible(&adapter->mbox_lock))
3255 return -1;
3256 wrb = wrb_from_mbox(adapter);
3257
3258 req = cmd->va;
3259 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3260 OPCODE_COMMON_GET_PROFILE_CONFIG,
3261 cmd->size, wrb, cmd);
3262
3263 req->type = ACTIVE_PROFILE_TYPE;
3264 req->hdr.domain = domain;
3265 if (!lancer_chip(adapter))
3266 req->hdr.version = 1;
3267
3268 status = be_mbox_notify_wait(adapter);
3269
3270 mutex_unlock(&adapter->mbox_lock);
3271 return status;
3272}
3273
3274/* Uses sync mcc */
Jingoo Han4188e7d2013-08-05 18:02:02 +09003275static int be_cmd_get_profile_config_mccq(struct be_adapter *adapter,
3276 u8 domain, struct be_dma_mem *cmd)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003277{
3278 struct be_mcc_wrb *wrb;
3279 struct be_cmd_req_get_profile_config *req;
3280 int status;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003281
3282 spin_lock_bh(&adapter->mcc_lock);
3283
3284 wrb = wrb_from_mccq(adapter);
3285 if (!wrb) {
3286 status = -EBUSY;
3287 goto err;
3288 }
3289
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003290 req = cmd->va;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003291 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3292 OPCODE_COMMON_GET_PROFILE_CONFIG,
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003293 cmd->size, wrb, cmd);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003294
3295 req->type = ACTIVE_PROFILE_TYPE;
3296 req->hdr.domain = domain;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003297 if (!lancer_chip(adapter))
3298 req->hdr.version = 1;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003299
3300 status = be_mcc_notify_wait(adapter);
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003301
3302err:
3303 spin_unlock_bh(&adapter->mcc_lock);
3304 return status;
3305}
3306
3307/* Uses sync mcc, if MCCQ is already created otherwise mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303308int be_cmd_get_profile_config(struct be_adapter *adapter,
3309 struct be_resources *res, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003310{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303311 struct be_cmd_resp_get_profile_config *resp;
3312 struct be_pcie_res_desc *pcie;
3313 struct be_nic_res_desc *nic;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003314 struct be_queue_info *mccq = &adapter->mcc_obj.q;
3315 struct be_dma_mem cmd;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303316 u32 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003317 int status;
3318
3319 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303320 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3321 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3322 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003323 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003324
3325 if (!mccq->created)
3326 status = be_cmd_get_profile_config_mbox(adapter, domain, &cmd);
3327 else
3328 status = be_cmd_get_profile_config_mccq(adapter, domain, &cmd);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303329 if (status)
3330 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003331
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303332 resp = cmd.va;
3333 desc_count = le32_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003334
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303335 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3336 desc_count);
3337 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303338 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303339
3340 nic = be_get_nic_desc(resp->func_param, desc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303341 if (nic)
3342 be_copy_nic_desc(res, nic);
3343
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003344err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003345 if (cmd.va)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303346 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003347 return status;
3348}
3349
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303350/* Currently only Lancer uses this command and it supports version 0 only
3351 * Uses sync mcc
3352 */
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003353int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
3354 u8 domain)
3355{
3356 struct be_mcc_wrb *wrb;
3357 struct be_cmd_req_set_profile_config *req;
3358 int status;
3359
3360 spin_lock_bh(&adapter->mcc_lock);
3361
3362 wrb = wrb_from_mccq(adapter);
3363 if (!wrb) {
3364 status = -EBUSY;
3365 goto err;
3366 }
3367
3368 req = embedded_payload(wrb);
3369
3370 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3371 OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req),
3372 wrb, NULL);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003373 req->hdr.domain = domain;
3374 req->desc_count = cpu_to_le32(1);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303375 req->nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
3376 req->nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003377 req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV);
3378 req->nic_desc.pf_num = adapter->pf_number;
3379 req->nic_desc.vf_num = domain;
3380
3381 /* Mark fields invalid */
3382 req->nic_desc.unicast_mac_count = 0xFFFF;
3383 req->nic_desc.mcc_count = 0xFFFF;
3384 req->nic_desc.vlan_count = 0xFFFF;
3385 req->nic_desc.mcast_mac_count = 0xFFFF;
3386 req->nic_desc.txq_count = 0xFFFF;
3387 req->nic_desc.rq_count = 0xFFFF;
3388 req->nic_desc.rssq_count = 0xFFFF;
3389 req->nic_desc.lro_count = 0xFFFF;
3390 req->nic_desc.cq_count = 0xFFFF;
3391 req->nic_desc.toe_conn_count = 0xFFFF;
3392 req->nic_desc.eq_count = 0xFFFF;
3393 req->nic_desc.link_param = 0xFF;
3394 req->nic_desc.bw_min = 0xFFFFFFFF;
3395 req->nic_desc.acpi_params = 0xFF;
3396 req->nic_desc.wol_param = 0x0F;
3397
3398 /* Change BW */
3399 req->nic_desc.bw_min = cpu_to_le32(bps);
3400 req->nic_desc.bw_max = cpu_to_le32(bps);
3401 status = be_mcc_notify_wait(adapter);
3402err:
3403 spin_unlock_bh(&adapter->mcc_lock);
3404 return status;
3405}
3406
Sathya Perla4c876612013-02-03 20:30:11 +00003407int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3408 int vf_num)
3409{
3410 struct be_mcc_wrb *wrb;
3411 struct be_cmd_req_get_iface_list *req;
3412 struct be_cmd_resp_get_iface_list *resp;
3413 int status;
3414
3415 spin_lock_bh(&adapter->mcc_lock);
3416
3417 wrb = wrb_from_mccq(adapter);
3418 if (!wrb) {
3419 status = -EBUSY;
3420 goto err;
3421 }
3422 req = embedded_payload(wrb);
3423
3424 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3425 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3426 wrb, NULL);
3427 req->hdr.domain = vf_num + 1;
3428
3429 status = be_mcc_notify_wait(adapter);
3430 if (!status) {
3431 resp = (struct be_cmd_resp_get_iface_list *)req;
3432 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3433 }
3434
3435err:
3436 spin_unlock_bh(&adapter->mcc_lock);
3437 return status;
3438}
3439
Somnath Kotur5c510812013-05-30 02:52:23 +00003440static int lancer_wait_idle(struct be_adapter *adapter)
3441{
3442#define SLIPORT_IDLE_TIMEOUT 30
3443 u32 reg_val;
3444 int status = 0, i;
3445
3446 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
3447 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
3448 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
3449 break;
3450
3451 ssleep(1);
3452 }
3453
3454 if (i == SLIPORT_IDLE_TIMEOUT)
3455 status = -1;
3456
3457 return status;
3458}
3459
3460int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
3461{
3462 int status = 0;
3463
3464 status = lancer_wait_idle(adapter);
3465 if (status)
3466 return status;
3467
3468 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
3469
3470 return status;
3471}
3472
3473/* Routine to check whether dump image is present or not */
3474bool dump_present(struct be_adapter *adapter)
3475{
3476 u32 sliport_status = 0;
3477
3478 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
3479 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
3480}
3481
3482int lancer_initiate_dump(struct be_adapter *adapter)
3483{
3484 int status;
3485
3486 /* give firmware reset and diagnostic dump */
3487 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
3488 PHYSDEV_CONTROL_DD_MASK);
3489 if (status < 0) {
3490 dev_err(&adapter->pdev->dev, "Firmware reset failed\n");
3491 return status;
3492 }
3493
3494 status = lancer_wait_idle(adapter);
3495 if (status)
3496 return status;
3497
3498 if (!dump_present(adapter)) {
3499 dev_err(&adapter->pdev->dev, "Dump image not present\n");
3500 return -1;
3501 }
3502
3503 return 0;
3504}
3505
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003506/* Uses sync mcc */
3507int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
3508{
3509 struct be_mcc_wrb *wrb;
3510 struct be_cmd_enable_disable_vf *req;
3511 int status;
3512
3513 if (!lancer_chip(adapter))
3514 return 0;
3515
3516 spin_lock_bh(&adapter->mcc_lock);
3517
3518 wrb = wrb_from_mccq(adapter);
3519 if (!wrb) {
3520 status = -EBUSY;
3521 goto err;
3522 }
3523
3524 req = embedded_payload(wrb);
3525
3526 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3527 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
3528 wrb, NULL);
3529
3530 req->hdr.domain = domain;
3531 req->enable = 1;
3532 status = be_mcc_notify_wait(adapter);
3533err:
3534 spin_unlock_bh(&adapter->mcc_lock);
3535 return status;
3536}
3537
Somnath Kotur68c45a22013-03-14 02:42:07 +00003538int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
3539{
3540 struct be_mcc_wrb *wrb;
3541 struct be_cmd_req_intr_set *req;
3542 int status;
3543
3544 if (mutex_lock_interruptible(&adapter->mbox_lock))
3545 return -1;
3546
3547 wrb = wrb_from_mbox(adapter);
3548
3549 req = embedded_payload(wrb);
3550
3551 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3552 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
3553 wrb, NULL);
3554
3555 req->intr_enabled = intr_enable;
3556
3557 status = be_mbox_notify_wait(adapter);
3558
3559 mutex_unlock(&adapter->mbox_lock);
3560 return status;
3561}
3562
Parav Pandit6a4ab662012-03-26 14:27:12 +00003563int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
3564 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
3565{
3566 struct be_adapter *adapter = netdev_priv(netdev_handle);
3567 struct be_mcc_wrb *wrb;
3568 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
3569 struct be_cmd_req_hdr *req;
3570 struct be_cmd_resp_hdr *resp;
3571 int status;
3572
3573 spin_lock_bh(&adapter->mcc_lock);
3574
3575 wrb = wrb_from_mccq(adapter);
3576 if (!wrb) {
3577 status = -EBUSY;
3578 goto err;
3579 }
3580 req = embedded_payload(wrb);
3581 resp = embedded_payload(wrb);
3582
3583 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
3584 hdr->opcode, wrb_payload_size, wrb, NULL);
3585 memcpy(req, wrb_payload, wrb_payload_size);
3586 be_dws_cpu_to_le(req, wrb_payload_size);
3587
3588 status = be_mcc_notify_wait(adapter);
3589 if (cmd_status)
3590 *cmd_status = (status & 0xffff);
3591 if (ext_status)
3592 *ext_status = 0;
3593 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
3594 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
3595err:
3596 spin_unlock_bh(&adapter->mcc_lock);
3597 return status;
3598}
3599EXPORT_SYMBOL(be_roce_mcc_cmd);