Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1 | /* |
Ajit Khaparde | 294aedc | 2010-02-19 13:54:58 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005 - 2010 ServerEngines |
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: |
| 11 | * linux-drivers@serverengines.com |
| 12 | * |
| 13 | * ServerEngines |
| 14 | * 209 N. Fair Oaks Ave |
| 15 | * Sunnyvale, CA 94085 |
| 16 | */ |
| 17 | |
| 18 | #include "be.h" |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 19 | #include "be_cmds.h" |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 20 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 21 | static void be_mcc_notify(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 22 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 23 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 24 | u32 val = 0; |
| 25 | |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 26 | if (adapter->eeh_err) { |
| 27 | dev_info(&adapter->pdev->dev, |
| 28 | "Error in Card Detected! Cannot issue commands\n"); |
| 29 | return; |
| 30 | } |
| 31 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 32 | val |= mccq->id & DB_MCCQ_RING_ID_MASK; |
| 33 | val |= 1 << DB_MCCQ_NUM_POSTED_SHIFT; |
Sathya Perla | f3eb62d | 2010-06-29 00:11:17 +0000 | [diff] [blame] | 34 | |
| 35 | wmb(); |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 36 | iowrite32(val, adapter->db + DB_MCCQ_OFFSET); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | /* To check if valid bit is set, check the entire word as we don't know |
| 40 | * the endianness of the data (old entry is host endian while a new entry is |
| 41 | * little endian) */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 42 | 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] | 43 | { |
| 44 | if (compl->flags != 0) { |
| 45 | compl->flags = le32_to_cpu(compl->flags); |
| 46 | BUG_ON((compl->flags & CQE_FLAGS_VALID_MASK) == 0); |
| 47 | return true; |
| 48 | } else { |
| 49 | return false; |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | /* Need to reset the entire word that houses the valid bit */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 54 | static inline void be_mcc_compl_use(struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 55 | { |
| 56 | compl->flags = 0; |
| 57 | } |
| 58 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 59 | static int be_mcc_compl_process(struct be_adapter *adapter, |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 60 | struct be_mcc_compl *compl) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 61 | { |
| 62 | u16 compl_status, extd_status; |
| 63 | |
| 64 | /* Just swap the status to host endian; mcc tag is opaquely copied |
| 65 | * from mcc_wrb */ |
| 66 | be_dws_le_to_cpu(compl, 4); |
| 67 | |
| 68 | compl_status = (compl->status >> CQE_STATUS_COMPL_SHIFT) & |
| 69 | CQE_STATUS_COMPL_MASK; |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 70 | |
| 71 | if ((compl->tag0 == OPCODE_COMMON_WRITE_FLASHROM) && |
| 72 | (compl->tag1 == CMD_SUBSYSTEM_COMMON)) { |
| 73 | adapter->flash_status = compl_status; |
| 74 | complete(&adapter->flash_compl); |
| 75 | } |
| 76 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 77 | if (compl_status == MCC_STATUS_SUCCESS) { |
| 78 | if (compl->tag0 == OPCODE_ETH_GET_STATISTICS) { |
| 79 | struct be_cmd_resp_get_stats *resp = |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 80 | adapter->stats_cmd.va; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 81 | be_dws_le_to_cpu(&resp->hw_stats, |
| 82 | sizeof(resp->hw_stats)); |
| 83 | netdev_stats_update(adapter); |
Ajit Khaparde | b2aebe6 | 2011-02-20 11:41:39 +0000 | [diff] [blame] | 84 | adapter->stats_cmd_sent = false; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 85 | } |
Ajit Khaparde | 8943807 | 2010-07-23 12:42:40 -0700 | [diff] [blame] | 86 | } else if ((compl_status != MCC_STATUS_NOT_SUPPORTED) && |
| 87 | (compl->tag0 != OPCODE_COMMON_NTWK_MAC_QUERY)) { |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 88 | extd_status = (compl->status >> CQE_STATUS_EXTD_SHIFT) & |
| 89 | CQE_STATUS_EXTD_MASK; |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 90 | dev_warn(&adapter->pdev->dev, |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 91 | "Error in cmd completion - opcode %d, compl %d, extd %d\n", |
| 92 | compl->tag0, compl_status, extd_status); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 93 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 94 | return compl_status; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 95 | } |
| 96 | |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 97 | /* 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] | 98 | static void be_async_link_state_process(struct be_adapter *adapter, |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 99 | struct be_async_event_link_state *evt) |
| 100 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 101 | be_link_status_update(adapter, |
| 102 | evt->port_link_status == ASYNC_EVENT_LINK_UP); |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 105 | /* Grp5 CoS Priority evt */ |
| 106 | static void be_async_grp5_cos_priority_process(struct be_adapter *adapter, |
| 107 | struct be_async_event_grp5_cos_priority *evt) |
| 108 | { |
| 109 | if (evt->valid) { |
| 110 | adapter->vlan_prio_bmap = evt->available_priority_bmap; |
Ajit Khaparde | 60964dd | 2011-02-11 13:37:25 +0000 | [diff] [blame] | 111 | adapter->recommended_prio &= ~VLAN_PRIO_MASK; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 112 | adapter->recommended_prio = |
| 113 | evt->reco_default_priority << VLAN_PRIO_SHIFT; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /* Grp5 QOS Speed evt */ |
| 118 | static void be_async_grp5_qos_speed_process(struct be_adapter *adapter, |
| 119 | struct be_async_event_grp5_qos_link_speed *evt) |
| 120 | { |
| 121 | if (evt->physical_port == adapter->port_num) { |
| 122 | /* qos_link_speed is in units of 10 Mbps */ |
| 123 | adapter->link_speed = evt->qos_link_speed * 10; |
| 124 | } |
| 125 | } |
| 126 | |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame^] | 127 | /*Grp5 PVID evt*/ |
| 128 | static void be_async_grp5_pvid_state_process(struct be_adapter *adapter, |
| 129 | struct be_async_event_grp5_pvid_state *evt) |
| 130 | { |
| 131 | if (evt->enabled) |
| 132 | adapter->pvid = evt->tag; |
| 133 | else |
| 134 | adapter->pvid = 0; |
| 135 | } |
| 136 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 137 | static void be_async_grp5_evt_process(struct be_adapter *adapter, |
| 138 | u32 trailer, struct be_mcc_compl *evt) |
| 139 | { |
| 140 | u8 event_type = 0; |
| 141 | |
| 142 | event_type = (trailer >> ASYNC_TRAILER_EVENT_TYPE_SHIFT) & |
| 143 | ASYNC_TRAILER_EVENT_TYPE_MASK; |
| 144 | |
| 145 | switch (event_type) { |
| 146 | case ASYNC_EVENT_COS_PRIORITY: |
| 147 | be_async_grp5_cos_priority_process(adapter, |
| 148 | (struct be_async_event_grp5_cos_priority *)evt); |
| 149 | break; |
| 150 | case ASYNC_EVENT_QOS_SPEED: |
| 151 | be_async_grp5_qos_speed_process(adapter, |
| 152 | (struct be_async_event_grp5_qos_link_speed *)evt); |
| 153 | break; |
Ajit Khaparde | 3968fa1 | 2011-02-20 11:41:53 +0000 | [diff] [blame^] | 154 | case ASYNC_EVENT_PVID_STATE: |
| 155 | be_async_grp5_pvid_state_process(adapter, |
| 156 | (struct be_async_event_grp5_pvid_state *)evt); |
| 157 | break; |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 158 | default: |
| 159 | dev_warn(&adapter->pdev->dev, "Unknown grp5 event!\n"); |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 164 | static inline bool is_link_state_evt(u32 trailer) |
| 165 | { |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 166 | return ((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 167 | ASYNC_TRAILER_EVENT_CODE_MASK) == |
Eric Dumazet | 807540b | 2010-09-23 05:40:09 +0000 | [diff] [blame] | 168 | ASYNC_EVENT_CODE_LINK_STATE; |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 169 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 170 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 171 | static inline bool is_grp5_evt(u32 trailer) |
| 172 | { |
| 173 | return (((trailer >> ASYNC_TRAILER_EVENT_CODE_SHIFT) & |
| 174 | ASYNC_TRAILER_EVENT_CODE_MASK) == |
| 175 | ASYNC_EVENT_CODE_GRP_5); |
| 176 | } |
| 177 | |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 178 | 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] | 179 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 180 | struct be_queue_info *mcc_cq = &adapter->mcc_obj.cq; |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 181 | struct be_mcc_compl *compl = queue_tail_node(mcc_cq); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 182 | |
| 183 | if (be_mcc_compl_is_new(compl)) { |
| 184 | queue_tail_inc(mcc_cq); |
| 185 | return compl; |
| 186 | } |
| 187 | return NULL; |
| 188 | } |
| 189 | |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 190 | void be_async_mcc_enable(struct be_adapter *adapter) |
| 191 | { |
| 192 | spin_lock_bh(&adapter->mcc_cq_lock); |
| 193 | |
| 194 | be_cq_notify(adapter, adapter->mcc_obj.cq.id, true, 0); |
| 195 | adapter->mcc_obj.rearm_cq = true; |
| 196 | |
| 197 | spin_unlock_bh(&adapter->mcc_cq_lock); |
| 198 | } |
| 199 | |
| 200 | void be_async_mcc_disable(struct be_adapter *adapter) |
| 201 | { |
| 202 | adapter->mcc_obj.rearm_cq = false; |
| 203 | } |
| 204 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 205 | int be_process_mcc(struct be_adapter *adapter, int *status) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 206 | { |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 207 | struct be_mcc_compl *compl; |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 208 | int num = 0; |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 209 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 210 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 211 | spin_lock_bh(&adapter->mcc_cq_lock); |
| 212 | while ((compl = be_mcc_compl_get(adapter))) { |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 213 | if (compl->flags & CQE_FLAGS_ASYNC_MASK) { |
| 214 | /* Interpret flags as an async trailer */ |
Ajit Khaparde | 323f30b | 2010-09-03 06:24:13 +0000 | [diff] [blame] | 215 | if (is_link_state_evt(compl->flags)) |
| 216 | be_async_link_state_process(adapter, |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 217 | (struct be_async_event_link_state *) compl); |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 218 | else if (is_grp5_evt(compl->flags)) |
| 219 | be_async_grp5_evt_process(adapter, |
| 220 | compl->flags, compl); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 221 | } else if (compl->flags & CQE_FLAGS_COMPLETED_MASK) { |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 222 | *status = be_mcc_compl_process(adapter, compl); |
Sathya Perla | 7a1e9b2 | 2010-02-17 01:35:11 +0000 | [diff] [blame] | 223 | atomic_dec(&mcc_obj->q.used); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 224 | } |
| 225 | be_mcc_compl_use(compl); |
| 226 | num++; |
| 227 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 228 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 229 | spin_unlock_bh(&adapter->mcc_cq_lock); |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 230 | return num; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 231 | } |
| 232 | |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 233 | /* Wait till no more pending mcc requests are present */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 234 | static int be_mcc_wait_compl(struct be_adapter *adapter) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 235 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 236 | #define mcc_timeout 120000 /* 12s timeout */ |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 237 | int i, num, status = 0; |
| 238 | struct be_mcc_obj *mcc_obj = &adapter->mcc_obj; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 239 | |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 240 | if (adapter->eeh_err) |
| 241 | return -EIO; |
| 242 | |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 243 | for (i = 0; i < mcc_timeout; i++) { |
| 244 | num = be_process_mcc(adapter, &status); |
| 245 | if (num) |
| 246 | be_cq_notify(adapter, mcc_obj->cq.id, |
| 247 | mcc_obj->rearm_cq, num); |
| 248 | |
| 249 | if (atomic_read(&mcc_obj->q.used) == 0) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 250 | break; |
| 251 | udelay(100); |
| 252 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 253 | if (i == mcc_timeout) { |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 254 | dev_err(&adapter->pdev->dev, "mccq poll timed out\n"); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 255 | return -1; |
| 256 | } |
Sathya Perla | f31e50a | 2010-03-02 03:56:39 -0800 | [diff] [blame] | 257 | return status; |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* Notify MCC requests and wait for completion */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 261 | static int be_mcc_notify_wait(struct be_adapter *adapter) |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 262 | { |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 263 | be_mcc_notify(adapter); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 264 | return be_mcc_wait_compl(adapter); |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 267 | 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] | 268 | { |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 269 | int msecs = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 270 | u32 ready; |
| 271 | |
Ajit Khaparde | 7acc208 | 2011-02-11 13:38:17 +0000 | [diff] [blame] | 272 | if (adapter->eeh_err) { |
| 273 | dev_err(&adapter->pdev->dev, |
| 274 | "Error detected in card.Cannot issue commands\n"); |
| 275 | return -EIO; |
| 276 | } |
| 277 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 278 | do { |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 279 | ready = ioread32(db); |
| 280 | if (ready == 0xffffffff) { |
| 281 | dev_err(&adapter->pdev->dev, |
| 282 | "pci slot disconnected\n"); |
| 283 | return -1; |
| 284 | } |
| 285 | |
| 286 | ready &= MPU_MAILBOX_DB_RDY_MASK; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 287 | if (ready) |
| 288 | break; |
| 289 | |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 290 | if (msecs > 4000) { |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 291 | dev_err(&adapter->pdev->dev, "mbox poll timed out\n"); |
Ajit Khaparde | d053de9 | 2010-09-03 06:23:30 +0000 | [diff] [blame] | 292 | be_detect_dump_ue(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 293 | return -1; |
| 294 | } |
| 295 | |
Sathya Perla | f25b03a | 2010-05-30 23:34:14 +0000 | [diff] [blame] | 296 | set_current_state(TASK_INTERRUPTIBLE); |
| 297 | schedule_timeout(msecs_to_jiffies(1)); |
| 298 | msecs++; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 299 | } while (true); |
| 300 | |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | /* |
| 305 | * Insert the mailbox address into the doorbell in two steps |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 306 | * 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] | 307 | */ |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 308 | static int be_mbox_notify_wait(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 309 | { |
| 310 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 311 | u32 val = 0; |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 312 | void __iomem *db = adapter->db + MPU_MAILBOX_DB_OFFSET; |
| 313 | struct be_dma_mem *mbox_mem = &adapter->mbox_mem; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 314 | struct be_mcc_mailbox *mbox = mbox_mem->va; |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 315 | struct be_mcc_compl *compl = &mbox->compl; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 316 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 317 | /* wait for ready to be set */ |
| 318 | status = be_mbox_db_ready_wait(adapter, db); |
| 319 | if (status != 0) |
| 320 | return status; |
| 321 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 322 | val |= MPU_MAILBOX_DB_HI_MASK; |
| 323 | /* at bits 2 - 31 place mbox dma addr msb bits 34 - 63 */ |
| 324 | val |= (upper_32_bits(mbox_mem->dma) >> 2) << 2; |
| 325 | iowrite32(val, db); |
| 326 | |
| 327 | /* wait for ready to be set */ |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 328 | status = be_mbox_db_ready_wait(adapter, db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 329 | if (status != 0) |
| 330 | return status; |
| 331 | |
| 332 | val = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 333 | /* at bits 2 - 31 place mbox dma addr lsb bits 4 - 33 */ |
| 334 | val |= (u32)(mbox_mem->dma >> 4) << 2; |
| 335 | iowrite32(val, db); |
| 336 | |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 337 | status = be_mbox_db_ready_wait(adapter, db); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 338 | if (status != 0) |
| 339 | return status; |
| 340 | |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 341 | /* A cq entry has been made now */ |
Sathya Perla | efd2e40 | 2009-07-27 22:53:10 +0000 | [diff] [blame] | 342 | if (be_mcc_compl_is_new(compl)) { |
| 343 | status = be_mcc_compl_process(adapter, &mbox->compl); |
| 344 | be_mcc_compl_use(compl); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 345 | if (status) |
| 346 | return status; |
| 347 | } else { |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 348 | dev_err(&adapter->pdev->dev, "invalid mailbox completion\n"); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 349 | return -1; |
| 350 | } |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 351 | return 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 354 | static int be_POST_stage_get(struct be_adapter *adapter, u16 *stage) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 355 | { |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 356 | u32 sem; |
| 357 | |
| 358 | if (lancer_chip(adapter)) |
| 359 | sem = ioread32(adapter->db + MPU_EP_SEMAPHORE_IF_TYPE2_OFFSET); |
| 360 | else |
| 361 | sem = ioread32(adapter->csr + MPU_EP_SEMAPHORE_OFFSET); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 362 | |
| 363 | *stage = sem & EP_SEMAPHORE_POST_STAGE_MASK; |
| 364 | if ((sem >> EP_SEMAPHORE_POST_ERR_SHIFT) & EP_SEMAPHORE_POST_ERR_MASK) |
| 365 | return -1; |
| 366 | else |
| 367 | return 0; |
| 368 | } |
| 369 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 370 | int be_cmd_POST(struct be_adapter *adapter) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 371 | { |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 372 | u16 stage; |
| 373 | int status, timeout = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 374 | |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 375 | do { |
| 376 | status = be_POST_stage_get(adapter, &stage); |
| 377 | if (status) { |
| 378 | dev_err(&adapter->pdev->dev, "POST error; stage=0x%x\n", |
| 379 | stage); |
| 380 | return -1; |
| 381 | } else if (stage != POST_STAGE_ARMFW_RDY) { |
| 382 | set_current_state(TASK_INTERRUPTIBLE); |
| 383 | schedule_timeout(2 * HZ); |
| 384 | timeout += 2; |
| 385 | } else { |
| 386 | return 0; |
| 387 | } |
Sathya Perla | d938a70 | 2010-05-26 00:33:43 -0700 | [diff] [blame] | 388 | } while (timeout < 40); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 389 | |
Sathya Perla | 43a04fdc | 2009-10-14 20:21:17 +0000 | [diff] [blame] | 390 | dev_err(&adapter->pdev->dev, "POST timeout; stage=0x%x\n", stage); |
| 391 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | static inline void *embedded_payload(struct be_mcc_wrb *wrb) |
| 395 | { |
| 396 | return wrb->payload.embedded_payload; |
| 397 | } |
| 398 | |
| 399 | static inline struct be_sge *nonembedded_sgl(struct be_mcc_wrb *wrb) |
| 400 | { |
| 401 | return &wrb->payload.sgl[0]; |
| 402 | } |
| 403 | |
| 404 | /* Don't touch the hdr after it's prepared */ |
| 405 | static void be_wrb_hdr_prepare(struct be_mcc_wrb *wrb, int payload_len, |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 406 | bool embedded, u8 sge_cnt, u32 opcode) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 407 | { |
| 408 | if (embedded) |
| 409 | wrb->embedded |= MCC_WRB_EMBEDDED_MASK; |
| 410 | else |
| 411 | wrb->embedded |= (sge_cnt & MCC_WRB_SGE_CNT_MASK) << |
| 412 | MCC_WRB_SGE_CNT_SHIFT; |
| 413 | wrb->payload_length = payload_len; |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 414 | wrb->tag0 = opcode; |
Sathya Perla | fa4281b | 2010-01-21 22:51:36 +0000 | [diff] [blame] | 415 | be_dws_cpu_to_le(wrb, 8); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | /* Don't touch the hdr after it's prepared */ |
| 419 | static void be_cmd_hdr_prepare(struct be_cmd_req_hdr *req_hdr, |
| 420 | u8 subsystem, u8 opcode, int cmd_len) |
| 421 | { |
| 422 | req_hdr->opcode = opcode; |
| 423 | req_hdr->subsystem = subsystem; |
| 424 | req_hdr->request_length = cpu_to_le32(cmd_len - sizeof(*req_hdr)); |
Ajit Khaparde | 07793d3 | 2010-02-16 00:18:46 +0000 | [diff] [blame] | 425 | req_hdr->version = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | static void be_cmd_page_addrs_prepare(struct phys_addr *pages, u32 max_pages, |
| 429 | struct be_dma_mem *mem) |
| 430 | { |
| 431 | int i, buf_pages = min(PAGES_4K_SPANNED(mem->va, mem->size), max_pages); |
| 432 | u64 dma = (u64)mem->dma; |
| 433 | |
| 434 | for (i = 0; i < buf_pages; i++) { |
| 435 | pages[i].lo = cpu_to_le32(dma & 0xFFFFFFFF); |
| 436 | pages[i].hi = cpu_to_le32(upper_32_bits(dma)); |
| 437 | dma += PAGE_SIZE_4K; |
| 438 | } |
| 439 | } |
| 440 | |
| 441 | /* Converts interrupt delay in microseconds to multiplier value */ |
| 442 | static u32 eq_delay_to_mult(u32 usec_delay) |
| 443 | { |
| 444 | #define MAX_INTR_RATE 651042 |
| 445 | const u32 round = 10; |
| 446 | u32 multiplier; |
| 447 | |
| 448 | if (usec_delay == 0) |
| 449 | multiplier = 0; |
| 450 | else { |
| 451 | u32 interrupt_rate = 1000000 / usec_delay; |
| 452 | /* Max delay, corresponding to the lowest interrupt rate */ |
| 453 | if (interrupt_rate == 0) |
| 454 | multiplier = 1023; |
| 455 | else { |
| 456 | multiplier = (MAX_INTR_RATE - interrupt_rate) * round; |
| 457 | multiplier /= interrupt_rate; |
| 458 | /* Round the multiplier to the closest value.*/ |
| 459 | multiplier = (multiplier + round/2) / round; |
| 460 | multiplier = min(multiplier, (u32)1023); |
| 461 | } |
| 462 | } |
| 463 | return multiplier; |
| 464 | } |
| 465 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 466 | 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] | 467 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 468 | struct be_dma_mem *mbox_mem = &adapter->mbox_mem; |
| 469 | struct be_mcc_wrb *wrb |
| 470 | = &((struct be_mcc_mailbox *)(mbox_mem->va))->wrb; |
| 471 | memset(wrb, 0, sizeof(*wrb)); |
| 472 | return wrb; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 475 | static struct be_mcc_wrb *wrb_from_mccq(struct be_adapter *adapter) |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 476 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 477 | struct be_queue_info *mccq = &adapter->mcc_obj.q; |
| 478 | struct be_mcc_wrb *wrb; |
| 479 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 480 | if (atomic_read(&mccq->used) >= mccq->len) { |
| 481 | dev_err(&adapter->pdev->dev, "Out of MCCQ wrbs\n"); |
| 482 | return NULL; |
| 483 | } |
| 484 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 485 | wrb = queue_head_node(mccq); |
| 486 | queue_head_inc(mccq); |
| 487 | atomic_inc(&mccq->used); |
| 488 | memset(wrb, 0, sizeof(*wrb)); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 489 | return wrb; |
| 490 | } |
| 491 | |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 492 | /* Tell fw we're about to start firing cmds by writing a |
| 493 | * special pattern across the wrb hdr; uses mbox |
| 494 | */ |
| 495 | int be_cmd_fw_init(struct be_adapter *adapter) |
| 496 | { |
| 497 | u8 *wrb; |
| 498 | int status; |
| 499 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 500 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 501 | return -1; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 502 | |
| 503 | wrb = (u8 *)wrb_from_mbox(adapter); |
Sathya Perla | 359a972 | 2010-12-01 01:03:36 +0000 | [diff] [blame] | 504 | *wrb++ = 0xFF; |
| 505 | *wrb++ = 0x12; |
| 506 | *wrb++ = 0x34; |
| 507 | *wrb++ = 0xFF; |
| 508 | *wrb++ = 0xFF; |
| 509 | *wrb++ = 0x56; |
| 510 | *wrb++ = 0x78; |
| 511 | *wrb = 0xFF; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 512 | |
| 513 | status = be_mbox_notify_wait(adapter); |
| 514 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 515 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 516 | return status; |
| 517 | } |
| 518 | |
| 519 | /* Tell fw we're done with firing cmds by writing a |
| 520 | * special pattern across the wrb hdr; uses mbox |
| 521 | */ |
| 522 | int be_cmd_fw_clean(struct be_adapter *adapter) |
| 523 | { |
| 524 | u8 *wrb; |
| 525 | int status; |
| 526 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 527 | if (adapter->eeh_err) |
| 528 | return -EIO; |
| 529 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 530 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 531 | return -1; |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 532 | |
| 533 | wrb = (u8 *)wrb_from_mbox(adapter); |
| 534 | *wrb++ = 0xFF; |
| 535 | *wrb++ = 0xAA; |
| 536 | *wrb++ = 0xBB; |
| 537 | *wrb++ = 0xFF; |
| 538 | *wrb++ = 0xFF; |
| 539 | *wrb++ = 0xCC; |
| 540 | *wrb++ = 0xDD; |
| 541 | *wrb = 0xFF; |
| 542 | |
| 543 | status = be_mbox_notify_wait(adapter); |
| 544 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 545 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 2243e2e | 2009-11-22 22:02:03 +0000 | [diff] [blame] | 546 | return status; |
| 547 | } |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 548 | int be_cmd_eq_create(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 549 | struct be_queue_info *eq, int eq_delay) |
| 550 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 551 | struct be_mcc_wrb *wrb; |
| 552 | struct be_cmd_req_eq_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 553 | struct be_dma_mem *q_mem = &eq->dma_mem; |
| 554 | int status; |
| 555 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 556 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 557 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 558 | |
| 559 | wrb = wrb_from_mbox(adapter); |
| 560 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 561 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 562 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_COMMON_EQ_CREATE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 563 | |
| 564 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 565 | OPCODE_COMMON_EQ_CREATE, sizeof(*req)); |
| 566 | |
| 567 | req->num_pages = cpu_to_le16(PAGES_4K_SPANNED(q_mem->va, q_mem->size)); |
| 568 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 569 | AMAP_SET_BITS(struct amap_eq_context, valid, req->context, 1); |
| 570 | /* 4byte eqe*/ |
| 571 | AMAP_SET_BITS(struct amap_eq_context, size, req->context, 0); |
| 572 | AMAP_SET_BITS(struct amap_eq_context, count, req->context, |
| 573 | __ilog2_u32(eq->len/256)); |
| 574 | AMAP_SET_BITS(struct amap_eq_context, delaymult, req->context, |
| 575 | eq_delay_to_mult(eq_delay)); |
| 576 | be_dws_cpu_to_le(req->context, sizeof(req->context)); |
| 577 | |
| 578 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 579 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 580 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 581 | if (!status) { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 582 | struct be_cmd_resp_eq_create *resp = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 583 | eq->id = le16_to_cpu(resp->eq_id); |
| 584 | eq->created = true; |
| 585 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 586 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 587 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 588 | return status; |
| 589 | } |
| 590 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 591 | /* Uses mbox */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 592 | int be_cmd_mac_addr_query(struct be_adapter *adapter, u8 *mac_addr, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 593 | u8 type, bool permanent, u32 if_handle) |
| 594 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 595 | struct be_mcc_wrb *wrb; |
| 596 | struct be_cmd_req_mac_query *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 597 | int status; |
| 598 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 599 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 600 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 601 | |
| 602 | wrb = wrb_from_mbox(adapter); |
| 603 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 604 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 605 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 606 | OPCODE_COMMON_NTWK_MAC_QUERY); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 607 | |
| 608 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 609 | OPCODE_COMMON_NTWK_MAC_QUERY, sizeof(*req)); |
| 610 | |
| 611 | req->type = type; |
| 612 | if (permanent) { |
| 613 | req->permanent = 1; |
| 614 | } else { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 615 | req->if_id = cpu_to_le16((u16) if_handle); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 616 | req->permanent = 0; |
| 617 | } |
| 618 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 619 | status = be_mbox_notify_wait(adapter); |
| 620 | if (!status) { |
| 621 | struct be_cmd_resp_mac_query *resp = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 622 | memcpy(mac_addr, resp->mac.addr, ETH_ALEN); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 623 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 624 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 625 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 626 | return status; |
| 627 | } |
| 628 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 629 | /* Uses synchronous MCCQ */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 630 | int be_cmd_pmac_add(struct be_adapter *adapter, u8 *mac_addr, |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 631 | u32 if_id, u32 *pmac_id, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 632 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 633 | struct be_mcc_wrb *wrb; |
| 634 | struct be_cmd_req_pmac_add *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 635 | int status; |
| 636 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 637 | spin_lock_bh(&adapter->mcc_lock); |
| 638 | |
| 639 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 640 | if (!wrb) { |
| 641 | status = -EBUSY; |
| 642 | goto err; |
| 643 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 644 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 645 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 646 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 647 | OPCODE_COMMON_NTWK_PMAC_ADD); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 648 | |
| 649 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 650 | OPCODE_COMMON_NTWK_PMAC_ADD, sizeof(*req)); |
| 651 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 652 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 653 | req->if_id = cpu_to_le32(if_id); |
| 654 | memcpy(req->mac_address, mac_addr, ETH_ALEN); |
| 655 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 656 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 657 | if (!status) { |
| 658 | struct be_cmd_resp_pmac_add *resp = embedded_payload(wrb); |
| 659 | *pmac_id = le32_to_cpu(resp->pmac_id); |
| 660 | } |
| 661 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 662 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 663 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 664 | return status; |
| 665 | } |
| 666 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 667 | /* Uses synchronous MCCQ */ |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 668 | int be_cmd_pmac_del(struct be_adapter *adapter, u32 if_id, u32 pmac_id, u32 dom) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 669 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 670 | struct be_mcc_wrb *wrb; |
| 671 | struct be_cmd_req_pmac_del *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 672 | int status; |
| 673 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 674 | spin_lock_bh(&adapter->mcc_lock); |
| 675 | |
| 676 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 677 | if (!wrb) { |
| 678 | status = -EBUSY; |
| 679 | goto err; |
| 680 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 681 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 682 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 683 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 684 | OPCODE_COMMON_NTWK_PMAC_DEL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 685 | |
| 686 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 687 | OPCODE_COMMON_NTWK_PMAC_DEL, sizeof(*req)); |
| 688 | |
Ajit Khaparde | f8617e0 | 2011-02-11 13:36:37 +0000 | [diff] [blame] | 689 | req->hdr.domain = dom; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 690 | req->if_id = cpu_to_le32(if_id); |
| 691 | req->pmac_id = cpu_to_le32(pmac_id); |
| 692 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 693 | status = be_mcc_notify_wait(adapter); |
| 694 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 695 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 696 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 697 | return status; |
| 698 | } |
| 699 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 700 | /* Uses Mbox */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 701 | int be_cmd_cq_create(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 702 | struct be_queue_info *cq, struct be_queue_info *eq, |
| 703 | bool sol_evts, bool no_delay, int coalesce_wm) |
| 704 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 705 | struct be_mcc_wrb *wrb; |
| 706 | struct be_cmd_req_cq_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 707 | struct be_dma_mem *q_mem = &cq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 708 | void *ctxt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 709 | int status; |
| 710 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 711 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 712 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 713 | |
| 714 | wrb = wrb_from_mbox(adapter); |
| 715 | req = embedded_payload(wrb); |
| 716 | ctxt = &req->context; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 717 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 718 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 719 | OPCODE_COMMON_CQ_CREATE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 720 | |
| 721 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 722 | OPCODE_COMMON_CQ_CREATE, sizeof(*req)); |
| 723 | |
| 724 | 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] | 725 | if (lancer_chip(adapter)) { |
| 726 | req->hdr.version = 1; |
| 727 | req->page_size = 1; /* 1 for 4K */ |
| 728 | AMAP_SET_BITS(struct amap_cq_context_lancer, coalescwm, ctxt, |
| 729 | coalesce_wm); |
| 730 | AMAP_SET_BITS(struct amap_cq_context_lancer, nodelay, ctxt, |
| 731 | no_delay); |
| 732 | AMAP_SET_BITS(struct amap_cq_context_lancer, count, ctxt, |
| 733 | __ilog2_u32(cq->len/256)); |
| 734 | AMAP_SET_BITS(struct amap_cq_context_lancer, valid, ctxt, 1); |
| 735 | AMAP_SET_BITS(struct amap_cq_context_lancer, eventable, |
| 736 | ctxt, 1); |
| 737 | AMAP_SET_BITS(struct amap_cq_context_lancer, eqid, |
| 738 | ctxt, eq->id); |
| 739 | AMAP_SET_BITS(struct amap_cq_context_lancer, armed, ctxt, 1); |
| 740 | } else { |
| 741 | AMAP_SET_BITS(struct amap_cq_context_be, coalescwm, ctxt, |
| 742 | coalesce_wm); |
| 743 | AMAP_SET_BITS(struct amap_cq_context_be, nodelay, |
| 744 | ctxt, no_delay); |
| 745 | AMAP_SET_BITS(struct amap_cq_context_be, count, ctxt, |
| 746 | __ilog2_u32(cq->len/256)); |
| 747 | AMAP_SET_BITS(struct amap_cq_context_be, valid, ctxt, 1); |
| 748 | AMAP_SET_BITS(struct amap_cq_context_be, solevent, |
| 749 | ctxt, sol_evts); |
| 750 | AMAP_SET_BITS(struct amap_cq_context_be, eventable, ctxt, 1); |
| 751 | AMAP_SET_BITS(struct amap_cq_context_be, eqid, ctxt, eq->id); |
| 752 | AMAP_SET_BITS(struct amap_cq_context_be, armed, ctxt, 1); |
| 753 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 754 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 755 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 756 | |
| 757 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 758 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 759 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 760 | if (!status) { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 761 | struct be_cmd_resp_cq_create *resp = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 762 | cq->id = le16_to_cpu(resp->cq_id); |
| 763 | cq->created = true; |
| 764 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 765 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 766 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 767 | |
| 768 | return status; |
| 769 | } |
| 770 | |
| 771 | static u32 be_encoded_q_len(int q_len) |
| 772 | { |
| 773 | u32 len_encoded = fls(q_len); /* log2(len) + 1 */ |
| 774 | if (len_encoded == 16) |
| 775 | len_encoded = 0; |
| 776 | return len_encoded; |
| 777 | } |
| 778 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 779 | int be_cmd_mccq_create(struct be_adapter *adapter, |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 780 | struct be_queue_info *mccq, |
| 781 | struct be_queue_info *cq) |
| 782 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 783 | struct be_mcc_wrb *wrb; |
| 784 | struct be_cmd_req_mcc_create *req; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 785 | struct be_dma_mem *q_mem = &mccq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 786 | void *ctxt; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 787 | int status; |
| 788 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 789 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 790 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 791 | |
| 792 | wrb = wrb_from_mbox(adapter); |
| 793 | req = embedded_payload(wrb); |
| 794 | ctxt = &req->context; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 795 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 796 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 797 | OPCODE_COMMON_MCC_CREATE_EXT); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 798 | |
| 799 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 800 | OPCODE_COMMON_MCC_CREATE_EXT, sizeof(*req)); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 801 | |
Ajit Khaparde | d4a2ac3 | 2010-03-11 01:35:59 +0000 | [diff] [blame] | 802 | 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] | 803 | if (lancer_chip(adapter)) { |
| 804 | req->hdr.version = 1; |
| 805 | req->cq_id = cpu_to_le16(cq->id); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 806 | |
Sathya Perla | fe6d2a3 | 2010-11-21 23:25:50 +0000 | [diff] [blame] | 807 | AMAP_SET_BITS(struct amap_mcc_context_lancer, ring_size, ctxt, |
| 808 | be_encoded_q_len(mccq->len)); |
| 809 | AMAP_SET_BITS(struct amap_mcc_context_lancer, valid, ctxt, 1); |
| 810 | AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_id, |
| 811 | ctxt, cq->id); |
| 812 | AMAP_SET_BITS(struct amap_mcc_context_lancer, async_cq_valid, |
| 813 | ctxt, 1); |
| 814 | |
| 815 | } else { |
| 816 | AMAP_SET_BITS(struct amap_mcc_context_be, valid, ctxt, 1); |
| 817 | AMAP_SET_BITS(struct amap_mcc_context_be, ring_size, ctxt, |
| 818 | be_encoded_q_len(mccq->len)); |
| 819 | AMAP_SET_BITS(struct amap_mcc_context_be, cq_id, ctxt, cq->id); |
| 820 | } |
| 821 | |
Somnath Kotur | cc4ce02 | 2010-10-21 07:11:14 -0700 | [diff] [blame] | 822 | /* 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] | 823 | req->async_event_bitmap[0] = cpu_to_le32(0x00000022); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 824 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 825 | |
| 826 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 827 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 828 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 829 | if (!status) { |
| 830 | struct be_cmd_resp_mcc_create *resp = embedded_payload(wrb); |
| 831 | mccq->id = le16_to_cpu(resp->id); |
| 832 | mccq->created = true; |
| 833 | } |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 834 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 835 | |
| 836 | return status; |
| 837 | } |
| 838 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 839 | int be_cmd_txq_create(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 840 | struct be_queue_info *txq, |
| 841 | struct be_queue_info *cq) |
| 842 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 843 | struct be_mcc_wrb *wrb; |
| 844 | struct be_cmd_req_eth_tx_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 845 | struct be_dma_mem *q_mem = &txq->dma_mem; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 846 | void *ctxt; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 847 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 848 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 849 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 850 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 851 | |
| 852 | wrb = wrb_from_mbox(adapter); |
| 853 | req = embedded_payload(wrb); |
| 854 | ctxt = &req->context; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 855 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 856 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 857 | OPCODE_ETH_TX_CREATE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 858 | |
| 859 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_TX_CREATE, |
| 860 | sizeof(*req)); |
| 861 | |
| 862 | req->num_pages = PAGES_4K_SPANNED(q_mem->va, q_mem->size); |
| 863 | req->ulp_num = BE_ULP1_NUM; |
| 864 | req->type = BE_ETH_TX_RING_TYPE_STANDARD; |
| 865 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 866 | AMAP_SET_BITS(struct amap_tx_context, tx_ring_size, ctxt, |
| 867 | be_encoded_q_len(txq->len)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 868 | AMAP_SET_BITS(struct amap_tx_context, ctx_valid, ctxt, 1); |
| 869 | AMAP_SET_BITS(struct amap_tx_context, cq_id_send, ctxt, cq->id); |
| 870 | |
| 871 | be_dws_cpu_to_le(ctxt, sizeof(req->context)); |
| 872 | |
| 873 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 874 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 875 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 876 | if (!status) { |
| 877 | struct be_cmd_resp_eth_tx_create *resp = embedded_payload(wrb); |
| 878 | txq->id = le16_to_cpu(resp->cid); |
| 879 | txq->created = true; |
| 880 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 881 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 882 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 883 | |
| 884 | return status; |
| 885 | } |
| 886 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 887 | /* Uses mbox */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 888 | int be_cmd_rxq_create(struct be_adapter *adapter, |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 889 | struct be_queue_info *rxq, u16 cq_id, u16 frag_size, |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 890 | u16 max_frame_size, u32 if_id, u32 rss, u8 *rss_id) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 891 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 892 | struct be_mcc_wrb *wrb; |
| 893 | struct be_cmd_req_eth_rx_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 894 | struct be_dma_mem *q_mem = &rxq->dma_mem; |
| 895 | int status; |
| 896 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 897 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 898 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 899 | |
| 900 | wrb = wrb_from_mbox(adapter); |
| 901 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 902 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 903 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 904 | OPCODE_ETH_RX_CREATE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 905 | |
| 906 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, OPCODE_ETH_RX_CREATE, |
| 907 | sizeof(*req)); |
| 908 | |
| 909 | req->cq_id = cpu_to_le16(cq_id); |
| 910 | req->frag_size = fls(frag_size) - 1; |
| 911 | req->num_pages = 2; |
| 912 | be_cmd_page_addrs_prepare(req->pages, ARRAY_SIZE(req->pages), q_mem); |
| 913 | req->interface_id = cpu_to_le32(if_id); |
| 914 | req->max_frame_size = cpu_to_le16(max_frame_size); |
| 915 | req->rss_queue = cpu_to_le32(rss); |
| 916 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 917 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 918 | if (!status) { |
| 919 | struct be_cmd_resp_eth_rx_create *resp = embedded_payload(wrb); |
| 920 | rxq->id = le16_to_cpu(resp->id); |
| 921 | rxq->created = true; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 922 | *rss_id = resp->rss_id; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 923 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 924 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 925 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 926 | |
| 927 | return status; |
| 928 | } |
| 929 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 930 | /* Generic destroyer function for all types of queues |
| 931 | * Uses Mbox |
| 932 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 933 | 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] | 934 | int queue_type) |
| 935 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 936 | struct be_mcc_wrb *wrb; |
| 937 | struct be_cmd_req_q_destroy *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 938 | u8 subsys = 0, opcode = 0; |
| 939 | int status; |
| 940 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 941 | if (adapter->eeh_err) |
| 942 | return -EIO; |
| 943 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 944 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 945 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 946 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 947 | wrb = wrb_from_mbox(adapter); |
| 948 | req = embedded_payload(wrb); |
| 949 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 950 | switch (queue_type) { |
| 951 | case QTYPE_EQ: |
| 952 | subsys = CMD_SUBSYSTEM_COMMON; |
| 953 | opcode = OPCODE_COMMON_EQ_DESTROY; |
| 954 | break; |
| 955 | case QTYPE_CQ: |
| 956 | subsys = CMD_SUBSYSTEM_COMMON; |
| 957 | opcode = OPCODE_COMMON_CQ_DESTROY; |
| 958 | break; |
| 959 | case QTYPE_TXQ: |
| 960 | subsys = CMD_SUBSYSTEM_ETH; |
| 961 | opcode = OPCODE_ETH_TX_DESTROY; |
| 962 | break; |
| 963 | case QTYPE_RXQ: |
| 964 | subsys = CMD_SUBSYSTEM_ETH; |
| 965 | opcode = OPCODE_ETH_RX_DESTROY; |
| 966 | break; |
Sathya Perla | 5fb379e | 2009-06-18 00:02:59 +0000 | [diff] [blame] | 967 | case QTYPE_MCCQ: |
| 968 | subsys = CMD_SUBSYSTEM_COMMON; |
| 969 | opcode = OPCODE_COMMON_MCC_DESTROY; |
| 970 | break; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 971 | default: |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 972 | BUG(); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 973 | } |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 974 | |
| 975 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, opcode); |
| 976 | |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 977 | be_cmd_hdr_prepare(&req->hdr, subsys, opcode, sizeof(*req)); |
| 978 | req->id = cpu_to_le16(q->id); |
| 979 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 980 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 5f0b849 | 2009-07-27 22:52:56 +0000 | [diff] [blame] | 981 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 982 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 983 | |
| 984 | return status; |
| 985 | } |
| 986 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 987 | /* Create an rx filtering policy configuration on an i/f |
| 988 | * Uses mbox |
| 989 | */ |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 990 | int be_cmd_if_create(struct be_adapter *adapter, u32 cap_flags, u32 en_flags, |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 991 | u8 *mac, bool pmac_invalid, u32 *if_handle, u32 *pmac_id, |
| 992 | u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 993 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 994 | struct be_mcc_wrb *wrb; |
| 995 | struct be_cmd_req_if_create *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 996 | int status; |
| 997 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 998 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 999 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1000 | |
| 1001 | wrb = wrb_from_mbox(adapter); |
| 1002 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1003 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1004 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1005 | OPCODE_COMMON_NTWK_INTERFACE_CREATE); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1006 | |
| 1007 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1008 | OPCODE_COMMON_NTWK_INTERFACE_CREATE, sizeof(*req)); |
| 1009 | |
Sarveshwar Bandi | ba343c7 | 2010-03-31 02:56:12 +0000 | [diff] [blame] | 1010 | req->hdr.domain = domain; |
Sathya Perla | 73d540f | 2009-10-14 20:20:42 +0000 | [diff] [blame] | 1011 | req->capability_flags = cpu_to_le32(cap_flags); |
| 1012 | req->enable_flags = cpu_to_le32(en_flags); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1013 | req->pmac_invalid = pmac_invalid; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1014 | if (!pmac_invalid) |
| 1015 | memcpy(req->mac_addr, mac, ETH_ALEN); |
| 1016 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1017 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1018 | if (!status) { |
| 1019 | struct be_cmd_resp_if_create *resp = embedded_payload(wrb); |
| 1020 | *if_handle = le32_to_cpu(resp->interface_id); |
| 1021 | if (!pmac_invalid) |
| 1022 | *pmac_id = le32_to_cpu(resp->pmac_id); |
| 1023 | } |
| 1024 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1025 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1026 | return status; |
| 1027 | } |
| 1028 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1029 | /* Uses mbox */ |
Ajit Khaparde | 658681f | 2011-02-11 13:34:46 +0000 | [diff] [blame] | 1030 | int be_cmd_if_destroy(struct be_adapter *adapter, u32 interface_id, u32 domain) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1031 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1032 | struct be_mcc_wrb *wrb; |
| 1033 | struct be_cmd_req_if_destroy *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1034 | int status; |
| 1035 | |
Sathya Perla | cf58847 | 2010-02-14 21:22:01 +0000 | [diff] [blame] | 1036 | if (adapter->eeh_err) |
| 1037 | return -EIO; |
| 1038 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1039 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1040 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1041 | |
| 1042 | wrb = wrb_from_mbox(adapter); |
| 1043 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1044 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1045 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1046 | OPCODE_COMMON_NTWK_INTERFACE_DESTROY); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1047 | |
| 1048 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1049 | OPCODE_COMMON_NTWK_INTERFACE_DESTROY, sizeof(*req)); |
| 1050 | |
Ajit Khaparde | 658681f | 2011-02-11 13:34:46 +0000 | [diff] [blame] | 1051 | req->hdr.domain = domain; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1052 | req->interface_id = cpu_to_le32(interface_id); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1053 | |
| 1054 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1055 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1056 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1057 | |
| 1058 | return status; |
| 1059 | } |
| 1060 | |
| 1061 | /* Get stats is a non embedded command: the request is not embedded inside |
| 1062 | * WRB but is a separate dma memory block |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1063 | * Uses asynchronous MCC |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1064 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1065 | 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] | 1066 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1067 | struct be_mcc_wrb *wrb; |
| 1068 | struct be_cmd_req_get_stats *req; |
| 1069 | struct be_sge *sge; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1070 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1071 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1072 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1073 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1074 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1075 | if (!wrb) { |
| 1076 | status = -EBUSY; |
| 1077 | goto err; |
| 1078 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1079 | req = nonemb_cmd->va; |
| 1080 | sge = nonembedded_sgl(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1081 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1082 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1, |
| 1083 | OPCODE_ETH_GET_STATISTICS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1084 | |
| 1085 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1086 | OPCODE_ETH_GET_STATISTICS, sizeof(*req)); |
| 1087 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); |
| 1088 | sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); |
| 1089 | sge->len = cpu_to_le32(nonemb_cmd->size); |
| 1090 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1091 | be_mcc_notify(adapter); |
Ajit Khaparde | b2aebe6 | 2011-02-20 11:41:39 +0000 | [diff] [blame] | 1092 | adapter->stats_cmd_sent = true; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1093 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1094 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1095 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1096 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1097 | } |
| 1098 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1099 | /* Uses synchronous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1100 | int be_cmd_link_status_query(struct be_adapter *adapter, |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1101 | bool *link_up, u8 *mac_speed, u16 *link_speed) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1102 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1103 | struct be_mcc_wrb *wrb; |
| 1104 | struct be_cmd_req_link_status *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1105 | int status; |
| 1106 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1107 | spin_lock_bh(&adapter->mcc_lock); |
| 1108 | |
| 1109 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1110 | if (!wrb) { |
| 1111 | status = -EBUSY; |
| 1112 | goto err; |
| 1113 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1114 | req = embedded_payload(wrb); |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1115 | |
| 1116 | *link_up = false; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1117 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1118 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1119 | OPCODE_COMMON_NTWK_LINK_STATUS_QUERY); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1120 | |
| 1121 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1122 | OPCODE_COMMON_NTWK_LINK_STATUS_QUERY, sizeof(*req)); |
| 1123 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1124 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1125 | if (!status) { |
| 1126 | struct be_cmd_resp_link_status *resp = embedded_payload(wrb); |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1127 | if (resp->mac_speed != PHY_LINK_SPEED_ZERO) { |
Sathya Perla | a8f447b | 2009-06-18 00:10:27 +0000 | [diff] [blame] | 1128 | *link_up = true; |
Sarveshwar Bandi | 0388f25 | 2009-10-28 04:15:20 -0700 | [diff] [blame] | 1129 | *link_speed = le16_to_cpu(resp->link_speed); |
| 1130 | *mac_speed = resp->mac_speed; |
| 1131 | } |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1132 | } |
| 1133 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1134 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1135 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1136 | return status; |
| 1137 | } |
| 1138 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1139 | /* Uses Mbox */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1140 | int be_cmd_get_fw_ver(struct be_adapter *adapter, char *fw_ver) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1141 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1142 | struct be_mcc_wrb *wrb; |
| 1143 | struct be_cmd_req_get_fw_version *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1144 | int status; |
| 1145 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1146 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1147 | return -1; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1148 | |
| 1149 | wrb = wrb_from_mbox(adapter); |
| 1150 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1151 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1152 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1153 | OPCODE_COMMON_GET_FW_VERSION); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1154 | |
| 1155 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1156 | OPCODE_COMMON_GET_FW_VERSION, sizeof(*req)); |
| 1157 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1158 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1159 | if (!status) { |
| 1160 | struct be_cmd_resp_get_fw_version *resp = embedded_payload(wrb); |
| 1161 | strncpy(fw_ver, resp->firmware_version_string, FW_VER_LEN); |
| 1162 | } |
| 1163 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1164 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1165 | return status; |
| 1166 | } |
| 1167 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1168 | /* set the EQ delay interval of an EQ to specified value |
| 1169 | * Uses async mcc |
| 1170 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1171 | 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] | 1172 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1173 | struct be_mcc_wrb *wrb; |
| 1174 | struct be_cmd_req_modify_eq_delay *req; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1175 | int status = 0; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1176 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1177 | spin_lock_bh(&adapter->mcc_lock); |
| 1178 | |
| 1179 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1180 | if (!wrb) { |
| 1181 | status = -EBUSY; |
| 1182 | goto err; |
| 1183 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1184 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1185 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1186 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1187 | OPCODE_COMMON_MODIFY_EQ_DELAY); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1188 | |
| 1189 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1190 | OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req)); |
| 1191 | |
| 1192 | req->num_eq = cpu_to_le32(1); |
| 1193 | req->delay[0].eq_id = cpu_to_le32(eq_id); |
| 1194 | req->delay[0].phase = 0; |
| 1195 | req->delay[0].delay_multiplier = cpu_to_le32(eqd); |
| 1196 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1197 | be_mcc_notify(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1198 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1199 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1200 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1201 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1202 | } |
| 1203 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1204 | /* Uses sycnhronous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1205 | 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] | 1206 | u32 num, bool untagged, bool promiscuous) |
| 1207 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1208 | struct be_mcc_wrb *wrb; |
| 1209 | struct be_cmd_req_vlan_config *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1210 | int status; |
| 1211 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1212 | spin_lock_bh(&adapter->mcc_lock); |
| 1213 | |
| 1214 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1215 | if (!wrb) { |
| 1216 | status = -EBUSY; |
| 1217 | goto err; |
| 1218 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1219 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1220 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1221 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1222 | OPCODE_COMMON_NTWK_VLAN_CONFIG); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1223 | |
| 1224 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1225 | OPCODE_COMMON_NTWK_VLAN_CONFIG, sizeof(*req)); |
| 1226 | |
| 1227 | req->interface_id = if_id; |
| 1228 | req->promiscuous = promiscuous; |
| 1229 | req->untagged = untagged; |
| 1230 | req->num_vlan = num; |
| 1231 | if (!promiscuous) { |
| 1232 | memcpy(req->normal_vlan, vtag_array, |
| 1233 | req->num_vlan * sizeof(vtag_array[0])); |
| 1234 | } |
| 1235 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1236 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1237 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1238 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1239 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1240 | return status; |
| 1241 | } |
| 1242 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1243 | /* Uses MCC for this command as it may be called in BH context |
| 1244 | * Uses synchronous mcc |
| 1245 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1246 | int be_cmd_promiscuous_config(struct be_adapter *adapter, u8 port_num, bool en) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1247 | { |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1248 | struct be_mcc_wrb *wrb; |
| 1249 | struct be_cmd_req_promiscuous_config *req; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1250 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1251 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1252 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1253 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1254 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1255 | if (!wrb) { |
| 1256 | status = -EBUSY; |
| 1257 | goto err; |
| 1258 | } |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1259 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1260 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1261 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, OPCODE_ETH_PROMISCUOUS); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1262 | |
| 1263 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1264 | OPCODE_ETH_PROMISCUOUS, sizeof(*req)); |
| 1265 | |
Sathya Perla | 69d7ce7 | 2010-04-11 22:35:27 +0000 | [diff] [blame] | 1266 | /* In FW versions X.102.149/X.101.487 and later, |
| 1267 | * the port setting associated only with the |
| 1268 | * issuing pci function will take effect |
| 1269 | */ |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1270 | if (port_num) |
| 1271 | req->port1_promiscuous = en; |
| 1272 | else |
| 1273 | req->port0_promiscuous = en; |
| 1274 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1275 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1276 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1277 | err: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1278 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1279 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1280 | } |
| 1281 | |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1282 | /* |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1283 | * Uses MCC for this command as it may be called in BH context |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1284 | * (mc == NULL) => multicast promiscous |
| 1285 | */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1286 | int be_cmd_multicast_set(struct be_adapter *adapter, u32 if_id, |
Jiri Pirko | 0ddf477 | 2010-02-20 00:13:58 +0000 | [diff] [blame] | 1287 | struct net_device *netdev, struct be_dma_mem *mem) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1288 | { |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1289 | struct be_mcc_wrb *wrb; |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1290 | struct be_cmd_req_mcast_mac_config *req = mem->va; |
| 1291 | struct be_sge *sge; |
| 1292 | int status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1293 | |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1294 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6ac7b68 | 2009-06-18 00:05:54 +0000 | [diff] [blame] | 1295 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1296 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1297 | if (!wrb) { |
| 1298 | status = -EBUSY; |
| 1299 | goto err; |
| 1300 | } |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1301 | sge = nonembedded_sgl(wrb); |
| 1302 | memset(req, 0, sizeof(*req)); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1303 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1304 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1, |
| 1305 | OPCODE_COMMON_NTWK_MULTICAST_SET); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1306 | sge->pa_hi = cpu_to_le32(upper_32_bits(mem->dma)); |
| 1307 | sge->pa_lo = cpu_to_le32(mem->dma & 0xFFFFFFFF); |
| 1308 | sge->len = cpu_to_le32(mem->size); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1309 | |
| 1310 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1311 | OPCODE_COMMON_NTWK_MULTICAST_SET, sizeof(*req)); |
| 1312 | |
| 1313 | req->interface_id = if_id; |
Jiri Pirko | 0ddf477 | 2010-02-20 00:13:58 +0000 | [diff] [blame] | 1314 | if (netdev) { |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1315 | int i; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1316 | struct netdev_hw_addr *ha; |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1317 | |
Jiri Pirko | 0ddf477 | 2010-02-20 00:13:58 +0000 | [diff] [blame] | 1318 | req->num_mac = cpu_to_le16(netdev_mc_count(netdev)); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1319 | |
Jiri Pirko | 0ddf477 | 2010-02-20 00:13:58 +0000 | [diff] [blame] | 1320 | i = 0; |
Jiri Pirko | 22bedad | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 1321 | netdev_for_each_mc_addr(ha, netdev) |
Joe Jin | 408cc29 | 2010-12-06 03:00:59 +0000 | [diff] [blame] | 1322 | memcpy(req->mac[i++].byte, ha->addr, ETH_ALEN); |
Sathya Perla | 24307ee | 2009-06-18 00:09:25 +0000 | [diff] [blame] | 1323 | } else { |
| 1324 | req->promiscuous = 1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1325 | } |
| 1326 | |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1327 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1328 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1329 | err: |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1330 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | e7b909a | 2009-11-22 22:01:10 +0000 | [diff] [blame] | 1331 | return status; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1334 | /* Uses synchrounous mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1335 | 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] | 1336 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1337 | struct be_mcc_wrb *wrb; |
| 1338 | struct be_cmd_req_set_flow_control *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1339 | int status; |
| 1340 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1341 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1342 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1343 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1344 | if (!wrb) { |
| 1345 | status = -EBUSY; |
| 1346 | goto err; |
| 1347 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1348 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1349 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1350 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1351 | OPCODE_COMMON_SET_FLOW_CONTROL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1352 | |
| 1353 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1354 | OPCODE_COMMON_SET_FLOW_CONTROL, sizeof(*req)); |
| 1355 | |
| 1356 | req->tx_flow_control = cpu_to_le16((u16)tx_fc); |
| 1357 | req->rx_flow_control = cpu_to_le16((u16)rx_fc); |
| 1358 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1359 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1360 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1361 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1362 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1363 | return status; |
| 1364 | } |
| 1365 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1366 | /* Uses sycn mcc */ |
Sathya Perla | 8788fdc | 2009-07-27 22:52:03 +0000 | [diff] [blame] | 1367 | 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] | 1368 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1369 | struct be_mcc_wrb *wrb; |
| 1370 | struct be_cmd_req_get_flow_control *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1371 | int status; |
| 1372 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1373 | spin_lock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1374 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1375 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1376 | if (!wrb) { |
| 1377 | status = -EBUSY; |
| 1378 | goto err; |
| 1379 | } |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1380 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1381 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1382 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1383 | OPCODE_COMMON_GET_FLOW_CONTROL); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1384 | |
| 1385 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1386 | OPCODE_COMMON_GET_FLOW_CONTROL, sizeof(*req)); |
| 1387 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1388 | status = be_mcc_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1389 | if (!status) { |
| 1390 | struct be_cmd_resp_get_flow_control *resp = |
| 1391 | embedded_payload(wrb); |
| 1392 | *tx_fc = le16_to_cpu(resp->tx_flow_control); |
| 1393 | *rx_fc = le16_to_cpu(resp->rx_flow_control); |
| 1394 | } |
| 1395 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1396 | err: |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1397 | spin_unlock_bh(&adapter->mcc_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1398 | return status; |
| 1399 | } |
| 1400 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1401 | /* Uses mbox */ |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1402 | int be_cmd_query_fw_cfg(struct be_adapter *adapter, u32 *port_num, |
| 1403 | u32 *mode, u32 *caps) |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1404 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1405 | struct be_mcc_wrb *wrb; |
| 1406 | struct be_cmd_req_query_fw_cfg *req; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1407 | int status; |
| 1408 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1409 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1410 | return -1; |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1411 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1412 | wrb = wrb_from_mbox(adapter); |
| 1413 | req = embedded_payload(wrb); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1414 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1415 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1416 | OPCODE_COMMON_QUERY_FIRMWARE_CONFIG); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1417 | |
| 1418 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1419 | OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req)); |
| 1420 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1421 | status = be_mbox_notify_wait(adapter); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1422 | if (!status) { |
| 1423 | struct be_cmd_resp_query_fw_cfg *resp = embedded_payload(wrb); |
| 1424 | *port_num = le32_to_cpu(resp->phys_port); |
Ajit Khaparde | 3486be2 | 2010-07-23 02:04:54 +0000 | [diff] [blame] | 1425 | *mode = le32_to_cpu(resp->function_mode); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1426 | *caps = le32_to_cpu(resp->function_caps); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1427 | } |
| 1428 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1429 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 6b7c5b9 | 2009-03-11 23:32:03 -0700 | [diff] [blame] | 1430 | return status; |
| 1431 | } |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1432 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1433 | /* Uses mbox */ |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1434 | int be_cmd_reset_function(struct be_adapter *adapter) |
| 1435 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1436 | struct be_mcc_wrb *wrb; |
| 1437 | struct be_cmd_req_hdr *req; |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1438 | int status; |
| 1439 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1440 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1441 | return -1; |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1442 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1443 | wrb = wrb_from_mbox(adapter); |
| 1444 | req = embedded_payload(wrb); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1445 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1446 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1447 | OPCODE_COMMON_FUNCTION_RESET); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1448 | |
| 1449 | be_cmd_hdr_prepare(req, CMD_SUBSYSTEM_COMMON, |
| 1450 | OPCODE_COMMON_FUNCTION_RESET, sizeof(*req)); |
| 1451 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1452 | status = be_mbox_notify_wait(adapter); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1453 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1454 | mutex_unlock(&adapter->mbox_lock); |
sarveshwarb | 14074ea | 2009-08-05 13:05:24 -0700 | [diff] [blame] | 1455 | return status; |
| 1456 | } |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1457 | |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1458 | int be_cmd_rss_config(struct be_adapter *adapter, u8 *rsstable, u16 table_size) |
| 1459 | { |
| 1460 | struct be_mcc_wrb *wrb; |
| 1461 | struct be_cmd_req_rss_config *req; |
| 1462 | u32 myhash[10]; |
| 1463 | int status; |
| 1464 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1465 | if (mutex_lock_interruptible(&adapter->mbox_lock)) |
| 1466 | return -1; |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1467 | |
| 1468 | wrb = wrb_from_mbox(adapter); |
| 1469 | req = embedded_payload(wrb); |
| 1470 | |
| 1471 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1472 | OPCODE_ETH_RSS_CONFIG); |
| 1473 | |
| 1474 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1475 | OPCODE_ETH_RSS_CONFIG, sizeof(*req)); |
| 1476 | |
| 1477 | req->if_id = cpu_to_le32(adapter->if_handle); |
| 1478 | req->enable_rss = cpu_to_le16(RSS_ENABLE_TCP_IPV4 | RSS_ENABLE_IPV4); |
| 1479 | req->cpu_table_size_log2 = cpu_to_le16(fls(table_size) - 1); |
| 1480 | memcpy(req->cpu_table, rsstable, table_size); |
| 1481 | memcpy(req->hash, myhash, sizeof(myhash)); |
| 1482 | be_dws_cpu_to_le(req->hash, sizeof(req->hash)); |
| 1483 | |
| 1484 | status = be_mbox_notify_wait(adapter); |
| 1485 | |
Ivan Vecera | 2984961 | 2010-12-14 05:43:19 +0000 | [diff] [blame] | 1486 | mutex_unlock(&adapter->mbox_lock); |
Sathya Perla | 3abcded | 2010-10-03 22:12:27 -0700 | [diff] [blame] | 1487 | return status; |
| 1488 | } |
| 1489 | |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1490 | /* Uses sync mcc */ |
| 1491 | int be_cmd_set_beacon_state(struct be_adapter *adapter, u8 port_num, |
| 1492 | u8 bcn, u8 sts, u8 state) |
| 1493 | { |
| 1494 | struct be_mcc_wrb *wrb; |
| 1495 | struct be_cmd_req_enable_disable_beacon *req; |
| 1496 | int status; |
| 1497 | |
| 1498 | spin_lock_bh(&adapter->mcc_lock); |
| 1499 | |
| 1500 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1501 | if (!wrb) { |
| 1502 | status = -EBUSY; |
| 1503 | goto err; |
| 1504 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1505 | req = embedded_payload(wrb); |
| 1506 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1507 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1508 | OPCODE_COMMON_ENABLE_DISABLE_BEACON); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1509 | |
| 1510 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1511 | OPCODE_COMMON_ENABLE_DISABLE_BEACON, sizeof(*req)); |
| 1512 | |
| 1513 | req->port_num = port_num; |
| 1514 | req->beacon_state = state; |
| 1515 | req->beacon_duration = bcn; |
| 1516 | req->status_duration = sts; |
| 1517 | |
| 1518 | status = be_mcc_notify_wait(adapter); |
| 1519 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1520 | err: |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1521 | spin_unlock_bh(&adapter->mcc_lock); |
| 1522 | return status; |
| 1523 | } |
| 1524 | |
| 1525 | /* Uses sync mcc */ |
| 1526 | int be_cmd_get_beacon_state(struct be_adapter *adapter, u8 port_num, u32 *state) |
| 1527 | { |
| 1528 | struct be_mcc_wrb *wrb; |
| 1529 | struct be_cmd_req_get_beacon_state *req; |
| 1530 | int status; |
| 1531 | |
| 1532 | spin_lock_bh(&adapter->mcc_lock); |
| 1533 | |
| 1534 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1535 | if (!wrb) { |
| 1536 | status = -EBUSY; |
| 1537 | goto err; |
| 1538 | } |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1539 | req = embedded_payload(wrb); |
| 1540 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1541 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1542 | OPCODE_COMMON_GET_BEACON_STATE); |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1543 | |
| 1544 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1545 | OPCODE_COMMON_GET_BEACON_STATE, sizeof(*req)); |
| 1546 | |
| 1547 | req->port_num = port_num; |
| 1548 | |
| 1549 | status = be_mcc_notify_wait(adapter); |
| 1550 | if (!status) { |
| 1551 | struct be_cmd_resp_get_beacon_state *resp = |
| 1552 | embedded_payload(wrb); |
| 1553 | *state = resp->beacon_state; |
| 1554 | } |
| 1555 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1556 | err: |
Sarveshwar Bandi | fad9ab2 | 2009-10-12 04:23:15 -0700 | [diff] [blame] | 1557 | spin_unlock_bh(&adapter->mcc_lock); |
| 1558 | return status; |
| 1559 | } |
| 1560 | |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1561 | int be_cmd_write_flashrom(struct be_adapter *adapter, struct be_dma_mem *cmd, |
| 1562 | u32 flash_type, u32 flash_opcode, u32 buf_size) |
| 1563 | { |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1564 | struct be_mcc_wrb *wrb; |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1565 | struct be_cmd_write_flashrom *req; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1566 | struct be_sge *sge; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1567 | int status; |
| 1568 | |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1569 | spin_lock_bh(&adapter->mcc_lock); |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 1570 | adapter->flash_status = 0; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1571 | |
| 1572 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1573 | if (!wrb) { |
| 1574 | status = -EBUSY; |
Dan Carpenter | 2892d9c | 2010-05-26 04:46:35 +0000 | [diff] [blame] | 1575 | goto err_unlock; |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1576 | } |
| 1577 | req = cmd->va; |
Sathya Perla | b31c50a | 2009-09-17 10:30:13 -0700 | [diff] [blame] | 1578 | sge = nonembedded_sgl(wrb); |
| 1579 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1580 | be_wrb_hdr_prepare(wrb, cmd->size, false, 1, |
| 1581 | OPCODE_COMMON_WRITE_FLASHROM); |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 1582 | wrb->tag1 = CMD_SUBSYSTEM_COMMON; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1583 | |
| 1584 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1585 | OPCODE_COMMON_WRITE_FLASHROM, cmd->size); |
| 1586 | sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma)); |
| 1587 | sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF); |
| 1588 | sge->len = cpu_to_le32(cmd->size); |
| 1589 | |
| 1590 | req->params.op_type = cpu_to_le32(flash_type); |
| 1591 | req->params.op_code = cpu_to_le32(flash_opcode); |
| 1592 | req->params.data_buf_size = cpu_to_le32(buf_size); |
| 1593 | |
Sarveshwar Bandi | dd131e7 | 2010-05-25 16:16:32 -0700 | [diff] [blame] | 1594 | be_mcc_notify(adapter); |
| 1595 | spin_unlock_bh(&adapter->mcc_lock); |
| 1596 | |
| 1597 | if (!wait_for_completion_timeout(&adapter->flash_compl, |
| 1598 | msecs_to_jiffies(12000))) |
| 1599 | status = -1; |
| 1600 | else |
| 1601 | status = adapter->flash_status; |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1602 | |
Dan Carpenter | 2892d9c | 2010-05-26 04:46:35 +0000 | [diff] [blame] | 1603 | return status; |
| 1604 | |
| 1605 | err_unlock: |
| 1606 | spin_unlock_bh(&adapter->mcc_lock); |
Ajit Khaparde | 8451748 | 2009-09-04 03:12:16 +0000 | [diff] [blame] | 1607 | return status; |
| 1608 | } |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1609 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1610 | int be_cmd_get_flash_crc(struct be_adapter *adapter, u8 *flashed_crc, |
| 1611 | int offset) |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1612 | { |
| 1613 | struct be_mcc_wrb *wrb; |
| 1614 | struct be_cmd_write_flashrom *req; |
| 1615 | int status; |
| 1616 | |
| 1617 | spin_lock_bh(&adapter->mcc_lock); |
| 1618 | |
| 1619 | wrb = wrb_from_mccq(adapter); |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1620 | if (!wrb) { |
| 1621 | status = -EBUSY; |
| 1622 | goto err; |
| 1623 | } |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1624 | req = embedded_payload(wrb); |
| 1625 | |
Ajit Khaparde | d744b44 | 2009-12-03 06:12:06 +0000 | [diff] [blame] | 1626 | be_wrb_hdr_prepare(wrb, sizeof(*req)+4, true, 0, |
| 1627 | OPCODE_COMMON_READ_FLASHROM); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1628 | |
| 1629 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1630 | OPCODE_COMMON_READ_FLASHROM, sizeof(*req)+4); |
| 1631 | |
Ajit Khaparde | 3f0d456 | 2010-02-09 01:30:35 +0000 | [diff] [blame] | 1632 | req->params.op_type = cpu_to_le32(IMG_TYPE_REDBOOT); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1633 | req->params.op_code = cpu_to_le32(FLASHROM_OPER_REPORT); |
Ajit Khaparde | 8b93b71 | 2010-03-31 01:57:10 +0000 | [diff] [blame] | 1634 | req->params.offset = cpu_to_le32(offset); |
| 1635 | req->params.data_buf_size = cpu_to_le32(0x4); |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1636 | |
| 1637 | status = be_mcc_notify_wait(adapter); |
| 1638 | if (!status) |
| 1639 | memcpy(flashed_crc, req->params.data_buf, 4); |
| 1640 | |
Sathya Perla | 713d0394 | 2009-11-22 22:02:45 +0000 | [diff] [blame] | 1641 | err: |
Sarveshwar Bandi | fa9a6fe | 2009-11-20 14:23:47 -0800 | [diff] [blame] | 1642 | spin_unlock_bh(&adapter->mcc_lock); |
| 1643 | return status; |
| 1644 | } |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 1645 | |
Dan Carpenter | c196b02 | 2010-05-26 04:47:39 +0000 | [diff] [blame] | 1646 | int be_cmd_enable_magic_wol(struct be_adapter *adapter, u8 *mac, |
Ajit Khaparde | 71d8d1b | 2009-12-03 06:16:59 +0000 | [diff] [blame] | 1647 | struct be_dma_mem *nonemb_cmd) |
| 1648 | { |
| 1649 | struct be_mcc_wrb *wrb; |
| 1650 | struct be_cmd_req_acpi_wol_magic_config *req; |
| 1651 | struct be_sge *sge; |
| 1652 | int status; |
| 1653 | |
| 1654 | spin_lock_bh(&adapter->mcc_lock); |
| 1655 | |
| 1656 | wrb = wrb_from_mccq(adapter); |
| 1657 | if (!wrb) { |
| 1658 | status = -EBUSY; |
| 1659 | goto err; |
| 1660 | } |
| 1661 | req = nonemb_cmd->va; |
| 1662 | sge = nonembedded_sgl(wrb); |
| 1663 | |
| 1664 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1, |
| 1665 | OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG); |
| 1666 | |
| 1667 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ETH, |
| 1668 | OPCODE_ETH_ACPI_WOL_MAGIC_CONFIG, sizeof(*req)); |
| 1669 | memcpy(req->magic_mac, mac, ETH_ALEN); |
| 1670 | |
| 1671 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); |
| 1672 | sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); |
| 1673 | sge->len = cpu_to_le32(nonemb_cmd->size); |
| 1674 | |
| 1675 | status = be_mcc_notify_wait(adapter); |
| 1676 | |
| 1677 | err: |
| 1678 | spin_unlock_bh(&adapter->mcc_lock); |
| 1679 | return status; |
| 1680 | } |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 1681 | |
Sarveshwar Bandi | fced999 | 2009-12-23 04:41:44 +0000 | [diff] [blame] | 1682 | int be_cmd_set_loopback(struct be_adapter *adapter, u8 port_num, |
| 1683 | u8 loopback_type, u8 enable) |
| 1684 | { |
| 1685 | struct be_mcc_wrb *wrb; |
| 1686 | struct be_cmd_req_set_lmode *req; |
| 1687 | int status; |
| 1688 | |
| 1689 | spin_lock_bh(&adapter->mcc_lock); |
| 1690 | |
| 1691 | wrb = wrb_from_mccq(adapter); |
| 1692 | if (!wrb) { |
| 1693 | status = -EBUSY; |
| 1694 | goto err; |
| 1695 | } |
| 1696 | |
| 1697 | req = embedded_payload(wrb); |
| 1698 | |
| 1699 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1700 | OPCODE_LOWLEVEL_SET_LOOPBACK_MODE); |
| 1701 | |
| 1702 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
| 1703 | OPCODE_LOWLEVEL_SET_LOOPBACK_MODE, |
| 1704 | sizeof(*req)); |
| 1705 | |
| 1706 | req->src_port = port_num; |
| 1707 | req->dest_port = port_num; |
| 1708 | req->loopback_type = loopback_type; |
| 1709 | req->loopback_state = enable; |
| 1710 | |
| 1711 | status = be_mcc_notify_wait(adapter); |
| 1712 | err: |
| 1713 | spin_unlock_bh(&adapter->mcc_lock); |
| 1714 | return status; |
| 1715 | } |
| 1716 | |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 1717 | int be_cmd_loopback_test(struct be_adapter *adapter, u32 port_num, |
| 1718 | u32 loopback_type, u32 pkt_size, u32 num_pkts, u64 pattern) |
| 1719 | { |
| 1720 | struct be_mcc_wrb *wrb; |
| 1721 | struct be_cmd_req_loopback_test *req; |
| 1722 | int status; |
| 1723 | |
| 1724 | spin_lock_bh(&adapter->mcc_lock); |
| 1725 | |
| 1726 | wrb = wrb_from_mccq(adapter); |
| 1727 | if (!wrb) { |
| 1728 | status = -EBUSY; |
| 1729 | goto err; |
| 1730 | } |
| 1731 | |
| 1732 | req = embedded_payload(wrb); |
| 1733 | |
| 1734 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1735 | OPCODE_LOWLEVEL_LOOPBACK_TEST); |
| 1736 | |
| 1737 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
| 1738 | OPCODE_LOWLEVEL_LOOPBACK_TEST, sizeof(*req)); |
Sathya Perla | 3ffd051 | 2010-06-01 00:19:33 -0700 | [diff] [blame] | 1739 | req->hdr.timeout = cpu_to_le32(4); |
Suresh R | ff33a6e | 2009-12-03 16:15:52 -0800 | [diff] [blame] | 1740 | |
| 1741 | req->pattern = cpu_to_le64(pattern); |
| 1742 | req->src_port = cpu_to_le32(port_num); |
| 1743 | req->dest_port = cpu_to_le32(port_num); |
| 1744 | req->pkt_size = cpu_to_le32(pkt_size); |
| 1745 | req->num_pkts = cpu_to_le32(num_pkts); |
| 1746 | req->loopback_type = cpu_to_le32(loopback_type); |
| 1747 | |
| 1748 | status = be_mcc_notify_wait(adapter); |
| 1749 | if (!status) { |
| 1750 | struct be_cmd_resp_loopback_test *resp = embedded_payload(wrb); |
| 1751 | status = le32_to_cpu(resp->status); |
| 1752 | } |
| 1753 | |
| 1754 | err: |
| 1755 | spin_unlock_bh(&adapter->mcc_lock); |
| 1756 | return status; |
| 1757 | } |
| 1758 | |
| 1759 | int be_cmd_ddr_dma_test(struct be_adapter *adapter, u64 pattern, |
| 1760 | u32 byte_cnt, struct be_dma_mem *cmd) |
| 1761 | { |
| 1762 | struct be_mcc_wrb *wrb; |
| 1763 | struct be_cmd_req_ddrdma_test *req; |
| 1764 | struct be_sge *sge; |
| 1765 | int status; |
| 1766 | int i, j = 0; |
| 1767 | |
| 1768 | spin_lock_bh(&adapter->mcc_lock); |
| 1769 | |
| 1770 | wrb = wrb_from_mccq(adapter); |
| 1771 | if (!wrb) { |
| 1772 | status = -EBUSY; |
| 1773 | goto err; |
| 1774 | } |
| 1775 | req = cmd->va; |
| 1776 | sge = nonembedded_sgl(wrb); |
| 1777 | be_wrb_hdr_prepare(wrb, cmd->size, false, 1, |
| 1778 | OPCODE_LOWLEVEL_HOST_DDR_DMA); |
| 1779 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_LOWLEVEL, |
| 1780 | OPCODE_LOWLEVEL_HOST_DDR_DMA, cmd->size); |
| 1781 | |
| 1782 | sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma)); |
| 1783 | sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF); |
| 1784 | sge->len = cpu_to_le32(cmd->size); |
| 1785 | |
| 1786 | req->pattern = cpu_to_le64(pattern); |
| 1787 | req->byte_count = cpu_to_le32(byte_cnt); |
| 1788 | for (i = 0; i < byte_cnt; i++) { |
| 1789 | req->snd_buff[i] = (u8)(pattern >> (j*8)); |
| 1790 | j++; |
| 1791 | if (j > 7) |
| 1792 | j = 0; |
| 1793 | } |
| 1794 | |
| 1795 | status = be_mcc_notify_wait(adapter); |
| 1796 | |
| 1797 | if (!status) { |
| 1798 | struct be_cmd_resp_ddrdma_test *resp; |
| 1799 | resp = cmd->va; |
| 1800 | if ((memcmp(resp->rcv_buff, req->snd_buff, byte_cnt) != 0) || |
| 1801 | resp->snd_err) { |
| 1802 | status = -1; |
| 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | err: |
| 1807 | spin_unlock_bh(&adapter->mcc_lock); |
| 1808 | return status; |
| 1809 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 1810 | |
Dan Carpenter | c196b02 | 2010-05-26 04:47:39 +0000 | [diff] [blame] | 1811 | int be_cmd_get_seeprom_data(struct be_adapter *adapter, |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 1812 | struct be_dma_mem *nonemb_cmd) |
| 1813 | { |
| 1814 | struct be_mcc_wrb *wrb; |
| 1815 | struct be_cmd_req_seeprom_read *req; |
| 1816 | struct be_sge *sge; |
| 1817 | int status; |
| 1818 | |
| 1819 | spin_lock_bh(&adapter->mcc_lock); |
| 1820 | |
| 1821 | wrb = wrb_from_mccq(adapter); |
Ajit Khaparde | e45ff01 | 2011-02-04 17:18:28 +0000 | [diff] [blame] | 1822 | if (!wrb) { |
| 1823 | status = -EBUSY; |
| 1824 | goto err; |
| 1825 | } |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 1826 | req = nonemb_cmd->va; |
| 1827 | sge = nonembedded_sgl(wrb); |
| 1828 | |
| 1829 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1, |
| 1830 | OPCODE_COMMON_SEEPROM_READ); |
| 1831 | |
| 1832 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1833 | OPCODE_COMMON_SEEPROM_READ, sizeof(*req)); |
| 1834 | |
| 1835 | sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma)); |
| 1836 | sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF); |
| 1837 | sge->len = cpu_to_le32(nonemb_cmd->size); |
| 1838 | |
| 1839 | status = be_mcc_notify_wait(adapter); |
| 1840 | |
Ajit Khaparde | e45ff01 | 2011-02-04 17:18:28 +0000 | [diff] [blame] | 1841 | err: |
Sarveshwar Bandi | 368c0ca | 2010-01-08 00:07:27 -0800 | [diff] [blame] | 1842 | spin_unlock_bh(&adapter->mcc_lock); |
| 1843 | return status; |
| 1844 | } |
Ajit Khaparde | ee3cb62 | 2010-07-01 03:51:00 +0000 | [diff] [blame] | 1845 | |
| 1846 | int be_cmd_get_phy_info(struct be_adapter *adapter, struct be_dma_mem *cmd) |
| 1847 | { |
| 1848 | struct be_mcc_wrb *wrb; |
| 1849 | struct be_cmd_req_get_phy_info *req; |
| 1850 | struct be_sge *sge; |
| 1851 | int status; |
| 1852 | |
| 1853 | spin_lock_bh(&adapter->mcc_lock); |
| 1854 | |
| 1855 | wrb = wrb_from_mccq(adapter); |
| 1856 | if (!wrb) { |
| 1857 | status = -EBUSY; |
| 1858 | goto err; |
| 1859 | } |
| 1860 | |
| 1861 | req = cmd->va; |
| 1862 | sge = nonembedded_sgl(wrb); |
| 1863 | |
| 1864 | be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1, |
| 1865 | OPCODE_COMMON_GET_PHY_DETAILS); |
| 1866 | |
| 1867 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1868 | OPCODE_COMMON_GET_PHY_DETAILS, |
| 1869 | sizeof(*req)); |
| 1870 | |
| 1871 | sge->pa_hi = cpu_to_le32(upper_32_bits(cmd->dma)); |
| 1872 | sge->pa_lo = cpu_to_le32(cmd->dma & 0xFFFFFFFF); |
| 1873 | sge->len = cpu_to_le32(cmd->size); |
| 1874 | |
| 1875 | status = be_mcc_notify_wait(adapter); |
| 1876 | err: |
| 1877 | spin_unlock_bh(&adapter->mcc_lock); |
| 1878 | return status; |
| 1879 | } |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1880 | |
| 1881 | int be_cmd_set_qos(struct be_adapter *adapter, u32 bps, u32 domain) |
| 1882 | { |
| 1883 | struct be_mcc_wrb *wrb; |
| 1884 | struct be_cmd_req_set_qos *req; |
| 1885 | int status; |
| 1886 | |
| 1887 | spin_lock_bh(&adapter->mcc_lock); |
| 1888 | |
| 1889 | wrb = wrb_from_mccq(adapter); |
| 1890 | if (!wrb) { |
| 1891 | status = -EBUSY; |
| 1892 | goto err; |
| 1893 | } |
| 1894 | |
| 1895 | req = embedded_payload(wrb); |
| 1896 | |
| 1897 | be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0, |
| 1898 | OPCODE_COMMON_SET_QOS); |
| 1899 | |
| 1900 | be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON, |
| 1901 | OPCODE_COMMON_SET_QOS, sizeof(*req)); |
| 1902 | |
| 1903 | req->hdr.domain = domain; |
Ajit Khaparde | 6bff57a | 2011-02-11 13:33:02 +0000 | [diff] [blame] | 1904 | req->valid_bits = cpu_to_le32(BE_QOS_BITS_NIC); |
| 1905 | req->max_bps_nic = cpu_to_le32(bps); |
Ajit Khaparde | e1d1873 | 2010-07-23 01:52:13 +0000 | [diff] [blame] | 1906 | |
| 1907 | status = be_mcc_notify_wait(adapter); |
| 1908 | |
| 1909 | err: |
| 1910 | spin_unlock_bh(&adapter->mcc_lock); |
| 1911 | return status; |
| 1912 | } |