Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Somnath Kotur | 7dfbe7d | 2016-06-22 08:54:56 -0400 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2016 Broadcom |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 3 | * 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 Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 11 | * linux-drivers@emulex.com |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 12 | * |
Ajit Khaparde | d2145cd | 2011-03-16 08:20:46 +0000 | [diff] [blame] | 13 | * Emulex |
| 14 | * 3333 Susan Street |
| 15 | * Costa Mesa, CA 92626 |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 18 | #include <linux/module.h> |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 19 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 20 | #include "be_cmds.h" |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 21 | |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 22 | char *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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 29 | }; |
| 30 | |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 31 | static char *be_port_misconfig_evt_severity[] = { |
| 32 | "KERN_WARN", |
| 33 | "KERN_INFO", |
| 34 | "KERN_ERR", |
| 35 | "KERN_WARN" |
| 36 | }; |
| 37 | |
| 38 | static char *phy_state_oper_desc[] = { |
| 39 | "Link is non-operational", |
| 40 | "Link is operational", |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 41 | "" |
| 42 | }; |
| 43 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 44 | static 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 Kotur | 2e365b1 | 2016-02-03 09:49:20 +0530 | [diff] [blame] | 74 | }, |
| 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 Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 90 | { |
| 91 | OPCODE_COMMON_SET_HSW_CONFIG, |
| 92 | CMD_SUBSYSTEM_COMMON, |
Venkat Duvvuru | d14584d | 2016-12-06 00:33:50 -0500 | [diff] [blame] | 93 | BE_PRIV_DEVCFG | BE_PRIV_VHADM | |
| 94 | BE_PRIV_DEVSEC |
Somnath Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 95 | }, |
Somnath Kotur | 62259ac | 2016-09-07 19:57:51 +0530 | [diff] [blame] | 96 | { |
| 97 | OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES, |
| 98 | CMD_SUBSYSTEM_COMMON, |
| 99 | BE_PRIV_DEVCFG |
| 100 | } |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 101 | }; |
| 102 | |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 103 | static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, u8 subsystem) |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 104 | { |
| 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 Kotur | 3de0945 | 2011-09-30 07:25:05 +0000 | [diff] [blame] | 118 | static inline void *embedded_payload(struct be_mcc_wrb *wrb) |
| 119 | { |
| 120 | return wrb->payload.embedded_payload; |
| 121 | } |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 122 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 123 | static int be_mcc_notify(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 124 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 125 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 126 | u32 val = 0; |
| 127 | |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 128 | if (be_check_error(adapter, BE_ERROR_ANY)) |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 129 | return -EIO; |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 130 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 131 | val |= mccq->id & DB_MCCQ_RING_ID_MASK; |
| 132 | val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 133 | |
| 134 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 135 | iowrite32(val, adapter->db + DB_MCCQ_OFFSET); |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 136 | |
| 137 | return 0; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 138 | } |
| 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 Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 143 | static inline bool be_mcc_compl_is_new(struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 144 | { |
Sathya Perla | 9e9ff4b | 2013-02-12 23:05:19 +0000 | [diff] [blame] | 145 | u32 flags; |
| 146 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 147 | if (compl->flags != 0) { |
Sathya Perla | 9e9ff4b | 2013-02-12 23:05:19 +0000 | [diff] [blame] | 148 | flags = le32_to_cpu(compl->flags); |
| 149 | if (flags & CQE_FLAGS_VALID_MASK) { |
| 150 | compl->flags = flags; |
| 151 | return true; |
| 152 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 153 | } |
Sathya Perla | 9e9ff4b | 2013-02-12 23:05:19 +0000 | [diff] [blame] | 154 | return false; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* Need to reset the entire word that houses the valid bit */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 158 | static inline void be_mcc_compl_use(struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 159 | { |
| 160 | compl->flags = 0; |
| 161 | } |
| 162 | |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 163 | static 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 AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 172 | static 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 AP | 77be8c1 | 2015-05-06 05:30:35 -0400 | [diff] [blame] | 177 | addl_status == MCC_ADDL_STATUS_INSUFFICIENT_VLANS || |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 178 | (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 Perla | 559b633 | 2014-05-30 19:06:27 +0530 | [diff] [blame] | 186 | /* 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 | */ |
| 189 | static 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 Reddy | 9c85597 | 2015-07-10 05:32:50 -0400 | [diff] [blame] | 207 | if (opcode == OPCODE_LOWLEVEL_SET_LOOPBACK_MODE && |
| 208 | subsystem == CMD_SUBSYSTEM_LOWLEVEL) { |
| 209 | complete(&adapter->et_cmd_compl); |
| 210 | return; |
| 211 | } |
| 212 | |
Sathya Perla | 559b633 | 2014-05-30 19:06:27 +0530 | [diff] [blame] | 213 | 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 Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 235 | adapter->hwmon_info.be_on_die_temp = |
Sathya Perla | 559b633 | 2014-05-30 19:06:27 +0530 | [diff] [blame] | 236 | resp->on_die_temperature; |
| 237 | } else { |
| 238 | adapter->be_get_temp_freq = 0; |
Venkata Duvvuru | 29e9122 | 2015-05-13 13:00:12 +0530 | [diff] [blame] | 239 | adapter->hwmon_info.be_on_die_temp = |
| 240 | BE_INVALID_DIE_TEMP; |
Sathya Perla | 559b633 | 2014-05-30 19:06:27 +0530 | [diff] [blame] | 241 | } |
| 242 | return; |
| 243 | } |
| 244 | } |
| 245 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 246 | static int be_mcc_compl_process(struct be_adapter *adapter, |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 247 | struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 248 | { |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 249 | enum mcc_base_status base_status; |
| 250 | enum mcc_addl_status addl_status; |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 251 | struct be_cmd_resp_hdr *resp_hdr; |
| 252 | u8 opcode = 0, subsystem = 0; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 253 | |
| 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 AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 258 | base_status = base_status(compl->status); |
| 259 | addl_status = addl_status(compl->status); |
Vasundhara Volam | 96c9b2e | 2014-05-30 19:06:25 +0530 | [diff] [blame] | 260 | |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 261 | resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1); |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 262 | if (resp_hdr) { |
| 263 | opcode = resp_hdr->opcode; |
| 264 | subsystem = resp_hdr->subsystem; |
| 265 | } |
| 266 | |
Sathya Perla | 559b633 | 2014-05-30 19:06:27 +0530 | [diff] [blame] | 267 | be_async_cmd_process(adapter, compl, resp_hdr); |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 268 | |
Sathya Perla | 559b633 | 2014-05-30 19:06:27 +0530 | [diff] [blame] | 269 | if (base_status != MCC_STATUS_SUCCESS && |
| 270 | !be_skip_err_log(opcode, base_status, addl_status)) { |
Suresh Reddy | fa5c867 | 2016-02-03 09:49:17 +0530 | [diff] [blame] | 271 | if (base_status == MCC_STATUS_UNAUTHORIZED_REQUEST || |
| 272 | addl_status == MCC_ADDL_STATUS_INSUFFICIENT_PRIVILEGES) { |
Vasundhara Volam | 97f1d8c | 2012-06-13 19:51:44 +0000 | [diff] [blame] | 273 | dev_warn(&adapter->pdev->dev, |
Vasundhara Volam | 522609f | 2012-08-28 20:37:44 +0000 | [diff] [blame] | 274 | "VF is not privileged to issue opcode %d-%d\n", |
Vasundhara Volam | 97f1d8c | 2012-06-13 19:51:44 +0000 | [diff] [blame] | 275 | opcode, subsystem); |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 276 | } else { |
Vasundhara Volam | 97f1d8c | 2012-06-13 19:51:44 +0000 | [diff] [blame] | 277 | dev_err(&adapter->pdev->dev, |
| 278 | "opcode %d-%d failed:status %d-%d\n", |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 279 | opcode, subsystem, base_status, addl_status); |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 280 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 281 | } |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 282 | return compl->status; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 283 | } |
| 284 | |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 285 | /* Link state evt is a string of bytes; no need for endian swapping */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 286 | static void be_async_link_state_process(struct be_adapter *adapter, |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 287 | struct be_mcc_compl *compl) |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 288 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 289 | struct be_async_event_link_state *evt = |
| 290 | (struct be_async_event_link_state *)compl; |
| 291 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 292 | /* When link status changes, link speed must be re-queried from FW */ |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 293 | adapter->phy.link_speed = -1; |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 294 | |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 295 | /* 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 Ratnakar | 2e177a5 | 2012-07-18 02:52:15 +0000 | [diff] [blame] | 301 | !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK)) |
| 302 | return; |
| 303 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 304 | /* 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 Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 308 | be_link_status_update(adapter, |
| 309 | evt->port_link_status & LINK_STATUS_MASK); |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 310 | } |
| 311 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 312 | static 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 Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 317 | 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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 320 | struct device *dev = &adapter->pdev->dev; |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 321 | u8 msg_severity = DEFAULT_MSG_SEVERITY; |
| 322 | u8 phy_state_info; |
| 323 | u8 new_phy_state; |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 324 | |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 325 | new_phy_state = |
| 326 | (sfp_misconfig_evt_word1 >> (adapter->hba_port_num * 8)) & 0xff; |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 327 | |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 328 | 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 | |
| 347 | log_message: |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 348 | /* Log an error message that would allow a user to determine |
| 349 | * whether the SFPs have an issue |
| 350 | */ |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 351 | 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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 363 | |
Ajit Khaparde | 51d1f98 | 2016-02-10 22:45:54 +0530 | [diff] [blame] | 364 | /* 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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 367 | } |
| 368 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 369 | /* Grp5 CoS Priority evt */ |
| 370 | static void be_async_grp5_cos_priority_process(struct be_adapter *adapter, |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 371 | struct be_mcc_compl *compl) |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 372 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 373 | struct be_async_event_grp5_cos_priority *evt = |
| 374 | (struct be_async_event_grp5_cos_priority *)compl; |
| 375 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 376 | if (evt->valid) { |
| 377 | adapter->vlan_prio_bmap = evt->available_priority_bmap; |
Sathya Perla | fdf81bf | 2015-12-30 01:29:01 -0500 | [diff] [blame] | 378 | adapter->recommended_prio_bits = |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 379 | evt->reco_default_priority << VLAN_PRIO_SHIFT; |
| 380 | } |
| 381 | } |
| 382 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 383 | /* Grp5 QOS Speed evt: qos_link_speed is in units of 10 Mbps */ |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 384 | static void be_async_grp5_qos_speed_process(struct be_adapter *adapter, |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 385 | struct be_mcc_compl *compl) |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 386 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 387 | struct be_async_event_grp5_qos_link_speed *evt = |
| 388 | (struct be_async_event_grp5_qos_link_speed *)compl; |
| 389 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 390 | 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 Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 395 | /*Grp5 PVID evt*/ |
| 396 | static void be_async_grp5_pvid_state_process(struct be_adapter *adapter, |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 397 | struct be_mcc_compl *compl) |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 398 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 399 | struct be_async_event_grp5_pvid_state *evt = |
| 400 | (struct be_async_event_grp5_pvid_state *)compl; |
| 401 | |
Ravikumar Nelavelli | bdac85b | 2014-03-11 18:53:05 +0530 | [diff] [blame] | 402 | if (evt->enabled) { |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 403 | adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK; |
Ravikumar Nelavelli | bdac85b | 2014-03-11 18:53:05 +0530 | [diff] [blame] | 404 | dev_info(&adapter->pdev->dev, "LPVID: %d\n", adapter->pvid); |
| 405 | } else { |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 406 | adapter->pvid = 0; |
Ravikumar Nelavelli | bdac85b | 2014-03-11 18:53:05 +0530 | [diff] [blame] | 407 | } |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 408 | } |
| 409 | |
Venkata Duvvuru | 760c295 | 2015-05-13 13:00:14 +0530 | [diff] [blame] | 410 | #define MGMT_ENABLE_MASK 0x4 |
| 411 | static 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 Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 425 | static void be_async_grp5_evt_process(struct be_adapter *adapter, |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 426 | struct be_mcc_compl *compl) |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 427 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 428 | u8 event_type = (compl->flags >> ASYNC_EVENT_TYPE_SHIFT) & |
| 429 | ASYNC_EVENT_TYPE_MASK; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 430 | |
| 431 | switch (event_type) { |
| 432 | case ASYNC_EVENT_COS_PRIORITY: |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 433 | be_async_grp5_cos_priority_process(adapter, compl); |
| 434 | break; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 435 | case ASYNC_EVENT_QOS_SPEED: |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 436 | be_async_grp5_qos_speed_process(adapter, compl); |
| 437 | break; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 438 | case ASYNC_EVENT_PVID_STATE: |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 439 | be_async_grp5_pvid_state_process(adapter, compl); |
| 440 | break; |
Venkata Duvvuru | 760c295 | 2015-05-13 13:00:14 +0530 | [diff] [blame] | 441 | /* 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 Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 445 | default: |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 446 | break; |
| 447 | } |
| 448 | } |
| 449 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 450 | static void be_async_dbg_evt_process(struct be_adapter *adapter, |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 451 | struct be_mcc_compl *cmp) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 452 | { |
| 453 | u8 event_type = 0; |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 454 | struct be_async_event_qnq *evt = (struct be_async_event_qnq *)cmp; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 455 | |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 456 | event_type = (cmp->flags >> ASYNC_EVENT_TYPE_SHIFT) & |
| 457 | ASYNC_EVENT_TYPE_MASK; |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 458 | |
| 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 Volam | 05ccaa2 | 2013-08-06 09:27:19 +0530 | [diff] [blame] | 466 | dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n", |
| 467 | event_type); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 468 | break; |
| 469 | } |
| 470 | } |
| 471 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 472 | static 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 Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 482 | static inline bool is_link_state_evt(u32 flags) |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 483 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 484 | return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) == |
| 485 | ASYNC_EVENT_CODE_LINK_STATE; |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 486 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 487 | |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 488 | static inline bool is_grp5_evt(u32 flags) |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 489 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 490 | return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) == |
| 491 | ASYNC_EVENT_CODE_GRP_5; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 492 | } |
| 493 | |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 494 | static inline bool is_dbg_evt(u32 flags) |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 495 | { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 496 | return ((flags >> ASYNC_EVENT_CODE_SHIFT) & ASYNC_EVENT_CODE_MASK) == |
| 497 | ASYNC_EVENT_CODE_QNQ; |
| 498 | } |
| 499 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 500 | static 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 Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 506 | static 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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 515 | else if (is_sliport_evt(compl->flags)) |
| 516 | be_async_sliport_evt_process(adapter, compl); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 519 | static struct be_mcc_compl *be_mcc_compl_get(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 520 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 521 | struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq; |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 522 | struct be_mcc_compl *compl = queue_tail_node(mcc_cq); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 523 | |
| 524 | if (be_mcc_compl_is_new(compl)) { |
| 525 | queue_tail_inc(mcc_cq); |
| 526 | return compl; |
| 527 | } |
| 528 | return NULL; |
| 529 | } |
| 530 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 531 | void 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 | |
| 541 | void be_async_mcc_disable(struct be_adapter *adapter) |
| 542 | { |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 543 | spin_lock_bh(&adapter->mcc_cq_lock); |
| 544 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 545 | adapter->mcc_obj.rearm_cq = false; |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 546 | be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0); |
| 547 | |
| 548 | spin_unlock_bh(&adapter->mcc_cq_lock); |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 549 | } |
| 550 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 551 | int be_process_mcc(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 552 | { |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 553 | struct be_mcc_compl *compl; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 554 | int num = 0, status = 0; |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 555 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 556 | |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 557 | spin_lock(&adapter->mcc_cq_lock); |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 558 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 559 | while ((compl = be_mcc_compl_get(adapter))) { |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 560 | if (compl->flags & CQE_FLAGS_ASYNC_MASK) { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 561 | be_mcc_event_process(adapter, compl); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 562 | } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
Sathya Perla | 3acf19d | 2014-05-30 19:06:28 +0530 | [diff] [blame] | 563 | status = be_mcc_compl_process(adapter, compl); |
| 564 | atomic_dec(&mcc_obj->q.used); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 565 | } |
| 566 | be_mcc_compl_use(compl); |
| 567 | num++; |
| 568 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 569 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 570 | if (num) |
| 571 | be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num); |
| 572 | |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 573 | spin_unlock(&adapter->mcc_cq_lock); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 574 | return status; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 577 | /* Wait till no more pending mcc requests are present */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 578 | static int be_mcc_wait_compl(struct be_adapter *adapter) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 579 | { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 580 | #define mcc_timeout 12000 /* 12s timeout */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 581 | int i, status = 0; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 582 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 583 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 584 | for (i = 0; i < mcc_timeout; i++) { |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 585 | if (be_check_error(adapter, BE_ERROR_ANY)) |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 586 | return -EIO; |
| 587 | |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 588 | local_bh_disable(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 589 | status = be_process_mcc(adapter); |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 590 | local_bh_enable(); |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 591 | |
| 592 | if (atomic_read(&mcc_obj->q.used) == 0) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 593 | break; |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 594 | usleep_range(500, 1000); |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 595 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 596 | if (i == mcc_timeout) { |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 597 | dev_err(&adapter->pdev->dev, "FW not responding\n"); |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 598 | be_set_error(adapter, BE_ERROR_FW); |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 599 | return -EIO; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 600 | } |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 601 | return status; |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /* Notify MCC requests and wait for completion */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 605 | static int be_mcc_notify_wait(struct be_adapter *adapter) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 606 | { |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 607 | int status; |
| 608 | struct be_mcc_wrb *wrb; |
| 609 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
ajit.khaparde@broadcom.com | b0fd2eb | 2016-02-23 00:33:48 +0530 | [diff] [blame] | 610 | u32 index = mcc_obj->q.head; |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 611 | 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 Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 618 | status = be_mcc_notify(adapter); |
| 619 | if (status) |
| 620 | goto out; |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 621 | |
| 622 | status = be_mcc_wait_compl(adapter); |
| 623 | if (status == -EIO) |
| 624 | goto out; |
| 625 | |
Kalesh AP | 4c60005 | 2014-05-30 19:06:26 +0530 | [diff] [blame] | 626 | status = (resp->base_status | |
| 627 | ((resp->addl_status & CQE_ADDL_STATUS_MASK) << |
| 628 | CQE_ADDL_STATUS_SHIFT)); |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 629 | out: |
| 630 | return status; |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 633 | static int be_mbox_db_ready_wait(struct be_adapter *adapter, void __iomem *db) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 634 | { |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 635 | int msecs = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 636 | u32 ready; |
| 637 | |
| 638 | do { |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 639 | if (be_check_error(adapter, BE_ERROR_ANY)) |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 640 | return -EIO; |
| 641 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 642 | ready = ioread32(db); |
Sathya Perla | 434b364 | 2011-11-10 19:17:59 +0000 | [diff] [blame] | 643 | if (ready == 0xffffffff) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 644 | return -1; |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 645 | |
| 646 | ready &= MPU_MAILBOX_DB_RDY_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 647 | if (ready) |
| 648 | break; |
| 649 | |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 650 | if (msecs > 4000) { |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 651 | dev_err(&adapter->pdev->dev, "FW not responding\n"); |
Venkata Duvvuru | 954f682 | 2015-05-13 13:00:13 +0530 | [diff] [blame] | 652 | be_set_error(adapter, BE_ERROR_FW); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 653 | be_detect_error(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 654 | return -1; |
| 655 | } |
| 656 | |
Sathya Perla | 1dbf53a | 2011-05-12 19:32:16 +0000 | [diff] [blame] | 657 | msleep(1); |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 658 | msecs++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 659 | } while (true); |
| 660 | |
| 661 | return 0; |
| 662 | } |
| 663 | |
| 664 | /* |
| 665 | * Insert the mailbox address into the doorbell in two steps |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 666 | * Polls on the mbox doorbell till a command completion (or a timeout) occurs |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 667 | */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 668 | static int be_mbox_notify_wait(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 669 | { |
| 670 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 671 | u32 val = 0; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 672 | void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET; |
| 673 | struct be_dma_mem *mbox_mem = &adapter->mbox_mem; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 674 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 675 | struct be_mcc_compl *compl = &mbox->compl; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 676 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 677 | /* wait for ready to be set */ |
| 678 | status = be_mbox_db_ready_wait(adapter, db); |
| 679 | if (status != 0) |
| 680 | return status; |
| 681 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 682 | 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 Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 688 | status = be_mbox_db_ready_wait(adapter, db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 689 | if (status != 0) |
| 690 | return status; |
| 691 | |
| 692 | val = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 693 | /* 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 Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 697 | status = be_mbox_db_ready_wait(adapter, db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 698 | if (status != 0) |
| 699 | return status; |
| 700 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 701 | /* A cq entry has been made now */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 702 | if (be_mcc_compl_is_new(compl)) { |
| 703 | status = be_mcc_compl_process(adapter, &mbox->compl); |
| 704 | be_mcc_compl_use(compl); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 705 | if (status) |
| 706 | return status; |
| 707 | } else { |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 708 | dev_err(&adapter->pdev->dev, "invalid mailbox completion\n"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 709 | return -1; |
| 710 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 711 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Sriharsha Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 714 | u16 be_POST_stage_get(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 715 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 716 | u32 sem; |
| 717 | |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 718 | if (BEx_chip(adapter)) |
| 719 | sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 720 | else |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 721 | pci_read_config_dword(adapter->pdev, |
| 722 | SLIPORT_SEMAPHORE_OFFSET_SH, &sem); |
| 723 | |
| 724 | return sem & POST_STAGE_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Gavin Shan | 87f20c2 | 2013-10-29 17:30:57 +0800 | [diff] [blame] | 727 | static int lancer_wait_ready(struct be_adapter *adapter) |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 728 | { |
| 729 | #define SLIPORT_READY_TIMEOUT 30 |
| 730 | u32 sliport_status; |
Kalesh AP | e673244 | 2015-01-20 03:51:46 -0500 | [diff] [blame] | 731 | int i; |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 732 | |
| 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 Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 736 | return 0; |
| 737 | |
| 738 | if (sliport_status & SLIPORT_STATUS_ERR_MASK && |
| 739 | !(sliport_status & SLIPORT_STATUS_RN_MASK)) |
| 740 | return -EIO; |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 741 | |
| 742 | msleep(1000); |
| 743 | } |
| 744 | |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 745 | return sliport_status ? : -1; |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | int be_fw_wait_ready(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 749 | { |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 750 | u16 stage; |
| 751 | int status, timeout = 0; |
Sathya Perla | 6ed35ee | 2011-05-12 19:32:15 +0000 | [diff] [blame] | 752 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 753 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 754 | if (lancer_chip(adapter)) { |
| 755 | status = lancer_wait_ready(adapter); |
Kalesh AP | e673244 | 2015-01-20 03:51:46 -0500 | [diff] [blame] | 756 | if (status) { |
| 757 | stage = status; |
| 758 | goto err; |
| 759 | } |
| 760 | return 0; |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 761 | } |
| 762 | |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 763 | do { |
Sathya Perla | ca3de6b | 2015-02-23 04:20:10 -0500 | [diff] [blame] | 764 | /* 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 Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 768 | stage = be_POST_stage_get(adapter); |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 769 | if (stage == POST_STAGE_ARMFW_RDY) |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 770 | return 0; |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 771 | |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 772 | dev_info(dev, "Waiting for POST, %ds elapsed\n", timeout); |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 773 | if (msleep_interruptible(2000)) { |
| 774 | dev_err(dev, "Waiting for POST aborted\n"); |
| 775 | return -EINTR; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 776 | } |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 777 | timeout += 2; |
Somnath Kotur | 3ab81b5 | 2011-10-03 08:10:57 +0000 | [diff] [blame] | 778 | } while (timeout < 60); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 779 | |
Kalesh AP | e673244 | 2015-01-20 03:51:46 -0500 | [diff] [blame] | 780 | err: |
| 781 | dev_err(dev, "POST timeout; stage=%#x\n", stage); |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 782 | return -ETIMEDOUT; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 783 | } |
| 784 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 785 | static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb) |
| 786 | { |
| 787 | return &wrb->payload.sgl[0]; |
| 788 | } |
| 789 | |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 790 | static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, unsigned long addr) |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 791 | { |
| 792 | wrb->tag0 = addr & 0xFFFFFFFF; |
| 793 | wrb->tag1 = upper_32_bits(addr); |
| 794 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 795 | |
| 796 | /* Don't touch the hdr after it's prepared */ |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 797 | /* mem will be NULL for embedded commands */ |
| 798 | static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 799 | u8 subsystem, u8 opcode, int cmd_len, |
| 800 | struct be_mcc_wrb *wrb, |
| 801 | struct be_dma_mem *mem) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 802 | { |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 803 | struct be_sge *sge; |
| 804 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 805 | req_hdr->opcode = opcode; |
| 806 | req_hdr->subsystem = subsystem; |
| 807 | req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr)); |
Ajit Khaparde | 07793d3 | 2010-02-16 00:18:46 +0000 | [diff] [blame] | 808 | req_hdr->version = 0; |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 809 | fill_wrb_tags(wrb, (ulong) req_hdr); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 810 | 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 Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 824 | struct be_dma_mem *mem) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 825 | { |
| 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 Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 836 | static inline struct be_mcc_wrb *wrb_from_mbox(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 837 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 838 | 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 Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 843 | } |
| 844 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 845 | static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 846 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 847 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
| 848 | struct be_mcc_wrb *wrb; |
| 849 | |
Padmanabh Ratnakar | aa790db | 2012-10-20 06:03:25 +0000 | [diff] [blame] | 850 | if (!mccq->created) |
| 851 | return NULL; |
| 852 | |
Vasundhara Volam | 4d27712 | 2013-04-21 23:28:15 +0000 | [diff] [blame] | 853 | if (atomic_read(&mccq->used) >= mccq->len) |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 854 | return NULL; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 855 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 856 | wrb = queue_head_node(mccq); |
| 857 | queue_head_inc(mccq); |
| 858 | atomic_inc(&mccq->used); |
| 859 | memset(wrb, 0, sizeof(*wrb)); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 860 | return wrb; |
| 861 | } |
| 862 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 863 | static 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 */ |
| 869 | static int be_cmd_lock(struct be_adapter *adapter) |
| 870 | { |
| 871 | if (use_mcc(adapter)) { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 872 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 873 | return 0; |
| 874 | } else { |
| 875 | return mutex_lock_interruptible(&adapter->mbox_lock); |
| 876 | } |
| 877 | } |
| 878 | |
| 879 | /* Must be used only in process context */ |
| 880 | static void be_cmd_unlock(struct be_adapter *adapter) |
| 881 | { |
| 882 | if (use_mcc(adapter)) |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 883 | return mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 884 | else |
| 885 | return mutex_unlock(&adapter->mbox_lock); |
| 886 | } |
| 887 | |
| 888 | static 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 */ |
| 909 | static 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 Reddy | 0c88456 | 2015-10-12 03:47:18 -0400 | [diff] [blame] | 920 | if (!dest_wrb) { |
| 921 | status = -EBUSY; |
| 922 | goto unlock; |
| 923 | } |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 924 | |
| 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 Reddy | 0c88456 | 2015-10-12 03:47:18 -0400 | [diff] [blame] | 933 | unlock: |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 934 | be_cmd_unlock(adapter); |
| 935 | return status; |
| 936 | } |
| 937 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 938 | /* Tell fw we're about to start firing cmds by writing a |
| 939 | * special pattern across the wrb hdr; uses mbox |
| 940 | */ |
| 941 | int be_cmd_fw_init(struct be_adapter *adapter) |
| 942 | { |
| 943 | u8 *wrb; |
| 944 | int status; |
| 945 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 946 | if (lancer_chip(adapter)) |
| 947 | return 0; |
| 948 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 949 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 950 | return -1; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 951 | |
| 952 | wrb = (u8 *)wrb_from_mbox(adapter); |
Sathya Perla | 359a972 | 2010-12-01 01:03:36 +0000 | [diff] [blame] | 953 | *wrb++ = 0xFF; |
| 954 | *wrb++ = 0x12; |
| 955 | *wrb++ = 0x34; |
| 956 | *wrb++ = 0xFF; |
| 957 | *wrb++ = 0xFF; |
| 958 | *wrb++ = 0x56; |
| 959 | *wrb++ = 0x78; |
| 960 | *wrb = 0xFF; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 961 | |
| 962 | status = be_mbox_notify_wait(adapter); |
| 963 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 964 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 965 | 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 | */ |
| 971 | int be_cmd_fw_clean(struct be_adapter *adapter) |
| 972 | { |
| 973 | u8 *wrb; |
| 974 | int status; |
| 975 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 976 | if (lancer_chip(adapter)) |
| 977 | return 0; |
| 978 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 979 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 980 | return -1; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 981 | |
| 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 Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 994 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 995 | return status; |
| 996 | } |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 997 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 998 | int be_cmd_eq_create(struct be_adapter *adapter, struct be_eq_obj *eqo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 999 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1000 | struct be_mcc_wrb *wrb; |
| 1001 | struct be_cmd_req_eq_create *req; |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 1002 | struct be_dma_mem *q_mem = &eqo->q.dma_mem; |
| 1003 | int status, ver = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1004 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1005 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1006 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1007 | |
| 1008 | wrb = wrb_from_mbox(adapter); |
| 1009 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1010 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1011 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1012 | OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, |
| 1013 | NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1014 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 1015 | /* 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 Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1020 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 1021 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1022 | 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 Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 1026 | __ilog2_u32(eqo->q.len / 256)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1027 | 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 Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1031 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1032 | if (!status) { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1033 | struct be_cmd_resp_eq_create *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1034 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 1035 | 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 Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1039 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1040 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1041 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1042 | return status; |
| 1043 | } |
| 1044 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1045 | /* Use MCC */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1046 | int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr, |
Sathya Perla | 5ee4979 | 2012-09-28 04:39:41 +0000 | [diff] [blame] | 1047 | bool permanent, u32 if_handle, u32 pmac_id) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1048 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1049 | struct be_mcc_wrb *wrb; |
| 1050 | struct be_cmd_req_mac_query *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1051 | int status; |
| 1052 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1053 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1054 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1055 | wrb = wrb_from_mccq(adapter); |
| 1056 | if (!wrb) { |
| 1057 | status = -EBUSY; |
| 1058 | goto err; |
| 1059 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1060 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1061 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1062 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1063 | OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, |
| 1064 | NULL); |
Sathya Perla | 5ee4979 | 2012-09-28 04:39:41 +0000 | [diff] [blame] | 1065 | req->type = MAC_ADDRESS_TYPE_NETWORK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1066 | if (permanent) { |
| 1067 | req->permanent = 1; |
| 1068 | } else { |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 1069 | req->if_id = cpu_to_le16((u16)if_handle); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 1070 | req->pmac_id = cpu_to_le32(pmac_id); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1071 | req->permanent = 0; |
| 1072 | } |
| 1073 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1074 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1075 | if (!status) { |
| 1076 | struct be_cmd_resp_mac_query *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1077 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1078 | memcpy(mac_addr, resp->mac.addr, ETH_ALEN); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1079 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1080 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1081 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1082 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1083 | return status; |
| 1084 | } |
| 1085 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1086 | /* Uses synchronous MCCQ */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1087 | int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1088 | u32 if_id, u32 *pmac_id, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1089 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1090 | struct be_mcc_wrb *wrb; |
| 1091 | struct be_cmd_req_pmac_add *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1092 | int status; |
| 1093 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1094 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1095 | |
| 1096 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1097 | if (!wrb) { |
| 1098 | status = -EBUSY; |
| 1099 | goto err; |
| 1100 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1101 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1102 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1103 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1104 | OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, |
| 1105 | NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1106 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 1107 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1108 | req->if_id = cpu_to_le32(if_id); |
| 1109 | memcpy(req->mac_address, mac_addr, ETH_ALEN); |
| 1110 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1111 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1112 | if (!status) { |
| 1113 | struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1114 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1115 | *pmac_id = le32_to_cpu(resp->pmac_id); |
| 1116 | } |
| 1117 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1118 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1119 | mutex_unlock(&adapter->mcc_lock); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 1120 | |
| 1121 | if (status == MCC_STATUS_UNAUTHORIZED_REQUEST) |
| 1122 | status = -EPERM; |
| 1123 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1124 | return status; |
| 1125 | } |
| 1126 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1127 | /* Uses synchronous MCCQ */ |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 1128 | int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, int pmac_id, u32 dom) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1129 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1130 | struct be_mcc_wrb *wrb; |
| 1131 | struct be_cmd_req_pmac_del *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1132 | int status; |
| 1133 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 1134 | if (pmac_id == -1) |
| 1135 | return 0; |
| 1136 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1137 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1138 | |
| 1139 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1140 | if (!wrb) { |
| 1141 | status = -EBUSY; |
| 1142 | goto err; |
| 1143 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1144 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1145 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1146 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 1147 | OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), |
| 1148 | wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1149 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 1150 | req->hdr.domain = dom; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1151 | req->if_id = cpu_to_le32(if_id); |
| 1152 | req->pmac_id = cpu_to_le32(pmac_id); |
| 1153 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1154 | status = be_mcc_notify_wait(adapter); |
| 1155 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1156 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1157 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1158 | return status; |
| 1159 | } |
| 1160 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1161 | /* Uses Mbox */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1162 | int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1163 | struct be_queue_info *eq, bool no_delay, int coalesce_wm) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1164 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1165 | struct be_mcc_wrb *wrb; |
| 1166 | struct be_cmd_req_cq_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1167 | struct be_dma_mem *q_mem = &cq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1168 | void *ctxt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1169 | int status; |
| 1170 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1171 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1172 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1173 | |
| 1174 | wrb = wrb_from_mbox(adapter); |
| 1175 | req = embedded_payload(wrb); |
| 1176 | ctxt = &req->context; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1177 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1178 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1179 | OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, |
| 1180 | NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1181 | |
| 1182 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
Ajit Khaparde | bbdc42f | 2013-05-01 09:37:17 +0000 | [diff] [blame] | 1183 | |
| 1184 | if (BEx_chip(adapter)) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1185 | AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1186 | coalesce_wm); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1187 | AMAP_SET_BITS(struct amap_cq_context_be, nodelay, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1188 | ctxt, no_delay); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1189 | AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1190 | __ilog2_u32(cq->len / 256)); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1191 | AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1192 | 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 Khaparde | bbdc42f | 2013-05-01 09:37:17 +0000 | [diff] [blame] | 1194 | } else { |
| 1195 | req->hdr.version = 2; |
| 1196 | req->page_size = 1; /* 1 for 4K */ |
Ajit Khaparde | 09e83a9 | 2013-11-22 12:51:20 -0600 | [diff] [blame] | 1197 | |
| 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 Khaparde | bbdc42f | 2013-05-01 09:37:17 +0000 | [diff] [blame] | 1204 | AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1205 | no_delay); |
Ajit Khaparde | bbdc42f | 2013-05-01 09:37:17 +0000 | [diff] [blame] | 1206 | AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1207 | __ilog2_u32(cq->len / 256)); |
Ajit Khaparde | bbdc42f | 2013-05-01 09:37:17 +0000 | [diff] [blame] | 1208 | AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1); |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1209 | 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 Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1211 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1212 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1213 | 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 Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1217 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1218 | if (!status) { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1219 | struct be_cmd_resp_cq_create *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1220 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1221 | cq->id = le16_to_cpu(resp->cq_id); |
| 1222 | cq->created = true; |
| 1223 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1224 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1225 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1226 | |
| 1227 | return status; |
| 1228 | } |
| 1229 | |
| 1230 | static u32 be_encoded_q_len(int q_len) |
| 1231 | { |
| 1232 | u32 len_encoded = fls(q_len); /* log2(len) + 1 */ |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1233 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1234 | if (len_encoded == 16) |
| 1235 | len_encoded = 0; |
| 1236 | return len_encoded; |
| 1237 | } |
| 1238 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1239 | static int be_cmd_mccq_ext_create(struct be_adapter *adapter, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1240 | struct be_queue_info *mccq, |
| 1241 | struct be_queue_info *cq) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1242 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1243 | struct be_mcc_wrb *wrb; |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1244 | struct be_cmd_req_mcc_ext_create *req; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1245 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1246 | void *ctxt; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1247 | int status; |
| 1248 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1249 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1250 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1251 | |
| 1252 | wrb = wrb_from_mbox(adapter); |
| 1253 | req = embedded_payload(wrb); |
| 1254 | ctxt = &req->context; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1255 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1256 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1257 | OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, |
| 1258 | NULL); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1259 | |
Ajit Khaparde | d4a2ac3 | 2010-03-11 01:35:59 +0000 | [diff] [blame] | 1260 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
Vasundhara Volam | 666d39c | 2014-01-15 13:23:31 +0530 | [diff] [blame] | 1261 | if (BEx_chip(adapter)) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1262 | AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1); |
| 1263 | AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1264 | be_encoded_q_len(mccq->len)); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1265 | AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id); |
Vasundhara Volam | 666d39c | 2014-01-15 13:23:31 +0530 | [diff] [blame] | 1266 | } 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 Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 1279 | /* 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 Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1288 | 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 Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1292 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1293 | if (!status) { |
| 1294 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1295 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1296 | mccq->id = le16_to_cpu(resp->id); |
| 1297 | mccq->created = true; |
| 1298 | } |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1299 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1300 | |
| 1301 | return status; |
| 1302 | } |
| 1303 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1304 | static int be_cmd_mccq_org_create(struct be_adapter *adapter, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1305 | struct be_queue_info *mccq, |
| 1306 | struct be_queue_info *cq) |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1307 | { |
| 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 Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1321 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1322 | OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, |
| 1323 | NULL); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1324 | |
| 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 Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1329 | be_encoded_q_len(mccq->len)); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1330 | 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1339 | |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1340 | mccq->id = le16_to_cpu(resp->id); |
| 1341 | mccq->created = true; |
| 1342 | } |
| 1343 | |
| 1344 | mutex_unlock(&adapter->mbox_lock); |
| 1345 | return status; |
| 1346 | } |
| 1347 | |
| 1348 | int be_cmd_mccq_create(struct be_adapter *adapter, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1349 | struct be_queue_info *mccq, struct be_queue_info *cq) |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1350 | { |
| 1351 | int status; |
| 1352 | |
| 1353 | status = be_cmd_mccq_ext_create(adapter, mccq, cq); |
Vasundhara Volam | 666d39c | 2014-01-15 13:23:31 +0530 | [diff] [blame] | 1354 | if (status && BEx_chip(adapter)) { |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1355 | 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 Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1363 | int be_cmd_txq_create(struct be_adapter *adapter, struct be_tx_obj *txo) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1364 | { |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1365 | struct be_mcc_wrb wrb = {0}; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1366 | struct be_cmd_req_eth_tx_create *req; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1367 | struct be_queue_info *txq = &txo->q; |
| 1368 | struct be_queue_info *cq = &txo->cq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1369 | struct be_dma_mem *q_mem = &txq->dma_mem; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1370 | int status, ver = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1371 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1372 | req = embedded_payload(&wrb); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1373 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1374 | OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1375 | |
Padmanabh Ratnakar | 8b7756c | 2011-03-07 03:08:52 +0000 | [diff] [blame] | 1376 | if (lancer_chip(adapter)) { |
| 1377 | req->hdr.version = 1; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1378 | } 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 Ratnakar | 8b7756c | 2011-03-07 03:08:52 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Vasundhara Volam | 81b0265 | 2013-10-01 15:59:57 +0530 | [diff] [blame] | 1385 | if (req->hdr.version > 0) |
| 1386 | req->if_id = cpu_to_le16(adapter->if_handle); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1387 | 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 Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1390 | req->cq_id = cpu_to_le16(cq->id); |
| 1391 | req->queue_size = be_encoded_q_len(txq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1392 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1393 | ver = req->hdr.version; |
| 1394 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1395 | status = be_cmd_notify_wait(adapter, &wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1396 | if (!status) { |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1397 | struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1398 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1399 | txq->id = le16_to_cpu(resp->cid); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1400 | if (ver == 2) |
| 1401 | txo->db_offset = le32_to_cpu(resp->db_offset); |
| 1402 | else |
| 1403 | txo->db_offset = DB_TXULP1_OFFSET; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1404 | txq->created = true; |
| 1405 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1406 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1407 | return status; |
| 1408 | } |
| 1409 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1410 | /* Uses MCC */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1411 | int be_cmd_rxq_create(struct be_adapter *adapter, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1412 | struct be_queue_info *rxq, u16 cq_id, u16 frag_size, |
| 1413 | u32 if_id, u32 rss, u8 *rss_id) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1414 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1415 | struct be_mcc_wrb *wrb; |
| 1416 | struct be_cmd_req_eth_rx_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1417 | struct be_dma_mem *q_mem = &rxq->dma_mem; |
| 1418 | int status; |
| 1419 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1420 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1421 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1422 | wrb = wrb_from_mccq(adapter); |
| 1423 | if (!wrb) { |
| 1424 | status = -EBUSY; |
| 1425 | goto err; |
| 1426 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1427 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1428 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1429 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1430 | OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1431 | |
| 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 Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1437 | req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1438 | req->rss_queue = cpu_to_le32(rss); |
| 1439 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1440 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1441 | if (!status) { |
| 1442 | struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1443 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1444 | rxq->id = le16_to_cpu(resp->id); |
| 1445 | rxq->created = true; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1446 | *rss_id = resp->rss_id; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1447 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1448 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1449 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1450 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1451 | return status; |
| 1452 | } |
| 1453 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1454 | /* Generic destroyer function for all types of queues |
| 1455 | * Uses Mbox |
| 1456 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1457 | int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1458 | int queue_type) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1459 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1460 | struct be_mcc_wrb *wrb; |
| 1461 | struct be_cmd_req_q_destroy *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1462 | u8 subsys = 0, opcode = 0; |
| 1463 | int status; |
| 1464 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1465 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1466 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1467 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1468 | wrb = wrb_from_mbox(adapter); |
| 1469 | req = embedded_payload(wrb); |
| 1470 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1471 | 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 Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1488 | case QTYPE_MCCQ: |
| 1489 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1490 | opcode = OPCODE_COMMON_MCC_DESTROY; |
| 1491 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1492 | default: |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 1493 | BUG(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1494 | } |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1495 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1496 | be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1497 | NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1498 | req->id = cpu_to_le16(q->id); |
| 1499 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1500 | status = be_mbox_notify_wait(adapter); |
Padmanabh Ratnakar | aa790db | 2012-10-20 06:03:25 +0000 | [diff] [blame] | 1501 | q->created = false; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 1502 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1503 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1504 | return status; |
| 1505 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1506 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1507 | /* Uses MCC */ |
| 1508 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1514 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1515 | |
| 1516 | wrb = wrb_from_mccq(adapter); |
| 1517 | if (!wrb) { |
| 1518 | status = -EBUSY; |
| 1519 | goto err; |
| 1520 | } |
| 1521 | req = embedded_payload(wrb); |
| 1522 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1523 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1524 | OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1525 | req->id = cpu_to_le16(q->id); |
| 1526 | |
| 1527 | status = be_mcc_notify_wait(adapter); |
Padmanabh Ratnakar | aa790db | 2012-10-20 06:03:25 +0000 | [diff] [blame] | 1528 | q->created = false; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1529 | |
| 1530 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1531 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1532 | return status; |
| 1533 | } |
| 1534 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1535 | /* Create an rx filtering policy configuration on an i/f |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1536 | * Will use MBOX only if MCCQ has not been created. |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1537 | */ |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 1538 | int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags, |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 1539 | u32 *if_handle, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1540 | { |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1541 | struct be_mcc_wrb wrb = {0}; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1542 | struct be_cmd_req_if_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1543 | int status; |
| 1544 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1545 | req = embedded_payload(&wrb); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1546 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1547 | OPCODE_COMMON_NTWK_INTERFACE_CREATE, |
| 1548 | sizeof(*req), &wrb, NULL); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1549 | req->hdr.domain = domain; |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 1550 | req->capability_flags = cpu_to_le32(cap_flags); |
| 1551 | req->enable_flags = cpu_to_le32(en_flags); |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 1552 | req->pmac_invalid = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1553 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1554 | status = be_cmd_notify_wait(adapter, &wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1555 | if (!status) { |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1556 | struct be_cmd_resp_if_create *resp = embedded_payload(&wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1557 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1558 | *if_handle = le32_to_cpu(resp->interface_id); |
Sathya Perla | b5bb977 | 2013-07-23 15:25:01 +0530 | [diff] [blame] | 1559 | |
| 1560 | /* Hack to retrieve VF's pmac-id on BE3 */ |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 1561 | if (BE3_chip(adapter) && be_virtfn(adapter)) |
Sathya Perla | b5bb977 | 2013-07-23 15:25:01 +0530 | [diff] [blame] | 1562 | adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1563 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1564 | return status; |
| 1565 | } |
| 1566 | |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 1567 | /* Uses MCCQ if available else MBOX */ |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 1568 | int be_cmd_if_destroy(struct be_adapter *adapter, int interface_id, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1569 | { |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 1570 | struct be_mcc_wrb wrb = {0}; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1571 | struct be_cmd_req_if_destroy *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1572 | int status; |
| 1573 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 1574 | if (interface_id == -1) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1575 | return 0; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1576 | |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 1577 | req = embedded_payload(&wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1578 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1579 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1580 | OPCODE_COMMON_NTWK_INTERFACE_DESTROY, |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 1581 | sizeof(*req), &wrb, NULL); |
Ajit Khaparde | 658681f | 2011-02-11 13:34:46 +0000 | [diff] [blame] | 1582 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1583 | req->interface_id = cpu_to_le32(interface_id); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1584 | |
Ajit Khaparde | 6221906 | 2016-02-10 22:45:53 +0530 | [diff] [blame] | 1585 | status = be_cmd_notify_wait(adapter, &wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1586 | 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 Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1591 | * Uses asynchronous MCC |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1592 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1593 | int be_cmd_get_stats(struct be_adapter *adapter, struct be_dma_mem *nonemb_cmd) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1594 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1595 | struct be_mcc_wrb *wrb; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1596 | struct be_cmd_req_hdr *hdr; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1597 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1598 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1599 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1600 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1601 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1602 | if (!wrb) { |
| 1603 | status = -EBUSY; |
| 1604 | goto err; |
| 1605 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1606 | hdr = nonemb_cmd->va; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1607 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1608 | be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1609 | OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, |
| 1610 | nonemb_cmd); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1611 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 1612 | /* version 1 of the cmd is not supported only by BE2 */ |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 1613 | if (BE2_chip(adapter)) |
| 1614 | hdr->version = 0; |
| 1615 | if (BE3_chip(adapter) || lancer_chip(adapter)) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1616 | hdr->version = 1; |
Ajit Khaparde | 6100086 | 2013-10-03 16:16:33 -0500 | [diff] [blame] | 1617 | else |
| 1618 | hdr->version = 2; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1619 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 1620 | status = be_mcc_notify(adapter); |
| 1621 | if (status) |
| 1622 | goto err; |
| 1623 | |
Ajit Khaparde | b2aebe6 | 2011-02-20 11:41:39 +0000 | [diff] [blame] | 1624 | adapter->stats_cmd_sent = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1625 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1626 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1627 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1628 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1631 | /* Lancer Stats */ |
| 1632 | int lancer_cmd_get_pport_stats(struct be_adapter *adapter, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1633 | struct be_dma_mem *nonemb_cmd) |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1634 | { |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1635 | struct be_mcc_wrb *wrb; |
| 1636 | struct lancer_cmd_req_pport_stats *req; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1637 | int status = 0; |
| 1638 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 1639 | if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS, |
| 1640 | CMD_SUBSYSTEM_ETH)) |
| 1641 | return -EPERM; |
| 1642 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1643 | mutex_lock(&adapter->mcc_lock); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1644 | |
| 1645 | wrb = wrb_from_mccq(adapter); |
| 1646 | if (!wrb) { |
| 1647 | status = -EBUSY; |
| 1648 | goto err; |
| 1649 | } |
| 1650 | req = nonemb_cmd->va; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1651 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1652 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1653 | OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, |
| 1654 | wrb, nonemb_cmd); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1655 | |
Padmanabh Ratnakar | d51ebd3 | 2012-04-25 01:46:52 +0000 | [diff] [blame] | 1656 | req->cmd_params.params.pport_num = cpu_to_le16(adapter->hba_port_num); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1657 | req->cmd_params.params.reset_stats = 0; |
| 1658 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 1659 | status = be_mcc_notify(adapter); |
| 1660 | if (status) |
| 1661 | goto err; |
| 1662 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1663 | adapter->stats_cmd_sent = true; |
| 1664 | |
| 1665 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1666 | mutex_unlock(&adapter->mcc_lock); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1667 | return status; |
| 1668 | } |
| 1669 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 1670 | static 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 Volam | b971f84 | 2013-08-06 09:27:15 +0530 | [diff] [blame] | 1683 | 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 Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 1689 | } |
| 1690 | return 0; |
| 1691 | } |
| 1692 | |
| 1693 | /* Uses synchronous mcc |
| 1694 | * Returns link_speed in Mbps |
| 1695 | */ |
| 1696 | int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed, |
| 1697 | u8 *link_status, u32 dom) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1698 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1699 | struct be_mcc_wrb *wrb; |
| 1700 | struct be_cmd_req_link_status *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1701 | int status; |
| 1702 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1703 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1704 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 1705 | if (link_status) |
| 1706 | *link_status = LINK_DOWN; |
| 1707 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1708 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1709 | if (!wrb) { |
| 1710 | status = -EBUSY; |
| 1711 | goto err; |
| 1712 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1713 | req = embedded_payload(wrb); |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1714 | |
Padmanabh Ratnakar | 57cd80d | 2012-02-03 09:49:46 +0000 | [diff] [blame] | 1715 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1716 | OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, |
| 1717 | sizeof(*req), wrb, NULL); |
Padmanabh Ratnakar | 57cd80d | 2012-02-03 09:49:46 +0000 | [diff] [blame] | 1718 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 1719 | /* version 1 of the cmd is not supported only by BE2 */ |
| 1720 | if (!BE2_chip(adapter)) |
Padmanabh Ratnakar | daad616 | 2011-11-16 02:03:45 +0000 | [diff] [blame] | 1721 | req->hdr.version = 1; |
| 1722 | |
Padmanabh Ratnakar | 57cd80d | 2012-02-03 09:49:46 +0000 | [diff] [blame] | 1723 | req->hdr.domain = dom; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1724 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1725 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1726 | if (!status) { |
| 1727 | struct be_cmd_resp_link_status *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1728 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 1729 | 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 Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1736 | } |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 1737 | if (link_status) |
| 1738 | *link_status = resp->logical_link_status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1741 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1742 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1743 | return status; |
| 1744 | } |
| 1745 | |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1746 | /* Uses synchronous mcc */ |
| 1747 | int 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 Volam | 117affe | 2013-08-06 09:27:20 +0530 | [diff] [blame] | 1751 | int status = 0; |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1752 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1753 | mutex_lock(&adapter->mcc_lock); |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1754 | |
| 1755 | wrb = wrb_from_mccq(adapter); |
| 1756 | if (!wrb) { |
| 1757 | status = -EBUSY; |
| 1758 | goto err; |
| 1759 | } |
| 1760 | req = embedded_payload(wrb); |
| 1761 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1762 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1763 | OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, |
| 1764 | sizeof(*req), wrb, NULL); |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1765 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 1766 | status = be_mcc_notify(adapter); |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1767 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1768 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1769 | return status; |
| 1770 | } |
| 1771 | |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1772 | /* Uses synchronous mcc */ |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1773 | int be_cmd_get_fat_dump_len(struct be_adapter *adapter, u32 *dump_size) |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1774 | { |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1775 | struct be_mcc_wrb wrb = {0}; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1776 | struct be_cmd_req_get_fat *req; |
| 1777 | int status; |
| 1778 | |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1779 | req = embedded_payload(&wrb); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1780 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1781 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1782 | OPCODE_COMMON_MANAGE_FAT, sizeof(*req), |
| 1783 | &wrb, NULL); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1784 | req->fat_operation = cpu_to_le32(QUERY_FAT); |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1785 | status = be_cmd_notify_wait(adapter, &wrb); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1786 | if (!status) { |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1787 | struct be_cmd_resp_get_fat *resp = embedded_payload(&wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1788 | |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1789 | if (dump_size && resp->log_size) |
| 1790 | *dump_size = le32_to_cpu(resp->log_size) - |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1791 | sizeof(u32); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1792 | } |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1793 | return status; |
| 1794 | } |
| 1795 | |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1796 | int be_cmd_get_fat_dump(struct be_adapter *adapter, u32 buf_len, void *buf) |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1797 | { |
| 1798 | struct be_dma_mem get_fat_cmd; |
| 1799 | struct be_mcc_wrb *wrb; |
| 1800 | struct be_cmd_req_get_fat *req; |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1801 | u32 offset = 0, total_size, buf_size, |
| 1802 | log_offset = sizeof(u32), payload_len; |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1803 | int status; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1804 | |
| 1805 | if (buf_len == 0) |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1806 | return 0; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1807 | |
| 1808 | total_size = buf_len; |
| 1809 | |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1810 | get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024; |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 1811 | get_fat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, |
| 1812 | get_fat_cmd.size, |
| 1813 | &get_fat_cmd.dma, GFP_ATOMIC); |
Venkat Duvvuru | fd7ff6f | 2015-12-30 01:29:04 -0500 | [diff] [blame] | 1814 | if (!get_fat_cmd.va) |
Vasundhara Volam | c5f156d | 2014-09-02 09:56:54 +0530 | [diff] [blame] | 1815 | return -ENOMEM; |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1816 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1817 | mutex_lock(&adapter->mcc_lock); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1818 | |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1819 | while (total_size) { |
| 1820 | buf_size = min(total_size, (u32)60*1024); |
| 1821 | total_size -= buf_size; |
| 1822 | |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1823 | wrb = wrb_from_mccq(adapter); |
| 1824 | if (!wrb) { |
| 1825 | status = -EBUSY; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1826 | goto err; |
| 1827 | } |
| 1828 | req = get_fat_cmd.va; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1829 | |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1830 | payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size; |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1831 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1832 | OPCODE_COMMON_MANAGE_FAT, payload_len, |
| 1833 | wrb, &get_fat_cmd); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1834 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 1843 | |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1844 | memcpy(buf + offset, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1845 | resp->data_buffer, |
| 1846 | le32_to_cpu(resp->read_log_length)); |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1847 | } else { |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1848 | dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n"); |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1849 | goto err; |
| 1850 | } |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1851 | offset += buf_size; |
| 1852 | log_offset += buf_size; |
| 1853 | } |
| 1854 | err: |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 1855 | dma_free_coherent(&adapter->pdev->dev, get_fat_cmd.size, |
| 1856 | get_fat_cmd.va, get_fat_cmd.dma); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1857 | mutex_unlock(&adapter->mcc_lock); |
Vasundhara Volam | c5f156d | 2014-09-02 09:56:54 +0530 | [diff] [blame] | 1858 | return status; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1859 | } |
| 1860 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1861 | /* Uses synchronous mcc */ |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 1862 | int be_cmd_get_fw_ver(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1863 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1864 | struct be_mcc_wrb *wrb; |
| 1865 | struct be_cmd_req_get_fw_version *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1866 | int status; |
| 1867 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1868 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1869 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1870 | wrb = wrb_from_mccq(adapter); |
| 1871 | if (!wrb) { |
| 1872 | status = -EBUSY; |
| 1873 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1876 | req = embedded_payload(wrb); |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1877 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1878 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1879 | OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, |
| 1880 | NULL); |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1881 | status = be_mcc_notify_wait(adapter); |
| 1882 | if (!status) { |
| 1883 | struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb); |
Sathya Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 1884 | |
Vasundhara Volam | 242eb47 | 2014-09-12 17:39:15 +0530 | [diff] [blame] | 1885 | 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 Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1889 | } |
| 1890 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1891 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1892 | return status; |
| 1893 | } |
| 1894 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1895 | /* set the EQ delay interval of an EQ to specified value |
| 1896 | * Uses async mcc |
| 1897 | */ |
Kalesh AP | b502ae8 | 2014-09-19 15:46:51 +0530 | [diff] [blame] | 1898 | static int __be_cmd_modify_eqd(struct be_adapter *adapter, |
| 1899 | struct be_set_eqd *set_eqd, int num) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1900 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1901 | struct be_mcc_wrb *wrb; |
| 1902 | struct be_cmd_req_modify_eq_delay *req; |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1903 | int status = 0, i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1904 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1905 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1906 | |
| 1907 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1908 | if (!wrb) { |
| 1909 | status = -EBUSY; |
| 1910 | goto err; |
| 1911 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1912 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1913 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1914 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1915 | OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, |
| 1916 | NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1917 | |
Sathya Perla | 2632baf | 2013-10-01 16:00:00 +0530 | [diff] [blame] | 1918 | 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 Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1925 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 1926 | status = be_mcc_notify(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1927 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1928 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1929 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
Kalesh AP | 9367670 | 2014-09-12 17:39:20 +0530 | [diff] [blame] | 1932 | int 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 Reddy | c8ba4ad0 | 2015-03-20 06:28:24 -0400 | [diff] [blame] | 1937 | 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 AP | 9367670 | 2014-09-12 17:39:20 +0530 | [diff] [blame] | 1942 | } |
| 1943 | |
| 1944 | return 0; |
| 1945 | } |
| 1946 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1947 | /* Uses sycnhronous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1948 | int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array, |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1949 | u32 num, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1950 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1951 | struct be_mcc_wrb *wrb; |
| 1952 | struct be_cmd_req_vlan_config *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1953 | int status; |
| 1954 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1955 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1956 | |
| 1957 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1958 | if (!wrb) { |
| 1959 | status = -EBUSY; |
| 1960 | goto err; |
| 1961 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1962 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1963 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1964 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1965 | OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), |
| 1966 | wrb, NULL); |
Vasundhara Volam | 435452a | 2015-03-20 06:28:23 -0400 | [diff] [blame] | 1967 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1968 | |
| 1969 | req->interface_id = if_id; |
Ajit Khaparde | 012bd38 | 2013-11-18 10:44:24 -0600 | [diff] [blame] | 1970 | req->untagged = BE_IF_FLAGS_UNTAGGED & be_if_cap_flags(adapter) ? 1 : 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1971 | req->num_vlan = num; |
Kalesh AP | 4d567d9 | 2014-05-09 13:29:17 +0530 | [diff] [blame] | 1972 | memcpy(req->normal_vlan, vtag_array, |
| 1973 | req->num_vlan * sizeof(vtag_array[0])); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1974 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1975 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1976 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1977 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1978 | return status; |
| 1979 | } |
| 1980 | |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 1981 | static int __be_cmd_rx_filter(struct be_adapter *adapter, u32 flags, u32 value) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1982 | { |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1983 | struct be_mcc_wrb *wrb; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1984 | struct be_dma_mem *mem = &adapter->rx_filter; |
| 1985 | struct be_cmd_req_rx_filter *req = mem->va; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1986 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1987 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 1988 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1989 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1990 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1991 | if (!wrb) { |
| 1992 | status = -EBUSY; |
| 1993 | goto err; |
| 1994 | } |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1995 | memset(req, 0, sizeof(*req)); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1996 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 1997 | OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req), |
| 1998 | wrb, mem); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1999 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 2000 | req->if_id = cpu_to_le32(adapter->if_handle); |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 2001 | req->if_flags_mask = cpu_to_le32(flags); |
| 2002 | req->if_flags = (value == ON) ? req->if_flags_mask : 0; |
Ajit Khaparde | d9d604f | 2013-09-27 15:17:58 -0500 | [diff] [blame] | 2003 | |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 2004 | if (flags & BE_IF_FLAGS_MULTICAST) { |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2005 | int i; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2006 | |
Padmanabh Ratnakar | 1610c79 | 2011-11-03 01:49:27 +0000 | [diff] [blame] | 2007 | /* Reset mcast promisc mode if already set by setting mask |
| 2008 | * and not setting flags field |
| 2009 | */ |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 2010 | req->if_flags_mask |= |
| 2011 | cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS & |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 2012 | be_if_cap_flags(adapter)); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2013 | 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 Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 2017 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2018 | |
Sathya Perla | b658887 | 2015-09-03 07:41:53 -0400 | [diff] [blame] | 2019 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2020 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2021 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 2022 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2023 | } |
| 2024 | |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 2025 | int 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 AP | 196e373 | 2015-10-12 03:47:21 -0400 | [diff] [blame] | 2035 | if (!flags) |
| 2036 | return -ENOTSUPP; |
Sathya Perla | ac34b74 | 2015-02-06 08:18:40 -0500 | [diff] [blame] | 2037 | |
| 2038 | return __be_cmd_rx_filter(adapter, flags, value); |
| 2039 | } |
| 2040 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2041 | /* Uses synchrounous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2042 | int be_cmd_set_flow_control(struct be_adapter *adapter, u32 tx_fc, u32 rx_fc) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2043 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2044 | struct be_mcc_wrb *wrb; |
| 2045 | struct be_cmd_req_set_flow_control *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2046 | int status; |
| 2047 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 2048 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL, |
| 2049 | CMD_SUBSYSTEM_COMMON)) |
| 2050 | return -EPERM; |
| 2051 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2052 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2053 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2054 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2055 | if (!wrb) { |
| 2056 | status = -EBUSY; |
| 2057 | goto err; |
| 2058 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2059 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2060 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2061 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2062 | OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), |
| 2063 | wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2064 | |
Suresh Reddy | b29812c | 2014-09-12 17:39:17 +0530 | [diff] [blame] | 2065 | req->hdr.version = 1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2066 | req->tx_flow_control = cpu_to_le16((u16)tx_fc); |
| 2067 | req->rx_flow_control = cpu_to_le16((u16)rx_fc); |
| 2068 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2069 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2070 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2071 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2072 | mutex_unlock(&adapter->mcc_lock); |
Suresh Reddy | b29812c | 2014-09-12 17:39:17 +0530 | [diff] [blame] | 2073 | |
| 2074 | if (base_status(status) == MCC_STATUS_FEATURE_NOT_SUPPORTED) |
| 2075 | return -EOPNOTSUPP; |
| 2076 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2077 | return status; |
| 2078 | } |
| 2079 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2080 | /* Uses sycn mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 2081 | int be_cmd_get_flow_control(struct be_adapter *adapter, u32 *tx_fc, u32 *rx_fc) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2082 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2083 | struct be_mcc_wrb *wrb; |
| 2084 | struct be_cmd_req_get_flow_control *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2085 | int status; |
| 2086 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 2087 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL, |
| 2088 | CMD_SUBSYSTEM_COMMON)) |
| 2089 | return -EPERM; |
| 2090 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2091 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2092 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2093 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2094 | if (!wrb) { |
| 2095 | status = -EBUSY; |
| 2096 | goto err; |
| 2097 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2098 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2099 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2100 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2101 | OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), |
| 2102 | wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2103 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2104 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2105 | if (!status) { |
| 2106 | struct be_cmd_resp_get_flow_control *resp = |
| 2107 | embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 2108 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2109 | *tx_fc = le16_to_cpu(resp->tx_flow_control); |
| 2110 | *rx_fc = le16_to_cpu(resp->rx_flow_control); |
| 2111 | } |
| 2112 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2113 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2114 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2115 | return status; |
| 2116 | } |
| 2117 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2118 | /* Uses mbox */ |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 2119 | int be_cmd_query_fw_cfg(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2120 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2121 | struct be_mcc_wrb *wrb; |
| 2122 | struct be_cmd_req_query_fw_cfg *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2123 | int status; |
| 2124 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 2125 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 2126 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2127 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2128 | wrb = wrb_from_mbox(adapter); |
| 2129 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2130 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2131 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2132 | OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, |
| 2133 | sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2134 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2135 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2136 | if (!status) { |
| 2137 | struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 2138 | |
Kalesh AP | e97e3cd | 2014-07-17 16:20:26 +0530 | [diff] [blame] | 2139 | 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 Perla | acbafeb | 2014-09-02 09:56:46 +0530 | [diff] [blame] | 2143 | 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 Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2146 | } |
| 2147 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 2148 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 2149 | return status; |
| 2150 | } |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2151 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2152 | /* Uses mbox */ |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2153 | int be_cmd_reset_function(struct be_adapter *adapter) |
| 2154 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2155 | struct be_mcc_wrb *wrb; |
| 2156 | struct be_cmd_req_hdr *req; |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2157 | int status; |
| 2158 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 2159 | if (lancer_chip(adapter)) { |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 2160 | iowrite32(SLI_PORT_CONTROL_IP_MASK, |
| 2161 | adapter->db + SLIPORT_CONTROL_OFFSET); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 2162 | status = lancer_wait_ready(adapter); |
Sathya Perla | 9fa465c | 2015-02-23 04:20:13 -0500 | [diff] [blame] | 2163 | if (status) |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 2164 | dev_err(&adapter->pdev->dev, |
| 2165 | "Adapter in non recoverable error\n"); |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 2166 | return status; |
| 2167 | } |
| 2168 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 2169 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 2170 | return -1; |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2171 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2172 | wrb = wrb_from_mbox(adapter); |
| 2173 | req = embedded_payload(wrb); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2174 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2175 | be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2176 | OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, |
| 2177 | NULL); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2178 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2179 | status = be_mbox_notify_wait(adapter); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2180 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 2181 | mutex_unlock(&adapter->mbox_lock); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 2182 | return status; |
| 2183 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2184 | |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 2185 | int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, |
Ben Hutchings | 33cb0fa | 2014-05-15 02:01:23 +0100 | [diff] [blame] | 2186 | u32 rss_hash_opts, u16 table_size, const u8 *rss_hkey) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2187 | { |
| 2188 | struct be_mcc_wrb *wrb; |
| 2189 | struct be_cmd_req_rss_config *req; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2190 | int status; |
| 2191 | |
Vasundhara Volam | da1388d | 2014-01-06 13:02:23 +0530 | [diff] [blame] | 2192 | if (!(be_if_cap_flags(adapter) & BE_IF_FLAGS_RSS)) |
| 2193 | return 0; |
| 2194 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2195 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2196 | |
Kalesh AP | b51aa36 | 2014-05-09 13:29:19 +0530 | [diff] [blame] | 2197 | wrb = wrb_from_mccq(adapter); |
| 2198 | if (!wrb) { |
| 2199 | status = -EBUSY; |
| 2200 | goto err; |
| 2201 | } |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2202 | req = embedded_payload(wrb); |
| 2203 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2204 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2205 | OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2206 | |
| 2207 | req->if_id = cpu_to_le32(adapter->if_handle); |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 2208 | req->enable_rss = cpu_to_le16(rss_hash_opts); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2209 | req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1); |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 2210 | |
Kalesh AP | b51aa36 | 2014-05-09 13:29:19 +0530 | [diff] [blame] | 2211 | if (!BEx_chip(adapter)) |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 2212 | req->hdr.version = 1; |
| 2213 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2214 | memcpy(req->cpu_table, rsstable, table_size); |
Venkata Duvvuru | e255787 | 2014-04-21 15:38:00 +0530 | [diff] [blame] | 2215 | memcpy(req->hash, rss_hkey, RSS_HASH_KEY_LEN); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2216 | be_dws_cpu_to_le(req->hash, sizeof(req->hash)); |
| 2217 | |
Kalesh AP | b51aa36 | 2014-05-09 13:29:19 +0530 | [diff] [blame] | 2218 | status = be_mcc_notify_wait(adapter); |
| 2219 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2220 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2221 | return status; |
| 2222 | } |
| 2223 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2224 | /* Uses sync mcc */ |
| 2225 | int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2226 | u8 bcn, u8 sts, u8 state) |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2227 | { |
| 2228 | struct be_mcc_wrb *wrb; |
| 2229 | struct be_cmd_req_enable_disable_beacon *req; |
| 2230 | int status; |
| 2231 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2232 | mutex_lock(&adapter->mcc_lock); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2233 | |
| 2234 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2235 | if (!wrb) { |
| 2236 | status = -EBUSY; |
| 2237 | goto err; |
| 2238 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2239 | req = embedded_payload(wrb); |
| 2240 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2241 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2242 | OPCODE_COMMON_ENABLE_DISABLE_BEACON, |
| 2243 | sizeof(*req), wrb, NULL); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2244 | |
| 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 Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2252 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2253 | mutex_unlock(&adapter->mcc_lock); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2254 | return status; |
| 2255 | } |
| 2256 | |
| 2257 | /* Uses sync mcc */ |
| 2258 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2264 | mutex_lock(&adapter->mcc_lock); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2265 | |
| 2266 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2267 | if (!wrb) { |
| 2268 | status = -EBUSY; |
| 2269 | goto err; |
| 2270 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2271 | req = embedded_payload(wrb); |
| 2272 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2273 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2274 | OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), |
| 2275 | wrb, NULL); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2276 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 2283 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2284 | *state = resp->beacon_state; |
| 2285 | } |
| 2286 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2287 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2288 | mutex_unlock(&adapter->mcc_lock); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2289 | return status; |
| 2290 | } |
| 2291 | |
Mark Leonard | e36edd9 | 2014-09-12 17:39:18 +0530 | [diff] [blame] | 2292 | /* Uses sync mcc */ |
| 2293 | int 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 Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 2305 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 2306 | GFP_ATOMIC); |
Mark Leonard | e36edd9 | 2014-09-12 17:39:18 +0530 | [diff] [blame] | 2307 | if (!cmd.va) { |
| 2308 | dev_err(&adapter->pdev->dev, "Memory allocation failed\n"); |
| 2309 | return -ENOMEM; |
| 2310 | } |
Mark Leonard | e36edd9 | 2014-09-12 17:39:18 +0530 | [diff] [blame] | 2311 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2312 | mutex_lock(&adapter->mcc_lock); |
Mark Leonard | e36edd9 | 2014-09-12 17:39:18 +0530 | [diff] [blame] | 2313 | |
| 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 | } |
| 2333 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2334 | mutex_unlock(&adapter->mcc_lock); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 2335 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Mark Leonard | e36edd9 | 2014-09-12 17:39:18 +0530 | [diff] [blame] | 2336 | return status; |
| 2337 | } |
| 2338 | |
Suresh Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2339 | static 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 Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2344 | { |
| 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2351 | mutex_lock(&adapter->mcc_lock); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2352 | 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 Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2362 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2363 | OPCODE_COMMON_WRITE_OBJECT, |
| 2364 | sizeof(struct lancer_cmd_req_write_object), wrb, |
| 2365 | NULL); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2366 | |
| 2367 | ctxt = &req->context; |
| 2368 | AMAP_SET_BITS(struct amap_lancer_write_obj_context, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2369 | write_length, ctxt, data_size); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2370 | |
| 2371 | if (data_size == 0) |
| 2372 | AMAP_SET_BITS(struct amap_lancer_write_obj_context, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2373 | eof, ctxt, 1); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2374 | else |
| 2375 | AMAP_SET_BITS(struct amap_lancer_write_obj_context, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2376 | eof, ctxt, 0); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2377 | |
| 2378 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 2379 | req->write_offset = cpu_to_le32(data_offset); |
Vasundhara Volam | 242eb47 | 2014-09-12 17:39:15 +0530 | [diff] [blame] | 2380 | strlcpy(req->object_name, obj_name, sizeof(req->object_name)); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2381 | 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 Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2384 | sizeof(struct lancer_cmd_req_write_object)) |
| 2385 | & 0xFFFFFFFF); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2386 | req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma + |
| 2387 | sizeof(struct lancer_cmd_req_write_object))); |
| 2388 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 2389 | status = be_mcc_notify(adapter); |
| 2390 | if (status) |
| 2391 | goto err_unlock; |
| 2392 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2393 | mutex_unlock(&adapter->mcc_lock); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2394 | |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 2395 | if (!wait_for_completion_timeout(&adapter->et_cmd_compl, |
Somnath Kotur | 701962d | 2013-05-02 03:36:34 +0000 | [diff] [blame] | 2396 | msecs_to_jiffies(60000))) |
Kalesh AP | fd45160 | 2014-07-17 16:20:21 +0530 | [diff] [blame] | 2397 | status = -ETIMEDOUT; |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2398 | else |
| 2399 | status = adapter->flash_status; |
| 2400 | |
| 2401 | resp = embedded_payload(wrb); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2402 | if (!status) { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2403 | *data_written = le32_to_cpu(resp->actual_write_len); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2404 | *change_status = resp->change_status; |
| 2405 | } else { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2406 | *addn_status = resp->additional_status; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2407 | } |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2408 | |
| 2409 | return status; |
| 2410 | |
| 2411 | err_unlock: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2412 | mutex_unlock(&adapter->mcc_lock); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2413 | return status; |
| 2414 | } |
| 2415 | |
Ravikumar Nelavelli | 6809cee | 2014-09-12 17:39:19 +0530 | [diff] [blame] | 2416 | int 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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 2441 | int 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 Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2459 | static int lancer_cmd_delete_object(struct be_adapter *adapter, |
| 2460 | const char *obj_name) |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 2461 | { |
| 2462 | struct lancer_cmd_req_delete_object *req; |
| 2463 | struct be_mcc_wrb *wrb; |
| 2464 | int status; |
| 2465 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2466 | mutex_lock(&adapter->mcc_lock); |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 2467 | |
| 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 Volam | 242eb47 | 2014-09-12 17:39:15 +0530 | [diff] [blame] | 2480 | strlcpy(req->object_name, obj_name, sizeof(req->object_name)); |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 2481 | |
| 2482 | status = be_mcc_notify_wait(adapter); |
| 2483 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2484 | mutex_unlock(&adapter->mcc_lock); |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 2485 | return status; |
| 2486 | } |
| 2487 | |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 2488 | int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2489 | u32 data_size, u32 data_offset, const char *obj_name, |
| 2490 | u32 *data_read, u32 *eof, u8 *addn_status) |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 2491 | { |
| 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2497 | mutex_lock(&adapter->mcc_lock); |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 2498 | |
| 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 Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2508 | OPCODE_COMMON_READ_OBJECT, |
| 2509 | sizeof(struct lancer_cmd_req_read_object), wrb, |
| 2510 | NULL); |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 2511 | |
| 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 | |
| 2530 | err_unlock: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2531 | mutex_unlock(&adapter->mcc_lock); |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 2532 | return status; |
| 2533 | } |
| 2534 | |
Suresh Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2535 | static 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 Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2538 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2539 | struct be_mcc_wrb *wrb; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2540 | struct be_cmd_write_flashrom *req; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2541 | int status; |
| 2542 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2543 | mutex_lock(&adapter->mcc_lock); |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2544 | adapter->flash_status = 0; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2545 | |
| 2546 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2547 | if (!wrb) { |
| 2548 | status = -EBUSY; |
Dan Carpenter | 2892d9c | 2010-05-26 04:46:35 +0000 | [diff] [blame] | 2549 | goto err_unlock; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2550 | } |
| 2551 | req = cmd->va; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2552 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2553 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 2554 | OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, |
| 2555 | cmd); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2556 | |
| 2557 | req->params.op_type = cpu_to_le32(flash_type); |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 2558 | if (flash_type == OPTYPE_OFFSET_SPECIFIED) |
| 2559 | req->params.offset = cpu_to_le32(img_offset); |
| 2560 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2561 | req->params.op_code = cpu_to_le32(flash_opcode); |
| 2562 | req->params.data_buf_size = cpu_to_le32(buf_size); |
| 2563 | |
Suresh Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 2564 | status = be_mcc_notify(adapter); |
| 2565 | if (status) |
| 2566 | goto err_unlock; |
| 2567 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2568 | mutex_unlock(&adapter->mcc_lock); |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2569 | |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 2570 | if (!wait_for_completion_timeout(&adapter->et_cmd_compl, |
| 2571 | msecs_to_jiffies(40000))) |
Kalesh AP | fd45160 | 2014-07-17 16:20:21 +0530 | [diff] [blame] | 2572 | status = -ETIMEDOUT; |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2573 | else |
| 2574 | status = adapter->flash_status; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2575 | |
Dan Carpenter | 2892d9c | 2010-05-26 04:46:35 +0000 | [diff] [blame] | 2576 | return status; |
| 2577 | |
| 2578 | err_unlock: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2579 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2580 | return status; |
| 2581 | } |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2582 | |
Suresh Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2583 | static int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc, |
| 2584 | u16 img_optype, u32 img_offset, u32 crc_offset) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2585 | { |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 2586 | struct be_cmd_read_flash_crc *req; |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 2587 | struct be_mcc_wrb *wrb; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2588 | int status; |
| 2589 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2590 | mutex_lock(&adapter->mcc_lock); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2591 | |
| 2592 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2593 | if (!wrb) { |
| 2594 | status = -EBUSY; |
| 2595 | goto err; |
| 2596 | } |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2597 | req = embedded_payload(wrb); |
| 2598 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2599 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 2600 | OPCODE_COMMON_READ_FLASHROM, sizeof(*req), |
| 2601 | wrb, NULL); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2602 | |
Vasundhara Volam | 70a7b52 | 2015-02-06 08:18:39 -0500 | [diff] [blame] | 2603 | 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 Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2609 | req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT); |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2610 | req->params.data_buf_size = cpu_to_le32(0x4); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2611 | |
| 2612 | status = be_mcc_notify_wait(adapter); |
| 2613 | if (!status) |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 2614 | memcpy(flashed_crc, req->crc, 4); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2615 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2616 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 2617 | mutex_unlock(&adapter->mcc_lock); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2618 | return status; |
| 2619 | } |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2620 | |
Suresh Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2621 | static char flash_cookie[2][16] = {"*** SE FLAS", "H DIRECTORY *** "}; |
| 2622 | |
| 2623 | static 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 | |
| 2629 | static 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 | |
| 2650 | static 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 | |
| 2667 | static 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 | |
| 2691 | static 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 Basavapatna | f5ef017 | 2016-10-09 09:58:50 +0530 | [diff] [blame] | 2732 | #define NCSI_UPDATE_LOG "NCSI section update is not supported in FW ver %s\n" |
| 2733 | static 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 Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2752 | /* For BE2, BE3 and BE3-R */ |
| 2753 | static 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 Basavapatna | f5ef017 | 2016-10-09 09:58:50 +0530 | [diff] [blame] | 2829 | !be_fw_ncsi_supported(adapter->fw_ver)) { |
| 2830 | dev_info(dev, NCSI_UPDATE_LOG, adapter->fw_ver); |
Suresh Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2831 | continue; |
Sriharsha Basavapatna | f5ef017 | 2016-10-09 09:58:50 +0530 | [diff] [blame] | 2832 | } |
Suresh Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 2833 | |
| 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 | |
| 2872 | static 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 | |
| 2924 | static 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 | |
| 2944 | retry_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 | |
| 3000 | flash: |
| 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 Reddy | 6b52578 | 2015-12-30 01:29:00 -0500 | [diff] [blame] | 3029 | |
| 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 Reddy | a23113b | 2015-12-30 01:28:59 -0500 | [diff] [blame] | 3042 | } |
| 3043 | } |
| 3044 | return 0; |
| 3045 | } |
| 3046 | |
| 3047 | int 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 | */ |
| 3133 | static 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 | |
| 3172 | int 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 Carpenter | c196b02 | 2010-05-26 04:47:39 +0000 | [diff] [blame] | 3216 | int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3217 | struct be_dma_mem *nonemb_cmd) |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3218 | { |
| 3219 | struct be_mcc_wrb *wrb; |
| 3220 | struct be_cmd_req_acpi_wol_magic_config *req; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3221 | int status; |
| 3222 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3223 | mutex_lock(&adapter->mcc_lock); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3224 | |
| 3225 | wrb = wrb_from_mccq(adapter); |
| 3226 | if (!wrb) { |
| 3227 | status = -EBUSY; |
| 3228 | goto err; |
| 3229 | } |
| 3230 | req = nonemb_cmd->va; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3231 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3232 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3233 | OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), |
| 3234 | wrb, nonemb_cmd); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3235 | memcpy(req->magic_mac, mac, ETH_ALEN); |
| 3236 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3237 | status = be_mcc_notify_wait(adapter); |
| 3238 | |
| 3239 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3240 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 3241 | return status; |
| 3242 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3243 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 3244 | int 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 Kotur | 2e365b1 | 2016-02-03 09:49:20 +0530 | [diff] [blame] | 3251 | if (!be_cmd_allowed(adapter, OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, |
| 3252 | CMD_SUBSYSTEM_LOWLEVEL)) |
| 3253 | return -EPERM; |
| 3254 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3255 | mutex_lock(&adapter->mcc_lock); |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 3256 | |
| 3257 | wrb = wrb_from_mccq(adapter); |
| 3258 | if (!wrb) { |
| 3259 | status = -EBUSY; |
Suresh Reddy | 9c85597 | 2015-07-10 05:32:50 -0400 | [diff] [blame] | 3260 | goto err_unlock; |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 3261 | } |
| 3262 | |
| 3263 | req = embedded_payload(wrb); |
| 3264 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3265 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3266 | OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), |
| 3267 | wrb, NULL); |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 3268 | |
| 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 Reddy | 9c85597 | 2015-07-10 05:32:50 -0400 | [diff] [blame] | 3274 | status = be_mcc_notify(adapter); |
| 3275 | if (status) |
| 3276 | goto err_unlock; |
| 3277 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3278 | mutex_unlock(&adapter->mcc_lock); |
Suresh Reddy | 9c85597 | 2015-07-10 05:32:50 -0400 | [diff] [blame] | 3279 | |
| 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 | |
| 3286 | err_unlock: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3287 | mutex_unlock(&adapter->mcc_lock); |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 3288 | return status; |
| 3289 | } |
| 3290 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3291 | int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3292 | u32 loopback_type, u32 pkt_size, u32 num_pkts, |
| 3293 | u64 pattern) |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3294 | { |
| 3295 | struct be_mcc_wrb *wrb; |
| 3296 | struct be_cmd_req_loopback_test *req; |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 3297 | struct be_cmd_resp_loopback_test *resp; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3298 | int status; |
| 3299 | |
Somnath Kotur | 2e365b1 | 2016-02-03 09:49:20 +0530 | [diff] [blame] | 3300 | if (!be_cmd_allowed(adapter, OPCODE_LOWLEVEL_LOOPBACK_TEST, |
| 3301 | CMD_SUBSYSTEM_LOWLEVEL)) |
| 3302 | return -EPERM; |
| 3303 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3304 | mutex_lock(&adapter->mcc_lock); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3305 | |
| 3306 | wrb = wrb_from_mccq(adapter); |
| 3307 | if (!wrb) { |
| 3308 | status = -EBUSY; |
| 3309 | goto err; |
| 3310 | } |
| 3311 | |
| 3312 | req = embedded_payload(wrb); |
| 3313 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3314 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3315 | OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, |
| 3316 | NULL); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3317 | |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 3318 | req->hdr.timeout = cpu_to_le32(15); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3319 | 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 Reddy | efaa408 | 2015-07-10 05:32:48 -0400 | [diff] [blame] | 3326 | status = be_mcc_notify(adapter); |
| 3327 | if (status) |
| 3328 | goto err; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3329 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3330 | mutex_unlock(&adapter->mcc_lock); |
Suresh Reddy | 5eeff63 | 2014-01-06 13:02:24 +0530 | [diff] [blame] | 3331 | |
| 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 R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3337 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3338 | mutex_unlock(&adapter->mcc_lock); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3339 | return status; |
| 3340 | } |
| 3341 | |
| 3342 | int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3343 | u32 byte_cnt, struct be_dma_mem *cmd) |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3344 | { |
| 3345 | struct be_mcc_wrb *wrb; |
| 3346 | struct be_cmd_req_ddrdma_test *req; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3347 | int status; |
| 3348 | int i, j = 0; |
| 3349 | |
Somnath Kotur | 2e365b1 | 2016-02-03 09:49:20 +0530 | [diff] [blame] | 3350 | if (!be_cmd_allowed(adapter, OPCODE_LOWLEVEL_HOST_DDR_DMA, |
| 3351 | CMD_SUBSYSTEM_LOWLEVEL)) |
| 3352 | return -EPERM; |
| 3353 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3354 | mutex_lock(&adapter->mcc_lock); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3355 | |
| 3356 | wrb = wrb_from_mccq(adapter); |
| 3357 | if (!wrb) { |
| 3358 | status = -EBUSY; |
| 3359 | goto err; |
| 3360 | } |
| 3361 | req = cmd->va; |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3362 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3363 | OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, |
| 3364 | cmd); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3365 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 3379 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3380 | resp = cmd->va; |
| 3381 | if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) || |
Kalesh AP | cd3307aa | 2014-09-19 15:47:02 +0530 | [diff] [blame] | 3382 | resp->snd_err) { |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3383 | status = -1; |
| 3384 | } |
| 3385 | } |
| 3386 | |
| 3387 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3388 | mutex_unlock(&adapter->mcc_lock); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 3389 | return status; |
| 3390 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3391 | |
Dan Carpenter | c196b02 | 2010-05-26 04:47:39 +0000 | [diff] [blame] | 3392 | int be_cmd_get_seeprom_data(struct be_adapter *adapter, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3393 | struct be_dma_mem *nonemb_cmd) |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3394 | { |
| 3395 | struct be_mcc_wrb *wrb; |
| 3396 | struct be_cmd_req_seeprom_read *req; |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3397 | int status; |
| 3398 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3399 | mutex_lock(&adapter->mcc_lock); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3400 | |
| 3401 | wrb = wrb_from_mccq(adapter); |
Ajit Khaparde | e45ff01 | 2011-02-04 17:18:28 +0000 | [diff] [blame] | 3402 | if (!wrb) { |
| 3403 | status = -EBUSY; |
| 3404 | goto err; |
| 3405 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3406 | req = nonemb_cmd->va; |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3407 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3408 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3409 | OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb, |
| 3410 | nonemb_cmd); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3411 | |
| 3412 | status = be_mcc_notify_wait(adapter); |
| 3413 | |
Ajit Khaparde | e45ff01 | 2011-02-04 17:18:28 +0000 | [diff] [blame] | 3414 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3415 | mutex_unlock(&adapter->mcc_lock); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 3416 | return status; |
| 3417 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3418 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3419 | int be_cmd_get_phy_info(struct be_adapter *adapter) |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3420 | { |
| 3421 | struct be_mcc_wrb *wrb; |
| 3422 | struct be_cmd_req_get_phy_info *req; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3423 | struct be_dma_mem cmd; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3424 | int status; |
| 3425 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3426 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS, |
| 3427 | CMD_SUBSYSTEM_COMMON)) |
| 3428 | return -EPERM; |
| 3429 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3430 | mutex_lock(&adapter->mcc_lock); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3431 | |
| 3432 | wrb = wrb_from_mccq(adapter); |
| 3433 | if (!wrb) { |
| 3434 | status = -EBUSY; |
| 3435 | goto err; |
| 3436 | } |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3437 | cmd.size = sizeof(struct be_cmd_req_get_phy_info); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3438 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 3439 | GFP_ATOMIC); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3440 | if (!cmd.va) { |
| 3441 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); |
| 3442 | status = -ENOMEM; |
| 3443 | goto err; |
| 3444 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3445 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3446 | req = cmd.va; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3447 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3448 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3449 | OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req), |
| 3450 | wrb, &cmd); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3451 | |
| 3452 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3453 | if (!status) { |
| 3454 | struct be_phy_info *resp_phy_info = |
| 3455 | cmd.va + sizeof(struct be_cmd_req_hdr); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 3456 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3457 | adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type); |
| 3458 | adapter->phy.interface_type = |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3459 | le16_to_cpu(resp_phy_info->interface_type); |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 3460 | 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 Volam | 68cb7e4 | 2013-08-06 09:27:18 +0530 | [diff] [blame] | 3466 | |
| 3467 | if (BE2_chip(adapter)) { |
| 3468 | adapter->phy.fixed_speeds_supported = |
| 3469 | BE_SUPPORTED_SPEED_10GBPS | |
| 3470 | BE_SUPPORTED_SPEED_1GBPS; |
| 3471 | } |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 3472 | } |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3473 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3474 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3475 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 3476 | return status; |
| 3477 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3478 | |
Lad, Prabhakar | bc0ee16 | 2015-02-05 15:24:43 +0000 | [diff] [blame] | 3479 | static int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain) |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3480 | { |
| 3481 | struct be_mcc_wrb *wrb; |
| 3482 | struct be_cmd_req_set_qos *req; |
| 3483 | int status; |
| 3484 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3485 | mutex_lock(&adapter->mcc_lock); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3486 | |
| 3487 | wrb = wrb_from_mccq(adapter); |
| 3488 | if (!wrb) { |
| 3489 | status = -EBUSY; |
| 3490 | goto err; |
| 3491 | } |
| 3492 | |
| 3493 | req = embedded_payload(wrb); |
| 3494 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3495 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3496 | OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3497 | |
| 3498 | req->hdr.domain = domain; |
Ajit Khaparde | 6bff57a | 2011-02-11 13:33:02 +0000 | [diff] [blame] | 3499 | req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC); |
| 3500 | req->max_bps_nic = cpu_to_le32(bps); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3501 | |
| 3502 | status = be_mcc_notify_wait(adapter); |
| 3503 | |
| 3504 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3505 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 3506 | return status; |
| 3507 | } |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3508 | |
| 3509 | int 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 Basavapatna | a155a5d | 2015-07-22 11:15:12 +0530 | [diff] [blame] | 3514 | int status, i; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3515 | int payload_len = max(sizeof(*req), sizeof(*resp)); |
| 3516 | struct mgmt_controller_attrib *attribs; |
| 3517 | struct be_dma_mem attribs_cmd; |
Sriharsha Basavapatna | a155a5d | 2015-07-22 11:15:12 +0530 | [diff] [blame] | 3518 | u32 *serial_num; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3519 | |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3520 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 3521 | return -1; |
| 3522 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3523 | memset(&attribs_cmd, 0, sizeof(struct be_dma_mem)); |
| 3524 | attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3525 | attribs_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, |
| 3526 | attribs_cmd.size, |
| 3527 | &attribs_cmd.dma, GFP_ATOMIC); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3528 | if (!attribs_cmd.va) { |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3529 | dev_err(&adapter->pdev->dev, "Memory allocation failure\n"); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3530 | status = -ENOMEM; |
| 3531 | goto err; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3532 | } |
| 3533 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3534 | wrb = wrb_from_mbox(adapter); |
| 3535 | if (!wrb) { |
| 3536 | status = -EBUSY; |
| 3537 | goto err; |
| 3538 | } |
| 3539 | req = attribs_cmd.va; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3540 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3541 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3542 | OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, |
| 3543 | wrb, &attribs_cmd); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3544 | |
| 3545 | status = be_mbox_notify_wait(adapter); |
| 3546 | if (!status) { |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 3547 | attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3548 | adapter->hba_port_num = attribs->hba_attribs.phy_port; |
Sriharsha Basavapatna | a155a5d | 2015-07-22 11:15:12 +0530 | [diff] [blame] | 3549 | 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 Basavapatna | 6ee080b | 2016-10-09 09:58:49 +0530 | [diff] [blame] | 3553 | /* 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 Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3558 | } |
| 3559 | |
| 3560 | err: |
| 3561 | mutex_unlock(&adapter->mbox_lock); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3562 | if (attribs_cmd.va) |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3563 | dma_free_coherent(&adapter->pdev->dev, attribs_cmd.size, |
| 3564 | attribs_cmd.va, attribs_cmd.dma); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 3565 | return status; |
| 3566 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3567 | |
| 3568 | /* Uses mbox */ |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 3569 | int be_cmd_req_native_mode(struct be_adapter *adapter) |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3570 | { |
| 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 Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 3586 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3587 | OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, |
| 3588 | sizeof(*req), wrb, NULL); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3589 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 3597 | |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3598 | adapter->be3_native = le32_to_cpu(resp->cap_flags) & |
| 3599 | CAPABILITY_BE3_NATIVE_ERX_API; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 3600 | if (!adapter->be3_native) |
| 3601 | dev_warn(&adapter->pdev->dev, |
| 3602 | "adapter not in advanced mode\n"); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 3603 | } |
| 3604 | err: |
| 3605 | mutex_unlock(&adapter->mbox_lock); |
| 3606 | return status; |
| 3607 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3608 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3609 | /* Get privilege(s) for a function */ |
| 3610 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3617 | mutex_lock(&adapter->mcc_lock); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3618 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 3637 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3638 | *privilege = le32_to_cpu(resp->privilege_mask); |
Suresh Reddy | 02308d7 | 2014-01-15 13:23:36 +0530 | [diff] [blame] | 3639 | |
| 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 Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3646 | } |
| 3647 | |
| 3648 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3649 | mutex_unlock(&adapter->mcc_lock); |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 3650 | return status; |
| 3651 | } |
| 3652 | |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3653 | /* Set privilege(s) for a function */ |
| 3654 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3661 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3662 | |
| 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); |
| 3680 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3681 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 3682 | return status; |
| 3683 | } |
| 3684 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3685 | /* 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 Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 3689 | int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3690 | bool *pmac_id_valid, u32 *pmac_id, u32 if_handle, |
| 3691 | u8 domain) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3692 | { |
| 3693 | struct be_mcc_wrb *wrb; |
| 3694 | struct be_cmd_req_get_mac_list *req; |
| 3695 | int status; |
| 3696 | int mac_count; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3697 | 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 Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3702 | 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 Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3706 | |
| 3707 | if (!get_mac_list_cmd.va) { |
| 3708 | dev_err(&adapter->pdev->dev, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3709 | "Memory allocation failure during GET_MAC_LIST\n"); |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3710 | return -ENOMEM; |
| 3711 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3712 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3713 | mutex_lock(&adapter->mcc_lock); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3714 | |
| 3715 | wrb = wrb_from_mccq(adapter); |
| 3716 | if (!wrb) { |
| 3717 | status = -EBUSY; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3718 | goto out; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3719 | } |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3720 | |
| 3721 | req = get_mac_list_cmd.va; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3722 | |
| 3723 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | bf591f5 | 2013-05-08 02:05:48 +0000 | [diff] [blame] | 3724 | OPCODE_COMMON_GET_MAC_LIST, |
| 3725 | get_mac_list_cmd.size, wrb, &get_mac_list_cmd); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3726 | req->hdr.domain = domain; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3727 | req->mac_type = MAC_ADDRESS_TYPE_NETWORK; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3728 | if (*pmac_id_valid) { |
| 3729 | req->mac_id = cpu_to_le32(*pmac_id); |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3730 | req->iface_id = cpu_to_le16(if_handle); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3731 | req->perm_override = 0; |
| 3732 | } else { |
| 3733 | req->perm_override = 1; |
| 3734 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3735 | |
| 3736 | status = be_mcc_notify_wait(adapter); |
| 3737 | if (!status) { |
| 3738 | struct be_cmd_resp_get_mac_list *resp = |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3739 | get_mac_list_cmd.va; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3740 | |
| 3741 | if (*pmac_id_valid) { |
| 3742 | memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr, |
| 3743 | ETH_ALEN); |
| 3744 | goto out; |
| 3745 | } |
| 3746 | |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3747 | mac_count = resp->true_mac_count + resp->pseudo_mac_count; |
| 3748 | /* Mac list returned could contain one or more active mac_ids |
Joe Perches | dbedd44 | 2015-03-06 20:49:12 -0800 | [diff] [blame] | 3749 | * or one or more true or pseudo permanent mac addresses. |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 3750 | * If an active mac_id is present, return first active mac_id |
| 3751 | * found. |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3752 | */ |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3753 | for (i = 0; i < mac_count; i++) { |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3754 | 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 Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3764 | *pmac_id_valid = true; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3765 | mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id; |
| 3766 | *pmac_id = le32_to_cpu(mac_id); |
| 3767 | goto out; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3768 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3769 | } |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 3770 | /* If no active mac_id found, return first mac addr */ |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3771 | *pmac_id_valid = false; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3772 | memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3773 | ETH_ALEN); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 3776 | out: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3777 | mutex_unlock(&adapter->mcc_lock); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3778 | dma_free_coherent(&adapter->pdev->dev, get_mac_list_cmd.size, |
| 3779 | get_mac_list_cmd.va, get_mac_list_cmd.dma); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3780 | return status; |
| 3781 | } |
| 3782 | |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3783 | int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id, |
| 3784 | u8 *mac, u32 if_handle, bool active, u32 domain) |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3785 | { |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3786 | if (!active) |
| 3787 | be_cmd_get_mac_from_list(adapter, mac, &active, &curr_pmac_id, |
| 3788 | if_handle, domain); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3789 | if (BEx_chip(adapter)) |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3790 | return be_cmd_mac_addr_query(adapter, mac, false, |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3791 | if_handle, curr_pmac_id); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3792 | else |
| 3793 | /* Fetch the MAC address using pmac_id */ |
| 3794 | return be_cmd_get_mac_from_list(adapter, mac, &active, |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3795 | &curr_pmac_id, |
| 3796 | if_handle, domain); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 3797 | } |
| 3798 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3799 | int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac) |
| 3800 | { |
| 3801 | int status; |
| 3802 | bool pmac_valid = false; |
| 3803 | |
Joe Perches | c7bf716 | 2015-03-02 19:54:47 -0800 | [diff] [blame] | 3804 | eth_zero_addr(mac); |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3805 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3806 | 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 Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3814 | status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid, |
Suresh Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3815 | NULL, adapter->if_handle, 0); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3816 | } |
| 3817 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 3818 | return status; |
| 3819 | } |
| 3820 | |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3821 | /* Uses synchronous MCCQ */ |
| 3822 | int 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 Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 3832 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 3833 | GFP_KERNEL); |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 3834 | if (!cmd.va) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3835 | return -ENOMEM; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3836 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3837 | mutex_lock(&adapter->mcc_lock); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3838 | |
| 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 Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3847 | OPCODE_COMMON_SET_MAC_LIST, sizeof(*req), |
| 3848 | wrb, &cmd); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3849 | |
| 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 | |
| 3857 | err: |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3858 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, cmd.dma); |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3859 | mutex_unlock(&adapter->mcc_lock); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 3860 | return status; |
| 3861 | } |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 3862 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3863 | /* 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 | */ |
| 3867 | int 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 Reddy | b188f09 | 2014-01-15 13:23:39 +0530 | [diff] [blame] | 3875 | &pmac_id, if_id, dom); |
| 3876 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 3877 | 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 Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3883 | int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 3884 | u32 domain, u16 intf_id, u16 hsw_mode, u8 spoofchk) |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3885 | { |
| 3886 | struct be_mcc_wrb *wrb; |
| 3887 | struct be_cmd_req_set_hsw_config *req; |
| 3888 | void *ctxt; |
| 3889 | int status; |
| 3890 | |
Somnath Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 3891 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_HSW_CONFIG, |
| 3892 | CMD_SUBSYSTEM_COMMON)) |
| 3893 | return -EPERM; |
| 3894 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3895 | mutex_lock(&adapter->mcc_lock); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3896 | |
| 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 Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3907 | OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, |
| 3908 | NULL); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3909 | |
| 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 Kotur | 884476b | 2016-06-22 08:54:55 -0400 | [diff] [blame] | 3916 | if (hsw_mode) { |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 3917 | 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 Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3923 | |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 3924 | /* 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 Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3932 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 3933 | status = be_mcc_notify_wait(adapter); |
| 3934 | |
| 3935 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3936 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3937 | return status; |
| 3938 | } |
| 3939 | |
| 3940 | /* Get Hyper switch config */ |
| 3941 | int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid, |
Kalesh AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 3942 | u32 domain, u16 intf_id, u8 *mode, bool *spoofchk) |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3943 | { |
| 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3950 | mutex_lock(&adapter->mcc_lock); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3951 | |
| 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 Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3962 | OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, |
| 3963 | NULL); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3964 | |
| 3965 | req->hdr.domain = domain; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 3966 | AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, |
| 3967 | ctxt, intf_id); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3968 | AMAP_SET_BITS(struct amap_get_hsw_req_context, pvid_valid, ctxt, 1); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 3969 | |
Vasundhara Volam | 2c07c1d | 2014-01-15 13:23:32 +0530 | [diff] [blame] | 3970 | if (!BEx_chip(adapter) && mode) { |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 3971 | 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 Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3975 | 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 3981 | |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3982 | be_dws_le_to_cpu(&resp->context, sizeof(resp->context)); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3983 | vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 3984 | pvid, &resp->context); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame] | 3985 | 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 AP | e7bcbd7 | 2015-05-06 05:30:32 -0400 | [diff] [blame] | 3990 | if (spoofchk) |
| 3991 | *spoofchk = |
| 3992 | AMAP_GET_BITS(struct amap_get_hsw_resp_context, |
| 3993 | spoofchk, &resp->context); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3994 | } |
| 3995 | |
| 3996 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 3997 | mutex_unlock(&adapter->mcc_lock); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 3998 | return status; |
| 3999 | } |
| 4000 | |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 4001 | static bool be_is_wol_excluded(struct be_adapter *adapter) |
| 4002 | { |
| 4003 | struct pci_dev *pdev = adapter->pdev; |
| 4004 | |
Kalesh AP | 18c57c7 | 2015-05-06 05:30:38 -0400 | [diff] [blame] | 4005 | if (be_virtfn(adapter)) |
Sathya Perla | f7062ee | 2015-02-06 08:18:35 -0500 | [diff] [blame] | 4006 | 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 Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4019 | int 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 Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 4023 | int status = 0; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4024 | struct be_dma_mem cmd; |
| 4025 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 4026 | if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, |
| 4027 | CMD_SUBSYSTEM_ETH)) |
| 4028 | return -EPERM; |
| 4029 | |
Suresh Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 4030 | if (be_is_wol_excluded(adapter)) |
| 4031 | return status; |
| 4032 | |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 4033 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 4034 | return -1; |
| 4035 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4036 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
| 4037 | cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4038 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 4039 | GFP_ATOMIC); |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4040 | if (!cmd.va) { |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 4041 | dev_err(&adapter->pdev->dev, "Memory allocation failure\n"); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 4042 | status = -ENOMEM; |
| 4043 | goto err; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4044 | } |
| 4045 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4046 | 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 Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 4056 | sizeof(*req), wrb, &cmd); |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4057 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 4064 | |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 4065 | resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *)cmd.va; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4066 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4067 | adapter->wol_cap = resp->wol_settings; |
Sriharsha Basavapatna | 45f13df | 2016-06-06 07:22:09 -0400 | [diff] [blame] | 4068 | |
| 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 Reddy | 76a9e08 | 2014-01-15 13:23:40 +0530 | [diff] [blame] | 4072 | adapter->wol_en = true; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4073 | } |
| 4074 | err: |
| 4075 | mutex_unlock(&adapter->mbox_lock); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 4076 | if (cmd.va) |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4077 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 4078 | cmd.dma); |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4079 | return status; |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4080 | |
| 4081 | } |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4082 | |
| 4083 | int 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 Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4092 | extfat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, |
| 4093 | extfat_cmd.size, &extfat_cmd.dma, |
| 4094 | GFP_ATOMIC); |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4095 | 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 4106 | |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4107 | 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); |
| 4115 | err: |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4116 | dma_free_coherent(&adapter->pdev->dev, extfat_cmd.size, extfat_cmd.va, |
| 4117 | extfat_cmd.dma); |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4118 | return status; |
| 4119 | } |
| 4120 | |
| 4121 | int 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 Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4130 | extfat_cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, |
| 4131 | extfat_cmd.size, &extfat_cmd.dma, |
| 4132 | GFP_ATOMIC); |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4133 | |
| 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 4144 | |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4145 | 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 Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4150 | dma_free_coherent(&adapter->pdev->dev, extfat_cmd.size, extfat_cmd.va, |
| 4151 | extfat_cmd.dma); |
Vasundhara Volam | baaa08d | 2014-01-15 13:23:34 +0530 | [diff] [blame] | 4152 | err: |
| 4153 | return level; |
| 4154 | } |
| 4155 | |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4156 | int 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 Kotur | 62259ac | 2016-09-07 19:57:51 +0530 | [diff] [blame] | 4163 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES, |
| 4164 | CMD_SUBSYSTEM_COMMON)) |
| 4165 | return -EPERM; |
| 4166 | |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4167 | 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 Kotur | 62259ac | 2016-09-07 19:57:51 +0530 | [diff] [blame] | 4178 | OPCODE_COMMON_GET_EXT_FAT_CAPABILITIES, |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4179 | cmd->size, wrb, cmd); |
| 4180 | req->parameter_type = cpu_to_le32(1); |
| 4181 | |
| 4182 | status = be_mbox_notify_wait(adapter); |
| 4183 | err: |
| 4184 | mutex_unlock(&adapter->mbox_lock); |
| 4185 | return status; |
| 4186 | } |
| 4187 | |
| 4188 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4196 | mutex_lock(&adapter->mcc_lock); |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4197 | |
| 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 Kotur | 62259ac | 2016-09-07 19:57:51 +0530 | [diff] [blame] | 4207 | OPCODE_COMMON_SET_EXT_FAT_CAPABILITIES, |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4208 | cmd->size, wrb, cmd); |
| 4209 | |
| 4210 | status = be_mcc_notify_wait(adapter); |
| 4211 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4212 | mutex_unlock(&adapter->mcc_lock); |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 4213 | return status; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 4214 | } |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 4215 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4216 | int be_cmd_query_port_name(struct be_adapter *adapter) |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4217 | { |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4218 | struct be_cmd_req_get_port_name *req; |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4219 | struct be_mcc_wrb *wrb; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4220 | int status; |
| 4221 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4222 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 4223 | return -1; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4224 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4225 | wrb = wrb_from_mbox(adapter); |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4226 | 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 Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4231 | if (!BEx_chip(adapter)) |
| 4232 | req->hdr.version = 1; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4233 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4234 | status = be_mbox_notify_wait(adapter); |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4235 | if (!status) { |
| 4236 | struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb); |
Kalesh AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 4237 | |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4238 | adapter->port_name = resp->port_name[adapter->hba_port_num]; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4239 | } else { |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4240 | adapter->port_name = adapter->hba_port_num + '0'; |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4241 | } |
Vasundhara Volam | 2125237 | 2015-02-06 08:18:42 -0500 | [diff] [blame] | 4242 | |
| 4243 | mutex_unlock(&adapter->mbox_lock); |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 4244 | return status; |
| 4245 | } |
| 4246 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4247 | /* 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 Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4255 | static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count, |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4256 | bool get_vft, u8 pf_num) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4257 | { |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4258 | struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf; |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4259 | struct be_nic_res_desc *nic; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4260 | int i; |
| 4261 | |
| 4262 | for (i = 0; i < desc_count; i++) { |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4263 | if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 || |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4264 | hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) { |
| 4265 | nic = (struct be_nic_res_desc *)hdr; |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4266 | |
| 4267 | if ((pf_num == PF_NUM_IGNORE || |
| 4268 | nic->pf_num == pf_num) && |
| 4269 | (!get_vft || nic->flags & BIT(VFT_SHIFT))) |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4270 | return nic; |
| 4271 | } |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4272 | hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0; |
| 4273 | hdr = (void *)hdr + hdr->desc_len; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4274 | } |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4275 | return NULL; |
| 4276 | } |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4277 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4278 | static struct be_nic_res_desc *be_get_vft_desc(u8 *buf, u32 desc_count, |
| 4279 | u8 pf_num) |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4280 | { |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4281 | return be_get_nic_desc(buf, desc_count, true, pf_num); |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4282 | } |
| 4283 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4284 | static struct be_nic_res_desc *be_get_func_nic_desc(u8 *buf, u32 desc_count, |
| 4285 | u8 pf_num) |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4286 | { |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4287 | return be_get_nic_desc(buf, desc_count, false, pf_num); |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4288 | } |
| 4289 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4290 | static struct be_pcie_res_desc *be_get_pcie_desc(u8 *buf, u32 desc_count, |
| 4291 | u8 pf_num) |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4292 | { |
| 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 Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4298 | 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 Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4302 | return pcie; |
| 4303 | } |
| 4304 | |
| 4305 | hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0; |
| 4306 | hdr = (void *)hdr + hdr->desc_len; |
| 4307 | } |
Wei Yang | 950e295 | 2013-05-22 15:58:22 +0000 | [diff] [blame] | 4308 | return NULL; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4309 | } |
| 4310 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4311 | static 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 Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4326 | static 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 Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4336 | 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 Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4339 | /* 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 Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4342 | } |
| 4343 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4344 | /* Uses Mbox */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4345 | int be_cmd_get_func_config(struct be_adapter *adapter, struct be_resources *res) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4346 | { |
| 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 Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 4352 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 4353 | return -1; |
| 4354 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4355 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
| 4356 | cmd.size = sizeof(struct be_cmd_resp_get_func_config); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4357 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 4358 | GFP_ATOMIC); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4359 | if (!cmd.va) { |
| 4360 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 4361 | status = -ENOMEM; |
| 4362 | goto err; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4363 | } |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4364 | |
| 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 AP | 28710c5 | 2013-04-28 22:21:13 +0000 | [diff] [blame] | 4377 | if (skyhawk_chip(adapter)) |
| 4378 | req->hdr.version = 1; |
| 4379 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4380 | 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 Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4384 | struct be_nic_res_desc *desc; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4385 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4386 | /* 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 Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4392 | if (!desc) { |
| 4393 | status = -EINVAL; |
| 4394 | goto err; |
| 4395 | } |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4396 | |
| 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 Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4403 | } |
| 4404 | err: |
| 4405 | mutex_unlock(&adapter->mbox_lock); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 4406 | if (cmd.va) |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4407 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 4408 | cmd.dma); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4409 | return status; |
| 4410 | } |
| 4411 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4412 | /* This routine returns a list of all the NIC PF_nums in the adapter */ |
Baoyou Xie | d766e7e | 2016-09-18 16:35:29 +0800 | [diff] [blame] | 4413 | static u16 be_get_nic_pf_num_list(u8 *buf, u32 desc_count, u16 *nic_pf_nums) |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4414 | { |
| 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 Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4436 | /* Will use MBOX only if MCCQ has not been created */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4437 | int be_cmd_get_profile_config(struct be_adapter *adapter, |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4438 | struct be_resources *res, |
| 4439 | struct be_port_resources *port_res, |
| 4440 | u8 profile_type, u8 query, u8 domain) |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 4441 | { |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4442 | struct be_cmd_resp_get_profile_config *resp; |
Vasundhara Volam | ba48c0c | 2014-06-30 13:01:30 +0530 | [diff] [blame] | 4443 | struct be_cmd_req_get_profile_config *req; |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4444 | struct be_nic_res_desc *vf_res; |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4445 | struct be_pcie_res_desc *pcie; |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4446 | struct be_port_res_desc *port; |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4447 | struct be_nic_res_desc *nic; |
Vasundhara Volam | ba48c0c | 2014-06-30 13:01:30 +0530 | [diff] [blame] | 4448 | struct be_mcc_wrb wrb = {0}; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 4449 | struct be_dma_mem cmd; |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4450 | u16 desc_count; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 4451 | int status; |
| 4452 | |
| 4453 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4454 | cmd.size = sizeof(struct be_cmd_resp_get_profile_config); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4455 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 4456 | GFP_ATOMIC); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4457 | if (!cmd.va) |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 4458 | return -ENOMEM; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 4459 | |
Vasundhara Volam | ba48c0c | 2014-06-30 13:01:30 +0530 | [diff] [blame] | 4460 | 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 Volam | ba48c0c | 2014-06-30 13:01:30 +0530 | [diff] [blame] | 4465 | if (!lancer_chip(adapter)) |
| 4466 | req->hdr.version = 1; |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4467 | req->type = profile_type; |
Somnath Kotur | 72ef3a8 | 2015-10-12 03:47:20 -0400 | [diff] [blame] | 4468 | req->hdr.domain = domain; |
Vasundhara Volam | ba48c0c | 2014-06-30 13:01:30 +0530 | [diff] [blame] | 4469 | |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4470 | /* 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 Volam | ba48c0c | 2014-06-30 13:01:30 +0530 | [diff] [blame] | 4477 | status = be_cmd_notify_wait(adapter, &wrb); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4478 | if (status) |
| 4479 | goto err; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4480 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4481 | resp = cmd.va; |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4482 | desc_count = le16_to_cpu(resp->desc_count); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4483 | |
Somnath Kotur | de2b1e0 | 2016-06-06 07:22:10 -0400 | [diff] [blame] | 4484 | 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 Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4506 | pcie = be_get_pcie_desc(resp->func_param, desc_count, |
| 4507 | adapter->pf_num); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4508 | if (pcie) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4509 | res->max_vfs = le16_to_cpu(pcie->num_vfs); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 4510 | |
Vasundhara Volam | f93f160 | 2014-02-12 16:09:25 +0530 | [diff] [blame] | 4511 | port = be_get_port_desc(resp->func_param, desc_count); |
| 4512 | if (port) |
| 4513 | adapter->mc_type = port->mc_type; |
| 4514 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4515 | nic = be_get_func_nic_desc(resp->func_param, desc_count, |
| 4516 | adapter->pf_num); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 4517 | if (nic) |
| 4518 | be_copy_nic_desc(res, nic); |
| 4519 | |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4520 | vf_res = be_get_vft_desc(resp->func_param, desc_count, |
| 4521 | adapter->pf_num); |
Vasundhara Volam | 10cccf6 | 2014-06-30 13:01:31 +0530 | [diff] [blame] | 4522 | if (vf_res) |
| 4523 | res->vf_if_cap_flags = vf_res->cap_flags; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4524 | err: |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 4525 | if (cmd.va) |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4526 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 4527 | cmd.dma); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 4528 | return status; |
| 4529 | } |
| 4530 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4531 | /* Will use MBOX only if MCCQ has not been created */ |
| 4532 | static int be_cmd_set_profile_config(struct be_adapter *adapter, void *desc, |
| 4533 | int size, int count, u8 version, u8 domain) |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4534 | { |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4535 | struct be_cmd_req_set_profile_config *req; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4536 | struct be_mcc_wrb wrb = {0}; |
| 4537 | struct be_dma_mem cmd; |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4538 | int status; |
| 4539 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4540 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
| 4541 | cmd.size = sizeof(struct be_cmd_req_set_profile_config); |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4542 | cmd.va = dma_zalloc_coherent(&adapter->pdev->dev, cmd.size, &cmd.dma, |
| 4543 | GFP_ATOMIC); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4544 | if (!cmd.va) |
| 4545 | return -ENOMEM; |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4546 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4547 | req = cmd.va; |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4548 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4549 | OPCODE_COMMON_SET_PROFILE_CONFIG, cmd.size, |
| 4550 | &wrb, &cmd); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4551 | req->hdr.version = version; |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4552 | req->hdr.domain = domain; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4553 | req->desc_count = cpu_to_le32(count); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4554 | memcpy(req->desc, desc, size); |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4555 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4556 | status = be_cmd_notify_wait(adapter, &wrb); |
| 4557 | |
| 4558 | if (cmd.va) |
Sriharsha Basavapatna | e51000db | 2015-06-05 15:33:59 +0530 | [diff] [blame] | 4559 | dma_free_coherent(&adapter->pdev->dev, cmd.size, cmd.va, |
| 4560 | cmd.dma); |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 4561 | return status; |
| 4562 | } |
| 4563 | |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4564 | /* Mark all fields invalid */ |
Baoyou Xie | d766e7e | 2016-09-18 16:35:29 +0800 | [diff] [blame] | 4565 | static void be_reset_nic_desc(struct be_nic_res_desc *nic) |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4566 | { |
| 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 Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4579 | nic->iface_count = 0xFFFF; |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4580 | nic->link_param = 0xFF; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4581 | nic->channel_id_param = cpu_to_le16(0xF000); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4582 | nic->acpi_params = 0xFF; |
| 4583 | nic->wol_param = 0x0F; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4584 | nic->tunnel_iface_count = 0xFFFF; |
| 4585 | nic->direct_tenant_iface_count = 0xFFFF; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4586 | nic->bw_min = 0xFFFFFFFF; |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4587 | nic->bw_max = 0xFFFFFFFF; |
| 4588 | } |
| 4589 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4590 | /* Mark all fields invalid */ |
| 4591 | static 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 Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4600 | int be_cmd_config_qos(struct be_adapter *adapter, u32 max_rate, u16 link_speed, |
| 4601 | u8 domain) |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4602 | { |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4603 | struct be_nic_res_desc nic_desc; |
| 4604 | u32 bw_percent; |
| 4605 | u16 version = 0; |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4606 | |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4607 | if (BE3_chip(adapter)) |
| 4608 | return be_cmd_set_qos(adapter, max_rate / 10, domain); |
| 4609 | |
| 4610 | be_reset_nic_desc(&nic_desc); |
Suresh Reddy | 980df24 | 2015-12-30 01:29:03 -0500 | [diff] [blame] | 4611 | nic_desc.pf_num = adapter->pf_num; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4612 | nic_desc.vf_num = domain; |
Kalesh AP | 58bdeaa | 2015-01-20 03:51:49 -0500 | [diff] [blame] | 4613 | nic_desc.bw_min = 0; |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4614 | if (lancer_chip(adapter)) { |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4615 | 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 Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4619 | nic_desc.bw_max = cpu_to_le32(max_rate / 10); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4620 | } else { |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4621 | 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 Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4627 | } |
Ravikumar Nelavelli | 0f77ba7 | 2014-05-30 19:06:24 +0530 | [diff] [blame] | 4628 | |
| 4629 | return be_cmd_set_profile_config(adapter, &nic_desc, |
| 4630 | nic_desc.hdr.desc_len, |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4631 | 1, version, domain); |
| 4632 | } |
| 4633 | |
| 4634 | int be_cmd_set_sriov_config(struct be_adapter *adapter, |
Vasundhara Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4635 | struct be_resources pool_res, u16 num_vfs, |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4636 | struct be_resources *vft_res) |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4637 | { |
| 4638 | struct { |
| 4639 | struct be_pcie_res_desc pcie; |
| 4640 | struct be_nic_res_desc nic_vft; |
| 4641 | } __packed desc; |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4642 | |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4643 | /* 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 Volam | f285873 | 2015-03-04 00:44:33 -0500 | [diff] [blame] | 4647 | desc.pcie.flags = BIT(IMM_SHIFT) | BIT(NOSV_SHIFT); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4648 | 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 Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4656 | desc.nic_vft.flags = vft_res->flags | BIT(VFT_SHIFT) | |
| 4657 | BIT(IMM_SHIFT) | BIT(NOSV_SHIFT); |
Vasundhara Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4658 | desc.nic_vft.pf_num = adapter->pdev->devfn; |
| 4659 | desc.nic_vft.vf_num = 0; |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4660 | 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 Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4665 | |
Suresh Reddy | b9263cb | 2016-06-06 07:22:08 -0400 | [diff] [blame] | 4666 | 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 Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4676 | |
| 4677 | return be_cmd_set_profile_config(adapter, &desc, |
| 4678 | 2 * RESOURCE_DESC_SIZE_V1, 2, 1, 0); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4679 | } |
| 4680 | |
| 4681 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4690 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4691 | |
| 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); |
| 4706 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4707 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4708 | return status; |
| 4709 | } |
| 4710 | |
| 4711 | int 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 Volam | bec84e6 | 2014-06-30 13:01:32 +0530 | [diff] [blame] | 4730 | RESOURCE_DESC_SIZE_V1, 1, 1, 0); |
Sathya Perla | a401801 | 2014-03-27 10:46:18 +0530 | [diff] [blame] | 4731 | } |
| 4732 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4733 | int 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 Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4741 | mutex_lock(&adapter->mcc_lock); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4742 | |
| 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 | |
| 4761 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4762 | mutex_unlock(&adapter->mcc_lock); |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 4763 | return status; |
| 4764 | } |
| 4765 | |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4766 | static 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 | |
| 4786 | int 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 */ |
| 4800 | bool 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 | |
| 4808 | int lancer_initiate_dump(struct be_adapter *adapter) |
| 4809 | { |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 4810 | struct device *dev = &adapter->pdev->dev; |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4811 | int status; |
| 4812 | |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 4813 | if (dump_present(adapter)) { |
| 4814 | dev_info(dev, "Previous dump not cleared, not forcing dump\n"); |
| 4815 | return -EEXIST; |
| 4816 | } |
| 4817 | |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4818 | /* 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 AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 4822 | dev_err(dev, "FW reset failed\n"); |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4823 | return status; |
| 4824 | } |
| 4825 | |
| 4826 | status = lancer_wait_idle(adapter); |
| 4827 | if (status) |
| 4828 | return status; |
| 4829 | |
| 4830 | if (!dump_present(adapter)) { |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 4831 | dev_err(dev, "FW dump not generated\n"); |
| 4832 | return -EIO; |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 4833 | } |
| 4834 | |
| 4835 | return 0; |
| 4836 | } |
| 4837 | |
Kalesh AP | f061338 | 2014-08-01 17:47:32 +0530 | [diff] [blame] | 4838 | int 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 Ratnakar | dcf7ebb | 2012-10-20 06:03:49 +0000 | [diff] [blame] | 4846 | /* Uses sync mcc */ |
| 4847 | int 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 Volam | 0599863 | 2013-10-01 15:59:59 +0530 | [diff] [blame] | 4853 | if (BEx_chip(adapter)) |
Padmanabh Ratnakar | dcf7ebb | 2012-10-20 06:03:49 +0000 | [diff] [blame] | 4854 | return 0; |
| 4855 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4856 | mutex_lock(&adapter->mcc_lock); |
Padmanabh Ratnakar | dcf7ebb | 2012-10-20 06:03:49 +0000 | [diff] [blame] | 4857 | |
| 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); |
| 4873 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4874 | mutex_unlock(&adapter->mcc_lock); |
Padmanabh Ratnakar | dcf7ebb | 2012-10-20 06:03:49 +0000 | [diff] [blame] | 4875 | return status; |
| 4876 | } |
| 4877 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 4878 | int 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 Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 4903 | /* Uses MBOX */ |
| 4904 | int 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 AP | 03d28ff | 2014-09-19 15:46:56 +0530 | [diff] [blame] | 4929 | |
Vasundhara Volam | 542963b | 2014-01-15 13:23:33 +0530 | [diff] [blame] | 4930 | *profile_id = le16_to_cpu(resp->active_profile_id); |
| 4931 | } |
| 4932 | |
| 4933 | err: |
| 4934 | mutex_unlock(&adapter->mbox_lock); |
| 4935 | return status; |
| 4936 | } |
| 4937 | |
Baoyou Xie | d766e7e | 2016-09-18 16:35:29 +0800 | [diff] [blame] | 4938 | static int |
| 4939 | __be_cmd_set_logical_link_config(struct be_adapter *adapter, |
| 4940 | int link_state, int version, u8 domain) |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4941 | { |
| 4942 | struct be_mcc_wrb *wrb; |
| 4943 | struct be_cmd_req_set_ll_link *req; |
| 4944 | int status; |
| 4945 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4946 | mutex_lock(&adapter->mcc_lock); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4947 | |
| 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 Reddy | d9d426a | 2015-12-30 01:28:56 -0500 | [diff] [blame] | 4960 | req->hdr.version = version; |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4961 | req->hdr.domain = domain; |
| 4962 | |
Suresh Reddy | d9d426a | 2015-12-30 01:28:56 -0500 | [diff] [blame] | 4963 | if (link_state == IFLA_VF_LINK_STATE_ENABLE || |
| 4964 | link_state == IFLA_VF_LINK_STATE_AUTO) |
| 4965 | req->link_config |= PLINK_ENABLE; |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4966 | |
| 4967 | if (link_state == IFLA_VF_LINK_STATE_AUTO) |
Suresh Reddy | d9d426a | 2015-12-30 01:28:56 -0500 | [diff] [blame] | 4968 | req->link_config |= PLINK_TRACK; |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4969 | |
| 4970 | status = be_mcc_notify_wait(adapter); |
| 4971 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 4972 | mutex_unlock(&adapter->mcc_lock); |
Suresh Reddy | bdce2ad | 2014-03-11 18:53:04 +0530 | [diff] [blame] | 4973 | return status; |
| 4974 | } |
| 4975 | |
Suresh Reddy | d9d426a | 2015-12-30 01:28:56 -0500 | [diff] [blame] | 4976 | int be_cmd_set_logical_link_config(struct be_adapter *adapter, |
| 4977 | int link_state, u8 domain) |
| 4978 | { |
| 4979 | int status; |
| 4980 | |
Suresh Reddy | dc6e851 | 2016-10-09 09:58:53 +0530 | [diff] [blame] | 4981 | if (BE2_chip(adapter)) |
Suresh Reddy | d9d426a | 2015-12-30 01:28:56 -0500 | [diff] [blame] | 4982 | 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 Basavapatna | 710f3e5 | 2016-09-07 19:57:49 +0530 | [diff] [blame] | 4995 | |
| 4996 | int 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; |
| 5033 | err: |
| 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 Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 5046 | int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload, |
Sathya Perla | a2cc4e0 | 2014-05-09 13:29:14 +0530 | [diff] [blame] | 5047 | int wrb_payload_size, u16 *cmd_status, u16 *ext_status) |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 5048 | { |
| 5049 | struct be_adapter *adapter = netdev_priv(netdev_handle); |
| 5050 | struct be_mcc_wrb *wrb; |
Kalesh AP | 504fbf1 | 2014-09-19 15:47:00 +0530 | [diff] [blame] | 5051 | struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *)wrb_payload; |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 5052 | struct be_cmd_req_hdr *req; |
| 5053 | struct be_cmd_resp_hdr *resp; |
| 5054 | int status; |
| 5055 | |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5056 | mutex_lock(&adapter->mcc_lock); |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 5057 | |
| 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); |
| 5078 | err: |
Sathya Perla | b717241 | 2016-07-27 05:26:18 -0400 | [diff] [blame] | 5079 | mutex_unlock(&adapter->mcc_lock); |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 5080 | return status; |
| 5081 | } |
| 5082 | EXPORT_SYMBOL(be_roce_mcc_cmd); |