summaryrefslogtreecommitdiff
path: root/iscsiuio/src/unix/libs/bnx2x.c
blob: 0e326d4c949a057b29dd63f66824ff1b5858045c (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
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
/*
 * Copyright (c) 2009-2011, Broadcom Corporation
 * Copyright (c) 2014, QLogic Corporation
 *
 * Written by:  Benjamin Li  (benli@broadcom.com)
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. All advertising materials mentioning features or use of this software
 *    must display the following acknowledgement:
 *      This product includes software developed by Adam Dunkels.
 * 4. The name of the author may not be used to endorse or promote
 *    products derived from this software without specific prior
 *    written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * bnx2x.c - bnx2x user space driver
 *
 */

/* include nic.h before linux/ethtool.h to avoid redefinitions of
 * eth structs
*/
#include "nic.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <arpa/inet.h>
#include <linux/types.h>	/* Needed for linux/ethtool.h on RHEL 5.x */
#include <linux/sockios.h>
#include <linux/ethtool.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/user.h>
#include <fcntl.h>
#include <unistd.h>

#include "config.h"

#include "build_date.h"
#include "bnx2x.h"
#include "cnic.h"
#include "logger.h"
#include "nic_id.h"
#include "nic_utils.h"
#include "options.h"

#define PFX	"bnx2x "

/*  Foward struct declarations */
struct nic_ops bnx2x_op;

/*******************************************************************************
 * NIC Library Strings
 ******************************************************************************/
static const char library_name[] = "bnx2x";
static const char library_version[] = PACKAGE_VERSION;
static const char library_uio_name[] = "bnx2x_cnic";

/*  The name that should be returned from /sys/class/uio/uio0/name */
static const char cnic_uio_sysfs_name_tempate[] = "/sys/class/uio/uio%i/name";
static const char bnx2x_uio_sysfs_name[] = "bnx2x_cnic";

/*******************************************************************************
 * String constants used to display human readable adapter name
 ******************************************************************************/
static const char brcm_57710[] = "QLogic NetXtreme II BCM57710 10-Gigabit";
static const char brcm_57711[] = "QLogic NetXtreme II BCM57711 10-Gigabit";
static const char brcm_57711e[] = "QLogic NetXtreme II BCM57711E 10-Gigabit";
static const char brcm_57712[] = "QLogic NetXtreme II BCM57712 10-Gigabit";
static const char brcm_57712_MF[] = "QLogic NetXtreme II BCM57712 MF "
				    "10-Gigabit";
static const char brcm_57712_VF[] = "QLogic NetXtreme II BCM57712 VF "
				    "10-Gigabit";
static const char brcm_57713[] = "QLogic NetXtreme II BCM57713 10-Gigabit";
static const char brcm_57713e[] = "QLogic NetXtreme II BCM57713E 10-Gigabit";
static const char brcm_57800[] = "QLogic NetXtreme II BCM57800 10-Gigabit";
static const char brcm_57800_MF[] = "QLogic NetXtreme II BCM57800 MF "
				    "10-Gigabit";
static const char brcm_57800_VF[] = "QLogic NetXtreme II BCM57800 VF "
				    "10-Gigabit";
static const char brcm_57810[] = "QLogic NetXtreme II BCM57810 10-Gigabit";
static const char brcm_57810_MF[] = "QLogic NetXtreme II BCM57810 MF "
				    "10-Gigabit";
static const char brcm_57810_VF[] = "QLogic NetXtreme II BCM57810 VF "
				    "10-Gigabit";
static const char brcm_57811[] = "QLogic NetXtreme II BCM57811 10-Gigabit";
static const char brcm_57811_MF[] = "QLogic NetXtreme II BCM57811 MF "
				    "10-Gigabit";
static const char brcm_57811_VF[] = "QLogic NetXtreme II BCM57811 VF "
				    "10-Gigabit";
static const char brcm_57840[] = "QLogic NetXtreme II BCM57840 10-Gigabit";
static const char brcm_57840_MF[] = "QLogic NetXtreme II BCM57840 MF "
				    "10-Gigabit";
static const char brcm_57840_VF[] = "QLogic NetXtreme II BCM57840 VF "
				    "10-Gigabit";
static const char brcm_57840_4_10[] = "QLogic NetXtreme II BCM57840 4x"
				      "10-Gigabit";
static const char brcm_57840_2_20[] = "QLogic NetXtreme II BCM57840 2x"
				      "20-Gigabit";

/*******************************************************************************
 * PCI ID constants
 ******************************************************************************/
#define PCI_VENDOR_ID_BROADCOM			0x14e4
#define PCI_VENDOR_ID_QLOGIC			0x1077
#define PCI_DEVICE_ID_NX2_57710			0x164e
#define PCI_DEVICE_ID_NX2_57711			0x164f
#define PCI_DEVICE_ID_NX2_57711E		0x1650
#define PCI_DEVICE_ID_NX2_57712			0x1662
#define PCI_DEVICE_ID_NX2_57712_MF		0x1663
#define PCI_DEVICE_ID_NX2_57712_VF		0x166f
#define PCI_DEVICE_ID_NX2_57713			0x1651
#define PCI_DEVICE_ID_NX2_57713E		0x1652
#define PCI_DEVICE_ID_NX2_57800			0x168a
#define PCI_DEVICE_ID_NX2_57800_MF		0x16a5
#define PCI_DEVICE_ID_NX2_57800_VF		0x16a9
#define PCI_DEVICE_ID_NX2_57810			0x168e
#define PCI_DEVICE_ID_NX2_57810_MF		0x16ae
#define PCI_DEVICE_ID_NX2_57810_VF		0x16af
#define PCI_DEVICE_ID_NX2_57811			0x163d
#define PCI_DEVICE_ID_NX2_57811_MF		0x163e
#define PCI_DEVICE_ID_NX2_57811_VF		0x163f
#define PCI_DEVICE_ID_NX2_57840_OBSOLETE	0x168d
#define PCI_DEVICE_ID_NX2_57840_MF_OBSOLETE	0x16ab
#define PCI_DEVICE_ID_NX2_57840_4_10		0x16a1
#define PCI_DEVICE_ID_NX2_57840_2_20		0x16a2
#define PCI_DEVICE_ID_NX2_57840_MF		0x16a4
#define PCI_DEVICE_ID_NX2_57840_VF		0x16ad
#define PCI_ANY_ID (~0)

/*  This is the table used to match PCI vendor and device ID's to the
 *  human readable string names of the devices */
static const struct pci_device_id bnx2x_pci_tbl[] = {
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57710,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57710},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57711},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57711E,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57711e},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57712,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57712},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57712_MF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57712_MF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57712_VF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57712_VF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57713,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57713},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57713E,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57713e},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57800,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57800},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57800_MF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57800_MF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57800_VF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57800_VF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57810,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57810},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57810_MF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57810_MF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57810_VF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57810_VF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57811,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57811},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57811_MF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57811_MF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57811_VF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57811_VF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840_OBSOLETE,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840_MF_OBSOLETE,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_MF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840_4_10,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_4_10},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840_2_20,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_2_20},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840_MF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_MF},
	{PCI_VENDOR_ID_BROADCOM, PCI_DEVICE_ID_NX2_57840_VF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_VF},
	{PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_NX2_57840_4_10,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_4_10},
	{PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_NX2_57840_2_20,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_2_20},
	{PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_NX2_57840_MF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_MF},
	{PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_NX2_57840_VF,
	 PCI_ANY_ID, PCI_ANY_ID, brcm_57840_VF},
};

static struct iro e1_iro[2] = {
	{0x45a0, 0x90, 0x8, 0x0, 0x8},	/* T6.0 */
	{0x50c8, 0x90, 0x8, 0x0, 0x8},	/* T6.4 */
};

static struct iro e1h_iro[2] = {
	{0x1c40, 0xe0, 0x8, 0x0, 0x8},	/* T6.0 */
	{0x1e00, 0xe0, 0x8, 0x0, 0x8},	/* T6.4 */
};

static struct iro e2_iro[2] = {
	{0x6000, 0x20, 0x0, 0x0, 0x8},	/* T6.0 */
	{0x6000, 0x20, 0x0, 0x0, 0x8},	/* T6.4 */
};

struct bnx2x_driver_version bnx2x_version = {
	BNX2X_UNKNOWN_MAJOR_VERSION,
	BNX2X_UNKNOWN_MINOR_VERSION,
	BNX2X_UNKNOWN_SUB_MINOR_VERSION,
};

static int bnx2x_clear_tx_intr(nic_t *nic);

/*******************************************************************************
 * BNX2X Library Functions
 ******************************************************************************/
/**
 *  bnx2x_get_library_name() - Used to get the name of this NIC libary
 *  @param name - This function will return the pointer to this NIC
 *                library name
 *  @param name_size
 */
static void bnx2x_get_library_name(char **name, size_t *name_size)
{
	*name = (char *)library_name;
	*name_size = sizeof(library_name);
}

/**
 *  bnx2x_get_library_version() - Used to get the version string of this
 *                                NIC libary
 *  @param version - This function will return the pointer to this NIC
 *                   library version string
 *  @param version_size - This will be set with the version size
 */
static void bnx2x_get_library_version(char **version, size_t *version_size)
{
	*version = (char *)library_version;
	*version_size = sizeof(library_version);
}

/**
 *  bnx2x_get_build_date() - Used to get the build date string of this library
 *  @param version - This function will return the pointer to this NIC
 *                   library build date string
 *  @param version_size - This will be set with the build date string size
 */
static void bnx2x_get_build_date(char **build, size_t *build_size)
{
	*build = (char *)build_date;
	*build_size = sizeof(build_date);
}

/**
 *  bnx2x_get_transport_name() - Used to get the transport name associated
 *                              with this this NIC libary
 *  @param transport_name - This function will return the pointer to this NIC
 *                          library's associated transport string
 *  @param transport_name_size - This will be set with the transport name size
 */
static void bnx2x_get_transport_name(char **transport_name,
				     size_t *transport_name_size)
{
	*transport_name = (char *)bnx2i_library_transport_name;
	*transport_name_size = bnx2i_library_transport_name_size;
}

/**
 *  bnx2x_get_uio_name() - Used to get the uio name associated with this this
 *                        NIC libary
 *  @param uio_name - This function will return the pointer to this NIC
 *                    library's associated uio string
 *  @param transport_name_size - This will be set with the uio name size
 */
static void bnx2x_get_uio_name(char **uio_name, size_t *uio_name_size)
{
	*uio_name = (char *)library_uio_name;
	*uio_name_size = sizeof(library_uio_name);
}

/**
 *  bnx2x_get_pci_table() - Used to get the PCI table for this NIC libary to
 *			    determine which NIC's based off of PCI ID's are
 *			    supported
 *  @param table - This function will return the pointer to the PCI table
 *  @param entries - This function will return the number of entries in the NIC
 *                   library's PCI table
 */
static void bnx2x_get_pci_table(struct pci_device_id **table,
				uint32_t *entries)
{
	*table = (struct pci_device_id *)bnx2x_pci_tbl;
	*entries =
	    (uint32_t) (sizeof(bnx2x_pci_tbl) / sizeof(bnx2x_pci_tbl[0]));
}

/**
 *  bnx2x_get_ops() - Used to get the NIC library op table
 *  @param op - The op table of this NIC library
 */
struct nic_ops *bnx2x_get_ops()
{
	return &bnx2x_op;
}

/*******************************************************************************
 * bnx2x Utility Functions
 ******************************************************************************/
/*******************************************************************************
 * Utility Functions Used to read register from the bnx2x device
 ******************************************************************************/
static void bnx2x_set_drv_version_unknown(bnx2x_t *bp)
{
	bp->version.major = BNX2X_UNKNOWN_MAJOR_VERSION;
	bp->version.minor = BNX2X_UNKNOWN_MINOR_VERSION;
	bp->version.sub_minor = BNX2X_UNKNOWN_SUB_MINOR_VERSION;
}

/* Return: 1 = Unknown, 0 = Known */
static int bnx2x_is_drv_version_unknown(struct bnx2x_driver_version *version)
{
	if ((version->major == (uint16_t)BNX2X_UNKNOWN_MAJOR_VERSION) &&
	    (version->minor == (uint16_t)BNX2X_UNKNOWN_MINOR_VERSION) &&
	    (version->sub_minor == (uint16_t)BNX2X_UNKNOWN_SUB_MINOR_VERSION)) {
		return 1;
	}

	return 0;
}

/**
 * bnx2x_get_drv_version() - Used to determine the driver version
 * @param bp - Device used to determine bnx2x driver version
 */
static int bnx2x_get_drv_version(bnx2x_t *bp)
{
	nic_t *nic = bp->parent;
	int fd, rc;
	struct ifreq ifr;
	struct ethtool_drvinfo drvinfo;
	char *tok, *save_ptr = NULL;

	/* Setup our control structures. */
	memset(&ifr, 0, sizeof(ifr));
	strcpy(ifr.ifr_name, nic->eth_device_name);

	/* Open control socket. */
	fd = socket(AF_INET, SOCK_DGRAM, 0);
	if (fd < 0) {
		LOG_ERR(PFX "%s: Cannot get socket to determine version "
			"[0x%x %s]", nic->log_name, errno, strerror(errno));
		return -EIO;
	}

	memset(&drvinfo, 0, sizeof(drvinfo));
	drvinfo.cmd = ETHTOOL_GDRVINFO;
	ifr.ifr_data = (caddr_t) &drvinfo;
	rc = ioctl(fd, SIOCETHTOOL, &ifr);
	if (rc < 0) {
		LOG_ERR(PFX "%s: call to ethool IOCTL failed [0x%x %s]",
			nic->log_name, errno, strerror(errno));
		goto error;
	}

	tok = strtok_r(drvinfo.version, ".", &save_ptr);
	if (tok == NULL) {
		rc = -EIO;
		goto error;
	}
	bp->version.major = atoi(tok);

	tok = strtok_r(NULL, ".", &save_ptr);
	if (tok == NULL) {
		rc = -EIO;
		goto error;
	}
	bp->version.minor = atoi(tok);

	tok = strtok_r(NULL, ".", &save_ptr);
	if (tok == NULL) {
		rc = -EIO;
		goto error;
	}
	bp->version.sub_minor = atoi(tok);

	LOG_INFO(PFX "%s: bnx2x driver using version %d.%d.%d",
		 nic->log_name,
		 bp->version.major, bp->version.minor, bp->version.sub_minor);

	close(fd);

	return 0;

error:
	close(fd);
	bnx2x_set_drv_version_unknown(bp);

	LOG_ERR(PFX "%s: error parsing driver string: '%s'",
		nic->log_name, drvinfo.version);

	return rc;

}

static inline int bnx2x_is_ver70(bnx2x_t *bp)
{
	return (bp->version.major == 1 && bp->version.minor >= 70);
}

static inline int bnx2x_is_ver60(bnx2x_t *bp)
{
	return (bp->version.major == 1 && (bp->version.minor == 60 ||
					   bp->version.minor == 62 ||
					   bp->version.minor == 64));
}

static inline int bnx2x_is_ver60_plus(bnx2x_t *bp)
{
	return bnx2x_is_ver60(bp) || bnx2x_is_ver70(bp);
}

static inline int bnx2x_is_ver52(bnx2x_t *bp)
{
	return (bp->version.major == 1 && bp->version.minor == 52);
}

static void bnx2x_wr32(bnx2x_t *bp, __u32 off, __u32 val)
{
	*((volatile __u32 *)(bp->reg + off)) = val;
}

static void bnx2x_doorbell(bnx2x_t *bp, __u32 off, __u32 val)
{
	*((volatile __u32 *)(bp->reg2 + off)) = val;
}

static void bnx2x_flush_doorbell(bnx2x_t *bp, __u32 off)
{
	volatile __u32 tmp __attribute__((__unused__));

	barrier();
	tmp = *((volatile __u32 *)(bp->reg2 + off));
}

static __u32 bnx2x_rd32(bnx2x_t *bp, __u32 off)
{
	return *((volatile __u32 *)(bp->reg + off));
}

static int bnx2x_reg_sync(bnx2x_t *bp, __u32 off, __u16 length)
{
	return msync(bp->reg + off, length, MS_SYNC);
}

static void bnx2x_update_rx_prod(bnx2x_t *bp)
{
	struct ustorm_eth_rx_producers rx_prods = { 0 };
	int i;

	rx_prods.bd_prod = bp->rx_bd_prod;
	rx_prods.cqe_prod = bp->rx_prod;

	barrier();

	for (i = 0; i < sizeof(struct ustorm_eth_rx_producers) / 4; i++)
		bnx2x_wr32(bp, bp->rx_prod_io + i * 4,
			   ((__u32 *)&rx_prods)[i]);

	barrier();

	bnx2x_reg_sync(bp, bp->rx_prod_io,
		       sizeof(struct ustorm_eth_rx_producers));
}

/**
 * bnx2x_get_chip_id() - Used to retrive the chip ID from the nic
 * @param dev - Device used to determin NIC type
 * @return Chip ID read from the MISC ID register
 */
static int bnx2x_get_chip_id(bnx2x_t *bp)
{
	int val, id;

	/* Get the chip revision id and number. */
	/* chip num:16-31, rev:12-15, metal:4-11, bond_id:0-3 */
	val = bnx2x_rd32(bp, BNX2X_MISC_REG_CHIP_NUM);
	id = ((val & 0xffff) << 16);
	val = bnx2x_rd32(bp, BNX2X_MISC_REG_CHIP_REV);
	id |= ((val & 0xf) << 12);
	val = bnx2x_rd32(bp, BNX2X_MISC_REG_CHIP_METAL);
	id |= ((val & 0xff) << 4);
	val = bnx2x_rd32(bp, BNX2X_MISC_REG_BOND_ID);
	id |= (val & 0xf);

	return id;
}

/**
 *  bnx2x_uio_verify()
 *
 */
static int bnx2x_uio_verify(nic_t *nic)
{
	char *raw = NULL, *raw_tmp;
	uint32_t raw_size = 0;
	char temp_path[sizeof(cnic_uio_sysfs_name_tempate) + 8];
	int rc = 0;

	/*  Build the path to determine uio name */
	snprintf(temp_path, sizeof(temp_path),
		 cnic_uio_sysfs_name_tempate, nic->uio_minor);

	rc = capture_file(&raw, &raw_size, temp_path);
	if (rc != 0)
		goto error;

	/* sanitize name string by replacing newline with null termination */
	raw_tmp = raw;
	while (*raw_tmp != '\n')
		raw_tmp++;
	*raw_tmp = '\0';

	if (strncmp(raw, bnx2x_uio_sysfs_name,
		    sizeof(bnx2x_uio_sysfs_name)) != 0) {
		LOG_ERR(PFX "%s: uio names not equal: "
			"expecting %s got %s from %s",
			nic->log_name, bnx2x_uio_sysfs_name, raw, temp_path);
		rc = -EIO;
	}

	free(raw);

	LOG_INFO(PFX "%s: Verified is a cnic_uio device", nic->log_name);

error:
	return rc;
}

/*******************************************************************************
 * bnx2x Utility Functions to get to the hardware consumer indexes
 ******************************************************************************/
static __u16 bnx2x_get_rx(bnx2x_t *bp)
{
	struct host_def_status_block *sblk = bp->status_blk.def;
	__u16 rx_comp_cons;

	msync(sblk, sizeof(*sblk), MS_SYNC);
	rx_comp_cons =
	    sblk->u_def_status_block.
	    index_values[HC_INDEX_DEF_U_ETH_ISCSI_RX_CQ_CONS];
	if ((rx_comp_cons & BNX2X_MAX_RCQ_DESC_CNT(bp)) ==
	    BNX2X_MAX_RCQ_DESC_CNT(bp))
		rx_comp_cons++;

	return rx_comp_cons;
}

static __u16 bnx2x_get_rx_60(bnx2x_t *bp)
{
	struct host_sp_status_block *sblk = bp->status_blk.sp;
	__u16 rx_comp_cons;

	msync(sblk, sizeof(*sblk), MS_SYNC);
	rx_comp_cons =
	    sblk->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_RX_CQ_CONS];
	if ((rx_comp_cons & BNX2X_MAX_RCQ_DESC_CNT(bp)) ==
	    BNX2X_MAX_RCQ_DESC_CNT(bp))
		rx_comp_cons++;

	return rx_comp_cons;
}

static __u16 bnx2x_get_tx(bnx2x_t *bp)
{
	struct host_def_status_block *sblk = bp->status_blk.def;
	__u16 tx_cons;

	msync(sblk, sizeof(*sblk), MS_SYNC);
	tx_cons =
	    sblk->c_def_status_block.
	    index_values[HC_INDEX_DEF_C_ETH_ISCSI_CQ_CONS];

	return tx_cons;
}

static __u16 bnx2x_get_tx_60(bnx2x_t *bp)
{
	struct host_sp_status_block *sblk = bp->status_blk.sp;
	__u16 tx_cons;

	msync(sblk, sizeof(*sblk), MS_SYNC);
	tx_cons = sblk->sp_sb.index_values[HC_SP_INDEX_ETH_ISCSI_CQ_CONS];

	return tx_cons;
}

typedef enum {
	CNIC_VLAN_STRIPPING_ENABLED = 1,
	CNIC_VLAN_STRIPPING_DISABLED = 2,
} CNIC_VLAN_STRIPPING_MODE;

/**
 *  bnx2x_strip_vlan_enabled() - This will query the device to determine whether
 *                              VLAN tag stripping is enabled or not
 *  @param dev - device to check stripping or not
 *  @ return CNIC_VLAN_STRIPPING_ENABLED stripping is enabled
 *           CNIC_VLAN_STRIPPING_DISABLED stripping is not enabled
 */
static CNIC_VLAN_STRIPPING_MODE bnx2x_strip_vlan_enabled(bnx2x_t *bp)
{
	return CNIC_VLAN_STRIPPING_DISABLED;
}

/**
 *  bnx2x_free() - Used to free a bnx2x structure
 */
static void bnx2x_free(nic_t *nic)
{
	if (nic->priv)
		free(nic->priv);
	nic->priv = NULL;
}

/**
 *  bnx2x_alloc() - Used to allocate a bnx2x structure
 */
static bnx2x_t *bnx2x_alloc(nic_t *nic)
{
	bnx2x_t *bp = malloc(sizeof(*bp));

	if (bp == NULL) {
		LOG_ERR(PFX "%s: Could not allocate BNX2X space",
			nic->log_name);
		return NULL;
	}

	/*  Clear out the CNIC contents */
	memset(bp, 0, sizeof(*bp));

	bp->bar0_fd = INVALID_FD;
	bp->bar2_fd = INVALID_FD;

	bp->parent = nic;
	nic->priv = (void *)bp;

	bnx2x_set_drv_version_unknown(bp);

	return bp;
}

/**
 * bnx2x_open() - This will initialize all the hardware resources underneath
 *               a struct cnic_uio device
 * @param dev - The struct cnic_uio device to attach the hardware with
 * @return 0 on success, on failure a errno will be returned
 */
static int bnx2x_open(nic_t *nic)
{
	bnx2x_t *bp;
	struct stat uio_stat;
	int i, rc;
	__u32 val;
	int count;
	char sysfs_resc_path[80];
	uint32_t bus;
	uint32_t slot;
	uint32_t func;
	uint32_t mode;
	__u32 proto_offset;
	__u32 ovtag_offset;

	/*  Sanity Check: validate the parameters */
	if (nic == NULL) {
		LOG_ERR(PFX "nic == NULL");
		return -EINVAL;
	}

	if ((nic->priv) != NULL &&
	    (((bnx2x_t *) (nic->priv))->flags & BNX2X_OPENED)) {
		return 0;
	}

	bp = bnx2x_alloc(nic);
	if (bp == NULL)
		return -ENOMEM;

	if (bnx2x_is_drv_version_unknown(&bnx2x_version)) {
		/* If version is unknown, go read from ethtool */
		rc = bnx2x_get_drv_version(bp);
		if (rc)
			goto open_error;
	} else {
		/* Version is not unknown, just use it */
		bnx2x_version.major = bp->version.major;
		bnx2x_version.minor = bp->version.minor;
		bnx2x_version.sub_minor = bp->version.sub_minor;
	}

	count = 0;
	while ((nic->fd < 0) && count < 15) {
		/*  udev might not have created the file yet */
		pthread_mutex_unlock(&nic->nic_mutex);
		sleep(1);
		pthread_mutex_lock(&nic->nic_mutex);

		nic->fd = open(nic->uio_device_name, O_RDWR | O_NONBLOCK);
		if (nic->fd != INVALID_FD) {
			LOG_ERR(PFX "%s: uio device has been brought up "
				"via pid: %d on fd: %d",
				nic->uio_device_name, getpid(), nic->fd);

			rc = bnx2x_uio_verify(nic);
			if (rc != 0)
				continue;

			break;
		} else {
			LOG_WARN(PFX "%s: Could not open device: %s, [%s]",
				 nic->log_name, nic->uio_device_name,
				 strerror(errno));

			manually_trigger_uio_event(nic, nic->uio_minor);

			/*  udev might not have created the file yet */
			pthread_mutex_unlock(&nic->nic_mutex);
			sleep(1);
			pthread_mutex_lock(&nic->nic_mutex);

			count++;
		}
	}
	if (nic->fd == INVALID_FD) {
		LOG_ERR(PFX "%s: Could not open device: %s, [%s]",
			nic->log_name, nic->uio_device_name,
			strerror(errno));
		rc = errno;
		goto open_error;
	}
	if (fstat(nic->fd, &uio_stat) < 0) {
		LOG_ERR(PFX "%s: Could not fstat device", nic->log_name);
		rc = -ENODEV;
		goto open_error;
	}
	nic->uio_minor = minor(uio_stat.st_rdev);

	cnic_get_sysfs_pci_resource_path(nic, 0, sysfs_resc_path, 80);
	bp->bar0_fd = open(sysfs_resc_path, O_RDWR | O_SYNC);
	if (bp->bar0_fd < 0) {
		LOG_ERR(PFX "%s: Could not open %s", nic->log_name,
			sysfs_resc_path);
		rc = -ENODEV;
		goto open_error;
	}

	bp->reg = mmap(NULL, BNX2X_BAR_SIZE, PROT_READ | PROT_WRITE,
			MAP_SHARED, bp->bar0_fd, (off_t) 0);

	if (bp->reg == MAP_FAILED) {
		LOG_INFO(PFX "%s: Couldn't mmap BAR registers: %s",
			 nic->log_name, strerror(errno));
		bp->reg = NULL;
		rc = errno;
		goto open_error;
	}

	msync(bp->reg, BNX2X_BAR_SIZE, MS_SYNC);

	cnic_get_sysfs_pci_resource_path(nic, 2, sysfs_resc_path, 80);
	bp->bar2_fd = open(sysfs_resc_path, O_RDWR | O_SYNC);
	if (bp->bar2_fd < 0) {
		LOG_ERR(PFX "%s: Could not open %s", nic->log_name,
			sysfs_resc_path);
		rc = -ENODEV;
		goto open_error;
	}

	bp->reg2 = mmap(NULL, BNX2X_BAR2_SIZE, PROT_READ | PROT_WRITE,
			MAP_SHARED, bp->bar2_fd, (off_t) 0);

	if (bp->reg2 == MAP_FAILED) {
		LOG_INFO(PFX "%s: Couldn't mmap BAR2 registers: %s",
			 nic->log_name, strerror(errno));
		bp->reg2 = NULL;
		rc = errno;
		goto open_error;
	}

	/*  TODO: hardcoded with the cnic driver */
	bp->rx_ring_size = 15;
	bp->rx_buffer_size = 0x400;

	LOG_DEBUG(PFX "%s: using rx ring size: %d, rx buffer size: %d",
		  nic->log_name, bp->rx_ring_size, bp->rx_buffer_size);

	/*  Determine the number of UIO events that have already occured */
	rc = detemine_initial_uio_events(nic, &nic->intr_count);
	if (rc != 0) {
		LOG_ERR("Could not determine the number ofinitial UIO events");
		nic->intr_count = 0;
	}

	/*  Allocate space for rx pkt ring */
	bp->rx_pkt_ring = malloc(sizeof(void *) * bp->rx_ring_size);
	if (bp->rx_pkt_ring == NULL) {
		LOG_ERR(PFX "%s: Could not allocate space for rx_pkt_ring",
			nic->log_name);
		rc = errno;
		goto open_error;
	}

	if (bnx2x_is_ver60_plus(bp))
		bp->status_blk_size = sizeof(struct host_sp_status_block);
	else if (bnx2x_is_ver52(bp))
		bp->status_blk_size = sizeof(struct host_def_status_block);
	else {
		LOG_INFO(PFX "%s: Unsupported bnx2x driver [%d.%d]",
			 nic->log_name, bp->version.major, bp->version.minor);

		rc = -ENOTSUP;
		goto open_error;
	}

	bp->status_blk.def = mmap(NULL, bp->status_blk_size,
				  PROT_READ | PROT_WRITE, MAP_SHARED,
				  nic->fd, (off_t) nic->page_size);
	if (bp->status_blk.def == MAP_FAILED) {
		LOG_INFO(PFX "%s: Could not mmap status block: %s",
			 nic->log_name, strerror(errno));
		bp->status_blk.def = NULL;
		rc = errno;
		goto open_error;
	}

	bp->tx_ring = mmap(NULL, 4 * nic->page_size,
			   PROT_READ | PROT_WRITE,
			   MAP_SHARED | MAP_LOCKED,
			   nic->fd, (off_t) 2 * nic->page_size);
	if (bp->tx_ring == MAP_FAILED) {
		LOG_INFO(PFX "%s: Could not mmap tx ring: %s",
			 nic->log_name, strerror(errno));
		bp->tx_ring = NULL;
		rc = errno;
		goto open_error;
	}

	bp->rx_comp_ring.cqe = (union eth_rx_cqe *)
	    (((__u8 *) bp->tx_ring) + 2 * nic->page_size);

	bp->bufs = mmap(NULL, (bp->rx_ring_size + 1) * bp->rx_buffer_size,
			PROT_READ | PROT_WRITE,
			MAP_SHARED | MAP_LOCKED,
			nic->fd, (off_t) 3 * nic->page_size);
	if (bp->bufs == MAP_FAILED) {
		LOG_INFO(PFX "%s: Could not mmap buffers: %s",
			 nic->log_name, strerror(errno));
		bp->bufs = NULL;
		rc = errno;
		goto open_error;
	}

	bp->chip_id = bnx2x_get_chip_id(bp);
	LOG_DEBUG(PFX "Chip ID: %x", bp->chip_id);

	rc = get_bus_slot_func_num(nic, &bus, &slot, &func);
	if (rc != 0) {
		LOG_INFO(PFX "%s: Couldn't determine bus:slot.func",
			 nic->log_name);
		goto open_error;
	}
	/* In E1/E1H use pci device function as read from sysfs.
	 * In E2/E3 read physical function from ME register since these chips
	 * support Physical Device Assignment where kernel BDF maybe arbitrary
	 * (depending on hypervisor).
	 */
	if (CHIP_IS_E2_PLUS(bp)) {
		func = (bnx2x_rd32(bp, BAR_ME_REGISTER) & ME_REG_ABS_PF_NUM) >>
			ME_REG_ABS_PF_NUM_SHIFT;
	}
	bp->func = func;
	bp->port = bp->func % PORT_MAX;

	if (CHIP_IS_E2_PLUS(bp)) {
		__u32 val = bnx2x_rd32(bp, MISC_REG_PORT4MODE_EN_OVWR);
		if (!(val & 1))
			val = bnx2x_rd32(bp, MISC_REG_PORT4MODE_EN);
		else
			val = (val >> 1) & 1;

		if (val)
			bp->pfid = func >> 1;
		else
			bp->pfid = func & 0x6;
	} else {
		bp->pfid = func;
	}

	if (bnx2x_is_ver60_plus(bp))
		bp->port = bp->pfid & 1;

	bp->cid = 17;
	bp->client_id = 17;

	if (bnx2x_is_ver60_plus(bp)) {
		struct client_init_general_data *data = bp->bufs;

		bp->client_id = data->client_id;
		if (data->uid.cid)
			bp->cid = data->uid.cid;
		if (bp->version.minor >= 78 && bp->version.sub_minor >= 55 &&
		    data->uid.cid_override_key == UIO_USE_TX_DOORBELL) {
			bp->tx_doorbell = data->uid.tx_db_off;
			LOG_INFO(PFX "%s: tx doorbell override offset = 0x%x",
				 nic->log_name, bp->tx_doorbell);
		}
	}

	LOG_INFO(PFX "%s: func 0x%x, pfid 0x%x, client_id 0x%x, cid 0x%x",
		 nic->log_name, bp->func, bp->pfid, bp->client_id, bp->cid);

	if (CHIP_IS_E1(bp))
		bp->iro = e1_iro;
	else if (CHIP_IS_E1H(bp))
		bp->iro = e1h_iro;
	else if (CHIP_IS_E2_PLUS(bp))
		bp->iro = e2_iro;

	if (bnx2x_is_ver60_plus(bp)) {
		__u32 cl_qzone_id = BNX2X_CL_QZONE_ID(bp, bp->client_id);

		bp->iro_idx = 0;
		if (bp->version.minor >= 64) {
			bp->iro_idx = 1;
			cl_qzone_id = BNX2X_CL_QZONE_ID_64(bp, bp->client_id);
		}

		bp->rx_prod_io = BAR_USTRORM_INTMEM +
		    (CHIP_IS_E2_PLUS(bp) ?
		     USTORM_RX_PRODS_E2_OFFSET(cl_qzone_id) :
		     USTORM_RX_PRODS_E1X_OFFSET(bp->port, bp->client_id));

		if (!bp->tx_doorbell)
			bp->tx_doorbell = bp->cid * 0x80 + 0x40;

		bp->get_rx_cons = bnx2x_get_rx_60;
		bp->get_tx_cons = bnx2x_get_tx_60;
		bp->tx_vlan_tag_bit = ETH_TX_BD_FLAGS_VLAN_TAG_T6X;
	} else {
		bp->rx_prod_io = BAR_USTRORM_INTMEM +
		    USTORM_RX_PRODS_OFFSET(bp->port, bp->client_id);

		bp->tx_doorbell = bp->cid * nic->page_size + 0x40;

		bp->get_rx_cons = bnx2x_get_rx;
		bp->get_tx_cons = bnx2x_get_tx;
		bp->tx_vlan_tag_bit = ETH_TX_BD_FLAGS_VLAN_TAG_T5X;
	}

	bp->tx_cons = 0;
	bp->tx_prod = 0;
	bp->tx_bd_prod = 0;
	bp->tx_pkt = bp->bufs;

	bp->rx_index = 0;
	bp->rx_cons = 0;
	bp->rx_bd_cons = 0;
	bp->rx_prod = 127;
	bp->rx_bd_prod = bp->rx_ring_size;

	for (i = 0; i < bp->rx_ring_size; i++) {
		void *ptr = bp->bufs + (bp->rx_buffer_size * (i + 1));

		bp->rx_pkt_ring[i] = ptr;
	}

	val = bnx2x_rd32(bp, MISC_REG_SHARED_MEM_ADDR);

	bp->shmem_base = val;
	val = bnx2x_rd32(bp, bp->shmem_base + SHMEM_ISCSI_MAC_UPPER(bp));
	nic->mac_addr[0] = (__u8) (val >> 8);
	nic->mac_addr[1] = (__u8) val;
	val = bnx2x_rd32(bp, bp->shmem_base + SHMEM_ISCSI_MAC_LOWER(bp));
	nic->mac_addr[2] = (__u8) (val >> 24);
	nic->mac_addr[3] = (__u8) (val >> 16);
	nic->mac_addr[4] = (__u8) (val >> 8);
	nic->mac_addr[5] = (__u8) val;

	if (bnx2x_is_ver60_plus(bp) && CHIP_IS_E2_PLUS(bp)) {
		__u32 mf_cfg_addr = 0;
		__u32 mac_offset;
		__u8 mac[6];

		val = bnx2x_rd32(bp, (BNX2X_PATH(bp) ? MISC_REG_GENERIC_CR_1 :
				      MISC_REG_GENERIC_CR_0));
		bp->shmem_base2 = val;
		if (bp->shmem_base2) {
			/* size */
			val = bnx2x_rd32(bp, bp->shmem_base2);

			if (val > 0x10)
				mf_cfg_addr =
				    bnx2x_rd32(bp, bp->shmem_base2 + 0x10);
		}

		if (!mf_cfg_addr)
			mf_cfg_addr = bp->shmem_base + 0x7e4;

		/* shared_feat_cfg.config */
		mode = bnx2x_rd32(bp, bp->shmem_base + 0x354);
		mode &= 0x700;
		LOG_DEBUG(PFX "%s: mode = 0x%x", nic->log_name, mode);
		switch (mode) {
		case 0x300: /* SI mode */
			mac_offset = 0xe4 + (bp->func * 0x28) + 4;
			val = bnx2x_rd32(bp, mf_cfg_addr + mac_offset);
			mac[0] = (__u8) (val >> 8);
			mac[1] = (__u8) val;
			mac_offset += 4;
			val = bnx2x_rd32(bp, mf_cfg_addr + mac_offset);
			mac[2] = (__u8) (val >> 24);
			mac[3] = (__u8) (val >> 16);
			mac[4] = (__u8) (val >> 8);
			mac[5] = (__u8) val;

			if (mac[0] != 0xff) {
				memcpy(nic->mac_addr, mac, 6);
			} else if (bp->func > 1) {
				LOG_INFO(PFX "%s:  Invalid mac address: "
					 "%02x:%02x:%02x:%02x:%02x:%02x, abort",
					 nic->log_name,
					 mac[0], mac[1], mac[2],
					 mac[3], mac[4], mac[5]);
				rc = -ENOTSUP;
				goto open_error;
			}
			break;

		case 0x0: /* MF SD mode */
		case 0x500:
		case 0x600:
			proto_offset = 0x24 + (bp->func * 0x18);
			ovtag_offset = proto_offset + 0xc;

			rc = -ENOTSUP;
			val = bnx2x_rd32(bp, mf_cfg_addr + ovtag_offset);
			val &= 0xffff;
			/* SD mode, check for valid outer VLAN */
			if (val == 0xffff) {
				LOG_ERR(PFX "%s: Invalid OV detected for SD, "
					" fallback to SF mode!\n",
					nic->log_name);
				goto SF;
			}
			/* Check for iSCSI protocol */
			val = bnx2x_rd32(bp, mf_cfg_addr + proto_offset);
			if ((val & 6) != 6)
				goto open_error;

			mac_offset = proto_offset + 0x4;
			val = bnx2x_rd32(bp, mf_cfg_addr + mac_offset);
			mac[0] = (__u8) (val >> 8);
			mac[1] = (__u8) val;
			mac_offset += 4;
			val = bnx2x_rd32(bp, mf_cfg_addr + mac_offset);
			mac[2] = (__u8) (val >> 24);
			mac[3] = (__u8) (val >> 16);
			mac[4] = (__u8) (val >> 8);
			mac[5] = (__u8) val;
			memcpy(nic->mac_addr, mac, 6);
			break;
		}
	}
SF:
	LOG_INFO(PFX "%s:  Using mac address: %02x:%02x:%02x:%02x:%02x:%02x",
		 nic->log_name,
		 nic->mac_addr[0], nic->mac_addr[1], nic->mac_addr[2],
		 nic->mac_addr[3], nic->mac_addr[4], nic->mac_addr[5]);

	/*  Determine if Hardware VLAN tag stripping is enabled or not */
	if (CNIC_VLAN_STRIPPING_ENABLED == bnx2x_strip_vlan_enabled(bp))
		nic->flags |= NIC_VLAN_STRIP_ENABLED;

	msync(bp->reg, BNX2X_BAR_SIZE, MS_SYNC);

	LOG_INFO("%s: bnx2x initialized", nic->log_name);

	bnx2x_update_rx_prod(bp);
	bp->flags |= BNX2X_OPENED;

	return 0;

open_error:
	if (bp->tx_ring) {
		munmap(bp->tx_ring, 4 * nic->page_size);
		bp->tx_ring = NULL;
	}

	if (bp->status_blk.def) {
		munmap(bp->status_blk.def, bp->status_blk_size);
		bp->status_blk.def = NULL;
	}

	if (bp->reg) {
		munmap(bp->reg, BNX2X_BAR_SIZE);
		bp->reg = NULL;
	}

	if (bp->reg2) {
		munmap(bp->reg2, BNX2X_BAR2_SIZE);
		bp->reg2 = NULL;
	}

	if (bp->rx_pkt_ring) {
		free(bp->rx_pkt_ring);
		bp->rx_pkt_ring = NULL;
	}

	if (bp->bar2_fd != INVALID_FD) {
		close(bp->bar2_fd);
		bp->bar2_fd = INVALID_FD;
	}

	if (bp->bar0_fd != INVALID_FD) {
		close(bp->bar0_fd);
		bp->bar0_fd = INVALID_FD;
	}
	if (nic->fd != INVALID_FD) {
		close(nic->fd);
		nic->fd = INVALID_FD;
	}
	bnx2x_free(nic);

	return rc;
}

/**
 *  bnx2x_uio_close_resources() - Used to free resource for the NIC/CNIC
 *  @param nic - NIC device to free resource
 *  @param graceful - whether to wait to close gracefully
 *  @return 0 on success, <0 on failure
 */
static int bnx2x_uio_close_resources(nic_t *nic, NIC_SHUTDOWN_T graceful)
{
	bnx2x_t *bp = (bnx2x_t *) nic->priv;
	int rc = 0;

	/*  Check if there is an assoicated bnx2x device */
	if (bp == NULL) {
		LOG_WARN(PFX "%s: when closing resources there is "
			 "no assoicated bnx2x", nic->log_name);
		return -EIO;
	}

	/*  Clean up allocated memory */

	if (bp->rx_pkt_ring != NULL) {
		free(bp->rx_pkt_ring);
		bp->rx_pkt_ring = NULL;
	}

	/*  Clean up mapped registers */
	if (bp->bufs != NULL) {
		rc = munmap(bp->bufs,
			    (bp->rx_ring_size + 1) * bp->rx_buffer_size);
		if (rc != 0)
			LOG_WARN(PFX "%s: Couldn't unmap bufs", nic->log_name);
		bp->bufs = NULL;
	}

	if (bp->tx_ring != NULL) {
		rc = munmap(bp->tx_ring, 4 * nic->page_size);
		if (rc != 0)
			LOG_WARN(PFX "%s: Couldn't unmap tx_rings",
				 nic->log_name);
		bp->tx_ring = NULL;
	}

	if (bp->status_blk.def != NULL) {
		rc = munmap(bp->status_blk.def, bp->status_blk_size);
		if (rc != 0)
			LOG_WARN(PFX "%s: Couldn't unmap status block",
				 nic->log_name);
		bp->status_blk.def = NULL;
	}

	if (bp->reg != NULL) {
		rc = munmap(bp->reg, BNX2X_BAR_SIZE);
		if (rc != 0)
			LOG_WARN(PFX "%s: Couldn't unmap regs", nic->log_name);
		bp->reg = NULL;
	}

	if (bp->reg2 != NULL) {
		rc = munmap(bp->reg2, BNX2X_BAR2_SIZE);
		if (rc != 0)
			LOG_WARN(PFX "%s: Couldn't unmap regs", nic->log_name);
		bp->reg2 = NULL;
	}

	if (bp->bar2_fd != INVALID_FD) {
		close(bp->bar2_fd);
		bp->bar2_fd = INVALID_FD;
	}

	if (bp->bar0_fd != INVALID_FD) {
		close(bp->bar0_fd);
		bp->bar0_fd = INVALID_FD;
	}

	if (nic->fd != INVALID_FD) {
		rc = close(nic->fd);
		if (rc != 0) {
			LOG_WARN(PFX
				 "%s: Couldn't close uio file descriptor: %d",
				 nic->log_name, nic->fd);
		} else {
			LOG_DEBUG(PFX "%s: Closed uio file descriptor: %d",
				  nic->log_name, nic->fd);
		}

		nic->fd = INVALID_FD;
	} else {
		LOG_WARN(PFX "%s: Invalid uio file descriptor: %d",
			 nic->log_name, nic->fd);
	}

	bnx2x_set_drv_version_unknown(bp);

	LOG_INFO(PFX "%s: Closed all resources", nic->log_name);

	return 0;
}

/**
 *  bnx2x_close() - Used to close the NIC device
 *  @param nic - NIC device to close
 *  @param graceful - whether to wait to close gracefully
 *  @return 0 if successful, <0 if there is an error
 */
static int bnx2x_close(nic_t *nic, NIC_SHUTDOWN_T graceful)
{
	/*  Sanity Check: validate the parameters */
	if (nic == NULL) {
		LOG_ERR(PFX "bnx2x_close(): nic == NULL");
		return -EINVAL;
	}
	if (nic->priv == NULL) {
		LOG_ERR(PFX "bnx2x_close(): nic->priv == NULL");
		return -EINVAL;
	}

	LOG_INFO(PFX "Closing NIC device: %s", nic->log_name);

	bnx2x_uio_close_resources(nic, graceful);
	bnx2x_free(nic);

	return 0;
}

static void bnx2x_prepare_xmit_packet(nic_t *nic,
				      nic_interface_t *nic_iface,
				      struct packet *pkt)
{
	bnx2x_t *bp = (bnx2x_t *) nic->priv;
	struct uip_vlan_eth_hdr *eth_vlan = (struct uip_vlan_eth_hdr *)pkt->buf;
	struct uip_eth_hdr *eth = (struct uip_eth_hdr *)bp->tx_pkt;

	if (eth_vlan->tpid == htons(UIP_ETHTYPE_8021Q)) {
		memcpy(bp->tx_pkt, pkt->buf, sizeof(struct uip_eth_hdr));
		eth->type = eth_vlan->type;
		pkt->buf_size -= (sizeof(struct uip_vlan_eth_hdr) -
				  sizeof(struct uip_eth_hdr));
		memcpy(bp->tx_pkt + sizeof(struct uip_eth_hdr),
		       pkt->buf + sizeof(struct uip_vlan_eth_hdr),
		       pkt->buf_size - sizeof(struct uip_eth_hdr));
	} else
		memcpy(bp->tx_pkt, pkt->buf, pkt->buf_size);

	msync(bp->tx_pkt, pkt->buf_size, MS_SYNC);
}

/**
 *  bnx2x_get_tx_pkt() - This function is used to a TX packet from the NIC
 *  @param nic - The NIC device to send the packet
 */
void *bnx2x_get_tx_pkt(nic_t *nic)
{
	bnx2x_t *bp = (bnx2x_t *) nic->priv;
	return bp->tx_pkt;
}

/**
 *  bnx2x_start_xmit() - This function is used to send a packet of data
 *  @param nic - The NIC device to send the packet
 *  @param len - the length of the TX packet
 *
 */
void bnx2x_start_xmit(nic_t *nic, size_t len, u16_t vlan_id)
{
	bnx2x_t *bp = (bnx2x_t *) nic->priv;
	uint16_t ring_prod;
	struct eth_tx_start_bd *txbd;
	struct eth_tx_bd *txbd2;
	struct eth_rx_bd *rx_bd;
	rx_bd = (struct eth_rx_bd *)(((__u8 *) bp->tx_ring) + nic->page_size);

	if ((rx_bd->addr_hi == 0) && (rx_bd->addr_lo == 0)) {
		LOG_PACKET(PFX "%s: trying to transmit when device is closed",
			   nic->log_name);
		return;
	}

	ring_prod = BNX2X_TX_RING_IDX(bp->tx_bd_prod);
	txbd = &bp->tx_ring[ring_prod];

	BNX2X_SET_TX_VLAN(bp, txbd, vlan_id);

	bp->tx_prod++;
	bp->tx_bd_prod = BNX2X_NEXT_TX_BD(bp->tx_bd_prod);
	bp->tx_bd_prod = BNX2X_NEXT_TX_BD(bp->tx_bd_prod);

	ring_prod = BNX2X_TX_RING_IDX(bp->tx_bd_prod);
	txbd2 = (struct eth_tx_bd *)&bp->tx_ring[ring_prod];

	txbd2->nbytes = len - 0x10;
	txbd2->total_pkt_bytes = len;

	bp->tx_bd_prod = BNX2X_NEXT_TX_BD(bp->tx_bd_prod);

	barrier();
	if (nic->nl_process_if_down == 0) {
		bnx2x_doorbell(bp, bp->tx_doorbell, 0x02 |
			       (bp->tx_bd_prod << 16));
		bnx2x_flush_doorbell(bp, bp->tx_doorbell);
	} else {
		LOG_ERR(PFX "Pkt transmission failed.");
	}

	LOG_PACKET(PFX "%s: sent %d bytes using bp->tx_prod: %d",
		   nic->log_name, len, bp->tx_prod);
}

/**
 *  bnx2x_write() - Used to write the data to the hardware
 *  @param nic - NIC hardware to read from
 *  @param pkt - The packet which will hold the data to be sent on the wire
 *  @return 0 if successful, <0 if failed
 */
int bnx2x_write(nic_t *nic, nic_interface_t *nic_iface, packet_t *pkt)
{
	bnx2x_t *bp;
	struct uip_stack *uip;
	int i = 0;

	/* Sanity Check: validate the parameters */
	if (nic == NULL || nic_iface == NULL || pkt == NULL) {
		LOG_ERR(PFX "%s: bnx2x_write() nic == 0x%p || "
			" nic_iface == 0x%p || "
			" pkt == 0x%x", nic, nic_iface, pkt);
		return -EINVAL;
	}
	bp = (bnx2x_t *) nic->priv;
	uip = &nic_iface->ustack;

	if (pkt->buf_size == 0) {
		LOG_ERR(PFX "%s: Trying to transmitted 0 sized packet",
			nic->log_name);
		return -EINVAL;
	}

	/*  Try to wait for a TX completion */
	for (i = 0; i < 15; i++) {
		struct timespec sleep_req = {.tv_sec = 0, .tv_nsec = 5000000 },
		    sleep_rem;

		if (bnx2x_clear_tx_intr(nic) == 0)
			break;

		nanosleep(&sleep_req, &sleep_rem);
	}

	if (pthread_mutex_trylock(&nic->xmit_mutex) != 0) {
		LOG_PACKET(PFX "%s: Dropped previous transmitted packet",
			   nic->log_name);
		return -EINVAL;
	}

	bnx2x_prepare_xmit_packet(nic, nic_iface, pkt);
	bnx2x_start_xmit(nic, pkt->buf_size,
			 (nic_iface->vlan_priority << 12) |
			 nic_iface->vlan_id);

	/*  bump the cnic dev send statistics */
	nic->stats.tx.packets++;
	nic->stats.tx.bytes += uip->uip_len;

	LOG_PACKET(PFX "%s: transmitted %d bytes "
		   "dev->tx_cons: %d, dev->tx_prod: %d, dev->tx_bd_prod:%d",
		   nic->log_name, pkt->buf_size,
		   bp->tx_cons, bp->tx_prod, bp->tx_bd_prod);

	pthread_mutex_unlock(&nic->xmit_mutex);

	return 0;
}

static inline int bnx2x_get_rx_pad(bnx2x_t *bp, union eth_rx_cqe *cqe)
{
	int pad = 0;

	if (bnx2x_is_ver70(bp))
		pad = ((union eth_rx_cqe_70 *)cqe)->fast_path_cqe_70. \
						    placement_offset;
	else if (bnx2x_is_ver60(bp)) {
		if (bp->version.minor >= 64)
			pad = cqe->fast_path_cqe_64.placement_offset;
		else
			pad = cqe->fast_path_cqe.placement_offset;
	}
	return pad;
}

/**
 *  bnx2x_read() - Used to read the data from the hardware
 *  @param nic - NIC hardware to read from
 *  @param pkt - The packet which will hold the data
 *  @return 0 if successful, <0 if failed
 */
static int bnx2x_read(nic_t *nic, packet_t *pkt)
{
	bnx2x_t *bp;
	int rc = 0;
	uint16_t hw_cons, sw_cons, bd_cons, bd_prod;

	/* Sanity Check: validate the parameters */
	if (nic == NULL || pkt == NULL) {
		LOG_ERR(PFX "%s: bnx2x_read() nic == 0x%p || "
			" pkt == 0x%x", nic, pkt);
		return -EINVAL;
	}
	bp = (bnx2x_t *) nic->priv;

	hw_cons = bp->get_rx_cons(bp);
	sw_cons = bp->rx_cons;
	bd_cons = BNX2X_RX_BD(bp->rx_bd_cons);
	bd_prod = BNX2X_RX_BD(bp->rx_bd_prod);

	if (sw_cons != hw_cons) {
		uint16_t comp_ring_index = sw_cons & BNX2X_MAX_RCQ_DESC_CNT(bp);
		uint8_t ring_index;
		union eth_rx_cqe *cqe;
		__u8 cqe_fp_flags;
		void *rx_pkt;
		int len, pad, cqe_size, max_len;
		rc = 1;

		if (bnx2x_is_ver70(bp)) {
			cqe = (union eth_rx_cqe *)
			      &bp->rx_comp_ring.cqe70[comp_ring_index];
			cqe_size = sizeof(union eth_rx_cqe_70);
		} else {
			cqe = &bp->rx_comp_ring.cqe[comp_ring_index];
			cqe_size = sizeof(union eth_rx_cqe);
		}
		cqe_fp_flags = cqe->fast_path_cqe.type_error_flags;

		LOG_PACKET(PFX "%s: clearing rx interrupt: %d %d",
			   nic->log_name, sw_cons, hw_cons);

		msync(cqe, cqe_size, MS_SYNC);

		if (!(cqe_fp_flags & ETH_FAST_PATH_RX_CQE_TYPE)) {
			ring_index = bd_cons % 15;
			len = cqe->fast_path_cqe.pkt_len;
			pad = bnx2x_get_rx_pad(bp, cqe);
			rx_pkt = bp->rx_pkt_ring[ring_index] + pad;

			/*  Doto query MTU size of physical device */
			/*  Ensure len is valid */
			max_len = pkt->max_buf_size < bp->rx_buffer_size ?
				  pkt->max_buf_size : bp->rx_buffer_size;
			if (len + pad > max_len) {
				LOG_DEBUG(PFX "%s: bad BD length: %d",
					  nic->log_name, len);
				len = max_len - pad;
			}
			if (len > 0) {
				msync(rx_pkt, len, MS_SYNC);
				/*  Copy the data */
				memcpy(pkt->buf, rx_pkt, len);
				pkt->buf_size = len;

				/*  Properly set the packet flags */
				/*  check if there is VLAN tagging */
				if (cqe->fast_path_cqe.vlan_tag != 0) {
					pkt->vlan_tag =
					    cqe->fast_path_cqe.vlan_tag;
					pkt->flags |= VLAN_TAGGED;
				} else {
					pkt->vlan_tag = 0;
				}

				LOG_PACKET(PFX
					   "%s: processing packet length: %d",
					   nic->log_name, len);

				/*  bump the cnic dev recv statistics */
				nic->stats.rx.packets++;
				nic->stats.rx.bytes += pkt->buf_size;
			}

			bd_cons = BNX2X_NEXT_RX_IDX(bd_cons);
			bd_prod = BNX2X_NEXT_RX_IDX(bd_prod);

		}
		sw_cons = BNX2X_NEXT_RCQ_IDX(bp, sw_cons);
		bp->rx_prod = BNX2X_NEXT_RCQ_IDX(bp, bp->rx_prod);
	}
	bp->rx_cons = sw_cons;
	bp->rx_bd_cons = bd_cons;
	bp->rx_bd_prod = bd_prod;
	bp->rx_hw_prod = hw_cons;

	if (rc)
		bnx2x_update_rx_prod(bp);

	return rc;
}

/*******************************************************************************
 * Clearing TX interrupts
 ******************************************************************************/
/**
 *  bnx2x_clear_tx_intr() - This routine is called when a TX interrupt occurs
 *  @param nic - the nic the interrupt occured on
 *  @return  0 on success
 */
static int bnx2x_clear_tx_intr(nic_t *nic)
{
	bnx2x_t *bp;
	uint16_t hw_cons;

	/* Sanity check: ensure the parameters passed in are valid */
	if (unlikely(nic == NULL)) {
		LOG_ERR(PFX "bnx2x_read() nic == NULL");
		return -EINVAL;
	}
	bp = (bnx2x_t *) nic->priv;
	hw_cons = bp->get_tx_cons(bp);

	if (bp->tx_cons == hw_cons) {
		if (bp->tx_cons == bp->tx_prod)
			return 0;
		return -EAGAIN;
	}

	if (pthread_mutex_trylock(&nic->xmit_mutex)) {
		LOG_ERR(PFX "%s: unable to get xmit_mutex.", nic->log_name);
		return -EINVAL;
	}

	LOG_PACKET(PFX "%s: clearing tx interrupt [%d %d]",
		   nic->log_name, bp->tx_cons, hw_cons);
	bp->tx_cons = hw_cons;

	/*  There is a queued TX packet that needs to be sent out.  The usual
	 *  case is when stack will send an ARP packet out before sending the
	 *  intended packet */
	if (nic->tx_packet_queue != NULL) {
		packet_t *pkt;
		int i;

		LOG_PACKET(PFX "%s: sending queued tx packet", nic->log_name);
		pkt = nic_dequeue_tx_packet(nic);

		/*  Got a TX packet buffer of the TX queue and put it onto
		 *  the hardware */
		if (pkt != NULL) {
			bnx2x_prepare_xmit_packet(nic, pkt->nic_iface, pkt);

			bnx2x_start_xmit(nic, pkt->buf_size,
					 (pkt->nic_iface->vlan_priority << 12) |
					 pkt->nic_iface->vlan_id);

			LOG_PACKET(PFX "%s: transmitted queued packet %d bytes "
				   "dev->tx_cons: %d, dev->tx_prod: %d, "
				   "dev->tx_bd_prod:%d",
				   nic->log_name, pkt->buf_size,
				   bp->tx_cons, bp->tx_prod, bp->tx_bd_prod);

			pthread_mutex_unlock(&nic->xmit_mutex);
			return 0;
		}

		/*  Try to wait for a TX completion */
		for (i = 0; i < 15; i++) {
			struct timespec sleep_req = {.tv_sec = 0,
				.tv_nsec = 5000000
			}, sleep_rem;

			hw_cons = bp->get_tx_cons(bp);
			if (bp->tx_cons != hw_cons) {
				LOG_PACKET(PFX
					   "%s: clearing tx interrupt [%d %d]",
					   nic->log_name, bp->tx_cons, hw_cons);
				bp->tx_cons = hw_cons;

				break;
			}

			nanosleep(&sleep_req, &sleep_rem);
		}
	}

	pthread_mutex_unlock(&nic->xmit_mutex);

	return 0;
}

/*******************************************************************************
 * bnx2x NIC op's table
 ******************************************************************************/
struct nic_ops bnx2x_op = {
	.description = "bnx2x",
	.open = bnx2x_open,
	.close = bnx2x_close,
	.write = bnx2x_write,
	.get_tx_pkt = bnx2x_get_tx_pkt,
	.start_xmit = bnx2x_start_xmit,
	.read = bnx2x_read,
	.clear_tx_intr = bnx2x_clear_tx_intr,
	.handle_iscsi_path_req = cnic_handle_iscsi_path_req,

	.lib_ops = {
		    .get_library_name = bnx2x_get_library_name,
		    .get_pci_table = bnx2x_get_pci_table,
		    .get_library_version = bnx2x_get_library_version,
		    .get_build_date = bnx2x_get_build_date,
		    .get_transport_name = bnx2x_get_transport_name,
		    .get_uio_name = bnx2x_get_uio_name,
		    },
};