blob: 808ad0dd4115a9d754d5062b9b690ab33617c05a [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
2 * Copyright (C) 2005 - 2009 ServerEngines
3 * 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,
74 "Error in cmd completion: status(compl/extd)=%d/%d\n",
Sathya Perla5fb379e2009-06-18 00:02:59 +000075 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 Perlaa8f447b2009-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 Perlaa8f447b2009-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 Perlaa8f447b2009-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 Perlab31c50a2009-09-17 10:30:13 -0700107int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000108{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000109 struct be_mcc_compl *compl;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700110 int num = 0, status = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000111
Sathya Perla8788fdc2009-07-27 22:52:03 +0000112 spin_lock_bh(&adapter->mcc_cq_lock);
113 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000114 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
115 /* Interpret flags as an async trailer */
116 BUG_ON(!is_link_state_evt(compl->flags));
117
118 /* Interpret compl as a async link evt */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000119 be_async_link_state_process(adapter,
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000120 (struct be_async_event_link_state *) compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700121 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
122 status = be_mcc_compl_process(adapter, compl);
123 atomic_dec(&adapter->mcc_obj.q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000124 }
125 be_mcc_compl_use(compl);
126 num++;
127 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700128
Sathya Perla5fb379e2009-06-18 00:02:59 +0000129 if (num)
Sathya Perla8788fdc2009-07-27 22:52:03 +0000130 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, num);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700131
Sathya Perla8788fdc2009-07-27 22:52:03 +0000132 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700133 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000134}
135
Sathya Perla6ac7b682009-06-18 00:05:54 +0000136/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700137static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000138{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700139#define mcc_timeout 120000 /* 12s timeout */
140 int i, status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000141 for (i = 0; i < mcc_timeout; i++) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700142 status = be_process_mcc(adapter);
143 if (status)
144 return status;
145
Sathya Perla8788fdc2009-07-27 22:52:03 +0000146 if (atomic_read(&adapter->mcc_obj.q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000147 break;
148 udelay(100);
149 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700150 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000151 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700152 return -1;
153 }
154 return 0;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000155}
156
157/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700158static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000159{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000160 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700161 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000162}
163
Sathya Perla5f0b8492009-07-27 22:52:56 +0000164static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700165{
166 int cnt = 0, wait = 5;
167 u32 ready;
168
169 do {
170 ready = ioread32(db) & MPU_MAILBOX_DB_RDY_MASK;
171 if (ready)
172 break;
173
Ajit Khaparde84517482009-09-04 03:12:16 +0000174 if (cnt > 4000000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000175 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700176 return -1;
177 }
178
179 if (cnt > 50)
180 wait = 200;
181 cnt += wait;
182 udelay(wait);
183 } while (true);
184
185 return 0;
186}
187
188/*
189 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000190 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700191 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700192static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700193{
194 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700195 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000196 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
197 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700198 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000199 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700200
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700201 val |= MPU_MAILBOX_DB_HI_MASK;
202 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
203 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
204 iowrite32(val, db);
205
206 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000207 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700208 if (status != 0)
209 return status;
210
211 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700212 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
213 val |= (u32)(mbox_mem->dma >> 4) << 2;
214 iowrite32(val, db);
215
Sathya Perla5f0b8492009-07-27 22:52:56 +0000216 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700217 if (status != 0)
218 return status;
219
Sathya Perla5fb379e2009-06-18 00:02:59 +0000220 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000221 if (be_mcc_compl_is_new(compl)) {
222 status = be_mcc_compl_process(adapter, &mbox->compl);
223 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000224 if (status)
225 return status;
226 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000227 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700228 return -1;
229 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000230 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700231}
232
Sathya Perla8788fdc2009-07-27 22:52:03 +0000233static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700234{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000235 u32 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700236
237 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
238 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
239 return -1;
240 else
241 return 0;
242}
243
Sathya Perla8788fdc2009-07-27 22:52:03 +0000244int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700245{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000246 u16 stage;
247 int status, timeout = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700248
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000249 do {
250 status = be_POST_stage_get(adapter, &stage);
251 if (status) {
252 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
253 stage);
254 return -1;
255 } else if (stage != POST_STAGE_ARMFW_RDY) {
256 set_current_state(TASK_INTERRUPTIBLE);
257 schedule_timeout(2 * HZ);
258 timeout += 2;
259 } else {
260 return 0;
261 }
262 } while (timeout < 20);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700263
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000264 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
265 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700266}
267
268static inline void *embedded_payload(struct be_mcc_wrb *wrb)
269{
270 return wrb->payload.embedded_payload;
271}
272
273static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
274{
275 return &wrb->payload.sgl[0];
276}
277
278/* Don't touch the hdr after it's prepared */
279static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
280 bool embedded, u8 sge_cnt)
281{
282 if (embedded)
283 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
284 else
285 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
286 MCC_WRB_SGE_CNT_SHIFT;
287 wrb->payload_length = payload_len;
288 be_dws_cpu_to_le(wrb, 20);
289}
290
291/* Don't touch the hdr after it's prepared */
292static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
293 u8 subsystem, u8 opcode, int cmd_len)
294{
295 req_hdr->opcode = opcode;
296 req_hdr->subsystem = subsystem;
297 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
298}
299
300static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
301 struct be_dma_mem *mem)
302{
303 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
304 u64 dma = (u64)mem->dma;
305
306 for (i = 0; i < buf_pages; i++) {
307 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
308 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
309 dma += PAGE_SIZE_4K;
310 }
311}
312
313/* Converts interrupt delay in microseconds to multiplier value */
314static u32 eq_delay_to_mult(u32 usec_delay)
315{
316#define MAX_INTR_RATE 651042
317 const u32 round = 10;
318 u32 multiplier;
319
320 if (usec_delay == 0)
321 multiplier = 0;
322 else {
323 u32 interrupt_rate = 1000000 / usec_delay;
324 /* Max delay, corresponding to the lowest interrupt rate */
325 if (interrupt_rate == 0)
326 multiplier = 1023;
327 else {
328 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
329 multiplier /= interrupt_rate;
330 /* Round the multiplier to the closest value.*/
331 multiplier = (multiplier + round/2) / round;
332 multiplier = min(multiplier, (u32)1023);
333 }
334 }
335 return multiplier;
336}
337
Sathya Perlab31c50a2009-09-17 10:30:13 -0700338static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700339{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700340 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
341 struct be_mcc_wrb *wrb
342 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
343 memset(wrb, 0, sizeof(*wrb));
344 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700345}
346
Sathya Perlab31c50a2009-09-17 10:30:13 -0700347static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000348{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700349 struct be_queue_info *mccq = &adapter->mcc_obj.q;
350 struct be_mcc_wrb *wrb;
351
352 BUG_ON(atomic_read(&mccq->used) >= mccq->len);
353 wrb = queue_head_node(mccq);
354 queue_head_inc(mccq);
355 atomic_inc(&mccq->used);
356 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000357 return wrb;
358}
359
Sathya Perla8788fdc2009-07-27 22:52:03 +0000360int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700361 struct be_queue_info *eq, int eq_delay)
362{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700363 struct be_mcc_wrb *wrb;
364 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700365 struct be_dma_mem *q_mem = &eq->dma_mem;
366 int status;
367
Sathya Perla8788fdc2009-07-27 22:52:03 +0000368 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700369
370 wrb = wrb_from_mbox(adapter);
371 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700372
373 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
374
375 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
376 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
377
378 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
379
380 AMAP_SET_BITS(struct amap_eq_context, func, req->context,
Sathya Perlaeec368f2009-07-27 22:52:23 +0000381 be_pci_func(adapter));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700382 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
383 /* 4byte eqe*/
384 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
385 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
386 __ilog2_u32(eq->len/256));
387 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
388 eq_delay_to_mult(eq_delay));
389 be_dws_cpu_to_le(req->context, sizeof(req->context));
390
391 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
392
Sathya Perlab31c50a2009-09-17 10:30:13 -0700393 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700394 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700395 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700396 eq->id = le16_to_cpu(resp->eq_id);
397 eq->created = true;
398 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700399
Sathya Perla8788fdc2009-07-27 22:52:03 +0000400 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700401 return status;
402}
403
Sathya Perlab31c50a2009-09-17 10:30:13 -0700404/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000405int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700406 u8 type, bool permanent, u32 if_handle)
407{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700408 struct be_mcc_wrb *wrb;
409 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700410 int status;
411
Sathya Perla8788fdc2009-07-27 22:52:03 +0000412 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700413
414 wrb = wrb_from_mbox(adapter);
415 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700416
417 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
418
419 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
420 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
421
422 req->type = type;
423 if (permanent) {
424 req->permanent = 1;
425 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700426 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700427 req->permanent = 0;
428 }
429
Sathya Perlab31c50a2009-09-17 10:30:13 -0700430 status = be_mbox_notify_wait(adapter);
431 if (!status) {
432 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700433 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700434 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700435
Sathya Perla8788fdc2009-07-27 22:52:03 +0000436 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700437 return status;
438}
439
Sathya Perlab31c50a2009-09-17 10:30:13 -0700440/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000441int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700442 u32 if_id, u32 *pmac_id)
443{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700444 struct be_mcc_wrb *wrb;
445 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700446 int status;
447
Sathya Perlab31c50a2009-09-17 10:30:13 -0700448 spin_lock_bh(&adapter->mcc_lock);
449
450 wrb = wrb_from_mccq(adapter);
451 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700452
453 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
454
455 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
456 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
457
458 req->if_id = cpu_to_le32(if_id);
459 memcpy(req->mac_address, mac_addr, ETH_ALEN);
460
Sathya Perlab31c50a2009-09-17 10:30:13 -0700461 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700462 if (!status) {
463 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
464 *pmac_id = le32_to_cpu(resp->pmac_id);
465 }
466
Sathya Perlab31c50a2009-09-17 10:30:13 -0700467 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700468 return status;
469}
470
Sathya Perlab31c50a2009-09-17 10:30:13 -0700471/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000472int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700473{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700474 struct be_mcc_wrb *wrb;
475 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700476 int status;
477
Sathya Perlab31c50a2009-09-17 10:30:13 -0700478 spin_lock_bh(&adapter->mcc_lock);
479
480 wrb = wrb_from_mccq(adapter);
481 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700482
483 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
484
485 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
486 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
487
488 req->if_id = cpu_to_le32(if_id);
489 req->pmac_id = cpu_to_le32(pmac_id);
490
Sathya Perlab31c50a2009-09-17 10:30:13 -0700491 status = be_mcc_notify_wait(adapter);
492
493 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700494
495 return status;
496}
497
Sathya Perlab31c50a2009-09-17 10:30:13 -0700498/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000499int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700500 struct be_queue_info *cq, struct be_queue_info *eq,
501 bool sol_evts, bool no_delay, int coalesce_wm)
502{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700503 struct be_mcc_wrb *wrb;
504 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700505 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700506 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700507 int status;
508
Sathya Perla8788fdc2009-07-27 22:52:03 +0000509 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700510
511 wrb = wrb_from_mbox(adapter);
512 req = embedded_payload(wrb);
513 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700514
515 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
516
517 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
518 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
519
520 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
521
522 AMAP_SET_BITS(struct amap_cq_context, coalescwm, ctxt, coalesce_wm);
523 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
524 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
525 __ilog2_u32(cq->len/256));
526 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
527 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
528 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
529 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000530 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
Sathya Perlaeec368f2009-07-27 22:52:23 +0000531 AMAP_SET_BITS(struct amap_cq_context, func, ctxt, be_pci_func(adapter));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700532 be_dws_cpu_to_le(ctxt, sizeof(req->context));
533
534 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
535
Sathya Perlab31c50a2009-09-17 10:30:13 -0700536 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700537 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700538 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700539 cq->id = le16_to_cpu(resp->cq_id);
540 cq->created = true;
541 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700542
Sathya Perla8788fdc2009-07-27 22:52:03 +0000543 spin_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000544
545 return status;
546}
547
548static u32 be_encoded_q_len(int q_len)
549{
550 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
551 if (len_encoded == 16)
552 len_encoded = 0;
553 return len_encoded;
554}
555
Sathya Perla8788fdc2009-07-27 22:52:03 +0000556int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000557 struct be_queue_info *mccq,
558 struct be_queue_info *cq)
559{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700560 struct be_mcc_wrb *wrb;
561 struct be_cmd_req_mcc_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000562 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700563 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000564 int status;
565
Sathya Perla8788fdc2009-07-27 22:52:03 +0000566 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700567
568 wrb = wrb_from_mbox(adapter);
569 req = embedded_payload(wrb);
570 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000571
572 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
573
574 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
575 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
576
577 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
578
Sathya Perlaeec368f2009-07-27 22:52:23 +0000579 AMAP_SET_BITS(struct amap_mcc_context, fid, ctxt, be_pci_func(adapter));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000580 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
581 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
582 be_encoded_q_len(mccq->len));
583 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
584
585 be_dws_cpu_to_le(ctxt, sizeof(req->context));
586
587 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
588
Sathya Perlab31c50a2009-09-17 10:30:13 -0700589 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000590 if (!status) {
591 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
592 mccq->id = le16_to_cpu(resp->id);
593 mccq->created = true;
594 }
Sathya Perla8788fdc2009-07-27 22:52:03 +0000595 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700596
597 return status;
598}
599
Sathya Perla8788fdc2009-07-27 22:52:03 +0000600int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700601 struct be_queue_info *txq,
602 struct be_queue_info *cq)
603{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700604 struct be_mcc_wrb *wrb;
605 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700606 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700607 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700608 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700609
Sathya Perla8788fdc2009-07-27 22:52:03 +0000610 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700611
612 wrb = wrb_from_mbox(adapter);
613 req = embedded_payload(wrb);
614 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700615
616 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
617
618 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
619 sizeof(*req));
620
621 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
622 req->ulp_num = BE_ULP1_NUM;
623 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
624
Sathya Perlab31c50a2009-09-17 10:30:13 -0700625 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
626 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700627 AMAP_SET_BITS(struct amap_tx_context, pci_func_id, ctxt,
Sathya Perlaeec368f2009-07-27 22:52:23 +0000628 be_pci_func(adapter));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700629 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
630 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
631
632 be_dws_cpu_to_le(ctxt, sizeof(req->context));
633
634 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
635
Sathya Perlab31c50a2009-09-17 10:30:13 -0700636 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700637 if (!status) {
638 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
639 txq->id = le16_to_cpu(resp->cid);
640 txq->created = true;
641 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700642
Sathya Perla8788fdc2009-07-27 22:52:03 +0000643 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700644
645 return status;
646}
647
Sathya Perlab31c50a2009-09-17 10:30:13 -0700648/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000649int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700650 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
651 u16 max_frame_size, u32 if_id, u32 rss)
652{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700653 struct be_mcc_wrb *wrb;
654 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700655 struct be_dma_mem *q_mem = &rxq->dma_mem;
656 int status;
657
Sathya Perla8788fdc2009-07-27 22:52:03 +0000658 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700659
660 wrb = wrb_from_mbox(adapter);
661 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700662
663 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
664
665 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
666 sizeof(*req));
667
668 req->cq_id = cpu_to_le16(cq_id);
669 req->frag_size = fls(frag_size) - 1;
670 req->num_pages = 2;
671 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
672 req->interface_id = cpu_to_le32(if_id);
673 req->max_frame_size = cpu_to_le16(max_frame_size);
674 req->rss_queue = cpu_to_le32(rss);
675
Sathya Perlab31c50a2009-09-17 10:30:13 -0700676 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677 if (!status) {
678 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
679 rxq->id = le16_to_cpu(resp->id);
680 rxq->created = true;
681 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700682
Sathya Perla8788fdc2009-07-27 22:52:03 +0000683 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700684
685 return status;
686}
687
Sathya Perlab31c50a2009-09-17 10:30:13 -0700688/* Generic destroyer function for all types of queues
689 * Uses Mbox
690 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000691int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700692 int queue_type)
693{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700694 struct be_mcc_wrb *wrb;
695 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700696 u8 subsys = 0, opcode = 0;
697 int status;
698
Sathya Perla8788fdc2009-07-27 22:52:03 +0000699 spin_lock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700700
Sathya Perlab31c50a2009-09-17 10:30:13 -0700701 wrb = wrb_from_mbox(adapter);
702 req = embedded_payload(wrb);
703
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700704 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
705
706 switch (queue_type) {
707 case QTYPE_EQ:
708 subsys = CMD_SUBSYSTEM_COMMON;
709 opcode = OPCODE_COMMON_EQ_DESTROY;
710 break;
711 case QTYPE_CQ:
712 subsys = CMD_SUBSYSTEM_COMMON;
713 opcode = OPCODE_COMMON_CQ_DESTROY;
714 break;
715 case QTYPE_TXQ:
716 subsys = CMD_SUBSYSTEM_ETH;
717 opcode = OPCODE_ETH_TX_DESTROY;
718 break;
719 case QTYPE_RXQ:
720 subsys = CMD_SUBSYSTEM_ETH;
721 opcode = OPCODE_ETH_RX_DESTROY;
722 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000723 case QTYPE_MCCQ:
724 subsys = CMD_SUBSYSTEM_COMMON;
725 opcode = OPCODE_COMMON_MCC_DESTROY;
726 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700727 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +0000728 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700729 }
730 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
731 req->id = cpu_to_le16(q->id);
732
Sathya Perlab31c50a2009-09-17 10:30:13 -0700733 status = be_mbox_notify_wait(adapter);
Sathya Perla5f0b8492009-07-27 22:52:56 +0000734
Sathya Perla8788fdc2009-07-27 22:52:03 +0000735 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700736
737 return status;
738}
739
Sathya Perlab31c50a2009-09-17 10:30:13 -0700740/* Create an rx filtering policy configuration on an i/f
741 * Uses mbox
742 */
Sathya Perla73d540f2009-10-14 20:20:42 +0000743int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
744 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700745{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700746 struct be_mcc_wrb *wrb;
747 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700748 int status;
749
Sathya Perla8788fdc2009-07-27 22:52:03 +0000750 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700751
752 wrb = wrb_from_mbox(adapter);
753 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700754
755 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
756
757 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
758 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
759
Sathya Perla73d540f2009-10-14 20:20:42 +0000760 req->capability_flags = cpu_to_le32(cap_flags);
761 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700762 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700763 if (!pmac_invalid)
764 memcpy(req->mac_addr, mac, ETH_ALEN);
765
Sathya Perlab31c50a2009-09-17 10:30:13 -0700766 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700767 if (!status) {
768 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
769 *if_handle = le32_to_cpu(resp->interface_id);
770 if (!pmac_invalid)
771 *pmac_id = le32_to_cpu(resp->pmac_id);
772 }
773
Sathya Perla8788fdc2009-07-27 22:52:03 +0000774 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700775 return status;
776}
777
Sathya Perlab31c50a2009-09-17 10:30:13 -0700778/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000779int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700780{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700781 struct be_mcc_wrb *wrb;
782 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700783 int status;
784
Sathya Perla8788fdc2009-07-27 22:52:03 +0000785 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700786
787 wrb = wrb_from_mbox(adapter);
788 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700789
790 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
791
792 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
793 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
794
795 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700796
797 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700798
Sathya Perla8788fdc2009-07-27 22:52:03 +0000799 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700800
801 return status;
802}
803
804/* Get stats is a non embedded command: the request is not embedded inside
805 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -0700806 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700807 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000808int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700809{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700810 struct be_mcc_wrb *wrb;
811 struct be_cmd_req_get_stats *req;
812 struct be_sge *sge;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700813
Sathya Perlab31c50a2009-09-17 10:30:13 -0700814 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700815
Sathya Perlab31c50a2009-09-17 10:30:13 -0700816 wrb = wrb_from_mccq(adapter);
817 req = nonemb_cmd->va;
818 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700819
820 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700821 wrb->tag0 = OPCODE_ETH_GET_STATISTICS;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700822
823 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
824 OPCODE_ETH_GET_STATISTICS, sizeof(*req));
825 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
826 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
827 sge->len = cpu_to_le32(nonemb_cmd->size);
828
Sathya Perlab31c50a2009-09-17 10:30:13 -0700829 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700830
Sathya Perlab31c50a2009-09-17 10:30:13 -0700831 spin_unlock_bh(&adapter->mcc_lock);
832 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700833}
834
Sathya Perlab31c50a2009-09-17 10:30:13 -0700835/* Uses synchronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000836int be_cmd_link_status_query(struct be_adapter *adapter,
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700837 bool *link_up, u8 *mac_speed, u16 *link_speed)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700838{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700839 struct be_mcc_wrb *wrb;
840 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700841 int status;
842
Sathya Perlab31c50a2009-09-17 10:30:13 -0700843 spin_lock_bh(&adapter->mcc_lock);
844
845 wrb = wrb_from_mccq(adapter);
846 req = embedded_payload(wrb);
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000847
848 *link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700849
850 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
851
852 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
853 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
854
Sathya Perlab31c50a2009-09-17 10:30:13 -0700855 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700856 if (!status) {
857 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700858 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000859 *link_up = true;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700860 *link_speed = le16_to_cpu(resp->link_speed);
861 *mac_speed = resp->mac_speed;
862 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700863 }
864
Sathya Perlab31c50a2009-09-17 10:30:13 -0700865 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700866 return status;
867}
868
Sathya Perlab31c50a2009-09-17 10:30:13 -0700869/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000870int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700871{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700872 struct be_mcc_wrb *wrb;
873 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700874 int status;
875
Sathya Perla8788fdc2009-07-27 22:52:03 +0000876 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700877
878 wrb = wrb_from_mbox(adapter);
879 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700880
881 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
882
883 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
884 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
885
Sathya Perlab31c50a2009-09-17 10:30:13 -0700886 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700887 if (!status) {
888 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
889 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
890 }
891
Sathya Perla8788fdc2009-07-27 22:52:03 +0000892 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700893 return status;
894}
895
Sathya Perlab31c50a2009-09-17 10:30:13 -0700896/* set the EQ delay interval of an EQ to specified value
897 * Uses async mcc
898 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000899int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700900{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700901 struct be_mcc_wrb *wrb;
902 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700903
Sathya Perlab31c50a2009-09-17 10:30:13 -0700904 spin_lock_bh(&adapter->mcc_lock);
905
906 wrb = wrb_from_mccq(adapter);
907 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700908
909 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
910
911 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
912 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
913
914 req->num_eq = cpu_to_le32(1);
915 req->delay[0].eq_id = cpu_to_le32(eq_id);
916 req->delay[0].phase = 0;
917 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
918
Sathya Perlab31c50a2009-09-17 10:30:13 -0700919 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700920
Sathya Perlab31c50a2009-09-17 10:30:13 -0700921 spin_unlock_bh(&adapter->mcc_lock);
922 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700923}
924
Sathya Perlab31c50a2009-09-17 10:30:13 -0700925/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000926int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700927 u32 num, bool untagged, bool promiscuous)
928{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700929 struct be_mcc_wrb *wrb;
930 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700931 int status;
932
Sathya Perlab31c50a2009-09-17 10:30:13 -0700933 spin_lock_bh(&adapter->mcc_lock);
934
935 wrb = wrb_from_mccq(adapter);
936 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700937
938 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
939
940 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
941 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
942
943 req->interface_id = if_id;
944 req->promiscuous = promiscuous;
945 req->untagged = untagged;
946 req->num_vlan = num;
947 if (!promiscuous) {
948 memcpy(req->normal_vlan, vtag_array,
949 req->num_vlan * sizeof(vtag_array[0]));
950 }
951
Sathya Perlab31c50a2009-09-17 10:30:13 -0700952 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700953
Sathya Perlab31c50a2009-09-17 10:30:13 -0700954 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700955 return status;
956}
957
Sathya Perlab31c50a2009-09-17 10:30:13 -0700958/* Uses MCC for this command as it may be called in BH context
959 * Uses synchronous mcc
960 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000961int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700962{
Sathya Perla6ac7b682009-06-18 00:05:54 +0000963 struct be_mcc_wrb *wrb;
964 struct be_cmd_req_promiscuous_config *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700965 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700966
Sathya Perla8788fdc2009-07-27 22:52:03 +0000967 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000968
Sathya Perlab31c50a2009-09-17 10:30:13 -0700969 wrb = wrb_from_mccq(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000970 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700971
972 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
973
974 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
975 OPCODE_ETH_PROMISCUOUS, sizeof(*req));
976
977 if (port_num)
978 req->port1_promiscuous = en;
979 else
980 req->port0_promiscuous = en;
981
Sathya Perlab31c50a2009-09-17 10:30:13 -0700982 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700983
Sathya Perla8788fdc2009-07-27 22:52:03 +0000984 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700985 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700986}
987
Sathya Perla6ac7b682009-06-18 00:05:54 +0000988/*
Sathya Perlab31c50a2009-09-17 10:30:13 -0700989 * Uses MCC for this command as it may be called in BH context
Sathya Perla6ac7b682009-06-18 00:05:54 +0000990 * (mc == NULL) => multicast promiscous
991 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000992int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
Sathya Perla24307ee2009-06-18 00:09:25 +0000993 struct dev_mc_list *mc_list, u32 mc_count)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700994{
Sathya Perla6ac7b682009-06-18 00:05:54 +0000995#define BE_MAX_MC 32 /* set mcast promisc if > 32 */
996 struct be_mcc_wrb *wrb;
997 struct be_cmd_req_mcast_mac_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700998
Sathya Perla8788fdc2009-07-27 22:52:03 +0000999 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001000
Sathya Perlab31c50a2009-09-17 10:30:13 -07001001 wrb = wrb_from_mccq(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001002 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001003
1004 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1005
1006 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1007 OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
1008
1009 req->interface_id = if_id;
Sathya Perla24307ee2009-06-18 00:09:25 +00001010 if (mc_list && mc_count <= BE_MAX_MC) {
1011 int i;
1012 struct dev_mc_list *mc;
1013
1014 req->num_mac = cpu_to_le16(mc_count);
1015
1016 for (mc = mc_list, i = 0; mc; mc = mc->next, i++)
1017 memcpy(req->mac[i].byte, mc->dmi_addr, ETH_ALEN);
1018 } else {
1019 req->promiscuous = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001020 }
1021
Sathya Perla8788fdc2009-07-27 22:52:03 +00001022 be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001023
Sathya Perla8788fdc2009-07-27 22:52:03 +00001024 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001025
1026 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027}
1028
Sathya Perlab31c50a2009-09-17 10:30:13 -07001029/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001030int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001031{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001032 struct be_mcc_wrb *wrb;
1033 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001034 int status;
1035
Sathya Perlab31c50a2009-09-17 10:30:13 -07001036 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001037
Sathya Perlab31c50a2009-09-17 10:30:13 -07001038 wrb = wrb_from_mccq(adapter);
1039 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001040
1041 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1042
1043 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1044 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1045
1046 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1047 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1048
Sathya Perlab31c50a2009-09-17 10:30:13 -07001049 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001050
Sathya Perlab31c50a2009-09-17 10:30:13 -07001051 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001052 return status;
1053}
1054
Sathya Perlab31c50a2009-09-17 10:30:13 -07001055/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001056int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001057{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001058 struct be_mcc_wrb *wrb;
1059 struct be_cmd_req_get_flow_control *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);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001063
Sathya Perlab31c50a2009-09-17 10:30:13 -07001064 wrb = wrb_from_mccq(adapter);
1065 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001066
1067 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1068
1069 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1070 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1071
Sathya Perlab31c50a2009-09-17 10:30:13 -07001072 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001073 if (!status) {
1074 struct be_cmd_resp_get_flow_control *resp =
1075 embedded_payload(wrb);
1076 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1077 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1078 }
1079
Sathya Perlab31c50a2009-09-17 10:30:13 -07001080 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001081 return status;
1082}
1083
Sathya Perlab31c50a2009-09-17 10:30:13 -07001084/* Uses mbox */
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001085int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num, u32 *cap)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001086{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001087 struct be_mcc_wrb *wrb;
1088 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001089 int status;
1090
Sathya Perla8788fdc2009-07-27 22:52:03 +00001091 spin_lock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001092
Sathya Perlab31c50a2009-09-17 10:30:13 -07001093 wrb = wrb_from_mbox(adapter);
1094 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001095
1096 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1097
1098 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1099 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1100
Sathya Perlab31c50a2009-09-17 10:30:13 -07001101 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102 if (!status) {
1103 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1104 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001105 *cap = le32_to_cpu(resp->function_cap);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001106 }
1107
Sathya Perla8788fdc2009-07-27 22:52:03 +00001108 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001109 return status;
1110}
sarveshwarb14074ea2009-08-05 13:05:24 -07001111
Sathya Perlab31c50a2009-09-17 10:30:13 -07001112/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001113int be_cmd_reset_function(struct be_adapter *adapter)
1114{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001115 struct be_mcc_wrb *wrb;
1116 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001117 int status;
1118
1119 spin_lock(&adapter->mbox_lock);
1120
Sathya Perlab31c50a2009-09-17 10:30:13 -07001121 wrb = wrb_from_mbox(adapter);
1122 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001123
1124 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1125
1126 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1127 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1128
Sathya Perlab31c50a2009-09-17 10:30:13 -07001129 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001130
1131 spin_unlock(&adapter->mbox_lock);
1132 return status;
1133}
Ajit Khaparde84517482009-09-04 03:12:16 +00001134
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001135/* Uses sync mcc */
1136int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1137 u8 bcn, u8 sts, u8 state)
1138{
1139 struct be_mcc_wrb *wrb;
1140 struct be_cmd_req_enable_disable_beacon *req;
1141 int status;
1142
1143 spin_lock_bh(&adapter->mcc_lock);
1144
1145 wrb = wrb_from_mccq(adapter);
1146 req = embedded_payload(wrb);
1147
1148 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1149
1150 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1151 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1152
1153 req->port_num = port_num;
1154 req->beacon_state = state;
1155 req->beacon_duration = bcn;
1156 req->status_duration = sts;
1157
1158 status = be_mcc_notify_wait(adapter);
1159
1160 spin_unlock_bh(&adapter->mcc_lock);
1161 return status;
1162}
1163
1164/* Uses sync mcc */
1165int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1166{
1167 struct be_mcc_wrb *wrb;
1168 struct be_cmd_req_get_beacon_state *req;
1169 int status;
1170
1171 spin_lock_bh(&adapter->mcc_lock);
1172
1173 wrb = wrb_from_mccq(adapter);
1174 req = embedded_payload(wrb);
1175
1176 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1177
1178 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1179 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1180
1181 req->port_num = port_num;
1182
1183 status = be_mcc_notify_wait(adapter);
1184 if (!status) {
1185 struct be_cmd_resp_get_beacon_state *resp =
1186 embedded_payload(wrb);
1187 *state = resp->beacon_state;
1188 }
1189
1190 spin_unlock_bh(&adapter->mcc_lock);
1191 return status;
1192}
1193
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001194/* Uses sync mcc */
1195int be_cmd_read_port_type(struct be_adapter *adapter, u32 port,
1196 u8 *connector)
1197{
1198 struct be_mcc_wrb *wrb;
1199 struct be_cmd_req_port_type *req;
1200 int status;
1201
1202 spin_lock_bh(&adapter->mcc_lock);
1203
1204 wrb = wrb_from_mccq(adapter);
1205 req = embedded_payload(wrb);
1206
1207 be_wrb_hdr_prepare(wrb, sizeof(struct be_cmd_resp_port_type), true, 0);
1208
1209 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1210 OPCODE_COMMON_READ_TRANSRECV_DATA, sizeof(*req));
1211
1212 req->port = cpu_to_le32(port);
1213 req->page_num = cpu_to_le32(TR_PAGE_A0);
1214 status = be_mcc_notify_wait(adapter);
1215 if (!status) {
1216 struct be_cmd_resp_port_type *resp = embedded_payload(wrb);
1217 *connector = resp->data.connector;
1218 }
1219
1220 spin_unlock_bh(&adapter->mcc_lock);
1221 return status;
1222}
1223
Ajit Khaparde84517482009-09-04 03:12:16 +00001224int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1225 u32 flash_type, u32 flash_opcode, u32 buf_size)
1226{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001227 struct be_mcc_wrb *wrb;
Ajit Khaparde84517482009-09-04 03:12:16 +00001228 struct be_cmd_write_flashrom *req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001229 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001230 int status;
1231
Sathya Perlab31c50a2009-09-17 10:30:13 -07001232 spin_lock_bh(&adapter->mcc_lock);
1233
1234 wrb = wrb_from_mccq(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001235 sge = nonembedded_sgl(wrb);
1236
Ajit Khaparde84517482009-09-04 03:12:16 +00001237 be_wrb_hdr_prepare(wrb, cmd->size, false, 1);
1238
1239 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1240 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1241 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1242 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1243 sge->len = cpu_to_le32(cmd->size);
1244
1245 req->params.op_type = cpu_to_le32(flash_type);
1246 req->params.op_code = cpu_to_le32(flash_opcode);
1247 req->params.data_buf_size = cpu_to_le32(buf_size);
1248
Sathya Perlab31c50a2009-09-17 10:30:13 -07001249 status = be_mcc_notify_wait(adapter);
Ajit Khaparde84517482009-09-04 03:12:16 +00001250
Sathya Perlab31c50a2009-09-17 10:30:13 -07001251 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001252 return status;
1253}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001254
1255int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc)
1256{
1257 struct be_mcc_wrb *wrb;
1258 struct be_cmd_write_flashrom *req;
1259 int status;
1260
1261 spin_lock_bh(&adapter->mcc_lock);
1262
1263 wrb = wrb_from_mccq(adapter);
1264 req = embedded_payload(wrb);
1265
1266 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0);
1267
1268 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1269 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1270
1271 req->params.op_type = cpu_to_le32(FLASHROM_TYPE_REDBOOT);
1272 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
1273 req->params.offset = 0x3FFFC;
1274 req->params.data_buf_size = 0x4;
1275
1276 status = be_mcc_notify_wait(adapter);
1277 if (!status)
1278 memcpy(flashed_crc, req->params.data_buf, 4);
1279
1280 spin_unlock_bh(&adapter->mcc_lock);
1281 return status;
1282}