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