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