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