blob: 9dc9394fd4cae51f5ec0b566daa6102d7b80e571 [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) {
81 if (compl->tag0 == OPCODE_ETH_GET_STATISTICS) {
82 struct be_cmd_resp_get_stats *resp =
Sathya Perla3abcded2010-10-03 22:12:27 -070083 adapter->stats_cmd.va;
Sathya Perlab31c50a2009-09-17 10:30:13 -070084 be_dws_le_to_cpu(&resp->hw_stats,
85 sizeof(resp->hw_stats));
86 netdev_stats_update(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +000087 adapter->stats_cmd_sent = false;
Sathya Perlab31c50a2009-09-17 10:30:13 -070088 }
Ajit Khaparde89438072010-07-23 12:42:40 -070089 } else if ((compl_status != MCC_STATUS_NOT_SUPPORTED) &&
90 (compl->tag0 != OPCODE_COMMON_NTWK_MAC_QUERY)) {
Sathya Perla5fb379e2009-06-18 00:02:59 +000091 extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) &
92 CQE_STATUS_EXTD_MASK;
Sathya Perla5f0b8492009-07-27 22:52:56 +000093 dev_warn(&adapter->pdev->dev,
Ajit Khaparded744b442009-12-03 06:12:06 +000094 "Error in cmd completion - opcode %d, compl %d, extd %d\n",
95 compl->tag0, compl_status, extd_status);
Sathya Perla5fb379e2009-06-18 00:02:59 +000096 }
Sathya Perlab31c50a2009-09-17 10:30:13 -070097 return compl_status;
Sathya Perla5fb379e2009-06-18 00:02:59 +000098}
99
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000100/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000101static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000102 struct be_async_event_link_state *evt)
103{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000104 be_link_status_update(adapter,
105 evt->port_link_status == ASYNC_EVENT_LINK_UP);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000106}
107
Somnath Koturcc4ce022010-10-21 07:11:14 -0700108/* Grp5 CoS Priority evt */
109static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
110 struct be_async_event_grp5_cos_priority *evt)
111{
112 if (evt->valid) {
113 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000114 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700115 adapter->recommended_prio =
116 evt->reco_default_priority << VLAN_PRIO_SHIFT;
117 }
118}
119
120/* Grp5 QOS Speed evt */
121static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
122 struct be_async_event_grp5_qos_link_speed *evt)
123{
124 if (evt->physical_port == adapter->port_num) {
125 /* qos_link_speed is in units of 10 Mbps */
126 adapter->link_speed = evt->qos_link_speed * 10;
127 }
128}
129
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000130/*Grp5 PVID evt*/
131static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
132 struct be_async_event_grp5_pvid_state *evt)
133{
134 if (evt->enabled)
Somnath Kotur6709d952011-05-04 22:40:46 +0000135 adapter->pvid = le16_to_cpu(evt->tag);
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000136 else
137 adapter->pvid = 0;
138}
139
Somnath Koturcc4ce022010-10-21 07:11:14 -0700140static void be_async_grp5_evt_process(struct be_adapter *adapter,
141 u32 trailer, struct be_mcc_compl *evt)
142{
143 u8 event_type = 0;
144
145 event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) &
146 ASYNC_TRAILER_EVENT_TYPE_MASK;
147
148 switch (event_type) {
149 case ASYNC_EVENT_COS_PRIORITY:
150 be_async_grp5_cos_priority_process(adapter,
151 (struct be_async_event_grp5_cos_priority *)evt);
152 break;
153 case ASYNC_EVENT_QOS_SPEED:
154 be_async_grp5_qos_speed_process(adapter,
155 (struct be_async_event_grp5_qos_link_speed *)evt);
156 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000157 case ASYNC_EVENT_PVID_STATE:
158 be_async_grp5_pvid_state_process(adapter,
159 (struct be_async_event_grp5_pvid_state *)evt);
160 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700161 default:
162 dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n");
163 break;
164 }
165}
166
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000167static inline bool is_link_state_evt(u32 trailer)
168{
Eric Dumazet807540b2010-09-23 05:40:09 +0000169 return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000170 ASYNC_TRAILER_EVENT_CODE_MASK) ==
Eric Dumazet807540b2010-09-23 05:40:09 +0000171 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000172}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000173
Somnath Koturcc4ce022010-10-21 07:11:14 -0700174static inline bool is_grp5_evt(u32 trailer)
175{
176 return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) &
177 ASYNC_TRAILER_EVENT_CODE_MASK) ==
178 ASYNC_EVENT_CODE_GRP_5);
179}
180
Sathya Perlaefd2e402009-07-27 22:53:10 +0000181static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000182{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000183 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000184 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000185
186 if (be_mcc_compl_is_new(compl)) {
187 queue_tail_inc(mcc_cq);
188 return compl;
189 }
190 return NULL;
191}
192
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000193void be_async_mcc_enable(struct be_adapter *adapter)
194{
195 spin_lock_bh(&adapter->mcc_cq_lock);
196
197 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
198 adapter->mcc_obj.rearm_cq = true;
199
200 spin_unlock_bh(&adapter->mcc_cq_lock);
201}
202
203void be_async_mcc_disable(struct be_adapter *adapter)
204{
205 adapter->mcc_obj.rearm_cq = false;
206}
207
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800208int be_process_mcc(struct be_adapter *adapter, int *status)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000209{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000210 struct be_mcc_compl *compl;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800211 int num = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000212 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000213
Sathya Perla8788fdc2009-07-27 22:52:03 +0000214 spin_lock_bh(&adapter->mcc_cq_lock);
215 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000216 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
217 /* Interpret flags as an async trailer */
Ajit Khaparde323f30b2010-09-03 06:24:13 +0000218 if (is_link_state_evt(compl->flags))
219 be_async_link_state_process(adapter,
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000220 (struct be_async_event_link_state *) compl);
Somnath Koturcc4ce022010-10-21 07:11:14 -0700221 else if (is_grp5_evt(compl->flags))
222 be_async_grp5_evt_process(adapter,
223 compl->flags, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700224 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800225 *status = be_mcc_compl_process(adapter, compl);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000226 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000227 }
228 be_mcc_compl_use(compl);
229 num++;
230 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700231
Sathya Perla8788fdc2009-07-27 22:52:03 +0000232 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800233 return num;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000234}
235
Sathya Perla6ac7b682009-06-18 00:05:54 +0000236/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700237static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000238{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700239#define mcc_timeout 120000 /* 12s timeout */
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800240 int i, num, status = 0;
241 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700242
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000243 if (adapter->eeh_err)
244 return -EIO;
245
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800246 for (i = 0; i < mcc_timeout; i++) {
247 num = be_process_mcc(adapter, &status);
248 if (num)
249 be_cq_notify(adapter, mcc_obj->cq.id,
250 mcc_obj->rearm_cq, num);
251
252 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000253 break;
254 udelay(100);
255 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700256 if (i == mcc_timeout) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000257 dev_err(&adapter->pdev->dev, "mccq poll timed out\n");
Sathya Perlab31c50a2009-09-17 10:30:13 -0700258 return -1;
259 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800260 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000261}
262
263/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700264static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000265{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000266 be_mcc_notify(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700267 return be_mcc_wait_compl(adapter);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000268}
269
Sathya Perla5f0b8492009-07-27 22:52:56 +0000270static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700271{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000272 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700273 u32 ready;
274
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000275 if (adapter->eeh_err) {
276 dev_err(&adapter->pdev->dev,
277 "Error detected in card.Cannot issue commands\n");
278 return -EIO;
279 }
280
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700281 do {
Sathya Perlacf588472010-02-14 21:22:01 +0000282 ready = ioread32(db);
283 if (ready == 0xffffffff) {
284 dev_err(&adapter->pdev->dev,
285 "pci slot disconnected\n");
286 return -1;
287 }
288
289 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700290 if (ready)
291 break;
292
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000293 if (msecs > 4000) {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000294 dev_err(&adapter->pdev->dev, "mbox poll timed out\n");
Ajit Khaparded053de92010-09-03 06:23:30 +0000295 be_detect_dump_ue(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700296 return -1;
297 }
298
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000299 set_current_state(TASK_INTERRUPTIBLE);
300 schedule_timeout(msecs_to_jiffies(1));
301 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700302 } while (true);
303
304 return 0;
305}
306
307/*
308 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000309 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700310 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700311static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700312{
313 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700314 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000315 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
316 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700317 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000318 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700319
Sathya Perlacf588472010-02-14 21:22:01 +0000320 /* wait for ready to be set */
321 status = be_mbox_db_ready_wait(adapter, db);
322 if (status != 0)
323 return status;
324
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700325 val |= MPU_MAILBOX_DB_HI_MASK;
326 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
327 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
328 iowrite32(val, db);
329
330 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000331 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700332 if (status != 0)
333 return status;
334
335 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700336 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
337 val |= (u32)(mbox_mem->dma >> 4) << 2;
338 iowrite32(val, db);
339
Sathya Perla5f0b8492009-07-27 22:52:56 +0000340 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700341 if (status != 0)
342 return status;
343
Sathya Perla5fb379e2009-06-18 00:02:59 +0000344 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000345 if (be_mcc_compl_is_new(compl)) {
346 status = be_mcc_compl_process(adapter, &mbox->compl);
347 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000348 if (status)
349 return status;
350 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000351 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700352 return -1;
353 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000354 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700355}
356
Sathya Perla8788fdc2009-07-27 22:52:03 +0000357static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700358{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000359 u32 sem;
360
361 if (lancer_chip(adapter))
362 sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET);
363 else
364 sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700365
366 *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK;
367 if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK)
368 return -1;
369 else
370 return 0;
371}
372
Sathya Perla8788fdc2009-07-27 22:52:03 +0000373int be_cmd_POST(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700374{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000375 u16 stage;
376 int status, timeout = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700377
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000378 do {
379 status = be_POST_stage_get(adapter, &stage);
380 if (status) {
381 dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n",
382 stage);
383 return -1;
384 } else if (stage != POST_STAGE_ARMFW_RDY) {
385 set_current_state(TASK_INTERRUPTIBLE);
386 schedule_timeout(2 * HZ);
387 timeout += 2;
388 } else {
389 return 0;
390 }
Sathya Perlad938a702010-05-26 00:33:43 -0700391 } while (timeout < 40);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700392
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000393 dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage);
394 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700395}
396
397static inline void *embedded_payload(struct be_mcc_wrb *wrb)
398{
399 return wrb->payload.embedded_payload;
400}
401
402static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
403{
404 return &wrb->payload.sgl[0];
405}
406
407/* Don't touch the hdr after it's prepared */
408static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len,
Ajit Khaparded744b442009-12-03 06:12:06 +0000409 bool embedded, u8 sge_cnt, u32 opcode)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700410{
411 if (embedded)
412 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
413 else
414 wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) <<
415 MCC_WRB_SGE_CNT_SHIFT;
416 wrb->payload_length = payload_len;
Ajit Khaparded744b442009-12-03 06:12:06 +0000417 wrb->tag0 = opcode;
Sathya Perlafa4281b2010-01-21 22:51:36 +0000418 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700419}
420
421/* Don't touch the hdr after it's prepared */
422static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
423 u8 subsystem, u8 opcode, int cmd_len)
424{
425 req_hdr->opcode = opcode;
426 req_hdr->subsystem = subsystem;
427 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000428 req_hdr->version = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700429}
430
431static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
432 struct be_dma_mem *mem)
433{
434 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
435 u64 dma = (u64)mem->dma;
436
437 for (i = 0; i < buf_pages; i++) {
438 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
439 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
440 dma += PAGE_SIZE_4K;
441 }
442}
443
444/* Converts interrupt delay in microseconds to multiplier value */
445static u32 eq_delay_to_mult(u32 usec_delay)
446{
447#define MAX_INTR_RATE 651042
448 const u32 round = 10;
449 u32 multiplier;
450
451 if (usec_delay == 0)
452 multiplier = 0;
453 else {
454 u32 interrupt_rate = 1000000 / usec_delay;
455 /* Max delay, corresponding to the lowest interrupt rate */
456 if (interrupt_rate == 0)
457 multiplier = 1023;
458 else {
459 multiplier = (MAX_INTR_RATE - interrupt_rate) * round;
460 multiplier /= interrupt_rate;
461 /* Round the multiplier to the closest value.*/
462 multiplier = (multiplier + round/2) / round;
463 multiplier = min(multiplier, (u32)1023);
464 }
465 }
466 return multiplier;
467}
468
Sathya Perlab31c50a2009-09-17 10:30:13 -0700469static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700470{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700471 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
472 struct be_mcc_wrb *wrb
473 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
474 memset(wrb, 0, sizeof(*wrb));
475 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700476}
477
Sathya Perlab31c50a2009-09-17 10:30:13 -0700478static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000479{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700480 struct be_queue_info *mccq = &adapter->mcc_obj.q;
481 struct be_mcc_wrb *wrb;
482
Sathya Perla713d03942009-11-22 22:02:45 +0000483 if (atomic_read(&mccq->used) >= mccq->len) {
484 dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n");
485 return NULL;
486 }
487
Sathya Perlab31c50a2009-09-17 10:30:13 -0700488 wrb = queue_head_node(mccq);
489 queue_head_inc(mccq);
490 atomic_inc(&mccq->used);
491 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000492 return wrb;
493}
494
Sathya Perla2243e2e2009-11-22 22:02:03 +0000495/* Tell fw we're about to start firing cmds by writing a
496 * special pattern across the wrb hdr; uses mbox
497 */
498int be_cmd_fw_init(struct be_adapter *adapter)
499{
500 u8 *wrb;
501 int status;
502
Ivan Vecera29849612010-12-14 05:43:19 +0000503 if (mutex_lock_interruptible(&adapter->mbox_lock))
504 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000505
506 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000507 *wrb++ = 0xFF;
508 *wrb++ = 0x12;
509 *wrb++ = 0x34;
510 *wrb++ = 0xFF;
511 *wrb++ = 0xFF;
512 *wrb++ = 0x56;
513 *wrb++ = 0x78;
514 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000515
516 status = be_mbox_notify_wait(adapter);
517
Ivan Vecera29849612010-12-14 05:43:19 +0000518 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000519 return status;
520}
521
522/* Tell fw we're done with firing cmds by writing a
523 * special pattern across the wrb hdr; uses mbox
524 */
525int be_cmd_fw_clean(struct be_adapter *adapter)
526{
527 u8 *wrb;
528 int status;
529
Sathya Perlacf588472010-02-14 21:22:01 +0000530 if (adapter->eeh_err)
531 return -EIO;
532
Ivan Vecera29849612010-12-14 05:43:19 +0000533 if (mutex_lock_interruptible(&adapter->mbox_lock))
534 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000535
536 wrb = (u8 *)wrb_from_mbox(adapter);
537 *wrb++ = 0xFF;
538 *wrb++ = 0xAA;
539 *wrb++ = 0xBB;
540 *wrb++ = 0xFF;
541 *wrb++ = 0xFF;
542 *wrb++ = 0xCC;
543 *wrb++ = 0xDD;
544 *wrb = 0xFF;
545
546 status = be_mbox_notify_wait(adapter);
547
Ivan Vecera29849612010-12-14 05:43:19 +0000548 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000549 return status;
550}
Sathya Perla8788fdc2009-07-27 22:52:03 +0000551int be_cmd_eq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700552 struct be_queue_info *eq, int eq_delay)
553{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700554 struct be_mcc_wrb *wrb;
555 struct be_cmd_req_eq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700556 struct be_dma_mem *q_mem = &eq->dma_mem;
557 int status;
558
Ivan Vecera29849612010-12-14 05:43:19 +0000559 if (mutex_lock_interruptible(&adapter->mbox_lock))
560 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700561
562 wrb = wrb_from_mbox(adapter);
563 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700564
Ajit Khaparded744b442009-12-03 06:12:06 +0000565 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700566
567 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
568 OPCODE_COMMON_EQ_CREATE, sizeof(*req));
569
570 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
571
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700572 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
573 /* 4byte eqe*/
574 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
575 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
576 __ilog2_u32(eq->len/256));
577 AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context,
578 eq_delay_to_mult(eq_delay));
579 be_dws_cpu_to_le(req->context, sizeof(req->context));
580
581 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
582
Sathya Perlab31c50a2009-09-17 10:30:13 -0700583 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700584 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700585 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700586 eq->id = le16_to_cpu(resp->eq_id);
587 eq->created = true;
588 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700589
Ivan Vecera29849612010-12-14 05:43:19 +0000590 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700591 return status;
592}
593
Sathya Perlab31c50a2009-09-17 10:30:13 -0700594/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000595int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700596 u8 type, bool permanent, u32 if_handle)
597{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700598 struct be_mcc_wrb *wrb;
599 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700600 int status;
601
Ivan Vecera29849612010-12-14 05:43:19 +0000602 if (mutex_lock_interruptible(&adapter->mbox_lock))
603 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700604
605 wrb = wrb_from_mbox(adapter);
606 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700607
Ajit Khaparded744b442009-12-03 06:12:06 +0000608 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
609 OPCODE_COMMON_NTWK_MAC_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700610
611 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
612 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req));
613
614 req->type = type;
615 if (permanent) {
616 req->permanent = 1;
617 } else {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700618 req->if_id = cpu_to_le16((u16) if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700619 req->permanent = 0;
620 }
621
Sathya Perlab31c50a2009-09-17 10:30:13 -0700622 status = be_mbox_notify_wait(adapter);
623 if (!status) {
624 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700625 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700626 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700627
Ivan Vecera29849612010-12-14 05:43:19 +0000628 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700629 return status;
630}
631
Sathya Perlab31c50a2009-09-17 10:30:13 -0700632/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000633int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Ajit Khapardef8617e02011-02-11 13:36:37 +0000634 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700635{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700636 struct be_mcc_wrb *wrb;
637 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700638 int status;
639
Sathya Perlab31c50a2009-09-17 10:30:13 -0700640 spin_lock_bh(&adapter->mcc_lock);
641
642 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000643 if (!wrb) {
644 status = -EBUSY;
645 goto err;
646 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700647 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700648
Ajit Khaparded744b442009-12-03 06:12:06 +0000649 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
650 OPCODE_COMMON_NTWK_PMAC_ADD);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700651
652 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
653 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req));
654
Ajit Khapardef8617e02011-02-11 13:36:37 +0000655 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700656 req->if_id = cpu_to_le32(if_id);
657 memcpy(req->mac_address, mac_addr, ETH_ALEN);
658
Sathya Perlab31c50a2009-09-17 10:30:13 -0700659 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700660 if (!status) {
661 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
662 *pmac_id = le32_to_cpu(resp->pmac_id);
663 }
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 synchronous MCCQ */
Ajit Khapardef8617e02011-02-11 13:36:37 +0000671int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700672{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700673 struct be_mcc_wrb *wrb;
674 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700675 int status;
676
Sathya Perlab31c50a2009-09-17 10:30:13 -0700677 spin_lock_bh(&adapter->mcc_lock);
678
679 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +0000680 if (!wrb) {
681 status = -EBUSY;
682 goto err;
683 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700684 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700685
Ajit Khaparded744b442009-12-03 06:12:06 +0000686 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
687 OPCODE_COMMON_NTWK_PMAC_DEL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700688
689 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
690 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req));
691
Ajit Khapardef8617e02011-02-11 13:36:37 +0000692 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700693 req->if_id = cpu_to_le32(if_id);
694 req->pmac_id = cpu_to_le32(pmac_id);
695
Sathya Perlab31c50a2009-09-17 10:30:13 -0700696 status = be_mcc_notify_wait(adapter);
697
Sathya Perla713d03942009-11-22 22:02:45 +0000698err:
Sathya Perlab31c50a2009-09-17 10:30:13 -0700699 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700700 return status;
701}
702
Sathya Perlab31c50a2009-09-17 10:30:13 -0700703/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000704int be_cmd_cq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700705 struct be_queue_info *cq, struct be_queue_info *eq,
706 bool sol_evts, bool no_delay, int coalesce_wm)
707{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700708 struct be_mcc_wrb *wrb;
709 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700710 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700711 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700712 int status;
713
Ivan Vecera29849612010-12-14 05:43:19 +0000714 if (mutex_lock_interruptible(&adapter->mbox_lock))
715 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700716
717 wrb = wrb_from_mbox(adapter);
718 req = embedded_payload(wrb);
719 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700720
Ajit Khaparded744b442009-12-03 06:12:06 +0000721 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
722 OPCODE_COMMON_CQ_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700723
724 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
725 OPCODE_COMMON_CQ_CREATE, sizeof(*req));
726
727 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000728 if (lancer_chip(adapter)) {
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000729 req->hdr.version = 2;
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000730 req->page_size = 1; /* 1 for 4K */
731 AMAP_SET_BITS(struct amap_cq_context_lancer, coalescwm, ctxt,
732 coalesce_wm);
733 AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt,
734 no_delay);
735 AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt,
736 __ilog2_u32(cq->len/256));
737 AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1);
738 AMAP_SET_BITS(struct amap_cq_context_lancer, eventable,
739 ctxt, 1);
740 AMAP_SET_BITS(struct amap_cq_context_lancer, eqid,
741 ctxt, eq->id);
742 AMAP_SET_BITS(struct amap_cq_context_lancer, armed, ctxt, 1);
743 } else {
744 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
745 coalesce_wm);
746 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
747 ctxt, no_delay);
748 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
749 __ilog2_u32(cq->len/256));
750 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
751 AMAP_SET_BITS(struct amap_cq_context_be, solevent,
752 ctxt, sol_evts);
753 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
754 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
755 AMAP_SET_BITS(struct amap_cq_context_be, armed, ctxt, 1);
756 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700757
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700758 be_dws_cpu_to_le(ctxt, sizeof(req->context));
759
760 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
761
Sathya Perlab31c50a2009-09-17 10:30:13 -0700762 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700763 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700764 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700765 cq->id = le16_to_cpu(resp->cq_id);
766 cq->created = true;
767 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700768
Ivan Vecera29849612010-12-14 05:43:19 +0000769 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000770
771 return status;
772}
773
774static u32 be_encoded_q_len(int q_len)
775{
776 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
777 if (len_encoded == 16)
778 len_encoded = 0;
779 return len_encoded;
780}
781
Sathya Perla8788fdc2009-07-27 22:52:03 +0000782int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perla5fb379e2009-06-18 00:02:59 +0000783 struct be_queue_info *mccq,
784 struct be_queue_info *cq)
785{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700786 struct be_mcc_wrb *wrb;
787 struct be_cmd_req_mcc_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000788 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700789 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000790 int status;
791
Ivan Vecera29849612010-12-14 05:43:19 +0000792 if (mutex_lock_interruptible(&adapter->mbox_lock))
793 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700794
795 wrb = wrb_from_mbox(adapter);
796 req = embedded_payload(wrb);
797 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000798
Ajit Khaparded744b442009-12-03 06:12:06 +0000799 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700800 OPCODE_COMMON_MCC_CREATE_EXT);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000801
802 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Koturcc4ce022010-10-21 07:11:14 -0700803 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000804
Ajit Khaparded4a2ac32010-03-11 01:35:59 +0000805 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000806 if (lancer_chip(adapter)) {
807 req->hdr.version = 1;
808 req->cq_id = cpu_to_le16(cq->id);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000809
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000810 AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt,
811 be_encoded_q_len(mccq->len));
812 AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1);
813 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id,
814 ctxt, cq->id);
815 AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid,
816 ctxt, 1);
817
818 } else {
819 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
820 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
821 be_encoded_q_len(mccq->len));
822 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
823 }
824
Somnath Koturcc4ce022010-10-21 07:11:14 -0700825 /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000826 req->async_event_bitmap[0] = cpu_to_le32(0x00000022);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000827 be_dws_cpu_to_le(ctxt, sizeof(req->context));
828
829 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
830
Sathya Perlab31c50a2009-09-17 10:30:13 -0700831 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000832 if (!status) {
833 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
834 mccq->id = le16_to_cpu(resp->id);
835 mccq->created = true;
836 }
Ivan Vecera29849612010-12-14 05:43:19 +0000837 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700838
839 return status;
840}
841
Sathya Perla8788fdc2009-07-27 22:52:03 +0000842int be_cmd_txq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700843 struct be_queue_info *txq,
844 struct be_queue_info *cq)
845{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700846 struct be_mcc_wrb *wrb;
847 struct be_cmd_req_eth_tx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700848 struct be_dma_mem *q_mem = &txq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700849 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700850 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700851
Ivan Vecera29849612010-12-14 05:43:19 +0000852 if (mutex_lock_interruptible(&adapter->mbox_lock))
853 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700854
855 wrb = wrb_from_mbox(adapter);
856 req = embedded_payload(wrb);
857 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700858
Ajit Khaparded744b442009-12-03 06:12:06 +0000859 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
860 OPCODE_ETH_TX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700861
862 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE,
863 sizeof(*req));
864
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +0000865 if (lancer_chip(adapter)) {
866 req->hdr.version = 1;
867 AMAP_SET_BITS(struct amap_tx_context, if_id, ctxt,
868 adapter->if_handle);
869 }
870
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700871 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
872 req->ulp_num = BE_ULP1_NUM;
873 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
874
Sathya Perlab31c50a2009-09-17 10:30:13 -0700875 AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt,
876 be_encoded_q_len(txq->len));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700877 AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1);
878 AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id);
879
880 be_dws_cpu_to_le(ctxt, sizeof(req->context));
881
882 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
883
Sathya Perlab31c50a2009-09-17 10:30:13 -0700884 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700885 if (!status) {
886 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb);
887 txq->id = le16_to_cpu(resp->cid);
888 txq->created = true;
889 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700890
Ivan Vecera29849612010-12-14 05:43:19 +0000891 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700892
893 return status;
894}
895
Sathya Perlab31c50a2009-09-17 10:30:13 -0700896/* Uses mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000897int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700898 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
Sathya Perla3abcded2010-10-03 22:12:27 -0700899 u16 max_frame_size, u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700900{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700901 struct be_mcc_wrb *wrb;
902 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700903 struct be_dma_mem *q_mem = &rxq->dma_mem;
904 int status;
905
Ivan Vecera29849612010-12-14 05:43:19 +0000906 if (mutex_lock_interruptible(&adapter->mbox_lock))
907 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700908
909 wrb = wrb_from_mbox(adapter);
910 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700911
Ajit Khaparded744b442009-12-03 06:12:06 +0000912 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
913 OPCODE_ETH_RX_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700914
915 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE,
916 sizeof(*req));
917
918 req->cq_id = cpu_to_le16(cq_id);
919 req->frag_size = fls(frag_size) - 1;
920 req->num_pages = 2;
921 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
922 req->interface_id = cpu_to_le32(if_id);
923 req->max_frame_size = cpu_to_le16(max_frame_size);
924 req->rss_queue = cpu_to_le32(rss);
925
Sathya Perlab31c50a2009-09-17 10:30:13 -0700926 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700927 if (!status) {
928 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
929 rxq->id = le16_to_cpu(resp->id);
930 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -0700931 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700932 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700933
Ivan Vecera29849612010-12-14 05:43:19 +0000934 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700935
936 return status;
937}
938
Sathya Perlab31c50a2009-09-17 10:30:13 -0700939/* Generic destroyer function for all types of queues
940 * Uses Mbox
941 */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000942int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700943 int queue_type)
944{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700945 struct be_mcc_wrb *wrb;
946 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700947 u8 subsys = 0, opcode = 0;
948 int status;
949
Sathya Perlacf588472010-02-14 21:22:01 +0000950 if (adapter->eeh_err)
951 return -EIO;
952
Ivan Vecera29849612010-12-14 05:43:19 +0000953 if (mutex_lock_interruptible(&adapter->mbox_lock))
954 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700955
Sathya Perlab31c50a2009-09-17 10:30:13 -0700956 wrb = wrb_from_mbox(adapter);
957 req = embedded_payload(wrb);
958
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700959 switch (queue_type) {
960 case QTYPE_EQ:
961 subsys = CMD_SUBSYSTEM_COMMON;
962 opcode = OPCODE_COMMON_EQ_DESTROY;
963 break;
964 case QTYPE_CQ:
965 subsys = CMD_SUBSYSTEM_COMMON;
966 opcode = OPCODE_COMMON_CQ_DESTROY;
967 break;
968 case QTYPE_TXQ:
969 subsys = CMD_SUBSYSTEM_ETH;
970 opcode = OPCODE_ETH_TX_DESTROY;
971 break;
972 case QTYPE_RXQ:
973 subsys = CMD_SUBSYSTEM_ETH;
974 opcode = OPCODE_ETH_RX_DESTROY;
975 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000976 case QTYPE_MCCQ:
977 subsys = CMD_SUBSYSTEM_COMMON;
978 opcode = OPCODE_COMMON_MCC_DESTROY;
979 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700980 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +0000981 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700982 }
Ajit Khaparded744b442009-12-03 06:12:06 +0000983
984 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode);
985
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700986 be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req));
987 req->id = cpu_to_le16(q->id);
988
Sathya Perlab31c50a2009-09-17 10:30:13 -0700989 status = be_mbox_notify_wait(adapter);
Sathya Perla5f0b8492009-07-27 22:52:56 +0000990
Ivan Vecera29849612010-12-14 05:43:19 +0000991 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700992
993 return status;
994}
995
Sathya Perlab31c50a2009-09-17 10:30:13 -0700996/* Create an rx filtering policy configuration on an i/f
997 * Uses mbox
998 */
Sathya Perla73d540f2009-10-14 20:20:42 +0000999int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001000 u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id,
1001 u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001002{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001003 struct be_mcc_wrb *wrb;
1004 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001005 int status;
1006
Ivan Vecera29849612010-12-14 05:43:19 +00001007 if (mutex_lock_interruptible(&adapter->mbox_lock))
1008 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001009
1010 wrb = wrb_from_mbox(adapter);
1011 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001012
Ajit Khaparded744b442009-12-03 06:12:06 +00001013 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1014 OPCODE_COMMON_NTWK_INTERFACE_CREATE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001015
1016 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1017 OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req));
1018
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001019 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001020 req->capability_flags = cpu_to_le32(cap_flags);
1021 req->enable_flags = cpu_to_le32(en_flags);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001022 req->pmac_invalid = pmac_invalid;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001023 if (!pmac_invalid)
1024 memcpy(req->mac_addr, mac, ETH_ALEN);
1025
Sathya Perlab31c50a2009-09-17 10:30:13 -07001026 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027 if (!status) {
1028 struct be_cmd_resp_if_create *resp = embedded_payload(wrb);
1029 *if_handle = le32_to_cpu(resp->interface_id);
1030 if (!pmac_invalid)
1031 *pmac_id = le32_to_cpu(resp->pmac_id);
1032 }
1033
Ivan Vecera29849612010-12-14 05:43:19 +00001034 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001035 return status;
1036}
1037
Sathya Perlab31c50a2009-09-17 10:30:13 -07001038/* Uses mbox */
Ajit Khaparde658681f2011-02-11 13:34:46 +00001039int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001040{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001041 struct be_mcc_wrb *wrb;
1042 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001043 int status;
1044
Sathya Perlacf588472010-02-14 21:22:01 +00001045 if (adapter->eeh_err)
1046 return -EIO;
1047
Ivan Vecera29849612010-12-14 05:43:19 +00001048 if (mutex_lock_interruptible(&adapter->mbox_lock))
1049 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001050
1051 wrb = wrb_from_mbox(adapter);
1052 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001053
Ajit Khaparded744b442009-12-03 06:12:06 +00001054 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1055 OPCODE_COMMON_NTWK_INTERFACE_DESTROY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001056
1057 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1058 OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req));
1059
Ajit Khaparde658681f2011-02-11 13:34:46 +00001060 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001061 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001062
1063 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001064
Ivan Vecera29849612010-12-14 05:43:19 +00001065 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001066
1067 return status;
1068}
1069
1070/* Get stats is a non embedded command: the request is not embedded inside
1071 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001072 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001073 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001074int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001075{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001076 struct be_mcc_wrb *wrb;
1077 struct be_cmd_req_get_stats *req;
1078 struct be_sge *sge;
Sathya Perla713d03942009-11-22 22:02:45 +00001079 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001080
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001081 if (MODULO(adapter->work_counter, be_get_temp_freq) == 0)
1082 be_cmd_get_die_temperature(adapter);
1083
Sathya Perlab31c50a2009-09-17 10:30:13 -07001084 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001085
Sathya Perlab31c50a2009-09-17 10:30:13 -07001086 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001087 if (!wrb) {
1088 status = -EBUSY;
1089 goto err;
1090 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001091 req = nonemb_cmd->va;
1092 sge = nonembedded_sgl(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001093
Ajit Khaparded744b442009-12-03 06:12:06 +00001094 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1095 OPCODE_ETH_GET_STATISTICS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001096
1097 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1098 OPCODE_ETH_GET_STATISTICS, sizeof(*req));
1099 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1100 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1101 sge->len = cpu_to_le32(nonemb_cmd->size);
1102
Sathya Perlab31c50a2009-09-17 10:30:13 -07001103 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001104 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001105
Sathya Perla713d03942009-11-22 22:02:45 +00001106err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001107 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001108 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001109}
1110
Sathya Perlab31c50a2009-09-17 10:30:13 -07001111/* Uses synchronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001112int be_cmd_link_status_query(struct be_adapter *adapter,
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001113 bool *link_up, u8 *mac_speed, u16 *link_speed)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001114{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001115 struct be_mcc_wrb *wrb;
1116 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001117 int status;
1118
Sathya Perlab31c50a2009-09-17 10:30:13 -07001119 spin_lock_bh(&adapter->mcc_lock);
1120
1121 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001122 if (!wrb) {
1123 status = -EBUSY;
1124 goto err;
1125 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001126 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001127
1128 *link_up = false;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001129
Ajit Khaparded744b442009-12-03 06:12:06 +00001130 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1131 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001132
1133 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1134 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req));
1135
Sathya Perlab31c50a2009-09-17 10:30:13 -07001136 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001137 if (!status) {
1138 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001139 if (resp->mac_speed != PHY_LINK_SPEED_ZERO) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001140 *link_up = true;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001141 *link_speed = le16_to_cpu(resp->link_speed);
1142 *mac_speed = resp->mac_speed;
1143 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001144 }
1145
Sathya Perla713d03942009-11-22 22:02:45 +00001146err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001147 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001148 return status;
1149}
1150
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001151/* Uses synchronous mcc */
1152int be_cmd_get_die_temperature(struct be_adapter *adapter)
1153{
1154 struct be_mcc_wrb *wrb;
1155 struct be_cmd_req_get_cntl_addnl_attribs *req;
1156 int status;
1157
1158 spin_lock_bh(&adapter->mcc_lock);
1159
1160 wrb = wrb_from_mccq(adapter);
1161 if (!wrb) {
1162 status = -EBUSY;
1163 goto err;
1164 }
1165 req = embedded_payload(wrb);
1166
1167 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1168 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES);
1169
1170 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1171 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req));
1172
1173 status = be_mcc_notify_wait(adapter);
1174 if (!status) {
1175 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
1176 embedded_payload(wrb);
1177 adapter->drv_stats.be_on_die_temperature =
1178 resp->on_die_temperature;
1179 }
1180 /* If IOCTL fails once, do not bother issuing it again */
1181 else
1182 be_get_temp_freq = 0;
1183
1184err:
1185 spin_unlock_bh(&adapter->mcc_lock);
1186 return status;
1187}
1188
Sathya Perlab31c50a2009-09-17 10:30:13 -07001189/* Uses Mbox */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001190int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001191{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001192 struct be_mcc_wrb *wrb;
1193 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001194 int status;
1195
Ivan Vecera29849612010-12-14 05:43:19 +00001196 if (mutex_lock_interruptible(&adapter->mbox_lock))
1197 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001198
1199 wrb = wrb_from_mbox(adapter);
1200 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001201
Ajit Khaparded744b442009-12-03 06:12:06 +00001202 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1203 OPCODE_COMMON_GET_FW_VERSION);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001204
1205 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1206 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req));
1207
Sathya Perlab31c50a2009-09-17 10:30:13 -07001208 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001209 if (!status) {
1210 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
1211 strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN);
1212 }
1213
Ivan Vecera29849612010-12-14 05:43:19 +00001214 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001215 return status;
1216}
1217
Sathya Perlab31c50a2009-09-17 10:30:13 -07001218/* set the EQ delay interval of an EQ to specified value
1219 * Uses async mcc
1220 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001221int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001222{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001223 struct be_mcc_wrb *wrb;
1224 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla713d03942009-11-22 22:02:45 +00001225 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001226
Sathya Perlab31c50a2009-09-17 10:30:13 -07001227 spin_lock_bh(&adapter->mcc_lock);
1228
1229 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001230 if (!wrb) {
1231 status = -EBUSY;
1232 goto err;
1233 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001234 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001235
Ajit Khaparded744b442009-12-03 06:12:06 +00001236 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1237 OPCODE_COMMON_MODIFY_EQ_DELAY);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001238
1239 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1240 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
1241
1242 req->num_eq = cpu_to_le32(1);
1243 req->delay[0].eq_id = cpu_to_le32(eq_id);
1244 req->delay[0].phase = 0;
1245 req->delay[0].delay_multiplier = cpu_to_le32(eqd);
1246
Sathya Perlab31c50a2009-09-17 10:30:13 -07001247 be_mcc_notify(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001248
Sathya Perla713d03942009-11-22 22:02:45 +00001249err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001250 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001251 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001252}
1253
Sathya Perlab31c50a2009-09-17 10:30:13 -07001254/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001255int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001256 u32 num, bool untagged, bool promiscuous)
1257{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001258 struct be_mcc_wrb *wrb;
1259 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001260 int status;
1261
Sathya Perlab31c50a2009-09-17 10:30:13 -07001262 spin_lock_bh(&adapter->mcc_lock);
1263
1264 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001265 if (!wrb) {
1266 status = -EBUSY;
1267 goto err;
1268 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001269 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001270
Ajit Khaparded744b442009-12-03 06:12:06 +00001271 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1272 OPCODE_COMMON_NTWK_VLAN_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001273
1274 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1275 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req));
1276
1277 req->interface_id = if_id;
1278 req->promiscuous = promiscuous;
1279 req->untagged = untagged;
1280 req->num_vlan = num;
1281 if (!promiscuous) {
1282 memcpy(req->normal_vlan, vtag_array,
1283 req->num_vlan * sizeof(vtag_array[0]));
1284 }
1285
Sathya Perlab31c50a2009-09-17 10:30:13 -07001286 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001287
Sathya Perla713d03942009-11-22 22:02:45 +00001288err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001289 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001290 return status;
1291}
1292
Sathya Perlab31c50a2009-09-17 10:30:13 -07001293/* Uses MCC for this command as it may be called in BH context
1294 * Uses synchronous mcc
1295 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001296int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001297{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001298 struct be_mcc_wrb *wrb;
1299 struct be_cmd_req_promiscuous_config *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001300 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001301
Sathya Perla8788fdc2009-07-27 22:52:03 +00001302 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001303
Sathya Perlab31c50a2009-09-17 10:30:13 -07001304 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001305 if (!wrb) {
1306 status = -EBUSY;
1307 goto err;
1308 }
Sathya Perla6ac7b682009-06-18 00:05:54 +00001309 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, OPCODE_ETH_PROMISCUOUS);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001312
1313 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1314 OPCODE_ETH_PROMISCUOUS, sizeof(*req));
1315
Sathya Perla69d7ce72010-04-11 22:35:27 +00001316 /* In FW versions X.102.149/X.101.487 and later,
1317 * the port setting associated only with the
1318 * issuing pci function will take effect
1319 */
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001320 if (port_num)
1321 req->port1_promiscuous = en;
1322 else
1323 req->port0_promiscuous = en;
1324
Sathya Perlab31c50a2009-09-17 10:30:13 -07001325 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001326
Sathya Perla713d03942009-11-22 22:02:45 +00001327err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001328 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001329 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001330}
1331
Sathya Perla6ac7b682009-06-18 00:05:54 +00001332/*
Sathya Perlab31c50a2009-09-17 10:30:13 -07001333 * Uses MCC for this command as it may be called in BH context
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001334 * (mc == NULL) => multicast promiscuous
Sathya Perla6ac7b682009-06-18 00:05:54 +00001335 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001336int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id,
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001337 struct net_device *netdev, struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001338{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001339 struct be_mcc_wrb *wrb;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001340 struct be_cmd_req_mcast_mac_config *req = mem->va;
1341 struct be_sge *sge;
1342 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001343
Sathya Perla8788fdc2009-07-27 22:52:03 +00001344 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001345
Sathya Perlab31c50a2009-09-17 10:30:13 -07001346 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001347 if (!wrb) {
1348 status = -EBUSY;
1349 goto err;
1350 }
Sathya Perlae7b909a2009-11-22 22:01:10 +00001351 sge = nonembedded_sgl(wrb);
1352 memset(req, 0, sizeof(*req));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001353
Ajit Khaparded744b442009-12-03 06:12:06 +00001354 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1355 OPCODE_COMMON_NTWK_MULTICAST_SET);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001356 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
1357 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
1358 sge->len = cpu_to_le32(mem->size);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001359
1360 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1361 OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req));
1362
1363 req->interface_id = if_id;
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001364 if (netdev) {
Sathya Perla24307ee2009-06-18 00:09:25 +00001365 int i;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001366 struct netdev_hw_addr *ha;
Sathya Perla24307ee2009-06-18 00:09:25 +00001367
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001368 req->num_mac = cpu_to_le16(netdev_mc_count(netdev));
Sathya Perla24307ee2009-06-18 00:09:25 +00001369
Jiri Pirko0ddf4772010-02-20 00:13:58 +00001370 i = 0;
Jiri Pirko22bedad32010-04-01 21:22:57 +00001371 netdev_for_each_mc_addr(ha, netdev)
Joe Jin408cc292010-12-06 03:00:59 +00001372 memcpy(req->mac[i++].byte, ha->addr, ETH_ALEN);
Sathya Perla24307ee2009-06-18 00:09:25 +00001373 } else {
1374 req->promiscuous = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001375 }
1376
Sathya Perlae7b909a2009-11-22 22:01:10 +00001377 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001378
Sathya Perla713d03942009-11-22 22:02:45 +00001379err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001380 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001381 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001382}
1383
Sathya Perlab31c50a2009-09-17 10:30:13 -07001384/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001385int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001386{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001387 struct be_mcc_wrb *wrb;
1388 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001389 int status;
1390
Sathya Perlab31c50a2009-09-17 10:30:13 -07001391 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001392
Sathya Perlab31c50a2009-09-17 10:30:13 -07001393 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001394 if (!wrb) {
1395 status = -EBUSY;
1396 goto err;
1397 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001398 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001399
Ajit Khaparded744b442009-12-03 06:12:06 +00001400 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1401 OPCODE_COMMON_SET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001402
1403 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1404 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req));
1405
1406 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
1407 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
1408
Sathya Perlab31c50a2009-09-17 10:30:13 -07001409 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001410
Sathya Perla713d03942009-11-22 22:02:45 +00001411err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001412 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001413 return status;
1414}
1415
Sathya Perlab31c50a2009-09-17 10:30:13 -07001416/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001417int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001418{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001419 struct be_mcc_wrb *wrb;
1420 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001421 int status;
1422
Sathya Perlab31c50a2009-09-17 10:30:13 -07001423 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001424
Sathya Perlab31c50a2009-09-17 10:30:13 -07001425 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001426 if (!wrb) {
1427 status = -EBUSY;
1428 goto err;
1429 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001430 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001431
Ajit Khaparded744b442009-12-03 06:12:06 +00001432 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1433 OPCODE_COMMON_GET_FLOW_CONTROL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001434
1435 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1436 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req));
1437
Sathya Perlab31c50a2009-09-17 10:30:13 -07001438 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001439 if (!status) {
1440 struct be_cmd_resp_get_flow_control *resp =
1441 embedded_payload(wrb);
1442 *tx_fc = le16_to_cpu(resp->tx_flow_control);
1443 *rx_fc = le16_to_cpu(resp->rx_flow_control);
1444 }
1445
Sathya Perla713d03942009-11-22 22:02:45 +00001446err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001447 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001448 return status;
1449}
1450
Sathya Perlab31c50a2009-09-17 10:30:13 -07001451/* Uses mbox */
Sathya Perla3abcded2010-10-03 22:12:27 -07001452int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num,
1453 u32 *mode, u32 *caps)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001454{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001455 struct be_mcc_wrb *wrb;
1456 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001457 int status;
1458
Ivan Vecera29849612010-12-14 05:43:19 +00001459 if (mutex_lock_interruptible(&adapter->mbox_lock))
1460 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001461
Sathya Perlab31c50a2009-09-17 10:30:13 -07001462 wrb = wrb_from_mbox(adapter);
1463 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001464
Ajit Khaparded744b442009-12-03 06:12:06 +00001465 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1466 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001467
1468 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1469 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
1470
Sathya Perlab31c50a2009-09-17 10:30:13 -07001471 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001472 if (!status) {
1473 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
1474 *port_num = le32_to_cpu(resp->phys_port);
Ajit Khaparde3486be22010-07-23 02:04:54 +00001475 *mode = le32_to_cpu(resp->function_mode);
Sathya Perla3abcded2010-10-03 22:12:27 -07001476 *caps = le32_to_cpu(resp->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001477 }
1478
Ivan Vecera29849612010-12-14 05:43:19 +00001479 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001480 return status;
1481}
sarveshwarb14074ea2009-08-05 13:05:24 -07001482
Sathya Perlab31c50a2009-09-17 10:30:13 -07001483/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07001484int be_cmd_reset_function(struct be_adapter *adapter)
1485{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001486 struct be_mcc_wrb *wrb;
1487 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07001488 int status;
1489
Ivan Vecera29849612010-12-14 05:43:19 +00001490 if (mutex_lock_interruptible(&adapter->mbox_lock))
1491 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07001492
Sathya Perlab31c50a2009-09-17 10:30:13 -07001493 wrb = wrb_from_mbox(adapter);
1494 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07001495
Ajit Khaparded744b442009-12-03 06:12:06 +00001496 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1497 OPCODE_COMMON_FUNCTION_RESET);
sarveshwarb14074ea2009-08-05 13:05:24 -07001498
1499 be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
1500 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req));
1501
Sathya Perlab31c50a2009-09-17 10:30:13 -07001502 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07001503
Ivan Vecera29849612010-12-14 05:43:19 +00001504 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07001505 return status;
1506}
Ajit Khaparde84517482009-09-04 03:12:16 +00001507
Sathya Perla3abcded2010-10-03 22:12:27 -07001508int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size)
1509{
1510 struct be_mcc_wrb *wrb;
1511 struct be_cmd_req_rss_config *req;
1512 u32 myhash[10];
1513 int status;
1514
Ivan Vecera29849612010-12-14 05:43:19 +00001515 if (mutex_lock_interruptible(&adapter->mbox_lock))
1516 return -1;
Sathya Perla3abcded2010-10-03 22:12:27 -07001517
1518 wrb = wrb_from_mbox(adapter);
1519 req = embedded_payload(wrb);
1520
1521 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1522 OPCODE_ETH_RSS_CONFIG);
1523
1524 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1525 OPCODE_ETH_RSS_CONFIG, sizeof(*req));
1526
1527 req->if_id = cpu_to_le32(adapter->if_handle);
1528 req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4);
1529 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
1530 memcpy(req->cpu_table, rsstable, table_size);
1531 memcpy(req->hash, myhash, sizeof(myhash));
1532 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
1533
1534 status = be_mbox_notify_wait(adapter);
1535
Ivan Vecera29849612010-12-14 05:43:19 +00001536 mutex_unlock(&adapter->mbox_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07001537 return status;
1538}
1539
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001540/* Uses sync mcc */
1541int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
1542 u8 bcn, u8 sts, u8 state)
1543{
1544 struct be_mcc_wrb *wrb;
1545 struct be_cmd_req_enable_disable_beacon *req;
1546 int status;
1547
1548 spin_lock_bh(&adapter->mcc_lock);
1549
1550 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001551 if (!wrb) {
1552 status = -EBUSY;
1553 goto err;
1554 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001555 req = embedded_payload(wrb);
1556
Ajit Khaparded744b442009-12-03 06:12:06 +00001557 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1558 OPCODE_COMMON_ENABLE_DISABLE_BEACON);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001559
1560 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1561 OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req));
1562
1563 req->port_num = port_num;
1564 req->beacon_state = state;
1565 req->beacon_duration = bcn;
1566 req->status_duration = sts;
1567
1568 status = be_mcc_notify_wait(adapter);
1569
Sathya Perla713d03942009-11-22 22:02:45 +00001570err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001571 spin_unlock_bh(&adapter->mcc_lock);
1572 return status;
1573}
1574
1575/* Uses sync mcc */
1576int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
1577{
1578 struct be_mcc_wrb *wrb;
1579 struct be_cmd_req_get_beacon_state *req;
1580 int status;
1581
1582 spin_lock_bh(&adapter->mcc_lock);
1583
1584 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001585 if (!wrb) {
1586 status = -EBUSY;
1587 goto err;
1588 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001589 req = embedded_payload(wrb);
1590
Ajit Khaparded744b442009-12-03 06:12:06 +00001591 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1592 OPCODE_COMMON_GET_BEACON_STATE);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001593
1594 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1595 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req));
1596
1597 req->port_num = port_num;
1598
1599 status = be_mcc_notify_wait(adapter);
1600 if (!status) {
1601 struct be_cmd_resp_get_beacon_state *resp =
1602 embedded_payload(wrb);
1603 *state = resp->beacon_state;
1604 }
1605
Sathya Perla713d03942009-11-22 22:02:45 +00001606err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07001607 spin_unlock_bh(&adapter->mcc_lock);
1608 return status;
1609}
1610
Ajit Khaparde84517482009-09-04 03:12:16 +00001611int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
1612 u32 flash_type, u32 flash_opcode, u32 buf_size)
1613{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001614 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001615 struct be_cmd_write_flashrom *req;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001616 struct be_sge *sge;
Ajit Khaparde84517482009-09-04 03:12:16 +00001617 int status;
1618
Sathya Perlab31c50a2009-09-17 10:30:13 -07001619 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001620 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001621
1622 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001623 if (!wrb) {
1624 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001625 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00001626 }
1627 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001628 sge = nonembedded_sgl(wrb);
1629
Ajit Khaparded744b442009-12-03 06:12:06 +00001630 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1631 OPCODE_COMMON_WRITE_FLASHROM);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001632 wrb->tag1 = CMD_SUBSYSTEM_COMMON;
Ajit Khaparde84517482009-09-04 03:12:16 +00001633
1634 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1635 OPCODE_COMMON_WRITE_FLASHROM, cmd->size);
1636 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1637 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1638 sge->len = cpu_to_le32(cmd->size);
1639
1640 req->params.op_type = cpu_to_le32(flash_type);
1641 req->params.op_code = cpu_to_le32(flash_opcode);
1642 req->params.data_buf_size = cpu_to_le32(buf_size);
1643
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07001644 be_mcc_notify(adapter);
1645 spin_unlock_bh(&adapter->mcc_lock);
1646
1647 if (!wait_for_completion_timeout(&adapter->flash_compl,
1648 msecs_to_jiffies(12000)))
1649 status = -1;
1650 else
1651 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00001652
Dan Carpenter2892d9c2010-05-26 04:46:35 +00001653 return status;
1654
1655err_unlock:
1656 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00001657 return status;
1658}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001659
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001660int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
1661 int offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001662{
1663 struct be_mcc_wrb *wrb;
1664 struct be_cmd_write_flashrom *req;
1665 int status;
1666
1667 spin_lock_bh(&adapter->mcc_lock);
1668
1669 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001670 if (!wrb) {
1671 status = -EBUSY;
1672 goto err;
1673 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001674 req = embedded_payload(wrb);
1675
Ajit Khaparded744b442009-12-03 06:12:06 +00001676 be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0,
1677 OPCODE_COMMON_READ_FLASHROM);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001678
1679 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1680 OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4);
1681
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00001682 req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001683 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00001684 req->params.offset = cpu_to_le32(offset);
1685 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001686
1687 status = be_mcc_notify_wait(adapter);
1688 if (!status)
1689 memcpy(flashed_crc, req->params.data_buf, 4);
1690
Sathya Perla713d03942009-11-22 22:02:45 +00001691err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08001692 spin_unlock_bh(&adapter->mcc_lock);
1693 return status;
1694}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001695
Dan Carpenterc196b022010-05-26 04:47:39 +00001696int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00001697 struct be_dma_mem *nonemb_cmd)
1698{
1699 struct be_mcc_wrb *wrb;
1700 struct be_cmd_req_acpi_wol_magic_config *req;
1701 struct be_sge *sge;
1702 int status;
1703
1704 spin_lock_bh(&adapter->mcc_lock);
1705
1706 wrb = wrb_from_mccq(adapter);
1707 if (!wrb) {
1708 status = -EBUSY;
1709 goto err;
1710 }
1711 req = nonemb_cmd->va;
1712 sge = nonembedded_sgl(wrb);
1713
1714 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1715 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG);
1716
1717 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
1718 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req));
1719 memcpy(req->magic_mac, mac, ETH_ALEN);
1720
1721 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1722 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1723 sge->len = cpu_to_le32(nonemb_cmd->size);
1724
1725 status = be_mcc_notify_wait(adapter);
1726
1727err:
1728 spin_unlock_bh(&adapter->mcc_lock);
1729 return status;
1730}
Suresh Rff33a6e2009-12-03 16:15:52 -08001731
Sarveshwar Bandifced9992009-12-23 04:41:44 +00001732int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
1733 u8 loopback_type, u8 enable)
1734{
1735 struct be_mcc_wrb *wrb;
1736 struct be_cmd_req_set_lmode *req;
1737 int status;
1738
1739 spin_lock_bh(&adapter->mcc_lock);
1740
1741 wrb = wrb_from_mccq(adapter);
1742 if (!wrb) {
1743 status = -EBUSY;
1744 goto err;
1745 }
1746
1747 req = embedded_payload(wrb);
1748
1749 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1750 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE);
1751
1752 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1753 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
1754 sizeof(*req));
1755
1756 req->src_port = port_num;
1757 req->dest_port = port_num;
1758 req->loopback_type = loopback_type;
1759 req->loopback_state = enable;
1760
1761 status = be_mcc_notify_wait(adapter);
1762err:
1763 spin_unlock_bh(&adapter->mcc_lock);
1764 return status;
1765}
1766
Suresh Rff33a6e2009-12-03 16:15:52 -08001767int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
1768 u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern)
1769{
1770 struct be_mcc_wrb *wrb;
1771 struct be_cmd_req_loopback_test *req;
1772 int status;
1773
1774 spin_lock_bh(&adapter->mcc_lock);
1775
1776 wrb = wrb_from_mccq(adapter);
1777 if (!wrb) {
1778 status = -EBUSY;
1779 goto err;
1780 }
1781
1782 req = embedded_payload(wrb);
1783
1784 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1785 OPCODE_LOWLEVEL_LOOPBACK_TEST);
1786
1787 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1788 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req));
Sathya Perla3ffd0512010-06-01 00:19:33 -07001789 req->hdr.timeout = cpu_to_le32(4);
Suresh Rff33a6e2009-12-03 16:15:52 -08001790
1791 req->pattern = cpu_to_le64(pattern);
1792 req->src_port = cpu_to_le32(port_num);
1793 req->dest_port = cpu_to_le32(port_num);
1794 req->pkt_size = cpu_to_le32(pkt_size);
1795 req->num_pkts = cpu_to_le32(num_pkts);
1796 req->loopback_type = cpu_to_le32(loopback_type);
1797
1798 status = be_mcc_notify_wait(adapter);
1799 if (!status) {
1800 struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb);
1801 status = le32_to_cpu(resp->status);
1802 }
1803
1804err:
1805 spin_unlock_bh(&adapter->mcc_lock);
1806 return status;
1807}
1808
1809int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
1810 u32 byte_cnt, struct be_dma_mem *cmd)
1811{
1812 struct be_mcc_wrb *wrb;
1813 struct be_cmd_req_ddrdma_test *req;
1814 struct be_sge *sge;
1815 int status;
1816 int i, j = 0;
1817
1818 spin_lock_bh(&adapter->mcc_lock);
1819
1820 wrb = wrb_from_mccq(adapter);
1821 if (!wrb) {
1822 status = -EBUSY;
1823 goto err;
1824 }
1825 req = cmd->va;
1826 sge = nonembedded_sgl(wrb);
1827 be_wrb_hdr_prepare(wrb, cmd->size, false, 1,
1828 OPCODE_LOWLEVEL_HOST_DDR_DMA);
1829 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
1830 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size);
1831
1832 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1833 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1834 sge->len = cpu_to_le32(cmd->size);
1835
1836 req->pattern = cpu_to_le64(pattern);
1837 req->byte_count = cpu_to_le32(byte_cnt);
1838 for (i = 0; i < byte_cnt; i++) {
1839 req->snd_buff[i] = (u8)(pattern >> (j*8));
1840 j++;
1841 if (j > 7)
1842 j = 0;
1843 }
1844
1845 status = be_mcc_notify_wait(adapter);
1846
1847 if (!status) {
1848 struct be_cmd_resp_ddrdma_test *resp;
1849 resp = cmd->va;
1850 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
1851 resp->snd_err) {
1852 status = -1;
1853 }
1854 }
1855
1856err:
1857 spin_unlock_bh(&adapter->mcc_lock);
1858 return status;
1859}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001860
Dan Carpenterc196b022010-05-26 04:47:39 +00001861int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001862 struct be_dma_mem *nonemb_cmd)
1863{
1864 struct be_mcc_wrb *wrb;
1865 struct be_cmd_req_seeprom_read *req;
1866 struct be_sge *sge;
1867 int status;
1868
1869 spin_lock_bh(&adapter->mcc_lock);
1870
1871 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00001872 if (!wrb) {
1873 status = -EBUSY;
1874 goto err;
1875 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001876 req = nonemb_cmd->va;
1877 sge = nonembedded_sgl(wrb);
1878
1879 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1880 OPCODE_COMMON_SEEPROM_READ);
1881
1882 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1883 OPCODE_COMMON_SEEPROM_READ, sizeof(*req));
1884
1885 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1886 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1887 sge->len = cpu_to_le32(nonemb_cmd->size);
1888
1889 status = be_mcc_notify_wait(adapter);
1890
Ajit Khapardee45ff012011-02-04 17:18:28 +00001891err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08001892 spin_unlock_bh(&adapter->mcc_lock);
1893 return status;
1894}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00001895
1896int be_cmd_get_phy_info(struct be_adapter *adapter, struct be_dma_mem *cmd)
1897{
1898 struct be_mcc_wrb *wrb;
1899 struct be_cmd_req_get_phy_info *req;
1900 struct be_sge *sge;
1901 int status;
1902
1903 spin_lock_bh(&adapter->mcc_lock);
1904
1905 wrb = wrb_from_mccq(adapter);
1906 if (!wrb) {
1907 status = -EBUSY;
1908 goto err;
1909 }
1910
1911 req = cmd->va;
1912 sge = nonembedded_sgl(wrb);
1913
1914 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1,
1915 OPCODE_COMMON_GET_PHY_DETAILS);
1916
1917 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1918 OPCODE_COMMON_GET_PHY_DETAILS,
1919 sizeof(*req));
1920
1921 sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma));
1922 sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF);
1923 sge->len = cpu_to_le32(cmd->size);
1924
1925 status = be_mcc_notify_wait(adapter);
1926err:
1927 spin_unlock_bh(&adapter->mcc_lock);
1928 return status;
1929}
Ajit Khapardee1d18732010-07-23 01:52:13 +00001930
1931int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
1932{
1933 struct be_mcc_wrb *wrb;
1934 struct be_cmd_req_set_qos *req;
1935 int status;
1936
1937 spin_lock_bh(&adapter->mcc_lock);
1938
1939 wrb = wrb_from_mccq(adapter);
1940 if (!wrb) {
1941 status = -EBUSY;
1942 goto err;
1943 }
1944
1945 req = embedded_payload(wrb);
1946
1947 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
1948 OPCODE_COMMON_SET_QOS);
1949
1950 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1951 OPCODE_COMMON_SET_QOS, sizeof(*req));
1952
1953 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00001954 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
1955 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00001956
1957 status = be_mcc_notify_wait(adapter);
1958
1959err:
1960 spin_unlock_bh(&adapter->mcc_lock);
1961 return status;
1962}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00001963
1964int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
1965{
1966 struct be_mcc_wrb *wrb;
1967 struct be_cmd_req_cntl_attribs *req;
1968 struct be_cmd_resp_cntl_attribs *resp;
1969 struct be_sge *sge;
1970 int status;
1971 int payload_len = max(sizeof(*req), sizeof(*resp));
1972 struct mgmt_controller_attrib *attribs;
1973 struct be_dma_mem attribs_cmd;
1974
1975 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
1976 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
1977 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
1978 &attribs_cmd.dma);
1979 if (!attribs_cmd.va) {
1980 dev_err(&adapter->pdev->dev,
1981 "Memory allocation failure\n");
1982 return -ENOMEM;
1983 }
1984
1985 if (mutex_lock_interruptible(&adapter->mbox_lock))
1986 return -1;
1987
1988 wrb = wrb_from_mbox(adapter);
1989 if (!wrb) {
1990 status = -EBUSY;
1991 goto err;
1992 }
1993 req = attribs_cmd.va;
1994 sge = nonembedded_sgl(wrb);
1995
1996 be_wrb_hdr_prepare(wrb, payload_len, false, 1,
1997 OPCODE_COMMON_GET_CNTL_ATTRIBUTES);
1998 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1999 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len);
2000 sge->pa_hi = cpu_to_le32(upper_32_bits(attribs_cmd.dma));
2001 sge->pa_lo = cpu_to_le32(attribs_cmd.dma & 0xFFFFFFFF);
2002 sge->len = cpu_to_le32(attribs_cmd.size);
2003
2004 status = be_mbox_notify_wait(adapter);
2005 if (!status) {
2006 attribs = (struct mgmt_controller_attrib *)( attribs_cmd.va +
2007 sizeof(struct be_cmd_resp_hdr));
2008 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2009 }
2010
2011err:
2012 mutex_unlock(&adapter->mbox_lock);
2013 pci_free_consistent(adapter->pdev, attribs_cmd.size, attribs_cmd.va,
2014 attribs_cmd.dma);
2015 return status;
2016}
Sathya Perla2e588f82011-03-11 02:49:26 +00002017
2018/* Uses mbox */
2019int be_cmd_check_native_mode(struct be_adapter *adapter)
2020{
2021 struct be_mcc_wrb *wrb;
2022 struct be_cmd_req_set_func_cap *req;
2023 int status;
2024
2025 if (mutex_lock_interruptible(&adapter->mbox_lock))
2026 return -1;
2027
2028 wrb = wrb_from_mbox(adapter);
2029 if (!wrb) {
2030 status = -EBUSY;
2031 goto err;
2032 }
2033
2034 req = embedded_payload(wrb);
2035
2036 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0,
2037 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP);
2038
2039 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2040 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req));
2041
2042 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2043 CAPABILITY_BE3_NATIVE_ERX_API);
2044 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2045
2046 status = be_mbox_notify_wait(adapter);
2047 if (!status) {
2048 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
2049 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2050 CAPABILITY_BE3_NATIVE_ERX_API;
2051 }
2052err:
2053 mutex_unlock(&adapter->mbox_lock);
2054 return status;
2055}