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