blob: 7292be64632b84bcb10becb216190b1cd8d61d34 [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 */
22static int be_get_temp_freq = 32;
23
Sathya Perla8788fdc2009-07-27 22:52:03 +000024static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000025{
Sathya Perla8788fdc2009-07-27 22:52:03 +000026 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000027 u32 val = 0;
28
Ajit Khaparde7acc2082011-02-11 13:38:17 +000029 if (adapter->eeh_err) {
30 dev_info(&adapter->pdev->dev,
31 "Error in Card Detected! Cannot issue commands\n");
32 return;
33 }
34
Sathya Perla5fb379e2009-06-18 00:02:59 +000035 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
36 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000037
38 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000039 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000040}
41
42/* To check if valid bit is set, check the entire word as we don't know
43 * the endianness of the data (old entry is host endian while a new entry is
44 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000045static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000046{
47 if (compl->flags != 0) {
48 compl->flags = le32_to_cpu(compl->flags);
49 BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
50 return true;
51 } else {
52 return false;
53 }
54}
55
56/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +000057static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000058{
59 compl->flags = 0;
60}
61
Sathya Perla8788fdc2009-07-27 22:52:03 +000062static int be_mcc_compl_process(struct be_adapter *adapter,
Sathya Perlaefd2e402009-07-27 22:53:10 +000063 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000064{
65 u16 compl_status, extd_status;
66
67 /* Just swap the status to host endian; mcc tag is opaquely copied
68 * from mcc_wrb */
69 be_dws_le_to_cpu(compl, 4);
70
71 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
72 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -070073
Shripad Nunjundarao485bf562011-05-16 07:36:59 +000074 if (((compl->tag0 == OPCODE_COMMON_WRITE_FLASHROM) ||
75 (compl->tag0 == OPCODE_COMMON_WRITE_OBJECT)) &&
Sarveshwar Bandidd131e72010-05-25 16:16:32 -070076 (compl->tag1 == CMD_SUBSYSTEM_COMMON)) {
77 adapter->flash_status = compl_status;
78 complete(&adapter->flash_compl);
79 }
80
Sathya Perlab31c50a2009-09-17 10:30:13 -070081 if (compl_status == MCC_STATUS_SUCCESS) {
Selvin Xavier005d5692011-05-16 07:36:35 +000082 if (((compl->tag0 == OPCODE_ETH_GET_STATISTICS) ||
83 (compl->tag0 == OPCODE_ETH_GET_PPORT_STATS)) &&
Ajit Khaparde63499352011-04-19 12:11:02 +000084 (compl->tag1 == CMD_SUBSYSTEM_ETH)) {
Ajit Khaparde89a88ab2011-05-16 07:36:18 +000085 be_parse_stats(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +000086 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -070087 }
Sathya Perla2b3f2912011-06-29 23:32:56 +000088 } else {
89 if (compl_status == MCC_STATUS_NOT_SUPPORTED ||
90 compl_status == MCC_STATUS_ILLEGAL_REQUEST)
91 goto done;
92
93 if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
94 dev_warn(&adapter->pdev->dev, "This domain(VM) is not "
95 "permitted to execute this cmd (opcode %d)\n",
96 compl->tag0);
97 } else {
98 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
99 CQE_STATUS_EXTD_MASK;
100 dev_err(&adapter->pdev->dev, "Cmd (opcode %d) failed:"
101 "status %d, extd-status %d\n",
102 compl->tag0, compl_status, extd_status);
103 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000104 }
Sathya Perla2b3f2912011-06-29 23:32:56 +0000105done:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700106 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000107}
108
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000109/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000110static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000111 struct be_async_event_link_state *evt)
112{
Sathya Perlaea172a02011-08-02 19:57:42 +0000113 be_link_status_update(adapter, evt->port_link_status);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000114}
115
Somnath Koturcc4ce022010-10-21 07:11:14 -0700116/* Grp5 CoS Priority evt */
117static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
118 struct be_async_event_grp5_cos_priority *evt)
119{
120 if (evt->valid) {
121 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000122 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700123 adapter->recommended_prio =
124 evt->reco_default_priority << VLAN_PRIO_SHIFT;
125 }
126}
127
128/* Grp5 QOS Speed evt */
129static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
130 struct be_async_event_grp5_qos_link_speed *evt)
131{
132 if (evt->physical_port == adapter->port_num) {
133 /* qos_link_speed is in units of 10 Mbps */
134 adapter->link_speed = evt->qos_link_speed * 10;
135 }
136}
137
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000138/*Grp5 PVID evt*/
139static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
140 struct be_async_event_grp5_pvid_state *evt)
141{
142 if (evt->enabled)
Somnath Kotur6709d952011-05-04 22:40:46 +0000143 adapter->pvid = le16_to_cpu(evt->tag);
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000144 else
145 adapter->pvid = 0;
146}
147
Somnath Koturcc4ce022010-10-21 07:11:14 -0700148static void be_async_grp5_evt_process(struct be_adapter *adapter,
149 u32 trailer, struct be_mcc_compl *evt)
150{
151 u8 event_type = 0;
152
153 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
154 ASYNC_TRAILER_EVENT_TYPE_MASK;
155
156 switch (event_type) {
157 case ASYNC_EVENT_COS_PRIORITY:
158 be_async_grp5_cos_priority_process(adapter,
159 (struct be_async_event_grp5_cos_priority *)evt);
160 break;
161 case ASYNC_EVENT_QOS_SPEED:
162 be_async_grp5_qos_speed_process(adapter,
163 (struct be_async_event_grp5_qos_link_speed *)evt);
164 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000165 case ASYNC_EVENT_PVID_STATE:
166 be_async_grp5_pvid_state_process(adapter,
167 (struct be_async_event_grp5_pvid_state *)evt);
168 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700169 default:
170 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
171 break;
172 }
173}
174
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000175static inline bool is_link_state_evt(u32 trailer)
176{
Eric Dumazet807540b2010-09-23 05:40:09 +0000177 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000178 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000179 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000180}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000181
Somnath Koturcc4ce022010-10-21 07:11:14 -0700182static inline bool is_grp5_evt(u32 trailer)
183{
184 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
185 ASYNC_TRAILER_EVENT_CODE_MASK) ==
186 ASYNC_EVENT_CODE_GRP_5);
187}
188
Sathya Perlaefd2e402009-07-27 22:53:10 +0000189static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000190{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000191 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000192 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000193
194 if (be_mcc_compl_is_new(compl)) {
195 queue_tail_inc(mcc_cq);
196 return compl;
197 }
198 return NULL;
199}
200
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000201void be_async_mcc_enable(struct be_adapter *adapter)
202{
203 spin_lock_bh(&adapter->mcc_cq_lock);
204
205 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
206 adapter->mcc_obj.rearm_cq = true;
207
208 spin_unlock_bh(&adapter->mcc_cq_lock);
209}
210
211void be_async_mcc_disable(struct be_adapter *adapter)
212{
213 adapter->mcc_obj.rearm_cq = false;
214}
215
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800216int be_process_mcc(struct be_adapter *adapter, int *status)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000217{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000218 struct be_mcc_compl *compl;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800219 int num = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000220 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000221
Sathya Perla8788fdc2009-07-27 22:52:03 +0000222 spin_lock_bh(&adapter->mcc_cq_lock);
223 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000224 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
225 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000226 if (is_link_state_evt(compl->flags))
227 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000228 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700229 else if (is_grp5_evt(compl->flags))
230 be_async_grp5_evt_process(adapter,
231 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700232 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800233 *status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000234 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000235 }
236 be_mcc_compl_use(compl);
237 num++;
238 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700239
Sathya Perla8788fdc2009-07-27 22:52:03 +0000240 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800241 return num;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000242}
243
Sathya Perla6ac7b682009-06-18 00:05:54 +0000244/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700245static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000246{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700247#define mcc_timeout 120000 /* 12s timeout */
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800248 int i, num, status = 0;
249 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700250
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000251 if (adapter->eeh_err)
252 return -EIO;
253
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800254 for (i = 0; i < mcc_timeout; i++) {
255 num = be_process_mcc(adapter, &status);
256 if (num)
257 be_cq_notify(adapter, mcc_obj->cq.id,
258 mcc_obj->rearm_cq, num);
259
260 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000261 break;
262 udelay(100);
263 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700264 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000265 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700266 return -1;
267 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800268 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000269}
270
271/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700272static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000273{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000274 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700275 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000276}
277
Sathya Perla5f0b8492009-07-27 22:52:56 +0000278static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700279{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000280 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700281 u32 ready;
282
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000283 if (adapter->eeh_err) {
284 dev_err(&adapter->pdev->dev,
285 "Error detected in card.Cannot issue commands\n");
286 return -EIO;
287 }
288
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700289 do {
Sathya Perlacf588472010-02-14 21:22:01 +0000290 ready = ioread32(db);
291 if (ready == 0xffffffff) {
292 dev_err(&adapter->pdev->dev,
293 "pci slot disconnected\n");
294 return -1;
295 }
296
297 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700298 if (ready)
299 break;
300
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000301 if (msecs > 4000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000302 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Padmanabh Ratnakar18a91e62011-05-10 05:13:01 +0000303 if (!lancer_chip(adapter))
304 be_detect_dump_ue(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700305 return -1;
306 }
307
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000308 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000309 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700310 } while (true);
311
312 return 0;
313}
314
315/*
316 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000317 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700318 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700319static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700320{
321 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700322 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000323 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
324 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700325 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000326 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700327
Sathya Perlacf588472010-02-14 21:22:01 +0000328 /* wait for ready to be set */
329 status = be_mbox_db_ready_wait(adapter, db);
330 if (status != 0)
331 return status;
332
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700333 val |= MPU_MAILBOX_DB_HI_MASK;
334 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
335 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
336 iowrite32(val, db);
337
338 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000339 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700340 if (status != 0)
341 return status;
342
343 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700344 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
345 val |= (u32)(mbox_mem->dma >> 4) << 2;
346 iowrite32(val, db);
347
Sathya Perla5f0b8492009-07-27 22:52:56 +0000348 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700349 if (status != 0)
350 return status;
351
Sathya Perla5fb379e2009-06-18 00:02:59 +0000352 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000353 if (be_mcc_compl_is_new(compl)) {
354 status = be_mcc_compl_process(adapter, &mbox->compl);
355 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000356 if (status)
357 return status;
358 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000359 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700360 return -1;
361 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000362 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700363}
364
Sathya Perla8788fdc2009-07-27 22:52:03 +0000365static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700366{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000367 u32 sem;
368
369 if (lancer_chip(adapter))
370 sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
371 else
372 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700373
374 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
375 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
376 return -1;
377 else
378 return 0;
379}
380
Sathya Perla8788fdc2009-07-27 22:52:03 +0000381int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700382{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000383 u16 stage;
384 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000385 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700386
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000387 do {
388 status = be_POST_stage_get(adapter, &stage);
389 if (status) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000390 dev_err(dev, "POST error; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000391 return -1;
392 } else if (stage != POST_STAGE_ARMFW_RDY) {
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000393 if (msleep_interruptible(2000)) {
394 dev_err(dev, "Waiting for POST aborted\n");
395 return -EINTR;
396 }
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000397 timeout += 2;
398 } else {
399 return 0;
400 }
Sathya Perlad938a702010-05-26 00:33:43 -0700401 } while (timeout < 40);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700402
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000403 dev_err(dev, "POST timeout; stage=0x%x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000404 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700405}
406
407static inline void *embedded_payload(struct be_mcc_wrb *wrb)
408{
409 return wrb->payload.embedded_payload;
410}
411
412static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
413{
414 return &wrb->payload.sgl[0];
415}
416
417/* Don't touch the hdr after it's prepared */
418static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
Ajit Khaparded744b442009-12-03 06:12:06 +0000419 bool embedded, u8 sge_cnt, u32 opcode)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700420{
421 if (embedded)
422 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
423 else
424 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
425 MCC_WRB_SGE_CNT_SHIFT;
426 wrb->payload_length = payload_len;
Ajit Khaparded744b442009-12-03 06:12:06 +0000427 wrb->tag0 = opcode;
Sathya Perlafa4281b2010-01-21 22:51:36 +0000428 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700429}
430
431/* Don't touch the hdr after it's prepared */
432static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
433 u8 subsystem, u8 opcode, int cmd_len)
434{
435 req_hdr->opcode = opcode;
436 req_hdr->subsystem = subsystem;
437 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000438 req_hdr->version = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700439}
440
441static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
442 struct be_dma_mem *mem)
443{
444 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
445 u64 dma = (u64)mem->dma;
446
447 for (i = 0; i < buf_pages; i++) {
448 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
449 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
450 dma += PAGE_SIZE_4K;
451 }
452}
453
454/* Converts interrupt delay in microseconds to multiplier value */
455static u32 eq_delay_to_mult(u32 usec_delay)
456{
457#define MAX_INTR_RATE 651042
458 const u32 round = 10;
459 u32 multiplier;
460
461 if (usec_delay == 0)
462 multiplier = 0;
463 else {
464 u32 interrupt_rate = 1000000 / usec_delay;
465 /* Max delay, corresponding to the lowest interrupt rate */
466 if (interrupt_rate == 0)
467 multiplier = 1023;
468 else {
469 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
470 multiplier /= interrupt_rate;
471 /* Round the multiplier to the closest value.*/
472 multiplier = (multiplier + round/2) / round;
473 multiplier = min(multiplier, (u32)1023);
474 }
475 }
476 return multiplier;
477}
478
Sathya Perlab31c50a2009-09-17 10:30:13 -0700479static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700480{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700481 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
482 struct be_mcc_wrb *wrb
483 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
484 memset(wrb, 0, sizeof(*wrb));
485 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700486}
487
Sathya Perlab31c50a2009-09-17 10:30:13 -0700488static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000489{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700490 struct be_queue_info *mccq = &adapter->mcc_obj.q;
491 struct be_mcc_wrb *wrb;
492
Sathya Perla713d03942009-11-22 22:02:45 +0000493 if (atomic_read(&mccq->used) >= mccq->len) {
494 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
495 return NULL;
496 }
497
Sathya Perlab31c50a2009-09-17 10:30:13 -0700498 wrb = queue_head_node(mccq);
499 queue_head_inc(mccq);
500 atomic_inc(&mccq->used);
501 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000502 return wrb;
503}
504
Sathya Perla2243e2e2009-11-22 22:02:03 +0000505/* Tell fw we're about to start firing cmds by writing a
506 * special pattern across the wrb hdr; uses mbox
507 */
508int be_cmd_fw_init(struct be_adapter *adapter)
509{
510 u8 *wrb;
511 int status;
512
Ivan Vecera29849612010-12-14 05:43:19 +0000513 if (mutex_lock_interruptible(&adapter->mbox_lock))
514 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000515
516 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000517 *wrb++ = 0xFF;
518 *wrb++ = 0x12;
519 *wrb++ = 0x34;
520 *wrb++ = 0xFF;
521 *wrb++ = 0xFF;
522 *wrb++ = 0x56;
523 *wrb++ = 0x78;
524 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000525
526 status = be_mbox_notify_wait(adapter);
527
Ivan Vecera29849612010-12-14 05:43:19 +0000528 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000529 return status;
530}
531
532/* Tell fw we're done with firing cmds by writing a
533 * special pattern across the wrb hdr; uses mbox
534 */
535int be_cmd_fw_clean(struct be_adapter *adapter)
536{
537 u8 *wrb;
538 int status;
539
Sathya Perlacf588472010-02-14 21:22:01 +0000540 if (adapter->eeh_err)
541 return -EIO;
542
Ivan Vecera29849612010-12-14 05:43:19 +0000543 if (mutex_lock_interruptible(&adapter->mbox_lock))
544 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000545
546 wrb = (u8 *)wrb_from_mbox(adapter);
547 *wrb++ = 0xFF;
548 *wrb++ = 0xAA;
549 *wrb++ = 0xBB;
550 *wrb++ = 0xFF;
551 *wrb++ = 0xFF;
552 *wrb++ = 0xCC;
553 *wrb++ = 0xDD;
554 *wrb = 0xFF;
555
556 status = be_mbox_notify_wait(adapter);
557
Ivan Vecera29849612010-12-14 05:43:19 +0000558 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000559 return status;
560}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000561int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700562 struct be_queue_info *eq, int eq_delay)
563{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700564 struct be_mcc_wrb *wrb;
565 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700566 struct be_dma_mem *q_mem = &eq->dma_mem;
567 int status;
568
Ivan Vecera29849612010-12-14 05:43:19 +0000569 if (mutex_lock_interruptible(&adapter->mbox_lock))
570 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700571
572 wrb = wrb_from_mbox(adapter);
573 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700574
Ajit Khaparded744b442009-12-03 06:12:06 +0000575 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700576
577 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
578 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
579
580 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
581
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700582 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
583 /* 4byte eqe*/
584 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
585 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
586 __ilog2_u32(eq->len/256));
587 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
588 eq_delay_to_mult(eq_delay));
589 be_dws_cpu_to_le(req->context, sizeof(req->context));
590
591 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
592
Sathya Perlab31c50a2009-09-17 10:30:13 -0700593 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700594 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700595 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700596 eq->id = le16_to_cpu(resp->eq_id);
597 eq->created = true;
598 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700599
Ivan Vecera29849612010-12-14 05:43:19 +0000600 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700601 return status;
602}
603
Sathya Perlab31c50a2009-09-17 10:30:13 -0700604/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000605int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700606 u8 type, bool permanent, u32 if_handle)
607{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700608 struct be_mcc_wrb *wrb;
609 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700610 int status;
611
Ivan Vecera29849612010-12-14 05:43:19 +0000612 if (mutex_lock_interruptible(&adapter->mbox_lock))
613 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700614
615 wrb = wrb_from_mbox(adapter);
616 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700617
Ajit Khaparded744b442009-12-03 06:12:06 +0000618 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
619 OPCODE_COMMON_NTWK_MAC_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700620
621 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
622 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
623
624 req->type = type;
625 if (permanent) {
626 req->permanent = 1;
627 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700628 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700629 req->permanent = 0;
630 }
631
Sathya Perlab31c50a2009-09-17 10:30:13 -0700632 status = be_mbox_notify_wait(adapter);
633 if (!status) {
634 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700635 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700636 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700637
Ivan Vecera29849612010-12-14 05:43:19 +0000638 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700639 return status;
640}
641
Sathya Perlab31c50a2009-09-17 10:30:13 -0700642/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000643int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000644 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700645{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700646 struct be_mcc_wrb *wrb;
647 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700648 int status;
649
Sathya Perlab31c50a2009-09-17 10:30:13 -0700650 spin_lock_bh(&adapter->mcc_lock);
651
652 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000653 if (!wrb) {
654 status = -EBUSY;
655 goto err;
656 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700657 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700658
Ajit Khaparded744b442009-12-03 06:12:06 +0000659 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
660 OPCODE_COMMON_NTWK_PMAC_ADD);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700661
662 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
663 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
664
Ajit Khapardef8617e02011-02-11 13:36:37 +0000665 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700666 req->if_id = cpu_to_le32(if_id);
667 memcpy(req->mac_address, mac_addr, ETH_ALEN);
668
Sathya Perlab31c50a2009-09-17 10:30:13 -0700669 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700670 if (!status) {
671 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
672 *pmac_id = le32_to_cpu(resp->pmac_id);
673 }
674
Sathya Perla713d03942009-11-22 22:02:45 +0000675err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700676 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677 return status;
678}
679
Sathya Perlab31c50a2009-09-17 10:30:13 -0700680/* Uses synchronous MCCQ */
Ajit Khapardef8617e02011-02-11 13:36:37 +0000681int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700682{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700683 struct be_mcc_wrb *wrb;
684 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700685 int status;
686
Sathya Perlab31c50a2009-09-17 10:30:13 -0700687 spin_lock_bh(&adapter->mcc_lock);
688
689 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000690 if (!wrb) {
691 status = -EBUSY;
692 goto err;
693 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700694 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700695
Ajit Khaparded744b442009-12-03 06:12:06 +0000696 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
697 OPCODE_COMMON_NTWK_PMAC_DEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700698
699 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
700 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
701
Ajit Khapardef8617e02011-02-11 13:36:37 +0000702 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700703 req->if_id = cpu_to_le32(if_id);
704 req->pmac_id = cpu_to_le32(pmac_id);
705
Sathya Perlab31c50a2009-09-17 10:30:13 -0700706 status = be_mcc_notify_wait(adapter);
707
Sathya Perla713d03942009-11-22 22:02:45 +0000708err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700709 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700710 return status;
711}
712
Sathya Perlab31c50a2009-09-17 10:30:13 -0700713/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000714int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700715 struct be_queue_info *cq, struct be_queue_info *eq,
716 bool sol_evts, bool no_delay, int coalesce_wm)
717{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700718 struct be_mcc_wrb *wrb;
719 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700720 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700721 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700722 int status;
723
Ivan Vecera29849612010-12-14 05:43:19 +0000724 if (mutex_lock_interruptible(&adapter->mbox_lock))
725 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700726
727 wrb = wrb_from_mbox(adapter);
728 req = embedded_payload(wrb);
729 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700730
Ajit Khaparded744b442009-12-03 06:12:06 +0000731 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
732 OPCODE_COMMON_CQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700733
734 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
735 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
736
737 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000738 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000739 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000740 req->page_size = 1; /* 1 for 4K */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000741 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
742 no_delay);
743 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
744 __ilog2_u32(cq->len/256));
745 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
746 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
747 ctxt, 1);
748 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
749 ctxt, eq->id);
750 AMAP_SET_BITS(struct amap_cq_context_lancer, armed, ctxt, 1);
751 } else {
752 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
753 coalesce_wm);
754 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
755 ctxt, no_delay);
756 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
757 __ilog2_u32(cq->len/256));
758 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
759 AMAP_SET_BITS(struct amap_cq_context_be, solevent,
760 ctxt, sol_evts);
761 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
762 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
763 AMAP_SET_BITS(struct amap_cq_context_be, armed, ctxt, 1);
764 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700765
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700766 be_dws_cpu_to_le(ctxt, sizeof(req->context));
767
768 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
769
Sathya Perlab31c50a2009-09-17 10:30:13 -0700770 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700771 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700772 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700773 cq->id = le16_to_cpu(resp->cq_id);
774 cq->created = true;
775 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700776
Ivan Vecera29849612010-12-14 05:43:19 +0000777 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000778
779 return status;
780}
781
782static u32 be_encoded_q_len(int q_len)
783{
784 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
785 if (len_encoded == 16)
786 len_encoded = 0;
787 return len_encoded;
788}
789
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000790int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000791 struct be_queue_info *mccq,
792 struct be_queue_info *cq)
793{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700794 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000795 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000796 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700797 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000798 int status;
799
Ivan Vecera29849612010-12-14 05:43:19 +0000800 if (mutex_lock_interruptible(&adapter->mbox_lock))
801 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700802
803 wrb = wrb_from_mbox(adapter);
804 req = embedded_payload(wrb);
805 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000806
Ajit Khaparded744b442009-12-03 06:12:06 +0000807 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700808 OPCODE_COMMON_MCC_CREATE_EXT);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000809
810 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700811 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000812
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000813 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000814 if (lancer_chip(adapter)) {
815 req->hdr.version = 1;
816 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000817
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000818 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
819 be_encoded_q_len(mccq->len));
820 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
821 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
822 ctxt, cq->id);
823 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
824 ctxt, 1);
825
826 } else {
827 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
828 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
829 be_encoded_q_len(mccq->len));
830 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
831 }
832
Somnath Koturcc4ce022010-10-21 07:11:14 -0700833 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000834 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000835 be_dws_cpu_to_le(ctxt, sizeof(req->context));
836
837 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
838
Sathya Perlab31c50a2009-09-17 10:30:13 -0700839 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000840 if (!status) {
841 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
842 mccq->id = le16_to_cpu(resp->id);
843 mccq->created = true;
844 }
Ivan Vecera29849612010-12-14 05:43:19 +0000845 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700846
847 return status;
848}
849
Somnath Kotur34b1ef02011-06-01 00:33:22 +0000850int be_cmd_mccq_org_create(struct be_adapter *adapter,
851 struct be_queue_info *mccq,
852 struct be_queue_info *cq)
853{
854 struct be_mcc_wrb *wrb;
855 struct be_cmd_req_mcc_create *req;
856 struct be_dma_mem *q_mem = &mccq->dma_mem;
857 void *ctxt;
858 int status;
859
860 if (mutex_lock_interruptible(&adapter->mbox_lock))
861 return -1;
862
863 wrb = wrb_from_mbox(adapter);
864 req = embedded_payload(wrb);
865 ctxt = &req->context;
866
867 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
868 OPCODE_COMMON_MCC_CREATE);
869
870 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
871 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
872
873 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
874
875 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
876 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
877 be_encoded_q_len(mccq->len));
878 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
879
880 be_dws_cpu_to_le(ctxt, sizeof(req->context));
881
882 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
883
884 status = be_mbox_notify_wait(adapter);
885 if (!status) {
886 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
887 mccq->id = le16_to_cpu(resp->id);
888 mccq->created = true;
889 }
890
891 mutex_unlock(&adapter->mbox_lock);
892 return status;
893}
894
895int be_cmd_mccq_create(struct be_adapter *adapter,
896 struct be_queue_info *mccq,
897 struct be_queue_info *cq)
898{
899 int status;
900
901 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
902 if (status && !lancer_chip(adapter)) {
903 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
904 "or newer to avoid conflicting priorities between NIC "
905 "and FCoE traffic");
906 status = be_cmd_mccq_org_create(adapter, mccq, cq);
907 }
908 return status;
909}
910
Sathya Perla8788fdc2009-07-27 22:52:03 +0000911int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700912 struct be_queue_info *txq,
913 struct be_queue_info *cq)
914{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700915 struct be_mcc_wrb *wrb;
916 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700917 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700918 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700919 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700920
Ivan Vecera29849612010-12-14 05:43:19 +0000921 if (mutex_lock_interruptible(&adapter->mbox_lock))
922 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700923
924 wrb = wrb_from_mbox(adapter);
925 req = embedded_payload(wrb);
926 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700927
Ajit Khaparded744b442009-12-03 06:12:06 +0000928 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
929 OPCODE_ETH_TX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700930
931 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
932 sizeof(*req));
933
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000934 if (lancer_chip(adapter)) {
935 req->hdr.version = 1;
936 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
937 adapter->if_handle);
938 }
939
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700940 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
941 req->ulp_num = BE_ULP1_NUM;
942 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
943
Sathya Perlab31c50a2009-09-17 10:30:13 -0700944 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
945 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700946 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
947 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
948
949 be_dws_cpu_to_le(ctxt, sizeof(req->context));
950
951 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
952
Sathya Perlab31c50a2009-09-17 10:30:13 -0700953 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700954 if (!status) {
955 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
956 txq->id = le16_to_cpu(resp->cid);
957 txq->created = true;
958 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700959
Ivan Vecera29849612010-12-14 05:43:19 +0000960 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700961
962 return status;
963}
964
Sathya Perla482c9e72011-06-29 23:33:17 +0000965/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000966int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700967 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla3abcded2010-10-03 22:12:27 -0700968 u16 max_frame_size, u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700969{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700970 struct be_mcc_wrb *wrb;
971 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700972 struct be_dma_mem *q_mem = &rxq->dma_mem;
973 int status;
974
Sathya Perla482c9e72011-06-29 23:33:17 +0000975 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700976
Sathya Perla482c9e72011-06-29 23:33:17 +0000977 wrb = wrb_from_mccq(adapter);
978 if (!wrb) {
979 status = -EBUSY;
980 goto err;
981 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700982 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700983
Ajit Khaparded744b442009-12-03 06:12:06 +0000984 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
985 OPCODE_ETH_RX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700986
987 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
988 sizeof(*req));
989
990 req->cq_id = cpu_to_le16(cq_id);
991 req->frag_size = fls(frag_size) - 1;
992 req->num_pages = 2;
993 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
994 req->interface_id = cpu_to_le32(if_id);
995 req->max_frame_size = cpu_to_le16(max_frame_size);
996 req->rss_queue = cpu_to_le32(rss);
997
Sathya Perla482c9e72011-06-29 23:33:17 +0000998 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700999 if (!status) {
1000 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
1001 rxq->id = le16_to_cpu(resp->id);
1002 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001003 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001004 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001005
Sathya Perla482c9e72011-06-29 23:33:17 +00001006err:
1007 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001008 return status;
1009}
1010
Sathya Perlab31c50a2009-09-17 10:30:13 -07001011/* Generic destroyer function for all types of queues
1012 * Uses Mbox
1013 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001014int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001015 int queue_type)
1016{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001017 struct be_mcc_wrb *wrb;
1018 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001019 u8 subsys = 0, opcode = 0;
1020 int status;
1021
Sathya Perlacf588472010-02-14 21:22:01 +00001022 if (adapter->eeh_err)
1023 return -EIO;
1024
Ivan Vecera29849612010-12-14 05:43:19 +00001025 if (mutex_lock_interruptible(&adapter->mbox_lock))
1026 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027
Sathya Perlab31c50a2009-09-17 10:30:13 -07001028 wrb = wrb_from_mbox(adapter);
1029 req = embedded_payload(wrb);
1030
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001031 switch (queue_type) {
1032 case QTYPE_EQ:
1033 subsys = CMD_SUBSYSTEM_COMMON;
1034 opcode = OPCODE_COMMON_EQ_DESTROY;
1035 break;
1036 case QTYPE_CQ:
1037 subsys = CMD_SUBSYSTEM_COMMON;
1038 opcode = OPCODE_COMMON_CQ_DESTROY;
1039 break;
1040 case QTYPE_TXQ:
1041 subsys = CMD_SUBSYSTEM_ETH;
1042 opcode = OPCODE_ETH_TX_DESTROY;
1043 break;
1044 case QTYPE_RXQ:
1045 subsys = CMD_SUBSYSTEM_ETH;
1046 opcode = OPCODE_ETH_RX_DESTROY;
1047 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001048 case QTYPE_MCCQ:
1049 subsys = CMD_SUBSYSTEM_COMMON;
1050 opcode = OPCODE_COMMON_MCC_DESTROY;
1051 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001052 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001053 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001054 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001055
1056 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
1057
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001058 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
1059 req->id = cpu_to_le16(q->id);
1060
Sathya Perlab31c50a2009-09-17 10:30:13 -07001061 status = be_mbox_notify_wait(adapter);
Sathya Perla482c9e72011-06-29 23:33:17 +00001062 if (!status)
1063 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001064
Ivan Vecera29849612010-12-14 05:43:19 +00001065 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001066 return status;
1067}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001068
Sathya Perla482c9e72011-06-29 23:33:17 +00001069/* Uses MCC */
1070int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1071{
1072 struct be_mcc_wrb *wrb;
1073 struct be_cmd_req_q_destroy *req;
1074 int status;
1075
1076 spin_lock_bh(&adapter->mcc_lock);
1077
1078 wrb = wrb_from_mccq(adapter);
1079 if (!wrb) {
1080 status = -EBUSY;
1081 goto err;
1082 }
1083 req = embedded_payload(wrb);
1084
1085 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_RX_DESTROY);
1086 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_DESTROY,
1087 sizeof(*req));
1088 req->id = cpu_to_le16(q->id);
1089
1090 status = be_mcc_notify_wait(adapter);
1091 if (!status)
1092 q->created = false;
1093
1094err:
1095 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001096 return status;
1097}
1098
Sathya Perlab31c50a2009-09-17 10:30:13 -07001099/* Create an rx filtering policy configuration on an i/f
1100 * Uses mbox
1101 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001102int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001103 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id,
1104 u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001105{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001106 struct be_mcc_wrb *wrb;
1107 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001108 int status;
1109
Ivan Vecera29849612010-12-14 05:43:19 +00001110 if (mutex_lock_interruptible(&adapter->mbox_lock))
1111 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001112
1113 wrb = wrb_from_mbox(adapter);
1114 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001115
Ajit Khaparded744b442009-12-03 06:12:06 +00001116 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1117 OPCODE_COMMON_NTWK_INTERFACE_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001118
1119 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1120 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
1121
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001122 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001123 req->capability_flags = cpu_to_le32(cap_flags);
1124 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001125 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001126 if (!pmac_invalid)
1127 memcpy(req->mac_addr, mac, ETH_ALEN);
1128
Sathya Perlab31c50a2009-09-17 10:30:13 -07001129 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001130 if (!status) {
1131 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1132 *if_handle = le32_to_cpu(resp->interface_id);
1133 if (!pmac_invalid)
1134 *pmac_id = le32_to_cpu(resp->pmac_id);
1135 }
1136
Ivan Vecera29849612010-12-14 05:43:19 +00001137 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001138 return status;
1139}
1140
Sathya Perlab31c50a2009-09-17 10:30:13 -07001141/* Uses mbox */
Ajit Khaparde658681f2011-02-11 13:34:46 +00001142int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001143{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001144 struct be_mcc_wrb *wrb;
1145 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001146 int status;
1147
Sathya Perlacf588472010-02-14 21:22:01 +00001148 if (adapter->eeh_err)
1149 return -EIO;
1150
Ivan Vecera29849612010-12-14 05:43:19 +00001151 if (mutex_lock_interruptible(&adapter->mbox_lock))
1152 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001153
1154 wrb = wrb_from_mbox(adapter);
1155 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001156
Ajit Khaparded744b442009-12-03 06:12:06 +00001157 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1158 OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001159
1160 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1161 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
1162
Ajit Khaparde658681f2011-02-11 13:34:46 +00001163 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001164 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001165
1166 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001167
Ivan Vecera29849612010-12-14 05:43:19 +00001168 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001169
1170 return status;
1171}
1172
1173/* Get stats is a non embedded command: the request is not embedded inside
1174 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001175 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001176 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001177int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001178{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001179 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001180 struct be_cmd_req_hdr *hdr;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001181 struct be_sge *sge;
Sathya Perla713d03942009-11-22 22:02:45 +00001182 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001183
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001184 if (MODULO(adapter->work_counter, be_get_temp_freq) == 0)
1185 be_cmd_get_die_temperature(adapter);
1186
Sathya Perlab31c50a2009-09-17 10:30:13 -07001187 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001188
Sathya Perlab31c50a2009-09-17 10:30:13 -07001189 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001190 if (!wrb) {
1191 status = -EBUSY;
1192 goto err;
1193 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001194 hdr = nonemb_cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001195 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001196
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001197 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1,
Ajit Khaparded744b442009-12-03 06:12:06 +00001198 OPCODE_ETH_GET_STATISTICS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001199
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001200 be_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
1201 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size);
1202
1203 if (adapter->generation == BE_GEN3)
1204 hdr->version = 1;
1205
Ajit Khaparde63499352011-04-19 12:11:02 +00001206 wrb->tag1 = CMD_SUBSYSTEM_ETH;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001207 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1208 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1209 sge->len = cpu_to_le32(nonemb_cmd->size);
1210
Sathya Perlab31c50a2009-09-17 10:30:13 -07001211 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001212 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001213
Sathya Perla713d03942009-11-22 22:02:45 +00001214err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001215 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001216 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001217}
1218
Selvin Xavier005d5692011-05-16 07:36:35 +00001219/* Lancer Stats */
1220int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
1221 struct be_dma_mem *nonemb_cmd)
1222{
1223
1224 struct be_mcc_wrb *wrb;
1225 struct lancer_cmd_req_pport_stats *req;
1226 struct be_sge *sge;
1227 int status = 0;
1228
1229 spin_lock_bh(&adapter->mcc_lock);
1230
1231 wrb = wrb_from_mccq(adapter);
1232 if (!wrb) {
1233 status = -EBUSY;
1234 goto err;
1235 }
1236 req = nonemb_cmd->va;
1237 sge = nonembedded_sgl(wrb);
1238
1239 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1,
1240 OPCODE_ETH_GET_PPORT_STATS);
1241
1242 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1243 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size);
1244
1245
1246 req->cmd_params.params.pport_num = cpu_to_le16(adapter->port_num);
1247 req->cmd_params.params.reset_stats = 0;
1248
1249 wrb->tag1 = CMD_SUBSYSTEM_ETH;
1250 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1251 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1252 sge->len = cpu_to_le32(nonemb_cmd->size);
1253
1254 be_mcc_notify(adapter);
1255 adapter->stats_cmd_sent = true;
1256
1257err:
1258 spin_unlock_bh(&adapter->mcc_lock);
1259 return status;
1260}
1261
Sathya Perlab31c50a2009-09-17 10:30:13 -07001262/* Uses synchronous mcc */
Sathya Perlaea172a02011-08-02 19:57:42 +00001263int be_cmd_link_status_query(struct be_adapter *adapter, u8 *mac_speed,
1264 u16 *link_speed, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001265{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001266 struct be_mcc_wrb *wrb;
1267 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001268 int status;
1269
Sathya Perlab31c50a2009-09-17 10:30:13 -07001270 spin_lock_bh(&adapter->mcc_lock);
1271
1272 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001273 if (!wrb) {
1274 status = -EBUSY;
1275 goto err;
1276 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001277 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001278
Ajit Khaparded744b442009-12-03 06:12:06 +00001279 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1280 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001281
1282 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1283 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
1284
Sathya Perlab31c50a2009-09-17 10:30:13 -07001285 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001286 if (!status) {
1287 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001288 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001289 *link_speed = le16_to_cpu(resp->link_speed);
1290 *mac_speed = resp->mac_speed;
1291 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001292 }
1293
Sathya Perla713d03942009-11-22 22:02:45 +00001294err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001295 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001296 return status;
1297}
1298
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001299/* Uses synchronous mcc */
1300int be_cmd_get_die_temperature(struct be_adapter *adapter)
1301{
1302 struct be_mcc_wrb *wrb;
1303 struct be_cmd_req_get_cntl_addnl_attribs *req;
1304 int status;
1305
1306 spin_lock_bh(&adapter->mcc_lock);
1307
1308 wrb = wrb_from_mccq(adapter);
1309 if (!wrb) {
1310 status = -EBUSY;
1311 goto err;
1312 }
1313 req = embedded_payload(wrb);
1314
1315 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1316 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES);
1317
1318 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1319 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req));
1320
1321 status = be_mcc_notify_wait(adapter);
1322 if (!status) {
1323 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
1324 embedded_payload(wrb);
1325 adapter->drv_stats.be_on_die_temperature =
1326 resp->on_die_temperature;
1327 }
1328 /* If IOCTL fails once, do not bother issuing it again */
1329 else
1330 be_get_temp_freq = 0;
1331
1332err:
1333 spin_unlock_bh(&adapter->mcc_lock);
1334 return status;
1335}
1336
Somnath Kotur311fddc2011-03-16 21:22:43 +00001337/* Uses synchronous mcc */
1338int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1339{
1340 struct be_mcc_wrb *wrb;
1341 struct be_cmd_req_get_fat *req;
1342 int status;
1343
1344 spin_lock_bh(&adapter->mcc_lock);
1345
1346 wrb = wrb_from_mccq(adapter);
1347 if (!wrb) {
1348 status = -EBUSY;
1349 goto err;
1350 }
1351 req = embedded_payload(wrb);
1352
1353 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1354 OPCODE_COMMON_MANAGE_FAT);
1355
1356 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1357 OPCODE_COMMON_MANAGE_FAT, sizeof(*req));
1358 req->fat_operation = cpu_to_le32(QUERY_FAT);
1359 status = be_mcc_notify_wait(adapter);
1360 if (!status) {
1361 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1362 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001363 *log_size = le32_to_cpu(resp->log_size) -
1364 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001365 }
1366err:
1367 spin_unlock_bh(&adapter->mcc_lock);
1368 return status;
1369}
1370
1371void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1372{
1373 struct be_dma_mem get_fat_cmd;
1374 struct be_mcc_wrb *wrb;
1375 struct be_cmd_req_get_fat *req;
1376 struct be_sge *sge;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001377 u32 offset = 0, total_size, buf_size,
1378 log_offset = sizeof(u32), payload_len;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001379 int status;
1380
1381 if (buf_len == 0)
1382 return;
1383
1384 total_size = buf_len;
1385
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001386 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1387 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1388 get_fat_cmd.size,
1389 &get_fat_cmd.dma);
1390 if (!get_fat_cmd.va) {
1391 status = -ENOMEM;
1392 dev_err(&adapter->pdev->dev,
1393 "Memory allocation failure while retrieving FAT data\n");
1394 return;
1395 }
1396
Somnath Kotur311fddc2011-03-16 21:22:43 +00001397 spin_lock_bh(&adapter->mcc_lock);
1398
Somnath Kotur311fddc2011-03-16 21:22:43 +00001399 while (total_size) {
1400 buf_size = min(total_size, (u32)60*1024);
1401 total_size -= buf_size;
1402
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001403 wrb = wrb_from_mccq(adapter);
1404 if (!wrb) {
1405 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001406 goto err;
1407 }
1408 req = get_fat_cmd.va;
1409 sge = nonembedded_sgl(wrb);
1410
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001411 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
1412 be_wrb_hdr_prepare(wrb, payload_len, false, 1,
Somnath Kotur311fddc2011-03-16 21:22:43 +00001413 OPCODE_COMMON_MANAGE_FAT);
1414
1415 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001416 OPCODE_COMMON_MANAGE_FAT, payload_len);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001417
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001418 sge->pa_hi = cpu_to_le32(upper_32_bits(get_fat_cmd.dma));
Somnath Kotur311fddc2011-03-16 21:22:43 +00001419 sge->pa_lo = cpu_to_le32(get_fat_cmd.dma & 0xFFFFFFFF);
1420 sge->len = cpu_to_le32(get_fat_cmd.size);
1421
1422 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1423 req->read_log_offset = cpu_to_le32(log_offset);
1424 req->read_log_length = cpu_to_le32(buf_size);
1425 req->data_buffer_size = cpu_to_le32(buf_size);
1426
1427 status = be_mcc_notify_wait(adapter);
1428 if (!status) {
1429 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1430 memcpy(buf + offset,
1431 resp->data_buffer,
1432 resp->read_log_length);
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001433 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001434 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001435 goto err;
1436 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001437 offset += buf_size;
1438 log_offset += buf_size;
1439 }
1440err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001441 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1442 get_fat_cmd.va,
1443 get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001444 spin_unlock_bh(&adapter->mcc_lock);
1445}
1446
Sathya Perlab31c50a2009-09-17 10:30:13 -07001447/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001448int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001449{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001450 struct be_mcc_wrb *wrb;
1451 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001452 int status;
1453
Ivan Vecera29849612010-12-14 05:43:19 +00001454 if (mutex_lock_interruptible(&adapter->mbox_lock))
1455 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001456
1457 wrb = wrb_from_mbox(adapter);
1458 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001459
Ajit Khaparded744b442009-12-03 06:12:06 +00001460 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1461 OPCODE_COMMON_GET_FW_VERSION);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001462
1463 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1464 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
1465
Sathya Perlab31c50a2009-09-17 10:30:13 -07001466 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001467 if (!status) {
1468 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1469 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
1470 }
1471
Ivan Vecera29849612010-12-14 05:43:19 +00001472 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001473 return status;
1474}
1475
Sathya Perlab31c50a2009-09-17 10:30:13 -07001476/* set the EQ delay interval of an EQ to specified value
1477 * Uses async mcc
1478 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001479int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001480{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001481 struct be_mcc_wrb *wrb;
1482 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001483 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001484
Sathya Perlab31c50a2009-09-17 10:30:13 -07001485 spin_lock_bh(&adapter->mcc_lock);
1486
1487 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001488 if (!wrb) {
1489 status = -EBUSY;
1490 goto err;
1491 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001492 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001493
Ajit Khaparded744b442009-12-03 06:12:06 +00001494 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1495 OPCODE_COMMON_MODIFY_EQ_DELAY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001496
1497 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1498 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
1499
1500 req->num_eq = cpu_to_le32(1);
1501 req->delay[0].eq_id = cpu_to_le32(eq_id);
1502 req->delay[0].phase = 0;
1503 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1504
Sathya Perlab31c50a2009-09-17 10:30:13 -07001505 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001506
Sathya Perla713d03942009-11-22 22:02:45 +00001507err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001508 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001509 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001510}
1511
Sathya Perlab31c50a2009-09-17 10:30:13 -07001512/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001513int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001514 u32 num, bool untagged, bool promiscuous)
1515{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001516 struct be_mcc_wrb *wrb;
1517 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001518 int status;
1519
Sathya Perlab31c50a2009-09-17 10:30:13 -07001520 spin_lock_bh(&adapter->mcc_lock);
1521
1522 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001523 if (!wrb) {
1524 status = -EBUSY;
1525 goto err;
1526 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001527 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001528
Ajit Khaparded744b442009-12-03 06:12:06 +00001529 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1530 OPCODE_COMMON_NTWK_VLAN_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001531
1532 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1533 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
1534
1535 req->interface_id = if_id;
1536 req->promiscuous = promiscuous;
1537 req->untagged = untagged;
1538 req->num_vlan = num;
1539 if (!promiscuous) {
1540 memcpy(req->normal_vlan, vtag_array,
1541 req->num_vlan * sizeof(vtag_array[0]));
1542 }
1543
Sathya Perlab31c50a2009-09-17 10:30:13 -07001544 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001545
Sathya Perla713d03942009-11-22 22:02:45 +00001546err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001547 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001548 return status;
1549}
1550
Sathya Perla5b8821b2011-08-02 19:57:44 +00001551int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001552{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001553 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001554 struct be_dma_mem *mem = &adapter->rx_filter;
1555 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001556 struct be_sge *sge;
1557 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001558
Sathya Perla8788fdc2009-07-27 22:52:03 +00001559 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001560
Sathya Perlab31c50a2009-09-17 10:30:13 -07001561 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001562 if (!wrb) {
1563 status = -EBUSY;
1564 goto err;
1565 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00001566 sge = nonembedded_sgl(wrb);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001567 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
1568 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
1569 sge->len = cpu_to_le32(mem->size);
Sathya Perla5b8821b2011-08-02 19:57:44 +00001570 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1571 OPCODE_COMMON_NTWK_RX_FILTER);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001572
Sathya Perla5b8821b2011-08-02 19:57:44 +00001573 memset(req, 0, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001574 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perla5b8821b2011-08-02 19:57:44 +00001575 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001576
Sathya Perla5b8821b2011-08-02 19:57:44 +00001577 req->if_id = cpu_to_le32(adapter->if_handle);
1578 if (flags & IFF_PROMISC) {
1579 req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1580 BE_IF_FLAGS_VLAN_PROMISCUOUS);
1581 if (value == ON)
1582 req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS |
1583 BE_IF_FLAGS_VLAN_PROMISCUOUS);
1584 } else if (flags & IFF_ALLMULTI) {
1585 req->if_flags_mask = req->if_flags =
1586 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS);
Sathya Perla24307ee2009-06-18 00:09:25 +00001587 } else {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001588 struct netdev_hw_addr *ha;
1589 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001590
Sathya Perla5b8821b2011-08-02 19:57:44 +00001591 req->mcast_num = cpu_to_le16(netdev_mc_count(adapter->netdev));
1592 netdev_for_each_mc_addr(ha, adapter->netdev)
1593 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1594 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001595
Sathya Perla713d03942009-11-22 22:02:45 +00001596err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001597 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001598 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001599}
1600
Sathya Perlab31c50a2009-09-17 10:30:13 -07001601/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001602int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001603{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001604 struct be_mcc_wrb *wrb;
1605 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001606 int status;
1607
Sathya Perlab31c50a2009-09-17 10:30:13 -07001608 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001609
Sathya Perlab31c50a2009-09-17 10:30:13 -07001610 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001611 if (!wrb) {
1612 status = -EBUSY;
1613 goto err;
1614 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001615 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001616
Ajit Khaparded744b442009-12-03 06:12:06 +00001617 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1618 OPCODE_COMMON_SET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001619
1620 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1621 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1622
1623 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1624 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1625
Sathya Perlab31c50a2009-09-17 10:30:13 -07001626 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001627
Sathya Perla713d03942009-11-22 22:02:45 +00001628err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001629 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001630 return status;
1631}
1632
Sathya Perlab31c50a2009-09-17 10:30:13 -07001633/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001634int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001635{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001636 struct be_mcc_wrb *wrb;
1637 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001638 int status;
1639
Sathya Perlab31c50a2009-09-17 10:30:13 -07001640 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001641
Sathya Perlab31c50a2009-09-17 10:30:13 -07001642 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001643 if (!wrb) {
1644 status = -EBUSY;
1645 goto err;
1646 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001647 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001648
Ajit Khaparded744b442009-12-03 06:12:06 +00001649 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1650 OPCODE_COMMON_GET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001651
1652 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1653 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1654
Sathya Perlab31c50a2009-09-17 10:30:13 -07001655 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001656 if (!status) {
1657 struct be_cmd_resp_get_flow_control *resp =
1658 embedded_payload(wrb);
1659 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1660 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1661 }
1662
Sathya Perla713d03942009-11-22 22:02:45 +00001663err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001664 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001665 return status;
1666}
1667
Sathya Perlab31c50a2009-09-17 10:30:13 -07001668/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001669int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1670 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001671{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001672 struct be_mcc_wrb *wrb;
1673 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001674 int status;
1675
Ivan Vecera29849612010-12-14 05:43:19 +00001676 if (mutex_lock_interruptible(&adapter->mbox_lock))
1677 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001678
Sathya Perlab31c50a2009-09-17 10:30:13 -07001679 wrb = wrb_from_mbox(adapter);
1680 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001681
Ajit Khaparded744b442009-12-03 06:12:06 +00001682 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1683 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001684
1685 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1686 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1687
Sathya Perlab31c50a2009-09-17 10:30:13 -07001688 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001689 if (!status) {
1690 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1691 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001692 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001693 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001694 }
1695
Ivan Vecera29849612010-12-14 05:43:19 +00001696 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001697 return status;
1698}
sarveshwarb14074ea2009-08-05 13:05:24 -07001699
Sathya Perlab31c50a2009-09-17 10:30:13 -07001700/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001701int be_cmd_reset_function(struct be_adapter *adapter)
1702{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001703 struct be_mcc_wrb *wrb;
1704 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001705 int status;
1706
Ivan Vecera29849612010-12-14 05:43:19 +00001707 if (mutex_lock_interruptible(&adapter->mbox_lock))
1708 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001709
Sathya Perlab31c50a2009-09-17 10:30:13 -07001710 wrb = wrb_from_mbox(adapter);
1711 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001712
Ajit Khaparded744b442009-12-03 06:12:06 +00001713 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1714 OPCODE_COMMON_FUNCTION_RESET);
sarveshwarb14074ea2009-08-05 13:05:24 -07001715
1716 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1717 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1718
Sathya Perlab31c50a2009-09-17 10:30:13 -07001719 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001720
Ivan Vecera29849612010-12-14 05:43:19 +00001721 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001722 return status;
1723}
Ajit Khaparde84517482009-09-04 03:12:16 +00001724
Sathya Perla3abcded2010-10-03 22:12:27 -07001725int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1726{
1727 struct be_mcc_wrb *wrb;
1728 struct be_cmd_req_rss_config *req;
Sathya Perla5d8bee62011-05-23 20:29:09 +00001729 u32 myhash[10] = {0x0123, 0x4567, 0x89AB, 0xCDEF, 0x01EF,
1730 0x0123, 0x4567, 0x89AB, 0xCDEF, 0x01EF};
Sathya Perla3abcded2010-10-03 22:12:27 -07001731 int status;
1732
Ivan Vecera29849612010-12-14 05:43:19 +00001733 if (mutex_lock_interruptible(&adapter->mbox_lock))
1734 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001735
1736 wrb = wrb_from_mbox(adapter);
1737 req = embedded_payload(wrb);
1738
1739 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1740 OPCODE_ETH_RSS_CONFIG);
1741
1742 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1743 OPCODE_ETH_RSS_CONFIG, sizeof(*req));
1744
1745 req->if_id = cpu_to_le32(adapter->if_handle);
1746 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4);
1747 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1748 memcpy(req->cpu_table, rsstable, table_size);
1749 memcpy(req->hash, myhash, sizeof(myhash));
1750 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1751
1752 status = be_mbox_notify_wait(adapter);
1753
Ivan Vecera29849612010-12-14 05:43:19 +00001754 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001755 return status;
1756}
1757
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001758/* Uses sync mcc */
1759int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1760 u8 bcn, u8 sts, u8 state)
1761{
1762 struct be_mcc_wrb *wrb;
1763 struct be_cmd_req_enable_disable_beacon *req;
1764 int status;
1765
1766 spin_lock_bh(&adapter->mcc_lock);
1767
1768 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001769 if (!wrb) {
1770 status = -EBUSY;
1771 goto err;
1772 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001773 req = embedded_payload(wrb);
1774
Ajit Khaparded744b442009-12-03 06:12:06 +00001775 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1776 OPCODE_COMMON_ENABLE_DISABLE_BEACON);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001777
1778 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1779 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1780
1781 req->port_num = port_num;
1782 req->beacon_state = state;
1783 req->beacon_duration = bcn;
1784 req->status_duration = sts;
1785
1786 status = be_mcc_notify_wait(adapter);
1787
Sathya Perla713d03942009-11-22 22:02:45 +00001788err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001789 spin_unlock_bh(&adapter->mcc_lock);
1790 return status;
1791}
1792
1793/* Uses sync mcc */
1794int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1795{
1796 struct be_mcc_wrb *wrb;
1797 struct be_cmd_req_get_beacon_state *req;
1798 int status;
1799
1800 spin_lock_bh(&adapter->mcc_lock);
1801
1802 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001803 if (!wrb) {
1804 status = -EBUSY;
1805 goto err;
1806 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001807 req = embedded_payload(wrb);
1808
Ajit Khaparded744b442009-12-03 06:12:06 +00001809 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1810 OPCODE_COMMON_GET_BEACON_STATE);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001811
1812 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1813 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1814
1815 req->port_num = port_num;
1816
1817 status = be_mcc_notify_wait(adapter);
1818 if (!status) {
1819 struct be_cmd_resp_get_beacon_state *resp =
1820 embedded_payload(wrb);
1821 *state = resp->beacon_state;
1822 }
1823
Sathya Perla713d03942009-11-22 22:02:45 +00001824err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001825 spin_unlock_bh(&adapter->mcc_lock);
1826 return status;
1827}
1828
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00001829int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
1830 u32 data_size, u32 data_offset, const char *obj_name,
1831 u32 *data_written, u8 *addn_status)
1832{
1833 struct be_mcc_wrb *wrb;
1834 struct lancer_cmd_req_write_object *req;
1835 struct lancer_cmd_resp_write_object *resp;
1836 void *ctxt = NULL;
1837 int status;
1838
1839 spin_lock_bh(&adapter->mcc_lock);
1840 adapter->flash_status = 0;
1841
1842 wrb = wrb_from_mccq(adapter);
1843 if (!wrb) {
1844 status = -EBUSY;
1845 goto err_unlock;
1846 }
1847
1848 req = embedded_payload(wrb);
1849
1850 be_wrb_hdr_prepare(wrb, sizeof(struct lancer_cmd_req_write_object),
1851 true, 1, OPCODE_COMMON_WRITE_OBJECT);
1852 wrb->tag1 = CMD_SUBSYSTEM_COMMON;
1853
1854 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1855 OPCODE_COMMON_WRITE_OBJECT,
1856 sizeof(struct lancer_cmd_req_write_object));
1857
1858 ctxt = &req->context;
1859 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
1860 write_length, ctxt, data_size);
1861
1862 if (data_size == 0)
1863 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
1864 eof, ctxt, 1);
1865 else
1866 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
1867 eof, ctxt, 0);
1868
1869 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1870 req->write_offset = cpu_to_le32(data_offset);
1871 strcpy(req->object_name, obj_name);
1872 req->descriptor_count = cpu_to_le32(1);
1873 req->buf_len = cpu_to_le32(data_size);
1874 req->addr_low = cpu_to_le32((cmd->dma +
1875 sizeof(struct lancer_cmd_req_write_object))
1876 & 0xFFFFFFFF);
1877 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
1878 sizeof(struct lancer_cmd_req_write_object)));
1879
1880 be_mcc_notify(adapter);
1881 spin_unlock_bh(&adapter->mcc_lock);
1882
1883 if (!wait_for_completion_timeout(&adapter->flash_compl,
1884 msecs_to_jiffies(12000)))
1885 status = -1;
1886 else
1887 status = adapter->flash_status;
1888
1889 resp = embedded_payload(wrb);
1890 if (!status) {
1891 *data_written = le32_to_cpu(resp->actual_write_len);
1892 } else {
1893 *addn_status = resp->additional_status;
1894 status = resp->status;
1895 }
1896
1897 return status;
1898
1899err_unlock:
1900 spin_unlock_bh(&adapter->mcc_lock);
1901 return status;
1902}
1903
Ajit Khaparde84517482009-09-04 03:12:16 +00001904int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1905 u32 flash_type, u32 flash_opcode, u32 buf_size)
1906{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001907 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001908 struct be_cmd_write_flashrom *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001909 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001910 int status;
1911
Sathya Perlab31c50a2009-09-17 10:30:13 -07001912 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001913 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001914
1915 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001916 if (!wrb) {
1917 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001918 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00001919 }
1920 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001921 sge = nonembedded_sgl(wrb);
1922
Ajit Khaparded744b442009-12-03 06:12:06 +00001923 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1924 OPCODE_COMMON_WRITE_FLASHROM);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001925 wrb->tag1 = CMD_SUBSYSTEM_COMMON;
Ajit Khaparde84517482009-09-04 03:12:16 +00001926
1927 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1928 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1929 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1930 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1931 sge->len = cpu_to_le32(cmd->size);
1932
1933 req->params.op_type = cpu_to_le32(flash_type);
1934 req->params.op_code = cpu_to_le32(flash_opcode);
1935 req->params.data_buf_size = cpu_to_le32(buf_size);
1936
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001937 be_mcc_notify(adapter);
1938 spin_unlock_bh(&adapter->mcc_lock);
1939
1940 if (!wait_for_completion_timeout(&adapter->flash_compl,
1941 msecs_to_jiffies(12000)))
1942 status = -1;
1943 else
1944 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00001945
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001946 return status;
1947
1948err_unlock:
1949 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001950 return status;
1951}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001952
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001953int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1954 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001955{
1956 struct be_mcc_wrb *wrb;
1957 struct be_cmd_write_flashrom *req;
1958 int status;
1959
1960 spin_lock_bh(&adapter->mcc_lock);
1961
1962 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001963 if (!wrb) {
1964 status = -EBUSY;
1965 goto err;
1966 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001967 req = embedded_payload(wrb);
1968
Ajit Khaparded744b442009-12-03 06:12:06 +00001969 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
1970 OPCODE_COMMON_READ_FLASHROM);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001971
1972 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1973 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1974
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001975 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001976 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00001977 req->params.offset = cpu_to_le32(offset);
1978 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001979
1980 status = be_mcc_notify_wait(adapter);
1981 if (!status)
1982 memcpy(flashed_crc, req->params.data_buf, 4);
1983
Sathya Perla713d03942009-11-22 22:02:45 +00001984err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001985 spin_unlock_bh(&adapter->mcc_lock);
1986 return status;
1987}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001988
Dan Carpenterc196b022010-05-26 04:47:39 +00001989int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001990 struct be_dma_mem *nonemb_cmd)
1991{
1992 struct be_mcc_wrb *wrb;
1993 struct be_cmd_req_acpi_wol_magic_config *req;
1994 struct be_sge *sge;
1995 int status;
1996
1997 spin_lock_bh(&adapter->mcc_lock);
1998
1999 wrb = wrb_from_mccq(adapter);
2000 if (!wrb) {
2001 status = -EBUSY;
2002 goto err;
2003 }
2004 req = nonemb_cmd->va;
2005 sge = nonembedded_sgl(wrb);
2006
2007 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
2008 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
2009
2010 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
2011 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
2012 memcpy(req->magic_mac, mac, ETH_ALEN);
2013
2014 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
2015 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
2016 sge->len = cpu_to_le32(nonemb_cmd->size);
2017
2018 status = be_mcc_notify_wait(adapter);
2019
2020err:
2021 spin_unlock_bh(&adapter->mcc_lock);
2022 return status;
2023}
Suresh Rff33a6e2009-12-03 16:15:52 -08002024
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002025int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2026 u8 loopback_type, u8 enable)
2027{
2028 struct be_mcc_wrb *wrb;
2029 struct be_cmd_req_set_lmode *req;
2030 int status;
2031
2032 spin_lock_bh(&adapter->mcc_lock);
2033
2034 wrb = wrb_from_mccq(adapter);
2035 if (!wrb) {
2036 status = -EBUSY;
2037 goto err;
2038 }
2039
2040 req = embedded_payload(wrb);
2041
2042 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2043 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
2044
2045 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2046 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
2047 sizeof(*req));
2048
2049 req->src_port = port_num;
2050 req->dest_port = port_num;
2051 req->loopback_type = loopback_type;
2052 req->loopback_state = enable;
2053
2054 status = be_mcc_notify_wait(adapter);
2055err:
2056 spin_unlock_bh(&adapter->mcc_lock);
2057 return status;
2058}
2059
Suresh Rff33a6e2009-12-03 16:15:52 -08002060int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
2061 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
2062{
2063 struct be_mcc_wrb *wrb;
2064 struct be_cmd_req_loopback_test *req;
2065 int status;
2066
2067 spin_lock_bh(&adapter->mcc_lock);
2068
2069 wrb = wrb_from_mccq(adapter);
2070 if (!wrb) {
2071 status = -EBUSY;
2072 goto err;
2073 }
2074
2075 req = embedded_payload(wrb);
2076
2077 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2078 OPCODE_LOWLEVEL_LOOPBACK_TEST);
2079
2080 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2081 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
Sathya Perla3ffd0512010-06-01 00:19:33 -07002082 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08002083
2084 req->pattern = cpu_to_le64(pattern);
2085 req->src_port = cpu_to_le32(port_num);
2086 req->dest_port = cpu_to_le32(port_num);
2087 req->pkt_size = cpu_to_le32(pkt_size);
2088 req->num_pkts = cpu_to_le32(num_pkts);
2089 req->loopback_type = cpu_to_le32(loopback_type);
2090
2091 status = be_mcc_notify_wait(adapter);
2092 if (!status) {
2093 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
2094 status = le32_to_cpu(resp->status);
2095 }
2096
2097err:
2098 spin_unlock_bh(&adapter->mcc_lock);
2099 return status;
2100}
2101
2102int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
2103 u32 byte_cnt, struct be_dma_mem *cmd)
2104{
2105 struct be_mcc_wrb *wrb;
2106 struct be_cmd_req_ddrdma_test *req;
2107 struct be_sge *sge;
2108 int status;
2109 int i, j = 0;
2110
2111 spin_lock_bh(&adapter->mcc_lock);
2112
2113 wrb = wrb_from_mccq(adapter);
2114 if (!wrb) {
2115 status = -EBUSY;
2116 goto err;
2117 }
2118 req = cmd->va;
2119 sge = nonembedded_sgl(wrb);
2120 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
2121 OPCODE_LOWLEVEL_HOST_DDR_DMA);
2122 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
2123 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
2124
2125 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
2126 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
2127 sge->len = cpu_to_le32(cmd->size);
2128
2129 req->pattern = cpu_to_le64(pattern);
2130 req->byte_count = cpu_to_le32(byte_cnt);
2131 for (i = 0; i < byte_cnt; i++) {
2132 req->snd_buff[i] = (u8)(pattern >> (j*8));
2133 j++;
2134 if (j > 7)
2135 j = 0;
2136 }
2137
2138 status = be_mcc_notify_wait(adapter);
2139
2140 if (!status) {
2141 struct be_cmd_resp_ddrdma_test *resp;
2142 resp = cmd->va;
2143 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
2144 resp->snd_err) {
2145 status = -1;
2146 }
2147 }
2148
2149err:
2150 spin_unlock_bh(&adapter->mcc_lock);
2151 return status;
2152}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002153
Dan Carpenterc196b022010-05-26 04:47:39 +00002154int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002155 struct be_dma_mem *nonemb_cmd)
2156{
2157 struct be_mcc_wrb *wrb;
2158 struct be_cmd_req_seeprom_read *req;
2159 struct be_sge *sge;
2160 int status;
2161
2162 spin_lock_bh(&adapter->mcc_lock);
2163
2164 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002165 if (!wrb) {
2166 status = -EBUSY;
2167 goto err;
2168 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002169 req = nonemb_cmd->va;
2170 sge = nonembedded_sgl(wrb);
2171
2172 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
2173 OPCODE_COMMON_SEEPROM_READ);
2174
2175 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2176 OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
2177
2178 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
2179 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
2180 sge->len = cpu_to_le32(nonemb_cmd->size);
2181
2182 status = be_mcc_notify_wait(adapter);
2183
Ajit Khapardee45ff012011-02-04 17:18:28 +00002184err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002185 spin_unlock_bh(&adapter->mcc_lock);
2186 return status;
2187}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002188
Sathya Perla306f1342011-08-02 19:57:45 +00002189int be_cmd_get_phy_info(struct be_adapter *adapter,
2190 struct be_phy_info *phy_info)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002191{
2192 struct be_mcc_wrb *wrb;
2193 struct be_cmd_req_get_phy_info *req;
2194 struct be_sge *sge;
Sathya Perla306f1342011-08-02 19:57:45 +00002195 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002196 int status;
2197
2198 spin_lock_bh(&adapter->mcc_lock);
2199
2200 wrb = wrb_from_mccq(adapter);
2201 if (!wrb) {
2202 status = -EBUSY;
2203 goto err;
2204 }
Sathya Perla306f1342011-08-02 19:57:45 +00002205 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
2206 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size,
2207 &cmd.dma);
2208 if (!cmd.va) {
2209 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2210 status = -ENOMEM;
2211 goto err;
2212 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002213
Sathya Perla306f1342011-08-02 19:57:45 +00002214 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002215 sge = nonembedded_sgl(wrb);
2216
2217 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
2218 OPCODE_COMMON_GET_PHY_DETAILS);
2219
2220 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2221 OPCODE_COMMON_GET_PHY_DETAILS,
2222 sizeof(*req));
2223
Sathya Perla306f1342011-08-02 19:57:45 +00002224 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd.dma));
2225 sge->pa_lo = cpu_to_le32(cmd.dma & 0xFFFFFFFF);
2226 sge->len = cpu_to_le32(cmd.size);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002227
2228 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002229 if (!status) {
2230 struct be_phy_info *resp_phy_info =
2231 cmd.va + sizeof(struct be_cmd_req_hdr);
2232 phy_info->phy_type = le16_to_cpu(resp_phy_info->phy_type);
2233 phy_info->interface_type =
2234 le16_to_cpu(resp_phy_info->interface_type);
2235 }
2236 pci_free_consistent(adapter->pdev, cmd.size,
2237 cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002238err:
2239 spin_unlock_bh(&adapter->mcc_lock);
2240 return status;
2241}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002242
2243int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2244{
2245 struct be_mcc_wrb *wrb;
2246 struct be_cmd_req_set_qos *req;
2247 int status;
2248
2249 spin_lock_bh(&adapter->mcc_lock);
2250
2251 wrb = wrb_from_mccq(adapter);
2252 if (!wrb) {
2253 status = -EBUSY;
2254 goto err;
2255 }
2256
2257 req = embedded_payload(wrb);
2258
2259 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2260 OPCODE_COMMON_SET_QOS);
2261
2262 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2263 OPCODE_COMMON_SET_QOS, sizeof(*req));
2264
2265 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002266 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2267 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002268
2269 status = be_mcc_notify_wait(adapter);
2270
2271err:
2272 spin_unlock_bh(&adapter->mcc_lock);
2273 return status;
2274}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002275
2276int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2277{
2278 struct be_mcc_wrb *wrb;
2279 struct be_cmd_req_cntl_attribs *req;
2280 struct be_cmd_resp_cntl_attribs *resp;
2281 struct be_sge *sge;
2282 int status;
2283 int payload_len = max(sizeof(*req), sizeof(*resp));
2284 struct mgmt_controller_attrib *attribs;
2285 struct be_dma_mem attribs_cmd;
2286
2287 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2288 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2289 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2290 &attribs_cmd.dma);
2291 if (!attribs_cmd.va) {
2292 dev_err(&adapter->pdev->dev,
2293 "Memory allocation failure\n");
2294 return -ENOMEM;
2295 }
2296
2297 if (mutex_lock_interruptible(&adapter->mbox_lock))
2298 return -1;
2299
2300 wrb = wrb_from_mbox(adapter);
2301 if (!wrb) {
2302 status = -EBUSY;
2303 goto err;
2304 }
2305 req = attribs_cmd.va;
2306 sge = nonembedded_sgl(wrb);
2307
2308 be_wrb_hdr_prepare(wrb, payload_len, false, 1,
2309 OPCODE_COMMON_GET_CNTL_ATTRIBUTES);
2310 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2311 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len);
2312 sge->pa_hi = cpu_to_le32(upper_32_bits(attribs_cmd.dma));
2313 sge->pa_lo = cpu_to_le32(attribs_cmd.dma & 0xFFFFFFFF);
2314 sge->len = cpu_to_le32(attribs_cmd.size);
2315
2316 status = be_mbox_notify_wait(adapter);
2317 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002318 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002319 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2320 }
2321
2322err:
2323 mutex_unlock(&adapter->mbox_lock);
2324 pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
2325 attribs_cmd.dma);
2326 return status;
2327}
Sathya Perla2e588f82011-03-11 02:49:26 +00002328
2329/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002330int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002331{
2332 struct be_mcc_wrb *wrb;
2333 struct be_cmd_req_set_func_cap *req;
2334 int status;
2335
2336 if (mutex_lock_interruptible(&adapter->mbox_lock))
2337 return -1;
2338
2339 wrb = wrb_from_mbox(adapter);
2340 if (!wrb) {
2341 status = -EBUSY;
2342 goto err;
2343 }
2344
2345 req = embedded_payload(wrb);
2346
2347 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2348 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP);
2349
2350 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2351 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req));
2352
2353 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2354 CAPABILITY_BE3_NATIVE_ERX_API);
2355 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2356
2357 status = be_mbox_notify_wait(adapter);
2358 if (!status) {
2359 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2360 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2361 CAPABILITY_BE3_NATIVE_ERX_API;
2362 }
2363err:
2364 mutex_unlock(&adapter->mbox_lock);
2365 return status;
2366}