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