blob: 344e062b7f25edad262ac4edc3acc2f29ac9ea36 [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 Perlaf3eb62d2010-06-29 00:11:17 +000028
29 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000030 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000031}
32
33/* To check if valid bit is set, check the entire word as we don't know
34 * the endianness of the data (old entry is host endian while a new entry is
35 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000036static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000037{
38 if (compl->flags != 0) {
39 compl->flags = le32_to_cpu(compl->flags);
40 BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
41 return true;
42 } else {
43 return false;
44 }
45}
46
47/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +000048static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000049{
50 compl->flags = 0;
51}
52
Sathya Perla8788fdc2009-07-27 22:52:03 +000053static int be_mcc_compl_process(struct be_adapter *adapter,
Sathya Perlaefd2e402009-07-27 22:53:10 +000054 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000055{
56 u16 compl_status, extd_status;
57
58 /* Just swap the status to host endian; mcc tag is opaquely copied
59 * from mcc_wrb */
60 be_dws_le_to_cpu(compl, 4);
61
62 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
63 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -070064
65 if ((compl->tag0 == OPCODE_COMMON_WRITE_FLASHROM) &&
66 (compl->tag1 == CMD_SUBSYSTEM_COMMON)) {
67 adapter->flash_status = compl_status;
68 complete(&adapter->flash_compl);
69 }
70
Sathya Perlab31c50a2009-09-17 10:30:13 -070071 if (compl_status == MCC_STATUS_SUCCESS) {
72 if (compl->tag0 == OPCODE_ETH_GET_STATISTICS) {
73 struct be_cmd_resp_get_stats *resp =
74 adapter->stats.cmd.va;
75 be_dws_le_to_cpu(&resp->hw_stats,
76 sizeof(resp->hw_stats));
77 netdev_stats_update(adapter);
78 }
79 } else if (compl_status != MCC_STATUS_NOT_SUPPORTED) {
Sathya Perla5fb379e2009-06-18 00:02:59 +000080 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
81 CQE_STATUS_EXTD_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +000082 dev_warn(&adapter->pdev->dev,
Ajit Khaparded744b442009-12-03 06:12:06 +000083 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
84 compl->tag0, compl_status, extd_status);
Sathya Perla5fb379e2009-06-18 00:02:59 +000085 }
Sathya Perlab31c50a2009-09-17 10:30:13 -070086 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +000087}
88
Sathya Perlaa8f447b2009-06-18 00:10:27 +000089/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +000090static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447b2009-06-18 00:10:27 +000091 struct be_async_event_link_state *evt)
92{
Sathya Perla8788fdc2009-07-27 22:52:03 +000093 be_link_status_update(adapter,
94 evt->port_link_status == ASYNC_EVENT_LINK_UP);
Sathya Perlaa8f447b2009-06-18 00:10:27 +000095}
96
97static inline bool is_link_state_evt(u32 trailer)
98{
99 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
100 ASYNC_TRAILER_EVENT_CODE_MASK) ==
101 ASYNC_EVENT_CODE_LINK_STATE);
102}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000103
Sathya Perlaefd2e402009-07-27 22:53:10 +0000104static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000105{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000106 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000107 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000108
109 if (be_mcc_compl_is_new(compl)) {
110 queue_tail_inc(mcc_cq);
111 return compl;
112 }
113 return NULL;
114}
115
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000116void be_async_mcc_enable(struct be_adapter *adapter)
117{
118 spin_lock_bh(&adapter->mcc_cq_lock);
119
120 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
121 adapter->mcc_obj.rearm_cq = true;
122
123 spin_unlock_bh(&adapter->mcc_cq_lock);
124}
125
126void be_async_mcc_disable(struct be_adapter *adapter)
127{
128 adapter->mcc_obj.rearm_cq = false;
129}
130
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800131int be_process_mcc(struct be_adapter *adapter, int *status)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000132{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000133 struct be_mcc_compl *compl;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800134 int num = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000135 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000136
Sathya Perla8788fdc2009-07-27 22:52:03 +0000137 spin_lock_bh(&adapter->mcc_cq_lock);
138 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000139 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
140 /* Interpret flags as an async trailer */
141 BUG_ON(!is_link_state_evt(compl->flags));
142
143 /* Interpret compl as a async link evt */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000144 be_async_link_state_process(adapter,
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000145 (struct be_async_event_link_state *) compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700146 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800147 *status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000148 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000149 }
150 be_mcc_compl_use(compl);
151 num++;
152 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700153
Sathya Perla8788fdc2009-07-27 22:52:03 +0000154 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800155 return num;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000156}
157
Sathya Perla6ac7b682009-06-18 00:05:54 +0000158/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700159static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000160{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700161#define mcc_timeout 120000 /* 12s timeout */
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800162 int i, num, status = 0;
163 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700164
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800165 for (i = 0; i < mcc_timeout; i++) {
166 num = be_process_mcc(adapter, &status);
167 if (num)
168 be_cq_notify(adapter, mcc_obj->cq.id,
169 mcc_obj->rearm_cq, num);
170
171 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000172 break;
173 udelay(100);
174 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700175 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000176 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700177 return -1;
178 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800179 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000180}
181
182/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700183static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000184{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000185 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700186 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000187}
188
Sathya Perla5f0b8492009-07-27 22:52:56 +0000189static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700190{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000191 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700192 u32 ready;
193
194 do {
Sathya Perlacf588472010-02-14 21:22:01 +0000195 ready = ioread32(db);
196 if (ready == 0xffffffff) {
197 dev_err(&adapter->pdev->dev,
198 "pci slot disconnected\n");
199 return -1;
200 }
201
202 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700203 if (ready)
204 break;
205
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000206 if (msecs > 4000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000207 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700208 return -1;
209 }
210
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000211 set_current_state(TASK_INTERRUPTIBLE);
212 schedule_timeout(msecs_to_jiffies(1));
213 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700214 } while (true);
215
216 return 0;
217}
218
219/*
220 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000221 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700222 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700223static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700224{
225 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700226 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000227 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
228 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700229 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000230 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700231
Sathya Perlacf588472010-02-14 21:22:01 +0000232 /* wait for ready to be set */
233 status = be_mbox_db_ready_wait(adapter, db);
234 if (status != 0)
235 return status;
236
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700237 val |= MPU_MAILBOX_DB_HI_MASK;
238 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
239 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
240 iowrite32(val, db);
241
242 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000243 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700244 if (status != 0)
245 return status;
246
247 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700248 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
249 val |= (u32)(mbox_mem->dma >> 4) << 2;
250 iowrite32(val, db);
251
Sathya Perla5f0b8492009-07-27 22:52:56 +0000252 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700253 if (status != 0)
254 return status;
255
Sathya Perla5fb379e2009-06-18 00:02:59 +0000256 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000257 if (be_mcc_compl_is_new(compl)) {
258 status = be_mcc_compl_process(adapter, &mbox->compl);
259 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000260 if (status)
261 return status;
262 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000263 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700264 return -1;
265 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000266 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700267}
268
Sathya Perla8788fdc2009-07-27 22:52:03 +0000269static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700270{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000271 u32 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700272
273 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
274 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
275 return -1;
276 else
277 return 0;
278}
279
Sathya Perla8788fdc2009-07-27 22:52:03 +0000280int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700281{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000282 u16 stage;
283 int status, timeout = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700284
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000285 do {
286 status = be_POST_stage_get(adapter, &stage);
287 if (status) {
288 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
289 stage);
290 return -1;
291 } else if (stage != POST_STAGE_ARMFW_RDY) {
292 set_current_state(TASK_INTERRUPTIBLE);
293 schedule_timeout(2 * HZ);
294 timeout += 2;
295 } else {
296 return 0;
297 }
Sathya Perlad938a702010-05-26 00:33:43 -0700298 } while (timeout < 40);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700299
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000300 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
301 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700302}
303
304static inline void *embedded_payload(struct be_mcc_wrb *wrb)
305{
306 return wrb->payload.embedded_payload;
307}
308
309static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
310{
311 return &wrb->payload.sgl[0];
312}
313
314/* Don't touch the hdr after it's prepared */
315static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
Ajit Khaparded744b442009-12-03 06:12:06 +0000316 bool embedded, u8 sge_cnt, u32 opcode)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700317{
318 if (embedded)
319 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
320 else
321 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
322 MCC_WRB_SGE_CNT_SHIFT;
323 wrb->payload_length = payload_len;
Ajit Khaparded744b442009-12-03 06:12:06 +0000324 wrb->tag0 = opcode;
Sathya Perlafa4281b2010-01-21 22:51:36 +0000325 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700326}
327
328/* Don't touch the hdr after it's prepared */
329static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
330 u8 subsystem, u8 opcode, int cmd_len)
331{
332 req_hdr->opcode = opcode;
333 req_hdr->subsystem = subsystem;
334 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000335 req_hdr->version = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700336}
337
338static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
339 struct be_dma_mem *mem)
340{
341 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
342 u64 dma = (u64)mem->dma;
343
344 for (i = 0; i < buf_pages; i++) {
345 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
346 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
347 dma += PAGE_SIZE_4K;
348 }
349}
350
351/* Converts interrupt delay in microseconds to multiplier value */
352static u32 eq_delay_to_mult(u32 usec_delay)
353{
354#define MAX_INTR_RATE 651042
355 const u32 round = 10;
356 u32 multiplier;
357
358 if (usec_delay == 0)
359 multiplier = 0;
360 else {
361 u32 interrupt_rate = 1000000 / usec_delay;
362 /* Max delay, corresponding to the lowest interrupt rate */
363 if (interrupt_rate == 0)
364 multiplier = 1023;
365 else {
366 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
367 multiplier /= interrupt_rate;
368 /* Round the multiplier to the closest value.*/
369 multiplier = (multiplier + round/2) / round;
370 multiplier = min(multiplier, (u32)1023);
371 }
372 }
373 return multiplier;
374}
375
Sathya Perlab31c50a2009-09-17 10:30:13 -0700376static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700377{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700378 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
379 struct be_mcc_wrb *wrb
380 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
381 memset(wrb, 0, sizeof(*wrb));
382 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700383}
384
Sathya Perlab31c50a2009-09-17 10:30:13 -0700385static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000386{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700387 struct be_queue_info *mccq = &adapter->mcc_obj.q;
388 struct be_mcc_wrb *wrb;
389
Sathya Perla713d03942009-11-22 22:02:45 +0000390 if (atomic_read(&mccq->used) >= mccq->len) {
391 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
392 return NULL;
393 }
394
Sathya Perlab31c50a2009-09-17 10:30:13 -0700395 wrb = queue_head_node(mccq);
396 queue_head_inc(mccq);
397 atomic_inc(&mccq->used);
398 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000399 return wrb;
400}
401
Sathya Perla2243e2e2009-11-22 22:02:03 +0000402/* Tell fw we're about to start firing cmds by writing a
403 * special pattern across the wrb hdr; uses mbox
404 */
405int be_cmd_fw_init(struct be_adapter *adapter)
406{
407 u8 *wrb;
408 int status;
409
410 spin_lock(&adapter->mbox_lock);
411
412 wrb = (u8 *)wrb_from_mbox(adapter);
413 *wrb++ = 0xFF;
414 *wrb++ = 0x12;
415 *wrb++ = 0x34;
416 *wrb++ = 0xFF;
417 *wrb++ = 0xFF;
418 *wrb++ = 0x56;
419 *wrb++ = 0x78;
420 *wrb = 0xFF;
421
422 status = be_mbox_notify_wait(adapter);
423
424 spin_unlock(&adapter->mbox_lock);
425 return status;
426}
427
428/* Tell fw we're done with firing cmds by writing a
429 * special pattern across the wrb hdr; uses mbox
430 */
431int be_cmd_fw_clean(struct be_adapter *adapter)
432{
433 u8 *wrb;
434 int status;
435
Sathya Perlacf588472010-02-14 21:22:01 +0000436 if (adapter->eeh_err)
437 return -EIO;
438
Sathya Perla2243e2e2009-11-22 22:02:03 +0000439 spin_lock(&adapter->mbox_lock);
440
441 wrb = (u8 *)wrb_from_mbox(adapter);
442 *wrb++ = 0xFF;
443 *wrb++ = 0xAA;
444 *wrb++ = 0xBB;
445 *wrb++ = 0xFF;
446 *wrb++ = 0xFF;
447 *wrb++ = 0xCC;
448 *wrb++ = 0xDD;
449 *wrb = 0xFF;
450
451 status = be_mbox_notify_wait(adapter);
452
453 spin_unlock(&adapter->mbox_lock);
454 return status;
455}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000456int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700457 struct be_queue_info *eq, int eq_delay)
458{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700459 struct be_mcc_wrb *wrb;
460 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700461 struct be_dma_mem *q_mem = &eq->dma_mem;
462 int status;
463
Sathya Perla8788fdc2009-07-27 22:52:03 +0000464 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700465
466 wrb = wrb_from_mbox(adapter);
467 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700468
Ajit Khaparded744b442009-12-03 06:12:06 +0000469 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700470
471 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
472 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
473
474 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
475
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700476 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
477 /* 4byte eqe*/
478 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
479 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
480 __ilog2_u32(eq->len/256));
481 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
482 eq_delay_to_mult(eq_delay));
483 be_dws_cpu_to_le(req->context, sizeof(req->context));
484
485 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
486
Sathya Perlab31c50a2009-09-17 10:30:13 -0700487 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700488 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700489 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700490 eq->id = le16_to_cpu(resp->eq_id);
491 eq->created = true;
492 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700493
Sathya Perla8788fdc2009-07-27 22:52:03 +0000494 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700495 return status;
496}
497
Sathya Perlab31c50a2009-09-17 10:30:13 -0700498/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000499int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700500 u8 type, bool permanent, u32 if_handle)
501{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700502 struct be_mcc_wrb *wrb;
503 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700504 int status;
505
Sathya Perla8788fdc2009-07-27 22:52:03 +0000506 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700507
508 wrb = wrb_from_mbox(adapter);
509 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700510
Ajit Khaparded744b442009-12-03 06:12:06 +0000511 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
512 OPCODE_COMMON_NTWK_MAC_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700513
514 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
515 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
516
517 req->type = type;
518 if (permanent) {
519 req->permanent = 1;
520 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700521 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700522 req->permanent = 0;
523 }
524
Sathya Perlab31c50a2009-09-17 10:30:13 -0700525 status = be_mbox_notify_wait(adapter);
526 if (!status) {
527 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700528 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700529 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700530
Sathya Perla8788fdc2009-07-27 22:52:03 +0000531 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700532 return status;
533}
534
Sathya Perlab31c50a2009-09-17 10:30:13 -0700535/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000536int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700537 u32 if_id, u32 *pmac_id)
538{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700539 struct be_mcc_wrb *wrb;
540 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700541 int status;
542
Sathya Perlab31c50a2009-09-17 10:30:13 -0700543 spin_lock_bh(&adapter->mcc_lock);
544
545 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000546 if (!wrb) {
547 status = -EBUSY;
548 goto err;
549 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700550 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700551
Ajit Khaparded744b442009-12-03 06:12:06 +0000552 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
553 OPCODE_COMMON_NTWK_PMAC_ADD);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700554
555 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
556 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
557
558 req->if_id = cpu_to_le32(if_id);
559 memcpy(req->mac_address, mac_addr, ETH_ALEN);
560
Sathya Perlab31c50a2009-09-17 10:30:13 -0700561 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700562 if (!status) {
563 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
564 *pmac_id = le32_to_cpu(resp->pmac_id);
565 }
566
Sathya Perla713d03942009-11-22 22:02:45 +0000567err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700568 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700569 return status;
570}
571
Sathya Perlab31c50a2009-09-17 10:30:13 -0700572/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000573int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700574{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700575 struct be_mcc_wrb *wrb;
576 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700577 int status;
578
Sathya Perlab31c50a2009-09-17 10:30:13 -0700579 spin_lock_bh(&adapter->mcc_lock);
580
581 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000582 if (!wrb) {
583 status = -EBUSY;
584 goto err;
585 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700586 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700587
Ajit Khaparded744b442009-12-03 06:12:06 +0000588 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
589 OPCODE_COMMON_NTWK_PMAC_DEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700590
591 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
592 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
593
594 req->if_id = cpu_to_le32(if_id);
595 req->pmac_id = cpu_to_le32(pmac_id);
596
Sathya Perlab31c50a2009-09-17 10:30:13 -0700597 status = be_mcc_notify_wait(adapter);
598
Sathya Perla713d03942009-11-22 22:02:45 +0000599err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700600 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700601 return status;
602}
603
Sathya Perlab31c50a2009-09-17 10:30:13 -0700604/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000605int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700606 struct be_queue_info *cq, struct be_queue_info *eq,
607 bool sol_evts, bool no_delay, int coalesce_wm)
608{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700609 struct be_mcc_wrb *wrb;
610 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700611 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700612 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700613 int status;
614
Sathya Perla8788fdc2009-07-27 22:52:03 +0000615 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700616
617 wrb = wrb_from_mbox(adapter);
618 req = embedded_payload(wrb);
619 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700620
Ajit Khaparded744b442009-12-03 06:12:06 +0000621 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
622 OPCODE_COMMON_CQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700623
624 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
625 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
626
627 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
628
629 AMAP_SET_BITS(struct amap_cq_context, coalescwm, ctxt, coalesce_wm);
630 AMAP_SET_BITS(struct amap_cq_context, nodelay, ctxt, no_delay);
631 AMAP_SET_BITS(struct amap_cq_context, count, ctxt,
632 __ilog2_u32(cq->len/256));
633 AMAP_SET_BITS(struct amap_cq_context, valid, ctxt, 1);
634 AMAP_SET_BITS(struct amap_cq_context, solevent, ctxt, sol_evts);
635 AMAP_SET_BITS(struct amap_cq_context, eventable, ctxt, 1);
636 AMAP_SET_BITS(struct amap_cq_context, eqid, ctxt, eq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000637 AMAP_SET_BITS(struct amap_cq_context, armed, ctxt, 1);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700638 be_dws_cpu_to_le(ctxt, sizeof(req->context));
639
640 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
641
Sathya Perlab31c50a2009-09-17 10:30:13 -0700642 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700643 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700644 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700645 cq->id = le16_to_cpu(resp->cq_id);
646 cq->created = true;
647 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700648
Sathya Perla8788fdc2009-07-27 22:52:03 +0000649 spin_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000650
651 return status;
652}
653
654static u32 be_encoded_q_len(int q_len)
655{
656 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
657 if (len_encoded == 16)
658 len_encoded = 0;
659 return len_encoded;
660}
661
Sathya Perla8788fdc2009-07-27 22:52:03 +0000662int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000663 struct be_queue_info *mccq,
664 struct be_queue_info *cq)
665{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700666 struct be_mcc_wrb *wrb;
667 struct be_cmd_req_mcc_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000668 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700669 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000670 int status;
671
Sathya Perla8788fdc2009-07-27 22:52:03 +0000672 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700673
674 wrb = wrb_from_mbox(adapter);
675 req = embedded_payload(wrb);
676 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000677
Ajit Khaparded744b442009-12-03 06:12:06 +0000678 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
679 OPCODE_COMMON_MCC_CREATE);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000680
681 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
682 OPCODE_COMMON_MCC_CREATE, sizeof(*req));
683
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000684 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000685
Sathya Perla5fb379e2009-06-18 00:02:59 +0000686 AMAP_SET_BITS(struct amap_mcc_context, valid, ctxt, 1);
687 AMAP_SET_BITS(struct amap_mcc_context, ring_size, ctxt,
688 be_encoded_q_len(mccq->len));
689 AMAP_SET_BITS(struct amap_mcc_context, cq_id, ctxt, cq->id);
690
691 be_dws_cpu_to_le(ctxt, sizeof(req->context));
692
693 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
694
Sathya Perlab31c50a2009-09-17 10:30:13 -0700695 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000696 if (!status) {
697 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
698 mccq->id = le16_to_cpu(resp->id);
699 mccq->created = true;
700 }
Sathya Perla8788fdc2009-07-27 22:52:03 +0000701 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700702
703 return status;
704}
705
Sathya Perla8788fdc2009-07-27 22:52:03 +0000706int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700707 struct be_queue_info *txq,
708 struct be_queue_info *cq)
709{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700710 struct be_mcc_wrb *wrb;
711 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700712 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700713 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700714 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700715
Sathya Perla8788fdc2009-07-27 22:52:03 +0000716 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700717
718 wrb = wrb_from_mbox(adapter);
719 req = embedded_payload(wrb);
720 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700721
Ajit Khaparded744b442009-12-03 06:12:06 +0000722 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
723 OPCODE_ETH_TX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700724
725 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
726 sizeof(*req));
727
728 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
729 req->ulp_num = BE_ULP1_NUM;
730 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
731
Sathya Perlab31c50a2009-09-17 10:30:13 -0700732 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
733 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700734 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
735 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
736
737 be_dws_cpu_to_le(ctxt, sizeof(req->context));
738
739 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
740
Sathya Perlab31c50a2009-09-17 10:30:13 -0700741 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700742 if (!status) {
743 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
744 txq->id = le16_to_cpu(resp->cid);
745 txq->created = true;
746 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700747
Sathya Perla8788fdc2009-07-27 22:52:03 +0000748 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700749
750 return status;
751}
752
Sathya Perlab31c50a2009-09-17 10:30:13 -0700753/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000754int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700755 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
756 u16 max_frame_size, u32 if_id, u32 rss)
757{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700758 struct be_mcc_wrb *wrb;
759 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700760 struct be_dma_mem *q_mem = &rxq->dma_mem;
761 int status;
762
Sathya Perla8788fdc2009-07-27 22:52:03 +0000763 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700764
765 wrb = wrb_from_mbox(adapter);
766 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700767
Ajit Khaparded744b442009-12-03 06:12:06 +0000768 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
769 OPCODE_ETH_RX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700770
771 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
772 sizeof(*req));
773
774 req->cq_id = cpu_to_le16(cq_id);
775 req->frag_size = fls(frag_size) - 1;
776 req->num_pages = 2;
777 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
778 req->interface_id = cpu_to_le32(if_id);
779 req->max_frame_size = cpu_to_le16(max_frame_size);
780 req->rss_queue = cpu_to_le32(rss);
781
Sathya Perlab31c50a2009-09-17 10:30:13 -0700782 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700783 if (!status) {
784 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
785 rxq->id = le16_to_cpu(resp->id);
786 rxq->created = true;
787 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700788
Sathya Perla8788fdc2009-07-27 22:52:03 +0000789 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700790
791 return status;
792}
793
Sathya Perlab31c50a2009-09-17 10:30:13 -0700794/* Generic destroyer function for all types of queues
795 * Uses Mbox
796 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000797int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700798 int queue_type)
799{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700800 struct be_mcc_wrb *wrb;
801 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700802 u8 subsys = 0, opcode = 0;
803 int status;
804
Sathya Perlacf588472010-02-14 21:22:01 +0000805 if (adapter->eeh_err)
806 return -EIO;
807
Sathya Perla8788fdc2009-07-27 22:52:03 +0000808 spin_lock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700809
Sathya Perlab31c50a2009-09-17 10:30:13 -0700810 wrb = wrb_from_mbox(adapter);
811 req = embedded_payload(wrb);
812
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700813 switch (queue_type) {
814 case QTYPE_EQ:
815 subsys = CMD_SUBSYSTEM_COMMON;
816 opcode = OPCODE_COMMON_EQ_DESTROY;
817 break;
818 case QTYPE_CQ:
819 subsys = CMD_SUBSYSTEM_COMMON;
820 opcode = OPCODE_COMMON_CQ_DESTROY;
821 break;
822 case QTYPE_TXQ:
823 subsys = CMD_SUBSYSTEM_ETH;
824 opcode = OPCODE_ETH_TX_DESTROY;
825 break;
826 case QTYPE_RXQ:
827 subsys = CMD_SUBSYSTEM_ETH;
828 opcode = OPCODE_ETH_RX_DESTROY;
829 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000830 case QTYPE_MCCQ:
831 subsys = CMD_SUBSYSTEM_COMMON;
832 opcode = OPCODE_COMMON_MCC_DESTROY;
833 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700834 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +0000835 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700836 }
Ajit Khaparded744b442009-12-03 06:12:06 +0000837
838 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
839
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700840 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
841 req->id = cpu_to_le16(q->id);
842
Sathya Perlab31c50a2009-09-17 10:30:13 -0700843 status = be_mbox_notify_wait(adapter);
Sathya Perla5f0b8492009-07-27 22:52:56 +0000844
Sathya Perla8788fdc2009-07-27 22:52:03 +0000845 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700846
847 return status;
848}
849
Sathya Perlab31c50a2009-09-17 10:30:13 -0700850/* Create an rx filtering policy configuration on an i/f
851 * Uses mbox
852 */
Sathya Perla73d540f2009-10-14 20:20:42 +0000853int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000854 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id,
855 u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700856{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700857 struct be_mcc_wrb *wrb;
858 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700859 int status;
860
Sathya Perla8788fdc2009-07-27 22:52:03 +0000861 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700862
863 wrb = wrb_from_mbox(adapter);
864 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700865
Ajit Khaparded744b442009-12-03 06:12:06 +0000866 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
867 OPCODE_COMMON_NTWK_INTERFACE_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700868
869 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
870 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
871
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000872 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +0000873 req->capability_flags = cpu_to_le32(cap_flags);
874 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700875 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700876 if (!pmac_invalid)
877 memcpy(req->mac_addr, mac, ETH_ALEN);
878
Sathya Perlab31c50a2009-09-17 10:30:13 -0700879 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700880 if (!status) {
881 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
882 *if_handle = le32_to_cpu(resp->interface_id);
883 if (!pmac_invalid)
884 *pmac_id = le32_to_cpu(resp->pmac_id);
885 }
886
Sathya Perla8788fdc2009-07-27 22:52:03 +0000887 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700888 return status;
889}
890
Sathya Perlab31c50a2009-09-17 10:30:13 -0700891/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000892int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700893{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700894 struct be_mcc_wrb *wrb;
895 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700896 int status;
897
Sathya Perlacf588472010-02-14 21:22:01 +0000898 if (adapter->eeh_err)
899 return -EIO;
900
Sathya Perla8788fdc2009-07-27 22:52:03 +0000901 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700902
903 wrb = wrb_from_mbox(adapter);
904 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700905
Ajit Khaparded744b442009-12-03 06:12:06 +0000906 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
907 OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700908
909 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
910 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
911
912 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700913
914 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700915
Sathya Perla8788fdc2009-07-27 22:52:03 +0000916 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700917
918 return status;
919}
920
921/* Get stats is a non embedded command: the request is not embedded inside
922 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -0700923 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700924 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000925int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700926{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700927 struct be_mcc_wrb *wrb;
928 struct be_cmd_req_get_stats *req;
929 struct be_sge *sge;
Sathya Perla713d03942009-11-22 22:02:45 +0000930 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700931
Sathya Perlab31c50a2009-09-17 10:30:13 -0700932 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700933
Sathya Perlab31c50a2009-09-17 10:30:13 -0700934 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000935 if (!wrb) {
936 status = -EBUSY;
937 goto err;
938 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700939 req = nonemb_cmd->va;
940 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700941
Ajit Khaparded744b442009-12-03 06:12:06 +0000942 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
943 OPCODE_ETH_GET_STATISTICS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700944
945 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
946 OPCODE_ETH_GET_STATISTICS, sizeof(*req));
947 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
948 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
949 sge->len = cpu_to_le32(nonemb_cmd->size);
950
Sathya Perlab31c50a2009-09-17 10:30:13 -0700951 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700952
Sathya Perla713d03942009-11-22 22:02:45 +0000953err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700954 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +0000955 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700956}
957
Sathya Perlab31c50a2009-09-17 10:30:13 -0700958/* Uses synchronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000959int be_cmd_link_status_query(struct be_adapter *adapter,
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700960 bool *link_up, u8 *mac_speed, u16 *link_speed)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700961{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700962 struct be_mcc_wrb *wrb;
963 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700964 int status;
965
Sathya Perlab31c50a2009-09-17 10:30:13 -0700966 spin_lock_bh(&adapter->mcc_lock);
967
968 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000969 if (!wrb) {
970 status = -EBUSY;
971 goto err;
972 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700973 req = embedded_payload(wrb);
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000974
975 *link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700976
Ajit Khaparded744b442009-12-03 06:12:06 +0000977 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
978 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700979
980 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
981 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
982
Sathya Perlab31c50a2009-09-17 10:30:13 -0700983 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700984 if (!status) {
985 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700986 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000987 *link_up = true;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -0700988 *link_speed = le16_to_cpu(resp->link_speed);
989 *mac_speed = resp->mac_speed;
990 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700991 }
992
Sathya Perla713d03942009-11-22 22:02:45 +0000993err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700994 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700995 return status;
996}
997
Sathya Perlab31c50a2009-09-17 10:30:13 -0700998/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000999int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001000{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001001 struct be_mcc_wrb *wrb;
1002 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001003 int status;
1004
Sathya Perla8788fdc2009-07-27 22:52:03 +00001005 spin_lock(&adapter->mbox_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001006
1007 wrb = wrb_from_mbox(adapter);
1008 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001009
Ajit Khaparded744b442009-12-03 06:12:06 +00001010 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1011 OPCODE_COMMON_GET_FW_VERSION);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001012
1013 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1014 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
1015
Sathya Perlab31c50a2009-09-17 10:30:13 -07001016 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001017 if (!status) {
1018 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1019 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
1020 }
1021
Sathya Perla8788fdc2009-07-27 22:52:03 +00001022 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001023 return status;
1024}
1025
Sathya Perlab31c50a2009-09-17 10:30:13 -07001026/* set the EQ delay interval of an EQ to specified value
1027 * Uses async mcc
1028 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001029int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001030{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001031 struct be_mcc_wrb *wrb;
1032 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001033 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001034
Sathya Perlab31c50a2009-09-17 10:30:13 -07001035 spin_lock_bh(&adapter->mcc_lock);
1036
1037 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001038 if (!wrb) {
1039 status = -EBUSY;
1040 goto err;
1041 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001042 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001043
Ajit Khaparded744b442009-12-03 06:12:06 +00001044 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1045 OPCODE_COMMON_MODIFY_EQ_DELAY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001046
1047 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1048 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
1049
1050 req->num_eq = cpu_to_le32(1);
1051 req->delay[0].eq_id = cpu_to_le32(eq_id);
1052 req->delay[0].phase = 0;
1053 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1054
Sathya Perlab31c50a2009-09-17 10:30:13 -07001055 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001056
Sathya Perla713d03942009-11-22 22:02:45 +00001057err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001058 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001059 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001060}
1061
Sathya Perlab31c50a2009-09-17 10:30:13 -07001062/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001063int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001064 u32 num, bool untagged, bool promiscuous)
1065{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001066 struct be_mcc_wrb *wrb;
1067 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001068 int status;
1069
Sathya Perlab31c50a2009-09-17 10:30:13 -07001070 spin_lock_bh(&adapter->mcc_lock);
1071
1072 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001073 if (!wrb) {
1074 status = -EBUSY;
1075 goto err;
1076 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001077 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001078
Ajit Khaparded744b442009-12-03 06:12:06 +00001079 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1080 OPCODE_COMMON_NTWK_VLAN_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001081
1082 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1083 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
1084
1085 req->interface_id = if_id;
1086 req->promiscuous = promiscuous;
1087 req->untagged = untagged;
1088 req->num_vlan = num;
1089 if (!promiscuous) {
1090 memcpy(req->normal_vlan, vtag_array,
1091 req->num_vlan * sizeof(vtag_array[0]));
1092 }
1093
Sathya Perlab31c50a2009-09-17 10:30:13 -07001094 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001095
Sathya Perla713d03942009-11-22 22:02:45 +00001096err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001097 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001098 return status;
1099}
1100
Sathya Perlab31c50a2009-09-17 10:30:13 -07001101/* Uses MCC for this command as it may be called in BH context
1102 * Uses synchronous mcc
1103 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001104int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001105{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001106 struct be_mcc_wrb *wrb;
1107 struct be_cmd_req_promiscuous_config *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001108 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001109
Sathya Perla8788fdc2009-07-27 22:52:03 +00001110 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001111
Sathya Perlab31c50a2009-09-17 10:30:13 -07001112 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001113 if (!wrb) {
1114 status = -EBUSY;
1115 goto err;
1116 }
Sathya Perla6ac7b682009-06-18 00:05:54 +00001117 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001118
Ajit Khaparded744b442009-12-03 06:12:06 +00001119 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_PROMISCUOUS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001120
1121 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1122 OPCODE_ETH_PROMISCUOUS, sizeof(*req));
1123
Sathya Perla69d7ce72010-04-11 22:35:27 +00001124 /* In FW versions X.102.149/X.101.487 and later,
1125 * the port setting associated only with the
1126 * issuing pci function will take effect
1127 */
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001128 if (port_num)
1129 req->port1_promiscuous = en;
1130 else
1131 req->port0_promiscuous = en;
1132
Sathya Perlab31c50a2009-09-17 10:30:13 -07001133 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001134
Sathya Perla713d03942009-11-22 22:02:45 +00001135err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001136 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001137 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001138}
1139
Sathya Perla6ac7b682009-06-18 00:05:54 +00001140/*
Sathya Perlab31c50a2009-09-17 10:30:13 -07001141 * Uses MCC for this command as it may be called in BH context
Sathya Perla6ac7b682009-06-18 00:05:54 +00001142 * (mc == NULL) => multicast promiscous
1143 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001144int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001145 struct net_device *netdev, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001146{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001147 struct be_mcc_wrb *wrb;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001148 struct be_cmd_req_mcast_mac_config *req = mem->va;
1149 struct be_sge *sge;
1150 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001151
Sathya Perla8788fdc2009-07-27 22:52:03 +00001152 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001153
Sathya Perlab31c50a2009-09-17 10:30:13 -07001154 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001155 if (!wrb) {
1156 status = -EBUSY;
1157 goto err;
1158 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00001159 sge = nonembedded_sgl(wrb);
1160 memset(req, 0, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001161
Ajit Khaparded744b442009-12-03 06:12:06 +00001162 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1163 OPCODE_COMMON_NTWK_MULTICAST_SET);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001164 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
1165 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
1166 sge->len = cpu_to_le32(mem->size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001167
1168 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1169 OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
1170
1171 req->interface_id = if_id;
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001172 if (netdev) {
Sathya Perla24307ee2009-06-18 00:09:25 +00001173 int i;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001174 struct netdev_hw_addr *ha;
Sathya Perla24307ee2009-06-18 00:09:25 +00001175
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001176 req->num_mac = cpu_to_le16(netdev_mc_count(netdev));
Sathya Perla24307ee2009-06-18 00:09:25 +00001177
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001178 i = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001179 netdev_for_each_mc_addr(ha, netdev)
1180 memcpy(req->mac[i].byte, ha->addr, ETH_ALEN);
Sathya Perla24307ee2009-06-18 00:09:25 +00001181 } else {
1182 req->promiscuous = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001183 }
1184
Sathya Perlae7b909a2009-11-22 22:01:10 +00001185 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001186
Sathya Perla713d03942009-11-22 22:02:45 +00001187err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001188 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001189 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001190}
1191
Sathya Perlab31c50a2009-09-17 10:30:13 -07001192/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001193int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001194{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001195 struct be_mcc_wrb *wrb;
1196 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001197 int status;
1198
Sathya Perlab31c50a2009-09-17 10:30:13 -07001199 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001200
Sathya Perlab31c50a2009-09-17 10:30:13 -07001201 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001202 if (!wrb) {
1203 status = -EBUSY;
1204 goto err;
1205 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001206 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001207
Ajit Khaparded744b442009-12-03 06:12:06 +00001208 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1209 OPCODE_COMMON_SET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001210
1211 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1212 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1213
1214 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1215 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1216
Sathya Perlab31c50a2009-09-17 10:30:13 -07001217 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001218
Sathya Perla713d03942009-11-22 22:02:45 +00001219err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001220 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001221 return status;
1222}
1223
Sathya Perlab31c50a2009-09-17 10:30:13 -07001224/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001225int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001226{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001227 struct be_mcc_wrb *wrb;
1228 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001229 int status;
1230
Sathya Perlab31c50a2009-09-17 10:30:13 -07001231 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001232
Sathya Perlab31c50a2009-09-17 10:30:13 -07001233 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001234 if (!wrb) {
1235 status = -EBUSY;
1236 goto err;
1237 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001238 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001239
Ajit Khaparded744b442009-12-03 06:12:06 +00001240 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1241 OPCODE_COMMON_GET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001242
1243 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1244 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1245
Sathya Perlab31c50a2009-09-17 10:30:13 -07001246 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001247 if (!status) {
1248 struct be_cmd_resp_get_flow_control *resp =
1249 embedded_payload(wrb);
1250 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1251 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1252 }
1253
Sathya Perla713d03942009-11-22 22:02:45 +00001254err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001255 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001256 return status;
1257}
1258
Sathya Perlab31c50a2009-09-17 10:30:13 -07001259/* Uses mbox */
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001260int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num, u32 *cap)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001261{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001262 struct be_mcc_wrb *wrb;
1263 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001264 int status;
1265
Sathya Perla8788fdc2009-07-27 22:52:03 +00001266 spin_lock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001267
Sathya Perlab31c50a2009-09-17 10:30:13 -07001268 wrb = wrb_from_mbox(adapter);
1269 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001270
Ajit Khaparded744b442009-12-03 06:12:06 +00001271 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1272 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001273
1274 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1275 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1276
Sathya Perlab31c50a2009-09-17 10:30:13 -07001277 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001278 if (!status) {
1279 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1280 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khapardedcb9b562009-09-30 21:58:22 -07001281 *cap = le32_to_cpu(resp->function_cap);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001282 }
1283
Sathya Perla8788fdc2009-07-27 22:52:03 +00001284 spin_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001285 return status;
1286}
sarveshwarb14074ea2009-08-05 13:05:24 -07001287
Sathya Perlab31c50a2009-09-17 10:30:13 -07001288/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001289int be_cmd_reset_function(struct be_adapter *adapter)
1290{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001291 struct be_mcc_wrb *wrb;
1292 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001293 int status;
1294
1295 spin_lock(&adapter->mbox_lock);
1296
Sathya Perlab31c50a2009-09-17 10:30:13 -07001297 wrb = wrb_from_mbox(adapter);
1298 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001299
Ajit Khaparded744b442009-12-03 06:12:06 +00001300 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1301 OPCODE_COMMON_FUNCTION_RESET);
sarveshwarb14074ea2009-08-05 13:05:24 -07001302
1303 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1304 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1305
Sathya Perlab31c50a2009-09-17 10:30:13 -07001306 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001307
1308 spin_unlock(&adapter->mbox_lock);
1309 return status;
1310}
Ajit Khaparde84517482009-09-04 03:12:16 +00001311
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001312/* Uses sync mcc */
1313int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1314 u8 bcn, u8 sts, u8 state)
1315{
1316 struct be_mcc_wrb *wrb;
1317 struct be_cmd_req_enable_disable_beacon *req;
1318 int status;
1319
1320 spin_lock_bh(&adapter->mcc_lock);
1321
1322 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001323 if (!wrb) {
1324 status = -EBUSY;
1325 goto err;
1326 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001327 req = embedded_payload(wrb);
1328
Ajit Khaparded744b442009-12-03 06:12:06 +00001329 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1330 OPCODE_COMMON_ENABLE_DISABLE_BEACON);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001331
1332 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1333 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1334
1335 req->port_num = port_num;
1336 req->beacon_state = state;
1337 req->beacon_duration = bcn;
1338 req->status_duration = sts;
1339
1340 status = be_mcc_notify_wait(adapter);
1341
Sathya Perla713d03942009-11-22 22:02:45 +00001342err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001343 spin_unlock_bh(&adapter->mcc_lock);
1344 return status;
1345}
1346
1347/* Uses sync mcc */
1348int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1349{
1350 struct be_mcc_wrb *wrb;
1351 struct be_cmd_req_get_beacon_state *req;
1352 int status;
1353
1354 spin_lock_bh(&adapter->mcc_lock);
1355
1356 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001357 if (!wrb) {
1358 status = -EBUSY;
1359 goto err;
1360 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001361 req = embedded_payload(wrb);
1362
Ajit Khaparded744b442009-12-03 06:12:06 +00001363 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1364 OPCODE_COMMON_GET_BEACON_STATE);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001365
1366 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1367 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1368
1369 req->port_num = port_num;
1370
1371 status = be_mcc_notify_wait(adapter);
1372 if (!status) {
1373 struct be_cmd_resp_get_beacon_state *resp =
1374 embedded_payload(wrb);
1375 *state = resp->beacon_state;
1376 }
1377
Sathya Perla713d03942009-11-22 22:02:45 +00001378err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001379 spin_unlock_bh(&adapter->mcc_lock);
1380 return status;
1381}
1382
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001383/* Uses sync mcc */
1384int be_cmd_read_port_type(struct be_adapter *adapter, u32 port,
1385 u8 *connector)
1386{
1387 struct be_mcc_wrb *wrb;
1388 struct be_cmd_req_port_type *req;
1389 int status;
1390
1391 spin_lock_bh(&adapter->mcc_lock);
1392
1393 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001394 if (!wrb) {
1395 status = -EBUSY;
1396 goto err;
1397 }
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001398 req = embedded_payload(wrb);
1399
Ajit Khaparded744b442009-12-03 06:12:06 +00001400 be_wrb_hdr_prepare(wrb, sizeof(struct be_cmd_resp_port_type), true, 0,
1401 OPCODE_COMMON_READ_TRANSRECV_DATA);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001402
1403 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1404 OPCODE_COMMON_READ_TRANSRECV_DATA, sizeof(*req));
1405
1406 req->port = cpu_to_le32(port);
1407 req->page_num = cpu_to_le32(TR_PAGE_A0);
1408 status = be_mcc_notify_wait(adapter);
1409 if (!status) {
1410 struct be_cmd_resp_port_type *resp = embedded_payload(wrb);
1411 *connector = resp->data.connector;
1412 }
1413
Sathya Perla713d03942009-11-22 22:02:45 +00001414err:
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001415 spin_unlock_bh(&adapter->mcc_lock);
1416 return status;
1417}
1418
Ajit Khaparde84517482009-09-04 03:12:16 +00001419int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1420 u32 flash_type, u32 flash_opcode, u32 buf_size)
1421{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001422 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001423 struct be_cmd_write_flashrom *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001424 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001425 int status;
1426
Sathya Perlab31c50a2009-09-17 10:30:13 -07001427 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001428 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001429
1430 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001431 if (!wrb) {
1432 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001433 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00001434 }
1435 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001436 sge = nonembedded_sgl(wrb);
1437
Ajit Khaparded744b442009-12-03 06:12:06 +00001438 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1439 OPCODE_COMMON_WRITE_FLASHROM);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001440 wrb->tag1 = CMD_SUBSYSTEM_COMMON;
Ajit Khaparde84517482009-09-04 03:12:16 +00001441
1442 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1443 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1444 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1445 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1446 sge->len = cpu_to_le32(cmd->size);
1447
1448 req->params.op_type = cpu_to_le32(flash_type);
1449 req->params.op_code = cpu_to_le32(flash_opcode);
1450 req->params.data_buf_size = cpu_to_le32(buf_size);
1451
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001452 be_mcc_notify(adapter);
1453 spin_unlock_bh(&adapter->mcc_lock);
1454
1455 if (!wait_for_completion_timeout(&adapter->flash_compl,
1456 msecs_to_jiffies(12000)))
1457 status = -1;
1458 else
1459 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00001460
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001461 return status;
1462
1463err_unlock:
1464 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001465 return status;
1466}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001467
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001468int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1469 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001470{
1471 struct be_mcc_wrb *wrb;
1472 struct be_cmd_write_flashrom *req;
1473 int status;
1474
1475 spin_lock_bh(&adapter->mcc_lock);
1476
1477 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001478 if (!wrb) {
1479 status = -EBUSY;
1480 goto err;
1481 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001482 req = embedded_payload(wrb);
1483
Ajit Khaparded744b442009-12-03 06:12:06 +00001484 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
1485 OPCODE_COMMON_READ_FLASHROM);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001486
1487 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1488 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1489
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001490 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001491 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00001492 req->params.offset = cpu_to_le32(offset);
1493 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001494
1495 status = be_mcc_notify_wait(adapter);
1496 if (!status)
1497 memcpy(flashed_crc, req->params.data_buf, 4);
1498
Sathya Perla713d03942009-11-22 22:02:45 +00001499err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001500 spin_unlock_bh(&adapter->mcc_lock);
1501 return status;
1502}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001503
Dan Carpenterc196b022010-05-26 04:47:39 +00001504int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001505 struct be_dma_mem *nonemb_cmd)
1506{
1507 struct be_mcc_wrb *wrb;
1508 struct be_cmd_req_acpi_wol_magic_config *req;
1509 struct be_sge *sge;
1510 int status;
1511
1512 spin_lock_bh(&adapter->mcc_lock);
1513
1514 wrb = wrb_from_mccq(adapter);
1515 if (!wrb) {
1516 status = -EBUSY;
1517 goto err;
1518 }
1519 req = nonemb_cmd->va;
1520 sge = nonembedded_sgl(wrb);
1521
1522 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1523 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
1524
1525 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1526 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
1527 memcpy(req->magic_mac, mac, ETH_ALEN);
1528
1529 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1530 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1531 sge->len = cpu_to_le32(nonemb_cmd->size);
1532
1533 status = be_mcc_notify_wait(adapter);
1534
1535err:
1536 spin_unlock_bh(&adapter->mcc_lock);
1537 return status;
1538}
Suresh Rff33a6e2009-12-03 16:15:52 -08001539
Sarveshwar Bandifced9992009-12-23 04:41:44 +00001540int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
1541 u8 loopback_type, u8 enable)
1542{
1543 struct be_mcc_wrb *wrb;
1544 struct be_cmd_req_set_lmode *req;
1545 int status;
1546
1547 spin_lock_bh(&adapter->mcc_lock);
1548
1549 wrb = wrb_from_mccq(adapter);
1550 if (!wrb) {
1551 status = -EBUSY;
1552 goto err;
1553 }
1554
1555 req = embedded_payload(wrb);
1556
1557 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1558 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
1559
1560 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1561 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
1562 sizeof(*req));
1563
1564 req->src_port = port_num;
1565 req->dest_port = port_num;
1566 req->loopback_type = loopback_type;
1567 req->loopback_state = enable;
1568
1569 status = be_mcc_notify_wait(adapter);
1570err:
1571 spin_unlock_bh(&adapter->mcc_lock);
1572 return status;
1573}
1574
Suresh Rff33a6e2009-12-03 16:15:52 -08001575int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
1576 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
1577{
1578 struct be_mcc_wrb *wrb;
1579 struct be_cmd_req_loopback_test *req;
1580 int status;
1581
1582 spin_lock_bh(&adapter->mcc_lock);
1583
1584 wrb = wrb_from_mccq(adapter);
1585 if (!wrb) {
1586 status = -EBUSY;
1587 goto err;
1588 }
1589
1590 req = embedded_payload(wrb);
1591
1592 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1593 OPCODE_LOWLEVEL_LOOPBACK_TEST);
1594
1595 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1596 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
Sathya Perla3ffd0512010-06-01 00:19:33 -07001597 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08001598
1599 req->pattern = cpu_to_le64(pattern);
1600 req->src_port = cpu_to_le32(port_num);
1601 req->dest_port = cpu_to_le32(port_num);
1602 req->pkt_size = cpu_to_le32(pkt_size);
1603 req->num_pkts = cpu_to_le32(num_pkts);
1604 req->loopback_type = cpu_to_le32(loopback_type);
1605
1606 status = be_mcc_notify_wait(adapter);
1607 if (!status) {
1608 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
1609 status = le32_to_cpu(resp->status);
1610 }
1611
1612err:
1613 spin_unlock_bh(&adapter->mcc_lock);
1614 return status;
1615}
1616
1617int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
1618 u32 byte_cnt, struct be_dma_mem *cmd)
1619{
1620 struct be_mcc_wrb *wrb;
1621 struct be_cmd_req_ddrdma_test *req;
1622 struct be_sge *sge;
1623 int status;
1624 int i, j = 0;
1625
1626 spin_lock_bh(&adapter->mcc_lock);
1627
1628 wrb = wrb_from_mccq(adapter);
1629 if (!wrb) {
1630 status = -EBUSY;
1631 goto err;
1632 }
1633 req = cmd->va;
1634 sge = nonembedded_sgl(wrb);
1635 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1636 OPCODE_LOWLEVEL_HOST_DDR_DMA);
1637 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1638 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
1639
1640 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1641 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1642 sge->len = cpu_to_le32(cmd->size);
1643
1644 req->pattern = cpu_to_le64(pattern);
1645 req->byte_count = cpu_to_le32(byte_cnt);
1646 for (i = 0; i < byte_cnt; i++) {
1647 req->snd_buff[i] = (u8)(pattern >> (j*8));
1648 j++;
1649 if (j > 7)
1650 j = 0;
1651 }
1652
1653 status = be_mcc_notify_wait(adapter);
1654
1655 if (!status) {
1656 struct be_cmd_resp_ddrdma_test *resp;
1657 resp = cmd->va;
1658 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
1659 resp->snd_err) {
1660 status = -1;
1661 }
1662 }
1663
1664err:
1665 spin_unlock_bh(&adapter->mcc_lock);
1666 return status;
1667}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001668
Dan Carpenterc196b022010-05-26 04:47:39 +00001669int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001670 struct be_dma_mem *nonemb_cmd)
1671{
1672 struct be_mcc_wrb *wrb;
1673 struct be_cmd_req_seeprom_read *req;
1674 struct be_sge *sge;
1675 int status;
1676
1677 spin_lock_bh(&adapter->mcc_lock);
1678
1679 wrb = wrb_from_mccq(adapter);
1680 req = nonemb_cmd->va;
1681 sge = nonembedded_sgl(wrb);
1682
1683 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1684 OPCODE_COMMON_SEEPROM_READ);
1685
1686 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1687 OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
1688
1689 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1690 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1691 sge->len = cpu_to_le32(nonemb_cmd->size);
1692
1693 status = be_mcc_notify_wait(adapter);
1694
1695 spin_unlock_bh(&adapter->mcc_lock);
1696 return status;
1697}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00001698
1699int be_cmd_get_phy_info(struct be_adapter *adapter, struct be_dma_mem *cmd)
1700{
1701 struct be_mcc_wrb *wrb;
1702 struct be_cmd_req_get_phy_info *req;
1703 struct be_sge *sge;
1704 int status;
1705
1706 spin_lock_bh(&adapter->mcc_lock);
1707
1708 wrb = wrb_from_mccq(adapter);
1709 if (!wrb) {
1710 status = -EBUSY;
1711 goto err;
1712 }
1713
1714 req = cmd->va;
1715 sge = nonembedded_sgl(wrb);
1716
1717 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1718 OPCODE_COMMON_GET_PHY_DETAILS);
1719
1720 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1721 OPCODE_COMMON_GET_PHY_DETAILS,
1722 sizeof(*req));
1723
1724 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1725 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1726 sge->len = cpu_to_le32(cmd->size);
1727
1728 status = be_mcc_notify_wait(adapter);
1729err:
1730 spin_unlock_bh(&adapter->mcc_lock);
1731 return status;
1732}