blob: 0e74529a42095b311c97dc367c2ba3b20bdfc27c [file] [log] [blame]
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001/*
Somnath Kotur7dfbe7d2016-06-22 08:54:56 -04002 * Copyright (C) 2005 - 2016 Broadcom
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
Ajit Khaparde51d1f982016-02-10 22:45:54 +053022char *be_misconfig_evt_port_state[] = {
23 "Physical Link is functional",
24 "Optics faulted/incorrectly installed/not installed - Reseat optics. If issue not resolved, replace.",
25 "Optics of two types installed – Remove one optic or install matching pair of optics.",
26 "Incompatible optics – Replace with compatible optics for card to function.",
27 "Unqualified optics – Replace with Avago optics for Warranty and Technical Support.",
28 "Uncertified optics – Replace with Avago-certified optics to enable link operation."
Vasundhara Volam21252372015-02-06 08:18:42 -050029};
30
Ajit Khaparde51d1f982016-02-10 22:45:54 +053031static char *be_port_misconfig_evt_severity[] = {
32 "KERN_WARN",
33 "KERN_INFO",
34 "KERN_ERR",
35 "KERN_WARN"
36};
37
38static char *phy_state_oper_desc[] = {
39 "Link is non-operational",
40 "Link is operational",
Vasundhara Volam21252372015-02-06 08:18:42 -050041 ""
42};
43
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +000044static struct be_cmd_priv_map cmd_priv_map[] = {
45 {
46 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
47 CMD_SUBSYSTEM_ETH,
48 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
49 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
50 },
51 {
52 OPCODE_COMMON_GET_FLOW_CONTROL,
53 CMD_SUBSYSTEM_COMMON,
54 BE_PRIV_LNKQUERY | BE_PRIV_VHADM |
55 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
56 },
57 {
58 OPCODE_COMMON_SET_FLOW_CONTROL,
59 CMD_SUBSYSTEM_COMMON,
60 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
61 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
62 },
63 {
64 OPCODE_ETH_GET_PPORT_STATS,
65 CMD_SUBSYSTEM_ETH,
66 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
67 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
68 },
69 {
70 OPCODE_COMMON_GET_PHY_DETAILS,
71 CMD_SUBSYSTEM_COMMON,
72 BE_PRIV_LNKMGMT | BE_PRIV_VHADM |
73 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
Somnath Kotur2e365b12016-02-03 09:49:20 +053074 },
75 {
76 OPCODE_LOWLEVEL_HOST_DDR_DMA,
77 CMD_SUBSYSTEM_LOWLEVEL,
78 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
79 },
80 {
81 OPCODE_LOWLEVEL_LOOPBACK_TEST,
82 CMD_SUBSYSTEM_LOWLEVEL,
83 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
84 },
85 {
86 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
87 CMD_SUBSYSTEM_LOWLEVEL,
88 BE_PRIV_DEVCFG | BE_PRIV_DEVSEC
89 },
Somnath Kotur884476b2016-06-22 08:54:55 -040090 {
91 OPCODE_COMMON_SET_HSW_CONFIG,
92 CMD_SUBSYSTEM_COMMON,
Venkat Duvvurud14584d2016-12-06 00:33:50 -050093 BE_PRIV_DEVCFG | BE_PRIV_VHADM |
94 BE_PRIV_DEVSEC
Somnath Kotur884476b2016-06-22 08:54:55 -040095 },
Somnath Kotur62259ac2016-09-07 19:57:51 +053096 {
97 OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES,
98 CMD_SUBSYSTEM_COMMON,
99 BE_PRIV_DEVCFG
100 }
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000101};
102
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530103static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem)
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +0000104{
105 int i;
106 int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map);
107 u32 cmd_privileges = adapter->cmd_privileges;
108
109 for (i = 0; i < num_entries; i++)
110 if (opcode == cmd_priv_map[i].opcode &&
111 subsystem == cmd_priv_map[i].subsystem)
112 if (!(cmd_privileges & cmd_priv_map[i].priv_mask))
113 return false;
114
115 return true;
116}
117
Somnath Kotur3de09452011-09-30 07:25:05 +0000118static inline void *embedded_payload(struct be_mcc_wrb *wrb)
119{
120 return wrb->payload.embedded_payload;
121}
Ajit Khaparde609ff3b2011-02-20 11:42:07 +0000122
Suresh Reddyefaa4082015-07-10 05:32:48 -0400123static int be_mcc_notify(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000124{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000125 struct be_queue_info *mccq = &adapter->mcc_obj.q;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000126 u32 val = 0;
127
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530128 if (be_check_error(adapter, BE_ERROR_ANY))
Suresh Reddyefaa4082015-07-10 05:32:48 -0400129 return -EIO;
Ajit Khaparde7acc2082011-02-11 13:38:17 +0000130
Sathya Perla5fb379e2009-06-18 00:02:59 +0000131 val |= mccq->id & DB_MCCQ_RING_ID_MASK;
132 val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT;
Sathya Perlaf3eb62d2010-06-29 00:11:17 +0000133
134 wmb();
Sathya Perla8788fdc2009-07-27 22:52:03 +0000135 iowrite32(val, adapter->db + DB_MCCQ_OFFSET);
Suresh Reddyefaa4082015-07-10 05:32:48 -0400136
137 return 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000138}
139
140/* To check if valid bit is set, check the entire word as we don't know
141 * the endianness of the data (old entry is host endian while a new entry is
142 * little endian) */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000143static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000144{
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000145 u32 flags;
146
Sathya Perla5fb379e2009-06-18 00:02:59 +0000147 if (compl->flags != 0) {
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000148 flags = le32_to_cpu(compl->flags);
149 if (flags & CQE_FLAGS_VALID_MASK) {
150 compl->flags = flags;
151 return true;
152 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000153 }
Sathya Perla9e9ff4b2013-02-12 23:05:19 +0000154 return false;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000155}
156
157/* Need to reset the entire word that houses the valid bit */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000158static inline void be_mcc_compl_use(struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000159{
160 compl->flags = 0;
161}
162
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000163static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1)
164{
165 unsigned long addr;
166
167 addr = tag1;
168 addr = ((addr << 16) << 16) | tag0;
169 return (void *)addr;
170}
171
Kalesh AP4c600052014-05-30 19:06:26 +0530172static bool be_skip_err_log(u8 opcode, u16 base_status, u16 addl_status)
173{
174 if (base_status == MCC_STATUS_NOT_SUPPORTED ||
175 base_status == MCC_STATUS_ILLEGAL_REQUEST ||
176 addl_status == MCC_ADDL_STATUS_TOO_MANY_INTERFACES ||
Kalesh AP77be8c12015-05-06 05:30:35 -0400177 addl_status == MCC_ADDL_STATUS_INSUFFICIENT_VLANS ||
Kalesh AP4c600052014-05-30 19:06:26 +0530178 (opcode == OPCODE_COMMON_WRITE_FLASHROM &&
179 (base_status == MCC_STATUS_ILLEGAL_FIELD ||
180 addl_status == MCC_ADDL_STATUS_FLASH_IMAGE_CRC_MISMATCH)))
181 return true;
182 else
183 return false;
184}
185
Sathya Perla559b6332014-05-30 19:06:27 +0530186/* Place holder for all the async MCC cmds wherein the caller is not in a busy
187 * loop (has not issued be_mcc_notify_wait())
188 */
189static void be_async_cmd_process(struct be_adapter *adapter,
190 struct be_mcc_compl *compl,
191 struct be_cmd_resp_hdr *resp_hdr)
192{
193 enum mcc_base_status base_status = base_status(compl->status);
194 u8 opcode = 0, subsystem = 0;
195
196 if (resp_hdr) {
197 opcode = resp_hdr->opcode;
198 subsystem = resp_hdr->subsystem;
199 }
200
201 if (opcode == OPCODE_LOWLEVEL_LOOPBACK_TEST &&
202 subsystem == CMD_SUBSYSTEM_LOWLEVEL) {
203 complete(&adapter->et_cmd_compl);
204 return;
205 }
206
Suresh Reddy9c855972015-07-10 05:32:50 -0400207 if (opcode == OPCODE_LOWLEVEL_SET_LOOPBACK_MODE &&
208 subsystem == CMD_SUBSYSTEM_LOWLEVEL) {
209 complete(&adapter->et_cmd_compl);
210 return;
211 }
212
Sathya Perla559b6332014-05-30 19:06:27 +0530213 if ((opcode == OPCODE_COMMON_WRITE_FLASHROM ||
214 opcode == OPCODE_COMMON_WRITE_OBJECT) &&
215 subsystem == CMD_SUBSYSTEM_COMMON) {
216 adapter->flash_status = compl->status;
217 complete(&adapter->et_cmd_compl);
218 return;
219 }
220
221 if ((opcode == OPCODE_ETH_GET_STATISTICS ||
222 opcode == OPCODE_ETH_GET_PPORT_STATS) &&
223 subsystem == CMD_SUBSYSTEM_ETH &&
224 base_status == MCC_STATUS_SUCCESS) {
225 be_parse_stats(adapter);
226 adapter->stats_cmd_sent = false;
227 return;
228 }
229
230 if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES &&
231 subsystem == CMD_SUBSYSTEM_COMMON) {
232 if (base_status == MCC_STATUS_SUCCESS) {
233 struct be_cmd_resp_get_cntl_addnl_attribs *resp =
234 (void *)resp_hdr;
Venkata Duvvuru29e91222015-05-13 13:00:12 +0530235 adapter->hwmon_info.be_on_die_temp =
Sathya Perla559b6332014-05-30 19:06:27 +0530236 resp->on_die_temperature;
237 } else {
238 adapter->be_get_temp_freq = 0;
Venkata Duvvuru29e91222015-05-13 13:00:12 +0530239 adapter->hwmon_info.be_on_die_temp =
240 BE_INVALID_DIE_TEMP;
Sathya Perla559b6332014-05-30 19:06:27 +0530241 }
242 return;
243 }
244}
245
Sathya Perla8788fdc2009-07-27 22:52:03 +0000246static int be_mcc_compl_process(struct be_adapter *adapter,
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000247 struct be_mcc_compl *compl)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000248{
Kalesh AP4c600052014-05-30 19:06:26 +0530249 enum mcc_base_status base_status;
250 enum mcc_addl_status addl_status;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000251 struct be_cmd_resp_hdr *resp_hdr;
252 u8 opcode = 0, subsystem = 0;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000253
254 /* Just swap the status to host endian; mcc tag is opaquely copied
255 * from mcc_wrb */
256 be_dws_le_to_cpu(compl, 4);
257
Kalesh AP4c600052014-05-30 19:06:26 +0530258 base_status = base_status(compl->status);
259 addl_status = addl_status(compl->status);
Vasundhara Volam96c9b2e2014-05-30 19:06:25 +0530260
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000261 resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000262 if (resp_hdr) {
263 opcode = resp_hdr->opcode;
264 subsystem = resp_hdr->subsystem;
265 }
266
Sathya Perla559b6332014-05-30 19:06:27 +0530267 be_async_cmd_process(adapter, compl, resp_hdr);
Suresh Reddy5eeff632014-01-06 13:02:24 +0530268
Sathya Perla559b6332014-05-30 19:06:27 +0530269 if (base_status != MCC_STATUS_SUCCESS &&
270 !be_skip_err_log(opcode, base_status, addl_status)) {
Suresh Reddyfa5c8672016-02-03 09:49:17 +0530271 if (base_status == MCC_STATUS_UNAUTHORIZED_REQUEST ||
272 addl_status == MCC_ADDL_STATUS_INSUFFICIENT_PRIVILEGES) {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000273 dev_warn(&adapter->pdev->dev,
Vasundhara Volam522609f2012-08-28 20:37:44 +0000274 "VF is not privileged to issue opcode %d-%d\n",
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000275 opcode, subsystem);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000276 } else {
Vasundhara Volam97f1d8c2012-06-13 19:51:44 +0000277 dev_err(&adapter->pdev->dev,
278 "opcode %d-%d failed:status %d-%d\n",
Kalesh AP4c600052014-05-30 19:06:26 +0530279 opcode, subsystem, base_status, addl_status);
Sathya Perla2b3f2912011-06-29 23:32:56 +0000280 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000281 }
Kalesh AP4c600052014-05-30 19:06:26 +0530282 return compl->status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000283}
284
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000285/* Link state evt is a string of bytes; no need for endian swapping */
Sathya Perla8788fdc2009-07-27 22:52:03 +0000286static void be_async_link_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530287 struct be_mcc_compl *compl)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000288{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530289 struct be_async_event_link_state *evt =
290 (struct be_async_event_link_state *)compl;
291
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000292 /* When link status changes, link speed must be re-queried from FW */
Ajit Khaparde42f11cf2012-04-21 18:53:22 +0000293 adapter->phy.link_speed = -1;
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000294
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530295 /* On BEx the FW does not send a separate link status
296 * notification for physical and logical link.
297 * On other chips just process the logical link
298 * status notification
299 */
300 if (!BEx_chip(adapter) &&
Padmanabh Ratnakar2e177a52012-07-18 02:52:15 +0000301 !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK))
302 return;
303
Ajit Khapardeb236916a2011-12-30 12:15:40 +0000304 /* For the initial link status do not rely on the ASYNC event as
305 * it may not be received in some cases.
306 */
307 if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT)
Suresh Reddybdce2ad2014-03-11 18:53:04 +0530308 be_link_status_update(adapter,
309 evt->port_link_status & LINK_STATUS_MASK);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000310}
311
Vasundhara Volam21252372015-02-06 08:18:42 -0500312static void be_async_port_misconfig_event_process(struct be_adapter *adapter,
313 struct be_mcc_compl *compl)
314{
315 struct be_async_event_misconfig_port *evt =
316 (struct be_async_event_misconfig_port *)compl;
Ajit Khaparde51d1f982016-02-10 22:45:54 +0530317 u32 sfp_misconfig_evt_word1 = le32_to_cpu(evt->event_data_word1);
318 u32 sfp_misconfig_evt_word2 = le32_to_cpu(evt->event_data_word2);
319 u8 phy_oper_state = PHY_STATE_OPER_MSG_NONE;
Vasundhara Volam21252372015-02-06 08:18:42 -0500320 struct device *dev = &adapter->pdev->dev;
Ajit Khaparde51d1f982016-02-10 22:45:54 +0530321 u8 msg_severity = DEFAULT_MSG_SEVERITY;
322 u8 phy_state_info;
323 u8 new_phy_state;
Vasundhara Volam21252372015-02-06 08:18:42 -0500324
Ajit Khaparde51d1f982016-02-10 22:45:54 +0530325 new_phy_state =
326 (sfp_misconfig_evt_word1 >> (adapter->hba_port_num * 8)) & 0xff;
Vasundhara Volam21252372015-02-06 08:18:42 -0500327
Ajit Khaparde51d1f982016-02-10 22:45:54 +0530328 if (new_phy_state == adapter->phy_state)
329 return;
330
331 adapter->phy_state = new_phy_state;
332
333 /* for older fw that doesn't populate link effect data */
334 if (!sfp_misconfig_evt_word2)
335 goto log_message;
336
337 phy_state_info =
338 (sfp_misconfig_evt_word2 >> (adapter->hba_port_num * 8)) & 0xff;
339
340 if (phy_state_info & PHY_STATE_INFO_VALID) {
341 msg_severity = (phy_state_info & PHY_STATE_MSG_SEVERITY) >> 1;
342
343 if (be_phy_unqualified(new_phy_state))
344 phy_oper_state = (phy_state_info & PHY_STATE_OPER);
345 }
346
347log_message:
Vasundhara Volam21252372015-02-06 08:18:42 -0500348 /* Log an error message that would allow a user to determine
349 * whether the SFPs have an issue
350 */
Ajit Khaparde51d1f982016-02-10 22:45:54 +0530351 if (be_phy_state_unknown(new_phy_state))
352 dev_printk(be_port_misconfig_evt_severity[msg_severity], dev,
353 "Port %c: Unrecognized Optics state: 0x%x. %s",
354 adapter->port_name,
355 new_phy_state,
356 phy_state_oper_desc[phy_oper_state]);
357 else
358 dev_printk(be_port_misconfig_evt_severity[msg_severity], dev,
359 "Port %c: %s %s",
360 adapter->port_name,
361 be_misconfig_evt_port_state[new_phy_state],
362 phy_state_oper_desc[phy_oper_state]);
Vasundhara Volam21252372015-02-06 08:18:42 -0500363
Ajit Khaparde51d1f982016-02-10 22:45:54 +0530364 /* Log Vendor name and part no. if a misconfigured SFP is detected */
365 if (be_phy_misconfigured(new_phy_state))
366 adapter->flags |= BE_FLAGS_PHY_MISCONFIGURED;
Vasundhara Volam21252372015-02-06 08:18:42 -0500367}
368
Somnath Koturcc4ce022010-10-21 07:11:14 -0700369/* Grp5 CoS Priority evt */
370static void be_async_grp5_cos_priority_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530371 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700372{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530373 struct be_async_event_grp5_cos_priority *evt =
374 (struct be_async_event_grp5_cos_priority *)compl;
375
Somnath Koturcc4ce022010-10-21 07:11:14 -0700376 if (evt->valid) {
377 adapter->vlan_prio_bmap = evt->available_priority_bmap;
Sathya Perlafdf81bf2015-12-30 01:29:01 -0500378 adapter->recommended_prio_bits =
Somnath Koturcc4ce022010-10-21 07:11:14 -0700379 evt->reco_default_priority << VLAN_PRIO_SHIFT;
380 }
381}
382
Sathya Perla323ff712012-09-28 04:39:43 +0000383/* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */
Somnath Koturcc4ce022010-10-21 07:11:14 -0700384static void be_async_grp5_qos_speed_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530385 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700386{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530387 struct be_async_event_grp5_qos_link_speed *evt =
388 (struct be_async_event_grp5_qos_link_speed *)compl;
389
Sathya Perla323ff712012-09-28 04:39:43 +0000390 if (adapter->phy.link_speed >= 0 &&
391 evt->physical_port == adapter->port_num)
392 adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700393}
394
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000395/*Grp5 PVID evt*/
396static void be_async_grp5_pvid_state_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530397 struct be_mcc_compl *compl)
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000398{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530399 struct be_async_event_grp5_pvid_state *evt =
400 (struct be_async_event_grp5_pvid_state *)compl;
401
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530402 if (evt->enabled) {
Somnath Kotur939cf302011-08-18 21:51:49 -0700403 adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530404 dev_info(&adapter->pdev->dev, "LPVID: %d\n", adapter->pvid);
405 } else {
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000406 adapter->pvid = 0;
Ravikumar Nelavellibdac85b2014-03-11 18:53:05 +0530407 }
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000408}
409
Venkata Duvvuru760c2952015-05-13 13:00:14 +0530410#define MGMT_ENABLE_MASK 0x4
411static void be_async_grp5_fw_control_process(struct be_adapter *adapter,
412 struct be_mcc_compl *compl)
413{
414 struct be_async_fw_control *evt = (struct be_async_fw_control *)compl;
415 u32 evt_dw1 = le32_to_cpu(evt->event_data_word1);
416
417 if (evt_dw1 & MGMT_ENABLE_MASK) {
418 adapter->flags |= BE_FLAGS_OS2BMC;
419 adapter->bmc_filt_mask = le32_to_cpu(evt->event_data_word2);
420 } else {
421 adapter->flags &= ~BE_FLAGS_OS2BMC;
422 }
423}
424
Somnath Koturcc4ce022010-10-21 07:11:14 -0700425static void be_async_grp5_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530426 struct be_mcc_compl *compl)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700427{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530428 u8 event_type = (compl->flags >> ASYNC_EVENT_TYPE_SHIFT) &
429 ASYNC_EVENT_TYPE_MASK;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700430
431 switch (event_type) {
432 case ASYNC_EVENT_COS_PRIORITY:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530433 be_async_grp5_cos_priority_process(adapter, compl);
434 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700435 case ASYNC_EVENT_QOS_SPEED:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530436 be_async_grp5_qos_speed_process(adapter, compl);
437 break;
Ajit Khaparde3968fa12011-02-20 11:41:53 +0000438 case ASYNC_EVENT_PVID_STATE:
Sathya Perla3acf19d2014-05-30 19:06:28 +0530439 be_async_grp5_pvid_state_process(adapter, compl);
440 break;
Venkata Duvvuru760c2952015-05-13 13:00:14 +0530441 /* Async event to disable/enable os2bmc and/or mac-learning */
442 case ASYNC_EVENT_FW_CONTROL:
443 be_async_grp5_fw_control_process(adapter, compl);
444 break;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700445 default:
Somnath Koturcc4ce022010-10-21 07:11:14 -0700446 break;
447 }
448}
449
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000450static void be_async_dbg_evt_process(struct be_adapter *adapter,
Sathya Perla3acf19d2014-05-30 19:06:28 +0530451 struct be_mcc_compl *cmp)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000452{
453 u8 event_type = 0;
Kalesh AP504fbf12014-09-19 15:47:00 +0530454 struct be_async_event_qnq *evt = (struct be_async_event_qnq *)cmp;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000455
Sathya Perla3acf19d2014-05-30 19:06:28 +0530456 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
457 ASYNC_EVENT_TYPE_MASK;
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000458
459 switch (event_type) {
460 case ASYNC_DEBUG_EVENT_TYPE_QNQ:
461 if (evt->valid)
462 adapter->qnq_vid = le16_to_cpu(evt->vlan_tag);
463 adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD;
464 break;
465 default:
Vasundhara Volam05ccaa22013-08-06 09:27:19 +0530466 dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n",
467 event_type);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000468 break;
469 }
470}
471
Vasundhara Volam21252372015-02-06 08:18:42 -0500472static void be_async_sliport_evt_process(struct be_adapter *adapter,
473 struct be_mcc_compl *cmp)
474{
475 u8 event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) &
476 ASYNC_EVENT_TYPE_MASK;
477
478 if (event_type == ASYNC_EVENT_PORT_MISCONFIG)
479 be_async_port_misconfig_event_process(adapter, cmp);
480}
481
Sathya Perla3acf19d2014-05-30 19:06:28 +0530482static inline bool is_link_state_evt(u32 flags)
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000483{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530484 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
485 ASYNC_EVENT_CODE_LINK_STATE;
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000486}
Sathya Perla5fb379e2009-06-18 00:02:59 +0000487
Sathya Perla3acf19d2014-05-30 19:06:28 +0530488static inline bool is_grp5_evt(u32 flags)
Somnath Koturcc4ce022010-10-21 07:11:14 -0700489{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530490 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
491 ASYNC_EVENT_CODE_GRP_5;
Somnath Koturcc4ce022010-10-21 07:11:14 -0700492}
493
Sathya Perla3acf19d2014-05-30 19:06:28 +0530494static inline bool is_dbg_evt(u32 flags)
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000495{
Sathya Perla3acf19d2014-05-30 19:06:28 +0530496 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
497 ASYNC_EVENT_CODE_QNQ;
498}
499
Vasundhara Volam21252372015-02-06 08:18:42 -0500500static inline bool is_sliport_evt(u32 flags)
501{
502 return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) ==
503 ASYNC_EVENT_CODE_SLIPORT;
504}
505
Sathya Perla3acf19d2014-05-30 19:06:28 +0530506static void be_mcc_event_process(struct be_adapter *adapter,
507 struct be_mcc_compl *compl)
508{
509 if (is_link_state_evt(compl->flags))
510 be_async_link_state_process(adapter, compl);
511 else if (is_grp5_evt(compl->flags))
512 be_async_grp5_evt_process(adapter, compl);
513 else if (is_dbg_evt(compl->flags))
514 be_async_dbg_evt_process(adapter, compl);
Vasundhara Volam21252372015-02-06 08:18:42 -0500515 else if (is_sliport_evt(compl->flags))
516 be_async_sliport_evt_process(adapter, compl);
Ajit Khapardebc0c3402013-04-24 11:52:50 +0000517}
518
Sathya Perlaefd2e402009-07-27 22:53:10 +0000519static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000520{
Sathya Perla8788fdc2009-07-27 22:52:03 +0000521 struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000522 struct be_mcc_compl *compl = queue_tail_node(mcc_cq);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000523
524 if (be_mcc_compl_is_new(compl)) {
525 queue_tail_inc(mcc_cq);
526 return compl;
527 }
528 return NULL;
529}
530
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000531void be_async_mcc_enable(struct be_adapter *adapter)
532{
533 spin_lock_bh(&adapter->mcc_cq_lock);
534
535 be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0);
536 adapter->mcc_obj.rearm_cq = true;
537
538 spin_unlock_bh(&adapter->mcc_cq_lock);
539}
540
541void be_async_mcc_disable(struct be_adapter *adapter)
542{
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000543 spin_lock_bh(&adapter->mcc_cq_lock);
544
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000545 adapter->mcc_obj.rearm_cq = false;
Sathya Perlaa323d9b2012-12-17 19:38:50 +0000546 be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0);
547
548 spin_unlock_bh(&adapter->mcc_cq_lock);
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000549}
550
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000551int be_process_mcc(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000552{
Sathya Perlaefd2e402009-07-27 22:53:10 +0000553 struct be_mcc_compl *compl;
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000554 int num = 0, status = 0;
Sathya Perla7a1e9b22010-02-17 01:35:11 +0000555 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000556
Amerigo Wang072a9c42012-08-24 21:41:11 +0000557 spin_lock(&adapter->mcc_cq_lock);
Sathya Perla3acf19d2014-05-30 19:06:28 +0530558
Sathya Perla8788fdc2009-07-27 22:52:03 +0000559 while ((compl = be_mcc_compl_get(adapter))) {
Sathya Perlaa8f447bd2009-06-18 00:10:27 +0000560 if (compl->flags & CQE_FLAGS_ASYNC_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530561 be_mcc_event_process(adapter, compl);
Sathya Perlab31c50a2009-09-17 10:30:13 -0700562 } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) {
Sathya Perla3acf19d2014-05-30 19:06:28 +0530563 status = be_mcc_compl_process(adapter, compl);
564 atomic_dec(&mcc_obj->q.used);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000565 }
566 be_mcc_compl_use(compl);
567 num++;
568 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700569
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000570 if (num)
571 be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num);
572
Amerigo Wang072a9c42012-08-24 21:41:11 +0000573 spin_unlock(&adapter->mcc_cq_lock);
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000574 return status;
Sathya Perla5fb379e2009-06-18 00:02:59 +0000575}
576
Sathya Perla6ac7b682009-06-18 00:05:54 +0000577/* Wait till no more pending mcc requests are present */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700578static int be_mcc_wait_compl(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000579{
Sathya Perlab7172412016-07-27 05:26:18 -0400580#define mcc_timeout 12000 /* 12s timeout */
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000581 int i, status = 0;
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800582 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700583
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800584 for (i = 0; i < mcc_timeout; i++) {
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530585 if (be_check_error(adapter, BE_ERROR_ANY))
Sathya Perla6589ade2011-11-10 19:18:00 +0000586 return -EIO;
587
Amerigo Wang072a9c42012-08-24 21:41:11 +0000588 local_bh_disable();
Sathya Perla10ef9ab2012-02-09 18:05:27 +0000589 status = be_process_mcc(adapter);
Amerigo Wang072a9c42012-08-24 21:41:11 +0000590 local_bh_enable();
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800591
592 if (atomic_read(&mcc_obj->q.used) == 0)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000593 break;
Sathya Perlab7172412016-07-27 05:26:18 -0400594 usleep_range(500, 1000);
Sathya Perla6ac7b682009-06-18 00:05:54 +0000595 }
Sathya Perlab31c50a2009-09-17 10:30:13 -0700596 if (i == mcc_timeout) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000597 dev_err(&adapter->pdev->dev, "FW not responding\n");
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530598 be_set_error(adapter, BE_ERROR_FW);
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000599 return -EIO;
Sathya Perlab31c50a2009-09-17 10:30:13 -0700600 }
Sathya Perlaf31e50a2010-03-02 03:56:39 -0800601 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000602}
603
604/* Notify MCC requests and wait for completion */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700605static int be_mcc_notify_wait(struct be_adapter *adapter)
Sathya Perla6ac7b682009-06-18 00:05:54 +0000606{
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000607 int status;
608 struct be_mcc_wrb *wrb;
609 struct be_mcc_obj *mcc_obj = &adapter->mcc_obj;
ajit.khaparde@broadcom.comb0fd2eb2016-02-23 00:33:48 +0530610 u32 index = mcc_obj->q.head;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000611 struct be_cmd_resp_hdr *resp;
612
613 index_dec(&index, mcc_obj->q.len);
614 wrb = queue_index_node(&mcc_obj->q, index);
615
616 resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1);
617
Suresh Reddyefaa4082015-07-10 05:32:48 -0400618 status = be_mcc_notify(adapter);
619 if (status)
620 goto out;
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000621
622 status = be_mcc_wait_compl(adapter);
623 if (status == -EIO)
624 goto out;
625
Kalesh AP4c600052014-05-30 19:06:26 +0530626 status = (resp->base_status |
627 ((resp->addl_status & CQE_ADDL_STATUS_MASK) <<
628 CQE_ADDL_STATUS_SHIFT));
Padmanabh Ratnakar652bf642012-04-25 01:47:03 +0000629out:
630 return status;
Sathya Perla6ac7b682009-06-18 00:05:54 +0000631}
632
Sathya Perla5f0b8492009-07-27 22:52:56 +0000633static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700634{
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000635 int msecs = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700636 u32 ready;
637
638 do {
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530639 if (be_check_error(adapter, BE_ERROR_ANY))
Sathya Perla6589ade2011-11-10 19:18:00 +0000640 return -EIO;
641
Sathya Perlacf588472010-02-14 21:22:01 +0000642 ready = ioread32(db);
Sathya Perla434b3642011-11-10 19:17:59 +0000643 if (ready == 0xffffffff)
Sathya Perlacf588472010-02-14 21:22:01 +0000644 return -1;
Sathya Perlacf588472010-02-14 21:22:01 +0000645
646 ready &= MPU_MAILBOX_DB_RDY_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700647 if (ready)
648 break;
649
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000650 if (msecs > 4000) {
Sathya Perla6589ade2011-11-10 19:18:00 +0000651 dev_err(&adapter->pdev->dev, "FW not responding\n");
Venkata Duvvuru954f6822015-05-13 13:00:13 +0530652 be_set_error(adapter, BE_ERROR_FW);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +0000653 be_detect_error(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700654 return -1;
655 }
656
Sathya Perla1dbf53a2011-05-12 19:32:16 +0000657 msleep(1);
Sathya Perlaf25b03a2010-05-30 23:34:14 +0000658 msecs++;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700659 } while (true);
660
661 return 0;
662}
663
664/*
665 * Insert the mailbox address into the doorbell in two steps
Sathya Perla5fb379e2009-06-18 00:02:59 +0000666 * Polls on the mbox doorbell till a command completion (or a timeout) occurs
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700667 */
Sathya Perlab31c50a2009-09-17 10:30:13 -0700668static int be_mbox_notify_wait(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700669{
670 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700671 u32 val = 0;
Sathya Perla8788fdc2009-07-27 22:52:03 +0000672 void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET;
673 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700674 struct be_mcc_mailbox *mbox = mbox_mem->va;
Sathya Perlaefd2e402009-07-27 22:53:10 +0000675 struct be_mcc_compl *compl = &mbox->compl;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700676
Sathya Perlacf588472010-02-14 21:22:01 +0000677 /* wait for ready to be set */
678 status = be_mbox_db_ready_wait(adapter, db);
679 if (status != 0)
680 return status;
681
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700682 val |= MPU_MAILBOX_DB_HI_MASK;
683 /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */
684 val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2;
685 iowrite32(val, db);
686
687 /* wait for ready to be set */
Sathya Perla5f0b8492009-07-27 22:52:56 +0000688 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700689 if (status != 0)
690 return status;
691
692 val = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700693 /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */
694 val |= (u32)(mbox_mem->dma >> 4) << 2;
695 iowrite32(val, db);
696
Sathya Perla5f0b8492009-07-27 22:52:56 +0000697 status = be_mbox_db_ready_wait(adapter, db);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700698 if (status != 0)
699 return status;
700
Sathya Perla5fb379e2009-06-18 00:02:59 +0000701 /* A cq entry has been made now */
Sathya Perlaefd2e402009-07-27 22:53:10 +0000702 if (be_mcc_compl_is_new(compl)) {
703 status = be_mcc_compl_process(adapter, &mbox->compl);
704 be_mcc_compl_use(compl);
Sathya Perla5fb379e2009-06-18 00:02:59 +0000705 if (status)
706 return status;
707 } else {
Sathya Perla5f0b8492009-07-27 22:52:56 +0000708 dev_err(&adapter->pdev->dev, "invalid mailbox completion\n");
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700709 return -1;
710 }
Sathya Perla5fb379e2009-06-18 00:02:59 +0000711 return 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700712}
713
Sriharsha Basavapatna710f3e52016-09-07 19:57:49 +0530714u16 be_POST_stage_get(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700715{
Sathya Perlafe6d2a32010-11-21 23:25:50 +0000716 u32 sem;
717
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000718 if (BEx_chip(adapter))
719 sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700720 else
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000721 pci_read_config_dword(adapter->pdev,
722 SLIPORT_SEMAPHORE_OFFSET_SH, &sem);
723
724 return sem & POST_STAGE_MASK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700725}
726
Gavin Shan87f20c22013-10-29 17:30:57 +0800727static int lancer_wait_ready(struct be_adapter *adapter)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000728{
729#define SLIPORT_READY_TIMEOUT 30
730 u32 sliport_status;
Kalesh APe6732442015-01-20 03:51:46 -0500731 int i;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000732
733 for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) {
734 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
735 if (sliport_status & SLIPORT_STATUS_RDY_MASK)
Sathya Perla9fa465c2015-02-23 04:20:13 -0500736 return 0;
737
738 if (sliport_status & SLIPORT_STATUS_ERR_MASK &&
739 !(sliport_status & SLIPORT_STATUS_RN_MASK))
740 return -EIO;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000741
742 msleep(1000);
743 }
744
Sathya Perla9fa465c2015-02-23 04:20:13 -0500745 return sliport_status ? : -1;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000746}
747
748int be_fw_wait_ready(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700749{
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000750 u16 stage;
751 int status, timeout = 0;
Sathya Perla6ed35ee2011-05-12 19:32:15 +0000752 struct device *dev = &adapter->pdev->dev;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700753
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000754 if (lancer_chip(adapter)) {
755 status = lancer_wait_ready(adapter);
Kalesh APe6732442015-01-20 03:51:46 -0500756 if (status) {
757 stage = status;
758 goto err;
759 }
760 return 0;
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000761 }
762
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000763 do {
Sathya Perlaca3de6b2015-02-23 04:20:10 -0500764 /* There's no means to poll POST state on BE2/3 VFs */
765 if (BEx_chip(adapter) && be_virtfn(adapter))
766 return 0;
767
Sathya Perlac5b3ad42013-03-05 22:23:20 +0000768 stage = be_POST_stage_get(adapter);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000769 if (stage == POST_STAGE_ARMFW_RDY)
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000770 return 0;
Gavin Shan66d29cb2013-03-03 21:48:46 +0000771
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530772 dev_info(dev, "Waiting for POST, %ds elapsed\n", timeout);
Gavin Shan66d29cb2013-03-03 21:48:46 +0000773 if (msleep_interruptible(2000)) {
774 dev_err(dev, "Waiting for POST aborted\n");
775 return -EINTR;
Sathya Perla43a04fdc2009-10-14 20:21:17 +0000776 }
Gavin Shan66d29cb2013-03-03 21:48:46 +0000777 timeout += 2;
Somnath Kotur3ab81b52011-10-03 08:10:57 +0000778 } while (timeout < 60);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700779
Kalesh APe6732442015-01-20 03:51:46 -0500780err:
781 dev_err(dev, "POST timeout; stage=%#x\n", stage);
Sathya Perla9fa465c2015-02-23 04:20:13 -0500782 return -ETIMEDOUT;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700783}
784
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700785static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb)
786{
787 return &wrb->payload.sgl[0];
788}
789
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530790static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, unsigned long addr)
Sathya Perlabea50982013-08-27 16:57:33 +0530791{
792 wrb->tag0 = addr & 0xFFFFFFFF;
793 wrb->tag1 = upper_32_bits(addr);
794}
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700795
796/* Don't touch the hdr after it's prepared */
Somnath Kotur106df1e2011-10-27 07:12:13 +0000797/* mem will be NULL for embedded commands */
798static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530799 u8 subsystem, u8 opcode, int cmd_len,
800 struct be_mcc_wrb *wrb,
801 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700802{
Somnath Kotur106df1e2011-10-27 07:12:13 +0000803 struct be_sge *sge;
804
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700805 req_hdr->opcode = opcode;
806 req_hdr->subsystem = subsystem;
807 req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr));
Ajit Khaparde07793d32010-02-16 00:18:46 +0000808 req_hdr->version = 0;
Sathya Perlabea50982013-08-27 16:57:33 +0530809 fill_wrb_tags(wrb, (ulong) req_hdr);
Somnath Kotur106df1e2011-10-27 07:12:13 +0000810 wrb->payload_length = cmd_len;
811 if (mem) {
812 wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) <<
813 MCC_WRB_SGE_CNT_SHIFT;
814 sge = nonembedded_sgl(wrb);
815 sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma));
816 sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF);
817 sge->len = cpu_to_le32(mem->size);
818 } else
819 wrb->embedded |= MCC_WRB_EMBEDDED_MASK;
820 be_dws_cpu_to_le(wrb, 8);
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700821}
822
823static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +0530824 struct be_dma_mem *mem)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700825{
826 int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages);
827 u64 dma = (u64)mem->dma;
828
829 for (i = 0; i < buf_pages; i++) {
830 pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF);
831 pages[i].hi = cpu_to_le32(upper_32_bits(dma));
832 dma += PAGE_SIZE_4K;
833 }
834}
835
Sathya Perlab31c50a2009-09-17 10:30:13 -0700836static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700837{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700838 struct be_dma_mem *mbox_mem = &adapter->mbox_mem;
839 struct be_mcc_wrb *wrb
840 = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb;
841 memset(wrb, 0, sizeof(*wrb));
842 return wrb;
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700843}
844
Sathya Perlab31c50a2009-09-17 10:30:13 -0700845static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter)
Sathya Perla5fb379e2009-06-18 00:02:59 +0000846{
Sathya Perlab31c50a2009-09-17 10:30:13 -0700847 struct be_queue_info *mccq = &adapter->mcc_obj.q;
848 struct be_mcc_wrb *wrb;
849
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +0000850 if (!mccq->created)
851 return NULL;
852
Vasundhara Volam4d277122013-04-21 23:28:15 +0000853 if (atomic_read(&mccq->used) >= mccq->len)
Sathya Perla713d03942009-11-22 22:02:45 +0000854 return NULL;
Sathya Perla713d03942009-11-22 22:02:45 +0000855
Sathya Perlab31c50a2009-09-17 10:30:13 -0700856 wrb = queue_head_node(mccq);
857 queue_head_inc(mccq);
858 atomic_inc(&mccq->used);
859 memset(wrb, 0, sizeof(*wrb));
Sathya Perla5fb379e2009-06-18 00:02:59 +0000860 return wrb;
861}
862
Sathya Perlabea50982013-08-27 16:57:33 +0530863static bool use_mcc(struct be_adapter *adapter)
864{
865 return adapter->mcc_obj.q.created;
866}
867
868/* Must be used only in process context */
869static int be_cmd_lock(struct be_adapter *adapter)
870{
871 if (use_mcc(adapter)) {
Sathya Perlab7172412016-07-27 05:26:18 -0400872 mutex_lock(&adapter->mcc_lock);
Sathya Perlabea50982013-08-27 16:57:33 +0530873 return 0;
874 } else {
875 return mutex_lock_interruptible(&adapter->mbox_lock);
876 }
877}
878
879/* Must be used only in process context */
880static void be_cmd_unlock(struct be_adapter *adapter)
881{
882 if (use_mcc(adapter))
Sathya Perlab7172412016-07-27 05:26:18 -0400883 return mutex_unlock(&adapter->mcc_lock);
Sathya Perlabea50982013-08-27 16:57:33 +0530884 else
885 return mutex_unlock(&adapter->mbox_lock);
886}
887
888static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter,
889 struct be_mcc_wrb *wrb)
890{
891 struct be_mcc_wrb *dest_wrb;
892
893 if (use_mcc(adapter)) {
894 dest_wrb = wrb_from_mccq(adapter);
895 if (!dest_wrb)
896 return NULL;
897 } else {
898 dest_wrb = wrb_from_mbox(adapter);
899 }
900
901 memcpy(dest_wrb, wrb, sizeof(*wrb));
902 if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK))
903 fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb));
904
905 return dest_wrb;
906}
907
908/* Must be used only in process context */
909static int be_cmd_notify_wait(struct be_adapter *adapter,
910 struct be_mcc_wrb *wrb)
911{
912 struct be_mcc_wrb *dest_wrb;
913 int status;
914
915 status = be_cmd_lock(adapter);
916 if (status)
917 return status;
918
919 dest_wrb = be_cmd_copy(adapter, wrb);
Suresh Reddy0c884562015-10-12 03:47:18 -0400920 if (!dest_wrb) {
921 status = -EBUSY;
922 goto unlock;
923 }
Sathya Perlabea50982013-08-27 16:57:33 +0530924
925 if (use_mcc(adapter))
926 status = be_mcc_notify_wait(adapter);
927 else
928 status = be_mbox_notify_wait(adapter);
929
930 if (!status)
931 memcpy(wrb, dest_wrb, sizeof(*wrb));
932
Suresh Reddy0c884562015-10-12 03:47:18 -0400933unlock:
Sathya Perlabea50982013-08-27 16:57:33 +0530934 be_cmd_unlock(adapter);
935 return status;
936}
937
Sathya Perla2243e2e2009-11-22 22:02:03 +0000938/* Tell fw we're about to start firing cmds by writing a
939 * special pattern across the wrb hdr; uses mbox
940 */
941int be_cmd_fw_init(struct be_adapter *adapter)
942{
943 u8 *wrb;
944 int status;
945
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000946 if (lancer_chip(adapter))
947 return 0;
948
Ivan Vecera29849612010-12-14 05:43:19 +0000949 if (mutex_lock_interruptible(&adapter->mbox_lock))
950 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000951
952 wrb = (u8 *)wrb_from_mbox(adapter);
Sathya Perla359a9722010-12-01 01:03:36 +0000953 *wrb++ = 0xFF;
954 *wrb++ = 0x12;
955 *wrb++ = 0x34;
956 *wrb++ = 0xFF;
957 *wrb++ = 0xFF;
958 *wrb++ = 0x56;
959 *wrb++ = 0x78;
960 *wrb = 0xFF;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000961
962 status = be_mbox_notify_wait(adapter);
963
Ivan Vecera29849612010-12-14 05:43:19 +0000964 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000965 return status;
966}
967
968/* Tell fw we're done with firing cmds by writing a
969 * special pattern across the wrb hdr; uses mbox
970 */
971int be_cmd_fw_clean(struct be_adapter *adapter)
972{
973 u8 *wrb;
974 int status;
975
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000976 if (lancer_chip(adapter))
977 return 0;
978
Ivan Vecera29849612010-12-14 05:43:19 +0000979 if (mutex_lock_interruptible(&adapter->mbox_lock))
980 return -1;
Sathya Perla2243e2e2009-11-22 22:02:03 +0000981
982 wrb = (u8 *)wrb_from_mbox(adapter);
983 *wrb++ = 0xFF;
984 *wrb++ = 0xAA;
985 *wrb++ = 0xBB;
986 *wrb++ = 0xFF;
987 *wrb++ = 0xFF;
988 *wrb++ = 0xCC;
989 *wrb++ = 0xDD;
990 *wrb = 0xFF;
991
992 status = be_mbox_notify_wait(adapter);
993
Ivan Vecera29849612010-12-14 05:43:19 +0000994 mutex_unlock(&adapter->mbox_lock);
Sathya Perla2243e2e2009-11-22 22:02:03 +0000995 return status;
996}
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +0000997
Sathya Perlaf2f781a2013-08-27 16:57:30 +0530998int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -0700999{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001000 struct be_mcc_wrb *wrb;
1001 struct be_cmd_req_eq_create *req;
Sathya Perlaf2f781a2013-08-27 16:57:30 +05301002 struct be_dma_mem *q_mem = &eqo->q.dma_mem;
1003 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001004
Ivan Vecera29849612010-12-14 05:43:19 +00001005 if (mutex_lock_interruptible(&adapter->mbox_lock))
1006 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001007
1008 wrb = wrb_from_mbox(adapter);
1009 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001010
Somnath Kotur106df1e2011-10-27 07:12:13 +00001011 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301012 OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb,
1013 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001014
Sathya Perlaf2f781a2013-08-27 16:57:30 +05301015 /* Support for EQ_CREATEv2 available only SH-R onwards */
1016 if (!(BEx_chip(adapter) || lancer_chip(adapter)))
1017 ver = 2;
1018
1019 req->hdr.version = ver;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001020 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1021
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001022 AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1);
1023 /* 4byte eqe*/
1024 AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0);
1025 AMAP_SET_BITS(struct amap_eq_context, count, req->context,
Sathya Perlaf2f781a2013-08-27 16:57:30 +05301026 __ilog2_u32(eqo->q.len / 256));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001027 be_dws_cpu_to_le(req->context, sizeof(req->context));
1028
1029 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1030
Sathya Perlab31c50a2009-09-17 10:30:13 -07001031 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001032 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001033 struct be_cmd_resp_eq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301034
Sathya Perlaf2f781a2013-08-27 16:57:30 +05301035 eqo->q.id = le16_to_cpu(resp->eq_id);
1036 eqo->msix_idx =
1037 (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx;
1038 eqo->q.created = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001039 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001040
Ivan Vecera29849612010-12-14 05:43:19 +00001041 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001042 return status;
1043}
1044
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001045/* Use MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001046int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perla5ee49792012-09-28 04:39:41 +00001047 bool permanent, u32 if_handle, u32 pmac_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001048{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001049 struct be_mcc_wrb *wrb;
1050 struct be_cmd_req_mac_query *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001051 int status;
1052
Sathya Perlab7172412016-07-27 05:26:18 -04001053 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001054
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001055 wrb = wrb_from_mccq(adapter);
1056 if (!wrb) {
1057 status = -EBUSY;
1058 goto err;
1059 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001060 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001061
Somnath Kotur106df1e2011-10-27 07:12:13 +00001062 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301063 OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb,
1064 NULL);
Sathya Perla5ee49792012-09-28 04:39:41 +00001065 req->type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001066 if (permanent) {
1067 req->permanent = 1;
1068 } else {
Kalesh AP504fbf12014-09-19 15:47:00 +05301069 req->if_id = cpu_to_le16((u16)if_handle);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00001070 req->pmac_id = cpu_to_le32(pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001071 req->permanent = 0;
1072 }
1073
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001074 status = be_mcc_notify_wait(adapter);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001075 if (!status) {
1076 struct be_cmd_resp_mac_query *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301077
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001078 memcpy(mac_addr, resp->mac.addr, ETH_ALEN);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001079 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001080
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001081err:
Sathya Perlab7172412016-07-27 05:26:18 -04001082 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001083 return status;
1084}
1085
Sathya Perlab31c50a2009-09-17 10:30:13 -07001086/* Uses synchronous MCCQ */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001087int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301088 u32 if_id, u32 *pmac_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001089{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001090 struct be_mcc_wrb *wrb;
1091 struct be_cmd_req_pmac_add *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001092 int status;
1093
Sathya Perlab7172412016-07-27 05:26:18 -04001094 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001095
1096 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001097 if (!wrb) {
1098 status = -EBUSY;
1099 goto err;
1100 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001101 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001102
Somnath Kotur106df1e2011-10-27 07:12:13 +00001103 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301104 OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb,
1105 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001106
Ajit Khapardef8617e02011-02-11 13:36:37 +00001107 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001108 req->if_id = cpu_to_le32(if_id);
1109 memcpy(req->mac_address, mac_addr, ETH_ALEN);
1110
Sathya Perlab31c50a2009-09-17 10:30:13 -07001111 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001112 if (!status) {
1113 struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301114
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001115 *pmac_id = le32_to_cpu(resp->pmac_id);
1116 }
1117
Sathya Perla713d03942009-11-22 22:02:45 +00001118err:
Sathya Perlab7172412016-07-27 05:26:18 -04001119 mutex_unlock(&adapter->mcc_lock);
Somnath Koture3a7ae22011-10-27 07:14:05 +00001120
1121 if (status == MCC_STATUS_UNAUTHORIZED_REQUEST)
1122 status = -EPERM;
1123
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001124 return status;
1125}
1126
Sathya Perlab31c50a2009-09-17 10:30:13 -07001127/* Uses synchronous MCCQ */
Sathya Perla30128032011-11-10 19:17:57 +00001128int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001129{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001130 struct be_mcc_wrb *wrb;
1131 struct be_cmd_req_pmac_del *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001132 int status;
1133
Sathya Perla30128032011-11-10 19:17:57 +00001134 if (pmac_id == -1)
1135 return 0;
1136
Sathya Perlab7172412016-07-27 05:26:18 -04001137 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001138
1139 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001140 if (!wrb) {
1141 status = -EBUSY;
1142 goto err;
1143 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001144 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001145
Somnath Kotur106df1e2011-10-27 07:12:13 +00001146 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Kalesh APcd3307aa2014-09-19 15:47:02 +05301147 OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req),
1148 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001149
Ajit Khapardef8617e02011-02-11 13:36:37 +00001150 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001151 req->if_id = cpu_to_le32(if_id);
1152 req->pmac_id = cpu_to_le32(pmac_id);
1153
Sathya Perlab31c50a2009-09-17 10:30:13 -07001154 status = be_mcc_notify_wait(adapter);
1155
Sathya Perla713d03942009-11-22 22:02:45 +00001156err:
Sathya Perlab7172412016-07-27 05:26:18 -04001157 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001158 return status;
1159}
1160
Sathya Perlab31c50a2009-09-17 10:30:13 -07001161/* Uses Mbox */
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001162int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301163 struct be_queue_info *eq, bool no_delay, int coalesce_wm)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001164{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001165 struct be_mcc_wrb *wrb;
1166 struct be_cmd_req_cq_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001167 struct be_dma_mem *q_mem = &cq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001168 void *ctxt;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001169 int status;
1170
Ivan Vecera29849612010-12-14 05:43:19 +00001171 if (mutex_lock_interruptible(&adapter->mbox_lock))
1172 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001173
1174 wrb = wrb_from_mbox(adapter);
1175 req = embedded_payload(wrb);
1176 ctxt = &req->context;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001177
Somnath Kotur106df1e2011-10-27 07:12:13 +00001178 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301179 OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb,
1180 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001181
1182 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001183
1184 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001185 AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301186 coalesce_wm);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001187 AMAP_SET_BITS(struct amap_cq_context_be, nodelay,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301188 ctxt, no_delay);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001189 AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301190 __ilog2_u32(cq->len / 256));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001191 AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001192 AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1);
1193 AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001194 } else {
1195 req->hdr.version = 2;
1196 req->page_size = 1; /* 1 for 4K */
Ajit Khaparde09e83a92013-11-22 12:51:20 -06001197
1198 /* coalesce-wm field in this cmd is not relevant to Lancer.
1199 * Lancer uses COMMON_MODIFY_CQ to set this field
1200 */
1201 if (!lancer_chip(adapter))
1202 AMAP_SET_BITS(struct amap_cq_context_v2, coalescwm,
1203 ctxt, coalesce_wm);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001204 AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301205 no_delay);
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001206 AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301207 __ilog2_u32(cq->len / 256));
Ajit Khapardebbdc42f2013-05-01 09:37:17 +00001208 AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1);
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301209 AMAP_SET_BITS(struct amap_cq_context_v2, eventable, ctxt, 1);
1210 AMAP_SET_BITS(struct amap_cq_context_v2, eqid, ctxt, eq->id);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001211 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001212
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001213 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1214
1215 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1216
Sathya Perlab31c50a2009-09-17 10:30:13 -07001217 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001218 if (!status) {
Sathya Perlab31c50a2009-09-17 10:30:13 -07001219 struct be_cmd_resp_cq_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301220
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001221 cq->id = le16_to_cpu(resp->cq_id);
1222 cq->created = true;
1223 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001224
Ivan Vecera29849612010-12-14 05:43:19 +00001225 mutex_unlock(&adapter->mbox_lock);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001226
1227 return status;
1228}
1229
1230static u32 be_encoded_q_len(int q_len)
1231{
1232 u32 len_encoded = fls(q_len); /* log2(len) + 1 */
Kalesh AP03d28ff2014-09-19 15:46:56 +05301233
Sathya Perla5fb379e2009-06-18 00:02:59 +00001234 if (len_encoded == 16)
1235 len_encoded = 0;
1236 return len_encoded;
1237}
1238
Jingoo Han4188e7d2013-08-05 18:02:02 +09001239static int be_cmd_mccq_ext_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301240 struct be_queue_info *mccq,
1241 struct be_queue_info *cq)
Sathya Perla5fb379e2009-06-18 00:02:59 +00001242{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001243 struct be_mcc_wrb *wrb;
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001244 struct be_cmd_req_mcc_ext_create *req;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001245 struct be_dma_mem *q_mem = &mccq->dma_mem;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001246 void *ctxt;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001247 int status;
1248
Ivan Vecera29849612010-12-14 05:43:19 +00001249 if (mutex_lock_interruptible(&adapter->mbox_lock))
1250 return -1;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001251
1252 wrb = wrb_from_mbox(adapter);
1253 req = embedded_payload(wrb);
1254 ctxt = &req->context;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001255
Somnath Kotur106df1e2011-10-27 07:12:13 +00001256 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301257 OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb,
1258 NULL);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001259
Ajit Khaparded4a2ac32010-03-11 01:35:59 +00001260 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301261 if (BEx_chip(adapter)) {
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001262 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1263 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301264 be_encoded_q_len(mccq->len));
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001265 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301266 } else {
1267 req->hdr.version = 1;
1268 req->cq_id = cpu_to_le16(cq->id);
1269
1270 AMAP_SET_BITS(struct amap_mcc_context_v1, ring_size, ctxt,
1271 be_encoded_q_len(mccq->len));
1272 AMAP_SET_BITS(struct amap_mcc_context_v1, valid, ctxt, 1);
1273 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_id,
1274 ctxt, cq->id);
1275 AMAP_SET_BITS(struct amap_mcc_context_v1, async_cq_valid,
1276 ctxt, 1);
Sathya Perlafe6d2a32010-11-21 23:25:50 +00001277 }
1278
Vasundhara Volam21252372015-02-06 08:18:42 -05001279 /* Subscribe to Link State, Sliport Event and Group 5 Events
1280 * (bits 1, 5 and 17 set)
1281 */
1282 req->async_event_bitmap[0] =
1283 cpu_to_le32(BIT(ASYNC_EVENT_CODE_LINK_STATE) |
1284 BIT(ASYNC_EVENT_CODE_GRP_5) |
1285 BIT(ASYNC_EVENT_CODE_QNQ) |
1286 BIT(ASYNC_EVENT_CODE_SLIPORT));
1287
Sathya Perla5fb379e2009-06-18 00:02:59 +00001288 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1289
1290 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1291
Sathya Perlab31c50a2009-09-17 10:30:13 -07001292 status = be_mbox_notify_wait(adapter);
Sathya Perla5fb379e2009-06-18 00:02:59 +00001293 if (!status) {
1294 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301295
Sathya Perla5fb379e2009-06-18 00:02:59 +00001296 mccq->id = le16_to_cpu(resp->id);
1297 mccq->created = true;
1298 }
Ivan Vecera29849612010-12-14 05:43:19 +00001299 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001300
1301 return status;
1302}
1303
Jingoo Han4188e7d2013-08-05 18:02:02 +09001304static int be_cmd_mccq_org_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301305 struct be_queue_info *mccq,
1306 struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001307{
1308 struct be_mcc_wrb *wrb;
1309 struct be_cmd_req_mcc_create *req;
1310 struct be_dma_mem *q_mem = &mccq->dma_mem;
1311 void *ctxt;
1312 int status;
1313
1314 if (mutex_lock_interruptible(&adapter->mbox_lock))
1315 return -1;
1316
1317 wrb = wrb_from_mbox(adapter);
1318 req = embedded_payload(wrb);
1319 ctxt = &req->context;
1320
Somnath Kotur106df1e2011-10-27 07:12:13 +00001321 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301322 OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb,
1323 NULL);
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001324
1325 req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size));
1326
1327 AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1);
1328 AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301329 be_encoded_q_len(mccq->len));
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001330 AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id);
1331
1332 be_dws_cpu_to_le(ctxt, sizeof(req->context));
1333
1334 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1335
1336 status = be_mbox_notify_wait(adapter);
1337 if (!status) {
1338 struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301339
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001340 mccq->id = le16_to_cpu(resp->id);
1341 mccq->created = true;
1342 }
1343
1344 mutex_unlock(&adapter->mbox_lock);
1345 return status;
1346}
1347
1348int be_cmd_mccq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301349 struct be_queue_info *mccq, struct be_queue_info *cq)
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001350{
1351 int status;
1352
1353 status = be_cmd_mccq_ext_create(adapter, mccq, cq);
Vasundhara Volam666d39c2014-01-15 13:23:31 +05301354 if (status && BEx_chip(adapter)) {
Somnath Kotur34b1ef02011-06-01 00:33:22 +00001355 dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 "
1356 "or newer to avoid conflicting priorities between NIC "
1357 "and FCoE traffic");
1358 status = be_cmd_mccq_org_create(adapter, mccq, cq);
1359 }
1360 return status;
1361}
1362
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001363int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001364{
Sathya Perla77071332013-08-27 16:57:34 +05301365 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001366 struct be_cmd_req_eth_tx_create *req;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001367 struct be_queue_info *txq = &txo->q;
1368 struct be_queue_info *cq = &txo->cq;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001369 struct be_dma_mem *q_mem = &txq->dma_mem;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001370 int status, ver = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001371
Sathya Perla77071332013-08-27 16:57:34 +05301372 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001373 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301374 OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001375
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001376 if (lancer_chip(adapter)) {
1377 req->hdr.version = 1;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001378 } else if (BEx_chip(adapter)) {
1379 if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC)
1380 req->hdr.version = 2;
1381 } else { /* For SH */
1382 req->hdr.version = 2;
Padmanabh Ratnakar8b7756c2011-03-07 03:08:52 +00001383 }
1384
Vasundhara Volam81b02652013-10-01 15:59:57 +05301385 if (req->hdr.version > 0)
1386 req->if_id = cpu_to_le16(adapter->if_handle);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001387 req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size);
1388 req->ulp_num = BE_ULP1_NUM;
1389 req->type = BE_ETH_TX_RING_TYPE_STANDARD;
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001390 req->cq_id = cpu_to_le16(cq->id);
1391 req->queue_size = be_encoded_q_len(txq->len);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001392 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001393 ver = req->hdr.version;
1394
Sathya Perla77071332013-08-27 16:57:34 +05301395 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001396 if (!status) {
Sathya Perla77071332013-08-27 16:57:34 +05301397 struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301398
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001399 txq->id = le16_to_cpu(resp->cid);
Vasundhara Volam94d73aa2013-04-21 23:28:14 +00001400 if (ver == 2)
1401 txo->db_offset = le32_to_cpu(resp->db_offset);
1402 else
1403 txo->db_offset = DB_TXULP1_OFFSET;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001404 txq->created = true;
1405 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001406
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001407 return status;
1408}
1409
Sathya Perla482c9e72011-06-29 23:33:17 +00001410/* Uses MCC */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001411int be_cmd_rxq_create(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301412 struct be_queue_info *rxq, u16 cq_id, u16 frag_size,
1413 u32 if_id, u32 rss, u8 *rss_id)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001414{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001415 struct be_mcc_wrb *wrb;
1416 struct be_cmd_req_eth_rx_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001417 struct be_dma_mem *q_mem = &rxq->dma_mem;
1418 int status;
1419
Sathya Perlab7172412016-07-27 05:26:18 -04001420 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001421
Sathya Perla482c9e72011-06-29 23:33:17 +00001422 wrb = wrb_from_mccq(adapter);
1423 if (!wrb) {
1424 status = -EBUSY;
1425 goto err;
1426 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001427 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001428
Somnath Kotur106df1e2011-10-27 07:12:13 +00001429 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301430 OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001431
1432 req->cq_id = cpu_to_le16(cq_id);
1433 req->frag_size = fls(frag_size) - 1;
1434 req->num_pages = 2;
1435 be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem);
1436 req->interface_id = cpu_to_le32(if_id);
Sathya Perla10ef9ab2012-02-09 18:05:27 +00001437 req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001438 req->rss_queue = cpu_to_le32(rss);
1439
Sathya Perla482c9e72011-06-29 23:33:17 +00001440 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001441 if (!status) {
1442 struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301443
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001444 rxq->id = le16_to_cpu(resp->id);
1445 rxq->created = true;
Sathya Perla3abcded2010-10-03 22:12:27 -07001446 *rss_id = resp->rss_id;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001447 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001448
Sathya Perla482c9e72011-06-29 23:33:17 +00001449err:
Sathya Perlab7172412016-07-27 05:26:18 -04001450 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001451 return status;
1452}
1453
Sathya Perlab31c50a2009-09-17 10:30:13 -07001454/* Generic destroyer function for all types of queues
1455 * Uses Mbox
1456 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001457int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301458 int queue_type)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001459{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001460 struct be_mcc_wrb *wrb;
1461 struct be_cmd_req_q_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001462 u8 subsys = 0, opcode = 0;
1463 int status;
1464
Ivan Vecera29849612010-12-14 05:43:19 +00001465 if (mutex_lock_interruptible(&adapter->mbox_lock))
1466 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001467
Sathya Perlab31c50a2009-09-17 10:30:13 -07001468 wrb = wrb_from_mbox(adapter);
1469 req = embedded_payload(wrb);
1470
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001471 switch (queue_type) {
1472 case QTYPE_EQ:
1473 subsys = CMD_SUBSYSTEM_COMMON;
1474 opcode = OPCODE_COMMON_EQ_DESTROY;
1475 break;
1476 case QTYPE_CQ:
1477 subsys = CMD_SUBSYSTEM_COMMON;
1478 opcode = OPCODE_COMMON_CQ_DESTROY;
1479 break;
1480 case QTYPE_TXQ:
1481 subsys = CMD_SUBSYSTEM_ETH;
1482 opcode = OPCODE_ETH_TX_DESTROY;
1483 break;
1484 case QTYPE_RXQ:
1485 subsys = CMD_SUBSYSTEM_ETH;
1486 opcode = OPCODE_ETH_RX_DESTROY;
1487 break;
Sathya Perla5fb379e2009-06-18 00:02:59 +00001488 case QTYPE_MCCQ:
1489 subsys = CMD_SUBSYSTEM_COMMON;
1490 opcode = OPCODE_COMMON_MCC_DESTROY;
1491 break;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001492 default:
Sathya Perla5f0b8492009-07-27 22:52:56 +00001493 BUG();
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001494 }
Ajit Khaparded744b442009-12-03 06:12:06 +00001495
Somnath Kotur106df1e2011-10-27 07:12:13 +00001496 be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301497 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001498 req->id = cpu_to_le16(q->id);
1499
Sathya Perlab31c50a2009-09-17 10:30:13 -07001500 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001501 q->created = false;
Sathya Perla5f0b8492009-07-27 22:52:56 +00001502
Ivan Vecera29849612010-12-14 05:43:19 +00001503 mutex_unlock(&adapter->mbox_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001504 return status;
1505}
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001506
Sathya Perla482c9e72011-06-29 23:33:17 +00001507/* Uses MCC */
1508int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q)
1509{
1510 struct be_mcc_wrb *wrb;
1511 struct be_cmd_req_q_destroy *req;
1512 int status;
1513
Sathya Perlab7172412016-07-27 05:26:18 -04001514 mutex_lock(&adapter->mcc_lock);
Sathya Perla482c9e72011-06-29 23:33:17 +00001515
1516 wrb = wrb_from_mccq(adapter);
1517 if (!wrb) {
1518 status = -EBUSY;
1519 goto err;
1520 }
1521 req = embedded_payload(wrb);
1522
Somnath Kotur106df1e2011-10-27 07:12:13 +00001523 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301524 OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL);
Sathya Perla482c9e72011-06-29 23:33:17 +00001525 req->id = cpu_to_le16(q->id);
1526
1527 status = be_mcc_notify_wait(adapter);
Padmanabh Ratnakaraa790db2012-10-20 06:03:25 +00001528 q->created = false;
Sathya Perla482c9e72011-06-29 23:33:17 +00001529
1530err:
Sathya Perlab7172412016-07-27 05:26:18 -04001531 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001532 return status;
1533}
1534
Sathya Perlab31c50a2009-09-17 10:30:13 -07001535/* Create an rx filtering policy configuration on an i/f
Sathya Perlabea50982013-08-27 16:57:33 +05301536 * Will use MBOX only if MCCQ has not been created.
Sathya Perlab31c50a2009-09-17 10:30:13 -07001537 */
Sathya Perla73d540f2009-10-14 20:20:42 +00001538int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags,
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001539 u32 *if_handle, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001540{
Sathya Perlabea50982013-08-27 16:57:33 +05301541 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001542 struct be_cmd_req_if_create *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001543 int status;
1544
Sathya Perlabea50982013-08-27 16:57:33 +05301545 req = embedded_payload(&wrb);
Somnath Kotur106df1e2011-10-27 07:12:13 +00001546 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301547 OPCODE_COMMON_NTWK_INTERFACE_CREATE,
1548 sizeof(*req), &wrb, NULL);
Sarveshwar Bandiba343c72010-03-31 02:56:12 +00001549 req->hdr.domain = domain;
Sathya Perla73d540f2009-10-14 20:20:42 +00001550 req->capability_flags = cpu_to_le32(cap_flags);
1551 req->enable_flags = cpu_to_le32(en_flags);
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00001552 req->pmac_invalid = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001553
Sathya Perlabea50982013-08-27 16:57:33 +05301554 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001555 if (!status) {
Sathya Perlabea50982013-08-27 16:57:33 +05301556 struct be_cmd_resp_if_create *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301557
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001558 *if_handle = le32_to_cpu(resp->interface_id);
Sathya Perlab5bb9772013-07-23 15:25:01 +05301559
1560 /* Hack to retrieve VF's pmac-id on BE3 */
Kalesh AP18c57c72015-05-06 05:30:38 -04001561 if (BE3_chip(adapter) && be_virtfn(adapter))
Sathya Perlab5bb9772013-07-23 15:25:01 +05301562 adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001563 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001564 return status;
1565}
1566
Ajit Khaparde62219062016-02-10 22:45:53 +05301567/* Uses MCCQ if available else MBOX */
Sathya Perla30128032011-11-10 19:17:57 +00001568int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001569{
Ajit Khaparde62219062016-02-10 22:45:53 +05301570 struct be_mcc_wrb wrb = {0};
Sathya Perlab31c50a2009-09-17 10:30:13 -07001571 struct be_cmd_req_if_destroy *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001572 int status;
1573
Sathya Perla30128032011-11-10 19:17:57 +00001574 if (interface_id == -1)
Sathya Perlaf9449ab2011-10-24 02:45:01 +00001575 return 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07001576
Ajit Khaparde62219062016-02-10 22:45:53 +05301577 req = embedded_payload(&wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001578
Somnath Kotur106df1e2011-10-27 07:12:13 +00001579 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301580 OPCODE_COMMON_NTWK_INTERFACE_DESTROY,
Ajit Khaparde62219062016-02-10 22:45:53 +05301581 sizeof(*req), &wrb, NULL);
Ajit Khaparde658681f2011-02-11 13:34:46 +00001582 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001583 req->interface_id = cpu_to_le32(interface_id);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001584
Ajit Khaparde62219062016-02-10 22:45:53 +05301585 status = be_cmd_notify_wait(adapter, &wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001586 return status;
1587}
1588
1589/* Get stats is a non embedded command: the request is not embedded inside
1590 * WRB but is a separate dma memory block
Sathya Perlab31c50a2009-09-17 10:30:13 -07001591 * Uses asynchronous MCC
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001592 */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001593int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001594{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001595 struct be_mcc_wrb *wrb;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001596 struct be_cmd_req_hdr *hdr;
Sathya Perla713d03942009-11-22 22:02:45 +00001597 int status = 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001598
Sathya Perlab7172412016-07-27 05:26:18 -04001599 mutex_lock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001600
Sathya Perlab31c50a2009-09-17 10:30:13 -07001601 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001602 if (!wrb) {
1603 status = -EBUSY;
1604 goto err;
1605 }
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001606 hdr = nonemb_cmd->va;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001607
Somnath Kotur106df1e2011-10-27 07:12:13 +00001608 be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301609 OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb,
1610 nonemb_cmd);
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001611
Sathya Perlaca34fe32012-11-06 17:48:56 +00001612 /* version 1 of the cmd is not supported only by BE2 */
Ajit Khaparde61000862013-10-03 16:16:33 -05001613 if (BE2_chip(adapter))
1614 hdr->version = 0;
1615 if (BE3_chip(adapter) || lancer_chip(adapter))
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001616 hdr->version = 1;
Ajit Khaparde61000862013-10-03 16:16:33 -05001617 else
1618 hdr->version = 2;
Ajit Khaparde89a88ab2011-05-16 07:36:18 +00001619
Suresh Reddyefaa4082015-07-10 05:32:48 -04001620 status = be_mcc_notify(adapter);
1621 if (status)
1622 goto err;
1623
Ajit Khapardeb2aebe62011-02-20 11:41:39 +00001624 adapter->stats_cmd_sent = true;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001625
Sathya Perla713d03942009-11-22 22:02:45 +00001626err:
Sathya Perlab7172412016-07-27 05:26:18 -04001627 mutex_unlock(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001628 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001629}
1630
Selvin Xavier005d5692011-05-16 07:36:35 +00001631/* Lancer Stats */
1632int lancer_cmd_get_pport_stats(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301633 struct be_dma_mem *nonemb_cmd)
Selvin Xavier005d5692011-05-16 07:36:35 +00001634{
Selvin Xavier005d5692011-05-16 07:36:35 +00001635 struct be_mcc_wrb *wrb;
1636 struct lancer_cmd_req_pport_stats *req;
Selvin Xavier005d5692011-05-16 07:36:35 +00001637 int status = 0;
1638
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00001639 if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS,
1640 CMD_SUBSYSTEM_ETH))
1641 return -EPERM;
1642
Sathya Perlab7172412016-07-27 05:26:18 -04001643 mutex_lock(&adapter->mcc_lock);
Selvin Xavier005d5692011-05-16 07:36:35 +00001644
1645 wrb = wrb_from_mccq(adapter);
1646 if (!wrb) {
1647 status = -EBUSY;
1648 goto err;
1649 }
1650 req = nonemb_cmd->va;
Selvin Xavier005d5692011-05-16 07:36:35 +00001651
Somnath Kotur106df1e2011-10-27 07:12:13 +00001652 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301653 OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size,
1654 wrb, nonemb_cmd);
Selvin Xavier005d5692011-05-16 07:36:35 +00001655
Padmanabh Ratnakard51ebd32012-04-25 01:46:52 +00001656 req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num);
Selvin Xavier005d5692011-05-16 07:36:35 +00001657 req->cmd_params.params.reset_stats = 0;
1658
Suresh Reddyefaa4082015-07-10 05:32:48 -04001659 status = be_mcc_notify(adapter);
1660 if (status)
1661 goto err;
1662
Selvin Xavier005d5692011-05-16 07:36:35 +00001663 adapter->stats_cmd_sent = true;
1664
1665err:
Sathya Perlab7172412016-07-27 05:26:18 -04001666 mutex_unlock(&adapter->mcc_lock);
Selvin Xavier005d5692011-05-16 07:36:35 +00001667 return status;
1668}
1669
Sathya Perla323ff712012-09-28 04:39:43 +00001670static int be_mac_to_link_speed(int mac_speed)
1671{
1672 switch (mac_speed) {
1673 case PHY_LINK_SPEED_ZERO:
1674 return 0;
1675 case PHY_LINK_SPEED_10MBPS:
1676 return 10;
1677 case PHY_LINK_SPEED_100MBPS:
1678 return 100;
1679 case PHY_LINK_SPEED_1GBPS:
1680 return 1000;
1681 case PHY_LINK_SPEED_10GBPS:
1682 return 10000;
Vasundhara Volamb971f842013-08-06 09:27:15 +05301683 case PHY_LINK_SPEED_20GBPS:
1684 return 20000;
1685 case PHY_LINK_SPEED_25GBPS:
1686 return 25000;
1687 case PHY_LINK_SPEED_40GBPS:
1688 return 40000;
Sathya Perla323ff712012-09-28 04:39:43 +00001689 }
1690 return 0;
1691}
1692
1693/* Uses synchronous mcc
1694 * Returns link_speed in Mbps
1695 */
1696int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed,
1697 u8 *link_status, u32 dom)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001698{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001699 struct be_mcc_wrb *wrb;
1700 struct be_cmd_req_link_status *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001701 int status;
1702
Sathya Perlab7172412016-07-27 05:26:18 -04001703 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001704
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001705 if (link_status)
1706 *link_status = LINK_DOWN;
1707
Sathya Perlab31c50a2009-09-17 10:30:13 -07001708 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001709 if (!wrb) {
1710 status = -EBUSY;
1711 goto err;
1712 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001713 req = embedded_payload(wrb);
Sathya Perlaa8f447bd2009-06-18 00:10:27 +00001714
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001715 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301716 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1717 sizeof(*req), wrb, NULL);
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001718
Sathya Perlaca34fe32012-11-06 17:48:56 +00001719 /* version 1 of the cmd is not supported only by BE2 */
1720 if (!BE2_chip(adapter))
Padmanabh Ratnakardaad6162011-11-16 02:03:45 +00001721 req->hdr.version = 1;
1722
Padmanabh Ratnakar57cd80d2012-02-03 09:49:46 +00001723 req->hdr.domain = dom;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001724
Sathya Perlab31c50a2009-09-17 10:30:13 -07001725 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001726 if (!status) {
1727 struct be_cmd_resp_link_status *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301728
Sathya Perla323ff712012-09-28 04:39:43 +00001729 if (link_speed) {
1730 *link_speed = resp->link_speed ?
1731 le16_to_cpu(resp->link_speed) * 10 :
1732 be_mac_to_link_speed(resp->mac_speed);
1733
1734 if (!resp->logical_link_status)
1735 *link_speed = 0;
Sarveshwar Bandi0388f252009-10-28 04:15:20 -07001736 }
Ajit Khapardeb236916a2011-12-30 12:15:40 +00001737 if (link_status)
1738 *link_status = resp->logical_link_status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001739 }
1740
Sathya Perla713d03942009-11-22 22:02:45 +00001741err:
Sathya Perlab7172412016-07-27 05:26:18 -04001742 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001743 return status;
1744}
1745
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001746/* Uses synchronous mcc */
1747int be_cmd_get_die_temperature(struct be_adapter *adapter)
1748{
1749 struct be_mcc_wrb *wrb;
1750 struct be_cmd_req_get_cntl_addnl_attribs *req;
Vasundhara Volam117affe2013-08-06 09:27:20 +05301751 int status = 0;
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001752
Sathya Perlab7172412016-07-27 05:26:18 -04001753 mutex_lock(&adapter->mcc_lock);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001754
1755 wrb = wrb_from_mccq(adapter);
1756 if (!wrb) {
1757 status = -EBUSY;
1758 goto err;
1759 }
1760 req = embedded_payload(wrb);
1761
Somnath Kotur106df1e2011-10-27 07:12:13 +00001762 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301763 OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES,
1764 sizeof(*req), wrb, NULL);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001765
Suresh Reddyefaa4082015-07-10 05:32:48 -04001766 status = be_mcc_notify(adapter);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001767err:
Sathya Perlab7172412016-07-27 05:26:18 -04001768 mutex_unlock(&adapter->mcc_lock);
Ajit Khaparde609ff3b2011-02-20 11:42:07 +00001769 return status;
1770}
1771
Somnath Kotur311fddc2011-03-16 21:22:43 +00001772/* Uses synchronous mcc */
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001773int be_cmd_get_fat_dump_len(struct be_adapter *adapter, u32 *dump_size)
Somnath Kotur311fddc2011-03-16 21:22:43 +00001774{
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001775 struct be_mcc_wrb wrb = {0};
Somnath Kotur311fddc2011-03-16 21:22:43 +00001776 struct be_cmd_req_get_fat *req;
1777 int status;
1778
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001779 req = embedded_payload(&wrb);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001780
Somnath Kotur106df1e2011-10-27 07:12:13 +00001781 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001782 OPCODE_COMMON_MANAGE_FAT, sizeof(*req),
1783 &wrb, NULL);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001784 req->fat_operation = cpu_to_le32(QUERY_FAT);
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001785 status = be_cmd_notify_wait(adapter, &wrb);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001786 if (!status) {
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001787 struct be_cmd_resp_get_fat *resp = embedded_payload(&wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05301788
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001789 if (dump_size && resp->log_size)
1790 *dump_size = le32_to_cpu(resp->log_size) -
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001791 sizeof(u32);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001792 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001793 return status;
1794}
1795
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001796int be_cmd_get_fat_dump(struct be_adapter *adapter, u32 buf_len, void *buf)
Somnath Kotur311fddc2011-03-16 21:22:43 +00001797{
1798 struct be_dma_mem get_fat_cmd;
1799 struct be_mcc_wrb *wrb;
1800 struct be_cmd_req_get_fat *req;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001801 u32 offset = 0, total_size, buf_size,
1802 log_offset = sizeof(u32), payload_len;
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001803 int status;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001804
1805 if (buf_len == 0)
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001806 return 0;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001807
1808 total_size = buf_len;
1809
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001810 get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024;
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05301811 get_fat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
1812 get_fat_cmd.size,
1813 &get_fat_cmd.dma, GFP_ATOMIC);
Venkat Duvvurufd7ff6f2015-12-30 01:29:04 -05001814 if (!get_fat_cmd.va)
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301815 return -ENOMEM;
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001816
Sathya Perlab7172412016-07-27 05:26:18 -04001817 mutex_lock(&adapter->mcc_lock);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001818
Somnath Kotur311fddc2011-03-16 21:22:43 +00001819 while (total_size) {
1820 buf_size = min(total_size, (u32)60*1024);
1821 total_size -= buf_size;
1822
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001823 wrb = wrb_from_mccq(adapter);
1824 if (!wrb) {
1825 status = -EBUSY;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001826 goto err;
1827 }
1828 req = get_fat_cmd.va;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001829
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001830 payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size;
Somnath Kotur106df1e2011-10-27 07:12:13 +00001831 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301832 OPCODE_COMMON_MANAGE_FAT, payload_len,
1833 wrb, &get_fat_cmd);
Somnath Kotur311fddc2011-03-16 21:22:43 +00001834
1835 req->fat_operation = cpu_to_le32(RETRIEVE_FAT);
1836 req->read_log_offset = cpu_to_le32(log_offset);
1837 req->read_log_length = cpu_to_le32(buf_size);
1838 req->data_buffer_size = cpu_to_le32(buf_size);
1839
1840 status = be_mcc_notify_wait(adapter);
1841 if (!status) {
1842 struct be_cmd_resp_get_fat *resp = get_fat_cmd.va;
Kalesh AP03d28ff2014-09-19 15:46:56 +05301843
Somnath Kotur311fddc2011-03-16 21:22:43 +00001844 memcpy(buf + offset,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301845 resp->data_buffer,
1846 le32_to_cpu(resp->read_log_length));
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001847 } else {
Somnath Kotur311fddc2011-03-16 21:22:43 +00001848 dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n");
Somnath Koturfe2a70e2011-04-21 03:18:12 +00001849 goto err;
1850 }
Somnath Kotur311fddc2011-03-16 21:22:43 +00001851 offset += buf_size;
1852 log_offset += buf_size;
1853 }
1854err:
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05301855 dma_free_coherent(&adapter->pdev->dev, get_fat_cmd.size,
1856 get_fat_cmd.va, get_fat_cmd.dma);
Sathya Perlab7172412016-07-27 05:26:18 -04001857 mutex_unlock(&adapter->mcc_lock);
Vasundhara Volamc5f156d2014-09-02 09:56:54 +05301858 return status;
Somnath Kotur311fddc2011-03-16 21:22:43 +00001859}
1860
Sathya Perla04b71172011-09-27 13:30:27 -04001861/* Uses synchronous mcc */
Kalesh APe97e3cd2014-07-17 16:20:26 +05301862int be_cmd_get_fw_ver(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001863{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001864 struct be_mcc_wrb *wrb;
1865 struct be_cmd_req_get_fw_version *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001866 int status;
1867
Sathya Perlab7172412016-07-27 05:26:18 -04001868 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001869
Sathya Perla04b71172011-09-27 13:30:27 -04001870 wrb = wrb_from_mccq(adapter);
1871 if (!wrb) {
1872 status = -EBUSY;
1873 goto err;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001874 }
1875
Sathya Perla04b71172011-09-27 13:30:27 -04001876 req = embedded_payload(wrb);
Sathya Perla04b71172011-09-27 13:30:27 -04001877
Somnath Kotur106df1e2011-10-27 07:12:13 +00001878 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301879 OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb,
1880 NULL);
Sathya Perla04b71172011-09-27 13:30:27 -04001881 status = be_mcc_notify_wait(adapter);
1882 if (!status) {
1883 struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb);
Sathya Perlaacbafeb2014-09-02 09:56:46 +05301884
Vasundhara Volam242eb472014-09-12 17:39:15 +05301885 strlcpy(adapter->fw_ver, resp->firmware_version_string,
1886 sizeof(adapter->fw_ver));
1887 strlcpy(adapter->fw_on_flash, resp->fw_on_flash_version_string,
1888 sizeof(adapter->fw_on_flash));
Sathya Perla04b71172011-09-27 13:30:27 -04001889 }
1890err:
Sathya Perlab7172412016-07-27 05:26:18 -04001891 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001892 return status;
1893}
1894
Sathya Perlab31c50a2009-09-17 10:30:13 -07001895/* set the EQ delay interval of an EQ to specified value
1896 * Uses async mcc
1897 */
Kalesh APb502ae82014-09-19 15:46:51 +05301898static int __be_cmd_modify_eqd(struct be_adapter *adapter,
1899 struct be_set_eqd *set_eqd, int num)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001900{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001901 struct be_mcc_wrb *wrb;
1902 struct be_cmd_req_modify_eq_delay *req;
Sathya Perla2632baf2013-10-01 16:00:00 +05301903 int status = 0, i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001904
Sathya Perlab7172412016-07-27 05:26:18 -04001905 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001906
1907 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001908 if (!wrb) {
1909 status = -EBUSY;
1910 goto err;
1911 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001912 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001913
Somnath Kotur106df1e2011-10-27 07:12:13 +00001914 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301915 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb,
1916 NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001917
Sathya Perla2632baf2013-10-01 16:00:00 +05301918 req->num_eq = cpu_to_le32(num);
1919 for (i = 0; i < num; i++) {
1920 req->set_eqd[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
1921 req->set_eqd[i].phase = 0;
1922 req->set_eqd[i].delay_multiplier =
1923 cpu_to_le32(set_eqd[i].delay_multiplier);
1924 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001925
Suresh Reddyefaa4082015-07-10 05:32:48 -04001926 status = be_mcc_notify(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001927err:
Sathya Perlab7172412016-07-27 05:26:18 -04001928 mutex_unlock(&adapter->mcc_lock);
Sathya Perla713d03942009-11-22 22:02:45 +00001929 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001930}
1931
Kalesh AP93676702014-09-12 17:39:20 +05301932int be_cmd_modify_eqd(struct be_adapter *adapter, struct be_set_eqd *set_eqd,
1933 int num)
1934{
1935 int num_eqs, i = 0;
1936
Suresh Reddyc8ba4ad02015-03-20 06:28:24 -04001937 while (num) {
1938 num_eqs = min(num, 8);
1939 __be_cmd_modify_eqd(adapter, &set_eqd[i], num_eqs);
1940 i += num_eqs;
1941 num -= num_eqs;
Kalesh AP93676702014-09-12 17:39:20 +05301942 }
1943
1944 return 0;
1945}
1946
Sathya Perlab31c50a2009-09-17 10:30:13 -07001947/* Uses sycnhronous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00001948int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array,
Vasundhara Volam435452a2015-03-20 06:28:23 -04001949 u32 num, u32 domain)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001950{
Sathya Perlab31c50a2009-09-17 10:30:13 -07001951 struct be_mcc_wrb *wrb;
1952 struct be_cmd_req_vlan_config *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001953 int status;
1954
Sathya Perlab7172412016-07-27 05:26:18 -04001955 mutex_lock(&adapter->mcc_lock);
Sathya Perlab31c50a2009-09-17 10:30:13 -07001956
1957 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001958 if (!wrb) {
1959 status = -EBUSY;
1960 goto err;
1961 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07001962 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001963
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_VLAN_CONFIG, sizeof(*req),
1966 wrb, NULL);
Vasundhara Volam435452a2015-03-20 06:28:23 -04001967 req->hdr.domain = domain;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001968
1969 req->interface_id = if_id;
Ajit Khaparde012bd382013-11-18 10:44:24 -06001970 req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001971 req->num_vlan = num;
Kalesh AP4d567d92014-05-09 13:29:17 +05301972 memcpy(req->normal_vlan, vtag_array,
1973 req->num_vlan * sizeof(vtag_array[0]));
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001974
Sathya Perlab31c50a2009-09-17 10:30:13 -07001975 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001976err:
Sathya Perlab7172412016-07-27 05:26:18 -04001977 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001978 return status;
1979}
1980
Sathya Perlaac34b742015-02-06 08:18:40 -05001981static int __be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001982{
Sathya Perla6ac7b682009-06-18 00:05:54 +00001983 struct be_mcc_wrb *wrb;
Sathya Perla5b8821b2011-08-02 19:57:44 +00001984 struct be_dma_mem *mem = &adapter->rx_filter;
1985 struct be_cmd_req_rx_filter *req = mem->va;
Sathya Perlae7b909a2009-11-22 22:01:10 +00001986 int status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001987
Sathya Perlab7172412016-07-27 05:26:18 -04001988 mutex_lock(&adapter->mcc_lock);
Sathya Perla6ac7b682009-06-18 00:05:54 +00001989
Sathya Perlab31c50a2009-09-17 10:30:13 -07001990 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00001991 if (!wrb) {
1992 status = -EBUSY;
1993 goto err;
1994 }
Sathya Perla5b8821b2011-08-02 19:57:44 +00001995 memset(req, 0, sizeof(*req));
Somnath Kotur106df1e2011-10-27 07:12:13 +00001996 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05301997 OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req),
1998 wrb, mem);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07001999
Sathya Perla5b8821b2011-08-02 19:57:44 +00002000 req->if_id = cpu_to_le32(adapter->if_handle);
Sathya Perlaac34b742015-02-06 08:18:40 -05002001 req->if_flags_mask = cpu_to_le32(flags);
2002 req->if_flags = (value == ON) ? req->if_flags_mask : 0;
Ajit Khaparded9d604f2013-09-27 15:17:58 -05002003
Sathya Perlaac34b742015-02-06 08:18:40 -05002004 if (flags & BE_IF_FLAGS_MULTICAST) {
Sathya Perlab7172412016-07-27 05:26:18 -04002005 int i;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002006
Padmanabh Ratnakar1610c792011-11-03 01:49:27 +00002007 /* Reset mcast promisc mode if already set by setting mask
2008 * and not setting flags field
2009 */
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00002010 req->if_flags_mask |=
2011 cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS &
Sathya Perla92bf14a2013-08-27 16:57:32 +05302012 be_if_cap_flags(adapter));
Sathya Perlab7172412016-07-27 05:26:18 -04002013 req->mcast_num = cpu_to_le32(adapter->mc_count);
2014 for (i = 0; i < adapter->mc_count; i++)
2015 ether_addr_copy(req->mcast_mac[i].byte,
2016 adapter->mc_list[i].mac);
Sathya Perla5b8821b2011-08-02 19:57:44 +00002017 }
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002018
Sathya Perlab6588872015-09-03 07:41:53 -04002019 status = be_mcc_notify_wait(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002020err:
Sathya Perlab7172412016-07-27 05:26:18 -04002021 mutex_unlock(&adapter->mcc_lock);
Sathya Perlae7b909a2009-11-22 22:01:10 +00002022 return status;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002023}
2024
Sathya Perlaac34b742015-02-06 08:18:40 -05002025int be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value)
2026{
2027 struct device *dev = &adapter->pdev->dev;
2028
2029 if ((flags & be_if_cap_flags(adapter)) != flags) {
2030 dev_warn(dev, "Cannot set rx filter flags 0x%x\n", flags);
2031 dev_warn(dev, "Interface is capable of 0x%x flags only\n",
2032 be_if_cap_flags(adapter));
2033 }
2034 flags &= be_if_cap_flags(adapter);
Kalesh AP196e3732015-10-12 03:47:21 -04002035 if (!flags)
2036 return -ENOTSUPP;
Sathya Perlaac34b742015-02-06 08:18:40 -05002037
2038 return __be_cmd_rx_filter(adapter, flags, value);
2039}
2040
Sathya Perlab31c50a2009-09-17 10:30:13 -07002041/* Uses synchrounous mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002042int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002043{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002044 struct be_mcc_wrb *wrb;
2045 struct be_cmd_req_set_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002046 int status;
2047
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002048 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL,
2049 CMD_SUBSYSTEM_COMMON))
2050 return -EPERM;
2051
Sathya Perlab7172412016-07-27 05:26:18 -04002052 mutex_lock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002053
Sathya Perlab31c50a2009-09-17 10:30:13 -07002054 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002055 if (!wrb) {
2056 status = -EBUSY;
2057 goto err;
2058 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002059 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002060
Somnath Kotur106df1e2011-10-27 07:12:13 +00002061 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302062 OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req),
2063 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002064
Suresh Reddyb29812c2014-09-12 17:39:17 +05302065 req->hdr.version = 1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002066 req->tx_flow_control = cpu_to_le16((u16)tx_fc);
2067 req->rx_flow_control = cpu_to_le16((u16)rx_fc);
2068
Sathya Perlab31c50a2009-09-17 10:30:13 -07002069 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002070
Sathya Perla713d03942009-11-22 22:02:45 +00002071err:
Sathya Perlab7172412016-07-27 05:26:18 -04002072 mutex_unlock(&adapter->mcc_lock);
Suresh Reddyb29812c2014-09-12 17:39:17 +05302073
2074 if (base_status(status) == MCC_STATUS_FEATURE_NOT_SUPPORTED)
2075 return -EOPNOTSUPP;
2076
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002077 return status;
2078}
2079
Sathya Perlab31c50a2009-09-17 10:30:13 -07002080/* Uses sycn mcc */
Sathya Perla8788fdc2009-07-27 22:52:03 +00002081int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002082{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002083 struct be_mcc_wrb *wrb;
2084 struct be_cmd_req_get_flow_control *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002085 int status;
2086
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00002087 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL,
2088 CMD_SUBSYSTEM_COMMON))
2089 return -EPERM;
2090
Sathya Perlab7172412016-07-27 05:26:18 -04002091 mutex_lock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002092
Sathya Perlab31c50a2009-09-17 10:30:13 -07002093 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002094 if (!wrb) {
2095 status = -EBUSY;
2096 goto err;
2097 }
Sathya Perlab31c50a2009-09-17 10:30:13 -07002098 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002099
Somnath Kotur106df1e2011-10-27 07:12:13 +00002100 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302101 OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req),
2102 wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002103
Sathya Perlab31c50a2009-09-17 10:30:13 -07002104 status = be_mcc_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002105 if (!status) {
2106 struct be_cmd_resp_get_flow_control *resp =
2107 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302108
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002109 *tx_fc = le16_to_cpu(resp->tx_flow_control);
2110 *rx_fc = le16_to_cpu(resp->rx_flow_control);
2111 }
2112
Sathya Perla713d03942009-11-22 22:02:45 +00002113err:
Sathya Perlab7172412016-07-27 05:26:18 -04002114 mutex_unlock(&adapter->mcc_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002115 return status;
2116}
2117
Sathya Perlab31c50a2009-09-17 10:30:13 -07002118/* Uses mbox */
Kalesh APe97e3cd2014-07-17 16:20:26 +05302119int be_cmd_query_fw_cfg(struct be_adapter *adapter)
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002120{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002121 struct be_mcc_wrb *wrb;
2122 struct be_cmd_req_query_fw_cfg *req;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002123 int status;
2124
Ivan Vecera29849612010-12-14 05:43:19 +00002125 if (mutex_lock_interruptible(&adapter->mbox_lock))
2126 return -1;
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002127
Sathya Perlab31c50a2009-09-17 10:30:13 -07002128 wrb = wrb_from_mbox(adapter);
2129 req = embedded_payload(wrb);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002130
Somnath Kotur106df1e2011-10-27 07:12:13 +00002131 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302132 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
2133 sizeof(*req), wrb, NULL);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002134
Sathya Perlab31c50a2009-09-17 10:30:13 -07002135 status = be_mbox_notify_wait(adapter);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002136 if (!status) {
2137 struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302138
Kalesh APe97e3cd2014-07-17 16:20:26 +05302139 adapter->port_num = le32_to_cpu(resp->phys_port);
2140 adapter->function_mode = le32_to_cpu(resp->function_mode);
2141 adapter->function_caps = le32_to_cpu(resp->function_caps);
2142 adapter->asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF;
Sathya Perlaacbafeb2014-09-02 09:56:46 +05302143 dev_info(&adapter->pdev->dev,
2144 "FW config: function_mode=0x%x, function_caps=0x%x\n",
2145 adapter->function_mode, adapter->function_caps);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002146 }
2147
Ivan Vecera29849612010-12-14 05:43:19 +00002148 mutex_unlock(&adapter->mbox_lock);
Sathya Perla6b7c5b92009-03-11 23:32:03 -07002149 return status;
2150}
sarveshwarb14074ea2009-08-05 13:05:24 -07002151
Sathya Perlab31c50a2009-09-17 10:30:13 -07002152/* Uses mbox */
sarveshwarb14074ea2009-08-05 13:05:24 -07002153int be_cmd_reset_function(struct be_adapter *adapter)
2154{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002155 struct be_mcc_wrb *wrb;
2156 struct be_cmd_req_hdr *req;
sarveshwarb14074ea2009-08-05 13:05:24 -07002157 int status;
2158
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002159 if (lancer_chip(adapter)) {
Sathya Perla9fa465c2015-02-23 04:20:13 -05002160 iowrite32(SLI_PORT_CONTROL_IP_MASK,
2161 adapter->db + SLIPORT_CONTROL_OFFSET);
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002162 status = lancer_wait_ready(adapter);
Sathya Perla9fa465c2015-02-23 04:20:13 -05002163 if (status)
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002164 dev_err(&adapter->pdev->dev,
2165 "Adapter in non recoverable error\n");
Padmanabh Ratnakarbf99e502012-07-12 03:56:58 +00002166 return status;
2167 }
2168
Ivan Vecera29849612010-12-14 05:43:19 +00002169 if (mutex_lock_interruptible(&adapter->mbox_lock))
2170 return -1;
sarveshwarb14074ea2009-08-05 13:05:24 -07002171
Sathya Perlab31c50a2009-09-17 10:30:13 -07002172 wrb = wrb_from_mbox(adapter);
2173 req = embedded_payload(wrb);
sarveshwarb14074ea2009-08-05 13:05:24 -07002174
Somnath Kotur106df1e2011-10-27 07:12:13 +00002175 be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302176 OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb,
2177 NULL);
sarveshwarb14074ea2009-08-05 13:05:24 -07002178
Sathya Perlab31c50a2009-09-17 10:30:13 -07002179 status = be_mbox_notify_wait(adapter);
sarveshwarb14074ea2009-08-05 13:05:24 -07002180
Ivan Vecera29849612010-12-14 05:43:19 +00002181 mutex_unlock(&adapter->mbox_lock);
sarveshwarb14074ea2009-08-05 13:05:24 -07002182 return status;
2183}
Ajit Khaparde84517482009-09-04 03:12:16 +00002184
Suresh Reddy594ad542013-04-25 23:03:20 +00002185int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable,
Ben Hutchings33cb0fa2014-05-15 02:01:23 +01002186 u32 rss_hash_opts, u16 table_size, const u8 *rss_hkey)
Sathya Perla3abcded2010-10-03 22:12:27 -07002187{
2188 struct be_mcc_wrb *wrb;
2189 struct be_cmd_req_rss_config *req;
Sathya Perla3abcded2010-10-03 22:12:27 -07002190 int status;
2191
Vasundhara Volamda1388d2014-01-06 13:02:23 +05302192 if (!(be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS))
2193 return 0;
2194
Sathya Perlab7172412016-07-27 05:26:18 -04002195 mutex_lock(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002196
Kalesh APb51aa362014-05-09 13:29:19 +05302197 wrb = wrb_from_mccq(adapter);
2198 if (!wrb) {
2199 status = -EBUSY;
2200 goto err;
2201 }
Sathya Perla3abcded2010-10-03 22:12:27 -07002202 req = embedded_payload(wrb);
2203
Somnath Kotur106df1e2011-10-27 07:12:13 +00002204 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302205 OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL);
Sathya Perla3abcded2010-10-03 22:12:27 -07002206
2207 req->if_id = cpu_to_le32(adapter->if_handle);
Suresh Reddy594ad542013-04-25 23:03:20 +00002208 req->enable_rss = cpu_to_le16(rss_hash_opts);
Sathya Perla3abcded2010-10-03 22:12:27 -07002209 req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1);
Suresh Reddy594ad542013-04-25 23:03:20 +00002210
Kalesh APb51aa362014-05-09 13:29:19 +05302211 if (!BEx_chip(adapter))
Suresh Reddy594ad542013-04-25 23:03:20 +00002212 req->hdr.version = 1;
2213
Sathya Perla3abcded2010-10-03 22:12:27 -07002214 memcpy(req->cpu_table, rsstable, table_size);
Venkata Duvvurue2557872014-04-21 15:38:00 +05302215 memcpy(req->hash, rss_hkey, RSS_HASH_KEY_LEN);
Sathya Perla3abcded2010-10-03 22:12:27 -07002216 be_dws_cpu_to_le(req->hash, sizeof(req->hash));
2217
Kalesh APb51aa362014-05-09 13:29:19 +05302218 status = be_mcc_notify_wait(adapter);
2219err:
Sathya Perlab7172412016-07-27 05:26:18 -04002220 mutex_unlock(&adapter->mcc_lock);
Sathya Perla3abcded2010-10-03 22:12:27 -07002221 return status;
2222}
2223
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002224/* Uses sync mcc */
2225int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302226 u8 bcn, u8 sts, u8 state)
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002227{
2228 struct be_mcc_wrb *wrb;
2229 struct be_cmd_req_enable_disable_beacon *req;
2230 int status;
2231
Sathya Perlab7172412016-07-27 05:26:18 -04002232 mutex_lock(&adapter->mcc_lock);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002233
2234 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002235 if (!wrb) {
2236 status = -EBUSY;
2237 goto err;
2238 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002239 req = embedded_payload(wrb);
2240
Somnath Kotur106df1e2011-10-27 07:12:13 +00002241 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302242 OPCODE_COMMON_ENABLE_DISABLE_BEACON,
2243 sizeof(*req), wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002244
2245 req->port_num = port_num;
2246 req->beacon_state = state;
2247 req->beacon_duration = bcn;
2248 req->status_duration = sts;
2249
2250 status = be_mcc_notify_wait(adapter);
2251
Sathya Perla713d03942009-11-22 22:02:45 +00002252err:
Sathya Perlab7172412016-07-27 05:26:18 -04002253 mutex_unlock(&adapter->mcc_lock);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002254 return status;
2255}
2256
2257/* Uses sync mcc */
2258int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state)
2259{
2260 struct be_mcc_wrb *wrb;
2261 struct be_cmd_req_get_beacon_state *req;
2262 int status;
2263
Sathya Perlab7172412016-07-27 05:26:18 -04002264 mutex_lock(&adapter->mcc_lock);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002265
2266 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002267 if (!wrb) {
2268 status = -EBUSY;
2269 goto err;
2270 }
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002271 req = embedded_payload(wrb);
2272
Somnath Kotur106df1e2011-10-27 07:12:13 +00002273 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302274 OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req),
2275 wrb, NULL);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002276
2277 req->port_num = port_num;
2278
2279 status = be_mcc_notify_wait(adapter);
2280 if (!status) {
2281 struct be_cmd_resp_get_beacon_state *resp =
2282 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05302283
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002284 *state = resp->beacon_state;
2285 }
2286
Sathya Perla713d03942009-11-22 22:02:45 +00002287err:
Sathya Perlab7172412016-07-27 05:26:18 -04002288 mutex_unlock(&adapter->mcc_lock);
Sarveshwar Bandifad9ab22009-10-12 04:23:15 -07002289 return status;
2290}
2291
Mark Leonarde36edd92014-09-12 17:39:18 +05302292/* Uses sync mcc */
2293int be_cmd_read_port_transceiver_data(struct be_adapter *adapter,
2294 u8 page_num, u8 *data)
2295{
2296 struct be_dma_mem cmd;
2297 struct be_mcc_wrb *wrb;
2298 struct be_cmd_req_port_type *req;
2299 int status;
2300
2301 if (page_num > TR_PAGE_A2)
2302 return -EINVAL;
2303
2304 cmd.size = sizeof(struct be_cmd_resp_port_type);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302305 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
2306 GFP_ATOMIC);
Mark Leonarde36edd92014-09-12 17:39:18 +05302307 if (!cmd.va) {
2308 dev_err(&adapter->pdev->dev, "Memory allocation failed\n");
2309 return -ENOMEM;
2310 }
Mark Leonarde36edd92014-09-12 17:39:18 +05302311
Sathya Perlab7172412016-07-27 05:26:18 -04002312 mutex_lock(&adapter->mcc_lock);
Mark Leonarde36edd92014-09-12 17:39:18 +05302313
2314 wrb = wrb_from_mccq(adapter);
2315 if (!wrb) {
2316 status = -EBUSY;
2317 goto err;
2318 }
2319 req = cmd.va;
2320
2321 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2322 OPCODE_COMMON_READ_TRANSRECV_DATA,
2323 cmd.size, wrb, &cmd);
2324
2325 req->port = cpu_to_le32(adapter->hba_port_num);
2326 req->page_num = cpu_to_le32(page_num);
2327 status = be_mcc_notify_wait(adapter);
2328 if (!status) {
2329 struct be_cmd_resp_port_type *resp = cmd.va;
2330
2331 memcpy(data, resp->page_data, PAGE_DATA_LEN);
2332 }
2333err:
Sathya Perlab7172412016-07-27 05:26:18 -04002334 mutex_unlock(&adapter->mcc_lock);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05302335 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Mark Leonarde36edd92014-09-12 17:39:18 +05302336 return status;
2337}
2338
Suresh Reddya23113b2015-12-30 01:28:59 -05002339static int lancer_cmd_write_object(struct be_adapter *adapter,
2340 struct be_dma_mem *cmd, u32 data_size,
2341 u32 data_offset, const char *obj_name,
2342 u32 *data_written, u8 *change_status,
2343 u8 *addn_status)
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002344{
2345 struct be_mcc_wrb *wrb;
2346 struct lancer_cmd_req_write_object *req;
2347 struct lancer_cmd_resp_write_object *resp;
2348 void *ctxt = NULL;
2349 int status;
2350
Sathya Perlab7172412016-07-27 05:26:18 -04002351 mutex_lock(&adapter->mcc_lock);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002352 adapter->flash_status = 0;
2353
2354 wrb = wrb_from_mccq(adapter);
2355 if (!wrb) {
2356 status = -EBUSY;
2357 goto err_unlock;
2358 }
2359
2360 req = embedded_payload(wrb);
2361
Somnath Kotur106df1e2011-10-27 07:12:13 +00002362 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302363 OPCODE_COMMON_WRITE_OBJECT,
2364 sizeof(struct lancer_cmd_req_write_object), wrb,
2365 NULL);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002366
2367 ctxt = &req->context;
2368 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302369 write_length, ctxt, data_size);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002370
2371 if (data_size == 0)
2372 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302373 eof, ctxt, 1);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002374 else
2375 AMAP_SET_BITS(struct amap_lancer_write_obj_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302376 eof, ctxt, 0);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002377
2378 be_dws_cpu_to_le(ctxt, sizeof(req->context));
2379 req->write_offset = cpu_to_le32(data_offset);
Vasundhara Volam242eb472014-09-12 17:39:15 +05302380 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002381 req->descriptor_count = cpu_to_le32(1);
2382 req->buf_len = cpu_to_le32(data_size);
2383 req->addr_low = cpu_to_le32((cmd->dma +
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302384 sizeof(struct lancer_cmd_req_write_object))
2385 & 0xFFFFFFFF);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002386 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma +
2387 sizeof(struct lancer_cmd_req_write_object)));
2388
Suresh Reddyefaa4082015-07-10 05:32:48 -04002389 status = be_mcc_notify(adapter);
2390 if (status)
2391 goto err_unlock;
2392
Sathya Perlab7172412016-07-27 05:26:18 -04002393 mutex_unlock(&adapter->mcc_lock);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002394
Suresh Reddy5eeff632014-01-06 13:02:24 +05302395 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
Somnath Kotur701962d2013-05-02 03:36:34 +00002396 msecs_to_jiffies(60000)))
Kalesh APfd451602014-07-17 16:20:21 +05302397 status = -ETIMEDOUT;
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002398 else
2399 status = adapter->flash_status;
2400
2401 resp = embedded_payload(wrb);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002402 if (!status) {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002403 *data_written = le32_to_cpu(resp->actual_write_len);
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002404 *change_status = resp->change_status;
2405 } else {
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002406 *addn_status = resp->additional_status;
Padmanabh Ratnakarf67ef7b2012-07-12 03:57:09 +00002407 }
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002408
2409 return status;
2410
2411err_unlock:
Sathya Perlab7172412016-07-27 05:26:18 -04002412 mutex_unlock(&adapter->mcc_lock);
Shripad Nunjundarao485bf562011-05-16 07:36:59 +00002413 return status;
2414}
2415
Ravikumar Nelavelli6809cee2014-09-12 17:39:19 +05302416int be_cmd_query_cable_type(struct be_adapter *adapter)
2417{
2418 u8 page_data[PAGE_DATA_LEN];
2419 int status;
2420
2421 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2422 page_data);
2423 if (!status) {
2424 switch (adapter->phy.interface_type) {
2425 case PHY_TYPE_QSFP:
2426 adapter->phy.cable_type =
2427 page_data[QSFP_PLUS_CABLE_TYPE_OFFSET];
2428 break;
2429 case PHY_TYPE_SFP_PLUS_10GB:
2430 adapter->phy.cable_type =
2431 page_data[SFP_PLUS_CABLE_TYPE_OFFSET];
2432 break;
2433 default:
2434 adapter->phy.cable_type = 0;
2435 break;
2436 }
2437 }
2438 return status;
2439}
2440
Vasundhara Volam21252372015-02-06 08:18:42 -05002441int be_cmd_query_sfp_info(struct be_adapter *adapter)
2442{
2443 u8 page_data[PAGE_DATA_LEN];
2444 int status;
2445
2446 status = be_cmd_read_port_transceiver_data(adapter, TR_PAGE_A0,
2447 page_data);
2448 if (!status) {
2449 strlcpy(adapter->phy.vendor_name, page_data +
2450 SFP_VENDOR_NAME_OFFSET, SFP_VENDOR_NAME_LEN - 1);
2451 strlcpy(adapter->phy.vendor_pn,
2452 page_data + SFP_VENDOR_PN_OFFSET,
2453 SFP_VENDOR_NAME_LEN - 1);
2454 }
2455
2456 return status;
2457}
2458
Suresh Reddya23113b2015-12-30 01:28:59 -05002459static int lancer_cmd_delete_object(struct be_adapter *adapter,
2460 const char *obj_name)
Kalesh APf0613382014-08-01 17:47:32 +05302461{
2462 struct lancer_cmd_req_delete_object *req;
2463 struct be_mcc_wrb *wrb;
2464 int status;
2465
Sathya Perlab7172412016-07-27 05:26:18 -04002466 mutex_lock(&adapter->mcc_lock);
Kalesh APf0613382014-08-01 17:47:32 +05302467
2468 wrb = wrb_from_mccq(adapter);
2469 if (!wrb) {
2470 status = -EBUSY;
2471 goto err;
2472 }
2473
2474 req = embedded_payload(wrb);
2475
2476 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
2477 OPCODE_COMMON_DELETE_OBJECT,
2478 sizeof(*req), wrb, NULL);
2479
Vasundhara Volam242eb472014-09-12 17:39:15 +05302480 strlcpy(req->object_name, obj_name, sizeof(req->object_name));
Kalesh APf0613382014-08-01 17:47:32 +05302481
2482 status = be_mcc_notify_wait(adapter);
2483err:
Sathya Perlab7172412016-07-27 05:26:18 -04002484 mutex_unlock(&adapter->mcc_lock);
Kalesh APf0613382014-08-01 17:47:32 +05302485 return status;
2486}
2487
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002488int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302489 u32 data_size, u32 data_offset, const char *obj_name,
2490 u32 *data_read, u32 *eof, u8 *addn_status)
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002491{
2492 struct be_mcc_wrb *wrb;
2493 struct lancer_cmd_req_read_object *req;
2494 struct lancer_cmd_resp_read_object *resp;
2495 int status;
2496
Sathya Perlab7172412016-07-27 05:26:18 -04002497 mutex_lock(&adapter->mcc_lock);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002498
2499 wrb = wrb_from_mccq(adapter);
2500 if (!wrb) {
2501 status = -EBUSY;
2502 goto err_unlock;
2503 }
2504
2505 req = embedded_payload(wrb);
2506
2507 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302508 OPCODE_COMMON_READ_OBJECT,
2509 sizeof(struct lancer_cmd_req_read_object), wrb,
2510 NULL);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002511
2512 req->desired_read_len = cpu_to_le32(data_size);
2513 req->read_offset = cpu_to_le32(data_offset);
2514 strcpy(req->object_name, obj_name);
2515 req->descriptor_count = cpu_to_le32(1);
2516 req->buf_len = cpu_to_le32(data_size);
2517 req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF));
2518 req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma));
2519
2520 status = be_mcc_notify_wait(adapter);
2521
2522 resp = embedded_payload(wrb);
2523 if (!status) {
2524 *data_read = le32_to_cpu(resp->actual_read_len);
2525 *eof = le32_to_cpu(resp->eof);
2526 } else {
2527 *addn_status = resp->additional_status;
2528 }
2529
2530err_unlock:
Sathya Perlab7172412016-07-27 05:26:18 -04002531 mutex_unlock(&adapter->mcc_lock);
Padmanabh Ratnakarde49bd52011-11-16 02:02:43 +00002532 return status;
2533}
2534
Suresh Reddya23113b2015-12-30 01:28:59 -05002535static int be_cmd_write_flashrom(struct be_adapter *adapter,
2536 struct be_dma_mem *cmd, u32 flash_type,
2537 u32 flash_opcode, u32 img_offset, u32 buf_size)
Ajit Khaparde84517482009-09-04 03:12:16 +00002538{
Sathya Perlab31c50a2009-09-17 10:30:13 -07002539 struct be_mcc_wrb *wrb;
Ajit Khaparde3f0d4562010-02-09 01:30:35 +00002540 struct be_cmd_write_flashrom *req;
Ajit Khaparde84517482009-09-04 03:12:16 +00002541 int status;
2542
Sathya Perlab7172412016-07-27 05:26:18 -04002543 mutex_lock(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002544 adapter->flash_status = 0;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002545
2546 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002547 if (!wrb) {
2548 status = -EBUSY;
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002549 goto err_unlock;
Sathya Perla713d03942009-11-22 22:02:45 +00002550 }
2551 req = cmd->va;
Sathya Perlab31c50a2009-09-17 10:30:13 -07002552
Somnath Kotur106df1e2011-10-27 07:12:13 +00002553 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05302554 OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb,
2555 cmd);
Ajit Khaparde84517482009-09-04 03:12:16 +00002556
2557 req->params.op_type = cpu_to_le32(flash_type);
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002558 if (flash_type == OPTYPE_OFFSET_SPECIFIED)
2559 req->params.offset = cpu_to_le32(img_offset);
2560
Ajit Khaparde84517482009-09-04 03:12:16 +00002561 req->params.op_code = cpu_to_le32(flash_opcode);
2562 req->params.data_buf_size = cpu_to_le32(buf_size);
2563
Suresh Reddyefaa4082015-07-10 05:32:48 -04002564 status = be_mcc_notify(adapter);
2565 if (status)
2566 goto err_unlock;
2567
Sathya Perlab7172412016-07-27 05:26:18 -04002568 mutex_unlock(&adapter->mcc_lock);
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002569
Suresh Reddy5eeff632014-01-06 13:02:24 +05302570 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
2571 msecs_to_jiffies(40000)))
Kalesh APfd451602014-07-17 16:20:21 +05302572 status = -ETIMEDOUT;
Sarveshwar Bandidd131e72010-05-25 16:16:32 -07002573 else
2574 status = adapter->flash_status;
Ajit Khaparde84517482009-09-04 03:12:16 +00002575
Dan Carpenter2892d9c2010-05-26 04:46:35 +00002576 return status;
2577
2578err_unlock:
Sathya Perlab7172412016-07-27 05:26:18 -04002579 mutex_unlock(&adapter->mcc_lock);
Ajit Khaparde84517482009-09-04 03:12:16 +00002580 return status;
2581}
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002582
Suresh Reddya23113b2015-12-30 01:28:59 -05002583static int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc,
2584 u16 img_optype, u32 img_offset, u32 crc_offset)
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002585{
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002586 struct be_cmd_read_flash_crc *req;
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002587 struct be_mcc_wrb *wrb;
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002588 int status;
2589
Sathya Perlab7172412016-07-27 05:26:18 -04002590 mutex_lock(&adapter->mcc_lock);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002591
2592 wrb = wrb_from_mccq(adapter);
Sathya Perla713d03942009-11-22 22:02:45 +00002593 if (!wrb) {
2594 status = -EBUSY;
2595 goto err;
2596 }
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002597 req = embedded_payload(wrb);
2598
Somnath Kotur106df1e2011-10-27 07:12:13 +00002599 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002600 OPCODE_COMMON_READ_FLASHROM, sizeof(*req),
2601 wrb, NULL);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002602
Vasundhara Volam70a7b522015-02-06 08:18:39 -05002603 req->params.op_type = cpu_to_le32(img_optype);
2604 if (img_optype == OPTYPE_OFFSET_SPECIFIED)
2605 req->params.offset = cpu_to_le32(img_offset + crc_offset);
2606 else
2607 req->params.offset = cpu_to_le32(crc_offset);
2608
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002609 req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT);
Ajit Khaparde8b93b712010-03-31 01:57:10 +00002610 req->params.data_buf_size = cpu_to_le32(0x4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002611
2612 status = be_mcc_notify_wait(adapter);
2613 if (!status)
Padmanabh Ratnakarbe716442012-10-22 23:02:44 +00002614 memcpy(flashed_crc, req->crc, 4);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002615
Sathya Perla713d03942009-11-22 22:02:45 +00002616err:
Sathya Perlab7172412016-07-27 05:26:18 -04002617 mutex_unlock(&adapter->mcc_lock);
Sarveshwar Bandifa9a6fe2009-11-20 14:23:47 -08002618 return status;
2619}
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00002620
Suresh Reddya23113b2015-12-30 01:28:59 -05002621static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "};
2622
2623static bool phy_flashing_required(struct be_adapter *adapter)
2624{
2625 return (adapter->phy.phy_type == PHY_TYPE_TN_8022 &&
2626 adapter->phy.interface_type == PHY_TYPE_BASET_10GB);
2627}
2628
2629static bool is_comp_in_ufi(struct be_adapter *adapter,
2630 struct flash_section_info *fsec, int type)
2631{
2632 int i = 0, img_type = 0;
2633 struct flash_section_info_g2 *fsec_g2 = NULL;
2634
2635 if (BE2_chip(adapter))
2636 fsec_g2 = (struct flash_section_info_g2 *)fsec;
2637
2638 for (i = 0; i < MAX_FLASH_COMP; i++) {
2639 if (fsec_g2)
2640 img_type = le32_to_cpu(fsec_g2->fsec_entry[i].type);
2641 else
2642 img_type = le32_to_cpu(fsec->fsec_entry[i].type);
2643
2644 if (img_type == type)
2645 return true;
2646 }
2647 return false;
2648}
2649
2650static struct flash_section_info *get_fsec_info(struct be_adapter *adapter,
2651 int header_size,
2652 const struct firmware *fw)
2653{
2654 struct flash_section_info *fsec = NULL;
2655 const u8 *p = fw->data;
2656
2657 p += header_size;
2658 while (p < (fw->data + fw->size)) {
2659 fsec = (struct flash_section_info *)p;
2660 if (!memcmp(flash_cookie, fsec->cookie, sizeof(flash_cookie)))
2661 return fsec;
2662 p += 32;
2663 }
2664 return NULL;
2665}
2666
2667static int be_check_flash_crc(struct be_adapter *adapter, const u8 *p,
2668 u32 img_offset, u32 img_size, int hdr_size,
2669 u16 img_optype, bool *crc_match)
2670{
2671 u32 crc_offset;
2672 int status;
2673 u8 crc[4];
2674
2675 status = be_cmd_get_flash_crc(adapter, crc, img_optype, img_offset,
2676 img_size - 4);
2677 if (status)
2678 return status;
2679
2680 crc_offset = hdr_size + img_offset + img_size - 4;
2681
2682 /* Skip flashing, if crc of flashed region matches */
2683 if (!memcmp(crc, p + crc_offset, 4))
2684 *crc_match = true;
2685 else
2686 *crc_match = false;
2687
2688 return status;
2689}
2690
2691static int be_flash(struct be_adapter *adapter, const u8 *img,
2692 struct be_dma_mem *flash_cmd, int optype, int img_size,
2693 u32 img_offset)
2694{
2695 u32 flash_op, num_bytes, total_bytes = img_size, bytes_sent = 0;
2696 struct be_cmd_write_flashrom *req = flash_cmd->va;
2697 int status;
2698
2699 while (total_bytes) {
2700 num_bytes = min_t(u32, 32 * 1024, total_bytes);
2701
2702 total_bytes -= num_bytes;
2703
2704 if (!total_bytes) {
2705 if (optype == OPTYPE_PHY_FW)
2706 flash_op = FLASHROM_OPER_PHY_FLASH;
2707 else
2708 flash_op = FLASHROM_OPER_FLASH;
2709 } else {
2710 if (optype == OPTYPE_PHY_FW)
2711 flash_op = FLASHROM_OPER_PHY_SAVE;
2712 else
2713 flash_op = FLASHROM_OPER_SAVE;
2714 }
2715
2716 memcpy(req->data_buf, img, num_bytes);
2717 img += num_bytes;
2718 status = be_cmd_write_flashrom(adapter, flash_cmd, optype,
2719 flash_op, img_offset +
2720 bytes_sent, num_bytes);
2721 if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST &&
2722 optype == OPTYPE_PHY_FW)
2723 break;
2724 else if (status)
2725 return status;
2726
2727 bytes_sent += num_bytes;
2728 }
2729 return 0;
2730}
2731
Sriharsha Basavapatnaf5ef0172016-10-09 09:58:50 +05302732#define NCSI_UPDATE_LOG "NCSI section update is not supported in FW ver %s\n"
2733static bool be_fw_ncsi_supported(char *ver)
2734{
2735 int v1[4] = {3, 102, 148, 0}; /* Min ver that supports NCSI FW */
2736 int v2[4];
2737 int i;
2738
2739 if (sscanf(ver, "%d.%d.%d.%d", &v2[0], &v2[1], &v2[2], &v2[3]) != 4)
2740 return false;
2741
2742 for (i = 0; i < 4; i++) {
2743 if (v1[i] < v2[i])
2744 return true;
2745 else if (v1[i] > v2[i])
2746 return false;
2747 }
2748
2749 return true;
2750}
2751
Suresh Reddya23113b2015-12-30 01:28:59 -05002752/* For BE2, BE3 and BE3-R */
2753static int be_flash_BEx(struct be_adapter *adapter,
2754 const struct firmware *fw,
2755 struct be_dma_mem *flash_cmd, int num_of_images)
2756{
2757 int img_hdrs_size = (num_of_images * sizeof(struct image_hdr));
2758 struct device *dev = &adapter->pdev->dev;
2759 struct flash_section_info *fsec = NULL;
2760 int status, i, filehdr_size, num_comp;
2761 const struct flash_comp *pflashcomp;
2762 bool crc_match;
2763 const u8 *p;
2764
2765 struct flash_comp gen3_flash_types[] = {
2766 { BE3_ISCSI_PRIMARY_IMAGE_START, OPTYPE_ISCSI_ACTIVE,
2767 BE3_COMP_MAX_SIZE, IMAGE_FIRMWARE_ISCSI},
2768 { BE3_REDBOOT_START, OPTYPE_REDBOOT,
2769 BE3_REDBOOT_COMP_MAX_SIZE, IMAGE_BOOT_CODE},
2770 { BE3_ISCSI_BIOS_START, OPTYPE_BIOS,
2771 BE3_BIOS_COMP_MAX_SIZE, IMAGE_OPTION_ROM_ISCSI},
2772 { BE3_PXE_BIOS_START, OPTYPE_PXE_BIOS,
2773 BE3_BIOS_COMP_MAX_SIZE, IMAGE_OPTION_ROM_PXE},
2774 { BE3_FCOE_BIOS_START, OPTYPE_FCOE_BIOS,
2775 BE3_BIOS_COMP_MAX_SIZE, IMAGE_OPTION_ROM_FCOE},
2776 { BE3_ISCSI_BACKUP_IMAGE_START, OPTYPE_ISCSI_BACKUP,
2777 BE3_COMP_MAX_SIZE, IMAGE_FIRMWARE_BACKUP_ISCSI},
2778 { BE3_FCOE_PRIMARY_IMAGE_START, OPTYPE_FCOE_FW_ACTIVE,
2779 BE3_COMP_MAX_SIZE, IMAGE_FIRMWARE_FCOE},
2780 { BE3_FCOE_BACKUP_IMAGE_START, OPTYPE_FCOE_FW_BACKUP,
2781 BE3_COMP_MAX_SIZE, IMAGE_FIRMWARE_BACKUP_FCOE},
2782 { BE3_NCSI_START, OPTYPE_NCSI_FW,
2783 BE3_NCSI_COMP_MAX_SIZE, IMAGE_NCSI},
2784 { BE3_PHY_FW_START, OPTYPE_PHY_FW,
2785 BE3_PHY_FW_COMP_MAX_SIZE, IMAGE_FIRMWARE_PHY}
2786 };
2787
2788 struct flash_comp gen2_flash_types[] = {
2789 { BE2_ISCSI_PRIMARY_IMAGE_START, OPTYPE_ISCSI_ACTIVE,
2790 BE2_COMP_MAX_SIZE, IMAGE_FIRMWARE_ISCSI},
2791 { BE2_REDBOOT_START, OPTYPE_REDBOOT,
2792 BE2_REDBOOT_COMP_MAX_SIZE, IMAGE_BOOT_CODE},
2793 { BE2_ISCSI_BIOS_START, OPTYPE_BIOS,
2794 BE2_BIOS_COMP_MAX_SIZE, IMAGE_OPTION_ROM_ISCSI},
2795 { BE2_PXE_BIOS_START, OPTYPE_PXE_BIOS,
2796 BE2_BIOS_COMP_MAX_SIZE, IMAGE_OPTION_ROM_PXE},
2797 { BE2_FCOE_BIOS_START, OPTYPE_FCOE_BIOS,
2798 BE2_BIOS_COMP_MAX_SIZE, IMAGE_OPTION_ROM_FCOE},
2799 { BE2_ISCSI_BACKUP_IMAGE_START, OPTYPE_ISCSI_BACKUP,
2800 BE2_COMP_MAX_SIZE, IMAGE_FIRMWARE_BACKUP_ISCSI},
2801 { BE2_FCOE_PRIMARY_IMAGE_START, OPTYPE_FCOE_FW_ACTIVE,
2802 BE2_COMP_MAX_SIZE, IMAGE_FIRMWARE_FCOE},
2803 { BE2_FCOE_BACKUP_IMAGE_START, OPTYPE_FCOE_FW_BACKUP,
2804 BE2_COMP_MAX_SIZE, IMAGE_FIRMWARE_BACKUP_FCOE}
2805 };
2806
2807 if (BE3_chip(adapter)) {
2808 pflashcomp = gen3_flash_types;
2809 filehdr_size = sizeof(struct flash_file_hdr_g3);
2810 num_comp = ARRAY_SIZE(gen3_flash_types);
2811 } else {
2812 pflashcomp = gen2_flash_types;
2813 filehdr_size = sizeof(struct flash_file_hdr_g2);
2814 num_comp = ARRAY_SIZE(gen2_flash_types);
2815 img_hdrs_size = 0;
2816 }
2817
2818 /* Get flash section info*/
2819 fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw);
2820 if (!fsec) {
2821 dev_err(dev, "Invalid Cookie. FW image may be corrupted\n");
2822 return -1;
2823 }
2824 for (i = 0; i < num_comp; i++) {
2825 if (!is_comp_in_ufi(adapter, fsec, pflashcomp[i].img_type))
2826 continue;
2827
2828 if ((pflashcomp[i].optype == OPTYPE_NCSI_FW) &&
Sriharsha Basavapatnaf5ef0172016-10-09 09:58:50 +05302829 !be_fw_ncsi_supported(adapter->fw_ver)) {
2830 dev_info(dev, NCSI_UPDATE_LOG, adapter->fw_ver);
Suresh Reddya23113b2015-12-30 01:28:59 -05002831 continue;
Sriharsha Basavapatnaf5ef0172016-10-09 09:58:50 +05302832 }
Suresh Reddya23113b2015-12-30 01:28:59 -05002833
2834 if (pflashcomp[i].optype == OPTYPE_PHY_FW &&
2835 !phy_flashing_required(adapter))
2836 continue;
2837
2838 if (pflashcomp[i].optype == OPTYPE_REDBOOT) {
2839 status = be_check_flash_crc(adapter, fw->data,
2840 pflashcomp[i].offset,
2841 pflashcomp[i].size,
2842 filehdr_size +
2843 img_hdrs_size,
2844 OPTYPE_REDBOOT, &crc_match);
2845 if (status) {
2846 dev_err(dev,
2847 "Could not get CRC for 0x%x region\n",
2848 pflashcomp[i].optype);
2849 continue;
2850 }
2851
2852 if (crc_match)
2853 continue;
2854 }
2855
2856 p = fw->data + filehdr_size + pflashcomp[i].offset +
2857 img_hdrs_size;
2858 if (p + pflashcomp[i].size > fw->data + fw->size)
2859 return -1;
2860
2861 status = be_flash(adapter, p, flash_cmd, pflashcomp[i].optype,
2862 pflashcomp[i].size, 0);
2863 if (status) {
2864 dev_err(dev, "Flashing section type 0x%x failed\n",
2865 pflashcomp[i].img_type);
2866 return status;
2867 }
2868 }
2869 return 0;
2870}
2871
2872static u16 be_get_img_optype(struct flash_section_entry fsec_entry)
2873{
2874 u32 img_type = le32_to_cpu(fsec_entry.type);
2875 u16 img_optype = le16_to_cpu(fsec_entry.optype);
2876
2877 if (img_optype != 0xFFFF)
2878 return img_optype;
2879
2880 switch (img_type) {
2881 case IMAGE_FIRMWARE_ISCSI:
2882 img_optype = OPTYPE_ISCSI_ACTIVE;
2883 break;
2884 case IMAGE_BOOT_CODE:
2885 img_optype = OPTYPE_REDBOOT;
2886 break;
2887 case IMAGE_OPTION_ROM_ISCSI:
2888 img_optype = OPTYPE_BIOS;
2889 break;
2890 case IMAGE_OPTION_ROM_PXE:
2891 img_optype = OPTYPE_PXE_BIOS;
2892 break;
2893 case IMAGE_OPTION_ROM_FCOE:
2894 img_optype = OPTYPE_FCOE_BIOS;
2895 break;
2896 case IMAGE_FIRMWARE_BACKUP_ISCSI:
2897 img_optype = OPTYPE_ISCSI_BACKUP;
2898 break;
2899 case IMAGE_NCSI:
2900 img_optype = OPTYPE_NCSI_FW;
2901 break;
2902 case IMAGE_FLASHISM_JUMPVECTOR:
2903 img_optype = OPTYPE_FLASHISM_JUMPVECTOR;
2904 break;
2905 case IMAGE_FIRMWARE_PHY:
2906 img_optype = OPTYPE_SH_PHY_FW;
2907 break;
2908 case IMAGE_REDBOOT_DIR:
2909 img_optype = OPTYPE_REDBOOT_DIR;
2910 break;
2911 case IMAGE_REDBOOT_CONFIG:
2912 img_optype = OPTYPE_REDBOOT_CONFIG;
2913 break;
2914 case IMAGE_UFI_DIR:
2915 img_optype = OPTYPE_UFI_DIR;
2916 break;
2917 default:
2918 break;
2919 }
2920
2921 return img_optype;
2922}
2923
2924static int be_flash_skyhawk(struct be_adapter *adapter,
2925 const struct firmware *fw,
2926 struct be_dma_mem *flash_cmd, int num_of_images)
2927{
2928 int img_hdrs_size = num_of_images * sizeof(struct image_hdr);
2929 bool crc_match, old_fw_img, flash_offset_support = true;
2930 struct device *dev = &adapter->pdev->dev;
2931 struct flash_section_info *fsec = NULL;
2932 u32 img_offset, img_size, img_type;
2933 u16 img_optype, flash_optype;
2934 int status, i, filehdr_size;
2935 const u8 *p;
2936
2937 filehdr_size = sizeof(struct flash_file_hdr_g3);
2938 fsec = get_fsec_info(adapter, filehdr_size + img_hdrs_size, fw);
2939 if (!fsec) {
2940 dev_err(dev, "Invalid Cookie. FW image may be corrupted\n");
2941 return -EINVAL;
2942 }
2943
2944retry_flash:
2945 for (i = 0; i < le32_to_cpu(fsec->fsec_hdr.num_images); i++) {
2946 img_offset = le32_to_cpu(fsec->fsec_entry[i].offset);
2947 img_size = le32_to_cpu(fsec->fsec_entry[i].pad_size);
2948 img_type = le32_to_cpu(fsec->fsec_entry[i].type);
2949 img_optype = be_get_img_optype(fsec->fsec_entry[i]);
2950 old_fw_img = fsec->fsec_entry[i].optype == 0xFFFF;
2951
2952 if (img_optype == 0xFFFF)
2953 continue;
2954
2955 if (flash_offset_support)
2956 flash_optype = OPTYPE_OFFSET_SPECIFIED;
2957 else
2958 flash_optype = img_optype;
2959
2960 /* Don't bother verifying CRC if an old FW image is being
2961 * flashed
2962 */
2963 if (old_fw_img)
2964 goto flash;
2965
2966 status = be_check_flash_crc(adapter, fw->data, img_offset,
2967 img_size, filehdr_size +
2968 img_hdrs_size, flash_optype,
2969 &crc_match);
2970 if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST ||
2971 base_status(status) == MCC_STATUS_ILLEGAL_FIELD) {
2972 /* The current FW image on the card does not support
2973 * OFFSET based flashing. Retry using older mechanism
2974 * of OPTYPE based flashing
2975 */
2976 if (flash_optype == OPTYPE_OFFSET_SPECIFIED) {
2977 flash_offset_support = false;
2978 goto retry_flash;
2979 }
2980
2981 /* The current FW image on the card does not recognize
2982 * the new FLASH op_type. The FW download is partially
2983 * complete. Reboot the server now to enable FW image
2984 * to recognize the new FLASH op_type. To complete the
2985 * remaining process, download the same FW again after
2986 * the reboot.
2987 */
2988 dev_err(dev, "Flash incomplete. Reset the server\n");
2989 dev_err(dev, "Download FW image again after reset\n");
2990 return -EAGAIN;
2991 } else if (status) {
2992 dev_err(dev, "Could not get CRC for 0x%x region\n",
2993 img_optype);
2994 return -EFAULT;
2995 }
2996
2997 if (crc_match)
2998 continue;
2999
3000flash:
3001 p = fw->data + filehdr_size + img_offset + img_hdrs_size;
3002 if (p + img_size > fw->data + fw->size)
3003 return -1;
3004
3005 status = be_flash(adapter, p, flash_cmd, flash_optype, img_size,
3006 img_offset);
3007
3008 /* The current FW image on the card does not support OFFSET
3009 * based flashing. Retry using older mechanism of OPTYPE based
3010 * flashing
3011 */
3012 if (base_status(status) == MCC_STATUS_ILLEGAL_FIELD &&
3013 flash_optype == OPTYPE_OFFSET_SPECIFIED) {
3014 flash_offset_support = false;
3015 goto retry_flash;
3016 }
3017
3018 /* For old FW images ignore ILLEGAL_FIELD error or errors on
3019 * UFI_DIR region
3020 */
3021 if (old_fw_img &&
3022 (base_status(status) == MCC_STATUS_ILLEGAL_FIELD ||
3023 (img_optype == OPTYPE_UFI_DIR &&
3024 base_status(status) == MCC_STATUS_FAILED))) {
3025 continue;
3026 } else if (status) {
3027 dev_err(dev, "Flashing section type 0x%x failed\n",
3028 img_type);
Suresh Reddy6b525782015-12-30 01:29:00 -05003029
3030 switch (addl_status(status)) {
3031 case MCC_ADDL_STATUS_MISSING_SIGNATURE:
3032 dev_err(dev,
3033 "Digital signature missing in FW\n");
3034 return -EINVAL;
3035 case MCC_ADDL_STATUS_INVALID_SIGNATURE:
3036 dev_err(dev,
3037 "Invalid digital signature in FW\n");
3038 return -EINVAL;
3039 default:
3040 return -EFAULT;
3041 }
Suresh Reddya23113b2015-12-30 01:28:59 -05003042 }
3043 }
3044 return 0;
3045}
3046
3047int lancer_fw_download(struct be_adapter *adapter,
3048 const struct firmware *fw)
3049{
3050 struct device *dev = &adapter->pdev->dev;
3051 struct be_dma_mem flash_cmd;
3052 const u8 *data_ptr = NULL;
3053 u8 *dest_image_ptr = NULL;
3054 size_t image_size = 0;
3055 u32 chunk_size = 0;
3056 u32 data_written = 0;
3057 u32 offset = 0;
3058 int status = 0;
3059 u8 add_status = 0;
3060 u8 change_status;
3061
3062 if (!IS_ALIGNED(fw->size, sizeof(u32))) {
3063 dev_err(dev, "FW image size should be multiple of 4\n");
3064 return -EINVAL;
3065 }
3066
3067 flash_cmd.size = sizeof(struct lancer_cmd_req_write_object)
3068 + LANCER_FW_DOWNLOAD_CHUNK;
3069 flash_cmd.va = dma_zalloc_coherent(dev, flash_cmd.size,
3070 &flash_cmd.dma, GFP_KERNEL);
3071 if (!flash_cmd.va)
3072 return -ENOMEM;
3073
3074 dest_image_ptr = flash_cmd.va +
3075 sizeof(struct lancer_cmd_req_write_object);
3076 image_size = fw->size;
3077 data_ptr = fw->data;
3078
3079 while (image_size) {
3080 chunk_size = min_t(u32, image_size, LANCER_FW_DOWNLOAD_CHUNK);
3081
3082 /* Copy the image chunk content. */
3083 memcpy(dest_image_ptr, data_ptr, chunk_size);
3084
3085 status = lancer_cmd_write_object(adapter, &flash_cmd,
3086 chunk_size, offset,
3087 LANCER_FW_DOWNLOAD_LOCATION,
3088 &data_written, &change_status,
3089 &add_status);
3090 if (status)
3091 break;
3092
3093 offset += data_written;
3094 data_ptr += data_written;
3095 image_size -= data_written;
3096 }
3097
3098 if (!status) {
3099 /* Commit the FW written */
3100 status = lancer_cmd_write_object(adapter, &flash_cmd,
3101 0, offset,
3102 LANCER_FW_DOWNLOAD_LOCATION,
3103 &data_written, &change_status,
3104 &add_status);
3105 }
3106
3107 dma_free_coherent(dev, flash_cmd.size, flash_cmd.va, flash_cmd.dma);
3108 if (status) {
3109 dev_err(dev, "Firmware load error\n");
3110 return be_cmd_status(status);
3111 }
3112
3113 dev_info(dev, "Firmware flashed successfully\n");
3114
3115 if (change_status == LANCER_FW_RESET_NEEDED) {
3116 dev_info(dev, "Resetting adapter to activate new FW\n");
3117 status = lancer_physdev_ctrl(adapter,
3118 PHYSDEV_CONTROL_FW_RESET_MASK);
3119 if (status) {
3120 dev_err(dev, "Adapter busy, could not reset FW\n");
3121 dev_err(dev, "Reboot server to activate new FW\n");
3122 }
3123 } else if (change_status != LANCER_NO_RESET_NEEDED) {
3124 dev_info(dev, "Reboot server to activate new FW\n");
3125 }
3126
3127 return 0;
3128}
3129
3130/* Check if the flash image file is compatible with the adapter that
3131 * is being flashed.
3132 */
3133static bool be_check_ufi_compatibility(struct be_adapter *adapter,
3134 struct flash_file_hdr_g3 *fhdr)
3135{
3136 if (!fhdr) {
3137 dev_err(&adapter->pdev->dev, "Invalid FW UFI file");
3138 return false;
3139 }
3140
3141 /* First letter of the build version is used to identify
3142 * which chip this image file is meant for.
3143 */
3144 switch (fhdr->build[0]) {
3145 case BLD_STR_UFI_TYPE_SH:
3146 if (!skyhawk_chip(adapter))
3147 return false;
3148 break;
3149 case BLD_STR_UFI_TYPE_BE3:
3150 if (!BE3_chip(adapter))
3151 return false;
3152 break;
3153 case BLD_STR_UFI_TYPE_BE2:
3154 if (!BE2_chip(adapter))
3155 return false;
3156 break;
3157 default:
3158 return false;
3159 }
3160
3161 /* In BE3 FW images the "asic_type_rev" field doesn't track the
3162 * asic_rev of the chips it is compatible with.
3163 * When asic_type_rev is 0 the image is compatible only with
3164 * pre-BE3-R chips (asic_rev < 0x10)
3165 */
3166 if (BEx_chip(adapter) && fhdr->asic_type_rev == 0)
3167 return adapter->asic_rev < 0x10;
3168 else
3169 return (fhdr->asic_type_rev >= adapter->asic_rev);
3170}
3171
3172int be_fw_download(struct be_adapter *adapter, const struct firmware *fw)
3173{
3174 struct device *dev = &adapter->pdev->dev;
3175 struct flash_file_hdr_g3 *fhdr3;
3176 struct image_hdr *img_hdr_ptr;
3177 int status = 0, i, num_imgs;
3178 struct be_dma_mem flash_cmd;
3179
3180 fhdr3 = (struct flash_file_hdr_g3 *)fw->data;
3181 if (!be_check_ufi_compatibility(adapter, fhdr3)) {
3182 dev_err(dev, "Flash image is not compatible with adapter\n");
3183 return -EINVAL;
3184 }
3185
3186 flash_cmd.size = sizeof(struct be_cmd_write_flashrom);
3187 flash_cmd.va = dma_zalloc_coherent(dev, flash_cmd.size, &flash_cmd.dma,
3188 GFP_KERNEL);
3189 if (!flash_cmd.va)
3190 return -ENOMEM;
3191
3192 num_imgs = le32_to_cpu(fhdr3->num_imgs);
3193 for (i = 0; i < num_imgs; i++) {
3194 img_hdr_ptr = (struct image_hdr *)(fw->data +
3195 (sizeof(struct flash_file_hdr_g3) +
3196 i * sizeof(struct image_hdr)));
3197 if (!BE2_chip(adapter) &&
3198 le32_to_cpu(img_hdr_ptr->imageid) != 1)
3199 continue;
3200
3201 if (skyhawk_chip(adapter))
3202 status = be_flash_skyhawk(adapter, fw, &flash_cmd,
3203 num_imgs);
3204 else
3205 status = be_flash_BEx(adapter, fw, &flash_cmd,
3206 num_imgs);
3207 }
3208
3209 dma_free_coherent(dev, flash_cmd.size, flash_cmd.va, flash_cmd.dma);
3210 if (!status)
3211 dev_info(dev, "Firmware flashed successfully\n");
3212
3213 return status;
3214}
3215
Dan Carpenterc196b022010-05-26 04:47:39 +00003216int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303217 struct be_dma_mem *nonemb_cmd)
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003218{
3219 struct be_mcc_wrb *wrb;
3220 struct be_cmd_req_acpi_wol_magic_config *req;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003221 int status;
3222
Sathya Perlab7172412016-07-27 05:26:18 -04003223 mutex_lock(&adapter->mcc_lock);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003224
3225 wrb = wrb_from_mccq(adapter);
3226 if (!wrb) {
3227 status = -EBUSY;
3228 goto err;
3229 }
3230 req = nonemb_cmd->va;
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003231
Somnath Kotur106df1e2011-10-27 07:12:13 +00003232 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303233 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req),
3234 wrb, nonemb_cmd);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003235 memcpy(req->magic_mac, mac, ETH_ALEN);
3236
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003237 status = be_mcc_notify_wait(adapter);
3238
3239err:
Sathya Perlab7172412016-07-27 05:26:18 -04003240 mutex_unlock(&adapter->mcc_lock);
Ajit Khaparde71d8d1b2009-12-03 06:16:59 +00003241 return status;
3242}
Suresh Rff33a6e2009-12-03 16:15:52 -08003243
Sarveshwar Bandifced9992009-12-23 04:41:44 +00003244int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num,
3245 u8 loopback_type, u8 enable)
3246{
3247 struct be_mcc_wrb *wrb;
3248 struct be_cmd_req_set_lmode *req;
3249 int status;
3250
Somnath Kotur2e365b12016-02-03 09:49:20 +05303251 if (!be_cmd_allowed(adapter, OPCODE_LOWLEVEL_SET_LOOPBACK_MODE,
3252 CMD_SUBSYSTEM_LOWLEVEL))
3253 return -EPERM;
3254
Sathya Perlab7172412016-07-27 05:26:18 -04003255 mutex_lock(&adapter->mcc_lock);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00003256
3257 wrb = wrb_from_mccq(adapter);
3258 if (!wrb) {
3259 status = -EBUSY;
Suresh Reddy9c855972015-07-10 05:32:50 -04003260 goto err_unlock;
Sarveshwar Bandifced9992009-12-23 04:41:44 +00003261 }
3262
3263 req = embedded_payload(wrb);
3264
Somnath Kotur106df1e2011-10-27 07:12:13 +00003265 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303266 OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req),
3267 wrb, NULL);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00003268
3269 req->src_port = port_num;
3270 req->dest_port = port_num;
3271 req->loopback_type = loopback_type;
3272 req->loopback_state = enable;
3273
Suresh Reddy9c855972015-07-10 05:32:50 -04003274 status = be_mcc_notify(adapter);
3275 if (status)
3276 goto err_unlock;
3277
Sathya Perlab7172412016-07-27 05:26:18 -04003278 mutex_unlock(&adapter->mcc_lock);
Suresh Reddy9c855972015-07-10 05:32:50 -04003279
3280 if (!wait_for_completion_timeout(&adapter->et_cmd_compl,
3281 msecs_to_jiffies(SET_LB_MODE_TIMEOUT)))
3282 status = -ETIMEDOUT;
3283
3284 return status;
3285
3286err_unlock:
Sathya Perlab7172412016-07-27 05:26:18 -04003287 mutex_unlock(&adapter->mcc_lock);
Sarveshwar Bandifced9992009-12-23 04:41:44 +00003288 return status;
3289}
3290
Suresh Rff33a6e2009-12-03 16:15:52 -08003291int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303292 u32 loopback_type, u32 pkt_size, u32 num_pkts,
3293 u64 pattern)
Suresh Rff33a6e2009-12-03 16:15:52 -08003294{
3295 struct be_mcc_wrb *wrb;
3296 struct be_cmd_req_loopback_test *req;
Suresh Reddy5eeff632014-01-06 13:02:24 +05303297 struct be_cmd_resp_loopback_test *resp;
Suresh Rff33a6e2009-12-03 16:15:52 -08003298 int status;
3299
Somnath Kotur2e365b12016-02-03 09:49:20 +05303300 if (!be_cmd_allowed(adapter, OPCODE_LOWLEVEL_LOOPBACK_TEST,
3301 CMD_SUBSYSTEM_LOWLEVEL))
3302 return -EPERM;
3303
Sathya Perlab7172412016-07-27 05:26:18 -04003304 mutex_lock(&adapter->mcc_lock);
Suresh Rff33a6e2009-12-03 16:15:52 -08003305
3306 wrb = wrb_from_mccq(adapter);
3307 if (!wrb) {
3308 status = -EBUSY;
3309 goto err;
3310 }
3311
3312 req = embedded_payload(wrb);
3313
Somnath Kotur106df1e2011-10-27 07:12:13 +00003314 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303315 OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb,
3316 NULL);
Suresh Rff33a6e2009-12-03 16:15:52 -08003317
Suresh Reddy5eeff632014-01-06 13:02:24 +05303318 req->hdr.timeout = cpu_to_le32(15);
Suresh Rff33a6e2009-12-03 16:15:52 -08003319 req->pattern = cpu_to_le64(pattern);
3320 req->src_port = cpu_to_le32(port_num);
3321 req->dest_port = cpu_to_le32(port_num);
3322 req->pkt_size = cpu_to_le32(pkt_size);
3323 req->num_pkts = cpu_to_le32(num_pkts);
3324 req->loopback_type = cpu_to_le32(loopback_type);
3325
Suresh Reddyefaa4082015-07-10 05:32:48 -04003326 status = be_mcc_notify(adapter);
3327 if (status)
3328 goto err;
Suresh Rff33a6e2009-12-03 16:15:52 -08003329
Sathya Perlab7172412016-07-27 05:26:18 -04003330 mutex_unlock(&adapter->mcc_lock);
Suresh Reddy5eeff632014-01-06 13:02:24 +05303331
3332 wait_for_completion(&adapter->et_cmd_compl);
3333 resp = embedded_payload(wrb);
3334 status = le32_to_cpu(resp->status);
3335
3336 return status;
Suresh Rff33a6e2009-12-03 16:15:52 -08003337err:
Sathya Perlab7172412016-07-27 05:26:18 -04003338 mutex_unlock(&adapter->mcc_lock);
Suresh Rff33a6e2009-12-03 16:15:52 -08003339 return status;
3340}
3341
3342int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303343 u32 byte_cnt, struct be_dma_mem *cmd)
Suresh Rff33a6e2009-12-03 16:15:52 -08003344{
3345 struct be_mcc_wrb *wrb;
3346 struct be_cmd_req_ddrdma_test *req;
Suresh Rff33a6e2009-12-03 16:15:52 -08003347 int status;
3348 int i, j = 0;
3349
Somnath Kotur2e365b12016-02-03 09:49:20 +05303350 if (!be_cmd_allowed(adapter, OPCODE_LOWLEVEL_HOST_DDR_DMA,
3351 CMD_SUBSYSTEM_LOWLEVEL))
3352 return -EPERM;
3353
Sathya Perlab7172412016-07-27 05:26:18 -04003354 mutex_lock(&adapter->mcc_lock);
Suresh Rff33a6e2009-12-03 16:15:52 -08003355
3356 wrb = wrb_from_mccq(adapter);
3357 if (!wrb) {
3358 status = -EBUSY;
3359 goto err;
3360 }
3361 req = cmd->va;
Somnath Kotur106df1e2011-10-27 07:12:13 +00003362 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303363 OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb,
3364 cmd);
Suresh Rff33a6e2009-12-03 16:15:52 -08003365
3366 req->pattern = cpu_to_le64(pattern);
3367 req->byte_count = cpu_to_le32(byte_cnt);
3368 for (i = 0; i < byte_cnt; i++) {
3369 req->snd_buff[i] = (u8)(pattern >> (j*8));
3370 j++;
3371 if (j > 7)
3372 j = 0;
3373 }
3374
3375 status = be_mcc_notify_wait(adapter);
3376
3377 if (!status) {
3378 struct be_cmd_resp_ddrdma_test *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05303379
Suresh Rff33a6e2009-12-03 16:15:52 -08003380 resp = cmd->va;
3381 if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) ||
Kalesh APcd3307aa2014-09-19 15:47:02 +05303382 resp->snd_err) {
Suresh Rff33a6e2009-12-03 16:15:52 -08003383 status = -1;
3384 }
3385 }
3386
3387err:
Sathya Perlab7172412016-07-27 05:26:18 -04003388 mutex_unlock(&adapter->mcc_lock);
Suresh Rff33a6e2009-12-03 16:15:52 -08003389 return status;
3390}
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003391
Dan Carpenterc196b022010-05-26 04:47:39 +00003392int be_cmd_get_seeprom_data(struct be_adapter *adapter,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303393 struct be_dma_mem *nonemb_cmd)
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003394{
3395 struct be_mcc_wrb *wrb;
3396 struct be_cmd_req_seeprom_read *req;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003397 int status;
3398
Sathya Perlab7172412016-07-27 05:26:18 -04003399 mutex_lock(&adapter->mcc_lock);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003400
3401 wrb = wrb_from_mccq(adapter);
Ajit Khapardee45ff012011-02-04 17:18:28 +00003402 if (!wrb) {
3403 status = -EBUSY;
3404 goto err;
3405 }
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003406 req = nonemb_cmd->va;
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003407
Somnath Kotur106df1e2011-10-27 07:12:13 +00003408 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303409 OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb,
3410 nonemb_cmd);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003411
3412 status = be_mcc_notify_wait(adapter);
3413
Ajit Khapardee45ff012011-02-04 17:18:28 +00003414err:
Sathya Perlab7172412016-07-27 05:26:18 -04003415 mutex_unlock(&adapter->mcc_lock);
Sarveshwar Bandi368c0ca2010-01-08 00:07:27 -08003416 return status;
3417}
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003418
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00003419int be_cmd_get_phy_info(struct be_adapter *adapter)
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003420{
3421 struct be_mcc_wrb *wrb;
3422 struct be_cmd_req_get_phy_info *req;
Sathya Perla306f1342011-08-02 19:57:45 +00003423 struct be_dma_mem cmd;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003424 int status;
3425
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003426 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS,
3427 CMD_SUBSYSTEM_COMMON))
3428 return -EPERM;
3429
Sathya Perlab7172412016-07-27 05:26:18 -04003430 mutex_lock(&adapter->mcc_lock);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003431
3432 wrb = wrb_from_mccq(adapter);
3433 if (!wrb) {
3434 status = -EBUSY;
3435 goto err;
3436 }
Sathya Perla306f1342011-08-02 19:57:45 +00003437 cmd.size = sizeof(struct be_cmd_req_get_phy_info);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303438 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3439 GFP_ATOMIC);
Sathya Perla306f1342011-08-02 19:57:45 +00003440 if (!cmd.va) {
3441 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
3442 status = -ENOMEM;
3443 goto err;
3444 }
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003445
Sathya Perla306f1342011-08-02 19:57:45 +00003446 req = cmd.va;
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003447
Somnath Kotur106df1e2011-10-27 07:12:13 +00003448 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303449 OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req),
3450 wrb, &cmd);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003451
3452 status = be_mcc_notify_wait(adapter);
Sathya Perla306f1342011-08-02 19:57:45 +00003453 if (!status) {
3454 struct be_phy_info *resp_phy_info =
3455 cmd.va + sizeof(struct be_cmd_req_hdr);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303456
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00003457 adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type);
3458 adapter->phy.interface_type =
Sathya Perla306f1342011-08-02 19:57:45 +00003459 le16_to_cpu(resp_phy_info->interface_type);
Ajit Khaparde42f11cf2012-04-21 18:53:22 +00003460 adapter->phy.auto_speeds_supported =
3461 le16_to_cpu(resp_phy_info->auto_speeds_supported);
3462 adapter->phy.fixed_speeds_supported =
3463 le16_to_cpu(resp_phy_info->fixed_speeds_supported);
3464 adapter->phy.misc_params =
3465 le32_to_cpu(resp_phy_info->misc_params);
Vasundhara Volam68cb7e42013-08-06 09:27:18 +05303466
3467 if (BE2_chip(adapter)) {
3468 adapter->phy.fixed_speeds_supported =
3469 BE_SUPPORTED_SPEED_10GBPS |
3470 BE_SUPPORTED_SPEED_1GBPS;
3471 }
Sathya Perla306f1342011-08-02 19:57:45 +00003472 }
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303473 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003474err:
Sathya Perlab7172412016-07-27 05:26:18 -04003475 mutex_unlock(&adapter->mcc_lock);
Ajit Khapardeee3cb622010-07-01 03:51:00 +00003476 return status;
3477}
Ajit Khapardee1d18732010-07-23 01:52:13 +00003478
Lad, Prabhakarbc0ee162015-02-05 15:24:43 +00003479static int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain)
Ajit Khapardee1d18732010-07-23 01:52:13 +00003480{
3481 struct be_mcc_wrb *wrb;
3482 struct be_cmd_req_set_qos *req;
3483 int status;
3484
Sathya Perlab7172412016-07-27 05:26:18 -04003485 mutex_lock(&adapter->mcc_lock);
Ajit Khapardee1d18732010-07-23 01:52:13 +00003486
3487 wrb = wrb_from_mccq(adapter);
3488 if (!wrb) {
3489 status = -EBUSY;
3490 goto err;
3491 }
3492
3493 req = embedded_payload(wrb);
3494
Somnath Kotur106df1e2011-10-27 07:12:13 +00003495 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303496 OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL);
Ajit Khapardee1d18732010-07-23 01:52:13 +00003497
3498 req->hdr.domain = domain;
Ajit Khaparde6bff57a2011-02-11 13:33:02 +00003499 req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC);
3500 req->max_bps_nic = cpu_to_le32(bps);
Ajit Khapardee1d18732010-07-23 01:52:13 +00003501
3502 status = be_mcc_notify_wait(adapter);
3503
3504err:
Sathya Perlab7172412016-07-27 05:26:18 -04003505 mutex_unlock(&adapter->mcc_lock);
Ajit Khapardee1d18732010-07-23 01:52:13 +00003506 return status;
3507}
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003508
3509int be_cmd_get_cntl_attributes(struct be_adapter *adapter)
3510{
3511 struct be_mcc_wrb *wrb;
3512 struct be_cmd_req_cntl_attribs *req;
3513 struct be_cmd_resp_cntl_attribs *resp;
Sriharsha Basavapatnaa155a5d2015-07-22 11:15:12 +05303514 int status, i;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003515 int payload_len = max(sizeof(*req), sizeof(*resp));
3516 struct mgmt_controller_attrib *attribs;
3517 struct be_dma_mem attribs_cmd;
Sriharsha Basavapatnaa155a5d2015-07-22 11:15:12 +05303518 u32 *serial_num;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003519
Suresh Reddyd98ef502013-04-25 00:56:55 +00003520 if (mutex_lock_interruptible(&adapter->mbox_lock))
3521 return -1;
3522
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003523 memset(&attribs_cmd, 0, sizeof(struct be_dma_mem));
3524 attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303525 attribs_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
3526 attribs_cmd.size,
3527 &attribs_cmd.dma, GFP_ATOMIC);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003528 if (!attribs_cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303529 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00003530 status = -ENOMEM;
3531 goto err;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003532 }
3533
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003534 wrb = wrb_from_mbox(adapter);
3535 if (!wrb) {
3536 status = -EBUSY;
3537 goto err;
3538 }
3539 req = attribs_cmd.va;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003540
Somnath Kotur106df1e2011-10-27 07:12:13 +00003541 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303542 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len,
3543 wrb, &attribs_cmd);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003544
3545 status = be_mbox_notify_wait(adapter);
3546 if (!status) {
Joe Perches43d620c2011-06-16 19:08:06 +00003547 attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003548 adapter->hba_port_num = attribs->hba_attribs.phy_port;
Sriharsha Basavapatnaa155a5d2015-07-22 11:15:12 +05303549 serial_num = attribs->hba_attribs.controller_serial_number;
3550 for (i = 0; i < CNTL_SERIAL_NUM_WORDS; i++)
3551 adapter->serial_num[i] = le32_to_cpu(serial_num[i]) &
3552 (BIT_MASK(16) - 1);
Sriharsha Basavapatna6ee080b2016-10-09 09:58:49 +05303553 /* For BEx, since GET_FUNC_CONFIG command is not
3554 * supported, we read funcnum here as a workaround.
3555 */
3556 if (BEx_chip(adapter))
3557 adapter->pf_num = attribs->hba_attribs.pci_funcnum;
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003558 }
3559
3560err:
3561 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00003562 if (attribs_cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303563 dma_free_coherent(&adapter->pdev->dev, attribs_cmd.size,
3564 attribs_cmd.va, attribs_cmd.dma);
Ajit Khaparde9e1453c2011-02-20 11:42:22 +00003565 return status;
3566}
Sathya Perla2e588f82011-03-11 02:49:26 +00003567
3568/* Uses mbox */
Sathya Perla2dc1deb2011-07-19 19:52:33 +00003569int be_cmd_req_native_mode(struct be_adapter *adapter)
Sathya Perla2e588f82011-03-11 02:49:26 +00003570{
3571 struct be_mcc_wrb *wrb;
3572 struct be_cmd_req_set_func_cap *req;
3573 int status;
3574
3575 if (mutex_lock_interruptible(&adapter->mbox_lock))
3576 return -1;
3577
3578 wrb = wrb_from_mbox(adapter);
3579 if (!wrb) {
3580 status = -EBUSY;
3581 goto err;
3582 }
3583
3584 req = embedded_payload(wrb);
3585
Somnath Kotur106df1e2011-10-27 07:12:13 +00003586 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303587 OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP,
3588 sizeof(*req), wrb, NULL);
Sathya Perla2e588f82011-03-11 02:49:26 +00003589
3590 req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS |
3591 CAPABILITY_BE3_NATIVE_ERX_API);
3592 req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API);
3593
3594 status = be_mbox_notify_wait(adapter);
3595 if (!status) {
3596 struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303597
Sathya Perla2e588f82011-03-11 02:49:26 +00003598 adapter->be3_native = le32_to_cpu(resp->cap_flags) &
3599 CAPABILITY_BE3_NATIVE_ERX_API;
Sathya Perlad3791422012-09-28 04:39:44 +00003600 if (!adapter->be3_native)
3601 dev_warn(&adapter->pdev->dev,
3602 "adapter not in advanced mode\n");
Sathya Perla2e588f82011-03-11 02:49:26 +00003603 }
3604err:
3605 mutex_unlock(&adapter->mbox_lock);
3606 return status;
3607}
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003608
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003609/* Get privilege(s) for a function */
3610int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege,
3611 u32 domain)
3612{
3613 struct be_mcc_wrb *wrb;
3614 struct be_cmd_req_get_fn_privileges *req;
3615 int status;
3616
Sathya Perlab7172412016-07-27 05:26:18 -04003617 mutex_lock(&adapter->mcc_lock);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003618
3619 wrb = wrb_from_mccq(adapter);
3620 if (!wrb) {
3621 status = -EBUSY;
3622 goto err;
3623 }
3624
3625 req = embedded_payload(wrb);
3626
3627 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3628 OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req),
3629 wrb, NULL);
3630
3631 req->hdr.domain = domain;
3632
3633 status = be_mcc_notify_wait(adapter);
3634 if (!status) {
3635 struct be_cmd_resp_get_fn_privileges *resp =
3636 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303637
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003638 *privilege = le32_to_cpu(resp->privilege_mask);
Suresh Reddy02308d72014-01-15 13:23:36 +05303639
3640 /* In UMC mode FW does not return right privileges.
3641 * Override with correct privilege equivalent to PF.
3642 */
3643 if (BEx_chip(adapter) && be_is_mc(adapter) &&
3644 be_physfn(adapter))
3645 *privilege = MAX_PRIVILEGES;
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003646 }
3647
3648err:
Sathya Perlab7172412016-07-27 05:26:18 -04003649 mutex_unlock(&adapter->mcc_lock);
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00003650 return status;
3651}
3652
Sathya Perla04a06022013-07-23 15:25:00 +05303653/* Set privilege(s) for a function */
3654int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges,
3655 u32 domain)
3656{
3657 struct be_mcc_wrb *wrb;
3658 struct be_cmd_req_set_fn_privileges *req;
3659 int status;
3660
Sathya Perlab7172412016-07-27 05:26:18 -04003661 mutex_lock(&adapter->mcc_lock);
Sathya Perla04a06022013-07-23 15:25:00 +05303662
3663 wrb = wrb_from_mccq(adapter);
3664 if (!wrb) {
3665 status = -EBUSY;
3666 goto err;
3667 }
3668
3669 req = embedded_payload(wrb);
3670 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
3671 OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req),
3672 wrb, NULL);
3673 req->hdr.domain = domain;
3674 if (lancer_chip(adapter))
3675 req->privileges_lancer = cpu_to_le32(privileges);
3676 else
3677 req->privileges = cpu_to_le32(privileges);
3678
3679 status = be_mcc_notify_wait(adapter);
3680err:
Sathya Perlab7172412016-07-27 05:26:18 -04003681 mutex_unlock(&adapter->mcc_lock);
Sathya Perla04a06022013-07-23 15:25:00 +05303682 return status;
3683}
3684
Sathya Perla5a712c12013-07-23 15:24:59 +05303685/* pmac_id_valid: true => pmac_id is supplied and MAC address is requested.
3686 * pmac_id_valid: false => pmac_id or MAC address is requested.
3687 * If pmac_id is returned, pmac_id_valid is returned as true
3688 */
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003689int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303690 bool *pmac_id_valid, u32 *pmac_id, u32 if_handle,
3691 u8 domain)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003692{
3693 struct be_mcc_wrb *wrb;
3694 struct be_cmd_req_get_mac_list *req;
3695 int status;
3696 int mac_count;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003697 struct be_dma_mem get_mac_list_cmd;
3698 int i;
3699
3700 memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem));
3701 get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303702 get_mac_list_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
3703 get_mac_list_cmd.size,
3704 &get_mac_list_cmd.dma,
3705 GFP_ATOMIC);
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003706
3707 if (!get_mac_list_cmd.va) {
3708 dev_err(&adapter->pdev->dev,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303709 "Memory allocation failure during GET_MAC_LIST\n");
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003710 return -ENOMEM;
3711 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003712
Sathya Perlab7172412016-07-27 05:26:18 -04003713 mutex_lock(&adapter->mcc_lock);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003714
3715 wrb = wrb_from_mccq(adapter);
3716 if (!wrb) {
3717 status = -EBUSY;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003718 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003719 }
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003720
3721 req = get_mac_list_cmd.va;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003722
3723 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlabf591f52013-05-08 02:05:48 +00003724 OPCODE_COMMON_GET_MAC_LIST,
3725 get_mac_list_cmd.size, wrb, &get_mac_list_cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003726 req->hdr.domain = domain;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003727 req->mac_type = MAC_ADDRESS_TYPE_NETWORK;
Sathya Perla5a712c12013-07-23 15:24:59 +05303728 if (*pmac_id_valid) {
3729 req->mac_id = cpu_to_le32(*pmac_id);
Suresh Reddyb188f092014-01-15 13:23:39 +05303730 req->iface_id = cpu_to_le16(if_handle);
Sathya Perla5a712c12013-07-23 15:24:59 +05303731 req->perm_override = 0;
3732 } else {
3733 req->perm_override = 1;
3734 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003735
3736 status = be_mcc_notify_wait(adapter);
3737 if (!status) {
3738 struct be_cmd_resp_get_mac_list *resp =
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003739 get_mac_list_cmd.va;
Sathya Perla5a712c12013-07-23 15:24:59 +05303740
3741 if (*pmac_id_valid) {
3742 memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr,
3743 ETH_ALEN);
3744 goto out;
3745 }
3746
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003747 mac_count = resp->true_mac_count + resp->pseudo_mac_count;
3748 /* Mac list returned could contain one or more active mac_ids
Joe Perchesdbedd442015-03-06 20:49:12 -08003749 * or one or more true or pseudo permanent mac addresses.
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003750 * If an active mac_id is present, return first active mac_id
3751 * found.
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003752 */
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003753 for (i = 0; i < mac_count; i++) {
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003754 struct get_list_macaddr *mac_entry;
3755 u16 mac_addr_size;
3756 u32 mac_id;
3757
3758 mac_entry = &resp->macaddr_list[i];
3759 mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size);
3760 /* mac_id is a 32 bit value and mac_addr size
3761 * is 6 bytes
3762 */
3763 if (mac_addr_size == sizeof(u32)) {
Sathya Perla5a712c12013-07-23 15:24:59 +05303764 *pmac_id_valid = true;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003765 mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id;
3766 *pmac_id = le32_to_cpu(mac_id);
3767 goto out;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003768 }
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003769 }
Padmanabh Ratnakar1578e772012-06-07 04:37:08 +00003770 /* If no active mac_id found, return first mac addr */
Sathya Perla5a712c12013-07-23 15:24:59 +05303771 *pmac_id_valid = false;
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003772 memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303773 ETH_ALEN);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003774 }
3775
Padmanabh Ratnakare5e1ee82012-02-03 09:50:17 +00003776out:
Sathya Perlab7172412016-07-27 05:26:18 -04003777 mutex_unlock(&adapter->mcc_lock);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303778 dma_free_coherent(&adapter->pdev->dev, get_mac_list_cmd.size,
3779 get_mac_list_cmd.va, get_mac_list_cmd.dma);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003780 return status;
3781}
3782
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303783int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id,
3784 u8 *mac, u32 if_handle, bool active, u32 domain)
Sathya Perla5a712c12013-07-23 15:24:59 +05303785{
Suresh Reddyb188f092014-01-15 13:23:39 +05303786 if (!active)
3787 be_cmd_get_mac_from_list(adapter, mac, &active, &curr_pmac_id,
3788 if_handle, domain);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303789 if (BEx_chip(adapter))
Sathya Perla5a712c12013-07-23 15:24:59 +05303790 return be_cmd_mac_addr_query(adapter, mac, false,
Suresh Reddyb188f092014-01-15 13:23:39 +05303791 if_handle, curr_pmac_id);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303792 else
3793 /* Fetch the MAC address using pmac_id */
3794 return be_cmd_get_mac_from_list(adapter, mac, &active,
Suresh Reddyb188f092014-01-15 13:23:39 +05303795 &curr_pmac_id,
3796 if_handle, domain);
Sathya Perla5a712c12013-07-23 15:24:59 +05303797}
3798
Sathya Perla95046b92013-07-23 15:25:02 +05303799int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac)
3800{
3801 int status;
3802 bool pmac_valid = false;
3803
Joe Perchesc7bf7162015-03-02 19:54:47 -08003804 eth_zero_addr(mac);
Sathya Perla95046b92013-07-23 15:25:02 +05303805
Sathya Perla3175d8c2013-07-23 15:25:03 +05303806 if (BEx_chip(adapter)) {
3807 if (be_physfn(adapter))
3808 status = be_cmd_mac_addr_query(adapter, mac, true, 0,
3809 0);
3810 else
3811 status = be_cmd_mac_addr_query(adapter, mac, false,
3812 adapter->if_handle, 0);
3813 } else {
Sathya Perla95046b92013-07-23 15:25:02 +05303814 status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid,
Suresh Reddyb188f092014-01-15 13:23:39 +05303815 NULL, adapter->if_handle, 0);
Sathya Perla3175d8c2013-07-23 15:25:03 +05303816 }
3817
Sathya Perla95046b92013-07-23 15:25:02 +05303818 return status;
3819}
3820
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003821/* Uses synchronous MCCQ */
3822int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array,
3823 u8 mac_count, u32 domain)
3824{
3825 struct be_mcc_wrb *wrb;
3826 struct be_cmd_req_set_mac_list *req;
3827 int status;
3828 struct be_dma_mem cmd;
3829
3830 memset(&cmd, 0, sizeof(struct be_dma_mem));
3831 cmd.size = sizeof(struct be_cmd_req_set_mac_list);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05303832 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
3833 GFP_KERNEL);
Joe Perchesd0320f72013-03-14 13:07:21 +00003834 if (!cmd.va)
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003835 return -ENOMEM;
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003836
Sathya Perlab7172412016-07-27 05:26:18 -04003837 mutex_lock(&adapter->mcc_lock);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003838
3839 wrb = wrb_from_mccq(adapter);
3840 if (!wrb) {
3841 status = -EBUSY;
3842 goto err;
3843 }
3844
3845 req = cmd.va;
3846 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303847 OPCODE_COMMON_SET_MAC_LIST, sizeof(*req),
3848 wrb, &cmd);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003849
3850 req->hdr.domain = domain;
3851 req->mac_count = mac_count;
3852 if (mac_count)
3853 memcpy(req->mac, mac_array, ETH_ALEN*mac_count);
3854
3855 status = be_mcc_notify_wait(adapter);
3856
3857err:
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303858 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma);
Sathya Perlab7172412016-07-27 05:26:18 -04003859 mutex_unlock(&adapter->mcc_lock);
Padmanabh Ratnakar590c3912011-11-25 05:47:26 +00003860 return status;
3861}
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00003862
Sathya Perla3175d8c2013-07-23 15:25:03 +05303863/* Wrapper to delete any active MACs and provision the new mac.
3864 * Changes to MAC_LIST are allowed iff none of the MAC addresses in the
3865 * current list are active.
3866 */
3867int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom)
3868{
3869 bool active_mac = false;
3870 u8 old_mac[ETH_ALEN];
3871 u32 pmac_id;
3872 int status;
3873
3874 status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac,
Suresh Reddyb188f092014-01-15 13:23:39 +05303875 &pmac_id, if_id, dom);
3876
Sathya Perla3175d8c2013-07-23 15:25:03 +05303877 if (!status && active_mac)
3878 be_cmd_pmac_del(adapter, if_id, pmac_id, dom);
3879
3880 return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom);
3881}
3882
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003883int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid,
Kalesh APe7bcbd72015-05-06 05:30:32 -04003884 u32 domain, u16 intf_id, u16 hsw_mode, u8 spoofchk)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003885{
3886 struct be_mcc_wrb *wrb;
3887 struct be_cmd_req_set_hsw_config *req;
3888 void *ctxt;
3889 int status;
3890
Somnath Kotur884476b2016-06-22 08:54:55 -04003891 if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_HSW_CONFIG,
3892 CMD_SUBSYSTEM_COMMON))
3893 return -EPERM;
3894
Sathya Perlab7172412016-07-27 05:26:18 -04003895 mutex_lock(&adapter->mcc_lock);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003896
3897 wrb = wrb_from_mccq(adapter);
3898 if (!wrb) {
3899 status = -EBUSY;
3900 goto err;
3901 }
3902
3903 req = embedded_payload(wrb);
3904 ctxt = &req->context;
3905
3906 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303907 OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb,
3908 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003909
3910 req->hdr.domain = domain;
3911 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id);
3912 if (pvid) {
3913 AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1);
3914 AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid);
3915 }
Somnath Kotur884476b2016-06-22 08:54:55 -04003916 if (hsw_mode) {
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003917 AMAP_SET_BITS(struct amap_set_hsw_context, interface_id,
3918 ctxt, adapter->hba_port_num);
3919 AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1);
3920 AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type,
3921 ctxt, hsw_mode);
3922 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003923
Kalesh APe7bcbd72015-05-06 05:30:32 -04003924 /* Enable/disable both mac and vlan spoof checking */
3925 if (!BEx_chip(adapter) && spoofchk) {
3926 AMAP_SET_BITS(struct amap_set_hsw_context, mac_spoofchk,
3927 ctxt, spoofchk);
3928 AMAP_SET_BITS(struct amap_set_hsw_context, vlan_spoofchk,
3929 ctxt, spoofchk);
3930 }
3931
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003932 be_dws_cpu_to_le(req->context, sizeof(req->context));
3933 status = be_mcc_notify_wait(adapter);
3934
3935err:
Sathya Perlab7172412016-07-27 05:26:18 -04003936 mutex_unlock(&adapter->mcc_lock);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003937 return status;
3938}
3939
3940/* Get Hyper switch config */
3941int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid,
Kalesh APe7bcbd72015-05-06 05:30:32 -04003942 u32 domain, u16 intf_id, u8 *mode, bool *spoofchk)
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003943{
3944 struct be_mcc_wrb *wrb;
3945 struct be_cmd_req_get_hsw_config *req;
3946 void *ctxt;
3947 int status;
3948 u16 vid;
3949
Sathya Perlab7172412016-07-27 05:26:18 -04003950 mutex_lock(&adapter->mcc_lock);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003951
3952 wrb = wrb_from_mccq(adapter);
3953 if (!wrb) {
3954 status = -EBUSY;
3955 goto err;
3956 }
3957
3958 req = embedded_payload(wrb);
3959 ctxt = &req->context;
3960
3961 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303962 OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb,
3963 NULL);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003964
3965 req->hdr.domain = domain;
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003966 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3967 ctxt, intf_id);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003968 AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003969
Vasundhara Volam2c07c1d2014-01-15 13:23:32 +05303970 if (!BEx_chip(adapter) && mode) {
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003971 AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id,
3972 ctxt, adapter->hba_port_num);
3973 AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1);
3974 }
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003975 be_dws_cpu_to_le(req->context, sizeof(req->context));
3976
3977 status = be_mcc_notify_wait(adapter);
3978 if (!status) {
3979 struct be_cmd_resp_get_hsw_config *resp =
3980 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05303981
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303982 be_dws_le_to_cpu(&resp->context, sizeof(resp->context));
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003983 vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05303984 pvid, &resp->context);
Ajit Khapardea77dcb82013-08-30 15:01:16 -05003985 if (pvid)
3986 *pvid = le16_to_cpu(vid);
3987 if (mode)
3988 *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3989 port_fwd_type, &resp->context);
Kalesh APe7bcbd72015-05-06 05:30:32 -04003990 if (spoofchk)
3991 *spoofchk =
3992 AMAP_GET_BITS(struct amap_get_hsw_resp_context,
3993 spoofchk, &resp->context);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003994 }
3995
3996err:
Sathya Perlab7172412016-07-27 05:26:18 -04003997 mutex_unlock(&adapter->mcc_lock);
Ajit Khapardef1f3ee12012-03-18 06:23:41 +00003998 return status;
3999}
4000
Sathya Perlaf7062ee2015-02-06 08:18:35 -05004001static bool be_is_wol_excluded(struct be_adapter *adapter)
4002{
4003 struct pci_dev *pdev = adapter->pdev;
4004
Kalesh AP18c57c72015-05-06 05:30:38 -04004005 if (be_virtfn(adapter))
Sathya Perlaf7062ee2015-02-06 08:18:35 -05004006 return true;
4007
4008 switch (pdev->subsystem_device) {
4009 case OC_SUBSYS_DEVICE_ID1:
4010 case OC_SUBSYS_DEVICE_ID2:
4011 case OC_SUBSYS_DEVICE_ID3:
4012 case OC_SUBSYS_DEVICE_ID4:
4013 return true;
4014 default:
4015 return false;
4016 }
4017}
4018
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004019int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter)
4020{
4021 struct be_mcc_wrb *wrb;
4022 struct be_cmd_req_acpi_wol_magic_config_v1 *req;
Suresh Reddy76a9e082014-01-15 13:23:40 +05304023 int status = 0;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004024 struct be_dma_mem cmd;
4025
Padmanabh Ratnakarf25b1192012-10-20 06:02:52 +00004026 if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
4027 CMD_SUBSYSTEM_ETH))
4028 return -EPERM;
4029
Suresh Reddy76a9e082014-01-15 13:23:40 +05304030 if (be_is_wol_excluded(adapter))
4031 return status;
4032
Suresh Reddyd98ef502013-04-25 00:56:55 +00004033 if (mutex_lock_interruptible(&adapter->mbox_lock))
4034 return -1;
4035
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004036 memset(&cmd, 0, sizeof(struct be_dma_mem));
4037 cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304038 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
4039 GFP_ATOMIC);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004040 if (!cmd.va) {
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05304041 dev_err(&adapter->pdev->dev, "Memory allocation failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00004042 status = -ENOMEM;
4043 goto err;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004044 }
4045
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004046 wrb = wrb_from_mbox(adapter);
4047 if (!wrb) {
4048 status = -EBUSY;
4049 goto err;
4050 }
4051
4052 req = cmd.va;
4053
4054 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH,
4055 OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG,
Suresh Reddy76a9e082014-01-15 13:23:40 +05304056 sizeof(*req), wrb, &cmd);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004057
4058 req->hdr.version = 1;
4059 req->query_options = BE_GET_WOL_CAP;
4060
4061 status = be_mbox_notify_wait(adapter);
4062 if (!status) {
4063 struct be_cmd_resp_acpi_wol_magic_config_v1 *resp;
Kalesh AP03d28ff2014-09-19 15:46:56 +05304064
Kalesh AP504fbf12014-09-19 15:47:00 +05304065 resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *)cmd.va;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004066
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004067 adapter->wol_cap = resp->wol_settings;
Sriharsha Basavapatna45f13df2016-06-06 07:22:09 -04004068
4069 /* Non-zero macaddr indicates WOL is enabled */
4070 if (adapter->wol_cap & BE_WOL_CAP &&
4071 !is_zero_ether_addr(resp->magic_mac))
Suresh Reddy76a9e082014-01-15 13:23:40 +05304072 adapter->wol_en = true;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004073 }
4074err:
4075 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00004076 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304077 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
4078 cmd.dma);
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004079 return status;
Somnath Kotur941a77d2012-05-17 22:59:03 +00004080
4081}
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304082
4083int be_cmd_set_fw_log_level(struct be_adapter *adapter, u32 level)
4084{
4085 struct be_dma_mem extfat_cmd;
4086 struct be_fat_conf_params *cfgs;
4087 int status;
4088 int i, j;
4089
4090 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
4091 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304092 extfat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
4093 extfat_cmd.size, &extfat_cmd.dma,
4094 GFP_ATOMIC);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304095 if (!extfat_cmd.va)
4096 return -ENOMEM;
4097
4098 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
4099 if (status)
4100 goto err;
4101
4102 cfgs = (struct be_fat_conf_params *)
4103 (extfat_cmd.va + sizeof(struct be_cmd_resp_hdr));
4104 for (i = 0; i < le32_to_cpu(cfgs->num_modules); i++) {
4105 u32 num_modes = le32_to_cpu(cfgs->module[i].num_modes);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304106
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304107 for (j = 0; j < num_modes; j++) {
4108 if (cfgs->module[i].trace_lvl[j].mode == MODE_UART)
4109 cfgs->module[i].trace_lvl[j].dbg_lvl =
4110 cpu_to_le32(level);
4111 }
4112 }
4113
4114 status = be_cmd_set_ext_fat_capabilites(adapter, &extfat_cmd, cfgs);
4115err:
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304116 dma_free_coherent(&adapter->pdev->dev, extfat_cmd.size, extfat_cmd.va,
4117 extfat_cmd.dma);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304118 return status;
4119}
4120
4121int be_cmd_get_fw_log_level(struct be_adapter *adapter)
4122{
4123 struct be_dma_mem extfat_cmd;
4124 struct be_fat_conf_params *cfgs;
4125 int status, j;
4126 int level = 0;
4127
4128 memset(&extfat_cmd, 0, sizeof(struct be_dma_mem));
4129 extfat_cmd.size = sizeof(struct be_cmd_resp_get_ext_fat_caps);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304130 extfat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev,
4131 extfat_cmd.size, &extfat_cmd.dma,
4132 GFP_ATOMIC);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304133
4134 if (!extfat_cmd.va) {
4135 dev_err(&adapter->pdev->dev, "%s: Memory allocation failure\n",
4136 __func__);
4137 goto err;
4138 }
4139
4140 status = be_cmd_get_ext_fat_capabilites(adapter, &extfat_cmd);
4141 if (!status) {
4142 cfgs = (struct be_fat_conf_params *)(extfat_cmd.va +
4143 sizeof(struct be_cmd_resp_hdr));
Kalesh AP03d28ff2014-09-19 15:46:56 +05304144
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304145 for (j = 0; j < le32_to_cpu(cfgs->module[0].num_modes); j++) {
4146 if (cfgs->module[0].trace_lvl[j].mode == MODE_UART)
4147 level = cfgs->module[0].trace_lvl[j].dbg_lvl;
4148 }
4149 }
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304150 dma_free_coherent(&adapter->pdev->dev, extfat_cmd.size, extfat_cmd.va,
4151 extfat_cmd.dma);
Vasundhara Volambaaa08d2014-01-15 13:23:34 +05304152err:
4153 return level;
4154}
4155
Somnath Kotur941a77d2012-05-17 22:59:03 +00004156int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter,
4157 struct be_dma_mem *cmd)
4158{
4159 struct be_mcc_wrb *wrb;
4160 struct be_cmd_req_get_ext_fat_caps *req;
4161 int status;
4162
Somnath Kotur62259ac2016-09-07 19:57:51 +05304163 if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES,
4164 CMD_SUBSYSTEM_COMMON))
4165 return -EPERM;
4166
Somnath Kotur941a77d2012-05-17 22:59:03 +00004167 if (mutex_lock_interruptible(&adapter->mbox_lock))
4168 return -1;
4169
4170 wrb = wrb_from_mbox(adapter);
4171 if (!wrb) {
4172 status = -EBUSY;
4173 goto err;
4174 }
4175
4176 req = cmd->va;
4177 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Kotur62259ac2016-09-07 19:57:51 +05304178 OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES,
Somnath Kotur941a77d2012-05-17 22:59:03 +00004179 cmd->size, wrb, cmd);
4180 req->parameter_type = cpu_to_le32(1);
4181
4182 status = be_mbox_notify_wait(adapter);
4183err:
4184 mutex_unlock(&adapter->mbox_lock);
4185 return status;
4186}
4187
4188int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter,
4189 struct be_dma_mem *cmd,
4190 struct be_fat_conf_params *configs)
4191{
4192 struct be_mcc_wrb *wrb;
4193 struct be_cmd_req_set_ext_fat_caps *req;
4194 int status;
4195
Sathya Perlab7172412016-07-27 05:26:18 -04004196 mutex_lock(&adapter->mcc_lock);
Somnath Kotur941a77d2012-05-17 22:59:03 +00004197
4198 wrb = wrb_from_mccq(adapter);
4199 if (!wrb) {
4200 status = -EBUSY;
4201 goto err;
4202 }
4203
4204 req = cmd->va;
4205 memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params));
4206 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Somnath Kotur62259ac2016-09-07 19:57:51 +05304207 OPCODE_COMMON_SET_EXT_FAT_CAPABILITIES,
Somnath Kotur941a77d2012-05-17 22:59:03 +00004208 cmd->size, wrb, cmd);
4209
4210 status = be_mcc_notify_wait(adapter);
4211err:
Sathya Perlab7172412016-07-27 05:26:18 -04004212 mutex_unlock(&adapter->mcc_lock);
Somnath Kotur941a77d2012-05-17 22:59:03 +00004213 return status;
Ajit Khaparde4762f6c2012-03-18 06:23:11 +00004214}
Parav Pandit6a4ab662012-03-26 14:27:12 +00004215
Vasundhara Volam21252372015-02-06 08:18:42 -05004216int be_cmd_query_port_name(struct be_adapter *adapter)
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004217{
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004218 struct be_cmd_req_get_port_name *req;
Vasundhara Volam21252372015-02-06 08:18:42 -05004219 struct be_mcc_wrb *wrb;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004220 int status;
4221
Vasundhara Volam21252372015-02-06 08:18:42 -05004222 if (mutex_lock_interruptible(&adapter->mbox_lock))
4223 return -1;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004224
Vasundhara Volam21252372015-02-06 08:18:42 -05004225 wrb = wrb_from_mbox(adapter);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004226 req = embedded_payload(wrb);
4227
4228 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4229 OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb,
4230 NULL);
Vasundhara Volam21252372015-02-06 08:18:42 -05004231 if (!BEx_chip(adapter))
4232 req->hdr.version = 1;
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004233
Vasundhara Volam21252372015-02-06 08:18:42 -05004234 status = be_mbox_notify_wait(adapter);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004235 if (!status) {
4236 struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304237
Vasundhara Volam21252372015-02-06 08:18:42 -05004238 adapter->port_name = resp->port_name[adapter->hba_port_num];
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004239 } else {
Vasundhara Volam21252372015-02-06 08:18:42 -05004240 adapter->port_name = adapter->hba_port_num + '0';
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004241 }
Vasundhara Volam21252372015-02-06 08:18:42 -05004242
4243 mutex_unlock(&adapter->mbox_lock);
Padmanabh Ratnakarb4e32a72012-07-12 03:57:35 +00004244 return status;
4245}
4246
Suresh Reddy980df242015-12-30 01:29:03 -05004247/* When more than 1 NIC descriptor is present in the descriptor list,
4248 * the caller must specify the pf_num to obtain the NIC descriptor
4249 * corresponding to its pci function.
4250 * get_vft must be true when the caller wants the VF-template desc of the
4251 * PF-pool.
4252 * The pf_num should be set to PF_NUM_IGNORE when the caller knows
4253 * that only it's NIC descriptor is present in the descriptor list.
4254 */
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304255static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count,
Suresh Reddy980df242015-12-30 01:29:03 -05004256 bool get_vft, u8 pf_num)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004257{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304258 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304259 struct be_nic_res_desc *nic;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004260 int i;
4261
4262 for (i = 0; i < desc_count; i++) {
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304263 if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 ||
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304264 hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) {
4265 nic = (struct be_nic_res_desc *)hdr;
Suresh Reddy980df242015-12-30 01:29:03 -05004266
4267 if ((pf_num == PF_NUM_IGNORE ||
4268 nic->pf_num == pf_num) &&
4269 (!get_vft || nic->flags & BIT(VFT_SHIFT)))
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304270 return nic;
4271 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304272 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
4273 hdr = (void *)hdr + hdr->desc_len;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004274 }
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304275 return NULL;
4276}
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004277
Suresh Reddy980df242015-12-30 01:29:03 -05004278static struct be_nic_res_desc *be_get_vft_desc(u8 *buf, u32 desc_count,
4279 u8 pf_num)
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304280{
Suresh Reddy980df242015-12-30 01:29:03 -05004281 return be_get_nic_desc(buf, desc_count, true, pf_num);
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304282}
4283
Suresh Reddy980df242015-12-30 01:29:03 -05004284static struct be_nic_res_desc *be_get_func_nic_desc(u8 *buf, u32 desc_count,
4285 u8 pf_num)
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304286{
Suresh Reddy980df242015-12-30 01:29:03 -05004287 return be_get_nic_desc(buf, desc_count, false, pf_num);
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304288}
4289
Suresh Reddy980df242015-12-30 01:29:03 -05004290static struct be_pcie_res_desc *be_get_pcie_desc(u8 *buf, u32 desc_count,
4291 u8 pf_num)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304292{
4293 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
4294 struct be_pcie_res_desc *pcie;
4295 int i;
4296
4297 for (i = 0; i < desc_count; i++) {
Suresh Reddy980df242015-12-30 01:29:03 -05004298 if (hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
4299 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1) {
4300 pcie = (struct be_pcie_res_desc *)hdr;
4301 if (pcie->pf_num == pf_num)
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304302 return pcie;
4303 }
4304
4305 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
4306 hdr = (void *)hdr + hdr->desc_len;
4307 }
Wei Yang950e2952013-05-22 15:58:22 +00004308 return NULL;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004309}
4310
Vasundhara Volamf93f1602014-02-12 16:09:25 +05304311static struct be_port_res_desc *be_get_port_desc(u8 *buf, u32 desc_count)
4312{
4313 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
4314 int i;
4315
4316 for (i = 0; i < desc_count; i++) {
4317 if (hdr->desc_type == PORT_RESOURCE_DESC_TYPE_V1)
4318 return (struct be_port_res_desc *)hdr;
4319
4320 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
4321 hdr = (void *)hdr + hdr->desc_len;
4322 }
4323 return NULL;
4324}
4325
Sathya Perla92bf14a2013-08-27 16:57:32 +05304326static void be_copy_nic_desc(struct be_resources *res,
4327 struct be_nic_res_desc *desc)
4328{
4329 res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count);
4330 res->max_vlans = le16_to_cpu(desc->vlan_count);
4331 res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count);
4332 res->max_tx_qs = le16_to_cpu(desc->txq_count);
4333 res->max_rss_qs = le16_to_cpu(desc->rssq_count);
4334 res->max_rx_qs = le16_to_cpu(desc->rq_count);
4335 res->max_evt_qs = le16_to_cpu(desc->eq_count);
Vasundhara Volamf2858732015-03-04 00:44:33 -05004336 res->max_cq_count = le16_to_cpu(desc->cq_count);
4337 res->max_iface_count = le16_to_cpu(desc->iface_count);
4338 res->max_mcc_count = le16_to_cpu(desc->mcc_count);
Sathya Perla92bf14a2013-08-27 16:57:32 +05304339 /* Clear flags that driver is not interested in */
4340 res->if_cap_flags = le32_to_cpu(desc->cap_flags) &
4341 BE_IF_CAP_FLAGS_WANT;
Sathya Perla92bf14a2013-08-27 16:57:32 +05304342}
4343
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004344/* Uses Mbox */
Sathya Perla92bf14a2013-08-27 16:57:32 +05304345int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res)
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004346{
4347 struct be_mcc_wrb *wrb;
4348 struct be_cmd_req_get_func_config *req;
4349 int status;
4350 struct be_dma_mem cmd;
4351
Suresh Reddyd98ef502013-04-25 00:56:55 +00004352 if (mutex_lock_interruptible(&adapter->mbox_lock))
4353 return -1;
4354
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004355 memset(&cmd, 0, sizeof(struct be_dma_mem));
4356 cmd.size = sizeof(struct be_cmd_resp_get_func_config);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304357 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
4358 GFP_ATOMIC);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004359 if (!cmd.va) {
4360 dev_err(&adapter->pdev->dev, "Memory alloc failure\n");
Suresh Reddyd98ef502013-04-25 00:56:55 +00004361 status = -ENOMEM;
4362 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004363 }
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004364
4365 wrb = wrb_from_mbox(adapter);
4366 if (!wrb) {
4367 status = -EBUSY;
4368 goto err;
4369 }
4370
4371 req = cmd.va;
4372
4373 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4374 OPCODE_COMMON_GET_FUNC_CONFIG,
4375 cmd.size, wrb, &cmd);
4376
Kalesh AP28710c52013-04-28 22:21:13 +00004377 if (skyhawk_chip(adapter))
4378 req->hdr.version = 1;
4379
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004380 status = be_mbox_notify_wait(adapter);
4381 if (!status) {
4382 struct be_cmd_resp_get_func_config *resp = cmd.va;
4383 u32 desc_count = le32_to_cpu(resp->desc_count);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304384 struct be_nic_res_desc *desc;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004385
Suresh Reddy980df242015-12-30 01:29:03 -05004386 /* GET_FUNC_CONFIG returns resource descriptors of the
4387 * current function only. So, pf_num should be set to
4388 * PF_NUM_IGNORE.
4389 */
4390 desc = be_get_func_nic_desc(resp->func_param, desc_count,
4391 PF_NUM_IGNORE);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004392 if (!desc) {
4393 status = -EINVAL;
4394 goto err;
4395 }
Suresh Reddy980df242015-12-30 01:29:03 -05004396
4397 /* Store pf_num & vf_num for later use in GET_PROFILE_CONFIG */
4398 adapter->pf_num = desc->pf_num;
4399 adapter->vf_num = desc->vf_num;
4400
4401 if (res)
4402 be_copy_nic_desc(res, desc);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004403 }
4404err:
4405 mutex_unlock(&adapter->mbox_lock);
Suresh Reddyd98ef502013-04-25 00:56:55 +00004406 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304407 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
4408 cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004409 return status;
4410}
4411
Somnath Koturde2b1e02016-06-06 07:22:10 -04004412/* This routine returns a list of all the NIC PF_nums in the adapter */
Baoyou Xied766e7e2016-09-18 16:35:29 +08004413static u16 be_get_nic_pf_num_list(u8 *buf, u32 desc_count, u16 *nic_pf_nums)
Somnath Koturde2b1e02016-06-06 07:22:10 -04004414{
4415 struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf;
4416 struct be_pcie_res_desc *pcie = NULL;
4417 int i;
4418 u16 nic_pf_count = 0;
4419
4420 for (i = 0; i < desc_count; i++) {
4421 if (hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 ||
4422 hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1) {
4423 pcie = (struct be_pcie_res_desc *)hdr;
4424 if (pcie->pf_state && (pcie->pf_type == MISSION_NIC ||
4425 pcie->pf_type == MISSION_RDMA)) {
4426 nic_pf_nums[nic_pf_count++] = pcie->pf_num;
4427 }
4428 }
4429
4430 hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0;
4431 hdr = (void *)hdr + hdr->desc_len;
4432 }
4433 return nic_pf_count;
4434}
4435
Suresh Reddy980df242015-12-30 01:29:03 -05004436/* Will use MBOX only if MCCQ has not been created */
Sathya Perla92bf14a2013-08-27 16:57:32 +05304437int be_cmd_get_profile_config(struct be_adapter *adapter,
Somnath Koturde2b1e02016-06-06 07:22:10 -04004438 struct be_resources *res,
4439 struct be_port_resources *port_res,
4440 u8 profile_type, u8 query, u8 domain)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00004441{
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304442 struct be_cmd_resp_get_profile_config *resp;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05304443 struct be_cmd_req_get_profile_config *req;
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304444 struct be_nic_res_desc *vf_res;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304445 struct be_pcie_res_desc *pcie;
Vasundhara Volamf93f1602014-02-12 16:09:25 +05304446 struct be_port_res_desc *port;
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304447 struct be_nic_res_desc *nic;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05304448 struct be_mcc_wrb wrb = {0};
Vasundhara Volama05f99d2013-04-21 23:28:17 +00004449 struct be_dma_mem cmd;
Vasundhara Volamf2858732015-03-04 00:44:33 -05004450 u16 desc_count;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00004451 int status;
4452
4453 memset(&cmd, 0, sizeof(struct be_dma_mem));
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304454 cmd.size = sizeof(struct be_cmd_resp_get_profile_config);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304455 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
4456 GFP_ATOMIC);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304457 if (!cmd.va)
Vasundhara Volama05f99d2013-04-21 23:28:17 +00004458 return -ENOMEM;
Vasundhara Volama05f99d2013-04-21 23:28:17 +00004459
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05304460 req = cmd.va;
4461 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4462 OPCODE_COMMON_GET_PROFILE_CONFIG,
4463 cmd.size, &wrb, &cmd);
4464
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05304465 if (!lancer_chip(adapter))
4466 req->hdr.version = 1;
Somnath Koturde2b1e02016-06-06 07:22:10 -04004467 req->type = profile_type;
Somnath Kotur72ef3a82015-10-12 03:47:20 -04004468 req->hdr.domain = domain;
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05304469
Vasundhara Volamf2858732015-03-04 00:44:33 -05004470 /* When QUERY_MODIFIABLE_FIELDS_TYPE bit is set, cmd returns the
4471 * descriptors with all bits set to "1" for the fields which can be
4472 * modified using SET_PROFILE_CONFIG cmd.
4473 */
4474 if (query == RESOURCE_MODIFIABLE)
4475 req->type |= QUERY_MODIFIABLE_FIELDS_TYPE;
4476
Vasundhara Volamba48c0c2014-06-30 13:01:30 +05304477 status = be_cmd_notify_wait(adapter, &wrb);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304478 if (status)
4479 goto err;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004480
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304481 resp = cmd.va;
Vasundhara Volamf2858732015-03-04 00:44:33 -05004482 desc_count = le16_to_cpu(resp->desc_count);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004483
Somnath Koturde2b1e02016-06-06 07:22:10 -04004484 if (port_res) {
4485 u16 nic_pf_cnt = 0, i;
4486 u16 nic_pf_num_list[MAX_NIC_FUNCS];
4487
4488 nic_pf_cnt = be_get_nic_pf_num_list(resp->func_param,
4489 desc_count,
4490 nic_pf_num_list);
4491
4492 for (i = 0; i < nic_pf_cnt; i++) {
4493 nic = be_get_func_nic_desc(resp->func_param, desc_count,
4494 nic_pf_num_list[i]);
4495 if (nic->link_param == adapter->port_num) {
4496 port_res->nic_pfs++;
4497 pcie = be_get_pcie_desc(resp->func_param,
4498 desc_count,
4499 nic_pf_num_list[i]);
4500 port_res->max_vfs += le16_to_cpu(pcie->num_vfs);
4501 }
4502 }
4503 return status;
4504 }
4505
Suresh Reddy980df242015-12-30 01:29:03 -05004506 pcie = be_get_pcie_desc(resp->func_param, desc_count,
4507 adapter->pf_num);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304508 if (pcie)
Sathya Perla92bf14a2013-08-27 16:57:32 +05304509 res->max_vfs = le16_to_cpu(pcie->num_vfs);
Vasundhara Volam150d58c2013-08-27 16:57:31 +05304510
Vasundhara Volamf93f1602014-02-12 16:09:25 +05304511 port = be_get_port_desc(resp->func_param, desc_count);
4512 if (port)
4513 adapter->mc_type = port->mc_type;
4514
Suresh Reddy980df242015-12-30 01:29:03 -05004515 nic = be_get_func_nic_desc(resp->func_param, desc_count,
4516 adapter->pf_num);
Sathya Perla92bf14a2013-08-27 16:57:32 +05304517 if (nic)
4518 be_copy_nic_desc(res, nic);
4519
Suresh Reddy980df242015-12-30 01:29:03 -05004520 vf_res = be_get_vft_desc(resp->func_param, desc_count,
4521 adapter->pf_num);
Vasundhara Volam10cccf62014-06-30 13:01:31 +05304522 if (vf_res)
4523 res->vf_if_cap_flags = vf_res->cap_flags;
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004524err:
Vasundhara Volama05f99d2013-04-21 23:28:17 +00004525 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304526 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
4527 cmd.dma);
Padmanabh Ratnakarabb93952012-10-20 06:01:41 +00004528 return status;
4529}
4530
Vasundhara Volambec84e62014-06-30 13:01:32 +05304531/* Will use MBOX only if MCCQ has not been created */
4532static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc,
4533 int size, int count, u8 version, u8 domain)
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004534{
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004535 struct be_cmd_req_set_profile_config *req;
Vasundhara Volambec84e62014-06-30 13:01:32 +05304536 struct be_mcc_wrb wrb = {0};
4537 struct be_dma_mem cmd;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004538 int status;
4539
Vasundhara Volambec84e62014-06-30 13:01:32 +05304540 memset(&cmd, 0, sizeof(struct be_dma_mem));
4541 cmd.size = sizeof(struct be_cmd_req_set_profile_config);
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304542 cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma,
4543 GFP_ATOMIC);
Vasundhara Volambec84e62014-06-30 13:01:32 +05304544 if (!cmd.va)
4545 return -ENOMEM;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004546
Vasundhara Volambec84e62014-06-30 13:01:32 +05304547 req = cmd.va;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004548 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
Vasundhara Volambec84e62014-06-30 13:01:32 +05304549 OPCODE_COMMON_SET_PROFILE_CONFIG, cmd.size,
4550 &wrb, &cmd);
Sathya Perlaa4018012014-03-27 10:46:18 +05304551 req->hdr.version = version;
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004552 req->hdr.domain = domain;
Vasundhara Volambec84e62014-06-30 13:01:32 +05304553 req->desc_count = cpu_to_le32(count);
Sathya Perlaa4018012014-03-27 10:46:18 +05304554 memcpy(req->desc, desc, size);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004555
Vasundhara Volambec84e62014-06-30 13:01:32 +05304556 status = be_cmd_notify_wait(adapter, &wrb);
4557
4558 if (cmd.va)
Sriharsha Basavapatnae51000db2015-06-05 15:33:59 +05304559 dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va,
4560 cmd.dma);
Padmanabh Ratnakard5c18472012-10-20 06:01:53 +00004561 return status;
4562}
4563
Sathya Perlaa4018012014-03-27 10:46:18 +05304564/* Mark all fields invalid */
Baoyou Xied766e7e2016-09-18 16:35:29 +08004565static void be_reset_nic_desc(struct be_nic_res_desc *nic)
Sathya Perlaa4018012014-03-27 10:46:18 +05304566{
4567 memset(nic, 0, sizeof(*nic));
4568 nic->unicast_mac_count = 0xFFFF;
4569 nic->mcc_count = 0xFFFF;
4570 nic->vlan_count = 0xFFFF;
4571 nic->mcast_mac_count = 0xFFFF;
4572 nic->txq_count = 0xFFFF;
4573 nic->rq_count = 0xFFFF;
4574 nic->rssq_count = 0xFFFF;
4575 nic->lro_count = 0xFFFF;
4576 nic->cq_count = 0xFFFF;
4577 nic->toe_conn_count = 0xFFFF;
4578 nic->eq_count = 0xFFFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304579 nic->iface_count = 0xFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05304580 nic->link_param = 0xFF;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304581 nic->channel_id_param = cpu_to_le16(0xF000);
Sathya Perlaa4018012014-03-27 10:46:18 +05304582 nic->acpi_params = 0xFF;
4583 nic->wol_param = 0x0F;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304584 nic->tunnel_iface_count = 0xFFFF;
4585 nic->direct_tenant_iface_count = 0xFFFF;
Vasundhara Volambec84e62014-06-30 13:01:32 +05304586 nic->bw_min = 0xFFFFFFFF;
Sathya Perlaa4018012014-03-27 10:46:18 +05304587 nic->bw_max = 0xFFFFFFFF;
4588}
4589
Vasundhara Volambec84e62014-06-30 13:01:32 +05304590/* Mark all fields invalid */
4591static void be_reset_pcie_desc(struct be_pcie_res_desc *pcie)
4592{
4593 memset(pcie, 0, sizeof(*pcie));
4594 pcie->sriov_state = 0xFF;
4595 pcie->pf_state = 0xFF;
4596 pcie->pf_type = 0xFF;
4597 pcie->num_vfs = 0xFFFF;
4598}
4599
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304600int be_cmd_config_qos(struct be_adapter *adapter, u32 max_rate, u16 link_speed,
4601 u8 domain)
Sathya Perlaa4018012014-03-27 10:46:18 +05304602{
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304603 struct be_nic_res_desc nic_desc;
4604 u32 bw_percent;
4605 u16 version = 0;
Sathya Perlaa4018012014-03-27 10:46:18 +05304606
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304607 if (BE3_chip(adapter))
4608 return be_cmd_set_qos(adapter, max_rate / 10, domain);
4609
4610 be_reset_nic_desc(&nic_desc);
Suresh Reddy980df242015-12-30 01:29:03 -05004611 nic_desc.pf_num = adapter->pf_num;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304612 nic_desc.vf_num = domain;
Kalesh AP58bdeaa2015-01-20 03:51:49 -05004613 nic_desc.bw_min = 0;
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304614 if (lancer_chip(adapter)) {
Sathya Perlaa4018012014-03-27 10:46:18 +05304615 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0;
4616 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0;
4617 nic_desc.flags = (1 << QUN_SHIFT) | (1 << IMM_SHIFT) |
4618 (1 << NOSV_SHIFT);
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304619 nic_desc.bw_max = cpu_to_le32(max_rate / 10);
Sathya Perlaa4018012014-03-27 10:46:18 +05304620 } else {
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304621 version = 1;
4622 nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
4623 nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
4624 nic_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
4625 bw_percent = max_rate ? (max_rate * 100) / link_speed : 100;
4626 nic_desc.bw_max = cpu_to_le32(bw_percent);
Sathya Perlaa4018012014-03-27 10:46:18 +05304627 }
Ravikumar Nelavelli0f77ba72014-05-30 19:06:24 +05304628
4629 return be_cmd_set_profile_config(adapter, &nic_desc,
4630 nic_desc.hdr.desc_len,
Vasundhara Volambec84e62014-06-30 13:01:32 +05304631 1, version, domain);
4632}
4633
4634int be_cmd_set_sriov_config(struct be_adapter *adapter,
Vasundhara Volamf2858732015-03-04 00:44:33 -05004635 struct be_resources pool_res, u16 num_vfs,
Suresh Reddyb9263cb2016-06-06 07:22:08 -04004636 struct be_resources *vft_res)
Vasundhara Volambec84e62014-06-30 13:01:32 +05304637{
4638 struct {
4639 struct be_pcie_res_desc pcie;
4640 struct be_nic_res_desc nic_vft;
4641 } __packed desc;
Vasundhara Volambec84e62014-06-30 13:01:32 +05304642
Vasundhara Volambec84e62014-06-30 13:01:32 +05304643 /* PF PCIE descriptor */
4644 be_reset_pcie_desc(&desc.pcie);
4645 desc.pcie.hdr.desc_type = PCIE_RESOURCE_DESC_TYPE_V1;
4646 desc.pcie.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
Vasundhara Volamf2858732015-03-04 00:44:33 -05004647 desc.pcie.flags = BIT(IMM_SHIFT) | BIT(NOSV_SHIFT);
Vasundhara Volambec84e62014-06-30 13:01:32 +05304648 desc.pcie.pf_num = adapter->pdev->devfn;
4649 desc.pcie.sriov_state = num_vfs ? 1 : 0;
4650 desc.pcie.num_vfs = cpu_to_le16(num_vfs);
4651
4652 /* VF NIC Template descriptor */
4653 be_reset_nic_desc(&desc.nic_vft);
4654 desc.nic_vft.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V1;
4655 desc.nic_vft.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
Suresh Reddyb9263cb2016-06-06 07:22:08 -04004656 desc.nic_vft.flags = vft_res->flags | BIT(VFT_SHIFT) |
4657 BIT(IMM_SHIFT) | BIT(NOSV_SHIFT);
Vasundhara Volambec84e62014-06-30 13:01:32 +05304658 desc.nic_vft.pf_num = adapter->pdev->devfn;
4659 desc.nic_vft.vf_num = 0;
Suresh Reddyb9263cb2016-06-06 07:22:08 -04004660 desc.nic_vft.cap_flags = cpu_to_le32(vft_res->vf_if_cap_flags);
4661 desc.nic_vft.rq_count = cpu_to_le16(vft_res->max_rx_qs);
4662 desc.nic_vft.txq_count = cpu_to_le16(vft_res->max_tx_qs);
4663 desc.nic_vft.rssq_count = cpu_to_le16(vft_res->max_rss_qs);
4664 desc.nic_vft.cq_count = cpu_to_le16(vft_res->max_cq_count);
Vasundhara Volambec84e62014-06-30 13:01:32 +05304665
Suresh Reddyb9263cb2016-06-06 07:22:08 -04004666 if (vft_res->max_uc_mac)
4667 desc.nic_vft.unicast_mac_count =
4668 cpu_to_le16(vft_res->max_uc_mac);
4669 if (vft_res->max_vlans)
4670 desc.nic_vft.vlan_count = cpu_to_le16(vft_res->max_vlans);
4671 if (vft_res->max_iface_count)
4672 desc.nic_vft.iface_count =
4673 cpu_to_le16(vft_res->max_iface_count);
4674 if (vft_res->max_mcc_count)
4675 desc.nic_vft.mcc_count = cpu_to_le16(vft_res->max_mcc_count);
Vasundhara Volambec84e62014-06-30 13:01:32 +05304676
4677 return be_cmd_set_profile_config(adapter, &desc,
4678 2 * RESOURCE_DESC_SIZE_V1, 2, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05304679}
4680
4681int be_cmd_manage_iface(struct be_adapter *adapter, u32 iface, u8 op)
4682{
4683 struct be_mcc_wrb *wrb;
4684 struct be_cmd_req_manage_iface_filters *req;
4685 int status;
4686
4687 if (iface == 0xFFFFFFFF)
4688 return -1;
4689
Sathya Perlab7172412016-07-27 05:26:18 -04004690 mutex_lock(&adapter->mcc_lock);
Sathya Perlaa4018012014-03-27 10:46:18 +05304691
4692 wrb = wrb_from_mccq(adapter);
4693 if (!wrb) {
4694 status = -EBUSY;
4695 goto err;
4696 }
4697 req = embedded_payload(wrb);
4698
4699 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4700 OPCODE_COMMON_MANAGE_IFACE_FILTERS, sizeof(*req),
4701 wrb, NULL);
4702 req->op = op;
4703 req->target_iface_id = cpu_to_le32(iface);
4704
4705 status = be_mcc_notify_wait(adapter);
4706err:
Sathya Perlab7172412016-07-27 05:26:18 -04004707 mutex_unlock(&adapter->mcc_lock);
Sathya Perlaa4018012014-03-27 10:46:18 +05304708 return status;
4709}
4710
4711int be_cmd_set_vxlan_port(struct be_adapter *adapter, __be16 port)
4712{
4713 struct be_port_res_desc port_desc;
4714
4715 memset(&port_desc, 0, sizeof(port_desc));
4716 port_desc.hdr.desc_type = PORT_RESOURCE_DESC_TYPE_V1;
4717 port_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V1;
4718 port_desc.flags = (1 << IMM_SHIFT) | (1 << NOSV_SHIFT);
4719 port_desc.link_num = adapter->hba_port_num;
4720 if (port) {
4721 port_desc.nv_flags = NV_TYPE_VXLAN | (1 << SOCVID_SHIFT) |
4722 (1 << RCVID_SHIFT);
4723 port_desc.nv_port = swab16(port);
4724 } else {
4725 port_desc.nv_flags = NV_TYPE_DISABLED;
4726 port_desc.nv_port = 0;
4727 }
4728
4729 return be_cmd_set_profile_config(adapter, &port_desc,
Vasundhara Volambec84e62014-06-30 13:01:32 +05304730 RESOURCE_DESC_SIZE_V1, 1, 1, 0);
Sathya Perlaa4018012014-03-27 10:46:18 +05304731}
4732
Sathya Perla4c876612013-02-03 20:30:11 +00004733int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg,
4734 int vf_num)
4735{
4736 struct be_mcc_wrb *wrb;
4737 struct be_cmd_req_get_iface_list *req;
4738 struct be_cmd_resp_get_iface_list *resp;
4739 int status;
4740
Sathya Perlab7172412016-07-27 05:26:18 -04004741 mutex_lock(&adapter->mcc_lock);
Sathya Perla4c876612013-02-03 20:30:11 +00004742
4743 wrb = wrb_from_mccq(adapter);
4744 if (!wrb) {
4745 status = -EBUSY;
4746 goto err;
4747 }
4748 req = embedded_payload(wrb);
4749
4750 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4751 OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp),
4752 wrb, NULL);
4753 req->hdr.domain = vf_num + 1;
4754
4755 status = be_mcc_notify_wait(adapter);
4756 if (!status) {
4757 resp = (struct be_cmd_resp_get_iface_list *)req;
4758 vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id);
4759 }
4760
4761err:
Sathya Perlab7172412016-07-27 05:26:18 -04004762 mutex_unlock(&adapter->mcc_lock);
Sathya Perla4c876612013-02-03 20:30:11 +00004763 return status;
4764}
4765
Somnath Kotur5c510812013-05-30 02:52:23 +00004766static int lancer_wait_idle(struct be_adapter *adapter)
4767{
4768#define SLIPORT_IDLE_TIMEOUT 30
4769 u32 reg_val;
4770 int status = 0, i;
4771
4772 for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) {
4773 reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET);
4774 if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0)
4775 break;
4776
4777 ssleep(1);
4778 }
4779
4780 if (i == SLIPORT_IDLE_TIMEOUT)
4781 status = -1;
4782
4783 return status;
4784}
4785
4786int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask)
4787{
4788 int status = 0;
4789
4790 status = lancer_wait_idle(adapter);
4791 if (status)
4792 return status;
4793
4794 iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET);
4795
4796 return status;
4797}
4798
4799/* Routine to check whether dump image is present or not */
4800bool dump_present(struct be_adapter *adapter)
4801{
4802 u32 sliport_status = 0;
4803
4804 sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET);
4805 return !!(sliport_status & SLIPORT_STATUS_DIP_MASK);
4806}
4807
4808int lancer_initiate_dump(struct be_adapter *adapter)
4809{
Kalesh APf0613382014-08-01 17:47:32 +05304810 struct device *dev = &adapter->pdev->dev;
Somnath Kotur5c510812013-05-30 02:52:23 +00004811 int status;
4812
Kalesh APf0613382014-08-01 17:47:32 +05304813 if (dump_present(adapter)) {
4814 dev_info(dev, "Previous dump not cleared, not forcing dump\n");
4815 return -EEXIST;
4816 }
4817
Somnath Kotur5c510812013-05-30 02:52:23 +00004818 /* give firmware reset and diagnostic dump */
4819 status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK |
4820 PHYSDEV_CONTROL_DD_MASK);
4821 if (status < 0) {
Kalesh APf0613382014-08-01 17:47:32 +05304822 dev_err(dev, "FW reset failed\n");
Somnath Kotur5c510812013-05-30 02:52:23 +00004823 return status;
4824 }
4825
4826 status = lancer_wait_idle(adapter);
4827 if (status)
4828 return status;
4829
4830 if (!dump_present(adapter)) {
Kalesh APf0613382014-08-01 17:47:32 +05304831 dev_err(dev, "FW dump not generated\n");
4832 return -EIO;
Somnath Kotur5c510812013-05-30 02:52:23 +00004833 }
4834
4835 return 0;
4836}
4837
Kalesh APf0613382014-08-01 17:47:32 +05304838int lancer_delete_dump(struct be_adapter *adapter)
4839{
4840 int status;
4841
4842 status = lancer_cmd_delete_object(adapter, LANCER_FW_DUMP_FILE);
4843 return be_cmd_status(status);
4844}
4845
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004846/* Uses sync mcc */
4847int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain)
4848{
4849 struct be_mcc_wrb *wrb;
4850 struct be_cmd_enable_disable_vf *req;
4851 int status;
4852
Vasundhara Volam05998632013-10-01 15:59:59 +05304853 if (BEx_chip(adapter))
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004854 return 0;
4855
Sathya Perlab7172412016-07-27 05:26:18 -04004856 mutex_lock(&adapter->mcc_lock);
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004857
4858 wrb = wrb_from_mccq(adapter);
4859 if (!wrb) {
4860 status = -EBUSY;
4861 goto err;
4862 }
4863
4864 req = embedded_payload(wrb);
4865
4866 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4867 OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req),
4868 wrb, NULL);
4869
4870 req->hdr.domain = domain;
4871 req->enable = 1;
4872 status = be_mcc_notify_wait(adapter);
4873err:
Sathya Perlab7172412016-07-27 05:26:18 -04004874 mutex_unlock(&adapter->mcc_lock);
Padmanabh Ratnakardcf7ebb2012-10-20 06:03:49 +00004875 return status;
4876}
4877
Somnath Kotur68c45a22013-03-14 02:42:07 +00004878int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable)
4879{
4880 struct be_mcc_wrb *wrb;
4881 struct be_cmd_req_intr_set *req;
4882 int status;
4883
4884 if (mutex_lock_interruptible(&adapter->mbox_lock))
4885 return -1;
4886
4887 wrb = wrb_from_mbox(adapter);
4888
4889 req = embedded_payload(wrb);
4890
4891 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4892 OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req),
4893 wrb, NULL);
4894
4895 req->intr_enabled = intr_enable;
4896
4897 status = be_mbox_notify_wait(adapter);
4898
4899 mutex_unlock(&adapter->mbox_lock);
4900 return status;
4901}
4902
Vasundhara Volam542963b2014-01-15 13:23:33 +05304903/* Uses MBOX */
4904int be_cmd_get_active_profile(struct be_adapter *adapter, u16 *profile_id)
4905{
4906 struct be_cmd_req_get_active_profile *req;
4907 struct be_mcc_wrb *wrb;
4908 int status;
4909
4910 if (mutex_lock_interruptible(&adapter->mbox_lock))
4911 return -1;
4912
4913 wrb = wrb_from_mbox(adapter);
4914 if (!wrb) {
4915 status = -EBUSY;
4916 goto err;
4917 }
4918
4919 req = embedded_payload(wrb);
4920
4921 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4922 OPCODE_COMMON_GET_ACTIVE_PROFILE, sizeof(*req),
4923 wrb, NULL);
4924
4925 status = be_mbox_notify_wait(adapter);
4926 if (!status) {
4927 struct be_cmd_resp_get_active_profile *resp =
4928 embedded_payload(wrb);
Kalesh AP03d28ff2014-09-19 15:46:56 +05304929
Vasundhara Volam542963b2014-01-15 13:23:33 +05304930 *profile_id = le16_to_cpu(resp->active_profile_id);
4931 }
4932
4933err:
4934 mutex_unlock(&adapter->mbox_lock);
4935 return status;
4936}
4937
Baoyou Xied766e7e2016-09-18 16:35:29 +08004938static int
4939__be_cmd_set_logical_link_config(struct be_adapter *adapter,
4940 int link_state, int version, u8 domain)
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304941{
4942 struct be_mcc_wrb *wrb;
4943 struct be_cmd_req_set_ll_link *req;
4944 int status;
4945
Sathya Perlab7172412016-07-27 05:26:18 -04004946 mutex_lock(&adapter->mcc_lock);
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304947
4948 wrb = wrb_from_mccq(adapter);
4949 if (!wrb) {
4950 status = -EBUSY;
4951 goto err;
4952 }
4953
4954 req = embedded_payload(wrb);
4955
4956 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
4957 OPCODE_COMMON_SET_LOGICAL_LINK_CONFIG,
4958 sizeof(*req), wrb, NULL);
4959
Suresh Reddyd9d426a2015-12-30 01:28:56 -05004960 req->hdr.version = version;
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304961 req->hdr.domain = domain;
4962
Suresh Reddyd9d426a2015-12-30 01:28:56 -05004963 if (link_state == IFLA_VF_LINK_STATE_ENABLE ||
4964 link_state == IFLA_VF_LINK_STATE_AUTO)
4965 req->link_config |= PLINK_ENABLE;
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304966
4967 if (link_state == IFLA_VF_LINK_STATE_AUTO)
Suresh Reddyd9d426a2015-12-30 01:28:56 -05004968 req->link_config |= PLINK_TRACK;
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304969
4970 status = be_mcc_notify_wait(adapter);
4971err:
Sathya Perlab7172412016-07-27 05:26:18 -04004972 mutex_unlock(&adapter->mcc_lock);
Suresh Reddybdce2ad2014-03-11 18:53:04 +05304973 return status;
4974}
4975
Suresh Reddyd9d426a2015-12-30 01:28:56 -05004976int be_cmd_set_logical_link_config(struct be_adapter *adapter,
4977 int link_state, u8 domain)
4978{
4979 int status;
4980
Suresh Reddydc6e8512016-10-09 09:58:53 +05304981 if (BE2_chip(adapter))
Suresh Reddyd9d426a2015-12-30 01:28:56 -05004982 return -EOPNOTSUPP;
4983
4984 status = __be_cmd_set_logical_link_config(adapter, link_state,
4985 2, domain);
4986
4987 /* Version 2 of the command will not be recognized by older FW.
4988 * On such a failure issue version 1 of the command.
4989 */
4990 if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST)
4991 status = __be_cmd_set_logical_link_config(adapter, link_state,
4992 1, domain);
4993 return status;
4994}
Sriharsha Basavapatna710f3e52016-09-07 19:57:49 +05304995
4996int be_cmd_set_features(struct be_adapter *adapter)
4997{
4998 struct be_cmd_resp_set_features *resp;
4999 struct be_cmd_req_set_features *req;
5000 struct be_mcc_wrb *wrb;
5001 int status;
5002
5003 if (mutex_lock_interruptible(&adapter->mcc_lock))
5004 return -1;
5005
5006 wrb = wrb_from_mccq(adapter);
5007 if (!wrb) {
5008 status = -EBUSY;
5009 goto err;
5010 }
5011
5012 req = embedded_payload(wrb);
5013
5014 be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
5015 OPCODE_COMMON_SET_FEATURES,
5016 sizeof(*req), wrb, NULL);
5017
5018 req->features = cpu_to_le32(BE_FEATURE_UE_RECOVERY);
5019 req->parameter_len = cpu_to_le32(sizeof(struct be_req_ue_recovery));
5020 req->parameter.req.uer = cpu_to_le32(BE_UE_RECOVERY_UER_MASK);
5021
5022 status = be_mcc_notify_wait(adapter);
5023 if (status)
5024 goto err;
5025
5026 resp = embedded_payload(wrb);
5027
5028 adapter->error_recovery.ue_to_poll_time =
5029 le16_to_cpu(resp->parameter.resp.ue2rp);
5030 adapter->error_recovery.ue_to_reset_time =
5031 le16_to_cpu(resp->parameter.resp.ue2sr);
5032 adapter->error_recovery.recovery_supported = true;
5033err:
5034 /* Checking "MCC_STATUS_INVALID_LENGTH" for SKH as FW
5035 * returns this error in older firmware versions
5036 */
5037 if (base_status(status) == MCC_STATUS_ILLEGAL_REQUEST ||
5038 base_status(status) == MCC_STATUS_INVALID_LENGTH)
5039 dev_info(&adapter->pdev->dev,
5040 "Adapter does not support HW error recovery\n");
5041
5042 mutex_unlock(&adapter->mcc_lock);
5043 return status;
5044}
5045
Parav Pandit6a4ab662012-03-26 14:27:12 +00005046int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload,
Sathya Perlaa2cc4e02014-05-09 13:29:14 +05305047 int wrb_payload_size, u16 *cmd_status, u16 *ext_status)
Parav Pandit6a4ab662012-03-26 14:27:12 +00005048{
5049 struct be_adapter *adapter = netdev_priv(netdev_handle);
5050 struct be_mcc_wrb *wrb;
Kalesh AP504fbf12014-09-19 15:47:00 +05305051 struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *)wrb_payload;
Parav Pandit6a4ab662012-03-26 14:27:12 +00005052 struct be_cmd_req_hdr *req;
5053 struct be_cmd_resp_hdr *resp;
5054 int status;
5055
Sathya Perlab7172412016-07-27 05:26:18 -04005056 mutex_lock(&adapter->mcc_lock);
Parav Pandit6a4ab662012-03-26 14:27:12 +00005057
5058 wrb = wrb_from_mccq(adapter);
5059 if (!wrb) {
5060 status = -EBUSY;
5061 goto err;
5062 }
5063 req = embedded_payload(wrb);
5064 resp = embedded_payload(wrb);
5065
5066 be_wrb_cmd_hdr_prepare(req, hdr->subsystem,
5067 hdr->opcode, wrb_payload_size, wrb, NULL);
5068 memcpy(req, wrb_payload, wrb_payload_size);
5069 be_dws_cpu_to_le(req, wrb_payload_size);
5070
5071 status = be_mcc_notify_wait(adapter);
5072 if (cmd_status)
5073 *cmd_status = (status & 0xffff);
5074 if (ext_status)
5075 *ext_status = 0;
5076 memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length);
5077 be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length);
5078err:
Sathya Perlab7172412016-07-27 05:26:18 -04005079 mutex_unlock(&adapter->mcc_lock);
Parav Pandit6a4ab662012-03-26 14:27:12 +00005080 return status;
5081}
5082EXPORT_SYMBOL(be_roce_mcc_cmd);