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