Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Vasundhara Volam | c7bb15a | 2013-03-06 20:05:05 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2013 Emulex |
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 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 22 | static struct be_cmd_priv_map cmd_priv_map[] = { |
| 23 | { |
| 24 | OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, |
| 25 | CMD_SUBSYSTEM_ETH, |
| 26 | BE_PRIV_LNKMGMT | BE_PRIV_VHADM | |
| 27 | BE_PRIV_DEVCFG | BE_PRIV_DEVSEC |
| 28 | }, |
| 29 | { |
| 30 | OPCODE_COMMON_GET_FLOW_CONTROL, |
| 31 | CMD_SUBSYSTEM_COMMON, |
| 32 | BE_PRIV_LNKQUERY | BE_PRIV_VHADM | |
| 33 | BE_PRIV_DEVCFG | BE_PRIV_DEVSEC |
| 34 | }, |
| 35 | { |
| 36 | OPCODE_COMMON_SET_FLOW_CONTROL, |
| 37 | CMD_SUBSYSTEM_COMMON, |
| 38 | BE_PRIV_LNKMGMT | BE_PRIV_VHADM | |
| 39 | BE_PRIV_DEVCFG | BE_PRIV_DEVSEC |
| 40 | }, |
| 41 | { |
| 42 | OPCODE_ETH_GET_PPORT_STATS, |
| 43 | CMD_SUBSYSTEM_ETH, |
| 44 | BE_PRIV_LNKMGMT | BE_PRIV_VHADM | |
| 45 | BE_PRIV_DEVCFG | BE_PRIV_DEVSEC |
| 46 | }, |
| 47 | { |
| 48 | OPCODE_COMMON_GET_PHY_DETAILS, |
| 49 | CMD_SUBSYSTEM_COMMON, |
| 50 | BE_PRIV_LNKMGMT | BE_PRIV_VHADM | |
| 51 | BE_PRIV_DEVCFG | BE_PRIV_DEVSEC |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | static bool be_cmd_allowed(struct be_adapter *adapter, u8 opcode, |
| 56 | u8 subsystem) |
| 57 | { |
| 58 | int i; |
| 59 | int num_entries = sizeof(cmd_priv_map)/sizeof(struct be_cmd_priv_map); |
| 60 | u32 cmd_privileges = adapter->cmd_privileges; |
| 61 | |
| 62 | for (i = 0; i < num_entries; i++) |
| 63 | if (opcode == cmd_priv_map[i].opcode && |
| 64 | subsystem == cmd_priv_map[i].subsystem) |
| 65 | if (!(cmd_privileges & cmd_priv_map[i].priv_mask)) |
| 66 | return false; |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | |
Somnath Kotur | 3de0945 | 2011-09-30 07:25:05 +0000 | [diff] [blame] | 71 | static inline void *embedded_payload(struct be_mcc_wrb *wrb) |
| 72 | { |
| 73 | return wrb->payload.embedded_payload; |
| 74 | } |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 75 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 76 | static void be_mcc_notify(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 77 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 78 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 79 | u32 val = 0; |
| 80 | |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 81 | if (be_error(adapter)) |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 82 | return; |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 83 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 84 | val |= mccq->id & DB_MCCQ_RING_ID_MASK; |
| 85 | val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 86 | |
| 87 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 88 | iowrite32(val, adapter->db + DB_MCCQ_OFFSET); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | /* To check if valid bit is set, check the entire word as we don't know |
| 92 | * the endianness of the data (old entry is host endian while a new entry is |
| 93 | * little endian) */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 94 | 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] | 95 | { |
Sathya Perla | 9e9ff4b | 2013-02-12 23:05:19 +0000 | [diff] [blame] | 96 | u32 flags; |
| 97 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 98 | if (compl->flags != 0) { |
Sathya Perla | 9e9ff4b | 2013-02-12 23:05:19 +0000 | [diff] [blame] | 99 | flags = le32_to_cpu(compl->flags); |
| 100 | if (flags & CQE_FLAGS_VALID_MASK) { |
| 101 | compl->flags = flags; |
| 102 | return true; |
| 103 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 104 | } |
Sathya Perla | 9e9ff4b | 2013-02-12 23:05:19 +0000 | [diff] [blame] | 105 | return false; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | /* Need to reset the entire word that houses the valid bit */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 109 | static inline void be_mcc_compl_use(struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 110 | { |
| 111 | compl->flags = 0; |
| 112 | } |
| 113 | |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 114 | static struct be_cmd_resp_hdr *be_decode_resp_hdr(u32 tag0, u32 tag1) |
| 115 | { |
| 116 | unsigned long addr; |
| 117 | |
| 118 | addr = tag1; |
| 119 | addr = ((addr << 16) << 16) | tag0; |
| 120 | return (void *)addr; |
| 121 | } |
| 122 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 123 | static int be_mcc_compl_process(struct be_adapter *adapter, |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 124 | struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 125 | { |
| 126 | u16 compl_status, extd_status; |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 127 | struct be_cmd_resp_hdr *resp_hdr; |
| 128 | u8 opcode = 0, subsystem = 0; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 129 | |
| 130 | /* Just swap the status to host endian; mcc tag is opaquely copied |
| 131 | * from mcc_wrb */ |
| 132 | be_dws_le_to_cpu(compl, 4); |
| 133 | |
| 134 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 135 | CQE_STATUS_COMPL_MASK; |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 136 | |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 137 | resp_hdr = be_decode_resp_hdr(compl->tag0, compl->tag1); |
| 138 | |
| 139 | if (resp_hdr) { |
| 140 | opcode = resp_hdr->opcode; |
| 141 | subsystem = resp_hdr->subsystem; |
| 142 | } |
| 143 | |
| 144 | if (((opcode == OPCODE_COMMON_WRITE_FLASHROM) || |
| 145 | (opcode == OPCODE_COMMON_WRITE_OBJECT)) && |
| 146 | (subsystem == CMD_SUBSYSTEM_COMMON)) { |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 147 | adapter->flash_status = compl_status; |
| 148 | complete(&adapter->flash_compl); |
| 149 | } |
| 150 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 151 | if (compl_status == MCC_STATUS_SUCCESS) { |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 152 | if (((opcode == OPCODE_ETH_GET_STATISTICS) || |
| 153 | (opcode == OPCODE_ETH_GET_PPORT_STATS)) && |
| 154 | (subsystem == CMD_SUBSYSTEM_ETH)) { |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 155 | be_parse_stats(adapter); |
Ajit Khaparde | b2aebe6 | 2011-02-20 11:41:39 +0000 | [diff] [blame] | 156 | adapter->stats_cmd_sent = false; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 157 | } |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 158 | if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES && |
| 159 | subsystem == CMD_SUBSYSTEM_COMMON) { |
Somnath Kotur | 3de0945 | 2011-09-30 07:25:05 +0000 | [diff] [blame] | 160 | struct be_cmd_resp_get_cntl_addnl_attribs *resp = |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 161 | (void *)resp_hdr; |
Somnath Kotur | 3de0945 | 2011-09-30 07:25:05 +0000 | [diff] [blame] | 162 | adapter->drv_stats.be_on_die_temperature = |
| 163 | resp->on_die_temperature; |
| 164 | } |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 165 | } else { |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 166 | if (opcode == OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES) |
Padmanabh Ratnakar | 7aeb215 | 2012-07-12 03:56:46 +0000 | [diff] [blame] | 167 | adapter->be_get_temp_freq = 0; |
Somnath Kotur | 3de0945 | 2011-09-30 07:25:05 +0000 | [diff] [blame] | 168 | |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 169 | if (compl_status == MCC_STATUS_NOT_SUPPORTED || |
| 170 | compl_status == MCC_STATUS_ILLEGAL_REQUEST) |
| 171 | goto done; |
| 172 | |
| 173 | if (compl_status == MCC_STATUS_UNAUTHORIZED_REQUEST) { |
Vasundhara Volam | 97f1d8c | 2012-06-13 19:51:44 +0000 | [diff] [blame] | 174 | dev_warn(&adapter->pdev->dev, |
Vasundhara Volam | 522609f | 2012-08-28 20:37:44 +0000 | [diff] [blame] | 175 | "VF is not privileged to issue opcode %d-%d\n", |
Vasundhara Volam | 97f1d8c | 2012-06-13 19:51:44 +0000 | [diff] [blame] | 176 | opcode, subsystem); |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 177 | } else { |
| 178 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 179 | CQE_STATUS_EXTD_MASK; |
Vasundhara Volam | 97f1d8c | 2012-06-13 19:51:44 +0000 | [diff] [blame] | 180 | dev_err(&adapter->pdev->dev, |
| 181 | "opcode %d-%d failed:status %d-%d\n", |
| 182 | opcode, subsystem, compl_status, extd_status); |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 183 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 184 | } |
Sathya Perla | 2b3f291 | 2011-06-29 23:32:56 +0000 | [diff] [blame] | 185 | done: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 186 | return compl_status; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 187 | } |
| 188 | |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 189 | /* 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] | 190 | static void be_async_link_state_process(struct be_adapter *adapter, |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 191 | struct be_async_event_link_state *evt) |
| 192 | { |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 193 | /* When link status changes, link speed must be re-queried from FW */ |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 194 | adapter->phy.link_speed = -1; |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 195 | |
Padmanabh Ratnakar | 2e177a5 | 2012-07-18 02:52:15 +0000 | [diff] [blame] | 196 | /* Ignore physical link event */ |
| 197 | if (lancer_chip(adapter) && |
| 198 | !(evt->port_link_status & LOGICAL_LINK_STATUS_MASK)) |
| 199 | return; |
| 200 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 201 | /* For the initial link status do not rely on the ASYNC event as |
| 202 | * it may not be received in some cases. |
| 203 | */ |
| 204 | if (adapter->flags & BE_FLAGS_LINK_STATUS_INIT) |
| 205 | be_link_status_update(adapter, evt->port_link_status); |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 208 | /* Grp5 CoS Priority evt */ |
| 209 | static void be_async_grp5_cos_priority_process(struct be_adapter *adapter, |
| 210 | struct be_async_event_grp5_cos_priority *evt) |
| 211 | { |
| 212 | if (evt->valid) { |
| 213 | adapter->vlan_prio_bmap = evt->available_priority_bmap; |
Ajit Khaparde | 60964dd | 2011-02-11 13:37:25 +0000 | [diff] [blame] | 214 | adapter->recommended_prio &= ~VLAN_PRIO_MASK; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 215 | adapter->recommended_prio = |
| 216 | evt->reco_default_priority << VLAN_PRIO_SHIFT; |
| 217 | } |
| 218 | } |
| 219 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 220 | /* 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] | 221 | static void be_async_grp5_qos_speed_process(struct be_adapter *adapter, |
| 222 | struct be_async_event_grp5_qos_link_speed *evt) |
| 223 | { |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 224 | if (adapter->phy.link_speed >= 0 && |
| 225 | evt->physical_port == adapter->port_num) |
| 226 | adapter->phy.link_speed = le16_to_cpu(evt->qos_link_speed) * 10; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 227 | } |
| 228 | |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 229 | /*Grp5 PVID evt*/ |
| 230 | static void be_async_grp5_pvid_state_process(struct be_adapter *adapter, |
| 231 | struct be_async_event_grp5_pvid_state *evt) |
| 232 | { |
| 233 | if (evt->enabled) |
Somnath Kotur | 939cf30 | 2011-08-18 21:51:49 -0700 | [diff] [blame] | 234 | adapter->pvid = le16_to_cpu(evt->tag) & VLAN_VID_MASK; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 235 | else |
| 236 | adapter->pvid = 0; |
| 237 | } |
| 238 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 239 | static void be_async_grp5_evt_process(struct be_adapter *adapter, |
| 240 | u32 trailer, struct be_mcc_compl *evt) |
| 241 | { |
| 242 | u8 event_type = 0; |
| 243 | |
| 244 | event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) & |
| 245 | ASYNC_TRAILER_EVENT_TYPE_MASK; |
| 246 | |
| 247 | switch (event_type) { |
| 248 | case ASYNC_EVENT_COS_PRIORITY: |
| 249 | be_async_grp5_cos_priority_process(adapter, |
| 250 | (struct be_async_event_grp5_cos_priority *)evt); |
| 251 | break; |
| 252 | case ASYNC_EVENT_QOS_SPEED: |
| 253 | be_async_grp5_qos_speed_process(adapter, |
| 254 | (struct be_async_event_grp5_qos_link_speed *)evt); |
| 255 | break; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame] | 256 | case ASYNC_EVENT_PVID_STATE: |
| 257 | be_async_grp5_pvid_state_process(adapter, |
| 258 | (struct be_async_event_grp5_pvid_state *)evt); |
| 259 | break; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 260 | default: |
Vasundhara Volam | 05ccaa2 | 2013-08-06 09:27:19 +0530 | [diff] [blame] | 261 | dev_warn(&adapter->pdev->dev, "Unknown grp5 event 0x%x!\n", |
| 262 | event_type); |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 263 | break; |
| 264 | } |
| 265 | } |
| 266 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 267 | static void be_async_dbg_evt_process(struct be_adapter *adapter, |
| 268 | u32 trailer, struct be_mcc_compl *cmp) |
| 269 | { |
| 270 | u8 event_type = 0; |
| 271 | struct be_async_event_qnq *evt = (struct be_async_event_qnq *) cmp; |
| 272 | |
| 273 | event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) & |
| 274 | ASYNC_TRAILER_EVENT_TYPE_MASK; |
| 275 | |
| 276 | switch (event_type) { |
| 277 | case ASYNC_DEBUG_EVENT_TYPE_QNQ: |
| 278 | if (evt->valid) |
| 279 | adapter->qnq_vid = le16_to_cpu(evt->vlan_tag); |
| 280 | adapter->flags |= BE_FLAGS_QNQ_ASYNC_EVT_RCVD; |
| 281 | break; |
| 282 | default: |
Vasundhara Volam | 05ccaa2 | 2013-08-06 09:27:19 +0530 | [diff] [blame] | 283 | dev_warn(&adapter->pdev->dev, "Unknown debug event 0x%x!\n", |
| 284 | event_type); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 289 | static inline bool is_link_state_evt(u32 trailer) |
| 290 | { |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 291 | return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 292 | ASYNC_TRAILER_EVENT_CODE_MASK) == |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 293 | ASYNC_EVENT_CODE_LINK_STATE; |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 294 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 295 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 296 | static inline bool is_grp5_evt(u32 trailer) |
| 297 | { |
| 298 | return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & |
| 299 | ASYNC_TRAILER_EVENT_CODE_MASK) == |
| 300 | ASYNC_EVENT_CODE_GRP_5); |
| 301 | } |
| 302 | |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 303 | static inline bool is_dbg_evt(u32 trailer) |
| 304 | { |
| 305 | return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & |
| 306 | ASYNC_TRAILER_EVENT_CODE_MASK) == |
| 307 | ASYNC_EVENT_CODE_QNQ); |
| 308 | } |
| 309 | |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 310 | 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] | 311 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 312 | struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq; |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 313 | struct be_mcc_compl *compl = queue_tail_node(mcc_cq); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 314 | |
| 315 | if (be_mcc_compl_is_new(compl)) { |
| 316 | queue_tail_inc(mcc_cq); |
| 317 | return compl; |
| 318 | } |
| 319 | return NULL; |
| 320 | } |
| 321 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 322 | void be_async_mcc_enable(struct be_adapter *adapter) |
| 323 | { |
| 324 | spin_lock_bh(&adapter->mcc_cq_lock); |
| 325 | |
| 326 | be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0); |
| 327 | adapter->mcc_obj.rearm_cq = true; |
| 328 | |
| 329 | spin_unlock_bh(&adapter->mcc_cq_lock); |
| 330 | } |
| 331 | |
| 332 | void be_async_mcc_disable(struct be_adapter *adapter) |
| 333 | { |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 334 | spin_lock_bh(&adapter->mcc_cq_lock); |
| 335 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 336 | adapter->mcc_obj.rearm_cq = false; |
Sathya Perla | a323d9b | 2012-12-17 19:38:50 +0000 | [diff] [blame] | 337 | be_cq_notify(adapter, adapter->mcc_obj.cq.id, false, 0); |
| 338 | |
| 339 | spin_unlock_bh(&adapter->mcc_cq_lock); |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 340 | } |
| 341 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 342 | int be_process_mcc(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 343 | { |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 344 | struct be_mcc_compl *compl; |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 345 | int num = 0, status = 0; |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 346 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 347 | |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 348 | spin_lock(&adapter->mcc_cq_lock); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 349 | while ((compl = be_mcc_compl_get(adapter))) { |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 350 | if (compl->flags & CQE_FLAGS_ASYNC_MASK) { |
| 351 | /* Interpret flags as an async trailer */ |
Ajit Khaparde | 323f30b | 2010-09-03 06:24:13 +0000 | [diff] [blame] | 352 | if (is_link_state_evt(compl->flags)) |
| 353 | be_async_link_state_process(adapter, |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 354 | (struct be_async_event_link_state *) compl); |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 355 | else if (is_grp5_evt(compl->flags)) |
| 356 | be_async_grp5_evt_process(adapter, |
| 357 | compl->flags, compl); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 358 | else if (is_dbg_evt(compl->flags)) |
| 359 | be_async_dbg_evt_process(adapter, |
| 360 | compl->flags, compl); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 361 | } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 362 | status = be_mcc_compl_process(adapter, compl); |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 363 | atomic_dec(&mcc_obj->q.used); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 364 | } |
| 365 | be_mcc_compl_use(compl); |
| 366 | num++; |
| 367 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 368 | |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 369 | if (num) |
| 370 | be_cq_notify(adapter, mcc_obj->cq.id, mcc_obj->rearm_cq, num); |
| 371 | |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 372 | spin_unlock(&adapter->mcc_cq_lock); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 373 | return status; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 376 | /* Wait till no more pending mcc requests are present */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 377 | static int be_mcc_wait_compl(struct be_adapter *adapter) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 378 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 379 | #define mcc_timeout 120000 /* 12s timeout */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 380 | int i, status = 0; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 381 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 382 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 383 | for (i = 0; i < mcc_timeout; i++) { |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 384 | if (be_error(adapter)) |
| 385 | return -EIO; |
| 386 | |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 387 | local_bh_disable(); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 388 | status = be_process_mcc(adapter); |
Amerigo Wang | 072a9c4 | 2012-08-24 21:41:11 +0000 | [diff] [blame] | 389 | local_bh_enable(); |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 390 | |
| 391 | if (atomic_read(&mcc_obj->q.used) == 0) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 392 | break; |
| 393 | udelay(100); |
| 394 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 395 | if (i == mcc_timeout) { |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 396 | dev_err(&adapter->pdev->dev, "FW not responding\n"); |
| 397 | adapter->fw_timeout = true; |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 398 | return -EIO; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 399 | } |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 400 | return status; |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /* Notify MCC requests and wait for completion */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 404 | static int be_mcc_notify_wait(struct be_adapter *adapter) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 405 | { |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 406 | int status; |
| 407 | struct be_mcc_wrb *wrb; |
| 408 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
| 409 | u16 index = mcc_obj->q.head; |
| 410 | struct be_cmd_resp_hdr *resp; |
| 411 | |
| 412 | index_dec(&index, mcc_obj->q.len); |
| 413 | wrb = queue_index_node(&mcc_obj->q, index); |
| 414 | |
| 415 | resp = be_decode_resp_hdr(wrb->tag0, wrb->tag1); |
| 416 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 417 | be_mcc_notify(adapter); |
Padmanabh Ratnakar | 652bf64 | 2012-04-25 01:47:03 +0000 | [diff] [blame] | 418 | |
| 419 | status = be_mcc_wait_compl(adapter); |
| 420 | if (status == -EIO) |
| 421 | goto out; |
| 422 | |
| 423 | status = resp->status; |
| 424 | out: |
| 425 | return status; |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 428 | 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] | 429 | { |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 430 | int msecs = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 431 | u32 ready; |
| 432 | |
| 433 | do { |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 434 | if (be_error(adapter)) |
| 435 | return -EIO; |
| 436 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 437 | ready = ioread32(db); |
Sathya Perla | 434b364 | 2011-11-10 19:17:59 +0000 | [diff] [blame] | 438 | if (ready == 0xffffffff) |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 439 | return -1; |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 440 | |
| 441 | ready &= MPU_MAILBOX_DB_RDY_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 442 | if (ready) |
| 443 | break; |
| 444 | |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 445 | if (msecs > 4000) { |
Sathya Perla | 6589ade | 2011-11-10 19:18:00 +0000 | [diff] [blame] | 446 | dev_err(&adapter->pdev->dev, "FW not responding\n"); |
| 447 | adapter->fw_timeout = true; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 448 | be_detect_error(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 449 | return -1; |
| 450 | } |
| 451 | |
Sathya Perla | 1dbf53a | 2011-05-12 19:32:16 +0000 | [diff] [blame] | 452 | msleep(1); |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 453 | msecs++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 454 | } while (true); |
| 455 | |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /* |
| 460 | * Insert the mailbox address into the doorbell in two steps |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 461 | * 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] | 462 | */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 463 | static int be_mbox_notify_wait(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 464 | { |
| 465 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 466 | u32 val = 0; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 467 | void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET; |
| 468 | struct be_dma_mem *mbox_mem = &adapter->mbox_mem; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 469 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 470 | struct be_mcc_compl *compl = &mbox->compl; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 471 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 472 | /* wait for ready to be set */ |
| 473 | status = be_mbox_db_ready_wait(adapter, db); |
| 474 | if (status != 0) |
| 475 | return status; |
| 476 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 477 | val |= MPU_MAILBOX_DB_HI_MASK; |
| 478 | /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */ |
| 479 | val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2; |
| 480 | iowrite32(val, db); |
| 481 | |
| 482 | /* wait for ready to be set */ |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 483 | status = be_mbox_db_ready_wait(adapter, db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 484 | if (status != 0) |
| 485 | return status; |
| 486 | |
| 487 | val = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 488 | /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */ |
| 489 | val |= (u32)(mbox_mem->dma >> 4) << 2; |
| 490 | iowrite32(val, db); |
| 491 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 492 | status = be_mbox_db_ready_wait(adapter, db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 493 | if (status != 0) |
| 494 | return status; |
| 495 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 496 | /* A cq entry has been made now */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 497 | if (be_mcc_compl_is_new(compl)) { |
| 498 | status = be_mcc_compl_process(adapter, &mbox->compl); |
| 499 | be_mcc_compl_use(compl); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 500 | if (status) |
| 501 | return status; |
| 502 | } else { |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 503 | dev_err(&adapter->pdev->dev, "invalid mailbox completion\n"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 504 | return -1; |
| 505 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 506 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 507 | } |
| 508 | |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 509 | static u16 be_POST_stage_get(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 510 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 511 | u32 sem; |
| 512 | |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 513 | if (BEx_chip(adapter)) |
| 514 | sem = ioread32(adapter->csr + SLIPORT_SEMAPHORE_OFFSET_BEx); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 515 | else |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 516 | pci_read_config_dword(adapter->pdev, |
| 517 | SLIPORT_SEMAPHORE_OFFSET_SH, &sem); |
| 518 | |
| 519 | return sem & POST_STAGE_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 522 | int lancer_wait_ready(struct be_adapter *adapter) |
| 523 | { |
| 524 | #define SLIPORT_READY_TIMEOUT 30 |
| 525 | u32 sliport_status; |
| 526 | int status = 0, i; |
| 527 | |
| 528 | for (i = 0; i < SLIPORT_READY_TIMEOUT; i++) { |
| 529 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 530 | if (sliport_status & SLIPORT_STATUS_RDY_MASK) |
| 531 | break; |
| 532 | |
| 533 | msleep(1000); |
| 534 | } |
| 535 | |
| 536 | if (i == SLIPORT_READY_TIMEOUT) |
| 537 | status = -1; |
| 538 | |
| 539 | return status; |
| 540 | } |
| 541 | |
Padmanabh Ratnakar | 67297ad | 2012-10-20 06:02:27 +0000 | [diff] [blame] | 542 | static bool lancer_provisioning_error(struct be_adapter *adapter) |
| 543 | { |
| 544 | u32 sliport_status = 0, sliport_err1 = 0, sliport_err2 = 0; |
| 545 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 546 | if (sliport_status & SLIPORT_STATUS_ERR_MASK) { |
| 547 | sliport_err1 = ioread32(adapter->db + |
| 548 | SLIPORT_ERROR1_OFFSET); |
| 549 | sliport_err2 = ioread32(adapter->db + |
| 550 | SLIPORT_ERROR2_OFFSET); |
| 551 | |
| 552 | if (sliport_err1 == SLIPORT_ERROR_NO_RESOURCE1 && |
| 553 | sliport_err2 == SLIPORT_ERROR_NO_RESOURCE2) |
| 554 | return true; |
| 555 | } |
| 556 | return false; |
| 557 | } |
| 558 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 559 | int lancer_test_and_set_rdy_state(struct be_adapter *adapter) |
| 560 | { |
| 561 | int status; |
| 562 | u32 sliport_status, err, reset_needed; |
Padmanabh Ratnakar | 67297ad | 2012-10-20 06:02:27 +0000 | [diff] [blame] | 563 | bool resource_error; |
| 564 | |
| 565 | resource_error = lancer_provisioning_error(adapter); |
| 566 | if (resource_error) |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 567 | return -EAGAIN; |
Padmanabh Ratnakar | 67297ad | 2012-10-20 06:02:27 +0000 | [diff] [blame] | 568 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 569 | status = lancer_wait_ready(adapter); |
| 570 | if (!status) { |
| 571 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 572 | err = sliport_status & SLIPORT_STATUS_ERR_MASK; |
| 573 | reset_needed = sliport_status & SLIPORT_STATUS_RN_MASK; |
| 574 | if (err && reset_needed) { |
| 575 | iowrite32(SLI_PORT_CONTROL_IP_MASK, |
| 576 | adapter->db + SLIPORT_CONTROL_OFFSET); |
| 577 | |
| 578 | /* check adapter has corrected the error */ |
| 579 | status = lancer_wait_ready(adapter); |
| 580 | sliport_status = ioread32(adapter->db + |
| 581 | SLIPORT_STATUS_OFFSET); |
| 582 | sliport_status &= (SLIPORT_STATUS_ERR_MASK | |
| 583 | SLIPORT_STATUS_RN_MASK); |
| 584 | if (status || sliport_status) |
| 585 | status = -1; |
| 586 | } else if (err || reset_needed) { |
| 587 | status = -1; |
| 588 | } |
| 589 | } |
Padmanabh Ratnakar | 67297ad | 2012-10-20 06:02:27 +0000 | [diff] [blame] | 590 | /* Stop error recovery if error is not recoverable. |
| 591 | * No resource error is temporary errors and will go away |
| 592 | * when PF provisions resources. |
| 593 | */ |
| 594 | resource_error = lancer_provisioning_error(adapter); |
Somnath Kotur | 01e5b2c | 2013-05-29 22:56:17 +0000 | [diff] [blame] | 595 | if (resource_error) |
| 596 | status = -EAGAIN; |
Padmanabh Ratnakar | 67297ad | 2012-10-20 06:02:27 +0000 | [diff] [blame] | 597 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 598 | return status; |
| 599 | } |
| 600 | |
| 601 | int be_fw_wait_ready(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 602 | { |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 603 | u16 stage; |
| 604 | int status, timeout = 0; |
Sathya Perla | 6ed35ee | 2011-05-12 19:32:15 +0000 | [diff] [blame] | 605 | struct device *dev = &adapter->pdev->dev; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 606 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 607 | if (lancer_chip(adapter)) { |
| 608 | status = lancer_wait_ready(adapter); |
| 609 | return status; |
| 610 | } |
| 611 | |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 612 | do { |
Sathya Perla | c5b3ad4 | 2013-03-05 22:23:20 +0000 | [diff] [blame] | 613 | stage = be_POST_stage_get(adapter); |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 614 | if (stage == POST_STAGE_ARMFW_RDY) |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 615 | return 0; |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 616 | |
| 617 | dev_info(dev, "Waiting for POST, %ds elapsed\n", |
| 618 | timeout); |
| 619 | if (msleep_interruptible(2000)) { |
| 620 | dev_err(dev, "Waiting for POST aborted\n"); |
| 621 | return -EINTR; |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 622 | } |
Gavin Shan | 66d29cb | 2013-03-03 21:48:46 +0000 | [diff] [blame] | 623 | timeout += 2; |
Somnath Kotur | 3ab81b5 | 2011-10-03 08:10:57 +0000 | [diff] [blame] | 624 | } while (timeout < 60); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 625 | |
Sathya Perla | 6ed35ee | 2011-05-12 19:32:15 +0000 | [diff] [blame] | 626 | dev_err(dev, "POST timeout; stage=0x%x\n", stage); |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 627 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 630 | |
| 631 | static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb) |
| 632 | { |
| 633 | return &wrb->payload.sgl[0]; |
| 634 | } |
| 635 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 636 | static inline void fill_wrb_tags(struct be_mcc_wrb *wrb, |
| 637 | unsigned long addr) |
| 638 | { |
| 639 | wrb->tag0 = addr & 0xFFFFFFFF; |
| 640 | wrb->tag1 = upper_32_bits(addr); |
| 641 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 642 | |
| 643 | /* Don't touch the hdr after it's prepared */ |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 644 | /* mem will be NULL for embedded commands */ |
| 645 | static void be_wrb_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr, |
| 646 | u8 subsystem, u8 opcode, int cmd_len, |
| 647 | struct be_mcc_wrb *wrb, struct be_dma_mem *mem) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 648 | { |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 649 | struct be_sge *sge; |
| 650 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 651 | req_hdr->opcode = opcode; |
| 652 | req_hdr->subsystem = subsystem; |
| 653 | req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr)); |
Ajit Khaparde | 07793d3 | 2010-02-16 00:18:46 +0000 | [diff] [blame] | 654 | req_hdr->version = 0; |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 655 | fill_wrb_tags(wrb, (ulong) req_hdr); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 656 | wrb->payload_length = cmd_len; |
| 657 | if (mem) { |
| 658 | wrb->embedded |= (1 & MCC_WRB_SGE_CNT_MASK) << |
| 659 | MCC_WRB_SGE_CNT_SHIFT; |
| 660 | sge = nonembedded_sgl(wrb); |
| 661 | sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma)); |
| 662 | sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF); |
| 663 | sge->len = cpu_to_le32(mem->size); |
| 664 | } else |
| 665 | wrb->embedded |= MCC_WRB_EMBEDDED_MASK; |
| 666 | be_dws_cpu_to_le(wrb, 8); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages, |
| 670 | struct be_dma_mem *mem) |
| 671 | { |
| 672 | int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages); |
| 673 | u64 dma = (u64)mem->dma; |
| 674 | |
| 675 | for (i = 0; i < buf_pages; i++) { |
| 676 | pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF); |
| 677 | pages[i].hi = cpu_to_le32(upper_32_bits(dma)); |
| 678 | dma += PAGE_SIZE_4K; |
| 679 | } |
| 680 | } |
| 681 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 682 | 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] | 683 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 684 | struct be_dma_mem *mbox_mem = &adapter->mbox_mem; |
| 685 | struct be_mcc_wrb *wrb |
| 686 | = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb; |
| 687 | memset(wrb, 0, sizeof(*wrb)); |
| 688 | return wrb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 689 | } |
| 690 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 691 | static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 692 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 693 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
| 694 | struct be_mcc_wrb *wrb; |
| 695 | |
Padmanabh Ratnakar | aa790db | 2012-10-20 06:03:25 +0000 | [diff] [blame] | 696 | if (!mccq->created) |
| 697 | return NULL; |
| 698 | |
Vasundhara Volam | 4d27712 | 2013-04-21 23:28:15 +0000 | [diff] [blame] | 699 | if (atomic_read(&mccq->used) >= mccq->len) |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 700 | return NULL; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 701 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 702 | wrb = queue_head_node(mccq); |
| 703 | queue_head_inc(mccq); |
| 704 | atomic_inc(&mccq->used); |
| 705 | memset(wrb, 0, sizeof(*wrb)); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 706 | return wrb; |
| 707 | } |
| 708 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 709 | static bool use_mcc(struct be_adapter *adapter) |
| 710 | { |
| 711 | return adapter->mcc_obj.q.created; |
| 712 | } |
| 713 | |
| 714 | /* Must be used only in process context */ |
| 715 | static int be_cmd_lock(struct be_adapter *adapter) |
| 716 | { |
| 717 | if (use_mcc(adapter)) { |
| 718 | spin_lock_bh(&adapter->mcc_lock); |
| 719 | return 0; |
| 720 | } else { |
| 721 | return mutex_lock_interruptible(&adapter->mbox_lock); |
| 722 | } |
| 723 | } |
| 724 | |
| 725 | /* Must be used only in process context */ |
| 726 | static void be_cmd_unlock(struct be_adapter *adapter) |
| 727 | { |
| 728 | if (use_mcc(adapter)) |
| 729 | spin_unlock_bh(&adapter->mcc_lock); |
| 730 | else |
| 731 | return mutex_unlock(&adapter->mbox_lock); |
| 732 | } |
| 733 | |
| 734 | static struct be_mcc_wrb *be_cmd_copy(struct be_adapter *adapter, |
| 735 | struct be_mcc_wrb *wrb) |
| 736 | { |
| 737 | struct be_mcc_wrb *dest_wrb; |
| 738 | |
| 739 | if (use_mcc(adapter)) { |
| 740 | dest_wrb = wrb_from_mccq(adapter); |
| 741 | if (!dest_wrb) |
| 742 | return NULL; |
| 743 | } else { |
| 744 | dest_wrb = wrb_from_mbox(adapter); |
| 745 | } |
| 746 | |
| 747 | memcpy(dest_wrb, wrb, sizeof(*wrb)); |
| 748 | if (wrb->embedded & cpu_to_le32(MCC_WRB_EMBEDDED_MASK)) |
| 749 | fill_wrb_tags(dest_wrb, (ulong) embedded_payload(wrb)); |
| 750 | |
| 751 | return dest_wrb; |
| 752 | } |
| 753 | |
| 754 | /* Must be used only in process context */ |
| 755 | static int be_cmd_notify_wait(struct be_adapter *adapter, |
| 756 | struct be_mcc_wrb *wrb) |
| 757 | { |
| 758 | struct be_mcc_wrb *dest_wrb; |
| 759 | int status; |
| 760 | |
| 761 | status = be_cmd_lock(adapter); |
| 762 | if (status) |
| 763 | return status; |
| 764 | |
| 765 | dest_wrb = be_cmd_copy(adapter, wrb); |
| 766 | if (!dest_wrb) |
| 767 | return -EBUSY; |
| 768 | |
| 769 | if (use_mcc(adapter)) |
| 770 | status = be_mcc_notify_wait(adapter); |
| 771 | else |
| 772 | status = be_mbox_notify_wait(adapter); |
| 773 | |
| 774 | if (!status) |
| 775 | memcpy(wrb, dest_wrb, sizeof(*wrb)); |
| 776 | |
| 777 | be_cmd_unlock(adapter); |
| 778 | return status; |
| 779 | } |
| 780 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 781 | /* Tell fw we're about to start firing cmds by writing a |
| 782 | * special pattern across the wrb hdr; uses mbox |
| 783 | */ |
| 784 | int be_cmd_fw_init(struct be_adapter *adapter) |
| 785 | { |
| 786 | u8 *wrb; |
| 787 | int status; |
| 788 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 789 | if (lancer_chip(adapter)) |
| 790 | return 0; |
| 791 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 792 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 793 | return -1; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 794 | |
| 795 | wrb = (u8 *)wrb_from_mbox(adapter); |
Sathya Perla | 359a972 | 2010-12-01 01:03:36 +0000 | [diff] [blame] | 796 | *wrb++ = 0xFF; |
| 797 | *wrb++ = 0x12; |
| 798 | *wrb++ = 0x34; |
| 799 | *wrb++ = 0xFF; |
| 800 | *wrb++ = 0xFF; |
| 801 | *wrb++ = 0x56; |
| 802 | *wrb++ = 0x78; |
| 803 | *wrb = 0xFF; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 804 | |
| 805 | status = be_mbox_notify_wait(adapter); |
| 806 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 807 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 808 | return status; |
| 809 | } |
| 810 | |
| 811 | /* Tell fw we're done with firing cmds by writing a |
| 812 | * special pattern across the wrb hdr; uses mbox |
| 813 | */ |
| 814 | int be_cmd_fw_clean(struct be_adapter *adapter) |
| 815 | { |
| 816 | u8 *wrb; |
| 817 | int status; |
| 818 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 819 | if (lancer_chip(adapter)) |
| 820 | return 0; |
| 821 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 822 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 823 | return -1; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 824 | |
| 825 | wrb = (u8 *)wrb_from_mbox(adapter); |
| 826 | *wrb++ = 0xFF; |
| 827 | *wrb++ = 0xAA; |
| 828 | *wrb++ = 0xBB; |
| 829 | *wrb++ = 0xFF; |
| 830 | *wrb++ = 0xFF; |
| 831 | *wrb++ = 0xCC; |
| 832 | *wrb++ = 0xDD; |
| 833 | *wrb = 0xFF; |
| 834 | |
| 835 | status = be_mbox_notify_wait(adapter); |
| 836 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 837 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 838 | return status; |
| 839 | } |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 840 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 841 | 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] | 842 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 843 | struct be_mcc_wrb *wrb; |
| 844 | struct be_cmd_req_eq_create *req; |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 845 | struct be_dma_mem *q_mem = &eqo->q.dma_mem; |
| 846 | int status, ver = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 847 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 848 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 849 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 850 | |
| 851 | wrb = wrb_from_mbox(adapter); |
| 852 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 853 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 854 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 855 | OPCODE_COMMON_EQ_CREATE, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 856 | |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 857 | /* Support for EQ_CREATEv2 available only SH-R onwards */ |
| 858 | if (!(BEx_chip(adapter) || lancer_chip(adapter))) |
| 859 | ver = 2; |
| 860 | |
| 861 | req->hdr.version = ver; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 862 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 863 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 864 | AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1); |
| 865 | /* 4byte eqe*/ |
| 866 | AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0); |
| 867 | AMAP_SET_BITS(struct amap_eq_context, count, req->context, |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 868 | __ilog2_u32(eqo->q.len / 256)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 869 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 870 | |
| 871 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 872 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 873 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 874 | if (!status) { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 875 | struct be_cmd_resp_eq_create *resp = embedded_payload(wrb); |
Sathya Perla | f2f781a | 2013-08-27 16:57:30 +0530 | [diff] [blame] | 876 | eqo->q.id = le16_to_cpu(resp->eq_id); |
| 877 | eqo->msix_idx = |
| 878 | (ver == 2) ? le16_to_cpu(resp->msix_idx) : eqo->idx; |
| 879 | eqo->q.created = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 880 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 881 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 882 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 883 | return status; |
| 884 | } |
| 885 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 886 | /* Use MCC */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 887 | 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] | 888 | bool permanent, u32 if_handle, u32 pmac_id) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 889 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 890 | struct be_mcc_wrb *wrb; |
| 891 | struct be_cmd_req_mac_query *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 892 | int status; |
| 893 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 894 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 895 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 896 | wrb = wrb_from_mccq(adapter); |
| 897 | if (!wrb) { |
| 898 | status = -EBUSY; |
| 899 | goto err; |
| 900 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 901 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 902 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 903 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 904 | OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req), wrb, NULL); |
Sathya Perla | 5ee4979 | 2012-09-28 04:39:41 +0000 | [diff] [blame] | 905 | req->type = MAC_ADDRESS_TYPE_NETWORK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 906 | if (permanent) { |
| 907 | req->permanent = 1; |
| 908 | } else { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 909 | req->if_id = cpu_to_le16((u16) if_handle); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 910 | req->pmac_id = cpu_to_le32(pmac_id); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 911 | req->permanent = 0; |
| 912 | } |
| 913 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 914 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 915 | if (!status) { |
| 916 | struct be_cmd_resp_mac_query *resp = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 917 | memcpy(mac_addr, resp->mac.addr, ETH_ALEN); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 918 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 919 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 920 | err: |
| 921 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 922 | return status; |
| 923 | } |
| 924 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 925 | /* Uses synchronous MCCQ */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 926 | int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 927 | u32 if_id, u32 *pmac_id, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 928 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 929 | struct be_mcc_wrb *wrb; |
| 930 | struct be_cmd_req_pmac_add *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 931 | int status; |
| 932 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 933 | spin_lock_bh(&adapter->mcc_lock); |
| 934 | |
| 935 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 936 | if (!wrb) { |
| 937 | status = -EBUSY; |
| 938 | goto err; |
| 939 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 940 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 941 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 942 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 943 | OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 944 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 945 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 946 | req->if_id = cpu_to_le32(if_id); |
| 947 | memcpy(req->mac_address, mac_addr, ETH_ALEN); |
| 948 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 949 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 950 | if (!status) { |
| 951 | struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb); |
| 952 | *pmac_id = le32_to_cpu(resp->pmac_id); |
| 953 | } |
| 954 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 955 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 956 | spin_unlock_bh(&adapter->mcc_lock); |
Somnath Kotur | e3a7ae2 | 2011-10-27 07:14:05 +0000 | [diff] [blame] | 957 | |
| 958 | if (status == MCC_STATUS_UNAUTHORIZED_REQUEST) |
| 959 | status = -EPERM; |
| 960 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 961 | return status; |
| 962 | } |
| 963 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 964 | /* Uses synchronous MCCQ */ |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 965 | 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] | 966 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 967 | struct be_mcc_wrb *wrb; |
| 968 | struct be_cmd_req_pmac_del *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 969 | int status; |
| 970 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 971 | if (pmac_id == -1) |
| 972 | return 0; |
| 973 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 974 | spin_lock_bh(&adapter->mcc_lock); |
| 975 | |
| 976 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 977 | if (!wrb) { |
| 978 | status = -EBUSY; |
| 979 | goto err; |
| 980 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 981 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 982 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 983 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 984 | OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 985 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 986 | req->hdr.domain = dom; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 987 | req->if_id = cpu_to_le32(if_id); |
| 988 | req->pmac_id = cpu_to_le32(pmac_id); |
| 989 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 990 | status = be_mcc_notify_wait(adapter); |
| 991 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 992 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 993 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 994 | return status; |
| 995 | } |
| 996 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 997 | /* Uses Mbox */ |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 998 | int be_cmd_cq_create(struct be_adapter *adapter, struct be_queue_info *cq, |
| 999 | struct be_queue_info *eq, bool no_delay, int coalesce_wm) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1000 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1001 | struct be_mcc_wrb *wrb; |
| 1002 | struct be_cmd_req_cq_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1003 | struct be_dma_mem *q_mem = &cq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1004 | void *ctxt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1005 | int status; |
| 1006 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1007 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1008 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1009 | |
| 1010 | wrb = wrb_from_mbox(adapter); |
| 1011 | req = embedded_payload(wrb); |
| 1012 | ctxt = &req->context; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1013 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1014 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1015 | OPCODE_COMMON_CQ_CREATE, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1016 | |
| 1017 | 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] | 1018 | |
| 1019 | if (BEx_chip(adapter)) { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1020 | AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt, |
| 1021 | coalesce_wm); |
| 1022 | AMAP_SET_BITS(struct amap_cq_context_be, nodelay, |
| 1023 | ctxt, no_delay); |
| 1024 | AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt, |
| 1025 | __ilog2_u32(cq->len/256)); |
| 1026 | AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1027 | AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1); |
| 1028 | AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id); |
Ajit Khaparde | bbdc42f | 2013-05-01 09:37:17 +0000 | [diff] [blame] | 1029 | } else { |
| 1030 | req->hdr.version = 2; |
| 1031 | req->page_size = 1; /* 1 for 4K */ |
| 1032 | AMAP_SET_BITS(struct amap_cq_context_v2, nodelay, ctxt, |
| 1033 | no_delay); |
| 1034 | AMAP_SET_BITS(struct amap_cq_context_v2, count, ctxt, |
| 1035 | __ilog2_u32(cq->len/256)); |
| 1036 | AMAP_SET_BITS(struct amap_cq_context_v2, valid, ctxt, 1); |
| 1037 | AMAP_SET_BITS(struct amap_cq_context_v2, eventable, |
| 1038 | ctxt, 1); |
| 1039 | AMAP_SET_BITS(struct amap_cq_context_v2, eqid, |
| 1040 | ctxt, eq->id); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1041 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1042 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1043 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 1044 | |
| 1045 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1046 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1047 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1048 | if (!status) { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1049 | struct be_cmd_resp_cq_create *resp = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1050 | cq->id = le16_to_cpu(resp->cq_id); |
| 1051 | cq->created = true; |
| 1052 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1053 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1054 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1055 | |
| 1056 | return status; |
| 1057 | } |
| 1058 | |
| 1059 | static u32 be_encoded_q_len(int q_len) |
| 1060 | { |
| 1061 | u32 len_encoded = fls(q_len); /* log2(len) + 1 */ |
| 1062 | if (len_encoded == 16) |
| 1063 | len_encoded = 0; |
| 1064 | return len_encoded; |
| 1065 | } |
| 1066 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1067 | static int be_cmd_mccq_ext_create(struct be_adapter *adapter, |
| 1068 | struct be_queue_info *mccq, |
| 1069 | struct be_queue_info *cq) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1070 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1071 | struct be_mcc_wrb *wrb; |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1072 | struct be_cmd_req_mcc_ext_create *req; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1073 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1074 | void *ctxt; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1075 | int status; |
| 1076 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1077 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1078 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1079 | |
| 1080 | wrb = wrb_from_mbox(adapter); |
| 1081 | req = embedded_payload(wrb); |
| 1082 | ctxt = &req->context; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1083 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1084 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1085 | OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req), wrb, NULL); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1086 | |
Ajit Khaparde | d4a2ac3 | 2010-03-11 01:35:59 +0000 | [diff] [blame] | 1087 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1088 | if (lancer_chip(adapter)) { |
| 1089 | req->hdr.version = 1; |
| 1090 | req->cq_id = cpu_to_le16(cq->id); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1091 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1092 | AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt, |
| 1093 | be_encoded_q_len(mccq->len)); |
| 1094 | AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1); |
| 1095 | AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id, |
| 1096 | ctxt, cq->id); |
| 1097 | AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid, |
| 1098 | ctxt, 1); |
| 1099 | |
| 1100 | } else { |
| 1101 | AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1); |
| 1102 | AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt, |
| 1103 | be_encoded_q_len(mccq->len)); |
| 1104 | AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id); |
| 1105 | } |
| 1106 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 1107 | /* Subscribe to Link State and Group 5 Events(bits 1 and 5 set) */ |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 1108 | req->async_event_bitmap[0] = cpu_to_le32(0x00000022); |
Ajit Khaparde | bc0c340 | 2013-04-24 11:52:50 +0000 | [diff] [blame] | 1109 | req->async_event_bitmap[0] |= cpu_to_le32(1 << ASYNC_EVENT_CODE_QNQ); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1110 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 1111 | |
| 1112 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1113 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1114 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1115 | if (!status) { |
| 1116 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
| 1117 | mccq->id = le16_to_cpu(resp->id); |
| 1118 | mccq->created = true; |
| 1119 | } |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1120 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1121 | |
| 1122 | return status; |
| 1123 | } |
| 1124 | |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 1125 | static int be_cmd_mccq_org_create(struct be_adapter *adapter, |
| 1126 | struct be_queue_info *mccq, |
| 1127 | struct be_queue_info *cq) |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1128 | { |
| 1129 | struct be_mcc_wrb *wrb; |
| 1130 | struct be_cmd_req_mcc_create *req; |
| 1131 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
| 1132 | void *ctxt; |
| 1133 | int status; |
| 1134 | |
| 1135 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1136 | return -1; |
| 1137 | |
| 1138 | wrb = wrb_from_mbox(adapter); |
| 1139 | req = embedded_payload(wrb); |
| 1140 | ctxt = &req->context; |
| 1141 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1142 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1143 | OPCODE_COMMON_MCC_CREATE, sizeof(*req), wrb, NULL); |
Somnath Kotur | 34b1ef0 | 2011-06-01 00:33:22 +0000 | [diff] [blame] | 1144 | |
| 1145 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 1146 | |
| 1147 | AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1); |
| 1148 | AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt, |
| 1149 | be_encoded_q_len(mccq->len)); |
| 1150 | AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id); |
| 1151 | |
| 1152 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 1153 | |
| 1154 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1155 | |
| 1156 | status = be_mbox_notify_wait(adapter); |
| 1157 | if (!status) { |
| 1158 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
| 1159 | mccq->id = le16_to_cpu(resp->id); |
| 1160 | mccq->created = true; |
| 1161 | } |
| 1162 | |
| 1163 | mutex_unlock(&adapter->mbox_lock); |
| 1164 | return status; |
| 1165 | } |
| 1166 | |
| 1167 | int be_cmd_mccq_create(struct be_adapter *adapter, |
| 1168 | struct be_queue_info *mccq, |
| 1169 | struct be_queue_info *cq) |
| 1170 | { |
| 1171 | int status; |
| 1172 | |
| 1173 | status = be_cmd_mccq_ext_create(adapter, mccq, cq); |
| 1174 | if (status && !lancer_chip(adapter)) { |
| 1175 | dev_warn(&adapter->pdev->dev, "Upgrade to F/W ver 2.102.235.0 " |
| 1176 | "or newer to avoid conflicting priorities between NIC " |
| 1177 | "and FCoE traffic"); |
| 1178 | status = be_cmd_mccq_org_create(adapter, mccq, cq); |
| 1179 | } |
| 1180 | return status; |
| 1181 | } |
| 1182 | |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1183 | 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] | 1184 | { |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1185 | struct be_mcc_wrb wrb = {0}; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1186 | struct be_cmd_req_eth_tx_create *req; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1187 | struct be_queue_info *txq = &txo->q; |
| 1188 | struct be_queue_info *cq = &txo->cq; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1189 | struct be_dma_mem *q_mem = &txq->dma_mem; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1190 | int status, ver = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1191 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1192 | req = embedded_payload(&wrb); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1193 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1194 | OPCODE_ETH_TX_CREATE, sizeof(*req), &wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1195 | |
Padmanabh Ratnakar | 8b7756c | 2011-03-07 03:08:52 +0000 | [diff] [blame] | 1196 | if (lancer_chip(adapter)) { |
| 1197 | req->hdr.version = 1; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1198 | req->if_id = cpu_to_le16(adapter->if_handle); |
| 1199 | } else if (BEx_chip(adapter)) { |
| 1200 | if (adapter->function_caps & BE_FUNCTION_CAPS_SUPER_NIC) |
| 1201 | req->hdr.version = 2; |
| 1202 | } else { /* For SH */ |
| 1203 | req->hdr.version = 2; |
Padmanabh Ratnakar | 8b7756c | 2011-03-07 03:08:52 +0000 | [diff] [blame] | 1204 | } |
| 1205 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1206 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 1207 | req->ulp_num = BE_ULP1_NUM; |
| 1208 | req->type = BE_ETH_TX_RING_TYPE_STANDARD; |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1209 | req->cq_id = cpu_to_le16(cq->id); |
| 1210 | req->queue_size = be_encoded_q_len(txq->len); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1211 | 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] | 1212 | ver = req->hdr.version; |
| 1213 | |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1214 | status = be_cmd_notify_wait(adapter, &wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1215 | if (!status) { |
Sathya Perla | 7707133 | 2013-08-27 16:57:34 +0530 | [diff] [blame] | 1216 | struct be_cmd_resp_eth_tx_create *resp = embedded_payload(&wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1217 | txq->id = le16_to_cpu(resp->cid); |
Vasundhara Volam | 94d73aa | 2013-04-21 23:28:14 +0000 | [diff] [blame] | 1218 | if (ver == 2) |
| 1219 | txo->db_offset = le32_to_cpu(resp->db_offset); |
| 1220 | else |
| 1221 | txo->db_offset = DB_TXULP1_OFFSET; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1222 | txq->created = true; |
| 1223 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1224 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1225 | return status; |
| 1226 | } |
| 1227 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1228 | /* Uses MCC */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1229 | int be_cmd_rxq_create(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1230 | struct be_queue_info *rxq, u16 cq_id, u16 frag_size, |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1231 | u32 if_id, u32 rss, u8 *rss_id) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1232 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1233 | struct be_mcc_wrb *wrb; |
| 1234 | struct be_cmd_req_eth_rx_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1235 | struct be_dma_mem *q_mem = &rxq->dma_mem; |
| 1236 | int status; |
| 1237 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1238 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1239 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1240 | wrb = wrb_from_mccq(adapter); |
| 1241 | if (!wrb) { |
| 1242 | status = -EBUSY; |
| 1243 | goto err; |
| 1244 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1245 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1246 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1247 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1248 | OPCODE_ETH_RX_CREATE, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1249 | |
| 1250 | req->cq_id = cpu_to_le16(cq_id); |
| 1251 | req->frag_size = fls(frag_size) - 1; |
| 1252 | req->num_pages = 2; |
| 1253 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 1254 | req->interface_id = cpu_to_le32(if_id); |
Sathya Perla | 10ef9ab | 2012-02-09 18:05:27 +0000 | [diff] [blame] | 1255 | req->max_frame_size = cpu_to_le16(BE_MAX_JUMBO_FRAME_SIZE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1256 | req->rss_queue = cpu_to_le32(rss); |
| 1257 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1258 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1259 | if (!status) { |
| 1260 | struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb); |
| 1261 | rxq->id = le16_to_cpu(resp->id); |
| 1262 | rxq->created = true; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1263 | *rss_id = resp->rss_id; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1264 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1265 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1266 | err: |
| 1267 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1268 | return status; |
| 1269 | } |
| 1270 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1271 | /* Generic destroyer function for all types of queues |
| 1272 | * Uses Mbox |
| 1273 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1274 | int be_cmd_q_destroy(struct be_adapter *adapter, struct be_queue_info *q, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1275 | int queue_type) |
| 1276 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1277 | struct be_mcc_wrb *wrb; |
| 1278 | struct be_cmd_req_q_destroy *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1279 | u8 subsys = 0, opcode = 0; |
| 1280 | int status; |
| 1281 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1282 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1283 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1284 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1285 | wrb = wrb_from_mbox(adapter); |
| 1286 | req = embedded_payload(wrb); |
| 1287 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1288 | switch (queue_type) { |
| 1289 | case QTYPE_EQ: |
| 1290 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1291 | opcode = OPCODE_COMMON_EQ_DESTROY; |
| 1292 | break; |
| 1293 | case QTYPE_CQ: |
| 1294 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1295 | opcode = OPCODE_COMMON_CQ_DESTROY; |
| 1296 | break; |
| 1297 | case QTYPE_TXQ: |
| 1298 | subsys = CMD_SUBSYSTEM_ETH; |
| 1299 | opcode = OPCODE_ETH_TX_DESTROY; |
| 1300 | break; |
| 1301 | case QTYPE_RXQ: |
| 1302 | subsys = CMD_SUBSYSTEM_ETH; |
| 1303 | opcode = OPCODE_ETH_RX_DESTROY; |
| 1304 | break; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 1305 | case QTYPE_MCCQ: |
| 1306 | subsys = CMD_SUBSYSTEM_COMMON; |
| 1307 | opcode = OPCODE_COMMON_MCC_DESTROY; |
| 1308 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1309 | default: |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 1310 | BUG(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1311 | } |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1312 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1313 | be_wrb_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req), wrb, |
| 1314 | NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1315 | req->id = cpu_to_le16(q->id); |
| 1316 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1317 | status = be_mbox_notify_wait(adapter); |
Padmanabh Ratnakar | aa790db | 2012-10-20 06:03:25 +0000 | [diff] [blame] | 1318 | q->created = false; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 1319 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1320 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1321 | return status; |
| 1322 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1323 | |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1324 | /* Uses MCC */ |
| 1325 | int be_cmd_rxq_destroy(struct be_adapter *adapter, struct be_queue_info *q) |
| 1326 | { |
| 1327 | struct be_mcc_wrb *wrb; |
| 1328 | struct be_cmd_req_q_destroy *req; |
| 1329 | int status; |
| 1330 | |
| 1331 | spin_lock_bh(&adapter->mcc_lock); |
| 1332 | |
| 1333 | wrb = wrb_from_mccq(adapter); |
| 1334 | if (!wrb) { |
| 1335 | status = -EBUSY; |
| 1336 | goto err; |
| 1337 | } |
| 1338 | req = embedded_payload(wrb); |
| 1339 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1340 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1341 | OPCODE_ETH_RX_DESTROY, sizeof(*req), wrb, NULL); |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1342 | req->id = cpu_to_le16(q->id); |
| 1343 | |
| 1344 | status = be_mcc_notify_wait(adapter); |
Padmanabh Ratnakar | aa790db | 2012-10-20 06:03:25 +0000 | [diff] [blame] | 1345 | q->created = false; |
Sathya Perla | 482c9e7 | 2011-06-29 23:33:17 +0000 | [diff] [blame] | 1346 | |
| 1347 | err: |
| 1348 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1349 | return status; |
| 1350 | } |
| 1351 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1352 | /* Create an rx filtering policy configuration on an i/f |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1353 | * Will use MBOX only if MCCQ has not been created. |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1354 | */ |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 1355 | 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] | 1356 | u32 *if_handle, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1357 | { |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1358 | struct be_mcc_wrb wrb = {0}; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1359 | struct be_cmd_req_if_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1360 | int status; |
| 1361 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1362 | req = embedded_payload(&wrb); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1363 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1364 | OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req), &wrb, NULL); |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1365 | req->hdr.domain = domain; |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 1366 | req->capability_flags = cpu_to_le32(cap_flags); |
| 1367 | req->enable_flags = cpu_to_le32(en_flags); |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 1368 | req->pmac_invalid = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1369 | |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1370 | status = be_cmd_notify_wait(adapter, &wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1371 | if (!status) { |
Sathya Perla | bea5098 | 2013-08-27 16:57:33 +0530 | [diff] [blame] | 1372 | struct be_cmd_resp_if_create *resp = embedded_payload(&wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1373 | *if_handle = le32_to_cpu(resp->interface_id); |
Sathya Perla | b5bb977 | 2013-07-23 15:25:01 +0530 | [diff] [blame] | 1374 | |
| 1375 | /* Hack to retrieve VF's pmac-id on BE3 */ |
| 1376 | if (BE3_chip(adapter) && !be_physfn(adapter)) |
| 1377 | adapter->pmac_id[0] = le32_to_cpu(resp->pmac_id); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1378 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1379 | return status; |
| 1380 | } |
| 1381 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1382 | /* Uses MCCQ */ |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 1383 | 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] | 1384 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1385 | struct be_mcc_wrb *wrb; |
| 1386 | struct be_cmd_req_if_destroy *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1387 | int status; |
| 1388 | |
Sathya Perla | 3012803 | 2011-11-10 19:17:57 +0000 | [diff] [blame] | 1389 | if (interface_id == -1) |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1390 | return 0; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1391 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1392 | spin_lock_bh(&adapter->mcc_lock); |
| 1393 | |
| 1394 | wrb = wrb_from_mccq(adapter); |
| 1395 | if (!wrb) { |
| 1396 | status = -EBUSY; |
| 1397 | goto err; |
| 1398 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1399 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1400 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1401 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1402 | OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req), wrb, NULL); |
Ajit Khaparde | 658681f | 2011-02-11 13:34:46 +0000 | [diff] [blame] | 1403 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1404 | req->interface_id = cpu_to_le32(interface_id); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1405 | |
Sathya Perla | f9449ab | 2011-10-24 02:45:01 +0000 | [diff] [blame] | 1406 | status = be_mcc_notify_wait(adapter); |
| 1407 | err: |
| 1408 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1409 | return status; |
| 1410 | } |
| 1411 | |
| 1412 | /* Get stats is a non embedded command: the request is not embedded inside |
| 1413 | * WRB but is a separate dma memory block |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1414 | * Uses asynchronous MCC |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1415 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1416 | 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] | 1417 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1418 | struct be_mcc_wrb *wrb; |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1419 | struct be_cmd_req_hdr *hdr; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1420 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1421 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1422 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1423 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1424 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1425 | if (!wrb) { |
| 1426 | status = -EBUSY; |
| 1427 | goto err; |
| 1428 | } |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1429 | hdr = nonemb_cmd->va; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1430 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1431 | be_wrb_cmd_hdr_prepare(hdr, CMD_SUBSYSTEM_ETH, |
| 1432 | OPCODE_ETH_GET_STATISTICS, nonemb_cmd->size, wrb, nonemb_cmd); |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1433 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 1434 | /* version 1 of the cmd is not supported only by BE2 */ |
| 1435 | if (!BE2_chip(adapter)) |
Ajit Khaparde | 89a88ab | 2011-05-16 07:36:18 +0000 | [diff] [blame] | 1436 | hdr->version = 1; |
| 1437 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1438 | be_mcc_notify(adapter); |
Ajit Khaparde | b2aebe6 | 2011-02-20 11:41:39 +0000 | [diff] [blame] | 1439 | adapter->stats_cmd_sent = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1440 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1441 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1442 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1443 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1446 | /* Lancer Stats */ |
| 1447 | int lancer_cmd_get_pport_stats(struct be_adapter *adapter, |
| 1448 | struct be_dma_mem *nonemb_cmd) |
| 1449 | { |
| 1450 | |
| 1451 | struct be_mcc_wrb *wrb; |
| 1452 | struct lancer_cmd_req_pport_stats *req; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1453 | int status = 0; |
| 1454 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 1455 | if (!be_cmd_allowed(adapter, OPCODE_ETH_GET_PPORT_STATS, |
| 1456 | CMD_SUBSYSTEM_ETH)) |
| 1457 | return -EPERM; |
| 1458 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1459 | spin_lock_bh(&adapter->mcc_lock); |
| 1460 | |
| 1461 | wrb = wrb_from_mccq(adapter); |
| 1462 | if (!wrb) { |
| 1463 | status = -EBUSY; |
| 1464 | goto err; |
| 1465 | } |
| 1466 | req = nonemb_cmd->va; |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1467 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1468 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1469 | OPCODE_ETH_GET_PPORT_STATS, nonemb_cmd->size, wrb, |
| 1470 | nonemb_cmd); |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1471 | |
Padmanabh Ratnakar | d51ebd3 | 2012-04-25 01:46:52 +0000 | [diff] [blame] | 1472 | 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] | 1473 | req->cmd_params.params.reset_stats = 0; |
| 1474 | |
Selvin Xavier | 005d569 | 2011-05-16 07:36:35 +0000 | [diff] [blame] | 1475 | be_mcc_notify(adapter); |
| 1476 | adapter->stats_cmd_sent = true; |
| 1477 | |
| 1478 | err: |
| 1479 | spin_unlock_bh(&adapter->mcc_lock); |
| 1480 | return status; |
| 1481 | } |
| 1482 | |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 1483 | static int be_mac_to_link_speed(int mac_speed) |
| 1484 | { |
| 1485 | switch (mac_speed) { |
| 1486 | case PHY_LINK_SPEED_ZERO: |
| 1487 | return 0; |
| 1488 | case PHY_LINK_SPEED_10MBPS: |
| 1489 | return 10; |
| 1490 | case PHY_LINK_SPEED_100MBPS: |
| 1491 | return 100; |
| 1492 | case PHY_LINK_SPEED_1GBPS: |
| 1493 | return 1000; |
| 1494 | case PHY_LINK_SPEED_10GBPS: |
| 1495 | return 10000; |
Vasundhara Volam | b971f84 | 2013-08-06 09:27:15 +0530 | [diff] [blame] | 1496 | case PHY_LINK_SPEED_20GBPS: |
| 1497 | return 20000; |
| 1498 | case PHY_LINK_SPEED_25GBPS: |
| 1499 | return 25000; |
| 1500 | case PHY_LINK_SPEED_40GBPS: |
| 1501 | return 40000; |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 1502 | } |
| 1503 | return 0; |
| 1504 | } |
| 1505 | |
| 1506 | /* Uses synchronous mcc |
| 1507 | * Returns link_speed in Mbps |
| 1508 | */ |
| 1509 | int be_cmd_link_status_query(struct be_adapter *adapter, u16 *link_speed, |
| 1510 | u8 *link_status, u32 dom) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1511 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1512 | struct be_mcc_wrb *wrb; |
| 1513 | struct be_cmd_req_link_status *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1514 | int status; |
| 1515 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1516 | spin_lock_bh(&adapter->mcc_lock); |
| 1517 | |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 1518 | if (link_status) |
| 1519 | *link_status = LINK_DOWN; |
| 1520 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1521 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1522 | if (!wrb) { |
| 1523 | status = -EBUSY; |
| 1524 | goto err; |
| 1525 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1526 | req = embedded_payload(wrb); |
Sathya Perla | a8f447bd | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1527 | |
Padmanabh Ratnakar | 57cd80d | 2012-02-03 09:49:46 +0000 | [diff] [blame] | 1528 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1529 | OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req), wrb, NULL); |
| 1530 | |
Sathya Perla | ca34fe3 | 2012-11-06 17:48:56 +0000 | [diff] [blame] | 1531 | /* version 1 of the cmd is not supported only by BE2 */ |
| 1532 | if (!BE2_chip(adapter)) |
Padmanabh Ratnakar | daad616 | 2011-11-16 02:03:45 +0000 | [diff] [blame] | 1533 | req->hdr.version = 1; |
| 1534 | |
Padmanabh Ratnakar | 57cd80d | 2012-02-03 09:49:46 +0000 | [diff] [blame] | 1535 | req->hdr.domain = dom; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1536 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1537 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1538 | if (!status) { |
| 1539 | struct be_cmd_resp_link_status *resp = embedded_payload(wrb); |
Sathya Perla | 323ff71 | 2012-09-28 04:39:43 +0000 | [diff] [blame] | 1540 | if (link_speed) { |
| 1541 | *link_speed = resp->link_speed ? |
| 1542 | le16_to_cpu(resp->link_speed) * 10 : |
| 1543 | be_mac_to_link_speed(resp->mac_speed); |
| 1544 | |
| 1545 | if (!resp->logical_link_status) |
| 1546 | *link_speed = 0; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1547 | } |
Ajit Khaparde | b236916a | 2011-12-30 12:15:40 +0000 | [diff] [blame] | 1548 | if (link_status) |
| 1549 | *link_status = resp->logical_link_status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1550 | } |
| 1551 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1552 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1553 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1554 | return status; |
| 1555 | } |
| 1556 | |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1557 | /* Uses synchronous mcc */ |
| 1558 | int be_cmd_get_die_temperature(struct be_adapter *adapter) |
| 1559 | { |
| 1560 | struct be_mcc_wrb *wrb; |
| 1561 | struct be_cmd_req_get_cntl_addnl_attribs *req; |
Vasundhara Volam | 117affe | 2013-08-06 09:27:20 +0530 | [diff] [blame] | 1562 | int status = 0; |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1563 | |
| 1564 | spin_lock_bh(&adapter->mcc_lock); |
| 1565 | |
| 1566 | wrb = wrb_from_mccq(adapter); |
| 1567 | if (!wrb) { |
| 1568 | status = -EBUSY; |
| 1569 | goto err; |
| 1570 | } |
| 1571 | req = embedded_payload(wrb); |
| 1572 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1573 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1574 | OPCODE_COMMON_GET_CNTL_ADDITIONAL_ATTRIBUTES, sizeof(*req), |
| 1575 | wrb, NULL); |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1576 | |
Somnath Kotur | 3de0945 | 2011-09-30 07:25:05 +0000 | [diff] [blame] | 1577 | be_mcc_notify(adapter); |
Ajit Khaparde | 609ff3b | 2011-02-20 11:42:07 +0000 | [diff] [blame] | 1578 | |
| 1579 | err: |
| 1580 | spin_unlock_bh(&adapter->mcc_lock); |
| 1581 | return status; |
| 1582 | } |
| 1583 | |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1584 | /* Uses synchronous mcc */ |
| 1585 | int be_cmd_get_reg_len(struct be_adapter *adapter, u32 *log_size) |
| 1586 | { |
| 1587 | struct be_mcc_wrb *wrb; |
| 1588 | struct be_cmd_req_get_fat *req; |
| 1589 | int status; |
| 1590 | |
| 1591 | spin_lock_bh(&adapter->mcc_lock); |
| 1592 | |
| 1593 | wrb = wrb_from_mccq(adapter); |
| 1594 | if (!wrb) { |
| 1595 | status = -EBUSY; |
| 1596 | goto err; |
| 1597 | } |
| 1598 | req = embedded_payload(wrb); |
| 1599 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1600 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1601 | OPCODE_COMMON_MANAGE_FAT, sizeof(*req), wrb, NULL); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1602 | req->fat_operation = cpu_to_le32(QUERY_FAT); |
| 1603 | status = be_mcc_notify_wait(adapter); |
| 1604 | if (!status) { |
| 1605 | struct be_cmd_resp_get_fat *resp = embedded_payload(wrb); |
| 1606 | if (log_size && resp->log_size) |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1607 | *log_size = le32_to_cpu(resp->log_size) - |
| 1608 | sizeof(u32); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1609 | } |
| 1610 | err: |
| 1611 | spin_unlock_bh(&adapter->mcc_lock); |
| 1612 | return status; |
| 1613 | } |
| 1614 | |
| 1615 | void be_cmd_get_regs(struct be_adapter *adapter, u32 buf_len, void *buf) |
| 1616 | { |
| 1617 | struct be_dma_mem get_fat_cmd; |
| 1618 | struct be_mcc_wrb *wrb; |
| 1619 | struct be_cmd_req_get_fat *req; |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1620 | u32 offset = 0, total_size, buf_size, |
| 1621 | log_offset = sizeof(u32), payload_len; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1622 | int status; |
| 1623 | |
| 1624 | if (buf_len == 0) |
| 1625 | return; |
| 1626 | |
| 1627 | total_size = buf_len; |
| 1628 | |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1629 | get_fat_cmd.size = sizeof(struct be_cmd_req_get_fat) + 60*1024; |
| 1630 | get_fat_cmd.va = pci_alloc_consistent(adapter->pdev, |
| 1631 | get_fat_cmd.size, |
| 1632 | &get_fat_cmd.dma); |
| 1633 | if (!get_fat_cmd.va) { |
| 1634 | status = -ENOMEM; |
| 1635 | dev_err(&adapter->pdev->dev, |
| 1636 | "Memory allocation failure while retrieving FAT data\n"); |
| 1637 | return; |
| 1638 | } |
| 1639 | |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1640 | spin_lock_bh(&adapter->mcc_lock); |
| 1641 | |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1642 | while (total_size) { |
| 1643 | buf_size = min(total_size, (u32)60*1024); |
| 1644 | total_size -= buf_size; |
| 1645 | |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1646 | wrb = wrb_from_mccq(adapter); |
| 1647 | if (!wrb) { |
| 1648 | status = -EBUSY; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1649 | goto err; |
| 1650 | } |
| 1651 | req = get_fat_cmd.va; |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1652 | |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1653 | payload_len = sizeof(struct be_cmd_req_get_fat) + buf_size; |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1654 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1655 | OPCODE_COMMON_MANAGE_FAT, payload_len, wrb, |
| 1656 | &get_fat_cmd); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1657 | |
| 1658 | req->fat_operation = cpu_to_le32(RETRIEVE_FAT); |
| 1659 | req->read_log_offset = cpu_to_le32(log_offset); |
| 1660 | req->read_log_length = cpu_to_le32(buf_size); |
| 1661 | req->data_buffer_size = cpu_to_le32(buf_size); |
| 1662 | |
| 1663 | status = be_mcc_notify_wait(adapter); |
| 1664 | if (!status) { |
| 1665 | struct be_cmd_resp_get_fat *resp = get_fat_cmd.va; |
| 1666 | memcpy(buf + offset, |
| 1667 | resp->data_buffer, |
Somnath Kotur | 92aa921 | 2011-09-30 07:24:00 +0000 | [diff] [blame] | 1668 | le32_to_cpu(resp->read_log_length)); |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1669 | } else { |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1670 | dev_err(&adapter->pdev->dev, "FAT Table Retrieve error\n"); |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1671 | goto err; |
| 1672 | } |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1673 | offset += buf_size; |
| 1674 | log_offset += buf_size; |
| 1675 | } |
| 1676 | err: |
Somnath Kotur | fe2a70e | 2011-04-21 03:18:12 +0000 | [diff] [blame] | 1677 | pci_free_consistent(adapter->pdev, get_fat_cmd.size, |
| 1678 | get_fat_cmd.va, |
| 1679 | get_fat_cmd.dma); |
Somnath Kotur | 311fddc | 2011-03-16 21:22:43 +0000 | [diff] [blame] | 1680 | spin_unlock_bh(&adapter->mcc_lock); |
| 1681 | } |
| 1682 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1683 | /* Uses synchronous mcc */ |
| 1684 | int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver, |
| 1685 | char *fw_on_flash) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1686 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1687 | struct be_mcc_wrb *wrb; |
| 1688 | struct be_cmd_req_get_fw_version *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1689 | int status; |
| 1690 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1691 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1692 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1693 | wrb = wrb_from_mccq(adapter); |
| 1694 | if (!wrb) { |
| 1695 | status = -EBUSY; |
| 1696 | goto err; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1697 | } |
| 1698 | |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1699 | req = embedded_payload(wrb); |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1700 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1701 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1702 | OPCODE_COMMON_GET_FW_VERSION, sizeof(*req), wrb, NULL); |
Sathya Perla | 04b7117 | 2011-09-27 13:30:27 -0400 | [diff] [blame] | 1703 | status = be_mcc_notify_wait(adapter); |
| 1704 | if (!status) { |
| 1705 | struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb); |
| 1706 | strcpy(fw_ver, resp->firmware_version_string); |
| 1707 | if (fw_on_flash) |
| 1708 | strcpy(fw_on_flash, resp->fw_on_flash_version_string); |
| 1709 | } |
| 1710 | err: |
| 1711 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1712 | return status; |
| 1713 | } |
| 1714 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1715 | /* set the EQ delay interval of an EQ to specified value |
| 1716 | * Uses async mcc |
| 1717 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1718 | int be_cmd_modify_eqd(struct be_adapter *adapter, u32 eq_id, u32 eqd) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1719 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1720 | struct be_mcc_wrb *wrb; |
| 1721 | struct be_cmd_req_modify_eq_delay *req; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1722 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1723 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1724 | spin_lock_bh(&adapter->mcc_lock); |
| 1725 | |
| 1726 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1727 | if (!wrb) { |
| 1728 | status = -EBUSY; |
| 1729 | goto err; |
| 1730 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1731 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1732 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1733 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1734 | OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1735 | |
| 1736 | req->num_eq = cpu_to_le32(1); |
| 1737 | req->delay[0].eq_id = cpu_to_le32(eq_id); |
| 1738 | req->delay[0].phase = 0; |
| 1739 | req->delay[0].delay_multiplier = cpu_to_le32(eqd); |
| 1740 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1741 | be_mcc_notify(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1742 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1743 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1744 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1745 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1746 | } |
| 1747 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1748 | /* Uses sycnhronous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1749 | int be_cmd_vlan_config(struct be_adapter *adapter, u32 if_id, u16 *vtag_array, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1750 | u32 num, bool untagged, bool promiscuous) |
| 1751 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1752 | struct be_mcc_wrb *wrb; |
| 1753 | struct be_cmd_req_vlan_config *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1754 | int status; |
| 1755 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1756 | spin_lock_bh(&adapter->mcc_lock); |
| 1757 | |
| 1758 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1759 | if (!wrb) { |
| 1760 | status = -EBUSY; |
| 1761 | goto err; |
| 1762 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1763 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1764 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1765 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1766 | OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1767 | |
| 1768 | req->interface_id = if_id; |
| 1769 | req->promiscuous = promiscuous; |
| 1770 | req->untagged = untagged; |
| 1771 | req->num_vlan = num; |
| 1772 | if (!promiscuous) { |
| 1773 | memcpy(req->normal_vlan, vtag_array, |
| 1774 | req->num_vlan * sizeof(vtag_array[0])); |
| 1775 | } |
| 1776 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1777 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1778 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1779 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1780 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1781 | return status; |
| 1782 | } |
| 1783 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1784 | 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] | 1785 | { |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1786 | struct be_mcc_wrb *wrb; |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1787 | struct be_dma_mem *mem = &adapter->rx_filter; |
| 1788 | struct be_cmd_req_rx_filter *req = mem->va; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1789 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1790 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1791 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1792 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1793 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1794 | if (!wrb) { |
| 1795 | status = -EBUSY; |
| 1796 | goto err; |
| 1797 | } |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1798 | memset(req, 0, sizeof(*req)); |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1799 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1800 | OPCODE_COMMON_NTWK_RX_FILTER, sizeof(*req), |
| 1801 | wrb, mem); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1802 | |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1803 | req->if_id = cpu_to_le32(adapter->if_handle); |
| 1804 | if (flags & IFF_PROMISC) { |
| 1805 | req->if_flags_mask = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS | |
Ajit Khaparde | c5dae58 | 2013-05-01 09:38:24 +0000 | [diff] [blame] | 1806 | BE_IF_FLAGS_VLAN_PROMISCUOUS | |
| 1807 | BE_IF_FLAGS_MCAST_PROMISCUOUS); |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1808 | if (value == ON) |
| 1809 | req->if_flags = cpu_to_le32(BE_IF_FLAGS_PROMISCUOUS | |
Ajit Khaparde | c5dae58 | 2013-05-01 09:38:24 +0000 | [diff] [blame] | 1810 | BE_IF_FLAGS_VLAN_PROMISCUOUS | |
| 1811 | BE_IF_FLAGS_MCAST_PROMISCUOUS); |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1812 | } else if (flags & IFF_ALLMULTI) { |
| 1813 | req->if_flags_mask = req->if_flags = |
Sathya Perla | 8e7d3f6 | 2011-09-27 13:29:38 -0400 | [diff] [blame] | 1814 | cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1815 | } else { |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1816 | struct netdev_hw_addr *ha; |
| 1817 | int i = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1818 | |
Sathya Perla | 8e7d3f6 | 2011-09-27 13:29:38 -0400 | [diff] [blame] | 1819 | req->if_flags_mask = req->if_flags = |
| 1820 | cpu_to_le32(BE_IF_FLAGS_MULTICAST); |
Padmanabh Ratnakar | 1610c79 | 2011-11-03 01:49:27 +0000 | [diff] [blame] | 1821 | |
| 1822 | /* Reset mcast promisc mode if already set by setting mask |
| 1823 | * and not setting flags field |
| 1824 | */ |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 1825 | req->if_flags_mask |= |
| 1826 | cpu_to_le32(BE_IF_FLAGS_MCAST_PROMISCUOUS & |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 1827 | be_if_cap_flags(adapter)); |
Padmanabh Ratnakar | 016f97b | 2011-11-03 01:49:13 +0000 | [diff] [blame] | 1828 | req->mcast_num = cpu_to_le32(netdev_mc_count(adapter->netdev)); |
Sathya Perla | 5b8821b | 2011-08-02 19:57:44 +0000 | [diff] [blame] | 1829 | netdev_for_each_mc_addr(ha, adapter->netdev) |
| 1830 | memcpy(req->mcast_mac[i++].byte, ha->addr, ETH_ALEN); |
| 1831 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1832 | |
Sathya Perla | 0d1d587 | 2011-08-03 05:19:27 -0700 | [diff] [blame] | 1833 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1834 | err: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1835 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1836 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1839 | /* Uses synchrounous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1840 | 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] | 1841 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1842 | struct be_mcc_wrb *wrb; |
| 1843 | struct be_cmd_req_set_flow_control *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1844 | int status; |
| 1845 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 1846 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_SET_FLOW_CONTROL, |
| 1847 | CMD_SUBSYSTEM_COMMON)) |
| 1848 | return -EPERM; |
| 1849 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1850 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1851 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1852 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1853 | if (!wrb) { |
| 1854 | status = -EBUSY; |
| 1855 | goto err; |
| 1856 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1857 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1858 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1859 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1860 | OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1861 | |
| 1862 | req->tx_flow_control = cpu_to_le16((u16)tx_fc); |
| 1863 | req->rx_flow_control = cpu_to_le16((u16)rx_fc); |
| 1864 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1865 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1866 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1867 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1868 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1869 | return status; |
| 1870 | } |
| 1871 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1872 | /* Uses sycn mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1873 | 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] | 1874 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1875 | struct be_mcc_wrb *wrb; |
| 1876 | struct be_cmd_req_get_flow_control *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1877 | int status; |
| 1878 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 1879 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_FLOW_CONTROL, |
| 1880 | CMD_SUBSYSTEM_COMMON)) |
| 1881 | return -EPERM; |
| 1882 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1883 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1884 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1885 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1886 | if (!wrb) { |
| 1887 | status = -EBUSY; |
| 1888 | goto err; |
| 1889 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1890 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1891 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1892 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1893 | OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1894 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1895 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1896 | if (!status) { |
| 1897 | struct be_cmd_resp_get_flow_control *resp = |
| 1898 | embedded_payload(wrb); |
| 1899 | *tx_fc = le16_to_cpu(resp->tx_flow_control); |
| 1900 | *rx_fc = le16_to_cpu(resp->rx_flow_control); |
| 1901 | } |
| 1902 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1903 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1904 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1905 | return status; |
| 1906 | } |
| 1907 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1908 | /* Uses mbox */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1909 | int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num, |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 1910 | u32 *mode, u32 *caps, u16 *asic_rev) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1911 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1912 | struct be_mcc_wrb *wrb; |
| 1913 | struct be_cmd_req_query_fw_cfg *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1914 | int status; |
| 1915 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1916 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1917 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1918 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1919 | wrb = wrb_from_mbox(adapter); |
| 1920 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1921 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1922 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1923 | OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req), wrb, NULL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1924 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1925 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1926 | if (!status) { |
| 1927 | struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb); |
| 1928 | *port_num = le32_to_cpu(resp->phys_port); |
Ajit Khaparde | 3486be2 | 2010-07-23 02:04:54 +0000 | [diff] [blame] | 1929 | *mode = le32_to_cpu(resp->function_mode); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1930 | *caps = le32_to_cpu(resp->function_caps); |
Vasundhara Volam | 0ad3157 | 2013-04-21 23:28:16 +0000 | [diff] [blame] | 1931 | *asic_rev = le32_to_cpu(resp->asic_revision) & 0xFF; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1934 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1935 | return status; |
| 1936 | } |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1937 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1938 | /* Uses mbox */ |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1939 | int be_cmd_reset_function(struct be_adapter *adapter) |
| 1940 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1941 | struct be_mcc_wrb *wrb; |
| 1942 | struct be_cmd_req_hdr *req; |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1943 | int status; |
| 1944 | |
Padmanabh Ratnakar | bf99e50 | 2012-07-12 03:56:58 +0000 | [diff] [blame] | 1945 | if (lancer_chip(adapter)) { |
| 1946 | status = lancer_wait_ready(adapter); |
| 1947 | if (!status) { |
| 1948 | iowrite32(SLI_PORT_CONTROL_IP_MASK, |
| 1949 | adapter->db + SLIPORT_CONTROL_OFFSET); |
| 1950 | status = lancer_test_and_set_rdy_state(adapter); |
| 1951 | } |
| 1952 | if (status) { |
| 1953 | dev_err(&adapter->pdev->dev, |
| 1954 | "Adapter in non recoverable error\n"); |
| 1955 | } |
| 1956 | return status; |
| 1957 | } |
| 1958 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1959 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1960 | return -1; |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1961 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1962 | wrb = wrb_from_mbox(adapter); |
| 1963 | req = embedded_payload(wrb); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1964 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1965 | be_wrb_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON, |
| 1966 | OPCODE_COMMON_FUNCTION_RESET, sizeof(*req), wrb, NULL); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1967 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1968 | status = be_mbox_notify_wait(adapter); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1969 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1970 | mutex_unlock(&adapter->mbox_lock); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1971 | return status; |
| 1972 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1973 | |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 1974 | int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, |
| 1975 | u32 rss_hash_opts, u16 table_size) |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1976 | { |
| 1977 | struct be_mcc_wrb *wrb; |
| 1978 | struct be_cmd_req_rss_config *req; |
Padmanabh Ratnakar | 65f8584 | 2011-11-25 05:48:38 +0000 | [diff] [blame] | 1979 | u32 myhash[10] = {0x15d43fa5, 0x2534685a, 0x5f87693a, 0x5668494e, |
| 1980 | 0x33cf6a53, 0x383334c6, 0x76ac4257, 0x59b242b2, |
| 1981 | 0x3ea83c02, 0x4a110304}; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1982 | int status; |
| 1983 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1984 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1985 | return -1; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1986 | |
| 1987 | wrb = wrb_from_mbox(adapter); |
| 1988 | req = embedded_payload(wrb); |
| 1989 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 1990 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1991 | OPCODE_ETH_RSS_CONFIG, sizeof(*req), wrb, NULL); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1992 | |
| 1993 | req->if_id = cpu_to_le32(adapter->if_handle); |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 1994 | req->enable_rss = cpu_to_le16(rss_hash_opts); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1995 | req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1); |
Suresh Reddy | 594ad54 | 2013-04-25 23:03:20 +0000 | [diff] [blame] | 1996 | |
| 1997 | if (lancer_chip(adapter) || skyhawk_chip(adapter)) |
| 1998 | req->hdr.version = 1; |
| 1999 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2000 | memcpy(req->cpu_table, rsstable, table_size); |
| 2001 | memcpy(req->hash, myhash, sizeof(myhash)); |
| 2002 | be_dws_cpu_to_le(req->hash, sizeof(req->hash)); |
| 2003 | |
| 2004 | status = be_mbox_notify_wait(adapter); |
| 2005 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 2006 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 2007 | return status; |
| 2008 | } |
| 2009 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2010 | /* Uses sync mcc */ |
| 2011 | int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num, |
| 2012 | u8 bcn, u8 sts, u8 state) |
| 2013 | { |
| 2014 | struct be_mcc_wrb *wrb; |
| 2015 | struct be_cmd_req_enable_disable_beacon *req; |
| 2016 | int status; |
| 2017 | |
| 2018 | spin_lock_bh(&adapter->mcc_lock); |
| 2019 | |
| 2020 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2021 | if (!wrb) { |
| 2022 | status = -EBUSY; |
| 2023 | goto err; |
| 2024 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2025 | req = embedded_payload(wrb); |
| 2026 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2027 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2028 | OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req), wrb, NULL); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2029 | |
| 2030 | req->port_num = port_num; |
| 2031 | req->beacon_state = state; |
| 2032 | req->beacon_duration = bcn; |
| 2033 | req->status_duration = sts; |
| 2034 | |
| 2035 | status = be_mcc_notify_wait(adapter); |
| 2036 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2037 | err: |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2038 | spin_unlock_bh(&adapter->mcc_lock); |
| 2039 | return status; |
| 2040 | } |
| 2041 | |
| 2042 | /* Uses sync mcc */ |
| 2043 | int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state) |
| 2044 | { |
| 2045 | struct be_mcc_wrb *wrb; |
| 2046 | struct be_cmd_req_get_beacon_state *req; |
| 2047 | int status; |
| 2048 | |
| 2049 | spin_lock_bh(&adapter->mcc_lock); |
| 2050 | |
| 2051 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2052 | if (!wrb) { |
| 2053 | status = -EBUSY; |
| 2054 | goto err; |
| 2055 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2056 | req = embedded_payload(wrb); |
| 2057 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2058 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2059 | OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req), wrb, NULL); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2060 | |
| 2061 | req->port_num = port_num; |
| 2062 | |
| 2063 | status = be_mcc_notify_wait(adapter); |
| 2064 | if (!status) { |
| 2065 | struct be_cmd_resp_get_beacon_state *resp = |
| 2066 | embedded_payload(wrb); |
| 2067 | *state = resp->beacon_state; |
| 2068 | } |
| 2069 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2070 | err: |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 2071 | spin_unlock_bh(&adapter->mcc_lock); |
| 2072 | return status; |
| 2073 | } |
| 2074 | |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2075 | int lancer_cmd_write_object(struct be_adapter *adapter, struct be_dma_mem *cmd, |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2076 | u32 data_size, u32 data_offset, |
| 2077 | const char *obj_name, u32 *data_written, |
| 2078 | u8 *change_status, u8 *addn_status) |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2079 | { |
| 2080 | struct be_mcc_wrb *wrb; |
| 2081 | struct lancer_cmd_req_write_object *req; |
| 2082 | struct lancer_cmd_resp_write_object *resp; |
| 2083 | void *ctxt = NULL; |
| 2084 | int status; |
| 2085 | |
| 2086 | spin_lock_bh(&adapter->mcc_lock); |
| 2087 | adapter->flash_status = 0; |
| 2088 | |
| 2089 | wrb = wrb_from_mccq(adapter); |
| 2090 | if (!wrb) { |
| 2091 | status = -EBUSY; |
| 2092 | goto err_unlock; |
| 2093 | } |
| 2094 | |
| 2095 | req = embedded_payload(wrb); |
| 2096 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2097 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2098 | OPCODE_COMMON_WRITE_OBJECT, |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2099 | sizeof(struct lancer_cmd_req_write_object), wrb, |
| 2100 | NULL); |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2101 | |
| 2102 | ctxt = &req->context; |
| 2103 | AMAP_SET_BITS(struct amap_lancer_write_obj_context, |
| 2104 | write_length, ctxt, data_size); |
| 2105 | |
| 2106 | if (data_size == 0) |
| 2107 | AMAP_SET_BITS(struct amap_lancer_write_obj_context, |
| 2108 | eof, ctxt, 1); |
| 2109 | else |
| 2110 | AMAP_SET_BITS(struct amap_lancer_write_obj_context, |
| 2111 | eof, ctxt, 0); |
| 2112 | |
| 2113 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 2114 | req->write_offset = cpu_to_le32(data_offset); |
| 2115 | strcpy(req->object_name, obj_name); |
| 2116 | req->descriptor_count = cpu_to_le32(1); |
| 2117 | req->buf_len = cpu_to_le32(data_size); |
| 2118 | req->addr_low = cpu_to_le32((cmd->dma + |
| 2119 | sizeof(struct lancer_cmd_req_write_object)) |
| 2120 | & 0xFFFFFFFF); |
| 2121 | req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma + |
| 2122 | sizeof(struct lancer_cmd_req_write_object))); |
| 2123 | |
| 2124 | be_mcc_notify(adapter); |
| 2125 | spin_unlock_bh(&adapter->mcc_lock); |
| 2126 | |
| 2127 | if (!wait_for_completion_timeout(&adapter->flash_compl, |
Somnath Kotur | 701962d | 2013-05-02 03:36:34 +0000 | [diff] [blame] | 2128 | msecs_to_jiffies(60000))) |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2129 | status = -1; |
| 2130 | else |
| 2131 | status = adapter->flash_status; |
| 2132 | |
| 2133 | resp = embedded_payload(wrb); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2134 | if (!status) { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2135 | *data_written = le32_to_cpu(resp->actual_write_len); |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2136 | *change_status = resp->change_status; |
| 2137 | } else { |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2138 | *addn_status = resp->additional_status; |
Padmanabh Ratnakar | f67ef7b | 2012-07-12 03:57:09 +0000 | [diff] [blame] | 2139 | } |
Shripad Nunjundarao | 485bf56 | 2011-05-16 07:36:59 +0000 | [diff] [blame] | 2140 | |
| 2141 | return status; |
| 2142 | |
| 2143 | err_unlock: |
| 2144 | spin_unlock_bh(&adapter->mcc_lock); |
| 2145 | return status; |
| 2146 | } |
| 2147 | |
Padmanabh Ratnakar | de49bd5 | 2011-11-16 02:02:43 +0000 | [diff] [blame] | 2148 | int lancer_cmd_read_object(struct be_adapter *adapter, struct be_dma_mem *cmd, |
| 2149 | u32 data_size, u32 data_offset, const char *obj_name, |
| 2150 | u32 *data_read, u32 *eof, u8 *addn_status) |
| 2151 | { |
| 2152 | struct be_mcc_wrb *wrb; |
| 2153 | struct lancer_cmd_req_read_object *req; |
| 2154 | struct lancer_cmd_resp_read_object *resp; |
| 2155 | int status; |
| 2156 | |
| 2157 | spin_lock_bh(&adapter->mcc_lock); |
| 2158 | |
| 2159 | wrb = wrb_from_mccq(adapter); |
| 2160 | if (!wrb) { |
| 2161 | status = -EBUSY; |
| 2162 | goto err_unlock; |
| 2163 | } |
| 2164 | |
| 2165 | req = embedded_payload(wrb); |
| 2166 | |
| 2167 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2168 | OPCODE_COMMON_READ_OBJECT, |
| 2169 | sizeof(struct lancer_cmd_req_read_object), wrb, |
| 2170 | NULL); |
| 2171 | |
| 2172 | req->desired_read_len = cpu_to_le32(data_size); |
| 2173 | req->read_offset = cpu_to_le32(data_offset); |
| 2174 | strcpy(req->object_name, obj_name); |
| 2175 | req->descriptor_count = cpu_to_le32(1); |
| 2176 | req->buf_len = cpu_to_le32(data_size); |
| 2177 | req->addr_low = cpu_to_le32((cmd->dma & 0xFFFFFFFF)); |
| 2178 | req->addr_high = cpu_to_le32(upper_32_bits(cmd->dma)); |
| 2179 | |
| 2180 | status = be_mcc_notify_wait(adapter); |
| 2181 | |
| 2182 | resp = embedded_payload(wrb); |
| 2183 | if (!status) { |
| 2184 | *data_read = le32_to_cpu(resp->actual_read_len); |
| 2185 | *eof = le32_to_cpu(resp->eof); |
| 2186 | } else { |
| 2187 | *addn_status = resp->additional_status; |
| 2188 | } |
| 2189 | |
| 2190 | err_unlock: |
| 2191 | spin_unlock_bh(&adapter->mcc_lock); |
| 2192 | return status; |
| 2193 | } |
| 2194 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2195 | int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd, |
| 2196 | u32 flash_type, u32 flash_opcode, u32 buf_size) |
| 2197 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2198 | struct be_mcc_wrb *wrb; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2199 | struct be_cmd_write_flashrom *req; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2200 | int status; |
| 2201 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2202 | spin_lock_bh(&adapter->mcc_lock); |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2203 | adapter->flash_status = 0; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2204 | |
| 2205 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2206 | if (!wrb) { |
| 2207 | status = -EBUSY; |
Dan Carpenter | 2892d9c | 2010-05-26 04:46:35 +0000 | [diff] [blame] | 2208 | goto err_unlock; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2209 | } |
| 2210 | req = cmd->va; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 2211 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2212 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2213 | OPCODE_COMMON_WRITE_FLASHROM, cmd->size, wrb, cmd); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2214 | |
| 2215 | req->params.op_type = cpu_to_le32(flash_type); |
| 2216 | req->params.op_code = cpu_to_le32(flash_opcode); |
| 2217 | req->params.data_buf_size = cpu_to_le32(buf_size); |
| 2218 | |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2219 | be_mcc_notify(adapter); |
| 2220 | spin_unlock_bh(&adapter->mcc_lock); |
| 2221 | |
| 2222 | if (!wait_for_completion_timeout(&adapter->flash_compl, |
Sathya Perla | e2edb7d | 2011-08-22 19:41:54 +0000 | [diff] [blame] | 2223 | msecs_to_jiffies(40000))) |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 2224 | status = -1; |
| 2225 | else |
| 2226 | status = adapter->flash_status; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2227 | |
Dan Carpenter | 2892d9c | 2010-05-26 04:46:35 +0000 | [diff] [blame] | 2228 | return status; |
| 2229 | |
| 2230 | err_unlock: |
| 2231 | spin_unlock_bh(&adapter->mcc_lock); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 2232 | return status; |
| 2233 | } |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2234 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 2235 | int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc, |
| 2236 | int offset) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2237 | { |
| 2238 | struct be_mcc_wrb *wrb; |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 2239 | struct be_cmd_read_flash_crc *req; |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2240 | int status; |
| 2241 | |
| 2242 | spin_lock_bh(&adapter->mcc_lock); |
| 2243 | |
| 2244 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2245 | if (!wrb) { |
| 2246 | status = -EBUSY; |
| 2247 | goto err; |
| 2248 | } |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2249 | req = embedded_payload(wrb); |
| 2250 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2251 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 2252 | OPCODE_COMMON_READ_FLASHROM, sizeof(*req), |
| 2253 | wrb, NULL); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2254 | |
Padmanabh Ratnakar | c165541e | 2012-04-25 01:47:15 +0000 | [diff] [blame] | 2255 | req->params.op_type = cpu_to_le32(OPTYPE_REDBOOT); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2256 | req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT); |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 2257 | req->params.offset = cpu_to_le32(offset); |
| 2258 | req->params.data_buf_size = cpu_to_le32(0x4); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2259 | |
| 2260 | status = be_mcc_notify_wait(adapter); |
| 2261 | if (!status) |
Padmanabh Ratnakar | be71644 | 2012-10-22 23:02:44 +0000 | [diff] [blame] | 2262 | memcpy(flashed_crc, req->crc, 4); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2263 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 2264 | err: |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 2265 | spin_unlock_bh(&adapter->mcc_lock); |
| 2266 | return status; |
| 2267 | } |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2268 | |
Dan Carpenter | c196b02 | 2010-05-26 04:47:39 +0000 | [diff] [blame] | 2269 | int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac, |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2270 | struct be_dma_mem *nonemb_cmd) |
| 2271 | { |
| 2272 | struct be_mcc_wrb *wrb; |
| 2273 | struct be_cmd_req_acpi_wol_magic_config *req; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2274 | int status; |
| 2275 | |
| 2276 | spin_lock_bh(&adapter->mcc_lock); |
| 2277 | |
| 2278 | wrb = wrb_from_mccq(adapter); |
| 2279 | if (!wrb) { |
| 2280 | status = -EBUSY; |
| 2281 | goto err; |
| 2282 | } |
| 2283 | req = nonemb_cmd->va; |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2284 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2285 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 2286 | OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req), wrb, |
| 2287 | nonemb_cmd); |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2288 | memcpy(req->magic_mac, mac, ETH_ALEN); |
| 2289 | |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 2290 | status = be_mcc_notify_wait(adapter); |
| 2291 | |
| 2292 | err: |
| 2293 | spin_unlock_bh(&adapter->mcc_lock); |
| 2294 | return status; |
| 2295 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 2296 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 2297 | int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num, |
| 2298 | u8 loopback_type, u8 enable) |
| 2299 | { |
| 2300 | struct be_mcc_wrb *wrb; |
| 2301 | struct be_cmd_req_set_lmode *req; |
| 2302 | int status; |
| 2303 | |
| 2304 | spin_lock_bh(&adapter->mcc_lock); |
| 2305 | |
| 2306 | wrb = wrb_from_mccq(adapter); |
| 2307 | if (!wrb) { |
| 2308 | status = -EBUSY; |
| 2309 | goto err; |
| 2310 | } |
| 2311 | |
| 2312 | req = embedded_payload(wrb); |
| 2313 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2314 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
| 2315 | OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, sizeof(*req), wrb, |
| 2316 | NULL); |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 2317 | |
| 2318 | req->src_port = port_num; |
| 2319 | req->dest_port = port_num; |
| 2320 | req->loopback_type = loopback_type; |
| 2321 | req->loopback_state = enable; |
| 2322 | |
| 2323 | status = be_mcc_notify_wait(adapter); |
| 2324 | err: |
| 2325 | spin_unlock_bh(&adapter->mcc_lock); |
| 2326 | return status; |
| 2327 | } |
| 2328 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 2329 | int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num, |
| 2330 | u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern) |
| 2331 | { |
| 2332 | struct be_mcc_wrb *wrb; |
| 2333 | struct be_cmd_req_loopback_test *req; |
| 2334 | int status; |
| 2335 | |
| 2336 | spin_lock_bh(&adapter->mcc_lock); |
| 2337 | |
| 2338 | wrb = wrb_from_mccq(adapter); |
| 2339 | if (!wrb) { |
| 2340 | status = -EBUSY; |
| 2341 | goto err; |
| 2342 | } |
| 2343 | |
| 2344 | req = embedded_payload(wrb); |
| 2345 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2346 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
| 2347 | OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req), wrb, NULL); |
Sathya Perla | 3ffd051 | 2010-06-01 00:19:33 -0700 | [diff] [blame] | 2348 | req->hdr.timeout = cpu_to_le32(4); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 2349 | |
| 2350 | req->pattern = cpu_to_le64(pattern); |
| 2351 | req->src_port = cpu_to_le32(port_num); |
| 2352 | req->dest_port = cpu_to_le32(port_num); |
| 2353 | req->pkt_size = cpu_to_le32(pkt_size); |
| 2354 | req->num_pkts = cpu_to_le32(num_pkts); |
| 2355 | req->loopback_type = cpu_to_le32(loopback_type); |
| 2356 | |
| 2357 | status = be_mcc_notify_wait(adapter); |
| 2358 | if (!status) { |
| 2359 | struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb); |
| 2360 | status = le32_to_cpu(resp->status); |
| 2361 | } |
| 2362 | |
| 2363 | err: |
| 2364 | spin_unlock_bh(&adapter->mcc_lock); |
| 2365 | return status; |
| 2366 | } |
| 2367 | |
| 2368 | int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern, |
| 2369 | u32 byte_cnt, struct be_dma_mem *cmd) |
| 2370 | { |
| 2371 | struct be_mcc_wrb *wrb; |
| 2372 | struct be_cmd_req_ddrdma_test *req; |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 2373 | int status; |
| 2374 | int i, j = 0; |
| 2375 | |
| 2376 | spin_lock_bh(&adapter->mcc_lock); |
| 2377 | |
| 2378 | wrb = wrb_from_mccq(adapter); |
| 2379 | if (!wrb) { |
| 2380 | status = -EBUSY; |
| 2381 | goto err; |
| 2382 | } |
| 2383 | req = cmd->va; |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2384 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
| 2385 | OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size, wrb, cmd); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 2386 | |
| 2387 | req->pattern = cpu_to_le64(pattern); |
| 2388 | req->byte_count = cpu_to_le32(byte_cnt); |
| 2389 | for (i = 0; i < byte_cnt; i++) { |
| 2390 | req->snd_buff[i] = (u8)(pattern >> (j*8)); |
| 2391 | j++; |
| 2392 | if (j > 7) |
| 2393 | j = 0; |
| 2394 | } |
| 2395 | |
| 2396 | status = be_mcc_notify_wait(adapter); |
| 2397 | |
| 2398 | if (!status) { |
| 2399 | struct be_cmd_resp_ddrdma_test *resp; |
| 2400 | resp = cmd->va; |
| 2401 | if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) || |
| 2402 | resp->snd_err) { |
| 2403 | status = -1; |
| 2404 | } |
| 2405 | } |
| 2406 | |
| 2407 | err: |
| 2408 | spin_unlock_bh(&adapter->mcc_lock); |
| 2409 | return status; |
| 2410 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2411 | |
Dan Carpenter | c196b02 | 2010-05-26 04:47:39 +0000 | [diff] [blame] | 2412 | int be_cmd_get_seeprom_data(struct be_adapter *adapter, |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2413 | struct be_dma_mem *nonemb_cmd) |
| 2414 | { |
| 2415 | struct be_mcc_wrb *wrb; |
| 2416 | struct be_cmd_req_seeprom_read *req; |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2417 | int status; |
| 2418 | |
| 2419 | spin_lock_bh(&adapter->mcc_lock); |
| 2420 | |
| 2421 | wrb = wrb_from_mccq(adapter); |
Ajit Khaparde | e45ff01 | 2011-02-04 17:18:28 +0000 | [diff] [blame] | 2422 | if (!wrb) { |
| 2423 | status = -EBUSY; |
| 2424 | goto err; |
| 2425 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2426 | req = nonemb_cmd->va; |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2427 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2428 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2429 | OPCODE_COMMON_SEEPROM_READ, sizeof(*req), wrb, |
| 2430 | nonemb_cmd); |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2431 | |
| 2432 | status = be_mcc_notify_wait(adapter); |
| 2433 | |
Ajit Khaparde | e45ff01 | 2011-02-04 17:18:28 +0000 | [diff] [blame] | 2434 | err: |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 2435 | spin_unlock_bh(&adapter->mcc_lock); |
| 2436 | return status; |
| 2437 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2438 | |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 2439 | int be_cmd_get_phy_info(struct be_adapter *adapter) |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2440 | { |
| 2441 | struct be_mcc_wrb *wrb; |
| 2442 | struct be_cmd_req_get_phy_info *req; |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2443 | struct be_dma_mem cmd; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2444 | int status; |
| 2445 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 2446 | if (!be_cmd_allowed(adapter, OPCODE_COMMON_GET_PHY_DETAILS, |
| 2447 | CMD_SUBSYSTEM_COMMON)) |
| 2448 | return -EPERM; |
| 2449 | |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2450 | spin_lock_bh(&adapter->mcc_lock); |
| 2451 | |
| 2452 | wrb = wrb_from_mccq(adapter); |
| 2453 | if (!wrb) { |
| 2454 | status = -EBUSY; |
| 2455 | goto err; |
| 2456 | } |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2457 | cmd.size = sizeof(struct be_cmd_req_get_phy_info); |
| 2458 | cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, |
| 2459 | &cmd.dma); |
| 2460 | if (!cmd.va) { |
| 2461 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); |
| 2462 | status = -ENOMEM; |
| 2463 | goto err; |
| 2464 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2465 | |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2466 | req = cmd.va; |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2467 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2468 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2469 | OPCODE_COMMON_GET_PHY_DETAILS, sizeof(*req), |
| 2470 | wrb, &cmd); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2471 | |
| 2472 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2473 | if (!status) { |
| 2474 | struct be_phy_info *resp_phy_info = |
| 2475 | cmd.va + sizeof(struct be_cmd_req_hdr); |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 2476 | adapter->phy.phy_type = le16_to_cpu(resp_phy_info->phy_type); |
| 2477 | adapter->phy.interface_type = |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2478 | le16_to_cpu(resp_phy_info->interface_type); |
Ajit Khaparde | 42f11cf | 2012-04-21 18:53:22 +0000 | [diff] [blame] | 2479 | adapter->phy.auto_speeds_supported = |
| 2480 | le16_to_cpu(resp_phy_info->auto_speeds_supported); |
| 2481 | adapter->phy.fixed_speeds_supported = |
| 2482 | le16_to_cpu(resp_phy_info->fixed_speeds_supported); |
| 2483 | adapter->phy.misc_params = |
| 2484 | le32_to_cpu(resp_phy_info->misc_params); |
Vasundhara Volam | 68cb7e4 | 2013-08-06 09:27:18 +0530 | [diff] [blame] | 2485 | |
| 2486 | if (BE2_chip(adapter)) { |
| 2487 | adapter->phy.fixed_speeds_supported = |
| 2488 | BE_SUPPORTED_SPEED_10GBPS | |
| 2489 | BE_SUPPORTED_SPEED_1GBPS; |
| 2490 | } |
Sathya Perla | 306f134 | 2011-08-02 19:57:45 +0000 | [diff] [blame] | 2491 | } |
| 2492 | pci_free_consistent(adapter->pdev, cmd.size, |
| 2493 | cmd.va, cmd.dma); |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 2494 | err: |
| 2495 | spin_unlock_bh(&adapter->mcc_lock); |
| 2496 | return status; |
| 2497 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 2498 | |
| 2499 | int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain) |
| 2500 | { |
| 2501 | struct be_mcc_wrb *wrb; |
| 2502 | struct be_cmd_req_set_qos *req; |
| 2503 | int status; |
| 2504 | |
| 2505 | spin_lock_bh(&adapter->mcc_lock); |
| 2506 | |
| 2507 | wrb = wrb_from_mccq(adapter); |
| 2508 | if (!wrb) { |
| 2509 | status = -EBUSY; |
| 2510 | goto err; |
| 2511 | } |
| 2512 | |
| 2513 | req = embedded_payload(wrb); |
| 2514 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2515 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2516 | OPCODE_COMMON_SET_QOS, sizeof(*req), wrb, NULL); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 2517 | |
| 2518 | req->hdr.domain = domain; |
Ajit Khaparde | 6bff57a | 2011-02-11 13:33:02 +0000 | [diff] [blame] | 2519 | req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC); |
| 2520 | req->max_bps_nic = cpu_to_le32(bps); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 2521 | |
| 2522 | status = be_mcc_notify_wait(adapter); |
| 2523 | |
| 2524 | err: |
| 2525 | spin_unlock_bh(&adapter->mcc_lock); |
| 2526 | return status; |
| 2527 | } |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2528 | |
| 2529 | int be_cmd_get_cntl_attributes(struct be_adapter *adapter) |
| 2530 | { |
| 2531 | struct be_mcc_wrb *wrb; |
| 2532 | struct be_cmd_req_cntl_attribs *req; |
| 2533 | struct be_cmd_resp_cntl_attribs *resp; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2534 | int status; |
| 2535 | int payload_len = max(sizeof(*req), sizeof(*resp)); |
| 2536 | struct mgmt_controller_attrib *attribs; |
| 2537 | struct be_dma_mem attribs_cmd; |
| 2538 | |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 2539 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 2540 | return -1; |
| 2541 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2542 | memset(&attribs_cmd, 0, sizeof(struct be_dma_mem)); |
| 2543 | attribs_cmd.size = sizeof(struct be_cmd_resp_cntl_attribs); |
| 2544 | attribs_cmd.va = pci_alloc_consistent(adapter->pdev, attribs_cmd.size, |
| 2545 | &attribs_cmd.dma); |
| 2546 | if (!attribs_cmd.va) { |
| 2547 | dev_err(&adapter->pdev->dev, |
| 2548 | "Memory allocation failure\n"); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 2549 | status = -ENOMEM; |
| 2550 | goto err; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2551 | } |
| 2552 | |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2553 | wrb = wrb_from_mbox(adapter); |
| 2554 | if (!wrb) { |
| 2555 | status = -EBUSY; |
| 2556 | goto err; |
| 2557 | } |
| 2558 | req = attribs_cmd.va; |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2559 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2560 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2561 | OPCODE_COMMON_GET_CNTL_ATTRIBUTES, payload_len, wrb, |
| 2562 | &attribs_cmd); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2563 | |
| 2564 | status = be_mbox_notify_wait(adapter); |
| 2565 | if (!status) { |
Joe Perches | 43d620c | 2011-06-16 19:08:06 +0000 | [diff] [blame] | 2566 | attribs = attribs_cmd.va + sizeof(struct be_cmd_resp_hdr); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2567 | adapter->hba_port_num = attribs->hba_attribs.phy_port; |
| 2568 | } |
| 2569 | |
| 2570 | err: |
| 2571 | mutex_unlock(&adapter->mbox_lock); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 2572 | if (attribs_cmd.va) |
| 2573 | pci_free_consistent(adapter->pdev, attribs_cmd.size, |
| 2574 | attribs_cmd.va, attribs_cmd.dma); |
Ajit Khaparde | 9e1453c | 2011-02-20 11:42:22 +0000 | [diff] [blame] | 2575 | return status; |
| 2576 | } |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2577 | |
| 2578 | /* Uses mbox */ |
Sathya Perla | 2dc1deb | 2011-07-19 19:52:33 +0000 | [diff] [blame] | 2579 | int be_cmd_req_native_mode(struct be_adapter *adapter) |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2580 | { |
| 2581 | struct be_mcc_wrb *wrb; |
| 2582 | struct be_cmd_req_set_func_cap *req; |
| 2583 | int status; |
| 2584 | |
| 2585 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 2586 | return -1; |
| 2587 | |
| 2588 | wrb = wrb_from_mbox(adapter); |
| 2589 | if (!wrb) { |
| 2590 | status = -EBUSY; |
| 2591 | goto err; |
| 2592 | } |
| 2593 | |
| 2594 | req = embedded_payload(wrb); |
| 2595 | |
Somnath Kotur | 106df1e | 2011-10-27 07:12:13 +0000 | [diff] [blame] | 2596 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2597 | OPCODE_COMMON_SET_DRIVER_FUNCTION_CAP, sizeof(*req), wrb, NULL); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2598 | |
| 2599 | req->valid_cap_flags = cpu_to_le32(CAPABILITY_SW_TIMESTAMPS | |
| 2600 | CAPABILITY_BE3_NATIVE_ERX_API); |
| 2601 | req->cap_flags = cpu_to_le32(CAPABILITY_BE3_NATIVE_ERX_API); |
| 2602 | |
| 2603 | status = be_mbox_notify_wait(adapter); |
| 2604 | if (!status) { |
| 2605 | struct be_cmd_resp_set_func_cap *resp = embedded_payload(wrb); |
| 2606 | adapter->be3_native = le32_to_cpu(resp->cap_flags) & |
| 2607 | CAPABILITY_BE3_NATIVE_ERX_API; |
Sathya Perla | d379142 | 2012-09-28 04:39:44 +0000 | [diff] [blame] | 2608 | if (!adapter->be3_native) |
| 2609 | dev_warn(&adapter->pdev->dev, |
| 2610 | "adapter not in advanced mode\n"); |
Sathya Perla | 2e588f8 | 2011-03-11 02:49:26 +0000 | [diff] [blame] | 2611 | } |
| 2612 | err: |
| 2613 | mutex_unlock(&adapter->mbox_lock); |
| 2614 | return status; |
| 2615 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2616 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 2617 | /* Get privilege(s) for a function */ |
| 2618 | int be_cmd_get_fn_privileges(struct be_adapter *adapter, u32 *privilege, |
| 2619 | u32 domain) |
| 2620 | { |
| 2621 | struct be_mcc_wrb *wrb; |
| 2622 | struct be_cmd_req_get_fn_privileges *req; |
| 2623 | int status; |
| 2624 | |
| 2625 | spin_lock_bh(&adapter->mcc_lock); |
| 2626 | |
| 2627 | wrb = wrb_from_mccq(adapter); |
| 2628 | if (!wrb) { |
| 2629 | status = -EBUSY; |
| 2630 | goto err; |
| 2631 | } |
| 2632 | |
| 2633 | req = embedded_payload(wrb); |
| 2634 | |
| 2635 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2636 | OPCODE_COMMON_GET_FN_PRIVILEGES, sizeof(*req), |
| 2637 | wrb, NULL); |
| 2638 | |
| 2639 | req->hdr.domain = domain; |
| 2640 | |
| 2641 | status = be_mcc_notify_wait(adapter); |
| 2642 | if (!status) { |
| 2643 | struct be_cmd_resp_get_fn_privileges *resp = |
| 2644 | embedded_payload(wrb); |
| 2645 | *privilege = le32_to_cpu(resp->privilege_mask); |
| 2646 | } |
| 2647 | |
| 2648 | err: |
| 2649 | spin_unlock_bh(&adapter->mcc_lock); |
| 2650 | return status; |
| 2651 | } |
| 2652 | |
Sathya Perla | 04a0602 | 2013-07-23 15:25:00 +0530 | [diff] [blame] | 2653 | /* Set privilege(s) for a function */ |
| 2654 | int be_cmd_set_fn_privileges(struct be_adapter *adapter, u32 privileges, |
| 2655 | u32 domain) |
| 2656 | { |
| 2657 | struct be_mcc_wrb *wrb; |
| 2658 | struct be_cmd_req_set_fn_privileges *req; |
| 2659 | int status; |
| 2660 | |
| 2661 | spin_lock_bh(&adapter->mcc_lock); |
| 2662 | |
| 2663 | wrb = wrb_from_mccq(adapter); |
| 2664 | if (!wrb) { |
| 2665 | status = -EBUSY; |
| 2666 | goto err; |
| 2667 | } |
| 2668 | |
| 2669 | req = embedded_payload(wrb); |
| 2670 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2671 | OPCODE_COMMON_SET_FN_PRIVILEGES, sizeof(*req), |
| 2672 | wrb, NULL); |
| 2673 | req->hdr.domain = domain; |
| 2674 | if (lancer_chip(adapter)) |
| 2675 | req->privileges_lancer = cpu_to_le32(privileges); |
| 2676 | else |
| 2677 | req->privileges = cpu_to_le32(privileges); |
| 2678 | |
| 2679 | status = be_mcc_notify_wait(adapter); |
| 2680 | err: |
| 2681 | spin_unlock_bh(&adapter->mcc_lock); |
| 2682 | return status; |
| 2683 | } |
| 2684 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2685 | /* pmac_id_valid: true => pmac_id is supplied and MAC address is requested. |
| 2686 | * pmac_id_valid: false => pmac_id or MAC address is requested. |
| 2687 | * If pmac_id is returned, pmac_id_valid is returned as true |
| 2688 | */ |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 2689 | int be_cmd_get_mac_from_list(struct be_adapter *adapter, u8 *mac, |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2690 | bool *pmac_id_valid, u32 *pmac_id, u8 domain) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2691 | { |
| 2692 | struct be_mcc_wrb *wrb; |
| 2693 | struct be_cmd_req_get_mac_list *req; |
| 2694 | int status; |
| 2695 | int mac_count; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2696 | struct be_dma_mem get_mac_list_cmd; |
| 2697 | int i; |
| 2698 | |
| 2699 | memset(&get_mac_list_cmd, 0, sizeof(struct be_dma_mem)); |
| 2700 | get_mac_list_cmd.size = sizeof(struct be_cmd_resp_get_mac_list); |
| 2701 | get_mac_list_cmd.va = pci_alloc_consistent(adapter->pdev, |
| 2702 | get_mac_list_cmd.size, |
| 2703 | &get_mac_list_cmd.dma); |
| 2704 | |
| 2705 | if (!get_mac_list_cmd.va) { |
| 2706 | dev_err(&adapter->pdev->dev, |
| 2707 | "Memory allocation failure during GET_MAC_LIST\n"); |
| 2708 | return -ENOMEM; |
| 2709 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2710 | |
| 2711 | spin_lock_bh(&adapter->mcc_lock); |
| 2712 | |
| 2713 | wrb = wrb_from_mccq(adapter); |
| 2714 | if (!wrb) { |
| 2715 | status = -EBUSY; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2716 | goto out; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2717 | } |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2718 | |
| 2719 | req = get_mac_list_cmd.va; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2720 | |
| 2721 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Sathya Perla | bf591f5 | 2013-05-08 02:05:48 +0000 | [diff] [blame] | 2722 | OPCODE_COMMON_GET_MAC_LIST, |
| 2723 | get_mac_list_cmd.size, wrb, &get_mac_list_cmd); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2724 | req->hdr.domain = domain; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2725 | req->mac_type = MAC_ADDRESS_TYPE_NETWORK; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2726 | if (*pmac_id_valid) { |
| 2727 | req->mac_id = cpu_to_le32(*pmac_id); |
| 2728 | req->iface_id = cpu_to_le16(adapter->if_handle); |
| 2729 | req->perm_override = 0; |
| 2730 | } else { |
| 2731 | req->perm_override = 1; |
| 2732 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2733 | |
| 2734 | status = be_mcc_notify_wait(adapter); |
| 2735 | if (!status) { |
| 2736 | struct be_cmd_resp_get_mac_list *resp = |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2737 | get_mac_list_cmd.va; |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2738 | |
| 2739 | if (*pmac_id_valid) { |
| 2740 | memcpy(mac, resp->macid_macaddr.mac_addr_id.macaddr, |
| 2741 | ETH_ALEN); |
| 2742 | goto out; |
| 2743 | } |
| 2744 | |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2745 | mac_count = resp->true_mac_count + resp->pseudo_mac_count; |
| 2746 | /* Mac list returned could contain one or more active mac_ids |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 2747 | * or one or more true or pseudo permanant mac addresses. |
| 2748 | * If an active mac_id is present, return first active mac_id |
| 2749 | * found. |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2750 | */ |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2751 | for (i = 0; i < mac_count; i++) { |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2752 | struct get_list_macaddr *mac_entry; |
| 2753 | u16 mac_addr_size; |
| 2754 | u32 mac_id; |
| 2755 | |
| 2756 | mac_entry = &resp->macaddr_list[i]; |
| 2757 | mac_addr_size = le16_to_cpu(mac_entry->mac_addr_size); |
| 2758 | /* mac_id is a 32 bit value and mac_addr size |
| 2759 | * is 6 bytes |
| 2760 | */ |
| 2761 | if (mac_addr_size == sizeof(u32)) { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2762 | *pmac_id_valid = true; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2763 | mac_id = mac_entry->mac_addr_id.s_mac_id.mac_id; |
| 2764 | *pmac_id = le32_to_cpu(mac_id); |
| 2765 | goto out; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2766 | } |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2767 | } |
Padmanabh Ratnakar | 1578e77 | 2012-06-07 04:37:08 +0000 | [diff] [blame] | 2768 | /* If no active mac_id found, return first mac addr */ |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2769 | *pmac_id_valid = false; |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2770 | memcpy(mac, resp->macaddr_list[0].mac_addr_id.macaddr, |
| 2771 | ETH_ALEN); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2772 | } |
| 2773 | |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2774 | out: |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2775 | spin_unlock_bh(&adapter->mcc_lock); |
Padmanabh Ratnakar | e5e1ee8 | 2012-02-03 09:50:17 +0000 | [diff] [blame] | 2776 | pci_free_consistent(adapter->pdev, get_mac_list_cmd.size, |
| 2777 | get_mac_list_cmd.va, get_mac_list_cmd.dma); |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2778 | return status; |
| 2779 | } |
| 2780 | |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2781 | int be_cmd_get_active_mac(struct be_adapter *adapter, u32 curr_pmac_id, u8 *mac) |
| 2782 | { |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2783 | bool active = true; |
| 2784 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2785 | if (BEx_chip(adapter)) |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2786 | return be_cmd_mac_addr_query(adapter, mac, false, |
| 2787 | adapter->if_handle, curr_pmac_id); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2788 | else |
| 2789 | /* Fetch the MAC address using pmac_id */ |
| 2790 | return be_cmd_get_mac_from_list(adapter, mac, &active, |
| 2791 | &curr_pmac_id, 0); |
Sathya Perla | 5a712c1 | 2013-07-23 15:24:59 +0530 | [diff] [blame] | 2792 | } |
| 2793 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 2794 | int be_cmd_get_perm_mac(struct be_adapter *adapter, u8 *mac) |
| 2795 | { |
| 2796 | int status; |
| 2797 | bool pmac_valid = false; |
| 2798 | |
| 2799 | memset(mac, 0, ETH_ALEN); |
| 2800 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2801 | if (BEx_chip(adapter)) { |
| 2802 | if (be_physfn(adapter)) |
| 2803 | status = be_cmd_mac_addr_query(adapter, mac, true, 0, |
| 2804 | 0); |
| 2805 | else |
| 2806 | status = be_cmd_mac_addr_query(adapter, mac, false, |
| 2807 | adapter->if_handle, 0); |
| 2808 | } else { |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 2809 | status = be_cmd_get_mac_from_list(adapter, mac, &pmac_valid, |
| 2810 | NULL, 0); |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2811 | } |
| 2812 | |
Sathya Perla | 95046b9 | 2013-07-23 15:25:02 +0530 | [diff] [blame] | 2813 | return status; |
| 2814 | } |
| 2815 | |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2816 | /* Uses synchronous MCCQ */ |
| 2817 | int be_cmd_set_mac_list(struct be_adapter *adapter, u8 *mac_array, |
| 2818 | u8 mac_count, u32 domain) |
| 2819 | { |
| 2820 | struct be_mcc_wrb *wrb; |
| 2821 | struct be_cmd_req_set_mac_list *req; |
| 2822 | int status; |
| 2823 | struct be_dma_mem cmd; |
| 2824 | |
| 2825 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
| 2826 | cmd.size = sizeof(struct be_cmd_req_set_mac_list); |
| 2827 | cmd.va = dma_alloc_coherent(&adapter->pdev->dev, cmd.size, |
| 2828 | &cmd.dma, GFP_KERNEL); |
Joe Perches | d0320f7 | 2013-03-14 13:07:21 +0000 | [diff] [blame] | 2829 | if (!cmd.va) |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2830 | return -ENOMEM; |
Padmanabh Ratnakar | 590c391 | 2011-11-25 05:47:26 +0000 | [diff] [blame] | 2831 | |
| 2832 | spin_lock_bh(&adapter->mcc_lock); |
| 2833 | |
| 2834 | wrb = wrb_from_mccq(adapter); |
| 2835 | if (!wrb) { |
| 2836 | status = -EBUSY; |
| 2837 | goto err; |
| 2838 | } |
| 2839 | |
| 2840 | req = cmd.va; |
| 2841 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2842 | OPCODE_COMMON_SET_MAC_LIST, sizeof(*req), |
| 2843 | wrb, &cmd); |
| 2844 | |
| 2845 | req->hdr.domain = domain; |
| 2846 | req->mac_count = mac_count; |
| 2847 | if (mac_count) |
| 2848 | memcpy(req->mac, mac_array, ETH_ALEN*mac_count); |
| 2849 | |
| 2850 | status = be_mcc_notify_wait(adapter); |
| 2851 | |
| 2852 | err: |
| 2853 | dma_free_coherent(&adapter->pdev->dev, cmd.size, |
| 2854 | cmd.va, cmd.dma); |
| 2855 | spin_unlock_bh(&adapter->mcc_lock); |
| 2856 | return status; |
| 2857 | } |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 2858 | |
Sathya Perla | 3175d8c | 2013-07-23 15:25:03 +0530 | [diff] [blame] | 2859 | /* Wrapper to delete any active MACs and provision the new mac. |
| 2860 | * Changes to MAC_LIST are allowed iff none of the MAC addresses in the |
| 2861 | * current list are active. |
| 2862 | */ |
| 2863 | int be_cmd_set_mac(struct be_adapter *adapter, u8 *mac, int if_id, u32 dom) |
| 2864 | { |
| 2865 | bool active_mac = false; |
| 2866 | u8 old_mac[ETH_ALEN]; |
| 2867 | u32 pmac_id; |
| 2868 | int status; |
| 2869 | |
| 2870 | status = be_cmd_get_mac_from_list(adapter, old_mac, &active_mac, |
| 2871 | &pmac_id, dom); |
| 2872 | if (!status && active_mac) |
| 2873 | be_cmd_pmac_del(adapter, if_id, pmac_id, dom); |
| 2874 | |
| 2875 | return be_cmd_set_mac_list(adapter, mac, mac ? 1 : 0, dom); |
| 2876 | } |
| 2877 | |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2878 | int be_cmd_set_hsw_config(struct be_adapter *adapter, u16 pvid, |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame^] | 2879 | u32 domain, u16 intf_id, u16 hsw_mode) |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2880 | { |
| 2881 | struct be_mcc_wrb *wrb; |
| 2882 | struct be_cmd_req_set_hsw_config *req; |
| 2883 | void *ctxt; |
| 2884 | int status; |
| 2885 | |
| 2886 | spin_lock_bh(&adapter->mcc_lock); |
| 2887 | |
| 2888 | wrb = wrb_from_mccq(adapter); |
| 2889 | if (!wrb) { |
| 2890 | status = -EBUSY; |
| 2891 | goto err; |
| 2892 | } |
| 2893 | |
| 2894 | req = embedded_payload(wrb); |
| 2895 | ctxt = &req->context; |
| 2896 | |
| 2897 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2898 | OPCODE_COMMON_SET_HSW_CONFIG, sizeof(*req), wrb, NULL); |
| 2899 | |
| 2900 | req->hdr.domain = domain; |
| 2901 | AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, ctxt, intf_id); |
| 2902 | if (pvid) { |
| 2903 | AMAP_SET_BITS(struct amap_set_hsw_context, pvid_valid, ctxt, 1); |
| 2904 | AMAP_SET_BITS(struct amap_set_hsw_context, pvid, ctxt, pvid); |
| 2905 | } |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame^] | 2906 | if (!BEx_chip(adapter) && hsw_mode) { |
| 2907 | AMAP_SET_BITS(struct amap_set_hsw_context, interface_id, |
| 2908 | ctxt, adapter->hba_port_num); |
| 2909 | AMAP_SET_BITS(struct amap_set_hsw_context, pport, ctxt, 1); |
| 2910 | AMAP_SET_BITS(struct amap_set_hsw_context, port_fwd_type, |
| 2911 | ctxt, hsw_mode); |
| 2912 | } |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2913 | |
| 2914 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 2915 | status = be_mcc_notify_wait(adapter); |
| 2916 | |
| 2917 | err: |
| 2918 | spin_unlock_bh(&adapter->mcc_lock); |
| 2919 | return status; |
| 2920 | } |
| 2921 | |
| 2922 | /* Get Hyper switch config */ |
| 2923 | int be_cmd_get_hsw_config(struct be_adapter *adapter, u16 *pvid, |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame^] | 2924 | u32 domain, u16 intf_id, u8 *mode) |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2925 | { |
| 2926 | struct be_mcc_wrb *wrb; |
| 2927 | struct be_cmd_req_get_hsw_config *req; |
| 2928 | void *ctxt; |
| 2929 | int status; |
| 2930 | u16 vid; |
| 2931 | |
| 2932 | spin_lock_bh(&adapter->mcc_lock); |
| 2933 | |
| 2934 | wrb = wrb_from_mccq(adapter); |
| 2935 | if (!wrb) { |
| 2936 | status = -EBUSY; |
| 2937 | goto err; |
| 2938 | } |
| 2939 | |
| 2940 | req = embedded_payload(wrb); |
| 2941 | ctxt = &req->context; |
| 2942 | |
| 2943 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 2944 | OPCODE_COMMON_GET_HSW_CONFIG, sizeof(*req), wrb, NULL); |
| 2945 | |
| 2946 | req->hdr.domain = domain; |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame^] | 2947 | AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, |
| 2948 | ctxt, intf_id); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2949 | 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^] | 2950 | |
| 2951 | if (!BEx_chip(adapter)) { |
| 2952 | AMAP_SET_BITS(struct amap_get_hsw_req_context, interface_id, |
| 2953 | ctxt, adapter->hba_port_num); |
| 2954 | AMAP_SET_BITS(struct amap_get_hsw_req_context, pport, ctxt, 1); |
| 2955 | } |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2956 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 2957 | |
| 2958 | status = be_mcc_notify_wait(adapter); |
| 2959 | if (!status) { |
| 2960 | struct be_cmd_resp_get_hsw_config *resp = |
| 2961 | embedded_payload(wrb); |
| 2962 | be_dws_le_to_cpu(&resp->context, |
| 2963 | sizeof(resp->context)); |
| 2964 | vid = AMAP_GET_BITS(struct amap_get_hsw_resp_context, |
| 2965 | pvid, &resp->context); |
Ajit Khaparde | a77dcb8 | 2013-08-30 15:01:16 -0500 | [diff] [blame^] | 2966 | if (pvid) |
| 2967 | *pvid = le16_to_cpu(vid); |
| 2968 | if (mode) |
| 2969 | *mode = AMAP_GET_BITS(struct amap_get_hsw_resp_context, |
| 2970 | port_fwd_type, &resp->context); |
Ajit Khaparde | f1f3ee1 | 2012-03-18 06:23:41 +0000 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | err: |
| 2974 | spin_unlock_bh(&adapter->mcc_lock); |
| 2975 | return status; |
| 2976 | } |
| 2977 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 2978 | int be_cmd_get_acpi_wol_cap(struct be_adapter *adapter) |
| 2979 | { |
| 2980 | struct be_mcc_wrb *wrb; |
| 2981 | struct be_cmd_req_acpi_wol_magic_config_v1 *req; |
| 2982 | int status; |
| 2983 | int payload_len = sizeof(*req); |
| 2984 | struct be_dma_mem cmd; |
| 2985 | |
Padmanabh Ratnakar | f25b119 | 2012-10-20 06:02:52 +0000 | [diff] [blame] | 2986 | if (!be_cmd_allowed(adapter, OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, |
| 2987 | CMD_SUBSYSTEM_ETH)) |
| 2988 | return -EPERM; |
| 2989 | |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 2990 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 2991 | return -1; |
| 2992 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 2993 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
| 2994 | cmd.size = sizeof(struct be_cmd_resp_acpi_wol_magic_config_v1); |
| 2995 | cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, |
| 2996 | &cmd.dma); |
| 2997 | if (!cmd.va) { |
| 2998 | dev_err(&adapter->pdev->dev, |
| 2999 | "Memory allocation failure\n"); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3000 | status = -ENOMEM; |
| 3001 | goto err; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 3002 | } |
| 3003 | |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 3004 | wrb = wrb_from_mbox(adapter); |
| 3005 | if (!wrb) { |
| 3006 | status = -EBUSY; |
| 3007 | goto err; |
| 3008 | } |
| 3009 | |
| 3010 | req = cmd.va; |
| 3011 | |
| 3012 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 3013 | OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, |
| 3014 | payload_len, wrb, &cmd); |
| 3015 | |
| 3016 | req->hdr.version = 1; |
| 3017 | req->query_options = BE_GET_WOL_CAP; |
| 3018 | |
| 3019 | status = be_mbox_notify_wait(adapter); |
| 3020 | if (!status) { |
| 3021 | struct be_cmd_resp_acpi_wol_magic_config_v1 *resp; |
| 3022 | resp = (struct be_cmd_resp_acpi_wol_magic_config_v1 *) cmd.va; |
| 3023 | |
| 3024 | /* the command could succeed misleadingly on old f/w |
| 3025 | * which is not aware of the V1 version. fake an error. */ |
| 3026 | if (resp->hdr.response_length < payload_len) { |
| 3027 | status = -1; |
| 3028 | goto err; |
| 3029 | } |
| 3030 | adapter->wol_cap = resp->wol_settings; |
| 3031 | } |
| 3032 | err: |
| 3033 | mutex_unlock(&adapter->mbox_lock); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3034 | if (cmd.va) |
| 3035 | pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma); |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 3036 | return status; |
Somnath Kotur | 941a77d | 2012-05-17 22:59:03 +0000 | [diff] [blame] | 3037 | |
| 3038 | } |
| 3039 | int be_cmd_get_ext_fat_capabilites(struct be_adapter *adapter, |
| 3040 | struct be_dma_mem *cmd) |
| 3041 | { |
| 3042 | struct be_mcc_wrb *wrb; |
| 3043 | struct be_cmd_req_get_ext_fat_caps *req; |
| 3044 | int status; |
| 3045 | |
| 3046 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 3047 | return -1; |
| 3048 | |
| 3049 | wrb = wrb_from_mbox(adapter); |
| 3050 | if (!wrb) { |
| 3051 | status = -EBUSY; |
| 3052 | goto err; |
| 3053 | } |
| 3054 | |
| 3055 | req = cmd->va; |
| 3056 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3057 | OPCODE_COMMON_GET_EXT_FAT_CAPABILITES, |
| 3058 | cmd->size, wrb, cmd); |
| 3059 | req->parameter_type = cpu_to_le32(1); |
| 3060 | |
| 3061 | status = be_mbox_notify_wait(adapter); |
| 3062 | err: |
| 3063 | mutex_unlock(&adapter->mbox_lock); |
| 3064 | return status; |
| 3065 | } |
| 3066 | |
| 3067 | int be_cmd_set_ext_fat_capabilites(struct be_adapter *adapter, |
| 3068 | struct be_dma_mem *cmd, |
| 3069 | struct be_fat_conf_params *configs) |
| 3070 | { |
| 3071 | struct be_mcc_wrb *wrb; |
| 3072 | struct be_cmd_req_set_ext_fat_caps *req; |
| 3073 | int status; |
| 3074 | |
| 3075 | spin_lock_bh(&adapter->mcc_lock); |
| 3076 | |
| 3077 | wrb = wrb_from_mccq(adapter); |
| 3078 | if (!wrb) { |
| 3079 | status = -EBUSY; |
| 3080 | goto err; |
| 3081 | } |
| 3082 | |
| 3083 | req = cmd->va; |
| 3084 | memcpy(&req->set_params, configs, sizeof(struct be_fat_conf_params)); |
| 3085 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3086 | OPCODE_COMMON_SET_EXT_FAT_CAPABILITES, |
| 3087 | cmd->size, wrb, cmd); |
| 3088 | |
| 3089 | status = be_mcc_notify_wait(adapter); |
| 3090 | err: |
| 3091 | spin_unlock_bh(&adapter->mcc_lock); |
| 3092 | return status; |
Ajit Khaparde | 4762f6c | 2012-03-18 06:23:11 +0000 | [diff] [blame] | 3093 | } |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 3094 | |
Padmanabh Ratnakar | b4e32a7 | 2012-07-12 03:57:35 +0000 | [diff] [blame] | 3095 | int be_cmd_query_port_name(struct be_adapter *adapter, u8 *port_name) |
| 3096 | { |
| 3097 | struct be_mcc_wrb *wrb; |
| 3098 | struct be_cmd_req_get_port_name *req; |
| 3099 | int status; |
| 3100 | |
| 3101 | if (!lancer_chip(adapter)) { |
| 3102 | *port_name = adapter->hba_port_num + '0'; |
| 3103 | return 0; |
| 3104 | } |
| 3105 | |
| 3106 | spin_lock_bh(&adapter->mcc_lock); |
| 3107 | |
| 3108 | wrb = wrb_from_mccq(adapter); |
| 3109 | if (!wrb) { |
| 3110 | status = -EBUSY; |
| 3111 | goto err; |
| 3112 | } |
| 3113 | |
| 3114 | req = embedded_payload(wrb); |
| 3115 | |
| 3116 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3117 | OPCODE_COMMON_GET_PORT_NAME, sizeof(*req), wrb, |
| 3118 | NULL); |
| 3119 | req->hdr.version = 1; |
| 3120 | |
| 3121 | status = be_mcc_notify_wait(adapter); |
| 3122 | if (!status) { |
| 3123 | struct be_cmd_resp_get_port_name *resp = embedded_payload(wrb); |
| 3124 | *port_name = resp->port_name[adapter->hba_port_num]; |
| 3125 | } else { |
| 3126 | *port_name = adapter->hba_port_num + '0'; |
| 3127 | } |
| 3128 | err: |
| 3129 | spin_unlock_bh(&adapter->mcc_lock); |
| 3130 | return status; |
| 3131 | } |
| 3132 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3133 | static struct be_nic_res_desc *be_get_nic_desc(u8 *buf, u32 desc_count) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3134 | { |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3135 | struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3136 | int i; |
| 3137 | |
| 3138 | for (i = 0; i < desc_count; i++) { |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3139 | if (hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V0 || |
| 3140 | hdr->desc_type == NIC_RESOURCE_DESC_TYPE_V1) |
| 3141 | return (struct be_nic_res_desc *)hdr; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3142 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3143 | hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0; |
| 3144 | hdr = (void *)hdr + hdr->desc_len; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3145 | } |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3146 | return NULL; |
| 3147 | } |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3148 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3149 | static struct be_pcie_res_desc *be_get_pcie_desc(u8 devfn, u8 *buf, |
| 3150 | u32 desc_count) |
| 3151 | { |
| 3152 | struct be_res_desc_hdr *hdr = (struct be_res_desc_hdr *)buf; |
| 3153 | struct be_pcie_res_desc *pcie; |
| 3154 | int i; |
| 3155 | |
| 3156 | for (i = 0; i < desc_count; i++) { |
| 3157 | if ((hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V0 || |
| 3158 | hdr->desc_type == PCIE_RESOURCE_DESC_TYPE_V1)) { |
| 3159 | pcie = (struct be_pcie_res_desc *)hdr; |
| 3160 | if (pcie->pf_num == devfn) |
| 3161 | return pcie; |
| 3162 | } |
| 3163 | |
| 3164 | hdr->desc_len = hdr->desc_len ? : RESOURCE_DESC_SIZE_V0; |
| 3165 | hdr = (void *)hdr + hdr->desc_len; |
| 3166 | } |
Wei Yang | 950e295 | 2013-05-22 15:58:22 +0000 | [diff] [blame] | 3167 | return NULL; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3170 | static void be_copy_nic_desc(struct be_resources *res, |
| 3171 | struct be_nic_res_desc *desc) |
| 3172 | { |
| 3173 | res->max_uc_mac = le16_to_cpu(desc->unicast_mac_count); |
| 3174 | res->max_vlans = le16_to_cpu(desc->vlan_count); |
| 3175 | res->max_mcast_mac = le16_to_cpu(desc->mcast_mac_count); |
| 3176 | res->max_tx_qs = le16_to_cpu(desc->txq_count); |
| 3177 | res->max_rss_qs = le16_to_cpu(desc->rssq_count); |
| 3178 | res->max_rx_qs = le16_to_cpu(desc->rq_count); |
| 3179 | res->max_evt_qs = le16_to_cpu(desc->eq_count); |
| 3180 | /* Clear flags that driver is not interested in */ |
| 3181 | res->if_cap_flags = le32_to_cpu(desc->cap_flags) & |
| 3182 | BE_IF_CAP_FLAGS_WANT; |
| 3183 | /* Need 1 RXQ as the default RXQ */ |
| 3184 | if (res->max_rss_qs && res->max_rss_qs == res->max_rx_qs) |
| 3185 | res->max_rss_qs -= 1; |
| 3186 | } |
| 3187 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3188 | /* Uses Mbox */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3189 | 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] | 3190 | { |
| 3191 | struct be_mcc_wrb *wrb; |
| 3192 | struct be_cmd_req_get_func_config *req; |
| 3193 | int status; |
| 3194 | struct be_dma_mem cmd; |
| 3195 | |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3196 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 3197 | return -1; |
| 3198 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3199 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
| 3200 | cmd.size = sizeof(struct be_cmd_resp_get_func_config); |
| 3201 | cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, |
| 3202 | &cmd.dma); |
| 3203 | if (!cmd.va) { |
| 3204 | dev_err(&adapter->pdev->dev, "Memory alloc failure\n"); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3205 | status = -ENOMEM; |
| 3206 | goto err; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3207 | } |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3208 | |
| 3209 | wrb = wrb_from_mbox(adapter); |
| 3210 | if (!wrb) { |
| 3211 | status = -EBUSY; |
| 3212 | goto err; |
| 3213 | } |
| 3214 | |
| 3215 | req = cmd.va; |
| 3216 | |
| 3217 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3218 | OPCODE_COMMON_GET_FUNC_CONFIG, |
| 3219 | cmd.size, wrb, &cmd); |
| 3220 | |
Kalesh AP | 28710c5 | 2013-04-28 22:21:13 +0000 | [diff] [blame] | 3221 | if (skyhawk_chip(adapter)) |
| 3222 | req->hdr.version = 1; |
| 3223 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3224 | status = be_mbox_notify_wait(adapter); |
| 3225 | if (!status) { |
| 3226 | struct be_cmd_resp_get_func_config *resp = cmd.va; |
| 3227 | u32 desc_count = le32_to_cpu(resp->desc_count); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3228 | struct be_nic_res_desc *desc; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3229 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3230 | desc = be_get_nic_desc(resp->func_param, desc_count); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3231 | if (!desc) { |
| 3232 | status = -EINVAL; |
| 3233 | goto err; |
| 3234 | } |
| 3235 | |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 3236 | adapter->pf_number = desc->pf_num; |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3237 | be_copy_nic_desc(res, desc); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3238 | } |
| 3239 | err: |
| 3240 | mutex_unlock(&adapter->mbox_lock); |
Suresh Reddy | d98ef50 | 2013-04-25 00:56:55 +0000 | [diff] [blame] | 3241 | if (cmd.va) |
| 3242 | pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3243 | return status; |
| 3244 | } |
| 3245 | |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3246 | /* Uses mbox */ |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 3247 | static int be_cmd_get_profile_config_mbox(struct be_adapter *adapter, |
| 3248 | u8 domain, struct be_dma_mem *cmd) |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3249 | { |
| 3250 | struct be_mcc_wrb *wrb; |
| 3251 | struct be_cmd_req_get_profile_config *req; |
| 3252 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3253 | |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3254 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 3255 | return -1; |
| 3256 | wrb = wrb_from_mbox(adapter); |
| 3257 | |
| 3258 | req = cmd->va; |
| 3259 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3260 | OPCODE_COMMON_GET_PROFILE_CONFIG, |
| 3261 | cmd->size, wrb, cmd); |
| 3262 | |
| 3263 | req->type = ACTIVE_PROFILE_TYPE; |
| 3264 | req->hdr.domain = domain; |
| 3265 | if (!lancer_chip(adapter)) |
| 3266 | req->hdr.version = 1; |
| 3267 | |
| 3268 | status = be_mbox_notify_wait(adapter); |
| 3269 | |
| 3270 | mutex_unlock(&adapter->mbox_lock); |
| 3271 | return status; |
| 3272 | } |
| 3273 | |
| 3274 | /* Uses sync mcc */ |
Jingoo Han | 4188e7d | 2013-08-05 18:02:02 +0900 | [diff] [blame] | 3275 | static int be_cmd_get_profile_config_mccq(struct be_adapter *adapter, |
| 3276 | u8 domain, struct be_dma_mem *cmd) |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3277 | { |
| 3278 | struct be_mcc_wrb *wrb; |
| 3279 | struct be_cmd_req_get_profile_config *req; |
| 3280 | int status; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3281 | |
| 3282 | spin_lock_bh(&adapter->mcc_lock); |
| 3283 | |
| 3284 | wrb = wrb_from_mccq(adapter); |
| 3285 | if (!wrb) { |
| 3286 | status = -EBUSY; |
| 3287 | goto err; |
| 3288 | } |
| 3289 | |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3290 | req = cmd->va; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3291 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3292 | OPCODE_COMMON_GET_PROFILE_CONFIG, |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3293 | cmd->size, wrb, cmd); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3294 | |
| 3295 | req->type = ACTIVE_PROFILE_TYPE; |
| 3296 | req->hdr.domain = domain; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3297 | if (!lancer_chip(adapter)) |
| 3298 | req->hdr.version = 1; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3299 | |
| 3300 | status = be_mcc_notify_wait(adapter); |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3301 | |
| 3302 | err: |
| 3303 | spin_unlock_bh(&adapter->mcc_lock); |
| 3304 | return status; |
| 3305 | } |
| 3306 | |
| 3307 | /* Uses sync mcc, if MCCQ is already created otherwise mbox */ |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3308 | int be_cmd_get_profile_config(struct be_adapter *adapter, |
| 3309 | struct be_resources *res, u8 domain) |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3310 | { |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3311 | struct be_cmd_resp_get_profile_config *resp; |
| 3312 | struct be_pcie_res_desc *pcie; |
| 3313 | struct be_nic_res_desc *nic; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3314 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
| 3315 | struct be_dma_mem cmd; |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3316 | u32 desc_count; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3317 | int status; |
| 3318 | |
| 3319 | memset(&cmd, 0, sizeof(struct be_dma_mem)); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3320 | cmd.size = sizeof(struct be_cmd_resp_get_profile_config); |
| 3321 | cmd.va = pci_alloc_consistent(adapter->pdev, cmd.size, &cmd.dma); |
| 3322 | if (!cmd.va) |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3323 | return -ENOMEM; |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3324 | |
| 3325 | if (!mccq->created) |
| 3326 | status = be_cmd_get_profile_config_mbox(adapter, domain, &cmd); |
| 3327 | else |
| 3328 | status = be_cmd_get_profile_config_mccq(adapter, domain, &cmd); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3329 | if (status) |
| 3330 | goto err; |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3331 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3332 | resp = cmd.va; |
| 3333 | desc_count = le32_to_cpu(resp->desc_count); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3334 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3335 | pcie = be_get_pcie_desc(adapter->pdev->devfn, resp->func_param, |
| 3336 | desc_count); |
| 3337 | if (pcie) |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3338 | res->max_vfs = le16_to_cpu(pcie->num_vfs); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3339 | |
| 3340 | nic = be_get_nic_desc(resp->func_param, desc_count); |
Sathya Perla | 92bf14a | 2013-08-27 16:57:32 +0530 | [diff] [blame] | 3341 | if (nic) |
| 3342 | be_copy_nic_desc(res, nic); |
| 3343 | |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3344 | err: |
Vasundhara Volam | a05f99d | 2013-04-21 23:28:17 +0000 | [diff] [blame] | 3345 | if (cmd.va) |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3346 | pci_free_consistent(adapter->pdev, cmd.size, cmd.va, cmd.dma); |
Padmanabh Ratnakar | abb9395 | 2012-10-20 06:01:41 +0000 | [diff] [blame] | 3347 | return status; |
| 3348 | } |
| 3349 | |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3350 | /* Currently only Lancer uses this command and it supports version 0 only |
| 3351 | * Uses sync mcc |
| 3352 | */ |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 3353 | int be_cmd_set_profile_config(struct be_adapter *adapter, u32 bps, |
| 3354 | u8 domain) |
| 3355 | { |
| 3356 | struct be_mcc_wrb *wrb; |
| 3357 | struct be_cmd_req_set_profile_config *req; |
| 3358 | int status; |
| 3359 | |
| 3360 | spin_lock_bh(&adapter->mcc_lock); |
| 3361 | |
| 3362 | wrb = wrb_from_mccq(adapter); |
| 3363 | if (!wrb) { |
| 3364 | status = -EBUSY; |
| 3365 | goto err; |
| 3366 | } |
| 3367 | |
| 3368 | req = embedded_payload(wrb); |
| 3369 | |
| 3370 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3371 | OPCODE_COMMON_SET_PROFILE_CONFIG, sizeof(*req), |
| 3372 | wrb, NULL); |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 3373 | req->hdr.domain = domain; |
| 3374 | req->desc_count = cpu_to_le32(1); |
Vasundhara Volam | 150d58c | 2013-08-27 16:57:31 +0530 | [diff] [blame] | 3375 | req->nic_desc.hdr.desc_type = NIC_RESOURCE_DESC_TYPE_V0; |
| 3376 | req->nic_desc.hdr.desc_len = RESOURCE_DESC_SIZE_V0; |
Padmanabh Ratnakar | d5c1847 | 2012-10-20 06:01:53 +0000 | [diff] [blame] | 3377 | req->nic_desc.flags = (1 << QUN) | (1 << IMM) | (1 << NOSV); |
| 3378 | req->nic_desc.pf_num = adapter->pf_number; |
| 3379 | req->nic_desc.vf_num = domain; |
| 3380 | |
| 3381 | /* Mark fields invalid */ |
| 3382 | req->nic_desc.unicast_mac_count = 0xFFFF; |
| 3383 | req->nic_desc.mcc_count = 0xFFFF; |
| 3384 | req->nic_desc.vlan_count = 0xFFFF; |
| 3385 | req->nic_desc.mcast_mac_count = 0xFFFF; |
| 3386 | req->nic_desc.txq_count = 0xFFFF; |
| 3387 | req->nic_desc.rq_count = 0xFFFF; |
| 3388 | req->nic_desc.rssq_count = 0xFFFF; |
| 3389 | req->nic_desc.lro_count = 0xFFFF; |
| 3390 | req->nic_desc.cq_count = 0xFFFF; |
| 3391 | req->nic_desc.toe_conn_count = 0xFFFF; |
| 3392 | req->nic_desc.eq_count = 0xFFFF; |
| 3393 | req->nic_desc.link_param = 0xFF; |
| 3394 | req->nic_desc.bw_min = 0xFFFFFFFF; |
| 3395 | req->nic_desc.acpi_params = 0xFF; |
| 3396 | req->nic_desc.wol_param = 0x0F; |
| 3397 | |
| 3398 | /* Change BW */ |
| 3399 | req->nic_desc.bw_min = cpu_to_le32(bps); |
| 3400 | req->nic_desc.bw_max = cpu_to_le32(bps); |
| 3401 | status = be_mcc_notify_wait(adapter); |
| 3402 | err: |
| 3403 | spin_unlock_bh(&adapter->mcc_lock); |
| 3404 | return status; |
| 3405 | } |
| 3406 | |
Sathya Perla | 4c87661 | 2013-02-03 20:30:11 +0000 | [diff] [blame] | 3407 | int be_cmd_get_if_id(struct be_adapter *adapter, struct be_vf_cfg *vf_cfg, |
| 3408 | int vf_num) |
| 3409 | { |
| 3410 | struct be_mcc_wrb *wrb; |
| 3411 | struct be_cmd_req_get_iface_list *req; |
| 3412 | struct be_cmd_resp_get_iface_list *resp; |
| 3413 | int status; |
| 3414 | |
| 3415 | spin_lock_bh(&adapter->mcc_lock); |
| 3416 | |
| 3417 | wrb = wrb_from_mccq(adapter); |
| 3418 | if (!wrb) { |
| 3419 | status = -EBUSY; |
| 3420 | goto err; |
| 3421 | } |
| 3422 | req = embedded_payload(wrb); |
| 3423 | |
| 3424 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3425 | OPCODE_COMMON_GET_IFACE_LIST, sizeof(*resp), |
| 3426 | wrb, NULL); |
| 3427 | req->hdr.domain = vf_num + 1; |
| 3428 | |
| 3429 | status = be_mcc_notify_wait(adapter); |
| 3430 | if (!status) { |
| 3431 | resp = (struct be_cmd_resp_get_iface_list *)req; |
| 3432 | vf_cfg->if_handle = le32_to_cpu(resp->if_desc.if_id); |
| 3433 | } |
| 3434 | |
| 3435 | err: |
| 3436 | spin_unlock_bh(&adapter->mcc_lock); |
| 3437 | return status; |
| 3438 | } |
| 3439 | |
Somnath Kotur | 5c51081 | 2013-05-30 02:52:23 +0000 | [diff] [blame] | 3440 | static int lancer_wait_idle(struct be_adapter *adapter) |
| 3441 | { |
| 3442 | #define SLIPORT_IDLE_TIMEOUT 30 |
| 3443 | u32 reg_val; |
| 3444 | int status = 0, i; |
| 3445 | |
| 3446 | for (i = 0; i < SLIPORT_IDLE_TIMEOUT; i++) { |
| 3447 | reg_val = ioread32(adapter->db + PHYSDEV_CONTROL_OFFSET); |
| 3448 | if ((reg_val & PHYSDEV_CONTROL_INP_MASK) == 0) |
| 3449 | break; |
| 3450 | |
| 3451 | ssleep(1); |
| 3452 | } |
| 3453 | |
| 3454 | if (i == SLIPORT_IDLE_TIMEOUT) |
| 3455 | status = -1; |
| 3456 | |
| 3457 | return status; |
| 3458 | } |
| 3459 | |
| 3460 | int lancer_physdev_ctrl(struct be_adapter *adapter, u32 mask) |
| 3461 | { |
| 3462 | int status = 0; |
| 3463 | |
| 3464 | status = lancer_wait_idle(adapter); |
| 3465 | if (status) |
| 3466 | return status; |
| 3467 | |
| 3468 | iowrite32(mask, adapter->db + PHYSDEV_CONTROL_OFFSET); |
| 3469 | |
| 3470 | return status; |
| 3471 | } |
| 3472 | |
| 3473 | /* Routine to check whether dump image is present or not */ |
| 3474 | bool dump_present(struct be_adapter *adapter) |
| 3475 | { |
| 3476 | u32 sliport_status = 0; |
| 3477 | |
| 3478 | sliport_status = ioread32(adapter->db + SLIPORT_STATUS_OFFSET); |
| 3479 | return !!(sliport_status & SLIPORT_STATUS_DIP_MASK); |
| 3480 | } |
| 3481 | |
| 3482 | int lancer_initiate_dump(struct be_adapter *adapter) |
| 3483 | { |
| 3484 | int status; |
| 3485 | |
| 3486 | /* give firmware reset and diagnostic dump */ |
| 3487 | status = lancer_physdev_ctrl(adapter, PHYSDEV_CONTROL_FW_RESET_MASK | |
| 3488 | PHYSDEV_CONTROL_DD_MASK); |
| 3489 | if (status < 0) { |
| 3490 | dev_err(&adapter->pdev->dev, "Firmware reset failed\n"); |
| 3491 | return status; |
| 3492 | } |
| 3493 | |
| 3494 | status = lancer_wait_idle(adapter); |
| 3495 | if (status) |
| 3496 | return status; |
| 3497 | |
| 3498 | if (!dump_present(adapter)) { |
| 3499 | dev_err(&adapter->pdev->dev, "Dump image not present\n"); |
| 3500 | return -1; |
| 3501 | } |
| 3502 | |
| 3503 | return 0; |
| 3504 | } |
| 3505 | |
Padmanabh Ratnakar | dcf7ebb | 2012-10-20 06:03:49 +0000 | [diff] [blame] | 3506 | /* Uses sync mcc */ |
| 3507 | int be_cmd_enable_vf(struct be_adapter *adapter, u8 domain) |
| 3508 | { |
| 3509 | struct be_mcc_wrb *wrb; |
| 3510 | struct be_cmd_enable_disable_vf *req; |
| 3511 | int status; |
| 3512 | |
| 3513 | if (!lancer_chip(adapter)) |
| 3514 | return 0; |
| 3515 | |
| 3516 | spin_lock_bh(&adapter->mcc_lock); |
| 3517 | |
| 3518 | wrb = wrb_from_mccq(adapter); |
| 3519 | if (!wrb) { |
| 3520 | status = -EBUSY; |
| 3521 | goto err; |
| 3522 | } |
| 3523 | |
| 3524 | req = embedded_payload(wrb); |
| 3525 | |
| 3526 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3527 | OPCODE_COMMON_ENABLE_DISABLE_VF, sizeof(*req), |
| 3528 | wrb, NULL); |
| 3529 | |
| 3530 | req->hdr.domain = domain; |
| 3531 | req->enable = 1; |
| 3532 | status = be_mcc_notify_wait(adapter); |
| 3533 | err: |
| 3534 | spin_unlock_bh(&adapter->mcc_lock); |
| 3535 | return status; |
| 3536 | } |
| 3537 | |
Somnath Kotur | 68c45a2 | 2013-03-14 02:42:07 +0000 | [diff] [blame] | 3538 | int be_cmd_intr_set(struct be_adapter *adapter, bool intr_enable) |
| 3539 | { |
| 3540 | struct be_mcc_wrb *wrb; |
| 3541 | struct be_cmd_req_intr_set *req; |
| 3542 | int status; |
| 3543 | |
| 3544 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 3545 | return -1; |
| 3546 | |
| 3547 | wrb = wrb_from_mbox(adapter); |
| 3548 | |
| 3549 | req = embedded_payload(wrb); |
| 3550 | |
| 3551 | be_wrb_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 3552 | OPCODE_COMMON_SET_INTERRUPT_ENABLE, sizeof(*req), |
| 3553 | wrb, NULL); |
| 3554 | |
| 3555 | req->intr_enabled = intr_enable; |
| 3556 | |
| 3557 | status = be_mbox_notify_wait(adapter); |
| 3558 | |
| 3559 | mutex_unlock(&adapter->mbox_lock); |
| 3560 | return status; |
| 3561 | } |
| 3562 | |
Parav Pandit | 6a4ab66 | 2012-03-26 14:27:12 +0000 | [diff] [blame] | 3563 | int be_roce_mcc_cmd(void *netdev_handle, void *wrb_payload, |
| 3564 | int wrb_payload_size, u16 *cmd_status, u16 *ext_status) |
| 3565 | { |
| 3566 | struct be_adapter *adapter = netdev_priv(netdev_handle); |
| 3567 | struct be_mcc_wrb *wrb; |
| 3568 | struct be_cmd_req_hdr *hdr = (struct be_cmd_req_hdr *) wrb_payload; |
| 3569 | struct be_cmd_req_hdr *req; |
| 3570 | struct be_cmd_resp_hdr *resp; |
| 3571 | int status; |
| 3572 | |
| 3573 | spin_lock_bh(&adapter->mcc_lock); |
| 3574 | |
| 3575 | wrb = wrb_from_mccq(adapter); |
| 3576 | if (!wrb) { |
| 3577 | status = -EBUSY; |
| 3578 | goto err; |
| 3579 | } |
| 3580 | req = embedded_payload(wrb); |
| 3581 | resp = embedded_payload(wrb); |
| 3582 | |
| 3583 | be_wrb_cmd_hdr_prepare(req, hdr->subsystem, |
| 3584 | hdr->opcode, wrb_payload_size, wrb, NULL); |
| 3585 | memcpy(req, wrb_payload, wrb_payload_size); |
| 3586 | be_dws_cpu_to_le(req, wrb_payload_size); |
| 3587 | |
| 3588 | status = be_mcc_notify_wait(adapter); |
| 3589 | if (cmd_status) |
| 3590 | *cmd_status = (status & 0xffff); |
| 3591 | if (ext_status) |
| 3592 | *ext_status = 0; |
| 3593 | memcpy(wrb_payload, resp, sizeof(*resp) + resp->response_length); |
| 3594 | be_dws_le_to_cpu(wrb_payload, sizeof(*resp) + resp->response_length); |
| 3595 | err: |
| 3596 | spin_unlock_bh(&adapter->mcc_lock); |
| 3597 | return status; |
| 3598 | } |
| 3599 | EXPORT_SYMBOL(be_roce_mcc_cmd); |