blob: 9d602f4a09d51ea668423868f65c82e83e8cbabc [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparded2145cd2011-03-16 08:20:46 +00002 * Copyright (C) 2005 - 2011 Emulex
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
10 * Contact Information:
Ajit Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
Parav Pandit6a4ab662012-03-26 14:27:12 +000018#include <linux/module.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070019#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000020#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070021
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000022static struct be_cmd_priv_map cmd_priv_map[] = {
23 {
24 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
25 CMD_SUBSYSTEM_ETH,
26 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
27 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
28 },
29 {
30 OPCODE_COMMON_GET_FLOW_CONTROL,
31 CMD_SUBSYSTEM_COMMON,
32 BE_PRIV_LNKQUERY | BE_PRIV_VHADM |
33 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
34 },
35 {
36 OPCODE_COMMON_SET_FLOW_CONTROL,
37 CMD_SUBSYSTEM_COMMON,
38 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
39 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
40 },
41 {
42 OPCODE_ETH_GET_PPORT_STATS,
43 CMD_SUBSYSTEM_ETH,
44 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
45 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
46 },
47 {
48 OPCODE_COMMON_GET_PHY_DETAILS,
49 CMD_SUBSYSTEM_COMMON,
50 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
51 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
52 }
53};
54
55static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode,
56 u8 subsystem)
57{
58 int i;
59 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
60 u32 cmd_privileges = adapter->cmd_privileges;
61
62 for (i = 0; i < num_entries; i++)
63 if (opcode == cmd_priv_map[i].opcode &&
64 subsystem == cmd_priv_map[i].subsystem)
65 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
66 return false;
67
68 return true;
69}
70
Somnath Kotur3de09452011-09-30 07:25:05 +000071static inline void *embedded_payload(struct be_mcc_wrb *wrb)
72{
73 return wrb->payload.embedded_payload;
74}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000075
Sathya Perla8788fdc2009-07-27 22:52:03 +000076static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000077{
Sathya Perla8788fdc2009-07-27 22:52:03 +000078 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000079 u32 val = 0;
80
Sathya Perla6589ade2011-11-10 19:18:00 +000081 if (be_error(adapter))
Ajit Khaparde7acc2082011-02-11 13:38:17 +000082 return;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000083
Sathya Perla5fb379e2009-06-18 00:02:59 +000084 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
85 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000086
87 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000088 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000089}
90
91/* To check if valid bit is set, check the entire word as we don't know
92 * the endianness of the data (old entry is host endian while a new entry is
93 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000094static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000095{
96 if (compl->flags != 0) {
97 compl->flags = le32_to_cpu(compl->flags);
98 BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
99 return true;
100 } else {
101 return false;
102 }
103}
104
105/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000106static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000107{
108 compl->flags = 0;
109}
110
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000111static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
112{
113 unsigned long addr;
114
115 addr = tag1;
116 addr = ((addr << 16) << 16) | tag0;
117 return (void *)addr;
118}
119
Sathya Perla8788fdc2009-07-27 22:52:03 +0000120static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000121 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000122{
123 u16 compl_status, extd_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000124 struct be_cmd_resp_hdr *resp_hdr;
125 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000126
127 /* Just swap the status to host endian; mcc tag is opaquely copied
128 * from mcc_wrb */
129 be_dws_le_to_cpu(compl, 4);
130
131 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
132 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -0700133
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000134 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
135
136 if (resp_hdr) {
137 opcode = resp_hdr->opcode;
138 subsystem = resp_hdr->subsystem;
139 }
140
141 if (((opcode == OPCODE_COMMON_WRITE_FLASHROM) ||
142 (opcode == OPCODE_COMMON_WRITE_OBJECT)) &&
143 (subsystem == CMD_SUBSYSTEM_COMMON)) {
Sarveshwar Bandidd131e72010-05-25 16:16:32 -0700144 adapter->flash_status = compl_status;
145 complete(&adapter->flash_compl);
146 }
147
Sathya Perlab31c50a2009-09-17 10:30:13 -0700148 if (compl_status == MCC_STATUS_SUCCESS) {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000149 if (((opcode == OPCODE_ETH_GET_STATISTICS) ||
150 (opcode == OPCODE_ETH_GET_PPORT_STATS)) &&
151 (subsystem == CMD_SUBSYSTEM_ETH)) {
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000152 be_parse_stats(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +0000153 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700154 }
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000155 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
156 subsystem == CMD_SUBSYSTEM_COMMON) {
Somnath Kotur3de09452011-09-30 07:25:05 +0000157 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000158 (void *)resp_hdr;
Somnath Kotur3de09452011-09-30 07:25:05 +0000159 adapter->drv_stats.be_on_die_temperature =
160 resp->on_die_temperature;
161 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000162 } else {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000163 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES)
Padmanabh Ratnakar7aeb2152012-07-12 03:56:46 +0000164 adapter->be_get_temp_freq = 0;
Somnath Kotur3de09452011-09-30 07:25:05 +0000165
Sathya Perla2b3f2912011-06-29 23:32:56 +0000166 if (compl_status == MCC_STATUS_NOT_SUPPORTED ||
167 compl_status == MCC_STATUS_ILLEGAL_REQUEST)
168 goto done;
169
170 if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000171 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000172 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000173 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000174 } else {
175 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
176 CQE_STATUS_EXTD_MASK;
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000177 dev_err(&adapter->pdev->dev,
178 "opcode %d-%d failed:status %d-%d\n",
179 opcode, subsystem, compl_status, extd_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000180 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000181 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000182done:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700183 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000184}
185
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000186/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000187static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000188 struct be_async_event_link_state *evt)
189{
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000190 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000191 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000192
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000193 /* Ignore physical link event */
194 if (lancer_chip(adapter) &&
195 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
196 return;
197
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000198 /* For the initial link status do not rely on the ASYNC event as
199 * it may not be received in some cases.
200 */
201 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
202 be_link_status_update(adapter, evt->port_link_status);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000203}
204
Somnath Koturcc4ce022010-10-21 07:11:14 -0700205/* Grp5 CoS Priority evt */
206static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
207 struct be_async_event_grp5_cos_priority *evt)
208{
209 if (evt->valid) {
210 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000211 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700212 adapter->recommended_prio =
213 evt->reco_default_priority << VLAN_PRIO_SHIFT;
214 }
215}
216
Sathya Perla323ff712012-09-28 04:39:43 +0000217/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700218static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
219 struct be_async_event_grp5_qos_link_speed *evt)
220{
Sathya Perla323ff712012-09-28 04:39:43 +0000221 if (adapter->phy.link_speed >= 0 &&
222 evt->physical_port == adapter->port_num)
223 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700224}
225
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000226/*Grp5 PVID evt*/
227static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
228 struct be_async_event_grp5_pvid_state *evt)
229{
230 if (evt->enabled)
Somnath Kotur939cf302011-08-18 21:51:49 -0700231 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000232 else
233 adapter->pvid = 0;
234}
235
Somnath Koturcc4ce022010-10-21 07:11:14 -0700236static void be_async_grp5_evt_process(struct be_adapter *adapter,
237 u32 trailer, struct be_mcc_compl *evt)
238{
239 u8 event_type = 0;
240
241 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
242 ASYNC_TRAILER_EVENT_TYPE_MASK;
243
244 switch (event_type) {
245 case ASYNC_EVENT_COS_PRIORITY:
246 be_async_grp5_cos_priority_process(adapter,
247 (struct be_async_event_grp5_cos_priority *)evt);
248 break;
249 case ASYNC_EVENT_QOS_SPEED:
250 be_async_grp5_qos_speed_process(adapter,
251 (struct be_async_event_grp5_qos_link_speed *)evt);
252 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000253 case ASYNC_EVENT_PVID_STATE:
254 be_async_grp5_pvid_state_process(adapter,
255 (struct be_async_event_grp5_pvid_state *)evt);
256 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700257 default:
258 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
259 break;
260 }
261}
262
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000263static inline bool is_link_state_evt(u32 trailer)
264{
Eric Dumazet807540b2010-09-23 05:40:09 +0000265 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000266 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000267 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000268}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000269
Somnath Koturcc4ce022010-10-21 07:11:14 -0700270static inline bool is_grp5_evt(u32 trailer)
271{
272 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
273 ASYNC_TRAILER_EVENT_CODE_MASK) ==
274 ASYNC_EVENT_CODE_GRP_5);
275}
276
Sathya Perlaefd2e402009-07-27 22:53:10 +0000277static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000278{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000279 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000280 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000281
282 if (be_mcc_compl_is_new(compl)) {
283 queue_tail_inc(mcc_cq);
284 return compl;
285 }
286 return NULL;
287}
288
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000289void be_async_mcc_enable(struct be_adapter *adapter)
290{
291 spin_lock_bh(&adapter->mcc_cq_lock);
292
293 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
294 adapter->mcc_obj.rearm_cq = true;
295
296 spin_unlock_bh(&adapter->mcc_cq_lock);
297}
298
299void be_async_mcc_disable(struct be_adapter *adapter)
300{
301 adapter->mcc_obj.rearm_cq = false;
302}
303
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000304int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000305{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000306 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000307 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000308 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000309
Amerigo Wang072a9c42012-08-24 21:41:11 +0000310 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla8788fdc2009-07-27 22:52:03 +0000311 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000312 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
313 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000314 if (is_link_state_evt(compl->flags))
315 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000316 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700317 else if (is_grp5_evt(compl->flags))
318 be_async_grp5_evt_process(adapter,
319 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700320 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000321 status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000322 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000323 }
324 be_mcc_compl_use(compl);
325 num++;
326 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700327
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000328 if (num)
329 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
330
Amerigo Wang072a9c42012-08-24 21:41:11 +0000331 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000332 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000333}
334
Sathya Perla6ac7b682009-06-18 00:05:54 +0000335/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700336static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000337{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700338#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000339 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800340 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700341
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800342 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000343 if (be_error(adapter))
344 return -EIO;
345
Amerigo Wang072a9c42012-08-24 21:41:11 +0000346 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000347 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000348 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800349
350 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000351 break;
352 udelay(100);
353 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700354 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000355 dev_err(&adapter->pdev->dev, "FW not responding\n");
356 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000357 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700358 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800359 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000360}
361
362/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700363static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000364{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000365 int status;
366 struct be_mcc_wrb *wrb;
367 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
368 u16 index = mcc_obj->q.head;
369 struct be_cmd_resp_hdr *resp;
370
371 index_dec(&index, mcc_obj->q.len);
372 wrb = queue_index_node(&mcc_obj->q, index);
373
374 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
375
Sathya Perla8788fdc2009-07-27 22:52:03 +0000376 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000377
378 status = be_mcc_wait_compl(adapter);
379 if (status == -EIO)
380 goto out;
381
382 status = resp->status;
383out:
384 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000385}
386
Sathya Perla5f0b8492009-07-27 22:52:56 +0000387static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700388{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000389 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700390 u32 ready;
391
392 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000393 if (be_error(adapter))
394 return -EIO;
395
Sathya Perlacf588472010-02-14 21:22:01 +0000396 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000397 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000398 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000399
400 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700401 if (ready)
402 break;
403
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000404 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000405 dev_err(&adapter->pdev->dev, "FW not responding\n");
406 adapter->fw_timeout = true;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000407 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700408 return -1;
409 }
410
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000411 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000412 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700413 } while (true);
414
415 return 0;
416}
417
418/*
419 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000420 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700421 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700422static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700423{
424 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700425 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000426 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
427 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700428 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000429 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700430
Sathya Perlacf588472010-02-14 21:22:01 +0000431 /* wait for ready to be set */
432 status = be_mbox_db_ready_wait(adapter, db);
433 if (status != 0)
434 return status;
435
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700436 val |= MPU_MAILBOX_DB_HI_MASK;
437 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
438 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
439 iowrite32(val, db);
440
441 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000442 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700443 if (status != 0)
444 return status;
445
446 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700447 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
448 val |= (u32)(mbox_mem->dma >> 4) << 2;
449 iowrite32(val, db);
450
Sathya Perla5f0b8492009-07-27 22:52:56 +0000451 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452 if (status != 0)
453 return status;
454
Sathya Perla5fb379e2009-06-18 00:02:59 +0000455 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000456 if (be_mcc_compl_is_new(compl)) {
457 status = be_mcc_compl_process(adapter, &mbox->compl);
458 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000459 if (status)
460 return status;
461 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000462 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700463 return -1;
464 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000465 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700466}
467
Sathya Perla8788fdc2009-07-27 22:52:03 +0000468static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700469{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000470 u32 sem;
471
472 if (lancer_chip(adapter))
473 sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
474 else
475 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700476
477 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
478 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
479 return -1;
480 else
481 return 0;
482}
483
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000484int lancer_wait_ready(struct be_adapter *adapter)
485{
486#define SLIPORT_READY_TIMEOUT 30
487 u32 sliport_status;
488 int status = 0, i;
489
490 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
491 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
492 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
493 break;
494
495 msleep(1000);
496 }
497
498 if (i == SLIPORT_READY_TIMEOUT)
499 status = -1;
500
501 return status;
502}
503
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000504static bool lancer_provisioning_error(struct be_adapter *adapter)
505{
506 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
507 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
508 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
509 sliport_err1 = ioread32(adapter->db +
510 SLIPORT_ERROR1_OFFSET);
511 sliport_err2 = ioread32(adapter->db +
512 SLIPORT_ERROR2_OFFSET);
513
514 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
515 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
516 return true;
517 }
518 return false;
519}
520
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000521int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
522{
523 int status;
524 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000525 bool resource_error;
526
527 resource_error = lancer_provisioning_error(adapter);
528 if (resource_error)
529 return -1;
530
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000531 status = lancer_wait_ready(adapter);
532 if (!status) {
533 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
534 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
535 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
536 if (err && reset_needed) {
537 iowrite32(SLI_PORT_CONTROL_IP_MASK,
538 adapter->db + SLIPORT_CONTROL_OFFSET);
539
540 /* check adapter has corrected the error */
541 status = lancer_wait_ready(adapter);
542 sliport_status = ioread32(adapter->db +
543 SLIPORT_STATUS_OFFSET);
544 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
545 SLIPORT_STATUS_RN_MASK);
546 if (status || sliport_status)
547 status = -1;
548 } else if (err || reset_needed) {
549 status = -1;
550 }
551 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000552 /* Stop error recovery if error is not recoverable.
553 * No resource error is temporary errors and will go away
554 * when PF provisions resources.
555 */
556 resource_error = lancer_provisioning_error(adapter);
557 if (status == -1 && !resource_error)
558 adapter->eeh_error = true;
559
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000560 return status;
561}
562
563int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700564{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000565 u16 stage;
566 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000567 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700568
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000569 if (lancer_chip(adapter)) {
570 status = lancer_wait_ready(adapter);
571 return status;
572 }
573
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000574 do {
575 status = be_POST_stage_get(adapter, &stage);
576 if (status) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000577 dev_err(dev, "POST error; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000578 return -1;
579 } else if (stage != POST_STAGE_ARMFW_RDY) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000580 if (msleep_interruptible(2000)) {
581 dev_err(dev, "Waiting for POST aborted\n");
582 return -EINTR;
583 }
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000584 timeout += 2;
585 } else {
586 return 0;
587 }
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000588 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700589
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000590 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000591 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700592}
593
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700594
595static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
596{
597 return &wrb->payload.sgl[0];
598}
599
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700600
601/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000602/* mem will be NULL for embedded commands */
603static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
604 u8 subsystem, u8 opcode, int cmd_len,
605 struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700606{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000607 struct be_sge *sge;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000608 unsigned long addr = (unsigned long)req_hdr;
609 u64 req_addr = addr;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000610
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700611 req_hdr->opcode = opcode;
612 req_hdr->subsystem = subsystem;
613 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000614 req_hdr->version = 0;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000615
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000616 wrb->tag0 = req_addr & 0xFFFFFFFF;
617 wrb->tag1 = upper_32_bits(req_addr);
618
Somnath Kotur106df1e2011-10-27 07:12:13 +0000619 wrb->payload_length = cmd_len;
620 if (mem) {
621 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
622 MCC_WRB_SGE_CNT_SHIFT;
623 sge = nonembedded_sgl(wrb);
624 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
625 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
626 sge->len = cpu_to_le32(mem->size);
627 } else
628 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
629 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700630}
631
632static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
633 struct be_dma_mem *mem)
634{
635 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
636 u64 dma = (u64)mem->dma;
637
638 for (i = 0; i < buf_pages; i++) {
639 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
640 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
641 dma += PAGE_SIZE_4K;
642 }
643}
644
645/* Converts interrupt delay in microseconds to multiplier value */
646static u32 eq_delay_to_mult(u32 usec_delay)
647{
648#define MAX_INTR_RATE 651042
649 const u32 round = 10;
650 u32 multiplier;
651
652 if (usec_delay == 0)
653 multiplier = 0;
654 else {
655 u32 interrupt_rate = 1000000 / usec_delay;
656 /* Max delay, corresponding to the lowest interrupt rate */
657 if (interrupt_rate == 0)
658 multiplier = 1023;
659 else {
660 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
661 multiplier /= interrupt_rate;
662 /* Round the multiplier to the closest value.*/
663 multiplier = (multiplier + round/2) / round;
664 multiplier = min(multiplier, (u32)1023);
665 }
666 }
667 return multiplier;
668}
669
Sathya Perlab31c50a2009-09-17 10:30:13 -0700670static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700671{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700672 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
673 struct be_mcc_wrb *wrb
674 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
675 memset(wrb, 0, sizeof(*wrb));
676 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677}
678
Sathya Perlab31c50a2009-09-17 10:30:13 -0700679static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000680{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700681 struct be_queue_info *mccq = &adapter->mcc_obj.q;
682 struct be_mcc_wrb *wrb;
683
Sathya Perla713d03942009-11-22 22:02:45 +0000684 if (atomic_read(&mccq->used) >= mccq->len) {
685 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
686 return NULL;
687 }
688
Sathya Perlab31c50a2009-09-17 10:30:13 -0700689 wrb = queue_head_node(mccq);
690 queue_head_inc(mccq);
691 atomic_inc(&mccq->used);
692 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000693 return wrb;
694}
695
Sathya Perla2243e2e2009-11-22 22:02:03 +0000696/* Tell fw we're about to start firing cmds by writing a
697 * special pattern across the wrb hdr; uses mbox
698 */
699int be_cmd_fw_init(struct be_adapter *adapter)
700{
701 u8 *wrb;
702 int status;
703
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000704 if (lancer_chip(adapter))
705 return 0;
706
Ivan Vecera29849612010-12-14 05:43:19 +0000707 if (mutex_lock_interruptible(&adapter->mbox_lock))
708 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000709
710 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000711 *wrb++ = 0xFF;
712 *wrb++ = 0x12;
713 *wrb++ = 0x34;
714 *wrb++ = 0xFF;
715 *wrb++ = 0xFF;
716 *wrb++ = 0x56;
717 *wrb++ = 0x78;
718 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000719
720 status = be_mbox_notify_wait(adapter);
721
Ivan Vecera29849612010-12-14 05:43:19 +0000722 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000723 return status;
724}
725
726/* Tell fw we're done with firing cmds by writing a
727 * special pattern across the wrb hdr; uses mbox
728 */
729int be_cmd_fw_clean(struct be_adapter *adapter)
730{
731 u8 *wrb;
732 int status;
733
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000734 if (lancer_chip(adapter))
735 return 0;
736
Ivan Vecera29849612010-12-14 05:43:19 +0000737 if (mutex_lock_interruptible(&adapter->mbox_lock))
738 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000739
740 wrb = (u8 *)wrb_from_mbox(adapter);
741 *wrb++ = 0xFF;
742 *wrb++ = 0xAA;
743 *wrb++ = 0xBB;
744 *wrb++ = 0xFF;
745 *wrb++ = 0xFF;
746 *wrb++ = 0xCC;
747 *wrb++ = 0xDD;
748 *wrb = 0xFF;
749
750 status = be_mbox_notify_wait(adapter);
751
Ivan Vecera29849612010-12-14 05:43:19 +0000752 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000753 return status;
754}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000755
Sathya Perla8788fdc2009-07-27 22:52:03 +0000756int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700757 struct be_queue_info *eq, int eq_delay)
758{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700759 struct be_mcc_wrb *wrb;
760 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700761 struct be_dma_mem *q_mem = &eq->dma_mem;
762 int status;
763
Ivan Vecera29849612010-12-14 05:43:19 +0000764 if (mutex_lock_interruptible(&adapter->mbox_lock))
765 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700766
767 wrb = wrb_from_mbox(adapter);
768 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700769
Somnath Kotur106df1e2011-10-27 07:12:13 +0000770 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
771 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700772
773 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
774
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700775 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
776 /* 4byte eqe*/
777 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
778 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
779 __ilog2_u32(eq->len/256));
780 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
781 eq_delay_to_mult(eq_delay));
782 be_dws_cpu_to_le(req->context, sizeof(req->context));
783
784 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
785
Sathya Perlab31c50a2009-09-17 10:30:13 -0700786 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700787 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700788 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700789 eq->id = le16_to_cpu(resp->eq_id);
790 eq->created = true;
791 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700792
Ivan Vecera29849612010-12-14 05:43:19 +0000793 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700794 return status;
795}
796
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000797/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000798int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000799 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700800{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700801 struct be_mcc_wrb *wrb;
802 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700803 int status;
804
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000805 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700806
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000807 wrb = wrb_from_mccq(adapter);
808 if (!wrb) {
809 status = -EBUSY;
810 goto err;
811 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700812 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700813
Somnath Kotur106df1e2011-10-27 07:12:13 +0000814 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
815 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000816 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700817 if (permanent) {
818 req->permanent = 1;
819 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700820 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000821 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700822 req->permanent = 0;
823 }
824
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000825 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700826 if (!status) {
827 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700828 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700829 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700830
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000831err:
832 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700833 return status;
834}
835
Sathya Perlab31c50a2009-09-17 10:30:13 -0700836/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000837int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000838 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700839{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700840 struct be_mcc_wrb *wrb;
841 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700842 int status;
843
Sathya Perlab31c50a2009-09-17 10:30:13 -0700844 spin_lock_bh(&adapter->mcc_lock);
845
846 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000847 if (!wrb) {
848 status = -EBUSY;
849 goto err;
850 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700851 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700852
Somnath Kotur106df1e2011-10-27 07:12:13 +0000853 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
854 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700855
Ajit Khapardef8617e02011-02-11 13:36:37 +0000856 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700857 req->if_id = cpu_to_le32(if_id);
858 memcpy(req->mac_address, mac_addr, ETH_ALEN);
859
Sathya Perlab31c50a2009-09-17 10:30:13 -0700860 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700861 if (!status) {
862 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
863 *pmac_id = le32_to_cpu(resp->pmac_id);
864 }
865
Sathya Perla713d03942009-11-22 22:02:45 +0000866err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700867 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000868
869 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
870 status = -EPERM;
871
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700872 return status;
873}
874
Sathya Perlab31c50a2009-09-17 10:30:13 -0700875/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000876int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700877{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700878 struct be_mcc_wrb *wrb;
879 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700880 int status;
881
Sathya Perla30128032011-11-10 19:17:57 +0000882 if (pmac_id == -1)
883 return 0;
884
Sathya Perlab31c50a2009-09-17 10:30:13 -0700885 spin_lock_bh(&adapter->mcc_lock);
886
887 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000888 if (!wrb) {
889 status = -EBUSY;
890 goto err;
891 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700892 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700893
Somnath Kotur106df1e2011-10-27 07:12:13 +0000894 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
895 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700896
Ajit Khapardef8617e02011-02-11 13:36:37 +0000897 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700898 req->if_id = cpu_to_le32(if_id);
899 req->pmac_id = cpu_to_le32(pmac_id);
900
Sathya Perlab31c50a2009-09-17 10:30:13 -0700901 status = be_mcc_notify_wait(adapter);
902
Sathya Perla713d03942009-11-22 22:02:45 +0000903err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700904 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700905 return status;
906}
907
Sathya Perlab31c50a2009-09-17 10:30:13 -0700908/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000909int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
910 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700911{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700912 struct be_mcc_wrb *wrb;
913 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700914 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700915 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700916 int status;
917
Ivan Vecera29849612010-12-14 05:43:19 +0000918 if (mutex_lock_interruptible(&adapter->mbox_lock))
919 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700920
921 wrb = wrb_from_mbox(adapter);
922 req = embedded_payload(wrb);
923 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700924
Somnath Kotur106df1e2011-10-27 07:12:13 +0000925 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
926 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700927
928 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000929 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000930 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000931 req->page_size = 1; /* 1 for 4K */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000932 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
933 no_delay);
934 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
935 __ilog2_u32(cq->len/256));
936 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
937 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
938 ctxt, 1);
939 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
940 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000941 } else {
942 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
943 coalesce_wm);
944 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
945 ctxt, no_delay);
946 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
947 __ilog2_u32(cq->len/256));
948 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000949 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
950 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000951 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700952
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700953 be_dws_cpu_to_le(ctxt, sizeof(req->context));
954
955 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
956
Sathya Perlab31c50a2009-09-17 10:30:13 -0700957 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700958 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700959 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700960 cq->id = le16_to_cpu(resp->cq_id);
961 cq->created = true;
962 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700963
Ivan Vecera29849612010-12-14 05:43:19 +0000964 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000965
966 return status;
967}
968
969static u32 be_encoded_q_len(int q_len)
970{
971 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
972 if (len_encoded == 16)
973 len_encoded = 0;
974 return len_encoded;
975}
976
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000977int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000978 struct be_queue_info *mccq,
979 struct be_queue_info *cq)
980{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700981 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000982 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000983 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700984 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000985 int status;
986
Ivan Vecera29849612010-12-14 05:43:19 +0000987 if (mutex_lock_interruptible(&adapter->mbox_lock))
988 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700989
990 wrb = wrb_from_mbox(adapter);
991 req = embedded_payload(wrb);
992 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000993
Somnath Kotur106df1e2011-10-27 07:12:13 +0000994 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
995 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000996
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000997 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000998 if (lancer_chip(adapter)) {
999 req->hdr.version = 1;
1000 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001001
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001002 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
1003 be_encoded_q_len(mccq->len));
1004 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
1005 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
1006 ctxt, cq->id);
1007 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
1008 ctxt, 1);
1009
1010 } else {
1011 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1012 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1013 be_encoded_q_len(mccq->len));
1014 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1015 }
1016
Somnath Koturcc4ce022010-10-21 07:11:14 -07001017 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001018 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001019 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1020
1021 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1022
Sathya Perlab31c50a2009-09-17 10:30:13 -07001023 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001024 if (!status) {
1025 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1026 mccq->id = le16_to_cpu(resp->id);
1027 mccq->created = true;
1028 }
Ivan Vecera29849612010-12-14 05:43:19 +00001029 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001030
1031 return status;
1032}
1033
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001034int be_cmd_mccq_org_create(struct be_adapter *adapter,
1035 struct be_queue_info *mccq,
1036 struct be_queue_info *cq)
1037{
1038 struct be_mcc_wrb *wrb;
1039 struct be_cmd_req_mcc_create *req;
1040 struct be_dma_mem *q_mem = &mccq->dma_mem;
1041 void *ctxt;
1042 int status;
1043
1044 if (mutex_lock_interruptible(&adapter->mbox_lock))
1045 return -1;
1046
1047 wrb = wrb_from_mbox(adapter);
1048 req = embedded_payload(wrb);
1049 ctxt = &req->context;
1050
Somnath Kotur106df1e2011-10-27 07:12:13 +00001051 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1052 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001053
1054 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1055
1056 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1057 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1058 be_encoded_q_len(mccq->len));
1059 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1060
1061 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1062
1063 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1064
1065 status = be_mbox_notify_wait(adapter);
1066 if (!status) {
1067 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1068 mccq->id = le16_to_cpu(resp->id);
1069 mccq->created = true;
1070 }
1071
1072 mutex_unlock(&adapter->mbox_lock);
1073 return status;
1074}
1075
1076int be_cmd_mccq_create(struct be_adapter *adapter,
1077 struct be_queue_info *mccq,
1078 struct be_queue_info *cq)
1079{
1080 int status;
1081
1082 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
1083 if (status && !lancer_chip(adapter)) {
1084 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1085 "or newer to avoid conflicting priorities between NIC "
1086 "and FCoE traffic");
1087 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1088 }
1089 return status;
1090}
1091
Sathya Perla8788fdc2009-07-27 22:52:03 +00001092int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001093 struct be_queue_info *txq,
1094 struct be_queue_info *cq)
1095{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001096 struct be_mcc_wrb *wrb;
1097 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001098 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001099 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001100 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001101
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001102 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001103
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001104 wrb = wrb_from_mccq(adapter);
1105 if (!wrb) {
1106 status = -EBUSY;
1107 goto err;
1108 }
1109
Sathya Perlab31c50a2009-09-17 10:30:13 -07001110 req = embedded_payload(wrb);
1111 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001112
Somnath Kotur106df1e2011-10-27 07:12:13 +00001113 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1114 OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001115
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001116 if (lancer_chip(adapter)) {
1117 req->hdr.version = 1;
1118 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
1119 adapter->if_handle);
1120 }
1121
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001122 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1123 req->ulp_num = BE_ULP1_NUM;
1124 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
1125
Sathya Perlab31c50a2009-09-17 10:30:13 -07001126 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
1127 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001128 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
1129 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
1130
1131 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1132
1133 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1134
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001135 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001136 if (!status) {
1137 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
1138 txq->id = le16_to_cpu(resp->cid);
1139 txq->created = true;
1140 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001141
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001142err:
1143 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001144
1145 return status;
1146}
1147
Sathya Perla482c9e72011-06-29 23:33:17 +00001148/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001149int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001150 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001151 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001152{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001153 struct be_mcc_wrb *wrb;
1154 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001155 struct be_dma_mem *q_mem = &rxq->dma_mem;
1156 int status;
1157
Sathya Perla482c9e72011-06-29 23:33:17 +00001158 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001159
Sathya Perla482c9e72011-06-29 23:33:17 +00001160 wrb = wrb_from_mccq(adapter);
1161 if (!wrb) {
1162 status = -EBUSY;
1163 goto err;
1164 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001165 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001166
Somnath Kotur106df1e2011-10-27 07:12:13 +00001167 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1168 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001169
1170 req->cq_id = cpu_to_le16(cq_id);
1171 req->frag_size = fls(frag_size) - 1;
1172 req->num_pages = 2;
1173 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1174 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001175 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001176 req->rss_queue = cpu_to_le32(rss);
1177
Sathya Perla482c9e72011-06-29 23:33:17 +00001178 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001179 if (!status) {
1180 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1181 rxq->id = le16_to_cpu(resp->id);
1182 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001183 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001184 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001185
Sathya Perla482c9e72011-06-29 23:33:17 +00001186err:
1187 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001188 return status;
1189}
1190
Sathya Perlab31c50a2009-09-17 10:30:13 -07001191/* Generic destroyer function for all types of queues
1192 * Uses Mbox
1193 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001194int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001195 int queue_type)
1196{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001197 struct be_mcc_wrb *wrb;
1198 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001199 u8 subsys = 0, opcode = 0;
1200 int status;
1201
Ivan Vecera29849612010-12-14 05:43:19 +00001202 if (mutex_lock_interruptible(&adapter->mbox_lock))
1203 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001204
Sathya Perlab31c50a2009-09-17 10:30:13 -07001205 wrb = wrb_from_mbox(adapter);
1206 req = embedded_payload(wrb);
1207
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001208 switch (queue_type) {
1209 case QTYPE_EQ:
1210 subsys = CMD_SUBSYSTEM_COMMON;
1211 opcode = OPCODE_COMMON_EQ_DESTROY;
1212 break;
1213 case QTYPE_CQ:
1214 subsys = CMD_SUBSYSTEM_COMMON;
1215 opcode = OPCODE_COMMON_CQ_DESTROY;
1216 break;
1217 case QTYPE_TXQ:
1218 subsys = CMD_SUBSYSTEM_ETH;
1219 opcode = OPCODE_ETH_TX_DESTROY;
1220 break;
1221 case QTYPE_RXQ:
1222 subsys = CMD_SUBSYSTEM_ETH;
1223 opcode = OPCODE_ETH_RX_DESTROY;
1224 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001225 case QTYPE_MCCQ:
1226 subsys = CMD_SUBSYSTEM_COMMON;
1227 opcode = OPCODE_COMMON_MCC_DESTROY;
1228 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001229 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001230 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001231 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001232
Somnath Kotur106df1e2011-10-27 07:12:13 +00001233 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1234 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001235 req->id = cpu_to_le16(q->id);
1236
Sathya Perlab31c50a2009-09-17 10:30:13 -07001237 status = be_mbox_notify_wait(adapter);
Sathya Perla482c9e72011-06-29 23:33:17 +00001238 if (!status)
1239 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001240
Ivan Vecera29849612010-12-14 05:43:19 +00001241 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001242 return status;
1243}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001244
Sathya Perla482c9e72011-06-29 23:33:17 +00001245/* Uses MCC */
1246int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1247{
1248 struct be_mcc_wrb *wrb;
1249 struct be_cmd_req_q_destroy *req;
1250 int status;
1251
1252 spin_lock_bh(&adapter->mcc_lock);
1253
1254 wrb = wrb_from_mccq(adapter);
1255 if (!wrb) {
1256 status = -EBUSY;
1257 goto err;
1258 }
1259 req = embedded_payload(wrb);
1260
Somnath Kotur106df1e2011-10-27 07:12:13 +00001261 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1262 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001263 req->id = cpu_to_le16(q->id);
1264
1265 status = be_mcc_notify_wait(adapter);
1266 if (!status)
1267 q->created = false;
1268
1269err:
1270 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001271 return status;
1272}
1273
Sathya Perlab31c50a2009-09-17 10:30:13 -07001274/* Create an rx filtering policy configuration on an i/f
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001275 * Uses MCCQ
Sathya Perlab31c50a2009-09-17 10:30:13 -07001276 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001277int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001278 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001279{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001280 struct be_mcc_wrb *wrb;
1281 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001282 int status;
1283
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001284 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001285
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001286 wrb = wrb_from_mccq(adapter);
1287 if (!wrb) {
1288 status = -EBUSY;
1289 goto err;
1290 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001291 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001292
Somnath Kotur106df1e2011-10-27 07:12:13 +00001293 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1294 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001295 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001296 req->capability_flags = cpu_to_le32(cap_flags);
1297 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001298
1299 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001301 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001302 if (!status) {
1303 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1304 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001305 }
1306
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001307err:
1308 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001309 return status;
1310}
1311
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001312/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001313int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001314{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001315 struct be_mcc_wrb *wrb;
1316 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001317 int status;
1318
Sathya Perla30128032011-11-10 19:17:57 +00001319 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001320 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001321
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001322 spin_lock_bh(&adapter->mcc_lock);
1323
1324 wrb = wrb_from_mccq(adapter);
1325 if (!wrb) {
1326 status = -EBUSY;
1327 goto err;
1328 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001329 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001330
Somnath Kotur106df1e2011-10-27 07:12:13 +00001331 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1332 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001333 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001334 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001335
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001336 status = be_mcc_notify_wait(adapter);
1337err:
1338 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001339 return status;
1340}
1341
1342/* Get stats is a non embedded command: the request is not embedded inside
1343 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001344 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001345 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001346int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001347{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001348 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001349 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001350 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001351
Sathya Perlab31c50a2009-09-17 10:30:13 -07001352 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001353
Sathya Perlab31c50a2009-09-17 10:30:13 -07001354 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001355 if (!wrb) {
1356 status = -EBUSY;
1357 goto err;
1358 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001359 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001360
Somnath Kotur106df1e2011-10-27 07:12:13 +00001361 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1362 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001363
1364 if (adapter->generation == BE_GEN3)
1365 hdr->version = 1;
1366
Sathya Perlab31c50a2009-09-17 10:30:13 -07001367 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001368 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369
Sathya Perla713d03942009-11-22 22:02:45 +00001370err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001371 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001372 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001373}
1374
Selvin Xavier005d5692011-05-16 07:36:35 +00001375/* Lancer Stats */
1376int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1377 struct be_dma_mem *nonemb_cmd)
1378{
1379
1380 struct be_mcc_wrb *wrb;
1381 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001382 int status = 0;
1383
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001384 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1385 CMD_SUBSYSTEM_ETH))
1386 return -EPERM;
1387
Selvin Xavier005d5692011-05-16 07:36:35 +00001388 spin_lock_bh(&adapter->mcc_lock);
1389
1390 wrb = wrb_from_mccq(adapter);
1391 if (!wrb) {
1392 status = -EBUSY;
1393 goto err;
1394 }
1395 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001396
Somnath Kotur106df1e2011-10-27 07:12:13 +00001397 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1398 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1399 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001400
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001401 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001402 req->cmd_params.params.reset_stats = 0;
1403
Selvin Xavier005d5692011-05-16 07:36:35 +00001404 be_mcc_notify(adapter);
1405 adapter->stats_cmd_sent = true;
1406
1407err:
1408 spin_unlock_bh(&adapter->mcc_lock);
1409 return status;
1410}
1411
Sathya Perla323ff712012-09-28 04:39:43 +00001412static int be_mac_to_link_speed(int mac_speed)
1413{
1414 switch (mac_speed) {
1415 case PHY_LINK_SPEED_ZERO:
1416 return 0;
1417 case PHY_LINK_SPEED_10MBPS:
1418 return 10;
1419 case PHY_LINK_SPEED_100MBPS:
1420 return 100;
1421 case PHY_LINK_SPEED_1GBPS:
1422 return 1000;
1423 case PHY_LINK_SPEED_10GBPS:
1424 return 10000;
1425 }
1426 return 0;
1427}
1428
1429/* Uses synchronous mcc
1430 * Returns link_speed in Mbps
1431 */
1432int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1433 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001434{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001435 struct be_mcc_wrb *wrb;
1436 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001437 int status;
1438
Sathya Perlab31c50a2009-09-17 10:30:13 -07001439 spin_lock_bh(&adapter->mcc_lock);
1440
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001441 if (link_status)
1442 *link_status = LINK_DOWN;
1443
Sathya Perlab31c50a2009-09-17 10:30:13 -07001444 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001445 if (!wrb) {
1446 status = -EBUSY;
1447 goto err;
1448 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001449 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001450
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001451 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1452 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1453
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001454 if (adapter->generation == BE_GEN3 || lancer_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001455 req->hdr.version = 1;
1456
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001457 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001458
Sathya Perlab31c50a2009-09-17 10:30:13 -07001459 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001460 if (!status) {
1461 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sathya Perla323ff712012-09-28 04:39:43 +00001462 if (link_speed) {
1463 *link_speed = resp->link_speed ?
1464 le16_to_cpu(resp->link_speed) * 10 :
1465 be_mac_to_link_speed(resp->mac_speed);
1466
1467 if (!resp->logical_link_status)
1468 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001469 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001470 if (link_status)
1471 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001472 }
1473
Sathya Perla713d03942009-11-22 22:02:45 +00001474err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001475 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001476 return status;
1477}
1478
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001479/* Uses synchronous mcc */
1480int be_cmd_get_die_temperature(struct be_adapter *adapter)
1481{
1482 struct be_mcc_wrb *wrb;
1483 struct be_cmd_req_get_cntl_addnl_attribs *req;
1484 int status;
1485
1486 spin_lock_bh(&adapter->mcc_lock);
1487
1488 wrb = wrb_from_mccq(adapter);
1489 if (!wrb) {
1490 status = -EBUSY;
1491 goto err;
1492 }
1493 req = embedded_payload(wrb);
1494
Somnath Kotur106df1e2011-10-27 07:12:13 +00001495 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1496 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1497 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001498
Somnath Kotur3de09452011-09-30 07:25:05 +00001499 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001500
1501err:
1502 spin_unlock_bh(&adapter->mcc_lock);
1503 return status;
1504}
1505
Somnath Kotur311fddc2011-03-16 21:22:43 +00001506/* Uses synchronous mcc */
1507int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1508{
1509 struct be_mcc_wrb *wrb;
1510 struct be_cmd_req_get_fat *req;
1511 int status;
1512
1513 spin_lock_bh(&adapter->mcc_lock);
1514
1515 wrb = wrb_from_mccq(adapter);
1516 if (!wrb) {
1517 status = -EBUSY;
1518 goto err;
1519 }
1520 req = embedded_payload(wrb);
1521
Somnath Kotur106df1e2011-10-27 07:12:13 +00001522 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1523 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001524 req->fat_operation = cpu_to_le32(QUERY_FAT);
1525 status = be_mcc_notify_wait(adapter);
1526 if (!status) {
1527 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1528 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001529 *log_size = le32_to_cpu(resp->log_size) -
1530 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001531 }
1532err:
1533 spin_unlock_bh(&adapter->mcc_lock);
1534 return status;
1535}
1536
1537void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1538{
1539 struct be_dma_mem get_fat_cmd;
1540 struct be_mcc_wrb *wrb;
1541 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001542 u32 offset = 0, total_size, buf_size,
1543 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001544 int status;
1545
1546 if (buf_len == 0)
1547 return;
1548
1549 total_size = buf_len;
1550
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001551 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1552 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1553 get_fat_cmd.size,
1554 &get_fat_cmd.dma);
1555 if (!get_fat_cmd.va) {
1556 status = -ENOMEM;
1557 dev_err(&adapter->pdev->dev,
1558 "Memory allocation failure while retrieving FAT data\n");
1559 return;
1560 }
1561
Somnath Kotur311fddc2011-03-16 21:22:43 +00001562 spin_lock_bh(&adapter->mcc_lock);
1563
Somnath Kotur311fddc2011-03-16 21:22:43 +00001564 while (total_size) {
1565 buf_size = min(total_size, (u32)60*1024);
1566 total_size -= buf_size;
1567
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001568 wrb = wrb_from_mccq(adapter);
1569 if (!wrb) {
1570 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001571 goto err;
1572 }
1573 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001574
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001575 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001576 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1577 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1578 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001579
1580 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1581 req->read_log_offset = cpu_to_le32(log_offset);
1582 req->read_log_length = cpu_to_le32(buf_size);
1583 req->data_buffer_size = cpu_to_le32(buf_size);
1584
1585 status = be_mcc_notify_wait(adapter);
1586 if (!status) {
1587 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1588 memcpy(buf + offset,
1589 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001590 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001591 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001592 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001593 goto err;
1594 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001595 offset += buf_size;
1596 log_offset += buf_size;
1597 }
1598err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001599 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1600 get_fat_cmd.va,
1601 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001602 spin_unlock_bh(&adapter->mcc_lock);
1603}
1604
Sathya Perla04b71172011-09-27 13:30:27 -04001605/* Uses synchronous mcc */
1606int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1607 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001608{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001609 struct be_mcc_wrb *wrb;
1610 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001611 int status;
1612
Sathya Perla04b71172011-09-27 13:30:27 -04001613 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001614
Sathya Perla04b71172011-09-27 13:30:27 -04001615 wrb = wrb_from_mccq(adapter);
1616 if (!wrb) {
1617 status = -EBUSY;
1618 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001619 }
1620
Sathya Perla04b71172011-09-27 13:30:27 -04001621 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001622
Somnath Kotur106df1e2011-10-27 07:12:13 +00001623 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1624 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001625 status = be_mcc_notify_wait(adapter);
1626 if (!status) {
1627 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1628 strcpy(fw_ver, resp->firmware_version_string);
1629 if (fw_on_flash)
1630 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1631 }
1632err:
1633 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001634 return status;
1635}
1636
Sathya Perlab31c50a2009-09-17 10:30:13 -07001637/* set the EQ delay interval of an EQ to specified value
1638 * Uses async mcc
1639 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001640int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001641{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001642 struct be_mcc_wrb *wrb;
1643 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001644 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001645
Sathya Perlab31c50a2009-09-17 10:30:13 -07001646 spin_lock_bh(&adapter->mcc_lock);
1647
1648 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001649 if (!wrb) {
1650 status = -EBUSY;
1651 goto err;
1652 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001653 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001654
Somnath Kotur106df1e2011-10-27 07:12:13 +00001655 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1656 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001657
1658 req->num_eq = cpu_to_le32(1);
1659 req->delay[0].eq_id = cpu_to_le32(eq_id);
1660 req->delay[0].phase = 0;
1661 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1662
Sathya Perlab31c50a2009-09-17 10:30:13 -07001663 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001664
Sathya Perla713d03942009-11-22 22:02:45 +00001665err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001666 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001667 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001668}
1669
Sathya Perlab31c50a2009-09-17 10:30:13 -07001670/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001671int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001672 u32 num, bool untagged, bool promiscuous)
1673{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001674 struct be_mcc_wrb *wrb;
1675 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001676 int status;
1677
Sathya Perlab31c50a2009-09-17 10:30:13 -07001678 spin_lock_bh(&adapter->mcc_lock);
1679
1680 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001681 if (!wrb) {
1682 status = -EBUSY;
1683 goto err;
1684 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001685 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001686
Somnath Kotur106df1e2011-10-27 07:12:13 +00001687 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1688 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001689
1690 req->interface_id = if_id;
1691 req->promiscuous = promiscuous;
1692 req->untagged = untagged;
1693 req->num_vlan = num;
1694 if (!promiscuous) {
1695 memcpy(req->normal_vlan, vtag_array,
1696 req->num_vlan * sizeof(vtag_array[0]));
1697 }
1698
Sathya Perlab31c50a2009-09-17 10:30:13 -07001699 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001700
Sathya Perla713d03942009-11-22 22:02:45 +00001701err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001702 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001703 return status;
1704}
1705
Sathya Perla5b8821b2011-08-02 19:57:44 +00001706int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001707{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001708 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001709 struct be_dma_mem *mem = &adapter->rx_filter;
1710 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001711 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001712
Sathya Perla8788fdc2009-07-27 22:52:03 +00001713 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001714
Sathya Perlab31c50a2009-09-17 10:30:13 -07001715 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001716 if (!wrb) {
1717 status = -EBUSY;
1718 goto err;
1719 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001720 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001721 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1722 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1723 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001724
Sathya Perla5b8821b2011-08-02 19:57:44 +00001725 req->if_id = cpu_to_le32(adapter->if_handle);
1726 if (flags & IFF_PROMISC) {
1727 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1728 BE_IF_FLAGS_VLAN_PROMISCUOUS);
1729 if (value == ON)
1730 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001731 BE_IF_FLAGS_VLAN_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001732 } else if (flags & IFF_ALLMULTI) {
1733 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001734 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001735 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001736 struct netdev_hw_addr *ha;
1737 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001738
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001739 req->if_flags_mask = req->if_flags =
1740 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001741
1742 /* Reset mcast promisc mode if already set by setting mask
1743 * and not setting flags field
1744 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001745 req->if_flags_mask |=
1746 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
1747 adapter->if_cap_flags);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001748
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001749 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001750 netdev_for_each_mc_addr(ha, adapter->netdev)
1751 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1752 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001753
Sathya Perla0d1d5872011-08-03 05:19:27 -07001754 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001755err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001756 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001757 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001758}
1759
Sathya Perlab31c50a2009-09-17 10:30:13 -07001760/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001761int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001762{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001763 struct be_mcc_wrb *wrb;
1764 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001765 int status;
1766
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001767 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1768 CMD_SUBSYSTEM_COMMON))
1769 return -EPERM;
1770
Sathya Perlab31c50a2009-09-17 10:30:13 -07001771 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001772
Sathya Perlab31c50a2009-09-17 10:30:13 -07001773 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001774 if (!wrb) {
1775 status = -EBUSY;
1776 goto err;
1777 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001778 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001779
Somnath Kotur106df1e2011-10-27 07:12:13 +00001780 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1781 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001782
1783 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1784 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1785
Sathya Perlab31c50a2009-09-17 10:30:13 -07001786 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001787
Sathya Perla713d03942009-11-22 22:02:45 +00001788err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001789 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001790 return status;
1791}
1792
Sathya Perlab31c50a2009-09-17 10:30:13 -07001793/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001794int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001795{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001796 struct be_mcc_wrb *wrb;
1797 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001798 int status;
1799
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001800 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
1801 CMD_SUBSYSTEM_COMMON))
1802 return -EPERM;
1803
Sathya Perlab31c50a2009-09-17 10:30:13 -07001804 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001805
Sathya Perlab31c50a2009-09-17 10:30:13 -07001806 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001807 if (!wrb) {
1808 status = -EBUSY;
1809 goto err;
1810 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001811 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001812
Somnath Kotur106df1e2011-10-27 07:12:13 +00001813 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1814 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001815
Sathya Perlab31c50a2009-09-17 10:30:13 -07001816 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001817 if (!status) {
1818 struct be_cmd_resp_get_flow_control *resp =
1819 embedded_payload(wrb);
1820 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1821 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1822 }
1823
Sathya Perla713d03942009-11-22 22:02:45 +00001824err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001825 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001826 return status;
1827}
1828
Sathya Perlab31c50a2009-09-17 10:30:13 -07001829/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001830int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1831 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001832{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001833 struct be_mcc_wrb *wrb;
1834 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001835 int status;
1836
Ivan Vecera29849612010-12-14 05:43:19 +00001837 if (mutex_lock_interruptible(&adapter->mbox_lock))
1838 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001839
Sathya Perlab31c50a2009-09-17 10:30:13 -07001840 wrb = wrb_from_mbox(adapter);
1841 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001842
Somnath Kotur106df1e2011-10-27 07:12:13 +00001843 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1844 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001845
Sathya Perlab31c50a2009-09-17 10:30:13 -07001846 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001847 if (!status) {
1848 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1849 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001850 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001851 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001852 }
1853
Ivan Vecera29849612010-12-14 05:43:19 +00001854 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001855 return status;
1856}
sarveshwarb14074ea2009-08-05 13:05:24 -07001857
Sathya Perlab31c50a2009-09-17 10:30:13 -07001858/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001859int be_cmd_reset_function(struct be_adapter *adapter)
1860{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001861 struct be_mcc_wrb *wrb;
1862 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001863 int status;
1864
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00001865 if (lancer_chip(adapter)) {
1866 status = lancer_wait_ready(adapter);
1867 if (!status) {
1868 iowrite32(SLI_PORT_CONTROL_IP_MASK,
1869 adapter->db + SLIPORT_CONTROL_OFFSET);
1870 status = lancer_test_and_set_rdy_state(adapter);
1871 }
1872 if (status) {
1873 dev_err(&adapter->pdev->dev,
1874 "Adapter in non recoverable error\n");
1875 }
1876 return status;
1877 }
1878
Ivan Vecera29849612010-12-14 05:43:19 +00001879 if (mutex_lock_interruptible(&adapter->mbox_lock))
1880 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001881
Sathya Perlab31c50a2009-09-17 10:30:13 -07001882 wrb = wrb_from_mbox(adapter);
1883 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001884
Somnath Kotur106df1e2011-10-27 07:12:13 +00001885 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1886 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001887
Sathya Perlab31c50a2009-09-17 10:30:13 -07001888 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001889
Ivan Vecera29849612010-12-14 05:43:19 +00001890 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001891 return status;
1892}
Ajit Khaparde84517482009-09-04 03:12:16 +00001893
Sathya Perla3abcded2010-10-03 22:12:27 -07001894int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1895{
1896 struct be_mcc_wrb *wrb;
1897 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001898 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1899 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1900 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001901 int status;
1902
Ivan Vecera29849612010-12-14 05:43:19 +00001903 if (mutex_lock_interruptible(&adapter->mbox_lock))
1904 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001905
1906 wrb = wrb_from_mbox(adapter);
1907 req = embedded_payload(wrb);
1908
Somnath Kotur106df1e2011-10-27 07:12:13 +00001909 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1910 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001911
1912 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perla1ca7ba92012-02-23 18:50:16 +00001913 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 |
1914 RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6);
Padmanabh Ratnakard3bd3a52012-07-12 03:57:47 +00001915
1916 if (lancer_chip(adapter) || skyhawk_chip(adapter)) {
1917 req->hdr.version = 1;
1918 req->enable_rss |= cpu_to_le16(RSS_ENABLE_UDP_IPV4 |
1919 RSS_ENABLE_UDP_IPV6);
1920 }
1921
Sathya Perla3abcded2010-10-03 22:12:27 -07001922 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1923 memcpy(req->cpu_table, rsstable, table_size);
1924 memcpy(req->hash, myhash, sizeof(myhash));
1925 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1926
1927 status = be_mbox_notify_wait(adapter);
1928
Ivan Vecera29849612010-12-14 05:43:19 +00001929 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001930 return status;
1931}
1932
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001933/* Uses sync mcc */
1934int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1935 u8 bcn, u8 sts, u8 state)
1936{
1937 struct be_mcc_wrb *wrb;
1938 struct be_cmd_req_enable_disable_beacon *req;
1939 int status;
1940
1941 spin_lock_bh(&adapter->mcc_lock);
1942
1943 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001944 if (!wrb) {
1945 status = -EBUSY;
1946 goto err;
1947 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001948 req = embedded_payload(wrb);
1949
Somnath Kotur106df1e2011-10-27 07:12:13 +00001950 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1951 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001952
1953 req->port_num = port_num;
1954 req->beacon_state = state;
1955 req->beacon_duration = bcn;
1956 req->status_duration = sts;
1957
1958 status = be_mcc_notify_wait(adapter);
1959
Sathya Perla713d03942009-11-22 22:02:45 +00001960err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001961 spin_unlock_bh(&adapter->mcc_lock);
1962 return status;
1963}
1964
1965/* Uses sync mcc */
1966int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1967{
1968 struct be_mcc_wrb *wrb;
1969 struct be_cmd_req_get_beacon_state *req;
1970 int status;
1971
1972 spin_lock_bh(&adapter->mcc_lock);
1973
1974 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001975 if (!wrb) {
1976 status = -EBUSY;
1977 goto err;
1978 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001979 req = embedded_payload(wrb);
1980
Somnath Kotur106df1e2011-10-27 07:12:13 +00001981 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1982 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001983
1984 req->port_num = port_num;
1985
1986 status = be_mcc_notify_wait(adapter);
1987 if (!status) {
1988 struct be_cmd_resp_get_beacon_state *resp =
1989 embedded_payload(wrb);
1990 *state = resp->beacon_state;
1991 }
1992
Sathya Perla713d03942009-11-22 22:02:45 +00001993err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001994 spin_unlock_bh(&adapter->mcc_lock);
1995 return status;
1996}
1997
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001998int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00001999 u32 data_size, u32 data_offset,
2000 const char *obj_name, u32 *data_written,
2001 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002002{
2003 struct be_mcc_wrb *wrb;
2004 struct lancer_cmd_req_write_object *req;
2005 struct lancer_cmd_resp_write_object *resp;
2006 void *ctxt = NULL;
2007 int status;
2008
2009 spin_lock_bh(&adapter->mcc_lock);
2010 adapter->flash_status = 0;
2011
2012 wrb = wrb_from_mccq(adapter);
2013 if (!wrb) {
2014 status = -EBUSY;
2015 goto err_unlock;
2016 }
2017
2018 req = embedded_payload(wrb);
2019
Somnath Kotur106df1e2011-10-27 07:12:13 +00002020 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002021 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00002022 sizeof(struct lancer_cmd_req_write_object), wrb,
2023 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002024
2025 ctxt = &req->context;
2026 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2027 write_length, ctxt, data_size);
2028
2029 if (data_size == 0)
2030 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2031 eof, ctxt, 1);
2032 else
2033 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2034 eof, ctxt, 0);
2035
2036 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2037 req->write_offset = cpu_to_le32(data_offset);
2038 strcpy(req->object_name, obj_name);
2039 req->descriptor_count = cpu_to_le32(1);
2040 req->buf_len = cpu_to_le32(data_size);
2041 req->addr_low = cpu_to_le32((cmd->dma +
2042 sizeof(struct lancer_cmd_req_write_object))
2043 & 0xFFFFFFFF);
2044 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2045 sizeof(struct lancer_cmd_req_write_object)));
2046
2047 be_mcc_notify(adapter);
2048 spin_unlock_bh(&adapter->mcc_lock);
2049
2050 if (!wait_for_completion_timeout(&adapter->flash_compl,
Padmanabh Ratnakar804c7512012-04-25 01:46:18 +00002051 msecs_to_jiffies(30000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002052 status = -1;
2053 else
2054 status = adapter->flash_status;
2055
2056 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002057 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002058 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002059 *change_status = resp->change_status;
2060 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002061 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002062 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002063
2064 return status;
2065
2066err_unlock:
2067 spin_unlock_bh(&adapter->mcc_lock);
2068 return status;
2069}
2070
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002071int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
2072 u32 data_size, u32 data_offset, const char *obj_name,
2073 u32 *data_read, u32 *eof, u8 *addn_status)
2074{
2075 struct be_mcc_wrb *wrb;
2076 struct lancer_cmd_req_read_object *req;
2077 struct lancer_cmd_resp_read_object *resp;
2078 int status;
2079
2080 spin_lock_bh(&adapter->mcc_lock);
2081
2082 wrb = wrb_from_mccq(adapter);
2083 if (!wrb) {
2084 status = -EBUSY;
2085 goto err_unlock;
2086 }
2087
2088 req = embedded_payload(wrb);
2089
2090 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2091 OPCODE_COMMON_READ_OBJECT,
2092 sizeof(struct lancer_cmd_req_read_object), wrb,
2093 NULL);
2094
2095 req->desired_read_len = cpu_to_le32(data_size);
2096 req->read_offset = cpu_to_le32(data_offset);
2097 strcpy(req->object_name, obj_name);
2098 req->descriptor_count = cpu_to_le32(1);
2099 req->buf_len = cpu_to_le32(data_size);
2100 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2101 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2102
2103 status = be_mcc_notify_wait(adapter);
2104
2105 resp = embedded_payload(wrb);
2106 if (!status) {
2107 *data_read = le32_to_cpu(resp->actual_read_len);
2108 *eof = le32_to_cpu(resp->eof);
2109 } else {
2110 *addn_status = resp->additional_status;
2111 }
2112
2113err_unlock:
2114 spin_unlock_bh(&adapter->mcc_lock);
2115 return status;
2116}
2117
Ajit Khaparde84517482009-09-04 03:12:16 +00002118int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
2119 u32 flash_type, u32 flash_opcode, u32 buf_size)
2120{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002121 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002122 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002123 int status;
2124
Sathya Perlab31c50a2009-09-17 10:30:13 -07002125 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002126 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002127
2128 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002129 if (!wrb) {
2130 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002131 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002132 }
2133 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002134
Somnath Kotur106df1e2011-10-27 07:12:13 +00002135 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2136 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002137
2138 req->params.op_type = cpu_to_le32(flash_type);
2139 req->params.op_code = cpu_to_le32(flash_opcode);
2140 req->params.data_buf_size = cpu_to_le32(buf_size);
2141
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002142 be_mcc_notify(adapter);
2143 spin_unlock_bh(&adapter->mcc_lock);
2144
2145 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00002146 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002147 status = -1;
2148 else
2149 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002150
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002151 return status;
2152
2153err_unlock:
2154 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002155 return status;
2156}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002157
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002158int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2159 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002160{
2161 struct be_mcc_wrb *wrb;
2162 struct be_cmd_write_flashrom *req;
2163 int status;
2164
2165 spin_lock_bh(&adapter->mcc_lock);
2166
2167 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002168 if (!wrb) {
2169 status = -EBUSY;
2170 goto err;
2171 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002172 req = embedded_payload(wrb);
2173
Somnath Kotur106df1e2011-10-27 07:12:13 +00002174 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2175 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4, wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002176
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00002177 req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002178 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002179 req->params.offset = cpu_to_le32(offset);
2180 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002181
2182 status = be_mcc_notify_wait(adapter);
2183 if (!status)
2184 memcpy(flashed_crc, req->params.data_buf, 4);
2185
Sathya Perla713d03942009-11-22 22:02:45 +00002186err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002187 spin_unlock_bh(&adapter->mcc_lock);
2188 return status;
2189}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002190
Dan Carpenterc196b022010-05-26 04:47:39 +00002191int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002192 struct be_dma_mem *nonemb_cmd)
2193{
2194 struct be_mcc_wrb *wrb;
2195 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002196 int status;
2197
2198 spin_lock_bh(&adapter->mcc_lock);
2199
2200 wrb = wrb_from_mccq(adapter);
2201 if (!wrb) {
2202 status = -EBUSY;
2203 goto err;
2204 }
2205 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002206
Somnath Kotur106df1e2011-10-27 07:12:13 +00002207 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2208 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2209 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002210 memcpy(req->magic_mac, mac, ETH_ALEN);
2211
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002212 status = be_mcc_notify_wait(adapter);
2213
2214err:
2215 spin_unlock_bh(&adapter->mcc_lock);
2216 return status;
2217}
Suresh Rff33a6e2009-12-03 16:15:52 -08002218
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002219int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2220 u8 loopback_type, u8 enable)
2221{
2222 struct be_mcc_wrb *wrb;
2223 struct be_cmd_req_set_lmode *req;
2224 int status;
2225
2226 spin_lock_bh(&adapter->mcc_lock);
2227
2228 wrb = wrb_from_mccq(adapter);
2229 if (!wrb) {
2230 status = -EBUSY;
2231 goto err;
2232 }
2233
2234 req = embedded_payload(wrb);
2235
Somnath Kotur106df1e2011-10-27 07:12:13 +00002236 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2237 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2238 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002239
2240 req->src_port = port_num;
2241 req->dest_port = port_num;
2242 req->loopback_type = loopback_type;
2243 req->loopback_state = enable;
2244
2245 status = be_mcc_notify_wait(adapter);
2246err:
2247 spin_unlock_bh(&adapter->mcc_lock);
2248 return status;
2249}
2250
Suresh Rff33a6e2009-12-03 16:15:52 -08002251int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2252 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2253{
2254 struct be_mcc_wrb *wrb;
2255 struct be_cmd_req_loopback_test *req;
2256 int status;
2257
2258 spin_lock_bh(&adapter->mcc_lock);
2259
2260 wrb = wrb_from_mccq(adapter);
2261 if (!wrb) {
2262 status = -EBUSY;
2263 goto err;
2264 }
2265
2266 req = embedded_payload(wrb);
2267
Somnath Kotur106df1e2011-10-27 07:12:13 +00002268 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2269 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002270 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002271
2272 req->pattern = cpu_to_le64(pattern);
2273 req->src_port = cpu_to_le32(port_num);
2274 req->dest_port = cpu_to_le32(port_num);
2275 req->pkt_size = cpu_to_le32(pkt_size);
2276 req->num_pkts = cpu_to_le32(num_pkts);
2277 req->loopback_type = cpu_to_le32(loopback_type);
2278
2279 status = be_mcc_notify_wait(adapter);
2280 if (!status) {
2281 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2282 status = le32_to_cpu(resp->status);
2283 }
2284
2285err:
2286 spin_unlock_bh(&adapter->mcc_lock);
2287 return status;
2288}
2289
2290int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2291 u32 byte_cnt, struct be_dma_mem *cmd)
2292{
2293 struct be_mcc_wrb *wrb;
2294 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002295 int status;
2296 int i, j = 0;
2297
2298 spin_lock_bh(&adapter->mcc_lock);
2299
2300 wrb = wrb_from_mccq(adapter);
2301 if (!wrb) {
2302 status = -EBUSY;
2303 goto err;
2304 }
2305 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002306 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2307 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002308
2309 req->pattern = cpu_to_le64(pattern);
2310 req->byte_count = cpu_to_le32(byte_cnt);
2311 for (i = 0; i < byte_cnt; i++) {
2312 req->snd_buff[i] = (u8)(pattern >> (j*8));
2313 j++;
2314 if (j > 7)
2315 j = 0;
2316 }
2317
2318 status = be_mcc_notify_wait(adapter);
2319
2320 if (!status) {
2321 struct be_cmd_resp_ddrdma_test *resp;
2322 resp = cmd->va;
2323 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2324 resp->snd_err) {
2325 status = -1;
2326 }
2327 }
2328
2329err:
2330 spin_unlock_bh(&adapter->mcc_lock);
2331 return status;
2332}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002333
Dan Carpenterc196b022010-05-26 04:47:39 +00002334int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002335 struct be_dma_mem *nonemb_cmd)
2336{
2337 struct be_mcc_wrb *wrb;
2338 struct be_cmd_req_seeprom_read *req;
2339 struct be_sge *sge;
2340 int status;
2341
2342 spin_lock_bh(&adapter->mcc_lock);
2343
2344 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002345 if (!wrb) {
2346 status = -EBUSY;
2347 goto err;
2348 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002349 req = nonemb_cmd->va;
2350 sge = nonembedded_sgl(wrb);
2351
Somnath Kotur106df1e2011-10-27 07:12:13 +00002352 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2353 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2354 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002355
2356 status = be_mcc_notify_wait(adapter);
2357
Ajit Khapardee45ff012011-02-04 17:18:28 +00002358err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002359 spin_unlock_bh(&adapter->mcc_lock);
2360 return status;
2361}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002362
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002363int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002364{
2365 struct be_mcc_wrb *wrb;
2366 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002367 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002368 int status;
2369
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002370 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2371 CMD_SUBSYSTEM_COMMON))
2372 return -EPERM;
2373
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002374 spin_lock_bh(&adapter->mcc_lock);
2375
2376 wrb = wrb_from_mccq(adapter);
2377 if (!wrb) {
2378 status = -EBUSY;
2379 goto err;
2380 }
Sathya Perla306f1342011-08-02 19:57:45 +00002381 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2382 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2383 &cmd.dma);
2384 if (!cmd.va) {
2385 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2386 status = -ENOMEM;
2387 goto err;
2388 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002389
Sathya Perla306f1342011-08-02 19:57:45 +00002390 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002391
Somnath Kotur106df1e2011-10-27 07:12:13 +00002392 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2393 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2394 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002395
2396 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002397 if (!status) {
2398 struct be_phy_info *resp_phy_info =
2399 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002400 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2401 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002402 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002403 adapter->phy.auto_speeds_supported =
2404 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2405 adapter->phy.fixed_speeds_supported =
2406 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2407 adapter->phy.misc_params =
2408 le32_to_cpu(resp_phy_info->misc_params);
Sathya Perla306f1342011-08-02 19:57:45 +00002409 }
2410 pci_free_consistent(adapter->pdev, cmd.size,
2411 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002412err:
2413 spin_unlock_bh(&adapter->mcc_lock);
2414 return status;
2415}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002416
2417int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2418{
2419 struct be_mcc_wrb *wrb;
2420 struct be_cmd_req_set_qos *req;
2421 int status;
2422
2423 spin_lock_bh(&adapter->mcc_lock);
2424
2425 wrb = wrb_from_mccq(adapter);
2426 if (!wrb) {
2427 status = -EBUSY;
2428 goto err;
2429 }
2430
2431 req = embedded_payload(wrb);
2432
Somnath Kotur106df1e2011-10-27 07:12:13 +00002433 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2434 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002435
2436 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002437 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2438 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002439
2440 status = be_mcc_notify_wait(adapter);
2441
2442err:
2443 spin_unlock_bh(&adapter->mcc_lock);
2444 return status;
2445}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002446
2447int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2448{
2449 struct be_mcc_wrb *wrb;
2450 struct be_cmd_req_cntl_attribs *req;
2451 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002452 int status;
2453 int payload_len = max(sizeof(*req), sizeof(*resp));
2454 struct mgmt_controller_attrib *attribs;
2455 struct be_dma_mem attribs_cmd;
2456
2457 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2458 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2459 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2460 &attribs_cmd.dma);
2461 if (!attribs_cmd.va) {
2462 dev_err(&adapter->pdev->dev,
2463 "Memory allocation failure\n");
2464 return -ENOMEM;
2465 }
2466
2467 if (mutex_lock_interruptible(&adapter->mbox_lock))
2468 return -1;
2469
2470 wrb = wrb_from_mbox(adapter);
2471 if (!wrb) {
2472 status = -EBUSY;
2473 goto err;
2474 }
2475 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002476
Somnath Kotur106df1e2011-10-27 07:12:13 +00002477 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2478 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2479 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002480
2481 status = be_mbox_notify_wait(adapter);
2482 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002483 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002484 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2485 }
2486
2487err:
2488 mutex_unlock(&adapter->mbox_lock);
2489 pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
2490 attribs_cmd.dma);
2491 return status;
2492}
Sathya Perla2e588f82011-03-11 02:49:26 +00002493
2494/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002495int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002496{
2497 struct be_mcc_wrb *wrb;
2498 struct be_cmd_req_set_func_cap *req;
2499 int status;
2500
2501 if (mutex_lock_interruptible(&adapter->mbox_lock))
2502 return -1;
2503
2504 wrb = wrb_from_mbox(adapter);
2505 if (!wrb) {
2506 status = -EBUSY;
2507 goto err;
2508 }
2509
2510 req = embedded_payload(wrb);
2511
Somnath Kotur106df1e2011-10-27 07:12:13 +00002512 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2513 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002514
2515 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2516 CAPABILITY_BE3_NATIVE_ERX_API);
2517 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2518
2519 status = be_mbox_notify_wait(adapter);
2520 if (!status) {
2521 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2522 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2523 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002524 if (!adapter->be3_native)
2525 dev_warn(&adapter->pdev->dev,
2526 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002527 }
2528err:
2529 mutex_unlock(&adapter->mbox_lock);
2530 return status;
2531}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002532
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002533/* Get privilege(s) for a function */
2534int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2535 u32 domain)
2536{
2537 struct be_mcc_wrb *wrb;
2538 struct be_cmd_req_get_fn_privileges *req;
2539 int status;
2540
2541 spin_lock_bh(&adapter->mcc_lock);
2542
2543 wrb = wrb_from_mccq(adapter);
2544 if (!wrb) {
2545 status = -EBUSY;
2546 goto err;
2547 }
2548
2549 req = embedded_payload(wrb);
2550
2551 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2552 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2553 wrb, NULL);
2554
2555 req->hdr.domain = domain;
2556
2557 status = be_mcc_notify_wait(adapter);
2558 if (!status) {
2559 struct be_cmd_resp_get_fn_privileges *resp =
2560 embedded_payload(wrb);
2561 *privilege = le32_to_cpu(resp->privilege_mask);
2562 }
2563
2564err:
2565 spin_unlock_bh(&adapter->mcc_lock);
2566 return status;
2567}
2568
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002569/* Uses synchronous MCCQ */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002570int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
2571 bool *pmac_id_active, u32 *pmac_id, u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002572{
2573 struct be_mcc_wrb *wrb;
2574 struct be_cmd_req_get_mac_list *req;
2575 int status;
2576 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002577 struct be_dma_mem get_mac_list_cmd;
2578 int i;
2579
2580 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2581 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2582 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2583 get_mac_list_cmd.size,
2584 &get_mac_list_cmd.dma);
2585
2586 if (!get_mac_list_cmd.va) {
2587 dev_err(&adapter->pdev->dev,
2588 "Memory allocation failure during GET_MAC_LIST\n");
2589 return -ENOMEM;
2590 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002591
2592 spin_lock_bh(&adapter->mcc_lock);
2593
2594 wrb = wrb_from_mccq(adapter);
2595 if (!wrb) {
2596 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002597 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002598 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002599
2600 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002601
2602 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2603 OPCODE_COMMON_GET_MAC_LIST, sizeof(*req),
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002604 wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002605
2606 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002607 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
2608 req->perm_override = 1;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002609
2610 status = be_mcc_notify_wait(adapter);
2611 if (!status) {
2612 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002613 get_mac_list_cmd.va;
2614 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2615 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002616 * or one or more true or pseudo permanant mac addresses.
2617 * If an active mac_id is present, return first active mac_id
2618 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002619 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002620 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002621 struct get_list_macaddr *mac_entry;
2622 u16 mac_addr_size;
2623 u32 mac_id;
2624
2625 mac_entry = &resp->macaddr_list[i];
2626 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2627 /* mac_id is a 32 bit value and mac_addr size
2628 * is 6 bytes
2629 */
2630 if (mac_addr_size == sizeof(u32)) {
2631 *pmac_id_active = true;
2632 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2633 *pmac_id = le32_to_cpu(mac_id);
2634 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002635 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002636 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002637 /* If no active mac_id found, return first mac addr */
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002638 *pmac_id_active = false;
2639 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2640 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002641 }
2642
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002643out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002644 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002645 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2646 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002647 return status;
2648}
2649
2650/* Uses synchronous MCCQ */
2651int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2652 u8 mac_count, u32 domain)
2653{
2654 struct be_mcc_wrb *wrb;
2655 struct be_cmd_req_set_mac_list *req;
2656 int status;
2657 struct be_dma_mem cmd;
2658
2659 memset(&cmd, 0, sizeof(struct be_dma_mem));
2660 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2661 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2662 &cmd.dma, GFP_KERNEL);
2663 if (!cmd.va) {
2664 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2665 return -ENOMEM;
2666 }
2667
2668 spin_lock_bh(&adapter->mcc_lock);
2669
2670 wrb = wrb_from_mccq(adapter);
2671 if (!wrb) {
2672 status = -EBUSY;
2673 goto err;
2674 }
2675
2676 req = cmd.va;
2677 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2678 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2679 wrb, &cmd);
2680
2681 req->hdr.domain = domain;
2682 req->mac_count = mac_count;
2683 if (mac_count)
2684 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2685
2686 status = be_mcc_notify_wait(adapter);
2687
2688err:
2689 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2690 cmd.va, cmd.dma);
2691 spin_unlock_bh(&adapter->mcc_lock);
2692 return status;
2693}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002694
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002695int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
2696 u32 domain, u16 intf_id)
2697{
2698 struct be_mcc_wrb *wrb;
2699 struct be_cmd_req_set_hsw_config *req;
2700 void *ctxt;
2701 int status;
2702
2703 spin_lock_bh(&adapter->mcc_lock);
2704
2705 wrb = wrb_from_mccq(adapter);
2706 if (!wrb) {
2707 status = -EBUSY;
2708 goto err;
2709 }
2710
2711 req = embedded_payload(wrb);
2712 ctxt = &req->context;
2713
2714 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2715 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2716
2717 req->hdr.domain = domain;
2718 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2719 if (pvid) {
2720 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2721 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2722 }
2723
2724 be_dws_cpu_to_le(req->context, sizeof(req->context));
2725 status = be_mcc_notify_wait(adapter);
2726
2727err:
2728 spin_unlock_bh(&adapter->mcc_lock);
2729 return status;
2730}
2731
2732/* Get Hyper switch config */
2733int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
2734 u32 domain, u16 intf_id)
2735{
2736 struct be_mcc_wrb *wrb;
2737 struct be_cmd_req_get_hsw_config *req;
2738 void *ctxt;
2739 int status;
2740 u16 vid;
2741
2742 spin_lock_bh(&adapter->mcc_lock);
2743
2744 wrb = wrb_from_mccq(adapter);
2745 if (!wrb) {
2746 status = -EBUSY;
2747 goto err;
2748 }
2749
2750 req = embedded_payload(wrb);
2751 ctxt = &req->context;
2752
2753 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2754 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2755
2756 req->hdr.domain = domain;
2757 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, ctxt,
2758 intf_id);
2759 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
2760 be_dws_cpu_to_le(req->context, sizeof(req->context));
2761
2762 status = be_mcc_notify_wait(adapter);
2763 if (!status) {
2764 struct be_cmd_resp_get_hsw_config *resp =
2765 embedded_payload(wrb);
2766 be_dws_le_to_cpu(&resp->context,
2767 sizeof(resp->context));
2768 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2769 pvid, &resp->context);
2770 *pvid = le16_to_cpu(vid);
2771 }
2772
2773err:
2774 spin_unlock_bh(&adapter->mcc_lock);
2775 return status;
2776}
2777
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002778int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2779{
2780 struct be_mcc_wrb *wrb;
2781 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2782 int status;
2783 int payload_len = sizeof(*req);
2784 struct be_dma_mem cmd;
2785
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002786 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2787 CMD_SUBSYSTEM_ETH))
2788 return -EPERM;
2789
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002790 memset(&cmd, 0, sizeof(struct be_dma_mem));
2791 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2792 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2793 &cmd.dma);
2794 if (!cmd.va) {
2795 dev_err(&adapter->pdev->dev,
2796 "Memory allocation failure\n");
2797 return -ENOMEM;
2798 }
2799
2800 if (mutex_lock_interruptible(&adapter->mbox_lock))
2801 return -1;
2802
2803 wrb = wrb_from_mbox(adapter);
2804 if (!wrb) {
2805 status = -EBUSY;
2806 goto err;
2807 }
2808
2809 req = cmd.va;
2810
2811 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2812 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2813 payload_len, wrb, &cmd);
2814
2815 req->hdr.version = 1;
2816 req->query_options = BE_GET_WOL_CAP;
2817
2818 status = be_mbox_notify_wait(adapter);
2819 if (!status) {
2820 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
2821 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
2822
2823 /* the command could succeed misleadingly on old f/w
2824 * which is not aware of the V1 version. fake an error. */
2825 if (resp->hdr.response_length < payload_len) {
2826 status = -1;
2827 goto err;
2828 }
2829 adapter->wol_cap = resp->wol_settings;
2830 }
2831err:
2832 mutex_unlock(&adapter->mbox_lock);
2833 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2834 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00002835
2836}
2837int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
2838 struct be_dma_mem *cmd)
2839{
2840 struct be_mcc_wrb *wrb;
2841 struct be_cmd_req_get_ext_fat_caps *req;
2842 int status;
2843
2844 if (mutex_lock_interruptible(&adapter->mbox_lock))
2845 return -1;
2846
2847 wrb = wrb_from_mbox(adapter);
2848 if (!wrb) {
2849 status = -EBUSY;
2850 goto err;
2851 }
2852
2853 req = cmd->va;
2854 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2855 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
2856 cmd->size, wrb, cmd);
2857 req->parameter_type = cpu_to_le32(1);
2858
2859 status = be_mbox_notify_wait(adapter);
2860err:
2861 mutex_unlock(&adapter->mbox_lock);
2862 return status;
2863}
2864
2865int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
2866 struct be_dma_mem *cmd,
2867 struct be_fat_conf_params *configs)
2868{
2869 struct be_mcc_wrb *wrb;
2870 struct be_cmd_req_set_ext_fat_caps *req;
2871 int status;
2872
2873 spin_lock_bh(&adapter->mcc_lock);
2874
2875 wrb = wrb_from_mccq(adapter);
2876 if (!wrb) {
2877 status = -EBUSY;
2878 goto err;
2879 }
2880
2881 req = cmd->va;
2882 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
2883 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2884 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
2885 cmd->size, wrb, cmd);
2886
2887 status = be_mcc_notify_wait(adapter);
2888err:
2889 spin_unlock_bh(&adapter->mcc_lock);
2890 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002891}
Parav Pandit6a4ab662012-03-26 14:27:12 +00002892
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00002893int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
2894{
2895 struct be_mcc_wrb *wrb;
2896 struct be_cmd_req_get_port_name *req;
2897 int status;
2898
2899 if (!lancer_chip(adapter)) {
2900 *port_name = adapter->hba_port_num + '0';
2901 return 0;
2902 }
2903
2904 spin_lock_bh(&adapter->mcc_lock);
2905
2906 wrb = wrb_from_mccq(adapter);
2907 if (!wrb) {
2908 status = -EBUSY;
2909 goto err;
2910 }
2911
2912 req = embedded_payload(wrb);
2913
2914 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2915 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
2916 NULL);
2917 req->hdr.version = 1;
2918
2919 status = be_mcc_notify_wait(adapter);
2920 if (!status) {
2921 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
2922 *port_name = resp->port_name[adapter->hba_port_num];
2923 } else {
2924 *port_name = adapter->hba_port_num + '0';
2925 }
2926err:
2927 spin_unlock_bh(&adapter->mcc_lock);
2928 return status;
2929}
2930
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002931static struct be_nic_resource_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
2932 u32 max_buf_size)
2933{
2934 struct be_nic_resource_desc *desc = (struct be_nic_resource_desc *)buf;
2935 int i;
2936
2937 for (i = 0; i < desc_count; i++) {
2938 desc->desc_len = RESOURCE_DESC_SIZE;
2939 if (((void *)desc + desc->desc_len) >
2940 (void *)(buf + max_buf_size)) {
2941 desc = NULL;
2942 break;
2943 }
2944
2945 if (desc->desc_type == NIC_RESOURCE_DESC_TYPE_ID)
2946 break;
2947
2948 desc = (void *)desc + desc->desc_len;
2949 }
2950
2951 if (!desc || i == MAX_RESOURCE_DESC)
2952 return NULL;
2953
2954 return desc;
2955}
2956
2957/* Uses Mbox */
2958int be_cmd_get_func_config(struct be_adapter *adapter)
2959{
2960 struct be_mcc_wrb *wrb;
2961 struct be_cmd_req_get_func_config *req;
2962 int status;
2963 struct be_dma_mem cmd;
2964
2965 memset(&cmd, 0, sizeof(struct be_dma_mem));
2966 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
2967 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2968 &cmd.dma);
2969 if (!cmd.va) {
2970 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2971 return -ENOMEM;
2972 }
2973 if (mutex_lock_interruptible(&adapter->mbox_lock))
2974 return -1;
2975
2976 wrb = wrb_from_mbox(adapter);
2977 if (!wrb) {
2978 status = -EBUSY;
2979 goto err;
2980 }
2981
2982 req = cmd.va;
2983
2984 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2985 OPCODE_COMMON_GET_FUNC_CONFIG,
2986 cmd.size, wrb, &cmd);
2987
2988 status = be_mbox_notify_wait(adapter);
2989 if (!status) {
2990 struct be_cmd_resp_get_func_config *resp = cmd.va;
2991 u32 desc_count = le32_to_cpu(resp->desc_count);
2992 struct be_nic_resource_desc *desc;
2993
2994 desc = be_get_nic_desc(resp->func_param, desc_count,
2995 sizeof(resp->func_param));
2996 if (!desc) {
2997 status = -EINVAL;
2998 goto err;
2999 }
3000
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003001 adapter->pf_number = desc->pf_num;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003002 adapter->max_pmac_cnt = le16_to_cpu(desc->unicast_mac_count);
3003 adapter->max_vlans = le16_to_cpu(desc->vlan_count);
3004 adapter->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3005 adapter->max_tx_queues = le16_to_cpu(desc->txq_count);
3006 adapter->max_rss_queues = le16_to_cpu(desc->rssq_count);
3007 adapter->max_rx_queues = le16_to_cpu(desc->rq_count);
3008
3009 adapter->max_event_queues = le16_to_cpu(desc->eq_count);
3010 adapter->if_cap_flags = le32_to_cpu(desc->cap_flags);
3011 }
3012err:
3013 mutex_unlock(&adapter->mbox_lock);
3014 pci_free_consistent(adapter->pdev, cmd.size,
3015 cmd.va, cmd.dma);
3016 return status;
3017}
3018
3019 /* Uses sync mcc */
3020int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags,
3021 u8 domain)
3022{
3023 struct be_mcc_wrb *wrb;
3024 struct be_cmd_req_get_profile_config *req;
3025 int status;
3026 struct be_dma_mem cmd;
3027
3028 memset(&cmd, 0, sizeof(struct be_dma_mem));
3029 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3030 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3031 &cmd.dma);
3032 if (!cmd.va) {
3033 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
3034 return -ENOMEM;
3035 }
3036
3037 spin_lock_bh(&adapter->mcc_lock);
3038
3039 wrb = wrb_from_mccq(adapter);
3040 if (!wrb) {
3041 status = -EBUSY;
3042 goto err;
3043 }
3044
3045 req = cmd.va;
3046
3047 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3048 OPCODE_COMMON_GET_PROFILE_CONFIG,
3049 cmd.size, wrb, &cmd);
3050
3051 req->type = ACTIVE_PROFILE_TYPE;
3052 req->hdr.domain = domain;
3053
3054 status = be_mcc_notify_wait(adapter);
3055 if (!status) {
3056 struct be_cmd_resp_get_profile_config *resp = cmd.va;
3057 u32 desc_count = le32_to_cpu(resp->desc_count);
3058 struct be_nic_resource_desc *desc;
3059
3060 desc = be_get_nic_desc(resp->func_param, desc_count,
3061 sizeof(resp->func_param));
3062
3063 if (!desc) {
3064 status = -EINVAL;
3065 goto err;
3066 }
3067 *cap_flags = le32_to_cpu(desc->cap_flags);
3068 }
3069err:
3070 spin_unlock_bh(&adapter->mcc_lock);
3071 pci_free_consistent(adapter->pdev, cmd.size,
3072 cmd.va, cmd.dma);
3073 return status;
3074}
3075
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003076/* Uses sync mcc */
3077int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
3078 u8 domain)
3079{
3080 struct be_mcc_wrb *wrb;
3081 struct be_cmd_req_set_profile_config *req;
3082 int status;
3083
3084 spin_lock_bh(&adapter->mcc_lock);
3085
3086 wrb = wrb_from_mccq(adapter);
3087 if (!wrb) {
3088 status = -EBUSY;
3089 goto err;
3090 }
3091
3092 req = embedded_payload(wrb);
3093
3094 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3095 OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req),
3096 wrb, NULL);
3097
3098 req->hdr.domain = domain;
3099 req->desc_count = cpu_to_le32(1);
3100
3101 req->nic_desc.desc_type = NIC_RESOURCE_DESC_TYPE_ID;
3102 req->nic_desc.desc_len = RESOURCE_DESC_SIZE;
3103 req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV);
3104 req->nic_desc.pf_num = adapter->pf_number;
3105 req->nic_desc.vf_num = domain;
3106
3107 /* Mark fields invalid */
3108 req->nic_desc.unicast_mac_count = 0xFFFF;
3109 req->nic_desc.mcc_count = 0xFFFF;
3110 req->nic_desc.vlan_count = 0xFFFF;
3111 req->nic_desc.mcast_mac_count = 0xFFFF;
3112 req->nic_desc.txq_count = 0xFFFF;
3113 req->nic_desc.rq_count = 0xFFFF;
3114 req->nic_desc.rssq_count = 0xFFFF;
3115 req->nic_desc.lro_count = 0xFFFF;
3116 req->nic_desc.cq_count = 0xFFFF;
3117 req->nic_desc.toe_conn_count = 0xFFFF;
3118 req->nic_desc.eq_count = 0xFFFF;
3119 req->nic_desc.link_param = 0xFF;
3120 req->nic_desc.bw_min = 0xFFFFFFFF;
3121 req->nic_desc.acpi_params = 0xFF;
3122 req->nic_desc.wol_param = 0x0F;
3123
3124 /* Change BW */
3125 req->nic_desc.bw_min = cpu_to_le32(bps);
3126 req->nic_desc.bw_max = cpu_to_le32(bps);
3127 status = be_mcc_notify_wait(adapter);
3128err:
3129 spin_unlock_bh(&adapter->mcc_lock);
3130 return status;
3131}
3132
Parav Pandit6a4ab662012-03-26 14:27:12 +00003133int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
3134 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
3135{
3136 struct be_adapter *adapter = netdev_priv(netdev_handle);
3137 struct be_mcc_wrb *wrb;
3138 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
3139 struct be_cmd_req_hdr *req;
3140 struct be_cmd_resp_hdr *resp;
3141 int status;
3142
3143 spin_lock_bh(&adapter->mcc_lock);
3144
3145 wrb = wrb_from_mccq(adapter);
3146 if (!wrb) {
3147 status = -EBUSY;
3148 goto err;
3149 }
3150 req = embedded_payload(wrb);
3151 resp = embedded_payload(wrb);
3152
3153 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
3154 hdr->opcode, wrb_payload_size, wrb, NULL);
3155 memcpy(req, wrb_payload, wrb_payload_size);
3156 be_dws_cpu_to_le(req, wrb_payload_size);
3157
3158 status = be_mcc_notify_wait(adapter);
3159 if (cmd_status)
3160 *cmd_status = (status & 0xffff);
3161 if (ext_status)
3162 *ext_status = 0;
3163 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
3164 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
3165err:
3166 spin_unlock_bh(&adapter->mcc_lock);
3167 return status;
3168}
3169EXPORT_SYMBOL(be_roce_mcc_cmd);