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