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