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