blob: 7d6d601a84203a39f4b2849b3bf6322c4078c65a [file] [log] [blame]
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001/* bnx2x_sp.c: Broadcom Everest network driver.
2 *
Yuval Mintz247fa822013-01-14 05:11:50 +00003 * Copyright (c) 2011-2013 Broadcom Corporation
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004 *
5 * Unless you and Broadcom execute a separate written software license
6 * agreement governing use of this software, this software is licensed to you
7 * under the terms of the GNU General Public License version 2, available
8 * at http://www.gnu.org/licenses/old-licenses/gpl-2.0.html (the "GPL").
9 *
10 * Notwithstanding the above, under no circumstances may you combine this
11 * software in any way with any other Broadcom software provided under a
12 * license other than the GPL, without Broadcom's express prior written
13 * consent.
14 *
15 * Maintained by: Eilon Greenstein <eilong@broadcom.com>
16 * Written by: Vladislav Zolotarov
17 *
18 */
Joe Perchesf1deab52011-08-14 12:16:21 +000019
20#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
21
Vladislav Zolotarov042181f2011-06-14 01:33:39 +000022#include <linux/module.h>
23#include <linux/crc32.h>
24#include <linux/netdevice.h>
25#include <linux/etherdevice.h>
26#include <linux/crc32c.h>
27#include "bnx2x.h"
28#include "bnx2x_cmn.h"
29#include "bnx2x_sp.h"
30
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030031#define BNX2X_MAX_EMUL_MULTI 16
32
Ariel Eliored5162a2011-12-05 21:52:24 +000033#define MAC_LEADING_ZERO_CNT (ALIGN(ETH_ALEN, sizeof(u32)) - ETH_ALEN)
34
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030035/**** Exe Queue interfaces ****/
Vladislav Zolotarov042181f2011-06-14 01:33:39 +000036
37/**
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030038 * bnx2x_exe_queue_init - init the Exe Queue object
39 *
40 * @o: poiter to the object
41 * @exe_len: length
42 * @owner: poiter to the owner
43 * @validate: validate function pointer
44 * @optimize: optimize function pointer
45 * @exec: execute function pointer
46 * @get: get function pointer
47 */
48static inline void bnx2x_exe_queue_init(struct bnx2x *bp,
49 struct bnx2x_exe_queue_obj *o,
50 int exe_len,
51 union bnx2x_qable_obj *owner,
52 exe_q_validate validate,
Yuval Mintz460a25c2012-01-23 07:31:51 +000053 exe_q_remove remove,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030054 exe_q_optimize optimize,
55 exe_q_execute exec,
56 exe_q_get get)
57{
58 memset(o, 0, sizeof(*o));
59
60 INIT_LIST_HEAD(&o->exe_queue);
61 INIT_LIST_HEAD(&o->pending_comp);
62
63 spin_lock_init(&o->lock);
64
65 o->exe_chunk_len = exe_len;
66 o->owner = owner;
67
68 /* Owner specific callbacks */
69 o->validate = validate;
Yuval Mintz460a25c2012-01-23 07:31:51 +000070 o->remove = remove;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030071 o->optimize = optimize;
72 o->execute = exec;
73 o->get = get;
74
Merav Sicron51c1a582012-03-18 10:33:38 +000075 DP(BNX2X_MSG_SP, "Setup the execution queue with the chunk length of %d\n",
76 exe_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030077}
78
79static inline void bnx2x_exe_queue_free_elem(struct bnx2x *bp,
80 struct bnx2x_exeq_elem *elem)
81{
82 DP(BNX2X_MSG_SP, "Deleting an exe_queue element\n");
83 kfree(elem);
84}
85
86static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
87{
88 struct bnx2x_exeq_elem *elem;
89 int cnt = 0;
90
91 spin_lock_bh(&o->lock);
92
93 list_for_each_entry(elem, &o->exe_queue, link)
94 cnt++;
95
96 spin_unlock_bh(&o->lock);
97
98 return cnt;
99}
100
101/**
102 * bnx2x_exe_queue_add - add a new element to the execution queue
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000103 *
104 * @bp: driver handle
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300105 * @o: queue
106 * @cmd: new command to add
107 * @restore: true - do not optimize the command
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000108 *
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300109 * If the element is optimized or is illegal, frees it.
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000110 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300111static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
112 struct bnx2x_exe_queue_obj *o,
113 struct bnx2x_exeq_elem *elem,
114 bool restore)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000115{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300116 int rc;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000117
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300118 spin_lock_bh(&o->lock);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000119
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300120 if (!restore) {
121 /* Try to cancel this element queue */
122 rc = o->optimize(bp, o->owner, elem);
123 if (rc)
124 goto free_and_exit;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000125
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300126 /* Check if this request is ok */
127 rc = o->validate(bp, o->owner, elem);
128 if (rc) {
Dmitry Kravkov2384d6a2012-10-16 01:28:27 +0000129 DP(BNX2X_MSG_SP, "Preamble failed: %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300130 goto free_and_exit;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000131 }
132 }
133
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300134 /* If so, add it to the execution queue */
135 list_add_tail(&elem->link, &o->exe_queue);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000136
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300137 spin_unlock_bh(&o->lock);
138
139 return 0;
140
141free_and_exit:
142 bnx2x_exe_queue_free_elem(bp, elem);
143
144 spin_unlock_bh(&o->lock);
145
146 return rc;
147
148}
149
150static inline void __bnx2x_exe_queue_reset_pending(
151 struct bnx2x *bp,
152 struct bnx2x_exe_queue_obj *o)
153{
154 struct bnx2x_exeq_elem *elem;
155
156 while (!list_empty(&o->pending_comp)) {
157 elem = list_first_entry(&o->pending_comp,
158 struct bnx2x_exeq_elem, link);
159
160 list_del(&elem->link);
161 bnx2x_exe_queue_free_elem(bp, elem);
162 }
163}
164
165static inline void bnx2x_exe_queue_reset_pending(struct bnx2x *bp,
166 struct bnx2x_exe_queue_obj *o)
167{
168
169 spin_lock_bh(&o->lock);
170
171 __bnx2x_exe_queue_reset_pending(bp, o);
172
173 spin_unlock_bh(&o->lock);
174
175}
176
177/**
178 * bnx2x_exe_queue_step - execute one execution chunk atomically
179 *
180 * @bp: driver handle
181 * @o: queue
182 * @ramrod_flags: flags
183 *
184 * (Atomicy is ensured using the exe_queue->lock).
185 */
186static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
187 struct bnx2x_exe_queue_obj *o,
188 unsigned long *ramrod_flags)
189{
190 struct bnx2x_exeq_elem *elem, spacer;
191 int cur_len = 0, rc;
192
193 memset(&spacer, 0, sizeof(spacer));
194
195 spin_lock_bh(&o->lock);
196
197 /*
198 * Next step should not be performed until the current is finished,
199 * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
200 * properly clear object internals without sending any command to the FW
201 * which also implies there won't be any completion to clear the
202 * 'pending' list.
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000203 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300204 if (!list_empty(&o->pending_comp)) {
205 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000206 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300207 __bnx2x_exe_queue_reset_pending(bp, o);
208 } else {
209 spin_unlock_bh(&o->lock);
210 return 1;
211 }
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000212 }
213
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300214 /*
215 * Run through the pending commands list and create a next
216 * execution chunk.
217 */
218 while (!list_empty(&o->exe_queue)) {
219 elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
220 link);
221 WARN_ON(!elem->cmd_len);
222
223 if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
224 cur_len += elem->cmd_len;
225 /*
226 * Prevent from both lists being empty when moving an
227 * element. This will allow the call of
228 * bnx2x_exe_queue_empty() without locking.
229 */
230 list_add_tail(&spacer.link, &o->pending_comp);
231 mb();
Wei Yongjun7933aa52012-09-04 21:06:55 +0000232 list_move_tail(&elem->link, &o->pending_comp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300233 list_del(&spacer.link);
234 } else
235 break;
236 }
237
238 /* Sanity check */
239 if (!cur_len) {
240 spin_unlock_bh(&o->lock);
241 return 0;
242 }
243
244 rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
245 if (rc < 0)
246 /*
247 * In case of an error return the commands back to the queue
248 * and reset the pending_comp.
249 */
250 list_splice_init(&o->pending_comp, &o->exe_queue);
251 else if (!rc)
252 /*
253 * If zero is returned, means there are no outstanding pending
254 * completions and we may dismiss the pending list.
255 */
256 __bnx2x_exe_queue_reset_pending(bp, o);
257
258 spin_unlock_bh(&o->lock);
259 return rc;
260}
261
262static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj *o)
263{
264 bool empty = list_empty(&o->exe_queue);
265
266 /* Don't reorder!!! */
267 mb();
268
269 return empty && list_empty(&o->pending_comp);
270}
271
272static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
273 struct bnx2x *bp)
274{
275 DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
276 return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
277}
278
279/************************ raw_obj functions ***********************************/
280static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
281{
282 return !!test_bit(o->state, o->pstate);
283}
284
285static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
286{
287 smp_mb__before_clear_bit();
288 clear_bit(o->state, o->pstate);
289 smp_mb__after_clear_bit();
290}
291
292static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
293{
294 smp_mb__before_clear_bit();
295 set_bit(o->state, o->pstate);
296 smp_mb__after_clear_bit();
297}
298
299/**
300 * bnx2x_state_wait - wait until the given bit(state) is cleared
301 *
302 * @bp: device handle
303 * @state: state which is to be cleared
304 * @state_p: state buffer
305 *
306 */
307static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
308 unsigned long *pstate)
309{
310 /* can take a while if any port is running */
311 int cnt = 5000;
312
313
314 if (CHIP_REV_IS_EMUL(bp))
315 cnt *= 20;
316
317 DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
318
319 might_sleep();
320 while (cnt--) {
321 if (!test_bit(state, pstate)) {
322#ifdef BNX2X_STOP_ON_ERROR
323 DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt);
324#endif
325 return 0;
326 }
327
Yuval Mintz0926d492013-01-23 03:21:45 +0000328 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300329
330 if (bp->panic)
331 return -EIO;
332 }
333
334 /* timeout! */
335 BNX2X_ERR("timeout waiting for state %d\n", state);
336#ifdef BNX2X_STOP_ON_ERROR
337 bnx2x_panic();
338#endif
339
340 return -EBUSY;
341}
342
343static int bnx2x_raw_wait(struct bnx2x *bp, struct bnx2x_raw_obj *raw)
344{
345 return bnx2x_state_wait(bp, raw->state, raw->pstate);
346}
347
348/***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
349/* credit handling callbacks */
350static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
351{
352 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
353
354 WARN_ON(!mp);
355
356 return mp->get_entry(mp, offset);
357}
358
359static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
360{
361 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
362
363 WARN_ON(!mp);
364
365 return mp->get(mp, 1);
366}
367
368static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
369{
370 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
371
372 WARN_ON(!vp);
373
374 return vp->get_entry(vp, offset);
375}
376
377static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
378{
379 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
380
381 WARN_ON(!vp);
382
383 return vp->get(vp, 1);
384}
385
386static bool bnx2x_get_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
387{
388 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
389 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
390
391 if (!mp->get(mp, 1))
392 return false;
393
394 if (!vp->get(vp, 1)) {
395 mp->put(mp, 1);
396 return false;
397 }
398
399 return true;
400}
401
402static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int offset)
403{
404 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
405
406 return mp->put_entry(mp, offset);
407}
408
409static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj *o)
410{
411 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
412
413 return mp->put(mp, 1);
414}
415
416static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int offset)
417{
418 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
419
420 return vp->put_entry(vp, offset);
421}
422
423static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj *o)
424{
425 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
426
427 return vp->put(vp, 1);
428}
429
430static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
431{
432 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
433 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
434
435 if (!mp->put(mp, 1))
436 return false;
437
438 if (!vp->put(vp, 1)) {
439 mp->get(mp, 1);
440 return false;
441 }
442
443 return true;
444}
445
Ariel Eliored5162a2011-12-05 21:52:24 +0000446static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
447 int n, u8 *buf)
448{
449 struct bnx2x_vlan_mac_registry_elem *pos;
450 u8 *next = buf;
451 int counter = 0;
452
453 /* traverse list */
454 list_for_each_entry(pos, &o->head, link) {
455 if (counter < n) {
456 /* place leading zeroes in buffer */
457 memset(next, 0, MAC_LEADING_ZERO_CNT);
458
459 /* place mac after leading zeroes*/
460 memcpy(next + MAC_LEADING_ZERO_CNT, pos->u.mac.mac,
461 ETH_ALEN);
462
463 /* calculate address of next element and
464 * advance counter
465 */
466 counter++;
467 next = buf + counter * ALIGN(ETH_ALEN, sizeof(u32));
468
469 DP(BNX2X_MSG_SP, "copied element number %d to address %p element was %pM\n",
470 counter, next, pos->u.mac.mac);
471 }
472 }
473 return counter * ETH_ALEN;
474}
475
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300476/* check_add() callbacks */
Merav Sicron51c1a582012-03-18 10:33:38 +0000477static int bnx2x_check_mac_add(struct bnx2x *bp,
478 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300479 union bnx2x_classification_ramrod_data *data)
480{
481 struct bnx2x_vlan_mac_registry_elem *pos;
482
Merav Sicron51c1a582012-03-18 10:33:38 +0000483 DP(BNX2X_MSG_SP, "Checking MAC %pM for ADD command\n", data->mac.mac);
484
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300485 if (!is_valid_ether_addr(data->mac.mac))
486 return -EINVAL;
487
488 /* Check if a requested MAC already exists */
489 list_for_each_entry(pos, &o->head, link)
490 if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
491 return -EEXIST;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000492
493 return 0;
494}
495
Merav Sicron51c1a582012-03-18 10:33:38 +0000496static int bnx2x_check_vlan_add(struct bnx2x *bp,
497 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300498 union bnx2x_classification_ramrod_data *data)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000499{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300500 struct bnx2x_vlan_mac_registry_elem *pos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000501
Merav Sicron51c1a582012-03-18 10:33:38 +0000502 DP(BNX2X_MSG_SP, "Checking VLAN %d for ADD command\n", data->vlan.vlan);
503
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300504 list_for_each_entry(pos, &o->head, link)
505 if (data->vlan.vlan == pos->u.vlan.vlan)
506 return -EEXIST;
507
508 return 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000509}
510
Merav Sicron51c1a582012-03-18 10:33:38 +0000511static int bnx2x_check_vlan_mac_add(struct bnx2x *bp,
512 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300513 union bnx2x_classification_ramrod_data *data)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000514{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300515 struct bnx2x_vlan_mac_registry_elem *pos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000516
Merav Sicron51c1a582012-03-18 10:33:38 +0000517 DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for ADD command\n",
518 data->vlan_mac.mac, data->vlan_mac.vlan);
519
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300520 list_for_each_entry(pos, &o->head, link)
521 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
522 (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
523 ETH_ALEN)))
524 return -EEXIST;
525
526 return 0;
527}
528
529
530/* check_del() callbacks */
531static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000532 bnx2x_check_mac_del(struct bnx2x *bp,
533 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300534 union bnx2x_classification_ramrod_data *data)
535{
536 struct bnx2x_vlan_mac_registry_elem *pos;
537
Merav Sicron51c1a582012-03-18 10:33:38 +0000538 DP(BNX2X_MSG_SP, "Checking MAC %pM for DEL command\n", data->mac.mac);
539
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300540 list_for_each_entry(pos, &o->head, link)
541 if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN))
542 return pos;
543
544 return NULL;
545}
546
547static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000548 bnx2x_check_vlan_del(struct bnx2x *bp,
549 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300550 union bnx2x_classification_ramrod_data *data)
551{
552 struct bnx2x_vlan_mac_registry_elem *pos;
553
Merav Sicron51c1a582012-03-18 10:33:38 +0000554 DP(BNX2X_MSG_SP, "Checking VLAN %d for DEL command\n", data->vlan.vlan);
555
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300556 list_for_each_entry(pos, &o->head, link)
557 if (data->vlan.vlan == pos->u.vlan.vlan)
558 return pos;
559
560 return NULL;
561}
562
563static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000564 bnx2x_check_vlan_mac_del(struct bnx2x *bp,
565 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300566 union bnx2x_classification_ramrod_data *data)
567{
568 struct bnx2x_vlan_mac_registry_elem *pos;
569
Merav Sicron51c1a582012-03-18 10:33:38 +0000570 DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for DEL command\n",
571 data->vlan_mac.mac, data->vlan_mac.vlan);
572
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300573 list_for_each_entry(pos, &o->head, link)
574 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
575 (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
576 ETH_ALEN)))
577 return pos;
578
579 return NULL;
580}
581
582/* check_move() callback */
Merav Sicron51c1a582012-03-18 10:33:38 +0000583static bool bnx2x_check_move(struct bnx2x *bp,
584 struct bnx2x_vlan_mac_obj *src_o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300585 struct bnx2x_vlan_mac_obj *dst_o,
586 union bnx2x_classification_ramrod_data *data)
587{
588 struct bnx2x_vlan_mac_registry_elem *pos;
589 int rc;
590
591 /* Check if we can delete the requested configuration from the first
592 * object.
593 */
Merav Sicron51c1a582012-03-18 10:33:38 +0000594 pos = src_o->check_del(bp, src_o, data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300595
596 /* check if configuration can be added */
Merav Sicron51c1a582012-03-18 10:33:38 +0000597 rc = dst_o->check_add(bp, dst_o, data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300598
599 /* If this classification can not be added (is already set)
600 * or can't be deleted - return an error.
601 */
602 if (rc || !pos)
603 return false;
604
605 return true;
606}
607
608static bool bnx2x_check_move_always_err(
Merav Sicron51c1a582012-03-18 10:33:38 +0000609 struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300610 struct bnx2x_vlan_mac_obj *src_o,
611 struct bnx2x_vlan_mac_obj *dst_o,
612 union bnx2x_classification_ramrod_data *data)
613{
614 return false;
615}
616
617
618static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
619{
620 struct bnx2x_raw_obj *raw = &o->raw;
621 u8 rx_tx_flag = 0;
622
623 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
624 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
625 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
626
627 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
628 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
629 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
630
631 return rx_tx_flag;
632}
633
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300634
Barak Witkowskia3348722012-04-23 03:04:46 +0000635void bnx2x_set_mac_in_nig(struct bnx2x *bp,
636 bool add, unsigned char *dev_addr, int index)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300637{
638 u32 wb_data[2];
639 u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
640 NIG_REG_LLH0_FUNC_MEM;
641
Barak Witkowskia3348722012-04-23 03:04:46 +0000642 if (!IS_MF_SI(bp) && !IS_MF_AFEX(bp))
643 return;
644
645 if (index > BNX2X_LLH_CAM_MAX_PF_LINE)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300646 return;
647
648 DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
649 (add ? "ADD" : "DELETE"), index);
650
651 if (add) {
652 /* LLH_FUNC_MEM is a u64 WB register */
653 reg_offset += 8*index;
654
655 wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
656 (dev_addr[4] << 8) | dev_addr[5]);
657 wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
658
659 REG_WR_DMAE(bp, reg_offset, wb_data, 2);
660 }
661
662 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
663 NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
664}
665
666/**
667 * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
668 *
669 * @bp: device handle
670 * @o: queue for which we want to configure this rule
671 * @add: if true the command is an ADD command, DEL otherwise
672 * @opcode: CLASSIFY_RULE_OPCODE_XXX
673 * @hdr: pointer to a header to setup
674 *
675 */
676static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
677 struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
678 struct eth_classify_cmd_header *hdr)
679{
680 struct bnx2x_raw_obj *raw = &o->raw;
681
682 hdr->client_id = raw->cl_id;
683 hdr->func_id = raw->func_id;
684
685 /* Rx or/and Tx (internal switching) configuration ? */
686 hdr->cmd_general_data |=
687 bnx2x_vlan_mac_get_rx_tx_flag(o);
688
689 if (add)
690 hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
691
692 hdr->cmd_general_data |=
693 (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
694}
695
696/**
697 * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
698 *
699 * @cid: connection id
700 * @type: BNX2X_FILTER_XXX_PENDING
701 * @hdr: poiter to header to setup
702 * @rule_cnt:
703 *
704 * currently we always configure one rule and echo field to contain a CID and an
705 * opcode type.
706 */
707static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
708 struct eth_classify_header *hdr, int rule_cnt)
709{
710 hdr->echo = (cid & BNX2X_SWCID_MASK) | (type << BNX2X_SWCID_SHIFT);
711 hdr->rule_cnt = (u8)rule_cnt;
712}
713
714
715/* hw_config() callbacks */
716static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
717 struct bnx2x_vlan_mac_obj *o,
718 struct bnx2x_exeq_elem *elem, int rule_idx,
719 int cam_offset)
720{
721 struct bnx2x_raw_obj *raw = &o->raw;
722 struct eth_classify_rules_ramrod_data *data =
723 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
724 int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
725 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
726 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
727 unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
728 u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
729
730 /*
731 * Set LLH CAM entry: currently only iSCSI and ETH macs are
732 * relevant. In addition, current implementation is tuned for a
733 * single ETH MAC.
734 *
735 * When multiple unicast ETH MACs PF configuration in switch
736 * independent mode is required (NetQ, multiple netdev MACs,
737 * etc.), consider better utilisation of 8 per function MAC
738 * entries in the LLH register. There is also
739 * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
740 * total number of CAM entries to 16.
741 *
742 * Currently we won't configure NIG for MACs other than a primary ETH
743 * MAC and iSCSI L2 MAC.
744 *
745 * If this MAC is moving from one Queue to another, no need to change
746 * NIG configuration.
747 */
748 if (cmd != BNX2X_VLAN_MAC_MOVE) {
749 if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
750 bnx2x_set_mac_in_nig(bp, add, mac,
Yuval Mintz0a52fd02012-03-12 08:53:07 +0000751 BNX2X_LLH_CAM_ISCSI_ETH_LINE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300752 else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
Yuval Mintz0a52fd02012-03-12 08:53:07 +0000753 bnx2x_set_mac_in_nig(bp, add, mac,
754 BNX2X_LLH_CAM_ETH_LINE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300755 }
756
757 /* Reset the ramrod data buffer for the first rule */
758 if (rule_idx == 0)
759 memset(data, 0, sizeof(*data));
760
761 /* Setup a command header */
762 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
763 &rule_entry->mac.header);
764
Joe Perches0f9dad12011-08-14 12:16:19 +0000765 DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +0000766 (add ? "add" : "delete"), mac, raw->cl_id);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300767
768 /* Set a MAC itself */
769 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
770 &rule_entry->mac.mac_mid,
771 &rule_entry->mac.mac_lsb, mac);
772
773 /* MOVE: Add a rule that will add this MAC to the target Queue */
774 if (cmd == BNX2X_VLAN_MAC_MOVE) {
775 rule_entry++;
776 rule_cnt++;
777
778 /* Setup ramrod data */
779 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
780 elem->cmd_data.vlan_mac.target_obj,
781 true, CLASSIFY_RULE_OPCODE_MAC,
782 &rule_entry->mac.header);
783
784 /* Set a MAC itself */
785 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
786 &rule_entry->mac.mac_mid,
787 &rule_entry->mac.mac_lsb, mac);
788 }
789
790 /* Set the ramrod data header */
791 /* TODO: take this to the higher level in order to prevent multiple
792 writing */
793 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
794 rule_cnt);
795}
796
797/**
798 * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
799 *
800 * @bp: device handle
801 * @o: queue
802 * @type:
803 * @cam_offset: offset in cam memory
804 * @hdr: pointer to a header to setup
805 *
806 * E1/E1H
807 */
808static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
809 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
810 struct mac_configuration_hdr *hdr)
811{
812 struct bnx2x_raw_obj *r = &o->raw;
813
814 hdr->length = 1;
815 hdr->offset = (u8)cam_offset;
816 hdr->client_id = 0xff;
817 hdr->echo = ((r->cid & BNX2X_SWCID_MASK) | (type << BNX2X_SWCID_SHIFT));
818}
819
820static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
821 struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
822 u16 vlan_id, struct mac_configuration_entry *cfg_entry)
823{
824 struct bnx2x_raw_obj *r = &o->raw;
825 u32 cl_bit_vec = (1 << r->cl_id);
826
827 cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
828 cfg_entry->pf_id = r->func_id;
829 cfg_entry->vlan_id = cpu_to_le16(vlan_id);
830
831 if (add) {
832 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
833 T_ETH_MAC_COMMAND_SET);
834 SET_FLAG(cfg_entry->flags,
835 MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
836
837 /* Set a MAC in a ramrod data */
838 bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
839 &cfg_entry->middle_mac_addr,
840 &cfg_entry->lsb_mac_addr, mac);
841 } else
842 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
843 T_ETH_MAC_COMMAND_INVALIDATE);
844}
845
846static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
847 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
848 u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
849{
850 struct mac_configuration_entry *cfg_entry = &config->config_table[0];
851 struct bnx2x_raw_obj *raw = &o->raw;
852
853 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
854 &config->hdr);
855 bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
856 cfg_entry);
857
Joe Perches0f9dad12011-08-14 12:16:19 +0000858 DP(BNX2X_MSG_SP, "%s MAC %pM CLID %d CAM offset %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +0000859 (add ? "setting" : "clearing"),
Joe Perches0f9dad12011-08-14 12:16:19 +0000860 mac, raw->cl_id, cam_offset);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300861}
862
863/**
864 * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
865 *
866 * @bp: device handle
867 * @o: bnx2x_vlan_mac_obj
868 * @elem: bnx2x_exeq_elem
869 * @rule_idx: rule_idx
870 * @cam_offset: cam_offset
871 */
872static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
873 struct bnx2x_vlan_mac_obj *o,
874 struct bnx2x_exeq_elem *elem, int rule_idx,
875 int cam_offset)
876{
877 struct bnx2x_raw_obj *raw = &o->raw;
878 struct mac_configuration_cmd *config =
879 (struct mac_configuration_cmd *)(raw->rdata);
880 /*
881 * 57710 and 57711 do not support MOVE command,
882 * so it's either ADD or DEL
883 */
884 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
885 true : false;
886
887 /* Reset the ramrod data buffer */
888 memset(config, 0, sizeof(*config));
889
Yuval Mintz33ac3382012-03-12 08:53:09 +0000890 bnx2x_vlan_mac_set_rdata_e1x(bp, o, raw->state,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300891 cam_offset, add,
892 elem->cmd_data.vlan_mac.u.mac.mac, 0,
893 ETH_VLAN_FILTER_ANY_VLAN, config);
894}
895
896static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
897 struct bnx2x_vlan_mac_obj *o,
898 struct bnx2x_exeq_elem *elem, int rule_idx,
899 int cam_offset)
900{
901 struct bnx2x_raw_obj *raw = &o->raw;
902 struct eth_classify_rules_ramrod_data *data =
903 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
904 int rule_cnt = rule_idx + 1;
905 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
906 int cmd = elem->cmd_data.vlan_mac.cmd;
907 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
908 u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
909
910 /* Reset the ramrod data buffer for the first rule */
911 if (rule_idx == 0)
912 memset(data, 0, sizeof(*data));
913
914 /* Set a rule header */
915 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
916 &rule_entry->vlan.header);
917
918 DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
919 vlan);
920
921 /* Set a VLAN itself */
922 rule_entry->vlan.vlan = cpu_to_le16(vlan);
923
924 /* MOVE: Add a rule that will add this MAC to the target Queue */
925 if (cmd == BNX2X_VLAN_MAC_MOVE) {
926 rule_entry++;
927 rule_cnt++;
928
929 /* Setup ramrod data */
930 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
931 elem->cmd_data.vlan_mac.target_obj,
932 true, CLASSIFY_RULE_OPCODE_VLAN,
933 &rule_entry->vlan.header);
934
935 /* Set a VLAN itself */
936 rule_entry->vlan.vlan = cpu_to_le16(vlan);
937 }
938
939 /* Set the ramrod data header */
940 /* TODO: take this to the higher level in order to prevent multiple
941 writing */
942 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
943 rule_cnt);
944}
945
946static void bnx2x_set_one_vlan_mac_e2(struct bnx2x *bp,
947 struct bnx2x_vlan_mac_obj *o,
948 struct bnx2x_exeq_elem *elem,
949 int rule_idx, int cam_offset)
950{
951 struct bnx2x_raw_obj *raw = &o->raw;
952 struct eth_classify_rules_ramrod_data *data =
953 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
954 int rule_cnt = rule_idx + 1;
955 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
956 int cmd = elem->cmd_data.vlan_mac.cmd;
957 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
958 u16 vlan = elem->cmd_data.vlan_mac.u.vlan_mac.vlan;
959 u8 *mac = elem->cmd_data.vlan_mac.u.vlan_mac.mac;
960
961
962 /* Reset the ramrod data buffer for the first rule */
963 if (rule_idx == 0)
964 memset(data, 0, sizeof(*data));
965
966 /* Set a rule header */
967 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
968 &rule_entry->pair.header);
969
970 /* Set VLAN and MAC themselvs */
971 rule_entry->pair.vlan = cpu_to_le16(vlan);
972 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
973 &rule_entry->pair.mac_mid,
974 &rule_entry->pair.mac_lsb, mac);
975
976 /* MOVE: Add a rule that will add this MAC to the target Queue */
977 if (cmd == BNX2X_VLAN_MAC_MOVE) {
978 rule_entry++;
979 rule_cnt++;
980
981 /* Setup ramrod data */
982 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
983 elem->cmd_data.vlan_mac.target_obj,
984 true, CLASSIFY_RULE_OPCODE_PAIR,
985 &rule_entry->pair.header);
986
987 /* Set a VLAN itself */
988 rule_entry->pair.vlan = cpu_to_le16(vlan);
989 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
990 &rule_entry->pair.mac_mid,
991 &rule_entry->pair.mac_lsb, mac);
992 }
993
994 /* Set the ramrod data header */
995 /* TODO: take this to the higher level in order to prevent multiple
996 writing */
997 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
998 rule_cnt);
999}
1000
1001/**
1002 * bnx2x_set_one_vlan_mac_e1h -
1003 *
1004 * @bp: device handle
1005 * @o: bnx2x_vlan_mac_obj
1006 * @elem: bnx2x_exeq_elem
1007 * @rule_idx: rule_idx
1008 * @cam_offset: cam_offset
1009 */
1010static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
1011 struct bnx2x_vlan_mac_obj *o,
1012 struct bnx2x_exeq_elem *elem,
1013 int rule_idx, int cam_offset)
1014{
1015 struct bnx2x_raw_obj *raw = &o->raw;
1016 struct mac_configuration_cmd *config =
1017 (struct mac_configuration_cmd *)(raw->rdata);
1018 /*
1019 * 57710 and 57711 do not support MOVE command,
1020 * so it's either ADD or DEL
1021 */
1022 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1023 true : false;
1024
1025 /* Reset the ramrod data buffer */
1026 memset(config, 0, sizeof(*config));
1027
1028 bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_VLAN_MAC_PENDING,
1029 cam_offset, add,
1030 elem->cmd_data.vlan_mac.u.vlan_mac.mac,
1031 elem->cmd_data.vlan_mac.u.vlan_mac.vlan,
1032 ETH_VLAN_FILTER_CLASSIFY, config);
1033}
1034
1035#define list_next_entry(pos, member) \
1036 list_entry((pos)->member.next, typeof(*(pos)), member)
1037
1038/**
1039 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1040 *
1041 * @bp: device handle
1042 * @p: command parameters
1043 * @ppos: pointer to the cooky
1044 *
1045 * reconfigure next MAC/VLAN/VLAN-MAC element from the
1046 * previously configured elements list.
1047 *
1048 * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
1049 * into an account
1050 *
1051 * pointer to the cooky - that should be given back in the next call to make
1052 * function handle the next element. If *ppos is set to NULL it will restart the
1053 * iterator. If returned *ppos == NULL this means that the last element has been
1054 * handled.
1055 *
1056 */
1057static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
1058 struct bnx2x_vlan_mac_ramrod_params *p,
1059 struct bnx2x_vlan_mac_registry_elem **ppos)
1060{
1061 struct bnx2x_vlan_mac_registry_elem *pos;
1062 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1063
1064 /* If list is empty - there is nothing to do here */
1065 if (list_empty(&o->head)) {
1066 *ppos = NULL;
1067 return 0;
1068 }
1069
1070 /* make a step... */
1071 if (*ppos == NULL)
1072 *ppos = list_first_entry(&o->head,
1073 struct bnx2x_vlan_mac_registry_elem,
1074 link);
1075 else
1076 *ppos = list_next_entry(*ppos, link);
1077
1078 pos = *ppos;
1079
1080 /* If it's the last step - return NULL */
1081 if (list_is_last(&pos->link, &o->head))
1082 *ppos = NULL;
1083
1084 /* Prepare a 'user_req' */
1085 memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
1086
1087 /* Set the command */
1088 p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
1089
1090 /* Set vlan_mac_flags */
1091 p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
1092
1093 /* Set a restore bit */
1094 __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
1095
1096 return bnx2x_config_vlan_mac(bp, p);
1097}
1098
1099/*
1100 * bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
1101 * pointer to an element with a specific criteria and NULL if such an element
1102 * hasn't been found.
1103 */
1104static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
1105 struct bnx2x_exe_queue_obj *o,
1106 struct bnx2x_exeq_elem *elem)
1107{
1108 struct bnx2x_exeq_elem *pos;
1109 struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
1110
1111 /* Check pending for execution commands */
1112 list_for_each_entry(pos, &o->exe_queue, link)
1113 if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
1114 sizeof(*data)) &&
1115 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1116 return pos;
1117
1118 return NULL;
1119}
1120
1121static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
1122 struct bnx2x_exe_queue_obj *o,
1123 struct bnx2x_exeq_elem *elem)
1124{
1125 struct bnx2x_exeq_elem *pos;
1126 struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
1127
1128 /* Check pending for execution commands */
1129 list_for_each_entry(pos, &o->exe_queue, link)
1130 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
1131 sizeof(*data)) &&
1132 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1133 return pos;
1134
1135 return NULL;
1136}
1137
1138static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan_mac(
1139 struct bnx2x_exe_queue_obj *o,
1140 struct bnx2x_exeq_elem *elem)
1141{
1142 struct bnx2x_exeq_elem *pos;
1143 struct bnx2x_vlan_mac_ramrod_data *data =
1144 &elem->cmd_data.vlan_mac.u.vlan_mac;
1145
1146 /* Check pending for execution commands */
1147 list_for_each_entry(pos, &o->exe_queue, link)
1148 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan_mac, data,
1149 sizeof(*data)) &&
1150 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1151 return pos;
1152
1153 return NULL;
1154}
1155
1156/**
1157 * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
1158 *
1159 * @bp: device handle
1160 * @qo: bnx2x_qable_obj
1161 * @elem: bnx2x_exeq_elem
1162 *
1163 * Checks that the requested configuration can be added. If yes and if
1164 * requested, consume CAM credit.
1165 *
1166 * The 'validate' is run after the 'optimize'.
1167 *
1168 */
1169static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
1170 union bnx2x_qable_obj *qo,
1171 struct bnx2x_exeq_elem *elem)
1172{
1173 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1174 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1175 int rc;
1176
1177 /* Check the registry */
Merav Sicron51c1a582012-03-18 10:33:38 +00001178 rc = o->check_add(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001179 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001180 DP(BNX2X_MSG_SP, "ADD command is not allowed considering current registry state.\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001181 return rc;
1182 }
1183
1184 /*
1185 * Check if there is a pending ADD command for this
1186 * MAC/VLAN/VLAN-MAC. Return an error if there is.
1187 */
1188 if (exeq->get(exeq, elem)) {
1189 DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
1190 return -EEXIST;
1191 }
1192
1193 /*
1194 * TODO: Check the pending MOVE from other objects where this
1195 * object is a destination object.
1196 */
1197
1198 /* Consume the credit if not requested not to */
1199 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1200 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1201 o->get_credit(o)))
1202 return -EINVAL;
1203
1204 return 0;
1205}
1206
1207/**
1208 * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
1209 *
1210 * @bp: device handle
1211 * @qo: quable object to check
1212 * @elem: element that needs to be deleted
1213 *
1214 * Checks that the requested configuration can be deleted. If yes and if
1215 * requested, returns a CAM credit.
1216 *
1217 * The 'validate' is run after the 'optimize'.
1218 */
1219static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
1220 union bnx2x_qable_obj *qo,
1221 struct bnx2x_exeq_elem *elem)
1222{
1223 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1224 struct bnx2x_vlan_mac_registry_elem *pos;
1225 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1226 struct bnx2x_exeq_elem query_elem;
1227
1228 /* If this classification can not be deleted (doesn't exist)
1229 * - return a BNX2X_EXIST.
1230 */
Merav Sicron51c1a582012-03-18 10:33:38 +00001231 pos = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001232 if (!pos) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001233 DP(BNX2X_MSG_SP, "DEL command is not allowed considering current registry state\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001234 return -EEXIST;
1235 }
1236
1237 /*
1238 * Check if there are pending DEL or MOVE commands for this
1239 * MAC/VLAN/VLAN-MAC. Return an error if so.
1240 */
1241 memcpy(&query_elem, elem, sizeof(query_elem));
1242
1243 /* Check for MOVE commands */
1244 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
1245 if (exeq->get(exeq, &query_elem)) {
1246 BNX2X_ERR("There is a pending MOVE command already\n");
1247 return -EINVAL;
1248 }
1249
1250 /* Check for DEL commands */
1251 if (exeq->get(exeq, elem)) {
1252 DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
1253 return -EEXIST;
1254 }
1255
1256 /* Return the credit to the credit pool if not requested not to */
1257 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1258 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1259 o->put_credit(o))) {
1260 BNX2X_ERR("Failed to return a credit\n");
1261 return -EINVAL;
1262 }
1263
1264 return 0;
1265}
1266
1267/**
1268 * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
1269 *
1270 * @bp: device handle
1271 * @qo: quable object to check (source)
1272 * @elem: element that needs to be moved
1273 *
1274 * Checks that the requested configuration can be moved. If yes and if
1275 * requested, returns a CAM credit.
1276 *
1277 * The 'validate' is run after the 'optimize'.
1278 */
1279static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
1280 union bnx2x_qable_obj *qo,
1281 struct bnx2x_exeq_elem *elem)
1282{
1283 struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
1284 struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
1285 struct bnx2x_exeq_elem query_elem;
1286 struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
1287 struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
1288
1289 /*
1290 * Check if we can perform this operation based on the current registry
1291 * state.
1292 */
Merav Sicron51c1a582012-03-18 10:33:38 +00001293 if (!src_o->check_move(bp, src_o, dest_o,
1294 &elem->cmd_data.vlan_mac.u)) {
1295 DP(BNX2X_MSG_SP, "MOVE command is not allowed considering current registry state\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001296 return -EINVAL;
1297 }
1298
1299 /*
1300 * Check if there is an already pending DEL or MOVE command for the
1301 * source object or ADD command for a destination object. Return an
1302 * error if so.
1303 */
1304 memcpy(&query_elem, elem, sizeof(query_elem));
1305
1306 /* Check DEL on source */
1307 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1308 if (src_exeq->get(src_exeq, &query_elem)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001309 BNX2X_ERR("There is a pending DEL command on the source queue already\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001310 return -EINVAL;
1311 }
1312
1313 /* Check MOVE on source */
1314 if (src_exeq->get(src_exeq, elem)) {
1315 DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
1316 return -EEXIST;
1317 }
1318
1319 /* Check ADD on destination */
1320 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1321 if (dest_exeq->get(dest_exeq, &query_elem)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001322 BNX2X_ERR("There is a pending ADD command on the destination queue already\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001323 return -EINVAL;
1324 }
1325
1326 /* Consume the credit if not requested not to */
1327 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
1328 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1329 dest_o->get_credit(dest_o)))
1330 return -EINVAL;
1331
1332 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1333 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1334 src_o->put_credit(src_o))) {
1335 /* return the credit taken from dest... */
1336 dest_o->put_credit(dest_o);
1337 return -EINVAL;
1338 }
1339
1340 return 0;
1341}
1342
1343static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
1344 union bnx2x_qable_obj *qo,
1345 struct bnx2x_exeq_elem *elem)
1346{
1347 switch (elem->cmd_data.vlan_mac.cmd) {
1348 case BNX2X_VLAN_MAC_ADD:
1349 return bnx2x_validate_vlan_mac_add(bp, qo, elem);
1350 case BNX2X_VLAN_MAC_DEL:
1351 return bnx2x_validate_vlan_mac_del(bp, qo, elem);
1352 case BNX2X_VLAN_MAC_MOVE:
1353 return bnx2x_validate_vlan_mac_move(bp, qo, elem);
1354 default:
1355 return -EINVAL;
1356 }
1357}
1358
Yuval Mintz460a25c2012-01-23 07:31:51 +00001359static int bnx2x_remove_vlan_mac(struct bnx2x *bp,
1360 union bnx2x_qable_obj *qo,
1361 struct bnx2x_exeq_elem *elem)
1362{
1363 int rc = 0;
1364
1365 /* If consumption wasn't required, nothing to do */
1366 if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1367 &elem->cmd_data.vlan_mac.vlan_mac_flags))
1368 return 0;
1369
1370 switch (elem->cmd_data.vlan_mac.cmd) {
1371 case BNX2X_VLAN_MAC_ADD:
1372 case BNX2X_VLAN_MAC_MOVE:
1373 rc = qo->vlan_mac.put_credit(&qo->vlan_mac);
1374 break;
1375 case BNX2X_VLAN_MAC_DEL:
1376 rc = qo->vlan_mac.get_credit(&qo->vlan_mac);
1377 break;
1378 default:
1379 return -EINVAL;
1380 }
1381
1382 if (rc != true)
1383 return -EINVAL;
1384
1385 return 0;
1386}
1387
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001388/**
1389 * bnx2x_wait_vlan_mac - passivly wait for 5 seconds until all work completes.
1390 *
1391 * @bp: device handle
1392 * @o: bnx2x_vlan_mac_obj
1393 *
1394 */
1395static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
1396 struct bnx2x_vlan_mac_obj *o)
1397{
1398 int cnt = 5000, rc;
1399 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1400 struct bnx2x_raw_obj *raw = &o->raw;
1401
1402 while (cnt--) {
1403 /* Wait for the current command to complete */
1404 rc = raw->wait_comp(bp, raw);
1405 if (rc)
1406 return rc;
1407
1408 /* Wait until there are no pending commands */
1409 if (!bnx2x_exe_queue_empty(exeq))
Yuval Mintz0926d492013-01-23 03:21:45 +00001410 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001411 else
1412 return 0;
1413 }
1414
1415 return -EBUSY;
1416}
1417
1418/**
1419 * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
1420 *
1421 * @bp: device handle
1422 * @o: bnx2x_vlan_mac_obj
1423 * @cqe:
1424 * @cont: if true schedule next execution chunk
1425 *
1426 */
1427static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
1428 struct bnx2x_vlan_mac_obj *o,
1429 union event_ring_elem *cqe,
1430 unsigned long *ramrod_flags)
1431{
1432 struct bnx2x_raw_obj *r = &o->raw;
1433 int rc;
1434
1435 /* Reset pending list */
1436 bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
1437
1438 /* Clear pending */
1439 r->clear_pending(r);
1440
1441 /* If ramrod failed this is most likely a SW bug */
1442 if (cqe->message.error)
1443 return -EINVAL;
1444
Yuval Mintz2de67432013-01-23 03:21:43 +00001445 /* Run the next bulk of pending commands if requested */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001446 if (test_bit(RAMROD_CONT, ramrod_flags)) {
1447 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1448 if (rc < 0)
1449 return rc;
1450 }
1451
1452 /* If there is more work to do return PENDING */
1453 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1454 return 1;
1455
1456 return 0;
1457}
1458
1459/**
1460 * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
1461 *
1462 * @bp: device handle
1463 * @o: bnx2x_qable_obj
1464 * @elem: bnx2x_exeq_elem
1465 */
1466static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
1467 union bnx2x_qable_obj *qo,
1468 struct bnx2x_exeq_elem *elem)
1469{
1470 struct bnx2x_exeq_elem query, *pos;
1471 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1472 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1473
1474 memcpy(&query, elem, sizeof(query));
1475
1476 switch (elem->cmd_data.vlan_mac.cmd) {
1477 case BNX2X_VLAN_MAC_ADD:
1478 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1479 break;
1480 case BNX2X_VLAN_MAC_DEL:
1481 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1482 break;
1483 default:
1484 /* Don't handle anything other than ADD or DEL */
1485 return 0;
1486 }
1487
1488 /* If we found the appropriate element - delete it */
1489 pos = exeq->get(exeq, &query);
1490 if (pos) {
1491
1492 /* Return the credit of the optimized command */
1493 if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1494 &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
1495 if ((query.cmd_data.vlan_mac.cmd ==
1496 BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001497 BNX2X_ERR("Failed to return the credit for the optimized ADD command\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001498 return -EINVAL;
1499 } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
Merav Sicron51c1a582012-03-18 10:33:38 +00001500 BNX2X_ERR("Failed to recover the credit from the optimized DEL command\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001501 return -EINVAL;
1502 }
1503 }
1504
1505 DP(BNX2X_MSG_SP, "Optimizing %s command\n",
1506 (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1507 "ADD" : "DEL");
1508
1509 list_del(&pos->link);
1510 bnx2x_exe_queue_free_elem(bp, pos);
1511 return 1;
1512 }
1513
1514 return 0;
1515}
1516
1517/**
1518 * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
1519 *
1520 * @bp: device handle
1521 * @o:
1522 * @elem:
1523 * @restore:
1524 * @re:
1525 *
1526 * prepare a registry element according to the current command request.
1527 */
1528static inline int bnx2x_vlan_mac_get_registry_elem(
1529 struct bnx2x *bp,
1530 struct bnx2x_vlan_mac_obj *o,
1531 struct bnx2x_exeq_elem *elem,
1532 bool restore,
1533 struct bnx2x_vlan_mac_registry_elem **re)
1534{
1535 int cmd = elem->cmd_data.vlan_mac.cmd;
1536 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1537
1538 /* Allocate a new registry element if needed. */
1539 if (!restore &&
1540 ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
1541 reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
1542 if (!reg_elem)
1543 return -ENOMEM;
1544
1545 /* Get a new CAM offset */
1546 if (!o->get_cam_offset(o, &reg_elem->cam_offset)) {
1547 /*
1548 * This shell never happen, because we have checked the
1549 * CAM availiability in the 'validate'.
1550 */
1551 WARN_ON(1);
1552 kfree(reg_elem);
1553 return -EINVAL;
1554 }
1555
1556 DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
1557
1558 /* Set a VLAN-MAC data */
1559 memcpy(&reg_elem->u, &elem->cmd_data.vlan_mac.u,
1560 sizeof(reg_elem->u));
1561
1562 /* Copy the flags (needed for DEL and RESTORE flows) */
1563 reg_elem->vlan_mac_flags =
1564 elem->cmd_data.vlan_mac.vlan_mac_flags;
1565 } else /* DEL, RESTORE */
Merav Sicron51c1a582012-03-18 10:33:38 +00001566 reg_elem = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001567
1568 *re = reg_elem;
1569 return 0;
1570}
1571
1572/**
1573 * bnx2x_execute_vlan_mac - execute vlan mac command
1574 *
1575 * @bp: device handle
1576 * @qo:
1577 * @exe_chunk:
1578 * @ramrod_flags:
1579 *
1580 * go and send a ramrod!
1581 */
1582static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
1583 union bnx2x_qable_obj *qo,
1584 struct list_head *exe_chunk,
1585 unsigned long *ramrod_flags)
1586{
1587 struct bnx2x_exeq_elem *elem;
1588 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
1589 struct bnx2x_raw_obj *r = &o->raw;
1590 int rc, idx = 0;
1591 bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
1592 bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
1593 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1594 int cmd;
1595
1596 /*
1597 * If DRIVER_ONLY execution is requested, cleanup a registry
1598 * and exit. Otherwise send a ramrod to FW.
1599 */
1600 if (!drv_only) {
1601 WARN_ON(r->check_pending(r));
1602
1603 /* Set pending */
1604 r->set_pending(r);
1605
1606 /* Fill tha ramrod data */
1607 list_for_each_entry(elem, exe_chunk, link) {
1608 cmd = elem->cmd_data.vlan_mac.cmd;
1609 /*
1610 * We will add to the target object in MOVE command, so
1611 * change the object for a CAM search.
1612 */
1613 if (cmd == BNX2X_VLAN_MAC_MOVE)
1614 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1615 else
1616 cam_obj = o;
1617
1618 rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
1619 elem, restore,
1620 &reg_elem);
1621 if (rc)
1622 goto error_exit;
1623
1624 WARN_ON(!reg_elem);
1625
1626 /* Push a new entry into the registry */
1627 if (!restore &&
1628 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1629 (cmd == BNX2X_VLAN_MAC_MOVE)))
1630 list_add(&reg_elem->link, &cam_obj->head);
1631
1632 /* Configure a single command in a ramrod data buffer */
1633 o->set_one_rule(bp, o, elem, idx,
1634 reg_elem->cam_offset);
1635
1636 /* MOVE command consumes 2 entries in the ramrod data */
1637 if (cmd == BNX2X_VLAN_MAC_MOVE)
1638 idx += 2;
1639 else
1640 idx++;
1641 }
1642
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00001643 /*
1644 * No need for an explicit memory barrier here as long we would
1645 * need to ensure the ordering of writing to the SPQ element
1646 * and updating of the SPQ producer which involves a memory
1647 * read and we will have to put a full memory barrier there
1648 * (inside bnx2x_sp_post()).
1649 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001650
1651 rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
1652 U64_HI(r->rdata_mapping),
1653 U64_LO(r->rdata_mapping),
1654 ETH_CONNECTION_TYPE);
1655 if (rc)
1656 goto error_exit;
1657 }
1658
1659 /* Now, when we are done with the ramrod - clean up the registry */
1660 list_for_each_entry(elem, exe_chunk, link) {
1661 cmd = elem->cmd_data.vlan_mac.cmd;
1662 if ((cmd == BNX2X_VLAN_MAC_DEL) ||
1663 (cmd == BNX2X_VLAN_MAC_MOVE)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001664 reg_elem = o->check_del(bp, o,
1665 &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001666
1667 WARN_ON(!reg_elem);
1668
1669 o->put_cam_offset(o, reg_elem->cam_offset);
1670 list_del(&reg_elem->link);
1671 kfree(reg_elem);
1672 }
1673 }
1674
1675 if (!drv_only)
1676 return 1;
1677 else
1678 return 0;
1679
1680error_exit:
1681 r->clear_pending(r);
1682
1683 /* Cleanup a registry in case of a failure */
1684 list_for_each_entry(elem, exe_chunk, link) {
1685 cmd = elem->cmd_data.vlan_mac.cmd;
1686
1687 if (cmd == BNX2X_VLAN_MAC_MOVE)
1688 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1689 else
1690 cam_obj = o;
1691
1692 /* Delete all newly added above entries */
1693 if (!restore &&
1694 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1695 (cmd == BNX2X_VLAN_MAC_MOVE))) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001696 reg_elem = o->check_del(bp, cam_obj,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001697 &elem->cmd_data.vlan_mac.u);
1698 if (reg_elem) {
1699 list_del(&reg_elem->link);
1700 kfree(reg_elem);
1701 }
1702 }
1703 }
1704
1705 return rc;
1706}
1707
1708static inline int bnx2x_vlan_mac_push_new_cmd(
1709 struct bnx2x *bp,
1710 struct bnx2x_vlan_mac_ramrod_params *p)
1711{
1712 struct bnx2x_exeq_elem *elem;
1713 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1714 bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
1715
1716 /* Allocate the execution queue element */
1717 elem = bnx2x_exe_queue_alloc_elem(bp);
1718 if (!elem)
1719 return -ENOMEM;
1720
1721 /* Set the command 'length' */
1722 switch (p->user_req.cmd) {
1723 case BNX2X_VLAN_MAC_MOVE:
1724 elem->cmd_len = 2;
1725 break;
1726 default:
1727 elem->cmd_len = 1;
1728 }
1729
1730 /* Fill the object specific info */
1731 memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
1732
1733 /* Try to add a new command to the pending list */
1734 return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
1735}
1736
1737/**
1738 * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
1739 *
1740 * @bp: device handle
1741 * @p:
1742 *
1743 */
1744int bnx2x_config_vlan_mac(
1745 struct bnx2x *bp,
1746 struct bnx2x_vlan_mac_ramrod_params *p)
1747{
1748 int rc = 0;
1749 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1750 unsigned long *ramrod_flags = &p->ramrod_flags;
1751 bool cont = test_bit(RAMROD_CONT, ramrod_flags);
1752 struct bnx2x_raw_obj *raw = &o->raw;
1753
1754 /*
1755 * Add new elements to the execution list for commands that require it.
1756 */
1757 if (!cont) {
1758 rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
1759 if (rc)
1760 return rc;
1761 }
1762
1763 /*
1764 * If nothing will be executed further in this iteration we want to
1765 * return PENDING if there are pending commands
1766 */
1767 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1768 rc = 1;
1769
Vladislav Zolotarov79616892011-07-21 07:58:54 +00001770 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001771 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
Vladislav Zolotarov79616892011-07-21 07:58:54 +00001772 raw->clear_pending(raw);
1773 }
1774
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001775 /* Execute commands if required */
1776 if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
1777 test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
1778 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1779 if (rc < 0)
1780 return rc;
1781 }
1782
1783 /*
1784 * RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
1785 * then user want to wait until the last command is done.
1786 */
1787 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
1788 /*
1789 * Wait maximum for the current exe_queue length iterations plus
1790 * one (for the current pending command).
1791 */
1792 int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
1793
1794 while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
1795 max_iterations--) {
1796
1797 /* Wait for the current command to complete */
1798 rc = raw->wait_comp(bp, raw);
1799 if (rc)
1800 return rc;
1801
1802 /* Make a next step */
1803 rc = bnx2x_exe_queue_step(bp, &o->exe_queue,
1804 ramrod_flags);
1805 if (rc < 0)
1806 return rc;
1807 }
1808
1809 return 0;
1810 }
1811
1812 return rc;
1813}
1814
1815
1816
1817/**
1818 * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
1819 *
1820 * @bp: device handle
1821 * @o:
1822 * @vlan_mac_flags:
1823 * @ramrod_flags: execution flags to be used for this deletion
1824 *
1825 * if the last operation has completed successfully and there are no
1826 * moreelements left, positive value if the last operation has completed
1827 * successfully and there are more previously configured elements, negative
1828 * value is current operation has failed.
1829 */
1830static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
1831 struct bnx2x_vlan_mac_obj *o,
1832 unsigned long *vlan_mac_flags,
1833 unsigned long *ramrod_flags)
1834{
1835 struct bnx2x_vlan_mac_registry_elem *pos = NULL;
1836 int rc = 0;
1837 struct bnx2x_vlan_mac_ramrod_params p;
1838 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1839 struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
1840
1841 /* Clear pending commands first */
1842
1843 spin_lock_bh(&exeq->lock);
1844
1845 list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
1846 if (exeq_pos->cmd_data.vlan_mac.vlan_mac_flags ==
Yuval Mintz460a25c2012-01-23 07:31:51 +00001847 *vlan_mac_flags) {
1848 rc = exeq->remove(bp, exeq->owner, exeq_pos);
1849 if (rc) {
1850 BNX2X_ERR("Failed to remove command\n");
Dan Carpentera44acd52012-01-24 21:59:31 +00001851 spin_unlock_bh(&exeq->lock);
Yuval Mintz460a25c2012-01-23 07:31:51 +00001852 return rc;
1853 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001854 list_del(&exeq_pos->link);
Yuval Mintz460a25c2012-01-23 07:31:51 +00001855 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001856 }
1857
1858 spin_unlock_bh(&exeq->lock);
1859
1860 /* Prepare a command request */
1861 memset(&p, 0, sizeof(p));
1862 p.vlan_mac_obj = o;
1863 p.ramrod_flags = *ramrod_flags;
1864 p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
1865
1866 /*
1867 * Add all but the last VLAN-MAC to the execution queue without actually
1868 * execution anything.
1869 */
1870 __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
1871 __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
1872 __clear_bit(RAMROD_CONT, &p.ramrod_flags);
1873
1874 list_for_each_entry(pos, &o->head, link) {
1875 if (pos->vlan_mac_flags == *vlan_mac_flags) {
1876 p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
1877 memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
1878 rc = bnx2x_config_vlan_mac(bp, &p);
1879 if (rc < 0) {
1880 BNX2X_ERR("Failed to add a new DEL command\n");
1881 return rc;
1882 }
1883 }
1884 }
1885
1886 p.ramrod_flags = *ramrod_flags;
1887 __set_bit(RAMROD_CONT, &p.ramrod_flags);
1888
1889 return bnx2x_config_vlan_mac(bp, &p);
1890}
1891
1892static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
1893 u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
1894 unsigned long *pstate, bnx2x_obj_type type)
1895{
1896 raw->func_id = func_id;
1897 raw->cid = cid;
1898 raw->cl_id = cl_id;
1899 raw->rdata = rdata;
1900 raw->rdata_mapping = rdata_mapping;
1901 raw->state = state;
1902 raw->pstate = pstate;
1903 raw->obj_type = type;
1904 raw->check_pending = bnx2x_raw_check_pending;
1905 raw->clear_pending = bnx2x_raw_clear_pending;
1906 raw->set_pending = bnx2x_raw_set_pending;
1907 raw->wait_comp = bnx2x_raw_wait;
1908}
1909
1910static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
1911 u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
1912 int state, unsigned long *pstate, bnx2x_obj_type type,
1913 struct bnx2x_credit_pool_obj *macs_pool,
1914 struct bnx2x_credit_pool_obj *vlans_pool)
1915{
1916 INIT_LIST_HEAD(&o->head);
1917
1918 o->macs_pool = macs_pool;
1919 o->vlans_pool = vlans_pool;
1920
1921 o->delete_all = bnx2x_vlan_mac_del_all;
1922 o->restore = bnx2x_vlan_mac_restore;
1923 o->complete = bnx2x_complete_vlan_mac;
1924 o->wait = bnx2x_wait_vlan_mac;
1925
1926 bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
1927 state, pstate, type);
1928}
1929
1930
1931void bnx2x_init_mac_obj(struct bnx2x *bp,
1932 struct bnx2x_vlan_mac_obj *mac_obj,
1933 u8 cl_id, u32 cid, u8 func_id, void *rdata,
1934 dma_addr_t rdata_mapping, int state,
1935 unsigned long *pstate, bnx2x_obj_type type,
1936 struct bnx2x_credit_pool_obj *macs_pool)
1937{
1938 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
1939
1940 bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
1941 rdata_mapping, state, pstate, type,
1942 macs_pool, NULL);
1943
1944 /* CAM credit pool handling */
1945 mac_obj->get_credit = bnx2x_get_credit_mac;
1946 mac_obj->put_credit = bnx2x_put_credit_mac;
1947 mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
1948 mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
1949
1950 if (CHIP_IS_E1x(bp)) {
1951 mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
1952 mac_obj->check_del = bnx2x_check_mac_del;
1953 mac_obj->check_add = bnx2x_check_mac_add;
1954 mac_obj->check_move = bnx2x_check_move_always_err;
1955 mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
1956
1957 /* Exe Queue */
1958 bnx2x_exe_queue_init(bp,
1959 &mac_obj->exe_queue, 1, qable_obj,
1960 bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00001961 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001962 bnx2x_optimize_vlan_mac,
1963 bnx2x_execute_vlan_mac,
1964 bnx2x_exeq_get_mac);
1965 } else {
1966 mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
1967 mac_obj->check_del = bnx2x_check_mac_del;
1968 mac_obj->check_add = bnx2x_check_mac_add;
1969 mac_obj->check_move = bnx2x_check_move;
1970 mac_obj->ramrod_cmd =
1971 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
Ariel Eliored5162a2011-12-05 21:52:24 +00001972 mac_obj->get_n_elements = bnx2x_get_n_elements;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001973
1974 /* Exe Queue */
1975 bnx2x_exe_queue_init(bp,
1976 &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
1977 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00001978 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001979 bnx2x_optimize_vlan_mac,
1980 bnx2x_execute_vlan_mac,
1981 bnx2x_exeq_get_mac);
1982 }
1983}
1984
1985void bnx2x_init_vlan_obj(struct bnx2x *bp,
1986 struct bnx2x_vlan_mac_obj *vlan_obj,
1987 u8 cl_id, u32 cid, u8 func_id, void *rdata,
1988 dma_addr_t rdata_mapping, int state,
1989 unsigned long *pstate, bnx2x_obj_type type,
1990 struct bnx2x_credit_pool_obj *vlans_pool)
1991{
1992 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
1993
1994 bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
1995 rdata_mapping, state, pstate, type, NULL,
1996 vlans_pool);
1997
1998 vlan_obj->get_credit = bnx2x_get_credit_vlan;
1999 vlan_obj->put_credit = bnx2x_put_credit_vlan;
2000 vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
2001 vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
2002
2003 if (CHIP_IS_E1x(bp)) {
2004 BNX2X_ERR("Do not support chips others than E2 and newer\n");
2005 BUG();
2006 } else {
2007 vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
2008 vlan_obj->check_del = bnx2x_check_vlan_del;
2009 vlan_obj->check_add = bnx2x_check_vlan_add;
2010 vlan_obj->check_move = bnx2x_check_move;
2011 vlan_obj->ramrod_cmd =
2012 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
2013
2014 /* Exe Queue */
2015 bnx2x_exe_queue_init(bp,
2016 &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
2017 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002018 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002019 bnx2x_optimize_vlan_mac,
2020 bnx2x_execute_vlan_mac,
2021 bnx2x_exeq_get_vlan);
2022 }
2023}
2024
2025void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
2026 struct bnx2x_vlan_mac_obj *vlan_mac_obj,
2027 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2028 dma_addr_t rdata_mapping, int state,
2029 unsigned long *pstate, bnx2x_obj_type type,
2030 struct bnx2x_credit_pool_obj *macs_pool,
2031 struct bnx2x_credit_pool_obj *vlans_pool)
2032{
2033 union bnx2x_qable_obj *qable_obj =
2034 (union bnx2x_qable_obj *)vlan_mac_obj;
2035
2036 bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
2037 rdata_mapping, state, pstate, type,
2038 macs_pool, vlans_pool);
2039
2040 /* CAM pool handling */
2041 vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
2042 vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac;
2043 /*
2044 * CAM offset is relevant for 57710 and 57711 chips only which have a
2045 * single CAM for both MACs and VLAN-MAC pairs. So the offset
2046 * will be taken from MACs' pool object only.
2047 */
2048 vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
2049 vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
2050
2051 if (CHIP_IS_E1(bp)) {
2052 BNX2X_ERR("Do not support chips others than E2\n");
2053 BUG();
2054 } else if (CHIP_IS_E1H(bp)) {
2055 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
2056 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2057 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2058 vlan_mac_obj->check_move = bnx2x_check_move_always_err;
2059 vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
2060
2061 /* Exe Queue */
2062 bnx2x_exe_queue_init(bp,
2063 &vlan_mac_obj->exe_queue, 1, qable_obj,
2064 bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002065 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002066 bnx2x_optimize_vlan_mac,
2067 bnx2x_execute_vlan_mac,
2068 bnx2x_exeq_get_vlan_mac);
2069 } else {
2070 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e2;
2071 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2072 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2073 vlan_mac_obj->check_move = bnx2x_check_move;
2074 vlan_mac_obj->ramrod_cmd =
2075 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
2076
2077 /* Exe Queue */
2078 bnx2x_exe_queue_init(bp,
2079 &vlan_mac_obj->exe_queue,
2080 CLASSIFY_RULES_COUNT,
2081 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002082 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002083 bnx2x_optimize_vlan_mac,
2084 bnx2x_execute_vlan_mac,
2085 bnx2x_exeq_get_vlan_mac);
2086 }
2087
2088}
2089
2090/* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
2091static inline void __storm_memset_mac_filters(struct bnx2x *bp,
2092 struct tstorm_eth_mac_filter_config *mac_filters,
2093 u16 pf_id)
2094{
2095 size_t size = sizeof(struct tstorm_eth_mac_filter_config);
2096
2097 u32 addr = BAR_TSTRORM_INTMEM +
2098 TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
2099
2100 __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
2101}
2102
2103static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
2104 struct bnx2x_rx_mode_ramrod_params *p)
2105{
Yuval Mintz2de67432013-01-23 03:21:43 +00002106 /* update the bp MAC filter structure */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002107 u32 mask = (1 << p->cl_id);
2108
2109 struct tstorm_eth_mac_filter_config *mac_filters =
2110 (struct tstorm_eth_mac_filter_config *)p->rdata;
2111
2112 /* initial seeting is drop-all */
2113 u8 drop_all_ucast = 1, drop_all_mcast = 1;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002114 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
2115 u8 unmatched_unicast = 0;
2116
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002117 /* In e1x there we only take into account rx acceot flag since tx switching
2118 * isn't enabled. */
2119 if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002120 /* accept matched ucast */
2121 drop_all_ucast = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002122
2123 if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002124 /* accept matched mcast */
2125 drop_all_mcast = 0;
2126
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002127 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002128 /* accept all mcast */
2129 drop_all_ucast = 0;
2130 accp_all_ucast = 1;
2131 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002132 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002133 /* accept all mcast */
2134 drop_all_mcast = 0;
2135 accp_all_mcast = 1;
2136 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002137 if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002138 /* accept (all) bcast */
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002139 accp_all_bcast = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002140 if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
2141 /* accept unmatched unicasts */
2142 unmatched_unicast = 1;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002143
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002144 mac_filters->ucast_drop_all = drop_all_ucast ?
2145 mac_filters->ucast_drop_all | mask :
2146 mac_filters->ucast_drop_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002147
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002148 mac_filters->mcast_drop_all = drop_all_mcast ?
2149 mac_filters->mcast_drop_all | mask :
2150 mac_filters->mcast_drop_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002151
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002152 mac_filters->ucast_accept_all = accp_all_ucast ?
2153 mac_filters->ucast_accept_all | mask :
2154 mac_filters->ucast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002155
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002156 mac_filters->mcast_accept_all = accp_all_mcast ?
2157 mac_filters->mcast_accept_all | mask :
2158 mac_filters->mcast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002159
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002160 mac_filters->bcast_accept_all = accp_all_bcast ?
2161 mac_filters->bcast_accept_all | mask :
2162 mac_filters->bcast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002163
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002164 mac_filters->unmatched_unicast = unmatched_unicast ?
2165 mac_filters->unmatched_unicast | mask :
2166 mac_filters->unmatched_unicast & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002167
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002168 DP(BNX2X_MSG_SP, "drop_ucast 0x%x\ndrop_mcast 0x%x\n accp_ucast 0x%x\n"
Yuval Mintz2de67432013-01-23 03:21:43 +00002169 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00002170 mac_filters->ucast_drop_all, mac_filters->mcast_drop_all,
2171 mac_filters->ucast_accept_all, mac_filters->mcast_accept_all,
2172 mac_filters->bcast_accept_all);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002173
2174 /* write the MAC filter structure*/
2175 __storm_memset_mac_filters(bp, mac_filters, p->func_id);
2176
2177 /* The operation is completed */
2178 clear_bit(p->state, p->pstate);
2179 smp_mb__after_clear_bit();
2180
2181 return 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002182}
2183
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002184/* Setup ramrod data */
2185static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
2186 struct eth_classify_header *hdr,
2187 u8 rule_cnt)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002188{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002189 hdr->echo = cid;
2190 hdr->rule_cnt = rule_cnt;
2191}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002192
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002193static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
Yuval Mintz924d75a2013-01-23 03:21:44 +00002194 unsigned long *accept_flags,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002195 struct eth_filter_rules_cmd *cmd,
2196 bool clear_accept_all)
2197{
2198 u16 state;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002199
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002200 /* start with 'drop-all' */
2201 state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
2202 ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2203
Yuval Mintz924d75a2013-01-23 03:21:44 +00002204 if (test_bit(BNX2X_ACCEPT_UNICAST, accept_flags))
2205 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002206
Yuval Mintz924d75a2013-01-23 03:21:44 +00002207 if (test_bit(BNX2X_ACCEPT_MULTICAST, accept_flags))
2208 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002209
Yuval Mintz924d75a2013-01-23 03:21:44 +00002210 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, accept_flags)) {
2211 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2212 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002213 }
2214
Yuval Mintz924d75a2013-01-23 03:21:44 +00002215 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, accept_flags)) {
2216 state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2217 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2218 }
2219
2220 if (test_bit(BNX2X_ACCEPT_BROADCAST, accept_flags))
2221 state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2222
2223 if (test_bit(BNX2X_ACCEPT_UNMATCHED, accept_flags)) {
2224 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2225 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2226 }
2227
2228 if (test_bit(BNX2X_ACCEPT_ANY_VLAN, accept_flags))
2229 state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
2230
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002231 /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
2232 if (clear_accept_all) {
2233 state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2234 state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2235 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2236 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2237 }
2238
2239 cmd->state = cpu_to_le16(state);
2240
2241}
2242
2243static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
2244 struct bnx2x_rx_mode_ramrod_params *p)
2245{
2246 struct eth_filter_rules_ramrod_data *data = p->rdata;
2247 int rc;
2248 u8 rule_idx = 0;
2249
2250 /* Reset the ramrod data buffer */
2251 memset(data, 0, sizeof(*data));
2252
2253 /* Setup ramrod data */
2254
2255 /* Tx (internal switching) */
2256 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2257 data->rules[rule_idx].client_id = p->cl_id;
2258 data->rules[rule_idx].func_id = p->func_id;
2259
2260 data->rules[rule_idx].cmd_general_data =
2261 ETH_FILTER_RULES_CMD_TX_CMD;
2262
Yuval Mintz924d75a2013-01-23 03:21:44 +00002263 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2264 &(data->rules[rule_idx++]),
2265 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002266 }
2267
2268 /* Rx */
2269 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2270 data->rules[rule_idx].client_id = p->cl_id;
2271 data->rules[rule_idx].func_id = p->func_id;
2272
2273 data->rules[rule_idx].cmd_general_data =
2274 ETH_FILTER_RULES_CMD_RX_CMD;
2275
Yuval Mintz924d75a2013-01-23 03:21:44 +00002276 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2277 &(data->rules[rule_idx++]),
2278 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002279 }
2280
2281
2282 /*
2283 * If FCoE Queue configuration has been requested configure the Rx and
2284 * internal switching modes for this queue in separate rules.
2285 *
2286 * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
2287 * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
2288 */
2289 if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
2290 /* Tx (internal switching) */
2291 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2292 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2293 data->rules[rule_idx].func_id = p->func_id;
2294
2295 data->rules[rule_idx].cmd_general_data =
2296 ETH_FILTER_RULES_CMD_TX_CMD;
2297
Yuval Mintz924d75a2013-01-23 03:21:44 +00002298 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2299 &(data->rules[rule_idx]),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002300 true);
Yuval Mintz924d75a2013-01-23 03:21:44 +00002301 rule_idx++;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002302 }
2303
2304 /* Rx */
2305 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2306 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2307 data->rules[rule_idx].func_id = p->func_id;
2308
2309 data->rules[rule_idx].cmd_general_data =
2310 ETH_FILTER_RULES_CMD_RX_CMD;
2311
Yuval Mintz924d75a2013-01-23 03:21:44 +00002312 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2313 &(data->rules[rule_idx]),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002314 true);
Yuval Mintz924d75a2013-01-23 03:21:44 +00002315 rule_idx++;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002316 }
2317 }
2318
2319 /*
2320 * Set the ramrod header (most importantly - number of rules to
2321 * configure).
2322 */
2323 bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
2324
Merav Sicron51c1a582012-03-18 10:33:38 +00002325 DP(BNX2X_MSG_SP, "About to configure %d rules, rx_accept_flags 0x%lx, tx_accept_flags 0x%lx\n",
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002326 data->header.rule_cnt, p->rx_accept_flags,
2327 p->tx_accept_flags);
2328
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00002329 /*
2330 * No need for an explicit memory barrier here as long we would
2331 * need to ensure the ordering of writing to the SPQ element
2332 * and updating of the SPQ producer which involves a memory
2333 * read and we will have to put a full memory barrier there
2334 * (inside bnx2x_sp_post()).
2335 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002336
2337 /* Send a ramrod */
2338 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
2339 U64_HI(p->rdata_mapping),
2340 U64_LO(p->rdata_mapping),
2341 ETH_CONNECTION_TYPE);
2342 if (rc)
2343 return rc;
2344
2345 /* Ramrod completion is pending */
2346 return 1;
2347}
2348
2349static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
2350 struct bnx2x_rx_mode_ramrod_params *p)
2351{
2352 return bnx2x_state_wait(bp, p->state, p->pstate);
2353}
2354
2355static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
2356 struct bnx2x_rx_mode_ramrod_params *p)
2357{
2358 /* Do nothing */
2359 return 0;
2360}
2361
2362int bnx2x_config_rx_mode(struct bnx2x *bp,
2363 struct bnx2x_rx_mode_ramrod_params *p)
2364{
2365 int rc;
2366
2367 /* Configure the new classification in the chip */
2368 rc = p->rx_mode_obj->config_rx_mode(bp, p);
2369 if (rc < 0)
2370 return rc;
2371
2372 /* Wait for a ramrod completion if was requested */
2373 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
2374 rc = p->rx_mode_obj->wait_comp(bp, p);
2375 if (rc)
2376 return rc;
2377 }
2378
2379 return rc;
2380}
2381
2382void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
2383 struct bnx2x_rx_mode_obj *o)
2384{
2385 if (CHIP_IS_E1x(bp)) {
2386 o->wait_comp = bnx2x_empty_rx_mode_wait;
2387 o->config_rx_mode = bnx2x_set_rx_mode_e1x;
2388 } else {
2389 o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
2390 o->config_rx_mode = bnx2x_set_rx_mode_e2;
2391 }
2392}
2393
2394/********************* Multicast verbs: SET, CLEAR ****************************/
2395static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
2396{
2397 return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
2398}
2399
2400struct bnx2x_mcast_mac_elem {
2401 struct list_head link;
2402 u8 mac[ETH_ALEN];
2403 u8 pad[2]; /* For a natural alignment of the following buffer */
2404};
2405
2406struct bnx2x_pending_mcast_cmd {
2407 struct list_head link;
2408 int type; /* BNX2X_MCAST_CMD_X */
2409 union {
2410 struct list_head macs_head;
2411 u32 macs_num; /* Needed for DEL command */
2412 int next_bin; /* Needed for RESTORE flow with aprox match */
2413 } data;
2414
2415 bool done; /* set to true, when the command has been handled,
2416 * practically used in 57712 handling only, where one pending
2417 * command may be handled in a few operations. As long as for
2418 * other chips every operation handling is completed in a
2419 * single ramrod, there is no need to utilize this field.
2420 */
2421};
2422
2423static int bnx2x_mcast_wait(struct bnx2x *bp,
2424 struct bnx2x_mcast_obj *o)
2425{
2426 if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
2427 o->raw.wait_comp(bp, &o->raw))
2428 return -EBUSY;
2429
2430 return 0;
2431}
2432
2433static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
2434 struct bnx2x_mcast_obj *o,
2435 struct bnx2x_mcast_ramrod_params *p,
2436 int cmd)
2437{
2438 int total_sz;
2439 struct bnx2x_pending_mcast_cmd *new_cmd;
2440 struct bnx2x_mcast_mac_elem *cur_mac = NULL;
2441 struct bnx2x_mcast_list_elem *pos;
2442 int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
2443 p->mcast_list_len : 0);
2444
2445 /* If the command is empty ("handle pending commands only"), break */
2446 if (!p->mcast_list_len)
2447 return 0;
2448
2449 total_sz = sizeof(*new_cmd) +
2450 macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
2451
2452 /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
2453 new_cmd = kzalloc(total_sz, GFP_ATOMIC);
2454
2455 if (!new_cmd)
2456 return -ENOMEM;
2457
Merav Sicron51c1a582012-03-18 10:33:38 +00002458 DP(BNX2X_MSG_SP, "About to enqueue a new %d command. macs_list_len=%d\n",
2459 cmd, macs_list_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002460
2461 INIT_LIST_HEAD(&new_cmd->data.macs_head);
2462
2463 new_cmd->type = cmd;
2464 new_cmd->done = false;
2465
2466 switch (cmd) {
2467 case BNX2X_MCAST_CMD_ADD:
2468 cur_mac = (struct bnx2x_mcast_mac_elem *)
2469 ((u8 *)new_cmd + sizeof(*new_cmd));
2470
2471 /* Push the MACs of the current command into the pendig command
2472 * MACs list: FIFO
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002473 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002474 list_for_each_entry(pos, &p->mcast_list, link) {
2475 memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
2476 list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
2477 cur_mac++;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002478 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002479
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002480 break;
2481
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002482 case BNX2X_MCAST_CMD_DEL:
2483 new_cmd->data.macs_num = p->mcast_list_len;
2484 break;
2485
2486 case BNX2X_MCAST_CMD_RESTORE:
2487 new_cmd->data.next_bin = 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002488 break;
2489
2490 default:
Jesper Juhl8b6d5c02012-07-31 11:39:37 +00002491 kfree(new_cmd);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002492 BNX2X_ERR("Unknown command: %d\n", cmd);
2493 return -EINVAL;
2494 }
2495
2496 /* Push the new pending command to the tail of the pending list: FIFO */
2497 list_add_tail(&new_cmd->link, &o->pending_cmds_head);
2498
2499 o->set_sched(o);
2500
2501 return 1;
2502}
2503
2504/**
2505 * bnx2x_mcast_get_next_bin - get the next set bin (index)
2506 *
2507 * @o:
2508 * @last: index to start looking from (including)
2509 *
2510 * returns the next found (set) bin or a negative value if none is found.
2511 */
2512static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
2513{
2514 int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
2515
2516 for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
2517 if (o->registry.aprox_match.vec[i])
2518 for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
2519 int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
2520 if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
2521 vec, cur_bit)) {
2522 return cur_bit;
2523 }
2524 }
2525 inner_start = 0;
2526 }
2527
2528 /* None found */
2529 return -1;
2530}
2531
2532/**
2533 * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
2534 *
2535 * @o:
2536 *
2537 * returns the index of the found bin or -1 if none is found
2538 */
2539static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
2540{
2541 int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
2542
2543 if (cur_bit >= 0)
2544 BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
2545
2546 return cur_bit;
2547}
2548
2549static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
2550{
2551 struct bnx2x_raw_obj *raw = &o->raw;
2552 u8 rx_tx_flag = 0;
2553
2554 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
2555 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2556 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
2557
2558 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
2559 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2560 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
2561
2562 return rx_tx_flag;
2563}
2564
2565static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
2566 struct bnx2x_mcast_obj *o, int idx,
2567 union bnx2x_mcast_config_data *cfg_data,
2568 int cmd)
2569{
2570 struct bnx2x_raw_obj *r = &o->raw;
2571 struct eth_multicast_rules_ramrod_data *data =
2572 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2573 u8 func_id = r->func_id;
2574 u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
2575 int bin;
2576
2577 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
2578 rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
2579
2580 data->rules[idx].cmd_general_data |= rx_tx_add_flag;
2581
2582 /* Get a bin and update a bins' vector */
2583 switch (cmd) {
2584 case BNX2X_MCAST_CMD_ADD:
2585 bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
2586 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002587 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002588
2589 case BNX2X_MCAST_CMD_DEL:
2590 /* If there were no more bins to clear
2591 * (bnx2x_mcast_clear_first_bin() returns -1) then we would
2592 * clear any (0xff) bin.
2593 * See bnx2x_mcast_validate_e2() for explanation when it may
2594 * happen.
2595 */
2596 bin = bnx2x_mcast_clear_first_bin(o);
2597 break;
2598
2599 case BNX2X_MCAST_CMD_RESTORE:
2600 bin = cfg_data->bin;
2601 break;
2602
2603 default:
2604 BNX2X_ERR("Unknown command: %d\n", cmd);
2605 return;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002606 }
2607
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002608 DP(BNX2X_MSG_SP, "%s bin %d\n",
2609 ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
2610 "Setting" : "Clearing"), bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002611
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002612 data->rules[idx].bin_id = (u8)bin;
2613 data->rules[idx].func_id = func_id;
2614 data->rules[idx].engine_id = o->engine_id;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002615}
2616
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002617/**
2618 * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
2619 *
2620 * @bp: device handle
2621 * @o:
2622 * @start_bin: index in the registry to start from (including)
2623 * @rdata_idx: index in the ramrod data to start from
2624 *
2625 * returns last handled bin index or -1 if all bins have been handled
2626 */
2627static inline int bnx2x_mcast_handle_restore_cmd_e2(
2628 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
2629 int *rdata_idx)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002630{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002631 int cur_bin, cnt = *rdata_idx;
2632 union bnx2x_mcast_config_data cfg_data = {0};
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002633
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002634 /* go through the registry and configure the bins from it */
2635 for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
2636 cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002637
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002638 cfg_data.bin = (u8)cur_bin;
2639 o->set_one_rule(bp, o, cnt, &cfg_data,
2640 BNX2X_MCAST_CMD_RESTORE);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002641
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002642 cnt++;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002643
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002644 DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002645
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002646 /* Break if we reached the maximum number
2647 * of rules.
2648 */
2649 if (cnt >= o->max_cmd_len)
2650 break;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002651 }
2652
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002653 *rdata_idx = cnt;
2654
2655 return cur_bin;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002656}
2657
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002658static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
2659 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2660 int *line_idx)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002661{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002662 struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
2663 int cnt = *line_idx;
2664 union bnx2x_mcast_config_data cfg_data = {0};
2665
2666 list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
2667 link) {
2668
2669 cfg_data.mac = &pmac_pos->mac[0];
2670 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
2671
2672 cnt++;
2673
Joe Perches0f9dad12011-08-14 12:16:19 +00002674 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00002675 pmac_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002676
2677 list_del(&pmac_pos->link);
2678
2679 /* Break if we reached the maximum number
2680 * of rules.
2681 */
2682 if (cnt >= o->max_cmd_len)
2683 break;
2684 }
2685
2686 *line_idx = cnt;
2687
2688 /* if no more MACs to configure - we are done */
2689 if (list_empty(&cmd_pos->data.macs_head))
2690 cmd_pos->done = true;
2691}
2692
2693static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
2694 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2695 int *line_idx)
2696{
2697 int cnt = *line_idx;
2698
2699 while (cmd_pos->data.macs_num) {
2700 o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
2701
2702 cnt++;
2703
2704 cmd_pos->data.macs_num--;
2705
2706 DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
2707 cmd_pos->data.macs_num, cnt);
2708
2709 /* Break if we reached the maximum
2710 * number of rules.
2711 */
2712 if (cnt >= o->max_cmd_len)
2713 break;
2714 }
2715
2716 *line_idx = cnt;
2717
2718 /* If we cleared all bins - we are done */
2719 if (!cmd_pos->data.macs_num)
2720 cmd_pos->done = true;
2721}
2722
2723static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
2724 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2725 int *line_idx)
2726{
2727 cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
2728 line_idx);
2729
2730 if (cmd_pos->data.next_bin < 0)
2731 /* If o->set_restore returned -1 we are done */
2732 cmd_pos->done = true;
2733 else
2734 /* Start from the next bin next time */
2735 cmd_pos->data.next_bin++;
2736}
2737
2738static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
2739 struct bnx2x_mcast_ramrod_params *p)
2740{
2741 struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
2742 int cnt = 0;
2743 struct bnx2x_mcast_obj *o = p->mcast_obj;
2744
2745 list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
2746 link) {
2747 switch (cmd_pos->type) {
2748 case BNX2X_MCAST_CMD_ADD:
2749 bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
2750 break;
2751
2752 case BNX2X_MCAST_CMD_DEL:
2753 bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
2754 break;
2755
2756 case BNX2X_MCAST_CMD_RESTORE:
2757 bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
2758 &cnt);
2759 break;
2760
2761 default:
2762 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
2763 return -EINVAL;
2764 }
2765
2766 /* If the command has been completed - remove it from the list
2767 * and free the memory
2768 */
2769 if (cmd_pos->done) {
2770 list_del(&cmd_pos->link);
2771 kfree(cmd_pos);
2772 }
2773
2774 /* Break if we reached the maximum number of rules */
2775 if (cnt >= o->max_cmd_len)
2776 break;
2777 }
2778
2779 return cnt;
2780}
2781
2782static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
2783 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2784 int *line_idx)
2785{
2786 struct bnx2x_mcast_list_elem *mlist_pos;
2787 union bnx2x_mcast_config_data cfg_data = {0};
2788 int cnt = *line_idx;
2789
2790 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
2791 cfg_data.mac = mlist_pos->mac;
2792 o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
2793
2794 cnt++;
2795
Joe Perches0f9dad12011-08-14 12:16:19 +00002796 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00002797 mlist_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002798 }
2799
2800 *line_idx = cnt;
2801}
2802
2803static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
2804 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2805 int *line_idx)
2806{
2807 int cnt = *line_idx, i;
2808
2809 for (i = 0; i < p->mcast_list_len; i++) {
2810 o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
2811
2812 cnt++;
2813
2814 DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
2815 p->mcast_list_len - i - 1);
2816 }
2817
2818 *line_idx = cnt;
2819}
2820
2821/**
2822 * bnx2x_mcast_handle_current_cmd -
2823 *
2824 * @bp: device handle
2825 * @p:
2826 * @cmd:
2827 * @start_cnt: first line in the ramrod data that may be used
2828 *
2829 * This function is called iff there is enough place for the current command in
2830 * the ramrod data.
2831 * Returns number of lines filled in the ramrod data in total.
2832 */
2833static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
2834 struct bnx2x_mcast_ramrod_params *p, int cmd,
2835 int start_cnt)
2836{
2837 struct bnx2x_mcast_obj *o = p->mcast_obj;
2838 int cnt = start_cnt;
2839
2840 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
2841
2842 switch (cmd) {
2843 case BNX2X_MCAST_CMD_ADD:
2844 bnx2x_mcast_hdl_add(bp, o, p, &cnt);
2845 break;
2846
2847 case BNX2X_MCAST_CMD_DEL:
2848 bnx2x_mcast_hdl_del(bp, o, p, &cnt);
2849 break;
2850
2851 case BNX2X_MCAST_CMD_RESTORE:
2852 o->hdl_restore(bp, o, 0, &cnt);
2853 break;
2854
2855 default:
2856 BNX2X_ERR("Unknown command: %d\n", cmd);
2857 return -EINVAL;
2858 }
2859
2860 /* The current command has been handled */
2861 p->mcast_list_len = 0;
2862
2863 return cnt;
2864}
2865
2866static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
2867 struct bnx2x_mcast_ramrod_params *p,
2868 int cmd)
2869{
2870 struct bnx2x_mcast_obj *o = p->mcast_obj;
2871 int reg_sz = o->get_registry_size(o);
2872
2873 switch (cmd) {
2874 /* DEL command deletes all currently configured MACs */
2875 case BNX2X_MCAST_CMD_DEL:
2876 o->set_registry_size(o, 0);
2877 /* Don't break */
2878
2879 /* RESTORE command will restore the entire multicast configuration */
2880 case BNX2X_MCAST_CMD_RESTORE:
2881 /* Here we set the approximate amount of work to do, which in
2882 * fact may be only less as some MACs in postponed ADD
2883 * command(s) scheduled before this command may fall into
2884 * the same bin and the actual number of bins set in the
2885 * registry would be less than we estimated here. See
2886 * bnx2x_mcast_set_one_rule_e2() for further details.
2887 */
2888 p->mcast_list_len = reg_sz;
2889 break;
2890
2891 case BNX2X_MCAST_CMD_ADD:
2892 case BNX2X_MCAST_CMD_CONT:
2893 /* Here we assume that all new MACs will fall into new bins.
2894 * However we will correct the real registry size after we
2895 * handle all pending commands.
2896 */
2897 o->set_registry_size(o, reg_sz + p->mcast_list_len);
2898 break;
2899
2900 default:
2901 BNX2X_ERR("Unknown command: %d\n", cmd);
2902 return -EINVAL;
2903
2904 }
2905
2906 /* Increase the total number of MACs pending to be configured */
2907 o->total_pending_num += p->mcast_list_len;
2908
2909 return 0;
2910}
2911
2912static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
2913 struct bnx2x_mcast_ramrod_params *p,
2914 int old_num_bins)
2915{
2916 struct bnx2x_mcast_obj *o = p->mcast_obj;
2917
2918 o->set_registry_size(o, old_num_bins);
2919 o->total_pending_num -= p->mcast_list_len;
2920}
2921
2922/**
2923 * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
2924 *
2925 * @bp: device handle
2926 * @p:
2927 * @len: number of rules to handle
2928 */
2929static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
2930 struct bnx2x_mcast_ramrod_params *p,
2931 u8 len)
2932{
2933 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
2934 struct eth_multicast_rules_ramrod_data *data =
2935 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2936
2937 data->header.echo = ((r->cid & BNX2X_SWCID_MASK) |
2938 (BNX2X_FILTER_MCAST_PENDING << BNX2X_SWCID_SHIFT));
2939 data->header.rule_cnt = len;
2940}
2941
2942/**
2943 * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
2944 *
2945 * @bp: device handle
2946 * @o:
2947 *
2948 * Recalculate the actual number of set bins in the registry using Brian
2949 * Kernighan's algorithm: it's execution complexity is as a number of set bins.
2950 *
2951 * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
2952 */
2953static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
2954 struct bnx2x_mcast_obj *o)
2955{
2956 int i, cnt = 0;
2957 u64 elem;
2958
2959 for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
2960 elem = o->registry.aprox_match.vec[i];
2961 for (; elem; cnt++)
2962 elem &= elem - 1;
2963 }
2964
2965 o->set_registry_size(o, cnt);
2966
2967 return 0;
2968}
2969
2970static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
2971 struct bnx2x_mcast_ramrod_params *p,
2972 int cmd)
2973{
2974 struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
2975 struct bnx2x_mcast_obj *o = p->mcast_obj;
2976 struct eth_multicast_rules_ramrod_data *data =
2977 (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
2978 int cnt = 0, rc;
2979
2980 /* Reset the ramrod data buffer */
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002981 memset(data, 0, sizeof(*data));
2982
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002983 cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
2984
2985 /* If there are no more pending commands - clear SCHEDULED state */
2986 if (list_empty(&o->pending_cmds_head))
2987 o->clear_sched(o);
2988
2989 /* The below may be true iff there was enough room in ramrod
2990 * data for all pending commands and for the current
2991 * command. Otherwise the current command would have been added
2992 * to the pending commands and p->mcast_list_len would have been
2993 * zeroed.
2994 */
2995 if (p->mcast_list_len > 0)
2996 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
2997
2998 /* We've pulled out some MACs - update the total number of
2999 * outstanding.
3000 */
3001 o->total_pending_num -= cnt;
3002
3003 /* send a ramrod */
3004 WARN_ON(o->total_pending_num < 0);
3005 WARN_ON(cnt > o->max_cmd_len);
3006
3007 bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
3008
3009 /* Update a registry size if there are no more pending operations.
3010 *
3011 * We don't want to change the value of the registry size if there are
3012 * pending operations because we want it to always be equal to the
3013 * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
3014 * set bins after the last requested operation in order to properly
3015 * evaluate the size of the next DEL/RESTORE operation.
3016 *
3017 * Note that we update the registry itself during command(s) handling
3018 * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
3019 * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
3020 * with a limited amount of update commands (per MAC/bin) and we don't
3021 * know in this scope what the actual state of bins configuration is
3022 * going to be after this ramrod.
3023 */
3024 if (!o->total_pending_num)
3025 bnx2x_mcast_refresh_registry_e2(bp, o);
3026
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003027 /*
3028 * If CLEAR_ONLY was requested - don't send a ramrod and clear
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003029 * RAMROD_PENDING status immediately.
3030 */
3031 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3032 raw->clear_pending(raw);
3033 return 0;
3034 } else {
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003035 /*
3036 * No need for an explicit memory barrier here as long we would
3037 * need to ensure the ordering of writing to the SPQ element
3038 * and updating of the SPQ producer which involves a memory
3039 * read and we will have to put a full memory barrier there
3040 * (inside bnx2x_sp_post()).
3041 */
3042
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003043 /* Send a ramrod */
3044 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
3045 raw->cid, U64_HI(raw->rdata_mapping),
3046 U64_LO(raw->rdata_mapping),
3047 ETH_CONNECTION_TYPE);
3048 if (rc)
3049 return rc;
3050
3051 /* Ramrod completion is pending */
3052 return 1;
3053 }
3054}
3055
3056static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
3057 struct bnx2x_mcast_ramrod_params *p,
3058 int cmd)
3059{
3060 /* Mark, that there is a work to do */
3061 if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
3062 p->mcast_list_len = 1;
3063
3064 return 0;
3065}
3066
3067static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
3068 struct bnx2x_mcast_ramrod_params *p,
3069 int old_num_bins)
3070{
3071 /* Do nothing */
3072}
3073
3074#define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3075do { \
3076 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3077} while (0)
3078
3079static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
3080 struct bnx2x_mcast_obj *o,
3081 struct bnx2x_mcast_ramrod_params *p,
3082 u32 *mc_filter)
3083{
3084 struct bnx2x_mcast_list_elem *mlist_pos;
3085 int bit;
3086
3087 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
3088 bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
3089 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3090
Joe Perches0f9dad12011-08-14 12:16:19 +00003091 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC, bin %d\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003092 mlist_pos->mac, bit);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003093
3094 /* bookkeeping... */
3095 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
3096 bit);
3097 }
3098}
3099
3100static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
3101 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3102 u32 *mc_filter)
3103{
3104 int bit;
3105
3106 for (bit = bnx2x_mcast_get_next_bin(o, 0);
3107 bit >= 0;
3108 bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
3109 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3110 DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
3111 }
3112}
3113
3114/* On 57711 we write the multicast MACs' aproximate match
3115 * table by directly into the TSTORM's internal RAM. So we don't
3116 * really need to handle any tricks to make it work.
3117 */
3118static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
3119 struct bnx2x_mcast_ramrod_params *p,
3120 int cmd)
3121{
3122 int i;
3123 struct bnx2x_mcast_obj *o = p->mcast_obj;
3124 struct bnx2x_raw_obj *r = &o->raw;
3125
3126 /* If CLEAR_ONLY has been requested - clear the registry
3127 * and clear a pending bit.
3128 */
3129 if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3130 u32 mc_filter[MC_HASH_SIZE] = {0};
3131
3132 /* Set the multicast filter bits before writing it into
3133 * the internal memory.
3134 */
3135 switch (cmd) {
3136 case BNX2X_MCAST_CMD_ADD:
3137 bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
3138 break;
3139
3140 case BNX2X_MCAST_CMD_DEL:
Joe Perches94f05b02011-08-14 12:16:20 +00003141 DP(BNX2X_MSG_SP,
3142 "Invalidating multicast MACs configuration\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003143
3144 /* clear the registry */
3145 memset(o->registry.aprox_match.vec, 0,
3146 sizeof(o->registry.aprox_match.vec));
3147 break;
3148
3149 case BNX2X_MCAST_CMD_RESTORE:
3150 bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
3151 break;
3152
3153 default:
3154 BNX2X_ERR("Unknown command: %d\n", cmd);
3155 return -EINVAL;
3156 }
3157
3158 /* Set the mcast filter in the internal memory */
3159 for (i = 0; i < MC_HASH_SIZE; i++)
3160 REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
3161 } else
3162 /* clear the registry */
3163 memset(o->registry.aprox_match.vec, 0,
3164 sizeof(o->registry.aprox_match.vec));
3165
3166 /* We are done */
3167 r->clear_pending(r);
3168
3169 return 0;
3170}
3171
3172static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
3173 struct bnx2x_mcast_ramrod_params *p,
3174 int cmd)
3175{
3176 struct bnx2x_mcast_obj *o = p->mcast_obj;
3177 int reg_sz = o->get_registry_size(o);
3178
3179 switch (cmd) {
3180 /* DEL command deletes all currently configured MACs */
3181 case BNX2X_MCAST_CMD_DEL:
3182 o->set_registry_size(o, 0);
3183 /* Don't break */
3184
3185 /* RESTORE command will restore the entire multicast configuration */
3186 case BNX2X_MCAST_CMD_RESTORE:
3187 p->mcast_list_len = reg_sz;
3188 DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
3189 cmd, p->mcast_list_len);
3190 break;
3191
3192 case BNX2X_MCAST_CMD_ADD:
3193 case BNX2X_MCAST_CMD_CONT:
3194 /* Multicast MACs on 57710 are configured as unicast MACs and
3195 * there is only a limited number of CAM entries for that
3196 * matter.
3197 */
3198 if (p->mcast_list_len > o->max_cmd_len) {
Merav Sicron51c1a582012-03-18 10:33:38 +00003199 BNX2X_ERR("Can't configure more than %d multicast MACs on 57710\n",
3200 o->max_cmd_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003201 return -EINVAL;
3202 }
3203 /* Every configured MAC should be cleared if DEL command is
3204 * called. Only the last ADD command is relevant as long as
3205 * every ADD commands overrides the previous configuration.
3206 */
3207 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3208 if (p->mcast_list_len > 0)
3209 o->set_registry_size(o, p->mcast_list_len);
3210
3211 break;
3212
3213 default:
3214 BNX2X_ERR("Unknown command: %d\n", cmd);
3215 return -EINVAL;
3216
3217 }
3218
3219 /* We want to ensure that commands are executed one by one for 57710.
3220 * Therefore each none-empty command will consume o->max_cmd_len.
3221 */
3222 if (p->mcast_list_len)
3223 o->total_pending_num += o->max_cmd_len;
3224
3225 return 0;
3226}
3227
3228static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
3229 struct bnx2x_mcast_ramrod_params *p,
3230 int old_num_macs)
3231{
3232 struct bnx2x_mcast_obj *o = p->mcast_obj;
3233
3234 o->set_registry_size(o, old_num_macs);
3235
3236 /* If current command hasn't been handled yet and we are
3237 * here means that it's meant to be dropped and we have to
3238 * update the number of outstandling MACs accordingly.
3239 */
3240 if (p->mcast_list_len)
3241 o->total_pending_num -= o->max_cmd_len;
3242}
3243
3244static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
3245 struct bnx2x_mcast_obj *o, int idx,
3246 union bnx2x_mcast_config_data *cfg_data,
3247 int cmd)
3248{
3249 struct bnx2x_raw_obj *r = &o->raw;
3250 struct mac_configuration_cmd *data =
3251 (struct mac_configuration_cmd *)(r->rdata);
3252
3253 /* copy mac */
3254 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
3255 bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
3256 &data->config_table[idx].middle_mac_addr,
3257 &data->config_table[idx].lsb_mac_addr,
3258 cfg_data->mac);
3259
3260 data->config_table[idx].vlan_id = 0;
3261 data->config_table[idx].pf_id = r->func_id;
3262 data->config_table[idx].clients_bit_vector =
3263 cpu_to_le32(1 << r->cl_id);
3264
3265 SET_FLAG(data->config_table[idx].flags,
3266 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3267 T_ETH_MAC_COMMAND_SET);
3268 }
3269}
3270
3271/**
3272 * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
3273 *
3274 * @bp: device handle
3275 * @p:
3276 * @len: number of rules to handle
3277 */
3278static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
3279 struct bnx2x_mcast_ramrod_params *p,
3280 u8 len)
3281{
3282 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3283 struct mac_configuration_cmd *data =
3284 (struct mac_configuration_cmd *)(r->rdata);
3285
3286 u8 offset = (CHIP_REV_IS_SLOW(bp) ?
3287 BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
3288 BNX2X_MAX_MULTICAST*(1 + r->func_id));
3289
3290 data->hdr.offset = offset;
3291 data->hdr.client_id = 0xff;
3292 data->hdr.echo = ((r->cid & BNX2X_SWCID_MASK) |
3293 (BNX2X_FILTER_MCAST_PENDING << BNX2X_SWCID_SHIFT));
3294 data->hdr.length = len;
3295}
3296
3297/**
3298 * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
3299 *
3300 * @bp: device handle
3301 * @o:
3302 * @start_idx: index in the registry to start from
3303 * @rdata_idx: index in the ramrod data to start from
3304 *
3305 * restore command for 57710 is like all other commands - always a stand alone
3306 * command - start_idx and rdata_idx will always be 0. This function will always
3307 * succeed.
3308 * returns -1 to comply with 57712 variant.
3309 */
3310static inline int bnx2x_mcast_handle_restore_cmd_e1(
3311 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
3312 int *rdata_idx)
3313{
3314 struct bnx2x_mcast_mac_elem *elem;
3315 int i = 0;
3316 union bnx2x_mcast_config_data cfg_data = {0};
3317
3318 /* go through the registry and configure the MACs from it. */
3319 list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
3320 cfg_data.mac = &elem->mac[0];
3321 o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
3322
3323 i++;
3324
Joe Perches0f9dad12011-08-14 12:16:19 +00003325 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003326 cfg_data.mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003327 }
3328
3329 *rdata_idx = i;
3330
3331 return -1;
3332}
3333
3334
3335static inline int bnx2x_mcast_handle_pending_cmds_e1(
3336 struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
3337{
3338 struct bnx2x_pending_mcast_cmd *cmd_pos;
3339 struct bnx2x_mcast_mac_elem *pmac_pos;
3340 struct bnx2x_mcast_obj *o = p->mcast_obj;
3341 union bnx2x_mcast_config_data cfg_data = {0};
3342 int cnt = 0;
3343
3344
3345 /* If nothing to be done - return */
3346 if (list_empty(&o->pending_cmds_head))
3347 return 0;
3348
3349 /* Handle the first command */
3350 cmd_pos = list_first_entry(&o->pending_cmds_head,
3351 struct bnx2x_pending_mcast_cmd, link);
3352
3353 switch (cmd_pos->type) {
3354 case BNX2X_MCAST_CMD_ADD:
3355 list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
3356 cfg_data.mac = &pmac_pos->mac[0];
3357 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
3358
3359 cnt++;
3360
Joe Perches0f9dad12011-08-14 12:16:19 +00003361 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003362 pmac_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003363 }
3364 break;
3365
3366 case BNX2X_MCAST_CMD_DEL:
3367 cnt = cmd_pos->data.macs_num;
3368 DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
3369 break;
3370
3371 case BNX2X_MCAST_CMD_RESTORE:
3372 o->hdl_restore(bp, o, 0, &cnt);
3373 break;
3374
3375 default:
3376 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
3377 return -EINVAL;
3378 }
3379
3380 list_del(&cmd_pos->link);
3381 kfree(cmd_pos);
3382
3383 return cnt;
3384}
3385
3386/**
3387 * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
3388 *
3389 * @fw_hi:
3390 * @fw_mid:
3391 * @fw_lo:
3392 * @mac:
3393 */
3394static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
3395 __le16 *fw_lo, u8 *mac)
3396{
3397 mac[1] = ((u8 *)fw_hi)[0];
3398 mac[0] = ((u8 *)fw_hi)[1];
3399 mac[3] = ((u8 *)fw_mid)[0];
3400 mac[2] = ((u8 *)fw_mid)[1];
3401 mac[5] = ((u8 *)fw_lo)[0];
3402 mac[4] = ((u8 *)fw_lo)[1];
3403}
3404
3405/**
3406 * bnx2x_mcast_refresh_registry_e1 -
3407 *
3408 * @bp: device handle
3409 * @cnt:
3410 *
3411 * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
3412 * and update the registry correspondingly: if ADD - allocate a memory and add
3413 * the entries to the registry (list), if DELETE - clear the registry and free
3414 * the memory.
3415 */
3416static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
3417 struct bnx2x_mcast_obj *o)
3418{
3419 struct bnx2x_raw_obj *raw = &o->raw;
3420 struct bnx2x_mcast_mac_elem *elem;
3421 struct mac_configuration_cmd *data =
3422 (struct mac_configuration_cmd *)(raw->rdata);
3423
3424 /* If first entry contains a SET bit - the command was ADD,
3425 * otherwise - DEL_ALL
3426 */
3427 if (GET_FLAG(data->config_table[0].flags,
3428 MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
3429 int i, len = data->hdr.length;
3430
3431 /* Break if it was a RESTORE command */
3432 if (!list_empty(&o->registry.exact_match.macs))
3433 return 0;
3434
Thomas Meyer01e23742011-11-29 11:08:00 +00003435 elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003436 if (!elem) {
3437 BNX2X_ERR("Failed to allocate registry memory\n");
3438 return -ENOMEM;
3439 }
3440
3441 for (i = 0; i < len; i++, elem++) {
3442 bnx2x_get_fw_mac_addr(
3443 &data->config_table[i].msb_mac_addr,
3444 &data->config_table[i].middle_mac_addr,
3445 &data->config_table[i].lsb_mac_addr,
3446 elem->mac);
Joe Perches0f9dad12011-08-14 12:16:19 +00003447 DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00003448 elem->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003449 list_add_tail(&elem->link,
3450 &o->registry.exact_match.macs);
3451 }
3452 } else {
3453 elem = list_first_entry(&o->registry.exact_match.macs,
3454 struct bnx2x_mcast_mac_elem, link);
3455 DP(BNX2X_MSG_SP, "Deleting a registry\n");
3456 kfree(elem);
3457 INIT_LIST_HEAD(&o->registry.exact_match.macs);
3458 }
3459
3460 return 0;
3461}
3462
3463static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
3464 struct bnx2x_mcast_ramrod_params *p,
3465 int cmd)
3466{
3467 struct bnx2x_mcast_obj *o = p->mcast_obj;
3468 struct bnx2x_raw_obj *raw = &o->raw;
3469 struct mac_configuration_cmd *data =
3470 (struct mac_configuration_cmd *)(raw->rdata);
3471 int cnt = 0, i, rc;
3472
3473 /* Reset the ramrod data buffer */
3474 memset(data, 0, sizeof(*data));
3475
3476 /* First set all entries as invalid */
3477 for (i = 0; i < o->max_cmd_len ; i++)
3478 SET_FLAG(data->config_table[i].flags,
3479 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3480 T_ETH_MAC_COMMAND_INVALIDATE);
3481
3482 /* Handle pending commands first */
3483 cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
3484
3485 /* If there are no more pending commands - clear SCHEDULED state */
3486 if (list_empty(&o->pending_cmds_head))
3487 o->clear_sched(o);
3488
3489 /* The below may be true iff there were no pending commands */
3490 if (!cnt)
3491 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
3492
3493 /* For 57710 every command has o->max_cmd_len length to ensure that
3494 * commands are done one at a time.
3495 */
3496 o->total_pending_num -= o->max_cmd_len;
3497
3498 /* send a ramrod */
3499
3500 WARN_ON(cnt > o->max_cmd_len);
3501
3502 /* Set ramrod header (in particular, a number of entries to update) */
3503 bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
3504
3505 /* update a registry: we need the registry contents to be always up
3506 * to date in order to be able to execute a RESTORE opcode. Here
3507 * we use the fact that for 57710 we sent one command at a time
3508 * hence we may take the registry update out of the command handling
3509 * and do it in a simpler way here.
3510 */
3511 rc = bnx2x_mcast_refresh_registry_e1(bp, o);
3512 if (rc)
3513 return rc;
3514
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003515 /*
3516 * If CLEAR_ONLY was requested - don't send a ramrod and clear
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003517 * RAMROD_PENDING status immediately.
3518 */
3519 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3520 raw->clear_pending(raw);
3521 return 0;
3522 } else {
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003523 /*
3524 * No need for an explicit memory barrier here as long we would
3525 * need to ensure the ordering of writing to the SPQ element
3526 * and updating of the SPQ producer which involves a memory
3527 * read and we will have to put a full memory barrier there
3528 * (inside bnx2x_sp_post()).
3529 */
3530
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003531 /* Send a ramrod */
3532 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
3533 U64_HI(raw->rdata_mapping),
3534 U64_LO(raw->rdata_mapping),
3535 ETH_CONNECTION_TYPE);
3536 if (rc)
3537 return rc;
3538
3539 /* Ramrod completion is pending */
3540 return 1;
3541 }
3542
3543}
3544
3545static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
3546{
3547 return o->registry.exact_match.num_macs_set;
3548}
3549
3550static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
3551{
3552 return o->registry.aprox_match.num_bins_set;
3553}
3554
3555static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
3556 int n)
3557{
3558 o->registry.exact_match.num_macs_set = n;
3559}
3560
3561static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
3562 int n)
3563{
3564 o->registry.aprox_match.num_bins_set = n;
3565}
3566
3567int bnx2x_config_mcast(struct bnx2x *bp,
3568 struct bnx2x_mcast_ramrod_params *p,
3569 int cmd)
3570{
3571 struct bnx2x_mcast_obj *o = p->mcast_obj;
3572 struct bnx2x_raw_obj *r = &o->raw;
3573 int rc = 0, old_reg_size;
3574
3575 /* This is needed to recover number of currently configured mcast macs
3576 * in case of failure.
3577 */
3578 old_reg_size = o->get_registry_size(o);
3579
3580 /* Do some calculations and checks */
3581 rc = o->validate(bp, p, cmd);
3582 if (rc)
3583 return rc;
3584
3585 /* Return if there is no work to do */
3586 if ((!p->mcast_list_len) && (!o->check_sched(o)))
3587 return 0;
3588
Merav Sicron51c1a582012-03-18 10:33:38 +00003589 DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d o->max_cmd_len=%d\n",
3590 o->total_pending_num, p->mcast_list_len, o->max_cmd_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003591
3592 /* Enqueue the current command to the pending list if we can't complete
3593 * it in the current iteration
3594 */
3595 if (r->check_pending(r) ||
3596 ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
3597 rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
3598 if (rc < 0)
3599 goto error_exit1;
3600
3601 /* As long as the current command is in a command list we
3602 * don't need to handle it separately.
3603 */
3604 p->mcast_list_len = 0;
3605 }
3606
3607 if (!r->check_pending(r)) {
3608
3609 /* Set 'pending' state */
3610 r->set_pending(r);
3611
3612 /* Configure the new classification in the chip */
3613 rc = o->config_mcast(bp, p, cmd);
3614 if (rc < 0)
3615 goto error_exit2;
3616
3617 /* Wait for a ramrod completion if was requested */
3618 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
3619 rc = o->wait_comp(bp, o);
3620 }
3621
3622 return rc;
3623
3624error_exit2:
3625 r->clear_pending(r);
3626
3627error_exit1:
3628 o->revert(bp, p, old_reg_size);
3629
3630 return rc;
3631}
3632
3633static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
3634{
3635 smp_mb__before_clear_bit();
3636 clear_bit(o->sched_state, o->raw.pstate);
3637 smp_mb__after_clear_bit();
3638}
3639
3640static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
3641{
3642 smp_mb__before_clear_bit();
3643 set_bit(o->sched_state, o->raw.pstate);
3644 smp_mb__after_clear_bit();
3645}
3646
3647static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
3648{
3649 return !!test_bit(o->sched_state, o->raw.pstate);
3650}
3651
3652static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
3653{
3654 return o->raw.check_pending(&o->raw) || o->check_sched(o);
3655}
3656
3657void bnx2x_init_mcast_obj(struct bnx2x *bp,
3658 struct bnx2x_mcast_obj *mcast_obj,
3659 u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
3660 u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
3661 int state, unsigned long *pstate, bnx2x_obj_type type)
3662{
3663 memset(mcast_obj, 0, sizeof(*mcast_obj));
3664
3665 bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
3666 rdata, rdata_mapping, state, pstate, type);
3667
3668 mcast_obj->engine_id = engine_id;
3669
3670 INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
3671
3672 mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
3673 mcast_obj->check_sched = bnx2x_mcast_check_sched;
3674 mcast_obj->set_sched = bnx2x_mcast_set_sched;
3675 mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
3676
3677 if (CHIP_IS_E1(bp)) {
3678 mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
3679 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3680 mcast_obj->hdl_restore =
3681 bnx2x_mcast_handle_restore_cmd_e1;
3682 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3683
3684 if (CHIP_REV_IS_SLOW(bp))
3685 mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
3686 else
3687 mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
3688
3689 mcast_obj->wait_comp = bnx2x_mcast_wait;
3690 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
3691 mcast_obj->validate = bnx2x_mcast_validate_e1;
3692 mcast_obj->revert = bnx2x_mcast_revert_e1;
3693 mcast_obj->get_registry_size =
3694 bnx2x_mcast_get_registry_size_exact;
3695 mcast_obj->set_registry_size =
3696 bnx2x_mcast_set_registry_size_exact;
3697
3698 /* 57710 is the only chip that uses the exact match for mcast
3699 * at the moment.
3700 */
3701 INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
3702
3703 } else if (CHIP_IS_E1H(bp)) {
3704 mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
3705 mcast_obj->enqueue_cmd = NULL;
3706 mcast_obj->hdl_restore = NULL;
3707 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3708
3709 /* 57711 doesn't send a ramrod, so it has unlimited credit
3710 * for one command.
3711 */
3712 mcast_obj->max_cmd_len = -1;
3713 mcast_obj->wait_comp = bnx2x_mcast_wait;
3714 mcast_obj->set_one_rule = NULL;
3715 mcast_obj->validate = bnx2x_mcast_validate_e1h;
3716 mcast_obj->revert = bnx2x_mcast_revert_e1h;
3717 mcast_obj->get_registry_size =
3718 bnx2x_mcast_get_registry_size_aprox;
3719 mcast_obj->set_registry_size =
3720 bnx2x_mcast_set_registry_size_aprox;
3721 } else {
3722 mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
3723 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3724 mcast_obj->hdl_restore =
3725 bnx2x_mcast_handle_restore_cmd_e2;
3726 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3727 /* TODO: There should be a proper HSI define for this number!!!
3728 */
3729 mcast_obj->max_cmd_len = 16;
3730 mcast_obj->wait_comp = bnx2x_mcast_wait;
3731 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
3732 mcast_obj->validate = bnx2x_mcast_validate_e2;
3733 mcast_obj->revert = bnx2x_mcast_revert_e2;
3734 mcast_obj->get_registry_size =
3735 bnx2x_mcast_get_registry_size_aprox;
3736 mcast_obj->set_registry_size =
3737 bnx2x_mcast_set_registry_size_aprox;
3738 }
3739}
3740
3741/*************************** Credit handling **********************************/
3742
3743/**
3744 * atomic_add_ifless - add if the result is less than a given value.
3745 *
3746 * @v: pointer of type atomic_t
3747 * @a: the amount to add to v...
3748 * @u: ...if (v + a) is less than u.
3749 *
3750 * returns true if (v + a) was less than u, and false otherwise.
3751 *
3752 */
3753static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
3754{
3755 int c, old;
3756
3757 c = atomic_read(v);
3758 for (;;) {
3759 if (unlikely(c + a >= u))
3760 return false;
3761
3762 old = atomic_cmpxchg((v), c, c + a);
3763 if (likely(old == c))
3764 break;
3765 c = old;
3766 }
3767
3768 return true;
3769}
3770
3771/**
3772 * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
3773 *
3774 * @v: pointer of type atomic_t
3775 * @a: the amount to dec from v...
3776 * @u: ...if (v - a) is more or equal than u.
3777 *
3778 * returns true if (v - a) was more or equal than u, and false
3779 * otherwise.
3780 */
3781static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
3782{
3783 int c, old;
3784
3785 c = atomic_read(v);
3786 for (;;) {
3787 if (unlikely(c - a < u))
3788 return false;
3789
3790 old = atomic_cmpxchg((v), c, c - a);
3791 if (likely(old == c))
3792 break;
3793 c = old;
3794 }
3795
3796 return true;
3797}
3798
3799static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
3800{
3801 bool rc;
3802
3803 smp_mb();
3804 rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
3805 smp_mb();
3806
3807 return rc;
3808}
3809
3810static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
3811{
3812 bool rc;
3813
3814 smp_mb();
3815
3816 /* Don't let to refill if credit + cnt > pool_sz */
3817 rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
3818
3819 smp_mb();
3820
3821 return rc;
3822}
3823
3824static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
3825{
3826 int cur_credit;
3827
3828 smp_mb();
3829 cur_credit = atomic_read(&o->credit);
3830
3831 return cur_credit;
3832}
3833
3834static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
3835 int cnt)
3836{
3837 return true;
3838}
3839
3840
3841static bool bnx2x_credit_pool_get_entry(
3842 struct bnx2x_credit_pool_obj *o,
3843 int *offset)
3844{
3845 int idx, vec, i;
3846
3847 *offset = -1;
3848
3849 /* Find "internal cam-offset" then add to base for this object... */
3850 for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
3851
3852 /* Skip the current vector if there are no free entries in it */
3853 if (!o->pool_mirror[vec])
3854 continue;
3855
3856 /* If we've got here we are going to find a free entry */
Dmitry Kravkovc54e9bd2012-03-26 21:08:55 +00003857 for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003858 i < BIT_VEC64_ELEM_SZ; idx++, i++)
3859
3860 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
3861 /* Got one!! */
3862 BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
3863 *offset = o->base_pool_offset + idx;
3864 return true;
3865 }
3866 }
3867
3868 return false;
3869}
3870
3871static bool bnx2x_credit_pool_put_entry(
3872 struct bnx2x_credit_pool_obj *o,
3873 int offset)
3874{
3875 if (offset < o->base_pool_offset)
3876 return false;
3877
3878 offset -= o->base_pool_offset;
3879
3880 if (offset >= o->pool_sz)
3881 return false;
3882
3883 /* Return the entry to the pool */
3884 BIT_VEC64_SET_BIT(o->pool_mirror, offset);
3885
3886 return true;
3887}
3888
3889static bool bnx2x_credit_pool_put_entry_always_true(
3890 struct bnx2x_credit_pool_obj *o,
3891 int offset)
3892{
3893 return true;
3894}
3895
3896static bool bnx2x_credit_pool_get_entry_always_true(
3897 struct bnx2x_credit_pool_obj *o,
3898 int *offset)
3899{
3900 *offset = -1;
3901 return true;
3902}
3903/**
3904 * bnx2x_init_credit_pool - initialize credit pool internals.
3905 *
3906 * @p:
3907 * @base: Base entry in the CAM to use.
3908 * @credit: pool size.
3909 *
3910 * If base is negative no CAM entries handling will be performed.
3911 * If credit is negative pool operations will always succeed (unlimited pool).
3912 *
3913 */
3914static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
3915 int base, int credit)
3916{
3917 /* Zero the object first */
3918 memset(p, 0, sizeof(*p));
3919
3920 /* Set the table to all 1s */
3921 memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
3922
3923 /* Init a pool as full */
3924 atomic_set(&p->credit, credit);
3925
3926 /* The total poll size */
3927 p->pool_sz = credit;
3928
3929 p->base_pool_offset = base;
3930
3931 /* Commit the change */
3932 smp_mb();
3933
3934 p->check = bnx2x_credit_pool_check;
3935
3936 /* if pool credit is negative - disable the checks */
3937 if (credit >= 0) {
3938 p->put = bnx2x_credit_pool_put;
3939 p->get = bnx2x_credit_pool_get;
3940 p->put_entry = bnx2x_credit_pool_put_entry;
3941 p->get_entry = bnx2x_credit_pool_get_entry;
3942 } else {
3943 p->put = bnx2x_credit_pool_always_true;
3944 p->get = bnx2x_credit_pool_always_true;
3945 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
3946 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
3947 }
3948
3949 /* If base is negative - disable entries handling */
3950 if (base < 0) {
3951 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
3952 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
3953 }
3954}
3955
3956void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
3957 struct bnx2x_credit_pool_obj *p, u8 func_id,
3958 u8 func_num)
3959{
3960/* TODO: this will be defined in consts as well... */
3961#define BNX2X_CAM_SIZE_EMUL 5
3962
3963 int cam_sz;
3964
3965 if (CHIP_IS_E1(bp)) {
3966 /* In E1, Multicast is saved in cam... */
3967 if (!CHIP_REV_IS_SLOW(bp))
3968 cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
3969 else
3970 cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
3971
3972 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3973
3974 } else if (CHIP_IS_E1H(bp)) {
3975 /* CAM credit is equaly divided between all active functions
3976 * on the PORT!.
3977 */
3978 if ((func_num > 0)) {
3979 if (!CHIP_REV_IS_SLOW(bp))
3980 cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
3981 else
3982 cam_sz = BNX2X_CAM_SIZE_EMUL;
3983 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
3984 } else {
3985 /* this should never happen! Block MAC operations. */
3986 bnx2x_init_credit_pool(p, 0, 0);
3987 }
3988
3989 } else {
3990
3991 /*
3992 * CAM credit is equaly divided between all active functions
3993 * on the PATH.
3994 */
3995 if ((func_num > 0)) {
3996 if (!CHIP_REV_IS_SLOW(bp))
3997 cam_sz = (MAX_MAC_CREDIT_E2 / func_num);
3998 else
3999 cam_sz = BNX2X_CAM_SIZE_EMUL;
4000
4001 /*
4002 * No need for CAM entries handling for 57712 and
4003 * newer.
4004 */
4005 bnx2x_init_credit_pool(p, -1, cam_sz);
4006 } else {
4007 /* this should never happen! Block MAC operations. */
4008 bnx2x_init_credit_pool(p, 0, 0);
4009 }
4010
4011 }
4012}
4013
4014void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
4015 struct bnx2x_credit_pool_obj *p,
4016 u8 func_id,
4017 u8 func_num)
4018{
4019 if (CHIP_IS_E1x(bp)) {
4020 /*
4021 * There is no VLAN credit in HW on 57710 and 57711 only
4022 * MAC / MAC-VLAN can be set
4023 */
4024 bnx2x_init_credit_pool(p, 0, -1);
4025 } else {
4026 /*
4027 * CAM credit is equaly divided between all active functions
4028 * on the PATH.
4029 */
4030 if (func_num > 0) {
4031 int credit = MAX_VLAN_CREDIT_E2 / func_num;
4032 bnx2x_init_credit_pool(p, func_id * credit, credit);
4033 } else
4034 /* this should never happen! Block VLAN operations. */
4035 bnx2x_init_credit_pool(p, 0, 0);
4036 }
4037}
4038
4039/****************** RSS Configuration ******************/
4040/**
4041 * bnx2x_debug_print_ind_table - prints the indirection table configuration.
4042 *
4043 * @bp: driver hanlde
4044 * @p: pointer to rss configuration
4045 *
4046 * Prints it when NETIF_MSG_IFUP debug level is configured.
4047 */
4048static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
4049 struct bnx2x_config_rss_params *p)
4050{
4051 int i;
4052
4053 DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
4054 DP(BNX2X_MSG_SP, "0x0000: ");
4055 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
4056 DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
4057
4058 /* Print 4 bytes in a line */
4059 if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
4060 (((i + 1) & 0x3) == 0)) {
4061 DP_CONT(BNX2X_MSG_SP, "\n");
4062 DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
4063 }
4064 }
4065
4066 DP_CONT(BNX2X_MSG_SP, "\n");
4067}
4068
4069/**
4070 * bnx2x_setup_rss - configure RSS
4071 *
4072 * @bp: device handle
4073 * @p: rss configuration
4074 *
4075 * sends on UPDATE ramrod for that matter.
4076 */
4077static int bnx2x_setup_rss(struct bnx2x *bp,
4078 struct bnx2x_config_rss_params *p)
4079{
4080 struct bnx2x_rss_config_obj *o = p->rss_obj;
4081 struct bnx2x_raw_obj *r = &o->raw;
4082 struct eth_rss_update_ramrod_data *data =
4083 (struct eth_rss_update_ramrod_data *)(r->rdata);
4084 u8 rss_mode = 0;
4085 int rc;
4086
4087 memset(data, 0, sizeof(*data));
4088
4089 DP(BNX2X_MSG_SP, "Configuring RSS\n");
4090
4091 /* Set an echo field */
4092 data->echo = (r->cid & BNX2X_SWCID_MASK) |
4093 (r->state << BNX2X_SWCID_SHIFT);
4094
4095 /* RSS mode */
4096 if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
4097 rss_mode = ETH_RSS_MODE_DISABLED;
4098 else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
4099 rss_mode = ETH_RSS_MODE_REGULAR;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004100
4101 data->rss_mode = rss_mode;
4102
4103 DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
4104
4105 /* RSS capabilities */
4106 if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
4107 data->capabilities |=
4108 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
4109
4110 if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
4111 data->capabilities |=
4112 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
4113
Merav Sicron5d317c6a2012-06-19 07:48:24 +00004114 if (test_bit(BNX2X_RSS_IPV4_UDP, &p->rss_flags))
4115 data->capabilities |=
4116 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_UDP_CAPABILITY;
4117
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004118 if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
4119 data->capabilities |=
4120 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
4121
4122 if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
4123 data->capabilities |=
4124 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
4125
Merav Sicron5d317c6a2012-06-19 07:48:24 +00004126 if (test_bit(BNX2X_RSS_IPV6_UDP, &p->rss_flags))
4127 data->capabilities |=
4128 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_UDP_CAPABILITY;
4129
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004130 /* Hashing mask */
4131 data->rss_result_mask = p->rss_result_mask;
4132
4133 /* RSS engine ID */
4134 data->rss_engine_id = o->engine_id;
4135
4136 DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
4137
4138 /* Indirection table */
4139 memcpy(data->indirection_table, p->ind_table,
4140 T_ETH_INDIRECTION_TABLE_SIZE);
4141
4142 /* Remember the last configuration */
4143 memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
4144
4145 /* Print the indirection table */
4146 if (netif_msg_ifup(bp))
4147 bnx2x_debug_print_ind_table(bp, p);
4148
4149 /* RSS keys */
4150 if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
4151 memcpy(&data->rss_key[0], &p->rss_key[0],
4152 sizeof(data->rss_key));
4153 data->capabilities |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
4154 }
4155
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004156 /*
4157 * No need for an explicit memory barrier here as long we would
4158 * need to ensure the ordering of writing to the SPQ element
4159 * and updating of the SPQ producer which involves a memory
4160 * read and we will have to put a full memory barrier there
4161 * (inside bnx2x_sp_post()).
4162 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004163
4164 /* Send a ramrod */
4165 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
4166 U64_HI(r->rdata_mapping),
4167 U64_LO(r->rdata_mapping),
4168 ETH_CONNECTION_TYPE);
4169
4170 if (rc < 0)
4171 return rc;
4172
4173 return 1;
4174}
4175
4176void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
4177 u8 *ind_table)
4178{
4179 memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
4180}
4181
4182int bnx2x_config_rss(struct bnx2x *bp,
4183 struct bnx2x_config_rss_params *p)
4184{
4185 int rc;
4186 struct bnx2x_rss_config_obj *o = p->rss_obj;
4187 struct bnx2x_raw_obj *r = &o->raw;
4188
4189 /* Do nothing if only driver cleanup was requested */
4190 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags))
4191 return 0;
4192
4193 r->set_pending(r);
4194
4195 rc = o->config_rss(bp, p);
4196 if (rc < 0) {
4197 r->clear_pending(r);
4198 return rc;
4199 }
4200
4201 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
4202 rc = r->wait_comp(bp, r);
4203
4204 return rc;
4205}
4206
4207
4208void bnx2x_init_rss_config_obj(struct bnx2x *bp,
4209 struct bnx2x_rss_config_obj *rss_obj,
4210 u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
4211 void *rdata, dma_addr_t rdata_mapping,
4212 int state, unsigned long *pstate,
4213 bnx2x_obj_type type)
4214{
4215 bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
4216 rdata_mapping, state, pstate, type);
4217
4218 rss_obj->engine_id = engine_id;
4219 rss_obj->config_rss = bnx2x_setup_rss;
4220}
4221
4222/********************** Queue state object ***********************************/
4223
4224/**
4225 * bnx2x_queue_state_change - perform Queue state change transition
4226 *
4227 * @bp: device handle
4228 * @params: parameters to perform the transition
4229 *
4230 * returns 0 in case of successfully completed transition, negative error
4231 * code in case of failure, positive (EBUSY) value if there is a completion
4232 * to that is still pending (possible only if RAMROD_COMP_WAIT is
4233 * not set in params->ramrod_flags for asynchronous commands).
4234 *
4235 */
4236int bnx2x_queue_state_change(struct bnx2x *bp,
4237 struct bnx2x_queue_state_params *params)
4238{
4239 struct bnx2x_queue_sp_obj *o = params->q_obj;
4240 int rc, pending_bit;
4241 unsigned long *pending = &o->pending;
4242
4243 /* Check that the requested transition is legal */
Yuval Mintz04c46732013-01-23 03:21:46 +00004244 rc = o->check_transition(bp, o, params);
4245 if (rc) {
4246 BNX2X_ERR("check transition returned an error. rc %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004247 return -EINVAL;
Yuval Mintz04c46732013-01-23 03:21:46 +00004248 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004249
4250 /* Set "pending" bit */
Yuval Mintz04c46732013-01-23 03:21:46 +00004251 DP(BNX2X_MSG_SP, "pending bit was=%lx\n", o->pending);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004252 pending_bit = o->set_pending(o, params);
Yuval Mintz04c46732013-01-23 03:21:46 +00004253 DP(BNX2X_MSG_SP, "pending bit now=%lx\n", o->pending);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004254
4255 /* Don't send a command if only driver cleanup was requested */
4256 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags))
4257 o->complete_cmd(bp, o, pending_bit);
4258 else {
4259 /* Send a ramrod */
4260 rc = o->send_cmd(bp, params);
4261 if (rc) {
4262 o->next_state = BNX2X_Q_STATE_MAX;
4263 clear_bit(pending_bit, pending);
4264 smp_mb__after_clear_bit();
4265 return rc;
4266 }
4267
4268 if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
4269 rc = o->wait_comp(bp, o, pending_bit);
4270 if (rc)
4271 return rc;
4272
4273 return 0;
4274 }
4275 }
4276
4277 return !!test_bit(pending_bit, pending);
4278}
4279
4280
4281static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
4282 struct bnx2x_queue_state_params *params)
4283{
4284 enum bnx2x_queue_cmd cmd = params->cmd, bit;
4285
4286 /* ACTIVATE and DEACTIVATE commands are implemented on top of
4287 * UPDATE command.
4288 */
4289 if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
4290 (cmd == BNX2X_Q_CMD_DEACTIVATE))
4291 bit = BNX2X_Q_CMD_UPDATE;
4292 else
4293 bit = cmd;
4294
4295 set_bit(bit, &obj->pending);
4296 return bit;
4297}
4298
4299static int bnx2x_queue_wait_comp(struct bnx2x *bp,
4300 struct bnx2x_queue_sp_obj *o,
4301 enum bnx2x_queue_cmd cmd)
4302{
4303 return bnx2x_state_wait(bp, cmd, &o->pending);
4304}
4305
4306/**
4307 * bnx2x_queue_comp_cmd - complete the state change command.
4308 *
4309 * @bp: device handle
4310 * @o:
4311 * @cmd:
4312 *
4313 * Checks that the arrived completion is expected.
4314 */
4315static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
4316 struct bnx2x_queue_sp_obj *o,
4317 enum bnx2x_queue_cmd cmd)
4318{
4319 unsigned long cur_pending = o->pending;
4320
4321 if (!test_and_clear_bit(cmd, &cur_pending)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00004322 BNX2X_ERR("Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
4323 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX],
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004324 o->state, cur_pending, o->next_state);
4325 return -EINVAL;
4326 }
4327
Ariel Elior6383c0b2011-07-14 08:31:57 +00004328 if (o->next_tx_only >= o->max_cos)
4329 /* >= becuase tx only must always be smaller than cos since the
Masanari Iida02582e92012-08-22 19:11:26 +09004330 * primary connection supports COS 0
Ariel Elior6383c0b2011-07-14 08:31:57 +00004331 */
4332 BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
4333 o->next_tx_only, o->max_cos);
4334
Merav Sicron51c1a582012-03-18 10:33:38 +00004335 DP(BNX2X_MSG_SP,
4336 "Completing command %d for queue %d, setting state to %d\n",
4337 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004338
4339 if (o->next_tx_only) /* print num tx-only if any exist */
Joe Perches94f05b02011-08-14 12:16:20 +00004340 DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00004341 o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004342
4343 o->state = o->next_state;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004344 o->num_tx_only = o->next_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004345 o->next_state = BNX2X_Q_STATE_MAX;
4346
4347 /* It's important that o->state and o->next_state are
4348 * updated before o->pending.
4349 */
4350 wmb();
4351
4352 clear_bit(cmd, &o->pending);
4353 smp_mb__after_clear_bit();
4354
4355 return 0;
4356}
4357
4358static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
4359 struct bnx2x_queue_state_params *cmd_params,
4360 struct client_init_ramrod_data *data)
4361{
4362 struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004363
4364 /* Rx data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004365
4366 /* IPv6 TPA supported for E2 and above only */
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00004367 data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA_IPV6, &params->flags) *
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004368 CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
4369}
4370
Ariel Elior6383c0b2011-07-14 08:31:57 +00004371static void bnx2x_q_fill_init_general_data(struct bnx2x *bp,
4372 struct bnx2x_queue_sp_obj *o,
4373 struct bnx2x_general_setup_params *params,
4374 struct client_init_general_data *gen_data,
4375 unsigned long *flags)
4376{
4377 gen_data->client_id = o->cl_id;
4378
4379 if (test_bit(BNX2X_Q_FLG_STATS, flags)) {
4380 gen_data->statistics_counter_id =
4381 params->stat_id;
4382 gen_data->statistics_en_flg = 1;
4383 gen_data->statistics_zero_flg =
4384 test_bit(BNX2X_Q_FLG_ZERO_STATS, flags);
4385 } else
4386 gen_data->statistics_counter_id =
4387 DISABLE_STATISTIC_COUNTER_ID_VALUE;
4388
4389 gen_data->is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, flags);
4390 gen_data->activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE, flags);
4391 gen_data->sp_client_id = params->spcl_id;
4392 gen_data->mtu = cpu_to_le16(params->mtu);
4393 gen_data->func_id = o->func_id;
4394
4395
4396 gen_data->cos = params->cos;
4397
4398 gen_data->traffic_type =
4399 test_bit(BNX2X_Q_FLG_FCOE, flags) ?
4400 LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
4401
Joe Perches94f05b02011-08-14 12:16:20 +00004402 DP(BNX2X_MSG_SP, "flags: active %d, cos %d, stats en %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004403 gen_data->activate_flg, gen_data->cos, gen_data->statistics_en_flg);
4404}
4405
4406static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj *o,
4407 struct bnx2x_txq_setup_params *params,
4408 struct client_init_tx_data *tx_data,
4409 unsigned long *flags)
4410{
4411 tx_data->enforce_security_flg =
4412 test_bit(BNX2X_Q_FLG_TX_SEC, flags);
4413 tx_data->default_vlan =
4414 cpu_to_le16(params->default_vlan);
4415 tx_data->default_vlan_flg =
4416 test_bit(BNX2X_Q_FLG_DEF_VLAN, flags);
4417 tx_data->tx_switching_flg =
4418 test_bit(BNX2X_Q_FLG_TX_SWITCH, flags);
4419 tx_data->anti_spoofing_flg =
4420 test_bit(BNX2X_Q_FLG_ANTI_SPOOF, flags);
Barak Witkowskia3348722012-04-23 03:04:46 +00004421 tx_data->force_default_pri_flg =
4422 test_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, flags);
4423
Ariel Elior6383c0b2011-07-14 08:31:57 +00004424 tx_data->tx_status_block_id = params->fw_sb_id;
4425 tx_data->tx_sb_index_number = params->sb_cq_index;
4426 tx_data->tss_leading_client_id = params->tss_leading_cl_id;
4427
4428 tx_data->tx_bd_page_base.lo =
4429 cpu_to_le32(U64_LO(params->dscr_map));
4430 tx_data->tx_bd_page_base.hi =
4431 cpu_to_le32(U64_HI(params->dscr_map));
4432
4433 /* Don't configure any Tx switching mode during queue SETUP */
4434 tx_data->state = 0;
4435}
4436
4437static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj *o,
4438 struct rxq_pause_params *params,
4439 struct client_init_rx_data *rx_data)
4440{
4441 /* flow control data */
4442 rx_data->cqe_pause_thr_low = cpu_to_le16(params->rcq_th_lo);
4443 rx_data->cqe_pause_thr_high = cpu_to_le16(params->rcq_th_hi);
4444 rx_data->bd_pause_thr_low = cpu_to_le16(params->bd_th_lo);
4445 rx_data->bd_pause_thr_high = cpu_to_le16(params->bd_th_hi);
4446 rx_data->sge_pause_thr_low = cpu_to_le16(params->sge_th_lo);
4447 rx_data->sge_pause_thr_high = cpu_to_le16(params->sge_th_hi);
4448 rx_data->rx_cos_mask = cpu_to_le16(params->pri_map);
4449}
4450
4451static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj *o,
4452 struct bnx2x_rxq_setup_params *params,
4453 struct client_init_rx_data *rx_data,
4454 unsigned long *flags)
4455{
Ariel Elior6383c0b2011-07-14 08:31:57 +00004456 rx_data->tpa_en = test_bit(BNX2X_Q_FLG_TPA, flags) *
4457 CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00004458 rx_data->tpa_en |= test_bit(BNX2X_Q_FLG_TPA_GRO, flags) *
4459 CLIENT_INIT_RX_DATA_TPA_MODE;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004460 rx_data->vmqueue_mode_en_flg = 0;
4461
4462 rx_data->cache_line_alignment_log_size =
4463 params->cache_line_log;
4464 rx_data->enable_dynamic_hc =
4465 test_bit(BNX2X_Q_FLG_DHC, flags);
4466 rx_data->max_sges_for_packet = params->max_sges_pkt;
4467 rx_data->client_qzone_id = params->cl_qzone_id;
4468 rx_data->max_agg_size = cpu_to_le16(params->tpa_agg_sz);
4469
4470 /* Always start in DROP_ALL mode */
4471 rx_data->state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
4472 CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
4473
4474 /* We don't set drop flags */
4475 rx_data->drop_ip_cs_err_flg = 0;
4476 rx_data->drop_tcp_cs_err_flg = 0;
4477 rx_data->drop_ttl0_flg = 0;
4478 rx_data->drop_udp_cs_err_flg = 0;
4479 rx_data->inner_vlan_removal_enable_flg =
4480 test_bit(BNX2X_Q_FLG_VLAN, flags);
4481 rx_data->outer_vlan_removal_enable_flg =
4482 test_bit(BNX2X_Q_FLG_OV, flags);
4483 rx_data->status_block_id = params->fw_sb_id;
4484 rx_data->rx_sb_index_number = params->sb_cq_index;
4485 rx_data->max_tpa_queues = params->max_tpa_queues;
4486 rx_data->max_bytes_on_bd = cpu_to_le16(params->buf_sz);
4487 rx_data->sge_buff_size = cpu_to_le16(params->sge_buf_sz);
4488 rx_data->bd_page_base.lo =
4489 cpu_to_le32(U64_LO(params->dscr_map));
4490 rx_data->bd_page_base.hi =
4491 cpu_to_le32(U64_HI(params->dscr_map));
4492 rx_data->sge_page_base.lo =
4493 cpu_to_le32(U64_LO(params->sge_map));
4494 rx_data->sge_page_base.hi =
4495 cpu_to_le32(U64_HI(params->sge_map));
4496 rx_data->cqe_page_base.lo =
4497 cpu_to_le32(U64_LO(params->rcq_map));
4498 rx_data->cqe_page_base.hi =
4499 cpu_to_le32(U64_HI(params->rcq_map));
4500 rx_data->is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS, flags);
4501
4502 if (test_bit(BNX2X_Q_FLG_MCAST, flags)) {
Yuval Mintz259afa12012-03-12 08:53:10 +00004503 rx_data->approx_mcast_engine_id = params->mcast_engine_id;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004504 rx_data->is_approx_mcast = 1;
4505 }
4506
4507 rx_data->rss_engine_id = params->rss_engine_id;
4508
4509 /* silent vlan removal */
4510 rx_data->silent_vlan_removal_flg =
4511 test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, flags);
4512 rx_data->silent_vlan_value =
4513 cpu_to_le16(params->silent_removal_value);
4514 rx_data->silent_vlan_mask =
4515 cpu_to_le16(params->silent_removal_mask);
4516
4517}
4518
4519/* initialize the general, tx and rx parts of a queue object */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004520static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
4521 struct bnx2x_queue_state_params *cmd_params,
4522 struct client_init_ramrod_data *data)
4523{
Ariel Elior6383c0b2011-07-14 08:31:57 +00004524 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4525 &cmd_params->params.setup.gen_params,
4526 &data->general,
4527 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004528
Ariel Elior6383c0b2011-07-14 08:31:57 +00004529 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4530 &cmd_params->params.setup.txq_params,
4531 &data->tx,
4532 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004533
Ariel Elior6383c0b2011-07-14 08:31:57 +00004534 bnx2x_q_fill_init_rx_data(cmd_params->q_obj,
4535 &cmd_params->params.setup.rxq_params,
4536 &data->rx,
4537 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004538
Ariel Elior6383c0b2011-07-14 08:31:57 +00004539 bnx2x_q_fill_init_pause_data(cmd_params->q_obj,
4540 &cmd_params->params.setup.pause_params,
4541 &data->rx);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004542}
4543
Ariel Elior6383c0b2011-07-14 08:31:57 +00004544/* initialize the general and tx parts of a tx-only queue object */
4545static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
4546 struct bnx2x_queue_state_params *cmd_params,
4547 struct tx_queue_init_ramrod_data *data)
4548{
4549 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4550 &cmd_params->params.tx_only.gen_params,
4551 &data->general,
4552 &cmd_params->params.tx_only.flags);
4553
4554 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4555 &cmd_params->params.tx_only.txq_params,
4556 &data->tx,
4557 &cmd_params->params.tx_only.flags);
4558
Merav Sicron51c1a582012-03-18 10:33:38 +00004559 DP(BNX2X_MSG_SP, "cid %d, tx bd page lo %x hi %x",
4560 cmd_params->q_obj->cids[0],
4561 data->tx.tx_bd_page_base.lo,
4562 data->tx.tx_bd_page_base.hi);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004563}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004564
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004565/**
4566 * bnx2x_q_init - init HW/FW queue
4567 *
4568 * @bp: device handle
4569 * @params:
4570 *
4571 * HW/FW initial Queue configuration:
4572 * - HC: Rx and Tx
4573 * - CDU context validation
4574 *
4575 */
4576static inline int bnx2x_q_init(struct bnx2x *bp,
4577 struct bnx2x_queue_state_params *params)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004578{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004579 struct bnx2x_queue_sp_obj *o = params->q_obj;
4580 struct bnx2x_queue_init_params *init = &params->params.init;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004581 u16 hc_usec;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004582 u8 cos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004583
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004584 /* Tx HC configuration */
4585 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
4586 test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
4587 hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
4588
4589 bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
4590 init->tx.sb_cq_index,
4591 !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004592 hc_usec);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004593 }
4594
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004595 /* Rx HC configuration */
4596 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
4597 test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
4598 hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004599
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004600 bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
4601 init->rx.sb_cq_index,
4602 !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
4603 hc_usec);
4604 }
4605
4606 /* Set CDU context validation values */
Ariel Elior6383c0b2011-07-14 08:31:57 +00004607 for (cos = 0; cos < o->max_cos; cos++) {
Joe Perches94f05b02011-08-14 12:16:20 +00004608 DP(BNX2X_MSG_SP, "setting context validation. cid %d, cos %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004609 o->cids[cos], cos);
Joe Perches94f05b02011-08-14 12:16:20 +00004610 DP(BNX2X_MSG_SP, "context pointer %p\n", init->cxts[cos]);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004611 bnx2x_set_ctx_validation(bp, init->cxts[cos], o->cids[cos]);
4612 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004613
4614 /* As no ramrod is sent, complete the command immediately */
4615 o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
4616
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004617 mmiowb();
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004618 smp_mb();
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004619
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004620 return 0;
4621}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004622
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004623static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
4624 struct bnx2x_queue_state_params *params)
4625{
4626 struct bnx2x_queue_sp_obj *o = params->q_obj;
4627 struct client_init_ramrod_data *rdata =
4628 (struct client_init_ramrod_data *)o->rdata;
4629 dma_addr_t data_mapping = o->rdata_mapping;
4630 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004631
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004632 /* Clear the ramrod data */
4633 memset(rdata, 0, sizeof(*rdata));
4634
4635 /* Fill the ramrod data */
4636 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4637
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004638 /*
4639 * No need for an explicit memory barrier here as long we would
4640 * need to ensure the ordering of writing to the SPQ element
4641 * and updating of the SPQ producer which involves a memory
4642 * read and we will have to put a full memory barrier there
4643 * (inside bnx2x_sp_post()).
4644 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004645
Ariel Elior6383c0b2011-07-14 08:31:57 +00004646 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4647 U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004648 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4649}
4650
4651static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
4652 struct bnx2x_queue_state_params *params)
4653{
4654 struct bnx2x_queue_sp_obj *o = params->q_obj;
4655 struct client_init_ramrod_data *rdata =
4656 (struct client_init_ramrod_data *)o->rdata;
4657 dma_addr_t data_mapping = o->rdata_mapping;
4658 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4659
4660 /* Clear the ramrod data */
4661 memset(rdata, 0, sizeof(*rdata));
4662
4663 /* Fill the ramrod data */
4664 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4665 bnx2x_q_fill_setup_data_e2(bp, params, rdata);
4666
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004667 /*
4668 * No need for an explicit memory barrier here as long we would
4669 * need to ensure the ordering of writing to the SPQ element
4670 * and updating of the SPQ producer which involves a memory
4671 * read and we will have to put a full memory barrier there
4672 * (inside bnx2x_sp_post()).
4673 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004674
Ariel Elior6383c0b2011-07-14 08:31:57 +00004675 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4676 U64_HI(data_mapping),
4677 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4678}
4679
4680static inline int bnx2x_q_send_setup_tx_only(struct bnx2x *bp,
4681 struct bnx2x_queue_state_params *params)
4682{
4683 struct bnx2x_queue_sp_obj *o = params->q_obj;
4684 struct tx_queue_init_ramrod_data *rdata =
4685 (struct tx_queue_init_ramrod_data *)o->rdata;
4686 dma_addr_t data_mapping = o->rdata_mapping;
4687 int ramrod = RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP;
4688 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
4689 &params->params.tx_only;
4690 u8 cid_index = tx_only_params->cid_index;
4691
4692
4693 if (cid_index >= o->max_cos) {
4694 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4695 o->cl_id, cid_index);
4696 return -EINVAL;
4697 }
4698
Joe Perches94f05b02011-08-14 12:16:20 +00004699 DP(BNX2X_MSG_SP, "parameters received: cos: %d sp-id: %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004700 tx_only_params->gen_params.cos,
4701 tx_only_params->gen_params.spcl_id);
4702
4703 /* Clear the ramrod data */
4704 memset(rdata, 0, sizeof(*rdata));
4705
4706 /* Fill the ramrod data */
4707 bnx2x_q_fill_setup_tx_only(bp, params, rdata);
4708
Merav Sicron51c1a582012-03-18 10:33:38 +00004709 DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
4710 o->cids[cid_index], rdata->general.client_id,
Ariel Elior6383c0b2011-07-14 08:31:57 +00004711 rdata->general.sp_client_id, rdata->general.cos);
4712
4713 /*
4714 * No need for an explicit memory barrier here as long we would
4715 * need to ensure the ordering of writing to the SPQ element
4716 * and updating of the SPQ producer which involves a memory
4717 * read and we will have to put a full memory barrier there
4718 * (inside bnx2x_sp_post()).
4719 */
4720
4721 return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
4722 U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004723 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4724}
4725
4726static void bnx2x_q_fill_update_data(struct bnx2x *bp,
4727 struct bnx2x_queue_sp_obj *obj,
4728 struct bnx2x_queue_update_params *params,
4729 struct client_update_ramrod_data *data)
4730{
4731 /* Client ID of the client to update */
4732 data->client_id = obj->cl_id;
4733
4734 /* Function ID of the client to update */
4735 data->func_id = obj->func_id;
4736
4737 /* Default VLAN value */
4738 data->default_vlan = cpu_to_le16(params->def_vlan);
4739
4740 /* Inner VLAN stripping */
4741 data->inner_vlan_removal_enable_flg =
4742 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, &params->update_flags);
4743 data->inner_vlan_removal_change_flg =
4744 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
4745 &params->update_flags);
4746
4747 /* Outer VLAN sripping */
4748 data->outer_vlan_removal_enable_flg =
4749 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, &params->update_flags);
4750 data->outer_vlan_removal_change_flg =
4751 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
4752 &params->update_flags);
4753
4754 /* Drop packets that have source MAC that doesn't belong to this
4755 * Queue.
4756 */
4757 data->anti_spoofing_enable_flg =
4758 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, &params->update_flags);
4759 data->anti_spoofing_change_flg =
4760 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, &params->update_flags);
4761
4762 /* Activate/Deactivate */
4763 data->activate_flg =
4764 test_bit(BNX2X_Q_UPDATE_ACTIVATE, &params->update_flags);
4765 data->activate_change_flg =
4766 test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &params->update_flags);
4767
4768 /* Enable default VLAN */
4769 data->default_vlan_enable_flg =
4770 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, &params->update_flags);
4771 data->default_vlan_change_flg =
4772 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
4773 &params->update_flags);
4774
4775 /* silent vlan removal */
4776 data->silent_vlan_change_flg =
4777 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4778 &params->update_flags);
4779 data->silent_vlan_removal_flg =
4780 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, &params->update_flags);
4781 data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
4782 data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
4783}
4784
4785static inline int bnx2x_q_send_update(struct bnx2x *bp,
4786 struct bnx2x_queue_state_params *params)
4787{
4788 struct bnx2x_queue_sp_obj *o = params->q_obj;
4789 struct client_update_ramrod_data *rdata =
4790 (struct client_update_ramrod_data *)o->rdata;
4791 dma_addr_t data_mapping = o->rdata_mapping;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004792 struct bnx2x_queue_update_params *update_params =
4793 &params->params.update;
4794 u8 cid_index = update_params->cid_index;
4795
4796 if (cid_index >= o->max_cos) {
4797 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4798 o->cl_id, cid_index);
4799 return -EINVAL;
4800 }
4801
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004802
4803 /* Clear the ramrod data */
4804 memset(rdata, 0, sizeof(*rdata));
4805
4806 /* Fill the ramrod data */
Ariel Elior6383c0b2011-07-14 08:31:57 +00004807 bnx2x_q_fill_update_data(bp, o, update_params, rdata);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004808
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004809 /*
4810 * No need for an explicit memory barrier here as long we would
4811 * need to ensure the ordering of writing to the SPQ element
4812 * and updating of the SPQ producer which involves a memory
4813 * read and we will have to put a full memory barrier there
4814 * (inside bnx2x_sp_post()).
4815 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004816
Ariel Elior6383c0b2011-07-14 08:31:57 +00004817 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
4818 o->cids[cid_index], U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004819 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4820}
4821
4822/**
4823 * bnx2x_q_send_deactivate - send DEACTIVATE command
4824 *
4825 * @bp: device handle
4826 * @params:
4827 *
4828 * implemented using the UPDATE command.
4829 */
4830static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
4831 struct bnx2x_queue_state_params *params)
4832{
4833 struct bnx2x_queue_update_params *update = &params->params.update;
4834
4835 memset(update, 0, sizeof(*update));
4836
4837 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
4838
4839 return bnx2x_q_send_update(bp, params);
4840}
4841
4842/**
4843 * bnx2x_q_send_activate - send ACTIVATE command
4844 *
4845 * @bp: device handle
4846 * @params:
4847 *
4848 * implemented using the UPDATE command.
4849 */
4850static inline int bnx2x_q_send_activate(struct bnx2x *bp,
4851 struct bnx2x_queue_state_params *params)
4852{
4853 struct bnx2x_queue_update_params *update = &params->params.update;
4854
4855 memset(update, 0, sizeof(*update));
4856
4857 __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
4858 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
4859
4860 return bnx2x_q_send_update(bp, params);
4861}
4862
4863static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
4864 struct bnx2x_queue_state_params *params)
4865{
4866 /* TODO: Not implemented yet. */
4867 return -1;
4868}
4869
4870static inline int bnx2x_q_send_halt(struct bnx2x *bp,
4871 struct bnx2x_queue_state_params *params)
4872{
4873 struct bnx2x_queue_sp_obj *o = params->q_obj;
4874
Ariel Elior6383c0b2011-07-14 08:31:57 +00004875 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT,
4876 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, o->cl_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004877 ETH_CONNECTION_TYPE);
4878}
4879
4880static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
4881 struct bnx2x_queue_state_params *params)
4882{
4883 struct bnx2x_queue_sp_obj *o = params->q_obj;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004884 u8 cid_idx = params->params.cfc_del.cid_index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004885
Ariel Elior6383c0b2011-07-14 08:31:57 +00004886 if (cid_idx >= o->max_cos) {
4887 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4888 o->cl_id, cid_idx);
4889 return -EINVAL;
4890 }
4891
4892 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL,
4893 o->cids[cid_idx], 0, 0, NONE_CONNECTION_TYPE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004894}
4895
4896static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
4897 struct bnx2x_queue_state_params *params)
4898{
4899 struct bnx2x_queue_sp_obj *o = params->q_obj;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004900 u8 cid_index = params->params.terminate.cid_index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004901
Ariel Elior6383c0b2011-07-14 08:31:57 +00004902 if (cid_index >= o->max_cos) {
4903 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4904 o->cl_id, cid_index);
4905 return -EINVAL;
4906 }
4907
4908 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE,
4909 o->cids[cid_index], 0, 0, ETH_CONNECTION_TYPE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004910}
4911
4912static inline int bnx2x_q_send_empty(struct bnx2x *bp,
4913 struct bnx2x_queue_state_params *params)
4914{
4915 struct bnx2x_queue_sp_obj *o = params->q_obj;
4916
Ariel Elior6383c0b2011-07-14 08:31:57 +00004917 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY,
4918 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004919 ETH_CONNECTION_TYPE);
4920}
4921
4922static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
4923 struct bnx2x_queue_state_params *params)
4924{
4925 switch (params->cmd) {
4926 case BNX2X_Q_CMD_INIT:
4927 return bnx2x_q_init(bp, params);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004928 case BNX2X_Q_CMD_SETUP_TX_ONLY:
4929 return bnx2x_q_send_setup_tx_only(bp, params);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004930 case BNX2X_Q_CMD_DEACTIVATE:
4931 return bnx2x_q_send_deactivate(bp, params);
4932 case BNX2X_Q_CMD_ACTIVATE:
4933 return bnx2x_q_send_activate(bp, params);
4934 case BNX2X_Q_CMD_UPDATE:
4935 return bnx2x_q_send_update(bp, params);
4936 case BNX2X_Q_CMD_UPDATE_TPA:
4937 return bnx2x_q_send_update_tpa(bp, params);
4938 case BNX2X_Q_CMD_HALT:
4939 return bnx2x_q_send_halt(bp, params);
4940 case BNX2X_Q_CMD_CFC_DEL:
4941 return bnx2x_q_send_cfc_del(bp, params);
4942 case BNX2X_Q_CMD_TERMINATE:
4943 return bnx2x_q_send_terminate(bp, params);
4944 case BNX2X_Q_CMD_EMPTY:
4945 return bnx2x_q_send_empty(bp, params);
4946 default:
4947 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4948 return -EINVAL;
4949 }
4950}
4951
4952static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
4953 struct bnx2x_queue_state_params *params)
4954{
4955 switch (params->cmd) {
4956 case BNX2X_Q_CMD_SETUP:
4957 return bnx2x_q_send_setup_e1x(bp, params);
4958 case BNX2X_Q_CMD_INIT:
Ariel Elior6383c0b2011-07-14 08:31:57 +00004959 case BNX2X_Q_CMD_SETUP_TX_ONLY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004960 case BNX2X_Q_CMD_DEACTIVATE:
4961 case BNX2X_Q_CMD_ACTIVATE:
4962 case BNX2X_Q_CMD_UPDATE:
4963 case BNX2X_Q_CMD_UPDATE_TPA:
4964 case BNX2X_Q_CMD_HALT:
4965 case BNX2X_Q_CMD_CFC_DEL:
4966 case BNX2X_Q_CMD_TERMINATE:
4967 case BNX2X_Q_CMD_EMPTY:
4968 return bnx2x_queue_send_cmd_cmn(bp, params);
4969 default:
4970 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4971 return -EINVAL;
4972 }
4973}
4974
4975static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
4976 struct bnx2x_queue_state_params *params)
4977{
4978 switch (params->cmd) {
4979 case BNX2X_Q_CMD_SETUP:
4980 return bnx2x_q_send_setup_e2(bp, params);
4981 case BNX2X_Q_CMD_INIT:
Ariel Elior6383c0b2011-07-14 08:31:57 +00004982 case BNX2X_Q_CMD_SETUP_TX_ONLY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004983 case BNX2X_Q_CMD_DEACTIVATE:
4984 case BNX2X_Q_CMD_ACTIVATE:
4985 case BNX2X_Q_CMD_UPDATE:
4986 case BNX2X_Q_CMD_UPDATE_TPA:
4987 case BNX2X_Q_CMD_HALT:
4988 case BNX2X_Q_CMD_CFC_DEL:
4989 case BNX2X_Q_CMD_TERMINATE:
4990 case BNX2X_Q_CMD_EMPTY:
4991 return bnx2x_queue_send_cmd_cmn(bp, params);
4992 default:
4993 BNX2X_ERR("Unknown command: %d\n", params->cmd);
4994 return -EINVAL;
4995 }
4996}
4997
4998/**
4999 * bnx2x_queue_chk_transition - check state machine of a regular Queue
5000 *
5001 * @bp: device handle
5002 * @o:
5003 * @params:
5004 *
5005 * (not Forwarding)
5006 * It both checks if the requested command is legal in a current
5007 * state and, if it's legal, sets a `next_state' in the object
5008 * that will be used in the completion flow to set the `state'
5009 * of the object.
5010 *
5011 * returns 0 if a requested command is a legal transition,
5012 * -EINVAL otherwise.
5013 */
5014static int bnx2x_queue_chk_transition(struct bnx2x *bp,
5015 struct bnx2x_queue_sp_obj *o,
5016 struct bnx2x_queue_state_params *params)
5017{
5018 enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
5019 enum bnx2x_queue_cmd cmd = params->cmd;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005020 struct bnx2x_queue_update_params *update_params =
5021 &params->params.update;
5022 u8 next_tx_only = o->num_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005023
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005024 /*
5025 * Forget all pending for completion commands if a driver only state
5026 * transition has been requested.
5027 */
5028 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5029 o->pending = 0;
5030 o->next_state = BNX2X_Q_STATE_MAX;
5031 }
5032
5033 /*
5034 * Don't allow a next state transition if we are in the middle of
5035 * the previous one.
5036 */
Yuval Mintz04c46732013-01-23 03:21:46 +00005037 if (o->pending) {
5038 BNX2X_ERR("Blocking transition since pending was %lx\n",
5039 o->pending);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005040 return -EBUSY;
Yuval Mintz04c46732013-01-23 03:21:46 +00005041 }
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005042
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005043 switch (state) {
5044 case BNX2X_Q_STATE_RESET:
5045 if (cmd == BNX2X_Q_CMD_INIT)
5046 next_state = BNX2X_Q_STATE_INITIALIZED;
5047
5048 break;
5049 case BNX2X_Q_STATE_INITIALIZED:
5050 if (cmd == BNX2X_Q_CMD_SETUP) {
5051 if (test_bit(BNX2X_Q_FLG_ACTIVE,
5052 &params->params.setup.flags))
5053 next_state = BNX2X_Q_STATE_ACTIVE;
5054 else
5055 next_state = BNX2X_Q_STATE_INACTIVE;
5056 }
5057
5058 break;
5059 case BNX2X_Q_STATE_ACTIVE:
5060 if (cmd == BNX2X_Q_CMD_DEACTIVATE)
5061 next_state = BNX2X_Q_STATE_INACTIVE;
5062
5063 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5064 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5065 next_state = BNX2X_Q_STATE_ACTIVE;
5066
Ariel Elior6383c0b2011-07-14 08:31:57 +00005067 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5068 next_state = BNX2X_Q_STATE_MULTI_COS;
5069 next_tx_only = 1;
5070 }
5071
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005072 else if (cmd == BNX2X_Q_CMD_HALT)
5073 next_state = BNX2X_Q_STATE_STOPPED;
5074
5075 else if (cmd == BNX2X_Q_CMD_UPDATE) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005076 /* If "active" state change is requested, update the
5077 * state accordingly.
5078 */
5079 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5080 &update_params->update_flags) &&
5081 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5082 &update_params->update_flags))
5083 next_state = BNX2X_Q_STATE_INACTIVE;
5084 else
5085 next_state = BNX2X_Q_STATE_ACTIVE;
5086 }
5087
5088 break;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005089 case BNX2X_Q_STATE_MULTI_COS:
5090 if (cmd == BNX2X_Q_CMD_TERMINATE)
5091 next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
5092
5093 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5094 next_state = BNX2X_Q_STATE_MULTI_COS;
5095 next_tx_only = o->num_tx_only + 1;
5096 }
5097
5098 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5099 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5100 next_state = BNX2X_Q_STATE_MULTI_COS;
5101
5102 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5103 /* If "active" state change is requested, update the
5104 * state accordingly.
5105 */
5106 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5107 &update_params->update_flags) &&
5108 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5109 &update_params->update_flags))
5110 next_state = BNX2X_Q_STATE_INACTIVE;
5111 else
5112 next_state = BNX2X_Q_STATE_MULTI_COS;
5113 }
5114
5115 break;
5116 case BNX2X_Q_STATE_MCOS_TERMINATED:
5117 if (cmd == BNX2X_Q_CMD_CFC_DEL) {
5118 next_tx_only = o->num_tx_only - 1;
5119 if (next_tx_only == 0)
5120 next_state = BNX2X_Q_STATE_ACTIVE;
5121 else
5122 next_state = BNX2X_Q_STATE_MULTI_COS;
5123 }
5124
5125 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005126 case BNX2X_Q_STATE_INACTIVE:
5127 if (cmd == BNX2X_Q_CMD_ACTIVATE)
5128 next_state = BNX2X_Q_STATE_ACTIVE;
5129
5130 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5131 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5132 next_state = BNX2X_Q_STATE_INACTIVE;
5133
5134 else if (cmd == BNX2X_Q_CMD_HALT)
5135 next_state = BNX2X_Q_STATE_STOPPED;
5136
5137 else if (cmd == BNX2X_Q_CMD_UPDATE) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005138 /* If "active" state change is requested, update the
5139 * state accordingly.
5140 */
5141 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5142 &update_params->update_flags) &&
5143 test_bit(BNX2X_Q_UPDATE_ACTIVATE,
Ariel Elior6383c0b2011-07-14 08:31:57 +00005144 &update_params->update_flags)){
5145 if (o->num_tx_only == 0)
5146 next_state = BNX2X_Q_STATE_ACTIVE;
5147 else /* tx only queues exist for this queue */
5148 next_state = BNX2X_Q_STATE_MULTI_COS;
5149 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005150 next_state = BNX2X_Q_STATE_INACTIVE;
5151 }
5152
5153 break;
5154 case BNX2X_Q_STATE_STOPPED:
5155 if (cmd == BNX2X_Q_CMD_TERMINATE)
5156 next_state = BNX2X_Q_STATE_TERMINATED;
5157
5158 break;
5159 case BNX2X_Q_STATE_TERMINATED:
5160 if (cmd == BNX2X_Q_CMD_CFC_DEL)
5161 next_state = BNX2X_Q_STATE_RESET;
5162
5163 break;
5164 default:
5165 BNX2X_ERR("Illegal state: %d\n", state);
5166 }
5167
5168 /* Transition is assured */
5169 if (next_state != BNX2X_Q_STATE_MAX) {
5170 DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
5171 state, cmd, next_state);
5172 o->next_state = next_state;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005173 o->next_tx_only = next_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005174 return 0;
5175 }
5176
5177 DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
5178
5179 return -EINVAL;
5180}
5181
5182void bnx2x_init_queue_obj(struct bnx2x *bp,
5183 struct bnx2x_queue_sp_obj *obj,
Ariel Elior6383c0b2011-07-14 08:31:57 +00005184 u8 cl_id, u32 *cids, u8 cid_cnt, u8 func_id,
5185 void *rdata,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005186 dma_addr_t rdata_mapping, unsigned long type)
5187{
5188 memset(obj, 0, sizeof(*obj));
5189
Ariel Elior6383c0b2011-07-14 08:31:57 +00005190 /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
5191 BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
5192
5193 memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
5194 obj->max_cos = cid_cnt;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005195 obj->cl_id = cl_id;
5196 obj->func_id = func_id;
5197 obj->rdata = rdata;
5198 obj->rdata_mapping = rdata_mapping;
5199 obj->type = type;
5200 obj->next_state = BNX2X_Q_STATE_MAX;
5201
5202 if (CHIP_IS_E1x(bp))
5203 obj->send_cmd = bnx2x_queue_send_cmd_e1x;
5204 else
5205 obj->send_cmd = bnx2x_queue_send_cmd_e2;
5206
5207 obj->check_transition = bnx2x_queue_chk_transition;
5208
5209 obj->complete_cmd = bnx2x_queue_comp_cmd;
5210 obj->wait_comp = bnx2x_queue_wait_comp;
5211 obj->set_pending = bnx2x_queue_set_pending;
5212}
5213
Ariel Elior67c431a2013-01-01 05:22:36 +00005214/* return a queue object's logical state*/
5215int bnx2x_get_q_logical_state(struct bnx2x *bp,
5216 struct bnx2x_queue_sp_obj *obj)
5217{
5218 switch (obj->state) {
5219 case BNX2X_Q_STATE_ACTIVE:
5220 case BNX2X_Q_STATE_MULTI_COS:
5221 return BNX2X_Q_LOGICAL_STATE_ACTIVE;
5222 case BNX2X_Q_STATE_RESET:
5223 case BNX2X_Q_STATE_INITIALIZED:
5224 case BNX2X_Q_STATE_MCOS_TERMINATED:
5225 case BNX2X_Q_STATE_INACTIVE:
5226 case BNX2X_Q_STATE_STOPPED:
5227 case BNX2X_Q_STATE_TERMINATED:
5228 case BNX2X_Q_STATE_FLRED:
5229 return BNX2X_Q_LOGICAL_STATE_STOPPED;
5230 default:
5231 return -EINVAL;
5232 }
5233}
5234
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005235/********************** Function state object *********************************/
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005236enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
5237 struct bnx2x_func_sp_obj *o)
5238{
5239 /* in the middle of transaction - return INVALID state */
5240 if (o->pending)
5241 return BNX2X_F_STATE_MAX;
5242
5243 /*
5244 * unsure the order of reading of o->pending and o->state
5245 * o->pending should be read first
5246 */
5247 rmb();
5248
5249 return o->state;
5250}
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005251
5252static int bnx2x_func_wait_comp(struct bnx2x *bp,
5253 struct bnx2x_func_sp_obj *o,
5254 enum bnx2x_func_cmd cmd)
5255{
5256 return bnx2x_state_wait(bp, cmd, &o->pending);
5257}
5258
5259/**
5260 * bnx2x_func_state_change_comp - complete the state machine transition
5261 *
5262 * @bp: device handle
5263 * @o:
5264 * @cmd:
5265 *
5266 * Called on state change transition. Completes the state
5267 * machine transition only - no HW interaction.
5268 */
5269static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
5270 struct bnx2x_func_sp_obj *o,
5271 enum bnx2x_func_cmd cmd)
5272{
5273 unsigned long cur_pending = o->pending;
5274
5275 if (!test_and_clear_bit(cmd, &cur_pending)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00005276 BNX2X_ERR("Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
5277 cmd, BP_FUNC(bp), o->state,
5278 cur_pending, o->next_state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005279 return -EINVAL;
5280 }
5281
Joe Perches94f05b02011-08-14 12:16:20 +00005282 DP(BNX2X_MSG_SP,
5283 "Completing command %d for func %d, setting state to %d\n",
5284 cmd, BP_FUNC(bp), o->next_state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005285
5286 o->state = o->next_state;
5287 o->next_state = BNX2X_F_STATE_MAX;
5288
5289 /* It's important that o->state and o->next_state are
5290 * updated before o->pending.
5291 */
5292 wmb();
5293
5294 clear_bit(cmd, &o->pending);
5295 smp_mb__after_clear_bit();
5296
5297 return 0;
5298}
5299
5300/**
5301 * bnx2x_func_comp_cmd - complete the state change command
5302 *
5303 * @bp: device handle
5304 * @o:
5305 * @cmd:
5306 *
5307 * Checks that the arrived completion is expected.
5308 */
5309static int bnx2x_func_comp_cmd(struct bnx2x *bp,
5310 struct bnx2x_func_sp_obj *o,
5311 enum bnx2x_func_cmd cmd)
5312{
5313 /* Complete the state machine part first, check if it's a
5314 * legal completion.
5315 */
5316 int rc = bnx2x_func_state_change_comp(bp, o, cmd);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005317 return rc;
5318}
5319
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005320/**
5321 * bnx2x_func_chk_transition - perform function state machine transition
5322 *
5323 * @bp: device handle
5324 * @o:
5325 * @params:
5326 *
5327 * It both checks if the requested command is legal in a current
5328 * state and, if it's legal, sets a `next_state' in the object
5329 * that will be used in the completion flow to set the `state'
5330 * of the object.
5331 *
5332 * returns 0 if a requested command is a legal transition,
5333 * -EINVAL otherwise.
5334 */
5335static int bnx2x_func_chk_transition(struct bnx2x *bp,
5336 struct bnx2x_func_sp_obj *o,
5337 struct bnx2x_func_state_params *params)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005338{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005339 enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
5340 enum bnx2x_func_cmd cmd = params->cmd;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005341
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005342 /*
5343 * Forget all pending for completion commands if a driver only state
5344 * transition has been requested.
5345 */
5346 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5347 o->pending = 0;
5348 o->next_state = BNX2X_F_STATE_MAX;
5349 }
5350
5351 /*
5352 * Don't allow a next state transition if we are in the middle of
5353 * the previous one.
5354 */
5355 if (o->pending)
5356 return -EBUSY;
5357
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005358 switch (state) {
5359 case BNX2X_F_STATE_RESET:
5360 if (cmd == BNX2X_F_CMD_HW_INIT)
5361 next_state = BNX2X_F_STATE_INITIALIZED;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005362
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005363 break;
5364 case BNX2X_F_STATE_INITIALIZED:
5365 if (cmd == BNX2X_F_CMD_START)
5366 next_state = BNX2X_F_STATE_STARTED;
5367
5368 else if (cmd == BNX2X_F_CMD_HW_RESET)
5369 next_state = BNX2X_F_STATE_RESET;
5370
5371 break;
5372 case BNX2X_F_STATE_STARTED:
5373 if (cmd == BNX2X_F_CMD_STOP)
5374 next_state = BNX2X_F_STATE_INITIALIZED;
Barak Witkowskia3348722012-04-23 03:04:46 +00005375 /* afex ramrods can be sent only in started mode, and only
5376 * if not pending for function_stop ramrod completion
5377 * for these events - next state remained STARTED.
5378 */
5379 else if ((cmd == BNX2X_F_CMD_AFEX_UPDATE) &&
5380 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5381 next_state = BNX2X_F_STATE_STARTED;
5382
5383 else if ((cmd == BNX2X_F_CMD_AFEX_VIFLISTS) &&
5384 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5385 next_state = BNX2X_F_STATE_STARTED;
Merav Sicron55c11942012-11-07 00:45:48 +00005386
5387 /* Switch_update ramrod can be sent in either started or
5388 * tx_stopped state, and it doesn't change the state.
5389 */
5390 else if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5391 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5392 next_state = BNX2X_F_STATE_STARTED;
5393
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005394 else if (cmd == BNX2X_F_CMD_TX_STOP)
5395 next_state = BNX2X_F_STATE_TX_STOPPED;
5396
5397 break;
5398 case BNX2X_F_STATE_TX_STOPPED:
Merav Sicron55c11942012-11-07 00:45:48 +00005399 if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5400 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5401 next_state = BNX2X_F_STATE_TX_STOPPED;
5402
5403 else if (cmd == BNX2X_F_CMD_TX_START)
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005404 next_state = BNX2X_F_STATE_STARTED;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005405
5406 break;
5407 default:
5408 BNX2X_ERR("Unknown state: %d\n", state);
5409 }
5410
5411 /* Transition is assured */
5412 if (next_state != BNX2X_F_STATE_MAX) {
5413 DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
5414 state, cmd, next_state);
5415 o->next_state = next_state;
5416 return 0;
5417 }
5418
5419 DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
5420 state, cmd);
5421
5422 return -EINVAL;
5423}
5424
5425/**
5426 * bnx2x_func_init_func - performs HW init at function stage
5427 *
5428 * @bp: device handle
5429 * @drv:
5430 *
5431 * Init HW when the current phase is
5432 * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
5433 * HW blocks.
5434 */
5435static inline int bnx2x_func_init_func(struct bnx2x *bp,
5436 const struct bnx2x_func_sp_drv_ops *drv)
5437{
5438 return drv->init_hw_func(bp);
5439}
5440
5441/**
5442 * bnx2x_func_init_port - performs HW init at port stage
5443 *
5444 * @bp: device handle
5445 * @drv:
5446 *
5447 * Init HW when the current phase is
5448 * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
5449 * FUNCTION-only HW blocks.
5450 *
5451 */
5452static inline int bnx2x_func_init_port(struct bnx2x *bp,
5453 const struct bnx2x_func_sp_drv_ops *drv)
5454{
5455 int rc = drv->init_hw_port(bp);
5456 if (rc)
5457 return rc;
5458
5459 return bnx2x_func_init_func(bp, drv);
5460}
5461
5462/**
5463 * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
5464 *
5465 * @bp: device handle
5466 * @drv:
5467 *
5468 * Init HW when the current phase is
5469 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
5470 * PORT-only and FUNCTION-only HW blocks.
5471 */
5472static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
5473 const struct bnx2x_func_sp_drv_ops *drv)
5474{
5475 int rc = drv->init_hw_cmn_chip(bp);
5476 if (rc)
5477 return rc;
5478
5479 return bnx2x_func_init_port(bp, drv);
5480}
5481
5482/**
5483 * bnx2x_func_init_cmn - performs HW init at common stage
5484 *
5485 * @bp: device handle
5486 * @drv:
5487 *
5488 * Init HW when the current phase is
5489 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
5490 * PORT-only and FUNCTION-only HW blocks.
5491 */
5492static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
5493 const struct bnx2x_func_sp_drv_ops *drv)
5494{
5495 int rc = drv->init_hw_cmn(bp);
5496 if (rc)
5497 return rc;
5498
5499 return bnx2x_func_init_port(bp, drv);
5500}
5501
5502static int bnx2x_func_hw_init(struct bnx2x *bp,
5503 struct bnx2x_func_state_params *params)
5504{
5505 u32 load_code = params->params.hw_init.load_phase;
5506 struct bnx2x_func_sp_obj *o = params->f_obj;
5507 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5508 int rc = 0;
5509
5510 DP(BNX2X_MSG_SP, "function %d load_code %x\n",
5511 BP_ABS_FUNC(bp), load_code);
5512
5513 /* Prepare buffers for unzipping the FW */
5514 rc = drv->gunzip_init(bp);
5515 if (rc)
5516 return rc;
5517
5518 /* Prepare FW */
5519 rc = drv->init_fw(bp);
5520 if (rc) {
5521 BNX2X_ERR("Error loading firmware\n");
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005522 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005523 }
5524
5525 /* Handle the beginning of COMMON_XXX pases separatelly... */
5526 switch (load_code) {
5527 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5528 rc = bnx2x_func_init_cmn_chip(bp, drv);
5529 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005530 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005531
5532 break;
5533 case FW_MSG_CODE_DRV_LOAD_COMMON:
5534 rc = bnx2x_func_init_cmn(bp, drv);
5535 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005536 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005537
5538 break;
5539 case FW_MSG_CODE_DRV_LOAD_PORT:
5540 rc = bnx2x_func_init_port(bp, drv);
5541 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005542 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005543
5544 break;
5545 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5546 rc = bnx2x_func_init_func(bp, drv);
5547 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005548 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005549
5550 break;
5551 default:
5552 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5553 rc = -EINVAL;
5554 }
5555
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005556init_err:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005557 drv->gunzip_end(bp);
5558
5559 /* In case of success, complete the comand immediatelly: no ramrods
5560 * have been sent.
5561 */
5562 if (!rc)
5563 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
5564
5565 return rc;
5566}
5567
5568/**
5569 * bnx2x_func_reset_func - reset HW at function stage
5570 *
5571 * @bp: device handle
5572 * @drv:
5573 *
5574 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
5575 * FUNCTION-only HW blocks.
5576 */
5577static inline void bnx2x_func_reset_func(struct bnx2x *bp,
5578 const struct bnx2x_func_sp_drv_ops *drv)
5579{
5580 drv->reset_hw_func(bp);
5581}
5582
5583/**
5584 * bnx2x_func_reset_port - reser HW at port stage
5585 *
5586 * @bp: device handle
5587 * @drv:
5588 *
5589 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
5590 * FUNCTION-only and PORT-only HW blocks.
5591 *
5592 * !!!IMPORTANT!!!
5593 *
5594 * It's important to call reset_port before reset_func() as the last thing
5595 * reset_func does is pf_disable() thus disabling PGLUE_B, which
5596 * makes impossible any DMAE transactions.
5597 */
5598static inline void bnx2x_func_reset_port(struct bnx2x *bp,
5599 const struct bnx2x_func_sp_drv_ops *drv)
5600{
5601 drv->reset_hw_port(bp);
5602 bnx2x_func_reset_func(bp, drv);
5603}
5604
5605/**
5606 * bnx2x_func_reset_cmn - reser HW at common stage
5607 *
5608 * @bp: device handle
5609 * @drv:
5610 *
5611 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
5612 * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
5613 * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
5614 */
5615static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
5616 const struct bnx2x_func_sp_drv_ops *drv)
5617{
5618 bnx2x_func_reset_port(bp, drv);
5619 drv->reset_hw_cmn(bp);
5620}
5621
5622
5623static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
5624 struct bnx2x_func_state_params *params)
5625{
5626 u32 reset_phase = params->params.hw_reset.reset_phase;
5627 struct bnx2x_func_sp_obj *o = params->f_obj;
5628 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5629
5630 DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
5631 reset_phase);
5632
5633 switch (reset_phase) {
5634 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
5635 bnx2x_func_reset_cmn(bp, drv);
5636 break;
5637 case FW_MSG_CODE_DRV_UNLOAD_PORT:
5638 bnx2x_func_reset_port(bp, drv);
5639 break;
5640 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
5641 bnx2x_func_reset_func(bp, drv);
5642 break;
5643 default:
5644 BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
5645 reset_phase);
5646 break;
5647 }
5648
5649 /* Complete the comand immediatelly: no ramrods have been sent. */
5650 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
5651
5652 return 0;
5653}
5654
5655static inline int bnx2x_func_send_start(struct bnx2x *bp,
5656 struct bnx2x_func_state_params *params)
5657{
5658 struct bnx2x_func_sp_obj *o = params->f_obj;
5659 struct function_start_data *rdata =
5660 (struct function_start_data *)o->rdata;
5661 dma_addr_t data_mapping = o->rdata_mapping;
5662 struct bnx2x_func_start_params *start_params = &params->params.start;
5663
5664 memset(rdata, 0, sizeof(*rdata));
5665
5666 /* Fill the ramrod data with provided parameters */
Yuval Mintz2de67432013-01-23 03:21:43 +00005667 rdata->function_mode = (u8)start_params->mf_mode;
5668 rdata->sd_vlan_tag = cpu_to_le16(start_params->sd_vlan_tag);
5669 rdata->path_id = BP_PATH(bp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005670 rdata->network_cos_mode = start_params->network_cos_mode;
5671
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00005672 /*
5673 * No need for an explicit memory barrier here as long we would
5674 * need to ensure the ordering of writing to the SPQ element
5675 * and updating of the SPQ producer which involves a memory
5676 * read and we will have to put a full memory barrier there
5677 * (inside bnx2x_sp_post()).
5678 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005679
5680 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
5681 U64_HI(data_mapping),
5682 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5683}
5684
Merav Sicron55c11942012-11-07 00:45:48 +00005685static inline int bnx2x_func_send_switch_update(struct bnx2x *bp,
5686 struct bnx2x_func_state_params *params)
5687{
5688 struct bnx2x_func_sp_obj *o = params->f_obj;
5689 struct function_update_data *rdata =
5690 (struct function_update_data *)o->rdata;
5691 dma_addr_t data_mapping = o->rdata_mapping;
5692 struct bnx2x_func_switch_update_params *switch_update_params =
5693 &params->params.switch_update;
5694
5695 memset(rdata, 0, sizeof(*rdata));
5696
5697 /* Fill the ramrod data with provided parameters */
5698 rdata->tx_switch_suspend_change_flg = 1;
5699 rdata->tx_switch_suspend = switch_update_params->suspend;
5700 rdata->echo = SWITCH_UPDATE;
5701
5702 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5703 U64_HI(data_mapping),
5704 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5705}
5706
Barak Witkowskia3348722012-04-23 03:04:46 +00005707static inline int bnx2x_func_send_afex_update(struct bnx2x *bp,
5708 struct bnx2x_func_state_params *params)
5709{
5710 struct bnx2x_func_sp_obj *o = params->f_obj;
5711 struct function_update_data *rdata =
5712 (struct function_update_data *)o->afex_rdata;
5713 dma_addr_t data_mapping = o->afex_rdata_mapping;
5714 struct bnx2x_func_afex_update_params *afex_update_params =
5715 &params->params.afex_update;
5716
5717 memset(rdata, 0, sizeof(*rdata));
5718
5719 /* Fill the ramrod data with provided parameters */
5720 rdata->vif_id_change_flg = 1;
5721 rdata->vif_id = cpu_to_le16(afex_update_params->vif_id);
5722 rdata->afex_default_vlan_change_flg = 1;
5723 rdata->afex_default_vlan =
5724 cpu_to_le16(afex_update_params->afex_default_vlan);
5725 rdata->allowed_priorities_change_flg = 1;
5726 rdata->allowed_priorities = afex_update_params->allowed_priorities;
Merav Sicron55c11942012-11-07 00:45:48 +00005727 rdata->echo = AFEX_UPDATE;
Barak Witkowskia3348722012-04-23 03:04:46 +00005728
5729 /* No need for an explicit memory barrier here as long we would
5730 * need to ensure the ordering of writing to the SPQ element
5731 * and updating of the SPQ producer which involves a memory
5732 * read and we will have to put a full memory barrier there
5733 * (inside bnx2x_sp_post()).
5734 */
5735 DP(BNX2X_MSG_SP,
5736 "afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
5737 rdata->vif_id,
5738 rdata->afex_default_vlan, rdata->allowed_priorities);
5739
5740 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5741 U64_HI(data_mapping),
5742 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5743}
5744
5745static
5746inline int bnx2x_func_send_afex_viflists(struct bnx2x *bp,
5747 struct bnx2x_func_state_params *params)
5748{
5749 struct bnx2x_func_sp_obj *o = params->f_obj;
5750 struct afex_vif_list_ramrod_data *rdata =
5751 (struct afex_vif_list_ramrod_data *)o->afex_rdata;
5752 struct bnx2x_func_afex_viflists_params *afex_viflist_params =
5753 &params->params.afex_viflists;
5754 u64 *p_rdata = (u64 *)rdata;
5755
5756 memset(rdata, 0, sizeof(*rdata));
5757
5758 /* Fill the ramrod data with provided parameters */
5759 rdata->vif_list_index = afex_viflist_params->vif_list_index;
5760 rdata->func_bit_map = afex_viflist_params->func_bit_map;
5761 rdata->afex_vif_list_command =
5762 afex_viflist_params->afex_vif_list_command;
5763 rdata->func_to_clear = afex_viflist_params->func_to_clear;
5764
5765 /* send in echo type of sub command */
5766 rdata->echo = afex_viflist_params->afex_vif_list_command;
5767
5768 /* No need for an explicit memory barrier here as long we would
5769 * need to ensure the ordering of writing to the SPQ element
5770 * and updating of the SPQ producer which involves a memory
5771 * read and we will have to put a full memory barrier there
5772 * (inside bnx2x_sp_post()).
5773 */
5774
5775 DP(BNX2X_MSG_SP, "afex: ramrod lists, cmd 0x%x index 0x%x func_bit_map 0x%x func_to_clr 0x%x\n",
5776 rdata->afex_vif_list_command, rdata->vif_list_index,
5777 rdata->func_bit_map, rdata->func_to_clear);
5778
5779 /* this ramrod sends data directly and not through DMA mapping */
5780 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_AFEX_VIF_LISTS, 0,
5781 U64_HI(*p_rdata), U64_LO(*p_rdata),
5782 NONE_CONNECTION_TYPE);
5783}
5784
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005785static inline int bnx2x_func_send_stop(struct bnx2x *bp,
5786 struct bnx2x_func_state_params *params)
5787{
5788 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
5789 NONE_CONNECTION_TYPE);
5790}
5791
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005792static inline int bnx2x_func_send_tx_stop(struct bnx2x *bp,
5793 struct bnx2x_func_state_params *params)
5794{
5795 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC, 0, 0, 0,
5796 NONE_CONNECTION_TYPE);
5797}
5798static inline int bnx2x_func_send_tx_start(struct bnx2x *bp,
5799 struct bnx2x_func_state_params *params)
5800{
5801 struct bnx2x_func_sp_obj *o = params->f_obj;
5802 struct flow_control_configuration *rdata =
5803 (struct flow_control_configuration *)o->rdata;
5804 dma_addr_t data_mapping = o->rdata_mapping;
5805 struct bnx2x_func_tx_start_params *tx_start_params =
5806 &params->params.tx_start;
5807 int i;
5808
5809 memset(rdata, 0, sizeof(*rdata));
5810
5811 rdata->dcb_enabled = tx_start_params->dcb_enabled;
5812 rdata->dcb_version = tx_start_params->dcb_version;
5813 rdata->dont_add_pri_0_en = tx_start_params->dont_add_pri_0_en;
5814
5815 for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
5816 rdata->traffic_type_to_priority_cos[i] =
5817 tx_start_params->traffic_type_to_priority_cos[i];
5818
5819 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
5820 U64_HI(data_mapping),
5821 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5822}
5823
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005824static int bnx2x_func_send_cmd(struct bnx2x *bp,
5825 struct bnx2x_func_state_params *params)
5826{
5827 switch (params->cmd) {
5828 case BNX2X_F_CMD_HW_INIT:
5829 return bnx2x_func_hw_init(bp, params);
5830 case BNX2X_F_CMD_START:
5831 return bnx2x_func_send_start(bp, params);
5832 case BNX2X_F_CMD_STOP:
5833 return bnx2x_func_send_stop(bp, params);
5834 case BNX2X_F_CMD_HW_RESET:
5835 return bnx2x_func_hw_reset(bp, params);
Barak Witkowskia3348722012-04-23 03:04:46 +00005836 case BNX2X_F_CMD_AFEX_UPDATE:
5837 return bnx2x_func_send_afex_update(bp, params);
5838 case BNX2X_F_CMD_AFEX_VIFLISTS:
5839 return bnx2x_func_send_afex_viflists(bp, params);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005840 case BNX2X_F_CMD_TX_STOP:
5841 return bnx2x_func_send_tx_stop(bp, params);
5842 case BNX2X_F_CMD_TX_START:
5843 return bnx2x_func_send_tx_start(bp, params);
Merav Sicron55c11942012-11-07 00:45:48 +00005844 case BNX2X_F_CMD_SWITCH_UPDATE:
5845 return bnx2x_func_send_switch_update(bp, params);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005846 default:
5847 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5848 return -EINVAL;
5849 }
5850}
5851
5852void bnx2x_init_func_obj(struct bnx2x *bp,
5853 struct bnx2x_func_sp_obj *obj,
5854 void *rdata, dma_addr_t rdata_mapping,
Barak Witkowskia3348722012-04-23 03:04:46 +00005855 void *afex_rdata, dma_addr_t afex_rdata_mapping,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005856 struct bnx2x_func_sp_drv_ops *drv_iface)
5857{
5858 memset(obj, 0, sizeof(*obj));
5859
5860 mutex_init(&obj->one_pending_mutex);
5861
5862 obj->rdata = rdata;
5863 obj->rdata_mapping = rdata_mapping;
Barak Witkowskia3348722012-04-23 03:04:46 +00005864 obj->afex_rdata = afex_rdata;
5865 obj->afex_rdata_mapping = afex_rdata_mapping;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005866 obj->send_cmd = bnx2x_func_send_cmd;
5867 obj->check_transition = bnx2x_func_chk_transition;
5868 obj->complete_cmd = bnx2x_func_comp_cmd;
5869 obj->wait_comp = bnx2x_func_wait_comp;
5870
5871 obj->drv = drv_iface;
5872}
5873
5874/**
5875 * bnx2x_func_state_change - perform Function state change transition
5876 *
5877 * @bp: device handle
5878 * @params: parameters to perform the transaction
5879 *
5880 * returns 0 in case of successfully completed transition,
5881 * negative error code in case of failure, positive
5882 * (EBUSY) value if there is a completion to that is
5883 * still pending (possible only if RAMROD_COMP_WAIT is
5884 * not set in params->ramrod_flags for asynchronous
5885 * commands).
5886 */
5887int bnx2x_func_state_change(struct bnx2x *bp,
5888 struct bnx2x_func_state_params *params)
5889{
5890 struct bnx2x_func_sp_obj *o = params->f_obj;
Merav Sicron55c11942012-11-07 00:45:48 +00005891 int rc, cnt = 300;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005892 enum bnx2x_func_cmd cmd = params->cmd;
5893 unsigned long *pending = &o->pending;
5894
5895 mutex_lock(&o->one_pending_mutex);
5896
5897 /* Check that the requested transition is legal */
Merav Sicron55c11942012-11-07 00:45:48 +00005898 rc = o->check_transition(bp, o, params);
5899 if ((rc == -EBUSY) &&
5900 (test_bit(RAMROD_RETRY, &params->ramrod_flags))) {
5901 while ((rc == -EBUSY) && (--cnt > 0)) {
5902 mutex_unlock(&o->one_pending_mutex);
5903 msleep(10);
5904 mutex_lock(&o->one_pending_mutex);
5905 rc = o->check_transition(bp, o, params);
5906 }
5907 if (rc == -EBUSY) {
5908 mutex_unlock(&o->one_pending_mutex);
5909 BNX2X_ERR("timeout waiting for previous ramrod completion\n");
5910 return rc;
5911 }
5912 } else if (rc) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005913 mutex_unlock(&o->one_pending_mutex);
Merav Sicron55c11942012-11-07 00:45:48 +00005914 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005915 }
5916
5917 /* Set "pending" bit */
5918 set_bit(cmd, pending);
5919
5920 /* Don't send a command if only driver cleanup was requested */
5921 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5922 bnx2x_func_state_change_comp(bp, o, cmd);
5923 mutex_unlock(&o->one_pending_mutex);
5924 } else {
5925 /* Send a ramrod */
5926 rc = o->send_cmd(bp, params);
5927
5928 mutex_unlock(&o->one_pending_mutex);
5929
5930 if (rc) {
5931 o->next_state = BNX2X_F_STATE_MAX;
5932 clear_bit(cmd, pending);
5933 smp_mb__after_clear_bit();
5934 return rc;
5935 }
5936
5937 if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
5938 rc = o->wait_comp(bp, o, cmd);
5939 if (rc)
5940 return rc;
5941
5942 return 0;
5943 }
5944 }
5945
5946 return !!test_bit(cmd, pending);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005947}