blob: f2875aa4766170a100b7a21aeffac60e1b9c8d57 [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;
Sathya Perla1bc8e7e2012-11-06 17:48:59 +0000471 u32 reg = skyhawk_chip(adapter) ? SLIPORT_SEMAPHORE_OFFSET_SH :
472 SLIPORT_SEMAPHORE_OFFSET_BE;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000473
Sathya Perla1bc8e7e2012-11-06 17:48:59 +0000474 pci_read_config_dword(adapter->pdev, reg, &sem);
475 *stage = sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700476
Sathya Perla1bc8e7e2012-11-06 17:48:59 +0000477 if ((sem >> POST_ERR_SHIFT) & POST_ERR_MASK)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700478 return -1;
479 else
480 return 0;
481}
482
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000483int lancer_wait_ready(struct be_adapter *adapter)
484{
485#define SLIPORT_READY_TIMEOUT 30
486 u32 sliport_status;
487 int status = 0, i;
488
489 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
490 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
491 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
492 break;
493
494 msleep(1000);
495 }
496
497 if (i == SLIPORT_READY_TIMEOUT)
498 status = -1;
499
500 return status;
501}
502
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000503static bool lancer_provisioning_error(struct be_adapter *adapter)
504{
505 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
506 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
507 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
508 sliport_err1 = ioread32(adapter->db +
509 SLIPORT_ERROR1_OFFSET);
510 sliport_err2 = ioread32(adapter->db +
511 SLIPORT_ERROR2_OFFSET);
512
513 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
514 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
515 return true;
516 }
517 return false;
518}
519
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000520int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
521{
522 int status;
523 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000524 bool resource_error;
525
526 resource_error = lancer_provisioning_error(adapter);
527 if (resource_error)
528 return -1;
529
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000530 status = lancer_wait_ready(adapter);
531 if (!status) {
532 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
533 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
534 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
535 if (err && reset_needed) {
536 iowrite32(SLI_PORT_CONTROL_IP_MASK,
537 adapter->db + SLIPORT_CONTROL_OFFSET);
538
539 /* check adapter has corrected the error */
540 status = lancer_wait_ready(adapter);
541 sliport_status = ioread32(adapter->db +
542 SLIPORT_STATUS_OFFSET);
543 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
544 SLIPORT_STATUS_RN_MASK);
545 if (status || sliport_status)
546 status = -1;
547 } else if (err || reset_needed) {
548 status = -1;
549 }
550 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000551 /* Stop error recovery if error is not recoverable.
552 * No resource error is temporary errors and will go away
553 * when PF provisions resources.
554 */
555 resource_error = lancer_provisioning_error(adapter);
556 if (status == -1 && !resource_error)
557 adapter->eeh_error = true;
558
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000559 return status;
560}
561
562int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700563{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000564 u16 stage;
565 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000566 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700567
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000568 if (lancer_chip(adapter)) {
569 status = lancer_wait_ready(adapter);
570 return status;
571 }
572
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000573 do {
574 status = be_POST_stage_get(adapter, &stage);
575 if (status) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000576 dev_err(dev, "POST error; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000577 return -1;
578 } else if (stage != POST_STAGE_ARMFW_RDY) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000579 if (msleep_interruptible(2000)) {
580 dev_err(dev, "Waiting for POST aborted\n");
581 return -EINTR;
582 }
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000583 timeout += 2;
584 } else {
585 return 0;
586 }
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000587 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700588
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000589 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000590 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700591}
592
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700593
594static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
595{
596 return &wrb->payload.sgl[0];
597}
598
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700599
600/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000601/* mem will be NULL for embedded commands */
602static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
603 u8 subsystem, u8 opcode, int cmd_len,
604 struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700605{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000606 struct be_sge *sge;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000607 unsigned long addr = (unsigned long)req_hdr;
608 u64 req_addr = addr;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000609
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700610 req_hdr->opcode = opcode;
611 req_hdr->subsystem = subsystem;
612 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000613 req_hdr->version = 0;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000614
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000615 wrb->tag0 = req_addr & 0xFFFFFFFF;
616 wrb->tag1 = upper_32_bits(req_addr);
617
Somnath Kotur106df1e2011-10-27 07:12:13 +0000618 wrb->payload_length = cmd_len;
619 if (mem) {
620 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
621 MCC_WRB_SGE_CNT_SHIFT;
622 sge = nonembedded_sgl(wrb);
623 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
624 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
625 sge->len = cpu_to_le32(mem->size);
626 } else
627 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
628 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700629}
630
631static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
632 struct be_dma_mem *mem)
633{
634 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
635 u64 dma = (u64)mem->dma;
636
637 for (i = 0; i < buf_pages; i++) {
638 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
639 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
640 dma += PAGE_SIZE_4K;
641 }
642}
643
644/* Converts interrupt delay in microseconds to multiplier value */
645static u32 eq_delay_to_mult(u32 usec_delay)
646{
647#define MAX_INTR_RATE 651042
648 const u32 round = 10;
649 u32 multiplier;
650
651 if (usec_delay == 0)
652 multiplier = 0;
653 else {
654 u32 interrupt_rate = 1000000 / usec_delay;
655 /* Max delay, corresponding to the lowest interrupt rate */
656 if (interrupt_rate == 0)
657 multiplier = 1023;
658 else {
659 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
660 multiplier /= interrupt_rate;
661 /* Round the multiplier to the closest value.*/
662 multiplier = (multiplier + round/2) / round;
663 multiplier = min(multiplier, (u32)1023);
664 }
665 }
666 return multiplier;
667}
668
Sathya Perlab31c50a2009-09-17 10:30:13 -0700669static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700670{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700671 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
672 struct be_mcc_wrb *wrb
673 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
674 memset(wrb, 0, sizeof(*wrb));
675 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700676}
677
Sathya Perlab31c50a2009-09-17 10:30:13 -0700678static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000679{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700680 struct be_queue_info *mccq = &adapter->mcc_obj.q;
681 struct be_mcc_wrb *wrb;
682
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000683 if (!mccq->created)
684 return NULL;
685
Sathya Perla713d03942009-11-22 22:02:45 +0000686 if (atomic_read(&mccq->used) >= mccq->len) {
687 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
688 return NULL;
689 }
690
Sathya Perlab31c50a2009-09-17 10:30:13 -0700691 wrb = queue_head_node(mccq);
692 queue_head_inc(mccq);
693 atomic_inc(&mccq->used);
694 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000695 return wrb;
696}
697
Sathya Perla2243e2e2009-11-22 22:02:03 +0000698/* Tell fw we're about to start firing cmds by writing a
699 * special pattern across the wrb hdr; uses mbox
700 */
701int be_cmd_fw_init(struct be_adapter *adapter)
702{
703 u8 *wrb;
704 int status;
705
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000706 if (lancer_chip(adapter))
707 return 0;
708
Ivan Vecera29849612010-12-14 05:43:19 +0000709 if (mutex_lock_interruptible(&adapter->mbox_lock))
710 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000711
712 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000713 *wrb++ = 0xFF;
714 *wrb++ = 0x12;
715 *wrb++ = 0x34;
716 *wrb++ = 0xFF;
717 *wrb++ = 0xFF;
718 *wrb++ = 0x56;
719 *wrb++ = 0x78;
720 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000721
722 status = be_mbox_notify_wait(adapter);
723
Ivan Vecera29849612010-12-14 05:43:19 +0000724 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000725 return status;
726}
727
728/* Tell fw we're done with firing cmds by writing a
729 * special pattern across the wrb hdr; uses mbox
730 */
731int be_cmd_fw_clean(struct be_adapter *adapter)
732{
733 u8 *wrb;
734 int status;
735
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000736 if (lancer_chip(adapter))
737 return 0;
738
Ivan Vecera29849612010-12-14 05:43:19 +0000739 if (mutex_lock_interruptible(&adapter->mbox_lock))
740 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000741
742 wrb = (u8 *)wrb_from_mbox(adapter);
743 *wrb++ = 0xFF;
744 *wrb++ = 0xAA;
745 *wrb++ = 0xBB;
746 *wrb++ = 0xFF;
747 *wrb++ = 0xFF;
748 *wrb++ = 0xCC;
749 *wrb++ = 0xDD;
750 *wrb = 0xFF;
751
752 status = be_mbox_notify_wait(adapter);
753
Ivan Vecera29849612010-12-14 05:43:19 +0000754 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000755 return status;
756}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000757
Sathya Perla8788fdc2009-07-27 22:52:03 +0000758int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700759 struct be_queue_info *eq, int eq_delay)
760{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700761 struct be_mcc_wrb *wrb;
762 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700763 struct be_dma_mem *q_mem = &eq->dma_mem;
764 int status;
765
Ivan Vecera29849612010-12-14 05:43:19 +0000766 if (mutex_lock_interruptible(&adapter->mbox_lock))
767 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700768
769 wrb = wrb_from_mbox(adapter);
770 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700771
Somnath Kotur106df1e2011-10-27 07:12:13 +0000772 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
773 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700774
775 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
776
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700777 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
778 /* 4byte eqe*/
779 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
780 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
781 __ilog2_u32(eq->len/256));
782 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
783 eq_delay_to_mult(eq_delay));
784 be_dws_cpu_to_le(req->context, sizeof(req->context));
785
786 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
787
Sathya Perlab31c50a2009-09-17 10:30:13 -0700788 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700789 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700790 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700791 eq->id = le16_to_cpu(resp->eq_id);
792 eq->created = true;
793 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700794
Ivan Vecera29849612010-12-14 05:43:19 +0000795 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700796 return status;
797}
798
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000799/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000800int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000801 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700802{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700803 struct be_mcc_wrb *wrb;
804 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700805 int status;
806
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000807 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700808
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000809 wrb = wrb_from_mccq(adapter);
810 if (!wrb) {
811 status = -EBUSY;
812 goto err;
813 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700814 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700815
Somnath Kotur106df1e2011-10-27 07:12:13 +0000816 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
817 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +0000818 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700819 if (permanent) {
820 req->permanent = 1;
821 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700822 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000823 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700824 req->permanent = 0;
825 }
826
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000827 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700828 if (!status) {
829 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700830 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700831 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700832
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000833err:
834 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700835 return status;
836}
837
Sathya Perlab31c50a2009-09-17 10:30:13 -0700838/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000839int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000840 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700841{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700842 struct be_mcc_wrb *wrb;
843 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700844 int status;
845
Sathya Perlab31c50a2009-09-17 10:30:13 -0700846 spin_lock_bh(&adapter->mcc_lock);
847
848 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000849 if (!wrb) {
850 status = -EBUSY;
851 goto err;
852 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700853 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700854
Somnath Kotur106df1e2011-10-27 07:12:13 +0000855 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
856 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700857
Ajit Khapardef8617e02011-02-11 13:36:37 +0000858 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700859 req->if_id = cpu_to_le32(if_id);
860 memcpy(req->mac_address, mac_addr, ETH_ALEN);
861
Sathya Perlab31c50a2009-09-17 10:30:13 -0700862 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700863 if (!status) {
864 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
865 *pmac_id = le32_to_cpu(resp->pmac_id);
866 }
867
Sathya Perla713d03942009-11-22 22:02:45 +0000868err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700869 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000870
871 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
872 status = -EPERM;
873
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700874 return status;
875}
876
Sathya Perlab31c50a2009-09-17 10:30:13 -0700877/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000878int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700879{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700880 struct be_mcc_wrb *wrb;
881 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700882 int status;
883
Sathya Perla30128032011-11-10 19:17:57 +0000884 if (pmac_id == -1)
885 return 0;
886
Sathya Perlab31c50a2009-09-17 10:30:13 -0700887 spin_lock_bh(&adapter->mcc_lock);
888
889 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000890 if (!wrb) {
891 status = -EBUSY;
892 goto err;
893 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700894 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700895
Somnath Kotur106df1e2011-10-27 07:12:13 +0000896 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
897 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700898
Ajit Khapardef8617e02011-02-11 13:36:37 +0000899 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700900 req->if_id = cpu_to_le32(if_id);
901 req->pmac_id = cpu_to_le32(pmac_id);
902
Sathya Perlab31c50a2009-09-17 10:30:13 -0700903 status = be_mcc_notify_wait(adapter);
904
Sathya Perla713d03942009-11-22 22:02:45 +0000905err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700906 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700907 return status;
908}
909
Sathya Perlab31c50a2009-09-17 10:30:13 -0700910/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000911int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
912 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700913{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700914 struct be_mcc_wrb *wrb;
915 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700916 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700917 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700918 int status;
919
Ivan Vecera29849612010-12-14 05:43:19 +0000920 if (mutex_lock_interruptible(&adapter->mbox_lock))
921 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700922
923 wrb = wrb_from_mbox(adapter);
924 req = embedded_payload(wrb);
925 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700926
Somnath Kotur106df1e2011-10-27 07:12:13 +0000927 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
928 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700929
930 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000931 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000932 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000933 req->page_size = 1; /* 1 for 4K */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000934 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
935 no_delay);
936 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
937 __ilog2_u32(cq->len/256));
938 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
939 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
940 ctxt, 1);
941 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
942 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000943 } else {
944 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
945 coalesce_wm);
946 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
947 ctxt, no_delay);
948 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
949 __ilog2_u32(cq->len/256));
950 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000951 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
952 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000953 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700954
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700955 be_dws_cpu_to_le(ctxt, sizeof(req->context));
956
957 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
958
Sathya Perlab31c50a2009-09-17 10:30:13 -0700959 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700960 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700961 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700962 cq->id = le16_to_cpu(resp->cq_id);
963 cq->created = true;
964 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700965
Ivan Vecera29849612010-12-14 05:43:19 +0000966 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000967
968 return status;
969}
970
971static u32 be_encoded_q_len(int q_len)
972{
973 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
974 if (len_encoded == 16)
975 len_encoded = 0;
976 return len_encoded;
977}
978
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000979int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000980 struct be_queue_info *mccq,
981 struct be_queue_info *cq)
982{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700983 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000984 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000985 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700986 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000987 int status;
988
Ivan Vecera29849612010-12-14 05:43:19 +0000989 if (mutex_lock_interruptible(&adapter->mbox_lock))
990 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700991
992 wrb = wrb_from_mbox(adapter);
993 req = embedded_payload(wrb);
994 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000995
Somnath Kotur106df1e2011-10-27 07:12:13 +0000996 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
997 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000998
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000999 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001000 if (lancer_chip(adapter)) {
1001 req->hdr.version = 1;
1002 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001003
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001004 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
1005 be_encoded_q_len(mccq->len));
1006 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
1007 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
1008 ctxt, cq->id);
1009 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
1010 ctxt, 1);
1011
1012 } else {
1013 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1014 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1015 be_encoded_q_len(mccq->len));
1016 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1017 }
1018
Somnath Koturcc4ce022010-10-21 07:11:14 -07001019 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001020 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001021 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1022
1023 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1024
Sathya Perlab31c50a2009-09-17 10:30:13 -07001025 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001026 if (!status) {
1027 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1028 mccq->id = le16_to_cpu(resp->id);
1029 mccq->created = true;
1030 }
Ivan Vecera29849612010-12-14 05:43:19 +00001031 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001032
1033 return status;
1034}
1035
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001036int be_cmd_mccq_org_create(struct be_adapter *adapter,
1037 struct be_queue_info *mccq,
1038 struct be_queue_info *cq)
1039{
1040 struct be_mcc_wrb *wrb;
1041 struct be_cmd_req_mcc_create *req;
1042 struct be_dma_mem *q_mem = &mccq->dma_mem;
1043 void *ctxt;
1044 int status;
1045
1046 if (mutex_lock_interruptible(&adapter->mbox_lock))
1047 return -1;
1048
1049 wrb = wrb_from_mbox(adapter);
1050 req = embedded_payload(wrb);
1051 ctxt = &req->context;
1052
Somnath Kotur106df1e2011-10-27 07:12:13 +00001053 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1054 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001055
1056 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1057
1058 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1059 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
1060 be_encoded_q_len(mccq->len));
1061 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1062
1063 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1064
1065 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1066
1067 status = be_mbox_notify_wait(adapter);
1068 if (!status) {
1069 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
1070 mccq->id = le16_to_cpu(resp->id);
1071 mccq->created = true;
1072 }
1073
1074 mutex_unlock(&adapter->mbox_lock);
1075 return status;
1076}
1077
1078int be_cmd_mccq_create(struct be_adapter *adapter,
1079 struct be_queue_info *mccq,
1080 struct be_queue_info *cq)
1081{
1082 int status;
1083
1084 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
1085 if (status && !lancer_chip(adapter)) {
1086 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1087 "or newer to avoid conflicting priorities between NIC "
1088 "and FCoE traffic");
1089 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1090 }
1091 return status;
1092}
1093
Sathya Perla8788fdc2009-07-27 22:52:03 +00001094int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001095 struct be_queue_info *txq,
1096 struct be_queue_info *cq)
1097{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001098 struct be_mcc_wrb *wrb;
1099 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001100 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001101 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001103
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001104 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001105
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001106 wrb = wrb_from_mccq(adapter);
1107 if (!wrb) {
1108 status = -EBUSY;
1109 goto err;
1110 }
1111
Sathya Perlab31c50a2009-09-17 10:30:13 -07001112 req = embedded_payload(wrb);
1113 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001114
Somnath Kotur106df1e2011-10-27 07:12:13 +00001115 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1116 OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001117
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001118 if (lancer_chip(adapter)) {
1119 req->hdr.version = 1;
1120 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
1121 adapter->if_handle);
1122 }
1123
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001124 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1125 req->ulp_num = BE_ULP1_NUM;
1126 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
1127
Sathya Perlab31c50a2009-09-17 10:30:13 -07001128 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
1129 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001130 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
1131 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
1132
1133 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1134
1135 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1136
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001137 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001138 if (!status) {
1139 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
1140 txq->id = le16_to_cpu(resp->cid);
1141 txq->created = true;
1142 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001143
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +00001144err:
1145 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001146
1147 return status;
1148}
1149
Sathya Perla482c9e72011-06-29 23:33:17 +00001150/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001151int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001152 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001153 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001154{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001155 struct be_mcc_wrb *wrb;
1156 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001157 struct be_dma_mem *q_mem = &rxq->dma_mem;
1158 int status;
1159
Sathya Perla482c9e72011-06-29 23:33:17 +00001160 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001161
Sathya Perla482c9e72011-06-29 23:33:17 +00001162 wrb = wrb_from_mccq(adapter);
1163 if (!wrb) {
1164 status = -EBUSY;
1165 goto err;
1166 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001167 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001168
Somnath Kotur106df1e2011-10-27 07:12:13 +00001169 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1170 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001171
1172 req->cq_id = cpu_to_le16(cq_id);
1173 req->frag_size = fls(frag_size) - 1;
1174 req->num_pages = 2;
1175 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1176 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001177 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001178 req->rss_queue = cpu_to_le32(rss);
1179
Sathya Perla482c9e72011-06-29 23:33:17 +00001180 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001181 if (!status) {
1182 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1183 rxq->id = le16_to_cpu(resp->id);
1184 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001185 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001186 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001187
Sathya Perla482c9e72011-06-29 23:33:17 +00001188err:
1189 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001190 return status;
1191}
1192
Sathya Perlab31c50a2009-09-17 10:30:13 -07001193/* Generic destroyer function for all types of queues
1194 * Uses Mbox
1195 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001196int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001197 int queue_type)
1198{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001199 struct be_mcc_wrb *wrb;
1200 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001201 u8 subsys = 0, opcode = 0;
1202 int status;
1203
Ivan Vecera29849612010-12-14 05:43:19 +00001204 if (mutex_lock_interruptible(&adapter->mbox_lock))
1205 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001206
Sathya Perlab31c50a2009-09-17 10:30:13 -07001207 wrb = wrb_from_mbox(adapter);
1208 req = embedded_payload(wrb);
1209
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001210 switch (queue_type) {
1211 case QTYPE_EQ:
1212 subsys = CMD_SUBSYSTEM_COMMON;
1213 opcode = OPCODE_COMMON_EQ_DESTROY;
1214 break;
1215 case QTYPE_CQ:
1216 subsys = CMD_SUBSYSTEM_COMMON;
1217 opcode = OPCODE_COMMON_CQ_DESTROY;
1218 break;
1219 case QTYPE_TXQ:
1220 subsys = CMD_SUBSYSTEM_ETH;
1221 opcode = OPCODE_ETH_TX_DESTROY;
1222 break;
1223 case QTYPE_RXQ:
1224 subsys = CMD_SUBSYSTEM_ETH;
1225 opcode = OPCODE_ETH_RX_DESTROY;
1226 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001227 case QTYPE_MCCQ:
1228 subsys = CMD_SUBSYSTEM_COMMON;
1229 opcode = OPCODE_COMMON_MCC_DESTROY;
1230 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001231 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001232 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001233 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001234
Somnath Kotur106df1e2011-10-27 07:12:13 +00001235 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1236 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001237 req->id = cpu_to_le16(q->id);
1238
Sathya Perlab31c50a2009-09-17 10:30:13 -07001239 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001240 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001241
Ivan Vecera29849612010-12-14 05:43:19 +00001242 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001243 return status;
1244}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001245
Sathya Perla482c9e72011-06-29 23:33:17 +00001246/* Uses MCC */
1247int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1248{
1249 struct be_mcc_wrb *wrb;
1250 struct be_cmd_req_q_destroy *req;
1251 int status;
1252
1253 spin_lock_bh(&adapter->mcc_lock);
1254
1255 wrb = wrb_from_mccq(adapter);
1256 if (!wrb) {
1257 status = -EBUSY;
1258 goto err;
1259 }
1260 req = embedded_payload(wrb);
1261
Somnath Kotur106df1e2011-10-27 07:12:13 +00001262 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1263 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001264 req->id = cpu_to_le16(q->id);
1265
1266 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001267 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001268
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
Sathya Perlaca34fe32012-11-06 17:48:56 +00001364 /* version 1 of the cmd is not supported only by BE2 */
1365 if (!BE2_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001366 hdr->version = 1;
1367
Sathya Perlab31c50a2009-09-17 10:30:13 -07001368 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001369 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001370
Sathya Perla713d03942009-11-22 22:02:45 +00001371err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001372 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001373 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001374}
1375
Selvin Xavier005d5692011-05-16 07:36:35 +00001376/* Lancer Stats */
1377int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1378 struct be_dma_mem *nonemb_cmd)
1379{
1380
1381 struct be_mcc_wrb *wrb;
1382 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001383 int status = 0;
1384
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001385 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1386 CMD_SUBSYSTEM_ETH))
1387 return -EPERM;
1388
Selvin Xavier005d5692011-05-16 07:36:35 +00001389 spin_lock_bh(&adapter->mcc_lock);
1390
1391 wrb = wrb_from_mccq(adapter);
1392 if (!wrb) {
1393 status = -EBUSY;
1394 goto err;
1395 }
1396 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001397
Somnath Kotur106df1e2011-10-27 07:12:13 +00001398 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1399 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1400 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001401
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001402 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001403 req->cmd_params.params.reset_stats = 0;
1404
Selvin Xavier005d5692011-05-16 07:36:35 +00001405 be_mcc_notify(adapter);
1406 adapter->stats_cmd_sent = true;
1407
1408err:
1409 spin_unlock_bh(&adapter->mcc_lock);
1410 return status;
1411}
1412
Sathya Perla323ff712012-09-28 04:39:43 +00001413static int be_mac_to_link_speed(int mac_speed)
1414{
1415 switch (mac_speed) {
1416 case PHY_LINK_SPEED_ZERO:
1417 return 0;
1418 case PHY_LINK_SPEED_10MBPS:
1419 return 10;
1420 case PHY_LINK_SPEED_100MBPS:
1421 return 100;
1422 case PHY_LINK_SPEED_1GBPS:
1423 return 1000;
1424 case PHY_LINK_SPEED_10GBPS:
1425 return 10000;
1426 }
1427 return 0;
1428}
1429
1430/* Uses synchronous mcc
1431 * Returns link_speed in Mbps
1432 */
1433int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1434 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001435{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001436 struct be_mcc_wrb *wrb;
1437 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001438 int status;
1439
Sathya Perlab31c50a2009-09-17 10:30:13 -07001440 spin_lock_bh(&adapter->mcc_lock);
1441
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001442 if (link_status)
1443 *link_status = LINK_DOWN;
1444
Sathya Perlab31c50a2009-09-17 10:30:13 -07001445 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001446 if (!wrb) {
1447 status = -EBUSY;
1448 goto err;
1449 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001450 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001451
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001452 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1453 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1454
Sathya Perlaca34fe32012-11-06 17:48:56 +00001455 /* version 1 of the cmd is not supported only by BE2 */
1456 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001457 req->hdr.version = 1;
1458
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001459 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001460
Sathya Perlab31c50a2009-09-17 10:30:13 -07001461 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001462 if (!status) {
1463 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sathya Perla323ff712012-09-28 04:39:43 +00001464 if (link_speed) {
1465 *link_speed = resp->link_speed ?
1466 le16_to_cpu(resp->link_speed) * 10 :
1467 be_mac_to_link_speed(resp->mac_speed);
1468
1469 if (!resp->logical_link_status)
1470 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001471 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001472 if (link_status)
1473 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001474 }
1475
Sathya Perla713d03942009-11-22 22:02:45 +00001476err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001477 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001478 return status;
1479}
1480
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001481/* Uses synchronous mcc */
1482int be_cmd_get_die_temperature(struct be_adapter *adapter)
1483{
1484 struct be_mcc_wrb *wrb;
1485 struct be_cmd_req_get_cntl_addnl_attribs *req;
1486 int status;
1487
1488 spin_lock_bh(&adapter->mcc_lock);
1489
1490 wrb = wrb_from_mccq(adapter);
1491 if (!wrb) {
1492 status = -EBUSY;
1493 goto err;
1494 }
1495 req = embedded_payload(wrb);
1496
Somnath Kotur106df1e2011-10-27 07:12:13 +00001497 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1498 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1499 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001500
Somnath Kotur3de09452011-09-30 07:25:05 +00001501 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001502
1503err:
1504 spin_unlock_bh(&adapter->mcc_lock);
1505 return status;
1506}
1507
Somnath Kotur311fddc2011-03-16 21:22:43 +00001508/* Uses synchronous mcc */
1509int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1510{
1511 struct be_mcc_wrb *wrb;
1512 struct be_cmd_req_get_fat *req;
1513 int status;
1514
1515 spin_lock_bh(&adapter->mcc_lock);
1516
1517 wrb = wrb_from_mccq(adapter);
1518 if (!wrb) {
1519 status = -EBUSY;
1520 goto err;
1521 }
1522 req = embedded_payload(wrb);
1523
Somnath Kotur106df1e2011-10-27 07:12:13 +00001524 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1525 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001526 req->fat_operation = cpu_to_le32(QUERY_FAT);
1527 status = be_mcc_notify_wait(adapter);
1528 if (!status) {
1529 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1530 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001531 *log_size = le32_to_cpu(resp->log_size) -
1532 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001533 }
1534err:
1535 spin_unlock_bh(&adapter->mcc_lock);
1536 return status;
1537}
1538
1539void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1540{
1541 struct be_dma_mem get_fat_cmd;
1542 struct be_mcc_wrb *wrb;
1543 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001544 u32 offset = 0, total_size, buf_size,
1545 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001546 int status;
1547
1548 if (buf_len == 0)
1549 return;
1550
1551 total_size = buf_len;
1552
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001553 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1554 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1555 get_fat_cmd.size,
1556 &get_fat_cmd.dma);
1557 if (!get_fat_cmd.va) {
1558 status = -ENOMEM;
1559 dev_err(&adapter->pdev->dev,
1560 "Memory allocation failure while retrieving FAT data\n");
1561 return;
1562 }
1563
Somnath Kotur311fddc2011-03-16 21:22:43 +00001564 spin_lock_bh(&adapter->mcc_lock);
1565
Somnath Kotur311fddc2011-03-16 21:22:43 +00001566 while (total_size) {
1567 buf_size = min(total_size, (u32)60*1024);
1568 total_size -= buf_size;
1569
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001570 wrb = wrb_from_mccq(adapter);
1571 if (!wrb) {
1572 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001573 goto err;
1574 }
1575 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001576
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001577 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001578 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1579 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1580 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001581
1582 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1583 req->read_log_offset = cpu_to_le32(log_offset);
1584 req->read_log_length = cpu_to_le32(buf_size);
1585 req->data_buffer_size = cpu_to_le32(buf_size);
1586
1587 status = be_mcc_notify_wait(adapter);
1588 if (!status) {
1589 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1590 memcpy(buf + offset,
1591 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001592 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001593 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001594 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001595 goto err;
1596 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001597 offset += buf_size;
1598 log_offset += buf_size;
1599 }
1600err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001601 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1602 get_fat_cmd.va,
1603 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001604 spin_unlock_bh(&adapter->mcc_lock);
1605}
1606
Sathya Perla04b71172011-09-27 13:30:27 -04001607/* Uses synchronous mcc */
1608int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1609 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001610{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001611 struct be_mcc_wrb *wrb;
1612 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001613 int status;
1614
Sathya Perla04b71172011-09-27 13:30:27 -04001615 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001616
Sathya Perla04b71172011-09-27 13:30:27 -04001617 wrb = wrb_from_mccq(adapter);
1618 if (!wrb) {
1619 status = -EBUSY;
1620 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001621 }
1622
Sathya Perla04b71172011-09-27 13:30:27 -04001623 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001624
Somnath Kotur106df1e2011-10-27 07:12:13 +00001625 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1626 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001627 status = be_mcc_notify_wait(adapter);
1628 if (!status) {
1629 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1630 strcpy(fw_ver, resp->firmware_version_string);
1631 if (fw_on_flash)
1632 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1633 }
1634err:
1635 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001636 return status;
1637}
1638
Sathya Perlab31c50a2009-09-17 10:30:13 -07001639/* set the EQ delay interval of an EQ to specified value
1640 * Uses async mcc
1641 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001642int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001643{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001644 struct be_mcc_wrb *wrb;
1645 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001646 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001647
Sathya Perlab31c50a2009-09-17 10:30:13 -07001648 spin_lock_bh(&adapter->mcc_lock);
1649
1650 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001651 if (!wrb) {
1652 status = -EBUSY;
1653 goto err;
1654 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001655 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001656
Somnath Kotur106df1e2011-10-27 07:12:13 +00001657 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1658 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001659
1660 req->num_eq = cpu_to_le32(1);
1661 req->delay[0].eq_id = cpu_to_le32(eq_id);
1662 req->delay[0].phase = 0;
1663 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1664
Sathya Perlab31c50a2009-09-17 10:30:13 -07001665 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001666
Sathya Perla713d03942009-11-22 22:02:45 +00001667err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001668 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001669 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001670}
1671
Sathya Perlab31c50a2009-09-17 10:30:13 -07001672/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001673int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001674 u32 num, bool untagged, bool promiscuous)
1675{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001676 struct be_mcc_wrb *wrb;
1677 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001678 int status;
1679
Sathya Perlab31c50a2009-09-17 10:30:13 -07001680 spin_lock_bh(&adapter->mcc_lock);
1681
1682 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001683 if (!wrb) {
1684 status = -EBUSY;
1685 goto err;
1686 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001687 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001688
Somnath Kotur106df1e2011-10-27 07:12:13 +00001689 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1690 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001691
1692 req->interface_id = if_id;
1693 req->promiscuous = promiscuous;
1694 req->untagged = untagged;
1695 req->num_vlan = num;
1696 if (!promiscuous) {
1697 memcpy(req->normal_vlan, vtag_array,
1698 req->num_vlan * sizeof(vtag_array[0]));
1699 }
1700
Sathya Perlab31c50a2009-09-17 10:30:13 -07001701 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001702
Sathya Perla713d03942009-11-22 22:02:45 +00001703err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001704 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001705 return status;
1706}
1707
Sathya Perla5b8821b2011-08-02 19:57:44 +00001708int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001709{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001710 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001711 struct be_dma_mem *mem = &adapter->rx_filter;
1712 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001713 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001714
Sathya Perla8788fdc2009-07-27 22:52:03 +00001715 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001716
Sathya Perlab31c50a2009-09-17 10:30:13 -07001717 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001718 if (!wrb) {
1719 status = -EBUSY;
1720 goto err;
1721 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001722 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001723 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1724 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1725 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001726
Sathya Perla5b8821b2011-08-02 19:57:44 +00001727 req->if_id = cpu_to_le32(adapter->if_handle);
1728 if (flags & IFF_PROMISC) {
1729 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1730 BE_IF_FLAGS_VLAN_PROMISCUOUS);
1731 if (value == ON)
1732 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001733 BE_IF_FLAGS_VLAN_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001734 } else if (flags & IFF_ALLMULTI) {
1735 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001736 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001737 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001738 struct netdev_hw_addr *ha;
1739 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001740
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001741 req->if_flags_mask = req->if_flags =
1742 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001743
1744 /* Reset mcast promisc mode if already set by setting mask
1745 * and not setting flags field
1746 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001747 req->if_flags_mask |=
1748 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
1749 adapter->if_cap_flags);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001750
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001751 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001752 netdev_for_each_mc_addr(ha, adapter->netdev)
1753 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1754 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001755
Sathya Perla0d1d5872011-08-03 05:19:27 -07001756 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001757err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001758 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001759 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001760}
1761
Sathya Perlab31c50a2009-09-17 10:30:13 -07001762/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001763int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001764{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001765 struct be_mcc_wrb *wrb;
1766 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001767 int status;
1768
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001769 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
1770 CMD_SUBSYSTEM_COMMON))
1771 return -EPERM;
1772
Sathya Perlab31c50a2009-09-17 10:30:13 -07001773 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001774
Sathya Perlab31c50a2009-09-17 10:30:13 -07001775 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001776 if (!wrb) {
1777 status = -EBUSY;
1778 goto err;
1779 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001780 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001781
Somnath Kotur106df1e2011-10-27 07:12:13 +00001782 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1783 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001784
1785 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1786 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1787
Sathya Perlab31c50a2009-09-17 10:30:13 -07001788 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001789
Sathya Perla713d03942009-11-22 22:02:45 +00001790err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001791 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001792 return status;
1793}
1794
Sathya Perlab31c50a2009-09-17 10:30:13 -07001795/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001796int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001797{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001798 struct be_mcc_wrb *wrb;
1799 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001800 int status;
1801
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001802 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
1803 CMD_SUBSYSTEM_COMMON))
1804 return -EPERM;
1805
Sathya Perlab31c50a2009-09-17 10:30:13 -07001806 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001807
Sathya Perlab31c50a2009-09-17 10:30:13 -07001808 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001809 if (!wrb) {
1810 status = -EBUSY;
1811 goto err;
1812 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001813 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001814
Somnath Kotur106df1e2011-10-27 07:12:13 +00001815 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1816 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001817
Sathya Perlab31c50a2009-09-17 10:30:13 -07001818 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001819 if (!status) {
1820 struct be_cmd_resp_get_flow_control *resp =
1821 embedded_payload(wrb);
1822 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1823 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1824 }
1825
Sathya Perla713d03942009-11-22 22:02:45 +00001826err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001827 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001828 return status;
1829}
1830
Sathya Perlab31c50a2009-09-17 10:30:13 -07001831/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001832int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1833 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001834{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001835 struct be_mcc_wrb *wrb;
1836 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001837 int status;
1838
Ivan Vecera29849612010-12-14 05:43:19 +00001839 if (mutex_lock_interruptible(&adapter->mbox_lock))
1840 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001841
Sathya Perlab31c50a2009-09-17 10:30:13 -07001842 wrb = wrb_from_mbox(adapter);
1843 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001844
Somnath Kotur106df1e2011-10-27 07:12:13 +00001845 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1846 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001847
Sathya Perlab31c50a2009-09-17 10:30:13 -07001848 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001849 if (!status) {
1850 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1851 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001852 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001853 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001854 }
1855
Ivan Vecera29849612010-12-14 05:43:19 +00001856 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001857 return status;
1858}
sarveshwarb14074ea2009-08-05 13:05:24 -07001859
Sathya Perlab31c50a2009-09-17 10:30:13 -07001860/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001861int be_cmd_reset_function(struct be_adapter *adapter)
1862{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001863 struct be_mcc_wrb *wrb;
1864 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001865 int status;
1866
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00001867 if (lancer_chip(adapter)) {
1868 status = lancer_wait_ready(adapter);
1869 if (!status) {
1870 iowrite32(SLI_PORT_CONTROL_IP_MASK,
1871 adapter->db + SLIPORT_CONTROL_OFFSET);
1872 status = lancer_test_and_set_rdy_state(adapter);
1873 }
1874 if (status) {
1875 dev_err(&adapter->pdev->dev,
1876 "Adapter in non recoverable error\n");
1877 }
1878 return status;
1879 }
1880
Ivan Vecera29849612010-12-14 05:43:19 +00001881 if (mutex_lock_interruptible(&adapter->mbox_lock))
1882 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001883
Sathya Perlab31c50a2009-09-17 10:30:13 -07001884 wrb = wrb_from_mbox(adapter);
1885 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001886
Somnath Kotur106df1e2011-10-27 07:12:13 +00001887 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1888 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001889
Sathya Perlab31c50a2009-09-17 10:30:13 -07001890 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001891
Ivan Vecera29849612010-12-14 05:43:19 +00001892 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001893 return status;
1894}
Ajit Khaparde84517482009-09-04 03:12:16 +00001895
Sathya Perla3abcded2010-10-03 22:12:27 -07001896int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1897{
1898 struct be_mcc_wrb *wrb;
1899 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001900 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1901 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1902 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001903 int status;
1904
Ivan Vecera29849612010-12-14 05:43:19 +00001905 if (mutex_lock_interruptible(&adapter->mbox_lock))
1906 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001907
1908 wrb = wrb_from_mbox(adapter);
1909 req = embedded_payload(wrb);
1910
Somnath Kotur106df1e2011-10-27 07:12:13 +00001911 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1912 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001913
1914 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perla1ca7ba92012-02-23 18:50:16 +00001915 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 |
1916 RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6);
Padmanabh Ratnakard3bd3a52012-07-12 03:57:47 +00001917
1918 if (lancer_chip(adapter) || skyhawk_chip(adapter)) {
1919 req->hdr.version = 1;
1920 req->enable_rss |= cpu_to_le16(RSS_ENABLE_UDP_IPV4 |
1921 RSS_ENABLE_UDP_IPV6);
1922 }
1923
Sathya Perla3abcded2010-10-03 22:12:27 -07001924 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1925 memcpy(req->cpu_table, rsstable, table_size);
1926 memcpy(req->hash, myhash, sizeof(myhash));
1927 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1928
1929 status = be_mbox_notify_wait(adapter);
1930
Ivan Vecera29849612010-12-14 05:43:19 +00001931 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001932 return status;
1933}
1934
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001935/* Uses sync mcc */
1936int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1937 u8 bcn, u8 sts, u8 state)
1938{
1939 struct be_mcc_wrb *wrb;
1940 struct be_cmd_req_enable_disable_beacon *req;
1941 int status;
1942
1943 spin_lock_bh(&adapter->mcc_lock);
1944
1945 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001946 if (!wrb) {
1947 status = -EBUSY;
1948 goto err;
1949 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001950 req = embedded_payload(wrb);
1951
Somnath Kotur106df1e2011-10-27 07:12:13 +00001952 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1953 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001954
1955 req->port_num = port_num;
1956 req->beacon_state = state;
1957 req->beacon_duration = bcn;
1958 req->status_duration = sts;
1959
1960 status = be_mcc_notify_wait(adapter);
1961
Sathya Perla713d03942009-11-22 22:02:45 +00001962err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001963 spin_unlock_bh(&adapter->mcc_lock);
1964 return status;
1965}
1966
1967/* Uses sync mcc */
1968int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1969{
1970 struct be_mcc_wrb *wrb;
1971 struct be_cmd_req_get_beacon_state *req;
1972 int status;
1973
1974 spin_lock_bh(&adapter->mcc_lock);
1975
1976 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001977 if (!wrb) {
1978 status = -EBUSY;
1979 goto err;
1980 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001981 req = embedded_payload(wrb);
1982
Somnath Kotur106df1e2011-10-27 07:12:13 +00001983 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1984 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001985
1986 req->port_num = port_num;
1987
1988 status = be_mcc_notify_wait(adapter);
1989 if (!status) {
1990 struct be_cmd_resp_get_beacon_state *resp =
1991 embedded_payload(wrb);
1992 *state = resp->beacon_state;
1993 }
1994
Sathya Perla713d03942009-11-22 22:02:45 +00001995err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001996 spin_unlock_bh(&adapter->mcc_lock);
1997 return status;
1998}
1999
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002000int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002001 u32 data_size, u32 data_offset,
2002 const char *obj_name, u32 *data_written,
2003 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002004{
2005 struct be_mcc_wrb *wrb;
2006 struct lancer_cmd_req_write_object *req;
2007 struct lancer_cmd_resp_write_object *resp;
2008 void *ctxt = NULL;
2009 int status;
2010
2011 spin_lock_bh(&adapter->mcc_lock);
2012 adapter->flash_status = 0;
2013
2014 wrb = wrb_from_mccq(adapter);
2015 if (!wrb) {
2016 status = -EBUSY;
2017 goto err_unlock;
2018 }
2019
2020 req = embedded_payload(wrb);
2021
Somnath Kotur106df1e2011-10-27 07:12:13 +00002022 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002023 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00002024 sizeof(struct lancer_cmd_req_write_object), wrb,
2025 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002026
2027 ctxt = &req->context;
2028 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2029 write_length, ctxt, data_size);
2030
2031 if (data_size == 0)
2032 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2033 eof, ctxt, 1);
2034 else
2035 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
2036 eof, ctxt, 0);
2037
2038 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2039 req->write_offset = cpu_to_le32(data_offset);
2040 strcpy(req->object_name, obj_name);
2041 req->descriptor_count = cpu_to_le32(1);
2042 req->buf_len = cpu_to_le32(data_size);
2043 req->addr_low = cpu_to_le32((cmd->dma +
2044 sizeof(struct lancer_cmd_req_write_object))
2045 & 0xFFFFFFFF);
2046 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2047 sizeof(struct lancer_cmd_req_write_object)));
2048
2049 be_mcc_notify(adapter);
2050 spin_unlock_bh(&adapter->mcc_lock);
2051
2052 if (!wait_for_completion_timeout(&adapter->flash_compl,
Padmanabh Ratnakar804c7512012-04-25 01:46:18 +00002053 msecs_to_jiffies(30000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002054 status = -1;
2055 else
2056 status = adapter->flash_status;
2057
2058 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002059 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002060 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002061 *change_status = resp->change_status;
2062 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002063 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002064 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002065
2066 return status;
2067
2068err_unlock:
2069 spin_unlock_bh(&adapter->mcc_lock);
2070 return status;
2071}
2072
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002073int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
2074 u32 data_size, u32 data_offset, const char *obj_name,
2075 u32 *data_read, u32 *eof, u8 *addn_status)
2076{
2077 struct be_mcc_wrb *wrb;
2078 struct lancer_cmd_req_read_object *req;
2079 struct lancer_cmd_resp_read_object *resp;
2080 int status;
2081
2082 spin_lock_bh(&adapter->mcc_lock);
2083
2084 wrb = wrb_from_mccq(adapter);
2085 if (!wrb) {
2086 status = -EBUSY;
2087 goto err_unlock;
2088 }
2089
2090 req = embedded_payload(wrb);
2091
2092 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2093 OPCODE_COMMON_READ_OBJECT,
2094 sizeof(struct lancer_cmd_req_read_object), wrb,
2095 NULL);
2096
2097 req->desired_read_len = cpu_to_le32(data_size);
2098 req->read_offset = cpu_to_le32(data_offset);
2099 strcpy(req->object_name, obj_name);
2100 req->descriptor_count = cpu_to_le32(1);
2101 req->buf_len = cpu_to_le32(data_size);
2102 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2103 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2104
2105 status = be_mcc_notify_wait(adapter);
2106
2107 resp = embedded_payload(wrb);
2108 if (!status) {
2109 *data_read = le32_to_cpu(resp->actual_read_len);
2110 *eof = le32_to_cpu(resp->eof);
2111 } else {
2112 *addn_status = resp->additional_status;
2113 }
2114
2115err_unlock:
2116 spin_unlock_bh(&adapter->mcc_lock);
2117 return status;
2118}
2119
Ajit Khaparde84517482009-09-04 03:12:16 +00002120int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
2121 u32 flash_type, u32 flash_opcode, u32 buf_size)
2122{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002123 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002124 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002125 int status;
2126
Sathya Perlab31c50a2009-09-17 10:30:13 -07002127 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002128 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002129
2130 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002131 if (!wrb) {
2132 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002133 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002134 }
2135 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002136
Somnath Kotur106df1e2011-10-27 07:12:13 +00002137 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2138 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002139
2140 req->params.op_type = cpu_to_le32(flash_type);
2141 req->params.op_code = cpu_to_le32(flash_opcode);
2142 req->params.data_buf_size = cpu_to_le32(buf_size);
2143
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002144 be_mcc_notify(adapter);
2145 spin_unlock_bh(&adapter->mcc_lock);
2146
2147 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00002148 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002149 status = -1;
2150 else
2151 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002152
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002153 return status;
2154
2155err_unlock:
2156 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002157 return status;
2158}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002159
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002160int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2161 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002162{
2163 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002164 struct be_cmd_read_flash_crc *req;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002165 int status;
2166
2167 spin_lock_bh(&adapter->mcc_lock);
2168
2169 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002170 if (!wrb) {
2171 status = -EBUSY;
2172 goto err;
2173 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002174 req = embedded_payload(wrb);
2175
Somnath Kotur106df1e2011-10-27 07:12:13 +00002176 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002177 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2178 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002179
Padmanabh Ratnakarc165541e2012-04-25 01:47:15 +00002180 req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002181 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002182 req->params.offset = cpu_to_le32(offset);
2183 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002184
2185 status = be_mcc_notify_wait(adapter);
2186 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002187 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002188
Sathya Perla713d03942009-11-22 22:02:45 +00002189err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002190 spin_unlock_bh(&adapter->mcc_lock);
2191 return status;
2192}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002193
Dan Carpenterc196b022010-05-26 04:47:39 +00002194int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002195 struct be_dma_mem *nonemb_cmd)
2196{
2197 struct be_mcc_wrb *wrb;
2198 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002199 int status;
2200
2201 spin_lock_bh(&adapter->mcc_lock);
2202
2203 wrb = wrb_from_mccq(adapter);
2204 if (!wrb) {
2205 status = -EBUSY;
2206 goto err;
2207 }
2208 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002209
Somnath Kotur106df1e2011-10-27 07:12:13 +00002210 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2211 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2212 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002213 memcpy(req->magic_mac, mac, ETH_ALEN);
2214
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002215 status = be_mcc_notify_wait(adapter);
2216
2217err:
2218 spin_unlock_bh(&adapter->mcc_lock);
2219 return status;
2220}
Suresh Rff33a6e2009-12-03 16:15:52 -08002221
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002222int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2223 u8 loopback_type, u8 enable)
2224{
2225 struct be_mcc_wrb *wrb;
2226 struct be_cmd_req_set_lmode *req;
2227 int status;
2228
2229 spin_lock_bh(&adapter->mcc_lock);
2230
2231 wrb = wrb_from_mccq(adapter);
2232 if (!wrb) {
2233 status = -EBUSY;
2234 goto err;
2235 }
2236
2237 req = embedded_payload(wrb);
2238
Somnath Kotur106df1e2011-10-27 07:12:13 +00002239 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2240 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2241 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002242
2243 req->src_port = port_num;
2244 req->dest_port = port_num;
2245 req->loopback_type = loopback_type;
2246 req->loopback_state = enable;
2247
2248 status = be_mcc_notify_wait(adapter);
2249err:
2250 spin_unlock_bh(&adapter->mcc_lock);
2251 return status;
2252}
2253
Suresh Rff33a6e2009-12-03 16:15:52 -08002254int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2255 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2256{
2257 struct be_mcc_wrb *wrb;
2258 struct be_cmd_req_loopback_test *req;
2259 int status;
2260
2261 spin_lock_bh(&adapter->mcc_lock);
2262
2263 wrb = wrb_from_mccq(adapter);
2264 if (!wrb) {
2265 status = -EBUSY;
2266 goto err;
2267 }
2268
2269 req = embedded_payload(wrb);
2270
Somnath Kotur106df1e2011-10-27 07:12:13 +00002271 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2272 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002273 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002274
2275 req->pattern = cpu_to_le64(pattern);
2276 req->src_port = cpu_to_le32(port_num);
2277 req->dest_port = cpu_to_le32(port_num);
2278 req->pkt_size = cpu_to_le32(pkt_size);
2279 req->num_pkts = cpu_to_le32(num_pkts);
2280 req->loopback_type = cpu_to_le32(loopback_type);
2281
2282 status = be_mcc_notify_wait(adapter);
2283 if (!status) {
2284 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2285 status = le32_to_cpu(resp->status);
2286 }
2287
2288err:
2289 spin_unlock_bh(&adapter->mcc_lock);
2290 return status;
2291}
2292
2293int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2294 u32 byte_cnt, struct be_dma_mem *cmd)
2295{
2296 struct be_mcc_wrb *wrb;
2297 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002298 int status;
2299 int i, j = 0;
2300
2301 spin_lock_bh(&adapter->mcc_lock);
2302
2303 wrb = wrb_from_mccq(adapter);
2304 if (!wrb) {
2305 status = -EBUSY;
2306 goto err;
2307 }
2308 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002309 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2310 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002311
2312 req->pattern = cpu_to_le64(pattern);
2313 req->byte_count = cpu_to_le32(byte_cnt);
2314 for (i = 0; i < byte_cnt; i++) {
2315 req->snd_buff[i] = (u8)(pattern >> (j*8));
2316 j++;
2317 if (j > 7)
2318 j = 0;
2319 }
2320
2321 status = be_mcc_notify_wait(adapter);
2322
2323 if (!status) {
2324 struct be_cmd_resp_ddrdma_test *resp;
2325 resp = cmd->va;
2326 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2327 resp->snd_err) {
2328 status = -1;
2329 }
2330 }
2331
2332err:
2333 spin_unlock_bh(&adapter->mcc_lock);
2334 return status;
2335}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002336
Dan Carpenterc196b022010-05-26 04:47:39 +00002337int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002338 struct be_dma_mem *nonemb_cmd)
2339{
2340 struct be_mcc_wrb *wrb;
2341 struct be_cmd_req_seeprom_read *req;
2342 struct be_sge *sge;
2343 int status;
2344
2345 spin_lock_bh(&adapter->mcc_lock);
2346
2347 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002348 if (!wrb) {
2349 status = -EBUSY;
2350 goto err;
2351 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002352 req = nonemb_cmd->va;
2353 sge = nonembedded_sgl(wrb);
2354
Somnath Kotur106df1e2011-10-27 07:12:13 +00002355 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2356 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2357 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002358
2359 status = be_mcc_notify_wait(adapter);
2360
Ajit Khapardee45ff012011-02-04 17:18:28 +00002361err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002362 spin_unlock_bh(&adapter->mcc_lock);
2363 return status;
2364}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002365
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002366int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002367{
2368 struct be_mcc_wrb *wrb;
2369 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002370 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002371 int status;
2372
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002373 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2374 CMD_SUBSYSTEM_COMMON))
2375 return -EPERM;
2376
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002377 spin_lock_bh(&adapter->mcc_lock);
2378
2379 wrb = wrb_from_mccq(adapter);
2380 if (!wrb) {
2381 status = -EBUSY;
2382 goto err;
2383 }
Sathya Perla306f1342011-08-02 19:57:45 +00002384 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2385 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2386 &cmd.dma);
2387 if (!cmd.va) {
2388 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2389 status = -ENOMEM;
2390 goto err;
2391 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002392
Sathya Perla306f1342011-08-02 19:57:45 +00002393 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002394
Somnath Kotur106df1e2011-10-27 07:12:13 +00002395 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2396 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2397 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002398
2399 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002400 if (!status) {
2401 struct be_phy_info *resp_phy_info =
2402 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002403 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2404 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002405 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002406 adapter->phy.auto_speeds_supported =
2407 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2408 adapter->phy.fixed_speeds_supported =
2409 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2410 adapter->phy.misc_params =
2411 le32_to_cpu(resp_phy_info->misc_params);
Sathya Perla306f1342011-08-02 19:57:45 +00002412 }
2413 pci_free_consistent(adapter->pdev, cmd.size,
2414 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002415err:
2416 spin_unlock_bh(&adapter->mcc_lock);
2417 return status;
2418}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002419
2420int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2421{
2422 struct be_mcc_wrb *wrb;
2423 struct be_cmd_req_set_qos *req;
2424 int status;
2425
2426 spin_lock_bh(&adapter->mcc_lock);
2427
2428 wrb = wrb_from_mccq(adapter);
2429 if (!wrb) {
2430 status = -EBUSY;
2431 goto err;
2432 }
2433
2434 req = embedded_payload(wrb);
2435
Somnath Kotur106df1e2011-10-27 07:12:13 +00002436 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2437 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002438
2439 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002440 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2441 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002442
2443 status = be_mcc_notify_wait(adapter);
2444
2445err:
2446 spin_unlock_bh(&adapter->mcc_lock);
2447 return status;
2448}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002449
2450int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2451{
2452 struct be_mcc_wrb *wrb;
2453 struct be_cmd_req_cntl_attribs *req;
2454 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002455 int status;
2456 int payload_len = max(sizeof(*req), sizeof(*resp));
2457 struct mgmt_controller_attrib *attribs;
2458 struct be_dma_mem attribs_cmd;
2459
2460 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2461 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2462 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2463 &attribs_cmd.dma);
2464 if (!attribs_cmd.va) {
2465 dev_err(&adapter->pdev->dev,
2466 "Memory allocation failure\n");
2467 return -ENOMEM;
2468 }
2469
2470 if (mutex_lock_interruptible(&adapter->mbox_lock))
2471 return -1;
2472
2473 wrb = wrb_from_mbox(adapter);
2474 if (!wrb) {
2475 status = -EBUSY;
2476 goto err;
2477 }
2478 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002479
Somnath Kotur106df1e2011-10-27 07:12:13 +00002480 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2481 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2482 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002483
2484 status = be_mbox_notify_wait(adapter);
2485 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002486 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002487 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2488 }
2489
2490err:
2491 mutex_unlock(&adapter->mbox_lock);
2492 pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
2493 attribs_cmd.dma);
2494 return status;
2495}
Sathya Perla2e588f82011-03-11 02:49:26 +00002496
2497/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002498int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002499{
2500 struct be_mcc_wrb *wrb;
2501 struct be_cmd_req_set_func_cap *req;
2502 int status;
2503
2504 if (mutex_lock_interruptible(&adapter->mbox_lock))
2505 return -1;
2506
2507 wrb = wrb_from_mbox(adapter);
2508 if (!wrb) {
2509 status = -EBUSY;
2510 goto err;
2511 }
2512
2513 req = embedded_payload(wrb);
2514
Somnath Kotur106df1e2011-10-27 07:12:13 +00002515 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2516 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002517
2518 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2519 CAPABILITY_BE3_NATIVE_ERX_API);
2520 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2521
2522 status = be_mbox_notify_wait(adapter);
2523 if (!status) {
2524 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2525 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2526 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002527 if (!adapter->be3_native)
2528 dev_warn(&adapter->pdev->dev,
2529 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002530 }
2531err:
2532 mutex_unlock(&adapter->mbox_lock);
2533 return status;
2534}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002535
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002536/* Get privilege(s) for a function */
2537int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2538 u32 domain)
2539{
2540 struct be_mcc_wrb *wrb;
2541 struct be_cmd_req_get_fn_privileges *req;
2542 int status;
2543
2544 spin_lock_bh(&adapter->mcc_lock);
2545
2546 wrb = wrb_from_mccq(adapter);
2547 if (!wrb) {
2548 status = -EBUSY;
2549 goto err;
2550 }
2551
2552 req = embedded_payload(wrb);
2553
2554 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2555 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2556 wrb, NULL);
2557
2558 req->hdr.domain = domain;
2559
2560 status = be_mcc_notify_wait(adapter);
2561 if (!status) {
2562 struct be_cmd_resp_get_fn_privileges *resp =
2563 embedded_payload(wrb);
2564 *privilege = le32_to_cpu(resp->privilege_mask);
2565 }
2566
2567err:
2568 spin_unlock_bh(&adapter->mcc_lock);
2569 return status;
2570}
2571
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002572/* Uses synchronous MCCQ */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002573int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
2574 bool *pmac_id_active, u32 *pmac_id, u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002575{
2576 struct be_mcc_wrb *wrb;
2577 struct be_cmd_req_get_mac_list *req;
2578 int status;
2579 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002580 struct be_dma_mem get_mac_list_cmd;
2581 int i;
2582
2583 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2584 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2585 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2586 get_mac_list_cmd.size,
2587 &get_mac_list_cmd.dma);
2588
2589 if (!get_mac_list_cmd.va) {
2590 dev_err(&adapter->pdev->dev,
2591 "Memory allocation failure during GET_MAC_LIST\n");
2592 return -ENOMEM;
2593 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002594
2595 spin_lock_bh(&adapter->mcc_lock);
2596
2597 wrb = wrb_from_mccq(adapter);
2598 if (!wrb) {
2599 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002600 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002601 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002602
2603 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002604
2605 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2606 OPCODE_COMMON_GET_MAC_LIST, sizeof(*req),
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002607 wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002608
2609 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002610 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
2611 req->perm_override = 1;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002612
2613 status = be_mcc_notify_wait(adapter);
2614 if (!status) {
2615 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002616 get_mac_list_cmd.va;
2617 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2618 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002619 * or one or more true or pseudo permanant mac addresses.
2620 * If an active mac_id is present, return first active mac_id
2621 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002622 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002623 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002624 struct get_list_macaddr *mac_entry;
2625 u16 mac_addr_size;
2626 u32 mac_id;
2627
2628 mac_entry = &resp->macaddr_list[i];
2629 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2630 /* mac_id is a 32 bit value and mac_addr size
2631 * is 6 bytes
2632 */
2633 if (mac_addr_size == sizeof(u32)) {
2634 *pmac_id_active = true;
2635 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2636 *pmac_id = le32_to_cpu(mac_id);
2637 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002638 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002639 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00002640 /* If no active mac_id found, return first mac addr */
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002641 *pmac_id_active = false;
2642 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2643 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002644 }
2645
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002646out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002647 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002648 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2649 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002650 return status;
2651}
2652
2653/* Uses synchronous MCCQ */
2654int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2655 u8 mac_count, u32 domain)
2656{
2657 struct be_mcc_wrb *wrb;
2658 struct be_cmd_req_set_mac_list *req;
2659 int status;
2660 struct be_dma_mem cmd;
2661
2662 memset(&cmd, 0, sizeof(struct be_dma_mem));
2663 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2664 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2665 &cmd.dma, GFP_KERNEL);
2666 if (!cmd.va) {
2667 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2668 return -ENOMEM;
2669 }
2670
2671 spin_lock_bh(&adapter->mcc_lock);
2672
2673 wrb = wrb_from_mccq(adapter);
2674 if (!wrb) {
2675 status = -EBUSY;
2676 goto err;
2677 }
2678
2679 req = cmd.va;
2680 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2681 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2682 wrb, &cmd);
2683
2684 req->hdr.domain = domain;
2685 req->mac_count = mac_count;
2686 if (mac_count)
2687 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2688
2689 status = be_mcc_notify_wait(adapter);
2690
2691err:
2692 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2693 cmd.va, cmd.dma);
2694 spin_unlock_bh(&adapter->mcc_lock);
2695 return status;
2696}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002697
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002698int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
2699 u32 domain, u16 intf_id)
2700{
2701 struct be_mcc_wrb *wrb;
2702 struct be_cmd_req_set_hsw_config *req;
2703 void *ctxt;
2704 int status;
2705
2706 spin_lock_bh(&adapter->mcc_lock);
2707
2708 wrb = wrb_from_mccq(adapter);
2709 if (!wrb) {
2710 status = -EBUSY;
2711 goto err;
2712 }
2713
2714 req = embedded_payload(wrb);
2715 ctxt = &req->context;
2716
2717 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2718 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2719
2720 req->hdr.domain = domain;
2721 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2722 if (pvid) {
2723 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2724 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2725 }
2726
2727 be_dws_cpu_to_le(req->context, sizeof(req->context));
2728 status = be_mcc_notify_wait(adapter);
2729
2730err:
2731 spin_unlock_bh(&adapter->mcc_lock);
2732 return status;
2733}
2734
2735/* Get Hyper switch config */
2736int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
2737 u32 domain, u16 intf_id)
2738{
2739 struct be_mcc_wrb *wrb;
2740 struct be_cmd_req_get_hsw_config *req;
2741 void *ctxt;
2742 int status;
2743 u16 vid;
2744
2745 spin_lock_bh(&adapter->mcc_lock);
2746
2747 wrb = wrb_from_mccq(adapter);
2748 if (!wrb) {
2749 status = -EBUSY;
2750 goto err;
2751 }
2752
2753 req = embedded_payload(wrb);
2754 ctxt = &req->context;
2755
2756 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2757 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2758
2759 req->hdr.domain = domain;
2760 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, ctxt,
2761 intf_id);
2762 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
2763 be_dws_cpu_to_le(req->context, sizeof(req->context));
2764
2765 status = be_mcc_notify_wait(adapter);
2766 if (!status) {
2767 struct be_cmd_resp_get_hsw_config *resp =
2768 embedded_payload(wrb);
2769 be_dws_le_to_cpu(&resp->context,
2770 sizeof(resp->context));
2771 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2772 pvid, &resp->context);
2773 *pvid = le16_to_cpu(vid);
2774 }
2775
2776err:
2777 spin_unlock_bh(&adapter->mcc_lock);
2778 return status;
2779}
2780
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002781int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2782{
2783 struct be_mcc_wrb *wrb;
2784 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2785 int status;
2786 int payload_len = sizeof(*req);
2787 struct be_dma_mem cmd;
2788
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002789 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2790 CMD_SUBSYSTEM_ETH))
2791 return -EPERM;
2792
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002793 memset(&cmd, 0, sizeof(struct be_dma_mem));
2794 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2795 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2796 &cmd.dma);
2797 if (!cmd.va) {
2798 dev_err(&adapter->pdev->dev,
2799 "Memory allocation failure\n");
2800 return -ENOMEM;
2801 }
2802
2803 if (mutex_lock_interruptible(&adapter->mbox_lock))
2804 return -1;
2805
2806 wrb = wrb_from_mbox(adapter);
2807 if (!wrb) {
2808 status = -EBUSY;
2809 goto err;
2810 }
2811
2812 req = cmd.va;
2813
2814 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2815 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2816 payload_len, wrb, &cmd);
2817
2818 req->hdr.version = 1;
2819 req->query_options = BE_GET_WOL_CAP;
2820
2821 status = be_mbox_notify_wait(adapter);
2822 if (!status) {
2823 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
2824 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
2825
2826 /* the command could succeed misleadingly on old f/w
2827 * which is not aware of the V1 version. fake an error. */
2828 if (resp->hdr.response_length < payload_len) {
2829 status = -1;
2830 goto err;
2831 }
2832 adapter->wol_cap = resp->wol_settings;
2833 }
2834err:
2835 mutex_unlock(&adapter->mbox_lock);
2836 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2837 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00002838
2839}
2840int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
2841 struct be_dma_mem *cmd)
2842{
2843 struct be_mcc_wrb *wrb;
2844 struct be_cmd_req_get_ext_fat_caps *req;
2845 int status;
2846
2847 if (mutex_lock_interruptible(&adapter->mbox_lock))
2848 return -1;
2849
2850 wrb = wrb_from_mbox(adapter);
2851 if (!wrb) {
2852 status = -EBUSY;
2853 goto err;
2854 }
2855
2856 req = cmd->va;
2857 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2858 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
2859 cmd->size, wrb, cmd);
2860 req->parameter_type = cpu_to_le32(1);
2861
2862 status = be_mbox_notify_wait(adapter);
2863err:
2864 mutex_unlock(&adapter->mbox_lock);
2865 return status;
2866}
2867
2868int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
2869 struct be_dma_mem *cmd,
2870 struct be_fat_conf_params *configs)
2871{
2872 struct be_mcc_wrb *wrb;
2873 struct be_cmd_req_set_ext_fat_caps *req;
2874 int status;
2875
2876 spin_lock_bh(&adapter->mcc_lock);
2877
2878 wrb = wrb_from_mccq(adapter);
2879 if (!wrb) {
2880 status = -EBUSY;
2881 goto err;
2882 }
2883
2884 req = cmd->va;
2885 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
2886 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2887 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
2888 cmd->size, wrb, cmd);
2889
2890 status = be_mcc_notify_wait(adapter);
2891err:
2892 spin_unlock_bh(&adapter->mcc_lock);
2893 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002894}
Parav Pandit6a4ab662012-03-26 14:27:12 +00002895
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00002896int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name)
2897{
2898 struct be_mcc_wrb *wrb;
2899 struct be_cmd_req_get_port_name *req;
2900 int status;
2901
2902 if (!lancer_chip(adapter)) {
2903 *port_name = adapter->hba_port_num + '0';
2904 return 0;
2905 }
2906
2907 spin_lock_bh(&adapter->mcc_lock);
2908
2909 wrb = wrb_from_mccq(adapter);
2910 if (!wrb) {
2911 status = -EBUSY;
2912 goto err;
2913 }
2914
2915 req = embedded_payload(wrb);
2916
2917 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2918 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
2919 NULL);
2920 req->hdr.version = 1;
2921
2922 status = be_mcc_notify_wait(adapter);
2923 if (!status) {
2924 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
2925 *port_name = resp->port_name[adapter->hba_port_num];
2926 } else {
2927 *port_name = adapter->hba_port_num + '0';
2928 }
2929err:
2930 spin_unlock_bh(&adapter->mcc_lock);
2931 return status;
2932}
2933
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002934static struct be_nic_resource_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
2935 u32 max_buf_size)
2936{
2937 struct be_nic_resource_desc *desc = (struct be_nic_resource_desc *)buf;
2938 int i;
2939
2940 for (i = 0; i < desc_count; i++) {
2941 desc->desc_len = RESOURCE_DESC_SIZE;
2942 if (((void *)desc + desc->desc_len) >
2943 (void *)(buf + max_buf_size)) {
2944 desc = NULL;
2945 break;
2946 }
2947
2948 if (desc->desc_type == NIC_RESOURCE_DESC_TYPE_ID)
2949 break;
2950
2951 desc = (void *)desc + desc->desc_len;
2952 }
2953
2954 if (!desc || i == MAX_RESOURCE_DESC)
2955 return NULL;
2956
2957 return desc;
2958}
2959
2960/* Uses Mbox */
2961int be_cmd_get_func_config(struct be_adapter *adapter)
2962{
2963 struct be_mcc_wrb *wrb;
2964 struct be_cmd_req_get_func_config *req;
2965 int status;
2966 struct be_dma_mem cmd;
2967
2968 memset(&cmd, 0, sizeof(struct be_dma_mem));
2969 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
2970 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2971 &cmd.dma);
2972 if (!cmd.va) {
2973 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2974 return -ENOMEM;
2975 }
2976 if (mutex_lock_interruptible(&adapter->mbox_lock))
2977 return -1;
2978
2979 wrb = wrb_from_mbox(adapter);
2980 if (!wrb) {
2981 status = -EBUSY;
2982 goto err;
2983 }
2984
2985 req = cmd.va;
2986
2987 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2988 OPCODE_COMMON_GET_FUNC_CONFIG,
2989 cmd.size, wrb, &cmd);
2990
2991 status = be_mbox_notify_wait(adapter);
2992 if (!status) {
2993 struct be_cmd_resp_get_func_config *resp = cmd.va;
2994 u32 desc_count = le32_to_cpu(resp->desc_count);
2995 struct be_nic_resource_desc *desc;
2996
2997 desc = be_get_nic_desc(resp->func_param, desc_count,
2998 sizeof(resp->func_param));
2999 if (!desc) {
3000 status = -EINVAL;
3001 goto err;
3002 }
3003
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003004 adapter->pf_number = desc->pf_num;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003005 adapter->max_pmac_cnt = le16_to_cpu(desc->unicast_mac_count);
3006 adapter->max_vlans = le16_to_cpu(desc->vlan_count);
3007 adapter->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3008 adapter->max_tx_queues = le16_to_cpu(desc->txq_count);
3009 adapter->max_rss_queues = le16_to_cpu(desc->rssq_count);
3010 adapter->max_rx_queues = le16_to_cpu(desc->rq_count);
3011
3012 adapter->max_event_queues = le16_to_cpu(desc->eq_count);
3013 adapter->if_cap_flags = le32_to_cpu(desc->cap_flags);
3014 }
3015err:
3016 mutex_unlock(&adapter->mbox_lock);
3017 pci_free_consistent(adapter->pdev, cmd.size,
3018 cmd.va, cmd.dma);
3019 return status;
3020}
3021
3022 /* Uses sync mcc */
3023int be_cmd_get_profile_config(struct be_adapter *adapter, u32 *cap_flags,
3024 u8 domain)
3025{
3026 struct be_mcc_wrb *wrb;
3027 struct be_cmd_req_get_profile_config *req;
3028 int status;
3029 struct be_dma_mem cmd;
3030
3031 memset(&cmd, 0, sizeof(struct be_dma_mem));
3032 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3033 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
3034 &cmd.dma);
3035 if (!cmd.va) {
3036 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
3037 return -ENOMEM;
3038 }
3039
3040 spin_lock_bh(&adapter->mcc_lock);
3041
3042 wrb = wrb_from_mccq(adapter);
3043 if (!wrb) {
3044 status = -EBUSY;
3045 goto err;
3046 }
3047
3048 req = cmd.va;
3049
3050 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3051 OPCODE_COMMON_GET_PROFILE_CONFIG,
3052 cmd.size, wrb, &cmd);
3053
3054 req->type = ACTIVE_PROFILE_TYPE;
3055 req->hdr.domain = domain;
3056
3057 status = be_mcc_notify_wait(adapter);
3058 if (!status) {
3059 struct be_cmd_resp_get_profile_config *resp = cmd.va;
3060 u32 desc_count = le32_to_cpu(resp->desc_count);
3061 struct be_nic_resource_desc *desc;
3062
3063 desc = be_get_nic_desc(resp->func_param, desc_count,
3064 sizeof(resp->func_param));
3065
3066 if (!desc) {
3067 status = -EINVAL;
3068 goto err;
3069 }
3070 *cap_flags = le32_to_cpu(desc->cap_flags);
3071 }
3072err:
3073 spin_unlock_bh(&adapter->mcc_lock);
3074 pci_free_consistent(adapter->pdev, cmd.size,
3075 cmd.va, cmd.dma);
3076 return status;
3077}
3078
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003079/* Uses sync mcc */
3080int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps,
3081 u8 domain)
3082{
3083 struct be_mcc_wrb *wrb;
3084 struct be_cmd_req_set_profile_config *req;
3085 int status;
3086
3087 spin_lock_bh(&adapter->mcc_lock);
3088
3089 wrb = wrb_from_mccq(adapter);
3090 if (!wrb) {
3091 status = -EBUSY;
3092 goto err;
3093 }
3094
3095 req = embedded_payload(wrb);
3096
3097 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3098 OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req),
3099 wrb, NULL);
3100
3101 req->hdr.domain = domain;
3102 req->desc_count = cpu_to_le32(1);
3103
3104 req->nic_desc.desc_type = NIC_RESOURCE_DESC_TYPE_ID;
3105 req->nic_desc.desc_len = RESOURCE_DESC_SIZE;
3106 req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV);
3107 req->nic_desc.pf_num = adapter->pf_number;
3108 req->nic_desc.vf_num = domain;
3109
3110 /* Mark fields invalid */
3111 req->nic_desc.unicast_mac_count = 0xFFFF;
3112 req->nic_desc.mcc_count = 0xFFFF;
3113 req->nic_desc.vlan_count = 0xFFFF;
3114 req->nic_desc.mcast_mac_count = 0xFFFF;
3115 req->nic_desc.txq_count = 0xFFFF;
3116 req->nic_desc.rq_count = 0xFFFF;
3117 req->nic_desc.rssq_count = 0xFFFF;
3118 req->nic_desc.lro_count = 0xFFFF;
3119 req->nic_desc.cq_count = 0xFFFF;
3120 req->nic_desc.toe_conn_count = 0xFFFF;
3121 req->nic_desc.eq_count = 0xFFFF;
3122 req->nic_desc.link_param = 0xFF;
3123 req->nic_desc.bw_min = 0xFFFFFFFF;
3124 req->nic_desc.acpi_params = 0xFF;
3125 req->nic_desc.wol_param = 0x0F;
3126
3127 /* Change BW */
3128 req->nic_desc.bw_min = cpu_to_le32(bps);
3129 req->nic_desc.bw_max = cpu_to_le32(bps);
3130 status = be_mcc_notify_wait(adapter);
3131err:
3132 spin_unlock_bh(&adapter->mcc_lock);
3133 return status;
3134}
3135
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00003136/* Uses sync mcc */
3137int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
3138{
3139 struct be_mcc_wrb *wrb;
3140 struct be_cmd_enable_disable_vf *req;
3141 int status;
3142
3143 if (!lancer_chip(adapter))
3144 return 0;
3145
3146 spin_lock_bh(&adapter->mcc_lock);
3147
3148 wrb = wrb_from_mccq(adapter);
3149 if (!wrb) {
3150 status = -EBUSY;
3151 goto err;
3152 }
3153
3154 req = embedded_payload(wrb);
3155
3156 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3157 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
3158 wrb, NULL);
3159
3160 req->hdr.domain = domain;
3161 req->enable = 1;
3162 status = be_mcc_notify_wait(adapter);
3163err:
3164 spin_unlock_bh(&adapter->mcc_lock);
3165 return status;
3166}
3167
Parav Pandit6a4ab662012-03-26 14:27:12 +00003168int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
3169 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
3170{
3171 struct be_adapter *adapter = netdev_priv(netdev_handle);
3172 struct be_mcc_wrb *wrb;
3173 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload;
3174 struct be_cmd_req_hdr *req;
3175 struct be_cmd_resp_hdr *resp;
3176 int status;
3177
3178 spin_lock_bh(&adapter->mcc_lock);
3179
3180 wrb = wrb_from_mccq(adapter);
3181 if (!wrb) {
3182 status = -EBUSY;
3183 goto err;
3184 }
3185 req = embedded_payload(wrb);
3186 resp = embedded_payload(wrb);
3187
3188 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
3189 hdr->opcode, wrb_payload_size, wrb, NULL);
3190 memcpy(req, wrb_payload, wrb_payload_size);
3191 be_dws_cpu_to_le(req, wrb_payload_size);
3192
3193 status = be_mcc_notify_wait(adapter);
3194 if (cmd_status)
3195 *cmd_status = (status & 0xffff);
3196 if (ext_status)
3197 *ext_status = 0;
3198 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
3199 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
3200err:
3201 spin_unlock_bh(&adapter->mcc_lock);
3202 return status;
3203}
3204EXPORT_SYMBOL(be_roce_mcc_cmd);