aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/qede/base/ecore_dcbx.c
blob: 6a966cb9178c9702eff3bbd705680035c015e3f7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
/*
 * Copyright (c) 2016 QLogic Corporation.
 * All rights reserved.
 * www.qlogic.com
 *
 * See LICENSE.qede_pmd for copyright and licensing details.
 */

#include "bcm_osal.h"
#include "ecore.h"
#include "ecore_sp_commands.h"
#include "ecore_dcbx.h"
#include "ecore_cxt.h"
#include "ecore_gtt_reg_addr.h"
#include "ecore_iro.h"

#define ECORE_DCBX_MAX_MIB_READ_TRY	(100)
#define ECORE_MAX_PFC_PRIORITIES	8
#define ECORE_ETH_TYPE_DEFAULT		(0)

#define ECORE_DCBX_INVALID_PRIORITY	0xFF

/* Get Traffic Class from priority traffic class table, 4 bits represent
 * the traffic class corresponding to the priority.
 */
#define ECORE_DCBX_PRIO2TC(prio_tc_tbl, prio) \
		((u32)(pri_tc_tbl >> ((7 - prio) * 4)) & 0x7)

static bool ecore_dcbx_app_ethtype(u32 app_info_bitmap)
{
	return (ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
		DCBX_APP_SF_ETHTYPE) ? true : false;
}

static bool ecore_dcbx_app_port(u32 app_info_bitmap)
{
	return (ECORE_MFW_GET_FIELD(app_info_bitmap, DCBX_APP_SF) ==
		DCBX_APP_SF_PORT) ? true : false;
}

static bool ecore_dcbx_default_tlv(u32 app_info_bitmap, u16 proto_id)
{
	return (ecore_dcbx_app_ethtype(app_info_bitmap) &&
		proto_id == ECORE_ETH_TYPE_DEFAULT) ? true : false;
}

static bool ecore_dcbx_enabled(u32 dcbx_cfg_bitmap)
{
	return (ECORE_MFW_GET_FIELD(dcbx_cfg_bitmap, DCBX_CONFIG_VERSION) ==
		DCBX_CONFIG_VERSION_DISABLED) ? false : true;
}

static bool ecore_dcbx_cee(u32 dcbx_cfg_bitmap)
{
	return (ECORE_MFW_GET_FIELD(dcbx_cfg_bitmap, DCBX_CONFIG_VERSION) ==
		DCBX_CONFIG_VERSION_CEE) ? true : false;
}

static bool ecore_dcbx_ieee(u32 dcbx_cfg_bitmap)
{
	return (ECORE_MFW_GET_FIELD(dcbx_cfg_bitmap, DCBX_CONFIG_VERSION) ==
		DCBX_CONFIG_VERSION_IEEE) ? true : false;
}

/* @@@TBD A0 Eagle workaround */
void ecore_dcbx_eagle_workaround(struct ecore_hwfn *p_hwfn,
				 struct ecore_ptt *p_ptt, bool set_to_pfc)
{
	if (!ENABLE_EAGLE_ENG1_WORKAROUND(p_hwfn))
		return;

	ecore_wr(p_hwfn, p_ptt,
		 YSEM_REG_FAST_MEMORY + 0x20000 /* RAM in FASTMEM */  +
		 YSTORM_FLOW_CONTROL_MODE_OFFSET,
		 set_to_pfc ? flow_ctrl_pfc : flow_ctrl_pause);
	ecore_wr(p_hwfn, p_ptt, NIG_REG_FLOWCTRL_MODE,
		 EAGLE_ENG1_WORKAROUND_NIG_FLOWCTRL_MODE);
}

static void
ecore_dcbx_dp_protocol(struct ecore_hwfn *p_hwfn,
		       struct ecore_dcbx_results *p_data)
{
	struct ecore_hw_info *p_info = &p_hwfn->hw_info;
	enum dcbx_protocol_type id;
	bool enable, update;
	u8 prio, tc, size;
	const char *name;	/* @DPDK */
	int i;

	size = OSAL_ARRAY_SIZE(ecore_dcbx_app_update);

	DP_INFO(p_hwfn, "DCBX negotiated: %d\n", p_data->dcbx_enabled);

	for (i = 0; i < size; i++) {
		id = ecore_dcbx_app_update[i].id;
		name = ecore_dcbx_app_update[i].name;

		enable = p_data->arr[id].enable;
		update = p_data->arr[id].update;
		tc = p_data->arr[id].tc;
		prio = p_data->arr[id].priority;

		DP_INFO(p_hwfn,
			"%s info: update %d, enable %d, prio %d, tc %d, num_tc %d\n",
			name, update, enable, prio, tc, p_info->num_tc);
	}
}

static void
ecore_dcbx_set_pf_tcs(struct ecore_hw_info *p_info,
		      u8 tc, enum ecore_pci_personality personality)
{
	/* QM reconf data */
	if (p_info->personality == personality) {
		if (personality == ECORE_PCI_ETH)
			p_info->non_offload_tc = tc;
		else
			p_info->offload_tc = tc;
	}
}

void
ecore_dcbx_set_params(struct ecore_dcbx_results *p_data,
		      struct ecore_hw_info *p_info,
		      bool enable, bool update, u8 prio, u8 tc,
		      enum dcbx_protocol_type type,
		      enum ecore_pci_personality personality)
{
	/* PF update ramrod data */
	p_data->arr[type].update = update;
	p_data->arr[type].enable = enable;
	p_data->arr[type].priority = prio;
	p_data->arr[type].tc = tc;

	ecore_dcbx_set_pf_tcs(p_info, tc, personality);
}

/* Update app protocol data and hw_info fields with the TLV info */
static void
ecore_dcbx_update_app_info(struct ecore_dcbx_results *p_data,
			   struct ecore_hwfn *p_hwfn,
			   bool enable, bool update, u8 prio, u8 tc,
			   enum dcbx_protocol_type type)
{
	struct ecore_hw_info *p_info = &p_hwfn->hw_info;
	enum ecore_pci_personality personality;
	enum dcbx_protocol_type id;
	const char *name;	/* @DPDK */
	u8 size;
	int i;

	size = OSAL_ARRAY_SIZE(ecore_dcbx_app_update);

	for (i = 0; i < size; i++) {
		id = ecore_dcbx_app_update[i].id;

		if (type != id)
			continue;

		personality = ecore_dcbx_app_update[i].personality;
		name = ecore_dcbx_app_update[i].name;

		ecore_dcbx_set_params(p_data, p_info, enable, update,
				      prio, tc, type, personality);
	}
}

static enum _ecore_status_t
ecore_dcbx_get_app_priority(u8 pri_bitmap, u8 *priority)
{
	u32 pri_mask, pri = ECORE_MAX_PFC_PRIORITIES;
	u32 index = ECORE_MAX_PFC_PRIORITIES - 1;
	enum _ecore_status_t rc = ECORE_SUCCESS;

	/* Bitmap 1 corresponds to priority 0, return priority 0 */
	if (pri_bitmap == 1) {
		*priority = 0;
		return rc;
	}

	/* Choose the highest priority */
	while ((pri == ECORE_MAX_PFC_PRIORITIES) && index) {
		pri_mask = 1 << index;
		if (pri_bitmap & pri_mask)
			pri = index;
		index--;
	}

	if (pri < ECORE_MAX_PFC_PRIORITIES)
		*priority = (u8)pri;
	else
		rc = ECORE_INVAL;

	return rc;
}

static bool
ecore_dcbx_get_app_protocol_type(struct ecore_hwfn *p_hwfn,
				 u32 app_prio_bitmap, u16 id, int *type)
{
	bool status = false;

	if (ecore_dcbx_default_tlv(app_prio_bitmap, id)) {
		*type = DCBX_PROTOCOL_ETH;
		status = true;
	} else {
		DP_ERR(p_hwfn, "Unsupported protocol %d\n", id);
	}

	return status;
}

/*  Parse app TLV's to update TC information in hw_info structure for
 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
 */
static enum _ecore_status_t
ecore_dcbx_process_tlv(struct ecore_hwfn *p_hwfn,
		       struct ecore_dcbx_results *p_data,
		       struct dcbx_app_priority_entry *p_tbl, u32 pri_tc_tbl,
		       int count, bool dcbx_enabled)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;
	u8 tc, priority, priority_map;
	int i, type = -1;
	u16 protocol_id;
	bool enable;

	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB, "Num APP entries = %d\n", count);

	/* Parse APP TLV */
	for (i = 0; i < count; i++) {
		protocol_id = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
						  DCBX_APP_PROTOCOL_ID);
		priority_map = ECORE_MFW_GET_FIELD(p_tbl[i].entry,
						   DCBX_APP_PRI_MAP);
		rc = ecore_dcbx_get_app_priority(priority_map, &priority);
		if (rc == ECORE_INVAL) {
			DP_ERR(p_hwfn, "Invalid priority\n");
			return rc;
		}

		tc = ECORE_DCBX_PRIO2TC(pri_tc_tbl, priority);
		if (ecore_dcbx_get_app_protocol_type(p_hwfn, p_tbl[i].entry,
						     protocol_id, &type)) {
			/* ETH always have the enable bit reset, as it gets
			 * vlan information per packet. For other protocols,
			 * should be set according to the dcbx_enabled
			 * indication, but we only got here if there was an
			 * app tlv for the protocol, so dcbx must be enabled.
			 */
			enable = (type == DCBX_PROTOCOL_ETH ? false : true);

			ecore_dcbx_update_app_info(p_data, p_hwfn, enable, true,
						   priority, tc, type);
		}
	}
	/* Update ramrod protocol data and hw_info fields
	 * with default info when corresponding APP TLV's are not detected.
	 * The enabled field has a different logic for ethernet as only for
	 * ethernet dcb should disabled by default, as the information arrives
	 * from the OS (unless an explicit app tlv was present).
	 */
	tc = p_data->arr[DCBX_PROTOCOL_ETH].tc;
	priority = p_data->arr[DCBX_PROTOCOL_ETH].priority;
	for (type = 0; type < DCBX_MAX_PROTOCOL_TYPE; type++) {
		if (p_data->arr[type].update)
			continue;

		enable = (type == DCBX_PROTOCOL_ETH) ? false : dcbx_enabled;
		ecore_dcbx_update_app_info(p_data, p_hwfn, enable, true,
					   priority, tc, type);
	}

	return ECORE_SUCCESS;
}

/* Parse app TLV's to update TC information in hw_info structure for
 * reconfiguring QM. Get protocol specific data for PF update ramrod command.
 */
static enum _ecore_status_t
ecore_dcbx_process_mib_info(struct ecore_hwfn *p_hwfn)
{
	struct dcbx_app_priority_feature *p_app;
	enum _ecore_status_t rc = ECORE_SUCCESS;
	struct ecore_dcbx_results data = { 0 };
	struct dcbx_app_priority_entry *p_tbl;
	struct dcbx_ets_feature *p_ets;
	struct ecore_hw_info *p_info;
	u32 pri_tc_tbl, flags;
	bool dcbx_enabled;
	int num_entries;

	/* If DCBx version is non zero, then negotiation was
	 * successfuly performed
	 */
	flags = p_hwfn->p_dcbx_info->operational.flags;
	dcbx_enabled = ECORE_MFW_GET_FIELD(flags, DCBX_CONFIG_VERSION) != 0;

	p_app = &p_hwfn->p_dcbx_info->operational.features.app;
	p_tbl = p_app->app_pri_tbl;

	p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
	pri_tc_tbl = p_ets->pri_tc_tbl[0];

	p_info = &p_hwfn->hw_info;
	num_entries = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_NUM_ENTRIES);

	rc = ecore_dcbx_process_tlv(p_hwfn, &data, p_tbl, pri_tc_tbl,
				    num_entries, dcbx_enabled);
	if (rc != ECORE_SUCCESS)
		return rc;

	p_info->num_tc = ECORE_MFW_GET_FIELD(p_ets->flags, DCBX_ETS_MAX_TCS);
	data.pf_id = p_hwfn->rel_pf_id;
	data.dcbx_enabled = dcbx_enabled;

	ecore_dcbx_dp_protocol(p_hwfn, &data);

	OSAL_MEMCPY(&p_hwfn->p_dcbx_info->results, &data,
		    sizeof(struct ecore_dcbx_results));

	return ECORE_SUCCESS;
}

static enum _ecore_status_t
ecore_dcbx_copy_mib(struct ecore_hwfn *p_hwfn,
		    struct ecore_ptt *p_ptt,
		    struct ecore_dcbx_mib_meta_data *p_data,
		    enum ecore_mib_read_type type)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;
	u32 prefix_seq_num, suffix_seq_num;
	int read_count = 0;

	do {
		if (type == ECORE_DCBX_REMOTE_LLDP_MIB) {
			ecore_memcpy_from(p_hwfn, p_ptt, p_data->lldp_remote,
					  p_data->addr, p_data->size);
			prefix_seq_num = p_data->lldp_remote->prefix_seq_num;
			suffix_seq_num = p_data->lldp_remote->suffix_seq_num;
		} else {
			ecore_memcpy_from(p_hwfn, p_ptt, p_data->mib,
					  p_data->addr, p_data->size);
			prefix_seq_num = p_data->mib->prefix_seq_num;
			suffix_seq_num = p_data->mib->suffix_seq_num;
		}
		read_count++;

		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
			   "mib type = %d, try count = %d prefix seq num  = %d suffix seq num = %d\n",
			   type, read_count, prefix_seq_num, suffix_seq_num);
	} while ((prefix_seq_num != suffix_seq_num) &&
		 (read_count < ECORE_DCBX_MAX_MIB_READ_TRY));

	if (read_count >= ECORE_DCBX_MAX_MIB_READ_TRY) {
		DP_ERR(p_hwfn,
		       "MIB read err, mib type = %d, try count = %d prefix seq num = %d suffix seq num = %d\n",
		       type, read_count, prefix_seq_num, suffix_seq_num);
		rc = ECORE_IO;
	}

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_get_priority_info(struct ecore_hwfn *p_hwfn,
			     struct ecore_dcbx_app_prio *p_prio,
			     struct ecore_dcbx_results *p_results)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;

	if (p_results->arr[DCBX_PROTOCOL_ETH].update &&
	    p_results->arr[DCBX_PROTOCOL_ETH].enable) {
		p_prio->eth = p_results->arr[DCBX_PROTOCOL_ETH].priority;
		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
			   "Priority: eth %d\n", p_prio->eth);
	}

	return rc;
}

static void
ecore_dcbx_get_app_data(struct ecore_hwfn *p_hwfn,
			struct dcbx_app_priority_feature *p_app,
			struct dcbx_app_priority_entry *p_tbl,
			struct ecore_dcbx_params *p_params)
{
	int i;

	p_params->app_willing = ECORE_MFW_GET_FIELD(p_app->flags,
						    DCBX_APP_WILLING);
	p_params->app_valid = ECORE_MFW_GET_FIELD(p_app->flags,
						  DCBX_APP_ENABLED);
	p_params->num_app_entries = ECORE_MFW_GET_FIELD(p_app->flags,
							DCBX_APP_ENABLED);
	for (i = 0; i < DCBX_MAX_APP_PROTOCOL; i++)
		p_params->app_bitmap[i] = p_tbl[i].entry;

	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
		   "APP params: willing %d, valid %d\n",
		   p_params->app_willing, p_params->app_valid);
}

static void
ecore_dcbx_get_pfc_data(struct ecore_hwfn *p_hwfn,
			u32 pfc, struct ecore_dcbx_params *p_params)
{
	p_params->pfc_willing = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_WILLING);
	p_params->max_pfc_tc = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_CAPS);
	p_params->pfc_enabled = ECORE_MFW_GET_FIELD(pfc, DCBX_PFC_ENABLED);
	p_params->pfc_bitmap = pfc;

	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
		   "PFC params: willing %d, pfc_bitmap %d\n",
		   p_params->pfc_willing, p_params->pfc_bitmap);
}

static void
ecore_dcbx_get_ets_data(struct ecore_hwfn *p_hwfn,
			struct dcbx_ets_feature *p_ets,
			struct ecore_dcbx_params *p_params)
{
	int i;

	p_params->ets_willing = ECORE_MFW_GET_FIELD(p_ets->flags,
						    DCBX_ETS_WILLING);
	p_params->ets_enabled = ECORE_MFW_GET_FIELD(p_ets->flags,
						    DCBX_ETS_ENABLED);
	p_params->max_ets_tc = ECORE_MFW_GET_FIELD(p_ets->flags,
						   DCBX_ETS_MAX_TCS);
	p_params->ets_pri_tc_tbl[0] = p_ets->pri_tc_tbl[0];

	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
		   "ETS params: willing %d, pri_tc_tbl_0 %x max_ets_tc %d\n",
		   p_params->ets_willing, p_params->ets_pri_tc_tbl[0],
		   p_params->max_ets_tc);

	/* 8 bit tsa and bw data corresponding to each of the 8 TC's are
	 * encoded in a type u32 array of size 2.
	 */
	for (i = 0; i < 2; i++) {
		p_params->ets_tc_tsa_tbl[i] = p_ets->tc_tsa_tbl[i];
		p_params->ets_tc_bw_tbl[i] = p_ets->tc_bw_tbl[i];

		DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
			   "elem %d  bw_tbl %x tsa_tbl %x\n",
			   i, p_params->ets_tc_bw_tbl[i],
			   p_params->ets_tc_tsa_tbl[i]);
	}
}

static enum _ecore_status_t
ecore_dcbx_get_common_params(struct ecore_hwfn *p_hwfn,
			     struct dcbx_app_priority_feature *p_app,
			     struct dcbx_app_priority_entry *p_tbl,
			     struct dcbx_ets_feature *p_ets,
			     u32 pfc, struct ecore_dcbx_params *p_params)
{
	ecore_dcbx_get_app_data(p_hwfn, p_app, p_tbl, p_params);
	ecore_dcbx_get_ets_data(p_hwfn, p_ets, p_params);
	ecore_dcbx_get_pfc_data(p_hwfn, pfc, p_params);

	return ECORE_SUCCESS;
}

static enum _ecore_status_t
ecore_dcbx_get_local_params(struct ecore_hwfn *p_hwfn,
			    struct ecore_ptt *p_ptt,
			    struct ecore_dcbx_get *params)
{
	struct ecore_dcbx_admin_params *p_local;
	struct dcbx_app_priority_feature *p_app;
	struct dcbx_app_priority_entry *p_tbl;
	struct ecore_dcbx_params *p_data;
	struct dcbx_ets_feature *p_ets;
	u32 pfc;

	p_local = &params->local;
	p_data = &p_local->params;
	p_app = &p_hwfn->p_dcbx_info->local_admin.features.app;
	p_tbl = p_app->app_pri_tbl;
	p_ets = &p_hwfn->p_dcbx_info->local_admin.features.ets;
	pfc = p_hwfn->p_dcbx_info->local_admin.features.pfc;

	ecore_dcbx_get_common_params(p_hwfn, p_app, p_tbl, p_ets, pfc, p_data);
	p_local->valid = true;

	return ECORE_SUCCESS;
}

static enum _ecore_status_t
ecore_dcbx_get_remote_params(struct ecore_hwfn *p_hwfn,
			     struct ecore_ptt *p_ptt,
			     struct ecore_dcbx_get *params)
{
	struct ecore_dcbx_remote_params *p_remote;
	struct dcbx_app_priority_feature *p_app;
	struct dcbx_app_priority_entry *p_tbl;
	struct ecore_dcbx_params *p_data;
	struct dcbx_ets_feature *p_ets;
	u32 pfc;

	p_remote = &params->remote;
	p_data = &p_remote->params;
	p_app = &p_hwfn->p_dcbx_info->remote.features.app;
	p_tbl = p_app->app_pri_tbl;
	p_ets = &p_hwfn->p_dcbx_info->remote.features.ets;
	pfc = p_hwfn->p_dcbx_info->remote.features.pfc;

	ecore_dcbx_get_common_params(p_hwfn, p_app, p_tbl, p_ets, pfc, p_data);
	p_remote->valid = true;

	return ECORE_SUCCESS;
}

static enum _ecore_status_t
ecore_dcbx_get_operational_params(struct ecore_hwfn *p_hwfn,
				  struct ecore_ptt *p_ptt,
				  struct ecore_dcbx_get *params)
{
	struct ecore_dcbx_operational_params *p_operational;
	enum _ecore_status_t rc = ECORE_SUCCESS;
	struct dcbx_app_priority_feature *p_app;
	struct dcbx_app_priority_entry *p_tbl;
	struct ecore_dcbx_results *p_results;
	struct ecore_dcbx_params *p_data;
	struct dcbx_ets_feature *p_ets;
	bool enabled, err;
	u32 pfc, flags;

	flags = p_hwfn->p_dcbx_info->operational.flags;

	/* If DCBx version is non zero, then negotiation
	 * was successfuly performed
	 */
	p_operational = &params->operational;
	enabled = ecore_dcbx_enabled(flags);
	if (!enabled) {
		p_operational->enabled = enabled;
		p_operational->valid = false;
		return ECORE_INVAL;
	}

	p_data = &p_operational->params;
	p_results = &p_hwfn->p_dcbx_info->results;
	p_app = &p_hwfn->p_dcbx_info->operational.features.app;
	p_tbl = p_app->app_pri_tbl;
	p_ets = &p_hwfn->p_dcbx_info->operational.features.ets;
	pfc = p_hwfn->p_dcbx_info->operational.features.pfc;

	p_operational->ieee = ecore_dcbx_ieee(flags);
	p_operational->cee = ecore_dcbx_cee(flags);

	DP_VERBOSE(p_hwfn, ECORE_MSG_DCB,
		   "Version support: ieee %d, cee %d\n",
		   p_operational->ieee, p_operational->cee);

	ecore_dcbx_get_common_params(p_hwfn, p_app, p_tbl, p_ets, pfc, p_data);
	ecore_dcbx_get_priority_info(p_hwfn, &p_operational->app_prio,
				     p_results);
	err = ECORE_MFW_GET_FIELD(p_app->flags, DCBX_APP_ERROR);
	p_operational->err = err;
	p_operational->enabled = enabled;
	p_operational->valid = true;

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_get_local_lldp_params(struct ecore_hwfn *p_hwfn,
				 struct ecore_ptt *p_ptt,
				 struct ecore_dcbx_get *params)
{
	struct ecore_dcbx_lldp_local *p_local;
	osal_size_t size;
	u32 *dest;

	p_local = &params->lldp_local;

	size = OSAL_ARRAY_SIZE(p_local->local_chassis_id);
	dest = p_hwfn->p_dcbx_info->get.lldp_local.local_chassis_id;
	OSAL_MEMCPY(dest, p_local->local_chassis_id, size);

	size = OSAL_ARRAY_SIZE(p_local->local_port_id);
	dest = p_hwfn->p_dcbx_info->get.lldp_local.local_port_id;
	OSAL_MEMCPY(dest, p_local->local_port_id, size);

	return ECORE_SUCCESS;
}

static enum _ecore_status_t
ecore_dcbx_get_remote_lldp_params(struct ecore_hwfn *p_hwfn,
				  struct ecore_ptt *p_ptt,
				  struct ecore_dcbx_get *params)
{
	struct ecore_dcbx_lldp_remote *p_remote;
	osal_size_t size;
	u32 *dest;

	p_remote = &params->lldp_remote;

	size = OSAL_ARRAY_SIZE(p_remote->peer_chassis_id);
	dest = p_hwfn->p_dcbx_info->get.lldp_remote.peer_chassis_id;
	OSAL_MEMCPY(dest, p_remote->peer_chassis_id, size);

	size = OSAL_ARRAY_SIZE(p_remote->peer_port_id);
	dest = p_hwfn->p_dcbx_info->get.lldp_remote.peer_port_id;
	OSAL_MEMCPY(dest, p_remote->peer_port_id, size);

	return ECORE_SUCCESS;
}

static enum _ecore_status_t
ecore_dcbx_get_params(struct ecore_hwfn *p_hwfn,
		      struct ecore_ptt *p_ptt, enum ecore_mib_read_type type)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;
	struct ecore_dcbx_get *p_params;

	p_params = &p_hwfn->p_dcbx_info->get;

	switch (type) {
	case ECORE_DCBX_REMOTE_MIB:
		ecore_dcbx_get_remote_params(p_hwfn, p_ptt, p_params);
		break;
	case ECORE_DCBX_LOCAL_MIB:
		ecore_dcbx_get_local_params(p_hwfn, p_ptt, p_params);
		break;
	case ECORE_DCBX_OPERATIONAL_MIB:
		ecore_dcbx_get_operational_params(p_hwfn, p_ptt, p_params);
		break;
	case ECORE_DCBX_REMOTE_LLDP_MIB:
		rc = ecore_dcbx_get_remote_lldp_params(p_hwfn, p_ptt, p_params);
		break;
	case ECORE_DCBX_LOCAL_LLDP_MIB:
		rc = ecore_dcbx_get_local_lldp_params(p_hwfn, p_ptt, p_params);
		break;
	default:
		DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
		return ECORE_INVAL;
	}

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_read_local_lldp_mib(struct ecore_hwfn *p_hwfn,
			       struct ecore_ptt *p_ptt)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;
	struct ecore_dcbx_mib_meta_data data;

	data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
							   lldp_config_params);
	data.lldp_local = p_hwfn->p_dcbx_info->lldp_local;
	data.size = sizeof(struct lldp_config_params_s);
	ecore_memcpy_from(p_hwfn, p_ptt, data.lldp_local, data.addr, data.size);

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_read_remote_lldp_mib(struct ecore_hwfn *p_hwfn,
				struct ecore_ptt *p_ptt,
				enum ecore_mib_read_type type)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;
	struct ecore_dcbx_mib_meta_data data;

	data.addr = p_hwfn->mcp_info->port_addr + offsetof(struct public_port,
							   lldp_status_params);
	data.lldp_remote = p_hwfn->p_dcbx_info->lldp_remote;
	data.size = sizeof(struct lldp_status_params_s);
	rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_read_operational_mib(struct ecore_hwfn *p_hwfn,
				struct ecore_ptt *p_ptt,
				enum ecore_mib_read_type type)
{
	struct ecore_dcbx_mib_meta_data data;
	enum _ecore_status_t rc = ECORE_SUCCESS;

	data.addr = p_hwfn->mcp_info->port_addr +
	    offsetof(struct public_port, operational_dcbx_mib);
	data.mib = &p_hwfn->p_dcbx_info->operational;
	data.size = sizeof(struct dcbx_mib);
	rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_read_remote_mib(struct ecore_hwfn *p_hwfn,
			   struct ecore_ptt *p_ptt,
			   enum ecore_mib_read_type type)
{
	struct ecore_dcbx_mib_meta_data data;
	enum _ecore_status_t rc = ECORE_SUCCESS;

	data.addr = p_hwfn->mcp_info->port_addr +
	    offsetof(struct public_port, remote_dcbx_mib);
	data.mib = &p_hwfn->p_dcbx_info->remote;
	data.size = sizeof(struct dcbx_mib);
	rc = ecore_dcbx_copy_mib(p_hwfn, p_ptt, &data, type);

	return rc;
}

static enum _ecore_status_t
ecore_dcbx_read_local_mib(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt)
{
	struct ecore_dcbx_mib_meta_data data;
	enum _ecore_status_t rc = ECORE_SUCCESS;

	data.addr = p_hwfn->mcp_info->port_addr +
	    offsetof(struct public_port, local_admin_dcbx_mib);
	data.local_admin = &p_hwfn->p_dcbx_info->local_admin;
	data.size = sizeof(struct dcbx_local_params);
	ecore_memcpy_from(p_hwfn, p_ptt, data.local_admin,
			  data.addr, data.size);

	return rc;
}

static enum _ecore_status_t ecore_dcbx_read_mib(struct ecore_hwfn *p_hwfn,
						struct ecore_ptt *p_ptt,
						enum ecore_mib_read_type type)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;

	switch (type) {
	case ECORE_DCBX_OPERATIONAL_MIB:
		rc = ecore_dcbx_read_operational_mib(p_hwfn, p_ptt, type);
		break;
	case ECORE_DCBX_REMOTE_MIB:
		rc = ecore_dcbx_read_remote_mib(p_hwfn, p_ptt, type);
		break;
	case ECORE_DCBX_LOCAL_MIB:
		rc = ecore_dcbx_read_local_mib(p_hwfn, p_ptt);
		break;
	case ECORE_DCBX_REMOTE_LLDP_MIB:
		rc = ecore_dcbx_read_remote_lldp_mib(p_hwfn, p_ptt, type);
		break;
	case ECORE_DCBX_LOCAL_LLDP_MIB:
		rc = ecore_dcbx_read_local_lldp_mib(p_hwfn, p_ptt);
		break;
	default:
		DP_ERR(p_hwfn, "MIB read err, unknown mib type %d\n", type);
		return ECORE_INVAL;
	}

	return rc;
}

/*
 * Read updated MIB.
 * Reconfigure QM and invoke PF update ramrod command if operational MIB
 * change is detected.
 */
enum _ecore_status_t
ecore_dcbx_mib_update_event(struct ecore_hwfn *p_hwfn, struct ecore_ptt *p_ptt,
			    enum ecore_mib_read_type type)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;

	rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
	if (rc)
		return rc;

	if (type == ECORE_DCBX_OPERATIONAL_MIB) {
		rc = ecore_dcbx_process_mib_info(p_hwfn);
		if (!rc) {
			bool enabled;

			/* reconfigure tcs of QM queues according
			 * to negotiation results
			 */
			ecore_qm_reconf(p_hwfn, p_ptt);

			/* update storm FW with negotiation results */
			ecore_sp_pf_update(p_hwfn);

			/* set eagle enigne 1 flow control workaround
			 * according to negotiation results
			 */
			enabled = p_hwfn->p_dcbx_info->results.dcbx_enabled;
			ecore_dcbx_eagle_workaround(p_hwfn, p_ptt, enabled);
		}
	}
	ecore_dcbx_get_params(p_hwfn, p_ptt, type);
	OSAL_DCBX_AEN(p_hwfn, type);

	return rc;
}

enum _ecore_status_t ecore_dcbx_info_alloc(struct ecore_hwfn *p_hwfn)
{
	enum _ecore_status_t rc = ECORE_SUCCESS;

	p_hwfn->p_dcbx_info = OSAL_ZALLOC(p_hwfn->p_dev, GFP_KERNEL,
					  sizeof(struct ecore_dcbx_info));
	if (!p_hwfn->p_dcbx_info) {
		DP_NOTICE(p_hwfn, true,
			  "Failed to allocate `struct ecore_dcbx_info'");
		rc = ECORE_NOMEM;
	}

	return rc;
}

void ecore_dcbx_info_free(struct ecore_hwfn *p_hwfn,
			  struct ecore_dcbx_info *p_dcbx_info)
{
	OSAL_FREE(p_hwfn->p_dev, p_hwfn->p_dcbx_info);
}

static void ecore_dcbx_update_protocol_data(struct protocol_dcb_data *p_data,
					    struct ecore_dcbx_results *p_src,
					    enum dcbx_protocol_type type)
{
	p_data->dcb_enable_flag = p_src->arr[type].enable;
	p_data->dcb_priority = p_src->arr[type].priority;
	p_data->dcb_tc = p_src->arr[type].tc;
}

/* Set pf update ramrod command params */
void ecore_dcbx_set_pf_update_params(struct ecore_dcbx_results *p_src,
				     struct pf_update_ramrod_data *p_dest)
{
	struct protocol_dcb_data *p_dcb_data;
	bool update_flag;

	p_dest->pf_id = p_src->pf_id;

	update_flag = p_src->arr[DCBX_PROTOCOL_ETH].update;
	p_dest->update_eth_dcb_data_flag = update_flag;

	p_dcb_data = &p_dest->eth_dcb_data;
	ecore_dcbx_update_protocol_data(p_dcb_data, p_src, DCBX_PROTOCOL_ETH);
}

static
enum _ecore_status_t ecore_dcbx_query(struct ecore_hwfn *p_hwfn,
				      enum ecore_mib_read_type type)
{
	struct ecore_ptt *p_ptt;
	enum _ecore_status_t rc;

	p_ptt = ecore_ptt_acquire(p_hwfn);
	if (!p_ptt) {
		rc = ECORE_TIMEOUT;
		DP_ERR(p_hwfn, "rc = %d\n", rc);
		return rc;
	}

	rc = ecore_dcbx_read_mib(p_hwfn, p_ptt, type);
	if (rc != ECORE_SUCCESS)
		goto out;

	rc = ecore_dcbx_get_params(p_hwfn, p_ptt, type);

out:
	ecore_ptt_release(p_hwfn, p_ptt);
	return rc;
}

enum _ecore_status_t ecore_dcbx_query_params(struct ecore_hwfn *p_hwfn,
					     struct ecore_dcbx_get *p_get,
					     enum ecore_mib_read_type type)
{
	enum _ecore_status_t rc;

	rc = ecore_dcbx_query(p_hwfn, type);
	if (rc)
		return rc;

	if (p_get != OSAL_NULL)
		OSAL_MEMCPY(p_get, &p_hwfn->p_dcbx_info->get,
			    sizeof(struct ecore_dcbx_get));

	return rc;
}