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