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