blob: 277982babc11510a7218c17be2cf290be6dbee80 [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 =
Sathya Perla3abcded2010-10-03 22:12:27 -070074 adapter->stats_cmd.va;
Sathya Perlab31c50a2009-09-17 10:30:13 -070075 be_dws_le_to_cpu(&resp->hw_stats,
76 sizeof(resp->hw_stats));
77 netdev_stats_update(adapter);
Ajit Khaparde0fc48c32010-07-29 06:18:58 +000078 adapter->stats_ioctl_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -070079 }
Ajit Khaparde89438072010-07-23 12:42:40 -070080 } else if ((compl_status != MCC_STATUS_NOT_SUPPORTED) &&
81 (compl->tag0 != OPCODE_COMMON_NTWK_MAC_QUERY)) {
Sathya Perla5fb379e2009-06-18 00:02:59 +000082 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
83 CQE_STATUS_EXTD_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +000084 dev_warn(&adapter->pdev->dev,
Ajit Khaparded744b442009-12-03 06:12:06 +000085 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
86 compl->tag0, compl_status, extd_status);
Sathya Perla5fb379e2009-06-18 00:02:59 +000087 }
Sathya Perlab31c50a2009-09-17 10:30:13 -070088 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +000089}
90
Sathya Perlaa8f447b2009-06-18 00:10:27 +000091/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +000092static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447b2009-06-18 00:10:27 +000093 struct be_async_event_link_state *evt)
94{
Sathya Perla8788fdc2009-07-27 22:52:03 +000095 be_link_status_update(adapter,
96 evt->port_link_status == ASYNC_EVENT_LINK_UP);
Sathya Perlaa8f447b2009-06-18 00:10:27 +000097}
98
Somnath Koturcc4ce022010-10-21 07:11:14 -070099/* Grp5 CoS Priority evt */
100static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
101 struct be_async_event_grp5_cos_priority *evt)
102{
103 if (evt->valid) {
104 adapter->vlan_prio_bmap = evt->available_priority_bmap;
105 adapter->recommended_prio =
106 evt->reco_default_priority << VLAN_PRIO_SHIFT;
107 }
108}
109
110/* Grp5 QOS Speed evt */
111static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
112 struct be_async_event_grp5_qos_link_speed *evt)
113{
114 if (evt->physical_port == adapter->port_num) {
115 /* qos_link_speed is in units of 10 Mbps */
116 adapter->link_speed = evt->qos_link_speed * 10;
117 }
118}
119
120static void be_async_grp5_evt_process(struct be_adapter *adapter,
121 u32 trailer, struct be_mcc_compl *evt)
122{
123 u8 event_type = 0;
124
125 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
126 ASYNC_TRAILER_EVENT_TYPE_MASK;
127
128 switch (event_type) {
129 case ASYNC_EVENT_COS_PRIORITY:
130 be_async_grp5_cos_priority_process(adapter,
131 (struct be_async_event_grp5_cos_priority *)evt);
132 break;
133 case ASYNC_EVENT_QOS_SPEED:
134 be_async_grp5_qos_speed_process(adapter,
135 (struct be_async_event_grp5_qos_link_speed *)evt);
136 break;
137 default:
138 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
139 break;
140 }
141}
142
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000143static inline bool is_link_state_evt(u32 trailer)
144{
Eric Dumazet807540b2010-09-23 05:40:09 +0000145 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000146 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000147 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000148}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000149
Somnath Koturcc4ce022010-10-21 07:11:14 -0700150static inline bool is_grp5_evt(u32 trailer)
151{
152 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
153 ASYNC_TRAILER_EVENT_CODE_MASK) ==
154 ASYNC_EVENT_CODE_GRP_5);
155}
156
Sathya Perlaefd2e402009-07-27 22:53:10 +0000157static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000158{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000159 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000160 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000161
162 if (be_mcc_compl_is_new(compl)) {
163 queue_tail_inc(mcc_cq);
164 return compl;
165 }
166 return NULL;
167}
168
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000169void be_async_mcc_enable(struct be_adapter *adapter)
170{
171 spin_lock_bh(&adapter->mcc_cq_lock);
172
173 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
174 adapter->mcc_obj.rearm_cq = true;
175
176 spin_unlock_bh(&adapter->mcc_cq_lock);
177}
178
179void be_async_mcc_disable(struct be_adapter *adapter)
180{
181 adapter->mcc_obj.rearm_cq = false;
182}
183
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800184int be_process_mcc(struct be_adapter *adapter, int *status)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000185{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000186 struct be_mcc_compl *compl;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800187 int num = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000188 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000189
Sathya Perla8788fdc2009-07-27 22:52:03 +0000190 spin_lock_bh(&adapter->mcc_cq_lock);
191 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000192 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
193 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000194 if (is_link_state_evt(compl->flags))
195 be_async_link_state_process(adapter,
Sathya Perlaa8f447b2009-06-18 00:10:27 +0000196 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700197 else if (is_grp5_evt(compl->flags))
198 be_async_grp5_evt_process(adapter,
199 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700200 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800201 *status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000202 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000203 }
204 be_mcc_compl_use(compl);
205 num++;
206 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700207
Sathya Perla8788fdc2009-07-27 22:52:03 +0000208 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800209 return num;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000210}
211
Sathya Perla6ac7b682009-06-18 00:05:54 +0000212/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700213static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000214{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700215#define mcc_timeout 120000 /* 12s timeout */
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800216 int i, num, status = 0;
217 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700218
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800219 for (i = 0; i < mcc_timeout; i++) {
220 num = be_process_mcc(adapter, &status);
221 if (num)
222 be_cq_notify(adapter, mcc_obj->cq.id,
223 mcc_obj->rearm_cq, num);
224
225 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000226 break;
227 udelay(100);
228 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700229 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000230 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700231 return -1;
232 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800233 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000234}
235
236/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700237static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000238{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000239 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700240 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000241}
242
Sathya Perla5f0b8492009-07-27 22:52:56 +0000243static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700244{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000245 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700246 u32 ready;
247
248 do {
Sathya Perlacf588472010-02-14 21:22:01 +0000249 ready = ioread32(db);
250 if (ready == 0xffffffff) {
251 dev_err(&adapter->pdev->dev,
252 "pci slot disconnected\n");
253 return -1;
254 }
255
256 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700257 if (ready)
258 break;
259
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000260 if (msecs > 4000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000261 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Ajit Khaparded053de92010-09-03 06:23:30 +0000262 be_detect_dump_ue(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700263 return -1;
264 }
265
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000266 set_current_state(TASK_INTERRUPTIBLE);
267 schedule_timeout(msecs_to_jiffies(1));
268 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700269 } while (true);
270
271 return 0;
272}
273
274/*
275 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000276 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700277 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700278static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700279{
280 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700281 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000282 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
283 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700284 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000285 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700286
Sathya Perlacf588472010-02-14 21:22:01 +0000287 /* wait for ready to be set */
288 status = be_mbox_db_ready_wait(adapter, db);
289 if (status != 0)
290 return status;
291
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700292 val |= MPU_MAILBOX_DB_HI_MASK;
293 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
294 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
295 iowrite32(val, db);
296
297 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000298 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700299 if (status != 0)
300 return status;
301
302 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700303 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
304 val |= (u32)(mbox_mem->dma >> 4) << 2;
305 iowrite32(val, db);
306
Sathya Perla5f0b8492009-07-27 22:52:56 +0000307 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700308 if (status != 0)
309 return status;
310
Sathya Perla5fb379e2009-06-18 00:02:59 +0000311 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000312 if (be_mcc_compl_is_new(compl)) {
313 status = be_mcc_compl_process(adapter, &mbox->compl);
314 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000315 if (status)
316 return status;
317 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000318 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700319 return -1;
320 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000321 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700322}
323
Sathya Perla8788fdc2009-07-27 22:52:03 +0000324static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700325{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000326 u32 sem;
327
328 if (lancer_chip(adapter))
329 sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
330 else
331 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700332
333 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
334 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
335 return -1;
336 else
337 return 0;
338}
339
Sathya Perla8788fdc2009-07-27 22:52:03 +0000340int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700341{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000342 u16 stage;
343 int status, timeout = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700344
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000345 do {
346 status = be_POST_stage_get(adapter, &stage);
347 if (status) {
348 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
349 stage);
350 return -1;
351 } else if (stage != POST_STAGE_ARMFW_RDY) {
352 set_current_state(TASK_INTERRUPTIBLE);
353 schedule_timeout(2 * HZ);
354 timeout += 2;
355 } else {
356 return 0;
357 }
Sathya Perlad938a702010-05-26 00:33:43 -0700358 } while (timeout < 40);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700359
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000360 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
361 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700362}
363
364static inline void *embedded_payload(struct be_mcc_wrb *wrb)
365{
366 return wrb->payload.embedded_payload;
367}
368
369static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
370{
371 return &wrb->payload.sgl[0];
372}
373
374/* Don't touch the hdr after it's prepared */
375static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
Ajit Khaparded744b442009-12-03 06:12:06 +0000376 bool embedded, u8 sge_cnt, u32 opcode)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700377{
378 if (embedded)
379 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
380 else
381 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
382 MCC_WRB_SGE_CNT_SHIFT;
383 wrb->payload_length = payload_len;
Ajit Khaparded744b442009-12-03 06:12:06 +0000384 wrb->tag0 = opcode;
Sathya Perlafa4281b2010-01-21 22:51:36 +0000385 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700386}
387
388/* Don't touch the hdr after it's prepared */
389static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
390 u8 subsystem, u8 opcode, int cmd_len)
391{
392 req_hdr->opcode = opcode;
393 req_hdr->subsystem = subsystem;
394 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000395 req_hdr->version = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700396}
397
398static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
399 struct be_dma_mem *mem)
400{
401 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
402 u64 dma = (u64)mem->dma;
403
404 for (i = 0; i < buf_pages; i++) {
405 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
406 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
407 dma += PAGE_SIZE_4K;
408 }
409}
410
411/* Converts interrupt delay in microseconds to multiplier value */
412static u32 eq_delay_to_mult(u32 usec_delay)
413{
414#define MAX_INTR_RATE 651042
415 const u32 round = 10;
416 u32 multiplier;
417
418 if (usec_delay == 0)
419 multiplier = 0;
420 else {
421 u32 interrupt_rate = 1000000 / usec_delay;
422 /* Max delay, corresponding to the lowest interrupt rate */
423 if (interrupt_rate == 0)
424 multiplier = 1023;
425 else {
426 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
427 multiplier /= interrupt_rate;
428 /* Round the multiplier to the closest value.*/
429 multiplier = (multiplier + round/2) / round;
430 multiplier = min(multiplier, (u32)1023);
431 }
432 }
433 return multiplier;
434}
435
Sathya Perlab31c50a2009-09-17 10:30:13 -0700436static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700437{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700438 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
439 struct be_mcc_wrb *wrb
440 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
441 memset(wrb, 0, sizeof(*wrb));
442 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700443}
444
Sathya Perlab31c50a2009-09-17 10:30:13 -0700445static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000446{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700447 struct be_queue_info *mccq = &adapter->mcc_obj.q;
448 struct be_mcc_wrb *wrb;
449
Sathya Perla713d03942009-11-22 22:02:45 +0000450 if (atomic_read(&mccq->used) >= mccq->len) {
451 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
452 return NULL;
453 }
454
Sathya Perlab31c50a2009-09-17 10:30:13 -0700455 wrb = queue_head_node(mccq);
456 queue_head_inc(mccq);
457 atomic_inc(&mccq->used);
458 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000459 return wrb;
460}
461
Sathya Perla2243e2e2009-11-22 22:02:03 +0000462/* Tell fw we're about to start firing cmds by writing a
463 * special pattern across the wrb hdr; uses mbox
464 */
465int be_cmd_fw_init(struct be_adapter *adapter)
466{
467 u8 *wrb;
468 int status;
469
Ivan Vecera29849612010-12-14 05:43:19 +0000470 if (mutex_lock_interruptible(&adapter->mbox_lock))
471 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000472
473 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000474 *wrb++ = 0xFF;
475 *wrb++ = 0x12;
476 *wrb++ = 0x34;
477 *wrb++ = 0xFF;
478 *wrb++ = 0xFF;
479 *wrb++ = 0x56;
480 *wrb++ = 0x78;
481 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000482
483 status = be_mbox_notify_wait(adapter);
484
Ivan Vecera29849612010-12-14 05:43:19 +0000485 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000486 return status;
487}
488
489/* Tell fw we're done with firing cmds by writing a
490 * special pattern across the wrb hdr; uses mbox
491 */
492int be_cmd_fw_clean(struct be_adapter *adapter)
493{
494 u8 *wrb;
495 int status;
496
Sathya Perlacf588472010-02-14 21:22:01 +0000497 if (adapter->eeh_err)
498 return -EIO;
499
Ivan Vecera29849612010-12-14 05:43:19 +0000500 if (mutex_lock_interruptible(&adapter->mbox_lock))
501 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000502
503 wrb = (u8 *)wrb_from_mbox(adapter);
504 *wrb++ = 0xFF;
505 *wrb++ = 0xAA;
506 *wrb++ = 0xBB;
507 *wrb++ = 0xFF;
508 *wrb++ = 0xFF;
509 *wrb++ = 0xCC;
510 *wrb++ = 0xDD;
511 *wrb = 0xFF;
512
513 status = be_mbox_notify_wait(adapter);
514
Ivan Vecera29849612010-12-14 05:43:19 +0000515 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000516 return status;
517}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000518int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700519 struct be_queue_info *eq, int eq_delay)
520{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700521 struct be_mcc_wrb *wrb;
522 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700523 struct be_dma_mem *q_mem = &eq->dma_mem;
524 int status;
525
Ivan Vecera29849612010-12-14 05:43:19 +0000526 if (mutex_lock_interruptible(&adapter->mbox_lock))
527 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700528
529 wrb = wrb_from_mbox(adapter);
530 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700531
Ajit Khaparded744b442009-12-03 06:12:06 +0000532 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700533
534 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
535 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
536
537 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
538
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700539 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
540 /* 4byte eqe*/
541 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
542 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
543 __ilog2_u32(eq->len/256));
544 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
545 eq_delay_to_mult(eq_delay));
546 be_dws_cpu_to_le(req->context, sizeof(req->context));
547
548 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
549
Sathya Perlab31c50a2009-09-17 10:30:13 -0700550 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700551 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700552 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700553 eq->id = le16_to_cpu(resp->eq_id);
554 eq->created = true;
555 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700556
Ivan Vecera29849612010-12-14 05:43:19 +0000557 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700558 return status;
559}
560
Sathya Perlab31c50a2009-09-17 10:30:13 -0700561/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000562int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700563 u8 type, bool permanent, u32 if_handle)
564{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700565 struct be_mcc_wrb *wrb;
566 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700567 int status;
568
Ivan Vecera29849612010-12-14 05:43:19 +0000569 if (mutex_lock_interruptible(&adapter->mbox_lock))
570 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700571
572 wrb = wrb_from_mbox(adapter);
573 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700574
Ajit Khaparded744b442009-12-03 06:12:06 +0000575 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
576 OPCODE_COMMON_NTWK_MAC_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700577
578 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
579 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
580
581 req->type = type;
582 if (permanent) {
583 req->permanent = 1;
584 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700585 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700586 req->permanent = 0;
587 }
588
Sathya Perlab31c50a2009-09-17 10:30:13 -0700589 status = be_mbox_notify_wait(adapter);
590 if (!status) {
591 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700592 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700593 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700594
Ivan Vecera29849612010-12-14 05:43:19 +0000595 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700596 return status;
597}
598
Sathya Perlab31c50a2009-09-17 10:30:13 -0700599/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000600int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000601 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700602{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700603 struct be_mcc_wrb *wrb;
604 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700605 int status;
606
Sathya Perlab31c50a2009-09-17 10:30:13 -0700607 spin_lock_bh(&adapter->mcc_lock);
608
609 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000610 if (!wrb) {
611 status = -EBUSY;
612 goto err;
613 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700614 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700615
Ajit Khaparded744b442009-12-03 06:12:06 +0000616 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
617 OPCODE_COMMON_NTWK_PMAC_ADD);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700618
619 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
620 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
621
Ajit Khapardef8617e02011-02-11 13:36:37 +0000622 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700623 req->if_id = cpu_to_le32(if_id);
624 memcpy(req->mac_address, mac_addr, ETH_ALEN);
625
Sathya Perlab31c50a2009-09-17 10:30:13 -0700626 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700627 if (!status) {
628 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
629 *pmac_id = le32_to_cpu(resp->pmac_id);
630 }
631
Sathya Perla713d03942009-11-22 22:02:45 +0000632err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700633 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700634 return status;
635}
636
Sathya Perlab31c50a2009-09-17 10:30:13 -0700637/* Uses synchronous MCCQ */
Ajit Khapardef8617e02011-02-11 13:36:37 +0000638int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700639{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700640 struct be_mcc_wrb *wrb;
641 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700642 int status;
643
Sathya Perlab31c50a2009-09-17 10:30:13 -0700644 spin_lock_bh(&adapter->mcc_lock);
645
646 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000647 if (!wrb) {
648 status = -EBUSY;
649 goto err;
650 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700651 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700652
Ajit Khaparded744b442009-12-03 06:12:06 +0000653 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
654 OPCODE_COMMON_NTWK_PMAC_DEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700655
656 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
657 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
658
Ajit Khapardef8617e02011-02-11 13:36:37 +0000659 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700660 req->if_id = cpu_to_le32(if_id);
661 req->pmac_id = cpu_to_le32(pmac_id);
662
Sathya Perlab31c50a2009-09-17 10:30:13 -0700663 status = be_mcc_notify_wait(adapter);
664
Sathya Perla713d03942009-11-22 22:02:45 +0000665err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700666 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700667 return status;
668}
669
Sathya Perlab31c50a2009-09-17 10:30:13 -0700670/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000671int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700672 struct be_queue_info *cq, struct be_queue_info *eq,
673 bool sol_evts, bool no_delay, int coalesce_wm)
674{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700675 struct be_mcc_wrb *wrb;
676 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700677 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700678 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700679 int status;
680
Ivan Vecera29849612010-12-14 05:43:19 +0000681 if (mutex_lock_interruptible(&adapter->mbox_lock))
682 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700683
684 wrb = wrb_from_mbox(adapter);
685 req = embedded_payload(wrb);
686 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700687
Ajit Khaparded744b442009-12-03 06:12:06 +0000688 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
689 OPCODE_COMMON_CQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700690
691 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
692 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
693
694 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000695 if (lancer_chip(adapter)) {
696 req->hdr.version = 1;
697 req->page_size = 1; /* 1 for 4K */
698 AMAP_SET_BITS(struct amap_cq_context_lancer, coalescwm, ctxt,
699 coalesce_wm);
700 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
701 no_delay);
702 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
703 __ilog2_u32(cq->len/256));
704 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
705 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
706 ctxt, 1);
707 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
708 ctxt, eq->id);
709 AMAP_SET_BITS(struct amap_cq_context_lancer, armed, ctxt, 1);
710 } else {
711 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
712 coalesce_wm);
713 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
714 ctxt, no_delay);
715 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
716 __ilog2_u32(cq->len/256));
717 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
718 AMAP_SET_BITS(struct amap_cq_context_be, solevent,
719 ctxt, sol_evts);
720 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
721 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
722 AMAP_SET_BITS(struct amap_cq_context_be, armed, ctxt, 1);
723 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700724
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700725 be_dws_cpu_to_le(ctxt, sizeof(req->context));
726
727 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
728
Sathya Perlab31c50a2009-09-17 10:30:13 -0700729 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700730 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700731 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700732 cq->id = le16_to_cpu(resp->cq_id);
733 cq->created = true;
734 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700735
Ivan Vecera29849612010-12-14 05:43:19 +0000736 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000737
738 return status;
739}
740
741static u32 be_encoded_q_len(int q_len)
742{
743 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
744 if (len_encoded == 16)
745 len_encoded = 0;
746 return len_encoded;
747}
748
Sathya Perla8788fdc2009-07-27 22:52:03 +0000749int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000750 struct be_queue_info *mccq,
751 struct be_queue_info *cq)
752{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700753 struct be_mcc_wrb *wrb;
754 struct be_cmd_req_mcc_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000755 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700756 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000757 int status;
758
Ivan Vecera29849612010-12-14 05:43:19 +0000759 if (mutex_lock_interruptible(&adapter->mbox_lock))
760 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700761
762 wrb = wrb_from_mbox(adapter);
763 req = embedded_payload(wrb);
764 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000765
Ajit Khaparded744b442009-12-03 06:12:06 +0000766 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700767 OPCODE_COMMON_MCC_CREATE_EXT);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000768
769 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700770 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000771
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000772 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000773 if (lancer_chip(adapter)) {
774 req->hdr.version = 1;
775 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000776
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000777 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
778 be_encoded_q_len(mccq->len));
779 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
780 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
781 ctxt, cq->id);
782 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
783 ctxt, 1);
784
785 } else {
786 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
787 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
788 be_encoded_q_len(mccq->len));
789 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
790 }
791
Somnath Koturcc4ce022010-10-21 07:11:14 -0700792 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000793 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000794 be_dws_cpu_to_le(ctxt, sizeof(req->context));
795
796 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
797
Sathya Perlab31c50a2009-09-17 10:30:13 -0700798 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000799 if (!status) {
800 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
801 mccq->id = le16_to_cpu(resp->id);
802 mccq->created = true;
803 }
Ivan Vecera29849612010-12-14 05:43:19 +0000804 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700805
806 return status;
807}
808
Sathya Perla8788fdc2009-07-27 22:52:03 +0000809int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700810 struct be_queue_info *txq,
811 struct be_queue_info *cq)
812{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700813 struct be_mcc_wrb *wrb;
814 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700815 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700816 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700817 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700818
Ivan Vecera29849612010-12-14 05:43:19 +0000819 if (mutex_lock_interruptible(&adapter->mbox_lock))
820 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700821
822 wrb = wrb_from_mbox(adapter);
823 req = embedded_payload(wrb);
824 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700825
Ajit Khaparded744b442009-12-03 06:12:06 +0000826 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
827 OPCODE_ETH_TX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700828
829 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
830 sizeof(*req));
831
832 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
833 req->ulp_num = BE_ULP1_NUM;
834 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
835
Sathya Perlab31c50a2009-09-17 10:30:13 -0700836 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
837 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700838 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
839 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
840
841 be_dws_cpu_to_le(ctxt, sizeof(req->context));
842
843 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
844
Sathya Perlab31c50a2009-09-17 10:30:13 -0700845 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700846 if (!status) {
847 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
848 txq->id = le16_to_cpu(resp->cid);
849 txq->created = true;
850 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700851
Ivan Vecera29849612010-12-14 05:43:19 +0000852 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700853
854 return status;
855}
856
Sathya Perlab31c50a2009-09-17 10:30:13 -0700857/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000858int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700859 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla3abcded2010-10-03 22:12:27 -0700860 u16 max_frame_size, u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700861{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700862 struct be_mcc_wrb *wrb;
863 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700864 struct be_dma_mem *q_mem = &rxq->dma_mem;
865 int status;
866
Ivan Vecera29849612010-12-14 05:43:19 +0000867 if (mutex_lock_interruptible(&adapter->mbox_lock))
868 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700869
870 wrb = wrb_from_mbox(adapter);
871 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700872
Ajit Khaparded744b442009-12-03 06:12:06 +0000873 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
874 OPCODE_ETH_RX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700875
876 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
877 sizeof(*req));
878
879 req->cq_id = cpu_to_le16(cq_id);
880 req->frag_size = fls(frag_size) - 1;
881 req->num_pages = 2;
882 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
883 req->interface_id = cpu_to_le32(if_id);
884 req->max_frame_size = cpu_to_le16(max_frame_size);
885 req->rss_queue = cpu_to_le32(rss);
886
Sathya Perlab31c50a2009-09-17 10:30:13 -0700887 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700888 if (!status) {
889 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
890 rxq->id = le16_to_cpu(resp->id);
891 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -0700892 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700893 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700894
Ivan Vecera29849612010-12-14 05:43:19 +0000895 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700896
897 return status;
898}
899
Sathya Perlab31c50a2009-09-17 10:30:13 -0700900/* Generic destroyer function for all types of queues
901 * Uses Mbox
902 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000903int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700904 int queue_type)
905{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700906 struct be_mcc_wrb *wrb;
907 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700908 u8 subsys = 0, opcode = 0;
909 int status;
910
Sathya Perlacf588472010-02-14 21:22:01 +0000911 if (adapter->eeh_err)
912 return -EIO;
913
Ivan Vecera29849612010-12-14 05:43:19 +0000914 if (mutex_lock_interruptible(&adapter->mbox_lock))
915 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700916
Sathya Perlab31c50a2009-09-17 10:30:13 -0700917 wrb = wrb_from_mbox(adapter);
918 req = embedded_payload(wrb);
919
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700920 switch (queue_type) {
921 case QTYPE_EQ:
922 subsys = CMD_SUBSYSTEM_COMMON;
923 opcode = OPCODE_COMMON_EQ_DESTROY;
924 break;
925 case QTYPE_CQ:
926 subsys = CMD_SUBSYSTEM_COMMON;
927 opcode = OPCODE_COMMON_CQ_DESTROY;
928 break;
929 case QTYPE_TXQ:
930 subsys = CMD_SUBSYSTEM_ETH;
931 opcode = OPCODE_ETH_TX_DESTROY;
932 break;
933 case QTYPE_RXQ:
934 subsys = CMD_SUBSYSTEM_ETH;
935 opcode = OPCODE_ETH_RX_DESTROY;
936 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000937 case QTYPE_MCCQ:
938 subsys = CMD_SUBSYSTEM_COMMON;
939 opcode = OPCODE_COMMON_MCC_DESTROY;
940 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700941 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +0000942 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700943 }
Ajit Khaparded744b442009-12-03 06:12:06 +0000944
945 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
946
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700947 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
948 req->id = cpu_to_le16(q->id);
949
Sathya Perlab31c50a2009-09-17 10:30:13 -0700950 status = be_mbox_notify_wait(adapter);
Sathya Perla5f0b8492009-07-27 22:52:56 +0000951
Ivan Vecera29849612010-12-14 05:43:19 +0000952 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700953
954 return status;
955}
956
Sathya Perlab31c50a2009-09-17 10:30:13 -0700957/* Create an rx filtering policy configuration on an i/f
958 * Uses mbox
959 */
Sathya Perla73d540f2009-10-14 20:20:42 +0000960int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000961 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id,
962 u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700963{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700964 struct be_mcc_wrb *wrb;
965 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700966 int status;
967
Ivan Vecera29849612010-12-14 05:43:19 +0000968 if (mutex_lock_interruptible(&adapter->mbox_lock))
969 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700970
971 wrb = wrb_from_mbox(adapter);
972 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700973
Ajit Khaparded744b442009-12-03 06:12:06 +0000974 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
975 OPCODE_COMMON_NTWK_INTERFACE_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700976
977 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
978 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
979
Sarveshwar Bandiba343c72010-03-31 02:56:12 +0000980 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +0000981 req->capability_flags = cpu_to_le32(cap_flags);
982 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700983 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700984 if (!pmac_invalid)
985 memcpy(req->mac_addr, mac, ETH_ALEN);
986
Sathya Perlab31c50a2009-09-17 10:30:13 -0700987 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700988 if (!status) {
989 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
990 *if_handle = le32_to_cpu(resp->interface_id);
991 if (!pmac_invalid)
992 *pmac_id = le32_to_cpu(resp->pmac_id);
993 }
994
Ivan Vecera29849612010-12-14 05:43:19 +0000995 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700996 return status;
997}
998
Sathya Perlab31c50a2009-09-17 10:30:13 -0700999/* Uses mbox */
Ajit Khaparde658681f2011-02-11 13:34:46 +00001000int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001001{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001002 struct be_mcc_wrb *wrb;
1003 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001004 int status;
1005
Sathya Perlacf588472010-02-14 21:22:01 +00001006 if (adapter->eeh_err)
1007 return -EIO;
1008
Ivan Vecera29849612010-12-14 05:43:19 +00001009 if (mutex_lock_interruptible(&adapter->mbox_lock))
1010 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001011
1012 wrb = wrb_from_mbox(adapter);
1013 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001014
Ajit Khaparded744b442009-12-03 06:12:06 +00001015 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1016 OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001017
1018 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1019 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
1020
Ajit Khaparde658681f2011-02-11 13:34:46 +00001021 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001022 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001023
1024 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001025
Ivan Vecera29849612010-12-14 05:43:19 +00001026 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027
1028 return status;
1029}
1030
1031/* Get stats is a non embedded command: the request is not embedded inside
1032 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001033 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001034 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001035int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001036{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001037 struct be_mcc_wrb *wrb;
1038 struct be_cmd_req_get_stats *req;
1039 struct be_sge *sge;
Sathya Perla713d03942009-11-22 22:02:45 +00001040 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001041
Sathya Perlab31c50a2009-09-17 10:30:13 -07001042 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001043
Sathya Perlab31c50a2009-09-17 10:30:13 -07001044 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001045 if (!wrb) {
1046 status = -EBUSY;
1047 goto err;
1048 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001049 req = nonemb_cmd->va;
1050 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001051
Ajit Khaparded744b442009-12-03 06:12:06 +00001052 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1053 OPCODE_ETH_GET_STATISTICS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001054
1055 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1056 OPCODE_ETH_GET_STATISTICS, sizeof(*req));
1057 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1058 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1059 sge->len = cpu_to_le32(nonemb_cmd->size);
1060
Sathya Perlab31c50a2009-09-17 10:30:13 -07001061 be_mcc_notify(adapter);
Ajit Khaparde0fc48c32010-07-29 06:18:58 +00001062 adapter->stats_ioctl_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001063
Sathya Perla713d03942009-11-22 22:02:45 +00001064err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001065 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001066 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001067}
1068
Sathya Perlab31c50a2009-09-17 10:30:13 -07001069/* Uses synchronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001070int be_cmd_link_status_query(struct be_adapter *adapter,
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001071 bool *link_up, u8 *mac_speed, u16 *link_speed)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001072{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001073 struct be_mcc_wrb *wrb;
1074 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001075 int status;
1076
Sathya Perlab31c50a2009-09-17 10:30:13 -07001077 spin_lock_bh(&adapter->mcc_lock);
1078
1079 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001080 if (!wrb) {
1081 status = -EBUSY;
1082 goto err;
1083 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001084 req = embedded_payload(wrb);
Sathya Perlaa8f447b2009-06-18 00:10:27 +00001085
1086 *link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001087
Ajit Khaparded744b442009-12-03 06:12:06 +00001088 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1089 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001090
1091 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1092 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
1093
Sathya Perlab31c50a2009-09-17 10:30:13 -07001094 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001095 if (!status) {
1096 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001097 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sathya Perlaa8f447b2009-06-18 00:10:27 +00001098 *link_up = true;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001099 *link_speed = le16_to_cpu(resp->link_speed);
1100 *mac_speed = resp->mac_speed;
1101 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102 }
1103
Sathya Perla713d03942009-11-22 22:02:45 +00001104err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001105 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001106 return status;
1107}
1108
Sathya Perlab31c50a2009-09-17 10:30:13 -07001109/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001110int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001111{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001112 struct be_mcc_wrb *wrb;
1113 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001114 int status;
1115
Ivan Vecera29849612010-12-14 05:43:19 +00001116 if (mutex_lock_interruptible(&adapter->mbox_lock))
1117 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001118
1119 wrb = wrb_from_mbox(adapter);
1120 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001121
Ajit Khaparded744b442009-12-03 06:12:06 +00001122 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1123 OPCODE_COMMON_GET_FW_VERSION);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001124
1125 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1126 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
1127
Sathya Perlab31c50a2009-09-17 10:30:13 -07001128 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001129 if (!status) {
1130 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1131 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
1132 }
1133
Ivan Vecera29849612010-12-14 05:43:19 +00001134 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001135 return status;
1136}
1137
Sathya Perlab31c50a2009-09-17 10:30:13 -07001138/* set the EQ delay interval of an EQ to specified value
1139 * Uses async mcc
1140 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001141int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001142{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001143 struct be_mcc_wrb *wrb;
1144 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001145 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001146
Sathya Perlab31c50a2009-09-17 10:30:13 -07001147 spin_lock_bh(&adapter->mcc_lock);
1148
1149 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001150 if (!wrb) {
1151 status = -EBUSY;
1152 goto err;
1153 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001154 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001155
Ajit Khaparded744b442009-12-03 06:12:06 +00001156 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1157 OPCODE_COMMON_MODIFY_EQ_DELAY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001158
1159 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1160 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
1161
1162 req->num_eq = cpu_to_le32(1);
1163 req->delay[0].eq_id = cpu_to_le32(eq_id);
1164 req->delay[0].phase = 0;
1165 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1166
Sathya Perlab31c50a2009-09-17 10:30:13 -07001167 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001168
Sathya Perla713d03942009-11-22 22:02:45 +00001169err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001170 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001171 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001172}
1173
Sathya Perlab31c50a2009-09-17 10:30:13 -07001174/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001175int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001176 u32 num, bool untagged, bool promiscuous)
1177{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001178 struct be_mcc_wrb *wrb;
1179 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001180 int status;
1181
Sathya Perlab31c50a2009-09-17 10:30:13 -07001182 spin_lock_bh(&adapter->mcc_lock);
1183
1184 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001185 if (!wrb) {
1186 status = -EBUSY;
1187 goto err;
1188 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001189 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001190
Ajit Khaparded744b442009-12-03 06:12:06 +00001191 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1192 OPCODE_COMMON_NTWK_VLAN_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001193
1194 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1195 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
1196
1197 req->interface_id = if_id;
1198 req->promiscuous = promiscuous;
1199 req->untagged = untagged;
1200 req->num_vlan = num;
1201 if (!promiscuous) {
1202 memcpy(req->normal_vlan, vtag_array,
1203 req->num_vlan * sizeof(vtag_array[0]));
1204 }
1205
Sathya Perlab31c50a2009-09-17 10:30:13 -07001206 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001207
Sathya Perla713d03942009-11-22 22:02:45 +00001208err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001209 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001210 return status;
1211}
1212
Sathya Perlab31c50a2009-09-17 10:30:13 -07001213/* Uses MCC for this command as it may be called in BH context
1214 * Uses synchronous mcc
1215 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001216int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001217{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001218 struct be_mcc_wrb *wrb;
1219 struct be_cmd_req_promiscuous_config *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001220 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001221
Sathya Perla8788fdc2009-07-27 22:52:03 +00001222 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001223
Sathya Perlab31c50a2009-09-17 10:30:13 -07001224 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001225 if (!wrb) {
1226 status = -EBUSY;
1227 goto err;
1228 }
Sathya Perla6ac7b682009-06-18 00:05:54 +00001229 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001230
Ajit Khaparded744b442009-12-03 06:12:06 +00001231 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_PROMISCUOUS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001232
1233 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1234 OPCODE_ETH_PROMISCUOUS, sizeof(*req));
1235
Sathya Perla69d7ce72010-04-11 22:35:27 +00001236 /* In FW versions X.102.149/X.101.487 and later,
1237 * the port setting associated only with the
1238 * issuing pci function will take effect
1239 */
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001240 if (port_num)
1241 req->port1_promiscuous = en;
1242 else
1243 req->port0_promiscuous = en;
1244
Sathya Perlab31c50a2009-09-17 10:30:13 -07001245 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001246
Sathya Perla713d03942009-11-22 22:02:45 +00001247err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001248 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001249 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001250}
1251
Sathya Perla6ac7b682009-06-18 00:05:54 +00001252/*
Sathya Perlab31c50a2009-09-17 10:30:13 -07001253 * Uses MCC for this command as it may be called in BH context
Sathya Perla6ac7b682009-06-18 00:05:54 +00001254 * (mc == NULL) => multicast promiscous
1255 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001256int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001257 struct net_device *netdev, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001258{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001259 struct be_mcc_wrb *wrb;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001260 struct be_cmd_req_mcast_mac_config *req = mem->va;
1261 struct be_sge *sge;
1262 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001263
Sathya Perla8788fdc2009-07-27 22:52:03 +00001264 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001265
Sathya Perlab31c50a2009-09-17 10:30:13 -07001266 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001267 if (!wrb) {
1268 status = -EBUSY;
1269 goto err;
1270 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00001271 sge = nonembedded_sgl(wrb);
1272 memset(req, 0, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001273
Ajit Khaparded744b442009-12-03 06:12:06 +00001274 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1275 OPCODE_COMMON_NTWK_MULTICAST_SET);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001276 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
1277 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
1278 sge->len = cpu_to_le32(mem->size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001279
1280 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1281 OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
1282
1283 req->interface_id = if_id;
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001284 if (netdev) {
Sathya Perla24307ee2009-06-18 00:09:25 +00001285 int i;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001286 struct netdev_hw_addr *ha;
Sathya Perla24307ee2009-06-18 00:09:25 +00001287
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001288 req->num_mac = cpu_to_le16(netdev_mc_count(netdev));
Sathya Perla24307ee2009-06-18 00:09:25 +00001289
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001290 i = 0;
Jiri Pirko22bedad2010-04-01 21:22:57 +00001291 netdev_for_each_mc_addr(ha, netdev)
Joe Jin408cc292010-12-06 03:00:59 +00001292 memcpy(req->mac[i++].byte, ha->addr, ETH_ALEN);
Sathya Perla24307ee2009-06-18 00:09:25 +00001293 } else {
1294 req->promiscuous = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001295 }
1296
Sathya Perlae7b909a2009-11-22 22:01:10 +00001297 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001298
Sathya Perla713d03942009-11-22 22:02:45 +00001299err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001300 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001301 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001302}
1303
Sathya Perlab31c50a2009-09-17 10:30:13 -07001304/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001305int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001306{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001307 struct be_mcc_wrb *wrb;
1308 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001309 int status;
1310
Sathya Perlab31c50a2009-09-17 10:30:13 -07001311 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001312
Sathya Perlab31c50a2009-09-17 10:30:13 -07001313 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001314 if (!wrb) {
1315 status = -EBUSY;
1316 goto err;
1317 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001318 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001319
Ajit Khaparded744b442009-12-03 06:12:06 +00001320 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1321 OPCODE_COMMON_SET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001322
1323 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1324 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1325
1326 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1327 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1328
Sathya Perlab31c50a2009-09-17 10:30:13 -07001329 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001330
Sathya Perla713d03942009-11-22 22:02:45 +00001331err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001332 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001333 return status;
1334}
1335
Sathya Perlab31c50a2009-09-17 10:30:13 -07001336/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001337int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001338{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001339 struct be_mcc_wrb *wrb;
1340 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001341 int status;
1342
Sathya Perlab31c50a2009-09-17 10:30:13 -07001343 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001344
Sathya Perlab31c50a2009-09-17 10:30:13 -07001345 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001346 if (!wrb) {
1347 status = -EBUSY;
1348 goto err;
1349 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001350 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001351
Ajit Khaparded744b442009-12-03 06:12:06 +00001352 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1353 OPCODE_COMMON_GET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001354
1355 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1356 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1357
Sathya Perlab31c50a2009-09-17 10:30:13 -07001358 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001359 if (!status) {
1360 struct be_cmd_resp_get_flow_control *resp =
1361 embedded_payload(wrb);
1362 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1363 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1364 }
1365
Sathya Perla713d03942009-11-22 22:02:45 +00001366err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001367 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001368 return status;
1369}
1370
Sathya Perlab31c50a2009-09-17 10:30:13 -07001371/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001372int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1373 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001374{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001375 struct be_mcc_wrb *wrb;
1376 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001377 int status;
1378
Ivan Vecera29849612010-12-14 05:43:19 +00001379 if (mutex_lock_interruptible(&adapter->mbox_lock))
1380 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001381
Sathya Perlab31c50a2009-09-17 10:30:13 -07001382 wrb = wrb_from_mbox(adapter);
1383 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001384
Ajit Khaparded744b442009-12-03 06:12:06 +00001385 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1386 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001387
1388 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1389 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1390
Sathya Perlab31c50a2009-09-17 10:30:13 -07001391 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001392 if (!status) {
1393 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1394 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001395 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001396 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001397 }
1398
Ivan Vecera29849612010-12-14 05:43:19 +00001399 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001400 return status;
1401}
sarveshwarb14074ea2009-08-05 13:05:24 -07001402
Sathya Perlab31c50a2009-09-17 10:30:13 -07001403/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001404int be_cmd_reset_function(struct be_adapter *adapter)
1405{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001406 struct be_mcc_wrb *wrb;
1407 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001408 int status;
1409
Ivan Vecera29849612010-12-14 05:43:19 +00001410 if (mutex_lock_interruptible(&adapter->mbox_lock))
1411 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001412
Sathya Perlab31c50a2009-09-17 10:30:13 -07001413 wrb = wrb_from_mbox(adapter);
1414 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001415
Ajit Khaparded744b442009-12-03 06:12:06 +00001416 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1417 OPCODE_COMMON_FUNCTION_RESET);
sarveshwarb14074ea2009-08-05 13:05:24 -07001418
1419 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1420 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1421
Sathya Perlab31c50a2009-09-17 10:30:13 -07001422 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001423
Ivan Vecera29849612010-12-14 05:43:19 +00001424 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001425 return status;
1426}
Ajit Khaparde84517482009-09-04 03:12:16 +00001427
Sathya Perla3abcded2010-10-03 22:12:27 -07001428int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1429{
1430 struct be_mcc_wrb *wrb;
1431 struct be_cmd_req_rss_config *req;
1432 u32 myhash[10];
1433 int status;
1434
Ivan Vecera29849612010-12-14 05:43:19 +00001435 if (mutex_lock_interruptible(&adapter->mbox_lock))
1436 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001437
1438 wrb = wrb_from_mbox(adapter);
1439 req = embedded_payload(wrb);
1440
1441 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1442 OPCODE_ETH_RSS_CONFIG);
1443
1444 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1445 OPCODE_ETH_RSS_CONFIG, sizeof(*req));
1446
1447 req->if_id = cpu_to_le32(adapter->if_handle);
1448 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4);
1449 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1450 memcpy(req->cpu_table, rsstable, table_size);
1451 memcpy(req->hash, myhash, sizeof(myhash));
1452 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1453
1454 status = be_mbox_notify_wait(adapter);
1455
Ivan Vecera29849612010-12-14 05:43:19 +00001456 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001457 return status;
1458}
1459
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001460/* Uses sync mcc */
1461int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1462 u8 bcn, u8 sts, u8 state)
1463{
1464 struct be_mcc_wrb *wrb;
1465 struct be_cmd_req_enable_disable_beacon *req;
1466 int status;
1467
1468 spin_lock_bh(&adapter->mcc_lock);
1469
1470 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001471 if (!wrb) {
1472 status = -EBUSY;
1473 goto err;
1474 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001475 req = embedded_payload(wrb);
1476
Ajit Khaparded744b442009-12-03 06:12:06 +00001477 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1478 OPCODE_COMMON_ENABLE_DISABLE_BEACON);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001479
1480 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1481 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1482
1483 req->port_num = port_num;
1484 req->beacon_state = state;
1485 req->beacon_duration = bcn;
1486 req->status_duration = sts;
1487
1488 status = be_mcc_notify_wait(adapter);
1489
Sathya Perla713d03942009-11-22 22:02:45 +00001490err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001491 spin_unlock_bh(&adapter->mcc_lock);
1492 return status;
1493}
1494
1495/* Uses sync mcc */
1496int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1497{
1498 struct be_mcc_wrb *wrb;
1499 struct be_cmd_req_get_beacon_state *req;
1500 int status;
1501
1502 spin_lock_bh(&adapter->mcc_lock);
1503
1504 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001505 if (!wrb) {
1506 status = -EBUSY;
1507 goto err;
1508 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001509 req = embedded_payload(wrb);
1510
Ajit Khaparded744b442009-12-03 06:12:06 +00001511 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1512 OPCODE_COMMON_GET_BEACON_STATE);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001513
1514 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1515 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1516
1517 req->port_num = port_num;
1518
1519 status = be_mcc_notify_wait(adapter);
1520 if (!status) {
1521 struct be_cmd_resp_get_beacon_state *resp =
1522 embedded_payload(wrb);
1523 *state = resp->beacon_state;
1524 }
1525
Sathya Perla713d03942009-11-22 22:02:45 +00001526err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001527 spin_unlock_bh(&adapter->mcc_lock);
1528 return status;
1529}
1530
Ajit Khaparde84517482009-09-04 03:12:16 +00001531int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1532 u32 flash_type, u32 flash_opcode, u32 buf_size)
1533{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001534 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001535 struct be_cmd_write_flashrom *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001536 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001537 int status;
1538
Sathya Perlab31c50a2009-09-17 10:30:13 -07001539 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001540 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001541
1542 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001543 if (!wrb) {
1544 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001545 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00001546 }
1547 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001548 sge = nonembedded_sgl(wrb);
1549
Ajit Khaparded744b442009-12-03 06:12:06 +00001550 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1551 OPCODE_COMMON_WRITE_FLASHROM);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001552 wrb->tag1 = CMD_SUBSYSTEM_COMMON;
Ajit Khaparde84517482009-09-04 03:12:16 +00001553
1554 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1555 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1556 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1557 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1558 sge->len = cpu_to_le32(cmd->size);
1559
1560 req->params.op_type = cpu_to_le32(flash_type);
1561 req->params.op_code = cpu_to_le32(flash_opcode);
1562 req->params.data_buf_size = cpu_to_le32(buf_size);
1563
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001564 be_mcc_notify(adapter);
1565 spin_unlock_bh(&adapter->mcc_lock);
1566
1567 if (!wait_for_completion_timeout(&adapter->flash_compl,
1568 msecs_to_jiffies(12000)))
1569 status = -1;
1570 else
1571 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00001572
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001573 return status;
1574
1575err_unlock:
1576 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001577 return status;
1578}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001579
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001580int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1581 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001582{
1583 struct be_mcc_wrb *wrb;
1584 struct be_cmd_write_flashrom *req;
1585 int status;
1586
1587 spin_lock_bh(&adapter->mcc_lock);
1588
1589 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001590 if (!wrb) {
1591 status = -EBUSY;
1592 goto err;
1593 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001594 req = embedded_payload(wrb);
1595
Ajit Khaparded744b442009-12-03 06:12:06 +00001596 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
1597 OPCODE_COMMON_READ_FLASHROM);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001598
1599 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1600 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1601
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001602 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001603 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00001604 req->params.offset = cpu_to_le32(offset);
1605 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001606
1607 status = be_mcc_notify_wait(adapter);
1608 if (!status)
1609 memcpy(flashed_crc, req->params.data_buf, 4);
1610
Sathya Perla713d03942009-11-22 22:02:45 +00001611err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001612 spin_unlock_bh(&adapter->mcc_lock);
1613 return status;
1614}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001615
Dan Carpenterc196b022010-05-26 04:47:39 +00001616int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001617 struct be_dma_mem *nonemb_cmd)
1618{
1619 struct be_mcc_wrb *wrb;
1620 struct be_cmd_req_acpi_wol_magic_config *req;
1621 struct be_sge *sge;
1622 int status;
1623
1624 spin_lock_bh(&adapter->mcc_lock);
1625
1626 wrb = wrb_from_mccq(adapter);
1627 if (!wrb) {
1628 status = -EBUSY;
1629 goto err;
1630 }
1631 req = nonemb_cmd->va;
1632 sge = nonembedded_sgl(wrb);
1633
1634 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1635 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
1636
1637 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1638 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
1639 memcpy(req->magic_mac, mac, ETH_ALEN);
1640
1641 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1642 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1643 sge->len = cpu_to_le32(nonemb_cmd->size);
1644
1645 status = be_mcc_notify_wait(adapter);
1646
1647err:
1648 spin_unlock_bh(&adapter->mcc_lock);
1649 return status;
1650}
Suresh Rff33a6e2009-12-03 16:15:52 -08001651
Sarveshwar Bandifced9992009-12-23 04:41:44 +00001652int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
1653 u8 loopback_type, u8 enable)
1654{
1655 struct be_mcc_wrb *wrb;
1656 struct be_cmd_req_set_lmode *req;
1657 int status;
1658
1659 spin_lock_bh(&adapter->mcc_lock);
1660
1661 wrb = wrb_from_mccq(adapter);
1662 if (!wrb) {
1663 status = -EBUSY;
1664 goto err;
1665 }
1666
1667 req = embedded_payload(wrb);
1668
1669 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1670 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
1671
1672 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1673 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
1674 sizeof(*req));
1675
1676 req->src_port = port_num;
1677 req->dest_port = port_num;
1678 req->loopback_type = loopback_type;
1679 req->loopback_state = enable;
1680
1681 status = be_mcc_notify_wait(adapter);
1682err:
1683 spin_unlock_bh(&adapter->mcc_lock);
1684 return status;
1685}
1686
Suresh Rff33a6e2009-12-03 16:15:52 -08001687int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
1688 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
1689{
1690 struct be_mcc_wrb *wrb;
1691 struct be_cmd_req_loopback_test *req;
1692 int status;
1693
1694 spin_lock_bh(&adapter->mcc_lock);
1695
1696 wrb = wrb_from_mccq(adapter);
1697 if (!wrb) {
1698 status = -EBUSY;
1699 goto err;
1700 }
1701
1702 req = embedded_payload(wrb);
1703
1704 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1705 OPCODE_LOWLEVEL_LOOPBACK_TEST);
1706
1707 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1708 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
Sathya Perla3ffd0512010-06-01 00:19:33 -07001709 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08001710
1711 req->pattern = cpu_to_le64(pattern);
1712 req->src_port = cpu_to_le32(port_num);
1713 req->dest_port = cpu_to_le32(port_num);
1714 req->pkt_size = cpu_to_le32(pkt_size);
1715 req->num_pkts = cpu_to_le32(num_pkts);
1716 req->loopback_type = cpu_to_le32(loopback_type);
1717
1718 status = be_mcc_notify_wait(adapter);
1719 if (!status) {
1720 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
1721 status = le32_to_cpu(resp->status);
1722 }
1723
1724err:
1725 spin_unlock_bh(&adapter->mcc_lock);
1726 return status;
1727}
1728
1729int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
1730 u32 byte_cnt, struct be_dma_mem *cmd)
1731{
1732 struct be_mcc_wrb *wrb;
1733 struct be_cmd_req_ddrdma_test *req;
1734 struct be_sge *sge;
1735 int status;
1736 int i, j = 0;
1737
1738 spin_lock_bh(&adapter->mcc_lock);
1739
1740 wrb = wrb_from_mccq(adapter);
1741 if (!wrb) {
1742 status = -EBUSY;
1743 goto err;
1744 }
1745 req = cmd->va;
1746 sge = nonembedded_sgl(wrb);
1747 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1748 OPCODE_LOWLEVEL_HOST_DDR_DMA);
1749 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1750 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
1751
1752 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1753 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1754 sge->len = cpu_to_le32(cmd->size);
1755
1756 req->pattern = cpu_to_le64(pattern);
1757 req->byte_count = cpu_to_le32(byte_cnt);
1758 for (i = 0; i < byte_cnt; i++) {
1759 req->snd_buff[i] = (u8)(pattern >> (j*8));
1760 j++;
1761 if (j > 7)
1762 j = 0;
1763 }
1764
1765 status = be_mcc_notify_wait(adapter);
1766
1767 if (!status) {
1768 struct be_cmd_resp_ddrdma_test *resp;
1769 resp = cmd->va;
1770 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
1771 resp->snd_err) {
1772 status = -1;
1773 }
1774 }
1775
1776err:
1777 spin_unlock_bh(&adapter->mcc_lock);
1778 return status;
1779}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001780
Dan Carpenterc196b022010-05-26 04:47:39 +00001781int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001782 struct be_dma_mem *nonemb_cmd)
1783{
1784 struct be_mcc_wrb *wrb;
1785 struct be_cmd_req_seeprom_read *req;
1786 struct be_sge *sge;
1787 int status;
1788
1789 spin_lock_bh(&adapter->mcc_lock);
1790
1791 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00001792 if (!wrb) {
1793 status = -EBUSY;
1794 goto err;
1795 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001796 req = nonemb_cmd->va;
1797 sge = nonembedded_sgl(wrb);
1798
1799 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1800 OPCODE_COMMON_SEEPROM_READ);
1801
1802 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1803 OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
1804
1805 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1806 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1807 sge->len = cpu_to_le32(nonemb_cmd->size);
1808
1809 status = be_mcc_notify_wait(adapter);
1810
Ajit Khapardee45ff012011-02-04 17:18:28 +00001811err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001812 spin_unlock_bh(&adapter->mcc_lock);
1813 return status;
1814}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00001815
1816int be_cmd_get_phy_info(struct be_adapter *adapter, struct be_dma_mem *cmd)
1817{
1818 struct be_mcc_wrb *wrb;
1819 struct be_cmd_req_get_phy_info *req;
1820 struct be_sge *sge;
1821 int status;
1822
1823 spin_lock_bh(&adapter->mcc_lock);
1824
1825 wrb = wrb_from_mccq(adapter);
1826 if (!wrb) {
1827 status = -EBUSY;
1828 goto err;
1829 }
1830
1831 req = cmd->va;
1832 sge = nonembedded_sgl(wrb);
1833
1834 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1835 OPCODE_COMMON_GET_PHY_DETAILS);
1836
1837 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1838 OPCODE_COMMON_GET_PHY_DETAILS,
1839 sizeof(*req));
1840
1841 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1842 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1843 sge->len = cpu_to_le32(cmd->size);
1844
1845 status = be_mcc_notify_wait(adapter);
1846err:
1847 spin_unlock_bh(&adapter->mcc_lock);
1848 return status;
1849}
Ajit Khapardee1d18732010-07-23 01:52:13 +00001850
1851int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
1852{
1853 struct be_mcc_wrb *wrb;
1854 struct be_cmd_req_set_qos *req;
1855 int status;
1856
1857 spin_lock_bh(&adapter->mcc_lock);
1858
1859 wrb = wrb_from_mccq(adapter);
1860 if (!wrb) {
1861 status = -EBUSY;
1862 goto err;
1863 }
1864
1865 req = embedded_payload(wrb);
1866
1867 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1868 OPCODE_COMMON_SET_QOS);
1869
1870 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1871 OPCODE_COMMON_SET_QOS, sizeof(*req));
1872
1873 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00001874 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
1875 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00001876
1877 status = be_mcc_notify_wait(adapter);
1878
1879err:
1880 spin_unlock_bh(&adapter->mcc_lock);
1881 return status;
1882}