blob: 1d46b68fb7664d69ca0e26b66d6340d9d18cb233 [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)
Dmitry Kravkov91226792013-03-11 05:17:52 +0000666 if (!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN) &&
667 (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) &&
699 (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
Dmitry Kravkov91226792013-03-11 05:17:52 +0000700 ETH_ALEN)) &&
701 (data->vlan_mac.is_inner_mac ==
702 pos->u.vlan_mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300703 return -EEXIST;
704
705 return 0;
706}
707
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300708/* check_del() callbacks */
709static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000710 bnx2x_check_mac_del(struct bnx2x *bp,
711 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300712 union bnx2x_classification_ramrod_data *data)
713{
714 struct bnx2x_vlan_mac_registry_elem *pos;
715
Merav Sicron51c1a582012-03-18 10:33:38 +0000716 DP(BNX2X_MSG_SP, "Checking MAC %pM for DEL command\n", data->mac.mac);
717
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300718 list_for_each_entry(pos, &o->head, link)
Dmitry Kravkov91226792013-03-11 05:17:52 +0000719 if ((!memcmp(data->mac.mac, pos->u.mac.mac, ETH_ALEN)) &&
720 (data->mac.is_inner_mac == pos->u.mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300721 return pos;
722
723 return NULL;
724}
725
726static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000727 bnx2x_check_vlan_del(struct bnx2x *bp,
728 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300729 union bnx2x_classification_ramrod_data *data)
730{
731 struct bnx2x_vlan_mac_registry_elem *pos;
732
Merav Sicron51c1a582012-03-18 10:33:38 +0000733 DP(BNX2X_MSG_SP, "Checking VLAN %d for DEL command\n", data->vlan.vlan);
734
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300735 list_for_each_entry(pos, &o->head, link)
736 if (data->vlan.vlan == pos->u.vlan.vlan)
737 return pos;
738
739 return NULL;
740}
741
742static struct bnx2x_vlan_mac_registry_elem *
Merav Sicron51c1a582012-03-18 10:33:38 +0000743 bnx2x_check_vlan_mac_del(struct bnx2x *bp,
744 struct bnx2x_vlan_mac_obj *o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300745 union bnx2x_classification_ramrod_data *data)
746{
747 struct bnx2x_vlan_mac_registry_elem *pos;
748
Merav Sicron51c1a582012-03-18 10:33:38 +0000749 DP(BNX2X_MSG_SP, "Checking VLAN_MAC (%pM, %d) for DEL command\n",
750 data->vlan_mac.mac, data->vlan_mac.vlan);
751
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300752 list_for_each_entry(pos, &o->head, link)
753 if ((data->vlan_mac.vlan == pos->u.vlan_mac.vlan) &&
754 (!memcmp(data->vlan_mac.mac, pos->u.vlan_mac.mac,
Dmitry Kravkov91226792013-03-11 05:17:52 +0000755 ETH_ALEN)) &&
756 (data->vlan_mac.is_inner_mac ==
757 pos->u.vlan_mac.is_inner_mac))
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300758 return pos;
759
760 return NULL;
761}
762
763/* check_move() callback */
Merav Sicron51c1a582012-03-18 10:33:38 +0000764static bool bnx2x_check_move(struct bnx2x *bp,
765 struct bnx2x_vlan_mac_obj *src_o,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300766 struct bnx2x_vlan_mac_obj *dst_o,
767 union bnx2x_classification_ramrod_data *data)
768{
769 struct bnx2x_vlan_mac_registry_elem *pos;
770 int rc;
771
772 /* Check if we can delete the requested configuration from the first
773 * object.
774 */
Merav Sicron51c1a582012-03-18 10:33:38 +0000775 pos = src_o->check_del(bp, src_o, data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300776
777 /* check if configuration can be added */
Merav Sicron51c1a582012-03-18 10:33:38 +0000778 rc = dst_o->check_add(bp, dst_o, data);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300779
780 /* If this classification can not be added (is already set)
781 * or can't be deleted - return an error.
782 */
783 if (rc || !pos)
784 return false;
785
786 return true;
787}
788
789static bool bnx2x_check_move_always_err(
Merav Sicron51c1a582012-03-18 10:33:38 +0000790 struct bnx2x *bp,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300791 struct bnx2x_vlan_mac_obj *src_o,
792 struct bnx2x_vlan_mac_obj *dst_o,
793 union bnx2x_classification_ramrod_data *data)
794{
795 return false;
796}
797
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300798static inline u8 bnx2x_vlan_mac_get_rx_tx_flag(struct bnx2x_vlan_mac_obj *o)
799{
800 struct bnx2x_raw_obj *raw = &o->raw;
801 u8 rx_tx_flag = 0;
802
803 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
804 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
805 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_TX_CMD;
806
807 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
808 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
809 rx_tx_flag |= ETH_CLASSIFY_CMD_HEADER_RX_CMD;
810
811 return rx_tx_flag;
812}
813
Barak Witkowskia3348722012-04-23 03:04:46 +0000814void bnx2x_set_mac_in_nig(struct bnx2x *bp,
815 bool add, unsigned char *dev_addr, int index)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300816{
817 u32 wb_data[2];
818 u32 reg_offset = BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM :
819 NIG_REG_LLH0_FUNC_MEM;
820
Barak Witkowskia3348722012-04-23 03:04:46 +0000821 if (!IS_MF_SI(bp) && !IS_MF_AFEX(bp))
822 return;
823
824 if (index > BNX2X_LLH_CAM_MAX_PF_LINE)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300825 return;
826
827 DP(BNX2X_MSG_SP, "Going to %s LLH configuration at entry %d\n",
828 (add ? "ADD" : "DELETE"), index);
829
830 if (add) {
831 /* LLH_FUNC_MEM is a u64 WB register */
832 reg_offset += 8*index;
833
834 wb_data[0] = ((dev_addr[2] << 24) | (dev_addr[3] << 16) |
835 (dev_addr[4] << 8) | dev_addr[5]);
836 wb_data[1] = ((dev_addr[0] << 8) | dev_addr[1]);
837
838 REG_WR_DMAE(bp, reg_offset, wb_data, 2);
839 }
840
841 REG_WR(bp, (BP_PORT(bp) ? NIG_REG_LLH1_FUNC_MEM_ENABLE :
842 NIG_REG_LLH0_FUNC_MEM_ENABLE) + 4*index, add);
843}
844
845/**
846 * bnx2x_vlan_mac_set_cmd_hdr_e2 - set a header in a single classify ramrod
847 *
848 * @bp: device handle
849 * @o: queue for which we want to configure this rule
850 * @add: if true the command is an ADD command, DEL otherwise
851 * @opcode: CLASSIFY_RULE_OPCODE_XXX
852 * @hdr: pointer to a header to setup
853 *
854 */
855static inline void bnx2x_vlan_mac_set_cmd_hdr_e2(struct bnx2x *bp,
856 struct bnx2x_vlan_mac_obj *o, bool add, int opcode,
857 struct eth_classify_cmd_header *hdr)
858{
859 struct bnx2x_raw_obj *raw = &o->raw;
860
861 hdr->client_id = raw->cl_id;
862 hdr->func_id = raw->func_id;
863
864 /* Rx or/and Tx (internal switching) configuration ? */
865 hdr->cmd_general_data |=
866 bnx2x_vlan_mac_get_rx_tx_flag(o);
867
868 if (add)
869 hdr->cmd_general_data |= ETH_CLASSIFY_CMD_HEADER_IS_ADD;
870
871 hdr->cmd_general_data |=
872 (opcode << ETH_CLASSIFY_CMD_HEADER_OPCODE_SHIFT);
873}
874
875/**
876 * bnx2x_vlan_mac_set_rdata_hdr_e2 - set the classify ramrod data header
877 *
878 * @cid: connection id
879 * @type: BNX2X_FILTER_XXX_PENDING
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000880 * @hdr: pointer to header to setup
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300881 * @rule_cnt:
882 *
883 * currently we always configure one rule and echo field to contain a CID and an
884 * opcode type.
885 */
886static inline void bnx2x_vlan_mac_set_rdata_hdr_e2(u32 cid, int type,
887 struct eth_classify_header *hdr, int rule_cnt)
888{
Yuval Mintz86564c32013-01-23 03:21:50 +0000889 hdr->echo = cpu_to_le32((cid & BNX2X_SWCID_MASK) |
890 (type << BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300891 hdr->rule_cnt = (u8)rule_cnt;
892}
893
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300894/* hw_config() callbacks */
895static void bnx2x_set_one_mac_e2(struct bnx2x *bp,
896 struct bnx2x_vlan_mac_obj *o,
897 struct bnx2x_exeq_elem *elem, int rule_idx,
898 int cam_offset)
899{
900 struct bnx2x_raw_obj *raw = &o->raw;
901 struct eth_classify_rules_ramrod_data *data =
902 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
903 int rule_cnt = rule_idx + 1, cmd = elem->cmd_data.vlan_mac.cmd;
904 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
905 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
906 unsigned long *vlan_mac_flags = &elem->cmd_data.vlan_mac.vlan_mac_flags;
907 u8 *mac = elem->cmd_data.vlan_mac.u.mac.mac;
908
Yuval Mintz16a5fd92013-06-02 00:06:18 +0000909 /* Set LLH CAM entry: currently only iSCSI and ETH macs are
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300910 * relevant. In addition, current implementation is tuned for a
911 * single ETH MAC.
912 *
913 * When multiple unicast ETH MACs PF configuration in switch
914 * independent mode is required (NetQ, multiple netdev MACs,
915 * etc.), consider better utilisation of 8 per function MAC
916 * entries in the LLH register. There is also
917 * NIG_REG_P[01]_LLH_FUNC_MEM2 registers that complete the
918 * total number of CAM entries to 16.
919 *
920 * Currently we won't configure NIG for MACs other than a primary ETH
921 * MAC and iSCSI L2 MAC.
922 *
923 * If this MAC is moving from one Queue to another, no need to change
924 * NIG configuration.
925 */
926 if (cmd != BNX2X_VLAN_MAC_MOVE) {
927 if (test_bit(BNX2X_ISCSI_ETH_MAC, vlan_mac_flags))
928 bnx2x_set_mac_in_nig(bp, add, mac,
Yuval Mintz0a52fd02012-03-12 08:53:07 +0000929 BNX2X_LLH_CAM_ISCSI_ETH_LINE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300930 else if (test_bit(BNX2X_ETH_MAC, vlan_mac_flags))
Yuval Mintz0a52fd02012-03-12 08:53:07 +0000931 bnx2x_set_mac_in_nig(bp, add, mac,
932 BNX2X_LLH_CAM_ETH_LINE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300933 }
934
935 /* Reset the ramrod data buffer for the first rule */
936 if (rule_idx == 0)
937 memset(data, 0, sizeof(*data));
938
939 /* Setup a command header */
940 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_MAC,
941 &rule_entry->mac.header);
942
Joe Perches0f9dad12011-08-14 12:16:19 +0000943 DP(BNX2X_MSG_SP, "About to %s MAC %pM for Queue %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +0000944 (add ? "add" : "delete"), mac, raw->cl_id);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300945
946 /* Set a MAC itself */
947 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
948 &rule_entry->mac.mac_mid,
949 &rule_entry->mac.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +0000950 rule_entry->mac.inner_mac =
951 cpu_to_le16(elem->cmd_data.vlan_mac.u.mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300952
953 /* MOVE: Add a rule that will add this MAC to the target Queue */
954 if (cmd == BNX2X_VLAN_MAC_MOVE) {
955 rule_entry++;
956 rule_cnt++;
957
958 /* Setup ramrod data */
959 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
960 elem->cmd_data.vlan_mac.target_obj,
961 true, CLASSIFY_RULE_OPCODE_MAC,
962 &rule_entry->mac.header);
963
964 /* Set a MAC itself */
965 bnx2x_set_fw_mac_addr(&rule_entry->mac.mac_msb,
966 &rule_entry->mac.mac_mid,
967 &rule_entry->mac.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +0000968 rule_entry->mac.inner_mac =
969 cpu_to_le16(elem->cmd_data.vlan_mac.
970 u.mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +0300971 }
972
973 /* Set the ramrod data header */
974 /* TODO: take this to the higher level in order to prevent multiple
975 writing */
976 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
977 rule_cnt);
978}
979
980/**
981 * bnx2x_vlan_mac_set_rdata_hdr_e1x - set a header in a single classify ramrod
982 *
983 * @bp: device handle
984 * @o: queue
985 * @type:
986 * @cam_offset: offset in cam memory
987 * @hdr: pointer to a header to setup
988 *
989 * E1/E1H
990 */
991static inline void bnx2x_vlan_mac_set_rdata_hdr_e1x(struct bnx2x *bp,
992 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset,
993 struct mac_configuration_hdr *hdr)
994{
995 struct bnx2x_raw_obj *r = &o->raw;
996
997 hdr->length = 1;
998 hdr->offset = (u8)cam_offset;
Yuval Mintz86564c32013-01-23 03:21:50 +0000999 hdr->client_id = cpu_to_le16(0xff);
1000 hdr->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
1001 (type << BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001002}
1003
1004static inline void bnx2x_vlan_mac_set_cfg_entry_e1x(struct bnx2x *bp,
1005 struct bnx2x_vlan_mac_obj *o, bool add, int opcode, u8 *mac,
1006 u16 vlan_id, struct mac_configuration_entry *cfg_entry)
1007{
1008 struct bnx2x_raw_obj *r = &o->raw;
1009 u32 cl_bit_vec = (1 << r->cl_id);
1010
1011 cfg_entry->clients_bit_vector = cpu_to_le32(cl_bit_vec);
1012 cfg_entry->pf_id = r->func_id;
1013 cfg_entry->vlan_id = cpu_to_le16(vlan_id);
1014
1015 if (add) {
1016 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
1017 T_ETH_MAC_COMMAND_SET);
1018 SET_FLAG(cfg_entry->flags,
1019 MAC_CONFIGURATION_ENTRY_VLAN_FILTERING_MODE, opcode);
1020
1021 /* Set a MAC in a ramrod data */
1022 bnx2x_set_fw_mac_addr(&cfg_entry->msb_mac_addr,
1023 &cfg_entry->middle_mac_addr,
1024 &cfg_entry->lsb_mac_addr, mac);
1025 } else
1026 SET_FLAG(cfg_entry->flags, MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
1027 T_ETH_MAC_COMMAND_INVALIDATE);
1028}
1029
1030static inline void bnx2x_vlan_mac_set_rdata_e1x(struct bnx2x *bp,
1031 struct bnx2x_vlan_mac_obj *o, int type, int cam_offset, bool add,
1032 u8 *mac, u16 vlan_id, int opcode, struct mac_configuration_cmd *config)
1033{
1034 struct mac_configuration_entry *cfg_entry = &config->config_table[0];
1035 struct bnx2x_raw_obj *raw = &o->raw;
1036
1037 bnx2x_vlan_mac_set_rdata_hdr_e1x(bp, o, type, cam_offset,
1038 &config->hdr);
1039 bnx2x_vlan_mac_set_cfg_entry_e1x(bp, o, add, opcode, mac, vlan_id,
1040 cfg_entry);
1041
Joe Perches0f9dad12011-08-14 12:16:19 +00001042 DP(BNX2X_MSG_SP, "%s MAC %pM CLID %d CAM offset %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00001043 (add ? "setting" : "clearing"),
Joe Perches0f9dad12011-08-14 12:16:19 +00001044 mac, raw->cl_id, cam_offset);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001045}
1046
1047/**
1048 * bnx2x_set_one_mac_e1x - fill a single MAC rule ramrod data
1049 *
1050 * @bp: device handle
1051 * @o: bnx2x_vlan_mac_obj
1052 * @elem: bnx2x_exeq_elem
1053 * @rule_idx: rule_idx
1054 * @cam_offset: cam_offset
1055 */
1056static void bnx2x_set_one_mac_e1x(struct bnx2x *bp,
1057 struct bnx2x_vlan_mac_obj *o,
1058 struct bnx2x_exeq_elem *elem, int rule_idx,
1059 int cam_offset)
1060{
1061 struct bnx2x_raw_obj *raw = &o->raw;
1062 struct mac_configuration_cmd *config =
1063 (struct mac_configuration_cmd *)(raw->rdata);
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001064 /* 57710 and 57711 do not support MOVE command,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001065 * so it's either ADD or DEL
1066 */
1067 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1068 true : false;
1069
1070 /* Reset the ramrod data buffer */
1071 memset(config, 0, sizeof(*config));
1072
Yuval Mintz33ac3382012-03-12 08:53:09 +00001073 bnx2x_vlan_mac_set_rdata_e1x(bp, o, raw->state,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001074 cam_offset, add,
1075 elem->cmd_data.vlan_mac.u.mac.mac, 0,
1076 ETH_VLAN_FILTER_ANY_VLAN, config);
1077}
1078
1079static void bnx2x_set_one_vlan_e2(struct bnx2x *bp,
1080 struct bnx2x_vlan_mac_obj *o,
1081 struct bnx2x_exeq_elem *elem, int rule_idx,
1082 int cam_offset)
1083{
1084 struct bnx2x_raw_obj *raw = &o->raw;
1085 struct eth_classify_rules_ramrod_data *data =
1086 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
1087 int rule_cnt = rule_idx + 1;
1088 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
Yuval Mintz86564c32013-01-23 03:21:50 +00001089 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001090 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
1091 u16 vlan = elem->cmd_data.vlan_mac.u.vlan.vlan;
1092
1093 /* Reset the ramrod data buffer for the first rule */
1094 if (rule_idx == 0)
1095 memset(data, 0, sizeof(*data));
1096
1097 /* Set a rule header */
1098 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_VLAN,
1099 &rule_entry->vlan.header);
1100
1101 DP(BNX2X_MSG_SP, "About to %s VLAN %d\n", (add ? "add" : "delete"),
1102 vlan);
1103
1104 /* Set a VLAN itself */
1105 rule_entry->vlan.vlan = cpu_to_le16(vlan);
1106
1107 /* MOVE: Add a rule that will add this MAC to the target Queue */
1108 if (cmd == BNX2X_VLAN_MAC_MOVE) {
1109 rule_entry++;
1110 rule_cnt++;
1111
1112 /* Setup ramrod data */
1113 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
1114 elem->cmd_data.vlan_mac.target_obj,
1115 true, CLASSIFY_RULE_OPCODE_VLAN,
1116 &rule_entry->vlan.header);
1117
1118 /* Set a VLAN itself */
1119 rule_entry->vlan.vlan = cpu_to_le16(vlan);
1120 }
1121
1122 /* Set the ramrod data header */
1123 /* TODO: take this to the higher level in order to prevent multiple
1124 writing */
1125 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
1126 rule_cnt);
1127}
1128
1129static void bnx2x_set_one_vlan_mac_e2(struct bnx2x *bp,
1130 struct bnx2x_vlan_mac_obj *o,
1131 struct bnx2x_exeq_elem *elem,
1132 int rule_idx, int cam_offset)
1133{
1134 struct bnx2x_raw_obj *raw = &o->raw;
1135 struct eth_classify_rules_ramrod_data *data =
1136 (struct eth_classify_rules_ramrod_data *)(raw->rdata);
1137 int rule_cnt = rule_idx + 1;
1138 union eth_classify_rule_cmd *rule_entry = &data->rules[rule_idx];
Yuval Mintz86564c32013-01-23 03:21:50 +00001139 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001140 bool add = (cmd == BNX2X_VLAN_MAC_ADD) ? true : false;
1141 u16 vlan = elem->cmd_data.vlan_mac.u.vlan_mac.vlan;
1142 u8 *mac = elem->cmd_data.vlan_mac.u.vlan_mac.mac;
1143
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001144 /* Reset the ramrod data buffer for the first rule */
1145 if (rule_idx == 0)
1146 memset(data, 0, sizeof(*data));
1147
1148 /* Set a rule header */
1149 bnx2x_vlan_mac_set_cmd_hdr_e2(bp, o, add, CLASSIFY_RULE_OPCODE_PAIR,
1150 &rule_entry->pair.header);
1151
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001152 /* Set VLAN and MAC themselves */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001153 rule_entry->pair.vlan = cpu_to_le16(vlan);
1154 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
1155 &rule_entry->pair.mac_mid,
1156 &rule_entry->pair.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +00001157 rule_entry->pair.inner_mac =
1158 cpu_to_le16(elem->cmd_data.vlan_mac.u.vlan_mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001159 /* MOVE: Add a rule that will add this MAC to the target Queue */
1160 if (cmd == BNX2X_VLAN_MAC_MOVE) {
1161 rule_entry++;
1162 rule_cnt++;
1163
1164 /* Setup ramrod data */
1165 bnx2x_vlan_mac_set_cmd_hdr_e2(bp,
1166 elem->cmd_data.vlan_mac.target_obj,
1167 true, CLASSIFY_RULE_OPCODE_PAIR,
1168 &rule_entry->pair.header);
1169
1170 /* Set a VLAN itself */
1171 rule_entry->pair.vlan = cpu_to_le16(vlan);
1172 bnx2x_set_fw_mac_addr(&rule_entry->pair.mac_msb,
1173 &rule_entry->pair.mac_mid,
1174 &rule_entry->pair.mac_lsb, mac);
Dmitry Kravkov91226792013-03-11 05:17:52 +00001175 rule_entry->pair.inner_mac =
1176 cpu_to_le16(elem->cmd_data.vlan_mac.u.
1177 vlan_mac.is_inner_mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001178 }
1179
1180 /* Set the ramrod data header */
1181 /* TODO: take this to the higher level in order to prevent multiple
1182 writing */
1183 bnx2x_vlan_mac_set_rdata_hdr_e2(raw->cid, raw->state, &data->header,
1184 rule_cnt);
1185}
1186
1187/**
1188 * bnx2x_set_one_vlan_mac_e1h -
1189 *
1190 * @bp: device handle
1191 * @o: bnx2x_vlan_mac_obj
1192 * @elem: bnx2x_exeq_elem
1193 * @rule_idx: rule_idx
1194 * @cam_offset: cam_offset
1195 */
1196static void bnx2x_set_one_vlan_mac_e1h(struct bnx2x *bp,
1197 struct bnx2x_vlan_mac_obj *o,
1198 struct bnx2x_exeq_elem *elem,
1199 int rule_idx, int cam_offset)
1200{
1201 struct bnx2x_raw_obj *raw = &o->raw;
1202 struct mac_configuration_cmd *config =
1203 (struct mac_configuration_cmd *)(raw->rdata);
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001204 /* 57710 and 57711 do not support MOVE command,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001205 * so it's either ADD or DEL
1206 */
1207 bool add = (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1208 true : false;
1209
1210 /* Reset the ramrod data buffer */
1211 memset(config, 0, sizeof(*config));
1212
1213 bnx2x_vlan_mac_set_rdata_e1x(bp, o, BNX2X_FILTER_VLAN_MAC_PENDING,
1214 cam_offset, add,
1215 elem->cmd_data.vlan_mac.u.vlan_mac.mac,
1216 elem->cmd_data.vlan_mac.u.vlan_mac.vlan,
1217 ETH_VLAN_FILTER_CLASSIFY, config);
1218}
1219
1220#define list_next_entry(pos, member) \
1221 list_entry((pos)->member.next, typeof(*(pos)), member)
1222
1223/**
1224 * bnx2x_vlan_mac_restore - reconfigure next MAC/VLAN/VLAN-MAC element
1225 *
1226 * @bp: device handle
1227 * @p: command parameters
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001228 * @ppos: pointer to the cookie
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001229 *
1230 * reconfigure next MAC/VLAN/VLAN-MAC element from the
1231 * previously configured elements list.
1232 *
1233 * from command parameters only RAMROD_COMP_WAIT bit in ramrod_flags is taken
1234 * into an account
1235 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001236 * pointer to the cookie - that should be given back in the next call to make
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001237 * function handle the next element. If *ppos is set to NULL it will restart the
1238 * iterator. If returned *ppos == NULL this means that the last element has been
1239 * handled.
1240 *
1241 */
1242static int bnx2x_vlan_mac_restore(struct bnx2x *bp,
1243 struct bnx2x_vlan_mac_ramrod_params *p,
1244 struct bnx2x_vlan_mac_registry_elem **ppos)
1245{
1246 struct bnx2x_vlan_mac_registry_elem *pos;
1247 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1248
1249 /* If list is empty - there is nothing to do here */
1250 if (list_empty(&o->head)) {
1251 *ppos = NULL;
1252 return 0;
1253 }
1254
1255 /* make a step... */
1256 if (*ppos == NULL)
1257 *ppos = list_first_entry(&o->head,
1258 struct bnx2x_vlan_mac_registry_elem,
1259 link);
1260 else
1261 *ppos = list_next_entry(*ppos, link);
1262
1263 pos = *ppos;
1264
1265 /* If it's the last step - return NULL */
1266 if (list_is_last(&pos->link, &o->head))
1267 *ppos = NULL;
1268
1269 /* Prepare a 'user_req' */
1270 memcpy(&p->user_req.u, &pos->u, sizeof(pos->u));
1271
1272 /* Set the command */
1273 p->user_req.cmd = BNX2X_VLAN_MAC_ADD;
1274
1275 /* Set vlan_mac_flags */
1276 p->user_req.vlan_mac_flags = pos->vlan_mac_flags;
1277
1278 /* Set a restore bit */
1279 __set_bit(RAMROD_RESTORE, &p->ramrod_flags);
1280
1281 return bnx2x_config_vlan_mac(bp, p);
1282}
1283
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001284/* bnx2x_exeq_get_mac/bnx2x_exeq_get_vlan/bnx2x_exeq_get_vlan_mac return a
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001285 * pointer to an element with a specific criteria and NULL if such an element
1286 * hasn't been found.
1287 */
1288static struct bnx2x_exeq_elem *bnx2x_exeq_get_mac(
1289 struct bnx2x_exe_queue_obj *o,
1290 struct bnx2x_exeq_elem *elem)
1291{
1292 struct bnx2x_exeq_elem *pos;
1293 struct bnx2x_mac_ramrod_data *data = &elem->cmd_data.vlan_mac.u.mac;
1294
1295 /* Check pending for execution commands */
1296 list_for_each_entry(pos, &o->exe_queue, link)
1297 if (!memcmp(&pos->cmd_data.vlan_mac.u.mac, data,
1298 sizeof(*data)) &&
1299 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1300 return pos;
1301
1302 return NULL;
1303}
1304
1305static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan(
1306 struct bnx2x_exe_queue_obj *o,
1307 struct bnx2x_exeq_elem *elem)
1308{
1309 struct bnx2x_exeq_elem *pos;
1310 struct bnx2x_vlan_ramrod_data *data = &elem->cmd_data.vlan_mac.u.vlan;
1311
1312 /* Check pending for execution commands */
1313 list_for_each_entry(pos, &o->exe_queue, link)
1314 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan, data,
1315 sizeof(*data)) &&
1316 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1317 return pos;
1318
1319 return NULL;
1320}
1321
1322static struct bnx2x_exeq_elem *bnx2x_exeq_get_vlan_mac(
1323 struct bnx2x_exe_queue_obj *o,
1324 struct bnx2x_exeq_elem *elem)
1325{
1326 struct bnx2x_exeq_elem *pos;
1327 struct bnx2x_vlan_mac_ramrod_data *data =
1328 &elem->cmd_data.vlan_mac.u.vlan_mac;
1329
1330 /* Check pending for execution commands */
1331 list_for_each_entry(pos, &o->exe_queue, link)
1332 if (!memcmp(&pos->cmd_data.vlan_mac.u.vlan_mac, data,
1333 sizeof(*data)) &&
1334 (pos->cmd_data.vlan_mac.cmd == elem->cmd_data.vlan_mac.cmd))
1335 return pos;
1336
1337 return NULL;
1338}
1339
1340/**
1341 * bnx2x_validate_vlan_mac_add - check if an ADD command can be executed
1342 *
1343 * @bp: device handle
1344 * @qo: bnx2x_qable_obj
1345 * @elem: bnx2x_exeq_elem
1346 *
1347 * Checks that the requested configuration can be added. If yes and if
1348 * requested, consume CAM credit.
1349 *
1350 * The 'validate' is run after the 'optimize'.
1351 *
1352 */
1353static inline int bnx2x_validate_vlan_mac_add(struct bnx2x *bp,
1354 union bnx2x_qable_obj *qo,
1355 struct bnx2x_exeq_elem *elem)
1356{
1357 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1358 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1359 int rc;
1360
1361 /* Check the registry */
Merav Sicron51c1a582012-03-18 10:33:38 +00001362 rc = o->check_add(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001363 if (rc) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001364 DP(BNX2X_MSG_SP, "ADD command is not allowed considering current registry state.\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001365 return rc;
1366 }
1367
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001368 /* Check if there is a pending ADD command for this
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001369 * MAC/VLAN/VLAN-MAC. Return an error if there is.
1370 */
1371 if (exeq->get(exeq, elem)) {
1372 DP(BNX2X_MSG_SP, "There is a pending ADD command already\n");
1373 return -EEXIST;
1374 }
1375
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001376 /* TODO: Check the pending MOVE from other objects where this
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001377 * object is a destination object.
1378 */
1379
1380 /* Consume the credit if not requested not to */
1381 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1382 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1383 o->get_credit(o)))
1384 return -EINVAL;
1385
1386 return 0;
1387}
1388
1389/**
1390 * bnx2x_validate_vlan_mac_del - check if the DEL command can be executed
1391 *
1392 * @bp: device handle
1393 * @qo: quable object to check
1394 * @elem: element that needs to be deleted
1395 *
1396 * Checks that the requested configuration can be deleted. If yes and if
1397 * requested, returns a CAM credit.
1398 *
1399 * The 'validate' is run after the 'optimize'.
1400 */
1401static inline int bnx2x_validate_vlan_mac_del(struct bnx2x *bp,
1402 union bnx2x_qable_obj *qo,
1403 struct bnx2x_exeq_elem *elem)
1404{
1405 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1406 struct bnx2x_vlan_mac_registry_elem *pos;
1407 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1408 struct bnx2x_exeq_elem query_elem;
1409
1410 /* If this classification can not be deleted (doesn't exist)
1411 * - return a BNX2X_EXIST.
1412 */
Merav Sicron51c1a582012-03-18 10:33:38 +00001413 pos = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001414 if (!pos) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001415 DP(BNX2X_MSG_SP, "DEL command is not allowed considering current registry state\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001416 return -EEXIST;
1417 }
1418
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001419 /* Check if there are pending DEL or MOVE commands for this
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001420 * MAC/VLAN/VLAN-MAC. Return an error if so.
1421 */
1422 memcpy(&query_elem, elem, sizeof(query_elem));
1423
1424 /* Check for MOVE commands */
1425 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_MOVE;
1426 if (exeq->get(exeq, &query_elem)) {
1427 BNX2X_ERR("There is a pending MOVE command already\n");
1428 return -EINVAL;
1429 }
1430
1431 /* Check for DEL commands */
1432 if (exeq->get(exeq, elem)) {
1433 DP(BNX2X_MSG_SP, "There is a pending DEL command already\n");
1434 return -EEXIST;
1435 }
1436
1437 /* Return the credit to the credit pool if not requested not to */
1438 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1439 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1440 o->put_credit(o))) {
1441 BNX2X_ERR("Failed to return a credit\n");
1442 return -EINVAL;
1443 }
1444
1445 return 0;
1446}
1447
1448/**
1449 * bnx2x_validate_vlan_mac_move - check if the MOVE command can be executed
1450 *
1451 * @bp: device handle
1452 * @qo: quable object to check (source)
1453 * @elem: element that needs to be moved
1454 *
1455 * Checks that the requested configuration can be moved. If yes and if
1456 * requested, returns a CAM credit.
1457 *
1458 * The 'validate' is run after the 'optimize'.
1459 */
1460static inline int bnx2x_validate_vlan_mac_move(struct bnx2x *bp,
1461 union bnx2x_qable_obj *qo,
1462 struct bnx2x_exeq_elem *elem)
1463{
1464 struct bnx2x_vlan_mac_obj *src_o = &qo->vlan_mac;
1465 struct bnx2x_vlan_mac_obj *dest_o = elem->cmd_data.vlan_mac.target_obj;
1466 struct bnx2x_exeq_elem query_elem;
1467 struct bnx2x_exe_queue_obj *src_exeq = &src_o->exe_queue;
1468 struct bnx2x_exe_queue_obj *dest_exeq = &dest_o->exe_queue;
1469
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001470 /* Check if we can perform this operation based on the current registry
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001471 * state.
1472 */
Merav Sicron51c1a582012-03-18 10:33:38 +00001473 if (!src_o->check_move(bp, src_o, dest_o,
1474 &elem->cmd_data.vlan_mac.u)) {
1475 DP(BNX2X_MSG_SP, "MOVE command is not allowed considering current registry state\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001476 return -EINVAL;
1477 }
1478
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001479 /* Check if there is an already pending DEL or MOVE command for the
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001480 * source object or ADD command for a destination object. Return an
1481 * error if so.
1482 */
1483 memcpy(&query_elem, elem, sizeof(query_elem));
1484
1485 /* Check DEL on source */
1486 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1487 if (src_exeq->get(src_exeq, &query_elem)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001488 BNX2X_ERR("There is a pending DEL command on the source queue already\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001489 return -EINVAL;
1490 }
1491
1492 /* Check MOVE on source */
1493 if (src_exeq->get(src_exeq, elem)) {
1494 DP(BNX2X_MSG_SP, "There is a pending MOVE command already\n");
1495 return -EEXIST;
1496 }
1497
1498 /* Check ADD on destination */
1499 query_elem.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1500 if (dest_exeq->get(dest_exeq, &query_elem)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001501 BNX2X_ERR("There is a pending ADD command on the destination queue already\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001502 return -EINVAL;
1503 }
1504
1505 /* Consume the credit if not requested not to */
1506 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT_DEST,
1507 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1508 dest_o->get_credit(dest_o)))
1509 return -EINVAL;
1510
1511 if (!(test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1512 &elem->cmd_data.vlan_mac.vlan_mac_flags) ||
1513 src_o->put_credit(src_o))) {
1514 /* return the credit taken from dest... */
1515 dest_o->put_credit(dest_o);
1516 return -EINVAL;
1517 }
1518
1519 return 0;
1520}
1521
1522static int bnx2x_validate_vlan_mac(struct bnx2x *bp,
1523 union bnx2x_qable_obj *qo,
1524 struct bnx2x_exeq_elem *elem)
1525{
1526 switch (elem->cmd_data.vlan_mac.cmd) {
1527 case BNX2X_VLAN_MAC_ADD:
1528 return bnx2x_validate_vlan_mac_add(bp, qo, elem);
1529 case BNX2X_VLAN_MAC_DEL:
1530 return bnx2x_validate_vlan_mac_del(bp, qo, elem);
1531 case BNX2X_VLAN_MAC_MOVE:
1532 return bnx2x_validate_vlan_mac_move(bp, qo, elem);
1533 default:
1534 return -EINVAL;
1535 }
1536}
1537
Yuval Mintz460a25c2012-01-23 07:31:51 +00001538static int bnx2x_remove_vlan_mac(struct bnx2x *bp,
1539 union bnx2x_qable_obj *qo,
1540 struct bnx2x_exeq_elem *elem)
1541{
1542 int rc = 0;
1543
1544 /* If consumption wasn't required, nothing to do */
1545 if (test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1546 &elem->cmd_data.vlan_mac.vlan_mac_flags))
1547 return 0;
1548
1549 switch (elem->cmd_data.vlan_mac.cmd) {
1550 case BNX2X_VLAN_MAC_ADD:
1551 case BNX2X_VLAN_MAC_MOVE:
1552 rc = qo->vlan_mac.put_credit(&qo->vlan_mac);
1553 break;
1554 case BNX2X_VLAN_MAC_DEL:
1555 rc = qo->vlan_mac.get_credit(&qo->vlan_mac);
1556 break;
1557 default:
1558 return -EINVAL;
1559 }
1560
1561 if (rc != true)
1562 return -EINVAL;
1563
1564 return 0;
1565}
1566
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001567/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001568 * bnx2x_wait_vlan_mac - passively wait for 5 seconds until all work completes.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001569 *
1570 * @bp: device handle
1571 * @o: bnx2x_vlan_mac_obj
1572 *
1573 */
1574static int bnx2x_wait_vlan_mac(struct bnx2x *bp,
1575 struct bnx2x_vlan_mac_obj *o)
1576{
1577 int cnt = 5000, rc;
1578 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1579 struct bnx2x_raw_obj *raw = &o->raw;
1580
1581 while (cnt--) {
1582 /* Wait for the current command to complete */
1583 rc = raw->wait_comp(bp, raw);
1584 if (rc)
1585 return rc;
1586
1587 /* Wait until there are no pending commands */
1588 if (!bnx2x_exe_queue_empty(exeq))
Yuval Mintz0926d492013-01-23 03:21:45 +00001589 usleep_range(1000, 2000);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001590 else
1591 return 0;
1592 }
1593
1594 return -EBUSY;
1595}
1596
Yuval Mintz8b09be52013-08-01 17:30:59 +03001597static int __bnx2x_vlan_mac_execute_step(struct bnx2x *bp,
1598 struct bnx2x_vlan_mac_obj *o,
1599 unsigned long *ramrod_flags)
1600{
1601 int rc = 0;
1602
1603 spin_lock_bh(&o->exe_queue.lock);
1604
1605 DP(BNX2X_MSG_SP, "vlan_mac_execute_step - trying to take writer lock\n");
1606 rc = __bnx2x_vlan_mac_h_write_trylock(bp, o);
1607
1608 if (rc != 0) {
1609 __bnx2x_vlan_mac_h_pend(bp, o, *ramrod_flags);
1610
1611 /* Calling function should not diffrentiate between this case
1612 * and the case in which there is already a pending ramrod
1613 */
1614 rc = 1;
1615 } else {
1616 rc = bnx2x_exe_queue_step(bp, &o->exe_queue, ramrod_flags);
1617 }
1618 spin_unlock_bh(&o->exe_queue.lock);
1619
1620 return rc;
1621}
1622
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001623/**
1624 * bnx2x_complete_vlan_mac - complete one VLAN-MAC ramrod
1625 *
1626 * @bp: device handle
1627 * @o: bnx2x_vlan_mac_obj
1628 * @cqe:
1629 * @cont: if true schedule next execution chunk
1630 *
1631 */
1632static int bnx2x_complete_vlan_mac(struct bnx2x *bp,
1633 struct bnx2x_vlan_mac_obj *o,
1634 union event_ring_elem *cqe,
1635 unsigned long *ramrod_flags)
1636{
1637 struct bnx2x_raw_obj *r = &o->raw;
1638 int rc;
1639
Yuval Mintz8b09be52013-08-01 17:30:59 +03001640 /* Clearing the pending list & raw state should be made
1641 * atomically (as execution flow assumes they represent the same).
1642 */
1643 spin_lock_bh(&o->exe_queue.lock);
1644
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001645 /* Reset pending list */
Yuval Mintz8b09be52013-08-01 17:30:59 +03001646 __bnx2x_exe_queue_reset_pending(bp, &o->exe_queue);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001647
1648 /* Clear pending */
1649 r->clear_pending(r);
1650
Yuval Mintz8b09be52013-08-01 17:30:59 +03001651 spin_unlock_bh(&o->exe_queue.lock);
1652
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001653 /* If ramrod failed this is most likely a SW bug */
1654 if (cqe->message.error)
1655 return -EINVAL;
1656
Yuval Mintz2de67432013-01-23 03:21:43 +00001657 /* Run the next bulk of pending commands if requested */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001658 if (test_bit(RAMROD_CONT, ramrod_flags)) {
Yuval Mintz8b09be52013-08-01 17:30:59 +03001659 rc = __bnx2x_vlan_mac_execute_step(bp, o, ramrod_flags);
1660
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001661 if (rc < 0)
1662 return rc;
1663 }
1664
1665 /* If there is more work to do return PENDING */
1666 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1667 return 1;
1668
1669 return 0;
1670}
1671
1672/**
1673 * bnx2x_optimize_vlan_mac - optimize ADD and DEL commands.
1674 *
1675 * @bp: device handle
1676 * @o: bnx2x_qable_obj
1677 * @elem: bnx2x_exeq_elem
1678 */
1679static int bnx2x_optimize_vlan_mac(struct bnx2x *bp,
1680 union bnx2x_qable_obj *qo,
1681 struct bnx2x_exeq_elem *elem)
1682{
1683 struct bnx2x_exeq_elem query, *pos;
1684 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac;
1685 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
1686
1687 memcpy(&query, elem, sizeof(query));
1688
1689 switch (elem->cmd_data.vlan_mac.cmd) {
1690 case BNX2X_VLAN_MAC_ADD:
1691 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_DEL;
1692 break;
1693 case BNX2X_VLAN_MAC_DEL:
1694 query.cmd_data.vlan_mac.cmd = BNX2X_VLAN_MAC_ADD;
1695 break;
1696 default:
1697 /* Don't handle anything other than ADD or DEL */
1698 return 0;
1699 }
1700
1701 /* If we found the appropriate element - delete it */
1702 pos = exeq->get(exeq, &query);
1703 if (pos) {
1704
1705 /* Return the credit of the optimized command */
1706 if (!test_bit(BNX2X_DONT_CONSUME_CAM_CREDIT,
1707 &pos->cmd_data.vlan_mac.vlan_mac_flags)) {
1708 if ((query.cmd_data.vlan_mac.cmd ==
1709 BNX2X_VLAN_MAC_ADD) && !o->put_credit(o)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001710 BNX2X_ERR("Failed to return the credit for the optimized ADD command\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001711 return -EINVAL;
1712 } else if (!o->get_credit(o)) { /* VLAN_MAC_DEL */
Merav Sicron51c1a582012-03-18 10:33:38 +00001713 BNX2X_ERR("Failed to recover the credit from the optimized DEL command\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001714 return -EINVAL;
1715 }
1716 }
1717
1718 DP(BNX2X_MSG_SP, "Optimizing %s command\n",
1719 (elem->cmd_data.vlan_mac.cmd == BNX2X_VLAN_MAC_ADD) ?
1720 "ADD" : "DEL");
1721
1722 list_del(&pos->link);
1723 bnx2x_exe_queue_free_elem(bp, pos);
1724 return 1;
1725 }
1726
1727 return 0;
1728}
1729
1730/**
1731 * bnx2x_vlan_mac_get_registry_elem - prepare a registry element
1732 *
1733 * @bp: device handle
1734 * @o:
1735 * @elem:
1736 * @restore:
1737 * @re:
1738 *
1739 * prepare a registry element according to the current command request.
1740 */
1741static inline int bnx2x_vlan_mac_get_registry_elem(
1742 struct bnx2x *bp,
1743 struct bnx2x_vlan_mac_obj *o,
1744 struct bnx2x_exeq_elem *elem,
1745 bool restore,
1746 struct bnx2x_vlan_mac_registry_elem **re)
1747{
Yuval Mintz86564c32013-01-23 03:21:50 +00001748 enum bnx2x_vlan_mac_cmd cmd = elem->cmd_data.vlan_mac.cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001749 struct bnx2x_vlan_mac_registry_elem *reg_elem;
1750
1751 /* Allocate a new registry element if needed. */
1752 if (!restore &&
1753 ((cmd == BNX2X_VLAN_MAC_ADD) || (cmd == BNX2X_VLAN_MAC_MOVE))) {
1754 reg_elem = kzalloc(sizeof(*reg_elem), GFP_ATOMIC);
1755 if (!reg_elem)
1756 return -ENOMEM;
1757
1758 /* Get a new CAM offset */
1759 if (!o->get_cam_offset(o, &reg_elem->cam_offset)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001760 /* This shall never happen, because we have checked the
1761 * CAM availability in the 'validate'.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001762 */
1763 WARN_ON(1);
1764 kfree(reg_elem);
1765 return -EINVAL;
1766 }
1767
1768 DP(BNX2X_MSG_SP, "Got cam offset %d\n", reg_elem->cam_offset);
1769
1770 /* Set a VLAN-MAC data */
1771 memcpy(&reg_elem->u, &elem->cmd_data.vlan_mac.u,
1772 sizeof(reg_elem->u));
1773
1774 /* Copy the flags (needed for DEL and RESTORE flows) */
1775 reg_elem->vlan_mac_flags =
1776 elem->cmd_data.vlan_mac.vlan_mac_flags;
1777 } else /* DEL, RESTORE */
Merav Sicron51c1a582012-03-18 10:33:38 +00001778 reg_elem = o->check_del(bp, o, &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001779
1780 *re = reg_elem;
1781 return 0;
1782}
1783
1784/**
1785 * bnx2x_execute_vlan_mac - execute vlan mac command
1786 *
1787 * @bp: device handle
1788 * @qo:
1789 * @exe_chunk:
1790 * @ramrod_flags:
1791 *
1792 * go and send a ramrod!
1793 */
1794static int bnx2x_execute_vlan_mac(struct bnx2x *bp,
1795 union bnx2x_qable_obj *qo,
1796 struct list_head *exe_chunk,
1797 unsigned long *ramrod_flags)
1798{
1799 struct bnx2x_exeq_elem *elem;
1800 struct bnx2x_vlan_mac_obj *o = &qo->vlan_mac, *cam_obj;
1801 struct bnx2x_raw_obj *r = &o->raw;
1802 int rc, idx = 0;
1803 bool restore = test_bit(RAMROD_RESTORE, ramrod_flags);
1804 bool drv_only = test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags);
1805 struct bnx2x_vlan_mac_registry_elem *reg_elem;
Yuval Mintz86564c32013-01-23 03:21:50 +00001806 enum bnx2x_vlan_mac_cmd cmd;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001807
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001808 /* If DRIVER_ONLY execution is requested, cleanup a registry
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001809 * and exit. Otherwise send a ramrod to FW.
1810 */
1811 if (!drv_only) {
1812 WARN_ON(r->check_pending(r));
1813
1814 /* Set pending */
1815 r->set_pending(r);
1816
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001817 /* Fill the ramrod data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001818 list_for_each_entry(elem, exe_chunk, link) {
1819 cmd = elem->cmd_data.vlan_mac.cmd;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001820 /* We will add to the target object in MOVE command, so
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001821 * change the object for a CAM search.
1822 */
1823 if (cmd == BNX2X_VLAN_MAC_MOVE)
1824 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1825 else
1826 cam_obj = o;
1827
1828 rc = bnx2x_vlan_mac_get_registry_elem(bp, cam_obj,
1829 elem, restore,
1830 &reg_elem);
1831 if (rc)
1832 goto error_exit;
1833
1834 WARN_ON(!reg_elem);
1835
1836 /* Push a new entry into the registry */
1837 if (!restore &&
1838 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1839 (cmd == BNX2X_VLAN_MAC_MOVE)))
1840 list_add(&reg_elem->link, &cam_obj->head);
1841
1842 /* Configure a single command in a ramrod data buffer */
1843 o->set_one_rule(bp, o, elem, idx,
1844 reg_elem->cam_offset);
1845
1846 /* MOVE command consumes 2 entries in the ramrod data */
1847 if (cmd == BNX2X_VLAN_MAC_MOVE)
1848 idx += 2;
1849 else
1850 idx++;
1851 }
1852
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001853 /* No need for an explicit memory barrier here as long we would
1854 * need to ensure the ordering of writing to the SPQ element
1855 * and updating of the SPQ producer which involves a memory
1856 * read and we will have to put a full memory barrier there
1857 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00001858 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001859
1860 rc = bnx2x_sp_post(bp, o->ramrod_cmd, r->cid,
1861 U64_HI(r->rdata_mapping),
1862 U64_LO(r->rdata_mapping),
1863 ETH_CONNECTION_TYPE);
1864 if (rc)
1865 goto error_exit;
1866 }
1867
1868 /* Now, when we are done with the ramrod - clean up the registry */
1869 list_for_each_entry(elem, exe_chunk, link) {
1870 cmd = elem->cmd_data.vlan_mac.cmd;
1871 if ((cmd == BNX2X_VLAN_MAC_DEL) ||
1872 (cmd == BNX2X_VLAN_MAC_MOVE)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001873 reg_elem = o->check_del(bp, o,
1874 &elem->cmd_data.vlan_mac.u);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001875
1876 WARN_ON(!reg_elem);
1877
1878 o->put_cam_offset(o, reg_elem->cam_offset);
1879 list_del(&reg_elem->link);
1880 kfree(reg_elem);
1881 }
1882 }
1883
1884 if (!drv_only)
1885 return 1;
1886 else
1887 return 0;
1888
1889error_exit:
1890 r->clear_pending(r);
1891
1892 /* Cleanup a registry in case of a failure */
1893 list_for_each_entry(elem, exe_chunk, link) {
1894 cmd = elem->cmd_data.vlan_mac.cmd;
1895
1896 if (cmd == BNX2X_VLAN_MAC_MOVE)
1897 cam_obj = elem->cmd_data.vlan_mac.target_obj;
1898 else
1899 cam_obj = o;
1900
1901 /* Delete all newly added above entries */
1902 if (!restore &&
1903 ((cmd == BNX2X_VLAN_MAC_ADD) ||
1904 (cmd == BNX2X_VLAN_MAC_MOVE))) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001905 reg_elem = o->check_del(bp, cam_obj,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001906 &elem->cmd_data.vlan_mac.u);
1907 if (reg_elem) {
1908 list_del(&reg_elem->link);
1909 kfree(reg_elem);
1910 }
1911 }
1912 }
1913
1914 return rc;
1915}
1916
1917static inline int bnx2x_vlan_mac_push_new_cmd(
1918 struct bnx2x *bp,
1919 struct bnx2x_vlan_mac_ramrod_params *p)
1920{
1921 struct bnx2x_exeq_elem *elem;
1922 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1923 bool restore = test_bit(RAMROD_RESTORE, &p->ramrod_flags);
1924
1925 /* Allocate the execution queue element */
1926 elem = bnx2x_exe_queue_alloc_elem(bp);
1927 if (!elem)
1928 return -ENOMEM;
1929
1930 /* Set the command 'length' */
1931 switch (p->user_req.cmd) {
1932 case BNX2X_VLAN_MAC_MOVE:
1933 elem->cmd_len = 2;
1934 break;
1935 default:
1936 elem->cmd_len = 1;
1937 }
1938
1939 /* Fill the object specific info */
1940 memcpy(&elem->cmd_data.vlan_mac, &p->user_req, sizeof(p->user_req));
1941
1942 /* Try to add a new command to the pending list */
1943 return bnx2x_exe_queue_add(bp, &o->exe_queue, elem, restore);
1944}
1945
1946/**
1947 * bnx2x_config_vlan_mac - configure VLAN/MAC/VLAN_MAC filtering rules.
1948 *
1949 * @bp: device handle
1950 * @p:
1951 *
1952 */
Yuval Mintz8b09be52013-08-01 17:30:59 +03001953int bnx2x_config_vlan_mac(struct bnx2x *bp,
1954 struct bnx2x_vlan_mac_ramrod_params *p)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001955{
1956 int rc = 0;
1957 struct bnx2x_vlan_mac_obj *o = p->vlan_mac_obj;
1958 unsigned long *ramrod_flags = &p->ramrod_flags;
1959 bool cont = test_bit(RAMROD_CONT, ramrod_flags);
1960 struct bnx2x_raw_obj *raw = &o->raw;
1961
1962 /*
1963 * Add new elements to the execution list for commands that require it.
1964 */
1965 if (!cont) {
1966 rc = bnx2x_vlan_mac_push_new_cmd(bp, p);
1967 if (rc)
1968 return rc;
1969 }
1970
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001971 /* If nothing will be executed further in this iteration we want to
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001972 * return PENDING if there are pending commands
1973 */
1974 if (!bnx2x_exe_queue_empty(&o->exe_queue))
1975 rc = 1;
1976
Vladislav Zolotarov79616892011-07-21 07:58:54 +00001977 if (test_bit(RAMROD_DRV_CLR_ONLY, ramrod_flags)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00001978 DP(BNX2X_MSG_SP, "RAMROD_DRV_CLR_ONLY requested: clearing a pending bit.\n");
Vladislav Zolotarov79616892011-07-21 07:58:54 +00001979 raw->clear_pending(raw);
1980 }
1981
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001982 /* Execute commands if required */
1983 if (cont || test_bit(RAMROD_EXEC, ramrod_flags) ||
1984 test_bit(RAMROD_COMP_WAIT, ramrod_flags)) {
Yuval Mintz8b09be52013-08-01 17:30:59 +03001985 rc = __bnx2x_vlan_mac_execute_step(bp, p->vlan_mac_obj,
1986 &p->ramrod_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001987 if (rc < 0)
1988 return rc;
1989 }
1990
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001991 /* RAMROD_COMP_WAIT is a superset of RAMROD_EXEC. If it was set
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001992 * then user want to wait until the last command is done.
1993 */
1994 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00001995 /* Wait maximum for the current exe_queue length iterations plus
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03001996 * one (for the current pending command).
1997 */
1998 int max_iterations = bnx2x_exe_queue_length(&o->exe_queue) + 1;
1999
2000 while (!bnx2x_exe_queue_empty(&o->exe_queue) &&
2001 max_iterations--) {
2002
2003 /* Wait for the current command to complete */
2004 rc = raw->wait_comp(bp, raw);
2005 if (rc)
2006 return rc;
2007
2008 /* Make a next step */
Yuval Mintz8b09be52013-08-01 17:30:59 +03002009 rc = __bnx2x_vlan_mac_execute_step(bp,
2010 p->vlan_mac_obj,
2011 &p->ramrod_flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002012 if (rc < 0)
2013 return rc;
2014 }
2015
2016 return 0;
2017 }
2018
2019 return rc;
2020}
2021
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002022/**
2023 * bnx2x_vlan_mac_del_all - delete elements with given vlan_mac_flags spec
2024 *
2025 * @bp: device handle
2026 * @o:
2027 * @vlan_mac_flags:
2028 * @ramrod_flags: execution flags to be used for this deletion
2029 *
2030 * if the last operation has completed successfully and there are no
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002031 * more elements left, positive value if the last operation has completed
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002032 * successfully and there are more previously configured elements, negative
2033 * value is current operation has failed.
2034 */
2035static int bnx2x_vlan_mac_del_all(struct bnx2x *bp,
2036 struct bnx2x_vlan_mac_obj *o,
2037 unsigned long *vlan_mac_flags,
2038 unsigned long *ramrod_flags)
2039{
2040 struct bnx2x_vlan_mac_registry_elem *pos = NULL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002041 struct bnx2x_vlan_mac_ramrod_params p;
2042 struct bnx2x_exe_queue_obj *exeq = &o->exe_queue;
2043 struct bnx2x_exeq_elem *exeq_pos, *exeq_pos_n;
Yuval Mintz8b09be52013-08-01 17:30:59 +03002044 int read_lock;
2045 int rc = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002046
2047 /* Clear pending commands first */
2048
2049 spin_lock_bh(&exeq->lock);
2050
2051 list_for_each_entry_safe(exeq_pos, exeq_pos_n, &exeq->exe_queue, link) {
2052 if (exeq_pos->cmd_data.vlan_mac.vlan_mac_flags ==
Yuval Mintz460a25c2012-01-23 07:31:51 +00002053 *vlan_mac_flags) {
2054 rc = exeq->remove(bp, exeq->owner, exeq_pos);
2055 if (rc) {
2056 BNX2X_ERR("Failed to remove command\n");
Dan Carpentera44acd52012-01-24 21:59:31 +00002057 spin_unlock_bh(&exeq->lock);
Yuval Mintz460a25c2012-01-23 07:31:51 +00002058 return rc;
2059 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002060 list_del(&exeq_pos->link);
Yuval Mintz07ef7be2013-03-11 05:17:41 +00002061 bnx2x_exe_queue_free_elem(bp, exeq_pos);
Yuval Mintz460a25c2012-01-23 07:31:51 +00002062 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002063 }
2064
2065 spin_unlock_bh(&exeq->lock);
2066
2067 /* Prepare a command request */
2068 memset(&p, 0, sizeof(p));
2069 p.vlan_mac_obj = o;
2070 p.ramrod_flags = *ramrod_flags;
2071 p.user_req.cmd = BNX2X_VLAN_MAC_DEL;
2072
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002073 /* Add all but the last VLAN-MAC to the execution queue without actually
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002074 * execution anything.
2075 */
2076 __clear_bit(RAMROD_COMP_WAIT, &p.ramrod_flags);
2077 __clear_bit(RAMROD_EXEC, &p.ramrod_flags);
2078 __clear_bit(RAMROD_CONT, &p.ramrod_flags);
2079
Yuval Mintz8b09be52013-08-01 17:30:59 +03002080 DP(BNX2X_MSG_SP, "vlan_mac_del_all -- taking vlan_mac_lock (reader)\n");
2081 read_lock = bnx2x_vlan_mac_h_read_lock(bp, o);
2082 if (read_lock != 0)
2083 return read_lock;
2084
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002085 list_for_each_entry(pos, &o->head, link) {
2086 if (pos->vlan_mac_flags == *vlan_mac_flags) {
2087 p.user_req.vlan_mac_flags = pos->vlan_mac_flags;
2088 memcpy(&p.user_req.u, &pos->u, sizeof(pos->u));
2089 rc = bnx2x_config_vlan_mac(bp, &p);
2090 if (rc < 0) {
2091 BNX2X_ERR("Failed to add a new DEL command\n");
Yuval Mintz8b09be52013-08-01 17:30:59 +03002092 bnx2x_vlan_mac_h_read_unlock(bp, o);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002093 return rc;
2094 }
2095 }
2096 }
2097
Yuval Mintz8b09be52013-08-01 17:30:59 +03002098 DP(BNX2X_MSG_SP, "vlan_mac_del_all -- releasing vlan_mac_lock (reader)\n");
2099 bnx2x_vlan_mac_h_read_unlock(bp, o);
2100
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002101 p.ramrod_flags = *ramrod_flags;
2102 __set_bit(RAMROD_CONT, &p.ramrod_flags);
2103
2104 return bnx2x_config_vlan_mac(bp, &p);
2105}
2106
2107static inline void bnx2x_init_raw_obj(struct bnx2x_raw_obj *raw, u8 cl_id,
2108 u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping, int state,
2109 unsigned long *pstate, bnx2x_obj_type type)
2110{
2111 raw->func_id = func_id;
2112 raw->cid = cid;
2113 raw->cl_id = cl_id;
2114 raw->rdata = rdata;
2115 raw->rdata_mapping = rdata_mapping;
2116 raw->state = state;
2117 raw->pstate = pstate;
2118 raw->obj_type = type;
2119 raw->check_pending = bnx2x_raw_check_pending;
2120 raw->clear_pending = bnx2x_raw_clear_pending;
2121 raw->set_pending = bnx2x_raw_set_pending;
2122 raw->wait_comp = bnx2x_raw_wait;
2123}
2124
2125static inline void bnx2x_init_vlan_mac_common(struct bnx2x_vlan_mac_obj *o,
2126 u8 cl_id, u32 cid, u8 func_id, void *rdata, dma_addr_t rdata_mapping,
2127 int state, unsigned long *pstate, bnx2x_obj_type type,
2128 struct bnx2x_credit_pool_obj *macs_pool,
2129 struct bnx2x_credit_pool_obj *vlans_pool)
2130{
2131 INIT_LIST_HEAD(&o->head);
Yuval Mintz8b09be52013-08-01 17:30:59 +03002132 o->head_reader = 0;
2133 o->head_exe_request = false;
2134 o->saved_ramrod_flags = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002135
2136 o->macs_pool = macs_pool;
2137 o->vlans_pool = vlans_pool;
2138
2139 o->delete_all = bnx2x_vlan_mac_del_all;
2140 o->restore = bnx2x_vlan_mac_restore;
2141 o->complete = bnx2x_complete_vlan_mac;
2142 o->wait = bnx2x_wait_vlan_mac;
2143
2144 bnx2x_init_raw_obj(&o->raw, cl_id, cid, func_id, rdata, rdata_mapping,
2145 state, pstate, type);
2146}
2147
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002148void bnx2x_init_mac_obj(struct bnx2x *bp,
2149 struct bnx2x_vlan_mac_obj *mac_obj,
2150 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2151 dma_addr_t rdata_mapping, int state,
2152 unsigned long *pstate, bnx2x_obj_type type,
2153 struct bnx2x_credit_pool_obj *macs_pool)
2154{
2155 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)mac_obj;
2156
2157 bnx2x_init_vlan_mac_common(mac_obj, cl_id, cid, func_id, rdata,
2158 rdata_mapping, state, pstate, type,
2159 macs_pool, NULL);
2160
2161 /* CAM credit pool handling */
2162 mac_obj->get_credit = bnx2x_get_credit_mac;
2163 mac_obj->put_credit = bnx2x_put_credit_mac;
2164 mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
2165 mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
2166
2167 if (CHIP_IS_E1x(bp)) {
2168 mac_obj->set_one_rule = bnx2x_set_one_mac_e1x;
2169 mac_obj->check_del = bnx2x_check_mac_del;
2170 mac_obj->check_add = bnx2x_check_mac_add;
2171 mac_obj->check_move = bnx2x_check_move_always_err;
2172 mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
2173
2174 /* Exe Queue */
2175 bnx2x_exe_queue_init(bp,
2176 &mac_obj->exe_queue, 1, qable_obj,
2177 bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002178 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002179 bnx2x_optimize_vlan_mac,
2180 bnx2x_execute_vlan_mac,
2181 bnx2x_exeq_get_mac);
2182 } else {
2183 mac_obj->set_one_rule = bnx2x_set_one_mac_e2;
2184 mac_obj->check_del = bnx2x_check_mac_del;
2185 mac_obj->check_add = bnx2x_check_mac_add;
2186 mac_obj->check_move = bnx2x_check_move;
2187 mac_obj->ramrod_cmd =
2188 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
Ariel Eliored5162a2011-12-05 21:52:24 +00002189 mac_obj->get_n_elements = bnx2x_get_n_elements;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002190
2191 /* Exe Queue */
2192 bnx2x_exe_queue_init(bp,
2193 &mac_obj->exe_queue, CLASSIFY_RULES_COUNT,
2194 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002195 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002196 bnx2x_optimize_vlan_mac,
2197 bnx2x_execute_vlan_mac,
2198 bnx2x_exeq_get_mac);
2199 }
2200}
2201
2202void bnx2x_init_vlan_obj(struct bnx2x *bp,
2203 struct bnx2x_vlan_mac_obj *vlan_obj,
2204 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2205 dma_addr_t rdata_mapping, int state,
2206 unsigned long *pstate, bnx2x_obj_type type,
2207 struct bnx2x_credit_pool_obj *vlans_pool)
2208{
2209 union bnx2x_qable_obj *qable_obj = (union bnx2x_qable_obj *)vlan_obj;
2210
2211 bnx2x_init_vlan_mac_common(vlan_obj, cl_id, cid, func_id, rdata,
2212 rdata_mapping, state, pstate, type, NULL,
2213 vlans_pool);
2214
2215 vlan_obj->get_credit = bnx2x_get_credit_vlan;
2216 vlan_obj->put_credit = bnx2x_put_credit_vlan;
2217 vlan_obj->get_cam_offset = bnx2x_get_cam_offset_vlan;
2218 vlan_obj->put_cam_offset = bnx2x_put_cam_offset_vlan;
2219
2220 if (CHIP_IS_E1x(bp)) {
2221 BNX2X_ERR("Do not support chips others than E2 and newer\n");
2222 BUG();
2223 } else {
2224 vlan_obj->set_one_rule = bnx2x_set_one_vlan_e2;
2225 vlan_obj->check_del = bnx2x_check_vlan_del;
2226 vlan_obj->check_add = bnx2x_check_vlan_add;
2227 vlan_obj->check_move = bnx2x_check_move;
2228 vlan_obj->ramrod_cmd =
2229 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
Ariel Elior3ec9f9c2013-03-11 05:17:45 +00002230 vlan_obj->get_n_elements = bnx2x_get_n_elements;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002231
2232 /* Exe Queue */
2233 bnx2x_exe_queue_init(bp,
2234 &vlan_obj->exe_queue, CLASSIFY_RULES_COUNT,
2235 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002236 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002237 bnx2x_optimize_vlan_mac,
2238 bnx2x_execute_vlan_mac,
2239 bnx2x_exeq_get_vlan);
2240 }
2241}
2242
2243void bnx2x_init_vlan_mac_obj(struct bnx2x *bp,
2244 struct bnx2x_vlan_mac_obj *vlan_mac_obj,
2245 u8 cl_id, u32 cid, u8 func_id, void *rdata,
2246 dma_addr_t rdata_mapping, int state,
2247 unsigned long *pstate, bnx2x_obj_type type,
2248 struct bnx2x_credit_pool_obj *macs_pool,
2249 struct bnx2x_credit_pool_obj *vlans_pool)
2250{
2251 union bnx2x_qable_obj *qable_obj =
2252 (union bnx2x_qable_obj *)vlan_mac_obj;
2253
2254 bnx2x_init_vlan_mac_common(vlan_mac_obj, cl_id, cid, func_id, rdata,
2255 rdata_mapping, state, pstate, type,
2256 macs_pool, vlans_pool);
2257
2258 /* CAM pool handling */
2259 vlan_mac_obj->get_credit = bnx2x_get_credit_vlan_mac;
2260 vlan_mac_obj->put_credit = bnx2x_put_credit_vlan_mac;
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002261 /* CAM offset is relevant for 57710 and 57711 chips only which have a
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002262 * single CAM for both MACs and VLAN-MAC pairs. So the offset
2263 * will be taken from MACs' pool object only.
2264 */
2265 vlan_mac_obj->get_cam_offset = bnx2x_get_cam_offset_mac;
2266 vlan_mac_obj->put_cam_offset = bnx2x_put_cam_offset_mac;
2267
2268 if (CHIP_IS_E1(bp)) {
2269 BNX2X_ERR("Do not support chips others than E2\n");
2270 BUG();
2271 } else if (CHIP_IS_E1H(bp)) {
2272 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e1h;
2273 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2274 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2275 vlan_mac_obj->check_move = bnx2x_check_move_always_err;
2276 vlan_mac_obj->ramrod_cmd = RAMROD_CMD_ID_ETH_SET_MAC;
2277
2278 /* Exe Queue */
2279 bnx2x_exe_queue_init(bp,
2280 &vlan_mac_obj->exe_queue, 1, qable_obj,
2281 bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002282 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002283 bnx2x_optimize_vlan_mac,
2284 bnx2x_execute_vlan_mac,
2285 bnx2x_exeq_get_vlan_mac);
2286 } else {
2287 vlan_mac_obj->set_one_rule = bnx2x_set_one_vlan_mac_e2;
2288 vlan_mac_obj->check_del = bnx2x_check_vlan_mac_del;
2289 vlan_mac_obj->check_add = bnx2x_check_vlan_mac_add;
2290 vlan_mac_obj->check_move = bnx2x_check_move;
2291 vlan_mac_obj->ramrod_cmd =
2292 RAMROD_CMD_ID_ETH_CLASSIFICATION_RULES;
2293
2294 /* Exe Queue */
2295 bnx2x_exe_queue_init(bp,
2296 &vlan_mac_obj->exe_queue,
2297 CLASSIFY_RULES_COUNT,
2298 qable_obj, bnx2x_validate_vlan_mac,
Yuval Mintz460a25c2012-01-23 07:31:51 +00002299 bnx2x_remove_vlan_mac,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002300 bnx2x_optimize_vlan_mac,
2301 bnx2x_execute_vlan_mac,
2302 bnx2x_exeq_get_vlan_mac);
2303 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002304}
2305
2306/* RX_MODE verbs: DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
2307static inline void __storm_memset_mac_filters(struct bnx2x *bp,
2308 struct tstorm_eth_mac_filter_config *mac_filters,
2309 u16 pf_id)
2310{
2311 size_t size = sizeof(struct tstorm_eth_mac_filter_config);
2312
2313 u32 addr = BAR_TSTRORM_INTMEM +
2314 TSTORM_MAC_FILTER_CONFIG_OFFSET(pf_id);
2315
2316 __storm_memset_struct(bp, addr, size, (u32 *)mac_filters);
2317}
2318
2319static int bnx2x_set_rx_mode_e1x(struct bnx2x *bp,
2320 struct bnx2x_rx_mode_ramrod_params *p)
2321{
Yuval Mintz2de67432013-01-23 03:21:43 +00002322 /* update the bp MAC filter structure */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002323 u32 mask = (1 << p->cl_id);
2324
2325 struct tstorm_eth_mac_filter_config *mac_filters =
2326 (struct tstorm_eth_mac_filter_config *)p->rdata;
2327
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002328 /* initial setting is drop-all */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002329 u8 drop_all_ucast = 1, drop_all_mcast = 1;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002330 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
2331 u8 unmatched_unicast = 0;
2332
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002333 /* In e1x there we only take into account rx accept flag since tx switching
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002334 * isn't enabled. */
2335 if (test_bit(BNX2X_ACCEPT_UNICAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002336 /* accept matched ucast */
2337 drop_all_ucast = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002338
2339 if (test_bit(BNX2X_ACCEPT_MULTICAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002340 /* accept matched mcast */
2341 drop_all_mcast = 0;
2342
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002343 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, &p->rx_accept_flags)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002344 /* accept all mcast */
2345 drop_all_ucast = 0;
2346 accp_all_ucast = 1;
2347 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002348 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, &p->rx_accept_flags)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002349 /* accept all mcast */
2350 drop_all_mcast = 0;
2351 accp_all_mcast = 1;
2352 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002353 if (test_bit(BNX2X_ACCEPT_BROADCAST, &p->rx_accept_flags))
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002354 /* accept (all) bcast */
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002355 accp_all_bcast = 1;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002356 if (test_bit(BNX2X_ACCEPT_UNMATCHED, &p->rx_accept_flags))
2357 /* accept unmatched unicasts */
2358 unmatched_unicast = 1;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002359
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002360 mac_filters->ucast_drop_all = drop_all_ucast ?
2361 mac_filters->ucast_drop_all | mask :
2362 mac_filters->ucast_drop_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002363
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002364 mac_filters->mcast_drop_all = drop_all_mcast ?
2365 mac_filters->mcast_drop_all | mask :
2366 mac_filters->mcast_drop_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002367
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002368 mac_filters->ucast_accept_all = accp_all_ucast ?
2369 mac_filters->ucast_accept_all | mask :
2370 mac_filters->ucast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002371
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002372 mac_filters->mcast_accept_all = accp_all_mcast ?
2373 mac_filters->mcast_accept_all | mask :
2374 mac_filters->mcast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002375
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002376 mac_filters->bcast_accept_all = accp_all_bcast ?
2377 mac_filters->bcast_accept_all | mask :
2378 mac_filters->bcast_accept_all & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002379
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002380 mac_filters->unmatched_unicast = unmatched_unicast ?
2381 mac_filters->unmatched_unicast | mask :
2382 mac_filters->unmatched_unicast & ~mask;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002383
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002384 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 +00002385 "accp_mcast 0x%x\naccp_bcast 0x%x\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00002386 mac_filters->ucast_drop_all, mac_filters->mcast_drop_all,
2387 mac_filters->ucast_accept_all, mac_filters->mcast_accept_all,
2388 mac_filters->bcast_accept_all);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002389
2390 /* write the MAC filter structure*/
2391 __storm_memset_mac_filters(bp, mac_filters, p->func_id);
2392
2393 /* The operation is completed */
2394 clear_bit(p->state, p->pstate);
2395 smp_mb__after_clear_bit();
2396
2397 return 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002398}
2399
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002400/* Setup ramrod data */
2401static inline void bnx2x_rx_mode_set_rdata_hdr_e2(u32 cid,
2402 struct eth_classify_header *hdr,
2403 u8 rule_cnt)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002404{
Yuval Mintz86564c32013-01-23 03:21:50 +00002405 hdr->echo = cpu_to_le32(cid);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002406 hdr->rule_cnt = rule_cnt;
2407}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002408
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002409static inline void bnx2x_rx_mode_set_cmd_state_e2(struct bnx2x *bp,
Yuval Mintz924d75a2013-01-23 03:21:44 +00002410 unsigned long *accept_flags,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002411 struct eth_filter_rules_cmd *cmd,
2412 bool clear_accept_all)
2413{
2414 u16 state;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002415
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002416 /* start with 'drop-all' */
2417 state = ETH_FILTER_RULES_CMD_UCAST_DROP_ALL |
2418 ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2419
Yuval Mintz924d75a2013-01-23 03:21:44 +00002420 if (test_bit(BNX2X_ACCEPT_UNICAST, accept_flags))
2421 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002422
Yuval Mintz924d75a2013-01-23 03:21:44 +00002423 if (test_bit(BNX2X_ACCEPT_MULTICAST, accept_flags))
2424 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002425
Yuval Mintz924d75a2013-01-23 03:21:44 +00002426 if (test_bit(BNX2X_ACCEPT_ALL_UNICAST, accept_flags)) {
2427 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2428 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002429 }
2430
Yuval Mintz924d75a2013-01-23 03:21:44 +00002431 if (test_bit(BNX2X_ACCEPT_ALL_MULTICAST, accept_flags)) {
2432 state |= ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2433 state &= ~ETH_FILTER_RULES_CMD_MCAST_DROP_ALL;
2434 }
2435
2436 if (test_bit(BNX2X_ACCEPT_BROADCAST, accept_flags))
2437 state |= ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2438
2439 if (test_bit(BNX2X_ACCEPT_UNMATCHED, accept_flags)) {
2440 state &= ~ETH_FILTER_RULES_CMD_UCAST_DROP_ALL;
2441 state |= ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2442 }
2443
2444 if (test_bit(BNX2X_ACCEPT_ANY_VLAN, accept_flags))
2445 state |= ETH_FILTER_RULES_CMD_ACCEPT_ANY_VLAN;
2446
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002447 /* Clear ACCEPT_ALL_XXX flags for FCoE L2 Queue */
2448 if (clear_accept_all) {
2449 state &= ~ETH_FILTER_RULES_CMD_MCAST_ACCEPT_ALL;
2450 state &= ~ETH_FILTER_RULES_CMD_BCAST_ACCEPT_ALL;
2451 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_ALL;
2452 state &= ~ETH_FILTER_RULES_CMD_UCAST_ACCEPT_UNMATCHED;
2453 }
2454
2455 cmd->state = cpu_to_le16(state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002456}
2457
2458static int bnx2x_set_rx_mode_e2(struct bnx2x *bp,
2459 struct bnx2x_rx_mode_ramrod_params *p)
2460{
2461 struct eth_filter_rules_ramrod_data *data = p->rdata;
2462 int rc;
2463 u8 rule_idx = 0;
2464
2465 /* Reset the ramrod data buffer */
2466 memset(data, 0, sizeof(*data));
2467
2468 /* Setup ramrod data */
2469
2470 /* Tx (internal switching) */
2471 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2472 data->rules[rule_idx].client_id = p->cl_id;
2473 data->rules[rule_idx].func_id = p->func_id;
2474
2475 data->rules[rule_idx].cmd_general_data =
2476 ETH_FILTER_RULES_CMD_TX_CMD;
2477
Yuval Mintz924d75a2013-01-23 03:21:44 +00002478 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2479 &(data->rules[rule_idx++]),
2480 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002481 }
2482
2483 /* Rx */
2484 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2485 data->rules[rule_idx].client_id = p->cl_id;
2486 data->rules[rule_idx].func_id = p->func_id;
2487
2488 data->rules[rule_idx].cmd_general_data =
2489 ETH_FILTER_RULES_CMD_RX_CMD;
2490
Yuval Mintz924d75a2013-01-23 03:21:44 +00002491 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2492 &(data->rules[rule_idx++]),
2493 false);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002494 }
2495
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002496 /* If FCoE Queue configuration has been requested configure the Rx and
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002497 * internal switching modes for this queue in separate rules.
2498 *
2499 * FCoE queue shell never be set to ACCEPT_ALL packets of any sort:
2500 * MCAST_ALL, UCAST_ALL, BCAST_ALL and UNMATCHED.
2501 */
2502 if (test_bit(BNX2X_RX_MODE_FCOE_ETH, &p->rx_mode_flags)) {
2503 /* Tx (internal switching) */
2504 if (test_bit(RAMROD_TX, &p->ramrod_flags)) {
2505 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2506 data->rules[rule_idx].func_id = p->func_id;
2507
2508 data->rules[rule_idx].cmd_general_data =
2509 ETH_FILTER_RULES_CMD_TX_CMD;
2510
Yuval Mintz924d75a2013-01-23 03:21:44 +00002511 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->tx_accept_flags,
2512 &(data->rules[rule_idx]),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002513 true);
Yuval Mintz924d75a2013-01-23 03:21:44 +00002514 rule_idx++;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002515 }
2516
2517 /* Rx */
2518 if (test_bit(RAMROD_RX, &p->ramrod_flags)) {
2519 data->rules[rule_idx].client_id = bnx2x_fcoe(bp, cl_id);
2520 data->rules[rule_idx].func_id = p->func_id;
2521
2522 data->rules[rule_idx].cmd_general_data =
2523 ETH_FILTER_RULES_CMD_RX_CMD;
2524
Yuval Mintz924d75a2013-01-23 03:21:44 +00002525 bnx2x_rx_mode_set_cmd_state_e2(bp, &p->rx_accept_flags,
2526 &(data->rules[rule_idx]),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002527 true);
Yuval Mintz924d75a2013-01-23 03:21:44 +00002528 rule_idx++;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002529 }
2530 }
2531
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002532 /* Set the ramrod header (most importantly - number of rules to
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002533 * configure).
2534 */
2535 bnx2x_rx_mode_set_rdata_hdr_e2(p->cid, &data->header, rule_idx);
2536
Merav Sicron51c1a582012-03-18 10:33:38 +00002537 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 +03002538 data->header.rule_cnt, p->rx_accept_flags,
2539 p->tx_accept_flags);
2540
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002541 /* No need for an explicit memory barrier here as long we would
2542 * need to ensure the ordering of writing to the SPQ element
2543 * and updating of the SPQ producer which involves a memory
2544 * read and we will have to put a full memory barrier there
2545 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00002546 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002547
2548 /* Send a ramrod */
2549 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_FILTER_RULES, p->cid,
2550 U64_HI(p->rdata_mapping),
2551 U64_LO(p->rdata_mapping),
2552 ETH_CONNECTION_TYPE);
2553 if (rc)
2554 return rc;
2555
2556 /* Ramrod completion is pending */
2557 return 1;
2558}
2559
2560static int bnx2x_wait_rx_mode_comp_e2(struct bnx2x *bp,
2561 struct bnx2x_rx_mode_ramrod_params *p)
2562{
2563 return bnx2x_state_wait(bp, p->state, p->pstate);
2564}
2565
2566static int bnx2x_empty_rx_mode_wait(struct bnx2x *bp,
2567 struct bnx2x_rx_mode_ramrod_params *p)
2568{
2569 /* Do nothing */
2570 return 0;
2571}
2572
2573int bnx2x_config_rx_mode(struct bnx2x *bp,
2574 struct bnx2x_rx_mode_ramrod_params *p)
2575{
2576 int rc;
2577
2578 /* Configure the new classification in the chip */
2579 rc = p->rx_mode_obj->config_rx_mode(bp, p);
2580 if (rc < 0)
2581 return rc;
2582
2583 /* Wait for a ramrod completion if was requested */
2584 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags)) {
2585 rc = p->rx_mode_obj->wait_comp(bp, p);
2586 if (rc)
2587 return rc;
2588 }
2589
2590 return rc;
2591}
2592
2593void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
2594 struct bnx2x_rx_mode_obj *o)
2595{
2596 if (CHIP_IS_E1x(bp)) {
2597 o->wait_comp = bnx2x_empty_rx_mode_wait;
2598 o->config_rx_mode = bnx2x_set_rx_mode_e1x;
2599 } else {
2600 o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
2601 o->config_rx_mode = bnx2x_set_rx_mode_e2;
2602 }
2603}
2604
2605/********************* Multicast verbs: SET, CLEAR ****************************/
2606static inline u8 bnx2x_mcast_bin_from_mac(u8 *mac)
2607{
2608 return (crc32c_le(0, mac, ETH_ALEN) >> 24) & 0xff;
2609}
2610
2611struct bnx2x_mcast_mac_elem {
2612 struct list_head link;
2613 u8 mac[ETH_ALEN];
2614 u8 pad[2]; /* For a natural alignment of the following buffer */
2615};
2616
2617struct bnx2x_pending_mcast_cmd {
2618 struct list_head link;
2619 int type; /* BNX2X_MCAST_CMD_X */
2620 union {
2621 struct list_head macs_head;
2622 u32 macs_num; /* Needed for DEL command */
2623 int next_bin; /* Needed for RESTORE flow with aprox match */
2624 } data;
2625
2626 bool done; /* set to true, when the command has been handled,
2627 * practically used in 57712 handling only, where one pending
2628 * command may be handled in a few operations. As long as for
2629 * other chips every operation handling is completed in a
2630 * single ramrod, there is no need to utilize this field.
2631 */
2632};
2633
2634static int bnx2x_mcast_wait(struct bnx2x *bp,
2635 struct bnx2x_mcast_obj *o)
2636{
2637 if (bnx2x_state_wait(bp, o->sched_state, o->raw.pstate) ||
2638 o->raw.wait_comp(bp, &o->raw))
2639 return -EBUSY;
2640
2641 return 0;
2642}
2643
2644static int bnx2x_mcast_enqueue_cmd(struct bnx2x *bp,
2645 struct bnx2x_mcast_obj *o,
2646 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00002647 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002648{
2649 int total_sz;
2650 struct bnx2x_pending_mcast_cmd *new_cmd;
2651 struct bnx2x_mcast_mac_elem *cur_mac = NULL;
2652 struct bnx2x_mcast_list_elem *pos;
2653 int macs_list_len = ((cmd == BNX2X_MCAST_CMD_ADD) ?
2654 p->mcast_list_len : 0);
2655
2656 /* If the command is empty ("handle pending commands only"), break */
2657 if (!p->mcast_list_len)
2658 return 0;
2659
2660 total_sz = sizeof(*new_cmd) +
2661 macs_list_len * sizeof(struct bnx2x_mcast_mac_elem);
2662
2663 /* Add mcast is called under spin_lock, thus calling with GFP_ATOMIC */
2664 new_cmd = kzalloc(total_sz, GFP_ATOMIC);
2665
2666 if (!new_cmd)
2667 return -ENOMEM;
2668
Merav Sicron51c1a582012-03-18 10:33:38 +00002669 DP(BNX2X_MSG_SP, "About to enqueue a new %d command. macs_list_len=%d\n",
2670 cmd, macs_list_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002671
2672 INIT_LIST_HEAD(&new_cmd->data.macs_head);
2673
2674 new_cmd->type = cmd;
2675 new_cmd->done = false;
2676
2677 switch (cmd) {
2678 case BNX2X_MCAST_CMD_ADD:
2679 cur_mac = (struct bnx2x_mcast_mac_elem *)
2680 ((u8 *)new_cmd + sizeof(*new_cmd));
2681
Yuval Mintz16a5fd92013-06-02 00:06:18 +00002682 /* Push the MACs of the current command into the pending command
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002683 * MACs list: FIFO
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002684 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002685 list_for_each_entry(pos, &p->mcast_list, link) {
2686 memcpy(cur_mac->mac, pos->mac, ETH_ALEN);
2687 list_add_tail(&cur_mac->link, &new_cmd->data.macs_head);
2688 cur_mac++;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002689 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002690
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002691 break;
2692
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002693 case BNX2X_MCAST_CMD_DEL:
2694 new_cmd->data.macs_num = p->mcast_list_len;
2695 break;
2696
2697 case BNX2X_MCAST_CMD_RESTORE:
2698 new_cmd->data.next_bin = 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002699 break;
2700
2701 default:
Jesper Juhl8b6d5c02012-07-31 11:39:37 +00002702 kfree(new_cmd);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002703 BNX2X_ERR("Unknown command: %d\n", cmd);
2704 return -EINVAL;
2705 }
2706
2707 /* Push the new pending command to the tail of the pending list: FIFO */
2708 list_add_tail(&new_cmd->link, &o->pending_cmds_head);
2709
2710 o->set_sched(o);
2711
2712 return 1;
2713}
2714
2715/**
2716 * bnx2x_mcast_get_next_bin - get the next set bin (index)
2717 *
2718 * @o:
2719 * @last: index to start looking from (including)
2720 *
2721 * returns the next found (set) bin or a negative value if none is found.
2722 */
2723static inline int bnx2x_mcast_get_next_bin(struct bnx2x_mcast_obj *o, int last)
2724{
2725 int i, j, inner_start = last % BIT_VEC64_ELEM_SZ;
2726
2727 for (i = last / BIT_VEC64_ELEM_SZ; i < BNX2X_MCAST_VEC_SZ; i++) {
2728 if (o->registry.aprox_match.vec[i])
2729 for (j = inner_start; j < BIT_VEC64_ELEM_SZ; j++) {
2730 int cur_bit = j + BIT_VEC64_ELEM_SZ * i;
2731 if (BIT_VEC64_TEST_BIT(o->registry.aprox_match.
2732 vec, cur_bit)) {
2733 return cur_bit;
2734 }
2735 }
2736 inner_start = 0;
2737 }
2738
2739 /* None found */
2740 return -1;
2741}
2742
2743/**
2744 * bnx2x_mcast_clear_first_bin - find the first set bin and clear it
2745 *
2746 * @o:
2747 *
2748 * returns the index of the found bin or -1 if none is found
2749 */
2750static inline int bnx2x_mcast_clear_first_bin(struct bnx2x_mcast_obj *o)
2751{
2752 int cur_bit = bnx2x_mcast_get_next_bin(o, 0);
2753
2754 if (cur_bit >= 0)
2755 BIT_VEC64_CLEAR_BIT(o->registry.aprox_match.vec, cur_bit);
2756
2757 return cur_bit;
2758}
2759
2760static inline u8 bnx2x_mcast_get_rx_tx_flag(struct bnx2x_mcast_obj *o)
2761{
2762 struct bnx2x_raw_obj *raw = &o->raw;
2763 u8 rx_tx_flag = 0;
2764
2765 if ((raw->obj_type == BNX2X_OBJ_TYPE_TX) ||
2766 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2767 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_TX_CMD;
2768
2769 if ((raw->obj_type == BNX2X_OBJ_TYPE_RX) ||
2770 (raw->obj_type == BNX2X_OBJ_TYPE_RX_TX))
2771 rx_tx_flag |= ETH_MULTICAST_RULES_CMD_RX_CMD;
2772
2773 return rx_tx_flag;
2774}
2775
2776static void bnx2x_mcast_set_one_rule_e2(struct bnx2x *bp,
2777 struct bnx2x_mcast_obj *o, int idx,
2778 union bnx2x_mcast_config_data *cfg_data,
Yuval Mintz86564c32013-01-23 03:21:50 +00002779 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002780{
2781 struct bnx2x_raw_obj *r = &o->raw;
2782 struct eth_multicast_rules_ramrod_data *data =
2783 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
2784 u8 func_id = r->func_id;
2785 u8 rx_tx_add_flag = bnx2x_mcast_get_rx_tx_flag(o);
2786 int bin;
2787
2788 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE))
2789 rx_tx_add_flag |= ETH_MULTICAST_RULES_CMD_IS_ADD;
2790
2791 data->rules[idx].cmd_general_data |= rx_tx_add_flag;
2792
2793 /* Get a bin and update a bins' vector */
2794 switch (cmd) {
2795 case BNX2X_MCAST_CMD_ADD:
2796 bin = bnx2x_mcast_bin_from_mac(cfg_data->mac);
2797 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec, bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002798 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002799
2800 case BNX2X_MCAST_CMD_DEL:
2801 /* If there were no more bins to clear
2802 * (bnx2x_mcast_clear_first_bin() returns -1) then we would
2803 * clear any (0xff) bin.
2804 * See bnx2x_mcast_validate_e2() for explanation when it may
2805 * happen.
2806 */
2807 bin = bnx2x_mcast_clear_first_bin(o);
2808 break;
2809
2810 case BNX2X_MCAST_CMD_RESTORE:
2811 bin = cfg_data->bin;
2812 break;
2813
2814 default:
2815 BNX2X_ERR("Unknown command: %d\n", cmd);
2816 return;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002817 }
2818
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002819 DP(BNX2X_MSG_SP, "%s bin %d\n",
2820 ((rx_tx_add_flag & ETH_MULTICAST_RULES_CMD_IS_ADD) ?
2821 "Setting" : "Clearing"), bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002822
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002823 data->rules[idx].bin_id = (u8)bin;
2824 data->rules[idx].func_id = func_id;
2825 data->rules[idx].engine_id = o->engine_id;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002826}
2827
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002828/**
2829 * bnx2x_mcast_handle_restore_cmd_e2 - restore configuration from the registry
2830 *
2831 * @bp: device handle
2832 * @o:
2833 * @start_bin: index in the registry to start from (including)
2834 * @rdata_idx: index in the ramrod data to start from
2835 *
2836 * returns last handled bin index or -1 if all bins have been handled
2837 */
2838static inline int bnx2x_mcast_handle_restore_cmd_e2(
2839 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_bin,
2840 int *rdata_idx)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002841{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002842 int cur_bin, cnt = *rdata_idx;
Yuval Mintz86564c32013-01-23 03:21:50 +00002843 union bnx2x_mcast_config_data cfg_data = {NULL};
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002844
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002845 /* go through the registry and configure the bins from it */
2846 for (cur_bin = bnx2x_mcast_get_next_bin(o, start_bin); cur_bin >= 0;
2847 cur_bin = bnx2x_mcast_get_next_bin(o, cur_bin + 1)) {
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002848
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002849 cfg_data.bin = (u8)cur_bin;
2850 o->set_one_rule(bp, o, cnt, &cfg_data,
2851 BNX2X_MCAST_CMD_RESTORE);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002852
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002853 cnt++;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002854
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002855 DP(BNX2X_MSG_SP, "About to configure a bin %d\n", cur_bin);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002856
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002857 /* Break if we reached the maximum number
2858 * of rules.
2859 */
2860 if (cnt >= o->max_cmd_len)
2861 break;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002862 }
2863
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002864 *rdata_idx = cnt;
2865
2866 return cur_bin;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002867}
2868
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002869static inline void bnx2x_mcast_hdl_pending_add_e2(struct bnx2x *bp,
2870 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2871 int *line_idx)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00002872{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002873 struct bnx2x_mcast_mac_elem *pmac_pos, *pmac_pos_n;
2874 int cnt = *line_idx;
Yuval Mintz86564c32013-01-23 03:21:50 +00002875 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002876
2877 list_for_each_entry_safe(pmac_pos, pmac_pos_n, &cmd_pos->data.macs_head,
2878 link) {
2879
2880 cfg_data.mac = &pmac_pos->mac[0];
2881 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
2882
2883 cnt++;
2884
Joe Perches0f9dad12011-08-14 12:16:19 +00002885 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00002886 pmac_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002887
2888 list_del(&pmac_pos->link);
2889
2890 /* Break if we reached the maximum number
2891 * of rules.
2892 */
2893 if (cnt >= o->max_cmd_len)
2894 break;
2895 }
2896
2897 *line_idx = cnt;
2898
2899 /* if no more MACs to configure - we are done */
2900 if (list_empty(&cmd_pos->data.macs_head))
2901 cmd_pos->done = true;
2902}
2903
2904static inline void bnx2x_mcast_hdl_pending_del_e2(struct bnx2x *bp,
2905 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2906 int *line_idx)
2907{
2908 int cnt = *line_idx;
2909
2910 while (cmd_pos->data.macs_num) {
2911 o->set_one_rule(bp, o, cnt, NULL, cmd_pos->type);
2912
2913 cnt++;
2914
2915 cmd_pos->data.macs_num--;
2916
2917 DP(BNX2X_MSG_SP, "Deleting MAC. %d left,cnt is %d\n",
2918 cmd_pos->data.macs_num, cnt);
2919
2920 /* Break if we reached the maximum
2921 * number of rules.
2922 */
2923 if (cnt >= o->max_cmd_len)
2924 break;
2925 }
2926
2927 *line_idx = cnt;
2928
2929 /* If we cleared all bins - we are done */
2930 if (!cmd_pos->data.macs_num)
2931 cmd_pos->done = true;
2932}
2933
2934static inline void bnx2x_mcast_hdl_pending_restore_e2(struct bnx2x *bp,
2935 struct bnx2x_mcast_obj *o, struct bnx2x_pending_mcast_cmd *cmd_pos,
2936 int *line_idx)
2937{
2938 cmd_pos->data.next_bin = o->hdl_restore(bp, o, cmd_pos->data.next_bin,
2939 line_idx);
2940
2941 if (cmd_pos->data.next_bin < 0)
2942 /* If o->set_restore returned -1 we are done */
2943 cmd_pos->done = true;
2944 else
2945 /* Start from the next bin next time */
2946 cmd_pos->data.next_bin++;
2947}
2948
2949static inline int bnx2x_mcast_handle_pending_cmds_e2(struct bnx2x *bp,
2950 struct bnx2x_mcast_ramrod_params *p)
2951{
2952 struct bnx2x_pending_mcast_cmd *cmd_pos, *cmd_pos_n;
2953 int cnt = 0;
2954 struct bnx2x_mcast_obj *o = p->mcast_obj;
2955
2956 list_for_each_entry_safe(cmd_pos, cmd_pos_n, &o->pending_cmds_head,
2957 link) {
2958 switch (cmd_pos->type) {
2959 case BNX2X_MCAST_CMD_ADD:
2960 bnx2x_mcast_hdl_pending_add_e2(bp, o, cmd_pos, &cnt);
2961 break;
2962
2963 case BNX2X_MCAST_CMD_DEL:
2964 bnx2x_mcast_hdl_pending_del_e2(bp, o, cmd_pos, &cnt);
2965 break;
2966
2967 case BNX2X_MCAST_CMD_RESTORE:
2968 bnx2x_mcast_hdl_pending_restore_e2(bp, o, cmd_pos,
2969 &cnt);
2970 break;
2971
2972 default:
2973 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
2974 return -EINVAL;
2975 }
2976
2977 /* If the command has been completed - remove it from the list
2978 * and free the memory
2979 */
2980 if (cmd_pos->done) {
2981 list_del(&cmd_pos->link);
2982 kfree(cmd_pos);
2983 }
2984
2985 /* Break if we reached the maximum number of rules */
2986 if (cnt >= o->max_cmd_len)
2987 break;
2988 }
2989
2990 return cnt;
2991}
2992
2993static inline void bnx2x_mcast_hdl_add(struct bnx2x *bp,
2994 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
2995 int *line_idx)
2996{
2997 struct bnx2x_mcast_list_elem *mlist_pos;
Yuval Mintz86564c32013-01-23 03:21:50 +00002998 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03002999 int cnt = *line_idx;
3000
3001 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
3002 cfg_data.mac = mlist_pos->mac;
3003 o->set_one_rule(bp, o, cnt, &cfg_data, BNX2X_MCAST_CMD_ADD);
3004
3005 cnt++;
3006
Joe Perches0f9dad12011-08-14 12:16:19 +00003007 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003008 mlist_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003009 }
3010
3011 *line_idx = cnt;
3012}
3013
3014static inline void bnx2x_mcast_hdl_del(struct bnx2x *bp,
3015 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3016 int *line_idx)
3017{
3018 int cnt = *line_idx, i;
3019
3020 for (i = 0; i < p->mcast_list_len; i++) {
3021 o->set_one_rule(bp, o, cnt, NULL, BNX2X_MCAST_CMD_DEL);
3022
3023 cnt++;
3024
3025 DP(BNX2X_MSG_SP, "Deleting MAC. %d left\n",
3026 p->mcast_list_len - i - 1);
3027 }
3028
3029 *line_idx = cnt;
3030}
3031
3032/**
3033 * bnx2x_mcast_handle_current_cmd -
3034 *
3035 * @bp: device handle
3036 * @p:
3037 * @cmd:
3038 * @start_cnt: first line in the ramrod data that may be used
3039 *
3040 * This function is called iff there is enough place for the current command in
3041 * the ramrod data.
3042 * Returns number of lines filled in the ramrod data in total.
3043 */
3044static inline int bnx2x_mcast_handle_current_cmd(struct bnx2x *bp,
Yuval Mintz86564c32013-01-23 03:21:50 +00003045 struct bnx2x_mcast_ramrod_params *p,
3046 enum bnx2x_mcast_cmd cmd,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003047 int start_cnt)
3048{
3049 struct bnx2x_mcast_obj *o = p->mcast_obj;
3050 int cnt = start_cnt;
3051
3052 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3053
3054 switch (cmd) {
3055 case BNX2X_MCAST_CMD_ADD:
3056 bnx2x_mcast_hdl_add(bp, o, p, &cnt);
3057 break;
3058
3059 case BNX2X_MCAST_CMD_DEL:
3060 bnx2x_mcast_hdl_del(bp, o, p, &cnt);
3061 break;
3062
3063 case BNX2X_MCAST_CMD_RESTORE:
3064 o->hdl_restore(bp, o, 0, &cnt);
3065 break;
3066
3067 default:
3068 BNX2X_ERR("Unknown command: %d\n", cmd);
3069 return -EINVAL;
3070 }
3071
3072 /* The current command has been handled */
3073 p->mcast_list_len = 0;
3074
3075 return cnt;
3076}
3077
3078static int bnx2x_mcast_validate_e2(struct bnx2x *bp,
3079 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003080 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003081{
3082 struct bnx2x_mcast_obj *o = p->mcast_obj;
3083 int reg_sz = o->get_registry_size(o);
3084
3085 switch (cmd) {
3086 /* DEL command deletes all currently configured MACs */
3087 case BNX2X_MCAST_CMD_DEL:
3088 o->set_registry_size(o, 0);
3089 /* Don't break */
3090
3091 /* RESTORE command will restore the entire multicast configuration */
3092 case BNX2X_MCAST_CMD_RESTORE:
3093 /* Here we set the approximate amount of work to do, which in
3094 * fact may be only less as some MACs in postponed ADD
3095 * command(s) scheduled before this command may fall into
3096 * the same bin and the actual number of bins set in the
3097 * registry would be less than we estimated here. See
3098 * bnx2x_mcast_set_one_rule_e2() for further details.
3099 */
3100 p->mcast_list_len = reg_sz;
3101 break;
3102
3103 case BNX2X_MCAST_CMD_ADD:
3104 case BNX2X_MCAST_CMD_CONT:
3105 /* Here we assume that all new MACs will fall into new bins.
3106 * However we will correct the real registry size after we
3107 * handle all pending commands.
3108 */
3109 o->set_registry_size(o, reg_sz + p->mcast_list_len);
3110 break;
3111
3112 default:
3113 BNX2X_ERR("Unknown command: %d\n", cmd);
3114 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003115 }
3116
3117 /* Increase the total number of MACs pending to be configured */
3118 o->total_pending_num += p->mcast_list_len;
3119
3120 return 0;
3121}
3122
3123static void bnx2x_mcast_revert_e2(struct bnx2x *bp,
3124 struct bnx2x_mcast_ramrod_params *p,
3125 int old_num_bins)
3126{
3127 struct bnx2x_mcast_obj *o = p->mcast_obj;
3128
3129 o->set_registry_size(o, old_num_bins);
3130 o->total_pending_num -= p->mcast_list_len;
3131}
3132
3133/**
3134 * bnx2x_mcast_set_rdata_hdr_e2 - sets a header values
3135 *
3136 * @bp: device handle
3137 * @p:
3138 * @len: number of rules to handle
3139 */
3140static inline void bnx2x_mcast_set_rdata_hdr_e2(struct bnx2x *bp,
3141 struct bnx2x_mcast_ramrod_params *p,
3142 u8 len)
3143{
3144 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3145 struct eth_multicast_rules_ramrod_data *data =
3146 (struct eth_multicast_rules_ramrod_data *)(r->rdata);
3147
Yuval Mintz86564c32013-01-23 03:21:50 +00003148 data->header.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
3149 (BNX2X_FILTER_MCAST_PENDING <<
3150 BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003151 data->header.rule_cnt = len;
3152}
3153
3154/**
3155 * bnx2x_mcast_refresh_registry_e2 - recalculate the actual number of set bins
3156 *
3157 * @bp: device handle
3158 * @o:
3159 *
3160 * Recalculate the actual number of set bins in the registry using Brian
3161 * Kernighan's algorithm: it's execution complexity is as a number of set bins.
3162 *
3163 * returns 0 for the compliance with bnx2x_mcast_refresh_registry_e1().
3164 */
3165static inline int bnx2x_mcast_refresh_registry_e2(struct bnx2x *bp,
3166 struct bnx2x_mcast_obj *o)
3167{
3168 int i, cnt = 0;
3169 u64 elem;
3170
3171 for (i = 0; i < BNX2X_MCAST_VEC_SZ; i++) {
3172 elem = o->registry.aprox_match.vec[i];
3173 for (; elem; cnt++)
3174 elem &= elem - 1;
3175 }
3176
3177 o->set_registry_size(o, cnt);
3178
3179 return 0;
3180}
3181
3182static int bnx2x_mcast_setup_e2(struct bnx2x *bp,
3183 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003184 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003185{
3186 struct bnx2x_raw_obj *raw = &p->mcast_obj->raw;
3187 struct bnx2x_mcast_obj *o = p->mcast_obj;
3188 struct eth_multicast_rules_ramrod_data *data =
3189 (struct eth_multicast_rules_ramrod_data *)(raw->rdata);
3190 int cnt = 0, rc;
3191
3192 /* Reset the ramrod data buffer */
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00003193 memset(data, 0, sizeof(*data));
3194
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003195 cnt = bnx2x_mcast_handle_pending_cmds_e2(bp, p);
3196
3197 /* If there are no more pending commands - clear SCHEDULED state */
3198 if (list_empty(&o->pending_cmds_head))
3199 o->clear_sched(o);
3200
3201 /* The below may be true iff there was enough room in ramrod
3202 * data for all pending commands and for the current
3203 * command. Otherwise the current command would have been added
3204 * to the pending commands and p->mcast_list_len would have been
3205 * zeroed.
3206 */
3207 if (p->mcast_list_len > 0)
3208 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, cnt);
3209
3210 /* We've pulled out some MACs - update the total number of
3211 * outstanding.
3212 */
3213 o->total_pending_num -= cnt;
3214
3215 /* send a ramrod */
3216 WARN_ON(o->total_pending_num < 0);
3217 WARN_ON(cnt > o->max_cmd_len);
3218
3219 bnx2x_mcast_set_rdata_hdr_e2(bp, p, (u8)cnt);
3220
3221 /* Update a registry size if there are no more pending operations.
3222 *
3223 * We don't want to change the value of the registry size if there are
3224 * pending operations because we want it to always be equal to the
3225 * exact or the approximate number (see bnx2x_mcast_validate_e2()) of
3226 * set bins after the last requested operation in order to properly
3227 * evaluate the size of the next DEL/RESTORE operation.
3228 *
3229 * Note that we update the registry itself during command(s) handling
3230 * - see bnx2x_mcast_set_one_rule_e2(). That's because for 57712 we
3231 * aggregate multiple commands (ADD/DEL/RESTORE) into one ramrod but
3232 * with a limited amount of update commands (per MAC/bin) and we don't
3233 * know in this scope what the actual state of bins configuration is
3234 * going to be after this ramrod.
3235 */
3236 if (!o->total_pending_num)
3237 bnx2x_mcast_refresh_registry_e2(bp, o);
3238
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003239 /* If CLEAR_ONLY was requested - don't send a ramrod and clear
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003240 * RAMROD_PENDING status immediately.
3241 */
3242 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3243 raw->clear_pending(raw);
3244 return 0;
3245 } else {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003246 /* No need for an explicit memory barrier here as long we would
3247 * need to ensure the ordering of writing to the SPQ element
3248 * and updating of the SPQ producer which involves a memory
3249 * read and we will have to put a full memory barrier there
3250 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003251 */
3252
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003253 /* Send a ramrod */
3254 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_MULTICAST_RULES,
3255 raw->cid, U64_HI(raw->rdata_mapping),
3256 U64_LO(raw->rdata_mapping),
3257 ETH_CONNECTION_TYPE);
3258 if (rc)
3259 return rc;
3260
3261 /* Ramrod completion is pending */
3262 return 1;
3263 }
3264}
3265
3266static int bnx2x_mcast_validate_e1h(struct bnx2x *bp,
3267 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003268 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003269{
3270 /* Mark, that there is a work to do */
3271 if ((cmd == BNX2X_MCAST_CMD_DEL) || (cmd == BNX2X_MCAST_CMD_RESTORE))
3272 p->mcast_list_len = 1;
3273
3274 return 0;
3275}
3276
3277static void bnx2x_mcast_revert_e1h(struct bnx2x *bp,
3278 struct bnx2x_mcast_ramrod_params *p,
3279 int old_num_bins)
3280{
3281 /* Do nothing */
3282}
3283
3284#define BNX2X_57711_SET_MC_FILTER(filter, bit) \
3285do { \
3286 (filter)[(bit) >> 5] |= (1 << ((bit) & 0x1f)); \
3287} while (0)
3288
3289static inline void bnx2x_mcast_hdl_add_e1h(struct bnx2x *bp,
3290 struct bnx2x_mcast_obj *o,
3291 struct bnx2x_mcast_ramrod_params *p,
3292 u32 *mc_filter)
3293{
3294 struct bnx2x_mcast_list_elem *mlist_pos;
3295 int bit;
3296
3297 list_for_each_entry(mlist_pos, &p->mcast_list, link) {
3298 bit = bnx2x_mcast_bin_from_mac(mlist_pos->mac);
3299 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3300
Joe Perches0f9dad12011-08-14 12:16:19 +00003301 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC, bin %d\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003302 mlist_pos->mac, bit);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003303
3304 /* bookkeeping... */
3305 BIT_VEC64_SET_BIT(o->registry.aprox_match.vec,
3306 bit);
3307 }
3308}
3309
3310static inline void bnx2x_mcast_hdl_restore_e1h(struct bnx2x *bp,
3311 struct bnx2x_mcast_obj *o, struct bnx2x_mcast_ramrod_params *p,
3312 u32 *mc_filter)
3313{
3314 int bit;
3315
3316 for (bit = bnx2x_mcast_get_next_bin(o, 0);
3317 bit >= 0;
3318 bit = bnx2x_mcast_get_next_bin(o, bit + 1)) {
3319 BNX2X_57711_SET_MC_FILTER(mc_filter, bit);
3320 DP(BNX2X_MSG_SP, "About to set bin %d\n", bit);
3321 }
3322}
3323
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003324/* On 57711 we write the multicast MACs' approximate match
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003325 * table by directly into the TSTORM's internal RAM. So we don't
3326 * really need to handle any tricks to make it work.
3327 */
3328static int bnx2x_mcast_setup_e1h(struct bnx2x *bp,
3329 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003330 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003331{
3332 int i;
3333 struct bnx2x_mcast_obj *o = p->mcast_obj;
3334 struct bnx2x_raw_obj *r = &o->raw;
3335
3336 /* If CLEAR_ONLY has been requested - clear the registry
3337 * and clear a pending bit.
3338 */
3339 if (!test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3340 u32 mc_filter[MC_HASH_SIZE] = {0};
3341
3342 /* Set the multicast filter bits before writing it into
3343 * the internal memory.
3344 */
3345 switch (cmd) {
3346 case BNX2X_MCAST_CMD_ADD:
3347 bnx2x_mcast_hdl_add_e1h(bp, o, p, mc_filter);
3348 break;
3349
3350 case BNX2X_MCAST_CMD_DEL:
Joe Perches94f05b02011-08-14 12:16:20 +00003351 DP(BNX2X_MSG_SP,
3352 "Invalidating multicast MACs configuration\n");
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003353
3354 /* clear the registry */
3355 memset(o->registry.aprox_match.vec, 0,
3356 sizeof(o->registry.aprox_match.vec));
3357 break;
3358
3359 case BNX2X_MCAST_CMD_RESTORE:
3360 bnx2x_mcast_hdl_restore_e1h(bp, o, p, mc_filter);
3361 break;
3362
3363 default:
3364 BNX2X_ERR("Unknown command: %d\n", cmd);
3365 return -EINVAL;
3366 }
3367
3368 /* Set the mcast filter in the internal memory */
3369 for (i = 0; i < MC_HASH_SIZE; i++)
3370 REG_WR(bp, MC_HASH_OFFSET(bp, i), mc_filter[i]);
3371 } else
3372 /* clear the registry */
3373 memset(o->registry.aprox_match.vec, 0,
3374 sizeof(o->registry.aprox_match.vec));
3375
3376 /* We are done */
3377 r->clear_pending(r);
3378
3379 return 0;
3380}
3381
3382static int bnx2x_mcast_validate_e1(struct bnx2x *bp,
3383 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003384 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003385{
3386 struct bnx2x_mcast_obj *o = p->mcast_obj;
3387 int reg_sz = o->get_registry_size(o);
3388
3389 switch (cmd) {
3390 /* DEL command deletes all currently configured MACs */
3391 case BNX2X_MCAST_CMD_DEL:
3392 o->set_registry_size(o, 0);
3393 /* Don't break */
3394
3395 /* RESTORE command will restore the entire multicast configuration */
3396 case BNX2X_MCAST_CMD_RESTORE:
3397 p->mcast_list_len = reg_sz;
3398 DP(BNX2X_MSG_SP, "Command %d, p->mcast_list_len=%d\n",
3399 cmd, p->mcast_list_len);
3400 break;
3401
3402 case BNX2X_MCAST_CMD_ADD:
3403 case BNX2X_MCAST_CMD_CONT:
3404 /* Multicast MACs on 57710 are configured as unicast MACs and
3405 * there is only a limited number of CAM entries for that
3406 * matter.
3407 */
3408 if (p->mcast_list_len > o->max_cmd_len) {
Merav Sicron51c1a582012-03-18 10:33:38 +00003409 BNX2X_ERR("Can't configure more than %d multicast MACs on 57710\n",
3410 o->max_cmd_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003411 return -EINVAL;
3412 }
3413 /* Every configured MAC should be cleared if DEL command is
3414 * called. Only the last ADD command is relevant as long as
3415 * every ADD commands overrides the previous configuration.
3416 */
3417 DP(BNX2X_MSG_SP, "p->mcast_list_len=%d\n", p->mcast_list_len);
3418 if (p->mcast_list_len > 0)
3419 o->set_registry_size(o, p->mcast_list_len);
3420
3421 break;
3422
3423 default:
3424 BNX2X_ERR("Unknown command: %d\n", cmd);
3425 return -EINVAL;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003426 }
3427
3428 /* We want to ensure that commands are executed one by one for 57710.
3429 * Therefore each none-empty command will consume o->max_cmd_len.
3430 */
3431 if (p->mcast_list_len)
3432 o->total_pending_num += o->max_cmd_len;
3433
3434 return 0;
3435}
3436
3437static void bnx2x_mcast_revert_e1(struct bnx2x *bp,
3438 struct bnx2x_mcast_ramrod_params *p,
3439 int old_num_macs)
3440{
3441 struct bnx2x_mcast_obj *o = p->mcast_obj;
3442
3443 o->set_registry_size(o, old_num_macs);
3444
3445 /* If current command hasn't been handled yet and we are
3446 * here means that it's meant to be dropped and we have to
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003447 * update the number of outstanding MACs accordingly.
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003448 */
3449 if (p->mcast_list_len)
3450 o->total_pending_num -= o->max_cmd_len;
3451}
3452
3453static void bnx2x_mcast_set_one_rule_e1(struct bnx2x *bp,
3454 struct bnx2x_mcast_obj *o, int idx,
3455 union bnx2x_mcast_config_data *cfg_data,
Yuval Mintz86564c32013-01-23 03:21:50 +00003456 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003457{
3458 struct bnx2x_raw_obj *r = &o->raw;
3459 struct mac_configuration_cmd *data =
3460 (struct mac_configuration_cmd *)(r->rdata);
3461
3462 /* copy mac */
3463 if ((cmd == BNX2X_MCAST_CMD_ADD) || (cmd == BNX2X_MCAST_CMD_RESTORE)) {
3464 bnx2x_set_fw_mac_addr(&data->config_table[idx].msb_mac_addr,
3465 &data->config_table[idx].middle_mac_addr,
3466 &data->config_table[idx].lsb_mac_addr,
3467 cfg_data->mac);
3468
3469 data->config_table[idx].vlan_id = 0;
3470 data->config_table[idx].pf_id = r->func_id;
3471 data->config_table[idx].clients_bit_vector =
3472 cpu_to_le32(1 << r->cl_id);
3473
3474 SET_FLAG(data->config_table[idx].flags,
3475 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3476 T_ETH_MAC_COMMAND_SET);
3477 }
3478}
3479
3480/**
3481 * bnx2x_mcast_set_rdata_hdr_e1 - set header values in mac_configuration_cmd
3482 *
3483 * @bp: device handle
3484 * @p:
3485 * @len: number of rules to handle
3486 */
3487static inline void bnx2x_mcast_set_rdata_hdr_e1(struct bnx2x *bp,
3488 struct bnx2x_mcast_ramrod_params *p,
3489 u8 len)
3490{
3491 struct bnx2x_raw_obj *r = &p->mcast_obj->raw;
3492 struct mac_configuration_cmd *data =
3493 (struct mac_configuration_cmd *)(r->rdata);
3494
3495 u8 offset = (CHIP_REV_IS_SLOW(bp) ?
3496 BNX2X_MAX_EMUL_MULTI*(1 + r->func_id) :
3497 BNX2X_MAX_MULTICAST*(1 + r->func_id));
3498
3499 data->hdr.offset = offset;
Yuval Mintz86564c32013-01-23 03:21:50 +00003500 data->hdr.client_id = cpu_to_le16(0xff);
3501 data->hdr.echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
3502 (BNX2X_FILTER_MCAST_PENDING <<
3503 BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003504 data->hdr.length = len;
3505}
3506
3507/**
3508 * bnx2x_mcast_handle_restore_cmd_e1 - restore command for 57710
3509 *
3510 * @bp: device handle
3511 * @o:
3512 * @start_idx: index in the registry to start from
3513 * @rdata_idx: index in the ramrod data to start from
3514 *
3515 * restore command for 57710 is like all other commands - always a stand alone
3516 * command - start_idx and rdata_idx will always be 0. This function will always
3517 * succeed.
3518 * returns -1 to comply with 57712 variant.
3519 */
3520static inline int bnx2x_mcast_handle_restore_cmd_e1(
3521 struct bnx2x *bp, struct bnx2x_mcast_obj *o , int start_idx,
3522 int *rdata_idx)
3523{
3524 struct bnx2x_mcast_mac_elem *elem;
3525 int i = 0;
Yuval Mintz86564c32013-01-23 03:21:50 +00003526 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003527
3528 /* go through the registry and configure the MACs from it. */
3529 list_for_each_entry(elem, &o->registry.exact_match.macs, link) {
3530 cfg_data.mac = &elem->mac[0];
3531 o->set_one_rule(bp, o, i, &cfg_data, BNX2X_MCAST_CMD_RESTORE);
3532
3533 i++;
3534
Joe Perches0f9dad12011-08-14 12:16:19 +00003535 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003536 cfg_data.mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003537 }
3538
3539 *rdata_idx = i;
3540
3541 return -1;
3542}
3543
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003544static inline int bnx2x_mcast_handle_pending_cmds_e1(
3545 struct bnx2x *bp, struct bnx2x_mcast_ramrod_params *p)
3546{
3547 struct bnx2x_pending_mcast_cmd *cmd_pos;
3548 struct bnx2x_mcast_mac_elem *pmac_pos;
3549 struct bnx2x_mcast_obj *o = p->mcast_obj;
Yuval Mintz86564c32013-01-23 03:21:50 +00003550 union bnx2x_mcast_config_data cfg_data = {NULL};
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003551 int cnt = 0;
3552
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003553 /* If nothing to be done - return */
3554 if (list_empty(&o->pending_cmds_head))
3555 return 0;
3556
3557 /* Handle the first command */
3558 cmd_pos = list_first_entry(&o->pending_cmds_head,
3559 struct bnx2x_pending_mcast_cmd, link);
3560
3561 switch (cmd_pos->type) {
3562 case BNX2X_MCAST_CMD_ADD:
3563 list_for_each_entry(pmac_pos, &cmd_pos->data.macs_head, link) {
3564 cfg_data.mac = &pmac_pos->mac[0];
3565 o->set_one_rule(bp, o, cnt, &cfg_data, cmd_pos->type);
3566
3567 cnt++;
3568
Joe Perches0f9dad12011-08-14 12:16:19 +00003569 DP(BNX2X_MSG_SP, "About to configure %pM mcast MAC\n",
Yuval Mintz2de67432013-01-23 03:21:43 +00003570 pmac_pos->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003571 }
3572 break;
3573
3574 case BNX2X_MCAST_CMD_DEL:
3575 cnt = cmd_pos->data.macs_num;
3576 DP(BNX2X_MSG_SP, "About to delete %d multicast MACs\n", cnt);
3577 break;
3578
3579 case BNX2X_MCAST_CMD_RESTORE:
3580 o->hdl_restore(bp, o, 0, &cnt);
3581 break;
3582
3583 default:
3584 BNX2X_ERR("Unknown command: %d\n", cmd_pos->type);
3585 return -EINVAL;
3586 }
3587
3588 list_del(&cmd_pos->link);
3589 kfree(cmd_pos);
3590
3591 return cnt;
3592}
3593
3594/**
3595 * bnx2x_get_fw_mac_addr - revert the bnx2x_set_fw_mac_addr().
3596 *
3597 * @fw_hi:
3598 * @fw_mid:
3599 * @fw_lo:
3600 * @mac:
3601 */
3602static inline void bnx2x_get_fw_mac_addr(__le16 *fw_hi, __le16 *fw_mid,
3603 __le16 *fw_lo, u8 *mac)
3604{
3605 mac[1] = ((u8 *)fw_hi)[0];
3606 mac[0] = ((u8 *)fw_hi)[1];
3607 mac[3] = ((u8 *)fw_mid)[0];
3608 mac[2] = ((u8 *)fw_mid)[1];
3609 mac[5] = ((u8 *)fw_lo)[0];
3610 mac[4] = ((u8 *)fw_lo)[1];
3611}
3612
3613/**
3614 * bnx2x_mcast_refresh_registry_e1 -
3615 *
3616 * @bp: device handle
3617 * @cnt:
3618 *
3619 * Check the ramrod data first entry flag to see if it's a DELETE or ADD command
3620 * and update the registry correspondingly: if ADD - allocate a memory and add
3621 * the entries to the registry (list), if DELETE - clear the registry and free
3622 * the memory.
3623 */
3624static inline int bnx2x_mcast_refresh_registry_e1(struct bnx2x *bp,
3625 struct bnx2x_mcast_obj *o)
3626{
3627 struct bnx2x_raw_obj *raw = &o->raw;
3628 struct bnx2x_mcast_mac_elem *elem;
3629 struct mac_configuration_cmd *data =
3630 (struct mac_configuration_cmd *)(raw->rdata);
3631
3632 /* If first entry contains a SET bit - the command was ADD,
3633 * otherwise - DEL_ALL
3634 */
3635 if (GET_FLAG(data->config_table[0].flags,
3636 MAC_CONFIGURATION_ENTRY_ACTION_TYPE)) {
3637 int i, len = data->hdr.length;
3638
3639 /* Break if it was a RESTORE command */
3640 if (!list_empty(&o->registry.exact_match.macs))
3641 return 0;
3642
Thomas Meyer01e23742011-11-29 11:08:00 +00003643 elem = kcalloc(len, sizeof(*elem), GFP_ATOMIC);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003644 if (!elem) {
3645 BNX2X_ERR("Failed to allocate registry memory\n");
3646 return -ENOMEM;
3647 }
3648
3649 for (i = 0; i < len; i++, elem++) {
3650 bnx2x_get_fw_mac_addr(
3651 &data->config_table[i].msb_mac_addr,
3652 &data->config_table[i].middle_mac_addr,
3653 &data->config_table[i].lsb_mac_addr,
3654 elem->mac);
Joe Perches0f9dad12011-08-14 12:16:19 +00003655 DP(BNX2X_MSG_SP, "Adding registry entry for [%pM]\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00003656 elem->mac);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003657 list_add_tail(&elem->link,
3658 &o->registry.exact_match.macs);
3659 }
3660 } else {
3661 elem = list_first_entry(&o->registry.exact_match.macs,
3662 struct bnx2x_mcast_mac_elem, link);
3663 DP(BNX2X_MSG_SP, "Deleting a registry\n");
3664 kfree(elem);
3665 INIT_LIST_HEAD(&o->registry.exact_match.macs);
3666 }
3667
3668 return 0;
3669}
3670
3671static int bnx2x_mcast_setup_e1(struct bnx2x *bp,
3672 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003673 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003674{
3675 struct bnx2x_mcast_obj *o = p->mcast_obj;
3676 struct bnx2x_raw_obj *raw = &o->raw;
3677 struct mac_configuration_cmd *data =
3678 (struct mac_configuration_cmd *)(raw->rdata);
3679 int cnt = 0, i, rc;
3680
3681 /* Reset the ramrod data buffer */
3682 memset(data, 0, sizeof(*data));
3683
3684 /* First set all entries as invalid */
3685 for (i = 0; i < o->max_cmd_len ; i++)
3686 SET_FLAG(data->config_table[i].flags,
3687 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
3688 T_ETH_MAC_COMMAND_INVALIDATE);
3689
3690 /* Handle pending commands first */
3691 cnt = bnx2x_mcast_handle_pending_cmds_e1(bp, p);
3692
3693 /* If there are no more pending commands - clear SCHEDULED state */
3694 if (list_empty(&o->pending_cmds_head))
3695 o->clear_sched(o);
3696
3697 /* The below may be true iff there were no pending commands */
3698 if (!cnt)
3699 cnt = bnx2x_mcast_handle_current_cmd(bp, p, cmd, 0);
3700
3701 /* For 57710 every command has o->max_cmd_len length to ensure that
3702 * commands are done one at a time.
3703 */
3704 o->total_pending_num -= o->max_cmd_len;
3705
3706 /* send a ramrod */
3707
3708 WARN_ON(cnt > o->max_cmd_len);
3709
3710 /* Set ramrod header (in particular, a number of entries to update) */
3711 bnx2x_mcast_set_rdata_hdr_e1(bp, p, (u8)cnt);
3712
3713 /* update a registry: we need the registry contents to be always up
3714 * to date in order to be able to execute a RESTORE opcode. Here
3715 * we use the fact that for 57710 we sent one command at a time
3716 * hence we may take the registry update out of the command handling
3717 * and do it in a simpler way here.
3718 */
3719 rc = bnx2x_mcast_refresh_registry_e1(bp, o);
3720 if (rc)
3721 return rc;
3722
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003723 /* If CLEAR_ONLY was requested - don't send a ramrod and clear
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003724 * RAMROD_PENDING status immediately.
3725 */
3726 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags)) {
3727 raw->clear_pending(raw);
3728 return 0;
3729 } else {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00003730 /* No need for an explicit memory barrier here as long we would
3731 * need to ensure the ordering of writing to the SPQ element
3732 * and updating of the SPQ producer which involves a memory
3733 * read and we will have to put a full memory barrier there
3734 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00003735 */
3736
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003737 /* Send a ramrod */
3738 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_SET_MAC, raw->cid,
3739 U64_HI(raw->rdata_mapping),
3740 U64_LO(raw->rdata_mapping),
3741 ETH_CONNECTION_TYPE);
3742 if (rc)
3743 return rc;
3744
3745 /* Ramrod completion is pending */
3746 return 1;
3747 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003748}
3749
3750static int bnx2x_mcast_get_registry_size_exact(struct bnx2x_mcast_obj *o)
3751{
3752 return o->registry.exact_match.num_macs_set;
3753}
3754
3755static int bnx2x_mcast_get_registry_size_aprox(struct bnx2x_mcast_obj *o)
3756{
3757 return o->registry.aprox_match.num_bins_set;
3758}
3759
3760static void bnx2x_mcast_set_registry_size_exact(struct bnx2x_mcast_obj *o,
3761 int n)
3762{
3763 o->registry.exact_match.num_macs_set = n;
3764}
3765
3766static void bnx2x_mcast_set_registry_size_aprox(struct bnx2x_mcast_obj *o,
3767 int n)
3768{
3769 o->registry.aprox_match.num_bins_set = n;
3770}
3771
3772int bnx2x_config_mcast(struct bnx2x *bp,
3773 struct bnx2x_mcast_ramrod_params *p,
Yuval Mintz86564c32013-01-23 03:21:50 +00003774 enum bnx2x_mcast_cmd cmd)
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003775{
3776 struct bnx2x_mcast_obj *o = p->mcast_obj;
3777 struct bnx2x_raw_obj *r = &o->raw;
3778 int rc = 0, old_reg_size;
3779
3780 /* This is needed to recover number of currently configured mcast macs
3781 * in case of failure.
3782 */
3783 old_reg_size = o->get_registry_size(o);
3784
3785 /* Do some calculations and checks */
3786 rc = o->validate(bp, p, cmd);
3787 if (rc)
3788 return rc;
3789
3790 /* Return if there is no work to do */
3791 if ((!p->mcast_list_len) && (!o->check_sched(o)))
3792 return 0;
3793
Merav Sicron51c1a582012-03-18 10:33:38 +00003794 DP(BNX2X_MSG_SP, "o->total_pending_num=%d p->mcast_list_len=%d o->max_cmd_len=%d\n",
3795 o->total_pending_num, p->mcast_list_len, o->max_cmd_len);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03003796
3797 /* Enqueue the current command to the pending list if we can't complete
3798 * it in the current iteration
3799 */
3800 if (r->check_pending(r) ||
3801 ((o->max_cmd_len > 0) && (o->total_pending_num > o->max_cmd_len))) {
3802 rc = o->enqueue_cmd(bp, p->mcast_obj, p, cmd);
3803 if (rc < 0)
3804 goto error_exit1;
3805
3806 /* As long as the current command is in a command list we
3807 * don't need to handle it separately.
3808 */
3809 p->mcast_list_len = 0;
3810 }
3811
3812 if (!r->check_pending(r)) {
3813
3814 /* Set 'pending' state */
3815 r->set_pending(r);
3816
3817 /* Configure the new classification in the chip */
3818 rc = o->config_mcast(bp, p, cmd);
3819 if (rc < 0)
3820 goto error_exit2;
3821
3822 /* Wait for a ramrod completion if was requested */
3823 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
3824 rc = o->wait_comp(bp, o);
3825 }
3826
3827 return rc;
3828
3829error_exit2:
3830 r->clear_pending(r);
3831
3832error_exit1:
3833 o->revert(bp, p, old_reg_size);
3834
3835 return rc;
3836}
3837
3838static void bnx2x_mcast_clear_sched(struct bnx2x_mcast_obj *o)
3839{
3840 smp_mb__before_clear_bit();
3841 clear_bit(o->sched_state, o->raw.pstate);
3842 smp_mb__after_clear_bit();
3843}
3844
3845static void bnx2x_mcast_set_sched(struct bnx2x_mcast_obj *o)
3846{
3847 smp_mb__before_clear_bit();
3848 set_bit(o->sched_state, o->raw.pstate);
3849 smp_mb__after_clear_bit();
3850}
3851
3852static bool bnx2x_mcast_check_sched(struct bnx2x_mcast_obj *o)
3853{
3854 return !!test_bit(o->sched_state, o->raw.pstate);
3855}
3856
3857static bool bnx2x_mcast_check_pending(struct bnx2x_mcast_obj *o)
3858{
3859 return o->raw.check_pending(&o->raw) || o->check_sched(o);
3860}
3861
3862void bnx2x_init_mcast_obj(struct bnx2x *bp,
3863 struct bnx2x_mcast_obj *mcast_obj,
3864 u8 mcast_cl_id, u32 mcast_cid, u8 func_id,
3865 u8 engine_id, void *rdata, dma_addr_t rdata_mapping,
3866 int state, unsigned long *pstate, bnx2x_obj_type type)
3867{
3868 memset(mcast_obj, 0, sizeof(*mcast_obj));
3869
3870 bnx2x_init_raw_obj(&mcast_obj->raw, mcast_cl_id, mcast_cid, func_id,
3871 rdata, rdata_mapping, state, pstate, type);
3872
3873 mcast_obj->engine_id = engine_id;
3874
3875 INIT_LIST_HEAD(&mcast_obj->pending_cmds_head);
3876
3877 mcast_obj->sched_state = BNX2X_FILTER_MCAST_SCHED;
3878 mcast_obj->check_sched = bnx2x_mcast_check_sched;
3879 mcast_obj->set_sched = bnx2x_mcast_set_sched;
3880 mcast_obj->clear_sched = bnx2x_mcast_clear_sched;
3881
3882 if (CHIP_IS_E1(bp)) {
3883 mcast_obj->config_mcast = bnx2x_mcast_setup_e1;
3884 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3885 mcast_obj->hdl_restore =
3886 bnx2x_mcast_handle_restore_cmd_e1;
3887 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3888
3889 if (CHIP_REV_IS_SLOW(bp))
3890 mcast_obj->max_cmd_len = BNX2X_MAX_EMUL_MULTI;
3891 else
3892 mcast_obj->max_cmd_len = BNX2X_MAX_MULTICAST;
3893
3894 mcast_obj->wait_comp = bnx2x_mcast_wait;
3895 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e1;
3896 mcast_obj->validate = bnx2x_mcast_validate_e1;
3897 mcast_obj->revert = bnx2x_mcast_revert_e1;
3898 mcast_obj->get_registry_size =
3899 bnx2x_mcast_get_registry_size_exact;
3900 mcast_obj->set_registry_size =
3901 bnx2x_mcast_set_registry_size_exact;
3902
3903 /* 57710 is the only chip that uses the exact match for mcast
3904 * at the moment.
3905 */
3906 INIT_LIST_HEAD(&mcast_obj->registry.exact_match.macs);
3907
3908 } else if (CHIP_IS_E1H(bp)) {
3909 mcast_obj->config_mcast = bnx2x_mcast_setup_e1h;
3910 mcast_obj->enqueue_cmd = NULL;
3911 mcast_obj->hdl_restore = NULL;
3912 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3913
3914 /* 57711 doesn't send a ramrod, so it has unlimited credit
3915 * for one command.
3916 */
3917 mcast_obj->max_cmd_len = -1;
3918 mcast_obj->wait_comp = bnx2x_mcast_wait;
3919 mcast_obj->set_one_rule = NULL;
3920 mcast_obj->validate = bnx2x_mcast_validate_e1h;
3921 mcast_obj->revert = bnx2x_mcast_revert_e1h;
3922 mcast_obj->get_registry_size =
3923 bnx2x_mcast_get_registry_size_aprox;
3924 mcast_obj->set_registry_size =
3925 bnx2x_mcast_set_registry_size_aprox;
3926 } else {
3927 mcast_obj->config_mcast = bnx2x_mcast_setup_e2;
3928 mcast_obj->enqueue_cmd = bnx2x_mcast_enqueue_cmd;
3929 mcast_obj->hdl_restore =
3930 bnx2x_mcast_handle_restore_cmd_e2;
3931 mcast_obj->check_pending = bnx2x_mcast_check_pending;
3932 /* TODO: There should be a proper HSI define for this number!!!
3933 */
3934 mcast_obj->max_cmd_len = 16;
3935 mcast_obj->wait_comp = bnx2x_mcast_wait;
3936 mcast_obj->set_one_rule = bnx2x_mcast_set_one_rule_e2;
3937 mcast_obj->validate = bnx2x_mcast_validate_e2;
3938 mcast_obj->revert = bnx2x_mcast_revert_e2;
3939 mcast_obj->get_registry_size =
3940 bnx2x_mcast_get_registry_size_aprox;
3941 mcast_obj->set_registry_size =
3942 bnx2x_mcast_set_registry_size_aprox;
3943 }
3944}
3945
3946/*************************** Credit handling **********************************/
3947
3948/**
3949 * atomic_add_ifless - add if the result is less than a given value.
3950 *
3951 * @v: pointer of type atomic_t
3952 * @a: the amount to add to v...
3953 * @u: ...if (v + a) is less than u.
3954 *
3955 * returns true if (v + a) was less than u, and false otherwise.
3956 *
3957 */
3958static inline bool __atomic_add_ifless(atomic_t *v, int a, int u)
3959{
3960 int c, old;
3961
3962 c = atomic_read(v);
3963 for (;;) {
3964 if (unlikely(c + a >= u))
3965 return false;
3966
3967 old = atomic_cmpxchg((v), c, c + a);
3968 if (likely(old == c))
3969 break;
3970 c = old;
3971 }
3972
3973 return true;
3974}
3975
3976/**
3977 * atomic_dec_ifmoe - dec if the result is more or equal than a given value.
3978 *
3979 * @v: pointer of type atomic_t
3980 * @a: the amount to dec from v...
3981 * @u: ...if (v - a) is more or equal than u.
3982 *
3983 * returns true if (v - a) was more or equal than u, and false
3984 * otherwise.
3985 */
3986static inline bool __atomic_dec_ifmoe(atomic_t *v, int a, int u)
3987{
3988 int c, old;
3989
3990 c = atomic_read(v);
3991 for (;;) {
3992 if (unlikely(c - a < u))
3993 return false;
3994
3995 old = atomic_cmpxchg((v), c, c - a);
3996 if (likely(old == c))
3997 break;
3998 c = old;
3999 }
4000
4001 return true;
4002}
4003
4004static bool bnx2x_credit_pool_get(struct bnx2x_credit_pool_obj *o, int cnt)
4005{
4006 bool rc;
4007
4008 smp_mb();
4009 rc = __atomic_dec_ifmoe(&o->credit, cnt, 0);
4010 smp_mb();
4011
4012 return rc;
4013}
4014
4015static bool bnx2x_credit_pool_put(struct bnx2x_credit_pool_obj *o, int cnt)
4016{
4017 bool rc;
4018
4019 smp_mb();
4020
4021 /* Don't let to refill if credit + cnt > pool_sz */
4022 rc = __atomic_add_ifless(&o->credit, cnt, o->pool_sz + 1);
4023
4024 smp_mb();
4025
4026 return rc;
4027}
4028
4029static int bnx2x_credit_pool_check(struct bnx2x_credit_pool_obj *o)
4030{
4031 int cur_credit;
4032
4033 smp_mb();
4034 cur_credit = atomic_read(&o->credit);
4035
4036 return cur_credit;
4037}
4038
4039static bool bnx2x_credit_pool_always_true(struct bnx2x_credit_pool_obj *o,
4040 int cnt)
4041{
4042 return true;
4043}
4044
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004045static bool bnx2x_credit_pool_get_entry(
4046 struct bnx2x_credit_pool_obj *o,
4047 int *offset)
4048{
4049 int idx, vec, i;
4050
4051 *offset = -1;
4052
4053 /* Find "internal cam-offset" then add to base for this object... */
4054 for (vec = 0; vec < BNX2X_POOL_VEC_SIZE; vec++) {
4055
4056 /* Skip the current vector if there are no free entries in it */
4057 if (!o->pool_mirror[vec])
4058 continue;
4059
4060 /* If we've got here we are going to find a free entry */
Dmitry Kravkovc54e9bd2012-03-26 21:08:55 +00004061 for (idx = vec * BIT_VEC64_ELEM_SZ, i = 0;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004062 i < BIT_VEC64_ELEM_SZ; idx++, i++)
4063
4064 if (BIT_VEC64_TEST_BIT(o->pool_mirror, idx)) {
4065 /* Got one!! */
4066 BIT_VEC64_CLEAR_BIT(o->pool_mirror, idx);
4067 *offset = o->base_pool_offset + idx;
4068 return true;
4069 }
4070 }
4071
4072 return false;
4073}
4074
4075static bool bnx2x_credit_pool_put_entry(
4076 struct bnx2x_credit_pool_obj *o,
4077 int offset)
4078{
4079 if (offset < o->base_pool_offset)
4080 return false;
4081
4082 offset -= o->base_pool_offset;
4083
4084 if (offset >= o->pool_sz)
4085 return false;
4086
4087 /* Return the entry to the pool */
4088 BIT_VEC64_SET_BIT(o->pool_mirror, offset);
4089
4090 return true;
4091}
4092
4093static bool bnx2x_credit_pool_put_entry_always_true(
4094 struct bnx2x_credit_pool_obj *o,
4095 int offset)
4096{
4097 return true;
4098}
4099
4100static bool bnx2x_credit_pool_get_entry_always_true(
4101 struct bnx2x_credit_pool_obj *o,
4102 int *offset)
4103{
4104 *offset = -1;
4105 return true;
4106}
4107/**
4108 * bnx2x_init_credit_pool - initialize credit pool internals.
4109 *
4110 * @p:
4111 * @base: Base entry in the CAM to use.
4112 * @credit: pool size.
4113 *
4114 * If base is negative no CAM entries handling will be performed.
4115 * If credit is negative pool operations will always succeed (unlimited pool).
4116 *
4117 */
4118static inline void bnx2x_init_credit_pool(struct bnx2x_credit_pool_obj *p,
4119 int base, int credit)
4120{
4121 /* Zero the object first */
4122 memset(p, 0, sizeof(*p));
4123
4124 /* Set the table to all 1s */
4125 memset(&p->pool_mirror, 0xff, sizeof(p->pool_mirror));
4126
4127 /* Init a pool as full */
4128 atomic_set(&p->credit, credit);
4129
4130 /* The total poll size */
4131 p->pool_sz = credit;
4132
4133 p->base_pool_offset = base;
4134
4135 /* Commit the change */
4136 smp_mb();
4137
4138 p->check = bnx2x_credit_pool_check;
4139
4140 /* if pool credit is negative - disable the checks */
4141 if (credit >= 0) {
4142 p->put = bnx2x_credit_pool_put;
4143 p->get = bnx2x_credit_pool_get;
4144 p->put_entry = bnx2x_credit_pool_put_entry;
4145 p->get_entry = bnx2x_credit_pool_get_entry;
4146 } else {
4147 p->put = bnx2x_credit_pool_always_true;
4148 p->get = bnx2x_credit_pool_always_true;
4149 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
4150 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
4151 }
4152
4153 /* If base is negative - disable entries handling */
4154 if (base < 0) {
4155 p->put_entry = bnx2x_credit_pool_put_entry_always_true;
4156 p->get_entry = bnx2x_credit_pool_get_entry_always_true;
4157 }
4158}
4159
4160void bnx2x_init_mac_credit_pool(struct bnx2x *bp,
4161 struct bnx2x_credit_pool_obj *p, u8 func_id,
4162 u8 func_num)
4163{
4164/* TODO: this will be defined in consts as well... */
4165#define BNX2X_CAM_SIZE_EMUL 5
4166
4167 int cam_sz;
4168
4169 if (CHIP_IS_E1(bp)) {
4170 /* In E1, Multicast is saved in cam... */
4171 if (!CHIP_REV_IS_SLOW(bp))
4172 cam_sz = (MAX_MAC_CREDIT_E1 / 2) - BNX2X_MAX_MULTICAST;
4173 else
4174 cam_sz = BNX2X_CAM_SIZE_EMUL - BNX2X_MAX_EMUL_MULTI;
4175
4176 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
4177
4178 } else if (CHIP_IS_E1H(bp)) {
4179 /* CAM credit is equaly divided between all active functions
4180 * on the PORT!.
4181 */
4182 if ((func_num > 0)) {
4183 if (!CHIP_REV_IS_SLOW(bp))
4184 cam_sz = (MAX_MAC_CREDIT_E1H / (2*func_num));
4185 else
4186 cam_sz = BNX2X_CAM_SIZE_EMUL;
4187 bnx2x_init_credit_pool(p, func_id * cam_sz, cam_sz);
4188 } else {
4189 /* this should never happen! Block MAC operations. */
4190 bnx2x_init_credit_pool(p, 0, 0);
4191 }
4192
4193 } else {
4194
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004195 /* CAM credit is equaly divided between all active functions
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004196 * on the PATH.
4197 */
4198 if ((func_num > 0)) {
4199 if (!CHIP_REV_IS_SLOW(bp))
4200 cam_sz = (MAX_MAC_CREDIT_E2 / func_num);
4201 else
4202 cam_sz = BNX2X_CAM_SIZE_EMUL;
4203
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004204 /* No need for CAM entries handling for 57712 and
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004205 * newer.
4206 */
4207 bnx2x_init_credit_pool(p, -1, cam_sz);
4208 } else {
4209 /* this should never happen! Block MAC operations. */
4210 bnx2x_init_credit_pool(p, 0, 0);
4211 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004212 }
4213}
4214
4215void bnx2x_init_vlan_credit_pool(struct bnx2x *bp,
4216 struct bnx2x_credit_pool_obj *p,
4217 u8 func_id,
4218 u8 func_num)
4219{
4220 if (CHIP_IS_E1x(bp)) {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004221 /* There is no VLAN credit in HW on 57710 and 57711 only
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004222 * MAC / MAC-VLAN can be set
4223 */
4224 bnx2x_init_credit_pool(p, 0, -1);
4225 } else {
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004226 /* CAM credit is equally divided between all active functions
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004227 * on the PATH.
4228 */
4229 if (func_num > 0) {
4230 int credit = MAX_VLAN_CREDIT_E2 / func_num;
4231 bnx2x_init_credit_pool(p, func_id * credit, credit);
4232 } else
4233 /* this should never happen! Block VLAN operations. */
4234 bnx2x_init_credit_pool(p, 0, 0);
4235 }
4236}
4237
4238/****************** RSS Configuration ******************/
4239/**
4240 * bnx2x_debug_print_ind_table - prints the indirection table configuration.
4241 *
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004242 * @bp: driver handle
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004243 * @p: pointer to rss configuration
4244 *
4245 * Prints it when NETIF_MSG_IFUP debug level is configured.
4246 */
4247static inline void bnx2x_debug_print_ind_table(struct bnx2x *bp,
4248 struct bnx2x_config_rss_params *p)
4249{
4250 int i;
4251
4252 DP(BNX2X_MSG_SP, "Setting indirection table to:\n");
4253 DP(BNX2X_MSG_SP, "0x0000: ");
4254 for (i = 0; i < T_ETH_INDIRECTION_TABLE_SIZE; i++) {
4255 DP_CONT(BNX2X_MSG_SP, "0x%02x ", p->ind_table[i]);
4256
4257 /* Print 4 bytes in a line */
4258 if ((i + 1 < T_ETH_INDIRECTION_TABLE_SIZE) &&
4259 (((i + 1) & 0x3) == 0)) {
4260 DP_CONT(BNX2X_MSG_SP, "\n");
4261 DP(BNX2X_MSG_SP, "0x%04x: ", i + 1);
4262 }
4263 }
4264
4265 DP_CONT(BNX2X_MSG_SP, "\n");
4266}
4267
4268/**
4269 * bnx2x_setup_rss - configure RSS
4270 *
4271 * @bp: device handle
4272 * @p: rss configuration
4273 *
4274 * sends on UPDATE ramrod for that matter.
4275 */
4276static int bnx2x_setup_rss(struct bnx2x *bp,
4277 struct bnx2x_config_rss_params *p)
4278{
4279 struct bnx2x_rss_config_obj *o = p->rss_obj;
4280 struct bnx2x_raw_obj *r = &o->raw;
4281 struct eth_rss_update_ramrod_data *data =
4282 (struct eth_rss_update_ramrod_data *)(r->rdata);
4283 u8 rss_mode = 0;
4284 int rc;
4285
4286 memset(data, 0, sizeof(*data));
4287
4288 DP(BNX2X_MSG_SP, "Configuring RSS\n");
4289
4290 /* Set an echo field */
Yuval Mintz86564c32013-01-23 03:21:50 +00004291 data->echo = cpu_to_le32((r->cid & BNX2X_SWCID_MASK) |
4292 (r->state << BNX2X_SWCID_SHIFT));
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004293
4294 /* RSS mode */
4295 if (test_bit(BNX2X_RSS_MODE_DISABLED, &p->rss_flags))
4296 rss_mode = ETH_RSS_MODE_DISABLED;
4297 else if (test_bit(BNX2X_RSS_MODE_REGULAR, &p->rss_flags))
4298 rss_mode = ETH_RSS_MODE_REGULAR;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004299
4300 data->rss_mode = rss_mode;
4301
4302 DP(BNX2X_MSG_SP, "rss_mode=%d\n", rss_mode);
4303
4304 /* RSS capabilities */
4305 if (test_bit(BNX2X_RSS_IPV4, &p->rss_flags))
4306 data->capabilities |=
4307 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_CAPABILITY;
4308
4309 if (test_bit(BNX2X_RSS_IPV4_TCP, &p->rss_flags))
4310 data->capabilities |=
4311 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_TCP_CAPABILITY;
4312
Merav Sicron5d317c6a2012-06-19 07:48:24 +00004313 if (test_bit(BNX2X_RSS_IPV4_UDP, &p->rss_flags))
4314 data->capabilities |=
4315 ETH_RSS_UPDATE_RAMROD_DATA_IPV4_UDP_CAPABILITY;
4316
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004317 if (test_bit(BNX2X_RSS_IPV6, &p->rss_flags))
4318 data->capabilities |=
4319 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_CAPABILITY;
4320
4321 if (test_bit(BNX2X_RSS_IPV6_TCP, &p->rss_flags))
4322 data->capabilities |=
4323 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_TCP_CAPABILITY;
4324
Merav Sicron5d317c6a2012-06-19 07:48:24 +00004325 if (test_bit(BNX2X_RSS_IPV6_UDP, &p->rss_flags))
4326 data->capabilities |=
4327 ETH_RSS_UPDATE_RAMROD_DATA_IPV6_UDP_CAPABILITY;
4328
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004329 /* Hashing mask */
4330 data->rss_result_mask = p->rss_result_mask;
4331
4332 /* RSS engine ID */
4333 data->rss_engine_id = o->engine_id;
4334
4335 DP(BNX2X_MSG_SP, "rss_engine_id=%d\n", data->rss_engine_id);
4336
4337 /* Indirection table */
4338 memcpy(data->indirection_table, p->ind_table,
4339 T_ETH_INDIRECTION_TABLE_SIZE);
4340
4341 /* Remember the last configuration */
4342 memcpy(o->ind_table, p->ind_table, T_ETH_INDIRECTION_TABLE_SIZE);
4343
4344 /* Print the indirection table */
4345 if (netif_msg_ifup(bp))
4346 bnx2x_debug_print_ind_table(bp, p);
4347
4348 /* RSS keys */
4349 if (test_bit(BNX2X_RSS_SET_SRCH, &p->rss_flags)) {
4350 memcpy(&data->rss_key[0], &p->rss_key[0],
4351 sizeof(data->rss_key));
4352 data->capabilities |= ETH_RSS_UPDATE_RAMROD_DATA_UPDATE_RSS_KEY;
4353 }
4354
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004355 /* No need for an explicit memory barrier here as long we would
4356 * need to ensure the ordering of writing to the SPQ element
4357 * and updating of the SPQ producer which involves a memory
4358 * read and we will have to put a full memory barrier there
4359 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004360 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004361
4362 /* Send a ramrod */
4363 rc = bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_RSS_UPDATE, r->cid,
4364 U64_HI(r->rdata_mapping),
4365 U64_LO(r->rdata_mapping),
4366 ETH_CONNECTION_TYPE);
4367
4368 if (rc < 0)
4369 return rc;
4370
4371 return 1;
4372}
4373
4374void bnx2x_get_rss_ind_table(struct bnx2x_rss_config_obj *rss_obj,
4375 u8 *ind_table)
4376{
4377 memcpy(ind_table, rss_obj->ind_table, sizeof(rss_obj->ind_table));
4378}
4379
4380int bnx2x_config_rss(struct bnx2x *bp,
4381 struct bnx2x_config_rss_params *p)
4382{
4383 int rc;
4384 struct bnx2x_rss_config_obj *o = p->rss_obj;
4385 struct bnx2x_raw_obj *r = &o->raw;
4386
4387 /* Do nothing if only driver cleanup was requested */
4388 if (test_bit(RAMROD_DRV_CLR_ONLY, &p->ramrod_flags))
4389 return 0;
4390
4391 r->set_pending(r);
4392
4393 rc = o->config_rss(bp, p);
4394 if (rc < 0) {
4395 r->clear_pending(r);
4396 return rc;
4397 }
4398
4399 if (test_bit(RAMROD_COMP_WAIT, &p->ramrod_flags))
4400 rc = r->wait_comp(bp, r);
4401
4402 return rc;
4403}
4404
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004405void bnx2x_init_rss_config_obj(struct bnx2x *bp,
4406 struct bnx2x_rss_config_obj *rss_obj,
4407 u8 cl_id, u32 cid, u8 func_id, u8 engine_id,
4408 void *rdata, dma_addr_t rdata_mapping,
4409 int state, unsigned long *pstate,
4410 bnx2x_obj_type type)
4411{
4412 bnx2x_init_raw_obj(&rss_obj->raw, cl_id, cid, func_id, rdata,
4413 rdata_mapping, state, pstate, type);
4414
4415 rss_obj->engine_id = engine_id;
4416 rss_obj->config_rss = bnx2x_setup_rss;
4417}
4418
4419/********************** Queue state object ***********************************/
4420
4421/**
4422 * bnx2x_queue_state_change - perform Queue state change transition
4423 *
4424 * @bp: device handle
4425 * @params: parameters to perform the transition
4426 *
4427 * returns 0 in case of successfully completed transition, negative error
4428 * code in case of failure, positive (EBUSY) value if there is a completion
4429 * to that is still pending (possible only if RAMROD_COMP_WAIT is
4430 * not set in params->ramrod_flags for asynchronous commands).
4431 *
4432 */
4433int bnx2x_queue_state_change(struct bnx2x *bp,
4434 struct bnx2x_queue_state_params *params)
4435{
4436 struct bnx2x_queue_sp_obj *o = params->q_obj;
4437 int rc, pending_bit;
4438 unsigned long *pending = &o->pending;
4439
4440 /* Check that the requested transition is legal */
Yuval Mintz04c46732013-01-23 03:21:46 +00004441 rc = o->check_transition(bp, o, params);
4442 if (rc) {
4443 BNX2X_ERR("check transition returned an error. rc %d\n", rc);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004444 return -EINVAL;
Yuval Mintz04c46732013-01-23 03:21:46 +00004445 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004446
4447 /* Set "pending" bit */
Yuval Mintz04c46732013-01-23 03:21:46 +00004448 DP(BNX2X_MSG_SP, "pending bit was=%lx\n", o->pending);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004449 pending_bit = o->set_pending(o, params);
Yuval Mintz04c46732013-01-23 03:21:46 +00004450 DP(BNX2X_MSG_SP, "pending bit now=%lx\n", o->pending);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004451
4452 /* Don't send a command if only driver cleanup was requested */
4453 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags))
4454 o->complete_cmd(bp, o, pending_bit);
4455 else {
4456 /* Send a ramrod */
4457 rc = o->send_cmd(bp, params);
4458 if (rc) {
4459 o->next_state = BNX2X_Q_STATE_MAX;
4460 clear_bit(pending_bit, pending);
4461 smp_mb__after_clear_bit();
4462 return rc;
4463 }
4464
4465 if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
4466 rc = o->wait_comp(bp, o, pending_bit);
4467 if (rc)
4468 return rc;
4469
4470 return 0;
4471 }
4472 }
4473
4474 return !!test_bit(pending_bit, pending);
4475}
4476
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004477static int bnx2x_queue_set_pending(struct bnx2x_queue_sp_obj *obj,
4478 struct bnx2x_queue_state_params *params)
4479{
4480 enum bnx2x_queue_cmd cmd = params->cmd, bit;
4481
4482 /* ACTIVATE and DEACTIVATE commands are implemented on top of
4483 * UPDATE command.
4484 */
4485 if ((cmd == BNX2X_Q_CMD_ACTIVATE) ||
4486 (cmd == BNX2X_Q_CMD_DEACTIVATE))
4487 bit = BNX2X_Q_CMD_UPDATE;
4488 else
4489 bit = cmd;
4490
4491 set_bit(bit, &obj->pending);
4492 return bit;
4493}
4494
4495static int bnx2x_queue_wait_comp(struct bnx2x *bp,
4496 struct bnx2x_queue_sp_obj *o,
4497 enum bnx2x_queue_cmd cmd)
4498{
4499 return bnx2x_state_wait(bp, cmd, &o->pending);
4500}
4501
4502/**
4503 * bnx2x_queue_comp_cmd - complete the state change command.
4504 *
4505 * @bp: device handle
4506 * @o:
4507 * @cmd:
4508 *
4509 * Checks that the arrived completion is expected.
4510 */
4511static int bnx2x_queue_comp_cmd(struct bnx2x *bp,
4512 struct bnx2x_queue_sp_obj *o,
4513 enum bnx2x_queue_cmd cmd)
4514{
4515 unsigned long cur_pending = o->pending;
4516
4517 if (!test_and_clear_bit(cmd, &cur_pending)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00004518 BNX2X_ERR("Bad MC reply %d for queue %d in state %d pending 0x%lx, next_state %d\n",
4519 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX],
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004520 o->state, cur_pending, o->next_state);
4521 return -EINVAL;
4522 }
4523
Ariel Elior6383c0b2011-07-14 08:31:57 +00004524 if (o->next_tx_only >= o->max_cos)
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004525 /* >= because tx only must always be smaller than cos since the
Masanari Iida02582e92012-08-22 19:11:26 +09004526 * primary connection supports COS 0
Ariel Elior6383c0b2011-07-14 08:31:57 +00004527 */
4528 BNX2X_ERR("illegal value for next tx_only: %d. max cos was %d",
4529 o->next_tx_only, o->max_cos);
4530
Merav Sicron51c1a582012-03-18 10:33:38 +00004531 DP(BNX2X_MSG_SP,
4532 "Completing command %d for queue %d, setting state to %d\n",
4533 cmd, o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_state);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004534
4535 if (o->next_tx_only) /* print num tx-only if any exist */
Joe Perches94f05b02011-08-14 12:16:20 +00004536 DP(BNX2X_MSG_SP, "primary cid %d: num tx-only cons %d\n",
Merav Sicron51c1a582012-03-18 10:33:38 +00004537 o->cids[BNX2X_PRIMARY_CID_INDEX], o->next_tx_only);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004538
4539 o->state = o->next_state;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004540 o->num_tx_only = o->next_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004541 o->next_state = BNX2X_Q_STATE_MAX;
4542
4543 /* It's important that o->state and o->next_state are
4544 * updated before o->pending.
4545 */
4546 wmb();
4547
4548 clear_bit(cmd, &o->pending);
4549 smp_mb__after_clear_bit();
4550
4551 return 0;
4552}
4553
4554static void bnx2x_q_fill_setup_data_e2(struct bnx2x *bp,
4555 struct bnx2x_queue_state_params *cmd_params,
4556 struct client_init_ramrod_data *data)
4557{
4558 struct bnx2x_queue_setup_params *params = &cmd_params->params.setup;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004559
4560 /* Rx data */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004561
4562 /* IPv6 TPA supported for E2 and above only */
Vladislav Zolotarovf5219d82011-07-19 01:44:11 +00004563 data->rx.tpa_en |= test_bit(BNX2X_Q_FLG_TPA_IPV6, &params->flags) *
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004564 CLIENT_INIT_RX_DATA_TPA_EN_IPV6;
4565}
4566
Ariel Elior6383c0b2011-07-14 08:31:57 +00004567static void bnx2x_q_fill_init_general_data(struct bnx2x *bp,
4568 struct bnx2x_queue_sp_obj *o,
4569 struct bnx2x_general_setup_params *params,
4570 struct client_init_general_data *gen_data,
4571 unsigned long *flags)
4572{
4573 gen_data->client_id = o->cl_id;
4574
4575 if (test_bit(BNX2X_Q_FLG_STATS, flags)) {
4576 gen_data->statistics_counter_id =
4577 params->stat_id;
4578 gen_data->statistics_en_flg = 1;
4579 gen_data->statistics_zero_flg =
4580 test_bit(BNX2X_Q_FLG_ZERO_STATS, flags);
4581 } else
4582 gen_data->statistics_counter_id =
4583 DISABLE_STATISTIC_COUNTER_ID_VALUE;
4584
4585 gen_data->is_fcoe_flg = test_bit(BNX2X_Q_FLG_FCOE, flags);
4586 gen_data->activate_flg = test_bit(BNX2X_Q_FLG_ACTIVE, flags);
4587 gen_data->sp_client_id = params->spcl_id;
4588 gen_data->mtu = cpu_to_le16(params->mtu);
4589 gen_data->func_id = o->func_id;
4590
Ariel Elior6383c0b2011-07-14 08:31:57 +00004591 gen_data->cos = params->cos;
4592
4593 gen_data->traffic_type =
4594 test_bit(BNX2X_Q_FLG_FCOE, flags) ?
4595 LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
4596
Joe Perches94f05b02011-08-14 12:16:20 +00004597 DP(BNX2X_MSG_SP, "flags: active %d, cos %d, stats en %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004598 gen_data->activate_flg, gen_data->cos, gen_data->statistics_en_flg);
4599}
4600
4601static void bnx2x_q_fill_init_tx_data(struct bnx2x_queue_sp_obj *o,
4602 struct bnx2x_txq_setup_params *params,
4603 struct client_init_tx_data *tx_data,
4604 unsigned long *flags)
4605{
4606 tx_data->enforce_security_flg =
4607 test_bit(BNX2X_Q_FLG_TX_SEC, flags);
4608 tx_data->default_vlan =
4609 cpu_to_le16(params->default_vlan);
4610 tx_data->default_vlan_flg =
4611 test_bit(BNX2X_Q_FLG_DEF_VLAN, flags);
4612 tx_data->tx_switching_flg =
4613 test_bit(BNX2X_Q_FLG_TX_SWITCH, flags);
4614 tx_data->anti_spoofing_flg =
4615 test_bit(BNX2X_Q_FLG_ANTI_SPOOF, flags);
Barak Witkowskia3348722012-04-23 03:04:46 +00004616 tx_data->force_default_pri_flg =
4617 test_bit(BNX2X_Q_FLG_FORCE_DEFAULT_PRI, flags);
4618
Dmitry Kravkove287a752013-03-21 15:38:24 +00004619 tx_data->tunnel_lso_inc_ip_id =
4620 test_bit(BNX2X_Q_FLG_TUN_INC_INNER_IP_ID, flags);
Dmitry Kravkov91226792013-03-11 05:17:52 +00004621 tx_data->tunnel_non_lso_pcsum_location =
4622 test_bit(BNX2X_Q_FLG_PCSUM_ON_PKT, flags) ? PCSUM_ON_PKT :
4623 PCSUM_ON_BD;
4624
Ariel Elior6383c0b2011-07-14 08:31:57 +00004625 tx_data->tx_status_block_id = params->fw_sb_id;
4626 tx_data->tx_sb_index_number = params->sb_cq_index;
4627 tx_data->tss_leading_client_id = params->tss_leading_cl_id;
4628
4629 tx_data->tx_bd_page_base.lo =
4630 cpu_to_le32(U64_LO(params->dscr_map));
4631 tx_data->tx_bd_page_base.hi =
4632 cpu_to_le32(U64_HI(params->dscr_map));
4633
4634 /* Don't configure any Tx switching mode during queue SETUP */
4635 tx_data->state = 0;
4636}
4637
4638static void bnx2x_q_fill_init_pause_data(struct bnx2x_queue_sp_obj *o,
4639 struct rxq_pause_params *params,
4640 struct client_init_rx_data *rx_data)
4641{
4642 /* flow control data */
4643 rx_data->cqe_pause_thr_low = cpu_to_le16(params->rcq_th_lo);
4644 rx_data->cqe_pause_thr_high = cpu_to_le16(params->rcq_th_hi);
4645 rx_data->bd_pause_thr_low = cpu_to_le16(params->bd_th_lo);
4646 rx_data->bd_pause_thr_high = cpu_to_le16(params->bd_th_hi);
4647 rx_data->sge_pause_thr_low = cpu_to_le16(params->sge_th_lo);
4648 rx_data->sge_pause_thr_high = cpu_to_le16(params->sge_th_hi);
4649 rx_data->rx_cos_mask = cpu_to_le16(params->pri_map);
4650}
4651
4652static void bnx2x_q_fill_init_rx_data(struct bnx2x_queue_sp_obj *o,
4653 struct bnx2x_rxq_setup_params *params,
4654 struct client_init_rx_data *rx_data,
4655 unsigned long *flags)
4656{
Ariel Elior6383c0b2011-07-14 08:31:57 +00004657 rx_data->tpa_en = test_bit(BNX2X_Q_FLG_TPA, flags) *
4658 CLIENT_INIT_RX_DATA_TPA_EN_IPV4;
Dmitry Kravkov621b4d62012-02-20 09:59:08 +00004659 rx_data->tpa_en |= test_bit(BNX2X_Q_FLG_TPA_GRO, flags) *
4660 CLIENT_INIT_RX_DATA_TPA_MODE;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004661 rx_data->vmqueue_mode_en_flg = 0;
4662
4663 rx_data->cache_line_alignment_log_size =
4664 params->cache_line_log;
4665 rx_data->enable_dynamic_hc =
4666 test_bit(BNX2X_Q_FLG_DHC, flags);
4667 rx_data->max_sges_for_packet = params->max_sges_pkt;
4668 rx_data->client_qzone_id = params->cl_qzone_id;
4669 rx_data->max_agg_size = cpu_to_le16(params->tpa_agg_sz);
4670
4671 /* Always start in DROP_ALL mode */
4672 rx_data->state = cpu_to_le16(CLIENT_INIT_RX_DATA_UCAST_DROP_ALL |
4673 CLIENT_INIT_RX_DATA_MCAST_DROP_ALL);
4674
4675 /* We don't set drop flags */
4676 rx_data->drop_ip_cs_err_flg = 0;
4677 rx_data->drop_tcp_cs_err_flg = 0;
4678 rx_data->drop_ttl0_flg = 0;
4679 rx_data->drop_udp_cs_err_flg = 0;
4680 rx_data->inner_vlan_removal_enable_flg =
4681 test_bit(BNX2X_Q_FLG_VLAN, flags);
4682 rx_data->outer_vlan_removal_enable_flg =
4683 test_bit(BNX2X_Q_FLG_OV, flags);
4684 rx_data->status_block_id = params->fw_sb_id;
4685 rx_data->rx_sb_index_number = params->sb_cq_index;
4686 rx_data->max_tpa_queues = params->max_tpa_queues;
4687 rx_data->max_bytes_on_bd = cpu_to_le16(params->buf_sz);
4688 rx_data->sge_buff_size = cpu_to_le16(params->sge_buf_sz);
4689 rx_data->bd_page_base.lo =
4690 cpu_to_le32(U64_LO(params->dscr_map));
4691 rx_data->bd_page_base.hi =
4692 cpu_to_le32(U64_HI(params->dscr_map));
4693 rx_data->sge_page_base.lo =
4694 cpu_to_le32(U64_LO(params->sge_map));
4695 rx_data->sge_page_base.hi =
4696 cpu_to_le32(U64_HI(params->sge_map));
4697 rx_data->cqe_page_base.lo =
4698 cpu_to_le32(U64_LO(params->rcq_map));
4699 rx_data->cqe_page_base.hi =
4700 cpu_to_le32(U64_HI(params->rcq_map));
4701 rx_data->is_leading_rss = test_bit(BNX2X_Q_FLG_LEADING_RSS, flags);
4702
4703 if (test_bit(BNX2X_Q_FLG_MCAST, flags)) {
Yuval Mintz259afa12012-03-12 08:53:10 +00004704 rx_data->approx_mcast_engine_id = params->mcast_engine_id;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004705 rx_data->is_approx_mcast = 1;
4706 }
4707
4708 rx_data->rss_engine_id = params->rss_engine_id;
4709
4710 /* silent vlan removal */
4711 rx_data->silent_vlan_removal_flg =
4712 test_bit(BNX2X_Q_FLG_SILENT_VLAN_REM, flags);
4713 rx_data->silent_vlan_value =
4714 cpu_to_le16(params->silent_removal_value);
4715 rx_data->silent_vlan_mask =
4716 cpu_to_le16(params->silent_removal_mask);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004717}
4718
4719/* initialize the general, tx and rx parts of a queue object */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004720static void bnx2x_q_fill_setup_data_cmn(struct bnx2x *bp,
4721 struct bnx2x_queue_state_params *cmd_params,
4722 struct client_init_ramrod_data *data)
4723{
Ariel Elior6383c0b2011-07-14 08:31:57 +00004724 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4725 &cmd_params->params.setup.gen_params,
4726 &data->general,
4727 &cmd_params->params.setup.flags);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004728
Ariel Elior6383c0b2011-07-14 08:31:57 +00004729 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4730 &cmd_params->params.setup.txq_params,
4731 &data->tx,
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_rx_data(cmd_params->q_obj,
4735 &cmd_params->params.setup.rxq_params,
4736 &data->rx,
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_pause_data(cmd_params->q_obj,
4740 &cmd_params->params.setup.pause_params,
4741 &data->rx);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004742}
4743
Ariel Elior6383c0b2011-07-14 08:31:57 +00004744/* initialize the general and tx parts of a tx-only queue object */
4745static void bnx2x_q_fill_setup_tx_only(struct bnx2x *bp,
4746 struct bnx2x_queue_state_params *cmd_params,
4747 struct tx_queue_init_ramrod_data *data)
4748{
4749 bnx2x_q_fill_init_general_data(bp, cmd_params->q_obj,
4750 &cmd_params->params.tx_only.gen_params,
4751 &data->general,
4752 &cmd_params->params.tx_only.flags);
4753
4754 bnx2x_q_fill_init_tx_data(cmd_params->q_obj,
4755 &cmd_params->params.tx_only.txq_params,
4756 &data->tx,
4757 &cmd_params->params.tx_only.flags);
4758
Merav Sicron51c1a582012-03-18 10:33:38 +00004759 DP(BNX2X_MSG_SP, "cid %d, tx bd page lo %x hi %x",
4760 cmd_params->q_obj->cids[0],
4761 data->tx.tx_bd_page_base.lo,
4762 data->tx.tx_bd_page_base.hi);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004763}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004764
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004765/**
4766 * bnx2x_q_init - init HW/FW queue
4767 *
4768 * @bp: device handle
4769 * @params:
4770 *
4771 * HW/FW initial Queue configuration:
4772 * - HC: Rx and Tx
4773 * - CDU context validation
4774 *
4775 */
4776static inline int bnx2x_q_init(struct bnx2x *bp,
4777 struct bnx2x_queue_state_params *params)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004778{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004779 struct bnx2x_queue_sp_obj *o = params->q_obj;
4780 struct bnx2x_queue_init_params *init = &params->params.init;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004781 u16 hc_usec;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004782 u8 cos;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004783
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004784 /* Tx HC configuration */
4785 if (test_bit(BNX2X_Q_TYPE_HAS_TX, &o->type) &&
4786 test_bit(BNX2X_Q_FLG_HC, &init->tx.flags)) {
4787 hc_usec = init->tx.hc_rate ? 1000000 / init->tx.hc_rate : 0;
4788
4789 bnx2x_update_coalesce_sb_index(bp, init->tx.fw_sb_id,
4790 init->tx.sb_cq_index,
4791 !test_bit(BNX2X_Q_FLG_HC_EN, &init->tx.flags),
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004792 hc_usec);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004793 }
4794
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004795 /* Rx HC configuration */
4796 if (test_bit(BNX2X_Q_TYPE_HAS_RX, &o->type) &&
4797 test_bit(BNX2X_Q_FLG_HC, &init->rx.flags)) {
4798 hc_usec = init->rx.hc_rate ? 1000000 / init->rx.hc_rate : 0;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004799
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004800 bnx2x_update_coalesce_sb_index(bp, init->rx.fw_sb_id,
4801 init->rx.sb_cq_index,
4802 !test_bit(BNX2X_Q_FLG_HC_EN, &init->rx.flags),
4803 hc_usec);
4804 }
4805
4806 /* Set CDU context validation values */
Ariel Elior6383c0b2011-07-14 08:31:57 +00004807 for (cos = 0; cos < o->max_cos; cos++) {
Joe Perches94f05b02011-08-14 12:16:20 +00004808 DP(BNX2X_MSG_SP, "setting context validation. cid %d, cos %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004809 o->cids[cos], cos);
Joe Perches94f05b02011-08-14 12:16:20 +00004810 DP(BNX2X_MSG_SP, "context pointer %p\n", init->cxts[cos]);
Ariel Elior6383c0b2011-07-14 08:31:57 +00004811 bnx2x_set_ctx_validation(bp, init->cxts[cos], o->cids[cos]);
4812 }
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004813
4814 /* As no ramrod is sent, complete the command immediately */
4815 o->complete_cmd(bp, o, BNX2X_Q_CMD_INIT);
4816
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004817 mmiowb();
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004818 smp_mb();
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004819
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004820 return 0;
4821}
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004822
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004823static inline int bnx2x_q_send_setup_e1x(struct bnx2x *bp,
4824 struct bnx2x_queue_state_params *params)
4825{
4826 struct bnx2x_queue_sp_obj *o = params->q_obj;
4827 struct client_init_ramrod_data *rdata =
4828 (struct client_init_ramrod_data *)o->rdata;
4829 dma_addr_t data_mapping = o->rdata_mapping;
4830 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00004831
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004832 /* Clear the ramrod data */
4833 memset(rdata, 0, sizeof(*rdata));
4834
4835 /* Fill the ramrod data */
4836 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4837
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004838 /* No need for an explicit memory barrier here as long we would
4839 * need to ensure the ordering of writing to the SPQ element
4840 * and updating of the SPQ producer which involves a memory
4841 * read and we will have to put a full memory barrier there
4842 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004843 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004844
Ariel Elior6383c0b2011-07-14 08:31:57 +00004845 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4846 U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004847 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4848}
4849
4850static inline int bnx2x_q_send_setup_e2(struct bnx2x *bp,
4851 struct bnx2x_queue_state_params *params)
4852{
4853 struct bnx2x_queue_sp_obj *o = params->q_obj;
4854 struct client_init_ramrod_data *rdata =
4855 (struct client_init_ramrod_data *)o->rdata;
4856 dma_addr_t data_mapping = o->rdata_mapping;
4857 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
4858
4859 /* Clear the ramrod data */
4860 memset(rdata, 0, sizeof(*rdata));
4861
4862 /* Fill the ramrod data */
4863 bnx2x_q_fill_setup_data_cmn(bp, params, rdata);
4864 bnx2x_q_fill_setup_data_e2(bp, params, rdata);
4865
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004866 /* No need for an explicit memory barrier here as long we would
4867 * need to ensure the ordering of writing to the SPQ element
4868 * and updating of the SPQ producer which involves a memory
4869 * read and we will have to put a full memory barrier there
4870 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00004871 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004872
Ariel Elior6383c0b2011-07-14 08:31:57 +00004873 return bnx2x_sp_post(bp, ramrod, o->cids[BNX2X_PRIMARY_CID_INDEX],
4874 U64_HI(data_mapping),
4875 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4876}
4877
4878static inline int bnx2x_q_send_setup_tx_only(struct bnx2x *bp,
4879 struct bnx2x_queue_state_params *params)
4880{
4881 struct bnx2x_queue_sp_obj *o = params->q_obj;
4882 struct tx_queue_init_ramrod_data *rdata =
4883 (struct tx_queue_init_ramrod_data *)o->rdata;
4884 dma_addr_t data_mapping = o->rdata_mapping;
4885 int ramrod = RAMROD_CMD_ID_ETH_TX_QUEUE_SETUP;
4886 struct bnx2x_queue_setup_tx_only_params *tx_only_params =
4887 &params->params.tx_only;
4888 u8 cid_index = tx_only_params->cid_index;
4889
Ariel Elior6383c0b2011-07-14 08:31:57 +00004890 if (cid_index >= o->max_cos) {
4891 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4892 o->cl_id, cid_index);
4893 return -EINVAL;
4894 }
4895
Joe Perches94f05b02011-08-14 12:16:20 +00004896 DP(BNX2X_MSG_SP, "parameters received: cos: %d sp-id: %d\n",
Ariel Elior6383c0b2011-07-14 08:31:57 +00004897 tx_only_params->gen_params.cos,
4898 tx_only_params->gen_params.spcl_id);
4899
4900 /* Clear the ramrod data */
4901 memset(rdata, 0, sizeof(*rdata));
4902
4903 /* Fill the ramrod data */
4904 bnx2x_q_fill_setup_tx_only(bp, params, rdata);
4905
Merav Sicron51c1a582012-03-18 10:33:38 +00004906 DP(BNX2X_MSG_SP, "sending tx-only ramrod: cid %d, client-id %d, sp-client id %d, cos %d\n",
4907 o->cids[cid_index], rdata->general.client_id,
Ariel Elior6383c0b2011-07-14 08:31:57 +00004908 rdata->general.sp_client_id, rdata->general.cos);
4909
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004910 /* No need for an explicit memory barrier here as long we would
4911 * need to ensure the ordering of writing to the SPQ element
4912 * and updating of the SPQ producer which involves a memory
4913 * read and we will have to put a full memory barrier there
4914 * (inside bnx2x_sp_post()).
Ariel Elior6383c0b2011-07-14 08:31:57 +00004915 */
4916
4917 return bnx2x_sp_post(bp, ramrod, o->cids[cid_index],
4918 U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004919 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
4920}
4921
4922static void bnx2x_q_fill_update_data(struct bnx2x *bp,
4923 struct bnx2x_queue_sp_obj *obj,
4924 struct bnx2x_queue_update_params *params,
4925 struct client_update_ramrod_data *data)
4926{
4927 /* Client ID of the client to update */
4928 data->client_id = obj->cl_id;
4929
4930 /* Function ID of the client to update */
4931 data->func_id = obj->func_id;
4932
4933 /* Default VLAN value */
4934 data->default_vlan = cpu_to_le16(params->def_vlan);
4935
4936 /* Inner VLAN stripping */
4937 data->inner_vlan_removal_enable_flg =
4938 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM, &params->update_flags);
4939 data->inner_vlan_removal_change_flg =
4940 test_bit(BNX2X_Q_UPDATE_IN_VLAN_REM_CHNG,
4941 &params->update_flags);
4942
Yuval Mintz16a5fd92013-06-02 00:06:18 +00004943 /* Outer VLAN stripping */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004944 data->outer_vlan_removal_enable_flg =
4945 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM, &params->update_flags);
4946 data->outer_vlan_removal_change_flg =
4947 test_bit(BNX2X_Q_UPDATE_OUT_VLAN_REM_CHNG,
4948 &params->update_flags);
4949
4950 /* Drop packets that have source MAC that doesn't belong to this
4951 * Queue.
4952 */
4953 data->anti_spoofing_enable_flg =
4954 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF, &params->update_flags);
4955 data->anti_spoofing_change_flg =
4956 test_bit(BNX2X_Q_UPDATE_ANTI_SPOOF_CHNG, &params->update_flags);
4957
4958 /* Activate/Deactivate */
4959 data->activate_flg =
4960 test_bit(BNX2X_Q_UPDATE_ACTIVATE, &params->update_flags);
4961 data->activate_change_flg =
4962 test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &params->update_flags);
4963
4964 /* Enable default VLAN */
4965 data->default_vlan_enable_flg =
4966 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN, &params->update_flags);
4967 data->default_vlan_change_flg =
4968 test_bit(BNX2X_Q_UPDATE_DEF_VLAN_EN_CHNG,
4969 &params->update_flags);
4970
4971 /* silent vlan removal */
4972 data->silent_vlan_change_flg =
4973 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM_CHNG,
4974 &params->update_flags);
4975 data->silent_vlan_removal_flg =
4976 test_bit(BNX2X_Q_UPDATE_SILENT_VLAN_REM, &params->update_flags);
4977 data->silent_vlan_value = cpu_to_le16(params->silent_removal_value);
4978 data->silent_vlan_mask = cpu_to_le16(params->silent_removal_mask);
4979}
4980
4981static inline int bnx2x_q_send_update(struct bnx2x *bp,
4982 struct bnx2x_queue_state_params *params)
4983{
4984 struct bnx2x_queue_sp_obj *o = params->q_obj;
4985 struct client_update_ramrod_data *rdata =
4986 (struct client_update_ramrod_data *)o->rdata;
4987 dma_addr_t data_mapping = o->rdata_mapping;
Ariel Elior6383c0b2011-07-14 08:31:57 +00004988 struct bnx2x_queue_update_params *update_params =
4989 &params->params.update;
4990 u8 cid_index = update_params->cid_index;
4991
4992 if (cid_index >= o->max_cos) {
4993 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
4994 o->cl_id, cid_index);
4995 return -EINVAL;
4996 }
4997
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03004998 /* Clear the ramrod data */
4999 memset(rdata, 0, sizeof(*rdata));
5000
5001 /* Fill the ramrod data */
Ariel Elior6383c0b2011-07-14 08:31:57 +00005002 bnx2x_q_fill_update_data(bp, o, update_params, rdata);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005003
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005004 /* No need for an explicit memory barrier here as long we would
5005 * need to ensure the ordering of writing to the SPQ element
5006 * and updating of the SPQ producer which involves a memory
5007 * read and we will have to put a full memory barrier there
5008 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00005009 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005010
Ariel Elior6383c0b2011-07-14 08:31:57 +00005011 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_CLIENT_UPDATE,
5012 o->cids[cid_index], U64_HI(data_mapping),
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005013 U64_LO(data_mapping), ETH_CONNECTION_TYPE);
5014}
5015
5016/**
5017 * bnx2x_q_send_deactivate - send DEACTIVATE command
5018 *
5019 * @bp: device handle
5020 * @params:
5021 *
5022 * implemented using the UPDATE command.
5023 */
5024static inline int bnx2x_q_send_deactivate(struct bnx2x *bp,
5025 struct bnx2x_queue_state_params *params)
5026{
5027 struct bnx2x_queue_update_params *update = &params->params.update;
5028
5029 memset(update, 0, sizeof(*update));
5030
5031 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
5032
5033 return bnx2x_q_send_update(bp, params);
5034}
5035
5036/**
5037 * bnx2x_q_send_activate - send ACTIVATE command
5038 *
5039 * @bp: device handle
5040 * @params:
5041 *
5042 * implemented using the UPDATE command.
5043 */
5044static inline int bnx2x_q_send_activate(struct bnx2x *bp,
5045 struct bnx2x_queue_state_params *params)
5046{
5047 struct bnx2x_queue_update_params *update = &params->params.update;
5048
5049 memset(update, 0, sizeof(*update));
5050
5051 __set_bit(BNX2X_Q_UPDATE_ACTIVATE, &update->update_flags);
5052 __set_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG, &update->update_flags);
5053
5054 return bnx2x_q_send_update(bp, params);
5055}
5056
5057static inline int bnx2x_q_send_update_tpa(struct bnx2x *bp,
5058 struct bnx2x_queue_state_params *params)
5059{
5060 /* TODO: Not implemented yet. */
5061 return -1;
5062}
5063
5064static inline int bnx2x_q_send_halt(struct bnx2x *bp,
5065 struct bnx2x_queue_state_params *params)
5066{
5067 struct bnx2x_queue_sp_obj *o = params->q_obj;
5068
Ariel Elior6383c0b2011-07-14 08:31:57 +00005069 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_HALT,
5070 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, o->cl_id,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005071 ETH_CONNECTION_TYPE);
5072}
5073
5074static inline int bnx2x_q_send_cfc_del(struct bnx2x *bp,
5075 struct bnx2x_queue_state_params *params)
5076{
5077 struct bnx2x_queue_sp_obj *o = params->q_obj;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005078 u8 cid_idx = params->params.cfc_del.cid_index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005079
Ariel Elior6383c0b2011-07-14 08:31:57 +00005080 if (cid_idx >= o->max_cos) {
5081 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
5082 o->cl_id, cid_idx);
5083 return -EINVAL;
5084 }
5085
5086 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_CFC_DEL,
5087 o->cids[cid_idx], 0, 0, NONE_CONNECTION_TYPE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005088}
5089
5090static inline int bnx2x_q_send_terminate(struct bnx2x *bp,
5091 struct bnx2x_queue_state_params *params)
5092{
5093 struct bnx2x_queue_sp_obj *o = params->q_obj;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005094 u8 cid_index = params->params.terminate.cid_index;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005095
Ariel Elior6383c0b2011-07-14 08:31:57 +00005096 if (cid_index >= o->max_cos) {
5097 BNX2X_ERR("queue[%d]: cid_index (%d) is out of range\n",
5098 o->cl_id, cid_index);
5099 return -EINVAL;
5100 }
5101
5102 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_TERMINATE,
5103 o->cids[cid_index], 0, 0, ETH_CONNECTION_TYPE);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005104}
5105
5106static inline int bnx2x_q_send_empty(struct bnx2x *bp,
5107 struct bnx2x_queue_state_params *params)
5108{
5109 struct bnx2x_queue_sp_obj *o = params->q_obj;
5110
Ariel Elior6383c0b2011-07-14 08:31:57 +00005111 return bnx2x_sp_post(bp, RAMROD_CMD_ID_ETH_EMPTY,
5112 o->cids[BNX2X_PRIMARY_CID_INDEX], 0, 0,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005113 ETH_CONNECTION_TYPE);
5114}
5115
5116static inline int bnx2x_queue_send_cmd_cmn(struct bnx2x *bp,
5117 struct bnx2x_queue_state_params *params)
5118{
5119 switch (params->cmd) {
5120 case BNX2X_Q_CMD_INIT:
5121 return bnx2x_q_init(bp, params);
Ariel Elior6383c0b2011-07-14 08:31:57 +00005122 case BNX2X_Q_CMD_SETUP_TX_ONLY:
5123 return bnx2x_q_send_setup_tx_only(bp, params);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005124 case BNX2X_Q_CMD_DEACTIVATE:
5125 return bnx2x_q_send_deactivate(bp, params);
5126 case BNX2X_Q_CMD_ACTIVATE:
5127 return bnx2x_q_send_activate(bp, params);
5128 case BNX2X_Q_CMD_UPDATE:
5129 return bnx2x_q_send_update(bp, params);
5130 case BNX2X_Q_CMD_UPDATE_TPA:
5131 return bnx2x_q_send_update_tpa(bp, params);
5132 case BNX2X_Q_CMD_HALT:
5133 return bnx2x_q_send_halt(bp, params);
5134 case BNX2X_Q_CMD_CFC_DEL:
5135 return bnx2x_q_send_cfc_del(bp, params);
5136 case BNX2X_Q_CMD_TERMINATE:
5137 return bnx2x_q_send_terminate(bp, params);
5138 case BNX2X_Q_CMD_EMPTY:
5139 return bnx2x_q_send_empty(bp, params);
5140 default:
5141 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5142 return -EINVAL;
5143 }
5144}
5145
5146static int bnx2x_queue_send_cmd_e1x(struct bnx2x *bp,
5147 struct bnx2x_queue_state_params *params)
5148{
5149 switch (params->cmd) {
5150 case BNX2X_Q_CMD_SETUP:
5151 return bnx2x_q_send_setup_e1x(bp, params);
5152 case BNX2X_Q_CMD_INIT:
Ariel Elior6383c0b2011-07-14 08:31:57 +00005153 case BNX2X_Q_CMD_SETUP_TX_ONLY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005154 case BNX2X_Q_CMD_DEACTIVATE:
5155 case BNX2X_Q_CMD_ACTIVATE:
5156 case BNX2X_Q_CMD_UPDATE:
5157 case BNX2X_Q_CMD_UPDATE_TPA:
5158 case BNX2X_Q_CMD_HALT:
5159 case BNX2X_Q_CMD_CFC_DEL:
5160 case BNX2X_Q_CMD_TERMINATE:
5161 case BNX2X_Q_CMD_EMPTY:
5162 return bnx2x_queue_send_cmd_cmn(bp, params);
5163 default:
5164 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5165 return -EINVAL;
5166 }
5167}
5168
5169static int bnx2x_queue_send_cmd_e2(struct bnx2x *bp,
5170 struct bnx2x_queue_state_params *params)
5171{
5172 switch (params->cmd) {
5173 case BNX2X_Q_CMD_SETUP:
5174 return bnx2x_q_send_setup_e2(bp, params);
5175 case BNX2X_Q_CMD_INIT:
Ariel Elior6383c0b2011-07-14 08:31:57 +00005176 case BNX2X_Q_CMD_SETUP_TX_ONLY:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005177 case BNX2X_Q_CMD_DEACTIVATE:
5178 case BNX2X_Q_CMD_ACTIVATE:
5179 case BNX2X_Q_CMD_UPDATE:
5180 case BNX2X_Q_CMD_UPDATE_TPA:
5181 case BNX2X_Q_CMD_HALT:
5182 case BNX2X_Q_CMD_CFC_DEL:
5183 case BNX2X_Q_CMD_TERMINATE:
5184 case BNX2X_Q_CMD_EMPTY:
5185 return bnx2x_queue_send_cmd_cmn(bp, params);
5186 default:
5187 BNX2X_ERR("Unknown command: %d\n", params->cmd);
5188 return -EINVAL;
5189 }
5190}
5191
5192/**
5193 * bnx2x_queue_chk_transition - check state machine of a regular Queue
5194 *
5195 * @bp: device handle
5196 * @o:
5197 * @params:
5198 *
5199 * (not Forwarding)
5200 * It both checks if the requested command is legal in a current
5201 * state and, if it's legal, sets a `next_state' in the object
5202 * that will be used in the completion flow to set the `state'
5203 * of the object.
5204 *
5205 * returns 0 if a requested command is a legal transition,
5206 * -EINVAL otherwise.
5207 */
5208static int bnx2x_queue_chk_transition(struct bnx2x *bp,
5209 struct bnx2x_queue_sp_obj *o,
5210 struct bnx2x_queue_state_params *params)
5211{
5212 enum bnx2x_q_state state = o->state, next_state = BNX2X_Q_STATE_MAX;
5213 enum bnx2x_queue_cmd cmd = params->cmd;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005214 struct bnx2x_queue_update_params *update_params =
5215 &params->params.update;
5216 u8 next_tx_only = o->num_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005217
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005218 /* Forget all pending for completion commands if a driver only state
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005219 * transition has been requested.
5220 */
5221 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5222 o->pending = 0;
5223 o->next_state = BNX2X_Q_STATE_MAX;
5224 }
5225
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005226 /* Don't allow a next state transition if we are in the middle of
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005227 * the previous one.
5228 */
Yuval Mintz04c46732013-01-23 03:21:46 +00005229 if (o->pending) {
5230 BNX2X_ERR("Blocking transition since pending was %lx\n",
5231 o->pending);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005232 return -EBUSY;
Yuval Mintz04c46732013-01-23 03:21:46 +00005233 }
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005234
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005235 switch (state) {
5236 case BNX2X_Q_STATE_RESET:
5237 if (cmd == BNX2X_Q_CMD_INIT)
5238 next_state = BNX2X_Q_STATE_INITIALIZED;
5239
5240 break;
5241 case BNX2X_Q_STATE_INITIALIZED:
5242 if (cmd == BNX2X_Q_CMD_SETUP) {
5243 if (test_bit(BNX2X_Q_FLG_ACTIVE,
5244 &params->params.setup.flags))
5245 next_state = BNX2X_Q_STATE_ACTIVE;
5246 else
5247 next_state = BNX2X_Q_STATE_INACTIVE;
5248 }
5249
5250 break;
5251 case BNX2X_Q_STATE_ACTIVE:
5252 if (cmd == BNX2X_Q_CMD_DEACTIVATE)
5253 next_state = BNX2X_Q_STATE_INACTIVE;
5254
5255 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5256 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5257 next_state = BNX2X_Q_STATE_ACTIVE;
5258
Ariel Elior6383c0b2011-07-14 08:31:57 +00005259 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5260 next_state = BNX2X_Q_STATE_MULTI_COS;
5261 next_tx_only = 1;
5262 }
5263
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005264 else if (cmd == BNX2X_Q_CMD_HALT)
5265 next_state = BNX2X_Q_STATE_STOPPED;
5266
5267 else if (cmd == BNX2X_Q_CMD_UPDATE) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005268 /* If "active" state change is requested, update the
5269 * state accordingly.
5270 */
5271 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5272 &update_params->update_flags) &&
5273 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5274 &update_params->update_flags))
5275 next_state = BNX2X_Q_STATE_INACTIVE;
5276 else
5277 next_state = BNX2X_Q_STATE_ACTIVE;
5278 }
5279
5280 break;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005281 case BNX2X_Q_STATE_MULTI_COS:
5282 if (cmd == BNX2X_Q_CMD_TERMINATE)
5283 next_state = BNX2X_Q_STATE_MCOS_TERMINATED;
5284
5285 else if (cmd == BNX2X_Q_CMD_SETUP_TX_ONLY) {
5286 next_state = BNX2X_Q_STATE_MULTI_COS;
5287 next_tx_only = o->num_tx_only + 1;
5288 }
5289
5290 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5291 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5292 next_state = BNX2X_Q_STATE_MULTI_COS;
5293
5294 else if (cmd == BNX2X_Q_CMD_UPDATE) {
5295 /* If "active" state change is requested, update the
5296 * state accordingly.
5297 */
5298 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5299 &update_params->update_flags) &&
5300 !test_bit(BNX2X_Q_UPDATE_ACTIVATE,
5301 &update_params->update_flags))
5302 next_state = BNX2X_Q_STATE_INACTIVE;
5303 else
5304 next_state = BNX2X_Q_STATE_MULTI_COS;
5305 }
5306
5307 break;
5308 case BNX2X_Q_STATE_MCOS_TERMINATED:
5309 if (cmd == BNX2X_Q_CMD_CFC_DEL) {
5310 next_tx_only = o->num_tx_only - 1;
5311 if (next_tx_only == 0)
5312 next_state = BNX2X_Q_STATE_ACTIVE;
5313 else
5314 next_state = BNX2X_Q_STATE_MULTI_COS;
5315 }
5316
5317 break;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005318 case BNX2X_Q_STATE_INACTIVE:
5319 if (cmd == BNX2X_Q_CMD_ACTIVATE)
5320 next_state = BNX2X_Q_STATE_ACTIVE;
5321
5322 else if ((cmd == BNX2X_Q_CMD_EMPTY) ||
5323 (cmd == BNX2X_Q_CMD_UPDATE_TPA))
5324 next_state = BNX2X_Q_STATE_INACTIVE;
5325
5326 else if (cmd == BNX2X_Q_CMD_HALT)
5327 next_state = BNX2X_Q_STATE_STOPPED;
5328
5329 else if (cmd == BNX2X_Q_CMD_UPDATE) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005330 /* If "active" state change is requested, update the
5331 * state accordingly.
5332 */
5333 if (test_bit(BNX2X_Q_UPDATE_ACTIVATE_CHNG,
5334 &update_params->update_flags) &&
5335 test_bit(BNX2X_Q_UPDATE_ACTIVATE,
Ariel Elior6383c0b2011-07-14 08:31:57 +00005336 &update_params->update_flags)){
5337 if (o->num_tx_only == 0)
5338 next_state = BNX2X_Q_STATE_ACTIVE;
5339 else /* tx only queues exist for this queue */
5340 next_state = BNX2X_Q_STATE_MULTI_COS;
5341 } else
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005342 next_state = BNX2X_Q_STATE_INACTIVE;
5343 }
5344
5345 break;
5346 case BNX2X_Q_STATE_STOPPED:
5347 if (cmd == BNX2X_Q_CMD_TERMINATE)
5348 next_state = BNX2X_Q_STATE_TERMINATED;
5349
5350 break;
5351 case BNX2X_Q_STATE_TERMINATED:
5352 if (cmd == BNX2X_Q_CMD_CFC_DEL)
5353 next_state = BNX2X_Q_STATE_RESET;
5354
5355 break;
5356 default:
5357 BNX2X_ERR("Illegal state: %d\n", state);
5358 }
5359
5360 /* Transition is assured */
5361 if (next_state != BNX2X_Q_STATE_MAX) {
5362 DP(BNX2X_MSG_SP, "Good state transition: %d(%d)->%d\n",
5363 state, cmd, next_state);
5364 o->next_state = next_state;
Ariel Elior6383c0b2011-07-14 08:31:57 +00005365 o->next_tx_only = next_tx_only;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005366 return 0;
5367 }
5368
5369 DP(BNX2X_MSG_SP, "Bad state transition request: %d %d\n", state, cmd);
5370
5371 return -EINVAL;
5372}
5373
5374void bnx2x_init_queue_obj(struct bnx2x *bp,
5375 struct bnx2x_queue_sp_obj *obj,
Ariel Elior6383c0b2011-07-14 08:31:57 +00005376 u8 cl_id, u32 *cids, u8 cid_cnt, u8 func_id,
5377 void *rdata,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005378 dma_addr_t rdata_mapping, unsigned long type)
5379{
5380 memset(obj, 0, sizeof(*obj));
5381
Ariel Elior6383c0b2011-07-14 08:31:57 +00005382 /* We support only BNX2X_MULTI_TX_COS Tx CoS at the moment */
5383 BUG_ON(BNX2X_MULTI_TX_COS < cid_cnt);
5384
5385 memcpy(obj->cids, cids, sizeof(obj->cids[0]) * cid_cnt);
5386 obj->max_cos = cid_cnt;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005387 obj->cl_id = cl_id;
5388 obj->func_id = func_id;
5389 obj->rdata = rdata;
5390 obj->rdata_mapping = rdata_mapping;
5391 obj->type = type;
5392 obj->next_state = BNX2X_Q_STATE_MAX;
5393
5394 if (CHIP_IS_E1x(bp))
5395 obj->send_cmd = bnx2x_queue_send_cmd_e1x;
5396 else
5397 obj->send_cmd = bnx2x_queue_send_cmd_e2;
5398
5399 obj->check_transition = bnx2x_queue_chk_transition;
5400
5401 obj->complete_cmd = bnx2x_queue_comp_cmd;
5402 obj->wait_comp = bnx2x_queue_wait_comp;
5403 obj->set_pending = bnx2x_queue_set_pending;
5404}
5405
Ariel Elior67c431a2013-01-01 05:22:36 +00005406/* return a queue object's logical state*/
5407int bnx2x_get_q_logical_state(struct bnx2x *bp,
5408 struct bnx2x_queue_sp_obj *obj)
5409{
5410 switch (obj->state) {
5411 case BNX2X_Q_STATE_ACTIVE:
5412 case BNX2X_Q_STATE_MULTI_COS:
5413 return BNX2X_Q_LOGICAL_STATE_ACTIVE;
5414 case BNX2X_Q_STATE_RESET:
5415 case BNX2X_Q_STATE_INITIALIZED:
5416 case BNX2X_Q_STATE_MCOS_TERMINATED:
5417 case BNX2X_Q_STATE_INACTIVE:
5418 case BNX2X_Q_STATE_STOPPED:
5419 case BNX2X_Q_STATE_TERMINATED:
5420 case BNX2X_Q_STATE_FLRED:
5421 return BNX2X_Q_LOGICAL_STATE_STOPPED;
5422 default:
5423 return -EINVAL;
5424 }
5425}
5426
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005427/********************** Function state object *********************************/
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005428enum bnx2x_func_state bnx2x_func_get_state(struct bnx2x *bp,
5429 struct bnx2x_func_sp_obj *o)
5430{
5431 /* in the middle of transaction - return INVALID state */
5432 if (o->pending)
5433 return BNX2X_F_STATE_MAX;
5434
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005435 /* unsure the order of reading of o->pending and o->state
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005436 * o->pending should be read first
5437 */
5438 rmb();
5439
5440 return o->state;
5441}
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005442
5443static int bnx2x_func_wait_comp(struct bnx2x *bp,
5444 struct bnx2x_func_sp_obj *o,
5445 enum bnx2x_func_cmd cmd)
5446{
5447 return bnx2x_state_wait(bp, cmd, &o->pending);
5448}
5449
5450/**
5451 * bnx2x_func_state_change_comp - complete the state machine transition
5452 *
5453 * @bp: device handle
5454 * @o:
5455 * @cmd:
5456 *
5457 * Called on state change transition. Completes the state
5458 * machine transition only - no HW interaction.
5459 */
5460static inline int bnx2x_func_state_change_comp(struct bnx2x *bp,
5461 struct bnx2x_func_sp_obj *o,
5462 enum bnx2x_func_cmd cmd)
5463{
5464 unsigned long cur_pending = o->pending;
5465
5466 if (!test_and_clear_bit(cmd, &cur_pending)) {
Merav Sicron51c1a582012-03-18 10:33:38 +00005467 BNX2X_ERR("Bad MC reply %d for func %d in state %d pending 0x%lx, next_state %d\n",
5468 cmd, BP_FUNC(bp), o->state,
5469 cur_pending, o->next_state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005470 return -EINVAL;
5471 }
5472
Joe Perches94f05b02011-08-14 12:16:20 +00005473 DP(BNX2X_MSG_SP,
5474 "Completing command %d for func %d, setting state to %d\n",
5475 cmd, BP_FUNC(bp), o->next_state);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005476
5477 o->state = o->next_state;
5478 o->next_state = BNX2X_F_STATE_MAX;
5479
5480 /* It's important that o->state and o->next_state are
5481 * updated before o->pending.
5482 */
5483 wmb();
5484
5485 clear_bit(cmd, &o->pending);
5486 smp_mb__after_clear_bit();
5487
5488 return 0;
5489}
5490
5491/**
5492 * bnx2x_func_comp_cmd - complete the state change command
5493 *
5494 * @bp: device handle
5495 * @o:
5496 * @cmd:
5497 *
5498 * Checks that the arrived completion is expected.
5499 */
5500static int bnx2x_func_comp_cmd(struct bnx2x *bp,
5501 struct bnx2x_func_sp_obj *o,
5502 enum bnx2x_func_cmd cmd)
5503{
5504 /* Complete the state machine part first, check if it's a
5505 * legal completion.
5506 */
5507 int rc = bnx2x_func_state_change_comp(bp, o, cmd);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005508 return rc;
5509}
5510
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005511/**
5512 * bnx2x_func_chk_transition - perform function state machine transition
5513 *
5514 * @bp: device handle
5515 * @o:
5516 * @params:
5517 *
5518 * It both checks if the requested command is legal in a current
5519 * state and, if it's legal, sets a `next_state' in the object
5520 * that will be used in the completion flow to set the `state'
5521 * of the object.
5522 *
5523 * returns 0 if a requested command is a legal transition,
5524 * -EINVAL otherwise.
5525 */
5526static int bnx2x_func_chk_transition(struct bnx2x *bp,
5527 struct bnx2x_func_sp_obj *o,
5528 struct bnx2x_func_state_params *params)
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005529{
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005530 enum bnx2x_func_state state = o->state, next_state = BNX2X_F_STATE_MAX;
5531 enum bnx2x_func_cmd cmd = params->cmd;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005532
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005533 /* Forget all pending for completion commands if a driver only state
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005534 * transition has been requested.
5535 */
5536 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
5537 o->pending = 0;
5538 o->next_state = BNX2X_F_STATE_MAX;
5539 }
5540
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005541 /* Don't allow a next state transition if we are in the middle of
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005542 * the previous one.
5543 */
5544 if (o->pending)
5545 return -EBUSY;
5546
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005547 switch (state) {
5548 case BNX2X_F_STATE_RESET:
5549 if (cmd == BNX2X_F_CMD_HW_INIT)
5550 next_state = BNX2X_F_STATE_INITIALIZED;
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00005551
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005552 break;
5553 case BNX2X_F_STATE_INITIALIZED:
5554 if (cmd == BNX2X_F_CMD_START)
5555 next_state = BNX2X_F_STATE_STARTED;
5556
5557 else if (cmd == BNX2X_F_CMD_HW_RESET)
5558 next_state = BNX2X_F_STATE_RESET;
5559
5560 break;
5561 case BNX2X_F_STATE_STARTED:
5562 if (cmd == BNX2X_F_CMD_STOP)
5563 next_state = BNX2X_F_STATE_INITIALIZED;
Barak Witkowskia3348722012-04-23 03:04:46 +00005564 /* afex ramrods can be sent only in started mode, and only
5565 * if not pending for function_stop ramrod completion
5566 * for these events - next state remained STARTED.
5567 */
5568 else if ((cmd == BNX2X_F_CMD_AFEX_UPDATE) &&
5569 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5570 next_state = BNX2X_F_STATE_STARTED;
5571
5572 else if ((cmd == BNX2X_F_CMD_AFEX_VIFLISTS) &&
5573 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5574 next_state = BNX2X_F_STATE_STARTED;
Merav Sicron55c11942012-11-07 00:45:48 +00005575
5576 /* Switch_update ramrod can be sent in either started or
5577 * tx_stopped state, and it doesn't change the state.
5578 */
5579 else if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5580 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5581 next_state = BNX2X_F_STATE_STARTED;
5582
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005583 else if (cmd == BNX2X_F_CMD_TX_STOP)
5584 next_state = BNX2X_F_STATE_TX_STOPPED;
5585
5586 break;
5587 case BNX2X_F_STATE_TX_STOPPED:
Merav Sicron55c11942012-11-07 00:45:48 +00005588 if ((cmd == BNX2X_F_CMD_SWITCH_UPDATE) &&
5589 (!test_bit(BNX2X_F_CMD_STOP, &o->pending)))
5590 next_state = BNX2X_F_STATE_TX_STOPPED;
5591
5592 else if (cmd == BNX2X_F_CMD_TX_START)
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005593 next_state = BNX2X_F_STATE_STARTED;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005594
5595 break;
5596 default:
5597 BNX2X_ERR("Unknown state: %d\n", state);
5598 }
5599
5600 /* Transition is assured */
5601 if (next_state != BNX2X_F_STATE_MAX) {
5602 DP(BNX2X_MSG_SP, "Good function state transition: %d(%d)->%d\n",
5603 state, cmd, next_state);
5604 o->next_state = next_state;
5605 return 0;
5606 }
5607
5608 DP(BNX2X_MSG_SP, "Bad function state transition request: %d %d\n",
5609 state, cmd);
5610
5611 return -EINVAL;
5612}
5613
5614/**
5615 * bnx2x_func_init_func - performs HW init at function stage
5616 *
5617 * @bp: device handle
5618 * @drv:
5619 *
5620 * Init HW when the current phase is
5621 * FW_MSG_CODE_DRV_LOAD_FUNCTION: initialize only FUNCTION-only
5622 * HW blocks.
5623 */
5624static inline int bnx2x_func_init_func(struct bnx2x *bp,
5625 const struct bnx2x_func_sp_drv_ops *drv)
5626{
5627 return drv->init_hw_func(bp);
5628}
5629
5630/**
5631 * bnx2x_func_init_port - performs HW init at port stage
5632 *
5633 * @bp: device handle
5634 * @drv:
5635 *
5636 * Init HW when the current phase is
5637 * FW_MSG_CODE_DRV_LOAD_PORT: initialize PORT-only and
5638 * FUNCTION-only HW blocks.
5639 *
5640 */
5641static inline int bnx2x_func_init_port(struct bnx2x *bp,
5642 const struct bnx2x_func_sp_drv_ops *drv)
5643{
5644 int rc = drv->init_hw_port(bp);
5645 if (rc)
5646 return rc;
5647
5648 return bnx2x_func_init_func(bp, drv);
5649}
5650
5651/**
5652 * bnx2x_func_init_cmn_chip - performs HW init at chip-common stage
5653 *
5654 * @bp: device handle
5655 * @drv:
5656 *
5657 * Init HW when the current phase is
5658 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON_CHIP,
5659 * PORT-only and FUNCTION-only HW blocks.
5660 */
5661static inline int bnx2x_func_init_cmn_chip(struct bnx2x *bp,
5662 const struct bnx2x_func_sp_drv_ops *drv)
5663{
5664 int rc = drv->init_hw_cmn_chip(bp);
5665 if (rc)
5666 return rc;
5667
5668 return bnx2x_func_init_port(bp, drv);
5669}
5670
5671/**
5672 * bnx2x_func_init_cmn - performs HW init at common stage
5673 *
5674 * @bp: device handle
5675 * @drv:
5676 *
5677 * Init HW when the current phase is
5678 * FW_MSG_CODE_DRV_LOAD_COMMON_CHIP: initialize COMMON,
5679 * PORT-only and FUNCTION-only HW blocks.
5680 */
5681static inline int bnx2x_func_init_cmn(struct bnx2x *bp,
5682 const struct bnx2x_func_sp_drv_ops *drv)
5683{
5684 int rc = drv->init_hw_cmn(bp);
5685 if (rc)
5686 return rc;
5687
5688 return bnx2x_func_init_port(bp, drv);
5689}
5690
5691static int bnx2x_func_hw_init(struct bnx2x *bp,
5692 struct bnx2x_func_state_params *params)
5693{
5694 u32 load_code = params->params.hw_init.load_phase;
5695 struct bnx2x_func_sp_obj *o = params->f_obj;
5696 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5697 int rc = 0;
5698
5699 DP(BNX2X_MSG_SP, "function %d load_code %x\n",
5700 BP_ABS_FUNC(bp), load_code);
5701
5702 /* Prepare buffers for unzipping the FW */
5703 rc = drv->gunzip_init(bp);
5704 if (rc)
5705 return rc;
5706
5707 /* Prepare FW */
5708 rc = drv->init_fw(bp);
5709 if (rc) {
5710 BNX2X_ERR("Error loading firmware\n");
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005711 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005712 }
5713
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005714 /* Handle the beginning of COMMON_XXX pases separately... */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005715 switch (load_code) {
5716 case FW_MSG_CODE_DRV_LOAD_COMMON_CHIP:
5717 rc = bnx2x_func_init_cmn_chip(bp, drv);
5718 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005719 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005720
5721 break;
5722 case FW_MSG_CODE_DRV_LOAD_COMMON:
5723 rc = bnx2x_func_init_cmn(bp, drv);
5724 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005725 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005726
5727 break;
5728 case FW_MSG_CODE_DRV_LOAD_PORT:
5729 rc = bnx2x_func_init_port(bp, drv);
5730 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005731 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005732
5733 break;
5734 case FW_MSG_CODE_DRV_LOAD_FUNCTION:
5735 rc = bnx2x_func_init_func(bp, drv);
5736 if (rc)
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005737 goto init_err;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005738
5739 break;
5740 default:
5741 BNX2X_ERR("Unknown load_code (0x%x) from MCP\n", load_code);
5742 rc = -EINVAL;
5743 }
5744
Dmitry Kravkoveb2afd42011-11-15 12:07:33 +00005745init_err:
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005746 drv->gunzip_end(bp);
5747
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005748 /* In case of success, complete the command immediately: no ramrods
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005749 * have been sent.
5750 */
5751 if (!rc)
5752 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_INIT);
5753
5754 return rc;
5755}
5756
5757/**
5758 * bnx2x_func_reset_func - reset HW at function stage
5759 *
5760 * @bp: device handle
5761 * @drv:
5762 *
5763 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_FUNCTION stage: reset only
5764 * FUNCTION-only HW blocks.
5765 */
5766static inline void bnx2x_func_reset_func(struct bnx2x *bp,
5767 const struct bnx2x_func_sp_drv_ops *drv)
5768{
5769 drv->reset_hw_func(bp);
5770}
5771
5772/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005773 * bnx2x_func_reset_port - reset HW at port stage
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005774 *
5775 * @bp: device handle
5776 * @drv:
5777 *
5778 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_PORT stage: reset
5779 * FUNCTION-only and PORT-only HW blocks.
5780 *
5781 * !!!IMPORTANT!!!
5782 *
5783 * It's important to call reset_port before reset_func() as the last thing
5784 * reset_func does is pf_disable() thus disabling PGLUE_B, which
5785 * makes impossible any DMAE transactions.
5786 */
5787static inline void bnx2x_func_reset_port(struct bnx2x *bp,
5788 const struct bnx2x_func_sp_drv_ops *drv)
5789{
5790 drv->reset_hw_port(bp);
5791 bnx2x_func_reset_func(bp, drv);
5792}
5793
5794/**
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005795 * bnx2x_func_reset_cmn - reset HW at common stage
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005796 *
5797 * @bp: device handle
5798 * @drv:
5799 *
5800 * Reset HW at FW_MSG_CODE_DRV_UNLOAD_COMMON and
5801 * FW_MSG_CODE_DRV_UNLOAD_COMMON_CHIP stages: reset COMMON,
5802 * COMMON_CHIP, FUNCTION-only and PORT-only HW blocks.
5803 */
5804static inline void bnx2x_func_reset_cmn(struct bnx2x *bp,
5805 const struct bnx2x_func_sp_drv_ops *drv)
5806{
5807 bnx2x_func_reset_port(bp, drv);
5808 drv->reset_hw_cmn(bp);
5809}
5810
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005811static inline int bnx2x_func_hw_reset(struct bnx2x *bp,
5812 struct bnx2x_func_state_params *params)
5813{
5814 u32 reset_phase = params->params.hw_reset.reset_phase;
5815 struct bnx2x_func_sp_obj *o = params->f_obj;
5816 const struct bnx2x_func_sp_drv_ops *drv = o->drv;
5817
5818 DP(BNX2X_MSG_SP, "function %d reset_phase %x\n", BP_ABS_FUNC(bp),
5819 reset_phase);
5820
5821 switch (reset_phase) {
5822 case FW_MSG_CODE_DRV_UNLOAD_COMMON:
5823 bnx2x_func_reset_cmn(bp, drv);
5824 break;
5825 case FW_MSG_CODE_DRV_UNLOAD_PORT:
5826 bnx2x_func_reset_port(bp, drv);
5827 break;
5828 case FW_MSG_CODE_DRV_UNLOAD_FUNCTION:
5829 bnx2x_func_reset_func(bp, drv);
5830 break;
5831 default:
5832 BNX2X_ERR("Unknown reset_phase (0x%x) from MCP\n",
5833 reset_phase);
5834 break;
5835 }
5836
Yuval Mintz16a5fd92013-06-02 00:06:18 +00005837 /* Complete the command immediately: no ramrods have been sent. */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005838 o->complete_cmd(bp, o, BNX2X_F_CMD_HW_RESET);
5839
5840 return 0;
5841}
5842
5843static inline int bnx2x_func_send_start(struct bnx2x *bp,
5844 struct bnx2x_func_state_params *params)
5845{
5846 struct bnx2x_func_sp_obj *o = params->f_obj;
5847 struct function_start_data *rdata =
5848 (struct function_start_data *)o->rdata;
5849 dma_addr_t data_mapping = o->rdata_mapping;
5850 struct bnx2x_func_start_params *start_params = &params->params.start;
5851
5852 memset(rdata, 0, sizeof(*rdata));
5853
5854 /* Fill the ramrod data with provided parameters */
Dmitry Kravkov1bc277f2013-03-18 06:51:04 +00005855 rdata->function_mode = (u8)start_params->mf_mode;
5856 rdata->sd_vlan_tag = cpu_to_le16(start_params->sd_vlan_tag);
5857 rdata->path_id = BP_PATH(bp);
5858 rdata->network_cos_mode = start_params->network_cos_mode;
5859 rdata->gre_tunnel_mode = start_params->gre_tunnel_mode;
5860 rdata->gre_tunnel_rss = start_params->gre_tunnel_rss;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005861
Dmitry Kravkov1bc277f2013-03-18 06:51:04 +00005862 /* No need for an explicit memory barrier here as long we would
5863 * need to ensure the ordering of writing to the SPQ element
5864 * and updating of the SPQ producer which involves a memory
5865 * read and we will have to put a full memory barrier there
5866 * (inside bnx2x_sp_post()).
Vladislav Zolotarov53e51e22011-07-19 01:45:02 +00005867 */
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005868
5869 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_START, 0,
5870 U64_HI(data_mapping),
5871 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5872}
5873
Merav Sicron55c11942012-11-07 00:45:48 +00005874static inline int bnx2x_func_send_switch_update(struct bnx2x *bp,
5875 struct bnx2x_func_state_params *params)
5876{
5877 struct bnx2x_func_sp_obj *o = params->f_obj;
5878 struct function_update_data *rdata =
5879 (struct function_update_data *)o->rdata;
5880 dma_addr_t data_mapping = o->rdata_mapping;
5881 struct bnx2x_func_switch_update_params *switch_update_params =
5882 &params->params.switch_update;
5883
5884 memset(rdata, 0, sizeof(*rdata));
5885
5886 /* Fill the ramrod data with provided parameters */
5887 rdata->tx_switch_suspend_change_flg = 1;
5888 rdata->tx_switch_suspend = switch_update_params->suspend;
5889 rdata->echo = SWITCH_UPDATE;
5890
5891 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5892 U64_HI(data_mapping),
5893 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5894}
5895
Barak Witkowskia3348722012-04-23 03:04:46 +00005896static inline int bnx2x_func_send_afex_update(struct bnx2x *bp,
5897 struct bnx2x_func_state_params *params)
5898{
5899 struct bnx2x_func_sp_obj *o = params->f_obj;
5900 struct function_update_data *rdata =
5901 (struct function_update_data *)o->afex_rdata;
5902 dma_addr_t data_mapping = o->afex_rdata_mapping;
5903 struct bnx2x_func_afex_update_params *afex_update_params =
5904 &params->params.afex_update;
5905
5906 memset(rdata, 0, sizeof(*rdata));
5907
5908 /* Fill the ramrod data with provided parameters */
5909 rdata->vif_id_change_flg = 1;
5910 rdata->vif_id = cpu_to_le16(afex_update_params->vif_id);
5911 rdata->afex_default_vlan_change_flg = 1;
5912 rdata->afex_default_vlan =
5913 cpu_to_le16(afex_update_params->afex_default_vlan);
5914 rdata->allowed_priorities_change_flg = 1;
5915 rdata->allowed_priorities = afex_update_params->allowed_priorities;
Merav Sicron55c11942012-11-07 00:45:48 +00005916 rdata->echo = AFEX_UPDATE;
Barak Witkowskia3348722012-04-23 03:04:46 +00005917
5918 /* No need for an explicit memory barrier here as long we would
5919 * need to ensure the ordering of writing to the SPQ element
5920 * and updating of the SPQ producer which involves a memory
5921 * read and we will have to put a full memory barrier there
5922 * (inside bnx2x_sp_post()).
5923 */
5924 DP(BNX2X_MSG_SP,
5925 "afex: sending func_update vif_id 0x%x dvlan 0x%x prio 0x%x\n",
5926 rdata->vif_id,
5927 rdata->afex_default_vlan, rdata->allowed_priorities);
5928
5929 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_UPDATE, 0,
5930 U64_HI(data_mapping),
5931 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
5932}
5933
5934static
5935inline int bnx2x_func_send_afex_viflists(struct bnx2x *bp,
5936 struct bnx2x_func_state_params *params)
5937{
5938 struct bnx2x_func_sp_obj *o = params->f_obj;
5939 struct afex_vif_list_ramrod_data *rdata =
5940 (struct afex_vif_list_ramrod_data *)o->afex_rdata;
Yuval Mintz86564c32013-01-23 03:21:50 +00005941 struct bnx2x_func_afex_viflists_params *afex_vif_params =
Barak Witkowskia3348722012-04-23 03:04:46 +00005942 &params->params.afex_viflists;
5943 u64 *p_rdata = (u64 *)rdata;
5944
5945 memset(rdata, 0, sizeof(*rdata));
5946
5947 /* Fill the ramrod data with provided parameters */
Yuval Mintz86564c32013-01-23 03:21:50 +00005948 rdata->vif_list_index = cpu_to_le16(afex_vif_params->vif_list_index);
5949 rdata->func_bit_map = afex_vif_params->func_bit_map;
5950 rdata->afex_vif_list_command = afex_vif_params->afex_vif_list_command;
5951 rdata->func_to_clear = afex_vif_params->func_to_clear;
Barak Witkowskia3348722012-04-23 03:04:46 +00005952
5953 /* send in echo type of sub command */
Yuval Mintz86564c32013-01-23 03:21:50 +00005954 rdata->echo = afex_vif_params->afex_vif_list_command;
Barak Witkowskia3348722012-04-23 03:04:46 +00005955
5956 /* No need for an explicit memory barrier here as long we would
5957 * need to ensure the ordering of writing to the SPQ element
5958 * and updating of the SPQ producer which involves a memory
5959 * read and we will have to put a full memory barrier there
5960 * (inside bnx2x_sp_post()).
5961 */
5962
5963 DP(BNX2X_MSG_SP, "afex: ramrod lists, cmd 0x%x index 0x%x func_bit_map 0x%x func_to_clr 0x%x\n",
5964 rdata->afex_vif_list_command, rdata->vif_list_index,
5965 rdata->func_bit_map, rdata->func_to_clear);
5966
5967 /* this ramrod sends data directly and not through DMA mapping */
5968 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_AFEX_VIF_LISTS, 0,
5969 U64_HI(*p_rdata), U64_LO(*p_rdata),
5970 NONE_CONNECTION_TYPE);
5971}
5972
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03005973static inline int bnx2x_func_send_stop(struct bnx2x *bp,
5974 struct bnx2x_func_state_params *params)
5975{
5976 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_FUNCTION_STOP, 0, 0, 0,
5977 NONE_CONNECTION_TYPE);
5978}
5979
Dmitry Kravkov6debea82011-07-19 01:42:04 +00005980static inline int bnx2x_func_send_tx_stop(struct bnx2x *bp,
5981 struct bnx2x_func_state_params *params)
5982{
5983 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_STOP_TRAFFIC, 0, 0, 0,
5984 NONE_CONNECTION_TYPE);
5985}
5986static inline int bnx2x_func_send_tx_start(struct bnx2x *bp,
5987 struct bnx2x_func_state_params *params)
5988{
5989 struct bnx2x_func_sp_obj *o = params->f_obj;
5990 struct flow_control_configuration *rdata =
5991 (struct flow_control_configuration *)o->rdata;
5992 dma_addr_t data_mapping = o->rdata_mapping;
5993 struct bnx2x_func_tx_start_params *tx_start_params =
5994 &params->params.tx_start;
5995 int i;
5996
5997 memset(rdata, 0, sizeof(*rdata));
5998
5999 rdata->dcb_enabled = tx_start_params->dcb_enabled;
6000 rdata->dcb_version = tx_start_params->dcb_version;
6001 rdata->dont_add_pri_0_en = tx_start_params->dont_add_pri_0_en;
6002
6003 for (i = 0; i < ARRAY_SIZE(rdata->traffic_type_to_priority_cos); i++)
6004 rdata->traffic_type_to_priority_cos[i] =
6005 tx_start_params->traffic_type_to_priority_cos[i];
6006
6007 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_START_TRAFFIC, 0,
6008 U64_HI(data_mapping),
6009 U64_LO(data_mapping), NONE_CONNECTION_TYPE);
6010}
6011
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006012static int bnx2x_func_send_cmd(struct bnx2x *bp,
6013 struct bnx2x_func_state_params *params)
6014{
6015 switch (params->cmd) {
6016 case BNX2X_F_CMD_HW_INIT:
6017 return bnx2x_func_hw_init(bp, params);
6018 case BNX2X_F_CMD_START:
6019 return bnx2x_func_send_start(bp, params);
6020 case BNX2X_F_CMD_STOP:
6021 return bnx2x_func_send_stop(bp, params);
6022 case BNX2X_F_CMD_HW_RESET:
6023 return bnx2x_func_hw_reset(bp, params);
Barak Witkowskia3348722012-04-23 03:04:46 +00006024 case BNX2X_F_CMD_AFEX_UPDATE:
6025 return bnx2x_func_send_afex_update(bp, params);
6026 case BNX2X_F_CMD_AFEX_VIFLISTS:
6027 return bnx2x_func_send_afex_viflists(bp, params);
Dmitry Kravkov6debea82011-07-19 01:42:04 +00006028 case BNX2X_F_CMD_TX_STOP:
6029 return bnx2x_func_send_tx_stop(bp, params);
6030 case BNX2X_F_CMD_TX_START:
6031 return bnx2x_func_send_tx_start(bp, params);
Merav Sicron55c11942012-11-07 00:45:48 +00006032 case BNX2X_F_CMD_SWITCH_UPDATE:
6033 return bnx2x_func_send_switch_update(bp, params);
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006034 default:
6035 BNX2X_ERR("Unknown command: %d\n", params->cmd);
6036 return -EINVAL;
6037 }
6038}
6039
6040void bnx2x_init_func_obj(struct bnx2x *bp,
6041 struct bnx2x_func_sp_obj *obj,
6042 void *rdata, dma_addr_t rdata_mapping,
Barak Witkowskia3348722012-04-23 03:04:46 +00006043 void *afex_rdata, dma_addr_t afex_rdata_mapping,
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006044 struct bnx2x_func_sp_drv_ops *drv_iface)
6045{
6046 memset(obj, 0, sizeof(*obj));
6047
6048 mutex_init(&obj->one_pending_mutex);
6049
6050 obj->rdata = rdata;
6051 obj->rdata_mapping = rdata_mapping;
Barak Witkowskia3348722012-04-23 03:04:46 +00006052 obj->afex_rdata = afex_rdata;
6053 obj->afex_rdata_mapping = afex_rdata_mapping;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006054 obj->send_cmd = bnx2x_func_send_cmd;
6055 obj->check_transition = bnx2x_func_chk_transition;
6056 obj->complete_cmd = bnx2x_func_comp_cmd;
6057 obj->wait_comp = bnx2x_func_wait_comp;
6058
6059 obj->drv = drv_iface;
6060}
6061
6062/**
6063 * bnx2x_func_state_change - perform Function state change transition
6064 *
6065 * @bp: device handle
6066 * @params: parameters to perform the transaction
6067 *
6068 * returns 0 in case of successfully completed transition,
6069 * negative error code in case of failure, positive
6070 * (EBUSY) value if there is a completion to that is
6071 * still pending (possible only if RAMROD_COMP_WAIT is
6072 * not set in params->ramrod_flags for asynchronous
6073 * commands).
6074 */
6075int bnx2x_func_state_change(struct bnx2x *bp,
6076 struct bnx2x_func_state_params *params)
6077{
6078 struct bnx2x_func_sp_obj *o = params->f_obj;
Merav Sicron55c11942012-11-07 00:45:48 +00006079 int rc, cnt = 300;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006080 enum bnx2x_func_cmd cmd = params->cmd;
6081 unsigned long *pending = &o->pending;
6082
6083 mutex_lock(&o->one_pending_mutex);
6084
6085 /* Check that the requested transition is legal */
Merav Sicron55c11942012-11-07 00:45:48 +00006086 rc = o->check_transition(bp, o, params);
6087 if ((rc == -EBUSY) &&
6088 (test_bit(RAMROD_RETRY, &params->ramrod_flags))) {
6089 while ((rc == -EBUSY) && (--cnt > 0)) {
6090 mutex_unlock(&o->one_pending_mutex);
6091 msleep(10);
6092 mutex_lock(&o->one_pending_mutex);
6093 rc = o->check_transition(bp, o, params);
6094 }
6095 if (rc == -EBUSY) {
6096 mutex_unlock(&o->one_pending_mutex);
6097 BNX2X_ERR("timeout waiting for previous ramrod completion\n");
6098 return rc;
6099 }
6100 } else if (rc) {
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006101 mutex_unlock(&o->one_pending_mutex);
Merav Sicron55c11942012-11-07 00:45:48 +00006102 return rc;
Vlad Zolotarov619c5cb2011-06-14 14:33:44 +03006103 }
6104
6105 /* Set "pending" bit */
6106 set_bit(cmd, pending);
6107
6108 /* Don't send a command if only driver cleanup was requested */
6109 if (test_bit(RAMROD_DRV_CLR_ONLY, &params->ramrod_flags)) {
6110 bnx2x_func_state_change_comp(bp, o, cmd);
6111 mutex_unlock(&o->one_pending_mutex);
6112 } else {
6113 /* Send a ramrod */
6114 rc = o->send_cmd(bp, params);
6115
6116 mutex_unlock(&o->one_pending_mutex);
6117
6118 if (rc) {
6119 o->next_state = BNX2X_F_STATE_MAX;
6120 clear_bit(cmd, pending);
6121 smp_mb__after_clear_bit();
6122 return rc;
6123 }
6124
6125 if (test_bit(RAMROD_COMP_WAIT, &params->ramrod_flags)) {
6126 rc = o->wait_comp(bp, o, cmd);
6127 if (rc)
6128 return rc;
6129
6130 return 0;
6131 }
6132 }
6133
6134 return !!test_bit(cmd, pending);
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00006135}