blob: 61a9afdb83f45eaa128e2c660243b948cbe7c595 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparde294aedc2010-02-19 13:54:58 +00002 * Copyright (C) 2005 - 2010 ServerEngines
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:
11 * linux-drivers@serverengines.com
12 *
13 * ServerEngines
14 * 209 N. Fair Oaks Ave
15 * Sunnyvale, CA 94085
16 */
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
Sathya Perla8788fdc2009-07-27 22:52:03 +000021static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000022{
Sathya Perla8788fdc2009-07-27 22:52:03 +000023 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000024 u32 val = 0;
25
26 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
27 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perla8788fdc2009-07-27 22:52:03 +000028 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000029}
30
31/* To check if valid bit is set, check the entire word as we don't know
32 * the endianness of the data (old entry is host endian while a new entry is
33 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000034static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000035{
36 if (compl->flags != 0) {
37 compl->flags = le32_to_cpu(compl->flags);
38 BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
39 return true;
40 } else {
41 return false;
42 }
43}
44
45/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +000046static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000047{
48 compl->flags = 0;
49}
50
Sathya Perla8788fdc2009-07-27 22:52:03 +000051static int be_mcc_compl_process(struct be_adapter *adapter,
Sathya Perlaefd2e402009-07-27 22:53:10 +000052 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000053{
54 u16 compl_status, extd_status;
55
56 /* Just swap the status to host endian; mcc tag is opaquely copied
57 * from mcc_wrb */
58 be_dws_le_to_cpu(compl, 4);
59
60 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
61 CQE_STATUS_COMPL_MASK;
Sathya Perlab31c50a2009-09-17 10:30:13 -070062 if (compl_status == MCC_STATUS_SUCCESS) {
63 if (compl->tag0 == OPCODE_ETH_GET_STATISTICS) {
64 struct be_cmd_resp_get_stats *resp =
65 adapter->stats.cmd.va;
66 be_dws_le_to_cpu(&resp->hw_stats,
67 sizeof(resp->hw_stats));
68 netdev_stats_update(adapter);
69 }
70 } else if (compl_status != MCC_STATUS_NOT_SUPPORTED) {
Sathya Perla5fb379e2009-06-18 00:02:59 +000071 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
72 CQE_STATUS_EXTD_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +000073 dev_warn(&adapter->pdev->dev,
Ajit Khaparded744b442009-12-03 06:12:06 +000074 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
75 compl->tag0, compl_status, extd_status);
Sathya Perla5fb379e2009-06-18 00:02:59 +000076 }
Sathya Perlab31c50a2009-09-17 10:30:13 -070077 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +000078}
79
Sathya Perlaa8f447bd2009-06-18 00:10:27 +000080/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +000081static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +000082 struct be_async_event_link_state *evt)
83{
Sathya Perla8788fdc2009-07-27 22:52:03 +000084 be_link_status_update(adapter,
85 evt->port_link_status == ASYNC_EVENT_LINK_UP);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +000086}
87
88static inline bool is_link_state_evt(u32 trailer)
89{
90 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
91 ASYNC_TRAILER_EVENT_CODE_MASK) ==
92 ASYNC_EVENT_CODE_LINK_STATE);
93}
Sathya Perla5fb379e2009-06-18 00:02:59 +000094
Sathya Perlaefd2e402009-07-27 22:53:10 +000095static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000096{
Sathya Perla8788fdc2009-07-27 22:52:03 +000097 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +000098 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +000099
100 if (be_mcc_compl_is_new(compl)) {
101 queue_tail_inc(mcc_cq);
102 return compl;
103 }
104 return NULL;
105}
106
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000107void be_async_mcc_enable(struct be_adapter *adapter)
108{
109 spin_lock_bh(&adapter->mcc_cq_lock);
110
111 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
112 adapter->mcc_obj.rearm_cq = true;
113
114 spin_unlock_bh(&adapter->mcc_cq_lock);
115}
116
117void be_async_mcc_disable(struct be_adapter *adapter)
118{
119 adapter->mcc_obj.rearm_cq = false;
120}
121
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800122int be_process_mcc(struct be_adapter *adapter, int *status)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000123{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000124 struct be_mcc_compl *compl;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800125 int num = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000126 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000127
Sathya Perla8788fdc2009-07-27 22:52:03 +0000128 spin_lock_bh(&adapter->mcc_cq_lock);
129 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000130 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
131 /* Interpret flags as an async trailer */
132 BUG_ON(!is_link_state_evt(compl->flags));
133
134 /* Interpret compl as a async link evt */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000135 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000136 (struct be_async_event_link_state *) compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700137 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800138 *status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000139 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000140 }
141 be_mcc_compl_use(compl);
142 num++;
143 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700144
Sathya Perla8788fdc2009-07-27 22:52:03 +0000145 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800146 return num;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000147}
148
Sathya Perla6ac7b682009-06-18 00:05:54 +0000149/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700150static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000151{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700152#define mcc_timeout 120000 /* 12s timeout */
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800153 int i, num, status = 0;
154 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700155
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800156 for (i = 0; i < mcc_timeout; i++) {
157 num = be_process_mcc(adapter, &status);
158 if (num)
159 be_cq_notify(adapter, mcc_obj->cq.id,
160 mcc_obj->rearm_cq, num);
161
162 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000163 break;
164 udelay(100);
165 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700166 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000167 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700168 return -1;
169 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800170 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000171}
172
173/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700174static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000175{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000176 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700177 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000178}
179
Sathya Perla5f0b8492009-07-27 22:52:56 +0000180static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700181{
182 int cnt = 0, wait = 5;
183 u32 ready;
184
185 do {
Sathya Perlacf588472010-02-14 21:22:01 +0000186 ready = ioread32(db);
187 if (ready == 0xffffffff) {
188 dev_err(&adapter->pdev->dev,
189 "pci slot disconnected\n");
190 return -1;
191 }
192
193 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700194 if (ready)
195 break;
196
Ajit Khaparde84517482009-09-04 03:12:16 +0000197 if (cnt > 4000000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000198 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700199 return -1;
200 }
201
202 if (cnt > 50)
203 wait = 200;
204 cnt += wait;
205 udelay(wait);
206 } while (true);
207
208 return 0;
209}
210
211/*
212 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000213 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700214 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700215static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700216{
217 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700218 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000219 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
220 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700221 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000222 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700223
Sathya Perlacf588472010-02-14 21:22:01 +0000224 /* wait for ready to be set */
225 status = be_mbox_db_ready_wait(adapter, db);
226 if (status != 0)
227 return status;
228
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700229 val |= MPU_MAILBOX_DB_HI_MASK;
230 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
231 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
232 iowrite32(val, db);
233
234 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000235 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700236 if (status != 0)
237 return status;
238
239 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700240 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
241 val |= (u32)(mbox_mem->dma >> 4) << 2;
242 iowrite32(val, db);
243
Sathya Perla5f0b8492009-07-27 22:52:56 +0000244 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700245 if (status != 0)
246 return status;
247
Sathya Perla5fb379e2009-06-18 00:02:59 +0000248 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000249 if (be_mcc_compl_is_new(compl)) {
250 status = be_mcc_compl_process(adapter, &mbox->compl);
251 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000252 if (status)
253 return status;
254 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000255 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700256 return -1;
257 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000258 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700259}
260
Sathya Perla8788fdc2009-07-27 22:52:03 +0000261static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700262{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000263 u32 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700264
265 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
266 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
267 return -1;
268 else
269 return 0;
270}
271
Sathya Perla8788fdc2009-07-27 22:52:03 +0000272int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700273{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000274 u16 stage;
275 int status, timeout = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700276
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000277 do {
278 status = be_POST_stage_get(adapter, &stage);
279 if (status) {
280 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
281 stage);
282 return -1;
283 } else if (stage != POST_STAGE_ARMFW_RDY) {
284 set_current_state(TASK_INTERRUPTIBLE);
285 schedule_timeout(2 * HZ);
286 timeout += 2;
287 } else {
288 return 0;
289 }
290 } while (timeout < 20);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700291
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000292 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
293 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700294}
295
296static inline void *embedded_payload(struct be_mcc_wrb *wrb)
297{
298 return wrb->payload.embedded_payload;
299}
300
301static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
302{
303 return &wrb->payload.sgl[0];
304}
305
306/* Don't touch the hdr after it's prepared */
307static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
Ajit Khaparded744b442009-12-03 06:12:06 +0000308 bool embedded, u8 sge_cnt, u32 opcode)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700309{
310 if (embedded)
311 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
312 else
313 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
314 MCC_WRB_SGE_CNT_SHIFT;
315 wrb->payload_length = payload_len;
Ajit Khaparded744b442009-12-03 06:12:06 +0000316 wrb->tag0 = opcode;
Sathya Perlafa4281b2010-01-21 22:51:36 +0000317 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700318}
319
320/* Don't touch the hdr after it's prepared */
321static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
322 u8 subsystem, u8 opcode, int cmd_len)
323{
324 req_hdr->opcode = opcode;
325 req_hdr->subsystem = subsystem;
326 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000327 req_hdr->version = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700328}
329
330static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
331 struct be_dma_mem *mem)
332{
333 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
334 u64 dma = (u64)mem->dma;
335
336 for (i = 0; i < buf_pages; i++) {
337 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
338 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
339 dma += PAGE_SIZE_4K;
340 }
341}
342
343/* Converts interrupt delay in microseconds to multiplier value */
344static u32 eq_delay_to_mult(u32 usec_delay)
345{
346#define MAX_INTR_RATE 651042
347 const u32 round = 10;
348 u32 multiplier;
349
350 if (usec_delay == 0)
351 multiplier = 0;
352 else {
353 u32 interrupt_rate = 1000000 / usec_delay;
354 /* Max delay, corresponding to the lowest interrupt rate */
355 if (interrupt_rate == 0)
356 multiplier = 1023;
357 else {
358 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
359 multiplier /= interrupt_rate;
360 /* Round the multiplier to the closest value.*/
361 multiplier = (multiplier + round/2) / round;
362 multiplier = min(multiplier, (u32)1023);
363 }
364 }
365 return multiplier;
366}
367
Sathya Perlab31c50a2009-09-17 10:30:13 -0700368static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700369{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700370 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
371 struct be_mcc_wrb *wrb
372 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
373 memset(wrb, 0, sizeof(*wrb));
374 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700375}
376
Sathya Perlab31c50a2009-09-17 10:30:13 -0700377static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000378{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700379 struct be_queue_info *mccq = &adapter->mcc_obj.q;
380 struct be_mcc_wrb *wrb;
381
Sathya Perla713d03942009-11-22 22:02:45 +0000382 if (atomic_read(&mccq->used) >= mccq->len) {
383 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
384 return NULL;
385 }
386
Sathya Perlab31c50a2009-09-17 10:30:13 -0700387 wrb = queue_head_node(mccq);
388 queue_head_inc(mccq);
389 atomic_inc(&mccq->used);
390 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000391 return wrb;
392}
393
Sathya Perla2243e2e2009-11-22 22:02:03 +0000394/* Tell fw we're about to start firing cmds by writing a
395 * special pattern across the wrb hdr; uses mbox
396 */
397int be_cmd_fw_init(struct be_adapter *adapter)
398{
399 u8 *wrb;
400 int status;
401
402 spin_lock(&adapter->mbox_lock);
403
404 wrb = (u8 *)wrb_from_mbox(adapter);
405 *wrb++ = 0xFF;
406 *wrb++ = 0x12;
407 *wrb++ = 0x34;
408 *wrb++ = 0xFF;
409 *wrb++ = 0xFF;
410 *wrb++ = 0x56;
411 *wrb++ = 0x78;
412 *wrb = 0xFF;
413
414 status = be_mbox_notify_wait(adapter);
415
416 spin_unlock(&adapter->mbox_lock);
417 return status;
418}
419
420/* Tell fw we're done with firing cmds by writing a
421 * special pattern across the wrb hdr; uses mbox
422 */
423int be_cmd_fw_clean(struct be_adapter *adapter)
424{
425 u8 *wrb;
426 int status;
427
Sathya Perlacf588472010-02-14 21:22:01 +0000428 if (adapter->eeh_err)
429 return -EIO;
430
Sathya Perla2243e2e2009-11-22 22:02:03 +0000431 spin_lock(&adapter->mbox_lock);
432
433 wrb = (u8 *)wrb_from_mbox(adapter);
434 *wrb++ = 0xFF;
435 *wrb++ = 0xAA;
436 *wrb++ = 0xBB;
437 *wrb++ = 0xFF;
438 *wrb++ = 0xFF;
439 *wrb++ = 0xCC;
440 *wrb++ = 0xDD;
441 *wrb = 0xFF;
442
443 status = be_mbox_notify_wait(adapter);
444
445 spin_unlock(&adapter->mbox_lock);
446 return status;
447}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000448int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700449 struct be_queue_info *eq, int eq_delay)
450{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700451 struct be_mcc_wrb *wrb;
452 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700453 struct be_dma_mem *q_mem = &eq->dma_mem;
454 int status;
455
Sathya Perla8788fdc2009-07-27 22:52:03 +0000456 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700457
458 wrb = wrb_from_mbox(adapter);
459 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700460
Ajit Khaparded744b442009-12-03 06:12:06 +0000461 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700462
463 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
464 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
465
466 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
467
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700468 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
469 /* 4byte eqe*/
470 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
471 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
472 __ilog2_u32(eq->len/256));
473 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
474 eq_delay_to_mult(eq_delay));
475 be_dws_cpu_to_le(req->context, sizeof(req->context));
476
477 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
478
Sathya Perlab31c50a2009-09-17 10:30:13 -0700479 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700480 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700481 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700482 eq->id = le16_to_cpu(resp->eq_id);
483 eq->created = true;
484 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700485
Sathya Perla8788fdc2009-07-27 22:52:03 +0000486 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700487 return status;
488}
489
Sathya Perlab31c50a2009-09-17 10:30:13 -0700490/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000491int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700492 u8 type, bool permanent, u32 if_handle)
493{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700494 struct be_mcc_wrb *wrb;
495 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700496 int status;
497
Sathya Perla8788fdc2009-07-27 22:52:03 +0000498 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700499
500 wrb = wrb_from_mbox(adapter);
501 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700502
Ajit Khaparded744b442009-12-03 06:12:06 +0000503 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
504 OPCODE_COMMON_NTWK_MAC_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700505
506 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
507 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
508
509 req->type = type;
510 if (permanent) {
511 req->permanent = 1;
512 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700513 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700514 req->permanent = 0;
515 }
516
Sathya Perlab31c50a2009-09-17 10:30:13 -0700517 status = be_mbox_notify_wait(adapter);
518 if (!status) {
519 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700520 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700521 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700522
Sathya Perla8788fdc2009-07-27 22:52:03 +0000523 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700524 return status;
525}
526
Sathya Perlab31c50a2009-09-17 10:30:13 -0700527/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000528int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700529 u32 if_id, u32 *pmac_id)
530{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700531 struct be_mcc_wrb *wrb;
532 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700533 int status;
534
Sathya Perlab31c50a2009-09-17 10:30:13 -0700535 spin_lock_bh(&adapter->mcc_lock);
536
537 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000538 if (!wrb) {
539 status = -EBUSY;
540 goto err;
541 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700542 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700543
Ajit Khaparded744b442009-12-03 06:12:06 +0000544 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
545 OPCODE_COMMON_NTWK_PMAC_ADD);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700546
547 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
548 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
549
550 req->if_id = cpu_to_le32(if_id);
551 memcpy(req->mac_address, mac_addr, ETH_ALEN);
552
Sathya Perlab31c50a2009-09-17 10:30:13 -0700553 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700554 if (!status) {
555 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
556 *pmac_id = le32_to_cpu(resp->pmac_id);
557 }
558
Sathya Perla713d03942009-11-22 22:02:45 +0000559err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700560 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700561 return status;
562}
563
Sathya Perlab31c50a2009-09-17 10:30:13 -0700564/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000565int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700566{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700567 struct be_mcc_wrb *wrb;
568 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700569 int status;
570
Sathya Perlab31c50a2009-09-17 10:30:13 -0700571 spin_lock_bh(&adapter->mcc_lock);
572
573 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000574 if (!wrb) {
575 status = -EBUSY;
576 goto err;
577 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700578 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700579
Ajit Khaparded744b442009-12-03 06:12:06 +0000580 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
581 OPCODE_COMMON_NTWK_PMAC_DEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700582
583 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
584 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
585
586 req->if_id = cpu_to_le32(if_id);
587 req->pmac_id = cpu_to_le32(pmac_id);
588
Sathya Perlab31c50a2009-09-17 10:30:13 -0700589 status = be_mcc_notify_wait(adapter);
590
Sathya Perla713d03942009-11-22 22:02:45 +0000591err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700592 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700593 return status;
594}
595
Sathya Perlab31c50a2009-09-17 10:30:13 -0700596/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000597int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700598 struct be_queue_info *cq, struct be_queue_info *eq,
599 bool sol_evts, bool no_delay, int coalesce_wm)
600{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700601 struct be_mcc_wrb *wrb;
602 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700603 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700604 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700605 int status;
606
Sathya Perla8788fdc2009-07-27 22:52:03 +0000607 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700608
609 wrb = wrb_from_mbox(adapter);
610 req = embedded_payload(wrb);
611 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700612
Ajit Khaparded744b442009-12-03 06:12:06 +0000613 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
614 OPCODE_COMMON_CQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700615
616 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
617 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
618
619 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
620
621 AMAP_SET_BITS(struct amap_cq_context, coalescwm, ctxt, coalesce_wm);
622 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
623 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
624 __ilog2_u32(cq->len/256));
625 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
626 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
627 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
628 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000629 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700630 be_dws_cpu_to_le(ctxt, sizeof(req->context));
631
632 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
633
Sathya Perlab31c50a2009-09-17 10:30:13 -0700634 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700635 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700636 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700637 cq->id = le16_to_cpu(resp->cq_id);
638 cq->created = true;
639 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700640
Sathya Perla8788fdc2009-07-27 22:52:03 +0000641 spin_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000642
643 return status;
644}
645
646static u32 be_encoded_q_len(int q_len)
647{
648 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
649 if (len_encoded == 16)
650 len_encoded = 0;
651 return len_encoded;
652}
653
Sathya Perla8788fdc2009-07-27 22:52:03 +0000654int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000655 struct be_queue_info *mccq,
656 struct be_queue_info *cq)
657{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700658 struct be_mcc_wrb *wrb;
659 struct be_cmd_req_mcc_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000660 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700661 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000662 int status;
663
Sathya Perla8788fdc2009-07-27 22:52:03 +0000664 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700665
666 wrb = wrb_from_mbox(adapter);
667 req = embedded_payload(wrb);
668 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000669
Ajit Khaparded744b442009-12-03 06:12:06 +0000670 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
671 OPCODE_COMMON_MCC_CREATE);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000672
673 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
674 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
675
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000676 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000677
Sathya Perla5fb379e2009-06-18 00:02:59 +0000678 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
679 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
680 be_encoded_q_len(mccq->len));
681 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
682
683 be_dws_cpu_to_le(ctxt, sizeof(req->context));
684
685 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
686
Sathya Perlab31c50a2009-09-17 10:30:13 -0700687 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000688 if (!status) {
689 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
690 mccq->id = le16_to_cpu(resp->id);
691 mccq->created = true;
692 }
Sathya Perla8788fdc2009-07-27 22:52:03 +0000693 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700694
695 return status;
696}
697
Sathya Perla8788fdc2009-07-27 22:52:03 +0000698int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700699 struct be_queue_info *txq,
700 struct be_queue_info *cq)
701{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700702 struct be_mcc_wrb *wrb;
703 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700704 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700705 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700706 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700707
Sathya Perla8788fdc2009-07-27 22:52:03 +0000708 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700709
710 wrb = wrb_from_mbox(adapter);
711 req = embedded_payload(wrb);
712 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700713
Ajit Khaparded744b442009-12-03 06:12:06 +0000714 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
715 OPCODE_ETH_TX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700716
717 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
718 sizeof(*req));
719
720 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
721 req->ulp_num = BE_ULP1_NUM;
722 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
723
Sathya Perlab31c50a2009-09-17 10:30:13 -0700724 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
725 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700726 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
727 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
728
729 be_dws_cpu_to_le(ctxt, sizeof(req->context));
730
731 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
732
Sathya Perlab31c50a2009-09-17 10:30:13 -0700733 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700734 if (!status) {
735 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
736 txq->id = le16_to_cpu(resp->cid);
737 txq->created = true;
738 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700739
Sathya Perla8788fdc2009-07-27 22:52:03 +0000740 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700741
742 return status;
743}
744
Sathya Perlab31c50a2009-09-17 10:30:13 -0700745/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000746int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700747 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
748 u16 max_frame_size, u32 if_id, u32 rss)
749{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700750 struct be_mcc_wrb *wrb;
751 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700752 struct be_dma_mem *q_mem = &rxq->dma_mem;
753 int status;
754
Sathya Perla8788fdc2009-07-27 22:52:03 +0000755 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700756
757 wrb = wrb_from_mbox(adapter);
758 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700759
Ajit Khaparded744b442009-12-03 06:12:06 +0000760 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
761 OPCODE_ETH_RX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700762
763 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
764 sizeof(*req));
765
766 req->cq_id = cpu_to_le16(cq_id);
767 req->frag_size = fls(frag_size) - 1;
768 req->num_pages = 2;
769 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
770 req->interface_id = cpu_to_le32(if_id);
771 req->max_frame_size = cpu_to_le16(max_frame_size);
772 req->rss_queue = cpu_to_le32(rss);
773
Sathya Perlab31c50a2009-09-17 10:30:13 -0700774 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700775 if (!status) {
776 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
777 rxq->id = le16_to_cpu(resp->id);
778 rxq->created = true;
779 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700780
Sathya Perla8788fdc2009-07-27 22:52:03 +0000781 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700782
783 return status;
784}
785
Sathya Perlab31c50a2009-09-17 10:30:13 -0700786/* Generic destroyer function for all types of queues
787 * Uses Mbox
788 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000789int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700790 int queue_type)
791{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700792 struct be_mcc_wrb *wrb;
793 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700794 u8 subsys = 0, opcode = 0;
795 int status;
796
Sathya Perlacf588472010-02-14 21:22:01 +0000797 if (adapter->eeh_err)
798 return -EIO;
799
Sathya Perla8788fdc2009-07-27 22:52:03 +0000800 spin_lock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700801
Sathya Perlab31c50a2009-09-17 10:30:13 -0700802 wrb = wrb_from_mbox(adapter);
803 req = embedded_payload(wrb);
804
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700805 switch (queue_type) {
806 case QTYPE_EQ:
807 subsys = CMD_SUBSYSTEM_COMMON;
808 opcode = OPCODE_COMMON_EQ_DESTROY;
809 break;
810 case QTYPE_CQ:
811 subsys = CMD_SUBSYSTEM_COMMON;
812 opcode = OPCODE_COMMON_CQ_DESTROY;
813 break;
814 case QTYPE_TXQ:
815 subsys = CMD_SUBSYSTEM_ETH;
816 opcode = OPCODE_ETH_TX_DESTROY;
817 break;
818 case QTYPE_RXQ:
819 subsys = CMD_SUBSYSTEM_ETH;
820 opcode = OPCODE_ETH_RX_DESTROY;
821 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000822 case QTYPE_MCCQ:
823 subsys = CMD_SUBSYSTEM_COMMON;
824 opcode = OPCODE_COMMON_MCC_DESTROY;
825 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700826 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +0000827 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700828 }
Ajit Khaparded744b442009-12-03 06:12:06 +0000829
830 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
831
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700832 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
833 req->id = cpu_to_le16(q->id);
834
Sathya Perlab31c50a2009-09-17 10:30:13 -0700835 status = be_mbox_notify_wait(adapter);
Sathya Perla5f0b8492009-07-27 22:52:56 +0000836
Sathya Perla8788fdc2009-07-27 22:52:03 +0000837 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700838
839 return status;
840}
841
Sathya Perlab31c50a2009-09-17 10:30:13 -0700842/* Create an rx filtering policy configuration on an i/f
843 * Uses mbox
844 */
Sathya Perla73d540f2009-10-14 20:20:42 +0000845int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000846 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id,
847 u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700848{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700849 struct be_mcc_wrb *wrb;
850 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700851 int status;
852
Sathya Perla8788fdc2009-07-27 22:52:03 +0000853 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700854
855 wrb = wrb_from_mbox(adapter);
856 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700857
Ajit Khaparded744b442009-12-03 06:12:06 +0000858 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
859 OPCODE_COMMON_NTWK_INTERFACE_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700860
861 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
862 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
863
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000864 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +0000865 req->capability_flags = cpu_to_le32(cap_flags);
866 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700867 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700868 if (!pmac_invalid)
869 memcpy(req->mac_addr, mac, ETH_ALEN);
870
Sathya Perlab31c50a2009-09-17 10:30:13 -0700871 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700872 if (!status) {
873 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
874 *if_handle = le32_to_cpu(resp->interface_id);
875 if (!pmac_invalid)
876 *pmac_id = le32_to_cpu(resp->pmac_id);
877 }
878
Sathya Perla8788fdc2009-07-27 22:52:03 +0000879 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700880 return status;
881}
882
Sathya Perlab31c50a2009-09-17 10:30:13 -0700883/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000884int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700885{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700886 struct be_mcc_wrb *wrb;
887 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700888 int status;
889
Sathya Perlacf588472010-02-14 21:22:01 +0000890 if (adapter->eeh_err)
891 return -EIO;
892
Sathya Perla8788fdc2009-07-27 22:52:03 +0000893 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700894
895 wrb = wrb_from_mbox(adapter);
896 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700897
Ajit Khaparded744b442009-12-03 06:12:06 +0000898 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
899 OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700900
901 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
902 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
903
904 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700905
906 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700907
Sathya Perla8788fdc2009-07-27 22:52:03 +0000908 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700909
910 return status;
911}
912
913/* Get stats is a non embedded command: the request is not embedded inside
914 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -0700915 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700916 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000917int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700918{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700919 struct be_mcc_wrb *wrb;
920 struct be_cmd_req_get_stats *req;
921 struct be_sge *sge;
Sathya Perla713d03942009-11-22 22:02:45 +0000922 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700923
Sathya Perlab31c50a2009-09-17 10:30:13 -0700924 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700925
Sathya Perlab31c50a2009-09-17 10:30:13 -0700926 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000927 if (!wrb) {
928 status = -EBUSY;
929 goto err;
930 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700931 req = nonemb_cmd->va;
932 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700933
Ajit Khaparded744b442009-12-03 06:12:06 +0000934 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
935 OPCODE_ETH_GET_STATISTICS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700936
937 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
938 OPCODE_ETH_GET_STATISTICS, sizeof(*req));
939 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
940 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
941 sge->len = cpu_to_le32(nonemb_cmd->size);
942
Sathya Perlab31c50a2009-09-17 10:30:13 -0700943 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700944
Sathya Perla713d03942009-11-22 22:02:45 +0000945err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700946 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +0000947 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700948}
949
Sathya Perlab31c50a2009-09-17 10:30:13 -0700950/* Uses synchronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000951int be_cmd_link_status_query(struct be_adapter *adapter,
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700952 bool *link_up, u8 *mac_speed, u16 *link_speed)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700953{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700954 struct be_mcc_wrb *wrb;
955 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700956 int status;
957
Sathya Perlab31c50a2009-09-17 10:30:13 -0700958 spin_lock_bh(&adapter->mcc_lock);
959
960 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000961 if (!wrb) {
962 status = -EBUSY;
963 goto err;
964 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700965 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000966
967 *link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700968
Ajit Khaparded744b442009-12-03 06:12:06 +0000969 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
970 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700971
972 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
973 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
974
Sathya Perlab31c50a2009-09-17 10:30:13 -0700975 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700976 if (!status) {
977 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700978 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000979 *link_up = true;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700980 *link_speed = le16_to_cpu(resp->link_speed);
981 *mac_speed = resp->mac_speed;
982 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700983 }
984
Sathya Perla713d03942009-11-22 22:02:45 +0000985err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700986 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700987 return status;
988}
989
Sathya Perlab31c50a2009-09-17 10:30:13 -0700990/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000991int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700992{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700993 struct be_mcc_wrb *wrb;
994 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700995 int status;
996
Sathya Perla8788fdc2009-07-27 22:52:03 +0000997 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700998
999 wrb = wrb_from_mbox(adapter);
1000 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001001
Ajit Khaparded744b442009-12-03 06:12:06 +00001002 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1003 OPCODE_COMMON_GET_FW_VERSION);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001004
1005 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1006 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
1007
Sathya Perlab31c50a2009-09-17 10:30:13 -07001008 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001009 if (!status) {
1010 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1011 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
1012 }
1013
Sathya Perla8788fdc2009-07-27 22:52:03 +00001014 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001015 return status;
1016}
1017
Sathya Perlab31c50a2009-09-17 10:30:13 -07001018/* set the EQ delay interval of an EQ to specified value
1019 * Uses async mcc
1020 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001021int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001022{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001023 struct be_mcc_wrb *wrb;
1024 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001025 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001026
Sathya Perlab31c50a2009-09-17 10:30:13 -07001027 spin_lock_bh(&adapter->mcc_lock);
1028
1029 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001030 if (!wrb) {
1031 status = -EBUSY;
1032 goto err;
1033 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001034 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001035
Ajit Khaparded744b442009-12-03 06:12:06 +00001036 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1037 OPCODE_COMMON_MODIFY_EQ_DELAY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001038
1039 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1040 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
1041
1042 req->num_eq = cpu_to_le32(1);
1043 req->delay[0].eq_id = cpu_to_le32(eq_id);
1044 req->delay[0].phase = 0;
1045 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1046
Sathya Perlab31c50a2009-09-17 10:30:13 -07001047 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001048
Sathya Perla713d03942009-11-22 22:02:45 +00001049err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001050 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001051 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001052}
1053
Sathya Perlab31c50a2009-09-17 10:30:13 -07001054/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001055int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001056 u32 num, bool untagged, bool promiscuous)
1057{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001058 struct be_mcc_wrb *wrb;
1059 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001060 int status;
1061
Sathya Perlab31c50a2009-09-17 10:30:13 -07001062 spin_lock_bh(&adapter->mcc_lock);
1063
1064 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001065 if (!wrb) {
1066 status = -EBUSY;
1067 goto err;
1068 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001069 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001070
Ajit Khaparded744b442009-12-03 06:12:06 +00001071 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1072 OPCODE_COMMON_NTWK_VLAN_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001073
1074 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1075 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
1076
1077 req->interface_id = if_id;
1078 req->promiscuous = promiscuous;
1079 req->untagged = untagged;
1080 req->num_vlan = num;
1081 if (!promiscuous) {
1082 memcpy(req->normal_vlan, vtag_array,
1083 req->num_vlan * sizeof(vtag_array[0]));
1084 }
1085
Sathya Perlab31c50a2009-09-17 10:30:13 -07001086 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001087
Sathya Perla713d03942009-11-22 22:02:45 +00001088err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001089 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001090 return status;
1091}
1092
Sathya Perlab31c50a2009-09-17 10:30:13 -07001093/* Uses MCC for this command as it may be called in BH context
1094 * Uses synchronous mcc
1095 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001096int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001097{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001098 struct be_mcc_wrb *wrb;
1099 struct be_cmd_req_promiscuous_config *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001100 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001101
Sathya Perla8788fdc2009-07-27 22:52:03 +00001102 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001103
Sathya Perlab31c50a2009-09-17 10:30:13 -07001104 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001105 if (!wrb) {
1106 status = -EBUSY;
1107 goto err;
1108 }
Sathya Perla6ac7b682009-06-18 00:05:54 +00001109 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001110
Ajit Khaparded744b442009-12-03 06:12:06 +00001111 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_PROMISCUOUS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001112
1113 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1114 OPCODE_ETH_PROMISCUOUS, sizeof(*req));
1115
1116 if (port_num)
1117 req->port1_promiscuous = en;
1118 else
1119 req->port0_promiscuous = en;
1120
Sathya Perlab31c50a2009-09-17 10:30:13 -07001121 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001122
Sathya Perla713d03942009-11-22 22:02:45 +00001123err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001124 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001125 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001126}
1127
Sathya Perla6ac7b682009-06-18 00:05:54 +00001128/*
Sathya Perlab31c50a2009-09-17 10:30:13 -07001129 * Uses MCC for this command as it may be called in BH context
Sathya Perla6ac7b682009-06-18 00:05:54 +00001130 * (mc == NULL) => multicast promiscous
1131 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001132int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001133 struct net_device *netdev, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001134{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001135 struct be_mcc_wrb *wrb;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001136 struct be_cmd_req_mcast_mac_config *req = mem->va;
1137 struct be_sge *sge;
1138 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001139
Sathya Perla8788fdc2009-07-27 22:52:03 +00001140 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001141
Sathya Perlab31c50a2009-09-17 10:30:13 -07001142 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001143 if (!wrb) {
1144 status = -EBUSY;
1145 goto err;
1146 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00001147 sge = nonembedded_sgl(wrb);
1148 memset(req, 0, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001149
Ajit Khaparded744b442009-12-03 06:12:06 +00001150 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1151 OPCODE_COMMON_NTWK_MULTICAST_SET);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001152 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
1153 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
1154 sge->len = cpu_to_le32(mem->size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001155
1156 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1157 OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
1158
1159 req->interface_id = if_id;
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001160 if (netdev) {
Sathya Perla24307ee2009-06-18 00:09:25 +00001161 int i;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001162 struct netdev_hw_addr *ha;
Sathya Perla24307ee2009-06-18 00:09:25 +00001163
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001164 req->num_mac = cpu_to_le16(netdev_mc_count(netdev));
Sathya Perla24307ee2009-06-18 00:09:25 +00001165
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001166 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001167 netdev_for_each_mc_addr(ha, netdev)
1168 memcpy(req->mac[i].byte, ha->addr, ETH_ALEN);
Sathya Perla24307ee2009-06-18 00:09:25 +00001169 } else {
1170 req->promiscuous = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001171 }
1172
Sathya Perlae7b909a2009-11-22 22:01:10 +00001173 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001174
Sathya Perla713d03942009-11-22 22:02:45 +00001175err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001176 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001177 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001178}
1179
Sathya Perlab31c50a2009-09-17 10:30:13 -07001180/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001181int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001182{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001183 struct be_mcc_wrb *wrb;
1184 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001185 int status;
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 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001194 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001195
Ajit Khaparded744b442009-12-03 06:12:06 +00001196 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1197 OPCODE_COMMON_SET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001198
1199 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1200 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1201
1202 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1203 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1204
Sathya Perlab31c50a2009-09-17 10:30:13 -07001205 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001206
Sathya Perla713d03942009-11-22 22:02:45 +00001207err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001208 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001209 return status;
1210}
1211
Sathya Perlab31c50a2009-09-17 10:30:13 -07001212/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001213int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001214{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001215 struct be_mcc_wrb *wrb;
1216 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001217 int status;
1218
Sathya Perlab31c50a2009-09-17 10:30:13 -07001219 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001220
Sathya Perlab31c50a2009-09-17 10:30:13 -07001221 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001222 if (!wrb) {
1223 status = -EBUSY;
1224 goto err;
1225 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001226 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001227
Ajit Khaparded744b442009-12-03 06:12:06 +00001228 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1229 OPCODE_COMMON_GET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001230
1231 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1232 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1233
Sathya Perlab31c50a2009-09-17 10:30:13 -07001234 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001235 if (!status) {
1236 struct be_cmd_resp_get_flow_control *resp =
1237 embedded_payload(wrb);
1238 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1239 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1240 }
1241
Sathya Perla713d03942009-11-22 22:02:45 +00001242err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001243 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001244 return status;
1245}
1246
Sathya Perlab31c50a2009-09-17 10:30:13 -07001247/* Uses mbox */
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001248int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num, u32 *cap)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001249{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001250 struct be_mcc_wrb *wrb;
1251 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001252 int status;
1253
Sathya Perla8788fdc2009-07-27 22:52:03 +00001254 spin_lock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001255
Sathya Perlab31c50a2009-09-17 10:30:13 -07001256 wrb = wrb_from_mbox(adapter);
1257 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001258
Ajit Khaparded744b442009-12-03 06:12:06 +00001259 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1260 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001261
1262 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1263 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1264
Sathya Perlab31c50a2009-09-17 10:30:13 -07001265 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001266 if (!status) {
1267 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1268 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001269 *cap = le32_to_cpu(resp->function_cap);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001270 }
1271
Sathya Perla8788fdc2009-07-27 22:52:03 +00001272 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001273 return status;
1274}
sarveshwarb14074ea2009-08-05 13:05:24 -07001275
Sathya Perlab31c50a2009-09-17 10:30:13 -07001276/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001277int be_cmd_reset_function(struct be_adapter *adapter)
1278{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001279 struct be_mcc_wrb *wrb;
1280 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001281 int status;
1282
1283 spin_lock(&adapter->mbox_lock);
1284
Sathya Perlab31c50a2009-09-17 10:30:13 -07001285 wrb = wrb_from_mbox(adapter);
1286 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001287
Ajit Khaparded744b442009-12-03 06:12:06 +00001288 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1289 OPCODE_COMMON_FUNCTION_RESET);
sarveshwarb14074ea2009-08-05 13:05:24 -07001290
1291 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1292 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1293
Sathya Perlab31c50a2009-09-17 10:30:13 -07001294 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001295
1296 spin_unlock(&adapter->mbox_lock);
1297 return status;
1298}
Ajit Khaparde84517482009-09-04 03:12:16 +00001299
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001300/* Uses sync mcc */
1301int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1302 u8 bcn, u8 sts, u8 state)
1303{
1304 struct be_mcc_wrb *wrb;
1305 struct be_cmd_req_enable_disable_beacon *req;
1306 int status;
1307
1308 spin_lock_bh(&adapter->mcc_lock);
1309
1310 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001311 if (!wrb) {
1312 status = -EBUSY;
1313 goto err;
1314 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001315 req = embedded_payload(wrb);
1316
Ajit Khaparded744b442009-12-03 06:12:06 +00001317 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1318 OPCODE_COMMON_ENABLE_DISABLE_BEACON);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001319
1320 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1321 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1322
1323 req->port_num = port_num;
1324 req->beacon_state = state;
1325 req->beacon_duration = bcn;
1326 req->status_duration = sts;
1327
1328 status = be_mcc_notify_wait(adapter);
1329
Sathya Perla713d03942009-11-22 22:02:45 +00001330err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001331 spin_unlock_bh(&adapter->mcc_lock);
1332 return status;
1333}
1334
1335/* Uses sync mcc */
1336int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1337{
1338 struct be_mcc_wrb *wrb;
1339 struct be_cmd_req_get_beacon_state *req;
1340 int status;
1341
1342 spin_lock_bh(&adapter->mcc_lock);
1343
1344 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001345 if (!wrb) {
1346 status = -EBUSY;
1347 goto err;
1348 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001349 req = embedded_payload(wrb);
1350
Ajit Khaparded744b442009-12-03 06:12:06 +00001351 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1352 OPCODE_COMMON_GET_BEACON_STATE);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001353
1354 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1355 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1356
1357 req->port_num = port_num;
1358
1359 status = be_mcc_notify_wait(adapter);
1360 if (!status) {
1361 struct be_cmd_resp_get_beacon_state *resp =
1362 embedded_payload(wrb);
1363 *state = resp->beacon_state;
1364 }
1365
Sathya Perla713d03942009-11-22 22:02:45 +00001366err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001367 spin_unlock_bh(&adapter->mcc_lock);
1368 return status;
1369}
1370
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001371/* Uses sync mcc */
1372int be_cmd_read_port_type(struct be_adapter *adapter, u32 port,
1373 u8 *connector)
1374{
1375 struct be_mcc_wrb *wrb;
1376 struct be_cmd_req_port_type *req;
1377 int status;
1378
1379 spin_lock_bh(&adapter->mcc_lock);
1380
1381 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001382 if (!wrb) {
1383 status = -EBUSY;
1384 goto err;
1385 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001386 req = embedded_payload(wrb);
1387
Ajit Khaparded744b442009-12-03 06:12:06 +00001388 be_wrb_hdr_prepare(wrb, sizeof(struct be_cmd_resp_port_type), true, 0,
1389 OPCODE_COMMON_READ_TRANSRECV_DATA);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001390
1391 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1392 OPCODE_COMMON_READ_TRANSRECV_DATA, sizeof(*req));
1393
1394 req->port = cpu_to_le32(port);
1395 req->page_num = cpu_to_le32(TR_PAGE_A0);
1396 status = be_mcc_notify_wait(adapter);
1397 if (!status) {
1398 struct be_cmd_resp_port_type *resp = embedded_payload(wrb);
1399 *connector = resp->data.connector;
1400 }
1401
Sathya Perla713d03942009-11-22 22:02:45 +00001402err:
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001403 spin_unlock_bh(&adapter->mcc_lock);
1404 return status;
1405}
1406
Ajit Khaparde84517482009-09-04 03:12:16 +00001407int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1408 u32 flash_type, u32 flash_opcode, u32 buf_size)
1409{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001410 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001411 struct be_cmd_write_flashrom *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001412 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001413 int status;
1414
Sathya Perlab31c50a2009-09-17 10:30:13 -07001415 spin_lock_bh(&adapter->mcc_lock);
1416
1417 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001418 if (!wrb) {
1419 status = -EBUSY;
1420 goto err;
1421 }
1422 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001423 sge = nonembedded_sgl(wrb);
1424
Ajit Khaparded744b442009-12-03 06:12:06 +00001425 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1426 OPCODE_COMMON_WRITE_FLASHROM);
Ajit Khaparde84517482009-09-04 03:12:16 +00001427
1428 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1429 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1430 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1431 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1432 sge->len = cpu_to_le32(cmd->size);
1433
1434 req->params.op_type = cpu_to_le32(flash_type);
1435 req->params.op_code = cpu_to_le32(flash_opcode);
1436 req->params.data_buf_size = cpu_to_le32(buf_size);
1437
Sathya Perlab31c50a2009-09-17 10:30:13 -07001438 status = be_mcc_notify_wait(adapter);
Ajit Khaparde84517482009-09-04 03:12:16 +00001439
Sathya Perla713d03942009-11-22 22:02:45 +00001440err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001441 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001442 return status;
1443}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001444
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001445int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1446 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001447{
1448 struct be_mcc_wrb *wrb;
1449 struct be_cmd_write_flashrom *req;
1450 int status;
1451
1452 spin_lock_bh(&adapter->mcc_lock);
1453
1454 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001455 if (!wrb) {
1456 status = -EBUSY;
1457 goto err;
1458 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001459 req = embedded_payload(wrb);
1460
Ajit Khaparded744b442009-12-03 06:12:06 +00001461 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
1462 OPCODE_COMMON_READ_FLASHROM);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001463
1464 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1465 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1466
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001467 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001468 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001469 req->params.offset = offset;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001470 req->params.data_buf_size = 0x4;
1471
1472 status = be_mcc_notify_wait(adapter);
1473 if (!status)
1474 memcpy(flashed_crc, req->params.data_buf, 4);
1475
Sathya Perla713d03942009-11-22 22:02:45 +00001476err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001477 spin_unlock_bh(&adapter->mcc_lock);
1478 return status;
1479}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001480
1481extern int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
1482 struct be_dma_mem *nonemb_cmd)
1483{
1484 struct be_mcc_wrb *wrb;
1485 struct be_cmd_req_acpi_wol_magic_config *req;
1486 struct be_sge *sge;
1487 int status;
1488
1489 spin_lock_bh(&adapter->mcc_lock);
1490
1491 wrb = wrb_from_mccq(adapter);
1492 if (!wrb) {
1493 status = -EBUSY;
1494 goto err;
1495 }
1496 req = nonemb_cmd->va;
1497 sge = nonembedded_sgl(wrb);
1498
1499 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1500 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
1501
1502 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1503 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
1504 memcpy(req->magic_mac, mac, ETH_ALEN);
1505
1506 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1507 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1508 sge->len = cpu_to_le32(nonemb_cmd->size);
1509
1510 status = be_mcc_notify_wait(adapter);
1511
1512err:
1513 spin_unlock_bh(&adapter->mcc_lock);
1514 return status;
1515}
Suresh Rff33a6e2009-12-03 16:15:52 -08001516
Sarveshwar Bandifced9992009-12-23 04:41:44 +00001517int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
1518 u8 loopback_type, u8 enable)
1519{
1520 struct be_mcc_wrb *wrb;
1521 struct be_cmd_req_set_lmode *req;
1522 int status;
1523
1524 spin_lock_bh(&adapter->mcc_lock);
1525
1526 wrb = wrb_from_mccq(adapter);
1527 if (!wrb) {
1528 status = -EBUSY;
1529 goto err;
1530 }
1531
1532 req = embedded_payload(wrb);
1533
1534 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1535 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
1536
1537 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1538 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
1539 sizeof(*req));
1540
1541 req->src_port = port_num;
1542 req->dest_port = port_num;
1543 req->loopback_type = loopback_type;
1544 req->loopback_state = enable;
1545
1546 status = be_mcc_notify_wait(adapter);
1547err:
1548 spin_unlock_bh(&adapter->mcc_lock);
1549 return status;
1550}
1551
Suresh Rff33a6e2009-12-03 16:15:52 -08001552int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
1553 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
1554{
1555 struct be_mcc_wrb *wrb;
1556 struct be_cmd_req_loopback_test *req;
1557 int status;
1558
1559 spin_lock_bh(&adapter->mcc_lock);
1560
1561 wrb = wrb_from_mccq(adapter);
1562 if (!wrb) {
1563 status = -EBUSY;
1564 goto err;
1565 }
1566
1567 req = embedded_payload(wrb);
1568
1569 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1570 OPCODE_LOWLEVEL_LOOPBACK_TEST);
1571
1572 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1573 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
Sarveshwar Bandid7b90142009-12-23 04:40:36 +00001574 req->hdr.timeout = 4;
Suresh Rff33a6e2009-12-03 16:15:52 -08001575
1576 req->pattern = cpu_to_le64(pattern);
1577 req->src_port = cpu_to_le32(port_num);
1578 req->dest_port = cpu_to_le32(port_num);
1579 req->pkt_size = cpu_to_le32(pkt_size);
1580 req->num_pkts = cpu_to_le32(num_pkts);
1581 req->loopback_type = cpu_to_le32(loopback_type);
1582
1583 status = be_mcc_notify_wait(adapter);
1584 if (!status) {
1585 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
1586 status = le32_to_cpu(resp->status);
1587 }
1588
1589err:
1590 spin_unlock_bh(&adapter->mcc_lock);
1591 return status;
1592}
1593
1594int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
1595 u32 byte_cnt, struct be_dma_mem *cmd)
1596{
1597 struct be_mcc_wrb *wrb;
1598 struct be_cmd_req_ddrdma_test *req;
1599 struct be_sge *sge;
1600 int status;
1601 int i, j = 0;
1602
1603 spin_lock_bh(&adapter->mcc_lock);
1604
1605 wrb = wrb_from_mccq(adapter);
1606 if (!wrb) {
1607 status = -EBUSY;
1608 goto err;
1609 }
1610 req = cmd->va;
1611 sge = nonembedded_sgl(wrb);
1612 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1613 OPCODE_LOWLEVEL_HOST_DDR_DMA);
1614 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1615 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
1616
1617 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1618 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1619 sge->len = cpu_to_le32(cmd->size);
1620
1621 req->pattern = cpu_to_le64(pattern);
1622 req->byte_count = cpu_to_le32(byte_cnt);
1623 for (i = 0; i < byte_cnt; i++) {
1624 req->snd_buff[i] = (u8)(pattern >> (j*8));
1625 j++;
1626 if (j > 7)
1627 j = 0;
1628 }
1629
1630 status = be_mcc_notify_wait(adapter);
1631
1632 if (!status) {
1633 struct be_cmd_resp_ddrdma_test *resp;
1634 resp = cmd->va;
1635 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
1636 resp->snd_err) {
1637 status = -1;
1638 }
1639 }
1640
1641err:
1642 spin_unlock_bh(&adapter->mcc_lock);
1643 return status;
1644}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001645
1646extern int be_cmd_get_seeprom_data(struct be_adapter *adapter,
1647 struct be_dma_mem *nonemb_cmd)
1648{
1649 struct be_mcc_wrb *wrb;
1650 struct be_cmd_req_seeprom_read *req;
1651 struct be_sge *sge;
1652 int status;
1653
1654 spin_lock_bh(&adapter->mcc_lock);
1655
1656 wrb = wrb_from_mccq(adapter);
1657 req = nonemb_cmd->va;
1658 sge = nonembedded_sgl(wrb);
1659
1660 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1661 OPCODE_COMMON_SEEPROM_READ);
1662
1663 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1664 OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
1665
1666 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1667 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1668 sge->len = cpu_to_le32(nonemb_cmd->size);
1669
1670 status = be_mcc_notify_wait(adapter);
1671
1672 spin_unlock_bh(&adapter->mcc_lock);
1673 return status;
1674}