blob: babf7b954ae66c960638bac9f9ac1f0f4c3958dd [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
33/**** Exe Queue interfaces ****/
Vladislav Zolotarov042181f2011-06-14 01:33:39 +000034
35/**
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030036 * bnx2x_exe_queue_init - init the Exe Queue object
37 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +000038 * @o: pointer to the object
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030039 * @exe_len: length
Yuval Mintz16a5fd92013-06-02 00:06:18 +000040 * @owner: pointer to the owner
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030041 * @validate: validate function pointer
42 * @optimize: optimize function pointer
43 * @exec: execute function pointer
44 * @get: get function pointer
45 */
46static inline void bnx2x_exe_queue_init(struct bnx2x *bp,
47 struct bnx2x_exe_queue_obj *o,
48 int exe_len,
49 union bnx2x_qable_obj *owner,
50 exe_q_validate validate,
Yuval Mintz460a25c2012-01-23 07:31:51 +000051 exe_q_remove remove,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030052 exe_q_optimize optimize,
53 exe_q_execute exec,
54 exe_q_get get)
55{
56 memset(o, 0, sizeof(*o));
57
58 INIT_LIST_HEAD(&o->exe_queue);
59 INIT_LIST_HEAD(&o->pending_comp);
60
61 spin_lock_init(&o->lock);
62
63 o->exe_chunk_len = exe_len;
64 o->owner = owner;
65
66 /* Owner specific callbacks */
67 o->validate = validate;
Yuval Mintz460a25c2012-01-23 07:31:51 +000068 o->remove = remove;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030069 o->optimize = optimize;
70 o->execute = exec;
71 o->get = get;
72
Merav Sicron51c1a582012-03-18 10:33:38 +000073 DP(BNX2X_MSG_SP, "Setup the execution queue with the chunk length of %d\n",
74 exe_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +030075}
76
77static inline void bnx2x_exe_queue_free_elem(struct bnx2x *bp,
78 struct bnx2x_exeq_elem *elem)
79{
80 DP(BNX2X_MSG_SP, "Deleting an exe_queue element\n");
81 kfree(elem);
82}
83
84static inline int bnx2x_exe_queue_length(struct bnx2x_exe_queue_obj *o)
85{
86 struct bnx2x_exeq_elem *elem;
87 int cnt = 0;
88
89 spin_lock_bh(&o->lock);
90
91 list_for_each_entry(elem, &o->exe_queue, link)
92 cnt++;
93
94 spin_unlock_bh(&o->lock);
95
96 return cnt;
97}
98
99/**
100 * bnx2x_exe_queue_add - add a new element to the execution queue
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000101 *
102 * @bp: driver handle
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300103 * @o: queue
104 * @cmd: new command to add
105 * @restore: true - do not optimize the command
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000106 *
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300107 * If the element is optimized or is illegal, frees it.
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000108 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300109static inline int bnx2x_exe_queue_add(struct bnx2x *bp,
110 struct bnx2x_exe_queue_obj *o,
111 struct bnx2x_exeq_elem *elem,
112 bool restore)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000113{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300114 int rc;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000115
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300116 spin_lock_bh(&o->lock);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000117
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300118 if (!restore) {
119 /* Try to cancel this element queue */
120 rc = o->optimize(bp, o->owner, elem);
121 if (rc)
122 goto free_and_exit;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000123
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300124 /* Check if this request is ok */
125 rc = o->validate(bp, o->owner, elem);
126 if (rc) {
Dmitry Kravkov2384d6a2012-10-16 01:28:27 +0000127 DP(BNX2X_MSG_SP, "Preamble failed: %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300128 goto free_and_exit;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000129 }
130 }
131
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300132 /* If so, add it to the execution queue */
133 list_add_tail(&elem->link, &o->exe_queue);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000134
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300135 spin_unlock_bh(&o->lock);
136
137 return 0;
138
139free_and_exit:
140 bnx2x_exe_queue_free_elem(bp, elem);
141
142 spin_unlock_bh(&o->lock);
143
144 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300145}
146
147static inline void __bnx2x_exe_queue_reset_pending(
148 struct bnx2x *bp,
149 struct bnx2x_exe_queue_obj *o)
150{
151 struct bnx2x_exeq_elem *elem;
152
153 while (!list_empty(&o->pending_comp)) {
154 elem = list_first_entry(&o->pending_comp,
155 struct bnx2x_exeq_elem, link);
156
157 list_del(&elem->link);
158 bnx2x_exe_queue_free_elem(bp, elem);
159 }
160}
161
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300162/**
163 * bnx2x_exe_queue_step - execute one execution chunk atomically
164 *
165 * @bp: driver handle
166 * @o: queue
167 * @ramrod_flags: flags
168 *
Yuval Mintz8b09be52013-08-01 17:30:59 +0300169 * (Should be called while holding the exe_queue->lock).
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300170 */
171static inline int bnx2x_exe_queue_step(struct bnx2x *bp,
172 struct bnx2x_exe_queue_obj *o,
173 unsigned long *ramrod_flags)
174{
175 struct bnx2x_exeq_elem *elem, spacer;
176 int cur_len = 0, rc;
177
178 memset(&spacer, 0, sizeof(spacer));
179
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000180 /* Next step should not be performed until the current is finished,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300181 * unless a DRV_CLEAR_ONLY bit is set. In this case we just want to
182 * properly clear object internals without sending any command to the FW
183 * which also implies there won't be any completion to clear the
184 * 'pending' list.
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000185 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300186 if (!list_empty(&o->pending_comp)) {
187 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
Merav Sicron51c1a582012-03-18 10:33:38 +0000188 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: resetting a pending_comp list\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300189 __bnx2x_exe_queue_reset_pending(bp, o);
190 } else {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300191 return 1;
192 }
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000193 }
194
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000195 /* Run through the pending commands list and create a next
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300196 * execution chunk.
197 */
198 while (!list_empty(&o->exe_queue)) {
199 elem = list_first_entry(&o->exe_queue, struct bnx2x_exeq_elem,
200 link);
201 WARN_ON(!elem->cmd_len);
202
203 if (cur_len + elem->cmd_len <= o->exe_chunk_len) {
204 cur_len += elem->cmd_len;
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000205 /* Prevent from both lists being empty when moving an
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300206 * element. This will allow the call of
207 * bnx2x_exe_queue_empty() without locking.
208 */
209 list_add_tail(&spacer.link, &o->pending_comp);
210 mb();
Wei Yongjun7933aa52012-09-04 21:06:55 +0000211 list_move_tail(&elem->link, &o->pending_comp);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300212 list_del(&spacer.link);
213 } else
214 break;
215 }
216
217 /* Sanity check */
Yuval Mintz8b09be52013-08-01 17:30:59 +0300218 if (!cur_len)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300219 return 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300220
221 rc = o->execute(bp, o->owner, &o->pending_comp, ramrod_flags);
222 if (rc < 0)
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000223 /* In case of an error return the commands back to the queue
224 * and reset the pending_comp.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300225 */
226 list_splice_init(&o->pending_comp, &o->exe_queue);
227 else if (!rc)
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000228 /* If zero is returned, means there are no outstanding pending
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300229 * completions and we may dismiss the pending list.
230 */
231 __bnx2x_exe_queue_reset_pending(bp, o);
232
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300233 return rc;
234}
235
236static inline bool bnx2x_exe_queue_empty(struct bnx2x_exe_queue_obj *o)
237{
238 bool empty = list_empty(&o->exe_queue);
239
240 /* Don't reorder!!! */
241 mb();
242
243 return empty && list_empty(&o->pending_comp);
244}
245
246static inline struct bnx2x_exeq_elem *bnx2x_exe_queue_alloc_elem(
247 struct bnx2x *bp)
248{
249 DP(BNX2X_MSG_SP, "Allocating a new exe_queue element\n");
250 return kzalloc(sizeof(struct bnx2x_exeq_elem), GFP_ATOMIC);
251}
252
253/************************ raw_obj functions ***********************************/
254static bool bnx2x_raw_check_pending(struct bnx2x_raw_obj *o)
255{
256 return !!test_bit(o->state, o->pstate);
257}
258
259static void bnx2x_raw_clear_pending(struct bnx2x_raw_obj *o)
260{
261 smp_mb__before_clear_bit();
262 clear_bit(o->state, o->pstate);
263 smp_mb__after_clear_bit();
264}
265
266static void bnx2x_raw_set_pending(struct bnx2x_raw_obj *o)
267{
268 smp_mb__before_clear_bit();
269 set_bit(o->state, o->pstate);
270 smp_mb__after_clear_bit();
271}
272
273/**
274 * bnx2x_state_wait - wait until the given bit(state) is cleared
275 *
276 * @bp: device handle
277 * @state: state which is to be cleared
278 * @state_p: state buffer
279 *
280 */
281static inline int bnx2x_state_wait(struct bnx2x *bp, int state,
282 unsigned long *pstate)
283{
284 /* can take a while if any port is running */
285 int cnt = 5000;
286
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300287 if (CHIP_REV_IS_EMUL(bp))
288 cnt *= 20;
289
290 DP(BNX2X_MSG_SP, "waiting for state to become %d\n", state);
291
292 might_sleep();
293 while (cnt--) {
294 if (!test_bit(state, pstate)) {
295#ifdef BNX2X_STOP_ON_ERROR
296 DP(BNX2X_MSG_SP, "exit (cnt %d)\n", 5000 - cnt);
297#endif
298 return 0;
299 }
300
Yuval Mintz0926d492013-01-23 03:21:45 +0000301 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300302
303 if (bp->panic)
304 return -EIO;
305 }
306
307 /* timeout! */
308 BNX2X_ERR("timeout waiting for state %d\n", state);
309#ifdef BNX2X_STOP_ON_ERROR
310 bnx2x_panic();
311#endif
312
313 return -EBUSY;
314}
315
316static int bnx2x_raw_wait(struct bnx2x *bp, struct bnx2x_raw_obj *raw)
317{
318 return bnx2x_state_wait(bp, raw->state, raw->pstate);
319}
320
321/***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
322/* credit handling callbacks */
323static bool bnx2x_get_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int *offset)
324{
325 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
326
327 WARN_ON(!mp);
328
329 return mp->get_entry(mp, offset);
330}
331
332static bool bnx2x_get_credit_mac(struct bnx2x_vlan_mac_obj *o)
333{
334 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
335
336 WARN_ON(!mp);
337
338 return mp->get(mp, 1);
339}
340
341static bool bnx2x_get_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int *offset)
342{
343 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
344
345 WARN_ON(!vp);
346
347 return vp->get_entry(vp, offset);
348}
349
350static bool bnx2x_get_credit_vlan(struct bnx2x_vlan_mac_obj *o)
351{
352 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
353
354 WARN_ON(!vp);
355
356 return vp->get(vp, 1);
357}
358
359static bool bnx2x_get_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
360{
361 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
362 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
363
364 if (!mp->get(mp, 1))
365 return false;
366
367 if (!vp->get(vp, 1)) {
368 mp->put(mp, 1);
369 return false;
370 }
371
372 return true;
373}
374
375static bool bnx2x_put_cam_offset_mac(struct bnx2x_vlan_mac_obj *o, int offset)
376{
377 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
378
379 return mp->put_entry(mp, offset);
380}
381
382static bool bnx2x_put_credit_mac(struct bnx2x_vlan_mac_obj *o)
383{
384 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
385
386 return mp->put(mp, 1);
387}
388
389static bool bnx2x_put_cam_offset_vlan(struct bnx2x_vlan_mac_obj *o, int offset)
390{
391 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
392
393 return vp->put_entry(vp, offset);
394}
395
396static bool bnx2x_put_credit_vlan(struct bnx2x_vlan_mac_obj *o)
397{
398 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
399
400 return vp->put(vp, 1);
401}
402
403static bool bnx2x_put_credit_vlan_mac(struct bnx2x_vlan_mac_obj *o)
404{
405 struct bnx2x_credit_pool_obj *mp = o->macs_pool;
406 struct bnx2x_credit_pool_obj *vp = o->vlans_pool;
407
408 if (!mp->put(mp, 1))
409 return false;
410
411 if (!vp->put(vp, 1)) {
412 mp->get(mp, 1);
413 return false;
414 }
415
416 return true;
417}
418
Yuval Mintz8b09be52013-08-01 17:30:59 +0300419/**
420 * __bnx2x_vlan_mac_h_write_trylock - try getting the vlan mac writer lock
421 *
422 * @bp: device handle
423 * @o: vlan_mac object
424 *
425 * @details: Non-blocking implementation; should be called under execution
426 * queue lock.
427 */
428static int __bnx2x_vlan_mac_h_write_trylock(struct bnx2x *bp,
429 struct bnx2x_vlan_mac_obj *o)
430{
431 if (o->head_reader) {
432 DP(BNX2X_MSG_SP, "vlan_mac_lock writer - There are readers; Busy\n");
433 return -EBUSY;
434 }
435
436 DP(BNX2X_MSG_SP, "vlan_mac_lock writer - Taken\n");
437 return 0;
438}
439
440/**
441 * __bnx2x_vlan_mac_h_exec_pending - execute step instead of a previous step
442 *
443 * @bp: device handle
444 * @o: vlan_mac object
445 *
446 * @details Should be called under execution queue lock; notice it might release
447 * and reclaim it during its run.
448 */
449static void __bnx2x_vlan_mac_h_exec_pending(struct bnx2x *bp,
450 struct bnx2x_vlan_mac_obj *o)
451{
452 int rc;
453 unsigned long ramrod_flags = o->saved_ramrod_flags;
454
455 DP(BNX2X_MSG_SP, "vlan_mac_lock execute pending command with ramrod flags %lu\n",
456 ramrod_flags);
457 o->head_exe_request = false;
458 o->saved_ramrod_flags = 0;
459 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, &ramrod_flags);
460 if (rc != 0) {
461 BNX2X_ERR("execution of pending commands failed with rc %d\n",
462 rc);
463#ifdef BNX2X_STOP_ON_ERROR
464 bnx2x_panic();
465#endif
466 }
467}
468
469/**
470 * __bnx2x_vlan_mac_h_pend - Pend an execution step which couldn't run
471 *
472 * @bp: device handle
473 * @o: vlan_mac object
474 * @ramrod_flags: ramrod flags of missed execution
475 *
476 * @details Should be called under execution queue lock.
477 */
478static void __bnx2x_vlan_mac_h_pend(struct bnx2x *bp,
479 struct bnx2x_vlan_mac_obj *o,
480 unsigned long ramrod_flags)
481{
482 o->head_exe_request = true;
483 o->saved_ramrod_flags = ramrod_flags;
484 DP(BNX2X_MSG_SP, "Placing pending execution with ramrod flags %lu\n",
485 ramrod_flags);
486}
487
488/**
489 * __bnx2x_vlan_mac_h_write_unlock - unlock the vlan mac head list writer lock
490 *
491 * @bp: device handle
492 * @o: vlan_mac object
493 *
494 * @details Should be called under execution queue lock. Notice if a pending
495 * execution exists, it would perform it - possibly releasing and
496 * reclaiming the execution queue lock.
497 */
498static void __bnx2x_vlan_mac_h_write_unlock(struct bnx2x *bp,
499 struct bnx2x_vlan_mac_obj *o)
500{
501 /* It's possible a new pending execution was added since this writer
502 * executed. If so, execute again. [Ad infinitum]
503 */
504 while (o->head_exe_request) {
505 DP(BNX2X_MSG_SP, "vlan_mac_lock - writer release encountered a pending request\n");
506 __bnx2x_vlan_mac_h_exec_pending(bp, o);
507 }
508}
509
510/**
511 * bnx2x_vlan_mac_h_write_unlock - unlock the vlan mac head list writer lock
512 *
513 * @bp: device handle
514 * @o: vlan_mac object
515 *
516 * @details Notice if a pending execution exists, it would perform it -
517 * possibly releasing and reclaiming the execution queue lock.
518 */
519void bnx2x_vlan_mac_h_write_unlock(struct bnx2x *bp,
520 struct bnx2x_vlan_mac_obj *o)
521{
522 spin_lock_bh(&o->exe_queue.lock);
523 __bnx2x_vlan_mac_h_write_unlock(bp, o);
524 spin_unlock_bh(&o->exe_queue.lock);
525}
526
527/**
528 * __bnx2x_vlan_mac_h_read_lock - lock the vlan mac head list reader lock
529 *
530 * @bp: device handle
531 * @o: vlan_mac object
532 *
533 * @details Should be called under the execution queue lock. May sleep. May
534 * release and reclaim execution queue lock during its run.
535 */
536static int __bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
537 struct bnx2x_vlan_mac_obj *o)
538{
539 /* If we got here, we're holding lock --> no WRITER exists */
540 o->head_reader++;
541 DP(BNX2X_MSG_SP, "vlan_mac_lock - locked reader - number %d\n",
542 o->head_reader);
543
544 return 0;
545}
546
547/**
548 * bnx2x_vlan_mac_h_read_lock - lock the vlan mac head list reader lock
549 *
550 * @bp: device handle
551 * @o: vlan_mac object
552 *
553 * @details May sleep. Claims and releases execution queue lock during its run.
554 */
555int bnx2x_vlan_mac_h_read_lock(struct bnx2x *bp,
556 struct bnx2x_vlan_mac_obj *o)
557{
558 int rc;
559
560 spin_lock_bh(&o->exe_queue.lock);
561 rc = __bnx2x_vlan_mac_h_read_lock(bp, o);
562 spin_unlock_bh(&o->exe_queue.lock);
563
564 return rc;
565}
566
567/**
568 * __bnx2x_vlan_mac_h_read_unlock - unlock the vlan mac head list reader lock
569 *
570 * @bp: device handle
571 * @o: vlan_mac object
572 *
573 * @details Should be called under execution queue lock. Notice if a pending
574 * execution exists, it would be performed if this was the last
575 * reader. possibly releasing and reclaiming the execution queue lock.
576 */
577static void __bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
578 struct bnx2x_vlan_mac_obj *o)
579{
580 if (!o->head_reader) {
581 BNX2X_ERR("Need to release vlan mac reader lock, but lock isn't taken\n");
582#ifdef BNX2X_STOP_ON_ERROR
583 bnx2x_panic();
584#endif
585 } else {
586 o->head_reader--;
587 DP(BNX2X_MSG_SP, "vlan_mac_lock - decreased readers to %d\n",
588 o->head_reader);
589 }
590
591 /* It's possible a new pending execution was added, and that this reader
592 * was last - if so we need to execute the command.
593 */
594 if (!o->head_reader && o->head_exe_request) {
595 DP(BNX2X_MSG_SP, "vlan_mac_lock - reader release encountered a pending request\n");
596
597 /* Writer release will do the trick */
598 __bnx2x_vlan_mac_h_write_unlock(bp, o);
599 }
600}
601
602/**
603 * bnx2x_vlan_mac_h_read_unlock - unlock the vlan mac head list reader lock
604 *
605 * @bp: device handle
606 * @o: vlan_mac object
607 *
608 * @details Notice if a pending execution exists, it would be performed if this
609 * was the last reader. Claims and releases the execution queue lock
610 * during its run.
611 */
612void bnx2x_vlan_mac_h_read_unlock(struct bnx2x *bp,
613 struct bnx2x_vlan_mac_obj *o)
614{
615 spin_lock_bh(&o->exe_queue.lock);
616 __bnx2x_vlan_mac_h_read_unlock(bp, o);
617 spin_unlock_bh(&o->exe_queue.lock);
618}
619
Ariel Eliored5162a2011-12-05 21:52:24 +0000620static int bnx2x_get_n_elements(struct bnx2x *bp, struct bnx2x_vlan_mac_obj *o,
Ariel Elior3ec9f9c2013-03-11 05:17:45 +0000621 int n, u8 *base, u8 stride, u8 size)
Ariel Eliored5162a2011-12-05 21:52:24 +0000622{
623 struct bnx2x_vlan_mac_registry_elem *pos;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +0000624 u8 *next = base;
Ariel Eliored5162a2011-12-05 21:52:24 +0000625 int counter = 0;
Yuval Mintz8b09be52013-08-01 17:30:59 +0300626 int read_lock;
627
628 DP(BNX2X_MSG_SP, "get_n_elements - taking vlan_mac_lock (reader)\n");
629 read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
630 if (read_lock != 0)
631 BNX2X_ERR("get_n_elements failed to get vlan mac reader lock; Access without lock\n");
Ariel Eliored5162a2011-12-05 21:52:24 +0000632
633 /* traverse list */
634 list_for_each_entry(pos, &o->head, link) {
635 if (counter < n) {
Ariel Elior3ec9f9c2013-03-11 05:17:45 +0000636 memcpy(next, &pos->u, size);
Ariel Eliored5162a2011-12-05 21:52:24 +0000637 counter++;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +0000638 DP(BNX2X_MSG_SP, "copied element number %d to address %p element was:\n",
639 counter, next);
640 next += stride + size;
Ariel Eliored5162a2011-12-05 21:52:24 +0000641 }
642 }
Yuval Mintz8b09be52013-08-01 17:30:59 +0300643
644 if (read_lock == 0) {
645 DP(BNX2X_MSG_SP, "get_n_elements - releasing vlan_mac_lock (reader)\n");
646 bnx2x_vlan_mac_h_read_unlock(bp, o);
647 }
648
Ariel Eliored5162a2011-12-05 21:52:24 +0000649 return counter * ETH_ALEN;
650}
651
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300652/* check_add() callbacks */
Merav Sicron51c1a582012-03-18 10:33:38 +0000653static int bnx2x_check_mac_add(struct bnx2x *bp,
654 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300655 union bnx2x_classification_ramrod_data *data)
656{
657 struct bnx2x_vlan_mac_registry_elem *pos;
658
Merav Sicron51c1a582012-03-18 10:33:38 +0000659 DP(BNX2X_MSG_SP, "Checking MAC %pM for ADD command\n", data->mac.mac);
660
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300661 if (!is_valid_ether_addr(data->mac.mac))
662 return -EINVAL;
663
664 /* Check if a requested MAC already exists */
665 list_for_each_entry(pos, &o->head, link)
dingtianhong8fd90de2013-12-30 15:40:32 +0800666 if (ether_addr_equal(data->mac.mac, pos->u.mac.mac) &&
Dmitry Kravkov91226792013-03-11 05:17:52 +0000667 (data->mac.is_inner_mac == pos->u.mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300668 return -EEXIST;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000669
670 return 0;
671}
672
Merav Sicron51c1a582012-03-18 10:33:38 +0000673static int bnx2x_check_vlan_add(struct bnx2x *bp,
674 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300675 union bnx2x_classification_ramrod_data *data)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000676{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300677 struct bnx2x_vlan_mac_registry_elem *pos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000678
Merav Sicron51c1a582012-03-18 10:33:38 +0000679 DP(BNX2X_MSG_SP, "Checking VLAN %d for ADD command\n", data->vlan.vlan);
680
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300681 list_for_each_entry(pos, &o->head, link)
682 if (data->vlan.vlan == pos->u.vlan.vlan)
683 return -EEXIST;
684
685 return 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000686}
687
Merav Sicron51c1a582012-03-18 10:33:38 +0000688static int bnx2x_check_vlan_mac_add(struct bnx2x *bp,
689 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300690 union bnx2x_classification_ramrod_data *data)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000691{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300692 struct bnx2x_vlan_mac_registry_elem *pos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +0000693
Merav Sicron51c1a582012-03-18 10:33:38 +0000694 DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for ADD command\n",
695 data->vlan_mac.mac, data->vlan_mac.vlan);
696
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300697 list_for_each_entry(pos, &o->head, link)
698 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
dingtianhong8fd90de2013-12-30 15:40:32 +0800699 ether_addr_equal_unaligned(data->vlan_mac.mac, pos->u.vlan_mac.mac) &&
Dmitry Kravkov91226792013-03-11 05:17:52 +0000700 (data->vlan_mac.is_inner_mac ==
701 pos->u.vlan_mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300702 return -EEXIST;
703
704 return 0;
705}
706
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300707/* check_del() callbacks */
708static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000709 bnx2x_check_mac_del(struct bnx2x *bp,
710 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300711 union bnx2x_classification_ramrod_data *data)
712{
713 struct bnx2x_vlan_mac_registry_elem *pos;
714
Merav Sicron51c1a582012-03-18 10:33:38 +0000715 DP(BNX2X_MSG_SP, "Checking MAC %pM for DEL command\n", data->mac.mac);
716
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300717 list_for_each_entry(pos, &o->head, link)
dingtianhong8fd90de2013-12-30 15:40:32 +0800718 if (ether_addr_equal(data->mac.mac, pos->u.mac.mac) &&
Dmitry Kravkov91226792013-03-11 05:17:52 +0000719 (data->mac.is_inner_mac == pos->u.mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300720 return pos;
721
722 return NULL;
723}
724
725static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000726 bnx2x_check_vlan_del(struct bnx2x *bp,
727 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300728 union bnx2x_classification_ramrod_data *data)
729{
730 struct bnx2x_vlan_mac_registry_elem *pos;
731
Merav Sicron51c1a582012-03-18 10:33:38 +0000732 DP(BNX2X_MSG_SP, "Checking VLAN %d for DEL command\n", data->vlan.vlan);
733
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300734 list_for_each_entry(pos, &o->head, link)
735 if (data->vlan.vlan == pos->u.vlan.vlan)
736 return pos;
737
738 return NULL;
739}
740
741static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000742 bnx2x_check_vlan_mac_del(struct bnx2x *bp,
743 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300744 union bnx2x_classification_ramrod_data *data)
745{
746 struct bnx2x_vlan_mac_registry_elem *pos;
747
Merav Sicron51c1a582012-03-18 10:33:38 +0000748 DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for DEL command\n",
749 data->vlan_mac.mac, data->vlan_mac.vlan);
750
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300751 list_for_each_entry(pos, &o->head, link)
752 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
dingtianhong8fd90de2013-12-30 15:40:32 +0800753 ether_addr_equal_unaligned(data->vlan_mac.mac, pos->u.vlan_mac.mac) &&
Dmitry Kravkov91226792013-03-11 05:17:52 +0000754 (data->vlan_mac.is_inner_mac ==
755 pos->u.vlan_mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300756 return pos;
757
758 return NULL;
759}
760
761/* check_move() callback */
Merav Sicron51c1a582012-03-18 10:33:38 +0000762static bool bnx2x_check_move(struct bnx2x *bp,
763 struct bnx2x_vlan_mac_obj *src_o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300764 struct bnx2x_vlan_mac_obj *dst_o,
765 union bnx2x_classification_ramrod_data *data)
766{
767 struct bnx2x_vlan_mac_registry_elem *pos;
768 int rc;
769
770 /* Check if we can delete the requested configuration from the first
771 * object.
772 */
Merav Sicron51c1a582012-03-18 10:33:38 +0000773 pos = src_o->check_del(bp, src_o, data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300774
775 /* check if configuration can be added */
Merav Sicron51c1a582012-03-18 10:33:38 +0000776 rc = dst_o->check_add(bp, dst_o, data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300777
778 /* If this classification can not be added (is already set)
779 * or can't be deleted - return an error.
780 */
781 if (rc || !pos)
782 return false;
783
784 return true;
785}
786
787static bool bnx2x_check_move_always_err(
Merav Sicron51c1a582012-03-18 10:33:38 +0000788 struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300789 struct bnx2x_vlan_mac_obj *src_o,
790 struct bnx2x_vlan_mac_obj *dst_o,
791 union bnx2x_classification_ramrod_data *data)
792{
793 return false;
794}
795
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300796static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
797{
798 struct bnx2x_raw_obj *raw = &o->raw;
799 u8 rx_tx_flag = 0;
800
801 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
802 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
803 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
804
805 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
806 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
807 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
808
809 return rx_tx_flag;
810}
811
Barak Witkowskia3348722012-04-23 03:04:46 +0000812void bnx2x_set_mac_in_nig(struct bnx2x *bp,
813 bool add, unsigned char *dev_addr, int index)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300814{
815 u32 wb_data[2];
816 u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
817 NIG_REG_LLH0_FUNC_MEM;
818
Barak Witkowskia3348722012-04-23 03:04:46 +0000819 if (!IS_MF_SI(bp) && !IS_MF_AFEX(bp))
820 return;
821
822 if (index > BNX2X_LLH_CAM_MAX_PF_LINE)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300823 return;
824
825 DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
826 (add ? "ADD" : "DELETE"), index);
827
828 if (add) {
829 /* LLH_FUNC_MEM is a u64 WB register */
830 reg_offset += 8*index;
831
832 wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
833 (dev_addr[4] << 8) | dev_addr[5]);
834 wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
835
836 REG_WR_DMAE(bp, reg_offset, wb_data, 2);
837 }
838
839 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
840 NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
841}
842
843/**
844 * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
845 *
846 * @bp: device handle
847 * @o: queue for which we want to configure this rule
848 * @add: if true the command is an ADD command, DEL otherwise
849 * @opcode: CLASSIFY_RULE_OPCODE_XXX
850 * @hdr: pointer to a header to setup
851 *
852 */
853static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
854 struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
855 struct eth_classify_cmd_header *hdr)
856{
857 struct bnx2x_raw_obj *raw = &o->raw;
858
859 hdr->client_id = raw->cl_id;
860 hdr->func_id = raw->func_id;
861
862 /* Rx or/and Tx (internal switching) configuration ? */
863 hdr->cmd_general_data |=
864 bnx2x_vlan_mac_get_rx_tx_flag(o);
865
866 if (add)
867 hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
868
869 hdr->cmd_general_data |=
870 (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
871}
872
873/**
874 * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
875 *
876 * @cid: connection id
877 * @type: BNX2X_FILTER_XXX_PENDING
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000878 * @hdr: pointer to header to setup
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300879 * @rule_cnt:
880 *
881 * currently we always configure one rule and echo field to contain a CID and an
882 * opcode type.
883 */
884static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
885 struct eth_classify_header *hdr, int rule_cnt)
886{
Yuval Mintz86564c32013-01-23 03:21:50 +0000887 hdr->echo = cpu_to_le32((cid & BNX2X_SWCID_MASK) |
888 (type << BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300889 hdr->rule_cnt = (u8)rule_cnt;
890}
891
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300892/* hw_config() callbacks */
893static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
894 struct bnx2x_vlan_mac_obj *o,
895 struct bnx2x_exeq_elem *elem, int rule_idx,
896 int cam_offset)
897{
898 struct bnx2x_raw_obj *raw = &o->raw;
899 struct eth_classify_rules_ramrod_data *data =
900 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
901 int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
902 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
903 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
904 unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
905 u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
906
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000907 /* Set LLH CAM entry: currently only iSCSI and ETH macs are
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300908 * relevant. In addition, current implementation is tuned for a
909 * single ETH MAC.
910 *
911 * When multiple unicast ETH MACs PF configuration in switch
912 * independent mode is required (NetQ, multiple netdev MACs,
913 * etc.), consider better utilisation of 8 per function MAC
914 * entries in the LLH register. There is also
915 * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
916 * total number of CAM entries to 16.
917 *
918 * Currently we won't configure NIG for MACs other than a primary ETH
919 * MAC and iSCSI L2 MAC.
920 *
921 * If this MAC is moving from one Queue to another, no need to change
922 * NIG configuration.
923 */
924 if (cmd != BNX2X_VLAN_MAC_MOVE) {
925 if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
926 bnx2x_set_mac_in_nig(bp, add, mac,
Yuval Mintz0a52fd02012-03-12 08:53:07 +0000927 BNX2X_LLH_CAM_ISCSI_ETH_LINE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300928 else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
Yuval Mintz0a52fd02012-03-12 08:53:07 +0000929 bnx2x_set_mac_in_nig(bp, add, mac,
930 BNX2X_LLH_CAM_ETH_LINE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300931 }
932
933 /* Reset the ramrod data buffer for the first rule */
934 if (rule_idx == 0)
935 memset(data, 0, sizeof(*data));
936
937 /* Setup a command header */
938 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
939 &rule_entry->mac.header);
940
Joe Perches0f9dad12011-08-14 12:16:19 +0000941 DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +0000942 (add ? "add" : "delete"), mac, raw->cl_id);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300943
944 /* Set a MAC itself */
945 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
946 &rule_entry->mac.mac_mid,
947 &rule_entry->mac.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +0000948 rule_entry->mac.inner_mac =
949 cpu_to_le16(elem->cmd_data.vlan_mac.u.mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300950
951 /* MOVE: Add a rule that will add this MAC to the target Queue */
952 if (cmd == BNX2X_VLAN_MAC_MOVE) {
953 rule_entry++;
954 rule_cnt++;
955
956 /* Setup ramrod data */
957 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
958 elem->cmd_data.vlan_mac.target_obj,
959 true, CLASSIFY_RULE_OPCODE_MAC,
960 &rule_entry->mac.header);
961
962 /* Set a MAC itself */
963 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
964 &rule_entry->mac.mac_mid,
965 &rule_entry->mac.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +0000966 rule_entry->mac.inner_mac =
967 cpu_to_le16(elem->cmd_data.vlan_mac.
968 u.mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300969 }
970
971 /* Set the ramrod data header */
972 /* TODO: take this to the higher level in order to prevent multiple
973 writing */
974 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
975 rule_cnt);
976}
977
978/**
979 * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
980 *
981 * @bp: device handle
982 * @o: queue
983 * @type:
984 * @cam_offset: offset in cam memory
985 * @hdr: pointer to a header to setup
986 *
987 * E1/E1H
988 */
989static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
990 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
991 struct mac_configuration_hdr *hdr)
992{
993 struct bnx2x_raw_obj *r = &o->raw;
994
995 hdr->length = 1;
996 hdr->offset = (u8)cam_offset;
Yuval Mintz86564c32013-01-23 03:21:50 +0000997 hdr->client_id = cpu_to_le16(0xff);
998 hdr->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
999 (type << BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001000}
1001
1002static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
1003 struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
1004 u16 vlan_id, struct mac_configuration_entry *cfg_entry)
1005{
1006 struct bnx2x_raw_obj *r = &o->raw;
1007 u32 cl_bit_vec = (1 << r->cl_id);
1008
1009 cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
1010 cfg_entry->pf_id = r->func_id;
1011 cfg_entry->vlan_id = cpu_to_le16(vlan_id);
1012
1013 if (add) {
1014 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
1015 T_ETH_MAC_COMMAND_SET);
1016 SET_FLAG(cfg_entry->flags,
1017 MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
1018
1019 /* Set a MAC in a ramrod data */
1020 bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
1021 &cfg_entry->middle_mac_addr,
1022 &cfg_entry->lsb_mac_addr, mac);
1023 } else
1024 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
1025 T_ETH_MAC_COMMAND_INVALIDATE);
1026}
1027
1028static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
1029 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
1030 u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
1031{
1032 struct mac_configuration_entry *cfg_entry = &config->config_table[0];
1033 struct bnx2x_raw_obj *raw = &o->raw;
1034
1035 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
1036 &config->hdr);
1037 bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
1038 cfg_entry);
1039
Joe Perches0f9dad12011-08-14 12:16:19 +00001040 DP(BNX2X_MSG_SP, "%s MAC %pM CLID %d CAM offset %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00001041 (add ? "setting" : "clearing"),
Joe Perches0f9dad12011-08-14 12:16:19 +00001042 mac, raw->cl_id, cam_offset);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001043}
1044
1045/**
1046 * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
1047 *
1048 * @bp: device handle
1049 * @o: bnx2x_vlan_mac_obj
1050 * @elem: bnx2x_exeq_elem
1051 * @rule_idx: rule_idx
1052 * @cam_offset: cam_offset
1053 */
1054static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
1055 struct bnx2x_vlan_mac_obj *o,
1056 struct bnx2x_exeq_elem *elem, int rule_idx,
1057 int cam_offset)
1058{
1059 struct bnx2x_raw_obj *raw = &o->raw;
1060 struct mac_configuration_cmd *config =
1061 (struct mac_configuration_cmd *)(raw->rdata);
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001062 /* 57710 and 57711 do not support MOVE command,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001063 * so it's either ADD or DEL
1064 */
1065 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1066 true : false;
1067
1068 /* Reset the ramrod data buffer */
1069 memset(config, 0, sizeof(*config));
1070
Yuval Mintz33ac3382012-03-12 08:53:09 +00001071 bnx2x_vlan_mac_set_rdata_e1x(bp, o, raw->state,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001072 cam_offset, add,
1073 elem->cmd_data.vlan_mac.u.mac.mac, 0,
1074 ETH_VLAN_FILTER_ANY_VLAN, config);
1075}
1076
1077static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
1078 struct bnx2x_vlan_mac_obj *o,
1079 struct bnx2x_exeq_elem *elem, int rule_idx,
1080 int cam_offset)
1081{
1082 struct bnx2x_raw_obj *raw = &o->raw;
1083 struct eth_classify_rules_ramrod_data *data =
1084 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
1085 int rule_cnt = rule_idx + 1;
1086 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
Yuval Mintz86564c32013-01-23 03:21:50 +00001087 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001088 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
1089 u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
1090
1091 /* Reset the ramrod data buffer for the first rule */
1092 if (rule_idx == 0)
1093 memset(data, 0, sizeof(*data));
1094
1095 /* Set a rule header */
1096 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
1097 &rule_entry->vlan.header);
1098
1099 DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
1100 vlan);
1101
1102 /* Set a VLAN itself */
1103 rule_entry->vlan.vlan = cpu_to_le16(vlan);
1104
1105 /* MOVE: Add a rule that will add this MAC to the target Queue */
1106 if (cmd == BNX2X_VLAN_MAC_MOVE) {
1107 rule_entry++;
1108 rule_cnt++;
1109
1110 /* Setup ramrod data */
1111 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
1112 elem->cmd_data.vlan_mac.target_obj,
1113 true, CLASSIFY_RULE_OPCODE_VLAN,
1114 &rule_entry->vlan.header);
1115
1116 /* Set a VLAN itself */
1117 rule_entry->vlan.vlan = cpu_to_le16(vlan);
1118 }
1119
1120 /* Set the ramrod data header */
1121 /* TODO: take this to the higher level in order to prevent multiple
1122 writing */
1123 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
1124 rule_cnt);
1125}
1126
1127static void bnx2x_set_one_vlan_mac_e2(struct bnx2x *bp,
1128 struct bnx2x_vlan_mac_obj *o,
1129 struct bnx2x_exeq_elem *elem,
1130 int rule_idx, int cam_offset)
1131{
1132 struct bnx2x_raw_obj *raw = &o->raw;
1133 struct eth_classify_rules_ramrod_data *data =
1134 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
1135 int rule_cnt = rule_idx + 1;
1136 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
Yuval Mintz86564c32013-01-23 03:21:50 +00001137 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001138 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
1139 u16 vlan = elem->cmd_data.vlan_mac.u.vlan_mac.vlan;
1140 u8 *mac = elem->cmd_data.vlan_mac.u.vlan_mac.mac;
1141
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001142 /* Reset the ramrod data buffer for the first rule */
1143 if (rule_idx == 0)
1144 memset(data, 0, sizeof(*data));
1145
1146 /* Set a rule header */
1147 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
1148 &rule_entry->pair.header);
1149
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001150 /* Set VLAN and MAC themselves */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001151 rule_entry->pair.vlan = cpu_to_le16(vlan);
1152 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
1153 &rule_entry->pair.mac_mid,
1154 &rule_entry->pair.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +00001155 rule_entry->pair.inner_mac =
1156 cpu_to_le16(elem->cmd_data.vlan_mac.u.vlan_mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001157 /* MOVE: Add a rule that will add this MAC to the target Queue */
1158 if (cmd == BNX2X_VLAN_MAC_MOVE) {
1159 rule_entry++;
1160 rule_cnt++;
1161
1162 /* Setup ramrod data */
1163 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
1164 elem->cmd_data.vlan_mac.target_obj,
1165 true, CLASSIFY_RULE_OPCODE_PAIR,
1166 &rule_entry->pair.header);
1167
1168 /* Set a VLAN itself */
1169 rule_entry->pair.vlan = cpu_to_le16(vlan);
1170 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
1171 &rule_entry->pair.mac_mid,
1172 &rule_entry->pair.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +00001173 rule_entry->pair.inner_mac =
1174 cpu_to_le16(elem->cmd_data.vlan_mac.u.
1175 vlan_mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001176 }
1177
1178 /* Set the ramrod data header */
1179 /* TODO: take this to the higher level in order to prevent multiple
1180 writing */
1181 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
1182 rule_cnt);
1183}
1184
1185/**
1186 * bnx2x_set_one_vlan_mac_e1h -
1187 *
1188 * @bp: device handle
1189 * @o: bnx2x_vlan_mac_obj
1190 * @elem: bnx2x_exeq_elem
1191 * @rule_idx: rule_idx
1192 * @cam_offset: cam_offset
1193 */
1194static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
1195 struct bnx2x_vlan_mac_obj *o,
1196 struct bnx2x_exeq_elem *elem,
1197 int rule_idx, int cam_offset)
1198{
1199 struct bnx2x_raw_obj *raw = &o->raw;
1200 struct mac_configuration_cmd *config =
1201 (struct mac_configuration_cmd *)(raw->rdata);
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001202 /* 57710 and 57711 do not support MOVE command,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001203 * so it's either ADD or DEL
1204 */
1205 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1206 true : false;
1207
1208 /* Reset the ramrod data buffer */
1209 memset(config, 0, sizeof(*config));
1210
1211 bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_VLAN_MAC_PENDING,
1212 cam_offset, add,
1213 elem->cmd_data.vlan_mac.u.vlan_mac.mac,
1214 elem->cmd_data.vlan_mac.u.vlan_mac.vlan,
1215 ETH_VLAN_FILTER_CLASSIFY, config);
1216}
1217
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001218/**
1219 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1220 *
1221 * @bp: device handle
1222 * @p: command parameters
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001223 * @ppos: pointer to the cookie
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001224 *
1225 * reconfigure next MAC/VLAN/VLAN-MAC element from the
1226 * previously configured elements list.
1227 *
1228 * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
1229 * into an account
1230 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001231 * pointer to the cookie - that should be given back in the next call to make
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001232 * function handle the next element. If *ppos is set to NULL it will restart the
1233 * iterator. If returned *ppos == NULL this means that the last element has been
1234 * handled.
1235 *
1236 */
1237static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
1238 struct bnx2x_vlan_mac_ramrod_params *p,
1239 struct bnx2x_vlan_mac_registry_elem **ppos)
1240{
1241 struct bnx2x_vlan_mac_registry_elem *pos;
1242 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1243
1244 /* If list is empty - there is nothing to do here */
1245 if (list_empty(&o->head)) {
1246 *ppos = NULL;
1247 return 0;
1248 }
1249
1250 /* make a step... */
1251 if (*ppos == NULL)
1252 *ppos = list_first_entry(&o->head,
1253 struct bnx2x_vlan_mac_registry_elem,
1254 link);
1255 else
1256 *ppos = list_next_entry(*ppos, link);
1257
1258 pos = *ppos;
1259
1260 /* If it's the last step - return NULL */
1261 if (list_is_last(&pos->link, &o->head))
1262 *ppos = NULL;
1263
1264 /* Prepare a 'user_req' */
1265 memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
1266
1267 /* Set the command */
1268 p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
1269
1270 /* Set vlan_mac_flags */
1271 p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
1272
1273 /* Set a restore bit */
1274 __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
1275
1276 return bnx2x_config_vlan_mac(bp, p);
1277}
1278
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001279/* bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001280 * pointer to an element with a specific criteria and NULL if such an element
1281 * hasn't been found.
1282 */
1283static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
1284 struct bnx2x_exe_queue_obj *o,
1285 struct bnx2x_exeq_elem *elem)
1286{
1287 struct bnx2x_exeq_elem *pos;
1288 struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
1289
1290 /* Check pending for execution commands */
1291 list_for_each_entry(pos, &o->exe_queue, link)
1292 if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
1293 sizeof(*data)) &&
1294 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1295 return pos;
1296
1297 return NULL;
1298}
1299
1300static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
1301 struct bnx2x_exe_queue_obj *o,
1302 struct bnx2x_exeq_elem *elem)
1303{
1304 struct bnx2x_exeq_elem *pos;
1305 struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
1306
1307 /* Check pending for execution commands */
1308 list_for_each_entry(pos, &o->exe_queue, link)
1309 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
1310 sizeof(*data)) &&
1311 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1312 return pos;
1313
1314 return NULL;
1315}
1316
1317static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan_mac(
1318 struct bnx2x_exe_queue_obj *o,
1319 struct bnx2x_exeq_elem *elem)
1320{
1321 struct bnx2x_exeq_elem *pos;
1322 struct bnx2x_vlan_mac_ramrod_data *data =
1323 &elem->cmd_data.vlan_mac.u.vlan_mac;
1324
1325 /* Check pending for execution commands */
1326 list_for_each_entry(pos, &o->exe_queue, link)
1327 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan_mac, data,
1328 sizeof(*data)) &&
1329 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1330 return pos;
1331
1332 return NULL;
1333}
1334
1335/**
1336 * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
1337 *
1338 * @bp: device handle
1339 * @qo: bnx2x_qable_obj
1340 * @elem: bnx2x_exeq_elem
1341 *
1342 * Checks that the requested configuration can be added. If yes and if
1343 * requested, consume CAM credit.
1344 *
1345 * The 'validate' is run after the 'optimize'.
1346 *
1347 */
1348static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
1349 union bnx2x_qable_obj *qo,
1350 struct bnx2x_exeq_elem *elem)
1351{
1352 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1353 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1354 int rc;
1355
1356 /* Check the registry */
Merav Sicron51c1a582012-03-18 10:33:38 +00001357 rc = o->check_add(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001358 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001359 DP(BNX2X_MSG_SP, "ADD command is not allowed considering current registry state.\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001360 return rc;
1361 }
1362
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001363 /* Check if there is a pending ADD command for this
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001364 * MAC/VLAN/VLAN-MAC. Return an error if there is.
1365 */
1366 if (exeq->get(exeq, elem)) {
1367 DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
1368 return -EEXIST;
1369 }
1370
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001371 /* TODO: Check the pending MOVE from other objects where this
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001372 * object is a destination object.
1373 */
1374
1375 /* Consume the credit if not requested not to */
1376 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1377 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1378 o->get_credit(o)))
1379 return -EINVAL;
1380
1381 return 0;
1382}
1383
1384/**
1385 * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
1386 *
1387 * @bp: device handle
1388 * @qo: quable object to check
1389 * @elem: element that needs to be deleted
1390 *
1391 * Checks that the requested configuration can be deleted. If yes and if
1392 * requested, returns a CAM credit.
1393 *
1394 * The 'validate' is run after the 'optimize'.
1395 */
1396static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
1397 union bnx2x_qable_obj *qo,
1398 struct bnx2x_exeq_elem *elem)
1399{
1400 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1401 struct bnx2x_vlan_mac_registry_elem *pos;
1402 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1403 struct bnx2x_exeq_elem query_elem;
1404
1405 /* If this classification can not be deleted (doesn't exist)
1406 * - return a BNX2X_EXIST.
1407 */
Merav Sicron51c1a582012-03-18 10:33:38 +00001408 pos = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001409 if (!pos) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001410 DP(BNX2X_MSG_SP, "DEL command is not allowed considering current registry state\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001411 return -EEXIST;
1412 }
1413
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001414 /* Check if there are pending DEL or MOVE commands for this
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001415 * MAC/VLAN/VLAN-MAC. Return an error if so.
1416 */
1417 memcpy(&query_elem, elem, sizeof(query_elem));
1418
1419 /* Check for MOVE commands */
1420 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
1421 if (exeq->get(exeq, &query_elem)) {
1422 BNX2X_ERR("There is a pending MOVE command already\n");
1423 return -EINVAL;
1424 }
1425
1426 /* Check for DEL commands */
1427 if (exeq->get(exeq, elem)) {
1428 DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
1429 return -EEXIST;
1430 }
1431
1432 /* Return the credit to the credit pool if not requested not to */
1433 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1434 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1435 o->put_credit(o))) {
1436 BNX2X_ERR("Failed to return a credit\n");
1437 return -EINVAL;
1438 }
1439
1440 return 0;
1441}
1442
1443/**
1444 * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
1445 *
1446 * @bp: device handle
1447 * @qo: quable object to check (source)
1448 * @elem: element that needs to be moved
1449 *
1450 * Checks that the requested configuration can be moved. If yes and if
1451 * requested, returns a CAM credit.
1452 *
1453 * The 'validate' is run after the 'optimize'.
1454 */
1455static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
1456 union bnx2x_qable_obj *qo,
1457 struct bnx2x_exeq_elem *elem)
1458{
1459 struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
1460 struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
1461 struct bnx2x_exeq_elem query_elem;
1462 struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
1463 struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
1464
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001465 /* Check if we can perform this operation based on the current registry
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001466 * state.
1467 */
Merav Sicron51c1a582012-03-18 10:33:38 +00001468 if (!src_o->check_move(bp, src_o, dest_o,
1469 &elem->cmd_data.vlan_mac.u)) {
1470 DP(BNX2X_MSG_SP, "MOVE command is not allowed considering current registry state\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001471 return -EINVAL;
1472 }
1473
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001474 /* Check if there is an already pending DEL or MOVE command for the
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001475 * source object or ADD command for a destination object. Return an
1476 * error if so.
1477 */
1478 memcpy(&query_elem, elem, sizeof(query_elem));
1479
1480 /* Check DEL on source */
1481 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1482 if (src_exeq->get(src_exeq, &query_elem)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001483 BNX2X_ERR("There is a pending DEL command on the source queue already\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001484 return -EINVAL;
1485 }
1486
1487 /* Check MOVE on source */
1488 if (src_exeq->get(src_exeq, elem)) {
1489 DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
1490 return -EEXIST;
1491 }
1492
1493 /* Check ADD on destination */
1494 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1495 if (dest_exeq->get(dest_exeq, &query_elem)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001496 BNX2X_ERR("There is a pending ADD command on the destination queue already\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001497 return -EINVAL;
1498 }
1499
1500 /* Consume the credit if not requested not to */
1501 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
1502 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1503 dest_o->get_credit(dest_o)))
1504 return -EINVAL;
1505
1506 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1507 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1508 src_o->put_credit(src_o))) {
1509 /* return the credit taken from dest... */
1510 dest_o->put_credit(dest_o);
1511 return -EINVAL;
1512 }
1513
1514 return 0;
1515}
1516
1517static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
1518 union bnx2x_qable_obj *qo,
1519 struct bnx2x_exeq_elem *elem)
1520{
1521 switch (elem->cmd_data.vlan_mac.cmd) {
1522 case BNX2X_VLAN_MAC_ADD:
1523 return bnx2x_validate_vlan_mac_add(bp, qo, elem);
1524 case BNX2X_VLAN_MAC_DEL:
1525 return bnx2x_validate_vlan_mac_del(bp, qo, elem);
1526 case BNX2X_VLAN_MAC_MOVE:
1527 return bnx2x_validate_vlan_mac_move(bp, qo, elem);
1528 default:
1529 return -EINVAL;
1530 }
1531}
1532
Yuval Mintz460a25c2012-01-23 07:31:51 +00001533static int bnx2x_remove_vlan_mac(struct bnx2x *bp,
1534 union bnx2x_qable_obj *qo,
1535 struct bnx2x_exeq_elem *elem)
1536{
1537 int rc = 0;
1538
1539 /* If consumption wasn't required, nothing to do */
1540 if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1541 &elem->cmd_data.vlan_mac.vlan_mac_flags))
1542 return 0;
1543
1544 switch (elem->cmd_data.vlan_mac.cmd) {
1545 case BNX2X_VLAN_MAC_ADD:
1546 case BNX2X_VLAN_MAC_MOVE:
1547 rc = qo->vlan_mac.put_credit(&qo->vlan_mac);
1548 break;
1549 case BNX2X_VLAN_MAC_DEL:
1550 rc = qo->vlan_mac.get_credit(&qo->vlan_mac);
1551 break;
1552 default:
1553 return -EINVAL;
1554 }
1555
1556 if (rc != true)
1557 return -EINVAL;
1558
1559 return 0;
1560}
1561
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001562/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001563 * bnx2x_wait_vlan_mac - passively wait for 5 seconds until all work completes.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001564 *
1565 * @bp: device handle
1566 * @o: bnx2x_vlan_mac_obj
1567 *
1568 */
1569static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
1570 struct bnx2x_vlan_mac_obj *o)
1571{
1572 int cnt = 5000, rc;
1573 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1574 struct bnx2x_raw_obj *raw = &o->raw;
1575
1576 while (cnt--) {
1577 /* Wait for the current command to complete */
1578 rc = raw->wait_comp(bp, raw);
1579 if (rc)
1580 return rc;
1581
1582 /* Wait until there are no pending commands */
1583 if (!bnx2x_exe_queue_empty(exeq))
Yuval Mintz0926d492013-01-23 03:21:45 +00001584 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001585 else
1586 return 0;
1587 }
1588
1589 return -EBUSY;
1590}
1591
Yuval Mintz8b09be52013-08-01 17:30:59 +03001592static int __bnx2x_vlan_mac_execute_step(struct bnx2x *bp,
1593 struct bnx2x_vlan_mac_obj *o,
1594 unsigned long *ramrod_flags)
1595{
1596 int rc = 0;
1597
1598 spin_lock_bh(&o->exe_queue.lock);
1599
1600 DP(BNX2X_MSG_SP, "vlan_mac_execute_step - trying to take writer lock\n");
1601 rc = __bnx2x_vlan_mac_h_write_trylock(bp, o);
1602
1603 if (rc != 0) {
1604 __bnx2x_vlan_mac_h_pend(bp, o, *ramrod_flags);
1605
1606 /* Calling function should not diffrentiate between this case
1607 * and the case in which there is already a pending ramrod
1608 */
1609 rc = 1;
1610 } else {
1611 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1612 }
1613 spin_unlock_bh(&o->exe_queue.lock);
1614
1615 return rc;
1616}
1617
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001618/**
1619 * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
1620 *
1621 * @bp: device handle
1622 * @o: bnx2x_vlan_mac_obj
1623 * @cqe:
1624 * @cont: if true schedule next execution chunk
1625 *
1626 */
1627static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
1628 struct bnx2x_vlan_mac_obj *o,
1629 union event_ring_elem *cqe,
1630 unsigned long *ramrod_flags)
1631{
1632 struct bnx2x_raw_obj *r = &o->raw;
1633 int rc;
1634
Yuval Mintz8b09be52013-08-01 17:30:59 +03001635 /* Clearing the pending list & raw state should be made
1636 * atomically (as execution flow assumes they represent the same).
1637 */
1638 spin_lock_bh(&o->exe_queue.lock);
1639
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001640 /* Reset pending list */
Yuval Mintz8b09be52013-08-01 17:30:59 +03001641 __bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001642
1643 /* Clear pending */
1644 r->clear_pending(r);
1645
Yuval Mintz8b09be52013-08-01 17:30:59 +03001646 spin_unlock_bh(&o->exe_queue.lock);
1647
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001648 /* If ramrod failed this is most likely a SW bug */
1649 if (cqe->message.error)
1650 return -EINVAL;
1651
Yuval Mintz2de67432013-01-23 03:21:43 +00001652 /* Run the next bulk of pending commands if requested */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001653 if (test_bit(RAMROD_CONT, ramrod_flags)) {
Yuval Mintz8b09be52013-08-01 17:30:59 +03001654 rc = __bnx2x_vlan_mac_execute_step(bp, o, ramrod_flags);
1655
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001656 if (rc < 0)
1657 return rc;
1658 }
1659
1660 /* If there is more work to do return PENDING */
1661 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1662 return 1;
1663
1664 return 0;
1665}
1666
1667/**
1668 * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
1669 *
1670 * @bp: device handle
1671 * @o: bnx2x_qable_obj
1672 * @elem: bnx2x_exeq_elem
1673 */
1674static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
1675 union bnx2x_qable_obj *qo,
1676 struct bnx2x_exeq_elem *elem)
1677{
1678 struct bnx2x_exeq_elem query, *pos;
1679 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1680 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1681
1682 memcpy(&query, elem, sizeof(query));
1683
1684 switch (elem->cmd_data.vlan_mac.cmd) {
1685 case BNX2X_VLAN_MAC_ADD:
1686 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1687 break;
1688 case BNX2X_VLAN_MAC_DEL:
1689 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1690 break;
1691 default:
1692 /* Don't handle anything other than ADD or DEL */
1693 return 0;
1694 }
1695
1696 /* If we found the appropriate element - delete it */
1697 pos = exeq->get(exeq, &query);
1698 if (pos) {
1699
1700 /* Return the credit of the optimized command */
1701 if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1702 &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
1703 if ((query.cmd_data.vlan_mac.cmd ==
1704 BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001705 BNX2X_ERR("Failed to return the credit for the optimized ADD command\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001706 return -EINVAL;
1707 } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
Merav Sicron51c1a582012-03-18 10:33:38 +00001708 BNX2X_ERR("Failed to recover the credit from the optimized DEL command\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001709 return -EINVAL;
1710 }
1711 }
1712
1713 DP(BNX2X_MSG_SP, "Optimizing %s command\n",
1714 (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1715 "ADD" : "DEL");
1716
1717 list_del(&pos->link);
1718 bnx2x_exe_queue_free_elem(bp, pos);
1719 return 1;
1720 }
1721
1722 return 0;
1723}
1724
1725/**
1726 * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
1727 *
1728 * @bp: device handle
1729 * @o:
1730 * @elem:
1731 * @restore:
1732 * @re:
1733 *
1734 * prepare a registry element according to the current command request.
1735 */
1736static inline int bnx2x_vlan_mac_get_registry_elem(
1737 struct bnx2x *bp,
1738 struct bnx2x_vlan_mac_obj *o,
1739 struct bnx2x_exeq_elem *elem,
1740 bool restore,
1741 struct bnx2x_vlan_mac_registry_elem **re)
1742{
Yuval Mintz86564c32013-01-23 03:21:50 +00001743 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001744 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1745
1746 /* Allocate a new registry element if needed. */
1747 if (!restore &&
1748 ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
1749 reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
1750 if (!reg_elem)
1751 return -ENOMEM;
1752
1753 /* Get a new CAM offset */
1754 if (!o->get_cam_offset(o, &reg_elem->cam_offset)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001755 /* This shall never happen, because we have checked the
1756 * CAM availability in the 'validate'.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001757 */
1758 WARN_ON(1);
1759 kfree(reg_elem);
1760 return -EINVAL;
1761 }
1762
1763 DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
1764
1765 /* Set a VLAN-MAC data */
1766 memcpy(&reg_elem->u, &elem->cmd_data.vlan_mac.u,
1767 sizeof(reg_elem->u));
1768
1769 /* Copy the flags (needed for DEL and RESTORE flows) */
1770 reg_elem->vlan_mac_flags =
1771 elem->cmd_data.vlan_mac.vlan_mac_flags;
1772 } else /* DEL, RESTORE */
Merav Sicron51c1a582012-03-18 10:33:38 +00001773 reg_elem = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001774
1775 *re = reg_elem;
1776 return 0;
1777}
1778
1779/**
1780 * bnx2x_execute_vlan_mac - execute vlan mac command
1781 *
1782 * @bp: device handle
1783 * @qo:
1784 * @exe_chunk:
1785 * @ramrod_flags:
1786 *
1787 * go and send a ramrod!
1788 */
1789static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
1790 union bnx2x_qable_obj *qo,
1791 struct list_head *exe_chunk,
1792 unsigned long *ramrod_flags)
1793{
1794 struct bnx2x_exeq_elem *elem;
1795 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
1796 struct bnx2x_raw_obj *r = &o->raw;
1797 int rc, idx = 0;
1798 bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
1799 bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
1800 struct bnx2x_vlan_mac_registry_elem *reg_elem;
Yuval Mintz86564c32013-01-23 03:21:50 +00001801 enum bnx2x_vlan_mac_cmd cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001802
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001803 /* If DRIVER_ONLY execution is requested, cleanup a registry
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001804 * and exit. Otherwise send a ramrod to FW.
1805 */
1806 if (!drv_only) {
1807 WARN_ON(r->check_pending(r));
1808
1809 /* Set pending */
1810 r->set_pending(r);
1811
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001812 /* Fill the ramrod data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001813 list_for_each_entry(elem, exe_chunk, link) {
1814 cmd = elem->cmd_data.vlan_mac.cmd;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001815 /* We will add to the target object in MOVE command, so
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001816 * change the object for a CAM search.
1817 */
1818 if (cmd == BNX2X_VLAN_MAC_MOVE)
1819 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1820 else
1821 cam_obj = o;
1822
1823 rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
1824 elem, restore,
1825 &reg_elem);
1826 if (rc)
1827 goto error_exit;
1828
1829 WARN_ON(!reg_elem);
1830
1831 /* Push a new entry into the registry */
1832 if (!restore &&
1833 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1834 (cmd == BNX2X_VLAN_MAC_MOVE)))
1835 list_add(&reg_elem->link, &cam_obj->head);
1836
1837 /* Configure a single command in a ramrod data buffer */
1838 o->set_one_rule(bp, o, elem, idx,
1839 reg_elem->cam_offset);
1840
1841 /* MOVE command consumes 2 entries in the ramrod data */
1842 if (cmd == BNX2X_VLAN_MAC_MOVE)
1843 idx += 2;
1844 else
1845 idx++;
1846 }
1847
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001848 /* No need for an explicit memory barrier here as long we would
1849 * need to ensure the ordering of writing to the SPQ element
1850 * and updating of the SPQ producer which involves a memory
1851 * read and we will have to put a full memory barrier there
1852 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00001853 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001854
1855 rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
1856 U64_HI(r->rdata_mapping),
1857 U64_LO(r->rdata_mapping),
1858 ETH_CONNECTION_TYPE);
1859 if (rc)
1860 goto error_exit;
1861 }
1862
1863 /* Now, when we are done with the ramrod - clean up the registry */
1864 list_for_each_entry(elem, exe_chunk, link) {
1865 cmd = elem->cmd_data.vlan_mac.cmd;
1866 if ((cmd == BNX2X_VLAN_MAC_DEL) ||
1867 (cmd == BNX2X_VLAN_MAC_MOVE)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001868 reg_elem = o->check_del(bp, o,
1869 &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001870
1871 WARN_ON(!reg_elem);
1872
1873 o->put_cam_offset(o, reg_elem->cam_offset);
1874 list_del(&reg_elem->link);
1875 kfree(reg_elem);
1876 }
1877 }
1878
1879 if (!drv_only)
1880 return 1;
1881 else
1882 return 0;
1883
1884error_exit:
1885 r->clear_pending(r);
1886
1887 /* Cleanup a registry in case of a failure */
1888 list_for_each_entry(elem, exe_chunk, link) {
1889 cmd = elem->cmd_data.vlan_mac.cmd;
1890
1891 if (cmd == BNX2X_VLAN_MAC_MOVE)
1892 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1893 else
1894 cam_obj = o;
1895
1896 /* Delete all newly added above entries */
1897 if (!restore &&
1898 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1899 (cmd == BNX2X_VLAN_MAC_MOVE))) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001900 reg_elem = o->check_del(bp, cam_obj,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001901 &elem->cmd_data.vlan_mac.u);
1902 if (reg_elem) {
1903 list_del(&reg_elem->link);
1904 kfree(reg_elem);
1905 }
1906 }
1907 }
1908
1909 return rc;
1910}
1911
1912static inline int bnx2x_vlan_mac_push_new_cmd(
1913 struct bnx2x *bp,
1914 struct bnx2x_vlan_mac_ramrod_params *p)
1915{
1916 struct bnx2x_exeq_elem *elem;
1917 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1918 bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
1919
1920 /* Allocate the execution queue element */
1921 elem = bnx2x_exe_queue_alloc_elem(bp);
1922 if (!elem)
1923 return -ENOMEM;
1924
1925 /* Set the command 'length' */
1926 switch (p->user_req.cmd) {
1927 case BNX2X_VLAN_MAC_MOVE:
1928 elem->cmd_len = 2;
1929 break;
1930 default:
1931 elem->cmd_len = 1;
1932 }
1933
1934 /* Fill the object specific info */
1935 memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
1936
1937 /* Try to add a new command to the pending list */
1938 return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
1939}
1940
1941/**
1942 * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
1943 *
1944 * @bp: device handle
1945 * @p:
1946 *
1947 */
Yuval Mintz8b09be52013-08-01 17:30:59 +03001948int bnx2x_config_vlan_mac(struct bnx2x *bp,
1949 struct bnx2x_vlan_mac_ramrod_params *p)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001950{
1951 int rc = 0;
1952 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1953 unsigned long *ramrod_flags = &p->ramrod_flags;
1954 bool cont = test_bit(RAMROD_CONT, ramrod_flags);
1955 struct bnx2x_raw_obj *raw = &o->raw;
1956
1957 /*
1958 * Add new elements to the execution list for commands that require it.
1959 */
1960 if (!cont) {
1961 rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
1962 if (rc)
1963 return rc;
1964 }
1965
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001966 /* If nothing will be executed further in this iteration we want to
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001967 * return PENDING if there are pending commands
1968 */
1969 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1970 rc = 1;
1971
Vladislav Zolotarov79616892011-07-21 07:58:54 +00001972 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001973 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
Vladislav Zolotarov79616892011-07-21 07:58:54 +00001974 raw->clear_pending(raw);
1975 }
1976
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001977 /* Execute commands if required */
1978 if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
1979 test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
Yuval Mintz8b09be52013-08-01 17:30:59 +03001980 rc = __bnx2x_vlan_mac_execute_step(bp, p->vlan_mac_obj,
1981 &p->ramrod_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001982 if (rc < 0)
1983 return rc;
1984 }
1985
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001986 /* RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001987 * then user want to wait until the last command is done.
1988 */
1989 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001990 /* Wait maximum for the current exe_queue length iterations plus
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001991 * one (for the current pending command).
1992 */
1993 int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
1994
1995 while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
1996 max_iterations--) {
1997
1998 /* Wait for the current command to complete */
1999 rc = raw->wait_comp(bp, raw);
2000 if (rc)
2001 return rc;
2002
2003 /* Make a next step */
Yuval Mintz8b09be52013-08-01 17:30:59 +03002004 rc = __bnx2x_vlan_mac_execute_step(bp,
2005 p->vlan_mac_obj,
2006 &p->ramrod_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002007 if (rc < 0)
2008 return rc;
2009 }
2010
2011 return 0;
2012 }
2013
2014 return rc;
2015}
2016
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002017/**
2018 * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
2019 *
2020 * @bp: device handle
2021 * @o:
2022 * @vlan_mac_flags:
2023 * @ramrod_flags: execution flags to be used for this deletion
2024 *
2025 * if the last operation has completed successfully and there are no
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002026 * more elements left, positive value if the last operation has completed
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002027 * successfully and there are more previously configured elements, negative
2028 * value is current operation has failed.
2029 */
2030static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
2031 struct bnx2x_vlan_mac_obj *o,
2032 unsigned long *vlan_mac_flags,
2033 unsigned long *ramrod_flags)
2034{
2035 struct bnx2x_vlan_mac_registry_elem *pos = NULL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002036 struct bnx2x_vlan_mac_ramrod_params p;
2037 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
2038 struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
Yuval Mintz8b09be52013-08-01 17:30:59 +03002039 int read_lock;
2040 int rc = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002041
2042 /* Clear pending commands first */
2043
2044 spin_lock_bh(&exeq->lock);
2045
2046 list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
2047 if (exeq_pos->cmd_data.vlan_mac.vlan_mac_flags ==
Yuval Mintz460a25c2012-01-23 07:31:51 +00002048 *vlan_mac_flags) {
2049 rc = exeq->remove(bp, exeq->owner, exeq_pos);
2050 if (rc) {
2051 BNX2X_ERR("Failed to remove command\n");
Dan Carpentera44acd52012-01-24 21:59:31 +00002052 spin_unlock_bh(&exeq->lock);
Yuval Mintz460a25c2012-01-23 07:31:51 +00002053 return rc;
2054 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002055 list_del(&exeq_pos->link);
Yuval Mintz07ef7be2013-03-11 05:17:41 +00002056 bnx2x_exe_queue_free_elem(bp, exeq_pos);
Yuval Mintz460a25c2012-01-23 07:31:51 +00002057 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002058 }
2059
2060 spin_unlock_bh(&exeq->lock);
2061
2062 /* Prepare a command request */
2063 memset(&p, 0, sizeof(p));
2064 p.vlan_mac_obj = o;
2065 p.ramrod_flags = *ramrod_flags;
2066 p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
2067
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002068 /* Add all but the last VLAN-MAC to the execution queue without actually
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002069 * execution anything.
2070 */
2071 __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
2072 __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
2073 __clear_bit(RAMROD_CONT, &p.ramrod_flags);
2074
Yuval Mintz8b09be52013-08-01 17:30:59 +03002075 DP(BNX2X_MSG_SP, "vlan_mac_del_all -- taking vlan_mac_lock (reader)\n");
2076 read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
2077 if (read_lock != 0)
2078 return read_lock;
2079
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002080 list_for_each_entry(pos, &o->head, link) {
2081 if (pos->vlan_mac_flags == *vlan_mac_flags) {
2082 p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
2083 memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
2084 rc = bnx2x_config_vlan_mac(bp, &p);
2085 if (rc < 0) {
2086 BNX2X_ERR("Failed to add a new DEL command\n");
Yuval Mintz8b09be52013-08-01 17:30:59 +03002087 bnx2x_vlan_mac_h_read_unlock(bp, o);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002088 return rc;
2089 }
2090 }
2091 }
2092
Yuval Mintz8b09be52013-08-01 17:30:59 +03002093 DP(BNX2X_MSG_SP, "vlan_mac_del_all -- releasing vlan_mac_lock (reader)\n");
2094 bnx2x_vlan_mac_h_read_unlock(bp, o);
2095
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002096 p.ramrod_flags = *ramrod_flags;
2097 __set_bit(RAMROD_CONT, &p.ramrod_flags);
2098
2099 return bnx2x_config_vlan_mac(bp, &p);
2100}
2101
2102static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
2103 u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
2104 unsigned long *pstate, bnx2x_obj_type type)
2105{
2106 raw->func_id = func_id;
2107 raw->cid = cid;
2108 raw->cl_id = cl_id;
2109 raw->rdata = rdata;
2110 raw->rdata_mapping = rdata_mapping;
2111 raw->state = state;
2112 raw->pstate = pstate;
2113 raw->obj_type = type;
2114 raw->check_pending = bnx2x_raw_check_pending;
2115 raw->clear_pending = bnx2x_raw_clear_pending;
2116 raw->set_pending = bnx2x_raw_set_pending;
2117 raw->wait_comp = bnx2x_raw_wait;
2118}
2119
2120static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
2121 u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
2122 int state, unsigned long *pstate, bnx2x_obj_type type,
2123 struct bnx2x_credit_pool_obj *macs_pool,
2124 struct bnx2x_credit_pool_obj *vlans_pool)
2125{
2126 INIT_LIST_HEAD(&o->head);
Yuval Mintz8b09be52013-08-01 17:30:59 +03002127 o->head_reader = 0;
2128 o->head_exe_request = false;
2129 o->saved_ramrod_flags = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002130
2131 o->macs_pool = macs_pool;
2132 o->vlans_pool = vlans_pool;
2133
2134 o->delete_all = bnx2x_vlan_mac_del_all;
2135 o->restore = bnx2x_vlan_mac_restore;
2136 o->complete = bnx2x_complete_vlan_mac;
2137 o->wait = bnx2x_wait_vlan_mac;
2138
2139 bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
2140 state, pstate, type);
2141}
2142
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002143void bnx2x_init_mac_obj(struct bnx2x *bp,
2144 struct bnx2x_vlan_mac_obj *mac_obj,
2145 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2146 dma_addr_t rdata_mapping, int state,
2147 unsigned long *pstate, bnx2x_obj_type type,
2148 struct bnx2x_credit_pool_obj *macs_pool)
2149{
2150 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
2151
2152 bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
2153 rdata_mapping, state, pstate, type,
2154 macs_pool, NULL);
2155
2156 /* CAM credit pool handling */
2157 mac_obj->get_credit = bnx2x_get_credit_mac;
2158 mac_obj->put_credit = bnx2x_put_credit_mac;
2159 mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
2160 mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
2161
2162 if (CHIP_IS_E1x(bp)) {
2163 mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
2164 mac_obj->check_del = bnx2x_check_mac_del;
2165 mac_obj->check_add = bnx2x_check_mac_add;
2166 mac_obj->check_move = bnx2x_check_move_always_err;
2167 mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
2168
2169 /* Exe Queue */
2170 bnx2x_exe_queue_init(bp,
2171 &mac_obj->exe_queue, 1, qable_obj,
2172 bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002173 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002174 bnx2x_optimize_vlan_mac,
2175 bnx2x_execute_vlan_mac,
2176 bnx2x_exeq_get_mac);
2177 } else {
2178 mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
2179 mac_obj->check_del = bnx2x_check_mac_del;
2180 mac_obj->check_add = bnx2x_check_mac_add;
2181 mac_obj->check_move = bnx2x_check_move;
2182 mac_obj->ramrod_cmd =
2183 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
Ariel Eliored5162a2011-12-05 21:52:24 +00002184 mac_obj->get_n_elements = bnx2x_get_n_elements;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002185
2186 /* Exe Queue */
2187 bnx2x_exe_queue_init(bp,
2188 &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
2189 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002190 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002191 bnx2x_optimize_vlan_mac,
2192 bnx2x_execute_vlan_mac,
2193 bnx2x_exeq_get_mac);
2194 }
2195}
2196
2197void bnx2x_init_vlan_obj(struct bnx2x *bp,
2198 struct bnx2x_vlan_mac_obj *vlan_obj,
2199 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2200 dma_addr_t rdata_mapping, int state,
2201 unsigned long *pstate, bnx2x_obj_type type,
2202 struct bnx2x_credit_pool_obj *vlans_pool)
2203{
2204 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
2205
2206 bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
2207 rdata_mapping, state, pstate, type, NULL,
2208 vlans_pool);
2209
2210 vlan_obj->get_credit = bnx2x_get_credit_vlan;
2211 vlan_obj->put_credit = bnx2x_put_credit_vlan;
2212 vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
2213 vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
2214
2215 if (CHIP_IS_E1x(bp)) {
2216 BNX2X_ERR("Do not support chips others than E2 and newer\n");
2217 BUG();
2218 } else {
2219 vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
2220 vlan_obj->check_del = bnx2x_check_vlan_del;
2221 vlan_obj->check_add = bnx2x_check_vlan_add;
2222 vlan_obj->check_move = bnx2x_check_move;
2223 vlan_obj->ramrod_cmd =
2224 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00002225 vlan_obj->get_n_elements = bnx2x_get_n_elements;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002226
2227 /* Exe Queue */
2228 bnx2x_exe_queue_init(bp,
2229 &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
2230 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002231 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002232 bnx2x_optimize_vlan_mac,
2233 bnx2x_execute_vlan_mac,
2234 bnx2x_exeq_get_vlan);
2235 }
2236}
2237
2238void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
2239 struct bnx2x_vlan_mac_obj *vlan_mac_obj,
2240 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2241 dma_addr_t rdata_mapping, int state,
2242 unsigned long *pstate, bnx2x_obj_type type,
2243 struct bnx2x_credit_pool_obj *macs_pool,
2244 struct bnx2x_credit_pool_obj *vlans_pool)
2245{
2246 union bnx2x_qable_obj *qable_obj =
2247 (union bnx2x_qable_obj *)vlan_mac_obj;
2248
2249 bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
2250 rdata_mapping, state, pstate, type,
2251 macs_pool, vlans_pool);
2252
2253 /* CAM pool handling */
2254 vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
2255 vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002256 /* CAM offset is relevant for 57710 and 57711 chips only which have a
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002257 * single CAM for both MACs and VLAN-MAC pairs. So the offset
2258 * will be taken from MACs' pool object only.
2259 */
2260 vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
2261 vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
2262
2263 if (CHIP_IS_E1(bp)) {
2264 BNX2X_ERR("Do not support chips others than E2\n");
2265 BUG();
2266 } else if (CHIP_IS_E1H(bp)) {
2267 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
2268 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2269 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2270 vlan_mac_obj->check_move = bnx2x_check_move_always_err;
2271 vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
2272
2273 /* Exe Queue */
2274 bnx2x_exe_queue_init(bp,
2275 &vlan_mac_obj->exe_queue, 1, qable_obj,
2276 bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002277 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002278 bnx2x_optimize_vlan_mac,
2279 bnx2x_execute_vlan_mac,
2280 bnx2x_exeq_get_vlan_mac);
2281 } else {
2282 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e2;
2283 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2284 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2285 vlan_mac_obj->check_move = bnx2x_check_move;
2286 vlan_mac_obj->ramrod_cmd =
2287 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
2288
2289 /* Exe Queue */
2290 bnx2x_exe_queue_init(bp,
2291 &vlan_mac_obj->exe_queue,
2292 CLASSIFY_RULES_COUNT,
2293 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002294 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002295 bnx2x_optimize_vlan_mac,
2296 bnx2x_execute_vlan_mac,
2297 bnx2x_exeq_get_vlan_mac);
2298 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002299}
2300
2301/* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
2302static inline void __storm_memset_mac_filters(struct bnx2x *bp,
2303 struct tstorm_eth_mac_filter_config *mac_filters,
2304 u16 pf_id)
2305{
2306 size_t size = sizeof(struct tstorm_eth_mac_filter_config);
2307
2308 u32 addr = BAR_TSTRORM_INTMEM +
2309 TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
2310
2311 __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
2312}
2313
2314static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
2315 struct bnx2x_rx_mode_ramrod_params *p)
2316{
Yuval Mintz2de67432013-01-23 03:21:43 +00002317 /* update the bp MAC filter structure */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002318 u32 mask = (1 << p->cl_id);
2319
2320 struct tstorm_eth_mac_filter_config *mac_filters =
2321 (struct tstorm_eth_mac_filter_config *)p->rdata;
2322
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002323 /* initial setting is drop-all */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002324 u8 drop_all_ucast = 1, drop_all_mcast = 1;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002325 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
2326 u8 unmatched_unicast = 0;
2327
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002328 /* In e1x there we only take into account rx accept flag since tx switching
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002329 * isn't enabled. */
2330 if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002331 /* accept matched ucast */
2332 drop_all_ucast = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002333
2334 if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002335 /* accept matched mcast */
2336 drop_all_mcast = 0;
2337
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002338 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002339 /* accept all mcast */
2340 drop_all_ucast = 0;
2341 accp_all_ucast = 1;
2342 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002343 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002344 /* accept all mcast */
2345 drop_all_mcast = 0;
2346 accp_all_mcast = 1;
2347 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002348 if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002349 /* accept (all) bcast */
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002350 accp_all_bcast = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002351 if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
2352 /* accept unmatched unicasts */
2353 unmatched_unicast = 1;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002354
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002355 mac_filters->ucast_drop_all = drop_all_ucast ?
2356 mac_filters->ucast_drop_all | mask :
2357 mac_filters->ucast_drop_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002358
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002359 mac_filters->mcast_drop_all = drop_all_mcast ?
2360 mac_filters->mcast_drop_all | mask :
2361 mac_filters->mcast_drop_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002362
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002363 mac_filters->ucast_accept_all = accp_all_ucast ?
2364 mac_filters->ucast_accept_all | mask :
2365 mac_filters->ucast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002366
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002367 mac_filters->mcast_accept_all = accp_all_mcast ?
2368 mac_filters->mcast_accept_all | mask :
2369 mac_filters->mcast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002370
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002371 mac_filters->bcast_accept_all = accp_all_bcast ?
2372 mac_filters->bcast_accept_all | mask :
2373 mac_filters->bcast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002374
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002375 mac_filters->unmatched_unicast = unmatched_unicast ?
2376 mac_filters->unmatched_unicast | mask :
2377 mac_filters->unmatched_unicast & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002378
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002379 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 +00002380 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00002381 mac_filters->ucast_drop_all, mac_filters->mcast_drop_all,
2382 mac_filters->ucast_accept_all, mac_filters->mcast_accept_all,
2383 mac_filters->bcast_accept_all);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002384
2385 /* write the MAC filter structure*/
2386 __storm_memset_mac_filters(bp, mac_filters, p->func_id);
2387
2388 /* The operation is completed */
2389 clear_bit(p->state, p->pstate);
2390 smp_mb__after_clear_bit();
2391
2392 return 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002393}
2394
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002395/* Setup ramrod data */
2396static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
2397 struct eth_classify_header *hdr,
2398 u8 rule_cnt)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002399{
Yuval Mintz86564c32013-01-23 03:21:50 +00002400 hdr->echo = cpu_to_le32(cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002401 hdr->rule_cnt = rule_cnt;
2402}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002403
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002404static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
Yuval Mintz924d75a2013-01-23 03:21:44 +00002405 unsigned long *accept_flags,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002406 struct eth_filter_rules_cmd *cmd,
2407 bool clear_accept_all)
2408{
2409 u16 state;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002410
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002411 /* start with 'drop-all' */
2412 state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
2413 ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2414
Yuval Mintz924d75a2013-01-23 03:21:44 +00002415 if (test_bit(BNX2X_ACCEPT_UNICAST, accept_flags))
2416 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002417
Yuval Mintz924d75a2013-01-23 03:21:44 +00002418 if (test_bit(BNX2X_ACCEPT_MULTICAST, accept_flags))
2419 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002420
Yuval Mintz924d75a2013-01-23 03:21:44 +00002421 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, accept_flags)) {
2422 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2423 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002424 }
2425
Yuval Mintz924d75a2013-01-23 03:21:44 +00002426 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, accept_flags)) {
2427 state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2428 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2429 }
2430
2431 if (test_bit(BNX2X_ACCEPT_BROADCAST, accept_flags))
2432 state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2433
2434 if (test_bit(BNX2X_ACCEPT_UNMATCHED, accept_flags)) {
2435 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2436 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2437 }
2438
2439 if (test_bit(BNX2X_ACCEPT_ANY_VLAN, accept_flags))
2440 state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
2441
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002442 /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
2443 if (clear_accept_all) {
2444 state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2445 state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2446 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2447 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2448 }
2449
2450 cmd->state = cpu_to_le16(state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002451}
2452
2453static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
2454 struct bnx2x_rx_mode_ramrod_params *p)
2455{
2456 struct eth_filter_rules_ramrod_data *data = p->rdata;
2457 int rc;
2458 u8 rule_idx = 0;
2459
2460 /* Reset the ramrod data buffer */
2461 memset(data, 0, sizeof(*data));
2462
2463 /* Setup ramrod data */
2464
2465 /* Tx (internal switching) */
2466 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2467 data->rules[rule_idx].client_id = p->cl_id;
2468 data->rules[rule_idx].func_id = p->func_id;
2469
2470 data->rules[rule_idx].cmd_general_data =
2471 ETH_FILTER_RULES_CMD_TX_CMD;
2472
Yuval Mintz924d75a2013-01-23 03:21:44 +00002473 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2474 &(data->rules[rule_idx++]),
2475 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002476 }
2477
2478 /* Rx */
2479 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2480 data->rules[rule_idx].client_id = p->cl_id;
2481 data->rules[rule_idx].func_id = p->func_id;
2482
2483 data->rules[rule_idx].cmd_general_data =
2484 ETH_FILTER_RULES_CMD_RX_CMD;
2485
Yuval Mintz924d75a2013-01-23 03:21:44 +00002486 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2487 &(data->rules[rule_idx++]),
2488 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002489 }
2490
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002491 /* If FCoE Queue configuration has been requested configure the Rx and
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002492 * internal switching modes for this queue in separate rules.
2493 *
2494 * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
2495 * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
2496 */
2497 if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
2498 /* Tx (internal switching) */
2499 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2500 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2501 data->rules[rule_idx].func_id = p->func_id;
2502
2503 data->rules[rule_idx].cmd_general_data =
2504 ETH_FILTER_RULES_CMD_TX_CMD;
2505
Yuval Mintz924d75a2013-01-23 03:21:44 +00002506 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2507 &(data->rules[rule_idx]),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002508 true);
Yuval Mintz924d75a2013-01-23 03:21:44 +00002509 rule_idx++;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002510 }
2511
2512 /* Rx */
2513 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2514 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2515 data->rules[rule_idx].func_id = p->func_id;
2516
2517 data->rules[rule_idx].cmd_general_data =
2518 ETH_FILTER_RULES_CMD_RX_CMD;
2519
Yuval Mintz924d75a2013-01-23 03:21:44 +00002520 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2521 &(data->rules[rule_idx]),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002522 true);
Yuval Mintz924d75a2013-01-23 03:21:44 +00002523 rule_idx++;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002524 }
2525 }
2526
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002527 /* Set the ramrod header (most importantly - number of rules to
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002528 * configure).
2529 */
2530 bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
2531
Merav Sicron51c1a582012-03-18 10:33:38 +00002532 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 +03002533 data->header.rule_cnt, p->rx_accept_flags,
2534 p->tx_accept_flags);
2535
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002536 /* No need for an explicit memory barrier here as long we would
2537 * need to ensure the ordering of writing to the SPQ element
2538 * and updating of the SPQ producer which involves a memory
2539 * read and we will have to put a full memory barrier there
2540 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00002541 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002542
2543 /* Send a ramrod */
2544 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
2545 U64_HI(p->rdata_mapping),
2546 U64_LO(p->rdata_mapping),
2547 ETH_CONNECTION_TYPE);
2548 if (rc)
2549 return rc;
2550
2551 /* Ramrod completion is pending */
2552 return 1;
2553}
2554
2555static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
2556 struct bnx2x_rx_mode_ramrod_params *p)
2557{
2558 return bnx2x_state_wait(bp, p->state, p->pstate);
2559}
2560
2561static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
2562 struct bnx2x_rx_mode_ramrod_params *p)
2563{
2564 /* Do nothing */
2565 return 0;
2566}
2567
2568int bnx2x_config_rx_mode(struct bnx2x *bp,
2569 struct bnx2x_rx_mode_ramrod_params *p)
2570{
2571 int rc;
2572
2573 /* Configure the new classification in the chip */
2574 rc = p->rx_mode_obj->config_rx_mode(bp, p);
2575 if (rc < 0)
2576 return rc;
2577
2578 /* Wait for a ramrod completion if was requested */
2579 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
2580 rc = p->rx_mode_obj->wait_comp(bp, p);
2581 if (rc)
2582 return rc;
2583 }
2584
2585 return rc;
2586}
2587
2588void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
2589 struct bnx2x_rx_mode_obj *o)
2590{
2591 if (CHIP_IS_E1x(bp)) {
2592 o->wait_comp = bnx2x_empty_rx_mode_wait;
2593 o->config_rx_mode = bnx2x_set_rx_mode_e1x;
2594 } else {
2595 o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
2596 o->config_rx_mode = bnx2x_set_rx_mode_e2;
2597 }
2598}
2599
2600/********************* Multicast verbs: SET, CLEAR ****************************/
2601static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
2602{
2603 return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
2604}
2605
2606struct bnx2x_mcast_mac_elem {
2607 struct list_head link;
2608 u8 mac[ETH_ALEN];
2609 u8 pad[2]; /* For a natural alignment of the following buffer */
2610};
2611
2612struct bnx2x_pending_mcast_cmd {
2613 struct list_head link;
2614 int type; /* BNX2X_MCAST_CMD_X */
2615 union {
2616 struct list_head macs_head;
2617 u32 macs_num; /* Needed for DEL command */
2618 int next_bin; /* Needed for RESTORE flow with aprox match */
2619 } data;
2620
2621 bool done; /* set to true, when the command has been handled,
2622 * practically used in 57712 handling only, where one pending
2623 * command may be handled in a few operations. As long as for
2624 * other chips every operation handling is completed in a
2625 * single ramrod, there is no need to utilize this field.
2626 */
2627};
2628
2629static int bnx2x_mcast_wait(struct bnx2x *bp,
2630 struct bnx2x_mcast_obj *o)
2631{
2632 if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
2633 o->raw.wait_comp(bp, &o->raw))
2634 return -EBUSY;
2635
2636 return 0;
2637}
2638
2639static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
2640 struct bnx2x_mcast_obj *o,
2641 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00002642 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002643{
2644 int total_sz;
2645 struct bnx2x_pending_mcast_cmd *new_cmd;
2646 struct bnx2x_mcast_mac_elem *cur_mac = NULL;
2647 struct bnx2x_mcast_list_elem *pos;
2648 int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
2649 p->mcast_list_len : 0);
2650
2651 /* If the command is empty ("handle pending commands only"), break */
2652 if (!p->mcast_list_len)
2653 return 0;
2654
2655 total_sz = sizeof(*new_cmd) +
2656 macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
2657
2658 /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
2659 new_cmd = kzalloc(total_sz, GFP_ATOMIC);
2660
2661 if (!new_cmd)
2662 return -ENOMEM;
2663
Merav Sicron51c1a582012-03-18 10:33:38 +00002664 DP(BNX2X_MSG_SP, "About to enqueue a new %d command. macs_list_len=%d\n",
2665 cmd, macs_list_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002666
2667 INIT_LIST_HEAD(&new_cmd->data.macs_head);
2668
2669 new_cmd->type = cmd;
2670 new_cmd->done = false;
2671
2672 switch (cmd) {
2673 case BNX2X_MCAST_CMD_ADD:
2674 cur_mac = (struct bnx2x_mcast_mac_elem *)
2675 ((u8 *)new_cmd + sizeof(*new_cmd));
2676
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002677 /* Push the MACs of the current command into the pending command
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002678 * MACs list: FIFO
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002679 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002680 list_for_each_entry(pos, &p->mcast_list, link) {
2681 memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
2682 list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
2683 cur_mac++;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002684 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002685
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002686 break;
2687
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002688 case BNX2X_MCAST_CMD_DEL:
2689 new_cmd->data.macs_num = p->mcast_list_len;
2690 break;
2691
2692 case BNX2X_MCAST_CMD_RESTORE:
2693 new_cmd->data.next_bin = 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002694 break;
2695
2696 default:
Jesper Juhl8b6d5c02012-07-31 11:39:37 +00002697 kfree(new_cmd);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002698 BNX2X_ERR("Unknown command: %d\n", cmd);
2699 return -EINVAL;
2700 }
2701
2702 /* Push the new pending command to the tail of the pending list: FIFO */
2703 list_add_tail(&new_cmd->link, &o->pending_cmds_head);
2704
2705 o->set_sched(o);
2706
2707 return 1;
2708}
2709
2710/**
2711 * bnx2x_mcast_get_next_bin - get the next set bin (index)
2712 *
2713 * @o:
2714 * @last: index to start looking from (including)
2715 *
2716 * returns the next found (set) bin or a negative value if none is found.
2717 */
2718static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
2719{
2720 int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
2721
2722 for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
2723 if (o->registry.aprox_match.vec[i])
2724 for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
2725 int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
2726 if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
2727 vec, cur_bit)) {
2728 return cur_bit;
2729 }
2730 }
2731 inner_start = 0;
2732 }
2733
2734 /* None found */
2735 return -1;
2736}
2737
2738/**
2739 * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
2740 *
2741 * @o:
2742 *
2743 * returns the index of the found bin or -1 if none is found
2744 */
2745static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
2746{
2747 int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
2748
2749 if (cur_bit >= 0)
2750 BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
2751
2752 return cur_bit;
2753}
2754
2755static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
2756{
2757 struct bnx2x_raw_obj *raw = &o->raw;
2758 u8 rx_tx_flag = 0;
2759
2760 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
2761 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2762 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
2763
2764 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
2765 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2766 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
2767
2768 return rx_tx_flag;
2769}
2770
2771static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
2772 struct bnx2x_mcast_obj *o, int idx,
2773 union bnx2x_mcast_config_data *cfg_data,
Yuval Mintz86564c32013-01-23 03:21:50 +00002774 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002775{
2776 struct bnx2x_raw_obj *r = &o->raw;
2777 struct eth_multicast_rules_ramrod_data *data =
2778 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2779 u8 func_id = r->func_id;
2780 u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
2781 int bin;
2782
2783 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
2784 rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
2785
2786 data->rules[idx].cmd_general_data |= rx_tx_add_flag;
2787
2788 /* Get a bin and update a bins' vector */
2789 switch (cmd) {
2790 case BNX2X_MCAST_CMD_ADD:
2791 bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
2792 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002793 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002794
2795 case BNX2X_MCAST_CMD_DEL:
2796 /* If there were no more bins to clear
2797 * (bnx2x_mcast_clear_first_bin() returns -1) then we would
2798 * clear any (0xff) bin.
2799 * See bnx2x_mcast_validate_e2() for explanation when it may
2800 * happen.
2801 */
2802 bin = bnx2x_mcast_clear_first_bin(o);
2803 break;
2804
2805 case BNX2X_MCAST_CMD_RESTORE:
2806 bin = cfg_data->bin;
2807 break;
2808
2809 default:
2810 BNX2X_ERR("Unknown command: %d\n", cmd);
2811 return;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002812 }
2813
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002814 DP(BNX2X_MSG_SP, "%s bin %d\n",
2815 ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
2816 "Setting" : "Clearing"), bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002817
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002818 data->rules[idx].bin_id = (u8)bin;
2819 data->rules[idx].func_id = func_id;
2820 data->rules[idx].engine_id = o->engine_id;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002821}
2822
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002823/**
2824 * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
2825 *
2826 * @bp: device handle
2827 * @o:
2828 * @start_bin: index in the registry to start from (including)
2829 * @rdata_idx: index in the ramrod data to start from
2830 *
2831 * returns last handled bin index or -1 if all bins have been handled
2832 */
2833static inline int bnx2x_mcast_handle_restore_cmd_e2(
2834 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
2835 int *rdata_idx)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002836{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002837 int cur_bin, cnt = *rdata_idx;
Yuval Mintz86564c32013-01-23 03:21:50 +00002838 union bnx2x_mcast_config_data cfg_data = {NULL};
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002839
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002840 /* go through the registry and configure the bins from it */
2841 for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
2842 cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002843
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002844 cfg_data.bin = (u8)cur_bin;
2845 o->set_one_rule(bp, o, cnt, &cfg_data,
2846 BNX2X_MCAST_CMD_RESTORE);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002847
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002848 cnt++;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002849
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002850 DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002851
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002852 /* Break if we reached the maximum number
2853 * of rules.
2854 */
2855 if (cnt >= o->max_cmd_len)
2856 break;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002857 }
2858
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002859 *rdata_idx = cnt;
2860
2861 return cur_bin;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002862}
2863
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002864static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
2865 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2866 int *line_idx)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002867{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002868 struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
2869 int cnt = *line_idx;
Yuval Mintz86564c32013-01-23 03:21:50 +00002870 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002871
2872 list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
2873 link) {
2874
2875 cfg_data.mac = &pmac_pos->mac[0];
2876 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
2877
2878 cnt++;
2879
Joe Perches0f9dad12011-08-14 12:16:19 +00002880 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00002881 pmac_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002882
2883 list_del(&pmac_pos->link);
2884
2885 /* Break if we reached the maximum number
2886 * of rules.
2887 */
2888 if (cnt >= o->max_cmd_len)
2889 break;
2890 }
2891
2892 *line_idx = cnt;
2893
2894 /* if no more MACs to configure - we are done */
2895 if (list_empty(&cmd_pos->data.macs_head))
2896 cmd_pos->done = true;
2897}
2898
2899static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
2900 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2901 int *line_idx)
2902{
2903 int cnt = *line_idx;
2904
2905 while (cmd_pos->data.macs_num) {
2906 o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
2907
2908 cnt++;
2909
2910 cmd_pos->data.macs_num--;
2911
2912 DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
2913 cmd_pos->data.macs_num, cnt);
2914
2915 /* Break if we reached the maximum
2916 * number of rules.
2917 */
2918 if (cnt >= o->max_cmd_len)
2919 break;
2920 }
2921
2922 *line_idx = cnt;
2923
2924 /* If we cleared all bins - we are done */
2925 if (!cmd_pos->data.macs_num)
2926 cmd_pos->done = true;
2927}
2928
2929static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
2930 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2931 int *line_idx)
2932{
2933 cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
2934 line_idx);
2935
2936 if (cmd_pos->data.next_bin < 0)
2937 /* If o->set_restore returned -1 we are done */
2938 cmd_pos->done = true;
2939 else
2940 /* Start from the next bin next time */
2941 cmd_pos->data.next_bin++;
2942}
2943
2944static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
2945 struct bnx2x_mcast_ramrod_params *p)
2946{
2947 struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
2948 int cnt = 0;
2949 struct bnx2x_mcast_obj *o = p->mcast_obj;
2950
2951 list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
2952 link) {
2953 switch (cmd_pos->type) {
2954 case BNX2X_MCAST_CMD_ADD:
2955 bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
2956 break;
2957
2958 case BNX2X_MCAST_CMD_DEL:
2959 bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
2960 break;
2961
2962 case BNX2X_MCAST_CMD_RESTORE:
2963 bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
2964 &cnt);
2965 break;
2966
2967 default:
2968 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
2969 return -EINVAL;
2970 }
2971
2972 /* If the command has been completed - remove it from the list
2973 * and free the memory
2974 */
2975 if (cmd_pos->done) {
2976 list_del(&cmd_pos->link);
2977 kfree(cmd_pos);
2978 }
2979
2980 /* Break if we reached the maximum number of rules */
2981 if (cnt >= o->max_cmd_len)
2982 break;
2983 }
2984
2985 return cnt;
2986}
2987
2988static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
2989 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2990 int *line_idx)
2991{
2992 struct bnx2x_mcast_list_elem *mlist_pos;
Yuval Mintz86564c32013-01-23 03:21:50 +00002993 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002994 int cnt = *line_idx;
2995
2996 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
2997 cfg_data.mac = mlist_pos->mac;
2998 o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
2999
3000 cnt++;
3001
Joe Perches0f9dad12011-08-14 12:16:19 +00003002 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003003 mlist_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003004 }
3005
3006 *line_idx = cnt;
3007}
3008
3009static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
3010 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3011 int *line_idx)
3012{
3013 int cnt = *line_idx, i;
3014
3015 for (i = 0; i < p->mcast_list_len; i++) {
3016 o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
3017
3018 cnt++;
3019
3020 DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
3021 p->mcast_list_len - i - 1);
3022 }
3023
3024 *line_idx = cnt;
3025}
3026
3027/**
3028 * bnx2x_mcast_handle_current_cmd -
3029 *
3030 * @bp: device handle
3031 * @p:
3032 * @cmd:
3033 * @start_cnt: first line in the ramrod data that may be used
3034 *
3035 * This function is called iff there is enough place for the current command in
3036 * the ramrod data.
3037 * Returns number of lines filled in the ramrod data in total.
3038 */
3039static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
Yuval Mintz86564c32013-01-23 03:21:50 +00003040 struct bnx2x_mcast_ramrod_params *p,
3041 enum bnx2x_mcast_cmd cmd,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003042 int start_cnt)
3043{
3044 struct bnx2x_mcast_obj *o = p->mcast_obj;
3045 int cnt = start_cnt;
3046
3047 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3048
3049 switch (cmd) {
3050 case BNX2X_MCAST_CMD_ADD:
3051 bnx2x_mcast_hdl_add(bp, o, p, &cnt);
3052 break;
3053
3054 case BNX2X_MCAST_CMD_DEL:
3055 bnx2x_mcast_hdl_del(bp, o, p, &cnt);
3056 break;
3057
3058 case BNX2X_MCAST_CMD_RESTORE:
3059 o->hdl_restore(bp, o, 0, &cnt);
3060 break;
3061
3062 default:
3063 BNX2X_ERR("Unknown command: %d\n", cmd);
3064 return -EINVAL;
3065 }
3066
3067 /* The current command has been handled */
3068 p->mcast_list_len = 0;
3069
3070 return cnt;
3071}
3072
3073static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
3074 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003075 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003076{
3077 struct bnx2x_mcast_obj *o = p->mcast_obj;
3078 int reg_sz = o->get_registry_size(o);
3079
3080 switch (cmd) {
3081 /* DEL command deletes all currently configured MACs */
3082 case BNX2X_MCAST_CMD_DEL:
3083 o->set_registry_size(o, 0);
3084 /* Don't break */
3085
3086 /* RESTORE command will restore the entire multicast configuration */
3087 case BNX2X_MCAST_CMD_RESTORE:
3088 /* Here we set the approximate amount of work to do, which in
3089 * fact may be only less as some MACs in postponed ADD
3090 * command(s) scheduled before this command may fall into
3091 * the same bin and the actual number of bins set in the
3092 * registry would be less than we estimated here. See
3093 * bnx2x_mcast_set_one_rule_e2() for further details.
3094 */
3095 p->mcast_list_len = reg_sz;
3096 break;
3097
3098 case BNX2X_MCAST_CMD_ADD:
3099 case BNX2X_MCAST_CMD_CONT:
3100 /* Here we assume that all new MACs will fall into new bins.
3101 * However we will correct the real registry size after we
3102 * handle all pending commands.
3103 */
3104 o->set_registry_size(o, reg_sz + p->mcast_list_len);
3105 break;
3106
3107 default:
3108 BNX2X_ERR("Unknown command: %d\n", cmd);
3109 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003110 }
3111
3112 /* Increase the total number of MACs pending to be configured */
3113 o->total_pending_num += p->mcast_list_len;
3114
3115 return 0;
3116}
3117
3118static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
3119 struct bnx2x_mcast_ramrod_params *p,
3120 int old_num_bins)
3121{
3122 struct bnx2x_mcast_obj *o = p->mcast_obj;
3123
3124 o->set_registry_size(o, old_num_bins);
3125 o->total_pending_num -= p->mcast_list_len;
3126}
3127
3128/**
3129 * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
3130 *
3131 * @bp: device handle
3132 * @p:
3133 * @len: number of rules to handle
3134 */
3135static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
3136 struct bnx2x_mcast_ramrod_params *p,
3137 u8 len)
3138{
3139 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3140 struct eth_multicast_rules_ramrod_data *data =
3141 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
3142
Yuval Mintz86564c32013-01-23 03:21:50 +00003143 data->header.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
3144 (BNX2X_FILTER_MCAST_PENDING <<
3145 BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003146 data->header.rule_cnt = len;
3147}
3148
3149/**
3150 * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
3151 *
3152 * @bp: device handle
3153 * @o:
3154 *
3155 * Recalculate the actual number of set bins in the registry using Brian
3156 * Kernighan's algorithm: it's execution complexity is as a number of set bins.
3157 *
3158 * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
3159 */
3160static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
3161 struct bnx2x_mcast_obj *o)
3162{
3163 int i, cnt = 0;
3164 u64 elem;
3165
3166 for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
3167 elem = o->registry.aprox_match.vec[i];
3168 for (; elem; cnt++)
3169 elem &= elem - 1;
3170 }
3171
3172 o->set_registry_size(o, cnt);
3173
3174 return 0;
3175}
3176
3177static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
3178 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003179 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003180{
3181 struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
3182 struct bnx2x_mcast_obj *o = p->mcast_obj;
3183 struct eth_multicast_rules_ramrod_data *data =
3184 (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
3185 int cnt = 0, rc;
3186
3187 /* Reset the ramrod data buffer */
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00003188 memset(data, 0, sizeof(*data));
3189
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003190 cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
3191
3192 /* If there are no more pending commands - clear SCHEDULED state */
3193 if (list_empty(&o->pending_cmds_head))
3194 o->clear_sched(o);
3195
3196 /* The below may be true iff there was enough room in ramrod
3197 * data for all pending commands and for the current
3198 * command. Otherwise the current command would have been added
3199 * to the pending commands and p->mcast_list_len would have been
3200 * zeroed.
3201 */
3202 if (p->mcast_list_len > 0)
3203 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
3204
3205 /* We've pulled out some MACs - update the total number of
3206 * outstanding.
3207 */
3208 o->total_pending_num -= cnt;
3209
3210 /* send a ramrod */
3211 WARN_ON(o->total_pending_num < 0);
3212 WARN_ON(cnt > o->max_cmd_len);
3213
3214 bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
3215
3216 /* Update a registry size if there are no more pending operations.
3217 *
3218 * We don't want to change the value of the registry size if there are
3219 * pending operations because we want it to always be equal to the
3220 * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
3221 * set bins after the last requested operation in order to properly
3222 * evaluate the size of the next DEL/RESTORE operation.
3223 *
3224 * Note that we update the registry itself during command(s) handling
3225 * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
3226 * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
3227 * with a limited amount of update commands (per MAC/bin) and we don't
3228 * know in this scope what the actual state of bins configuration is
3229 * going to be after this ramrod.
3230 */
3231 if (!o->total_pending_num)
3232 bnx2x_mcast_refresh_registry_e2(bp, o);
3233
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003234 /* If CLEAR_ONLY was requested - don't send a ramrod and clear
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003235 * RAMROD_PENDING status immediately.
3236 */
3237 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3238 raw->clear_pending(raw);
3239 return 0;
3240 } else {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003241 /* No need for an explicit memory barrier here as long we would
3242 * need to ensure the ordering of writing to the SPQ element
3243 * and updating of the SPQ producer which involves a memory
3244 * read and we will have to put a full memory barrier there
3245 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003246 */
3247
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003248 /* Send a ramrod */
3249 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
3250 raw->cid, U64_HI(raw->rdata_mapping),
3251 U64_LO(raw->rdata_mapping),
3252 ETH_CONNECTION_TYPE);
3253 if (rc)
3254 return rc;
3255
3256 /* Ramrod completion is pending */
3257 return 1;
3258 }
3259}
3260
3261static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
3262 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003263 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003264{
3265 /* Mark, that there is a work to do */
3266 if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
3267 p->mcast_list_len = 1;
3268
3269 return 0;
3270}
3271
3272static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
3273 struct bnx2x_mcast_ramrod_params *p,
3274 int old_num_bins)
3275{
3276 /* Do nothing */
3277}
3278
3279#define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3280do { \
3281 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3282} while (0)
3283
3284static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
3285 struct bnx2x_mcast_obj *o,
3286 struct bnx2x_mcast_ramrod_params *p,
3287 u32 *mc_filter)
3288{
3289 struct bnx2x_mcast_list_elem *mlist_pos;
3290 int bit;
3291
3292 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
3293 bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
3294 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3295
Joe Perches0f9dad12011-08-14 12:16:19 +00003296 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC, bin %d\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003297 mlist_pos->mac, bit);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003298
3299 /* bookkeeping... */
3300 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
3301 bit);
3302 }
3303}
3304
3305static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
3306 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3307 u32 *mc_filter)
3308{
3309 int bit;
3310
3311 for (bit = bnx2x_mcast_get_next_bin(o, 0);
3312 bit >= 0;
3313 bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
3314 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3315 DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
3316 }
3317}
3318
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003319/* On 57711 we write the multicast MACs' approximate match
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003320 * table by directly into the TSTORM's internal RAM. So we don't
3321 * really need to handle any tricks to make it work.
3322 */
3323static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
3324 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003325 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003326{
3327 int i;
3328 struct bnx2x_mcast_obj *o = p->mcast_obj;
3329 struct bnx2x_raw_obj *r = &o->raw;
3330
3331 /* If CLEAR_ONLY has been requested - clear the registry
3332 * and clear a pending bit.
3333 */
3334 if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3335 u32 mc_filter[MC_HASH_SIZE] = {0};
3336
3337 /* Set the multicast filter bits before writing it into
3338 * the internal memory.
3339 */
3340 switch (cmd) {
3341 case BNX2X_MCAST_CMD_ADD:
3342 bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
3343 break;
3344
3345 case BNX2X_MCAST_CMD_DEL:
Joe Perches94f05b02011-08-14 12:16:20 +00003346 DP(BNX2X_MSG_SP,
3347 "Invalidating multicast MACs configuration\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003348
3349 /* clear the registry */
3350 memset(o->registry.aprox_match.vec, 0,
3351 sizeof(o->registry.aprox_match.vec));
3352 break;
3353
3354 case BNX2X_MCAST_CMD_RESTORE:
3355 bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
3356 break;
3357
3358 default:
3359 BNX2X_ERR("Unknown command: %d\n", cmd);
3360 return -EINVAL;
3361 }
3362
3363 /* Set the mcast filter in the internal memory */
3364 for (i = 0; i < MC_HASH_SIZE; i++)
3365 REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
3366 } else
3367 /* clear the registry */
3368 memset(o->registry.aprox_match.vec, 0,
3369 sizeof(o->registry.aprox_match.vec));
3370
3371 /* We are done */
3372 r->clear_pending(r);
3373
3374 return 0;
3375}
3376
3377static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
3378 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003379 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003380{
3381 struct bnx2x_mcast_obj *o = p->mcast_obj;
3382 int reg_sz = o->get_registry_size(o);
3383
3384 switch (cmd) {
3385 /* DEL command deletes all currently configured MACs */
3386 case BNX2X_MCAST_CMD_DEL:
3387 o->set_registry_size(o, 0);
3388 /* Don't break */
3389
3390 /* RESTORE command will restore the entire multicast configuration */
3391 case BNX2X_MCAST_CMD_RESTORE:
3392 p->mcast_list_len = reg_sz;
3393 DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
3394 cmd, p->mcast_list_len);
3395 break;
3396
3397 case BNX2X_MCAST_CMD_ADD:
3398 case BNX2X_MCAST_CMD_CONT:
3399 /* Multicast MACs on 57710 are configured as unicast MACs and
3400 * there is only a limited number of CAM entries for that
3401 * matter.
3402 */
3403 if (p->mcast_list_len > o->max_cmd_len) {
Merav Sicron51c1a582012-03-18 10:33:38 +00003404 BNX2X_ERR("Can't configure more than %d multicast MACs on 57710\n",
3405 o->max_cmd_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003406 return -EINVAL;
3407 }
3408 /* Every configured MAC should be cleared if DEL command is
3409 * called. Only the last ADD command is relevant as long as
3410 * every ADD commands overrides the previous configuration.
3411 */
3412 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3413 if (p->mcast_list_len > 0)
3414 o->set_registry_size(o, p->mcast_list_len);
3415
3416 break;
3417
3418 default:
3419 BNX2X_ERR("Unknown command: %d\n", cmd);
3420 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003421 }
3422
3423 /* We want to ensure that commands are executed one by one for 57710.
3424 * Therefore each none-empty command will consume o->max_cmd_len.
3425 */
3426 if (p->mcast_list_len)
3427 o->total_pending_num += o->max_cmd_len;
3428
3429 return 0;
3430}
3431
3432static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
3433 struct bnx2x_mcast_ramrod_params *p,
3434 int old_num_macs)
3435{
3436 struct bnx2x_mcast_obj *o = p->mcast_obj;
3437
3438 o->set_registry_size(o, old_num_macs);
3439
3440 /* If current command hasn't been handled yet and we are
3441 * here means that it's meant to be dropped and we have to
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003442 * update the number of outstanding MACs accordingly.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003443 */
3444 if (p->mcast_list_len)
3445 o->total_pending_num -= o->max_cmd_len;
3446}
3447
3448static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
3449 struct bnx2x_mcast_obj *o, int idx,
3450 union bnx2x_mcast_config_data *cfg_data,
Yuval Mintz86564c32013-01-23 03:21:50 +00003451 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003452{
3453 struct bnx2x_raw_obj *r = &o->raw;
3454 struct mac_configuration_cmd *data =
3455 (struct mac_configuration_cmd *)(r->rdata);
3456
3457 /* copy mac */
3458 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
3459 bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
3460 &data->config_table[idx].middle_mac_addr,
3461 &data->config_table[idx].lsb_mac_addr,
3462 cfg_data->mac);
3463
3464 data->config_table[idx].vlan_id = 0;
3465 data->config_table[idx].pf_id = r->func_id;
3466 data->config_table[idx].clients_bit_vector =
3467 cpu_to_le32(1 << r->cl_id);
3468
3469 SET_FLAG(data->config_table[idx].flags,
3470 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3471 T_ETH_MAC_COMMAND_SET);
3472 }
3473}
3474
3475/**
3476 * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
3477 *
3478 * @bp: device handle
3479 * @p:
3480 * @len: number of rules to handle
3481 */
3482static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
3483 struct bnx2x_mcast_ramrod_params *p,
3484 u8 len)
3485{
3486 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3487 struct mac_configuration_cmd *data =
3488 (struct mac_configuration_cmd *)(r->rdata);
3489
3490 u8 offset = (CHIP_REV_IS_SLOW(bp) ?
3491 BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
3492 BNX2X_MAX_MULTICAST*(1 + r->func_id));
3493
3494 data->hdr.offset = offset;
Yuval Mintz86564c32013-01-23 03:21:50 +00003495 data->hdr.client_id = cpu_to_le16(0xff);
3496 data->hdr.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
3497 (BNX2X_FILTER_MCAST_PENDING <<
3498 BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003499 data->hdr.length = len;
3500}
3501
3502/**
3503 * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
3504 *
3505 * @bp: device handle
3506 * @o:
3507 * @start_idx: index in the registry to start from
3508 * @rdata_idx: index in the ramrod data to start from
3509 *
3510 * restore command for 57710 is like all other commands - always a stand alone
3511 * command - start_idx and rdata_idx will always be 0. This function will always
3512 * succeed.
3513 * returns -1 to comply with 57712 variant.
3514 */
3515static inline int bnx2x_mcast_handle_restore_cmd_e1(
3516 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
3517 int *rdata_idx)
3518{
3519 struct bnx2x_mcast_mac_elem *elem;
3520 int i = 0;
Yuval Mintz86564c32013-01-23 03:21:50 +00003521 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003522
3523 /* go through the registry and configure the MACs from it. */
3524 list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
3525 cfg_data.mac = &elem->mac[0];
3526 o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
3527
3528 i++;
3529
Joe Perches0f9dad12011-08-14 12:16:19 +00003530 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003531 cfg_data.mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003532 }
3533
3534 *rdata_idx = i;
3535
3536 return -1;
3537}
3538
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003539static inline int bnx2x_mcast_handle_pending_cmds_e1(
3540 struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
3541{
3542 struct bnx2x_pending_mcast_cmd *cmd_pos;
3543 struct bnx2x_mcast_mac_elem *pmac_pos;
3544 struct bnx2x_mcast_obj *o = p->mcast_obj;
Yuval Mintz86564c32013-01-23 03:21:50 +00003545 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003546 int cnt = 0;
3547
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003548 /* If nothing to be done - return */
3549 if (list_empty(&o->pending_cmds_head))
3550 return 0;
3551
3552 /* Handle the first command */
3553 cmd_pos = list_first_entry(&o->pending_cmds_head,
3554 struct bnx2x_pending_mcast_cmd, link);
3555
3556 switch (cmd_pos->type) {
3557 case BNX2X_MCAST_CMD_ADD:
3558 list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
3559 cfg_data.mac = &pmac_pos->mac[0];
3560 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
3561
3562 cnt++;
3563
Joe Perches0f9dad12011-08-14 12:16:19 +00003564 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003565 pmac_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003566 }
3567 break;
3568
3569 case BNX2X_MCAST_CMD_DEL:
3570 cnt = cmd_pos->data.macs_num;
3571 DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
3572 break;
3573
3574 case BNX2X_MCAST_CMD_RESTORE:
3575 o->hdl_restore(bp, o, 0, &cnt);
3576 break;
3577
3578 default:
3579 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
3580 return -EINVAL;
3581 }
3582
3583 list_del(&cmd_pos->link);
3584 kfree(cmd_pos);
3585
3586 return cnt;
3587}
3588
3589/**
3590 * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
3591 *
3592 * @fw_hi:
3593 * @fw_mid:
3594 * @fw_lo:
3595 * @mac:
3596 */
3597static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
3598 __le16 *fw_lo, u8 *mac)
3599{
3600 mac[1] = ((u8 *)fw_hi)[0];
3601 mac[0] = ((u8 *)fw_hi)[1];
3602 mac[3] = ((u8 *)fw_mid)[0];
3603 mac[2] = ((u8 *)fw_mid)[1];
3604 mac[5] = ((u8 *)fw_lo)[0];
3605 mac[4] = ((u8 *)fw_lo)[1];
3606}
3607
3608/**
3609 * bnx2x_mcast_refresh_registry_e1 -
3610 *
3611 * @bp: device handle
3612 * @cnt:
3613 *
3614 * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
3615 * and update the registry correspondingly: if ADD - allocate a memory and add
3616 * the entries to the registry (list), if DELETE - clear the registry and free
3617 * the memory.
3618 */
3619static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
3620 struct bnx2x_mcast_obj *o)
3621{
3622 struct bnx2x_raw_obj *raw = &o->raw;
3623 struct bnx2x_mcast_mac_elem *elem;
3624 struct mac_configuration_cmd *data =
3625 (struct mac_configuration_cmd *)(raw->rdata);
3626
3627 /* If first entry contains a SET bit - the command was ADD,
3628 * otherwise - DEL_ALL
3629 */
3630 if (GET_FLAG(data->config_table[0].flags,
3631 MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
3632 int i, len = data->hdr.length;
3633
3634 /* Break if it was a RESTORE command */
3635 if (!list_empty(&o->registry.exact_match.macs))
3636 return 0;
3637
Thomas Meyer01e23742011-11-29 11:08:00 +00003638 elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003639 if (!elem) {
3640 BNX2X_ERR("Failed to allocate registry memory\n");
3641 return -ENOMEM;
3642 }
3643
3644 for (i = 0; i < len; i++, elem++) {
3645 bnx2x_get_fw_mac_addr(
3646 &data->config_table[i].msb_mac_addr,
3647 &data->config_table[i].middle_mac_addr,
3648 &data->config_table[i].lsb_mac_addr,
3649 elem->mac);
Joe Perches0f9dad12011-08-14 12:16:19 +00003650 DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00003651 elem->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003652 list_add_tail(&elem->link,
3653 &o->registry.exact_match.macs);
3654 }
3655 } else {
3656 elem = list_first_entry(&o->registry.exact_match.macs,
3657 struct bnx2x_mcast_mac_elem, link);
3658 DP(BNX2X_MSG_SP, "Deleting a registry\n");
3659 kfree(elem);
3660 INIT_LIST_HEAD(&o->registry.exact_match.macs);
3661 }
3662
3663 return 0;
3664}
3665
3666static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
3667 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003668 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003669{
3670 struct bnx2x_mcast_obj *o = p->mcast_obj;
3671 struct bnx2x_raw_obj *raw = &o->raw;
3672 struct mac_configuration_cmd *data =
3673 (struct mac_configuration_cmd *)(raw->rdata);
3674 int cnt = 0, i, rc;
3675
3676 /* Reset the ramrod data buffer */
3677 memset(data, 0, sizeof(*data));
3678
3679 /* First set all entries as invalid */
3680 for (i = 0; i < o->max_cmd_len ; i++)
3681 SET_FLAG(data->config_table[i].flags,
3682 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3683 T_ETH_MAC_COMMAND_INVALIDATE);
3684
3685 /* Handle pending commands first */
3686 cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
3687
3688 /* If there are no more pending commands - clear SCHEDULED state */
3689 if (list_empty(&o->pending_cmds_head))
3690 o->clear_sched(o);
3691
3692 /* The below may be true iff there were no pending commands */
3693 if (!cnt)
3694 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
3695
3696 /* For 57710 every command has o->max_cmd_len length to ensure that
3697 * commands are done one at a time.
3698 */
3699 o->total_pending_num -= o->max_cmd_len;
3700
3701 /* send a ramrod */
3702
3703 WARN_ON(cnt > o->max_cmd_len);
3704
3705 /* Set ramrod header (in particular, a number of entries to update) */
3706 bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
3707
3708 /* update a registry: we need the registry contents to be always up
3709 * to date in order to be able to execute a RESTORE opcode. Here
3710 * we use the fact that for 57710 we sent one command at a time
3711 * hence we may take the registry update out of the command handling
3712 * and do it in a simpler way here.
3713 */
3714 rc = bnx2x_mcast_refresh_registry_e1(bp, o);
3715 if (rc)
3716 return rc;
3717
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003718 /* If CLEAR_ONLY was requested - don't send a ramrod and clear
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003719 * RAMROD_PENDING status immediately.
3720 */
3721 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3722 raw->clear_pending(raw);
3723 return 0;
3724 } else {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003725 /* No need for an explicit memory barrier here as long we would
3726 * need to ensure the ordering of writing to the SPQ element
3727 * and updating of the SPQ producer which involves a memory
3728 * read and we will have to put a full memory barrier there
3729 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003730 */
3731
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003732 /* Send a ramrod */
3733 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
3734 U64_HI(raw->rdata_mapping),
3735 U64_LO(raw->rdata_mapping),
3736 ETH_CONNECTION_TYPE);
3737 if (rc)
3738 return rc;
3739
3740 /* Ramrod completion is pending */
3741 return 1;
3742 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003743}
3744
3745static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
3746{
3747 return o->registry.exact_match.num_macs_set;
3748}
3749
3750static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
3751{
3752 return o->registry.aprox_match.num_bins_set;
3753}
3754
3755static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
3756 int n)
3757{
3758 o->registry.exact_match.num_macs_set = n;
3759}
3760
3761static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
3762 int n)
3763{
3764 o->registry.aprox_match.num_bins_set = n;
3765}
3766
3767int bnx2x_config_mcast(struct bnx2x *bp,
3768 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003769 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003770{
3771 struct bnx2x_mcast_obj *o = p->mcast_obj;
3772 struct bnx2x_raw_obj *r = &o->raw;
3773 int rc = 0, old_reg_size;
3774
3775 /* This is needed to recover number of currently configured mcast macs
3776 * in case of failure.
3777 */
3778 old_reg_size = o->get_registry_size(o);
3779
3780 /* Do some calculations and checks */
3781 rc = o->validate(bp, p, cmd);
3782 if (rc)
3783 return rc;
3784
3785 /* Return if there is no work to do */
3786 if ((!p->mcast_list_len) && (!o->check_sched(o)))
3787 return 0;
3788
Merav Sicron51c1a582012-03-18 10:33:38 +00003789 DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d o->max_cmd_len=%d\n",
3790 o->total_pending_num, p->mcast_list_len, o->max_cmd_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003791
3792 /* Enqueue the current command to the pending list if we can't complete
3793 * it in the current iteration
3794 */
3795 if (r->check_pending(r) ||
3796 ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
3797 rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
3798 if (rc < 0)
3799 goto error_exit1;
3800
3801 /* As long as the current command is in a command list we
3802 * don't need to handle it separately.
3803 */
3804 p->mcast_list_len = 0;
3805 }
3806
3807 if (!r->check_pending(r)) {
3808
3809 /* Set 'pending' state */
3810 r->set_pending(r);
3811
3812 /* Configure the new classification in the chip */
3813 rc = o->config_mcast(bp, p, cmd);
3814 if (rc < 0)
3815 goto error_exit2;
3816
3817 /* Wait for a ramrod completion if was requested */
3818 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
3819 rc = o->wait_comp(bp, o);
3820 }
3821
3822 return rc;
3823
3824error_exit2:
3825 r->clear_pending(r);
3826
3827error_exit1:
3828 o->revert(bp, p, old_reg_size);
3829
3830 return rc;
3831}
3832
3833static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
3834{
3835 smp_mb__before_clear_bit();
3836 clear_bit(o->sched_state, o->raw.pstate);
3837 smp_mb__after_clear_bit();
3838}
3839
3840static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
3841{
3842 smp_mb__before_clear_bit();
3843 set_bit(o->sched_state, o->raw.pstate);
3844 smp_mb__after_clear_bit();
3845}
3846
3847static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
3848{
3849 return !!test_bit(o->sched_state, o->raw.pstate);
3850}
3851
3852static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
3853{
3854 return o->raw.check_pending(&o->raw) || o->check_sched(o);
3855}
3856
3857void bnx2x_init_mcast_obj(struct bnx2x *bp,
3858 struct bnx2x_mcast_obj *mcast_obj,
3859 u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
3860 u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
3861 int state, unsigned long *pstate, bnx2x_obj_type type)
3862{
3863 memset(mcast_obj, 0, sizeof(*mcast_obj));
3864
3865 bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
3866 rdata, rdata_mapping, state, pstate, type);
3867
3868 mcast_obj->engine_id = engine_id;
3869
3870 INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
3871
3872 mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
3873 mcast_obj->check_sched = bnx2x_mcast_check_sched;
3874 mcast_obj->set_sched = bnx2x_mcast_set_sched;
3875 mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
3876
3877 if (CHIP_IS_E1(bp)) {
3878 mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
3879 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3880 mcast_obj->hdl_restore =
3881 bnx2x_mcast_handle_restore_cmd_e1;
3882 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3883
3884 if (CHIP_REV_IS_SLOW(bp))
3885 mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
3886 else
3887 mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
3888
3889 mcast_obj->wait_comp = bnx2x_mcast_wait;
3890 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
3891 mcast_obj->validate = bnx2x_mcast_validate_e1;
3892 mcast_obj->revert = bnx2x_mcast_revert_e1;
3893 mcast_obj->get_registry_size =
3894 bnx2x_mcast_get_registry_size_exact;
3895 mcast_obj->set_registry_size =
3896 bnx2x_mcast_set_registry_size_exact;
3897
3898 /* 57710 is the only chip that uses the exact match for mcast
3899 * at the moment.
3900 */
3901 INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
3902
3903 } else if (CHIP_IS_E1H(bp)) {
3904 mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
3905 mcast_obj->enqueue_cmd = NULL;
3906 mcast_obj->hdl_restore = NULL;
3907 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3908
3909 /* 57711 doesn't send a ramrod, so it has unlimited credit
3910 * for one command.
3911 */
3912 mcast_obj->max_cmd_len = -1;
3913 mcast_obj->wait_comp = bnx2x_mcast_wait;
3914 mcast_obj->set_one_rule = NULL;
3915 mcast_obj->validate = bnx2x_mcast_validate_e1h;
3916 mcast_obj->revert = bnx2x_mcast_revert_e1h;
3917 mcast_obj->get_registry_size =
3918 bnx2x_mcast_get_registry_size_aprox;
3919 mcast_obj->set_registry_size =
3920 bnx2x_mcast_set_registry_size_aprox;
3921 } else {
3922 mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
3923 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3924 mcast_obj->hdl_restore =
3925 bnx2x_mcast_handle_restore_cmd_e2;
3926 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3927 /* TODO: There should be a proper HSI define for this number!!!
3928 */
3929 mcast_obj->max_cmd_len = 16;
3930 mcast_obj->wait_comp = bnx2x_mcast_wait;
3931 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
3932 mcast_obj->validate = bnx2x_mcast_validate_e2;
3933 mcast_obj->revert = bnx2x_mcast_revert_e2;
3934 mcast_obj->get_registry_size =
3935 bnx2x_mcast_get_registry_size_aprox;
3936 mcast_obj->set_registry_size =
3937 bnx2x_mcast_set_registry_size_aprox;
3938 }
3939}
3940
3941/*************************** Credit handling **********************************/
3942
3943/**
3944 * atomic_add_ifless - add if the result is less than a given value.
3945 *
3946 * @v: pointer of type atomic_t
3947 * @a: the amount to add to v...
3948 * @u: ...if (v + a) is less than u.
3949 *
3950 * returns true if (v + a) was less than u, and false otherwise.
3951 *
3952 */
3953static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
3954{
3955 int c, old;
3956
3957 c = atomic_read(v);
3958 for (;;) {
3959 if (unlikely(c + a >= u))
3960 return false;
3961
3962 old = atomic_cmpxchg((v), c, c + a);
3963 if (likely(old == c))
3964 break;
3965 c = old;
3966 }
3967
3968 return true;
3969}
3970
3971/**
3972 * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
3973 *
3974 * @v: pointer of type atomic_t
3975 * @a: the amount to dec from v...
3976 * @u: ...if (v - a) is more or equal than u.
3977 *
3978 * returns true if (v - a) was more or equal than u, and false
3979 * otherwise.
3980 */
3981static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
3982{
3983 int c, old;
3984
3985 c = atomic_read(v);
3986 for (;;) {
3987 if (unlikely(c - a < u))
3988 return false;
3989
3990 old = atomic_cmpxchg((v), c, c - a);
3991 if (likely(old == c))
3992 break;
3993 c = old;
3994 }
3995
3996 return true;
3997}
3998
3999static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
4000{
4001 bool rc;
4002
4003 smp_mb();
4004 rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
4005 smp_mb();
4006
4007 return rc;
4008}
4009
4010static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
4011{
4012 bool rc;
4013
4014 smp_mb();
4015
4016 /* Don't let to refill if credit + cnt > pool_sz */
4017 rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
4018
4019 smp_mb();
4020
4021 return rc;
4022}
4023
4024static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
4025{
4026 int cur_credit;
4027
4028 smp_mb();
4029 cur_credit = atomic_read(&o->credit);
4030
4031 return cur_credit;
4032}
4033
4034static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
4035 int cnt)
4036{
4037 return true;
4038}
4039
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004040static bool bnx2x_credit_pool_get_entry(
4041 struct bnx2x_credit_pool_obj *o,
4042 int *offset)
4043{
4044 int idx, vec, i;
4045
4046 *offset = -1;
4047
4048 /* Find "internal cam-offset" then add to base for this object... */
4049 for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
4050
4051 /* Skip the current vector if there are no free entries in it */
4052 if (!o->pool_mirror[vec])
4053 continue;
4054
4055 /* If we've got here we are going to find a free entry */
Dmitry Kravkovc54e9bd2012-03-26 21:08:55 +00004056 for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004057 i < BIT_VEC64_ELEM_SZ; idx++, i++)
4058
4059 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
4060 /* Got one!! */
4061 BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
4062 *offset = o->base_pool_offset + idx;
4063 return true;
4064 }
4065 }
4066
4067 return false;
4068}
4069
4070static bool bnx2x_credit_pool_put_entry(
4071 struct bnx2x_credit_pool_obj *o,
4072 int offset)
4073{
4074 if (offset < o->base_pool_offset)
4075 return false;
4076
4077 offset -= o->base_pool_offset;
4078
4079 if (offset >= o->pool_sz)
4080 return false;
4081
4082 /* Return the entry to the pool */
4083 BIT_VEC64_SET_BIT(o->pool_mirror, offset);
4084
4085 return true;
4086}
4087
4088static bool bnx2x_credit_pool_put_entry_always_true(
4089 struct bnx2x_credit_pool_obj *o,
4090 int offset)
4091{
4092 return true;
4093}
4094
4095static bool bnx2x_credit_pool_get_entry_always_true(
4096 struct bnx2x_credit_pool_obj *o,
4097 int *offset)
4098{
4099 *offset = -1;
4100 return true;
4101}
4102/**
4103 * bnx2x_init_credit_pool - initialize credit pool internals.
4104 *
4105 * @p:
4106 * @base: Base entry in the CAM to use.
4107 * @credit: pool size.
4108 *
4109 * If base is negative no CAM entries handling will be performed.
4110 * If credit is negative pool operations will always succeed (unlimited pool).
4111 *
4112 */
4113static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
4114 int base, int credit)
4115{
4116 /* Zero the object first */
4117 memset(p, 0, sizeof(*p));
4118
4119 /* Set the table to all 1s */
4120 memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
4121
4122 /* Init a pool as full */
4123 atomic_set(&p->credit, credit);
4124
4125 /* The total poll size */
4126 p->pool_sz = credit;
4127
4128 p->base_pool_offset = base;
4129
4130 /* Commit the change */
4131 smp_mb();
4132
4133 p->check = bnx2x_credit_pool_check;
4134
4135 /* if pool credit is negative - disable the checks */
4136 if (credit >= 0) {
4137 p->put = bnx2x_credit_pool_put;
4138 p->get = bnx2x_credit_pool_get;
4139 p->put_entry = bnx2x_credit_pool_put_entry;
4140 p->get_entry = bnx2x_credit_pool_get_entry;
4141 } else {
4142 p->put = bnx2x_credit_pool_always_true;
4143 p->get = bnx2x_credit_pool_always_true;
4144 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
4145 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
4146 }
4147
4148 /* If base is negative - disable entries handling */
4149 if (base < 0) {
4150 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
4151 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
4152 }
4153}
4154
4155void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
4156 struct bnx2x_credit_pool_obj *p, u8 func_id,
4157 u8 func_num)
4158{
4159/* TODO: this will be defined in consts as well... */
4160#define BNX2X_CAM_SIZE_EMUL 5
4161
4162 int cam_sz;
4163
4164 if (CHIP_IS_E1(bp)) {
4165 /* In E1, Multicast is saved in cam... */
4166 if (!CHIP_REV_IS_SLOW(bp))
4167 cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
4168 else
4169 cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
4170
4171 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
4172
4173 } else if (CHIP_IS_E1H(bp)) {
4174 /* CAM credit is equaly divided between all active functions
4175 * on the PORT!.
4176 */
4177 if ((func_num > 0)) {
4178 if (!CHIP_REV_IS_SLOW(bp))
4179 cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
4180 else
4181 cam_sz = BNX2X_CAM_SIZE_EMUL;
4182 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
4183 } else {
4184 /* this should never happen! Block MAC operations. */
4185 bnx2x_init_credit_pool(p, 0, 0);
4186 }
4187
4188 } else {
4189
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004190 /* CAM credit is equaly divided between all active functions
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004191 * on the PATH.
4192 */
4193 if ((func_num > 0)) {
4194 if (!CHIP_REV_IS_SLOW(bp))
4195 cam_sz = (MAX_MAC_CREDIT_E2 / func_num);
4196 else
4197 cam_sz = BNX2X_CAM_SIZE_EMUL;
4198
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004199 /* No need for CAM entries handling for 57712 and
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004200 * newer.
4201 */
4202 bnx2x_init_credit_pool(p, -1, cam_sz);
4203 } else {
4204 /* this should never happen! Block MAC operations. */
4205 bnx2x_init_credit_pool(p, 0, 0);
4206 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004207 }
4208}
4209
4210void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
4211 struct bnx2x_credit_pool_obj *p,
4212 u8 func_id,
4213 u8 func_num)
4214{
4215 if (CHIP_IS_E1x(bp)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004216 /* There is no VLAN credit in HW on 57710 and 57711 only
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004217 * MAC / MAC-VLAN can be set
4218 */
4219 bnx2x_init_credit_pool(p, 0, -1);
4220 } else {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004221 /* CAM credit is equally divided between all active functions
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004222 * on the PATH.
4223 */
4224 if (func_num > 0) {
4225 int credit = MAX_VLAN_CREDIT_E2 / func_num;
4226 bnx2x_init_credit_pool(p, func_id * credit, credit);
4227 } else
4228 /* this should never happen! Block VLAN operations. */
4229 bnx2x_init_credit_pool(p, 0, 0);
4230 }
4231}
4232
4233/****************** RSS Configuration ******************/
4234/**
4235 * bnx2x_debug_print_ind_table - prints the indirection table configuration.
4236 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004237 * @bp: driver handle
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004238 * @p: pointer to rss configuration
4239 *
4240 * Prints it when NETIF_MSG_IFUP debug level is configured.
4241 */
4242static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
4243 struct bnx2x_config_rss_params *p)
4244{
4245 int i;
4246
4247 DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
4248 DP(BNX2X_MSG_SP, "0x0000: ");
4249 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
4250 DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
4251
4252 /* Print 4 bytes in a line */
4253 if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
4254 (((i + 1) & 0x3) == 0)) {
4255 DP_CONT(BNX2X_MSG_SP, "\n");
4256 DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
4257 }
4258 }
4259
4260 DP_CONT(BNX2X_MSG_SP, "\n");
4261}
4262
4263/**
4264 * bnx2x_setup_rss - configure RSS
4265 *
4266 * @bp: device handle
4267 * @p: rss configuration
4268 *
4269 * sends on UPDATE ramrod for that matter.
4270 */
4271static int bnx2x_setup_rss(struct bnx2x *bp,
4272 struct bnx2x_config_rss_params *p)
4273{
4274 struct bnx2x_rss_config_obj *o = p->rss_obj;
4275 struct bnx2x_raw_obj *r = &o->raw;
4276 struct eth_rss_update_ramrod_data *data =
4277 (struct eth_rss_update_ramrod_data *)(r->rdata);
4278 u8 rss_mode = 0;
4279 int rc;
4280
4281 memset(data, 0, sizeof(*data));
4282
4283 DP(BNX2X_MSG_SP, "Configuring RSS\n");
4284
4285 /* Set an echo field */
Yuval Mintz86564c32013-01-23 03:21:50 +00004286 data->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
4287 (r->state << BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004288
4289 /* RSS mode */
4290 if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
4291 rss_mode = ETH_RSS_MODE_DISABLED;
4292 else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
4293 rss_mode = ETH_RSS_MODE_REGULAR;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004294
4295 data->rss_mode = rss_mode;
4296
4297 DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
4298
4299 /* RSS capabilities */
4300 if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
4301 data->capabilities |=
4302 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
4303
4304 if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
4305 data->capabilities |=
4306 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
4307
Merav Sicron5d317c6a2012-06-19 07:48:24 +00004308 if (test_bit(BNX2X_RSS_IPV4_UDP, &p->rss_flags))
4309 data->capabilities |=
4310 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_UDP_CAPABILITY;
4311
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004312 if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
4313 data->capabilities |=
4314 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
4315
4316 if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
4317 data->capabilities |=
4318 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
4319
Merav Sicron5d317c6a2012-06-19 07:48:24 +00004320 if (test_bit(BNX2X_RSS_IPV6_UDP, &p->rss_flags))
4321 data->capabilities |=
4322 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_UDP_CAPABILITY;
4323
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004324 /* Hashing mask */
4325 data->rss_result_mask = p->rss_result_mask;
4326
4327 /* RSS engine ID */
4328 data->rss_engine_id = o->engine_id;
4329
4330 DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
4331
4332 /* Indirection table */
4333 memcpy(data->indirection_table, p->ind_table,
4334 T_ETH_INDIRECTION_TABLE_SIZE);
4335
4336 /* Remember the last configuration */
4337 memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
4338
4339 /* Print the indirection table */
4340 if (netif_msg_ifup(bp))
4341 bnx2x_debug_print_ind_table(bp, p);
4342
4343 /* RSS keys */
4344 if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
4345 memcpy(&data->rss_key[0], &p->rss_key[0],
4346 sizeof(data->rss_key));
4347 data->capabilities |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
4348 }
4349
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004350 /* No need for an explicit memory barrier here as long we would
4351 * need to ensure the ordering of writing to the SPQ element
4352 * and updating of the SPQ producer which involves a memory
4353 * read and we will have to put a full memory barrier there
4354 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004355 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004356
4357 /* Send a ramrod */
4358 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
4359 U64_HI(r->rdata_mapping),
4360 U64_LO(r->rdata_mapping),
4361 ETH_CONNECTION_TYPE);
4362
4363 if (rc < 0)
4364 return rc;
4365
4366 return 1;
4367}
4368
4369void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
4370 u8 *ind_table)
4371{
4372 memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
4373}
4374
4375int bnx2x_config_rss(struct bnx2x *bp,
4376 struct bnx2x_config_rss_params *p)
4377{
4378 int rc;
4379 struct bnx2x_rss_config_obj *o = p->rss_obj;
4380 struct bnx2x_raw_obj *r = &o->raw;
4381
4382 /* Do nothing if only driver cleanup was requested */
4383 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags))
4384 return 0;
4385
4386 r->set_pending(r);
4387
4388 rc = o->config_rss(bp, p);
4389 if (rc < 0) {
4390 r->clear_pending(r);
4391 return rc;
4392 }
4393
4394 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
4395 rc = r->wait_comp(bp, r);
4396
4397 return rc;
4398}
4399
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004400void bnx2x_init_rss_config_obj(struct bnx2x *bp,
4401 struct bnx2x_rss_config_obj *rss_obj,
4402 u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
4403 void *rdata, dma_addr_t rdata_mapping,
4404 int state, unsigned long *pstate,
4405 bnx2x_obj_type type)
4406{
4407 bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
4408 rdata_mapping, state, pstate, type);
4409
4410 rss_obj->engine_id = engine_id;
4411 rss_obj->config_rss = bnx2x_setup_rss;
4412}
4413
Ariel Eliorb9871bc2013-09-04 14:09:21 +03004414int validate_vlan_mac(struct bnx2x *bp,
4415 struct bnx2x_vlan_mac_obj *vlan_mac)
4416{
4417 if (!vlan_mac->get_n_elements) {
4418 BNX2X_ERR("vlan mac object was not intialized\n");
4419 return -EINVAL;
4420 }
4421 return 0;
4422}
4423
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004424/********************** Queue state object ***********************************/
4425
4426/**
4427 * bnx2x_queue_state_change - perform Queue state change transition
4428 *
4429 * @bp: device handle
4430 * @params: parameters to perform the transition
4431 *
4432 * returns 0 in case of successfully completed transition, negative error
4433 * code in case of failure, positive (EBUSY) value if there is a completion
4434 * to that is still pending (possible only if RAMROD_COMP_WAIT is
4435 * not set in params->ramrod_flags for asynchronous commands).
4436 *
4437 */
4438int bnx2x_queue_state_change(struct bnx2x *bp,
4439 struct bnx2x_queue_state_params *params)
4440{
4441 struct bnx2x_queue_sp_obj *o = params->q_obj;
4442 int rc, pending_bit;
4443 unsigned long *pending = &o->pending;
4444
4445 /* Check that the requested transition is legal */
Yuval Mintz04c46732013-01-23 03:21:46 +00004446 rc = o->check_transition(bp, o, params);
4447 if (rc) {
4448 BNX2X_ERR("check transition returned an error. rc %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004449 return -EINVAL;
Yuval Mintz04c46732013-01-23 03:21:46 +00004450 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004451
4452 /* Set "pending" bit */
Yuval Mintz04c46732013-01-23 03:21:46 +00004453 DP(BNX2X_MSG_SP, "pending bit was=%lx\n", o->pending);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004454 pending_bit = o->set_pending(o, params);
Yuval Mintz04c46732013-01-23 03:21:46 +00004455 DP(BNX2X_MSG_SP, "pending bit now=%lx\n", o->pending);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004456
4457 /* Don't send a command if only driver cleanup was requested */
4458 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags))
4459 o->complete_cmd(bp, o, pending_bit);
4460 else {
4461 /* Send a ramrod */
4462 rc = o->send_cmd(bp, params);
4463 if (rc) {
4464 o->next_state = BNX2X_Q_STATE_MAX;
4465 clear_bit(pending_bit, pending);
4466 smp_mb__after_clear_bit();
4467 return rc;
4468 }
4469
4470 if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
4471 rc = o->wait_comp(bp, o, pending_bit);
4472 if (rc)
4473 return rc;
4474
4475 return 0;
4476 }
4477 }
4478
4479 return !!test_bit(pending_bit, pending);
4480}
4481
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004482static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
4483 struct bnx2x_queue_state_params *params)
4484{
4485 enum bnx2x_queue_cmd cmd = params->cmd, bit;
4486
4487 /* ACTIVATE and DEACTIVATE commands are implemented on top of
4488 * UPDATE command.
4489 */
4490 if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
4491 (cmd == BNX2X_Q_CMD_DEACTIVATE))
4492 bit = BNX2X_Q_CMD_UPDATE;
4493 else
4494 bit = cmd;
4495
4496 set_bit(bit, &obj->pending);
4497 return bit;
4498}
4499
4500static int bnx2x_queue_wait_comp(struct bnx2x *bp,
4501 struct bnx2x_queue_sp_obj *o,
4502 enum bnx2x_queue_cmd cmd)
4503{
4504 return bnx2x_state_wait(bp, cmd, &o->pending);
4505}
4506
4507/**
4508 * bnx2x_queue_comp_cmd - complete the state change command.
4509 *
4510 * @bp: device handle
4511 * @o:
4512 * @cmd:
4513 *
4514 * Checks that the arrived completion is expected.
4515 */
4516static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
4517 struct bnx2x_queue_sp_obj *o,
4518 enum bnx2x_queue_cmd cmd)
4519{
4520 unsigned long cur_pending = o->pending;
4521
4522 if (!test_and_clear_bit(cmd, &cur_pending)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00004523 BNX2X_ERR("Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
4524 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX],
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004525 o->state, cur_pending, o->next_state);
4526 return -EINVAL;
4527 }
4528
Ariel Elior6383c0b2011-07-14 08:31:57 +00004529 if (o->next_tx_only >= o->max_cos)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004530 /* >= because tx only must always be smaller than cos since the
Masanari Iida02582e92012-08-22 19:11:26 +09004531 * primary connection supports COS 0
Ariel Elior6383c0b2011-07-14 08:31:57 +00004532 */
4533 BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
4534 o->next_tx_only, o->max_cos);
4535
Merav Sicron51c1a582012-03-18 10:33:38 +00004536 DP(BNX2X_MSG_SP,
4537 "Completing command %d for queue %d, setting state to %d\n",
4538 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004539
4540 if (o->next_tx_only) /* print num tx-only if any exist */
Joe Perches94f05b02011-08-14 12:16:20 +00004541 DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00004542 o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004543
4544 o->state = o->next_state;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004545 o->num_tx_only = o->next_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004546 o->next_state = BNX2X_Q_STATE_MAX;
4547
4548 /* It's important that o->state and o->next_state are
4549 * updated before o->pending.
4550 */
4551 wmb();
4552
4553 clear_bit(cmd, &o->pending);
4554 smp_mb__after_clear_bit();
4555
4556 return 0;
4557}
4558
4559static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
4560 struct bnx2x_queue_state_params *cmd_params,
4561 struct client_init_ramrod_data *data)
4562{
4563 struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004564
4565 /* Rx data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004566
4567 /* IPv6 TPA supported for E2 and above only */
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00004568 data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA_IPV6, &params->flags) *
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004569 CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
4570}
4571
Ariel Elior6383c0b2011-07-14 08:31:57 +00004572static void bnx2x_q_fill_init_general_data(struct bnx2x *bp,
4573 struct bnx2x_queue_sp_obj *o,
4574 struct bnx2x_general_setup_params *params,
4575 struct client_init_general_data *gen_data,
4576 unsigned long *flags)
4577{
4578 gen_data->client_id = o->cl_id;
4579
4580 if (test_bit(BNX2X_Q_FLG_STATS, flags)) {
4581 gen_data->statistics_counter_id =
4582 params->stat_id;
4583 gen_data->statistics_en_flg = 1;
4584 gen_data->statistics_zero_flg =
4585 test_bit(BNX2X_Q_FLG_ZERO_STATS, flags);
4586 } else
4587 gen_data->statistics_counter_id =
4588 DISABLE_STATISTIC_COUNTER_ID_VALUE;
4589
4590 gen_data->is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, flags);
4591 gen_data->activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE, flags);
4592 gen_data->sp_client_id = params->spcl_id;
4593 gen_data->mtu = cpu_to_le16(params->mtu);
4594 gen_data->func_id = o->func_id;
4595
Ariel Elior6383c0b2011-07-14 08:31:57 +00004596 gen_data->cos = params->cos;
4597
4598 gen_data->traffic_type =
4599 test_bit(BNX2X_Q_FLG_FCOE, flags) ?
4600 LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
4601
Joe Perches94f05b02011-08-14 12:16:20 +00004602 DP(BNX2X_MSG_SP, "flags: active %d, cos %d, stats en %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004603 gen_data->activate_flg, gen_data->cos, gen_data->statistics_en_flg);
4604}
4605
4606static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj *o,
4607 struct bnx2x_txq_setup_params *params,
4608 struct client_init_tx_data *tx_data,
4609 unsigned long *flags)
4610{
4611 tx_data->enforce_security_flg =
4612 test_bit(BNX2X_Q_FLG_TX_SEC, flags);
4613 tx_data->default_vlan =
4614 cpu_to_le16(params->default_vlan);
4615 tx_data->default_vlan_flg =
4616 test_bit(BNX2X_Q_FLG_DEF_VLAN, flags);
4617 tx_data->tx_switching_flg =
4618 test_bit(BNX2X_Q_FLG_TX_SWITCH, flags);
4619 tx_data->anti_spoofing_flg =
4620 test_bit(BNX2X_Q_FLG_ANTI_SPOOF, flags);
Barak Witkowskia3348722012-04-23 03:04:46 +00004621 tx_data->force_default_pri_flg =
4622 test_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, flags);
4623
Dmitry Kravkove287a752013-03-21 15:38:24 +00004624 tx_data->tunnel_lso_inc_ip_id =
4625 test_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, flags);
Dmitry Kravkov91226792013-03-11 05:17:52 +00004626 tx_data->tunnel_non_lso_pcsum_location =
4627 test_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, flags) ? PCSUM_ON_PKT :
4628 PCSUM_ON_BD;
4629
Ariel Elior6383c0b2011-07-14 08:31:57 +00004630 tx_data->tx_status_block_id = params->fw_sb_id;
4631 tx_data->tx_sb_index_number = params->sb_cq_index;
4632 tx_data->tss_leading_client_id = params->tss_leading_cl_id;
4633
4634 tx_data->tx_bd_page_base.lo =
4635 cpu_to_le32(U64_LO(params->dscr_map));
4636 tx_data->tx_bd_page_base.hi =
4637 cpu_to_le32(U64_HI(params->dscr_map));
4638
4639 /* Don't configure any Tx switching mode during queue SETUP */
4640 tx_data->state = 0;
4641}
4642
4643static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj *o,
4644 struct rxq_pause_params *params,
4645 struct client_init_rx_data *rx_data)
4646{
4647 /* flow control data */
4648 rx_data->cqe_pause_thr_low = cpu_to_le16(params->rcq_th_lo);
4649 rx_data->cqe_pause_thr_high = cpu_to_le16(params->rcq_th_hi);
4650 rx_data->bd_pause_thr_low = cpu_to_le16(params->bd_th_lo);
4651 rx_data->bd_pause_thr_high = cpu_to_le16(params->bd_th_hi);
4652 rx_data->sge_pause_thr_low = cpu_to_le16(params->sge_th_lo);
4653 rx_data->sge_pause_thr_high = cpu_to_le16(params->sge_th_hi);
4654 rx_data->rx_cos_mask = cpu_to_le16(params->pri_map);
4655}
4656
4657static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj *o,
4658 struct bnx2x_rxq_setup_params *params,
4659 struct client_init_rx_data *rx_data,
4660 unsigned long *flags)
4661{
Ariel Elior6383c0b2011-07-14 08:31:57 +00004662 rx_data->tpa_en = test_bit(BNX2X_Q_FLG_TPA, flags) *
4663 CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00004664 rx_data->tpa_en |= test_bit(BNX2X_Q_FLG_TPA_GRO, flags) *
4665 CLIENT_INIT_RX_DATA_TPA_MODE;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004666 rx_data->vmqueue_mode_en_flg = 0;
4667
4668 rx_data->cache_line_alignment_log_size =
4669 params->cache_line_log;
4670 rx_data->enable_dynamic_hc =
4671 test_bit(BNX2X_Q_FLG_DHC, flags);
4672 rx_data->max_sges_for_packet = params->max_sges_pkt;
4673 rx_data->client_qzone_id = params->cl_qzone_id;
4674 rx_data->max_agg_size = cpu_to_le16(params->tpa_agg_sz);
4675
4676 /* Always start in DROP_ALL mode */
4677 rx_data->state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
4678 CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
4679
4680 /* We don't set drop flags */
4681 rx_data->drop_ip_cs_err_flg = 0;
4682 rx_data->drop_tcp_cs_err_flg = 0;
4683 rx_data->drop_ttl0_flg = 0;
4684 rx_data->drop_udp_cs_err_flg = 0;
4685 rx_data->inner_vlan_removal_enable_flg =
4686 test_bit(BNX2X_Q_FLG_VLAN, flags);
4687 rx_data->outer_vlan_removal_enable_flg =
4688 test_bit(BNX2X_Q_FLG_OV, flags);
4689 rx_data->status_block_id = params->fw_sb_id;
4690 rx_data->rx_sb_index_number = params->sb_cq_index;
4691 rx_data->max_tpa_queues = params->max_tpa_queues;
4692 rx_data->max_bytes_on_bd = cpu_to_le16(params->buf_sz);
4693 rx_data->sge_buff_size = cpu_to_le16(params->sge_buf_sz);
4694 rx_data->bd_page_base.lo =
4695 cpu_to_le32(U64_LO(params->dscr_map));
4696 rx_data->bd_page_base.hi =
4697 cpu_to_le32(U64_HI(params->dscr_map));
4698 rx_data->sge_page_base.lo =
4699 cpu_to_le32(U64_LO(params->sge_map));
4700 rx_data->sge_page_base.hi =
4701 cpu_to_le32(U64_HI(params->sge_map));
4702 rx_data->cqe_page_base.lo =
4703 cpu_to_le32(U64_LO(params->rcq_map));
4704 rx_data->cqe_page_base.hi =
4705 cpu_to_le32(U64_HI(params->rcq_map));
4706 rx_data->is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS, flags);
4707
4708 if (test_bit(BNX2X_Q_FLG_MCAST, flags)) {
Yuval Mintz259afa12012-03-12 08:53:10 +00004709 rx_data->approx_mcast_engine_id = params->mcast_engine_id;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004710 rx_data->is_approx_mcast = 1;
4711 }
4712
4713 rx_data->rss_engine_id = params->rss_engine_id;
4714
4715 /* silent vlan removal */
4716 rx_data->silent_vlan_removal_flg =
4717 test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, flags);
4718 rx_data->silent_vlan_value =
4719 cpu_to_le16(params->silent_removal_value);
4720 rx_data->silent_vlan_mask =
4721 cpu_to_le16(params->silent_removal_mask);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004722}
4723
4724/* initialize the general, tx and rx parts of a queue object */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004725static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
4726 struct bnx2x_queue_state_params *cmd_params,
4727 struct client_init_ramrod_data *data)
4728{
Ariel Elior6383c0b2011-07-14 08:31:57 +00004729 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4730 &cmd_params->params.setup.gen_params,
4731 &data->general,
4732 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004733
Ariel Elior6383c0b2011-07-14 08:31:57 +00004734 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4735 &cmd_params->params.setup.txq_params,
4736 &data->tx,
4737 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004738
Ariel Elior6383c0b2011-07-14 08:31:57 +00004739 bnx2x_q_fill_init_rx_data(cmd_params->q_obj,
4740 &cmd_params->params.setup.rxq_params,
4741 &data->rx,
4742 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004743
Ariel Elior6383c0b2011-07-14 08:31:57 +00004744 bnx2x_q_fill_init_pause_data(cmd_params->q_obj,
4745 &cmd_params->params.setup.pause_params,
4746 &data->rx);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004747}
4748
Ariel Elior6383c0b2011-07-14 08:31:57 +00004749/* initialize the general and tx parts of a tx-only queue object */
4750static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
4751 struct bnx2x_queue_state_params *cmd_params,
4752 struct tx_queue_init_ramrod_data *data)
4753{
4754 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4755 &cmd_params->params.tx_only.gen_params,
4756 &data->general,
4757 &cmd_params->params.tx_only.flags);
4758
4759 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4760 &cmd_params->params.tx_only.txq_params,
4761 &data->tx,
4762 &cmd_params->params.tx_only.flags);
4763
Merav Sicron51c1a582012-03-18 10:33:38 +00004764 DP(BNX2X_MSG_SP, "cid %d, tx bd page lo %x hi %x",
4765 cmd_params->q_obj->cids[0],
4766 data->tx.tx_bd_page_base.lo,
4767 data->tx.tx_bd_page_base.hi);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004768}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004769
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004770/**
4771 * bnx2x_q_init - init HW/FW queue
4772 *
4773 * @bp: device handle
4774 * @params:
4775 *
4776 * HW/FW initial Queue configuration:
4777 * - HC: Rx and Tx
4778 * - CDU context validation
4779 *
4780 */
4781static inline int bnx2x_q_init(struct bnx2x *bp,
4782 struct bnx2x_queue_state_params *params)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004783{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004784 struct bnx2x_queue_sp_obj *o = params->q_obj;
4785 struct bnx2x_queue_init_params *init = &params->params.init;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004786 u16 hc_usec;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004787 u8 cos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004788
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004789 /* Tx HC configuration */
4790 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
4791 test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
4792 hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
4793
4794 bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
4795 init->tx.sb_cq_index,
4796 !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004797 hc_usec);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004798 }
4799
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004800 /* Rx HC configuration */
4801 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
4802 test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
4803 hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004804
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004805 bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
4806 init->rx.sb_cq_index,
4807 !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
4808 hc_usec);
4809 }
4810
4811 /* Set CDU context validation values */
Ariel Elior6383c0b2011-07-14 08:31:57 +00004812 for (cos = 0; cos < o->max_cos; cos++) {
Joe Perches94f05b02011-08-14 12:16:20 +00004813 DP(BNX2X_MSG_SP, "setting context validation. cid %d, cos %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004814 o->cids[cos], cos);
Joe Perches94f05b02011-08-14 12:16:20 +00004815 DP(BNX2X_MSG_SP, "context pointer %p\n", init->cxts[cos]);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004816 bnx2x_set_ctx_validation(bp, init->cxts[cos], o->cids[cos]);
4817 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004818
4819 /* As no ramrod is sent, complete the command immediately */
4820 o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
4821
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004822 mmiowb();
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004823 smp_mb();
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004824
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004825 return 0;
4826}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004827
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004828static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
4829 struct bnx2x_queue_state_params *params)
4830{
4831 struct bnx2x_queue_sp_obj *o = params->q_obj;
4832 struct client_init_ramrod_data *rdata =
4833 (struct client_init_ramrod_data *)o->rdata;
4834 dma_addr_t data_mapping = o->rdata_mapping;
4835 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004836
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004837 /* Clear the ramrod data */
4838 memset(rdata, 0, sizeof(*rdata));
4839
4840 /* Fill the ramrod data */
4841 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4842
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004843 /* No need for an explicit memory barrier here as long we would
4844 * need to ensure the ordering of writing to the SPQ element
4845 * and updating of the SPQ producer which involves a memory
4846 * read and we will have to put a full memory barrier there
4847 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004848 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004849
Ariel Elior6383c0b2011-07-14 08:31:57 +00004850 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4851 U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004852 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4853}
4854
4855static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
4856 struct bnx2x_queue_state_params *params)
4857{
4858 struct bnx2x_queue_sp_obj *o = params->q_obj;
4859 struct client_init_ramrod_data *rdata =
4860 (struct client_init_ramrod_data *)o->rdata;
4861 dma_addr_t data_mapping = o->rdata_mapping;
4862 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4863
4864 /* Clear the ramrod data */
4865 memset(rdata, 0, sizeof(*rdata));
4866
4867 /* Fill the ramrod data */
4868 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4869 bnx2x_q_fill_setup_data_e2(bp, params, rdata);
4870
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004871 /* No need for an explicit memory barrier here as long we would
4872 * need to ensure the ordering of writing to the SPQ element
4873 * and updating of the SPQ producer which involves a memory
4874 * read and we will have to put a full memory barrier there
4875 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004876 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004877
Ariel Elior6383c0b2011-07-14 08:31:57 +00004878 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4879 U64_HI(data_mapping),
4880 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4881}
4882
4883static inline int bnx2x_q_send_setup_tx_only(struct bnx2x *bp,
4884 struct bnx2x_queue_state_params *params)
4885{
4886 struct bnx2x_queue_sp_obj *o = params->q_obj;
4887 struct tx_queue_init_ramrod_data *rdata =
4888 (struct tx_queue_init_ramrod_data *)o->rdata;
4889 dma_addr_t data_mapping = o->rdata_mapping;
4890 int ramrod = RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP;
4891 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
4892 &params->params.tx_only;
4893 u8 cid_index = tx_only_params->cid_index;
4894
Ariel Elior6383c0b2011-07-14 08:31:57 +00004895 if (cid_index >= o->max_cos) {
4896 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4897 o->cl_id, cid_index);
4898 return -EINVAL;
4899 }
4900
Joe Perches94f05b02011-08-14 12:16:20 +00004901 DP(BNX2X_MSG_SP, "parameters received: cos: %d sp-id: %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004902 tx_only_params->gen_params.cos,
4903 tx_only_params->gen_params.spcl_id);
4904
4905 /* Clear the ramrod data */
4906 memset(rdata, 0, sizeof(*rdata));
4907
4908 /* Fill the ramrod data */
4909 bnx2x_q_fill_setup_tx_only(bp, params, rdata);
4910
Merav Sicron51c1a582012-03-18 10:33:38 +00004911 DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
4912 o->cids[cid_index], rdata->general.client_id,
Ariel Elior6383c0b2011-07-14 08:31:57 +00004913 rdata->general.sp_client_id, rdata->general.cos);
4914
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004915 /* No need for an explicit memory barrier here as long we would
4916 * need to ensure the ordering of writing to the SPQ element
4917 * and updating of the SPQ producer which involves a memory
4918 * read and we will have to put a full memory barrier there
4919 * (inside bnx2x_sp_post()).
Ariel Elior6383c0b2011-07-14 08:31:57 +00004920 */
4921
4922 return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
4923 U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004924 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4925}
4926
4927static void bnx2x_q_fill_update_data(struct bnx2x *bp,
4928 struct bnx2x_queue_sp_obj *obj,
4929 struct bnx2x_queue_update_params *params,
4930 struct client_update_ramrod_data *data)
4931{
4932 /* Client ID of the client to update */
4933 data->client_id = obj->cl_id;
4934
4935 /* Function ID of the client to update */
4936 data->func_id = obj->func_id;
4937
4938 /* Default VLAN value */
4939 data->default_vlan = cpu_to_le16(params->def_vlan);
4940
4941 /* Inner VLAN stripping */
4942 data->inner_vlan_removal_enable_flg =
4943 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, &params->update_flags);
4944 data->inner_vlan_removal_change_flg =
4945 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
4946 &params->update_flags);
4947
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004948 /* Outer VLAN stripping */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004949 data->outer_vlan_removal_enable_flg =
4950 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, &params->update_flags);
4951 data->outer_vlan_removal_change_flg =
4952 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
4953 &params->update_flags);
4954
4955 /* Drop packets that have source MAC that doesn't belong to this
4956 * Queue.
4957 */
4958 data->anti_spoofing_enable_flg =
4959 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, &params->update_flags);
4960 data->anti_spoofing_change_flg =
4961 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, &params->update_flags);
4962
4963 /* Activate/Deactivate */
4964 data->activate_flg =
4965 test_bit(BNX2X_Q_UPDATE_ACTIVATE, &params->update_flags);
4966 data->activate_change_flg =
4967 test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &params->update_flags);
4968
4969 /* Enable default VLAN */
4970 data->default_vlan_enable_flg =
4971 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, &params->update_flags);
4972 data->default_vlan_change_flg =
4973 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
4974 &params->update_flags);
4975
4976 /* silent vlan removal */
4977 data->silent_vlan_change_flg =
4978 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4979 &params->update_flags);
4980 data->silent_vlan_removal_flg =
4981 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, &params->update_flags);
4982 data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
4983 data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
4984}
4985
4986static inline int bnx2x_q_send_update(struct bnx2x *bp,
4987 struct bnx2x_queue_state_params *params)
4988{
4989 struct bnx2x_queue_sp_obj *o = params->q_obj;
4990 struct client_update_ramrod_data *rdata =
4991 (struct client_update_ramrod_data *)o->rdata;
4992 dma_addr_t data_mapping = o->rdata_mapping;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004993 struct bnx2x_queue_update_params *update_params =
4994 &params->params.update;
4995 u8 cid_index = update_params->cid_index;
4996
4997 if (cid_index >= o->max_cos) {
4998 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4999 o->cl_id, cid_index);
5000 return -EINVAL;
5001 }
5002
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005003 /* Clear the ramrod data */
5004 memset(rdata, 0, sizeof(*rdata));
5005
5006 /* Fill the ramrod data */
Ariel Elior6383c0b2011-07-14 08:31:57 +00005007 bnx2x_q_fill_update_data(bp, o, update_params, rdata);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005008
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005009 /* No need for an explicit memory barrier here as long we would
5010 * need to ensure the ordering of writing to the SPQ element
5011 * and updating of the SPQ producer which involves a memory
5012 * read and we will have to put a full memory barrier there
5013 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00005014 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005015
Ariel Elior6383c0b2011-07-14 08:31:57 +00005016 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
5017 o->cids[cid_index], U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005018 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
5019}
5020
5021/**
5022 * bnx2x_q_send_deactivate - send DEACTIVATE command
5023 *
5024 * @bp: device handle
5025 * @params:
5026 *
5027 * implemented using the UPDATE command.
5028 */
5029static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
5030 struct bnx2x_queue_state_params *params)
5031{
5032 struct bnx2x_queue_update_params *update = &params->params.update;
5033
5034 memset(update, 0, sizeof(*update));
5035
5036 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
5037
5038 return bnx2x_q_send_update(bp, params);
5039}
5040
5041/**
5042 * bnx2x_q_send_activate - send ACTIVATE command
5043 *
5044 * @bp: device handle
5045 * @params:
5046 *
5047 * implemented using the UPDATE command.
5048 */
5049static inline int bnx2x_q_send_activate(struct bnx2x *bp,
5050 struct bnx2x_queue_state_params *params)
5051{
5052 struct bnx2x_queue_update_params *update = &params->params.update;
5053
5054 memset(update, 0, sizeof(*update));
5055
5056 __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
5057 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
5058
5059 return bnx2x_q_send_update(bp, params);
5060}
5061
5062static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
5063 struct bnx2x_queue_state_params *params)
5064{
5065 /* TODO: Not implemented yet. */
5066 return -1;
5067}
5068
5069static inline int bnx2x_q_send_halt(struct bnx2x *bp,
5070 struct bnx2x_queue_state_params *params)
5071{
5072 struct bnx2x_queue_sp_obj *o = params->q_obj;
5073
Ariel Elior6383c0b2011-07-14 08:31:57 +00005074 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT,
5075 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, o->cl_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005076 ETH_CONNECTION_TYPE);
5077}
5078
5079static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
5080 struct bnx2x_queue_state_params *params)
5081{
5082 struct bnx2x_queue_sp_obj *o = params->q_obj;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005083 u8 cid_idx = params->params.cfc_del.cid_index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005084
Ariel Elior6383c0b2011-07-14 08:31:57 +00005085 if (cid_idx >= o->max_cos) {
5086 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
5087 o->cl_id, cid_idx);
5088 return -EINVAL;
5089 }
5090
5091 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL,
5092 o->cids[cid_idx], 0, 0, NONE_CONNECTION_TYPE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005093}
5094
5095static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
5096 struct bnx2x_queue_state_params *params)
5097{
5098 struct bnx2x_queue_sp_obj *o = params->q_obj;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005099 u8 cid_index = params->params.terminate.cid_index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005100
Ariel Elior6383c0b2011-07-14 08:31:57 +00005101 if (cid_index >= o->max_cos) {
5102 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
5103 o->cl_id, cid_index);
5104 return -EINVAL;
5105 }
5106
5107 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE,
5108 o->cids[cid_index], 0, 0, ETH_CONNECTION_TYPE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005109}
5110
5111static inline int bnx2x_q_send_empty(struct bnx2x *bp,
5112 struct bnx2x_queue_state_params *params)
5113{
5114 struct bnx2x_queue_sp_obj *o = params->q_obj;
5115
Ariel Elior6383c0b2011-07-14 08:31:57 +00005116 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY,
5117 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005118 ETH_CONNECTION_TYPE);
5119}
5120
5121static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
5122 struct bnx2x_queue_state_params *params)
5123{
5124 switch (params->cmd) {
5125 case BNX2X_Q_CMD_INIT:
5126 return bnx2x_q_init(bp, params);
Ariel Elior6383c0b2011-07-14 08:31:57 +00005127 case BNX2X_Q_CMD_SETUP_TX_ONLY:
5128 return bnx2x_q_send_setup_tx_only(bp, params);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005129 case BNX2X_Q_CMD_DEACTIVATE:
5130 return bnx2x_q_send_deactivate(bp, params);
5131 case BNX2X_Q_CMD_ACTIVATE:
5132 return bnx2x_q_send_activate(bp, params);
5133 case BNX2X_Q_CMD_UPDATE:
5134 return bnx2x_q_send_update(bp, params);
5135 case BNX2X_Q_CMD_UPDATE_TPA:
5136 return bnx2x_q_send_update_tpa(bp, params);
5137 case BNX2X_Q_CMD_HALT:
5138 return bnx2x_q_send_halt(bp, params);
5139 case BNX2X_Q_CMD_CFC_DEL:
5140 return bnx2x_q_send_cfc_del(bp, params);
5141 case BNX2X_Q_CMD_TERMINATE:
5142 return bnx2x_q_send_terminate(bp, params);
5143 case BNX2X_Q_CMD_EMPTY:
5144 return bnx2x_q_send_empty(bp, params);
5145 default:
5146 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5147 return -EINVAL;
5148 }
5149}
5150
5151static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
5152 struct bnx2x_queue_state_params *params)
5153{
5154 switch (params->cmd) {
5155 case BNX2X_Q_CMD_SETUP:
5156 return bnx2x_q_send_setup_e1x(bp, params);
5157 case BNX2X_Q_CMD_INIT:
Ariel Elior6383c0b2011-07-14 08:31:57 +00005158 case BNX2X_Q_CMD_SETUP_TX_ONLY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005159 case BNX2X_Q_CMD_DEACTIVATE:
5160 case BNX2X_Q_CMD_ACTIVATE:
5161 case BNX2X_Q_CMD_UPDATE:
5162 case BNX2X_Q_CMD_UPDATE_TPA:
5163 case BNX2X_Q_CMD_HALT:
5164 case BNX2X_Q_CMD_CFC_DEL:
5165 case BNX2X_Q_CMD_TERMINATE:
5166 case BNX2X_Q_CMD_EMPTY:
5167 return bnx2x_queue_send_cmd_cmn(bp, params);
5168 default:
5169 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5170 return -EINVAL;
5171 }
5172}
5173
5174static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
5175 struct bnx2x_queue_state_params *params)
5176{
5177 switch (params->cmd) {
5178 case BNX2X_Q_CMD_SETUP:
5179 return bnx2x_q_send_setup_e2(bp, params);
5180 case BNX2X_Q_CMD_INIT:
Ariel Elior6383c0b2011-07-14 08:31:57 +00005181 case BNX2X_Q_CMD_SETUP_TX_ONLY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005182 case BNX2X_Q_CMD_DEACTIVATE:
5183 case BNX2X_Q_CMD_ACTIVATE:
5184 case BNX2X_Q_CMD_UPDATE:
5185 case BNX2X_Q_CMD_UPDATE_TPA:
5186 case BNX2X_Q_CMD_HALT:
5187 case BNX2X_Q_CMD_CFC_DEL:
5188 case BNX2X_Q_CMD_TERMINATE:
5189 case BNX2X_Q_CMD_EMPTY:
5190 return bnx2x_queue_send_cmd_cmn(bp, params);
5191 default:
5192 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5193 return -EINVAL;
5194 }
5195}
5196
5197/**
5198 * bnx2x_queue_chk_transition - check state machine of a regular Queue
5199 *
5200 * @bp: device handle
5201 * @o:
5202 * @params:
5203 *
5204 * (not Forwarding)
5205 * It both checks if the requested command is legal in a current
5206 * state and, if it's legal, sets a `next_state' in the object
5207 * that will be used in the completion flow to set the `state'
5208 * of the object.
5209 *
5210 * returns 0 if a requested command is a legal transition,
5211 * -EINVAL otherwise.
5212 */
5213static int bnx2x_queue_chk_transition(struct bnx2x *bp,
5214 struct bnx2x_queue_sp_obj *o,
5215 struct bnx2x_queue_state_params *params)
5216{
5217 enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
5218 enum bnx2x_queue_cmd cmd = params->cmd;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005219 struct bnx2x_queue_update_params *update_params =
5220 &params->params.update;
5221 u8 next_tx_only = o->num_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005222
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005223 /* Forget all pending for completion commands if a driver only state
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005224 * transition has been requested.
5225 */
5226 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5227 o->pending = 0;
5228 o->next_state = BNX2X_Q_STATE_MAX;
5229 }
5230
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005231 /* Don't allow a next state transition if we are in the middle of
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005232 * the previous one.
5233 */
Yuval Mintz04c46732013-01-23 03:21:46 +00005234 if (o->pending) {
5235 BNX2X_ERR("Blocking transition since pending was %lx\n",
5236 o->pending);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005237 return -EBUSY;
Yuval Mintz04c46732013-01-23 03:21:46 +00005238 }
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005239
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005240 switch (state) {
5241 case BNX2X_Q_STATE_RESET:
5242 if (cmd == BNX2X_Q_CMD_INIT)
5243 next_state = BNX2X_Q_STATE_INITIALIZED;
5244
5245 break;
5246 case BNX2X_Q_STATE_INITIALIZED:
5247 if (cmd == BNX2X_Q_CMD_SETUP) {
5248 if (test_bit(BNX2X_Q_FLG_ACTIVE,
5249 &params->params.setup.flags))
5250 next_state = BNX2X_Q_STATE_ACTIVE;
5251 else
5252 next_state = BNX2X_Q_STATE_INACTIVE;
5253 }
5254
5255 break;
5256 case BNX2X_Q_STATE_ACTIVE:
5257 if (cmd == BNX2X_Q_CMD_DEACTIVATE)
5258 next_state = BNX2X_Q_STATE_INACTIVE;
5259
5260 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5261 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5262 next_state = BNX2X_Q_STATE_ACTIVE;
5263
Ariel Elior6383c0b2011-07-14 08:31:57 +00005264 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5265 next_state = BNX2X_Q_STATE_MULTI_COS;
5266 next_tx_only = 1;
5267 }
5268
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005269 else if (cmd == BNX2X_Q_CMD_HALT)
5270 next_state = BNX2X_Q_STATE_STOPPED;
5271
5272 else if (cmd == BNX2X_Q_CMD_UPDATE) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005273 /* If "active" state change is requested, update the
5274 * state accordingly.
5275 */
5276 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5277 &update_params->update_flags) &&
5278 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5279 &update_params->update_flags))
5280 next_state = BNX2X_Q_STATE_INACTIVE;
5281 else
5282 next_state = BNX2X_Q_STATE_ACTIVE;
5283 }
5284
5285 break;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005286 case BNX2X_Q_STATE_MULTI_COS:
5287 if (cmd == BNX2X_Q_CMD_TERMINATE)
5288 next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
5289
5290 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5291 next_state = BNX2X_Q_STATE_MULTI_COS;
5292 next_tx_only = o->num_tx_only + 1;
5293 }
5294
5295 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5296 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5297 next_state = BNX2X_Q_STATE_MULTI_COS;
5298
5299 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5300 /* If "active" state change is requested, update the
5301 * state accordingly.
5302 */
5303 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5304 &update_params->update_flags) &&
5305 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5306 &update_params->update_flags))
5307 next_state = BNX2X_Q_STATE_INACTIVE;
5308 else
5309 next_state = BNX2X_Q_STATE_MULTI_COS;
5310 }
5311
5312 break;
5313 case BNX2X_Q_STATE_MCOS_TERMINATED:
5314 if (cmd == BNX2X_Q_CMD_CFC_DEL) {
5315 next_tx_only = o->num_tx_only - 1;
5316 if (next_tx_only == 0)
5317 next_state = BNX2X_Q_STATE_ACTIVE;
5318 else
5319 next_state = BNX2X_Q_STATE_MULTI_COS;
5320 }
5321
5322 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005323 case BNX2X_Q_STATE_INACTIVE:
5324 if (cmd == BNX2X_Q_CMD_ACTIVATE)
5325 next_state = BNX2X_Q_STATE_ACTIVE;
5326
5327 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5328 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5329 next_state = BNX2X_Q_STATE_INACTIVE;
5330
5331 else if (cmd == BNX2X_Q_CMD_HALT)
5332 next_state = BNX2X_Q_STATE_STOPPED;
5333
5334 else if (cmd == BNX2X_Q_CMD_UPDATE) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005335 /* If "active" state change is requested, update the
5336 * state accordingly.
5337 */
5338 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5339 &update_params->update_flags) &&
5340 test_bit(BNX2X_Q_UPDATE_ACTIVATE,
Ariel Elior6383c0b2011-07-14 08:31:57 +00005341 &update_params->update_flags)){
5342 if (o->num_tx_only == 0)
5343 next_state = BNX2X_Q_STATE_ACTIVE;
5344 else /* tx only queues exist for this queue */
5345 next_state = BNX2X_Q_STATE_MULTI_COS;
5346 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005347 next_state = BNX2X_Q_STATE_INACTIVE;
5348 }
5349
5350 break;
5351 case BNX2X_Q_STATE_STOPPED:
5352 if (cmd == BNX2X_Q_CMD_TERMINATE)
5353 next_state = BNX2X_Q_STATE_TERMINATED;
5354
5355 break;
5356 case BNX2X_Q_STATE_TERMINATED:
5357 if (cmd == BNX2X_Q_CMD_CFC_DEL)
5358 next_state = BNX2X_Q_STATE_RESET;
5359
5360 break;
5361 default:
5362 BNX2X_ERR("Illegal state: %d\n", state);
5363 }
5364
5365 /* Transition is assured */
5366 if (next_state != BNX2X_Q_STATE_MAX) {
5367 DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
5368 state, cmd, next_state);
5369 o->next_state = next_state;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005370 o->next_tx_only = next_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005371 return 0;
5372 }
5373
5374 DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
5375
5376 return -EINVAL;
5377}
5378
5379void bnx2x_init_queue_obj(struct bnx2x *bp,
5380 struct bnx2x_queue_sp_obj *obj,
Ariel Elior6383c0b2011-07-14 08:31:57 +00005381 u8 cl_id, u32 *cids, u8 cid_cnt, u8 func_id,
5382 void *rdata,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005383 dma_addr_t rdata_mapping, unsigned long type)
5384{
5385 memset(obj, 0, sizeof(*obj));
5386
Ariel Elior6383c0b2011-07-14 08:31:57 +00005387 /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
5388 BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
5389
5390 memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
5391 obj->max_cos = cid_cnt;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005392 obj->cl_id = cl_id;
5393 obj->func_id = func_id;
5394 obj->rdata = rdata;
5395 obj->rdata_mapping = rdata_mapping;
5396 obj->type = type;
5397 obj->next_state = BNX2X_Q_STATE_MAX;
5398
5399 if (CHIP_IS_E1x(bp))
5400 obj->send_cmd = bnx2x_queue_send_cmd_e1x;
5401 else
5402 obj->send_cmd = bnx2x_queue_send_cmd_e2;
5403
5404 obj->check_transition = bnx2x_queue_chk_transition;
5405
5406 obj->complete_cmd = bnx2x_queue_comp_cmd;
5407 obj->wait_comp = bnx2x_queue_wait_comp;
5408 obj->set_pending = bnx2x_queue_set_pending;
5409}
5410
Ariel Elior67c431a2013-01-01 05:22:36 +00005411/* return a queue object's logical state*/
5412int bnx2x_get_q_logical_state(struct bnx2x *bp,
5413 struct bnx2x_queue_sp_obj *obj)
5414{
5415 switch (obj->state) {
5416 case BNX2X_Q_STATE_ACTIVE:
5417 case BNX2X_Q_STATE_MULTI_COS:
5418 return BNX2X_Q_LOGICAL_STATE_ACTIVE;
5419 case BNX2X_Q_STATE_RESET:
5420 case BNX2X_Q_STATE_INITIALIZED:
5421 case BNX2X_Q_STATE_MCOS_TERMINATED:
5422 case BNX2X_Q_STATE_INACTIVE:
5423 case BNX2X_Q_STATE_STOPPED:
5424 case BNX2X_Q_STATE_TERMINATED:
5425 case BNX2X_Q_STATE_FLRED:
5426 return BNX2X_Q_LOGICAL_STATE_STOPPED;
5427 default:
5428 return -EINVAL;
5429 }
5430}
5431
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005432/********************** Function state object *********************************/
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005433enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
5434 struct bnx2x_func_sp_obj *o)
5435{
5436 /* in the middle of transaction - return INVALID state */
5437 if (o->pending)
5438 return BNX2X_F_STATE_MAX;
5439
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005440 /* unsure the order of reading of o->pending and o->state
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005441 * o->pending should be read first
5442 */
5443 rmb();
5444
5445 return o->state;
5446}
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005447
5448static int bnx2x_func_wait_comp(struct bnx2x *bp,
5449 struct bnx2x_func_sp_obj *o,
5450 enum bnx2x_func_cmd cmd)
5451{
5452 return bnx2x_state_wait(bp, cmd, &o->pending);
5453}
5454
5455/**
5456 * bnx2x_func_state_change_comp - complete the state machine transition
5457 *
5458 * @bp: device handle
5459 * @o:
5460 * @cmd:
5461 *
5462 * Called on state change transition. Completes the state
5463 * machine transition only - no HW interaction.
5464 */
5465static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
5466 struct bnx2x_func_sp_obj *o,
5467 enum bnx2x_func_cmd cmd)
5468{
5469 unsigned long cur_pending = o->pending;
5470
5471 if (!test_and_clear_bit(cmd, &cur_pending)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00005472 BNX2X_ERR("Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
5473 cmd, BP_FUNC(bp), o->state,
5474 cur_pending, o->next_state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005475 return -EINVAL;
5476 }
5477
Joe Perches94f05b02011-08-14 12:16:20 +00005478 DP(BNX2X_MSG_SP,
5479 "Completing command %d for func %d, setting state to %d\n",
5480 cmd, BP_FUNC(bp), o->next_state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005481
5482 o->state = o->next_state;
5483 o->next_state = BNX2X_F_STATE_MAX;
5484
5485 /* It's important that o->state and o->next_state are
5486 * updated before o->pending.
5487 */
5488 wmb();
5489
5490 clear_bit(cmd, &o->pending);
5491 smp_mb__after_clear_bit();
5492
5493 return 0;
5494}
5495
5496/**
5497 * bnx2x_func_comp_cmd - complete the state change command
5498 *
5499 * @bp: device handle
5500 * @o:
5501 * @cmd:
5502 *
5503 * Checks that the arrived completion is expected.
5504 */
5505static int bnx2x_func_comp_cmd(struct bnx2x *bp,
5506 struct bnx2x_func_sp_obj *o,
5507 enum bnx2x_func_cmd cmd)
5508{
5509 /* Complete the state machine part first, check if it's a
5510 * legal completion.
5511 */
5512 int rc = bnx2x_func_state_change_comp(bp, o, cmd);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005513 return rc;
5514}
5515
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005516/**
5517 * bnx2x_func_chk_transition - perform function state machine transition
5518 *
5519 * @bp: device handle
5520 * @o:
5521 * @params:
5522 *
5523 * It both checks if the requested command is legal in a current
5524 * state and, if it's legal, sets a `next_state' in the object
5525 * that will be used in the completion flow to set the `state'
5526 * of the object.
5527 *
5528 * returns 0 if a requested command is a legal transition,
5529 * -EINVAL otherwise.
5530 */
5531static int bnx2x_func_chk_transition(struct bnx2x *bp,
5532 struct bnx2x_func_sp_obj *o,
5533 struct bnx2x_func_state_params *params)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005534{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005535 enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
5536 enum bnx2x_func_cmd cmd = params->cmd;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005537
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005538 /* Forget all pending for completion commands if a driver only state
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005539 * transition has been requested.
5540 */
5541 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5542 o->pending = 0;
5543 o->next_state = BNX2X_F_STATE_MAX;
5544 }
5545
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005546 /* Don't allow a next state transition if we are in the middle of
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005547 * the previous one.
5548 */
5549 if (o->pending)
5550 return -EBUSY;
5551
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005552 switch (state) {
5553 case BNX2X_F_STATE_RESET:
5554 if (cmd == BNX2X_F_CMD_HW_INIT)
5555 next_state = BNX2X_F_STATE_INITIALIZED;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005556
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005557 break;
5558 case BNX2X_F_STATE_INITIALIZED:
5559 if (cmd == BNX2X_F_CMD_START)
5560 next_state = BNX2X_F_STATE_STARTED;
5561
5562 else if (cmd == BNX2X_F_CMD_HW_RESET)
5563 next_state = BNX2X_F_STATE_RESET;
5564
5565 break;
5566 case BNX2X_F_STATE_STARTED:
5567 if (cmd == BNX2X_F_CMD_STOP)
5568 next_state = BNX2X_F_STATE_INITIALIZED;
Barak Witkowskia3348722012-04-23 03:04:46 +00005569 /* afex ramrods can be sent only in started mode, and only
5570 * if not pending for function_stop ramrod completion
5571 * for these events - next state remained STARTED.
5572 */
5573 else if ((cmd == BNX2X_F_CMD_AFEX_UPDATE) &&
5574 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5575 next_state = BNX2X_F_STATE_STARTED;
5576
5577 else if ((cmd == BNX2X_F_CMD_AFEX_VIFLISTS) &&
5578 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5579 next_state = BNX2X_F_STATE_STARTED;
Merav Sicron55c11942012-11-07 00:45:48 +00005580
5581 /* Switch_update ramrod can be sent in either started or
5582 * tx_stopped state, and it doesn't change the state.
5583 */
5584 else if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5585 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5586 next_state = BNX2X_F_STATE_STARTED;
5587
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005588 else if (cmd == BNX2X_F_CMD_TX_STOP)
5589 next_state = BNX2X_F_STATE_TX_STOPPED;
5590
5591 break;
5592 case BNX2X_F_STATE_TX_STOPPED:
Merav Sicron55c11942012-11-07 00:45:48 +00005593 if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5594 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5595 next_state = BNX2X_F_STATE_TX_STOPPED;
5596
5597 else if (cmd == BNX2X_F_CMD_TX_START)
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005598 next_state = BNX2X_F_STATE_STARTED;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005599
5600 break;
5601 default:
5602 BNX2X_ERR("Unknown state: %d\n", state);
5603 }
5604
5605 /* Transition is assured */
5606 if (next_state != BNX2X_F_STATE_MAX) {
5607 DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
5608 state, cmd, next_state);
5609 o->next_state = next_state;
5610 return 0;
5611 }
5612
5613 DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
5614 state, cmd);
5615
5616 return -EINVAL;
5617}
5618
5619/**
5620 * bnx2x_func_init_func - performs HW init at function stage
5621 *
5622 * @bp: device handle
5623 * @drv:
5624 *
5625 * Init HW when the current phase is
5626 * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
5627 * HW blocks.
5628 */
5629static inline int bnx2x_func_init_func(struct bnx2x *bp,
5630 const struct bnx2x_func_sp_drv_ops *drv)
5631{
5632 return drv->init_hw_func(bp);
5633}
5634
5635/**
5636 * bnx2x_func_init_port - performs HW init at port stage
5637 *
5638 * @bp: device handle
5639 * @drv:
5640 *
5641 * Init HW when the current phase is
5642 * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
5643 * FUNCTION-only HW blocks.
5644 *
5645 */
5646static inline int bnx2x_func_init_port(struct bnx2x *bp,
5647 const struct bnx2x_func_sp_drv_ops *drv)
5648{
5649 int rc = drv->init_hw_port(bp);
5650 if (rc)
5651 return rc;
5652
5653 return bnx2x_func_init_func(bp, drv);
5654}
5655
5656/**
5657 * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
5658 *
5659 * @bp: device handle
5660 * @drv:
5661 *
5662 * Init HW when the current phase is
5663 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
5664 * PORT-only and FUNCTION-only HW blocks.
5665 */
5666static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
5667 const struct bnx2x_func_sp_drv_ops *drv)
5668{
5669 int rc = drv->init_hw_cmn_chip(bp);
5670 if (rc)
5671 return rc;
5672
5673 return bnx2x_func_init_port(bp, drv);
5674}
5675
5676/**
5677 * bnx2x_func_init_cmn - performs HW init at common stage
5678 *
5679 * @bp: device handle
5680 * @drv:
5681 *
5682 * Init HW when the current phase is
5683 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
5684 * PORT-only and FUNCTION-only HW blocks.
5685 */
5686static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
5687 const struct bnx2x_func_sp_drv_ops *drv)
5688{
5689 int rc = drv->init_hw_cmn(bp);
5690 if (rc)
5691 return rc;
5692
5693 return bnx2x_func_init_port(bp, drv);
5694}
5695
5696static int bnx2x_func_hw_init(struct bnx2x *bp,
5697 struct bnx2x_func_state_params *params)
5698{
5699 u32 load_code = params->params.hw_init.load_phase;
5700 struct bnx2x_func_sp_obj *o = params->f_obj;
5701 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5702 int rc = 0;
5703
5704 DP(BNX2X_MSG_SP, "function %d load_code %x\n",
5705 BP_ABS_FUNC(bp), load_code);
5706
5707 /* Prepare buffers for unzipping the FW */
5708 rc = drv->gunzip_init(bp);
5709 if (rc)
5710 return rc;
5711
5712 /* Prepare FW */
5713 rc = drv->init_fw(bp);
5714 if (rc) {
5715 BNX2X_ERR("Error loading firmware\n");
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005716 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005717 }
5718
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005719 /* Handle the beginning of COMMON_XXX pases separately... */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005720 switch (load_code) {
5721 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5722 rc = bnx2x_func_init_cmn_chip(bp, drv);
5723 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005724 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005725
5726 break;
5727 case FW_MSG_CODE_DRV_LOAD_COMMON:
5728 rc = bnx2x_func_init_cmn(bp, drv);
5729 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005730 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005731
5732 break;
5733 case FW_MSG_CODE_DRV_LOAD_PORT:
5734 rc = bnx2x_func_init_port(bp, drv);
5735 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005736 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005737
5738 break;
5739 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5740 rc = bnx2x_func_init_func(bp, drv);
5741 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005742 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005743
5744 break;
5745 default:
5746 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5747 rc = -EINVAL;
5748 }
5749
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005750init_err:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005751 drv->gunzip_end(bp);
5752
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005753 /* In case of success, complete the command immediately: no ramrods
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005754 * have been sent.
5755 */
5756 if (!rc)
5757 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
5758
5759 return rc;
5760}
5761
5762/**
5763 * bnx2x_func_reset_func - reset HW at function stage
5764 *
5765 * @bp: device handle
5766 * @drv:
5767 *
5768 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
5769 * FUNCTION-only HW blocks.
5770 */
5771static inline void bnx2x_func_reset_func(struct bnx2x *bp,
5772 const struct bnx2x_func_sp_drv_ops *drv)
5773{
5774 drv->reset_hw_func(bp);
5775}
5776
5777/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005778 * bnx2x_func_reset_port - reset HW at port stage
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005779 *
5780 * @bp: device handle
5781 * @drv:
5782 *
5783 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
5784 * FUNCTION-only and PORT-only HW blocks.
5785 *
5786 * !!!IMPORTANT!!!
5787 *
5788 * It's important to call reset_port before reset_func() as the last thing
5789 * reset_func does is pf_disable() thus disabling PGLUE_B, which
5790 * makes impossible any DMAE transactions.
5791 */
5792static inline void bnx2x_func_reset_port(struct bnx2x *bp,
5793 const struct bnx2x_func_sp_drv_ops *drv)
5794{
5795 drv->reset_hw_port(bp);
5796 bnx2x_func_reset_func(bp, drv);
5797}
5798
5799/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005800 * bnx2x_func_reset_cmn - reset HW at common stage
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005801 *
5802 * @bp: device handle
5803 * @drv:
5804 *
5805 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
5806 * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
5807 * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
5808 */
5809static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
5810 const struct bnx2x_func_sp_drv_ops *drv)
5811{
5812 bnx2x_func_reset_port(bp, drv);
5813 drv->reset_hw_cmn(bp);
5814}
5815
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005816static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
5817 struct bnx2x_func_state_params *params)
5818{
5819 u32 reset_phase = params->params.hw_reset.reset_phase;
5820 struct bnx2x_func_sp_obj *o = params->f_obj;
5821 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5822
5823 DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
5824 reset_phase);
5825
5826 switch (reset_phase) {
5827 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
5828 bnx2x_func_reset_cmn(bp, drv);
5829 break;
5830 case FW_MSG_CODE_DRV_UNLOAD_PORT:
5831 bnx2x_func_reset_port(bp, drv);
5832 break;
5833 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
5834 bnx2x_func_reset_func(bp, drv);
5835 break;
5836 default:
5837 BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
5838 reset_phase);
5839 break;
5840 }
5841
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005842 /* Complete the command immediately: no ramrods have been sent. */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005843 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
5844
5845 return 0;
5846}
5847
5848static inline int bnx2x_func_send_start(struct bnx2x *bp,
5849 struct bnx2x_func_state_params *params)
5850{
5851 struct bnx2x_func_sp_obj *o = params->f_obj;
5852 struct function_start_data *rdata =
5853 (struct function_start_data *)o->rdata;
5854 dma_addr_t data_mapping = o->rdata_mapping;
5855 struct bnx2x_func_start_params *start_params = &params->params.start;
5856
5857 memset(rdata, 0, sizeof(*rdata));
5858
5859 /* Fill the ramrod data with provided parameters */
Dmitry Kravkov1bc277f2013-03-18 06:51:04 +00005860 rdata->function_mode = (u8)start_params->mf_mode;
5861 rdata->sd_vlan_tag = cpu_to_le16(start_params->sd_vlan_tag);
5862 rdata->path_id = BP_PATH(bp);
5863 rdata->network_cos_mode = start_params->network_cos_mode;
5864 rdata->gre_tunnel_mode = start_params->gre_tunnel_mode;
5865 rdata->gre_tunnel_rss = start_params->gre_tunnel_rss;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005866
Dmitry Kravkov1bc277f2013-03-18 06:51:04 +00005867 /* No need for an explicit memory barrier here as long we would
5868 * need to ensure the ordering of writing to the SPQ element
5869 * and updating of the SPQ producer which involves a memory
5870 * read and we will have to put a full memory barrier there
5871 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00005872 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005873
5874 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
5875 U64_HI(data_mapping),
5876 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5877}
5878
Merav Sicron55c11942012-11-07 00:45:48 +00005879static inline int bnx2x_func_send_switch_update(struct bnx2x *bp,
5880 struct bnx2x_func_state_params *params)
5881{
5882 struct bnx2x_func_sp_obj *o = params->f_obj;
5883 struct function_update_data *rdata =
5884 (struct function_update_data *)o->rdata;
5885 dma_addr_t data_mapping = o->rdata_mapping;
5886 struct bnx2x_func_switch_update_params *switch_update_params =
5887 &params->params.switch_update;
5888
5889 memset(rdata, 0, sizeof(*rdata));
5890
5891 /* Fill the ramrod data with provided parameters */
5892 rdata->tx_switch_suspend_change_flg = 1;
5893 rdata->tx_switch_suspend = switch_update_params->suspend;
5894 rdata->echo = SWITCH_UPDATE;
5895
5896 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5897 U64_HI(data_mapping),
5898 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5899}
5900
Barak Witkowskia3348722012-04-23 03:04:46 +00005901static inline int bnx2x_func_send_afex_update(struct bnx2x *bp,
5902 struct bnx2x_func_state_params *params)
5903{
5904 struct bnx2x_func_sp_obj *o = params->f_obj;
5905 struct function_update_data *rdata =
5906 (struct function_update_data *)o->afex_rdata;
5907 dma_addr_t data_mapping = o->afex_rdata_mapping;
5908 struct bnx2x_func_afex_update_params *afex_update_params =
5909 &params->params.afex_update;
5910
5911 memset(rdata, 0, sizeof(*rdata));
5912
5913 /* Fill the ramrod data with provided parameters */
5914 rdata->vif_id_change_flg = 1;
5915 rdata->vif_id = cpu_to_le16(afex_update_params->vif_id);
5916 rdata->afex_default_vlan_change_flg = 1;
5917 rdata->afex_default_vlan =
5918 cpu_to_le16(afex_update_params->afex_default_vlan);
5919 rdata->allowed_priorities_change_flg = 1;
5920 rdata->allowed_priorities = afex_update_params->allowed_priorities;
Merav Sicron55c11942012-11-07 00:45:48 +00005921 rdata->echo = AFEX_UPDATE;
Barak Witkowskia3348722012-04-23 03:04:46 +00005922
5923 /* No need for an explicit memory barrier here as long we would
5924 * need to ensure the ordering of writing to the SPQ element
5925 * and updating of the SPQ producer which involves a memory
5926 * read and we will have to put a full memory barrier there
5927 * (inside bnx2x_sp_post()).
5928 */
5929 DP(BNX2X_MSG_SP,
5930 "afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
5931 rdata->vif_id,
5932 rdata->afex_default_vlan, rdata->allowed_priorities);
5933
5934 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5935 U64_HI(data_mapping),
5936 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5937}
5938
5939static
5940inline int bnx2x_func_send_afex_viflists(struct bnx2x *bp,
5941 struct bnx2x_func_state_params *params)
5942{
5943 struct bnx2x_func_sp_obj *o = params->f_obj;
5944 struct afex_vif_list_ramrod_data *rdata =
5945 (struct afex_vif_list_ramrod_data *)o->afex_rdata;
Yuval Mintz86564c32013-01-23 03:21:50 +00005946 struct bnx2x_func_afex_viflists_params *afex_vif_params =
Barak Witkowskia3348722012-04-23 03:04:46 +00005947 &params->params.afex_viflists;
5948 u64 *p_rdata = (u64 *)rdata;
5949
5950 memset(rdata, 0, sizeof(*rdata));
5951
5952 /* Fill the ramrod data with provided parameters */
Yuval Mintz86564c32013-01-23 03:21:50 +00005953 rdata->vif_list_index = cpu_to_le16(afex_vif_params->vif_list_index);
5954 rdata->func_bit_map = afex_vif_params->func_bit_map;
5955 rdata->afex_vif_list_command = afex_vif_params->afex_vif_list_command;
5956 rdata->func_to_clear = afex_vif_params->func_to_clear;
Barak Witkowskia3348722012-04-23 03:04:46 +00005957
5958 /* send in echo type of sub command */
Yuval Mintz86564c32013-01-23 03:21:50 +00005959 rdata->echo = afex_vif_params->afex_vif_list_command;
Barak Witkowskia3348722012-04-23 03:04:46 +00005960
5961 /* No need for an explicit memory barrier here as long we would
5962 * need to ensure the ordering of writing to the SPQ element
5963 * and updating of the SPQ producer which involves a memory
5964 * read and we will have to put a full memory barrier there
5965 * (inside bnx2x_sp_post()).
5966 */
5967
5968 DP(BNX2X_MSG_SP, "afex: ramrod lists, cmd 0x%x index 0x%x func_bit_map 0x%x func_to_clr 0x%x\n",
5969 rdata->afex_vif_list_command, rdata->vif_list_index,
5970 rdata->func_bit_map, rdata->func_to_clear);
5971
5972 /* this ramrod sends data directly and not through DMA mapping */
5973 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_AFEX_VIF_LISTS, 0,
5974 U64_HI(*p_rdata), U64_LO(*p_rdata),
5975 NONE_CONNECTION_TYPE);
5976}
5977
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005978static inline int bnx2x_func_send_stop(struct bnx2x *bp,
5979 struct bnx2x_func_state_params *params)
5980{
5981 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
5982 NONE_CONNECTION_TYPE);
5983}
5984
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005985static inline int bnx2x_func_send_tx_stop(struct bnx2x *bp,
5986 struct bnx2x_func_state_params *params)
5987{
5988 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC, 0, 0, 0,
5989 NONE_CONNECTION_TYPE);
5990}
5991static inline int bnx2x_func_send_tx_start(struct bnx2x *bp,
5992 struct bnx2x_func_state_params *params)
5993{
5994 struct bnx2x_func_sp_obj *o = params->f_obj;
5995 struct flow_control_configuration *rdata =
5996 (struct flow_control_configuration *)o->rdata;
5997 dma_addr_t data_mapping = o->rdata_mapping;
5998 struct bnx2x_func_tx_start_params *tx_start_params =
5999 &params->params.tx_start;
6000 int i;
6001
6002 memset(rdata, 0, sizeof(*rdata));
6003
6004 rdata->dcb_enabled = tx_start_params->dcb_enabled;
6005 rdata->dcb_version = tx_start_params->dcb_version;
6006 rdata->dont_add_pri_0_en = tx_start_params->dont_add_pri_0_en;
6007
6008 for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
6009 rdata->traffic_type_to_priority_cos[i] =
6010 tx_start_params->traffic_type_to_priority_cos[i];
6011
6012 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
6013 U64_HI(data_mapping),
6014 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
6015}
6016
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006017static int bnx2x_func_send_cmd(struct bnx2x *bp,
6018 struct bnx2x_func_state_params *params)
6019{
6020 switch (params->cmd) {
6021 case BNX2X_F_CMD_HW_INIT:
6022 return bnx2x_func_hw_init(bp, params);
6023 case BNX2X_F_CMD_START:
6024 return bnx2x_func_send_start(bp, params);
6025 case BNX2X_F_CMD_STOP:
6026 return bnx2x_func_send_stop(bp, params);
6027 case BNX2X_F_CMD_HW_RESET:
6028 return bnx2x_func_hw_reset(bp, params);
Barak Witkowskia3348722012-04-23 03:04:46 +00006029 case BNX2X_F_CMD_AFEX_UPDATE:
6030 return bnx2x_func_send_afex_update(bp, params);
6031 case BNX2X_F_CMD_AFEX_VIFLISTS:
6032 return bnx2x_func_send_afex_viflists(bp, params);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00006033 case BNX2X_F_CMD_TX_STOP:
6034 return bnx2x_func_send_tx_stop(bp, params);
6035 case BNX2X_F_CMD_TX_START:
6036 return bnx2x_func_send_tx_start(bp, params);
Merav Sicron55c11942012-11-07 00:45:48 +00006037 case BNX2X_F_CMD_SWITCH_UPDATE:
6038 return bnx2x_func_send_switch_update(bp, params);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006039 default:
6040 BNX2X_ERR("Unknown command: %d\n", params->cmd);
6041 return -EINVAL;
6042 }
6043}
6044
6045void bnx2x_init_func_obj(struct bnx2x *bp,
6046 struct bnx2x_func_sp_obj *obj,
6047 void *rdata, dma_addr_t rdata_mapping,
Barak Witkowskia3348722012-04-23 03:04:46 +00006048 void *afex_rdata, dma_addr_t afex_rdata_mapping,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006049 struct bnx2x_func_sp_drv_ops *drv_iface)
6050{
6051 memset(obj, 0, sizeof(*obj));
6052
6053 mutex_init(&obj->one_pending_mutex);
6054
6055 obj->rdata = rdata;
6056 obj->rdata_mapping = rdata_mapping;
Barak Witkowskia3348722012-04-23 03:04:46 +00006057 obj->afex_rdata = afex_rdata;
6058 obj->afex_rdata_mapping = afex_rdata_mapping;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006059 obj->send_cmd = bnx2x_func_send_cmd;
6060 obj->check_transition = bnx2x_func_chk_transition;
6061 obj->complete_cmd = bnx2x_func_comp_cmd;
6062 obj->wait_comp = bnx2x_func_wait_comp;
6063
6064 obj->drv = drv_iface;
6065}
6066
6067/**
6068 * bnx2x_func_state_change - perform Function state change transition
6069 *
6070 * @bp: device handle
6071 * @params: parameters to perform the transaction
6072 *
6073 * returns 0 in case of successfully completed transition,
6074 * negative error code in case of failure, positive
6075 * (EBUSY) value if there is a completion to that is
6076 * still pending (possible only if RAMROD_COMP_WAIT is
6077 * not set in params->ramrod_flags for asynchronous
6078 * commands).
6079 */
6080int bnx2x_func_state_change(struct bnx2x *bp,
6081 struct bnx2x_func_state_params *params)
6082{
6083 struct bnx2x_func_sp_obj *o = params->f_obj;
Merav Sicron55c11942012-11-07 00:45:48 +00006084 int rc, cnt = 300;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006085 enum bnx2x_func_cmd cmd = params->cmd;
6086 unsigned long *pending = &o->pending;
6087
6088 mutex_lock(&o->one_pending_mutex);
6089
6090 /* Check that the requested transition is legal */
Merav Sicron55c11942012-11-07 00:45:48 +00006091 rc = o->check_transition(bp, o, params);
6092 if ((rc == -EBUSY) &&
6093 (test_bit(RAMROD_RETRY, &params->ramrod_flags))) {
6094 while ((rc == -EBUSY) && (--cnt > 0)) {
6095 mutex_unlock(&o->one_pending_mutex);
6096 msleep(10);
6097 mutex_lock(&o->one_pending_mutex);
6098 rc = o->check_transition(bp, o, params);
6099 }
6100 if (rc == -EBUSY) {
6101 mutex_unlock(&o->one_pending_mutex);
6102 BNX2X_ERR("timeout waiting for previous ramrod completion\n");
6103 return rc;
6104 }
6105 } else if (rc) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006106 mutex_unlock(&o->one_pending_mutex);
Merav Sicron55c11942012-11-07 00:45:48 +00006107 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006108 }
6109
6110 /* Set "pending" bit */
6111 set_bit(cmd, pending);
6112
6113 /* Don't send a command if only driver cleanup was requested */
6114 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
6115 bnx2x_func_state_change_comp(bp, o, cmd);
6116 mutex_unlock(&o->one_pending_mutex);
6117 } else {
6118 /* Send a ramrod */
6119 rc = o->send_cmd(bp, params);
6120
6121 mutex_unlock(&o->one_pending_mutex);
6122
6123 if (rc) {
6124 o->next_state = BNX2X_F_STATE_MAX;
6125 clear_bit(cmd, pending);
6126 smp_mb__after_clear_bit();
6127 return rc;
6128 }
6129
6130 if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
6131 rc = o->wait_comp(bp, o, cmd);
6132 if (rc)
6133 return rc;
6134
6135 return 0;
6136 }
6137 }
6138
6139 return !!test_bit(cmd, pending);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00006140}