blob: 7f05f309e93596778851fb280fa4c8bd068828c3 [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Vasundhara Volam40263822014-02-12 16:09:07 +05302 * Copyright (C) 2005 - 2014 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
Parav Pandit6a4ab662012-03-26 14:27:12 +000018#include <linux/module.h>
Sathya Perla6b7c5b92009-03-11 23:32:03 -070019#include "be.h"
Sathya Perla8788fdc2009-07-27 22:52:03 +000020#include "be_cmds.h"
Sathya Perla6b7c5b92009-03-11 23:32:03 -070021
Vasundhara Volam21252372015-02-06 08:18:42 -050022static char *be_port_misconfig_evt_desc[] = {
23 "A valid SFP module detected",
24 "Optics faulted/ incorrectly installed/ not installed.",
25 "Optics of two types installed.",
26 "Incompatible optics.",
27 "Unknown port SFP status"
28};
29
30static char *be_port_misconfig_remedy_desc[] = {
31 "",
32 "Reseat optics. If issue not resolved, replace",
33 "Remove one optic or install matching pair of optics",
34 "Replace with compatible optics for card to function",
35 ""
36};
37
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000038static struct be_cmd_priv_map cmd_priv_map[] = {
39 {
40 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
41 CMD_SUBSYSTEM_ETH,
42 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
43 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
44 },
45 {
46 OPCODE_COMMON_GET_FLOW_CONTROL,
47 CMD_SUBSYSTEM_COMMON,
48 BE_PRIV_LNKQUERY | BE_PRIV_VHADM |
49 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
50 },
51 {
52 OPCODE_COMMON_SET_FLOW_CONTROL,
53 CMD_SUBSYSTEM_COMMON,
54 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
55 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
56 },
57 {
58 OPCODE_ETH_GET_PPORT_STATS,
59 CMD_SUBSYSTEM_ETH,
60 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
61 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
62 },
63 {
64 OPCODE_COMMON_GET_PHY_DETAILS,
65 CMD_SUBSYSTEM_COMMON,
66 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
67 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
68 }
69};
70
Sathya Perlaa2cc4e02014-05-09 13:29:14 +053071static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem)
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000072{
73 int i;
74 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
75 u32 cmd_privileges = adapter->cmd_privileges;
76
77 for (i = 0; i < num_entries; i++)
78 if (opcode == cmd_priv_map[i].opcode &&
79 subsystem == cmd_priv_map[i].subsystem)
80 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
81 return false;
82
83 return true;
84}
85
Somnath Kotur3de09452011-09-30 07:25:05 +000086static inline void *embedded_payload(struct be_mcc_wrb *wrb)
87{
88 return wrb->payload.embedded_payload;
89}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +000090
Sathya Perla8788fdc2009-07-27 22:52:03 +000091static void be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +000092{
Sathya Perla8788fdc2009-07-27 22:52:03 +000093 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +000094 u32 val = 0;
95
Sathya Perla6589ade2011-11-10 19:18:00 +000096 if (be_error(adapter))
Ajit Khaparde7acc2082011-02-11 13:38:17 +000097 return;
Ajit Khaparde7acc2082011-02-11 13:38:17 +000098
Sathya Perla5fb379e2009-06-18 00:02:59 +000099 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
100 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000101
102 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +0000103 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000104}
105
106/* To check if valid bit is set, check the entire word as we don't know
107 * the endianness of the data (old entry is host endian while a new entry is
108 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000109static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000110{
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000111 u32 flags;
112
Sathya Perla5fb379e2009-06-18 00:02:59 +0000113 if (compl->flags != 0) {
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000114 flags = le32_to_cpu(compl->flags);
115 if (flags & CQE_FLAGS_VALID_MASK) {
116 compl->flags = flags;
117 return true;
118 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000119 }
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000120 return false;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000121}
122
123/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000124static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000125{
126 compl->flags = 0;
127}
128
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000129static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
130{
131 unsigned long addr;
132
133 addr = tag1;
134 addr = ((addr << 16) << 16) | tag0;
135 return (void *)addr;
136}
137
Kalesh AP4c600052014-05-30 19:06:26 +0530138static bool be_skip_err_log(u8 opcode, u16 base_status, u16 addl_status)
139{
140 if (base_status == MCC_STATUS_NOT_SUPPORTED ||
141 base_status == MCC_STATUS_ILLEGAL_REQUEST ||
142 addl_status == MCC_ADDL_STATUS_TOO_MANY_INTERFACES ||
143 (opcode == OPCODE_COMMON_WRITE_FLASHROM &&
144 (base_status == MCC_STATUS_ILLEGAL_FIELD ||
145 addl_status == MCC_ADDL_STATUS_FLASH_IMAGE_CRC_MISMATCH)))
146 return true;
147 else
148 return false;
149}
150
Sathya Perla559b6332014-05-30 19:06:27 +0530151/* Place holder for all the async MCC cmds wherein the caller is not in a busy
152 * loop (has not issued be_mcc_notify_wait())
153 */
154static void be_async_cmd_process(struct be_adapter *adapter,
155 struct be_mcc_compl *compl,
156 struct be_cmd_resp_hdr *resp_hdr)
157{
158 enum mcc_base_status base_status = base_status(compl->status);
159 u8 opcode = 0, subsystem = 0;
160
161 if (resp_hdr) {
162 opcode = resp_hdr->opcode;
163 subsystem = resp_hdr->subsystem;
164 }
165
166 if (opcode == OPCODE_LOWLEVEL_LOOPBACK_TEST &&
167 subsystem == CMD_SUBSYSTEM_LOWLEVEL) {
168 complete(&adapter->et_cmd_compl);
169 return;
170 }
171
172 if ((opcode == OPCODE_COMMON_WRITE_FLASHROM ||
173 opcode == OPCODE_COMMON_WRITE_OBJECT) &&
174 subsystem == CMD_SUBSYSTEM_COMMON) {
175 adapter->flash_status = compl->status;
176 complete(&adapter->et_cmd_compl);
177 return;
178 }
179
180 if ((opcode == OPCODE_ETH_GET_STATISTICS ||
181 opcode == OPCODE_ETH_GET_PPORT_STATS) &&
182 subsystem == CMD_SUBSYSTEM_ETH &&
183 base_status == MCC_STATUS_SUCCESS) {
184 be_parse_stats(adapter);
185 adapter->stats_cmd_sent = false;
186 return;
187 }
188
189 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
190 subsystem == CMD_SUBSYSTEM_COMMON) {
191 if (base_status == MCC_STATUS_SUCCESS) {
192 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
193 (void *)resp_hdr;
194 adapter->drv_stats.be_on_die_temperature =
195 resp->on_die_temperature;
196 } else {
197 adapter->be_get_temp_freq = 0;
198 }
199 return;
200 }
201}
202
Sathya Perla8788fdc2009-07-27 22:52:03 +0000203static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000204 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000205{
Kalesh AP4c600052014-05-30 19:06:26 +0530206 enum mcc_base_status base_status;
207 enum mcc_addl_status addl_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000208 struct be_cmd_resp_hdr *resp_hdr;
209 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000210
211 /* Just swap the status to host endian; mcc tag is opaquely copied
212 * from mcc_wrb */
213 be_dws_le_to_cpu(compl, 4);
214
Kalesh AP4c600052014-05-30 19:06:26 +0530215 base_status = base_status(compl->status);
216 addl_status = addl_status(compl->status);
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +0530217
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000218 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000219 if (resp_hdr) {
220 opcode = resp_hdr->opcode;
221 subsystem = resp_hdr->subsystem;
222 }
223
Sathya Perla559b6332014-05-30 19:06:27 +0530224 be_async_cmd_process(adapter, compl, resp_hdr);
Suresh Reddy5eeff632014-01-06 13:02:24 +0530225
Sathya Perla559b6332014-05-30 19:06:27 +0530226 if (base_status != MCC_STATUS_SUCCESS &&
227 !be_skip_err_log(opcode, base_status, addl_status)) {
Kalesh AP4c600052014-05-30 19:06:26 +0530228 if (base_status == MCC_STATUS_UNAUTHORIZED_REQUEST) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000229 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000230 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000231 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000232 } else {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000233 dev_err(&adapter->pdev->dev,
234 "opcode %d-%d failed:status %d-%d\n",
Kalesh AP4c600052014-05-30 19:06:26 +0530235 opcode, subsystem, base_status, addl_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000236 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000237 }
Kalesh AP4c600052014-05-30 19:06:26 +0530238 return compl->status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000239}
240
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000241/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000242static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530243 struct be_mcc_compl *compl)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000244{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530245 struct be_async_event_link_state *evt =
246 (struct be_async_event_link_state *)compl;
247
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000248 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000249 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000250
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530251 /* On BEx the FW does not send a separate link status
252 * notification for physical and logical link.
253 * On other chips just process the logical link
254 * status notification
255 */
256 if (!BEx_chip(adapter) &&
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000257 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
258 return;
259
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000260 /* For the initial link status do not rely on the ASYNC event as
261 * it may not be received in some cases.
262 */
263 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530264 be_link_status_update(adapter,
265 evt->port_link_status & LINK_STATUS_MASK);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000266}
267
Vasundhara Volam21252372015-02-06 08:18:42 -0500268static void be_async_port_misconfig_event_process(struct be_adapter *adapter,
269 struct be_mcc_compl *compl)
270{
271 struct be_async_event_misconfig_port *evt =
272 (struct be_async_event_misconfig_port *)compl;
273 u32 sfp_mismatch_evt = le32_to_cpu(evt->event_data_word1);
274 struct device *dev = &adapter->pdev->dev;
275 u8 port_misconfig_evt;
276
277 port_misconfig_evt =
278 ((sfp_mismatch_evt >> (adapter->hba_port_num * 8)) & 0xff);
279
280 /* Log an error message that would allow a user to determine
281 * whether the SFPs have an issue
282 */
283 dev_info(dev, "Port %c: %s %s", adapter->port_name,
284 be_port_misconfig_evt_desc[port_misconfig_evt],
285 be_port_misconfig_remedy_desc[port_misconfig_evt]);
286
287 if (port_misconfig_evt == INCOMPATIBLE_SFP)
288 adapter->flags |= BE_FLAGS_EVT_INCOMPATIBLE_SFP;
289}
290
Somnath Koturcc4ce022010-10-21 07:11:14 -0700291/* Grp5 CoS Priority evt */
292static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530293 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700294{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530295 struct be_async_event_grp5_cos_priority *evt =
296 (struct be_async_event_grp5_cos_priority *)compl;
297
Somnath Koturcc4ce022010-10-21 07:11:14 -0700298 if (evt->valid) {
299 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Ajit Khaparde60964dd2011-02-11 13:37:25 +0000300 adapter->recommended_prio &= ~VLAN_PRIO_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700301 adapter->recommended_prio =
302 evt->reco_default_priority << VLAN_PRIO_SHIFT;
303 }
304}
305
Sathya Perla323ff712012-09-28 04:39:43 +0000306/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700307static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530308 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700309{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530310 struct be_async_event_grp5_qos_link_speed *evt =
311 (struct be_async_event_grp5_qos_link_speed *)compl;
312
Sathya Perla323ff712012-09-28 04:39:43 +0000313 if (adapter->phy.link_speed >= 0 &&
314 evt->physical_port == adapter->port_num)
315 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700316}
317
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000318/*Grp5 PVID evt*/
319static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530320 struct be_mcc_compl *compl)
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000321{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530322 struct be_async_event_grp5_pvid_state *evt =
323 (struct be_async_event_grp5_pvid_state *)compl;
324
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530325 if (evt->enabled) {
Somnath Kotur939cf302011-08-18 21:51:49 -0700326 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530327 dev_info(&adapter->pdev->dev, "LPVID: %d\n", adapter->pvid);
328 } else {
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000329 adapter->pvid = 0;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530330 }
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000331}
332
Somnath Koturcc4ce022010-10-21 07:11:14 -0700333static void be_async_grp5_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530334 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700335{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530336 u8 event_type = (compl->flags >> ASYNC_EVENT_TYPE_SHIFT) &
337 ASYNC_EVENT_TYPE_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700338
339 switch (event_type) {
340 case ASYNC_EVENT_COS_PRIORITY:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530341 be_async_grp5_cos_priority_process(adapter, compl);
342 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700343 case ASYNC_EVENT_QOS_SPEED:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530344 be_async_grp5_qos_speed_process(adapter, compl);
345 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000346 case ASYNC_EVENT_PVID_STATE:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530347 be_async_grp5_pvid_state_process(adapter, compl);
348 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700349 default:
Somnath Koturcc4ce022010-10-21 07:11:14 -0700350 break;
351 }
352}
353
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000354static void be_async_dbg_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530355 struct be_mcc_compl *cmp)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000356{
357 u8 event_type = 0;
Kalesh AP504fbf12014-09-19 15:47:00 +0530358 struct be_async_event_qnq *evt = (struct be_async_event_qnq *)cmp;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000359
Sathya Perla3acf19d2014-05-30 19:06:28 +0530360 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
361 ASYNC_EVENT_TYPE_MASK;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000362
363 switch (event_type) {
364 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
365 if (evt->valid)
366 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
367 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
368 break;
369 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530370 dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n",
371 event_type);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000372 break;
373 }
374}
375
Vasundhara Volam21252372015-02-06 08:18:42 -0500376static void be_async_sliport_evt_process(struct be_adapter *adapter,
377 struct be_mcc_compl *cmp)
378{
379 u8 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
380 ASYNC_EVENT_TYPE_MASK;
381
382 if (event_type == ASYNC_EVENT_PORT_MISCONFIG)
383 be_async_port_misconfig_event_process(adapter, cmp);
384}
385
Sathya Perla3acf19d2014-05-30 19:06:28 +0530386static inline bool is_link_state_evt(u32 flags)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000387{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530388 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
389 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000390}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000391
Sathya Perla3acf19d2014-05-30 19:06:28 +0530392static inline bool is_grp5_evt(u32 flags)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700393{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530394 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
395 ASYNC_EVENT_CODE_GRP_5;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700396}
397
Sathya Perla3acf19d2014-05-30 19:06:28 +0530398static inline bool is_dbg_evt(u32 flags)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000399{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530400 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
401 ASYNC_EVENT_CODE_QNQ;
402}
403
Vasundhara Volam21252372015-02-06 08:18:42 -0500404static inline bool is_sliport_evt(u32 flags)
405{
406 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
407 ASYNC_EVENT_CODE_SLIPORT;
408}
409
Sathya Perla3acf19d2014-05-30 19:06:28 +0530410static void be_mcc_event_process(struct be_adapter *adapter,
411 struct be_mcc_compl *compl)
412{
413 if (is_link_state_evt(compl->flags))
414 be_async_link_state_process(adapter, compl);
415 else if (is_grp5_evt(compl->flags))
416 be_async_grp5_evt_process(adapter, compl);
417 else if (is_dbg_evt(compl->flags))
418 be_async_dbg_evt_process(adapter, compl);
Vasundhara Volam21252372015-02-06 08:18:42 -0500419 else if (is_sliport_evt(compl->flags))
420 be_async_sliport_evt_process(adapter, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000421}
422
Sathya Perlaefd2e402009-07-27 22:53:10 +0000423static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000424{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000425 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000426 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000427
428 if (be_mcc_compl_is_new(compl)) {
429 queue_tail_inc(mcc_cq);
430 return compl;
431 }
432 return NULL;
433}
434
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000435void be_async_mcc_enable(struct be_adapter *adapter)
436{
437 spin_lock_bh(&adapter->mcc_cq_lock);
438
439 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
440 adapter->mcc_obj.rearm_cq = true;
441
442 spin_unlock_bh(&adapter->mcc_cq_lock);
443}
444
445void be_async_mcc_disable(struct be_adapter *adapter)
446{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000447 spin_lock_bh(&adapter->mcc_cq_lock);
448
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000449 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000450 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
451
452 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000453}
454
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000455int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000456{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000457 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000458 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000459 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000460
Amerigo Wang072a9c42012-08-24 21:41:11 +0000461 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla3acf19d2014-05-30 19:06:28 +0530462
Sathya Perla8788fdc2009-07-27 22:52:03 +0000463 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000464 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530465 be_mcc_event_process(adapter, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700466 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530467 status = be_mcc_compl_process(adapter, compl);
468 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000469 }
470 be_mcc_compl_use(compl);
471 num++;
472 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700473
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000474 if (num)
475 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
476
Amerigo Wang072a9c42012-08-24 21:41:11 +0000477 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000478 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000479}
480
Sathya Perla6ac7b682009-06-18 00:05:54 +0000481/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700482static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000483{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700484#define mcc_timeout 120000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000485 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800486 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700487
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800488 for (i = 0; i < mcc_timeout; i++) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000489 if (be_error(adapter))
490 return -EIO;
491
Amerigo Wang072a9c42012-08-24 21:41:11 +0000492 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000493 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000494 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800495
496 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000497 break;
498 udelay(100);
499 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700500 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000501 dev_err(&adapter->pdev->dev, "FW not responding\n");
502 adapter->fw_timeout = true;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000503 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700504 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800505 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000506}
507
508/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700509static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000510{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000511 int status;
512 struct be_mcc_wrb *wrb;
513 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
514 u16 index = mcc_obj->q.head;
515 struct be_cmd_resp_hdr *resp;
516
517 index_dec(&index, mcc_obj->q.len);
518 wrb = queue_index_node(&mcc_obj->q, index);
519
520 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
521
Sathya Perla8788fdc2009-07-27 22:52:03 +0000522 be_mcc_notify(adapter);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000523
524 status = be_mcc_wait_compl(adapter);
525 if (status == -EIO)
526 goto out;
527
Kalesh AP4c600052014-05-30 19:06:26 +0530528 status = (resp->base_status |
529 ((resp->addl_status & CQE_ADDL_STATUS_MASK) <<
530 CQE_ADDL_STATUS_SHIFT));
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000531out:
532 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000533}
534
Sathya Perla5f0b8492009-07-27 22:52:56 +0000535static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700536{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000537 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700538 u32 ready;
539
540 do {
Sathya Perla6589ade2011-11-10 19:18:00 +0000541 if (be_error(adapter))
542 return -EIO;
543
Sathya Perlacf588472010-02-14 21:22:01 +0000544 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000545 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000546 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000547
548 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700549 if (ready)
550 break;
551
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000552 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000553 dev_err(&adapter->pdev->dev, "FW not responding\n");
554 adapter->fw_timeout = true;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000555 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700556 return -1;
557 }
558
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000559 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000560 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700561 } while (true);
562
563 return 0;
564}
565
566/*
567 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000568 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700569 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700570static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700571{
572 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700573 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000574 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
575 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700576 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000577 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700578
Sathya Perlacf588472010-02-14 21:22:01 +0000579 /* wait for ready to be set */
580 status = be_mbox_db_ready_wait(adapter, db);
581 if (status != 0)
582 return status;
583
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700584 val |= MPU_MAILBOX_DB_HI_MASK;
585 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
586 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
587 iowrite32(val, db);
588
589 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000590 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700591 if (status != 0)
592 return status;
593
594 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700595 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
596 val |= (u32)(mbox_mem->dma >> 4) << 2;
597 iowrite32(val, db);
598
Sathya Perla5f0b8492009-07-27 22:52:56 +0000599 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700600 if (status != 0)
601 return status;
602
Sathya Perla5fb379e2009-06-18 00:02:59 +0000603 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000604 if (be_mcc_compl_is_new(compl)) {
605 status = be_mcc_compl_process(adapter, &mbox->compl);
606 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000607 if (status)
608 return status;
609 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000610 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700611 return -1;
612 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000613 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700614}
615
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000616static u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700617{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000618 u32 sem;
619
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000620 if (BEx_chip(adapter))
621 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700622 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000623 pci_read_config_dword(adapter->pdev,
624 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
625
626 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700627}
628
Gavin Shan87f20c22013-10-29 17:30:57 +0800629static int lancer_wait_ready(struct be_adapter *adapter)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000630{
631#define SLIPORT_READY_TIMEOUT 30
632 u32 sliport_status;
Kalesh APe6732442015-01-20 03:51:46 -0500633 int i;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000634
635 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
636 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
637 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
638 break;
639
640 msleep(1000);
641 }
642
643 if (i == SLIPORT_READY_TIMEOUT)
Kalesh APe6732442015-01-20 03:51:46 -0500644 return sliport_status ? : -1;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000645
Kalesh APe6732442015-01-20 03:51:46 -0500646 return 0;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000647}
648
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000649static bool lancer_provisioning_error(struct be_adapter *adapter)
650{
651 u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0;
Kalesh AP03d28ff2014-09-19 15:46:56 +0530652
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000653 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
654 if (sliport_status & SLIPORT_STATUS_ERR_MASK) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530655 sliport_err1 = ioread32(adapter->db + SLIPORT_ERROR1_OFFSET);
656 sliport_err2 = ioread32(adapter->db + SLIPORT_ERROR2_OFFSET);
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000657
658 if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 &&
659 sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2)
660 return true;
661 }
662 return false;
663}
664
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000665int lancer_test_and_set_rdy_state(struct be_adapter *adapter)
666{
667 int status;
668 u32 sliport_status, err, reset_needed;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000669 bool resource_error;
670
671 resource_error = lancer_provisioning_error(adapter);
672 if (resource_error)
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000673 return -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000674
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000675 status = lancer_wait_ready(adapter);
676 if (!status) {
677 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
678 err = sliport_status & SLIPORT_STATUS_ERR_MASK;
679 reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK;
680 if (err && reset_needed) {
681 iowrite32(SLI_PORT_CONTROL_IP_MASK,
682 adapter->db + SLIPORT_CONTROL_OFFSET);
683
Kalesh APe6732442015-01-20 03:51:46 -0500684 /* check if adapter has corrected the error */
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000685 status = lancer_wait_ready(adapter);
686 sliport_status = ioread32(adapter->db +
687 SLIPORT_STATUS_OFFSET);
688 sliport_status &= (SLIPORT_STATUS_ERR_MASK |
689 SLIPORT_STATUS_RN_MASK);
690 if (status || sliport_status)
691 status = -1;
692 } else if (err || reset_needed) {
693 status = -1;
694 }
695 }
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000696 /* Stop error recovery if error is not recoverable.
697 * No resource error is temporary errors and will go away
698 * when PF provisions resources.
699 */
700 resource_error = lancer_provisioning_error(adapter);
Somnath Kotur01e5b2c2013-05-29 22:56:17 +0000701 if (resource_error)
702 status = -EAGAIN;
Padmanabh Ratnakar67297ad2012-10-20 06:02:27 +0000703
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000704 return status;
705}
706
707int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700708{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000709 u16 stage;
710 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000711 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700712
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000713 if (lancer_chip(adapter)) {
714 status = lancer_wait_ready(adapter);
Kalesh APe6732442015-01-20 03:51:46 -0500715 if (status) {
716 stage = status;
717 goto err;
718 }
719 return 0;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000720 }
721
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000722 do {
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000723 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000724 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000725 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000726
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530727 dev_info(dev, "Waiting for POST, %ds elapsed\n", timeout);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000728 if (msleep_interruptible(2000)) {
729 dev_err(dev, "Waiting for POST aborted\n");
730 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000731 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000732 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000733 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700734
Kalesh APe6732442015-01-20 03:51:46 -0500735err:
736 dev_err(dev, "POST timeout; stage=%#x\n", stage);
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000737 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700738}
739
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700740static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
741{
742 return &wrb->payload.sgl[0];
743}
744
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530745static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, unsigned long addr)
Sathya Perlabea50982013-08-27 16:57:33 +0530746{
747 wrb->tag0 = addr & 0xFFFFFFFF;
748 wrb->tag1 = upper_32_bits(addr);
749}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700750
751/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000752/* mem will be NULL for embedded commands */
753static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530754 u8 subsystem, u8 opcode, int cmd_len,
755 struct be_mcc_wrb *wrb,
756 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700757{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000758 struct be_sge *sge;
759
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700760 req_hdr->opcode = opcode;
761 req_hdr->subsystem = subsystem;
762 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000763 req_hdr->version = 0;
Sathya Perlabea50982013-08-27 16:57:33 +0530764 fill_wrb_tags(wrb, (ulong) req_hdr);
Somnath Kotur106df1e2011-10-27 07:12:13 +0000765 wrb->payload_length = cmd_len;
766 if (mem) {
767 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
768 MCC_WRB_SGE_CNT_SHIFT;
769 sge = nonembedded_sgl(wrb);
770 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
771 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
772 sge->len = cpu_to_le32(mem->size);
773 } else
774 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
775 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700776}
777
778static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530779 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700780{
781 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
782 u64 dma = (u64)mem->dma;
783
784 for (i = 0; i < buf_pages; i++) {
785 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
786 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
787 dma += PAGE_SIZE_4K;
788 }
789}
790
Sathya Perlab31c50a2009-09-17 10:30:13 -0700791static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700792{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700793 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
794 struct be_mcc_wrb *wrb
795 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
796 memset(wrb, 0, sizeof(*wrb));
797 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700798}
799
Sathya Perlab31c50a2009-09-17 10:30:13 -0700800static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000801{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700802 struct be_queue_info *mccq = &adapter->mcc_obj.q;
803 struct be_mcc_wrb *wrb;
804
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000805 if (!mccq->created)
806 return NULL;
807
Vasundhara Volam4d277122013-04-21 23:28:15 +0000808 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000809 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000810
Sathya Perlab31c50a2009-09-17 10:30:13 -0700811 wrb = queue_head_node(mccq);
812 queue_head_inc(mccq);
813 atomic_inc(&mccq->used);
814 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000815 return wrb;
816}
817
Sathya Perlabea50982013-08-27 16:57:33 +0530818static bool use_mcc(struct be_adapter *adapter)
819{
820 return adapter->mcc_obj.q.created;
821}
822
823/* Must be used only in process context */
824static int be_cmd_lock(struct be_adapter *adapter)
825{
826 if (use_mcc(adapter)) {
827 spin_lock_bh(&adapter->mcc_lock);
828 return 0;
829 } else {
830 return mutex_lock_interruptible(&adapter->mbox_lock);
831 }
832}
833
834/* Must be used only in process context */
835static void be_cmd_unlock(struct be_adapter *adapter)
836{
837 if (use_mcc(adapter))
838 spin_unlock_bh(&adapter->mcc_lock);
839 else
840 return mutex_unlock(&adapter->mbox_lock);
841}
842
843static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter,
844 struct be_mcc_wrb *wrb)
845{
846 struct be_mcc_wrb *dest_wrb;
847
848 if (use_mcc(adapter)) {
849 dest_wrb = wrb_from_mccq(adapter);
850 if (!dest_wrb)
851 return NULL;
852 } else {
853 dest_wrb = wrb_from_mbox(adapter);
854 }
855
856 memcpy(dest_wrb, wrb, sizeof(*wrb));
857 if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK))
858 fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb));
859
860 return dest_wrb;
861}
862
863/* Must be used only in process context */
864static int be_cmd_notify_wait(struct be_adapter *adapter,
865 struct be_mcc_wrb *wrb)
866{
867 struct be_mcc_wrb *dest_wrb;
868 int status;
869
870 status = be_cmd_lock(adapter);
871 if (status)
872 return status;
873
874 dest_wrb = be_cmd_copy(adapter, wrb);
875 if (!dest_wrb)
876 return -EBUSY;
877
878 if (use_mcc(adapter))
879 status = be_mcc_notify_wait(adapter);
880 else
881 status = be_mbox_notify_wait(adapter);
882
883 if (!status)
884 memcpy(wrb, dest_wrb, sizeof(*wrb));
885
886 be_cmd_unlock(adapter);
887 return status;
888}
889
Sathya Perla2243e2e2009-11-22 22:02:03 +0000890/* Tell fw we're about to start firing cmds by writing a
891 * special pattern across the wrb hdr; uses mbox
892 */
893int be_cmd_fw_init(struct be_adapter *adapter)
894{
895 u8 *wrb;
896 int status;
897
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000898 if (lancer_chip(adapter))
899 return 0;
900
Ivan Vecera29849612010-12-14 05:43:19 +0000901 if (mutex_lock_interruptible(&adapter->mbox_lock))
902 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000903
904 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000905 *wrb++ = 0xFF;
906 *wrb++ = 0x12;
907 *wrb++ = 0x34;
908 *wrb++ = 0xFF;
909 *wrb++ = 0xFF;
910 *wrb++ = 0x56;
911 *wrb++ = 0x78;
912 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000913
914 status = be_mbox_notify_wait(adapter);
915
Ivan Vecera29849612010-12-14 05:43:19 +0000916 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000917 return status;
918}
919
920/* Tell fw we're done with firing cmds by writing a
921 * special pattern across the wrb hdr; uses mbox
922 */
923int be_cmd_fw_clean(struct be_adapter *adapter)
924{
925 u8 *wrb;
926 int status;
927
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000928 if (lancer_chip(adapter))
929 return 0;
930
Ivan Vecera29849612010-12-14 05:43:19 +0000931 if (mutex_lock_interruptible(&adapter->mbox_lock))
932 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000933
934 wrb = (u8 *)wrb_from_mbox(adapter);
935 *wrb++ = 0xFF;
936 *wrb++ = 0xAA;
937 *wrb++ = 0xBB;
938 *wrb++ = 0xFF;
939 *wrb++ = 0xFF;
940 *wrb++ = 0xCC;
941 *wrb++ = 0xDD;
942 *wrb = 0xFF;
943
944 status = be_mbox_notify_wait(adapter);
945
Ivan Vecera29849612010-12-14 05:43:19 +0000946 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000947 return status;
948}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000949
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530950int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700951{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700952 struct be_mcc_wrb *wrb;
953 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530954 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
955 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700956
Ivan Vecera29849612010-12-14 05:43:19 +0000957 if (mutex_lock_interruptible(&adapter->mbox_lock))
958 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700959
960 wrb = wrb_from_mbox(adapter);
961 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700962
Somnath Kotur106df1e2011-10-27 07:12:13 +0000963 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530964 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb,
965 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700966
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530967 /* Support for EQ_CREATEv2 available only SH-R onwards */
968 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
969 ver = 2;
970
971 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700972 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
973
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700974 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
975 /* 4byte eqe*/
976 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
977 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530978 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700979 be_dws_cpu_to_le(req->context, sizeof(req->context));
980
981 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
982
Sathya Perlab31c50a2009-09-17 10:30:13 -0700983 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700984 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -0700985 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +0530986
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530987 eqo->q.id = le16_to_cpu(resp->eq_id);
988 eqo->msix_idx =
989 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
990 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700991 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700992
Ivan Vecera29849612010-12-14 05:43:19 +0000993 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700994 return status;
995}
996
Sathya Perlaf9449ab2011-10-24 02:45:01 +0000997/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000998int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +0000999 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001000{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001001 struct be_mcc_wrb *wrb;
1002 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001003 int status;
1004
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001005 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001006
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001007 wrb = wrb_from_mccq(adapter);
1008 if (!wrb) {
1009 status = -EBUSY;
1010 goto err;
1011 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001012 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001013
Somnath Kotur106df1e2011-10-27 07:12:13 +00001014 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301015 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb,
1016 NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +00001017 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001018 if (permanent) {
1019 req->permanent = 1;
1020 } else {
Kalesh AP504fbf12014-09-19 15:47:00 +05301021 req->if_id = cpu_to_le16((u16)if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00001022 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001023 req->permanent = 0;
1024 }
1025
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001026 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001027 if (!status) {
1028 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301029
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001030 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001031 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001032
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001033err:
1034 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001035 return status;
1036}
1037
Sathya Perlab31c50a2009-09-17 10:30:13 -07001038/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001039int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301040 u32 if_id, u32 *pmac_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_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001044 int status;
1045
Sathya Perlab31c50a2009-09-17 10:30:13 -07001046 spin_lock_bh(&adapter->mcc_lock);
1047
1048 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001049 if (!wrb) {
1050 status = -EBUSY;
1051 goto err;
1052 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001053 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001054
Somnath Kotur106df1e2011-10-27 07:12:13 +00001055 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301056 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb,
1057 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001058
Ajit Khapardef8617e02011-02-11 13:36:37 +00001059 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001060 req->if_id = cpu_to_le32(if_id);
1061 memcpy(req->mac_address, mac_addr, ETH_ALEN);
1062
Sathya Perlab31c50a2009-09-17 10:30:13 -07001063 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001064 if (!status) {
1065 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301066
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001067 *pmac_id = le32_to_cpu(resp->pmac_id);
1068 }
1069
Sathya Perla713d03942009-11-22 22:02:45 +00001070err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001071 spin_unlock_bh(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +00001072
1073 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
1074 status = -EPERM;
1075
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001076 return status;
1077}
1078
Sathya Perlab31c50a2009-09-17 10:30:13 -07001079/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001080int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001081{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001082 struct be_mcc_wrb *wrb;
1083 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001084 int status;
1085
Sathya Perla30128032011-11-10 19:17:57 +00001086 if (pmac_id == -1)
1087 return 0;
1088
Sathya Perlab31c50a2009-09-17 10:30:13 -07001089 spin_lock_bh(&adapter->mcc_lock);
1090
1091 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001092 if (!wrb) {
1093 status = -EBUSY;
1094 goto err;
1095 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001096 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001097
Somnath Kotur106df1e2011-10-27 07:12:13 +00001098 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Kalesh APcd3307aa2014-09-19 15:47:02 +05301099 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req),
1100 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001101
Ajit Khapardef8617e02011-02-11 13:36:37 +00001102 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001103 req->if_id = cpu_to_le32(if_id);
1104 req->pmac_id = cpu_to_le32(pmac_id);
1105
Sathya Perlab31c50a2009-09-17 10:30:13 -07001106 status = be_mcc_notify_wait(adapter);
1107
Sathya Perla713d03942009-11-22 22:02:45 +00001108err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001109 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001110 return status;
1111}
1112
Sathya Perlab31c50a2009-09-17 10:30:13 -07001113/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001114int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301115 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
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_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001119 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001120 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001121 int status;
1122
Ivan Vecera29849612010-12-14 05:43:19 +00001123 if (mutex_lock_interruptible(&adapter->mbox_lock))
1124 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001125
1126 wrb = wrb_from_mbox(adapter);
1127 req = embedded_payload(wrb);
1128 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001129
Somnath Kotur106df1e2011-10-27 07:12:13 +00001130 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301131 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb,
1132 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001133
1134 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001135
1136 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001137 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301138 coalesce_wm);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001139 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301140 ctxt, no_delay);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001141 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301142 __ilog2_u32(cq->len / 256));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001143 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001144 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
1145 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001146 } else {
1147 req->hdr.version = 2;
1148 req->page_size = 1; /* 1 for 4K */
Ajit Khaparde09e83a92013-11-22 12:51:20 -06001149
1150 /* coalesce-wm field in this cmd is not relevant to Lancer.
1151 * Lancer uses COMMON_MODIFY_CQ to set this field
1152 */
1153 if (!lancer_chip(adapter))
1154 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1155 ctxt, coalesce_wm);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001156 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301157 no_delay);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001158 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301159 __ilog2_u32(cq->len / 256));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001160 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301161 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1162 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001163 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001164
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001165 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1166
1167 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1168
Sathya Perlab31c50a2009-09-17 10:30:13 -07001169 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001170 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001171 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301172
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001173 cq->id = le16_to_cpu(resp->cq_id);
1174 cq->created = true;
1175 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001176
Ivan Vecera29849612010-12-14 05:43:19 +00001177 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001178
1179 return status;
1180}
1181
1182static u32 be_encoded_q_len(int q_len)
1183{
1184 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
Kalesh AP03d28ff2014-09-19 15:46:56 +05301185
Sathya Perla5fb379e2009-06-18 00:02:59 +00001186 if (len_encoded == 16)
1187 len_encoded = 0;
1188 return len_encoded;
1189}
1190
Jingoo Han4188e7d2013-08-05 18:02:02 +09001191static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301192 struct be_queue_info *mccq,
1193 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001194{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001195 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001196 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001197 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001198 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001199 int status;
1200
Ivan Vecera29849612010-12-14 05:43:19 +00001201 if (mutex_lock_interruptible(&adapter->mbox_lock))
1202 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001203
1204 wrb = wrb_from_mbox(adapter);
1205 req = embedded_payload(wrb);
1206 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001207
Somnath Kotur106df1e2011-10-27 07:12:13 +00001208 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301209 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb,
1210 NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001211
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001212 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301213 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001214 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1215 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301216 be_encoded_q_len(mccq->len));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001217 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301218 } else {
1219 req->hdr.version = 1;
1220 req->cq_id = cpu_to_le16(cq->id);
1221
1222 AMAP_SET_BITS(struct amap_mcc_context_v1, ring_size, ctxt,
1223 be_encoded_q_len(mccq->len));
1224 AMAP_SET_BITS(struct amap_mcc_context_v1, valid, ctxt, 1);
1225 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_id,
1226 ctxt, cq->id);
1227 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_valid,
1228 ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001229 }
1230
Vasundhara Volam21252372015-02-06 08:18:42 -05001231 /* Subscribe to Link State, Sliport Event and Group 5 Events
1232 * (bits 1, 5 and 17 set)
1233 */
1234 req->async_event_bitmap[0] =
1235 cpu_to_le32(BIT(ASYNC_EVENT_CODE_LINK_STATE) |
1236 BIT(ASYNC_EVENT_CODE_GRP_5) |
1237 BIT(ASYNC_EVENT_CODE_QNQ) |
1238 BIT(ASYNC_EVENT_CODE_SLIPORT));
1239
Sathya Perla5fb379e2009-06-18 00:02:59 +00001240 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1241
1242 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1243
Sathya Perlab31c50a2009-09-17 10:30:13 -07001244 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001245 if (!status) {
1246 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301247
Sathya Perla5fb379e2009-06-18 00:02:59 +00001248 mccq->id = le16_to_cpu(resp->id);
1249 mccq->created = true;
1250 }
Ivan Vecera29849612010-12-14 05:43:19 +00001251 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001252
1253 return status;
1254}
1255
Jingoo Han4188e7d2013-08-05 18:02:02 +09001256static int be_cmd_mccq_org_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301257 struct be_queue_info *mccq,
1258 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001259{
1260 struct be_mcc_wrb *wrb;
1261 struct be_cmd_req_mcc_create *req;
1262 struct be_dma_mem *q_mem = &mccq->dma_mem;
1263 void *ctxt;
1264 int status;
1265
1266 if (mutex_lock_interruptible(&adapter->mbox_lock))
1267 return -1;
1268
1269 wrb = wrb_from_mbox(adapter);
1270 req = embedded_payload(wrb);
1271 ctxt = &req->context;
1272
Somnath Kotur106df1e2011-10-27 07:12:13 +00001273 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301274 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb,
1275 NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001276
1277 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1278
1279 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1280 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301281 be_encoded_q_len(mccq->len));
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001282 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1283
1284 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1285
1286 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1287
1288 status = be_mbox_notify_wait(adapter);
1289 if (!status) {
1290 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301291
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001292 mccq->id = le16_to_cpu(resp->id);
1293 mccq->created = true;
1294 }
1295
1296 mutex_unlock(&adapter->mbox_lock);
1297 return status;
1298}
1299
1300int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301301 struct be_queue_info *mccq, struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001302{
1303 int status;
1304
1305 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301306 if (status && BEx_chip(adapter)) {
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001307 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1308 "or newer to avoid conflicting priorities between NIC "
1309 "and FCoE traffic");
1310 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1311 }
1312 return status;
1313}
1314
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001315int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001316{
Sathya Perla77071332013-08-27 16:57:34 +05301317 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001318 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001319 struct be_queue_info *txq = &txo->q;
1320 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001321 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001322 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001323
Sathya Perla77071332013-08-27 16:57:34 +05301324 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001325 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301326 OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001327
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001328 if (lancer_chip(adapter)) {
1329 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001330 } else if (BEx_chip(adapter)) {
1331 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1332 req->hdr.version = 2;
1333 } else { /* For SH */
1334 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001335 }
1336
Vasundhara Volam81b02652013-10-01 15:59:57 +05301337 if (req->hdr.version > 0)
1338 req->if_id = cpu_to_le16(adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001339 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1340 req->ulp_num = BE_ULP1_NUM;
1341 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001342 req->cq_id = cpu_to_le16(cq->id);
1343 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001344 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001345 ver = req->hdr.version;
1346
Sathya Perla77071332013-08-27 16:57:34 +05301347 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001348 if (!status) {
Sathya Perla77071332013-08-27 16:57:34 +05301349 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301350
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001351 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001352 if (ver == 2)
1353 txo->db_offset = le32_to_cpu(resp->db_offset);
1354 else
1355 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001356 txq->created = true;
1357 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001358
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001359 return status;
1360}
1361
Sathya Perla482c9e72011-06-29 23:33:17 +00001362/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001363int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301364 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
1365 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001366{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001367 struct be_mcc_wrb *wrb;
1368 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369 struct be_dma_mem *q_mem = &rxq->dma_mem;
1370 int status;
1371
Sathya Perla482c9e72011-06-29 23:33:17 +00001372 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001373
Sathya Perla482c9e72011-06-29 23:33:17 +00001374 wrb = wrb_from_mccq(adapter);
1375 if (!wrb) {
1376 status = -EBUSY;
1377 goto err;
1378 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001379 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001380
Somnath Kotur106df1e2011-10-27 07:12:13 +00001381 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301382 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001383
1384 req->cq_id = cpu_to_le16(cq_id);
1385 req->frag_size = fls(frag_size) - 1;
1386 req->num_pages = 2;
1387 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1388 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001389 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001390 req->rss_queue = cpu_to_le32(rss);
1391
Sathya Perla482c9e72011-06-29 23:33:17 +00001392 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001393 if (!status) {
1394 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301395
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001396 rxq->id = le16_to_cpu(resp->id);
1397 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001398 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001399 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001400
Sathya Perla482c9e72011-06-29 23:33:17 +00001401err:
1402 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001403 return status;
1404}
1405
Sathya Perlab31c50a2009-09-17 10:30:13 -07001406/* Generic destroyer function for all types of queues
1407 * Uses Mbox
1408 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001409int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301410 int queue_type)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001411{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001412 struct be_mcc_wrb *wrb;
1413 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001414 u8 subsys = 0, opcode = 0;
1415 int status;
1416
Ivan Vecera29849612010-12-14 05:43:19 +00001417 if (mutex_lock_interruptible(&adapter->mbox_lock))
1418 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001419
Sathya Perlab31c50a2009-09-17 10:30:13 -07001420 wrb = wrb_from_mbox(adapter);
1421 req = embedded_payload(wrb);
1422
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001423 switch (queue_type) {
1424 case QTYPE_EQ:
1425 subsys = CMD_SUBSYSTEM_COMMON;
1426 opcode = OPCODE_COMMON_EQ_DESTROY;
1427 break;
1428 case QTYPE_CQ:
1429 subsys = CMD_SUBSYSTEM_COMMON;
1430 opcode = OPCODE_COMMON_CQ_DESTROY;
1431 break;
1432 case QTYPE_TXQ:
1433 subsys = CMD_SUBSYSTEM_ETH;
1434 opcode = OPCODE_ETH_TX_DESTROY;
1435 break;
1436 case QTYPE_RXQ:
1437 subsys = CMD_SUBSYSTEM_ETH;
1438 opcode = OPCODE_ETH_RX_DESTROY;
1439 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001440 case QTYPE_MCCQ:
1441 subsys = CMD_SUBSYSTEM_COMMON;
1442 opcode = OPCODE_COMMON_MCC_DESTROY;
1443 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001444 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001445 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001446 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001447
Somnath Kotur106df1e2011-10-27 07:12:13 +00001448 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301449 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001450 req->id = cpu_to_le16(q->id);
1451
Sathya Perlab31c50a2009-09-17 10:30:13 -07001452 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001453 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001454
Ivan Vecera29849612010-12-14 05:43:19 +00001455 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001456 return status;
1457}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001458
Sathya Perla482c9e72011-06-29 23:33:17 +00001459/* Uses MCC */
1460int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1461{
1462 struct be_mcc_wrb *wrb;
1463 struct be_cmd_req_q_destroy *req;
1464 int status;
1465
1466 spin_lock_bh(&adapter->mcc_lock);
1467
1468 wrb = wrb_from_mccq(adapter);
1469 if (!wrb) {
1470 status = -EBUSY;
1471 goto err;
1472 }
1473 req = embedded_payload(wrb);
1474
Somnath Kotur106df1e2011-10-27 07:12:13 +00001475 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301476 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001477 req->id = cpu_to_le16(q->id);
1478
1479 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001480 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001481
1482err:
1483 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001484 return status;
1485}
1486
Sathya Perlab31c50a2009-09-17 10:30:13 -07001487/* Create an rx filtering policy configuration on an i/f
Sathya Perlabea50982013-08-27 16:57:33 +05301488 * Will use MBOX only if MCCQ has not been created.
Sathya Perlab31c50a2009-09-17 10:30:13 -07001489 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001490int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001491 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001492{
Sathya Perlabea50982013-08-27 16:57:33 +05301493 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001494 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001495 int status;
1496
Sathya Perlabea50982013-08-27 16:57:33 +05301497 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001498 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301499 OPCODE_COMMON_NTWK_INTERFACE_CREATE,
1500 sizeof(*req), &wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001501 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001502 req->capability_flags = cpu_to_le32(cap_flags);
1503 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001504 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001505
Sathya Perlabea50982013-08-27 16:57:33 +05301506 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001507 if (!status) {
Sathya Perlabea50982013-08-27 16:57:33 +05301508 struct be_cmd_resp_if_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301509
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001510 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301511
1512 /* Hack to retrieve VF's pmac-id on BE3 */
1513 if (BE3_chip(adapter) && !be_physfn(adapter))
1514 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001515 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001516 return status;
1517}
1518
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001519/* Uses MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001520int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001521{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001522 struct be_mcc_wrb *wrb;
1523 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001524 int status;
1525
Sathya Perla30128032011-11-10 19:17:57 +00001526 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001527 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001528
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001529 spin_lock_bh(&adapter->mcc_lock);
1530
1531 wrb = wrb_from_mccq(adapter);
1532 if (!wrb) {
1533 status = -EBUSY;
1534 goto err;
1535 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001536 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001537
Somnath Kotur106df1e2011-10-27 07:12:13 +00001538 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301539 OPCODE_COMMON_NTWK_INTERFACE_DESTROY,
1540 sizeof(*req), wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001541 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001542 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001543
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001544 status = be_mcc_notify_wait(adapter);
1545err:
1546 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001547 return status;
1548}
1549
1550/* Get stats is a non embedded command: the request is not embedded inside
1551 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001552 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001553 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001554int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001555{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001556 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001557 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001558 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001559
Sathya Perlab31c50a2009-09-17 10:30:13 -07001560 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001561
Sathya Perlab31c50a2009-09-17 10:30:13 -07001562 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001563 if (!wrb) {
1564 status = -EBUSY;
1565 goto err;
1566 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001567 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001568
Somnath Kotur106df1e2011-10-27 07:12:13 +00001569 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301570 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb,
1571 nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001572
Sathya Perlaca34fe32012-11-06 17:48:56 +00001573 /* version 1 of the cmd is not supported only by BE2 */
Ajit Khaparde61000862013-10-03 16:16:33 -05001574 if (BE2_chip(adapter))
1575 hdr->version = 0;
1576 if (BE3_chip(adapter) || lancer_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001577 hdr->version = 1;
Ajit Khaparde61000862013-10-03 16:16:33 -05001578 else
1579 hdr->version = 2;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001580
Sathya Perlab31c50a2009-09-17 10:30:13 -07001581 be_mcc_notify(adapter);
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001582 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001583
Sathya Perla713d03942009-11-22 22:02:45 +00001584err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001585 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001586 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001587}
1588
Selvin Xavier005d5692011-05-16 07:36:35 +00001589/* Lancer Stats */
1590int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301591 struct be_dma_mem *nonemb_cmd)
Selvin Xavier005d5692011-05-16 07:36:35 +00001592{
Selvin Xavier005d5692011-05-16 07:36:35 +00001593 struct be_mcc_wrb *wrb;
1594 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001595 int status = 0;
1596
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001597 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1598 CMD_SUBSYSTEM_ETH))
1599 return -EPERM;
1600
Selvin Xavier005d5692011-05-16 07:36:35 +00001601 spin_lock_bh(&adapter->mcc_lock);
1602
1603 wrb = wrb_from_mccq(adapter);
1604 if (!wrb) {
1605 status = -EBUSY;
1606 goto err;
1607 }
1608 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001609
Somnath Kotur106df1e2011-10-27 07:12:13 +00001610 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301611 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size,
1612 wrb, nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001613
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001614 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001615 req->cmd_params.params.reset_stats = 0;
1616
Selvin Xavier005d5692011-05-16 07:36:35 +00001617 be_mcc_notify(adapter);
1618 adapter->stats_cmd_sent = true;
1619
1620err:
1621 spin_unlock_bh(&adapter->mcc_lock);
1622 return status;
1623}
1624
Sathya Perla323ff712012-09-28 04:39:43 +00001625static int be_mac_to_link_speed(int mac_speed)
1626{
1627 switch (mac_speed) {
1628 case PHY_LINK_SPEED_ZERO:
1629 return 0;
1630 case PHY_LINK_SPEED_10MBPS:
1631 return 10;
1632 case PHY_LINK_SPEED_100MBPS:
1633 return 100;
1634 case PHY_LINK_SPEED_1GBPS:
1635 return 1000;
1636 case PHY_LINK_SPEED_10GBPS:
1637 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301638 case PHY_LINK_SPEED_20GBPS:
1639 return 20000;
1640 case PHY_LINK_SPEED_25GBPS:
1641 return 25000;
1642 case PHY_LINK_SPEED_40GBPS:
1643 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001644 }
1645 return 0;
1646}
1647
1648/* Uses synchronous mcc
1649 * Returns link_speed in Mbps
1650 */
1651int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1652 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001653{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001654 struct be_mcc_wrb *wrb;
1655 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001656 int status;
1657
Sathya Perlab31c50a2009-09-17 10:30:13 -07001658 spin_lock_bh(&adapter->mcc_lock);
1659
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001660 if (link_status)
1661 *link_status = LINK_DOWN;
1662
Sathya Perlab31c50a2009-09-17 10:30:13 -07001663 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001664 if (!wrb) {
1665 status = -EBUSY;
1666 goto err;
1667 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001668 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001669
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001670 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301671 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1672 sizeof(*req), wrb, NULL);
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001673
Sathya Perlaca34fe32012-11-06 17:48:56 +00001674 /* version 1 of the cmd is not supported only by BE2 */
1675 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001676 req->hdr.version = 1;
1677
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001678 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001679
Sathya Perlab31c50a2009-09-17 10:30:13 -07001680 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001681 if (!status) {
1682 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301683
Sathya Perla323ff712012-09-28 04:39:43 +00001684 if (link_speed) {
1685 *link_speed = resp->link_speed ?
1686 le16_to_cpu(resp->link_speed) * 10 :
1687 be_mac_to_link_speed(resp->mac_speed);
1688
1689 if (!resp->logical_link_status)
1690 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001691 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001692 if (link_status)
1693 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001694 }
1695
Sathya Perla713d03942009-11-22 22:02:45 +00001696err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001697 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001698 return status;
1699}
1700
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001701/* Uses synchronous mcc */
1702int be_cmd_get_die_temperature(struct be_adapter *adapter)
1703{
1704 struct be_mcc_wrb *wrb;
1705 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301706 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001707
1708 spin_lock_bh(&adapter->mcc_lock);
1709
1710 wrb = wrb_from_mccq(adapter);
1711 if (!wrb) {
1712 status = -EBUSY;
1713 goto err;
1714 }
1715 req = embedded_payload(wrb);
1716
Somnath Kotur106df1e2011-10-27 07:12:13 +00001717 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301718 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES,
1719 sizeof(*req), wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001720
Somnath Kotur3de09452011-09-30 07:25:05 +00001721 be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001722
1723err:
1724 spin_unlock_bh(&adapter->mcc_lock);
1725 return status;
1726}
1727
Somnath Kotur311fddc2011-03-16 21:22:43 +00001728/* Uses synchronous mcc */
1729int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size)
1730{
1731 struct be_mcc_wrb *wrb;
1732 struct be_cmd_req_get_fat *req;
1733 int status;
1734
1735 spin_lock_bh(&adapter->mcc_lock);
1736
1737 wrb = wrb_from_mccq(adapter);
1738 if (!wrb) {
1739 status = -EBUSY;
1740 goto err;
1741 }
1742 req = embedded_payload(wrb);
1743
Somnath Kotur106df1e2011-10-27 07:12:13 +00001744 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301745 OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb,
1746 NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001747 req->fat_operation = cpu_to_le32(QUERY_FAT);
1748 status = be_mcc_notify_wait(adapter);
1749 if (!status) {
1750 struct be_cmd_resp_get_fat *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301751
Somnath Kotur311fddc2011-03-16 21:22:43 +00001752 if (log_size && resp->log_size)
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001753 *log_size = le32_to_cpu(resp->log_size) -
1754 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001755 }
1756err:
1757 spin_unlock_bh(&adapter->mcc_lock);
1758 return status;
1759}
1760
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301761int be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf)
Somnath Kotur311fddc2011-03-16 21:22:43 +00001762{
1763 struct be_dma_mem get_fat_cmd;
1764 struct be_mcc_wrb *wrb;
1765 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001766 u32 offset = 0, total_size, buf_size,
1767 log_offset = sizeof(u32), payload_len;
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301768 int status = 0;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001769
1770 if (buf_len == 0)
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301771 return -EIO;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001772
1773 total_size = buf_len;
1774
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001775 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
1776 get_fat_cmd.va = pci_alloc_consistent(adapter->pdev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301777 get_fat_cmd.size,
1778 &get_fat_cmd.dma);
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001779 if (!get_fat_cmd.va) {
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001780 dev_err(&adapter->pdev->dev,
Kalesh APcd3307aa2014-09-19 15:47:02 +05301781 "Memory allocation failure while reading FAT data\n");
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301782 return -ENOMEM;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001783 }
1784
Somnath Kotur311fddc2011-03-16 21:22:43 +00001785 spin_lock_bh(&adapter->mcc_lock);
1786
Somnath Kotur311fddc2011-03-16 21:22:43 +00001787 while (total_size) {
1788 buf_size = min(total_size, (u32)60*1024);
1789 total_size -= buf_size;
1790
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001791 wrb = wrb_from_mccq(adapter);
1792 if (!wrb) {
1793 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001794 goto err;
1795 }
1796 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001797
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001798 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001799 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301800 OPCODE_COMMON_MANAGE_FAT, payload_len,
1801 wrb, &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001802
1803 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1804 req->read_log_offset = cpu_to_le32(log_offset);
1805 req->read_log_length = cpu_to_le32(buf_size);
1806 req->data_buffer_size = cpu_to_le32(buf_size);
1807
1808 status = be_mcc_notify_wait(adapter);
1809 if (!status) {
1810 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
Kalesh AP03d28ff2014-09-19 15:46:56 +05301811
Somnath Kotur311fddc2011-03-16 21:22:43 +00001812 memcpy(buf + offset,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301813 resp->data_buffer,
1814 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001815 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001816 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001817 goto err;
1818 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001819 offset += buf_size;
1820 log_offset += buf_size;
1821 }
1822err:
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001823 pci_free_consistent(adapter->pdev, get_fat_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301824 get_fat_cmd.va, get_fat_cmd.dma);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001825 spin_unlock_bh(&adapter->mcc_lock);
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301826 return status;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001827}
1828
Sathya Perla04b71172011-09-27 13:30:27 -04001829/* Uses synchronous mcc */
Kalesh APe97e3cd2014-07-17 16:20:26 +05301830int be_cmd_get_fw_ver(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001831{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001832 struct be_mcc_wrb *wrb;
1833 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001834 int status;
1835
Sathya Perla04b71172011-09-27 13:30:27 -04001836 spin_lock_bh(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001837
Sathya Perla04b71172011-09-27 13:30:27 -04001838 wrb = wrb_from_mccq(adapter);
1839 if (!wrb) {
1840 status = -EBUSY;
1841 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001842 }
1843
Sathya Perla04b71172011-09-27 13:30:27 -04001844 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001845
Somnath Kotur106df1e2011-10-27 07:12:13 +00001846 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301847 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb,
1848 NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001849 status = be_mcc_notify_wait(adapter);
1850 if (!status) {
1851 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
Sathya Perlaacbafeb2014-09-02 09:56:46 +05301852
Vasundhara Volam242eb472014-09-12 17:39:15 +05301853 strlcpy(adapter->fw_ver, resp->firmware_version_string,
1854 sizeof(adapter->fw_ver));
1855 strlcpy(adapter->fw_on_flash, resp->fw_on_flash_version_string,
1856 sizeof(adapter->fw_on_flash));
Sathya Perla04b71172011-09-27 13:30:27 -04001857 }
1858err:
1859 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001860 return status;
1861}
1862
Sathya Perlab31c50a2009-09-17 10:30:13 -07001863/* set the EQ delay interval of an EQ to specified value
1864 * Uses async mcc
1865 */
Kalesh APb502ae82014-09-19 15:46:51 +05301866static int __be_cmd_modify_eqd(struct be_adapter *adapter,
1867 struct be_set_eqd *set_eqd, int num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001868{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001869 struct be_mcc_wrb *wrb;
1870 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla2632baf2013-10-01 16:00:00 +05301871 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001872
Sathya Perlab31c50a2009-09-17 10:30:13 -07001873 spin_lock_bh(&adapter->mcc_lock);
1874
1875 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001876 if (!wrb) {
1877 status = -EBUSY;
1878 goto err;
1879 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001880 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001881
Somnath Kotur106df1e2011-10-27 07:12:13 +00001882 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301883 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb,
1884 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001885
Sathya Perla2632baf2013-10-01 16:00:00 +05301886 req->num_eq = cpu_to_le32(num);
1887 for (i = 0; i < num; i++) {
1888 req->set_eqd[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
1889 req->set_eqd[i].phase = 0;
1890 req->set_eqd[i].delay_multiplier =
1891 cpu_to_le32(set_eqd[i].delay_multiplier);
1892 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001893
Sathya Perlab31c50a2009-09-17 10:30:13 -07001894 be_mcc_notify(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001895err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001896 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001897 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001898}
1899
Kalesh AP93676702014-09-12 17:39:20 +05301900int be_cmd_modify_eqd(struct be_adapter *adapter, struct be_set_eqd *set_eqd,
1901 int num)
1902{
1903 int num_eqs, i = 0;
1904
Suresh Reddyc8ba4ad02015-03-20 06:28:24 -04001905 while (num) {
1906 num_eqs = min(num, 8);
1907 __be_cmd_modify_eqd(adapter, &set_eqd[i], num_eqs);
1908 i += num_eqs;
1909 num -= num_eqs;
Kalesh AP93676702014-09-12 17:39:20 +05301910 }
1911
1912 return 0;
1913}
1914
Sathya Perlab31c50a2009-09-17 10:30:13 -07001915/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001916int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Vasundhara Volam435452a2015-03-20 06:28:23 -04001917 u32 num, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001918{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001919 struct be_mcc_wrb *wrb;
1920 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001921 int status;
1922
Sathya Perlab31c50a2009-09-17 10:30:13 -07001923 spin_lock_bh(&adapter->mcc_lock);
1924
1925 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001926 if (!wrb) {
1927 status = -EBUSY;
1928 goto err;
1929 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001930 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001931
Somnath Kotur106df1e2011-10-27 07:12:13 +00001932 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301933 OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req),
1934 wrb, NULL);
Vasundhara Volam435452a2015-03-20 06:28:23 -04001935 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001936
1937 req->interface_id = if_id;
Ajit Khaparde012bd382013-11-18 10:44:24 -06001938 req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001939 req->num_vlan = num;
Kalesh AP4d567d92014-05-09 13:29:17 +05301940 memcpy(req->normal_vlan, vtag_array,
1941 req->num_vlan * sizeof(vtag_array[0]));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001942
Sathya Perlab31c50a2009-09-17 10:30:13 -07001943 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001944err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07001945 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001946 return status;
1947}
1948
Sathya Perlaac34b742015-02-06 08:18:40 -05001949static int __be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001950{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001951 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001952 struct be_dma_mem *mem = &adapter->rx_filter;
1953 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001954 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001955
Sathya Perla8788fdc2009-07-27 22:52:03 +00001956 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001957
Sathya Perlab31c50a2009-09-17 10:30:13 -07001958 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001959 if (!wrb) {
1960 status = -EBUSY;
1961 goto err;
1962 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001963 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001964 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301965 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1966 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001967
Sathya Perla5b8821b2011-08-02 19:57:44 +00001968 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perlaac34b742015-02-06 08:18:40 -05001969 req->if_flags_mask = cpu_to_le32(flags);
1970 req->if_flags = (value == ON) ? req->if_flags_mask : 0;
Ajit Khaparded9d604f2013-09-27 15:17:58 -05001971
Sathya Perlaac34b742015-02-06 08:18:40 -05001972 if (flags & BE_IF_FLAGS_MULTICAST) {
Sathya Perla5b8821b2011-08-02 19:57:44 +00001973 struct netdev_hw_addr *ha;
1974 int i = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001975
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00001976 /* Reset mcast promisc mode if already set by setting mask
1977 * and not setting flags field
1978 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00001979 req->if_flags_mask |=
1980 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05301981 be_if_cap_flags(adapter));
Padmanabh Ratnakar016f97b2011-11-03 01:49:13 +00001982 req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev));
Sathya Perla5b8821b2011-08-02 19:57:44 +00001983 netdev_for_each_mc_addr(ha, adapter->netdev)
1984 memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN);
1985 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001986
Sathya Perla0d1d5872011-08-03 05:19:27 -07001987 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001988err:
Sathya Perla8788fdc2009-07-27 22:52:03 +00001989 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00001990 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001991}
1992
Sathya Perlaac34b742015-02-06 08:18:40 -05001993int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
1994{
1995 struct device *dev = &adapter->pdev->dev;
1996
1997 if ((flags & be_if_cap_flags(adapter)) != flags) {
1998 dev_warn(dev, "Cannot set rx filter flags 0x%x\n", flags);
1999 dev_warn(dev, "Interface is capable of 0x%x flags only\n",
2000 be_if_cap_flags(adapter));
2001 }
2002 flags &= be_if_cap_flags(adapter);
2003
2004 return __be_cmd_rx_filter(adapter, flags, value);
2005}
2006
Sathya Perlab31c50a2009-09-17 10:30:13 -07002007/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002008int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002009{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002010 struct be_mcc_wrb *wrb;
2011 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002012 int status;
2013
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002014 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
2015 CMD_SUBSYSTEM_COMMON))
2016 return -EPERM;
2017
Sathya Perlab31c50a2009-09-17 10:30:13 -07002018 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002019
Sathya Perlab31c50a2009-09-17 10:30:13 -07002020 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002021 if (!wrb) {
2022 status = -EBUSY;
2023 goto err;
2024 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002025 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002026
Somnath Kotur106df1e2011-10-27 07:12:13 +00002027 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302028 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req),
2029 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002030
Suresh Reddyb29812c2014-09-12 17:39:17 +05302031 req->hdr.version = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002032 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
2033 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
2034
Sathya Perlab31c50a2009-09-17 10:30:13 -07002035 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002036
Sathya Perla713d03942009-11-22 22:02:45 +00002037err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07002038 spin_unlock_bh(&adapter->mcc_lock);
Suresh Reddyb29812c2014-09-12 17:39:17 +05302039
2040 if (base_status(status) == MCC_STATUS_FEATURE_NOT_SUPPORTED)
2041 return -EOPNOTSUPP;
2042
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002043 return status;
2044}
2045
Sathya Perlab31c50a2009-09-17 10:30:13 -07002046/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002047int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002048{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002049 struct be_mcc_wrb *wrb;
2050 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002051 int status;
2052
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002053 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
2054 CMD_SUBSYSTEM_COMMON))
2055 return -EPERM;
2056
Sathya Perlab31c50a2009-09-17 10:30:13 -07002057 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002058
Sathya Perlab31c50a2009-09-17 10:30:13 -07002059 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002060 if (!wrb) {
2061 status = -EBUSY;
2062 goto err;
2063 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002064 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002065
Somnath Kotur106df1e2011-10-27 07:12:13 +00002066 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302067 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req),
2068 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002069
Sathya Perlab31c50a2009-09-17 10:30:13 -07002070 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002071 if (!status) {
2072 struct be_cmd_resp_get_flow_control *resp =
2073 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302074
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002075 *tx_fc = le16_to_cpu(resp->tx_flow_control);
2076 *rx_fc = le16_to_cpu(resp->rx_flow_control);
2077 }
2078
Sathya Perla713d03942009-11-22 22:02:45 +00002079err:
Sathya Perlab31c50a2009-09-17 10:30:13 -07002080 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002081 return status;
2082}
2083
Sathya Perlab31c50a2009-09-17 10:30:13 -07002084/* Uses mbox */
Kalesh APe97e3cd2014-07-17 16:20:26 +05302085int be_cmd_query_fw_cfg(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002086{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002087 struct be_mcc_wrb *wrb;
2088 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002089 int status;
2090
Ivan Vecera29849612010-12-14 05:43:19 +00002091 if (mutex_lock_interruptible(&adapter->mbox_lock))
2092 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002093
Sathya Perlab31c50a2009-09-17 10:30:13 -07002094 wrb = wrb_from_mbox(adapter);
2095 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002096
Somnath Kotur106df1e2011-10-27 07:12:13 +00002097 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302098 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
2099 sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002100
Sathya Perlab31c50a2009-09-17 10:30:13 -07002101 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002102 if (!status) {
2103 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302104
Kalesh APe97e3cd2014-07-17 16:20:26 +05302105 adapter->port_num = le32_to_cpu(resp->phys_port);
2106 adapter->function_mode = le32_to_cpu(resp->function_mode);
2107 adapter->function_caps = le32_to_cpu(resp->function_caps);
2108 adapter->asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perlaacbafeb2014-09-02 09:56:46 +05302109 dev_info(&adapter->pdev->dev,
2110 "FW config: function_mode=0x%x, function_caps=0x%x\n",
2111 adapter->function_mode, adapter->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002112 }
2113
Ivan Vecera29849612010-12-14 05:43:19 +00002114 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002115 return status;
2116}
sarveshwarb14074ea2009-08-05 13:05:24 -07002117
Sathya Perlab31c50a2009-09-17 10:30:13 -07002118/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07002119int be_cmd_reset_function(struct be_adapter *adapter)
2120{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002121 struct be_mcc_wrb *wrb;
2122 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07002123 int status;
2124
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002125 if (lancer_chip(adapter)) {
2126 status = lancer_wait_ready(adapter);
2127 if (!status) {
2128 iowrite32(SLI_PORT_CONTROL_IP_MASK,
2129 adapter->db + SLIPORT_CONTROL_OFFSET);
2130 status = lancer_test_and_set_rdy_state(adapter);
2131 }
2132 if (status) {
2133 dev_err(&adapter->pdev->dev,
2134 "Adapter in non recoverable error\n");
2135 }
2136 return status;
2137 }
2138
Ivan Vecera29849612010-12-14 05:43:19 +00002139 if (mutex_lock_interruptible(&adapter->mbox_lock))
2140 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07002141
Sathya Perlab31c50a2009-09-17 10:30:13 -07002142 wrb = wrb_from_mbox(adapter);
2143 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07002144
Somnath Kotur106df1e2011-10-27 07:12:13 +00002145 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302146 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb,
2147 NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07002148
Sathya Perlab31c50a2009-09-17 10:30:13 -07002149 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07002150
Ivan Vecera29849612010-12-14 05:43:19 +00002151 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07002152 return status;
2153}
Ajit Khaparde84517482009-09-04 03:12:16 +00002154
Suresh Reddy594ad542013-04-25 23:03:20 +00002155int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01002156 u32 rss_hash_opts, u16 table_size, const u8 *rss_hkey)
Sathya Perla3abcded2010-10-03 22:12:27 -07002157{
2158 struct be_mcc_wrb *wrb;
2159 struct be_cmd_req_rss_config *req;
Sathya Perla3abcded2010-10-03 22:12:27 -07002160 int status;
2161
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302162 if (!(be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS))
2163 return 0;
2164
Kalesh APb51aa362014-05-09 13:29:19 +05302165 spin_lock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002166
Kalesh APb51aa362014-05-09 13:29:19 +05302167 wrb = wrb_from_mccq(adapter);
2168 if (!wrb) {
2169 status = -EBUSY;
2170 goto err;
2171 }
Sathya Perla3abcded2010-10-03 22:12:27 -07002172 req = embedded_payload(wrb);
2173
Somnath Kotur106df1e2011-10-27 07:12:13 +00002174 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302175 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07002176
2177 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00002178 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07002179 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00002180
Kalesh APb51aa362014-05-09 13:29:19 +05302181 if (!BEx_chip(adapter))
Suresh Reddy594ad542013-04-25 23:03:20 +00002182 req->hdr.version = 1;
2183
Sathya Perla3abcded2010-10-03 22:12:27 -07002184 memcpy(req->cpu_table, rsstable, table_size);
Venkata Duvvurue2557872014-04-21 15:38:00 +05302185 memcpy(req->hash, rss_hkey, RSS_HASH_KEY_LEN);
Sathya Perla3abcded2010-10-03 22:12:27 -07002186 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
2187
Kalesh APb51aa362014-05-09 13:29:19 +05302188 status = be_mcc_notify_wait(adapter);
2189err:
2190 spin_unlock_bh(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002191 return status;
2192}
2193
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002194/* Uses sync mcc */
2195int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302196 u8 bcn, u8 sts, u8 state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002197{
2198 struct be_mcc_wrb *wrb;
2199 struct be_cmd_req_enable_disable_beacon *req;
2200 int status;
2201
2202 spin_lock_bh(&adapter->mcc_lock);
2203
2204 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002205 if (!wrb) {
2206 status = -EBUSY;
2207 goto err;
2208 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002209 req = embedded_payload(wrb);
2210
Somnath Kotur106df1e2011-10-27 07:12:13 +00002211 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302212 OPCODE_COMMON_ENABLE_DISABLE_BEACON,
2213 sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002214
2215 req->port_num = port_num;
2216 req->beacon_state = state;
2217 req->beacon_duration = bcn;
2218 req->status_duration = sts;
2219
2220 status = be_mcc_notify_wait(adapter);
2221
Sathya Perla713d03942009-11-22 22:02:45 +00002222err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002223 spin_unlock_bh(&adapter->mcc_lock);
2224 return status;
2225}
2226
2227/* Uses sync mcc */
2228int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2229{
2230 struct be_mcc_wrb *wrb;
2231 struct be_cmd_req_get_beacon_state *req;
2232 int status;
2233
2234 spin_lock_bh(&adapter->mcc_lock);
2235
2236 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002237 if (!wrb) {
2238 status = -EBUSY;
2239 goto err;
2240 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002241 req = embedded_payload(wrb);
2242
Somnath Kotur106df1e2011-10-27 07:12:13 +00002243 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302244 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req),
2245 wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002246
2247 req->port_num = port_num;
2248
2249 status = be_mcc_notify_wait(adapter);
2250 if (!status) {
2251 struct be_cmd_resp_get_beacon_state *resp =
2252 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302253
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002254 *state = resp->beacon_state;
2255 }
2256
Sathya Perla713d03942009-11-22 22:02:45 +00002257err:
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002258 spin_unlock_bh(&adapter->mcc_lock);
2259 return status;
2260}
2261
Mark Leonarde36edd92014-09-12 17:39:18 +05302262/* Uses sync mcc */
2263int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2264 u8 page_num, u8 *data)
2265{
2266 struct be_dma_mem cmd;
2267 struct be_mcc_wrb *wrb;
2268 struct be_cmd_req_port_type *req;
2269 int status;
2270
2271 if (page_num > TR_PAGE_A2)
2272 return -EINVAL;
2273
2274 cmd.size = sizeof(struct be_cmd_resp_port_type);
2275 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
2276 if (!cmd.va) {
2277 dev_err(&adapter->pdev->dev, "Memory allocation failed\n");
2278 return -ENOMEM;
2279 }
2280 memset(cmd.va, 0, cmd.size);
2281
2282 spin_lock_bh(&adapter->mcc_lock);
2283
2284 wrb = wrb_from_mccq(adapter);
2285 if (!wrb) {
2286 status = -EBUSY;
2287 goto err;
2288 }
2289 req = cmd.va;
2290
2291 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2292 OPCODE_COMMON_READ_TRANSRECV_DATA,
2293 cmd.size, wrb, &cmd);
2294
2295 req->port = cpu_to_le32(adapter->hba_port_num);
2296 req->page_num = cpu_to_le32(page_num);
2297 status = be_mcc_notify_wait(adapter);
2298 if (!status) {
2299 struct be_cmd_resp_port_type *resp = cmd.va;
2300
2301 memcpy(data, resp->page_data, PAGE_DATA_LEN);
2302 }
2303err:
2304 spin_unlock_bh(&adapter->mcc_lock);
2305 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
2306 return status;
2307}
2308
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002309int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002310 u32 data_size, u32 data_offset,
2311 const char *obj_name, u32 *data_written,
2312 u8 *change_status, u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002313{
2314 struct be_mcc_wrb *wrb;
2315 struct lancer_cmd_req_write_object *req;
2316 struct lancer_cmd_resp_write_object *resp;
2317 void *ctxt = NULL;
2318 int status;
2319
2320 spin_lock_bh(&adapter->mcc_lock);
2321 adapter->flash_status = 0;
2322
2323 wrb = wrb_from_mccq(adapter);
2324 if (!wrb) {
2325 status = -EBUSY;
2326 goto err_unlock;
2327 }
2328
2329 req = embedded_payload(wrb);
2330
Somnath Kotur106df1e2011-10-27 07:12:13 +00002331 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302332 OPCODE_COMMON_WRITE_OBJECT,
2333 sizeof(struct lancer_cmd_req_write_object), wrb,
2334 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002335
2336 ctxt = &req->context;
2337 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302338 write_length, ctxt, data_size);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002339
2340 if (data_size == 0)
2341 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302342 eof, ctxt, 1);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002343 else
2344 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302345 eof, ctxt, 0);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002346
2347 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2348 req->write_offset = cpu_to_le32(data_offset);
Vasundhara Volam242eb472014-09-12 17:39:15 +05302349 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002350 req->descriptor_count = cpu_to_le32(1);
2351 req->buf_len = cpu_to_le32(data_size);
2352 req->addr_low = cpu_to_le32((cmd->dma +
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302353 sizeof(struct lancer_cmd_req_write_object))
2354 & 0xFFFFFFFF);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002355 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2356 sizeof(struct lancer_cmd_req_write_object)));
2357
2358 be_mcc_notify(adapter);
2359 spin_unlock_bh(&adapter->mcc_lock);
2360
Suresh Reddy5eeff632014-01-06 13:02:24 +05302361 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002362 msecs_to_jiffies(60000)))
Kalesh APfd451602014-07-17 16:20:21 +05302363 status = -ETIMEDOUT;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002364 else
2365 status = adapter->flash_status;
2366
2367 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002368 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002369 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002370 *change_status = resp->change_status;
2371 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002372 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002373 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002374
2375 return status;
2376
2377err_unlock:
2378 spin_unlock_bh(&adapter->mcc_lock);
2379 return status;
2380}
2381
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +05302382int be_cmd_query_cable_type(struct be_adapter *adapter)
2383{
2384 u8 page_data[PAGE_DATA_LEN];
2385 int status;
2386
2387 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2388 page_data);
2389 if (!status) {
2390 switch (adapter->phy.interface_type) {
2391 case PHY_TYPE_QSFP:
2392 adapter->phy.cable_type =
2393 page_data[QSFP_PLUS_CABLE_TYPE_OFFSET];
2394 break;
2395 case PHY_TYPE_SFP_PLUS_10GB:
2396 adapter->phy.cable_type =
2397 page_data[SFP_PLUS_CABLE_TYPE_OFFSET];
2398 break;
2399 default:
2400 adapter->phy.cable_type = 0;
2401 break;
2402 }
2403 }
2404 return status;
2405}
2406
Vasundhara Volam21252372015-02-06 08:18:42 -05002407int be_cmd_query_sfp_info(struct be_adapter *adapter)
2408{
2409 u8 page_data[PAGE_DATA_LEN];
2410 int status;
2411
2412 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2413 page_data);
2414 if (!status) {
2415 strlcpy(adapter->phy.vendor_name, page_data +
2416 SFP_VENDOR_NAME_OFFSET, SFP_VENDOR_NAME_LEN - 1);
2417 strlcpy(adapter->phy.vendor_pn,
2418 page_data + SFP_VENDOR_PN_OFFSET,
2419 SFP_VENDOR_NAME_LEN - 1);
2420 }
2421
2422 return status;
2423}
2424
Kalesh APf0613382014-08-01 17:47:32 +05302425int lancer_cmd_delete_object(struct be_adapter *adapter, const char *obj_name)
2426{
2427 struct lancer_cmd_req_delete_object *req;
2428 struct be_mcc_wrb *wrb;
2429 int status;
2430
2431 spin_lock_bh(&adapter->mcc_lock);
2432
2433 wrb = wrb_from_mccq(adapter);
2434 if (!wrb) {
2435 status = -EBUSY;
2436 goto err;
2437 }
2438
2439 req = embedded_payload(wrb);
2440
2441 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2442 OPCODE_COMMON_DELETE_OBJECT,
2443 sizeof(*req), wrb, NULL);
2444
Vasundhara Volam242eb472014-09-12 17:39:15 +05302445 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Kalesh APf0613382014-08-01 17:47:32 +05302446
2447 status = be_mcc_notify_wait(adapter);
2448err:
2449 spin_unlock_bh(&adapter->mcc_lock);
2450 return status;
2451}
2452
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002453int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302454 u32 data_size, u32 data_offset, const char *obj_name,
2455 u32 *data_read, u32 *eof, u8 *addn_status)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002456{
2457 struct be_mcc_wrb *wrb;
2458 struct lancer_cmd_req_read_object *req;
2459 struct lancer_cmd_resp_read_object *resp;
2460 int status;
2461
2462 spin_lock_bh(&adapter->mcc_lock);
2463
2464 wrb = wrb_from_mccq(adapter);
2465 if (!wrb) {
2466 status = -EBUSY;
2467 goto err_unlock;
2468 }
2469
2470 req = embedded_payload(wrb);
2471
2472 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302473 OPCODE_COMMON_READ_OBJECT,
2474 sizeof(struct lancer_cmd_req_read_object), wrb,
2475 NULL);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002476
2477 req->desired_read_len = cpu_to_le32(data_size);
2478 req->read_offset = cpu_to_le32(data_offset);
2479 strcpy(req->object_name, obj_name);
2480 req->descriptor_count = cpu_to_le32(1);
2481 req->buf_len = cpu_to_le32(data_size);
2482 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2483 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2484
2485 status = be_mcc_notify_wait(adapter);
2486
2487 resp = embedded_payload(wrb);
2488 if (!status) {
2489 *data_read = le32_to_cpu(resp->actual_read_len);
2490 *eof = le32_to_cpu(resp->eof);
2491 } else {
2492 *addn_status = resp->additional_status;
2493 }
2494
2495err_unlock:
2496 spin_unlock_bh(&adapter->mcc_lock);
2497 return status;
2498}
2499
Ajit Khaparde84517482009-09-04 03:12:16 +00002500int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd,
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002501 u32 flash_type, u32 flash_opcode, u32 img_offset,
2502 u32 buf_size)
Ajit Khaparde84517482009-09-04 03:12:16 +00002503{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002504 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002505 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002506 int status;
2507
Sathya Perlab31c50a2009-09-17 10:30:13 -07002508 spin_lock_bh(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002509 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002510
2511 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002512 if (!wrb) {
2513 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002514 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002515 }
2516 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002517
Somnath Kotur106df1e2011-10-27 07:12:13 +00002518 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302519 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb,
2520 cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002521
2522 req->params.op_type = cpu_to_le32(flash_type);
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002523 if (flash_type == OPTYPE_OFFSET_SPECIFIED)
2524 req->params.offset = cpu_to_le32(img_offset);
2525
Ajit Khaparde84517482009-09-04 03:12:16 +00002526 req->params.op_code = cpu_to_le32(flash_opcode);
2527 req->params.data_buf_size = cpu_to_le32(buf_size);
2528
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002529 be_mcc_notify(adapter);
2530 spin_unlock_bh(&adapter->mcc_lock);
2531
Suresh Reddy5eeff632014-01-06 13:02:24 +05302532 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
2533 msecs_to_jiffies(40000)))
Kalesh APfd451602014-07-17 16:20:21 +05302534 status = -ETIMEDOUT;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002535 else
2536 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002537
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002538 return status;
2539
2540err_unlock:
2541 spin_unlock_bh(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002542 return status;
2543}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002544
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002545int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002546 u16 img_optype, u32 img_offset, u32 crc_offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002547{
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002548 struct be_cmd_read_flash_crc *req;
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002549 struct be_mcc_wrb *wrb;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002550 int status;
2551
2552 spin_lock_bh(&adapter->mcc_lock);
2553
2554 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002555 if (!wrb) {
2556 status = -EBUSY;
2557 goto err;
2558 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002559 req = embedded_payload(wrb);
2560
Somnath Kotur106df1e2011-10-27 07:12:13 +00002561 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002562 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2563 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002564
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002565 req->params.op_type = cpu_to_le32(img_optype);
2566 if (img_optype == OPTYPE_OFFSET_SPECIFIED)
2567 req->params.offset = cpu_to_le32(img_offset + crc_offset);
2568 else
2569 req->params.offset = cpu_to_le32(crc_offset);
2570
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002571 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002572 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002573
2574 status = be_mcc_notify_wait(adapter);
2575 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002576 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002577
Sathya Perla713d03942009-11-22 22:02:45 +00002578err:
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002579 spin_unlock_bh(&adapter->mcc_lock);
2580 return status;
2581}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002582
Dan Carpenterc196b022010-05-26 04:47:39 +00002583int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302584 struct be_dma_mem *nonemb_cmd)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002585{
2586 struct be_mcc_wrb *wrb;
2587 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002588 int status;
2589
2590 spin_lock_bh(&adapter->mcc_lock);
2591
2592 wrb = wrb_from_mccq(adapter);
2593 if (!wrb) {
2594 status = -EBUSY;
2595 goto err;
2596 }
2597 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002598
Somnath Kotur106df1e2011-10-27 07:12:13 +00002599 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302600 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req),
2601 wrb, nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002602 memcpy(req->magic_mac, mac, ETH_ALEN);
2603
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002604 status = be_mcc_notify_wait(adapter);
2605
2606err:
2607 spin_unlock_bh(&adapter->mcc_lock);
2608 return status;
2609}
Suresh Rff33a6e2009-12-03 16:15:52 -08002610
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002611int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
2612 u8 loopback_type, u8 enable)
2613{
2614 struct be_mcc_wrb *wrb;
2615 struct be_cmd_req_set_lmode *req;
2616 int status;
2617
2618 spin_lock_bh(&adapter->mcc_lock);
2619
2620 wrb = wrb_from_mccq(adapter);
2621 if (!wrb) {
2622 status = -EBUSY;
2623 goto err;
2624 }
2625
2626 req = embedded_payload(wrb);
2627
Somnath Kotur106df1e2011-10-27 07:12:13 +00002628 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302629 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req),
2630 wrb, NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00002631
2632 req->src_port = port_num;
2633 req->dest_port = port_num;
2634 req->loopback_type = loopback_type;
2635 req->loopback_state = enable;
2636
2637 status = be_mcc_notify_wait(adapter);
2638err:
2639 spin_unlock_bh(&adapter->mcc_lock);
2640 return status;
2641}
2642
Suresh Rff33a6e2009-12-03 16:15:52 -08002643int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302644 u32 loopback_type, u32 pkt_size, u32 num_pkts,
2645 u64 pattern)
Suresh Rff33a6e2009-12-03 16:15:52 -08002646{
2647 struct be_mcc_wrb *wrb;
2648 struct be_cmd_req_loopback_test *req;
Suresh Reddy5eeff632014-01-06 13:02:24 +05302649 struct be_cmd_resp_loopback_test *resp;
Suresh Rff33a6e2009-12-03 16:15:52 -08002650 int status;
2651
2652 spin_lock_bh(&adapter->mcc_lock);
2653
2654 wrb = wrb_from_mccq(adapter);
2655 if (!wrb) {
2656 status = -EBUSY;
2657 goto err;
2658 }
2659
2660 req = embedded_payload(wrb);
2661
Somnath Kotur106df1e2011-10-27 07:12:13 +00002662 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302663 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb,
2664 NULL);
Suresh Rff33a6e2009-12-03 16:15:52 -08002665
Suresh Reddy5eeff632014-01-06 13:02:24 +05302666 req->hdr.timeout = cpu_to_le32(15);
Suresh Rff33a6e2009-12-03 16:15:52 -08002667 req->pattern = cpu_to_le64(pattern);
2668 req->src_port = cpu_to_le32(port_num);
2669 req->dest_port = cpu_to_le32(port_num);
2670 req->pkt_size = cpu_to_le32(pkt_size);
2671 req->num_pkts = cpu_to_le32(num_pkts);
2672 req->loopback_type = cpu_to_le32(loopback_type);
2673
Suresh Reddy5eeff632014-01-06 13:02:24 +05302674 be_mcc_notify(adapter);
Suresh Rff33a6e2009-12-03 16:15:52 -08002675
Suresh Reddy5eeff632014-01-06 13:02:24 +05302676 spin_unlock_bh(&adapter->mcc_lock);
2677
2678 wait_for_completion(&adapter->et_cmd_compl);
2679 resp = embedded_payload(wrb);
2680 status = le32_to_cpu(resp->status);
2681
2682 return status;
Suresh Rff33a6e2009-12-03 16:15:52 -08002683err:
2684 spin_unlock_bh(&adapter->mcc_lock);
2685 return status;
2686}
2687
2688int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302689 u32 byte_cnt, struct be_dma_mem *cmd)
Suresh Rff33a6e2009-12-03 16:15:52 -08002690{
2691 struct be_mcc_wrb *wrb;
2692 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08002693 int status;
2694 int i, j = 0;
2695
2696 spin_lock_bh(&adapter->mcc_lock);
2697
2698 wrb = wrb_from_mccq(adapter);
2699 if (!wrb) {
2700 status = -EBUSY;
2701 goto err;
2702 }
2703 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00002704 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302705 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb,
2706 cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08002707
2708 req->pattern = cpu_to_le64(pattern);
2709 req->byte_count = cpu_to_le32(byte_cnt);
2710 for (i = 0; i < byte_cnt; i++) {
2711 req->snd_buff[i] = (u8)(pattern >> (j*8));
2712 j++;
2713 if (j > 7)
2714 j = 0;
2715 }
2716
2717 status = be_mcc_notify_wait(adapter);
2718
2719 if (!status) {
2720 struct be_cmd_resp_ddrdma_test *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05302721
Suresh Rff33a6e2009-12-03 16:15:52 -08002722 resp = cmd->va;
2723 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
Kalesh APcd3307aa2014-09-19 15:47:02 +05302724 resp->snd_err) {
Suresh Rff33a6e2009-12-03 16:15:52 -08002725 status = -1;
2726 }
2727 }
2728
2729err:
2730 spin_unlock_bh(&adapter->mcc_lock);
2731 return status;
2732}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002733
Dan Carpenterc196b022010-05-26 04:47:39 +00002734int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302735 struct be_dma_mem *nonemb_cmd)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002736{
2737 struct be_mcc_wrb *wrb;
2738 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002739 int status;
2740
2741 spin_lock_bh(&adapter->mcc_lock);
2742
2743 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00002744 if (!wrb) {
2745 status = -EBUSY;
2746 goto err;
2747 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002748 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002749
Somnath Kotur106df1e2011-10-27 07:12:13 +00002750 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302751 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
2752 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002753
2754 status = be_mcc_notify_wait(adapter);
2755
Ajit Khapardee45ff012011-02-04 17:18:28 +00002756err:
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08002757 spin_unlock_bh(&adapter->mcc_lock);
2758 return status;
2759}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002760
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002761int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002762{
2763 struct be_mcc_wrb *wrb;
2764 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00002765 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002766 int status;
2767
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002768 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
2769 CMD_SUBSYSTEM_COMMON))
2770 return -EPERM;
2771
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002772 spin_lock_bh(&adapter->mcc_lock);
2773
2774 wrb = wrb_from_mccq(adapter);
2775 if (!wrb) {
2776 status = -EBUSY;
2777 goto err;
2778 }
Sathya Perla306f1342011-08-02 19:57:45 +00002779 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302780 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Sathya Perla306f1342011-08-02 19:57:45 +00002781 if (!cmd.va) {
2782 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
2783 status = -ENOMEM;
2784 goto err;
2785 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002786
Sathya Perla306f1342011-08-02 19:57:45 +00002787 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002788
Somnath Kotur106df1e2011-10-27 07:12:13 +00002789 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302790 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
2791 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002792
2793 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00002794 if (!status) {
2795 struct be_phy_info *resp_phy_info =
2796 cmd.va + sizeof(struct be_cmd_req_hdr);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302797
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002798 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
2799 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00002800 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00002801 adapter->phy.auto_speeds_supported =
2802 le16_to_cpu(resp_phy_info->auto_speeds_supported);
2803 adapter->phy.fixed_speeds_supported =
2804 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
2805 adapter->phy.misc_params =
2806 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05302807
2808 if (BE2_chip(adapter)) {
2809 adapter->phy.fixed_speeds_supported =
2810 BE_SUPPORTED_SPEED_10GBPS |
2811 BE_SUPPORTED_SPEED_1GBPS;
2812 }
Sathya Perla306f1342011-08-02 19:57:45 +00002813 }
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302814 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00002815err:
2816 spin_unlock_bh(&adapter->mcc_lock);
2817 return status;
2818}
Ajit Khapardee1d18732010-07-23 01:52:13 +00002819
Lad, Prabhakarbc0ee162015-02-05 15:24:43 +00002820static int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
Ajit Khapardee1d18732010-07-23 01:52:13 +00002821{
2822 struct be_mcc_wrb *wrb;
2823 struct be_cmd_req_set_qos *req;
2824 int status;
2825
2826 spin_lock_bh(&adapter->mcc_lock);
2827
2828 wrb = wrb_from_mccq(adapter);
2829 if (!wrb) {
2830 status = -EBUSY;
2831 goto err;
2832 }
2833
2834 req = embedded_payload(wrb);
2835
Somnath Kotur106df1e2011-10-27 07:12:13 +00002836 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302837 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002838
2839 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00002840 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
2841 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00002842
2843 status = be_mcc_notify_wait(adapter);
2844
2845err:
2846 spin_unlock_bh(&adapter->mcc_lock);
2847 return status;
2848}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002849
2850int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
2851{
2852 struct be_mcc_wrb *wrb;
2853 struct be_cmd_req_cntl_attribs *req;
2854 struct be_cmd_resp_cntl_attribs *resp;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002855 int status;
2856 int payload_len = max(sizeof(*req), sizeof(*resp));
2857 struct mgmt_controller_attrib *attribs;
2858 struct be_dma_mem attribs_cmd;
2859
Suresh Reddyd98ef502013-04-25 00:56:55 +00002860 if (mutex_lock_interruptible(&adapter->mbox_lock))
2861 return -1;
2862
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002863 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
2864 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
2865 attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302866 &attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002867 if (!attribs_cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302868 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00002869 status = -ENOMEM;
2870 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002871 }
2872
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002873 wrb = wrb_from_mbox(adapter);
2874 if (!wrb) {
2875 status = -EBUSY;
2876 goto err;
2877 }
2878 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002879
Somnath Kotur106df1e2011-10-27 07:12:13 +00002880 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302881 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len,
2882 wrb, &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002883
2884 status = be_mbox_notify_wait(adapter);
2885 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00002886 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002887 adapter->hba_port_num = attribs->hba_attribs.phy_port;
2888 }
2889
2890err:
2891 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00002892 if (attribs_cmd.va)
2893 pci_free_consistent(adapter->pdev, attribs_cmd.size,
2894 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00002895 return status;
2896}
Sathya Perla2e588f82011-03-11 02:49:26 +00002897
2898/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00002899int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00002900{
2901 struct be_mcc_wrb *wrb;
2902 struct be_cmd_req_set_func_cap *req;
2903 int status;
2904
2905 if (mutex_lock_interruptible(&adapter->mbox_lock))
2906 return -1;
2907
2908 wrb = wrb_from_mbox(adapter);
2909 if (!wrb) {
2910 status = -EBUSY;
2911 goto err;
2912 }
2913
2914 req = embedded_payload(wrb);
2915
Somnath Kotur106df1e2011-10-27 07:12:13 +00002916 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302917 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP,
2918 sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00002919
2920 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
2921 CAPABILITY_BE3_NATIVE_ERX_API);
2922 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
2923
2924 status = be_mbox_notify_wait(adapter);
2925 if (!status) {
2926 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302927
Sathya Perla2e588f82011-03-11 02:49:26 +00002928 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
2929 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00002930 if (!adapter->be3_native)
2931 dev_warn(&adapter->pdev->dev,
2932 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00002933 }
2934err:
2935 mutex_unlock(&adapter->mbox_lock);
2936 return status;
2937}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00002938
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002939/* Get privilege(s) for a function */
2940int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
2941 u32 domain)
2942{
2943 struct be_mcc_wrb *wrb;
2944 struct be_cmd_req_get_fn_privileges *req;
2945 int status;
2946
2947 spin_lock_bh(&adapter->mcc_lock);
2948
2949 wrb = wrb_from_mccq(adapter);
2950 if (!wrb) {
2951 status = -EBUSY;
2952 goto err;
2953 }
2954
2955 req = embedded_payload(wrb);
2956
2957 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2958 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
2959 wrb, NULL);
2960
2961 req->hdr.domain = domain;
2962
2963 status = be_mcc_notify_wait(adapter);
2964 if (!status) {
2965 struct be_cmd_resp_get_fn_privileges *resp =
2966 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302967
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002968 *privilege = le32_to_cpu(resp->privilege_mask);
Suresh Reddy02308d72014-01-15 13:23:36 +05302969
2970 /* In UMC mode FW does not return right privileges.
2971 * Override with correct privilege equivalent to PF.
2972 */
2973 if (BEx_chip(adapter) && be_is_mc(adapter) &&
2974 be_physfn(adapter))
2975 *privilege = MAX_PRIVILEGES;
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002976 }
2977
2978err:
2979 spin_unlock_bh(&adapter->mcc_lock);
2980 return status;
2981}
2982
Sathya Perla04a06022013-07-23 15:25:00 +05302983/* Set privilege(s) for a function */
2984int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
2985 u32 domain)
2986{
2987 struct be_mcc_wrb *wrb;
2988 struct be_cmd_req_set_fn_privileges *req;
2989 int status;
2990
2991 spin_lock_bh(&adapter->mcc_lock);
2992
2993 wrb = wrb_from_mccq(adapter);
2994 if (!wrb) {
2995 status = -EBUSY;
2996 goto err;
2997 }
2998
2999 req = embedded_payload(wrb);
3000 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3001 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
3002 wrb, NULL);
3003 req->hdr.domain = domain;
3004 if (lancer_chip(adapter))
3005 req->privileges_lancer = cpu_to_le32(privileges);
3006 else
3007 req->privileges = cpu_to_le32(privileges);
3008
3009 status = be_mcc_notify_wait(adapter);
3010err:
3011 spin_unlock_bh(&adapter->mcc_lock);
3012 return status;
3013}
3014
Sathya Perla5a712c12013-07-23 15:24:59 +05303015/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
3016 * pmac_id_valid: false => pmac_id or MAC address is requested.
3017 * If pmac_id is returned, pmac_id_valid is returned as true
3018 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003019int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303020 bool *pmac_id_valid, u32 *pmac_id, u32 if_handle,
3021 u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003022{
3023 struct be_mcc_wrb *wrb;
3024 struct be_cmd_req_get_mac_list *req;
3025 int status;
3026 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003027 struct be_dma_mem get_mac_list_cmd;
3028 int i;
3029
3030 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
3031 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
3032 get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303033 get_mac_list_cmd.size,
3034 &get_mac_list_cmd.dma);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003035
3036 if (!get_mac_list_cmd.va) {
3037 dev_err(&adapter->pdev->dev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303038 "Memory allocation failure during GET_MAC_LIST\n");
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003039 return -ENOMEM;
3040 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003041
3042 spin_lock_bh(&adapter->mcc_lock);
3043
3044 wrb = wrb_from_mccq(adapter);
3045 if (!wrb) {
3046 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003047 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003048 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003049
3050 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003051
3052 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00003053 OPCODE_COMMON_GET_MAC_LIST,
3054 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003055 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003056 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05303057 if (*pmac_id_valid) {
3058 req->mac_id = cpu_to_le32(*pmac_id);
Suresh Reddyb188f092014-01-15 13:23:39 +05303059 req->iface_id = cpu_to_le16(if_handle);
Sathya Perla5a712c12013-07-23 15:24:59 +05303060 req->perm_override = 0;
3061 } else {
3062 req->perm_override = 1;
3063 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003064
3065 status = be_mcc_notify_wait(adapter);
3066 if (!status) {
3067 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003068 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05303069
3070 if (*pmac_id_valid) {
3071 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
3072 ETH_ALEN);
3073 goto out;
3074 }
3075
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003076 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
3077 /* Mac list returned could contain one or more active mac_ids
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003078 * or one or more true or pseudo permanant mac addresses.
3079 * If an active mac_id is present, return first active mac_id
3080 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003081 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003082 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003083 struct get_list_macaddr *mac_entry;
3084 u16 mac_addr_size;
3085 u32 mac_id;
3086
3087 mac_entry = &resp->macaddr_list[i];
3088 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
3089 /* mac_id is a 32 bit value and mac_addr size
3090 * is 6 bytes
3091 */
3092 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05303093 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003094 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
3095 *pmac_id = le32_to_cpu(mac_id);
3096 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003097 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003098 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003099 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05303100 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003101 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303102 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003103 }
3104
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003105out:
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003106 spin_unlock_bh(&adapter->mcc_lock);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003107 pci_free_consistent(adapter->pdev, get_mac_list_cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303108 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003109 return status;
3110}
3111
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303112int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id,
3113 u8 *mac, u32 if_handle, bool active, u32 domain)
Sathya Perla5a712c12013-07-23 15:24:59 +05303114{
Suresh Reddyb188f092014-01-15 13:23:39 +05303115 if (!active)
3116 be_cmd_get_mac_from_list(adapter, mac, &active, &curr_pmac_id,
3117 if_handle, domain);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303118 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05303119 return be_cmd_mac_addr_query(adapter, mac, false,
Suresh Reddyb188f092014-01-15 13:23:39 +05303120 if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303121 else
3122 /* Fetch the MAC address using pmac_id */
3123 return be_cmd_get_mac_from_list(adapter, mac, &active,
Suresh Reddyb188f092014-01-15 13:23:39 +05303124 &curr_pmac_id,
3125 if_handle, domain);
Sathya Perla5a712c12013-07-23 15:24:59 +05303126}
3127
Sathya Perla95046b92013-07-23 15:25:02 +05303128int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
3129{
3130 int status;
3131 bool pmac_valid = false;
3132
3133 memset(mac, 0, ETH_ALEN);
3134
Sathya Perla3175d8c2013-07-23 15:25:03 +05303135 if (BEx_chip(adapter)) {
3136 if (be_physfn(adapter))
3137 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
3138 0);
3139 else
3140 status = be_cmd_mac_addr_query(adapter, mac, false,
3141 adapter->if_handle, 0);
3142 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05303143 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
Suresh Reddyb188f092014-01-15 13:23:39 +05303144 NULL, adapter->if_handle, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303145 }
3146
Sathya Perla95046b92013-07-23 15:25:02 +05303147 return status;
3148}
3149
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003150/* Uses synchronous MCCQ */
3151int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
3152 u8 mac_count, u32 domain)
3153{
3154 struct be_mcc_wrb *wrb;
3155 struct be_cmd_req_set_mac_list *req;
3156 int status;
3157 struct be_dma_mem cmd;
3158
3159 memset(&cmd, 0, sizeof(struct be_dma_mem));
3160 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
3161 cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303162 &cmd.dma, GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00003163 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003164 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003165
3166 spin_lock_bh(&adapter->mcc_lock);
3167
3168 wrb = wrb_from_mccq(adapter);
3169 if (!wrb) {
3170 status = -EBUSY;
3171 goto err;
3172 }
3173
3174 req = cmd.va;
3175 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303176 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
3177 wrb, &cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003178
3179 req->hdr.domain = domain;
3180 req->mac_count = mac_count;
3181 if (mac_count)
3182 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
3183
3184 status = be_mcc_notify_wait(adapter);
3185
3186err:
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303187 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003188 spin_unlock_bh(&adapter->mcc_lock);
3189 return status;
3190}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003191
Sathya Perla3175d8c2013-07-23 15:25:03 +05303192/* Wrapper to delete any active MACs and provision the new mac.
3193 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
3194 * current list are active.
3195 */
3196int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
3197{
3198 bool active_mac = false;
3199 u8 old_mac[ETH_ALEN];
3200 u32 pmac_id;
3201 int status;
3202
3203 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303204 &pmac_id, if_id, dom);
3205
Sathya Perla3175d8c2013-07-23 15:25:03 +05303206 if (!status && active_mac)
3207 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
3208
3209 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
3210}
3211
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003212int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003213 u32 domain, u16 intf_id, u16 hsw_mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003214{
3215 struct be_mcc_wrb *wrb;
3216 struct be_cmd_req_set_hsw_config *req;
3217 void *ctxt;
3218 int status;
3219
3220 spin_lock_bh(&adapter->mcc_lock);
3221
3222 wrb = wrb_from_mccq(adapter);
3223 if (!wrb) {
3224 status = -EBUSY;
3225 goto err;
3226 }
3227
3228 req = embedded_payload(wrb);
3229 ctxt = &req->context;
3230
3231 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303232 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb,
3233 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003234
3235 req->hdr.domain = domain;
3236 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
3237 if (pvid) {
3238 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
3239 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
3240 }
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003241 if (!BEx_chip(adapter) && hsw_mode) {
3242 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id,
3243 ctxt, adapter->hba_port_num);
3244 AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1);
3245 AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type,
3246 ctxt, hsw_mode);
3247 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003248
3249 be_dws_cpu_to_le(req->context, sizeof(req->context));
3250 status = be_mcc_notify_wait(adapter);
3251
3252err:
3253 spin_unlock_bh(&adapter->mcc_lock);
3254 return status;
3255}
3256
3257/* Get Hyper switch config */
3258int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003259 u32 domain, u16 intf_id, u8 *mode)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003260{
3261 struct be_mcc_wrb *wrb;
3262 struct be_cmd_req_get_hsw_config *req;
3263 void *ctxt;
3264 int status;
3265 u16 vid;
3266
3267 spin_lock_bh(&adapter->mcc_lock);
3268
3269 wrb = wrb_from_mccq(adapter);
3270 if (!wrb) {
3271 status = -EBUSY;
3272 goto err;
3273 }
3274
3275 req = embedded_payload(wrb);
3276 ctxt = &req->context;
3277
3278 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303279 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb,
3280 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003281
3282 req->hdr.domain = domain;
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003283 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3284 ctxt, intf_id);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003285 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003286
Vasundhara Volam2c07c1d2014-01-15 13:23:32 +05303287 if (!BEx_chip(adapter) && mode) {
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003288 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3289 ctxt, adapter->hba_port_num);
3290 AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1);
3291 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003292 be_dws_cpu_to_le(req->context, sizeof(req->context));
3293
3294 status = be_mcc_notify_wait(adapter);
3295 if (!status) {
3296 struct be_cmd_resp_get_hsw_config *resp =
3297 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303298
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303299 be_dws_le_to_cpu(&resp->context, sizeof(resp->context));
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003300 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303301 pvid, &resp->context);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003302 if (pvid)
3303 *pvid = le16_to_cpu(vid);
3304 if (mode)
3305 *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3306 port_fwd_type, &resp->context);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003307 }
3308
3309err:
3310 spin_unlock_bh(&adapter->mcc_lock);
3311 return status;
3312}
3313
Sathya Perlaf7062ee2015-02-06 08:18:35 -05003314static bool be_is_wol_excluded(struct be_adapter *adapter)
3315{
3316 struct pci_dev *pdev = adapter->pdev;
3317
3318 if (!be_physfn(adapter))
3319 return true;
3320
3321 switch (pdev->subsystem_device) {
3322 case OC_SUBSYS_DEVICE_ID1:
3323 case OC_SUBSYS_DEVICE_ID2:
3324 case OC_SUBSYS_DEVICE_ID3:
3325 case OC_SUBSYS_DEVICE_ID4:
3326 return true;
3327 default:
3328 return false;
3329 }
3330}
3331
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003332int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
3333{
3334 struct be_mcc_wrb *wrb;
3335 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303336 int status = 0;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003337 struct be_dma_mem cmd;
3338
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003339 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
3340 CMD_SUBSYSTEM_ETH))
3341 return -EPERM;
3342
Suresh Reddy76a9e082014-01-15 13:23:40 +05303343 if (be_is_wol_excluded(adapter))
3344 return status;
3345
Suresh Reddyd98ef502013-04-25 00:56:55 +00003346 if (mutex_lock_interruptible(&adapter->mbox_lock))
3347 return -1;
3348
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003349 memset(&cmd, 0, sizeof(struct be_dma_mem));
3350 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303351 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003352 if (!cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303353 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003354 status = -ENOMEM;
3355 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003356 }
3357
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003358 wrb = wrb_from_mbox(adapter);
3359 if (!wrb) {
3360 status = -EBUSY;
3361 goto err;
3362 }
3363
3364 req = cmd.va;
3365
3366 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
3367 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
Suresh Reddy76a9e082014-01-15 13:23:40 +05303368 sizeof(*req), wrb, &cmd);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003369
3370 req->hdr.version = 1;
3371 req->query_options = BE_GET_WOL_CAP;
3372
3373 status = be_mbox_notify_wait(adapter);
3374 if (!status) {
3375 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05303376
Kalesh AP504fbf12014-09-19 15:47:00 +05303377 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *)cmd.va;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003378
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003379 adapter->wol_cap = resp->wol_settings;
Suresh Reddy76a9e082014-01-15 13:23:40 +05303380 if (adapter->wol_cap & BE_WOL_CAP)
3381 adapter->wol_en = true;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003382 }
3383err:
3384 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003385 if (cmd.va)
3386 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003387 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00003388
3389}
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303390
3391int be_cmd_set_fw_log_level(struct be_adapter *adapter, u32 level)
3392{
3393 struct be_dma_mem extfat_cmd;
3394 struct be_fat_conf_params *cfgs;
3395 int status;
3396 int i, j;
3397
3398 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3399 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
3400 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
3401 &extfat_cmd.dma);
3402 if (!extfat_cmd.va)
3403 return -ENOMEM;
3404
3405 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3406 if (status)
3407 goto err;
3408
3409 cfgs = (struct be_fat_conf_params *)
3410 (extfat_cmd.va + sizeof(struct be_cmd_resp_hdr));
3411 for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
3412 u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303413
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303414 for (j = 0; j < num_modes; j++) {
3415 if (cfgs->module[i].trace_lvl[j].mode == MODE_UART)
3416 cfgs->module[i].trace_lvl[j].dbg_lvl =
3417 cpu_to_le32(level);
3418 }
3419 }
3420
3421 status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd, cfgs);
3422err:
3423 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
3424 extfat_cmd.dma);
3425 return status;
3426}
3427
3428int be_cmd_get_fw_log_level(struct be_adapter *adapter)
3429{
3430 struct be_dma_mem extfat_cmd;
3431 struct be_fat_conf_params *cfgs;
3432 int status, j;
3433 int level = 0;
3434
3435 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
3436 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
3437 extfat_cmd.va = pci_alloc_consistent(adapter->pdev, extfat_cmd.size,
3438 &extfat_cmd.dma);
3439
3440 if (!extfat_cmd.va) {
3441 dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
3442 __func__);
3443 goto err;
3444 }
3445
3446 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
3447 if (!status) {
3448 cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
3449 sizeof(struct be_cmd_resp_hdr));
Kalesh AP03d28ff2014-09-19 15:46:56 +05303450
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05303451 for (j = 0; j < le32_to_cpu(cfgs->module[0].num_modes); j++) {
3452 if (cfgs->module[0].trace_lvl[j].mode == MODE_UART)
3453 level = cfgs->module[0].trace_lvl[j].dbg_lvl;
3454 }
3455 }
3456 pci_free_consistent(adapter->pdev, extfat_cmd.size, extfat_cmd.va,
3457 extfat_cmd.dma);
3458err:
3459 return level;
3460}
3461
Somnath Kotur941a77d2012-05-17 22:59:03 +00003462int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
3463 struct be_dma_mem *cmd)
3464{
3465 struct be_mcc_wrb *wrb;
3466 struct be_cmd_req_get_ext_fat_caps *req;
3467 int status;
3468
3469 if (mutex_lock_interruptible(&adapter->mbox_lock))
3470 return -1;
3471
3472 wrb = wrb_from_mbox(adapter);
3473 if (!wrb) {
3474 status = -EBUSY;
3475 goto err;
3476 }
3477
3478 req = cmd->va;
3479 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3480 OPCODE_COMMON_GET_EXT_FAT_CAPABILITES,
3481 cmd->size, wrb, cmd);
3482 req->parameter_type = cpu_to_le32(1);
3483
3484 status = be_mbox_notify_wait(adapter);
3485err:
3486 mutex_unlock(&adapter->mbox_lock);
3487 return status;
3488}
3489
3490int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
3491 struct be_dma_mem *cmd,
3492 struct be_fat_conf_params *configs)
3493{
3494 struct be_mcc_wrb *wrb;
3495 struct be_cmd_req_set_ext_fat_caps *req;
3496 int status;
3497
3498 spin_lock_bh(&adapter->mcc_lock);
3499
3500 wrb = wrb_from_mccq(adapter);
3501 if (!wrb) {
3502 status = -EBUSY;
3503 goto err;
3504 }
3505
3506 req = cmd->va;
3507 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
3508 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3509 OPCODE_COMMON_SET_EXT_FAT_CAPABILITES,
3510 cmd->size, wrb, cmd);
3511
3512 status = be_mcc_notify_wait(adapter);
3513err:
3514 spin_unlock_bh(&adapter->mcc_lock);
3515 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003516}
Parav Pandit6a4ab662012-03-26 14:27:12 +00003517
Vasundhara Volam21252372015-02-06 08:18:42 -05003518int be_cmd_query_port_name(struct be_adapter *adapter)
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003519{
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003520 struct be_cmd_req_get_port_name *req;
Vasundhara Volam21252372015-02-06 08:18:42 -05003521 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003522 int status;
3523
Vasundhara Volam21252372015-02-06 08:18:42 -05003524 if (mutex_lock_interruptible(&adapter->mbox_lock))
3525 return -1;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003526
Vasundhara Volam21252372015-02-06 08:18:42 -05003527 wrb = wrb_from_mbox(adapter);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003528 req = embedded_payload(wrb);
3529
3530 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3531 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
3532 NULL);
Vasundhara Volam21252372015-02-06 08:18:42 -05003533 if (!BEx_chip(adapter))
3534 req->hdr.version = 1;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003535
Vasundhara Volam21252372015-02-06 08:18:42 -05003536 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003537 if (!status) {
3538 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303539
Vasundhara Volam21252372015-02-06 08:18:42 -05003540 adapter->port_name = resp->port_name[adapter->hba_port_num];
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003541 } else {
Vasundhara Volam21252372015-02-06 08:18:42 -05003542 adapter->port_name = adapter->hba_port_num + '0';
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003543 }
Vasundhara Volam21252372015-02-06 08:18:42 -05003544
3545 mutex_unlock(&adapter->mbox_lock);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00003546 return status;
3547}
3548
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303549/* Descriptor type */
3550enum {
3551 FUNC_DESC = 1,
3552 VFT_DESC = 2
3553};
3554
3555static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
3556 int desc_type)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003557{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303558 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303559 struct be_nic_res_desc *nic;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003560 int i;
3561
3562 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303563 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303564 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) {
3565 nic = (struct be_nic_res_desc *)hdr;
3566 if (desc_type == FUNC_DESC ||
3567 (desc_type == VFT_DESC &&
3568 nic->flags & (1 << VFT_SHIFT)))
3569 return nic;
3570 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003571
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303572 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3573 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003574 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303575 return NULL;
3576}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003577
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303578static struct be_nic_res_desc *be_get_vft_desc(u8 *buf, u32 desc_count)
3579{
3580 return be_get_nic_desc(buf, desc_count, VFT_DESC);
3581}
3582
3583static struct be_nic_res_desc *be_get_func_nic_desc(u8 *buf, u32 desc_count)
3584{
3585 return be_get_nic_desc(buf, desc_count, FUNC_DESC);
3586}
3587
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303588static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf,
3589 u32 desc_count)
3590{
3591 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3592 struct be_pcie_res_desc *pcie;
3593 int i;
3594
3595 for (i = 0; i < desc_count; i++) {
3596 if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
3597 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) {
3598 pcie = (struct be_pcie_res_desc *)hdr;
3599 if (pcie->pf_num == devfn)
3600 return pcie;
3601 }
3602
3603 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3604 hdr = (void *)hdr + hdr->desc_len;
3605 }
Wei Yang950e2952013-05-22 15:58:22 +00003606 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003607}
3608
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303609static struct be_port_res_desc *be_get_port_desc(u8 *buf, u32 desc_count)
3610{
3611 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
3612 int i;
3613
3614 for (i = 0; i < desc_count; i++) {
3615 if (hdr->desc_type == PORT_RESOURCE_DESC_TYPE_V1)
3616 return (struct be_port_res_desc *)hdr;
3617
3618 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
3619 hdr = (void *)hdr + hdr->desc_len;
3620 }
3621 return NULL;
3622}
3623
Sathya Perla92bf14a2013-08-27 16:57:32 +05303624static void be_copy_nic_desc(struct be_resources *res,
3625 struct be_nic_res_desc *desc)
3626{
3627 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
3628 res->max_vlans = le16_to_cpu(desc->vlan_count);
3629 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
3630 res->max_tx_qs = le16_to_cpu(desc->txq_count);
3631 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
3632 res->max_rx_qs = le16_to_cpu(desc->rq_count);
3633 res->max_evt_qs = le16_to_cpu(desc->eq_count);
3634 /* Clear flags that driver is not interested in */
3635 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
3636 BE_IF_CAP_FLAGS_WANT;
3637 /* Need 1 RXQ as the default RXQ */
3638 if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs)
3639 res->max_rss_qs -= 1;
3640}
3641
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003642/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303643int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003644{
3645 struct be_mcc_wrb *wrb;
3646 struct be_cmd_req_get_func_config *req;
3647 int status;
3648 struct be_dma_mem cmd;
3649
Suresh Reddyd98ef502013-04-25 00:56:55 +00003650 if (mutex_lock_interruptible(&adapter->mbox_lock))
3651 return -1;
3652
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003653 memset(&cmd, 0, sizeof(struct be_dma_mem));
3654 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303655 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003656 if (!cmd.va) {
3657 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003658 status = -ENOMEM;
3659 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003660 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003661
3662 wrb = wrb_from_mbox(adapter);
3663 if (!wrb) {
3664 status = -EBUSY;
3665 goto err;
3666 }
3667
3668 req = cmd.va;
3669
3670 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3671 OPCODE_COMMON_GET_FUNC_CONFIG,
3672 cmd.size, wrb, &cmd);
3673
Kalesh AP28710c52013-04-28 22:21:13 +00003674 if (skyhawk_chip(adapter))
3675 req->hdr.version = 1;
3676
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003677 status = be_mbox_notify_wait(adapter);
3678 if (!status) {
3679 struct be_cmd_resp_get_func_config *resp = cmd.va;
3680 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303681 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003682
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303683 desc = be_get_func_nic_desc(resp->func_param, desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003684 if (!desc) {
3685 status = -EINVAL;
3686 goto err;
3687 }
3688
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003689 adapter->pf_number = desc->pf_num;
Sathya Perla92bf14a2013-08-27 16:57:32 +05303690 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003691 }
3692err:
3693 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003694 if (cmd.va)
3695 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003696 return status;
3697}
3698
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303699/* Will use MBOX only if MCCQ has not been created */
Sathya Perla92bf14a2013-08-27 16:57:32 +05303700int be_cmd_get_profile_config(struct be_adapter *adapter,
3701 struct be_resources *res, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003702{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303703 struct be_cmd_resp_get_profile_config *resp;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303704 struct be_cmd_req_get_profile_config *req;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303705 struct be_nic_res_desc *vf_res;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303706 struct be_pcie_res_desc *pcie;
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303707 struct be_port_res_desc *port;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303708 struct be_nic_res_desc *nic;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303709 struct be_mcc_wrb wrb = {0};
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003710 struct be_dma_mem cmd;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303711 u32 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003712 int status;
3713
3714 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303715 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
3716 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3717 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003718 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003719
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05303720 req = cmd.va;
3721 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3722 OPCODE_COMMON_GET_PROFILE_CONFIG,
3723 cmd.size, &wrb, &cmd);
3724
3725 req->hdr.domain = domain;
3726 if (!lancer_chip(adapter))
3727 req->hdr.version = 1;
3728 req->type = ACTIVE_PROFILE_TYPE;
3729
3730 status = be_cmd_notify_wait(adapter, &wrb);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303731 if (status)
3732 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003733
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303734 resp = cmd.va;
3735 desc_count = le32_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003736
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303737 pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param,
3738 desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303739 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05303740 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303741
Vasundhara Volamf93f1602014-02-12 16:09:25 +05303742 port = be_get_port_desc(resp->func_param, desc_count);
3743 if (port)
3744 adapter->mc_type = port->mc_type;
3745
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303746 nic = be_get_func_nic_desc(resp->func_param, desc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05303747 if (nic)
3748 be_copy_nic_desc(res, nic);
3749
Vasundhara Volam10cccf62014-06-30 13:01:31 +05303750 vf_res = be_get_vft_desc(resp->func_param, desc_count);
3751 if (vf_res)
3752 res->vf_if_cap_flags = vf_res->cap_flags;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003753err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00003754 if (cmd.va)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05303755 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00003756 return status;
3757}
3758
Vasundhara Volambec84e62014-06-30 13:01:32 +05303759/* Will use MBOX only if MCCQ has not been created */
3760static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc,
3761 int size, int count, u8 version, u8 domain)
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003762{
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003763 struct be_cmd_req_set_profile_config *req;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303764 struct be_mcc_wrb wrb = {0};
3765 struct be_dma_mem cmd;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003766 int status;
3767
Vasundhara Volambec84e62014-06-30 13:01:32 +05303768 memset(&cmd, 0, sizeof(struct be_dma_mem));
3769 cmd.size = sizeof(struct be_cmd_req_set_profile_config);
3770 cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma);
3771 if (!cmd.va)
3772 return -ENOMEM;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003773
Vasundhara Volambec84e62014-06-30 13:01:32 +05303774 req = cmd.va;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003775 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303776 OPCODE_COMMON_SET_PROFILE_CONFIG, cmd.size,
3777 &wrb, &cmd);
Sathya Perlaa4018012014-03-27 10:46:18 +05303778 req->hdr.version = version;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003779 req->hdr.domain = domain;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303780 req->desc_count = cpu_to_le32(count);
Sathya Perlaa4018012014-03-27 10:46:18 +05303781 memcpy(req->desc, desc, size);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003782
Vasundhara Volambec84e62014-06-30 13:01:32 +05303783 status = be_cmd_notify_wait(adapter, &wrb);
3784
3785 if (cmd.va)
3786 pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00003787 return status;
3788}
3789
Sathya Perlaa4018012014-03-27 10:46:18 +05303790/* Mark all fields invalid */
Vasundhara Volambec84e62014-06-30 13:01:32 +05303791static void be_reset_nic_desc(struct be_nic_res_desc *nic)
Sathya Perlaa4018012014-03-27 10:46:18 +05303792{
3793 memset(nic, 0, sizeof(*nic));
3794 nic->unicast_mac_count = 0xFFFF;
3795 nic->mcc_count = 0xFFFF;
3796 nic->vlan_count = 0xFFFF;
3797 nic->mcast_mac_count = 0xFFFF;
3798 nic->txq_count = 0xFFFF;
3799 nic->rq_count = 0xFFFF;
3800 nic->rssq_count = 0xFFFF;
3801 nic->lro_count = 0xFFFF;
3802 nic->cq_count = 0xFFFF;
3803 nic->toe_conn_count = 0xFFFF;
3804 nic->eq_count = 0xFFFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303805 nic->iface_count = 0xFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303806 nic->link_param = 0xFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303807 nic->channel_id_param = cpu_to_le16(0xF000);
Sathya Perlaa4018012014-03-27 10:46:18 +05303808 nic->acpi_params = 0xFF;
3809 nic->wol_param = 0x0F;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303810 nic->tunnel_iface_count = 0xFFFF;
3811 nic->direct_tenant_iface_count = 0xFFFF;
Vasundhara Volambec84e62014-06-30 13:01:32 +05303812 nic->bw_min = 0xFFFFFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05303813 nic->bw_max = 0xFFFFFFFF;
3814}
3815
Vasundhara Volambec84e62014-06-30 13:01:32 +05303816/* Mark all fields invalid */
3817static void be_reset_pcie_desc(struct be_pcie_res_desc *pcie)
3818{
3819 memset(pcie, 0, sizeof(*pcie));
3820 pcie->sriov_state = 0xFF;
3821 pcie->pf_state = 0xFF;
3822 pcie->pf_type = 0xFF;
3823 pcie->num_vfs = 0xFFFF;
3824}
3825
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303826int be_cmd_config_qos(struct be_adapter *adapter, u32 max_rate, u16 link_speed,
3827 u8 domain)
Sathya Perlaa4018012014-03-27 10:46:18 +05303828{
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303829 struct be_nic_res_desc nic_desc;
3830 u32 bw_percent;
3831 u16 version = 0;
Sathya Perlaa4018012014-03-27 10:46:18 +05303832
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303833 if (BE3_chip(adapter))
3834 return be_cmd_set_qos(adapter, max_rate / 10, domain);
3835
3836 be_reset_nic_desc(&nic_desc);
3837 nic_desc.pf_num = adapter->pf_number;
3838 nic_desc.vf_num = domain;
Kalesh AP58bdeaa2015-01-20 03:51:49 -05003839 nic_desc.bw_min = 0;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303840 if (lancer_chip(adapter)) {
Sathya Perlaa4018012014-03-27 10:46:18 +05303841 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
3842 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
3843 nic_desc.flags = (1 << QUN_SHIFT) | (1 << IMM_SHIFT) |
3844 (1 << NOSV_SHIFT);
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303845 nic_desc.bw_max = cpu_to_le32(max_rate / 10);
Sathya Perlaa4018012014-03-27 10:46:18 +05303846 } else {
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303847 version = 1;
3848 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3849 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3850 nic_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3851 bw_percent = max_rate ? (max_rate * 100) / link_speed : 100;
3852 nic_desc.bw_max = cpu_to_le32(bw_percent);
Sathya Perlaa4018012014-03-27 10:46:18 +05303853 }
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05303854
3855 return be_cmd_set_profile_config(adapter, &nic_desc,
3856 nic_desc.hdr.desc_len,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303857 1, version, domain);
3858}
3859
3860int be_cmd_set_sriov_config(struct be_adapter *adapter,
3861 struct be_resources res, u16 num_vfs)
3862{
3863 struct {
3864 struct be_pcie_res_desc pcie;
3865 struct be_nic_res_desc nic_vft;
3866 } __packed desc;
3867 u16 vf_q_count;
3868
3869 if (BEx_chip(adapter) || lancer_chip(adapter))
3870 return 0;
3871
3872 /* PF PCIE descriptor */
3873 be_reset_pcie_desc(&desc.pcie);
3874 desc.pcie.hdr.desc_type = PCIE_RESOURCE_DESC_TYPE_V1;
3875 desc.pcie.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3876 desc.pcie.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3877 desc.pcie.pf_num = adapter->pdev->devfn;
3878 desc.pcie.sriov_state = num_vfs ? 1 : 0;
3879 desc.pcie.num_vfs = cpu_to_le16(num_vfs);
3880
3881 /* VF NIC Template descriptor */
3882 be_reset_nic_desc(&desc.nic_vft);
3883 desc.nic_vft.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
3884 desc.nic_vft.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3885 desc.nic_vft.flags = (1 << VFT_SHIFT) | (1 << IMM_SHIFT) |
3886 (1 << NOSV_SHIFT);
3887 desc.nic_vft.pf_num = adapter->pdev->devfn;
3888 desc.nic_vft.vf_num = 0;
3889
3890 if (num_vfs && res.vf_if_cap_flags & BE_IF_FLAGS_RSS) {
3891 /* If number of VFs requested is 8 less than max supported,
3892 * assign 8 queue pairs to the PF and divide the remaining
3893 * resources evenly among the VFs
3894 */
3895 if (num_vfs < (be_max_vfs(adapter) - 8))
3896 vf_q_count = (res.max_rss_qs - 8) / num_vfs;
3897 else
3898 vf_q_count = res.max_rss_qs / num_vfs;
3899
3900 desc.nic_vft.rq_count = cpu_to_le16(vf_q_count);
3901 desc.nic_vft.txq_count = cpu_to_le16(vf_q_count);
3902 desc.nic_vft.rssq_count = cpu_to_le16(vf_q_count - 1);
3903 desc.nic_vft.cq_count = cpu_to_le16(3 * vf_q_count);
3904 } else {
3905 desc.nic_vft.txq_count = cpu_to_le16(1);
3906 desc.nic_vft.rq_count = cpu_to_le16(1);
3907 desc.nic_vft.rssq_count = cpu_to_le16(0);
3908 /* One CQ for each TX, RX and MCCQ */
3909 desc.nic_vft.cq_count = cpu_to_le16(3);
3910 }
3911
3912 return be_cmd_set_profile_config(adapter, &desc,
3913 2 * RESOURCE_DESC_SIZE_V1, 2, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303914}
3915
3916int be_cmd_manage_iface(struct be_adapter *adapter, u32 iface, u8 op)
3917{
3918 struct be_mcc_wrb *wrb;
3919 struct be_cmd_req_manage_iface_filters *req;
3920 int status;
3921
3922 if (iface == 0xFFFFFFFF)
3923 return -1;
3924
3925 spin_lock_bh(&adapter->mcc_lock);
3926
3927 wrb = wrb_from_mccq(adapter);
3928 if (!wrb) {
3929 status = -EBUSY;
3930 goto err;
3931 }
3932 req = embedded_payload(wrb);
3933
3934 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3935 OPCODE_COMMON_MANAGE_IFACE_FILTERS, sizeof(*req),
3936 wrb, NULL);
3937 req->op = op;
3938 req->target_iface_id = cpu_to_le32(iface);
3939
3940 status = be_mcc_notify_wait(adapter);
3941err:
3942 spin_unlock_bh(&adapter->mcc_lock);
3943 return status;
3944}
3945
3946int be_cmd_set_vxlan_port(struct be_adapter *adapter, __be16 port)
3947{
3948 struct be_port_res_desc port_desc;
3949
3950 memset(&port_desc, 0, sizeof(port_desc));
3951 port_desc.hdr.desc_type = PORT_RESOURCE_DESC_TYPE_V1;
3952 port_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
3953 port_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
3954 port_desc.link_num = adapter->hba_port_num;
3955 if (port) {
3956 port_desc.nv_flags = NV_TYPE_VXLAN | (1 << SOCVID_SHIFT) |
3957 (1 << RCVID_SHIFT);
3958 port_desc.nv_port = swab16(port);
3959 } else {
3960 port_desc.nv_flags = NV_TYPE_DISABLED;
3961 port_desc.nv_port = 0;
3962 }
3963
3964 return be_cmd_set_profile_config(adapter, &port_desc,
Vasundhara Volambec84e62014-06-30 13:01:32 +05303965 RESOURCE_DESC_SIZE_V1, 1, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05303966}
3967
Sathya Perla4c876612013-02-03 20:30:11 +00003968int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
3969 int vf_num)
3970{
3971 struct be_mcc_wrb *wrb;
3972 struct be_cmd_req_get_iface_list *req;
3973 struct be_cmd_resp_get_iface_list *resp;
3974 int status;
3975
3976 spin_lock_bh(&adapter->mcc_lock);
3977
3978 wrb = wrb_from_mccq(adapter);
3979 if (!wrb) {
3980 status = -EBUSY;
3981 goto err;
3982 }
3983 req = embedded_payload(wrb);
3984
3985 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3986 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
3987 wrb, NULL);
3988 req->hdr.domain = vf_num + 1;
3989
3990 status = be_mcc_notify_wait(adapter);
3991 if (!status) {
3992 resp = (struct be_cmd_resp_get_iface_list *)req;
3993 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
3994 }
3995
3996err:
3997 spin_unlock_bh(&adapter->mcc_lock);
3998 return status;
3999}
4000
Somnath Kotur5c510812013-05-30 02:52:23 +00004001static int lancer_wait_idle(struct be_adapter *adapter)
4002{
4003#define SLIPORT_IDLE_TIMEOUT 30
4004 u32 reg_val;
4005 int status = 0, i;
4006
4007 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
4008 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
4009 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
4010 break;
4011
4012 ssleep(1);
4013 }
4014
4015 if (i == SLIPORT_IDLE_TIMEOUT)
4016 status = -1;
4017
4018 return status;
4019}
4020
4021int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
4022{
4023 int status = 0;
4024
4025 status = lancer_wait_idle(adapter);
4026 if (status)
4027 return status;
4028
4029 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
4030
4031 return status;
4032}
4033
4034/* Routine to check whether dump image is present or not */
4035bool dump_present(struct be_adapter *adapter)
4036{
4037 u32 sliport_status = 0;
4038
4039 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
4040 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
4041}
4042
4043int lancer_initiate_dump(struct be_adapter *adapter)
4044{
Kalesh APf0613382014-08-01 17:47:32 +05304045 struct device *dev = &adapter->pdev->dev;
Somnath Kotur5c510812013-05-30 02:52:23 +00004046 int status;
4047
Kalesh APf0613382014-08-01 17:47:32 +05304048 if (dump_present(adapter)) {
4049 dev_info(dev, "Previous dump not cleared, not forcing dump\n");
4050 return -EEXIST;
4051 }
4052
Somnath Kotur5c510812013-05-30 02:52:23 +00004053 /* give firmware reset and diagnostic dump */
4054 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
4055 PHYSDEV_CONTROL_DD_MASK);
4056 if (status < 0) {
Kalesh APf0613382014-08-01 17:47:32 +05304057 dev_err(dev, "FW reset failed\n");
Somnath Kotur5c510812013-05-30 02:52:23 +00004058 return status;
4059 }
4060
4061 status = lancer_wait_idle(adapter);
4062 if (status)
4063 return status;
4064
4065 if (!dump_present(adapter)) {
Kalesh APf0613382014-08-01 17:47:32 +05304066 dev_err(dev, "FW dump not generated\n");
4067 return -EIO;
Somnath Kotur5c510812013-05-30 02:52:23 +00004068 }
4069
4070 return 0;
4071}
4072
Kalesh APf0613382014-08-01 17:47:32 +05304073int lancer_delete_dump(struct be_adapter *adapter)
4074{
4075 int status;
4076
4077 status = lancer_cmd_delete_object(adapter, LANCER_FW_DUMP_FILE);
4078 return be_cmd_status(status);
4079}
4080
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004081/* Uses sync mcc */
4082int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
4083{
4084 struct be_mcc_wrb *wrb;
4085 struct be_cmd_enable_disable_vf *req;
4086 int status;
4087
Vasundhara Volam05998632013-10-01 15:59:59 +05304088 if (BEx_chip(adapter))
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004089 return 0;
4090
4091 spin_lock_bh(&adapter->mcc_lock);
4092
4093 wrb = wrb_from_mccq(adapter);
4094 if (!wrb) {
4095 status = -EBUSY;
4096 goto err;
4097 }
4098
4099 req = embedded_payload(wrb);
4100
4101 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4102 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
4103 wrb, NULL);
4104
4105 req->hdr.domain = domain;
4106 req->enable = 1;
4107 status = be_mcc_notify_wait(adapter);
4108err:
4109 spin_unlock_bh(&adapter->mcc_lock);
4110 return status;
4111}
4112
Somnath Kotur68c45a22013-03-14 02:42:07 +00004113int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
4114{
4115 struct be_mcc_wrb *wrb;
4116 struct be_cmd_req_intr_set *req;
4117 int status;
4118
4119 if (mutex_lock_interruptible(&adapter->mbox_lock))
4120 return -1;
4121
4122 wrb = wrb_from_mbox(adapter);
4123
4124 req = embedded_payload(wrb);
4125
4126 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4127 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
4128 wrb, NULL);
4129
4130 req->intr_enabled = intr_enable;
4131
4132 status = be_mbox_notify_wait(adapter);
4133
4134 mutex_unlock(&adapter->mbox_lock);
4135 return status;
4136}
4137
Vasundhara Volam542963b2014-01-15 13:23:33 +05304138/* Uses MBOX */
4139int be_cmd_get_active_profile(struct be_adapter *adapter, u16 *profile_id)
4140{
4141 struct be_cmd_req_get_active_profile *req;
4142 struct be_mcc_wrb *wrb;
4143 int status;
4144
4145 if (mutex_lock_interruptible(&adapter->mbox_lock))
4146 return -1;
4147
4148 wrb = wrb_from_mbox(adapter);
4149 if (!wrb) {
4150 status = -EBUSY;
4151 goto err;
4152 }
4153
4154 req = embedded_payload(wrb);
4155
4156 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4157 OPCODE_COMMON_GET_ACTIVE_PROFILE, sizeof(*req),
4158 wrb, NULL);
4159
4160 status = be_mbox_notify_wait(adapter);
4161 if (!status) {
4162 struct be_cmd_resp_get_active_profile *resp =
4163 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304164
Vasundhara Volam542963b2014-01-15 13:23:33 +05304165 *profile_id = le16_to_cpu(resp->active_profile_id);
4166 }
4167
4168err:
4169 mutex_unlock(&adapter->mbox_lock);
4170 return status;
4171}
4172
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304173int be_cmd_set_logical_link_config(struct be_adapter *adapter,
4174 int link_state, u8 domain)
4175{
4176 struct be_mcc_wrb *wrb;
4177 struct be_cmd_req_set_ll_link *req;
4178 int status;
4179
4180 if (BEx_chip(adapter) || lancer_chip(adapter))
Kalesh AP18fd6022015-01-20 03:51:45 -05004181 return -EOPNOTSUPP;
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304182
4183 spin_lock_bh(&adapter->mcc_lock);
4184
4185 wrb = wrb_from_mccq(adapter);
4186 if (!wrb) {
4187 status = -EBUSY;
4188 goto err;
4189 }
4190
4191 req = embedded_payload(wrb);
4192
4193 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4194 OPCODE_COMMON_SET_LOGICAL_LINK_CONFIG,
4195 sizeof(*req), wrb, NULL);
4196
4197 req->hdr.version = 1;
4198 req->hdr.domain = domain;
4199
4200 if (link_state == IFLA_VF_LINK_STATE_ENABLE)
4201 req->link_config |= 1;
4202
4203 if (link_state == IFLA_VF_LINK_STATE_AUTO)
4204 req->link_config |= 1 << PLINK_TRACK_SHIFT;
4205
4206 status = be_mcc_notify_wait(adapter);
4207err:
4208 spin_unlock_bh(&adapter->mcc_lock);
4209 return status;
4210}
4211
Parav Pandit6a4ab662012-03-26 14:27:12 +00004212int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05304213 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
Parav Pandit6a4ab662012-03-26 14:27:12 +00004214{
4215 struct be_adapter *adapter = netdev_priv(netdev_handle);
4216 struct be_mcc_wrb *wrb;
Kalesh AP504fbf12014-09-19 15:47:00 +05304217 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *)wrb_payload;
Parav Pandit6a4ab662012-03-26 14:27:12 +00004218 struct be_cmd_req_hdr *req;
4219 struct be_cmd_resp_hdr *resp;
4220 int status;
4221
4222 spin_lock_bh(&adapter->mcc_lock);
4223
4224 wrb = wrb_from_mccq(adapter);
4225 if (!wrb) {
4226 status = -EBUSY;
4227 goto err;
4228 }
4229 req = embedded_payload(wrb);
4230 resp = embedded_payload(wrb);
4231
4232 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
4233 hdr->opcode, wrb_payload_size, wrb, NULL);
4234 memcpy(req, wrb_payload, wrb_payload_size);
4235 be_dws_cpu_to_le(req, wrb_payload_size);
4236
4237 status = be_mcc_notify_wait(adapter);
4238 if (cmd_status)
4239 *cmd_status = (status & 0xffff);
4240 if (ext_status)
4241 *ext_status = 0;
4242 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
4243 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
4244err:
4245 spin_unlock_bh(&adapter->mcc_lock);
4246 return status;
4247}
4248EXPORT_SYMBOL(be_roce_mcc_cmd);