blob: af8cf3d7c1e33337577fdff0f6c1ddea951b98b5 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Ajit Khaparded2145cd2011-03-16 08:20:46 +00002 * Copyright (C) 2005 - 2011 Emulex
Sathya Perla6b7c5b92009-03-11 23:32:03 -07003 * All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License version 2
7 * as published by the Free Software Foundation. The full GNU General
8 * Public License is included in this distribution in the file called COPYING.
9 *
10 * Contact Information:
Ajit Khaparded2145cd2011-03-16 08:20:46 +000011 * linux-drivers@emulex.com
Sathya Perla6b7c5b92009-03-11 23:32:03 -070012 *
Ajit Khaparded2145cd2011-03-16 08:20:46 +000013 * Emulex
14 * 3333 Susan Street
15 * Costa Mesa, CA 92626
Sathya Perla6b7c5b92009-03-11 23:32:03 -070016 */
17
18#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000019#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070020
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000021/* Must be a power of 2 or else MODULO will BUG_ON */
22static int be_get_temp_freq = 32;
23
Sathya Perla8788fdc2009-07-27 22:52:03 +000024static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000025{
Sathya Perla8788fdc2009-07-27 22:52:03 +000026 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000027 u32 val = 0;
28
Ajit Khaparde7acc2082011-02-11 13:38:17 +000029 if (adapter->eeh_err) {
30 dev_info(&adapter->pdev->dev,
31 "Error in Card Detected! Cannot issue commands\n");
32 return;
33 }
34
Sathya Perla5fb379e2009-06-18 00:02:59 +000035 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
36 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +000037
38 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +000039 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +000040}
41
42/* To check if valid bit is set, check the entire word as we don't know
43 * the endianness of the data (old entry is host endian while a new entry is
44 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +000045static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000046{
47 if (compl->flags != 0) {
48 compl->flags = le32_to_cpu(compl->flags);
49 BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0);
50 return true;
51 } else {
52 return false;
53 }
54}
55
56/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +000057static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000058{
59 compl->flags = 0;
60}
61
Sathya Perla8788fdc2009-07-27 22:52:03 +000062static int be_mcc_compl_process(struct be_adapter *adapter,
Sathya Perlaefd2e402009-07-27 22:53:10 +000063 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +000064{
65 u16 compl_status, extd_status;
66
67 /* Just swap the status to host endian; mcc tag is opaquely copied
68 * from mcc_wrb */
69 be_dws_le_to_cpu(compl, 4);
70
71 compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) &
72 CQE_STATUS_COMPL_MASK;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -070073
74 if ((compl->tag0 == OPCODE_COMMON_WRITE_FLASHROM) &&
75 (compl->tag1 == CMD_SUBSYSTEM_COMMON)) {
76 adapter->flash_status = compl_status;
77 complete(&adapter->flash_compl);
78 }
79
Sathya Perlab31c50a2009-09-17 10:30:13 -070080 if (compl_status == MCC_STATUS_SUCCESS) {
Ajit Khaparde63499352011-04-19 12:11:02 +000081 if ((compl->tag0 == OPCODE_ETH_GET_STATISTICS) &&
82 (compl->tag1 == CMD_SUBSYSTEM_ETH)) {
Sathya Perlab31c50a2009-09-17 10:30:13 -070083 struct be_cmd_resp_get_stats *resp =
Sathya Perla3abcded2010-10-03 22:12:27 -070084 adapter->stats_cmd.va;
Sathya Perlab31c50a2009-09-17 10:30:13 -070085 be_dws_le_to_cpu(&resp->hw_stats,
86 sizeof(resp->hw_stats));
87 netdev_stats_update(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +000088 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -070089 }
Ajit Khaparde89438072010-07-23 12:42:40 -070090 } else if ((compl_status != MCC_STATUS_NOT_SUPPORTED) &&
91 (compl->tag0 != OPCODE_COMMON_NTWK_MAC_QUERY)) {
Sathya Perla5fb379e2009-06-18 00:02:59 +000092 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
93 CQE_STATUS_EXTD_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +000094 dev_warn(&adapter->pdev->dev,
Ajit Khaparded744b442009-12-03 06:12:06 +000095 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
96 compl->tag0, compl_status, extd_status);
Sathya Perla5fb379e2009-06-18 00:02:59 +000097 }
Sathya Perlab31c50a2009-09-17 10:30:13 -070098 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +000099}
100
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000101/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000102static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000103 struct be_async_event_link_state *evt)
104{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000105 be_link_status_update(adapter,
106 evt->port_link_status == ASYNC_EVENT_LINK_UP);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000107}
108
Somnath Koturcc4ce022010-10-21 07:11:14 -0700109/* Grp5 CoS Priority evt */
110static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
111 struct be_async_event_grp5_cos_priority *evt)
112{
113 if (evt->valid) {
114 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000115 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700116 adapter->recommended_prio =
117 evt->reco_default_priority << VLAN_PRIO_SHIFT;
118 }
119}
120
121/* Grp5 QOS Speed evt */
122static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
123 struct be_async_event_grp5_qos_link_speed *evt)
124{
125 if (evt->physical_port == adapter->port_num) {
126 /* qos_link_speed is in units of 10 Mbps */
127 adapter->link_speed = evt->qos_link_speed * 10;
128 }
129}
130
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000131/*Grp5 PVID evt*/
132static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
133 struct be_async_event_grp5_pvid_state *evt)
134{
135 if (evt->enabled)
136 adapter->pvid = evt->tag;
137 else
138 adapter->pvid = 0;
139}
140
Somnath Koturcc4ce022010-10-21 07:11:14 -0700141static void be_async_grp5_evt_process(struct be_adapter *adapter,
142 u32 trailer, struct be_mcc_compl *evt)
143{
144 u8 event_type = 0;
145
146 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
147 ASYNC_TRAILER_EVENT_TYPE_MASK;
148
149 switch (event_type) {
150 case ASYNC_EVENT_COS_PRIORITY:
151 be_async_grp5_cos_priority_process(adapter,
152 (struct be_async_event_grp5_cos_priority *)evt);
153 break;
154 case ASYNC_EVENT_QOS_SPEED:
155 be_async_grp5_qos_speed_process(adapter,
156 (struct be_async_event_grp5_qos_link_speed *)evt);
157 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000158 case ASYNC_EVENT_PVID_STATE:
159 be_async_grp5_pvid_state_process(adapter,
160 (struct be_async_event_grp5_pvid_state *)evt);
161 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700162 default:
163 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
164 break;
165 }
166}
167
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000168static inline bool is_link_state_evt(u32 trailer)
169{
Eric Dumazet807540b2010-09-23 05:40:09 +0000170 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000171 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000172 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000173}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000174
Somnath Koturcc4ce022010-10-21 07:11:14 -0700175static inline bool is_grp5_evt(u32 trailer)
176{
177 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
178 ASYNC_TRAILER_EVENT_CODE_MASK) ==
179 ASYNC_EVENT_CODE_GRP_5);
180}
181
Sathya Perlaefd2e402009-07-27 22:53:10 +0000182static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000183{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000184 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000185 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000186
187 if (be_mcc_compl_is_new(compl)) {
188 queue_tail_inc(mcc_cq);
189 return compl;
190 }
191 return NULL;
192}
193
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000194void be_async_mcc_enable(struct be_adapter *adapter)
195{
196 spin_lock_bh(&adapter->mcc_cq_lock);
197
198 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
199 adapter->mcc_obj.rearm_cq = true;
200
201 spin_unlock_bh(&adapter->mcc_cq_lock);
202}
203
204void be_async_mcc_disable(struct be_adapter *adapter)
205{
206 adapter->mcc_obj.rearm_cq = false;
207}
208
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800209int be_process_mcc(struct be_adapter *adapter, int *status)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000210{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000211 struct be_mcc_compl *compl;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800212 int num = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000213 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000214
Sathya Perla8788fdc2009-07-27 22:52:03 +0000215 spin_lock_bh(&adapter->mcc_cq_lock);
216 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000217 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
218 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000219 if (is_link_state_evt(compl->flags))
220 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000221 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700222 else if (is_grp5_evt(compl->flags))
223 be_async_grp5_evt_process(adapter,
224 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700225 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800226 *status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000227 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000228 }
229 be_mcc_compl_use(compl);
230 num++;
231 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700232
Sathya Perla8788fdc2009-07-27 22:52:03 +0000233 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800234 return num;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000235}
236
Sathya Perla6ac7b682009-06-18 00:05:54 +0000237/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700238static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000239{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700240#define mcc_timeout 120000 /* 12s timeout */
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800241 int i, num, status = 0;
242 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700243
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000244 if (adapter->eeh_err)
245 return -EIO;
246
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800247 for (i = 0; i < mcc_timeout; i++) {
248 num = be_process_mcc(adapter, &status);
249 if (num)
250 be_cq_notify(adapter, mcc_obj->cq.id,
251 mcc_obj->rearm_cq, num);
252
253 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000254 break;
255 udelay(100);
256 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700257 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000258 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700259 return -1;
260 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800261 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000262}
263
264/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700265static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000266{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000267 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700268 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000269}
270
Sathya Perla5f0b8492009-07-27 22:52:56 +0000271static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700272{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000273 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700274 u32 ready;
275
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000276 if (adapter->eeh_err) {
277 dev_err(&adapter->pdev->dev,
278 "Error detected in card.Cannot issue commands\n");
279 return -EIO;
280 }
281
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700282 do {
Sathya Perlacf588472010-02-14 21:22:01 +0000283 ready = ioread32(db);
284 if (ready == 0xffffffff) {
285 dev_err(&adapter->pdev->dev,
286 "pci slot disconnected\n");
287 return -1;
288 }
289
290 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700291 if (ready)
292 break;
293
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000294 if (msecs > 4000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000295 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Ajit Khaparded053de92010-09-03 06:23:30 +0000296 be_detect_dump_ue(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700297 return -1;
298 }
299
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000300 set_current_state(TASK_INTERRUPTIBLE);
301 schedule_timeout(msecs_to_jiffies(1));
302 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700303 } while (true);
304
305 return 0;
306}
307
308/*
309 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000310 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700311 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700312static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700313{
314 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700315 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000316 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
317 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700318 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000319 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700320
Sathya Perlacf588472010-02-14 21:22:01 +0000321 /* wait for ready to be set */
322 status = be_mbox_db_ready_wait(adapter, db);
323 if (status != 0)
324 return status;
325
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700326 val |= MPU_MAILBOX_DB_HI_MASK;
327 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
328 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
329 iowrite32(val, db);
330
331 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000332 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700333 if (status != 0)
334 return status;
335
336 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700337 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
338 val |= (u32)(mbox_mem->dma >> 4) << 2;
339 iowrite32(val, db);
340
Sathya Perla5f0b8492009-07-27 22:52:56 +0000341 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700342 if (status != 0)
343 return status;
344
Sathya Perla5fb379e2009-06-18 00:02:59 +0000345 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000346 if (be_mcc_compl_is_new(compl)) {
347 status = be_mcc_compl_process(adapter, &mbox->compl);
348 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000349 if (status)
350 return status;
351 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000352 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700353 return -1;
354 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000355 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700356}
357
Sathya Perla8788fdc2009-07-27 22:52:03 +0000358static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700359{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000360 u32 sem;
361
362 if (lancer_chip(adapter))
363 sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
364 else
365 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700366
367 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
368 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
369 return -1;
370 else
371 return 0;
372}
373
Sathya Perla8788fdc2009-07-27 22:52:03 +0000374int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700375{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000376 u16 stage;
377 int status, timeout = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700378
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000379 do {
380 status = be_POST_stage_get(adapter, &stage);
381 if (status) {
382 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
383 stage);
384 return -1;
385 } else if (stage != POST_STAGE_ARMFW_RDY) {
386 set_current_state(TASK_INTERRUPTIBLE);
387 schedule_timeout(2 * HZ);
388 timeout += 2;
389 } else {
390 return 0;
391 }
Sathya Perlad938a702010-05-26 00:33:43 -0700392 } while (timeout < 40);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700393
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000394 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
395 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700396}
397
398static inline void *embedded_payload(struct be_mcc_wrb *wrb)
399{
400 return wrb->payload.embedded_payload;
401}
402
403static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
404{
405 return &wrb->payload.sgl[0];
406}
407
408/* Don't touch the hdr after it's prepared */
409static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
Ajit Khaparded744b442009-12-03 06:12:06 +0000410 bool embedded, u8 sge_cnt, u32 opcode)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700411{
412 if (embedded)
413 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
414 else
415 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
416 MCC_WRB_SGE_CNT_SHIFT;
417 wrb->payload_length = payload_len;
Ajit Khaparded744b442009-12-03 06:12:06 +0000418 wrb->tag0 = opcode;
Sathya Perlafa4281b2010-01-21 22:51:36 +0000419 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700420}
421
422/* Don't touch the hdr after it's prepared */
423static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
424 u8 subsystem, u8 opcode, int cmd_len)
425{
426 req_hdr->opcode = opcode;
427 req_hdr->subsystem = subsystem;
428 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000429 req_hdr->version = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700430}
431
432static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
433 struct be_dma_mem *mem)
434{
435 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
436 u64 dma = (u64)mem->dma;
437
438 for (i = 0; i < buf_pages; i++) {
439 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
440 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
441 dma += PAGE_SIZE_4K;
442 }
443}
444
445/* Converts interrupt delay in microseconds to multiplier value */
446static u32 eq_delay_to_mult(u32 usec_delay)
447{
448#define MAX_INTR_RATE 651042
449 const u32 round = 10;
450 u32 multiplier;
451
452 if (usec_delay == 0)
453 multiplier = 0;
454 else {
455 u32 interrupt_rate = 1000000 / usec_delay;
456 /* Max delay, corresponding to the lowest interrupt rate */
457 if (interrupt_rate == 0)
458 multiplier = 1023;
459 else {
460 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
461 multiplier /= interrupt_rate;
462 /* Round the multiplier to the closest value.*/
463 multiplier = (multiplier + round/2) / round;
464 multiplier = min(multiplier, (u32)1023);
465 }
466 }
467 return multiplier;
468}
469
Sathya Perlab31c50a2009-09-17 10:30:13 -0700470static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700471{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700472 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
473 struct be_mcc_wrb *wrb
474 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
475 memset(wrb, 0, sizeof(*wrb));
476 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700477}
478
Sathya Perlab31c50a2009-09-17 10:30:13 -0700479static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000480{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700481 struct be_queue_info *mccq = &adapter->mcc_obj.q;
482 struct be_mcc_wrb *wrb;
483
Sathya Perla713d03942009-11-22 22:02:45 +0000484 if (atomic_read(&mccq->used) >= mccq->len) {
485 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
486 return NULL;
487 }
488
Sathya Perlab31c50a2009-09-17 10:30:13 -0700489 wrb = queue_head_node(mccq);
490 queue_head_inc(mccq);
491 atomic_inc(&mccq->used);
492 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000493 return wrb;
494}
495
Sathya Perla2243e2e2009-11-22 22:02:03 +0000496/* Tell fw we're about to start firing cmds by writing a
497 * special pattern across the wrb hdr; uses mbox
498 */
499int be_cmd_fw_init(struct be_adapter *adapter)
500{
501 u8 *wrb;
502 int status;
503
Ivan Vecera29849612010-12-14 05:43:19 +0000504 if (mutex_lock_interruptible(&adapter->mbox_lock))
505 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000506
507 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000508 *wrb++ = 0xFF;
509 *wrb++ = 0x12;
510 *wrb++ = 0x34;
511 *wrb++ = 0xFF;
512 *wrb++ = 0xFF;
513 *wrb++ = 0x56;
514 *wrb++ = 0x78;
515 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000516
517 status = be_mbox_notify_wait(adapter);
518
Ivan Vecera29849612010-12-14 05:43:19 +0000519 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000520 return status;
521}
522
523/* Tell fw we're done with firing cmds by writing a
524 * special pattern across the wrb hdr; uses mbox
525 */
526int be_cmd_fw_clean(struct be_adapter *adapter)
527{
528 u8 *wrb;
529 int status;
530
Sathya Perlacf588472010-02-14 21:22:01 +0000531 if (adapter->eeh_err)
532 return -EIO;
533
Ivan Vecera29849612010-12-14 05:43:19 +0000534 if (mutex_lock_interruptible(&adapter->mbox_lock))
535 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000536
537 wrb = (u8 *)wrb_from_mbox(adapter);
538 *wrb++ = 0xFF;
539 *wrb++ = 0xAA;
540 *wrb++ = 0xBB;
541 *wrb++ = 0xFF;
542 *wrb++ = 0xFF;
543 *wrb++ = 0xCC;
544 *wrb++ = 0xDD;
545 *wrb = 0xFF;
546
547 status = be_mbox_notify_wait(adapter);
548
Ivan Vecera29849612010-12-14 05:43:19 +0000549 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000550 return status;
551}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000552int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700553 struct be_queue_info *eq, int eq_delay)
554{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700555 struct be_mcc_wrb *wrb;
556 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700557 struct be_dma_mem *q_mem = &eq->dma_mem;
558 int status;
559
Ivan Vecera29849612010-12-14 05:43:19 +0000560 if (mutex_lock_interruptible(&adapter->mbox_lock))
561 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700562
563 wrb = wrb_from_mbox(adapter);
564 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700565
Ajit Khaparded744b442009-12-03 06:12:06 +0000566 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700567
568 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
569 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
570
571 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
572
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700573 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
574 /* 4byte eqe*/
575 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
576 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
577 __ilog2_u32(eq->len/256));
578 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
579 eq_delay_to_mult(eq_delay));
580 be_dws_cpu_to_le(req->context, sizeof(req->context));
581
582 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
583
Sathya Perlab31c50a2009-09-17 10:30:13 -0700584 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700585 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700586 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700587 eq->id = le16_to_cpu(resp->eq_id);
588 eq->created = true;
589 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700590
Ivan Vecera29849612010-12-14 05:43:19 +0000591 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700592 return status;
593}
594
Sathya Perlab31c50a2009-09-17 10:30:13 -0700595/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000596int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700597 u8 type, bool permanent, u32 if_handle)
598{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700599 struct be_mcc_wrb *wrb;
600 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700601 int status;
602
Ivan Vecera29849612010-12-14 05:43:19 +0000603 if (mutex_lock_interruptible(&adapter->mbox_lock))
604 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700605
606 wrb = wrb_from_mbox(adapter);
607 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700608
Ajit Khaparded744b442009-12-03 06:12:06 +0000609 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
610 OPCODE_COMMON_NTWK_MAC_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700611
612 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
613 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
614
615 req->type = type;
616 if (permanent) {
617 req->permanent = 1;
618 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700619 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700620 req->permanent = 0;
621 }
622
Sathya Perlab31c50a2009-09-17 10:30:13 -0700623 status = be_mbox_notify_wait(adapter);
624 if (!status) {
625 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700626 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700627 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700628
Ivan Vecera29849612010-12-14 05:43:19 +0000629 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700630 return status;
631}
632
Sathya Perlab31c50a2009-09-17 10:30:13 -0700633/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000634int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000635 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700636{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700637 struct be_mcc_wrb *wrb;
638 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700639 int status;
640
Sathya Perlab31c50a2009-09-17 10:30:13 -0700641 spin_lock_bh(&adapter->mcc_lock);
642
643 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000644 if (!wrb) {
645 status = -EBUSY;
646 goto err;
647 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700648 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700649
Ajit Khaparded744b442009-12-03 06:12:06 +0000650 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
651 OPCODE_COMMON_NTWK_PMAC_ADD);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700652
653 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
654 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
655
Ajit Khapardef8617e02011-02-11 13:36:37 +0000656 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700657 req->if_id = cpu_to_le32(if_id);
658 memcpy(req->mac_address, mac_addr, ETH_ALEN);
659
Sathya Perlab31c50a2009-09-17 10:30:13 -0700660 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700661 if (!status) {
662 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
663 *pmac_id = le32_to_cpu(resp->pmac_id);
664 }
665
Sathya Perla713d03942009-11-22 22:02:45 +0000666err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700667 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700668 return status;
669}
670
Sathya Perlab31c50a2009-09-17 10:30:13 -0700671/* Uses synchronous MCCQ */
Ajit Khapardef8617e02011-02-11 13:36:37 +0000672int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700673{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700674 struct be_mcc_wrb *wrb;
675 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700676 int status;
677
Sathya Perlab31c50a2009-09-17 10:30:13 -0700678 spin_lock_bh(&adapter->mcc_lock);
679
680 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000681 if (!wrb) {
682 status = -EBUSY;
683 goto err;
684 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700685 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700686
Ajit Khaparded744b442009-12-03 06:12:06 +0000687 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
688 OPCODE_COMMON_NTWK_PMAC_DEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700689
690 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
691 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
692
Ajit Khapardef8617e02011-02-11 13:36:37 +0000693 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700694 req->if_id = cpu_to_le32(if_id);
695 req->pmac_id = cpu_to_le32(pmac_id);
696
Sathya Perlab31c50a2009-09-17 10:30:13 -0700697 status = be_mcc_notify_wait(adapter);
698
Sathya Perla713d03942009-11-22 22:02:45 +0000699err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700700 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700701 return status;
702}
703
Sathya Perlab31c50a2009-09-17 10:30:13 -0700704/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000705int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700706 struct be_queue_info *cq, struct be_queue_info *eq,
707 bool sol_evts, bool no_delay, int coalesce_wm)
708{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700709 struct be_mcc_wrb *wrb;
710 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700711 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700712 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700713 int status;
714
Ivan Vecera29849612010-12-14 05:43:19 +0000715 if (mutex_lock_interruptible(&adapter->mbox_lock))
716 return -1;
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_COMMON_CQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700724
725 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
726 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
727
728 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000729 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000730 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000731 req->page_size = 1; /* 1 for 4K */
732 AMAP_SET_BITS(struct amap_cq_context_lancer, coalescwm, ctxt,
733 coalesce_wm);
734 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
735 no_delay);
736 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
737 __ilog2_u32(cq->len/256));
738 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
739 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
740 ctxt, 1);
741 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
742 ctxt, eq->id);
743 AMAP_SET_BITS(struct amap_cq_context_lancer, armed, ctxt, 1);
744 } else {
745 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
746 coalesce_wm);
747 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
748 ctxt, no_delay);
749 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
750 __ilog2_u32(cq->len/256));
751 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
752 AMAP_SET_BITS(struct amap_cq_context_be, solevent,
753 ctxt, sol_evts);
754 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
755 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
756 AMAP_SET_BITS(struct amap_cq_context_be, armed, ctxt, 1);
757 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700758
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700759 be_dws_cpu_to_le(ctxt, sizeof(req->context));
760
761 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
762
Sathya Perlab31c50a2009-09-17 10:30:13 -0700763 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700764 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700765 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700766 cq->id = le16_to_cpu(resp->cq_id);
767 cq->created = true;
768 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700769
Ivan Vecera29849612010-12-14 05:43:19 +0000770 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000771
772 return status;
773}
774
775static u32 be_encoded_q_len(int q_len)
776{
777 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
778 if (len_encoded == 16)
779 len_encoded = 0;
780 return len_encoded;
781}
782
Sathya Perla8788fdc2009-07-27 22:52:03 +0000783int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000784 struct be_queue_info *mccq,
785 struct be_queue_info *cq)
786{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700787 struct be_mcc_wrb *wrb;
788 struct be_cmd_req_mcc_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000789 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700790 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000791 int status;
792
Ivan Vecera29849612010-12-14 05:43:19 +0000793 if (mutex_lock_interruptible(&adapter->mbox_lock))
794 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700795
796 wrb = wrb_from_mbox(adapter);
797 req = embedded_payload(wrb);
798 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000799
Ajit Khaparded744b442009-12-03 06:12:06 +0000800 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700801 OPCODE_COMMON_MCC_CREATE_EXT);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000802
803 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700804 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000805
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000806 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000807 if (lancer_chip(adapter)) {
808 req->hdr.version = 1;
809 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000810
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000811 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
812 be_encoded_q_len(mccq->len));
813 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
814 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
815 ctxt, cq->id);
816 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
817 ctxt, 1);
818
819 } else {
820 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
821 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
822 be_encoded_q_len(mccq->len));
823 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
824 }
825
Somnath Koturcc4ce022010-10-21 07:11:14 -0700826 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000827 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000828 be_dws_cpu_to_le(ctxt, sizeof(req->context));
829
830 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
831
Sathya Perlab31c50a2009-09-17 10:30:13 -0700832 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000833 if (!status) {
834 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
835 mccq->id = le16_to_cpu(resp->id);
836 mccq->created = true;
837 }
Ivan Vecera29849612010-12-14 05:43:19 +0000838 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700839
840 return status;
841}
842
Sathya Perla8788fdc2009-07-27 22:52:03 +0000843int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700844 struct be_queue_info *txq,
845 struct be_queue_info *cq)
846{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700847 struct be_mcc_wrb *wrb;
848 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700849 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700850 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700851 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700852
Ivan Vecera29849612010-12-14 05:43:19 +0000853 if (mutex_lock_interruptible(&adapter->mbox_lock))
854 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700855
856 wrb = wrb_from_mbox(adapter);
857 req = embedded_payload(wrb);
858 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700859
Ajit Khaparded744b442009-12-03 06:12:06 +0000860 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
861 OPCODE_ETH_TX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700862
863 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
864 sizeof(*req));
865
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000866 if (lancer_chip(adapter)) {
867 req->hdr.version = 1;
868 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
869 adapter->if_handle);
870 }
871
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700872 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
873 req->ulp_num = BE_ULP1_NUM;
874 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
875
Sathya Perlab31c50a2009-09-17 10:30:13 -0700876 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
877 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700878 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
879 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
880
881 be_dws_cpu_to_le(ctxt, sizeof(req->context));
882
883 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
884
Sathya Perlab31c50a2009-09-17 10:30:13 -0700885 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700886 if (!status) {
887 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
888 txq->id = le16_to_cpu(resp->cid);
889 txq->created = true;
890 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700891
Ivan Vecera29849612010-12-14 05:43:19 +0000892 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700893
894 return status;
895}
896
Sathya Perlab31c50a2009-09-17 10:30:13 -0700897/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000898int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700899 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla3abcded2010-10-03 22:12:27 -0700900 u16 max_frame_size, u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700901{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700902 struct be_mcc_wrb *wrb;
903 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700904 struct be_dma_mem *q_mem = &rxq->dma_mem;
905 int status;
906
Ivan Vecera29849612010-12-14 05:43:19 +0000907 if (mutex_lock_interruptible(&adapter->mbox_lock))
908 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700909
910 wrb = wrb_from_mbox(adapter);
911 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700912
Ajit Khaparded744b442009-12-03 06:12:06 +0000913 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
914 OPCODE_ETH_RX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700915
916 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
917 sizeof(*req));
918
919 req->cq_id = cpu_to_le16(cq_id);
920 req->frag_size = fls(frag_size) - 1;
921 req->num_pages = 2;
922 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
923 req->interface_id = cpu_to_le32(if_id);
924 req->max_frame_size = cpu_to_le16(max_frame_size);
925 req->rss_queue = cpu_to_le32(rss);
926
Sathya Perlab31c50a2009-09-17 10:30:13 -0700927 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700928 if (!status) {
929 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
930 rxq->id = le16_to_cpu(resp->id);
931 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -0700932 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700933 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700934
Ivan Vecera29849612010-12-14 05:43:19 +0000935 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700936
937 return status;
938}
939
Sathya Perlab31c50a2009-09-17 10:30:13 -0700940/* Generic destroyer function for all types of queues
941 * Uses Mbox
942 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000943int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700944 int queue_type)
945{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700946 struct be_mcc_wrb *wrb;
947 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700948 u8 subsys = 0, opcode = 0;
949 int status;
950
Sathya Perlacf588472010-02-14 21:22:01 +0000951 if (adapter->eeh_err)
952 return -EIO;
953
Ivan Vecera29849612010-12-14 05:43:19 +0000954 if (mutex_lock_interruptible(&adapter->mbox_lock))
955 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700956
Sathya Perlab31c50a2009-09-17 10:30:13 -0700957 wrb = wrb_from_mbox(adapter);
958 req = embedded_payload(wrb);
959
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700960 switch (queue_type) {
961 case QTYPE_EQ:
962 subsys = CMD_SUBSYSTEM_COMMON;
963 opcode = OPCODE_COMMON_EQ_DESTROY;
964 break;
965 case QTYPE_CQ:
966 subsys = CMD_SUBSYSTEM_COMMON;
967 opcode = OPCODE_COMMON_CQ_DESTROY;
968 break;
969 case QTYPE_TXQ:
970 subsys = CMD_SUBSYSTEM_ETH;
971 opcode = OPCODE_ETH_TX_DESTROY;
972 break;
973 case QTYPE_RXQ:
974 subsys = CMD_SUBSYSTEM_ETH;
975 opcode = OPCODE_ETH_RX_DESTROY;
976 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000977 case QTYPE_MCCQ:
978 subsys = CMD_SUBSYSTEM_COMMON;
979 opcode = OPCODE_COMMON_MCC_DESTROY;
980 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700981 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +0000982 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700983 }
Ajit Khaparded744b442009-12-03 06:12:06 +0000984
985 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
986
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700987 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
988 req->id = cpu_to_le16(q->id);
989
Sathya Perlab31c50a2009-09-17 10:30:13 -0700990 status = be_mbox_notify_wait(adapter);
Sathya Perla5f0b8492009-07-27 22:52:56 +0000991
Ivan Vecera29849612010-12-14 05:43:19 +0000992 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700993
994 return status;
995}
996
Sathya Perlab31c50a2009-09-17 10:30:13 -0700997/* Create an rx filtering policy configuration on an i/f
998 * Uses mbox
999 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001000int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001001 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id,
1002 u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001003{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001004 struct be_mcc_wrb *wrb;
1005 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001006 int status;
1007
Ivan Vecera29849612010-12-14 05:43:19 +00001008 if (mutex_lock_interruptible(&adapter->mbox_lock))
1009 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001010
1011 wrb = wrb_from_mbox(adapter);
1012 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001013
Ajit Khaparded744b442009-12-03 06:12:06 +00001014 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1015 OPCODE_COMMON_NTWK_INTERFACE_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001016
1017 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1018 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
1019
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001020 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001021 req->capability_flags = cpu_to_le32(cap_flags);
1022 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001023 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001024 if (!pmac_invalid)
1025 memcpy(req->mac_addr, mac, ETH_ALEN);
1026
Sathya Perlab31c50a2009-09-17 10:30:13 -07001027 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001028 if (!status) {
1029 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1030 *if_handle = le32_to_cpu(resp->interface_id);
1031 if (!pmac_invalid)
1032 *pmac_id = le32_to_cpu(resp->pmac_id);
1033 }
1034
Ivan Vecera29849612010-12-14 05:43:19 +00001035 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001036 return status;
1037}
1038
Sathya Perlab31c50a2009-09-17 10:30:13 -07001039/* Uses mbox */
Ajit Khaparde658681f2011-02-11 13:34:46 +00001040int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001041{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001042 struct be_mcc_wrb *wrb;
1043 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001044 int status;
1045
Sathya Perlacf588472010-02-14 21:22:01 +00001046 if (adapter->eeh_err)
1047 return -EIO;
1048
Ivan Vecera29849612010-12-14 05:43:19 +00001049 if (mutex_lock_interruptible(&adapter->mbox_lock))
1050 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001051
1052 wrb = wrb_from_mbox(adapter);
1053 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001054
Ajit Khaparded744b442009-12-03 06:12:06 +00001055 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1056 OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001057
1058 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1059 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
1060
Ajit Khaparde658681f2011-02-11 13:34:46 +00001061 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001062 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001063
1064 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001065
Ivan Vecera29849612010-12-14 05:43:19 +00001066 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001067
1068 return status;
1069}
1070
1071/* Get stats is a non embedded command: the request is not embedded inside
1072 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001073 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001074 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001075int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001076{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001077 struct be_mcc_wrb *wrb;
1078 struct be_cmd_req_get_stats *req;
1079 struct be_sge *sge;
Sathya Perla713d03942009-11-22 22:02:45 +00001080 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001081
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001082 if (MODULO(adapter->work_counter, be_get_temp_freq) == 0)
1083 be_cmd_get_die_temperature(adapter);
1084
Sathya Perlab31c50a2009-09-17 10:30:13 -07001085 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001086
Sathya Perlab31c50a2009-09-17 10:30:13 -07001087 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001088 if (!wrb) {
1089 status = -EBUSY;
1090 goto err;
1091 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001092 req = nonemb_cmd->va;
1093 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001094
Ajit Khaparded744b442009-12-03 06:12:06 +00001095 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1096 OPCODE_ETH_GET_STATISTICS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001097
1098 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1099 OPCODE_ETH_GET_STATISTICS, sizeof(*req));
Ajit Khaparde63499352011-04-19 12:11:02 +00001100 wrb->tag1 = CMD_SUBSYSTEM_ETH;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001101 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1102 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1103 sge->len = cpu_to_le32(nonemb_cmd->size);
1104
Sathya Perlab31c50a2009-09-17 10:30:13 -07001105 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001106 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001107
Sathya Perla713d03942009-11-22 22:02:45 +00001108err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001109 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001110 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001111}
1112
Sathya Perlab31c50a2009-09-17 10:30:13 -07001113/* Uses synchronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001114int be_cmd_link_status_query(struct be_adapter *adapter,
Ajit Khaparde187e8752011-04-19 12:11:46 +00001115 bool *link_up, u8 *mac_speed, u16 *link_speed, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001116{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001117 struct be_mcc_wrb *wrb;
1118 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001119 int status;
1120
Sathya Perlab31c50a2009-09-17 10:30:13 -07001121 spin_lock_bh(&adapter->mcc_lock);
1122
1123 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001124 if (!wrb) {
1125 status = -EBUSY;
1126 goto err;
1127 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001128 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001129
1130 *link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001131
Ajit Khaparded744b442009-12-03 06:12:06 +00001132 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1133 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001134
1135 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1136 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
1137
Sathya Perlab31c50a2009-09-17 10:30:13 -07001138 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001139 if (!status) {
1140 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001141 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001142 *link_up = true;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001143 *link_speed = le16_to_cpu(resp->link_speed);
1144 *mac_speed = resp->mac_speed;
1145 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001146 }
1147
Sathya Perla713d03942009-11-22 22:02:45 +00001148err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001149 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001150 return status;
1151}
1152
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001153/* Uses synchronous mcc */
1154int be_cmd_get_die_temperature(struct be_adapter *adapter)
1155{
1156 struct be_mcc_wrb *wrb;
1157 struct be_cmd_req_get_cntl_addnl_attribs *req;
1158 int status;
1159
1160 spin_lock_bh(&adapter->mcc_lock);
1161
1162 wrb = wrb_from_mccq(adapter);
1163 if (!wrb) {
1164 status = -EBUSY;
1165 goto err;
1166 }
1167 req = embedded_payload(wrb);
1168
1169 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1170 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES);
1171
1172 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1173 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req));
1174
1175 status = be_mcc_notify_wait(adapter);
1176 if (!status) {
1177 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
1178 embedded_payload(wrb);
1179 adapter->drv_stats.be_on_die_temperature =
1180 resp->on_die_temperature;
1181 }
1182 /* If IOCTL fails once, do not bother issuing it again */
1183 else
1184 be_get_temp_freq = 0;
1185
1186err:
1187 spin_unlock_bh(&adapter->mcc_lock);
1188 return status;
1189}
1190
Somnath Kotur311fddc2011-03-16 21:22:43 +00001191/* Uses synchronous mcc */
1192int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1193{
1194 struct be_mcc_wrb *wrb;
1195 struct be_cmd_req_get_fat *req;
1196 int status;
1197
1198 spin_lock_bh(&adapter->mcc_lock);
1199
1200 wrb = wrb_from_mccq(adapter);
1201 if (!wrb) {
1202 status = -EBUSY;
1203 goto err;
1204 }
1205 req = embedded_payload(wrb);
1206
1207 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1208 OPCODE_COMMON_MANAGE_FAT);
1209
1210 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1211 OPCODE_COMMON_MANAGE_FAT, sizeof(*req));
1212 req->fat_operation = cpu_to_le32(QUERY_FAT);
1213 status = be_mcc_notify_wait(adapter);
1214 if (!status) {
1215 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
1216 if (log_size && resp->log_size)
1217 *log_size = le32_to_cpu(resp->log_size -
1218 sizeof(u32));
1219 }
1220err:
1221 spin_unlock_bh(&adapter->mcc_lock);
1222 return status;
1223}
1224
1225void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
1226{
1227 struct be_dma_mem get_fat_cmd;
1228 struct be_mcc_wrb *wrb;
1229 struct be_cmd_req_get_fat *req;
1230 struct be_sge *sge;
1231 u32 offset = 0, total_size, buf_size, log_offset = sizeof(u32);
1232 int status;
1233
1234 if (buf_len == 0)
1235 return;
1236
1237 total_size = buf_len;
1238
1239 spin_lock_bh(&adapter->mcc_lock);
1240
1241 wrb = wrb_from_mccq(adapter);
1242 if (!wrb) {
1243 status = -EBUSY;
1244 goto err;
1245 }
1246 while (total_size) {
1247 buf_size = min(total_size, (u32)60*1024);
1248 total_size -= buf_size;
1249
1250 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + buf_size;
1251 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
1252 get_fat_cmd.size,
1253 &get_fat_cmd.dma);
1254 if (!get_fat_cmd.va) {
1255 status = -ENOMEM;
1256 dev_err(&adapter->pdev->dev,
1257 "Memory allocation failure while retrieving FAT data\n");
1258 goto err;
1259 }
1260 req = get_fat_cmd.va;
1261 sge = nonembedded_sgl(wrb);
1262
1263 be_wrb_hdr_prepare(wrb, get_fat_cmd.size, false, 1,
1264 OPCODE_COMMON_MANAGE_FAT);
1265
1266 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1267 OPCODE_COMMON_MANAGE_FAT, get_fat_cmd.size);
1268
1269 sge->pa_hi = cpu_to_le32(upper_32_bits(get_fat_cmd.size));
1270 sge->pa_lo = cpu_to_le32(get_fat_cmd.dma & 0xFFFFFFFF);
1271 sge->len = cpu_to_le32(get_fat_cmd.size);
1272
1273 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1274 req->read_log_offset = cpu_to_le32(log_offset);
1275 req->read_log_length = cpu_to_le32(buf_size);
1276 req->data_buffer_size = cpu_to_le32(buf_size);
1277
1278 status = be_mcc_notify_wait(adapter);
1279 if (!status) {
1280 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
1281 memcpy(buf + offset,
1282 resp->data_buffer,
1283 resp->read_log_length);
1284 }
1285 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
1286 get_fat_cmd.va,
1287 get_fat_cmd.dma);
1288 if (status)
1289 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
1290
1291 offset += buf_size;
1292 log_offset += buf_size;
1293 }
1294err:
1295 spin_unlock_bh(&adapter->mcc_lock);
1296}
1297
Sathya Perlab31c50a2009-09-17 10:30:13 -07001298/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001299int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001301 struct be_mcc_wrb *wrb;
1302 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001303 int status;
1304
Ivan Vecera29849612010-12-14 05:43:19 +00001305 if (mutex_lock_interruptible(&adapter->mbox_lock))
1306 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001307
1308 wrb = wrb_from_mbox(adapter);
1309 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001310
Ajit Khaparded744b442009-12-03 06:12:06 +00001311 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1312 OPCODE_COMMON_GET_FW_VERSION);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001313
1314 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1315 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
1316
Sathya Perlab31c50a2009-09-17 10:30:13 -07001317 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001318 if (!status) {
1319 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1320 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
1321 }
1322
Ivan Vecera29849612010-12-14 05:43:19 +00001323 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001324 return status;
1325}
1326
Sathya Perlab31c50a2009-09-17 10:30:13 -07001327/* set the EQ delay interval of an EQ to specified value
1328 * Uses async mcc
1329 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001330int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001331{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001332 struct be_mcc_wrb *wrb;
1333 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001334 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001335
Sathya Perlab31c50a2009-09-17 10:30:13 -07001336 spin_lock_bh(&adapter->mcc_lock);
1337
1338 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001339 if (!wrb) {
1340 status = -EBUSY;
1341 goto err;
1342 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001343 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001344
Ajit Khaparded744b442009-12-03 06:12:06 +00001345 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1346 OPCODE_COMMON_MODIFY_EQ_DELAY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001347
1348 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1349 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
1350
1351 req->num_eq = cpu_to_le32(1);
1352 req->delay[0].eq_id = cpu_to_le32(eq_id);
1353 req->delay[0].phase = 0;
1354 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1355
Sathya Perlab31c50a2009-09-17 10:30:13 -07001356 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001357
Sathya Perla713d03942009-11-22 22:02:45 +00001358err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001359 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001360 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001361}
1362
Sathya Perlab31c50a2009-09-17 10:30:13 -07001363/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001364int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001365 u32 num, bool untagged, bool promiscuous)
1366{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001367 struct be_mcc_wrb *wrb;
1368 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369 int status;
1370
Sathya Perlab31c50a2009-09-17 10:30:13 -07001371 spin_lock_bh(&adapter->mcc_lock);
1372
1373 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001374 if (!wrb) {
1375 status = -EBUSY;
1376 goto err;
1377 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001378 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001379
Ajit Khaparded744b442009-12-03 06:12:06 +00001380 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1381 OPCODE_COMMON_NTWK_VLAN_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001382
1383 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1384 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
1385
1386 req->interface_id = if_id;
1387 req->promiscuous = promiscuous;
1388 req->untagged = untagged;
1389 req->num_vlan = num;
1390 if (!promiscuous) {
1391 memcpy(req->normal_vlan, vtag_array,
1392 req->num_vlan * sizeof(vtag_array[0]));
1393 }
1394
Sathya Perlab31c50a2009-09-17 10:30:13 -07001395 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001396
Sathya Perla713d03942009-11-22 22:02:45 +00001397err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001398 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001399 return status;
1400}
1401
Sathya Perlab31c50a2009-09-17 10:30:13 -07001402/* Uses MCC for this command as it may be called in BH context
1403 * Uses synchronous mcc
1404 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001405int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001406{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001407 struct be_mcc_wrb *wrb;
1408 struct be_cmd_req_promiscuous_config *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001409 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001410
Sathya Perla8788fdc2009-07-27 22:52:03 +00001411 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001412
Sathya Perlab31c50a2009-09-17 10:30:13 -07001413 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001414 if (!wrb) {
1415 status = -EBUSY;
1416 goto err;
1417 }
Sathya Perla6ac7b682009-06-18 00:05:54 +00001418 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001419
Ajit Khaparded744b442009-12-03 06:12:06 +00001420 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_PROMISCUOUS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001421
1422 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1423 OPCODE_ETH_PROMISCUOUS, sizeof(*req));
1424
Sathya Perla69d7ce72010-04-11 22:35:27 +00001425 /* In FW versions X.102.149/X.101.487 and later,
1426 * the port setting associated only with the
1427 * issuing pci function will take effect
1428 */
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001429 if (port_num)
1430 req->port1_promiscuous = en;
1431 else
1432 req->port0_promiscuous = en;
1433
Sathya Perlab31c50a2009-09-17 10:30:13 -07001434 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001435
Sathya Perla713d03942009-11-22 22:02:45 +00001436err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001437 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001438 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001439}
1440
Sathya Perla6ac7b682009-06-18 00:05:54 +00001441/*
Sathya Perlab31c50a2009-09-17 10:30:13 -07001442 * Uses MCC for this command as it may be called in BH context
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001443 * (mc == NULL) => multicast promiscuous
Sathya Perla6ac7b682009-06-18 00:05:54 +00001444 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001445int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001446 struct net_device *netdev, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001447{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001448 struct be_mcc_wrb *wrb;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001449 struct be_cmd_req_mcast_mac_config *req = mem->va;
1450 struct be_sge *sge;
1451 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001452
Sathya Perla8788fdc2009-07-27 22:52:03 +00001453 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001454
Sathya Perlab31c50a2009-09-17 10:30:13 -07001455 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001456 if (!wrb) {
1457 status = -EBUSY;
1458 goto err;
1459 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00001460 sge = nonembedded_sgl(wrb);
1461 memset(req, 0, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001462
Ajit Khaparded744b442009-12-03 06:12:06 +00001463 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1464 OPCODE_COMMON_NTWK_MULTICAST_SET);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001465 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
1466 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
1467 sge->len = cpu_to_le32(mem->size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001468
1469 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1470 OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
1471
1472 req->interface_id = if_id;
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001473 if (netdev) {
Sathya Perla24307ee2009-06-18 00:09:25 +00001474 int i;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001475 struct netdev_hw_addr *ha;
Sathya Perla24307ee2009-06-18 00:09:25 +00001476
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001477 req->num_mac = cpu_to_le16(netdev_mc_count(netdev));
Sathya Perla24307ee2009-06-18 00:09:25 +00001478
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001479 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001480 netdev_for_each_mc_addr(ha, netdev)
Joe Jin408cc292010-12-06 03:00:59 +00001481 memcpy(req->mac[i++].byte, ha->addr, ETH_ALEN);
Sathya Perla24307ee2009-06-18 00:09:25 +00001482 } else {
1483 req->promiscuous = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001484 }
1485
Sathya Perlae7b909a2009-11-22 22:01:10 +00001486 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001487
Sathya Perla713d03942009-11-22 22:02:45 +00001488err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001489 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001490 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001491}
1492
Sathya Perlab31c50a2009-09-17 10:30:13 -07001493/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001494int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001495{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001496 struct be_mcc_wrb *wrb;
1497 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001498 int status;
1499
Sathya Perlab31c50a2009-09-17 10:30:13 -07001500 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001501
Sathya Perlab31c50a2009-09-17 10:30:13 -07001502 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001503 if (!wrb) {
1504 status = -EBUSY;
1505 goto err;
1506 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001507 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001508
Ajit Khaparded744b442009-12-03 06:12:06 +00001509 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1510 OPCODE_COMMON_SET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001511
1512 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1513 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1514
1515 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1516 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1517
Sathya Perlab31c50a2009-09-17 10:30:13 -07001518 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001519
Sathya Perla713d03942009-11-22 22:02:45 +00001520err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001521 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001522 return status;
1523}
1524
Sathya Perlab31c50a2009-09-17 10:30:13 -07001525/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001526int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001527{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001528 struct be_mcc_wrb *wrb;
1529 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001530 int status;
1531
Sathya Perlab31c50a2009-09-17 10:30:13 -07001532 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001533
Sathya Perlab31c50a2009-09-17 10:30:13 -07001534 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001535 if (!wrb) {
1536 status = -EBUSY;
1537 goto err;
1538 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001539 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001540
Ajit Khaparded744b442009-12-03 06:12:06 +00001541 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1542 OPCODE_COMMON_GET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001543
1544 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1545 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1546
Sathya Perlab31c50a2009-09-17 10:30:13 -07001547 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001548 if (!status) {
1549 struct be_cmd_resp_get_flow_control *resp =
1550 embedded_payload(wrb);
1551 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1552 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1553 }
1554
Sathya Perla713d03942009-11-22 22:02:45 +00001555err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001556 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001557 return status;
1558}
1559
Sathya Perlab31c50a2009-09-17 10:30:13 -07001560/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001561int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1562 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001563{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001564 struct be_mcc_wrb *wrb;
1565 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001566 int status;
1567
Ivan Vecera29849612010-12-14 05:43:19 +00001568 if (mutex_lock_interruptible(&adapter->mbox_lock))
1569 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001570
Sathya Perlab31c50a2009-09-17 10:30:13 -07001571 wrb = wrb_from_mbox(adapter);
1572 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001573
Ajit Khaparded744b442009-12-03 06:12:06 +00001574 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1575 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001576
1577 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1578 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1579
Sathya Perlab31c50a2009-09-17 10:30:13 -07001580 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001581 if (!status) {
1582 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1583 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001584 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001585 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001586 }
1587
Ivan Vecera29849612010-12-14 05:43:19 +00001588 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001589 return status;
1590}
sarveshwarb14074ea2009-08-05 13:05:24 -07001591
Sathya Perlab31c50a2009-09-17 10:30:13 -07001592/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001593int be_cmd_reset_function(struct be_adapter *adapter)
1594{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001595 struct be_mcc_wrb *wrb;
1596 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001597 int status;
1598
Ivan Vecera29849612010-12-14 05:43:19 +00001599 if (mutex_lock_interruptible(&adapter->mbox_lock))
1600 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001601
Sathya Perlab31c50a2009-09-17 10:30:13 -07001602 wrb = wrb_from_mbox(adapter);
1603 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001604
Ajit Khaparded744b442009-12-03 06:12:06 +00001605 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1606 OPCODE_COMMON_FUNCTION_RESET);
sarveshwarb14074ea2009-08-05 13:05:24 -07001607
1608 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1609 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1610
Sathya Perlab31c50a2009-09-17 10:30:13 -07001611 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001612
Ivan Vecera29849612010-12-14 05:43:19 +00001613 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001614 return status;
1615}
Ajit Khaparde84517482009-09-04 03:12:16 +00001616
Sathya Perla3abcded2010-10-03 22:12:27 -07001617int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1618{
1619 struct be_mcc_wrb *wrb;
1620 struct be_cmd_req_rss_config *req;
1621 u32 myhash[10];
1622 int status;
1623
Ivan Vecera29849612010-12-14 05:43:19 +00001624 if (mutex_lock_interruptible(&adapter->mbox_lock))
1625 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001626
1627 wrb = wrb_from_mbox(adapter);
1628 req = embedded_payload(wrb);
1629
1630 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1631 OPCODE_ETH_RSS_CONFIG);
1632
1633 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1634 OPCODE_ETH_RSS_CONFIG, sizeof(*req));
1635
1636 req->if_id = cpu_to_le32(adapter->if_handle);
1637 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4);
1638 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1639 memcpy(req->cpu_table, rsstable, table_size);
1640 memcpy(req->hash, myhash, sizeof(myhash));
1641 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1642
1643 status = be_mbox_notify_wait(adapter);
1644
Ivan Vecera29849612010-12-14 05:43:19 +00001645 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001646 return status;
1647}
1648
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001649/* Uses sync mcc */
1650int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1651 u8 bcn, u8 sts, u8 state)
1652{
1653 struct be_mcc_wrb *wrb;
1654 struct be_cmd_req_enable_disable_beacon *req;
1655 int status;
1656
1657 spin_lock_bh(&adapter->mcc_lock);
1658
1659 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001660 if (!wrb) {
1661 status = -EBUSY;
1662 goto err;
1663 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001664 req = embedded_payload(wrb);
1665
Ajit Khaparded744b442009-12-03 06:12:06 +00001666 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1667 OPCODE_COMMON_ENABLE_DISABLE_BEACON);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001668
1669 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1670 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1671
1672 req->port_num = port_num;
1673 req->beacon_state = state;
1674 req->beacon_duration = bcn;
1675 req->status_duration = sts;
1676
1677 status = be_mcc_notify_wait(adapter);
1678
Sathya Perla713d03942009-11-22 22:02:45 +00001679err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001680 spin_unlock_bh(&adapter->mcc_lock);
1681 return status;
1682}
1683
1684/* Uses sync mcc */
1685int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1686{
1687 struct be_mcc_wrb *wrb;
1688 struct be_cmd_req_get_beacon_state *req;
1689 int status;
1690
1691 spin_lock_bh(&adapter->mcc_lock);
1692
1693 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001694 if (!wrb) {
1695 status = -EBUSY;
1696 goto err;
1697 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001698 req = embedded_payload(wrb);
1699
Ajit Khaparded744b442009-12-03 06:12:06 +00001700 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1701 OPCODE_COMMON_GET_BEACON_STATE);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001702
1703 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1704 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1705
1706 req->port_num = port_num;
1707
1708 status = be_mcc_notify_wait(adapter);
1709 if (!status) {
1710 struct be_cmd_resp_get_beacon_state *resp =
1711 embedded_payload(wrb);
1712 *state = resp->beacon_state;
1713 }
1714
Sathya Perla713d03942009-11-22 22:02:45 +00001715err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001716 spin_unlock_bh(&adapter->mcc_lock);
1717 return status;
1718}
1719
Ajit Khaparde84517482009-09-04 03:12:16 +00001720int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1721 u32 flash_type, u32 flash_opcode, u32 buf_size)
1722{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001723 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001724 struct be_cmd_write_flashrom *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001725 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001726 int status;
1727
Sathya Perlab31c50a2009-09-17 10:30:13 -07001728 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001729 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001730
1731 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001732 if (!wrb) {
1733 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001734 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00001735 }
1736 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001737 sge = nonembedded_sgl(wrb);
1738
Ajit Khaparded744b442009-12-03 06:12:06 +00001739 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1740 OPCODE_COMMON_WRITE_FLASHROM);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001741 wrb->tag1 = CMD_SUBSYSTEM_COMMON;
Ajit Khaparde84517482009-09-04 03:12:16 +00001742
1743 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1744 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1745 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1746 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1747 sge->len = cpu_to_le32(cmd->size);
1748
1749 req->params.op_type = cpu_to_le32(flash_type);
1750 req->params.op_code = cpu_to_le32(flash_opcode);
1751 req->params.data_buf_size = cpu_to_le32(buf_size);
1752
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001753 be_mcc_notify(adapter);
1754 spin_unlock_bh(&adapter->mcc_lock);
1755
1756 if (!wait_for_completion_timeout(&adapter->flash_compl,
1757 msecs_to_jiffies(12000)))
1758 status = -1;
1759 else
1760 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00001761
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001762 return status;
1763
1764err_unlock:
1765 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001766 return status;
1767}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001768
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001769int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1770 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001771{
1772 struct be_mcc_wrb *wrb;
1773 struct be_cmd_write_flashrom *req;
1774 int status;
1775
1776 spin_lock_bh(&adapter->mcc_lock);
1777
1778 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001779 if (!wrb) {
1780 status = -EBUSY;
1781 goto err;
1782 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001783 req = embedded_payload(wrb);
1784
Ajit Khaparded744b442009-12-03 06:12:06 +00001785 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
1786 OPCODE_COMMON_READ_FLASHROM);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001787
1788 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1789 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1790
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001791 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001792 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00001793 req->params.offset = cpu_to_le32(offset);
1794 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001795
1796 status = be_mcc_notify_wait(adapter);
1797 if (!status)
1798 memcpy(flashed_crc, req->params.data_buf, 4);
1799
Sathya Perla713d03942009-11-22 22:02:45 +00001800err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001801 spin_unlock_bh(&adapter->mcc_lock);
1802 return status;
1803}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001804
Dan Carpenterc196b022010-05-26 04:47:39 +00001805int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001806 struct be_dma_mem *nonemb_cmd)
1807{
1808 struct be_mcc_wrb *wrb;
1809 struct be_cmd_req_acpi_wol_magic_config *req;
1810 struct be_sge *sge;
1811 int status;
1812
1813 spin_lock_bh(&adapter->mcc_lock);
1814
1815 wrb = wrb_from_mccq(adapter);
1816 if (!wrb) {
1817 status = -EBUSY;
1818 goto err;
1819 }
1820 req = nonemb_cmd->va;
1821 sge = nonembedded_sgl(wrb);
1822
1823 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1824 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
1825
1826 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1827 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
1828 memcpy(req->magic_mac, mac, ETH_ALEN);
1829
1830 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1831 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1832 sge->len = cpu_to_le32(nonemb_cmd->size);
1833
1834 status = be_mcc_notify_wait(adapter);
1835
1836err:
1837 spin_unlock_bh(&adapter->mcc_lock);
1838 return status;
1839}
Suresh Rff33a6e2009-12-03 16:15:52 -08001840
Sarveshwar Bandifced9992009-12-23 04:41:44 +00001841int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
1842 u8 loopback_type, u8 enable)
1843{
1844 struct be_mcc_wrb *wrb;
1845 struct be_cmd_req_set_lmode *req;
1846 int status;
1847
1848 spin_lock_bh(&adapter->mcc_lock);
1849
1850 wrb = wrb_from_mccq(adapter);
1851 if (!wrb) {
1852 status = -EBUSY;
1853 goto err;
1854 }
1855
1856 req = embedded_payload(wrb);
1857
1858 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1859 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
1860
1861 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1862 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
1863 sizeof(*req));
1864
1865 req->src_port = port_num;
1866 req->dest_port = port_num;
1867 req->loopback_type = loopback_type;
1868 req->loopback_state = enable;
1869
1870 status = be_mcc_notify_wait(adapter);
1871err:
1872 spin_unlock_bh(&adapter->mcc_lock);
1873 return status;
1874}
1875
Suresh Rff33a6e2009-12-03 16:15:52 -08001876int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
1877 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
1878{
1879 struct be_mcc_wrb *wrb;
1880 struct be_cmd_req_loopback_test *req;
1881 int status;
1882
1883 spin_lock_bh(&adapter->mcc_lock);
1884
1885 wrb = wrb_from_mccq(adapter);
1886 if (!wrb) {
1887 status = -EBUSY;
1888 goto err;
1889 }
1890
1891 req = embedded_payload(wrb);
1892
1893 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1894 OPCODE_LOWLEVEL_LOOPBACK_TEST);
1895
1896 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1897 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
Sathya Perla3ffd0512010-06-01 00:19:33 -07001898 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08001899
1900 req->pattern = cpu_to_le64(pattern);
1901 req->src_port = cpu_to_le32(port_num);
1902 req->dest_port = cpu_to_le32(port_num);
1903 req->pkt_size = cpu_to_le32(pkt_size);
1904 req->num_pkts = cpu_to_le32(num_pkts);
1905 req->loopback_type = cpu_to_le32(loopback_type);
1906
1907 status = be_mcc_notify_wait(adapter);
1908 if (!status) {
1909 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
1910 status = le32_to_cpu(resp->status);
1911 }
1912
1913err:
1914 spin_unlock_bh(&adapter->mcc_lock);
1915 return status;
1916}
1917
1918int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
1919 u32 byte_cnt, struct be_dma_mem *cmd)
1920{
1921 struct be_mcc_wrb *wrb;
1922 struct be_cmd_req_ddrdma_test *req;
1923 struct be_sge *sge;
1924 int status;
1925 int i, j = 0;
1926
1927 spin_lock_bh(&adapter->mcc_lock);
1928
1929 wrb = wrb_from_mccq(adapter);
1930 if (!wrb) {
1931 status = -EBUSY;
1932 goto err;
1933 }
1934 req = cmd->va;
1935 sge = nonembedded_sgl(wrb);
1936 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1937 OPCODE_LOWLEVEL_HOST_DDR_DMA);
1938 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1939 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
1940
1941 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1942 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1943 sge->len = cpu_to_le32(cmd->size);
1944
1945 req->pattern = cpu_to_le64(pattern);
1946 req->byte_count = cpu_to_le32(byte_cnt);
1947 for (i = 0; i < byte_cnt; i++) {
1948 req->snd_buff[i] = (u8)(pattern >> (j*8));
1949 j++;
1950 if (j > 7)
1951 j = 0;
1952 }
1953
1954 status = be_mcc_notify_wait(adapter);
1955
1956 if (!status) {
1957 struct be_cmd_resp_ddrdma_test *resp;
1958 resp = cmd->va;
1959 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
1960 resp->snd_err) {
1961 status = -1;
1962 }
1963 }
1964
1965err:
1966 spin_unlock_bh(&adapter->mcc_lock);
1967 return status;
1968}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001969
Dan Carpenterc196b022010-05-26 04:47:39 +00001970int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001971 struct be_dma_mem *nonemb_cmd)
1972{
1973 struct be_mcc_wrb *wrb;
1974 struct be_cmd_req_seeprom_read *req;
1975 struct be_sge *sge;
1976 int status;
1977
1978 spin_lock_bh(&adapter->mcc_lock);
1979
1980 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00001981 if (!wrb) {
1982 status = -EBUSY;
1983 goto err;
1984 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001985 req = nonemb_cmd->va;
1986 sge = nonembedded_sgl(wrb);
1987
1988 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1989 OPCODE_COMMON_SEEPROM_READ);
1990
1991 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1992 OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
1993
1994 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1995 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1996 sge->len = cpu_to_le32(nonemb_cmd->size);
1997
1998 status = be_mcc_notify_wait(adapter);
1999
Ajit Khapardee45ff012011-02-04 17:18:28 +00002000err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002001 spin_unlock_bh(&adapter->mcc_lock);
2002 return status;
2003}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002004
2005int be_cmd_get_phy_info(struct be_adapter *adapter, struct be_dma_mem *cmd)
2006{
2007 struct be_mcc_wrb *wrb;
2008 struct be_cmd_req_get_phy_info *req;
2009 struct be_sge *sge;
2010 int status;
2011
2012 spin_lock_bh(&adapter->mcc_lock);
2013
2014 wrb = wrb_from_mccq(adapter);
2015 if (!wrb) {
2016 status = -EBUSY;
2017 goto err;
2018 }
2019
2020 req = cmd->va;
2021 sge = nonembedded_sgl(wrb);
2022
2023 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
2024 OPCODE_COMMON_GET_PHY_DETAILS);
2025
2026 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2027 OPCODE_COMMON_GET_PHY_DETAILS,
2028 sizeof(*req));
2029
2030 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
2031 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
2032 sge->len = cpu_to_le32(cmd->size);
2033
2034 status = be_mcc_notify_wait(adapter);
2035err:
2036 spin_unlock_bh(&adapter->mcc_lock);
2037 return status;
2038}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002039
2040int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
2041{
2042 struct be_mcc_wrb *wrb;
2043 struct be_cmd_req_set_qos *req;
2044 int status;
2045
2046 spin_lock_bh(&adapter->mcc_lock);
2047
2048 wrb = wrb_from_mccq(adapter);
2049 if (!wrb) {
2050 status = -EBUSY;
2051 goto err;
2052 }
2053
2054 req = embedded_payload(wrb);
2055
2056 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2057 OPCODE_COMMON_SET_QOS);
2058
2059 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2060 OPCODE_COMMON_SET_QOS, sizeof(*req));
2061
2062 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002063 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2064 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002065
2066 status = be_mcc_notify_wait(adapter);
2067
2068err:
2069 spin_unlock_bh(&adapter->mcc_lock);
2070 return status;
2071}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002072
2073int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2074{
2075 struct be_mcc_wrb *wrb;
2076 struct be_cmd_req_cntl_attribs *req;
2077 struct be_cmd_resp_cntl_attribs *resp;
2078 struct be_sge *sge;
2079 int status;
2080 int payload_len = max(sizeof(*req), sizeof(*resp));
2081 struct mgmt_controller_attrib *attribs;
2082 struct be_dma_mem attribs_cmd;
2083
2084 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2085 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2086 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
2087 &attribs_cmd.dma);
2088 if (!attribs_cmd.va) {
2089 dev_err(&adapter->pdev->dev,
2090 "Memory allocation failure\n");
2091 return -ENOMEM;
2092 }
2093
2094 if (mutex_lock_interruptible(&adapter->mbox_lock))
2095 return -1;
2096
2097 wrb = wrb_from_mbox(adapter);
2098 if (!wrb) {
2099 status = -EBUSY;
2100 goto err;
2101 }
2102 req = attribs_cmd.va;
2103 sge = nonembedded_sgl(wrb);
2104
2105 be_wrb_hdr_prepare(wrb, payload_len, false, 1,
2106 OPCODE_COMMON_GET_CNTL_ATTRIBUTES);
2107 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2108 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len);
2109 sge->pa_hi = cpu_to_le32(upper_32_bits(attribs_cmd.dma));
2110 sge->pa_lo = cpu_to_le32(attribs_cmd.dma & 0xFFFFFFFF);
2111 sge->len = cpu_to_le32(attribs_cmd.size);
2112
2113 status = be_mbox_notify_wait(adapter);
2114 if (!status) {
2115 attribs = (struct mgmt_controller_attrib *)( attribs_cmd.va +
2116 sizeof(struct be_cmd_resp_hdr));
2117 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2118 }
2119
2120err:
2121 mutex_unlock(&adapter->mbox_lock);
2122 pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
2123 attribs_cmd.dma);
2124 return status;
2125}
Sathya Perla2e588f82011-03-11 02:49:26 +00002126
2127/* Uses mbox */
2128int be_cmd_check_native_mode(struct be_adapter *adapter)
2129{
2130 struct be_mcc_wrb *wrb;
2131 struct be_cmd_req_set_func_cap *req;
2132 int status;
2133
2134 if (mutex_lock_interruptible(&adapter->mbox_lock))
2135 return -1;
2136
2137 wrb = wrb_from_mbox(adapter);
2138 if (!wrb) {
2139 status = -EBUSY;
2140 goto err;
2141 }
2142
2143 req = embedded_payload(wrb);
2144
2145 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2146 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP);
2147
2148 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2149 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req));
2150
2151 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2152 CAPABILITY_BE3_NATIVE_ERX_API);
2153 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2154
2155 status = be_mbox_notify_wait(adapter);
2156 if (!status) {
2157 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2158 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2159 CAPABILITY_BE3_NATIVE_ERX_API;
2160 }
2161err:
2162 mutex_unlock(&adapter->mbox_lock);
2163 return status;
2164}