blob: 2673081aaf2f15c9da8f59ebfcf20b46c31f05fd [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
18#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000019#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070020
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000021/* Must be a power of 2 or else MODULO will BUG_ON */
Somnath Kotur3de09452011-09-30 07:25:05 +000022static int be_get_temp_freq = 64;
23
24static inline void *embedded_payload(struct be_mcc_wrb *wrb)
25{
26 return wrb->payload.embedded_payload;
27}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000028
Sathya Perla8788fdc2009-07-27 22:52:03 +000029static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000030{
Sathya Perla8788fdc2009-07-27 22:52:03 +000031 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000032 u32 val = 0;
33
Sathya Perla6589ade2011-11-10 19:18:00 +000034 if (be_error(adapter))
Ajit Khaparde7acc2082011-02-11 13:38:17 +000035 return;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000036
Sathya Perla5fb379e2009-06-18 00:02:59 +000037 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
38 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000039
40 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000041 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000042}
43
44/* To check if valid bit is set, check the entire word as we don't know
45 * the endianness of the data (old entry is host endian while a new entry is
46 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000047static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000048{
49 if (compl->flags != 0) {
50 compl->flags = le32_to_cpu(compl->flags);
51 BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
52 return true;
53 } else {
54 return false;
55 }
56}
57
58/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +000059static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000060{
61 compl->flags = 0;
62}
63
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +000064static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
65{
66 unsigned long addr;
67
68 addr = tag1;
69 addr = ((addr << 16) << 16) | tag0;
70 return (void *)addr;
71}
72
Sathya Perla8788fdc2009-07-27 22:52:03 +000073static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +000074 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000075{
76 u16 compl_status, extd_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +000077 struct be_cmd_resp_hdr *resp_hdr;
78 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +000079
80 /* Just swap the status to host endian; mcc tag is opaquely copied
81 * from mcc_wrb */
82 be_dws_le_to_cpu(compl, 4);
83
84 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
85 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -070086
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +000087 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
88
89 if (resp_hdr) {
90 opcode = resp_hdr->opcode;
91 subsystem = resp_hdr->subsystem;
92 }
93
94 if (((opcode == OPCODE_COMMON_WRITE_FLASHROM) ||
95 (opcode == OPCODE_COMMON_WRITE_OBJECT)) &&
96 (subsystem == CMD_SUBSYSTEM_COMMON)) {
Sarveshwar Bandidd131e72010-05-25 16:16:32 -070097 adapter->flash_status = compl_status;
98 complete(&adapter->flash_compl);
99 }
100
Sathya Perlab31c50a2009-09-17 10:30:13 -0700101 if (compl_status == MCC_STATUS_SUCCESS) {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000102 if (((opcode == OPCODE_ETH_GET_STATISTICS) ||
103 (opcode == OPCODE_ETH_GET_PPORT_STATS)) &&
104 (subsystem == CMD_SUBSYSTEM_ETH)) {
Ajit Khaparde89a88ab2011-05-16 07:36:18 +0000105 be_parse_stats(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +0000106 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700107 }
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000108 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
109 subsystem == CMD_SUBSYSTEM_COMMON) {
Somnath Kotur3de09452011-09-30 07:25:05 +0000110 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000111 (void *)resp_hdr;
Somnath Kotur3de09452011-09-30 07:25:05 +0000112 adapter->drv_stats.be_on_die_temperature =
113 resp->on_die_temperature;
114 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000115 } else {
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000116 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES)
Somnath Kotur3de09452011-09-30 07:25:05 +0000117 be_get_temp_freq = 0;
118
Sathya Perla2b3f2912011-06-29 23:32:56 +0000119 if (compl_status == MCC_STATUS_NOT_SUPPORTED ||
120 compl_status == MCC_STATUS_ILLEGAL_REQUEST)
121 goto done;
122
123 if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
124 dev_warn(&adapter->pdev->dev, "This domain(VM) is not "
125 "permitted to execute this cmd (opcode %d)\n",
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000126 opcode);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000127 } else {
128 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
129 CQE_STATUS_EXTD_MASK;
130 dev_err(&adapter->pdev->dev, "Cmd (opcode %d) failed:"
131 "status %d, extd-status %d\n",
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000132 opcode, compl_status, extd_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000133 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000134 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000135done:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700136 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000137}
138
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000139/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000140static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000141 struct be_async_event_link_state *evt)
142{
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000143 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000144 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000145
146 /* For the initial link status do not rely on the ASYNC event as
147 * it may not be received in some cases.
148 */
149 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
150 be_link_status_update(adapter, evt->port_link_status);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000151}
152
Somnath Koturcc4ce022010-10-21 07:11:14 -0700153/* Grp5 CoS Priority evt */
154static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
155 struct be_async_event_grp5_cos_priority *evt)
156{
157 if (evt->valid) {
158 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000159 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700160 adapter->recommended_prio =
161 evt->reco_default_priority << VLAN_PRIO_SHIFT;
162 }
163}
164
165/* Grp5 QOS Speed evt */
166static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
167 struct be_async_event_grp5_qos_link_speed *evt)
168{
169 if (evt->physical_port == adapter->port_num) {
170 /* qos_link_speed is in units of 10 Mbps */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000171 adapter->phy.link_speed = evt->qos_link_speed * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700172 }
173}
174
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000175/*Grp5 PVID evt*/
176static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
177 struct be_async_event_grp5_pvid_state *evt)
178{
179 if (evt->enabled)
Somnath Kotur939cf302011-08-18 21:51:49 -0700180 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000181 else
182 adapter->pvid = 0;
183}
184
Somnath Koturcc4ce022010-10-21 07:11:14 -0700185static void be_async_grp5_evt_process(struct be_adapter *adapter,
186 u32 trailer, struct be_mcc_compl *evt)
187{
188 u8 event_type = 0;
189
190 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
191 ASYNC_TRAILER_EVENT_TYPE_MASK;
192
193 switch (event_type) {
194 case ASYNC_EVENT_COS_PRIORITY:
195 be_async_grp5_cos_priority_process(adapter,
196 (struct be_async_event_grp5_cos_priority *)evt);
197 break;
198 case ASYNC_EVENT_QOS_SPEED:
199 be_async_grp5_qos_speed_process(adapter,
200 (struct be_async_event_grp5_qos_link_speed *)evt);
201 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000202 case ASYNC_EVENT_PVID_STATE:
203 be_async_grp5_pvid_state_process(adapter,
204 (struct be_async_event_grp5_pvid_state *)evt);
205 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700206 default:
207 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
208 break;
209 }
210}
211
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000212static inline bool is_link_state_evt(u32 trailer)
213{
Eric Dumazet807540b2010-09-23 05:40:09 +0000214 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000215 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000216 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000217}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000218
Somnath Koturcc4ce022010-10-21 07:11:14 -0700219static inline bool is_grp5_evt(u32 trailer)
220{
221 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
222 ASYNC_TRAILER_EVENT_CODE_MASK) ==
223 ASYNC_EVENT_CODE_GRP_5);
224}
225
Sathya Perlaefd2e402009-07-27 22:53:10 +0000226static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000227{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000228 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000229 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000230
231 if (be_mcc_compl_is_new(compl)) {
232 queue_tail_inc(mcc_cq);
233 return compl;
234 }
235 return NULL;
236}
237
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000238void be_async_mcc_enable(struct be_adapter *adapter)
239{
240 spin_lock_bh(&adapter->mcc_cq_lock);
241
242 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
243 adapter->mcc_obj.rearm_cq = true;
244
245 spin_unlock_bh(&adapter->mcc_cq_lock);
246}
247
248void be_async_mcc_disable(struct be_adapter *adapter)
249{
250 adapter->mcc_obj.rearm_cq = false;
251}
252
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000253int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000254{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000255 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000256 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000257 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000258
Sathya Perla8788fdc2009-07-27 22:52:03 +0000259 spin_lock_bh(&adapter->mcc_cq_lock);
260 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000261 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
262 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000263 if (is_link_state_evt(compl->flags))
264 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000265 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700266 else if (is_grp5_evt(compl->flags))
267 be_async_grp5_evt_process(adapter,
268 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700269 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000270 status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000271 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000272 }
273 be_mcc_compl_use(compl);
274 num++;
275 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700276
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000277 if (num)
278 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
279
Sathya Perla8788fdc2009-07-27 22:52:03 +0000280 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000281 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000282}
283
Sathya Perla6ac7b682009-06-18 00:05:54 +0000284/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700285static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000286{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700287#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000288 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800289 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700290
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800291 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000292 if (be_error(adapter))
293 return -EIO;
294
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000295 status = be_process_mcc(adapter);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800296
297 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000298 break;
299 udelay(100);
300 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700301 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000302 dev_err(&adapter->pdev->dev, "FW not responding\n");
303 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000304 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700305 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800306 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000307}
308
309/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700310static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000311{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000312 int status;
313 struct be_mcc_wrb *wrb;
314 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
315 u16 index = mcc_obj->q.head;
316 struct be_cmd_resp_hdr *resp;
317
318 index_dec(&index, mcc_obj->q.len);
319 wrb = queue_index_node(&mcc_obj->q, index);
320
321 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
322
Sathya Perla8788fdc2009-07-27 22:52:03 +0000323 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000324
325 status = be_mcc_wait_compl(adapter);
326 if (status == -EIO)
327 goto out;
328
329 status = resp->status;
330out:
331 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000332}
333
Sathya Perla5f0b8492009-07-27 22:52:56 +0000334static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700335{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000336 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700337 u32 ready;
338
339 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000340 if (be_error(adapter))
341 return -EIO;
342
Sathya Perlacf588472010-02-14 21:22:01 +0000343 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000344 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000345 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000346
347 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700348 if (ready)
349 break;
350
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000351 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000352 dev_err(&adapter->pdev->dev, "FW not responding\n");
353 adapter->fw_timeout = true;
Padmanabh Ratnakare1cfb672011-11-03 01:50:08 +0000354 be_detect_dump_ue(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700355 return -1;
356 }
357
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000358 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000359 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700360 } while (true);
361
362 return 0;
363}
364
365/*
366 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000367 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700368 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700369static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700370{
371 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700372 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000373 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
374 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700375 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000376 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700377
Sathya Perlacf588472010-02-14 21:22:01 +0000378 /* wait for ready to be set */
379 status = be_mbox_db_ready_wait(adapter, db);
380 if (status != 0)
381 return status;
382
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700383 val |= MPU_MAILBOX_DB_HI_MASK;
384 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
385 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
386 iowrite32(val, db);
387
388 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000389 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700390 if (status != 0)
391 return status;
392
393 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700394 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
395 val |= (u32)(mbox_mem->dma >> 4) << 2;
396 iowrite32(val, db);
397
Sathya Perla5f0b8492009-07-27 22:52:56 +0000398 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700399 if (status != 0)
400 return status;
401
Sathya Perla5fb379e2009-06-18 00:02:59 +0000402 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000403 if (be_mcc_compl_is_new(compl)) {
404 status = be_mcc_compl_process(adapter, &mbox->compl);
405 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000406 if (status)
407 return status;
408 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000409 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700410 return -1;
411 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000412 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700413}
414
Sathya Perla8788fdc2009-07-27 22:52:03 +0000415static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700416{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000417 u32 sem;
418
419 if (lancer_chip(adapter))
420 sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
421 else
422 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700423
424 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
425 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
426 return -1;
427 else
428 return 0;
429}
430
Sathya Perla8788fdc2009-07-27 22:52:03 +0000431int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700432{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000433 u16 stage;
434 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000435 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700436
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000437 do {
438 status = be_POST_stage_get(adapter, &stage);
439 if (status) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000440 dev_err(dev, "POST error; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000441 return -1;
442 } else if (stage != POST_STAGE_ARMFW_RDY) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000443 if (msleep_interruptible(2000)) {
444 dev_err(dev, "Waiting for POST aborted\n");
445 return -EINTR;
446 }
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000447 timeout += 2;
448 } else {
449 return 0;
450 }
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000451 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000453 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000454 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700455}
456
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700457
458static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
459{
460 return &wrb->payload.sgl[0];
461}
462
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700463
464/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000465/* mem will be NULL for embedded commands */
466static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
467 u8 subsystem, u8 opcode, int cmd_len,
468 struct be_mcc_wrb *wrb, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700469{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000470 struct be_sge *sge;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000471 unsigned long addr = (unsigned long)req_hdr;
472 u64 req_addr = addr;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000473
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700474 req_hdr->opcode = opcode;
475 req_hdr->subsystem = subsystem;
476 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000477 req_hdr->version = 0;
Somnath Kotur106df1e2011-10-27 07:12:13 +0000478
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000479 wrb->tag0 = req_addr & 0xFFFFFFFF;
480 wrb->tag1 = upper_32_bits(req_addr);
481
Somnath Kotur106df1e2011-10-27 07:12:13 +0000482 wrb->payload_length = cmd_len;
483 if (mem) {
484 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
485 MCC_WRB_SGE_CNT_SHIFT;
486 sge = nonembedded_sgl(wrb);
487 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
488 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
489 sge->len = cpu_to_le32(mem->size);
490 } else
491 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
492 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700493}
494
495static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
496 struct be_dma_mem *mem)
497{
498 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
499 u64 dma = (u64)mem->dma;
500
501 for (i = 0; i < buf_pages; i++) {
502 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
503 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
504 dma += PAGE_SIZE_4K;
505 }
506}
507
508/* Converts interrupt delay in microseconds to multiplier value */
509static u32 eq_delay_to_mult(u32 usec_delay)
510{
511#define MAX_INTR_RATE 651042
512 const u32 round = 10;
513 u32 multiplier;
514
515 if (usec_delay == 0)
516 multiplier = 0;
517 else {
518 u32 interrupt_rate = 1000000 / usec_delay;
519 /* Max delay, corresponding to the lowest interrupt rate */
520 if (interrupt_rate == 0)
521 multiplier = 1023;
522 else {
523 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
524 multiplier /= interrupt_rate;
525 /* Round the multiplier to the closest value.*/
526 multiplier = (multiplier + round/2) / round;
527 multiplier = min(multiplier, (u32)1023);
528 }
529 }
530 return multiplier;
531}
532
Sathya Perlab31c50a2009-09-17 10:30:13 -0700533static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700534{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700535 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
536 struct be_mcc_wrb *wrb
537 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
538 memset(wrb, 0, sizeof(*wrb));
539 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700540}
541
Sathya Perlab31c50a2009-09-17 10:30:13 -0700542static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000543{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700544 struct be_queue_info *mccq = &adapter->mcc_obj.q;
545 struct be_mcc_wrb *wrb;
546
Sathya Perla713d03942009-11-22 22:02:45 +0000547 if (atomic_read(&mccq->used) >= mccq->len) {
548 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
549 return NULL;
550 }
551
Sathya Perlab31c50a2009-09-17 10:30:13 -0700552 wrb = queue_head_node(mccq);
553 queue_head_inc(mccq);
554 atomic_inc(&mccq->used);
555 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000556 return wrb;
557}
558
Sathya Perla2243e2e2009-11-22 22:02:03 +0000559/* Tell fw we're about to start firing cmds by writing a
560 * special pattern across the wrb hdr; uses mbox
561 */
562int be_cmd_fw_init(struct be_adapter *adapter)
563{
564 u8 *wrb;
565 int status;
566
Ivan Vecera29849612010-12-14 05:43:19 +0000567 if (mutex_lock_interruptible(&adapter->mbox_lock))
568 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000569
570 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000571 *wrb++ = 0xFF;
572 *wrb++ = 0x12;
573 *wrb++ = 0x34;
574 *wrb++ = 0xFF;
575 *wrb++ = 0xFF;
576 *wrb++ = 0x56;
577 *wrb++ = 0x78;
578 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000579
580 status = be_mbox_notify_wait(adapter);
581
Ivan Vecera29849612010-12-14 05:43:19 +0000582 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000583 return status;
584}
585
586/* Tell fw we're done with firing cmds by writing a
587 * special pattern across the wrb hdr; uses mbox
588 */
589int be_cmd_fw_clean(struct be_adapter *adapter)
590{
591 u8 *wrb;
592 int status;
593
Ivan Vecera29849612010-12-14 05:43:19 +0000594 if (mutex_lock_interruptible(&adapter->mbox_lock))
595 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000596
597 wrb = (u8 *)wrb_from_mbox(adapter);
598 *wrb++ = 0xFF;
599 *wrb++ = 0xAA;
600 *wrb++ = 0xBB;
601 *wrb++ = 0xFF;
602 *wrb++ = 0xFF;
603 *wrb++ = 0xCC;
604 *wrb++ = 0xDD;
605 *wrb = 0xFF;
606
607 status = be_mbox_notify_wait(adapter);
608
Ivan Vecera29849612010-12-14 05:43:19 +0000609 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000610 return status;
611}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000612int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700613 struct be_queue_info *eq, int eq_delay)
614{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700615 struct be_mcc_wrb *wrb;
616 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700617 struct be_dma_mem *q_mem = &eq->dma_mem;
618 int status;
619
Ivan Vecera29849612010-12-14 05:43:19 +0000620 if (mutex_lock_interruptible(&adapter->mbox_lock))
621 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700622
623 wrb = wrb_from_mbox(adapter);
624 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700625
Somnath Kotur106df1e2011-10-27 07:12:13 +0000626 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
627 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700628
629 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
630
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700631 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
632 /* 4byte eqe*/
633 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
634 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
635 __ilog2_u32(eq->len/256));
636 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
637 eq_delay_to_mult(eq_delay));
638 be_dws_cpu_to_le(req->context, sizeof(req->context));
639
640 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
641
Sathya Perlab31c50a2009-09-17 10:30:13 -0700642 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700643 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700644 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700645 eq->id = le16_to_cpu(resp->eq_id);
646 eq->created = true;
647 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700648
Ivan Vecera29849612010-12-14 05:43:19 +0000649 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700650 return status;
651}
652
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000653/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000654int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000655 u8 type, bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700656{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700657 struct be_mcc_wrb *wrb;
658 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700659 int status;
660
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000661 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700662
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000663 wrb = wrb_from_mccq(adapter);
664 if (!wrb) {
665 status = -EBUSY;
666 goto err;
667 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700668 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700669
Somnath Kotur106df1e2011-10-27 07:12:13 +0000670 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
671 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700672 req->type = type;
673 if (permanent) {
674 req->permanent = 1;
675 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700676 req->if_id = cpu_to_le16((u16) if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +0000677 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700678 req->permanent = 0;
679 }
680
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000681 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700682 if (!status) {
683 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700684 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700685 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700686
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000687err:
688 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700689 return status;
690}
691
Sathya Perlab31c50a2009-09-17 10:30:13 -0700692/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000693int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000694 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700695{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700696 struct be_mcc_wrb *wrb;
697 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700698 int status;
699
Sathya Perlab31c50a2009-09-17 10:30:13 -0700700 spin_lock_bh(&adapter->mcc_lock);
701
702 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000703 if (!wrb) {
704 status = -EBUSY;
705 goto err;
706 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700707 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700708
Somnath Kotur106df1e2011-10-27 07:12:13 +0000709 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
710 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700711
Ajit Khapardef8617e02011-02-11 13:36:37 +0000712 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700713 req->if_id = cpu_to_le32(if_id);
714 memcpy(req->mac_address, mac_addr, ETH_ALEN);
715
Sathya Perlab31c50a2009-09-17 10:30:13 -0700716 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700717 if (!status) {
718 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
719 *pmac_id = le32_to_cpu(resp->pmac_id);
720 }
721
Sathya Perla713d03942009-11-22 22:02:45 +0000722err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700723 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +0000724
725 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
726 status = -EPERM;
727
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700728 return status;
729}
730
Sathya Perlab31c50a2009-09-17 10:30:13 -0700731/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +0000732int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700733{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700734 struct be_mcc_wrb *wrb;
735 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700736 int status;
737
Sathya Perla30128032011-11-10 19:17:57 +0000738 if (pmac_id == -1)
739 return 0;
740
Sathya Perlab31c50a2009-09-17 10:30:13 -0700741 spin_lock_bh(&adapter->mcc_lock);
742
743 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000744 if (!wrb) {
745 status = -EBUSY;
746 goto err;
747 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700748 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700749
Somnath Kotur106df1e2011-10-27 07:12:13 +0000750 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
751 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700752
Ajit Khapardef8617e02011-02-11 13:36:37 +0000753 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700754 req->if_id = cpu_to_le32(if_id);
755 req->pmac_id = cpu_to_le32(pmac_id);
756
Sathya Perlab31c50a2009-09-17 10:30:13 -0700757 status = be_mcc_notify_wait(adapter);
758
Sathya Perla713d03942009-11-22 22:02:45 +0000759err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700760 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700761 return status;
762}
763
Sathya Perlab31c50a2009-09-17 10:30:13 -0700764/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000765int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
766 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700767{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700768 struct be_mcc_wrb *wrb;
769 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700770 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700771 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700772 int status;
773
Ivan Vecera29849612010-12-14 05:43:19 +0000774 if (mutex_lock_interruptible(&adapter->mbox_lock))
775 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700776
777 wrb = wrb_from_mbox(adapter);
778 req = embedded_payload(wrb);
779 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700780
Somnath Kotur106df1e2011-10-27 07:12:13 +0000781 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
782 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700783
784 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000785 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000786 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000787 req->page_size = 1; /* 1 for 4K */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000788 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
789 no_delay);
790 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
791 __ilog2_u32(cq->len/256));
792 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
793 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
794 ctxt, 1);
795 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
796 ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000797 } else {
798 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
799 coalesce_wm);
800 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
801 ctxt, no_delay);
802 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
803 __ilog2_u32(cq->len/256));
804 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000805 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
806 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000807 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700808
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700809 be_dws_cpu_to_le(ctxt, sizeof(req->context));
810
811 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
812
Sathya Perlab31c50a2009-09-17 10:30:13 -0700813 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700814 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700815 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700816 cq->id = le16_to_cpu(resp->cq_id);
817 cq->created = true;
818 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700819
Ivan Vecera29849612010-12-14 05:43:19 +0000820 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000821
822 return status;
823}
824
825static u32 be_encoded_q_len(int q_len)
826{
827 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
828 if (len_encoded == 16)
829 len_encoded = 0;
830 return len_encoded;
831}
832
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000833int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000834 struct be_queue_info *mccq,
835 struct be_queue_info *cq)
836{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700837 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000838 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000839 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700840 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000841 int status;
842
Ivan Vecera29849612010-12-14 05:43:19 +0000843 if (mutex_lock_interruptible(&adapter->mbox_lock))
844 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700845
846 wrb = wrb_from_mbox(adapter);
847 req = embedded_payload(wrb);
848 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000849
Somnath Kotur106df1e2011-10-27 07:12:13 +0000850 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
851 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000852
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000853 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000854 if (lancer_chip(adapter)) {
855 req->hdr.version = 1;
856 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000857
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000858 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
859 be_encoded_q_len(mccq->len));
860 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
861 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
862 ctxt, cq->id);
863 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
864 ctxt, 1);
865
866 } else {
867 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
868 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
869 be_encoded_q_len(mccq->len));
870 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
871 }
872
Somnath Koturcc4ce022010-10-21 07:11:14 -0700873 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000874 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000875 be_dws_cpu_to_le(ctxt, sizeof(req->context));
876
877 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
878
Sathya Perlab31c50a2009-09-17 10:30:13 -0700879 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000880 if (!status) {
881 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
882 mccq->id = le16_to_cpu(resp->id);
883 mccq->created = true;
884 }
Ivan Vecera29849612010-12-14 05:43:19 +0000885 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700886
887 return status;
888}
889
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000890int be_cmd_mccq_org_create(struct be_adapter *adapter,
891 struct be_queue_info *mccq,
892 struct be_queue_info *cq)
893{
894 struct be_mcc_wrb *wrb;
895 struct be_cmd_req_mcc_create *req;
896 struct be_dma_mem *q_mem = &mccq->dma_mem;
897 void *ctxt;
898 int status;
899
900 if (mutex_lock_interruptible(&adapter->mbox_lock))
901 return -1;
902
903 wrb = wrb_from_mbox(adapter);
904 req = embedded_payload(wrb);
905 ctxt = &req->context;
906
Somnath Kotur106df1e2011-10-27 07:12:13 +0000907 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
908 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000909
910 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
911
912 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
913 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
914 be_encoded_q_len(mccq->len));
915 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
916
917 be_dws_cpu_to_le(ctxt, sizeof(req->context));
918
919 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
920
921 status = be_mbox_notify_wait(adapter);
922 if (!status) {
923 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
924 mccq->id = le16_to_cpu(resp->id);
925 mccq->created = true;
926 }
927
928 mutex_unlock(&adapter->mbox_lock);
929 return status;
930}
931
932int be_cmd_mccq_create(struct be_adapter *adapter,
933 struct be_queue_info *mccq,
934 struct be_queue_info *cq)
935{
936 int status;
937
938 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
939 if (status && !lancer_chip(adapter)) {
940 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
941 "or newer to avoid conflicting priorities between NIC "
942 "and FCoE traffic");
943 status = be_cmd_mccq_org_create(adapter, mccq, cq);
944 }
945 return status;
946}
947
Sathya Perla8788fdc2009-07-27 22:52:03 +0000948int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700949 struct be_queue_info *txq,
950 struct be_queue_info *cq)
951{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700952 struct be_mcc_wrb *wrb;
953 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700954 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700955 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700956 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700957
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +0000958 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700959
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +0000960 wrb = wrb_from_mccq(adapter);
961 if (!wrb) {
962 status = -EBUSY;
963 goto err;
964 }
965
Sathya Perlab31c50a2009-09-17 10:30:13 -0700966 req = embedded_payload(wrb);
967 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700968
Somnath Kotur106df1e2011-10-27 07:12:13 +0000969 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
970 OPCODE_ETH_TX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700971
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000972 if (lancer_chip(adapter)) {
973 req->hdr.version = 1;
974 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
975 adapter->if_handle);
976 }
977
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700978 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
979 req->ulp_num = BE_ULP1_NUM;
980 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
981
Sathya Perlab31c50a2009-09-17 10:30:13 -0700982 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
983 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700984 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
985 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
986
987 be_dws_cpu_to_le(ctxt, sizeof(req->context));
988
989 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
990
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +0000991 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700992 if (!status) {
993 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
994 txq->id = le16_to_cpu(resp->cid);
995 txq->created = true;
996 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700997
Padmanabh Ratnakar293c4a72011-11-16 02:02:23 +0000998err:
999 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001000
1001 return status;
1002}
1003
Sathya Perla482c9e72011-06-29 23:33:17 +00001004/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001005int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001006 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001007 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001008{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001009 struct be_mcc_wrb *wrb;
1010 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001011 struct be_dma_mem *q_mem = &rxq->dma_mem;
1012 int status;
1013
Sathya Perla482c9e72011-06-29 23:33:17 +00001014 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001015
Sathya Perla482c9e72011-06-29 23:33:17 +00001016 wrb = wrb_from_mccq(adapter);
1017 if (!wrb) {
1018 status = -EBUSY;
1019 goto err;
1020 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001021 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001022
Somnath Kotur106df1e2011-10-27 07:12:13 +00001023 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1024 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001025
1026 req->cq_id = cpu_to_le16(cq_id);
1027 req->frag_size = fls(frag_size) - 1;
1028 req->num_pages = 2;
1029 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1030 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001031 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001032 req->rss_queue = cpu_to_le32(rss);
1033
Sathya Perla482c9e72011-06-29 23:33:17 +00001034 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001035 if (!status) {
1036 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1037 rxq->id = le16_to_cpu(resp->id);
1038 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001039 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001040 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001041
Sathya Perla482c9e72011-06-29 23:33:17 +00001042err:
1043 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001044 return status;
1045}
1046
Sathya Perlab31c50a2009-09-17 10:30:13 -07001047/* Generic destroyer function for all types of queues
1048 * Uses Mbox
1049 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001050int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001051 int queue_type)
1052{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001053 struct be_mcc_wrb *wrb;
1054 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001055 u8 subsys = 0, opcode = 0;
1056 int status;
1057
Ivan Vecera29849612010-12-14 05:43:19 +00001058 if (mutex_lock_interruptible(&adapter->mbox_lock))
1059 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001060
Sathya Perlab31c50a2009-09-17 10:30:13 -07001061 wrb = wrb_from_mbox(adapter);
1062 req = embedded_payload(wrb);
1063
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001064 switch (queue_type) {
1065 case QTYPE_EQ:
1066 subsys = CMD_SUBSYSTEM_COMMON;
1067 opcode = OPCODE_COMMON_EQ_DESTROY;
1068 break;
1069 case QTYPE_CQ:
1070 subsys = CMD_SUBSYSTEM_COMMON;
1071 opcode = OPCODE_COMMON_CQ_DESTROY;
1072 break;
1073 case QTYPE_TXQ:
1074 subsys = CMD_SUBSYSTEM_ETH;
1075 opcode = OPCODE_ETH_TX_DESTROY;
1076 break;
1077 case QTYPE_RXQ:
1078 subsys = CMD_SUBSYSTEM_ETH;
1079 opcode = OPCODE_ETH_RX_DESTROY;
1080 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001081 case QTYPE_MCCQ:
1082 subsys = CMD_SUBSYSTEM_COMMON;
1083 opcode = OPCODE_COMMON_MCC_DESTROY;
1084 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001085 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001086 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001087 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001088
Somnath Kotur106df1e2011-10-27 07:12:13 +00001089 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
1090 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001091 req->id = cpu_to_le16(q->id);
1092
Sathya Perlab31c50a2009-09-17 10:30:13 -07001093 status = be_mbox_notify_wait(adapter);
Sathya Perla482c9e72011-06-29 23:33:17 +00001094 if (!status)
1095 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001096
Ivan Vecera29849612010-12-14 05:43:19 +00001097 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001098 return status;
1099}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001100
Sathya Perla482c9e72011-06-29 23:33:17 +00001101/* Uses MCC */
1102int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1103{
1104 struct be_mcc_wrb *wrb;
1105 struct be_cmd_req_q_destroy *req;
1106 int status;
1107
1108 spin_lock_bh(&adapter->mcc_lock);
1109
1110 wrb = wrb_from_mccq(adapter);
1111 if (!wrb) {
1112 status = -EBUSY;
1113 goto err;
1114 }
1115 req = embedded_payload(wrb);
1116
Somnath Kotur106df1e2011-10-27 07:12:13 +00001117 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1118 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001119 req->id = cpu_to_le16(q->id);
1120
1121 status = be_mcc_notify_wait(adapter);
1122 if (!status)
1123 q->created = false;
1124
1125err:
1126 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001127 return status;
1128}
1129
Sathya Perlab31c50a2009-09-17 10:30:13 -07001130/* Create an rx filtering policy configuration on an i/f
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001131 * Uses MCCQ
Sathya Perlab31c50a2009-09-17 10:30:13 -07001132 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001133int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001134 u8 *mac, u32 *if_handle, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001135{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001136 struct be_mcc_wrb *wrb;
1137 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001138 int status;
1139
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001140 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001141
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001142 wrb = wrb_from_mccq(adapter);
1143 if (!wrb) {
1144 status = -EBUSY;
1145 goto err;
1146 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001147 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001148
Somnath Kotur106df1e2011-10-27 07:12:13 +00001149 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1150 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001151 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001152 req->capability_flags = cpu_to_le32(cap_flags);
1153 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001154 if (mac)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001155 memcpy(req->mac_addr, mac, ETH_ALEN);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001156 else
1157 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001158
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001159 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001160 if (!status) {
1161 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1162 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001163 if (mac)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001164 *pmac_id = le32_to_cpu(resp->pmac_id);
1165 }
1166
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001167err:
1168 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001169 return status;
1170}
1171
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001172/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001173int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001174{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001175 struct be_mcc_wrb *wrb;
1176 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001177 int status;
1178
Sathya Perla30128032011-11-10 19:17:57 +00001179 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001180 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001181
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001182 spin_lock_bh(&adapter->mcc_lock);
1183
1184 wrb = wrb_from_mccq(adapter);
1185 if (!wrb) {
1186 status = -EBUSY;
1187 goto err;
1188 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001189 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001190
Somnath Kotur106df1e2011-10-27 07:12:13 +00001191 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1192 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001193 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001194 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001195
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001196 status = be_mcc_notify_wait(adapter);
1197err:
1198 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001199 return status;
1200}
1201
1202/* Get stats is a non embedded command: the request is not embedded inside
1203 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001204 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001205 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001206int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001207{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001208 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001209 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001210 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001211
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001212 if (MODULO(adapter->work_counter, be_get_temp_freq) == 0)
1213 be_cmd_get_die_temperature(adapter);
1214
Sathya Perlab31c50a2009-09-17 10:30:13 -07001215 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001216
Sathya Perlab31c50a2009-09-17 10:30:13 -07001217 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001218 if (!wrb) {
1219 status = -EBUSY;
1220 goto err;
1221 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001222 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001223
Somnath Kotur106df1e2011-10-27 07:12:13 +00001224 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1225 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001226
1227 if (adapter->generation == BE_GEN3)
1228 hdr->version = 1;
1229
Sathya Perlab31c50a2009-09-17 10:30:13 -07001230 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001231 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001232
Sathya Perla713d03942009-11-22 22:02:45 +00001233err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001234 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001235 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001236}
1237
Selvin Xavier005d5692011-05-16 07:36:35 +00001238/* Lancer Stats */
1239int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1240 struct be_dma_mem *nonemb_cmd)
1241{
1242
1243 struct be_mcc_wrb *wrb;
1244 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001245 int status = 0;
1246
1247 spin_lock_bh(&adapter->mcc_lock);
1248
1249 wrb = wrb_from_mccq(adapter);
1250 if (!wrb) {
1251 status = -EBUSY;
1252 goto err;
1253 }
1254 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001255
Somnath Kotur106df1e2011-10-27 07:12:13 +00001256 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1257 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb,
1258 nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001259
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001260 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001261 req->cmd_params.params.reset_stats = 0;
1262
Selvin Xavier005d5692011-05-16 07:36:35 +00001263 be_mcc_notify(adapter);
1264 adapter->stats_cmd_sent = true;
1265
1266err:
1267 spin_unlock_bh(&adapter->mcc_lock);
1268 return status;
1269}
1270
Sathya Perlab31c50a2009-09-17 10:30:13 -07001271/* Uses synchronous mcc */
Sathya Perlaea172a02011-08-02 19:57:42 +00001272int be_cmd_link_status_query(struct be_adapter *adapter, u8 *mac_speed,
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001273 u16 *link_speed, u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001274{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001275 struct be_mcc_wrb *wrb;
1276 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001277 int status;
1278
Sathya Perlab31c50a2009-09-17 10:30:13 -07001279 spin_lock_bh(&adapter->mcc_lock);
1280
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001281 if (link_status)
1282 *link_status = LINK_DOWN;
1283
Sathya Perlab31c50a2009-09-17 10:30:13 -07001284 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001285 if (!wrb) {
1286 status = -EBUSY;
1287 goto err;
1288 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001289 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001290
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001291 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1292 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL);
1293
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001294 if (adapter->generation == BE_GEN3 || lancer_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001295 req->hdr.version = 1;
1296
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001297 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001298
Sathya Perlab31c50a2009-09-17 10:30:13 -07001299 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300 if (!status) {
1301 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001302 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001303 if (link_speed)
1304 *link_speed = le16_to_cpu(resp->link_speed);
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001305 if (mac_speed)
1306 *mac_speed = resp->mac_speed;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001307 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001308 if (link_status)
1309 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001310 }
1311
Sathya Perla713d03942009-11-22 22:02:45 +00001312err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001313 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001314 return status;
1315}
1316
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001317/* Uses synchronous mcc */
1318int be_cmd_get_die_temperature(struct be_adapter *adapter)
1319{
1320 struct be_mcc_wrb *wrb;
1321 struct be_cmd_req_get_cntl_addnl_attribs *req;
1322 int status;
1323
1324 spin_lock_bh(&adapter->mcc_lock);
1325
1326 wrb = wrb_from_mccq(adapter);
1327 if (!wrb) {
1328 status = -EBUSY;
1329 goto err;
1330 }
1331 req = embedded_payload(wrb);
1332
Somnath Kotur106df1e2011-10-27 07:12:13 +00001333 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1334 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req),
1335 wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001336
Somnath Kotur3de09452011-09-30 07:25:05 +00001337 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001338
1339err:
1340 spin_unlock_bh(&adapter->mcc_lock);
1341 return status;
1342}
1343
Somnath Kotur311fddc2011-03-16 21:22:43 +00001344/* Uses synchronous mcc */
1345int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1346{
1347 struct be_mcc_wrb *wrb;
1348 struct be_cmd_req_get_fat *req;
1349 int status;
1350
1351 spin_lock_bh(&adapter->mcc_lock);
1352
1353 wrb = wrb_from_mccq(adapter);
1354 if (!wrb) {
1355 status = -EBUSY;
1356 goto err;
1357 }
1358 req = embedded_payload(wrb);
1359
Somnath Kotur106df1e2011-10-27 07:12:13 +00001360 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1361 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001362 req->fat_operation = cpu_to_le32(QUERY_FAT);
1363 status = be_mcc_notify_wait(adapter);
1364 if (!status) {
1365 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1366 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001367 *log_size = le32_to_cpu(resp->log_size) -
1368 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001369 }
1370err:
1371 spin_unlock_bh(&adapter->mcc_lock);
1372 return status;
1373}
1374
1375void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1376{
1377 struct be_dma_mem get_fat_cmd;
1378 struct be_mcc_wrb *wrb;
1379 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001380 u32 offset = 0, total_size, buf_size,
1381 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001382 int status;
1383
1384 if (buf_len == 0)
1385 return;
1386
1387 total_size = buf_len;
1388
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001389 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1390 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1391 get_fat_cmd.size,
1392 &get_fat_cmd.dma);
1393 if (!get_fat_cmd.va) {
1394 status = -ENOMEM;
1395 dev_err(&adapter->pdev->dev,
1396 "Memory allocation failure while retrieving FAT data\n");
1397 return;
1398 }
1399
Somnath Kotur311fddc2011-03-16 21:22:43 +00001400 spin_lock_bh(&adapter->mcc_lock);
1401
Somnath Kotur311fddc2011-03-16 21:22:43 +00001402 while (total_size) {
1403 buf_size = min(total_size, (u32)60*1024);
1404 total_size -= buf_size;
1405
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001406 wrb = wrb_from_mccq(adapter);
1407 if (!wrb) {
1408 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001409 goto err;
1410 }
1411 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001412
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001413 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001414 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1415 OPCODE_COMMON_MANAGE_FAT, payload_len, wrb,
1416 &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001417
1418 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1419 req->read_log_offset = cpu_to_le32(log_offset);
1420 req->read_log_length = cpu_to_le32(buf_size);
1421 req->data_buffer_size = cpu_to_le32(buf_size);
1422
1423 status = be_mcc_notify_wait(adapter);
1424 if (!status) {
1425 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1426 memcpy(buf + offset,
1427 resp->data_buffer,
Somnath Kotur92aa9212011-09-30 07:24:00 +00001428 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001429 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001430 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001431 goto err;
1432 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001433 offset += buf_size;
1434 log_offset += buf_size;
1435 }
1436err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001437 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1438 get_fat_cmd.va,
1439 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001440 spin_unlock_bh(&adapter->mcc_lock);
1441}
1442
Sathya Perla04b71172011-09-27 13:30:27 -04001443/* Uses synchronous mcc */
1444int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver,
1445 char *fw_on_flash)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001446{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001447 struct be_mcc_wrb *wrb;
1448 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001449 int status;
1450
Sathya Perla04b71172011-09-27 13:30:27 -04001451 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001452
Sathya Perla04b71172011-09-27 13:30:27 -04001453 wrb = wrb_from_mccq(adapter);
1454 if (!wrb) {
1455 status = -EBUSY;
1456 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001457 }
1458
Sathya Perla04b71172011-09-27 13:30:27 -04001459 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001460
Somnath Kotur106df1e2011-10-27 07:12:13 +00001461 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1462 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001463 status = be_mcc_notify_wait(adapter);
1464 if (!status) {
1465 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1466 strcpy(fw_ver, resp->firmware_version_string);
1467 if (fw_on_flash)
1468 strcpy(fw_on_flash, resp->fw_on_flash_version_string);
1469 }
1470err:
1471 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001472 return status;
1473}
1474
Sathya Perlab31c50a2009-09-17 10:30:13 -07001475/* set the EQ delay interval of an EQ to specified value
1476 * Uses async mcc
1477 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001478int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001479{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001480 struct be_mcc_wrb *wrb;
1481 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001482 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001483
Sathya Perlab31c50a2009-09-17 10:30:13 -07001484 spin_lock_bh(&adapter->mcc_lock);
1485
1486 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001487 if (!wrb) {
1488 status = -EBUSY;
1489 goto err;
1490 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001491 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001492
Somnath Kotur106df1e2011-10-27 07:12:13 +00001493 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1494 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001495
1496 req->num_eq = cpu_to_le32(1);
1497 req->delay[0].eq_id = cpu_to_le32(eq_id);
1498 req->delay[0].phase = 0;
1499 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1500
Sathya Perlab31c50a2009-09-17 10:30:13 -07001501 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001502
Sathya Perla713d03942009-11-22 22:02:45 +00001503err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001504 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001505 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001506}
1507
Sathya Perlab31c50a2009-09-17 10:30:13 -07001508/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001509int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001510 u32 num, bool untagged, bool promiscuous)
1511{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001512 struct be_mcc_wrb *wrb;
1513 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001514 int status;
1515
Sathya Perlab31c50a2009-09-17 10:30:13 -07001516 spin_lock_bh(&adapter->mcc_lock);
1517
1518 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001519 if (!wrb) {
1520 status = -EBUSY;
1521 goto err;
1522 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001523 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001524
Somnath Kotur106df1e2011-10-27 07:12:13 +00001525 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1526 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001527
1528 req->interface_id = if_id;
1529 req->promiscuous = promiscuous;
1530 req->untagged = untagged;
1531 req->num_vlan = num;
1532 if (!promiscuous) {
1533 memcpy(req->normal_vlan, vtag_array,
1534 req->num_vlan * sizeof(vtag_array[0]));
1535 }
1536
Sathya Perlab31c50a2009-09-17 10:30:13 -07001537 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001538
Sathya Perla713d03942009-11-22 22:02:45 +00001539err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001540 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001541 return status;
1542}
1543
Sathya Perla5b8821b2011-08-02 19:57:44 +00001544int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001545{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001546 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001547 struct be_dma_mem *mem = &adapter->rx_filter;
1548 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001549 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001550
Sathya Perla8788fdc2009-07-27 22:52:03 +00001551 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001552
Sathya Perlab31c50a2009-09-17 10:30:13 -07001553 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001554 if (!wrb) {
1555 status = -EBUSY;
1556 goto err;
1557 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001558 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001559 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1560 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1561 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001562
Sathya Perla5b8821b2011-08-02 19:57:44 +00001563 req->if_id = cpu_to_le32(adapter->if_handle);
1564 if (flags & IFF_PROMISC) {
1565 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1566 BE_IF_FLAGS_VLAN_PROMISCUOUS);
1567 if (value == ON)
1568 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001569 BE_IF_FLAGS_VLAN_PROMISCUOUS);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001570 } else if (flags & IFF_ALLMULTI) {
1571 req->if_flags_mask = req->if_flags =
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001572 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001573 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001574 struct netdev_hw_addr *ha;
1575 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001576
Sathya Perla8e7d3f62011-09-27 13:29:38 -04001577 req->if_flags_mask = req->if_flags =
1578 cpu_to_le32(BE_IF_FLAGS_MULTICAST);
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001579
1580 /* Reset mcast promisc mode if already set by setting mask
1581 * and not setting flags field
1582 */
1583 req->if_flags_mask |=
1584 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
1585
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001586 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001587 netdev_for_each_mc_addr(ha, adapter->netdev)
1588 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1589 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001590
Sathya Perla0d1d5872011-08-03 05:19:27 -07001591 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001592err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001593 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001594 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001595}
1596
Sathya Perlab31c50a2009-09-17 10:30:13 -07001597/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001598int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001599{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001600 struct be_mcc_wrb *wrb;
1601 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001602 int status;
1603
Sathya Perlab31c50a2009-09-17 10:30:13 -07001604 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001605
Sathya Perlab31c50a2009-09-17 10:30:13 -07001606 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001607 if (!wrb) {
1608 status = -EBUSY;
1609 goto err;
1610 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001611 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001612
Somnath Kotur106df1e2011-10-27 07:12:13 +00001613 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1614 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001615
1616 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1617 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1618
Sathya Perlab31c50a2009-09-17 10:30:13 -07001619 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001620
Sathya Perla713d03942009-11-22 22:02:45 +00001621err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001622 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001623 return status;
1624}
1625
Sathya Perlab31c50a2009-09-17 10:30:13 -07001626/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001627int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001628{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001629 struct be_mcc_wrb *wrb;
1630 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001631 int status;
1632
Sathya Perlab31c50a2009-09-17 10:30:13 -07001633 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001634
Sathya Perlab31c50a2009-09-17 10:30:13 -07001635 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001636 if (!wrb) {
1637 status = -EBUSY;
1638 goto err;
1639 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001640 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001641
Somnath Kotur106df1e2011-10-27 07:12:13 +00001642 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1643 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001644
Sathya Perlab31c50a2009-09-17 10:30:13 -07001645 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001646 if (!status) {
1647 struct be_cmd_resp_get_flow_control *resp =
1648 embedded_payload(wrb);
1649 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1650 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1651 }
1652
Sathya Perla713d03942009-11-22 22:02:45 +00001653err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001654 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001655 return status;
1656}
1657
Sathya Perlab31c50a2009-09-17 10:30:13 -07001658/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001659int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1660 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001661{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001662 struct be_mcc_wrb *wrb;
1663 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001664 int status;
1665
Ivan Vecera29849612010-12-14 05:43:19 +00001666 if (mutex_lock_interruptible(&adapter->mbox_lock))
1667 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001668
Sathya Perlab31c50a2009-09-17 10:30:13 -07001669 wrb = wrb_from_mbox(adapter);
1670 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001671
Somnath Kotur106df1e2011-10-27 07:12:13 +00001672 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1673 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001674
Sathya Perlab31c50a2009-09-17 10:30:13 -07001675 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001676 if (!status) {
1677 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1678 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001679 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001680 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001681 }
1682
Ivan Vecera29849612010-12-14 05:43:19 +00001683 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001684 return status;
1685}
sarveshwarb14074ea2009-08-05 13:05:24 -07001686
Sathya Perlab31c50a2009-09-17 10:30:13 -07001687/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001688int be_cmd_reset_function(struct be_adapter *adapter)
1689{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001690 struct be_mcc_wrb *wrb;
1691 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001692 int status;
1693
Ivan Vecera29849612010-12-14 05:43:19 +00001694 if (mutex_lock_interruptible(&adapter->mbox_lock))
1695 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001696
Sathya Perlab31c50a2009-09-17 10:30:13 -07001697 wrb = wrb_from_mbox(adapter);
1698 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001699
Somnath Kotur106df1e2011-10-27 07:12:13 +00001700 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1701 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07001702
Sathya Perlab31c50a2009-09-17 10:30:13 -07001703 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001704
Ivan Vecera29849612010-12-14 05:43:19 +00001705 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001706 return status;
1707}
Ajit Khaparde84517482009-09-04 03:12:16 +00001708
Sathya Perla3abcded2010-10-03 22:12:27 -07001709int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1710{
1711 struct be_mcc_wrb *wrb;
1712 struct be_cmd_req_rss_config *req;
Padmanabh Ratnakar65f85842011-11-25 05:48:38 +00001713 u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e,
1714 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2,
1715 0x3ea83c02, 0x4a110304};
Sathya Perla3abcded2010-10-03 22:12:27 -07001716 int status;
1717
Ivan Vecera29849612010-12-14 05:43:19 +00001718 if (mutex_lock_interruptible(&adapter->mbox_lock))
1719 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001720
1721 wrb = wrb_from_mbox(adapter);
1722 req = embedded_payload(wrb);
1723
Somnath Kotur106df1e2011-10-27 07:12:13 +00001724 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1725 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07001726
1727 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perla1ca7ba92012-02-23 18:50:16 +00001728 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4 |
1729 RSS_ENABLE_TCP_IPV6 | RSS_ENABLE_IPV6);
Sathya Perla3abcded2010-10-03 22:12:27 -07001730 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1731 memcpy(req->cpu_table, rsstable, table_size);
1732 memcpy(req->hash, myhash, sizeof(myhash));
1733 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1734
1735 status = be_mbox_notify_wait(adapter);
1736
Ivan Vecera29849612010-12-14 05:43:19 +00001737 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001738 return status;
1739}
1740
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001741/* Uses sync mcc */
1742int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1743 u8 bcn, u8 sts, u8 state)
1744{
1745 struct be_mcc_wrb *wrb;
1746 struct be_cmd_req_enable_disable_beacon *req;
1747 int status;
1748
1749 spin_lock_bh(&adapter->mcc_lock);
1750
1751 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001752 if (!wrb) {
1753 status = -EBUSY;
1754 goto err;
1755 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001756 req = embedded_payload(wrb);
1757
Somnath Kotur106df1e2011-10-27 07:12:13 +00001758 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1759 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001760
1761 req->port_num = port_num;
1762 req->beacon_state = state;
1763 req->beacon_duration = bcn;
1764 req->status_duration = sts;
1765
1766 status = be_mcc_notify_wait(adapter);
1767
Sathya Perla713d03942009-11-22 22:02:45 +00001768err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001769 spin_unlock_bh(&adapter->mcc_lock);
1770 return status;
1771}
1772
1773/* Uses sync mcc */
1774int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1775{
1776 struct be_mcc_wrb *wrb;
1777 struct be_cmd_req_get_beacon_state *req;
1778 int status;
1779
1780 spin_lock_bh(&adapter->mcc_lock);
1781
1782 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001783 if (!wrb) {
1784 status = -EBUSY;
1785 goto err;
1786 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001787 req = embedded_payload(wrb);
1788
Somnath Kotur106df1e2011-10-27 07:12:13 +00001789 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1790 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001791
1792 req->port_num = port_num;
1793
1794 status = be_mcc_notify_wait(adapter);
1795 if (!status) {
1796 struct be_cmd_resp_get_beacon_state *resp =
1797 embedded_payload(wrb);
1798 *state = resp->beacon_state;
1799 }
1800
Sathya Perla713d03942009-11-22 22:02:45 +00001801err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001802 spin_unlock_bh(&adapter->mcc_lock);
1803 return status;
1804}
1805
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001806int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
1807 u32 data_size, u32 data_offset, const char *obj_name,
1808 u32 *data_written, u8 *addn_status)
1809{
1810 struct be_mcc_wrb *wrb;
1811 struct lancer_cmd_req_write_object *req;
1812 struct lancer_cmd_resp_write_object *resp;
1813 void *ctxt = NULL;
1814 int status;
1815
1816 spin_lock_bh(&adapter->mcc_lock);
1817 adapter->flash_status = 0;
1818
1819 wrb = wrb_from_mccq(adapter);
1820 if (!wrb) {
1821 status = -EBUSY;
1822 goto err_unlock;
1823 }
1824
1825 req = embedded_payload(wrb);
1826
Somnath Kotur106df1e2011-10-27 07:12:13 +00001827 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001828 OPCODE_COMMON_WRITE_OBJECT,
Somnath Kotur106df1e2011-10-27 07:12:13 +00001829 sizeof(struct lancer_cmd_req_write_object), wrb,
1830 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001831
1832 ctxt = &req->context;
1833 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
1834 write_length, ctxt, data_size);
1835
1836 if (data_size == 0)
1837 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
1838 eof, ctxt, 1);
1839 else
1840 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
1841 eof, ctxt, 0);
1842
1843 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1844 req->write_offset = cpu_to_le32(data_offset);
1845 strcpy(req->object_name, obj_name);
1846 req->descriptor_count = cpu_to_le32(1);
1847 req->buf_len = cpu_to_le32(data_size);
1848 req->addr_low = cpu_to_le32((cmd->dma +
1849 sizeof(struct lancer_cmd_req_write_object))
1850 & 0xFFFFFFFF);
1851 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
1852 sizeof(struct lancer_cmd_req_write_object)));
1853
1854 be_mcc_notify(adapter);
1855 spin_unlock_bh(&adapter->mcc_lock);
1856
1857 if (!wait_for_completion_timeout(&adapter->flash_compl,
Padmanabh Ratnakar804c7512012-04-25 01:46:18 +00001858 msecs_to_jiffies(30000)))
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001859 status = -1;
1860 else
1861 status = adapter->flash_status;
1862
1863 resp = embedded_payload(wrb);
Padmanabh Ratnakar804c7512012-04-25 01:46:18 +00001864 if (!status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001865 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakar804c7512012-04-25 01:46:18 +00001866 else
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001867 *addn_status = resp->additional_status;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001868
1869 return status;
1870
1871err_unlock:
1872 spin_unlock_bh(&adapter->mcc_lock);
1873 return status;
1874}
1875
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00001876int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
1877 u32 data_size, u32 data_offset, const char *obj_name,
1878 u32 *data_read, u32 *eof, u8 *addn_status)
1879{
1880 struct be_mcc_wrb *wrb;
1881 struct lancer_cmd_req_read_object *req;
1882 struct lancer_cmd_resp_read_object *resp;
1883 int status;
1884
1885 spin_lock_bh(&adapter->mcc_lock);
1886
1887 wrb = wrb_from_mccq(adapter);
1888 if (!wrb) {
1889 status = -EBUSY;
1890 goto err_unlock;
1891 }
1892
1893 req = embedded_payload(wrb);
1894
1895 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1896 OPCODE_COMMON_READ_OBJECT,
1897 sizeof(struct lancer_cmd_req_read_object), wrb,
1898 NULL);
1899
1900 req->desired_read_len = cpu_to_le32(data_size);
1901 req->read_offset = cpu_to_le32(data_offset);
1902 strcpy(req->object_name, obj_name);
1903 req->descriptor_count = cpu_to_le32(1);
1904 req->buf_len = cpu_to_le32(data_size);
1905 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
1906 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
1907
1908 status = be_mcc_notify_wait(adapter);
1909
1910 resp = embedded_payload(wrb);
1911 if (!status) {
1912 *data_read = le32_to_cpu(resp->actual_read_len);
1913 *eof = le32_to_cpu(resp->eof);
1914 } else {
1915 *addn_status = resp->additional_status;
1916 }
1917
1918err_unlock:
1919 spin_unlock_bh(&adapter->mcc_lock);
1920 return status;
1921}
1922
Ajit Khaparde84517482009-09-04 03:12:16 +00001923int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1924 u32 flash_type, u32 flash_opcode, u32 buf_size)
1925{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001926 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001927 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00001928 int status;
1929
Sathya Perlab31c50a2009-09-17 10:30:13 -07001930 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001931 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001932
1933 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001934 if (!wrb) {
1935 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001936 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00001937 }
1938 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001939
Somnath Kotur106df1e2011-10-27 07:12:13 +00001940 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1941 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00001942
1943 req->params.op_type = cpu_to_le32(flash_type);
1944 req->params.op_code = cpu_to_le32(flash_opcode);
1945 req->params.data_buf_size = cpu_to_le32(buf_size);
1946
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001947 be_mcc_notify(adapter);
1948 spin_unlock_bh(&adapter->mcc_lock);
1949
1950 if (!wait_for_completion_timeout(&adapter->flash_compl,
Sathya Perlae2edb7d2011-08-22 19:41:54 +00001951 msecs_to_jiffies(40000)))
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001952 status = -1;
1953 else
1954 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00001955
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001956 return status;
1957
1958err_unlock:
1959 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001960 return status;
1961}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001962
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001963int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1964 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001965{
1966 struct be_mcc_wrb *wrb;
1967 struct be_cmd_write_flashrom *req;
1968 int status;
1969
1970 spin_lock_bh(&adapter->mcc_lock);
1971
1972 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001973 if (!wrb) {
1974 status = -EBUSY;
1975 goto err;
1976 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001977 req = embedded_payload(wrb);
1978
Somnath Kotur106df1e2011-10-27 07:12:13 +00001979 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1980 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4, wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001981
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001982 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001983 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00001984 req->params.offset = cpu_to_le32(offset);
1985 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001986
1987 status = be_mcc_notify_wait(adapter);
1988 if (!status)
1989 memcpy(flashed_crc, req->params.data_buf, 4);
1990
Sathya Perla713d03942009-11-22 22:02:45 +00001991err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001992 spin_unlock_bh(&adapter->mcc_lock);
1993 return status;
1994}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001995
Dan Carpenterc196b022010-05-26 04:47:39 +00001996int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001997 struct be_dma_mem *nonemb_cmd)
1998{
1999 struct be_mcc_wrb *wrb;
2000 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002001 int status;
2002
2003 spin_lock_bh(&adapter->mcc_lock);
2004
2005 wrb = wrb_from_mccq(adapter);
2006 if (!wrb) {
2007 status = -EBUSY;
2008 goto err;
2009 }
2010 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002011
Somnath Kotur106df1e2011-10-27 07:12:13 +00002012 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2013 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb,
2014 nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002015 memcpy(req->magic_mac, mac, ETH_ALEN);
2016
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002017 status = be_mcc_notify_wait(adapter);
2018
2019err:
2020 spin_unlock_bh(&adapter->mcc_lock);
2021 return status;
2022}
Suresh Rff33a6e2009-12-03 16:15:52 -08002023
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002024int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2025 u8 loopback_type, u8 enable)
2026{
2027 struct be_mcc_wrb *wrb;
2028 struct be_cmd_req_set_lmode *req;
2029 int status;
2030
2031 spin_lock_bh(&adapter->mcc_lock);
2032
2033 wrb = wrb_from_mccq(adapter);
2034 if (!wrb) {
2035 status = -EBUSY;
2036 goto err;
2037 }
2038
2039 req = embedded_payload(wrb);
2040
Somnath Kotur106df1e2011-10-27 07:12:13 +00002041 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2042 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb,
2043 NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002044
2045 req->src_port = port_num;
2046 req->dest_port = port_num;
2047 req->loopback_type = loopback_type;
2048 req->loopback_state = enable;
2049
2050 status = be_mcc_notify_wait(adapter);
2051err:
2052 spin_unlock_bh(&adapter->mcc_lock);
2053 return status;
2054}
2055
Suresh Rff33a6e2009-12-03 16:15:52 -08002056int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2057 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2058{
2059 struct be_mcc_wrb *wrb;
2060 struct be_cmd_req_loopback_test *req;
2061 int status;
2062
2063 spin_lock_bh(&adapter->mcc_lock);
2064
2065 wrb = wrb_from_mccq(adapter);
2066 if (!wrb) {
2067 status = -EBUSY;
2068 goto err;
2069 }
2070
2071 req = embedded_payload(wrb);
2072
Somnath Kotur106df1e2011-10-27 07:12:13 +00002073 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2074 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL);
Sathya Perla3ffd0512010-06-01 00:19:33 -07002075 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002076
2077 req->pattern = cpu_to_le64(pattern);
2078 req->src_port = cpu_to_le32(port_num);
2079 req->dest_port = cpu_to_le32(port_num);
2080 req->pkt_size = cpu_to_le32(pkt_size);
2081 req->num_pkts = cpu_to_le32(num_pkts);
2082 req->loopback_type = cpu_to_le32(loopback_type);
2083
2084 status = be_mcc_notify_wait(adapter);
2085 if (!status) {
2086 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2087 status = le32_to_cpu(resp->status);
2088 }
2089
2090err:
2091 spin_unlock_bh(&adapter->mcc_lock);
2092 return status;
2093}
2094
2095int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2096 u32 byte_cnt, struct be_dma_mem *cmd)
2097{
2098 struct be_mcc_wrb *wrb;
2099 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002100 int status;
2101 int i, j = 0;
2102
2103 spin_lock_bh(&adapter->mcc_lock);
2104
2105 wrb = wrb_from_mccq(adapter);
2106 if (!wrb) {
2107 status = -EBUSY;
2108 goto err;
2109 }
2110 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002111 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2112 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002113
2114 req->pattern = cpu_to_le64(pattern);
2115 req->byte_count = cpu_to_le32(byte_cnt);
2116 for (i = 0; i < byte_cnt; i++) {
2117 req->snd_buff[i] = (u8)(pattern >> (j*8));
2118 j++;
2119 if (j > 7)
2120 j = 0;
2121 }
2122
2123 status = be_mcc_notify_wait(adapter);
2124
2125 if (!status) {
2126 struct be_cmd_resp_ddrdma_test *resp;
2127 resp = cmd->va;
2128 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2129 resp->snd_err) {
2130 status = -1;
2131 }
2132 }
2133
2134err:
2135 spin_unlock_bh(&adapter->mcc_lock);
2136 return status;
2137}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002138
Dan Carpenterc196b022010-05-26 04:47:39 +00002139int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002140 struct be_dma_mem *nonemb_cmd)
2141{
2142 struct be_mcc_wrb *wrb;
2143 struct be_cmd_req_seeprom_read *req;
2144 struct be_sge *sge;
2145 int status;
2146
2147 spin_lock_bh(&adapter->mcc_lock);
2148
2149 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002150 if (!wrb) {
2151 status = -EBUSY;
2152 goto err;
2153 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002154 req = nonemb_cmd->va;
2155 sge = nonembedded_sgl(wrb);
2156
Somnath Kotur106df1e2011-10-27 07:12:13 +00002157 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2158 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2159 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002160
2161 status = be_mcc_notify_wait(adapter);
2162
Ajit Khapardee45ff012011-02-04 17:18:28 +00002163err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002164 spin_unlock_bh(&adapter->mcc_lock);
2165 return status;
2166}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002167
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002168int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002169{
2170 struct be_mcc_wrb *wrb;
2171 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002172 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002173 int status;
2174
2175 spin_lock_bh(&adapter->mcc_lock);
2176
2177 wrb = wrb_from_mccq(adapter);
2178 if (!wrb) {
2179 status = -EBUSY;
2180 goto err;
2181 }
Sathya Perla306f1342011-08-02 19:57:45 +00002182 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2183 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2184 &cmd.dma);
2185 if (!cmd.va) {
2186 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2187 status = -ENOMEM;
2188 goto err;
2189 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002190
Sathya Perla306f1342011-08-02 19:57:45 +00002191 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002192
Somnath Kotur106df1e2011-10-27 07:12:13 +00002193 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2194 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2195 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002196
2197 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002198 if (!status) {
2199 struct be_phy_info *resp_phy_info =
2200 cmd.va + sizeof(struct be_cmd_req_hdr);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002201 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2202 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002203 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002204 adapter->phy.auto_speeds_supported =
2205 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2206 adapter->phy.fixed_speeds_supported =
2207 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2208 adapter->phy.misc_params =
2209 le32_to_cpu(resp_phy_info->misc_params);
Sathya Perla306f1342011-08-02 19:57:45 +00002210 }
2211 pci_free_consistent(adapter->pdev, cmd.size,
2212 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002213err:
2214 spin_unlock_bh(&adapter->mcc_lock);
2215 return status;
2216}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002217
2218int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2219{
2220 struct be_mcc_wrb *wrb;
2221 struct be_cmd_req_set_qos *req;
2222 int status;
2223
2224 spin_lock_bh(&adapter->mcc_lock);
2225
2226 wrb = wrb_from_mccq(adapter);
2227 if (!wrb) {
2228 status = -EBUSY;
2229 goto err;
2230 }
2231
2232 req = embedded_payload(wrb);
2233
Somnath Kotur106df1e2011-10-27 07:12:13 +00002234 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2235 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002236
2237 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002238 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2239 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002240
2241 status = be_mcc_notify_wait(adapter);
2242
2243err:
2244 spin_unlock_bh(&adapter->mcc_lock);
2245 return status;
2246}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002247
2248int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2249{
2250 struct be_mcc_wrb *wrb;
2251 struct be_cmd_req_cntl_attribs *req;
2252 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002253 int status;
2254 int payload_len = max(sizeof(*req), sizeof(*resp));
2255 struct mgmt_controller_attrib *attribs;
2256 struct be_dma_mem attribs_cmd;
2257
2258 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2259 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2260 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2261 &attribs_cmd.dma);
2262 if (!attribs_cmd.va) {
2263 dev_err(&adapter->pdev->dev,
2264 "Memory allocation failure\n");
2265 return -ENOMEM;
2266 }
2267
2268 if (mutex_lock_interruptible(&adapter->mbox_lock))
2269 return -1;
2270
2271 wrb = wrb_from_mbox(adapter);
2272 if (!wrb) {
2273 status = -EBUSY;
2274 goto err;
2275 }
2276 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002277
Somnath Kotur106df1e2011-10-27 07:12:13 +00002278 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2279 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb,
2280 &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002281
2282 status = be_mbox_notify_wait(adapter);
2283 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002284 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002285 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2286 }
2287
2288err:
2289 mutex_unlock(&adapter->mbox_lock);
2290 pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
2291 attribs_cmd.dma);
2292 return status;
2293}
Sathya Perla2e588f82011-03-11 02:49:26 +00002294
2295/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002296int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002297{
2298 struct be_mcc_wrb *wrb;
2299 struct be_cmd_req_set_func_cap *req;
2300 int status;
2301
2302 if (mutex_lock_interruptible(&adapter->mbox_lock))
2303 return -1;
2304
2305 wrb = wrb_from_mbox(adapter);
2306 if (!wrb) {
2307 status = -EBUSY;
2308 goto err;
2309 }
2310
2311 req = embedded_payload(wrb);
2312
Somnath Kotur106df1e2011-10-27 07:12:13 +00002313 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2314 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002315
2316 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2317 CAPABILITY_BE3_NATIVE_ERX_API);
2318 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2319
2320 status = be_mbox_notify_wait(adapter);
2321 if (!status) {
2322 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2323 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2324 CAPABILITY_BE3_NATIVE_ERX_API;
2325 }
2326err:
2327 mutex_unlock(&adapter->mbox_lock);
2328 return status;
2329}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002330
2331/* Uses synchronous MCCQ */
2332int be_cmd_get_mac_from_list(struct be_adapter *adapter, u32 domain,
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002333 bool *pmac_id_active, u32 *pmac_id, u8 *mac)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002334{
2335 struct be_mcc_wrb *wrb;
2336 struct be_cmd_req_get_mac_list *req;
2337 int status;
2338 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002339 struct be_dma_mem get_mac_list_cmd;
2340 int i;
2341
2342 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
2343 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
2344 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
2345 get_mac_list_cmd.size,
2346 &get_mac_list_cmd.dma);
2347
2348 if (!get_mac_list_cmd.va) {
2349 dev_err(&adapter->pdev->dev,
2350 "Memory allocation failure during GET_MAC_LIST\n");
2351 return -ENOMEM;
2352 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002353
2354 spin_lock_bh(&adapter->mcc_lock);
2355
2356 wrb = wrb_from_mccq(adapter);
2357 if (!wrb) {
2358 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002359 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002360 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002361
2362 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002363
2364 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2365 OPCODE_COMMON_GET_MAC_LIST, sizeof(*req),
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002366 wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002367
2368 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002369 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
2370 req->perm_override = 1;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002371
2372 status = be_mcc_notify_wait(adapter);
2373 if (!status) {
2374 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002375 get_mac_list_cmd.va;
2376 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
2377 /* Mac list returned could contain one or more active mac_ids
2378 * or one or more pseudo permanant mac addresses. If an active
2379 * mac_id is present, return first active mac_id found
2380 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002381 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002382 struct get_list_macaddr *mac_entry;
2383 u16 mac_addr_size;
2384 u32 mac_id;
2385
2386 mac_entry = &resp->macaddr_list[i];
2387 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
2388 /* mac_id is a 32 bit value and mac_addr size
2389 * is 6 bytes
2390 */
2391 if (mac_addr_size == sizeof(u32)) {
2392 *pmac_id_active = true;
2393 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
2394 *pmac_id = le32_to_cpu(mac_id);
2395 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002396 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002397 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002398 /* If no active mac_id found, return first pseudo mac addr */
2399 *pmac_id_active = false;
2400 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
2401 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002402 }
2403
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002404out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002405 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00002406 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
2407 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002408 return status;
2409}
2410
2411/* Uses synchronous MCCQ */
2412int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
2413 u8 mac_count, u32 domain)
2414{
2415 struct be_mcc_wrb *wrb;
2416 struct be_cmd_req_set_mac_list *req;
2417 int status;
2418 struct be_dma_mem cmd;
2419
2420 memset(&cmd, 0, sizeof(struct be_dma_mem));
2421 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
2422 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
2423 &cmd.dma, GFP_KERNEL);
2424 if (!cmd.va) {
2425 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2426 return -ENOMEM;
2427 }
2428
2429 spin_lock_bh(&adapter->mcc_lock);
2430
2431 wrb = wrb_from_mccq(adapter);
2432 if (!wrb) {
2433 status = -EBUSY;
2434 goto err;
2435 }
2436
2437 req = cmd.va;
2438 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2439 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
2440 wrb, &cmd);
2441
2442 req->hdr.domain = domain;
2443 req->mac_count = mac_count;
2444 if (mac_count)
2445 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
2446
2447 status = be_mcc_notify_wait(adapter);
2448
2449err:
2450 dma_free_coherent(&adapter->pdev->dev, cmd.size,
2451 cmd.va, cmd.dma);
2452 spin_unlock_bh(&adapter->mcc_lock);
2453 return status;
2454}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002455
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00002456int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
2457 u32 domain, u16 intf_id)
2458{
2459 struct be_mcc_wrb *wrb;
2460 struct be_cmd_req_set_hsw_config *req;
2461 void *ctxt;
2462 int status;
2463
2464 spin_lock_bh(&adapter->mcc_lock);
2465
2466 wrb = wrb_from_mccq(adapter);
2467 if (!wrb) {
2468 status = -EBUSY;
2469 goto err;
2470 }
2471
2472 req = embedded_payload(wrb);
2473 ctxt = &req->context;
2474
2475 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2476 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2477
2478 req->hdr.domain = domain;
2479 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
2480 if (pvid) {
2481 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
2482 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
2483 }
2484
2485 be_dws_cpu_to_le(req->context, sizeof(req->context));
2486 status = be_mcc_notify_wait(adapter);
2487
2488err:
2489 spin_unlock_bh(&adapter->mcc_lock);
2490 return status;
2491}
2492
2493/* Get Hyper switch config */
2494int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
2495 u32 domain, u16 intf_id)
2496{
2497 struct be_mcc_wrb *wrb;
2498 struct be_cmd_req_get_hsw_config *req;
2499 void *ctxt;
2500 int status;
2501 u16 vid;
2502
2503 spin_lock_bh(&adapter->mcc_lock);
2504
2505 wrb = wrb_from_mccq(adapter);
2506 if (!wrb) {
2507 status = -EBUSY;
2508 goto err;
2509 }
2510
2511 req = embedded_payload(wrb);
2512 ctxt = &req->context;
2513
2514 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2515 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL);
2516
2517 req->hdr.domain = domain;
2518 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, ctxt,
2519 intf_id);
2520 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
2521 be_dws_cpu_to_le(req->context, sizeof(req->context));
2522
2523 status = be_mcc_notify_wait(adapter);
2524 if (!status) {
2525 struct be_cmd_resp_get_hsw_config *resp =
2526 embedded_payload(wrb);
2527 be_dws_le_to_cpu(&resp->context,
2528 sizeof(resp->context));
2529 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
2530 pvid, &resp->context);
2531 *pvid = le16_to_cpu(vid);
2532 }
2533
2534err:
2535 spin_unlock_bh(&adapter->mcc_lock);
2536 return status;
2537}
2538
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00002539int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
2540{
2541 struct be_mcc_wrb *wrb;
2542 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
2543 int status;
2544 int payload_len = sizeof(*req);
2545 struct be_dma_mem cmd;
2546
2547 memset(&cmd, 0, sizeof(struct be_dma_mem));
2548 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
2549 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2550 &cmd.dma);
2551 if (!cmd.va) {
2552 dev_err(&adapter->pdev->dev,
2553 "Memory allocation failure\n");
2554 return -ENOMEM;
2555 }
2556
2557 if (mutex_lock_interruptible(&adapter->mbox_lock))
2558 return -1;
2559
2560 wrb = wrb_from_mbox(adapter);
2561 if (!wrb) {
2562 status = -EBUSY;
2563 goto err;
2564 }
2565
2566 req = cmd.va;
2567
2568 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2569 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
2570 payload_len, wrb, &cmd);
2571
2572 req->hdr.version = 1;
2573 req->query_options = BE_GET_WOL_CAP;
2574
2575 status = be_mbox_notify_wait(adapter);
2576 if (!status) {
2577 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
2578 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va;
2579
2580 /* the command could succeed misleadingly on old f/w
2581 * which is not aware of the V1 version. fake an error. */
2582 if (resp->hdr.response_length < payload_len) {
2583 status = -1;
2584 goto err;
2585 }
2586 adapter->wol_cap = resp->wol_settings;
2587 }
2588err:
2589 mutex_unlock(&adapter->mbox_lock);
2590 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2591 return status;
2592}