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