blob: 7c876a06b7791be71db294b59e9be0a6f3ca9bb7 [file] [log] [blame]
Vladislav Zolotarov042181f2011-06-14 01:33:39 +00001#include <linux/version.h>
2#include <linux/module.h>
3#include <linux/crc32.h>
4#include <linux/netdevice.h>
5#include <linux/etherdevice.h>
6#include <linux/crc32c.h>
7#include "bnx2x.h"
8#include "bnx2x_cmn.h"
9#include "bnx2x_sp.h"
10
11
12/**
13 * bnx2x_set_mac_addr_gen - set a MAC in a CAM for a few L2 Clients for E1x chips
14 *
15 * @bp: driver handle
16 * @set: set or clear an entry (1 or 0)
17 * @mac: pointer to a buffer containing a MAC
18 * @cl_bit_vec: bit vector of clients to register a MAC for
19 * @cam_offset: offset in a CAM to use
20 * @is_bcast: is the set MAC a broadcast address (for E1 only)
21 */
22void bnx2x_set_mac_addr_gen(struct bnx2x *bp, int set, const u8 *mac,
23 u32 cl_bit_vec, u8 cam_offset,
24 u8 is_bcast)
25{
26 struct mac_configuration_cmd *config =
27 (struct mac_configuration_cmd *)bnx2x_sp(bp, mac_config);
28 int ramrod_flags = WAIT_RAMROD_COMMON;
29
30 bp->set_mac_pending = 1;
31
32 config->hdr.length = 1;
33 config->hdr.offset = cam_offset;
34 config->hdr.client_id = 0xff;
35 /* Mark the single MAC configuration ramrod as opposed to a
36 * UC/MC list configuration).
37 */
38 config->hdr.echo = 1;
39
40 /* primary MAC */
41 config->config_table[0].msb_mac_addr =
42 swab16(*(u16 *)&mac[0]);
43 config->config_table[0].middle_mac_addr =
44 swab16(*(u16 *)&mac[2]);
45 config->config_table[0].lsb_mac_addr =
46 swab16(*(u16 *)&mac[4]);
47 config->config_table[0].clients_bit_vector =
48 cpu_to_le32(cl_bit_vec);
49 config->config_table[0].vlan_id = 0;
50 config->config_table[0].pf_id = BP_FUNC(bp);
51 if (set)
52 SET_FLAG(config->config_table[0].flags,
53 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
54 T_ETH_MAC_COMMAND_SET);
55 else
56 SET_FLAG(config->config_table[0].flags,
57 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
58 T_ETH_MAC_COMMAND_INVALIDATE);
59
60 if (is_bcast)
61 SET_FLAG(config->config_table[0].flags,
62 MAC_CONFIGURATION_ENTRY_BROADCAST, 1);
63
64 DP(NETIF_MSG_IFUP, "%s MAC (%04x:%04x:%04x) PF_ID %d CLID mask %d\n",
65 (set ? "setting" : "clearing"),
66 config->config_table[0].msb_mac_addr,
67 config->config_table[0].middle_mac_addr,
68 config->config_table[0].lsb_mac_addr, BP_FUNC(bp), cl_bit_vec);
69
70 mb();
71
72 bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_MAC, 0,
73 U64_HI(bnx2x_sp_mapping(bp, mac_config)),
74 U64_LO(bnx2x_sp_mapping(bp, mac_config)), 1);
75
76 /* Wait for a completion */
77 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending, ramrod_flags);
78}
79
80
81static inline u8 bnx2x_e1_cam_mc_offset(struct bnx2x *bp)
82{
83 return CHIP_REV_IS_SLOW(bp) ?
84 (BNX2X_MAX_EMUL_MULTI * (1 + BP_PORT(bp))) :
85 (BNX2X_MAX_MULTICAST * (1 + BP_PORT(bp)));
86}
87
88/* set mc list, do not wait as wait implies sleep and
89 * set_rx_mode can be invoked from non-sleepable context.
90 *
91 * Instead we use the same ramrod data buffer each time we need
92 * to configure a list of addresses, and use the fact that the
93 * list of MACs is changed in an incremental way and that the
94 * function is called under the netif_addr_lock. A temporary
95 * inconsistent CAM configuration (possible in case of a very fast
96 * sequence of add/del/add on the host side) will shortly be
97 * restored by the handler of the last ramrod.
98 */
99int bnx2x_set_e1_mc_list(struct bnx2x *bp)
100{
101 int i = 0, old;
102 struct net_device *dev = bp->dev;
103 u8 offset = bnx2x_e1_cam_mc_offset(bp);
104 struct netdev_hw_addr *ha;
105 struct mac_configuration_cmd *config_cmd = bnx2x_sp(bp, mcast_config);
106 dma_addr_t config_cmd_map = bnx2x_sp_mapping(bp, mcast_config);
107
108 if (netdev_mc_count(dev) > BNX2X_MAX_MULTICAST)
109 return -EINVAL;
110
111 netdev_for_each_mc_addr(ha, dev) {
112 /* copy mac */
113 config_cmd->config_table[i].msb_mac_addr =
114 swab16(*(u16 *)&bnx2x_mc_addr(ha)[0]);
115 config_cmd->config_table[i].middle_mac_addr =
116 swab16(*(u16 *)&bnx2x_mc_addr(ha)[2]);
117 config_cmd->config_table[i].lsb_mac_addr =
118 swab16(*(u16 *)&bnx2x_mc_addr(ha)[4]);
119
120 config_cmd->config_table[i].vlan_id = 0;
121 config_cmd->config_table[i].pf_id = BP_FUNC(bp);
122 config_cmd->config_table[i].clients_bit_vector =
123 cpu_to_le32(1 << BP_L_ID(bp));
124
125 SET_FLAG(config_cmd->config_table[i].flags,
126 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
127 T_ETH_MAC_COMMAND_SET);
128
129 DP(NETIF_MSG_IFUP,
130 "setting MCAST[%d] (%04x:%04x:%04x)\n", i,
131 config_cmd->config_table[i].msb_mac_addr,
132 config_cmd->config_table[i].middle_mac_addr,
133 config_cmd->config_table[i].lsb_mac_addr);
134 i++;
135 }
136 old = config_cmd->hdr.length;
137 if (old > i) {
138 for (; i < old; i++) {
139 if (CAM_IS_INVALID(config_cmd->
140 config_table[i])) {
141 /* already invalidated */
142 break;
143 }
144 /* invalidate */
145 SET_FLAG(config_cmd->config_table[i].flags,
146 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
147 T_ETH_MAC_COMMAND_INVALIDATE);
148 }
149 }
150
151 wmb();
152
153 config_cmd->hdr.length = i;
154 config_cmd->hdr.offset = offset;
155 config_cmd->hdr.client_id = 0xff;
156 /* Mark that this ramrod doesn't use bp->set_mac_pending for
157 * synchronization.
158 */
159 config_cmd->hdr.echo = 0;
160
161 mb();
162
163 return bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_MAC, 0,
164 U64_HI(config_cmd_map), U64_LO(config_cmd_map), 1);
165}
166
167void bnx2x_invalidate_e1_mc_list(struct bnx2x *bp)
168{
169 int i;
170 struct mac_configuration_cmd *config_cmd = bnx2x_sp(bp, mcast_config);
171 dma_addr_t config_cmd_map = bnx2x_sp_mapping(bp, mcast_config);
172 int ramrod_flags = WAIT_RAMROD_COMMON;
173 u8 offset = bnx2x_e1_cam_mc_offset(bp);
174
175 for (i = 0; i < BNX2X_MAX_MULTICAST; i++)
176 SET_FLAG(config_cmd->config_table[i].flags,
177 MAC_CONFIGURATION_ENTRY_ACTION_TYPE,
178 T_ETH_MAC_COMMAND_INVALIDATE);
179
180 wmb();
181
182 config_cmd->hdr.length = BNX2X_MAX_MULTICAST;
183 config_cmd->hdr.offset = offset;
184 config_cmd->hdr.client_id = 0xff;
185 /* We'll wait for a completion this time... */
186 config_cmd->hdr.echo = 1;
187
188 bp->set_mac_pending = 1;
189
190 mb();
191
192 bnx2x_sp_post(bp, RAMROD_CMD_ID_COMMON_SET_MAC, 0,
193 U64_HI(config_cmd_map), U64_LO(config_cmd_map), 1);
194
195 /* Wait for a completion */
196 bnx2x_wait_ramrod(bp, 0, 0, &bp->set_mac_pending,
197 ramrod_flags);
198
199}
200
201/* Accept one or more multicasts */
202int bnx2x_set_e1h_mc_list(struct bnx2x *bp)
203{
204 struct net_device *dev = bp->dev;
205 struct netdev_hw_addr *ha;
206 u32 mc_filter[MC_HASH_SIZE];
207 u32 crc, bit, regidx;
208 int i;
209
210 memset(mc_filter, 0, 4 * MC_HASH_SIZE);
211
212 netdev_for_each_mc_addr(ha, dev) {
213 DP(NETIF_MSG_IFUP, "Adding mcast MAC: %pM\n",
214 bnx2x_mc_addr(ha));
215
216 crc = crc32c_le(0, bnx2x_mc_addr(ha),
217 ETH_ALEN);
218 bit = (crc >> 24) & 0xff;
219 regidx = bit >> 5;
220 bit &= 0x1f;
221 mc_filter[regidx] |= (1 << bit);
222 }
223
224 for (i = 0; i < MC_HASH_SIZE; i++)
225 REG_WR(bp, MC_HASH_OFFSET(bp, i),
226 mc_filter[i]);
227
228 return 0;
229}
230
231void bnx2x_invalidate_e1h_mc_list(struct bnx2x *bp)
232{
233 int i;
234
235 for (i = 0; i < MC_HASH_SIZE; i++)
236 REG_WR(bp, MC_HASH_OFFSET(bp, i), 0);
237}
238
239/* must be called under rtnl_lock */
240void bnx2x_rxq_set_mac_filters(struct bnx2x *bp, u16 cl_id, u32 filters)
241{
242 u32 mask = (1 << cl_id);
243
244 /* initial seeting is BNX2X_ACCEPT_NONE */
245 u8 drop_all_ucast = 1, drop_all_bcast = 1, drop_all_mcast = 1;
246 u8 accp_all_ucast = 0, accp_all_bcast = 0, accp_all_mcast = 0;
247 u8 unmatched_unicast = 0;
248
249 if (filters & BNX2X_ACCEPT_UNMATCHED_UCAST)
250 unmatched_unicast = 1;
251
252 if (filters & BNX2X_PROMISCUOUS_MODE) {
253 /* promiscious - accept all, drop none */
254 drop_all_ucast = drop_all_bcast = drop_all_mcast = 0;
255 accp_all_ucast = accp_all_bcast = accp_all_mcast = 1;
256 if (IS_MF_SI(bp)) {
257 /*
258 * SI mode defines to accept in promiscuos mode
259 * only unmatched packets
260 */
261 unmatched_unicast = 1;
262 accp_all_ucast = 0;
263 }
264 }
265 if (filters & BNX2X_ACCEPT_UNICAST) {
266 /* accept matched ucast */
267 drop_all_ucast = 0;
268 }
269 if (filters & BNX2X_ACCEPT_MULTICAST)
270 /* accept matched mcast */
271 drop_all_mcast = 0;
272
273 if (filters & BNX2X_ACCEPT_ALL_UNICAST) {
274 /* accept all mcast */
275 drop_all_ucast = 0;
276 accp_all_ucast = 1;
277 }
278 if (filters & BNX2X_ACCEPT_ALL_MULTICAST) {
279 /* accept all mcast */
280 drop_all_mcast = 0;
281 accp_all_mcast = 1;
282 }
283 if (filters & BNX2X_ACCEPT_BROADCAST) {
284 /* accept (all) bcast */
285 drop_all_bcast = 0;
286 accp_all_bcast = 1;
287 }
288
289 bp->mac_filters.ucast_drop_all = drop_all_ucast ?
290 bp->mac_filters.ucast_drop_all | mask :
291 bp->mac_filters.ucast_drop_all & ~mask;
292
293 bp->mac_filters.mcast_drop_all = drop_all_mcast ?
294 bp->mac_filters.mcast_drop_all | mask :
295 bp->mac_filters.mcast_drop_all & ~mask;
296
297 bp->mac_filters.bcast_drop_all = drop_all_bcast ?
298 bp->mac_filters.bcast_drop_all | mask :
299 bp->mac_filters.bcast_drop_all & ~mask;
300
301 bp->mac_filters.ucast_accept_all = accp_all_ucast ?
302 bp->mac_filters.ucast_accept_all | mask :
303 bp->mac_filters.ucast_accept_all & ~mask;
304
305 bp->mac_filters.mcast_accept_all = accp_all_mcast ?
306 bp->mac_filters.mcast_accept_all | mask :
307 bp->mac_filters.mcast_accept_all & ~mask;
308
309 bp->mac_filters.bcast_accept_all = accp_all_bcast ?
310 bp->mac_filters.bcast_accept_all | mask :
311 bp->mac_filters.bcast_accept_all & ~mask;
312
313 bp->mac_filters.unmatched_unicast = unmatched_unicast ?
314 bp->mac_filters.unmatched_unicast | mask :
315 bp->mac_filters.unmatched_unicast & ~mask;
316}
317
318void bnx2x_set_storm_rx_mode(struct bnx2x *bp)
319{
320 int mode = bp->rx_mode;
321 int port = BP_PORT(bp);
322 u16 cl_id;
323 u32 def_q_filters = 0;
324
325 /* All but management unicast packets should pass to the host as well */
326 u32 llh_mask =
327 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_BRCST |
328 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_MLCST |
329 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_VLAN |
330 NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_NO_VLAN;
331
332 switch (mode) {
333 case BNX2X_RX_MODE_NONE: /* no Rx */
334 def_q_filters = BNX2X_ACCEPT_NONE;
335#ifdef BCM_CNIC
336 if (!NO_FCOE(bp)) {
337 cl_id = bnx2x_fcoe(bp, cl_id);
338 bnx2x_rxq_set_mac_filters(bp, cl_id, BNX2X_ACCEPT_NONE);
339 }
340#endif
341 break;
342
343 case BNX2X_RX_MODE_NORMAL:
344 def_q_filters |= BNX2X_ACCEPT_UNICAST | BNX2X_ACCEPT_BROADCAST |
345 BNX2X_ACCEPT_MULTICAST;
346#ifdef BCM_CNIC
347 if (!NO_FCOE(bp)) {
348 cl_id = bnx2x_fcoe(bp, cl_id);
349 bnx2x_rxq_set_mac_filters(bp, cl_id,
350 BNX2X_ACCEPT_UNICAST |
351 BNX2X_ACCEPT_MULTICAST);
352 }
353#endif
354 break;
355
356 case BNX2X_RX_MODE_ALLMULTI:
357 def_q_filters |= BNX2X_ACCEPT_UNICAST | BNX2X_ACCEPT_BROADCAST |
358 BNX2X_ACCEPT_ALL_MULTICAST;
359#ifdef BCM_CNIC
360 /*
361 * Prevent duplication of multicast packets by configuring FCoE
362 * L2 Client to receive only matched unicast frames.
363 */
364 if (!NO_FCOE(bp)) {
365 cl_id = bnx2x_fcoe(bp, cl_id);
366 bnx2x_rxq_set_mac_filters(bp, cl_id,
367 BNX2X_ACCEPT_UNICAST);
368 }
369#endif
370 break;
371
372 case BNX2X_RX_MODE_PROMISC:
373 def_q_filters |= BNX2X_PROMISCUOUS_MODE;
374#ifdef BCM_CNIC
375 /*
376 * Prevent packets duplication by configuring DROP_ALL for FCoE
377 * L2 Client.
378 */
379 if (!NO_FCOE(bp)) {
380 cl_id = bnx2x_fcoe(bp, cl_id);
381 bnx2x_rxq_set_mac_filters(bp, cl_id, BNX2X_ACCEPT_NONE);
382 }
383#endif
384 /* pass management unicast packets as well */
385 llh_mask |= NIG_LLH0_BRB1_DRV_MASK_REG_LLH0_BRB1_DRV_MASK_UNCST;
386 break;
387
388 default:
389 BNX2X_ERR("BAD rx mode (%d)\n", mode);
390 break;
391 }
392
393 cl_id = BP_L_ID(bp);
394 bnx2x_rxq_set_mac_filters(bp, cl_id, def_q_filters);
395
396 REG_WR(bp,
397 (port ? NIG_REG_LLH1_BRB1_DRV_MASK :
398 NIG_REG_LLH0_BRB1_DRV_MASK), llh_mask);
399
400 DP(NETIF_MSG_IFUP, "rx mode %d\n"
401 "drop_ucast 0x%x\ndrop_mcast 0x%x\ndrop_bcast 0x%x\n"
402 "accp_ucast 0x%x\naccp_mcast 0x%x\naccp_bcast 0x%x\n"
403 "unmatched_ucast 0x%x\n", mode,
404 bp->mac_filters.ucast_drop_all,
405 bp->mac_filters.mcast_drop_all,
406 bp->mac_filters.bcast_drop_all,
407 bp->mac_filters.ucast_accept_all,
408 bp->mac_filters.mcast_accept_all,
409 bp->mac_filters.bcast_accept_all,
410 bp->mac_filters.unmatched_unicast
411 );
412
413 storm_memset_mac_filters(bp, &bp->mac_filters, BP_FUNC(bp));
414}
415
416/* RSS configuration */
417static inline void __storm_memset_dma_mapping(struct bnx2x *bp,
418 u32 addr, dma_addr_t mapping)
419{
420 REG_WR(bp, addr, U64_LO(mapping));
421 REG_WR(bp, addr + 4, U64_HI(mapping));
422}
423
424static inline void __storm_fill(struct bnx2x *bp,
425 u32 addr, size_t size, u32 val)
426{
427 int i;
428 for (i = 0; i < size/4; i++)
429 REG_WR(bp, addr + (i * 4), val);
430}
431
432static inline void storm_memset_ustats_zero(struct bnx2x *bp,
433 u8 port, u16 stat_id)
434{
435 size_t size = sizeof(struct ustorm_per_client_stats);
436
437 u32 addr = BAR_USTRORM_INTMEM +
438 USTORM_PER_COUNTER_ID_STATS_OFFSET(port, stat_id);
439
440 __storm_fill(bp, addr, size, 0);
441}
442
443static inline void storm_memset_tstats_zero(struct bnx2x *bp,
444 u8 port, u16 stat_id)
445{
446 size_t size = sizeof(struct tstorm_per_client_stats);
447
448 u32 addr = BAR_TSTRORM_INTMEM +
449 TSTORM_PER_COUNTER_ID_STATS_OFFSET(port, stat_id);
450
451 __storm_fill(bp, addr, size, 0);
452}
453
454static inline void storm_memset_xstats_zero(struct bnx2x *bp,
455 u8 port, u16 stat_id)
456{
457 size_t size = sizeof(struct xstorm_per_client_stats);
458
459 u32 addr = BAR_XSTRORM_INTMEM +
460 XSTORM_PER_COUNTER_ID_STATS_OFFSET(port, stat_id);
461
462 __storm_fill(bp, addr, size, 0);
463}
464
465
466static inline void storm_memset_spq_addr(struct bnx2x *bp,
467 dma_addr_t mapping, u16 abs_fid)
468{
469 u32 addr = XSEM_REG_FAST_MEMORY +
470 XSTORM_SPQ_PAGE_BASE_OFFSET(abs_fid);
471
472 __storm_memset_dma_mapping(bp, addr, mapping);
473}
474
475static inline void storm_memset_xstats_flags(struct bnx2x *bp,
476 struct stats_indication_flags *flags,
477 u16 abs_fid)
478{
479 size_t size = sizeof(struct stats_indication_flags);
480
481 u32 addr = BAR_XSTRORM_INTMEM + XSTORM_STATS_FLAGS_OFFSET(abs_fid);
482
483 __storm_memset_struct(bp, addr, size, (u32 *)flags);
484}
485
486static inline void storm_memset_tstats_flags(struct bnx2x *bp,
487 struct stats_indication_flags *flags,
488 u16 abs_fid)
489{
490 size_t size = sizeof(struct stats_indication_flags);
491
492 u32 addr = BAR_TSTRORM_INTMEM + TSTORM_STATS_FLAGS_OFFSET(abs_fid);
493
494 __storm_memset_struct(bp, addr, size, (u32 *)flags);
495}
496
497static inline void storm_memset_ustats_flags(struct bnx2x *bp,
498 struct stats_indication_flags *flags,
499 u16 abs_fid)
500{
501 size_t size = sizeof(struct stats_indication_flags);
502
503 u32 addr = BAR_USTRORM_INTMEM + USTORM_STATS_FLAGS_OFFSET(abs_fid);
504
505 __storm_memset_struct(bp, addr, size, (u32 *)flags);
506}
507
508static inline void storm_memset_cstats_flags(struct bnx2x *bp,
509 struct stats_indication_flags *flags,
510 u16 abs_fid)
511{
512 size_t size = sizeof(struct stats_indication_flags);
513
514 u32 addr = BAR_CSTRORM_INTMEM + CSTORM_STATS_FLAGS_OFFSET(abs_fid);
515
516 __storm_memset_struct(bp, addr, size, (u32 *)flags);
517}
518
519static inline void storm_memset_xstats_addr(struct bnx2x *bp,
520 dma_addr_t mapping, u16 abs_fid)
521{
522 u32 addr = BAR_XSTRORM_INTMEM +
523 XSTORM_ETH_STATS_QUERY_ADDR_OFFSET(abs_fid);
524
525 __storm_memset_dma_mapping(bp, addr, mapping);
526}
527
528static inline void storm_memset_tstats_addr(struct bnx2x *bp,
529 dma_addr_t mapping, u16 abs_fid)
530{
531 u32 addr = BAR_TSTRORM_INTMEM +
532 TSTORM_ETH_STATS_QUERY_ADDR_OFFSET(abs_fid);
533
534 __storm_memset_dma_mapping(bp, addr, mapping);
535}
536
537static inline void storm_memset_ustats_addr(struct bnx2x *bp,
538 dma_addr_t mapping, u16 abs_fid)
539{
540 u32 addr = BAR_USTRORM_INTMEM +
541 USTORM_ETH_STATS_QUERY_ADDR_OFFSET(abs_fid);
542
543 __storm_memset_dma_mapping(bp, addr, mapping);
544}
545
546static inline void storm_memset_cstats_addr(struct bnx2x *bp,
547 dma_addr_t mapping, u16 abs_fid)
548{
549 u32 addr = BAR_CSTRORM_INTMEM +
550 CSTORM_ETH_STATS_QUERY_ADDR_OFFSET(abs_fid);
551
552 __storm_memset_dma_mapping(bp, addr, mapping);
553}
554
555static inline void storm_memset_vf_to_pf(struct bnx2x *bp, u16 abs_fid,
556 u16 pf_id)
557{
558 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_VF_TO_PF_OFFSET(abs_fid),
559 pf_id);
560 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_VF_TO_PF_OFFSET(abs_fid),
561 pf_id);
562 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_VF_TO_PF_OFFSET(abs_fid),
563 pf_id);
564 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_VF_TO_PF_OFFSET(abs_fid),
565 pf_id);
566}
567
568static inline void storm_memset_func_en(struct bnx2x *bp, u16 abs_fid,
569 u8 enable)
570{
571 REG_WR8(bp, BAR_XSTRORM_INTMEM + XSTORM_FUNC_EN_OFFSET(abs_fid),
572 enable);
573 REG_WR8(bp, BAR_CSTRORM_INTMEM + CSTORM_FUNC_EN_OFFSET(abs_fid),
574 enable);
575 REG_WR8(bp, BAR_TSTRORM_INTMEM + TSTORM_FUNC_EN_OFFSET(abs_fid),
576 enable);
577 REG_WR8(bp, BAR_USTRORM_INTMEM + USTORM_FUNC_EN_OFFSET(abs_fid),
578 enable);
579}
580
581static inline void storm_memset_func_cfg(struct bnx2x *bp,
582 struct tstorm_eth_function_common_config *tcfg,
583 u16 abs_fid)
584{
585 size_t size = sizeof(struct tstorm_eth_function_common_config);
586
587 u32 addr = BAR_TSTRORM_INTMEM +
588 TSTORM_FUNCTION_COMMON_CONFIG_OFFSET(abs_fid);
589
590 __storm_memset_struct(bp, addr, size, (u32 *)tcfg);
591}
592
593void bnx2x_func_init(struct bnx2x *bp, struct bnx2x_func_init_params *p)
594{
595 struct tstorm_eth_function_common_config tcfg = {0};
596 u16 rss_flgs;
597
598 /* tpa */
599 if (p->func_flgs & FUNC_FLG_TPA)
600 tcfg.config_flags |=
601 TSTORM_ETH_FUNCTION_COMMON_CONFIG_ENABLE_TPA;
602
603 /* set rss flags */
604 rss_flgs = (p->rss->mode <<
605 TSTORM_ETH_FUNCTION_COMMON_CONFIG_RSS_MODE_SHIFT);
606
607 if (p->rss->cap & RSS_IPV4_CAP)
608 rss_flgs |= RSS_IPV4_CAP_MASK;
609 if (p->rss->cap & RSS_IPV4_TCP_CAP)
610 rss_flgs |= RSS_IPV4_TCP_CAP_MASK;
611 if (p->rss->cap & RSS_IPV6_CAP)
612 rss_flgs |= RSS_IPV6_CAP_MASK;
613 if (p->rss->cap & RSS_IPV6_TCP_CAP)
614 rss_flgs |= RSS_IPV6_TCP_CAP_MASK;
615
616 tcfg.config_flags |= rss_flgs;
617 tcfg.rss_result_mask = p->rss->result_mask;
618
619 storm_memset_func_cfg(bp, &tcfg, p->func_id);
620
621 /* Enable the function in the FW */
622 storm_memset_vf_to_pf(bp, p->func_id, p->pf_id);
623 storm_memset_func_en(bp, p->func_id, 1);
624
625 /* statistics */
626 if (p->func_flgs & FUNC_FLG_STATS) {
627 struct stats_indication_flags stats_flags = {0};
628 stats_flags.collect_eth = 1;
629
630 storm_memset_xstats_flags(bp, &stats_flags, p->func_id);
631 storm_memset_xstats_addr(bp, p->fw_stat_map, p->func_id);
632
633 storm_memset_tstats_flags(bp, &stats_flags, p->func_id);
634 storm_memset_tstats_addr(bp, p->fw_stat_map, p->func_id);
635
636 storm_memset_ustats_flags(bp, &stats_flags, p->func_id);
637 storm_memset_ustats_addr(bp, p->fw_stat_map, p->func_id);
638
639 storm_memset_cstats_flags(bp, &stats_flags, p->func_id);
640 storm_memset_cstats_addr(bp, p->fw_stat_map, p->func_id);
641 }
642
643 /* spq */
644 if (p->func_flgs & FUNC_FLG_SPQ) {
645 storm_memset_spq_addr(bp, p->spq_map, p->func_id);
646 REG_WR(bp, XSEM_REG_FAST_MEMORY +
647 XSTORM_SPQ_PROD_OFFSET(p->func_id), p->spq_prod);
648 }
649}
650
651static void bnx2x_fill_cl_init_data(struct bnx2x *bp,
652 struct bnx2x_client_init_params *params,
653 u8 activate,
654 struct client_init_ramrod_data *data)
655{
656 /* Clear the buffer */
657 memset(data, 0, sizeof(*data));
658
659 /* general */
660 data->general.client_id = params->rxq_params.cl_id;
661 data->general.statistics_counter_id = params->rxq_params.stat_id;
662 data->general.statistics_en_flg =
663 (params->rxq_params.flags & QUEUE_FLG_STATS) ? 1 : 0;
664 data->general.is_fcoe_flg =
665 (params->ramrod_params.flags & CLIENT_IS_FCOE) ? 1 : 0;
666 data->general.activate_flg = activate;
667 data->general.sp_client_id = params->rxq_params.spcl_id;
668
669 /* Rx data */
670 data->rx.tpa_en_flg =
671 (params->rxq_params.flags & QUEUE_FLG_TPA) ? 1 : 0;
672 data->rx.vmqueue_mode_en_flg = 0;
673 data->rx.cache_line_alignment_log_size =
674 params->rxq_params.cache_line_log;
675 data->rx.enable_dynamic_hc =
676 (params->rxq_params.flags & QUEUE_FLG_DHC) ? 1 : 0;
677 data->rx.max_sges_for_packet = params->rxq_params.max_sges_pkt;
678 data->rx.client_qzone_id = params->rxq_params.cl_qzone_id;
679 data->rx.max_agg_size = params->rxq_params.tpa_agg_sz;
680
681 /* We don't set drop flags */
682 data->rx.drop_ip_cs_err_flg = 0;
683 data->rx.drop_tcp_cs_err_flg = 0;
684 data->rx.drop_ttl0_flg = 0;
685 data->rx.drop_udp_cs_err_flg = 0;
686
687 data->rx.inner_vlan_removal_enable_flg =
688 (params->rxq_params.flags & QUEUE_FLG_VLAN) ? 1 : 0;
689 data->rx.outer_vlan_removal_enable_flg =
690 (params->rxq_params.flags & QUEUE_FLG_OV) ? 1 : 0;
691 data->rx.status_block_id = params->rxq_params.fw_sb_id;
692 data->rx.rx_sb_index_number = params->rxq_params.sb_cq_index;
693 data->rx.bd_buff_size = cpu_to_le16(params->rxq_params.buf_sz);
694 data->rx.sge_buff_size = cpu_to_le16(params->rxq_params.sge_buf_sz);
695 data->rx.mtu = cpu_to_le16(params->rxq_params.mtu);
696 data->rx.bd_page_base.lo =
697 cpu_to_le32(U64_LO(params->rxq_params.dscr_map));
698 data->rx.bd_page_base.hi =
699 cpu_to_le32(U64_HI(params->rxq_params.dscr_map));
700 data->rx.sge_page_base.lo =
701 cpu_to_le32(U64_LO(params->rxq_params.sge_map));
702 data->rx.sge_page_base.hi =
703 cpu_to_le32(U64_HI(params->rxq_params.sge_map));
704 data->rx.cqe_page_base.lo =
705 cpu_to_le32(U64_LO(params->rxq_params.rcq_map));
706 data->rx.cqe_page_base.hi =
707 cpu_to_le32(U64_HI(params->rxq_params.rcq_map));
708 data->rx.is_leading_rss =
709 (params->ramrod_params.flags & CLIENT_IS_LEADING_RSS) ? 1 : 0;
710 data->rx.is_approx_mcast = data->rx.is_leading_rss;
711
712 /* Tx data */
713 data->tx.enforce_security_flg = 0; /* VF specific */
714 data->tx.tx_status_block_id = params->txq_params.fw_sb_id;
715 data->tx.tx_sb_index_number = params->txq_params.sb_cq_index;
716 data->tx.mtu = 0; /* VF specific */
717 data->tx.tx_bd_page_base.lo =
718 cpu_to_le32(U64_LO(params->txq_params.dscr_map));
719 data->tx.tx_bd_page_base.hi =
720 cpu_to_le32(U64_HI(params->txq_params.dscr_map));
721
722 /* flow control data */
723 data->fc.cqe_pause_thr_low = cpu_to_le16(params->pause.rcq_th_lo);
724 data->fc.cqe_pause_thr_high = cpu_to_le16(params->pause.rcq_th_hi);
725 data->fc.bd_pause_thr_low = cpu_to_le16(params->pause.bd_th_lo);
726 data->fc.bd_pause_thr_high = cpu_to_le16(params->pause.bd_th_hi);
727 data->fc.sge_pause_thr_low = cpu_to_le16(params->pause.sge_th_lo);
728 data->fc.sge_pause_thr_high = cpu_to_le16(params->pause.sge_th_hi);
729 data->fc.rx_cos_mask = cpu_to_le16(params->pause.pri_map);
730
731 data->fc.safc_group_num = params->txq_params.cos;
732 data->fc.safc_group_en_flg =
733 (params->txq_params.flags & QUEUE_FLG_COS) ? 1 : 0;
734 data->fc.traffic_type =
735 (params->ramrod_params.flags & CLIENT_IS_FCOE) ?
736 LLFC_TRAFFIC_TYPE_FCOE : LLFC_TRAFFIC_TYPE_NW;
737}
738
739
740int bnx2x_setup_fw_client(struct bnx2x *bp,
741 struct bnx2x_client_init_params *params,
742 u8 activate,
743 struct client_init_ramrod_data *data,
744 dma_addr_t data_mapping)
745{
746 u16 hc_usec;
747 int ramrod = RAMROD_CMD_ID_ETH_CLIENT_SETUP;
748 int ramrod_flags = 0, rc;
749
750 /* HC and context validation values */
751 hc_usec = params->txq_params.hc_rate ?
752 1000000 / params->txq_params.hc_rate : 0;
753 bnx2x_update_coalesce_sb_index(bp,
754 params->txq_params.fw_sb_id,
755 params->txq_params.sb_cq_index,
756 !(params->txq_params.flags & QUEUE_FLG_HC),
757 hc_usec);
758
759 *(params->ramrod_params.pstate) = BNX2X_FP_STATE_OPENING;
760
761 hc_usec = params->rxq_params.hc_rate ?
762 1000000 / params->rxq_params.hc_rate : 0;
763 bnx2x_update_coalesce_sb_index(bp,
764 params->rxq_params.fw_sb_id,
765 params->rxq_params.sb_cq_index,
766 !(params->rxq_params.flags & QUEUE_FLG_HC),
767 hc_usec);
768
769 bnx2x_set_ctx_validation(params->rxq_params.cxt,
770 params->rxq_params.cid);
771
772 /* zero stats */
773 if (params->txq_params.flags & QUEUE_FLG_STATS)
774 storm_memset_xstats_zero(bp, BP_PORT(bp),
775 params->txq_params.stat_id);
776
777 if (params->rxq_params.flags & QUEUE_FLG_STATS) {
778 storm_memset_ustats_zero(bp, BP_PORT(bp),
779 params->rxq_params.stat_id);
780 storm_memset_tstats_zero(bp, BP_PORT(bp),
781 params->rxq_params.stat_id);
782 }
783
784 /* Fill the ramrod data */
785 bnx2x_fill_cl_init_data(bp, params, activate, data);
786
787 /* SETUP ramrod.
788 *
789 * bnx2x_sp_post() takes a spin_lock thus no other explict memory
790 * barrier except from mmiowb() is needed to impose a
791 * proper ordering of memory operations.
792 */
793 mmiowb();
794
795
796 bnx2x_sp_post(bp, ramrod, params->ramrod_params.cid,
797 U64_HI(data_mapping), U64_LO(data_mapping), 0);
798
799 /* Wait for completion */
800 rc = bnx2x_wait_ramrod(bp, params->ramrod_params.state,
801 params->ramrod_params.index,
802 params->ramrod_params.pstate,
803 ramrod_flags);
804 return rc;
805}
806
807void bnx2x_push_indir_table(struct bnx2x *bp)
808{
809 int func = BP_FUNC(bp);
810 int i;
811
812 if (bp->multi_mode == ETH_RSS_MODE_DISABLED)
813 return;
814
815 for (i = 0; i < TSTORM_INDIRECTION_TABLE_SIZE; i++)
816 REG_WR8(bp, BAR_TSTRORM_INTMEM +
817 TSTORM_INDIRECTION_TABLE_OFFSET(func) + i,
818 bp->fp->cl_id + bp->rx_indir_table[i]);
819}