aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/qlcnic
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/net/qlcnic')
-rw-r--r--drivers/net/qlcnic/qlcnic.h108
-rw-r--r--drivers/net/qlcnic/qlcnic_ctx.c267
-rw-r--r--drivers/net/qlcnic/qlcnic_ethtool.c75
-rw-r--r--drivers/net/qlcnic/qlcnic_hdr.h23
-rw-r--r--drivers/net/qlcnic/qlcnic_hw.c77
-rw-r--r--drivers/net/qlcnic/qlcnic_init.c309
-rw-r--r--drivers/net/qlcnic/qlcnic_main.c1163
7 files changed, 1504 insertions, 518 deletions
diff --git a/drivers/net/qlcnic/qlcnic.h b/drivers/net/qlcnic/qlcnic.h
index 970389331bbc..714ddf461d73 100644
--- a/drivers/net/qlcnic/qlcnic.h
+++ b/drivers/net/qlcnic/qlcnic.h
@@ -51,9 +51,11 @@
51 51
52#define _QLCNIC_LINUX_MAJOR 5 52#define _QLCNIC_LINUX_MAJOR 5
53#define _QLCNIC_LINUX_MINOR 0 53#define _QLCNIC_LINUX_MINOR 0
54#define _QLCNIC_LINUX_SUBVERSION 7 54#define _QLCNIC_LINUX_SUBVERSION 10
55#define QLCNIC_LINUX_VERSIONID "5.0.7" 55#define QLCNIC_LINUX_VERSIONID "5.0.10"
56#define QLCNIC_DRV_IDC_VER 0x01 56#define QLCNIC_DRV_IDC_VER 0x01
57#define QLCNIC_DRIVER_VERSION ((_QLCNIC_LINUX_MAJOR << 16) |\
58 (_QLCNIC_LINUX_MINOR << 8) | (_QLCNIC_LINUX_SUBVERSION))
57 59
58#define QLCNIC_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c)) 60#define QLCNIC_VERSION_CODE(a, b, c) (((a) << 24) + ((b) << 16) + (c))
59#define _major(v) (((v) >> 24) & 0xff) 61#define _major(v) (((v) >> 24) & 0xff)
@@ -148,6 +150,7 @@
148 150
149#define DEFAULT_RCV_DESCRIPTORS_1G 2048 151#define DEFAULT_RCV_DESCRIPTORS_1G 2048
150#define DEFAULT_RCV_DESCRIPTORS_10G 4096 152#define DEFAULT_RCV_DESCRIPTORS_10G 4096
153#define MAX_RDS_RINGS 2
151 154
152#define get_next_index(index, length) \ 155#define get_next_index(index, length) \
153 (((index) + 1) & ((length) - 1)) 156 (((index) + 1) & ((length) - 1))
@@ -172,7 +175,7 @@
172 ((_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0)) 175 ((_desc)->port_ctxid = ((_port) & 0xf) | (((_port) << 4) & 0xf0))
173 176
174#define qlcnic_set_tx_flags_opcode(_desc, _flags, _opcode) \ 177#define qlcnic_set_tx_flags_opcode(_desc, _flags, _opcode) \
175 ((_desc)->flags_opcode = \ 178 ((_desc)->flags_opcode |= \
176 cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7))) 179 cpu_to_le16(((_flags) & 0x7f) | (((_opcode) & 0x3f) << 7)))
177 180
178#define qlcnic_set_tx_frags_len(_desc, _frags, _len) \ 181#define qlcnic_set_tx_frags_len(_desc, _frags, _len) \
@@ -221,7 +224,8 @@ struct rcv_desc {
221#define QLCNIC_LRO_DESC 0x12 224#define QLCNIC_LRO_DESC 0x12
222 225
223/* for status field in status_desc */ 226/* for status field in status_desc */
224#define STATUS_CKSUM_OK (2) 227#define STATUS_CKSUM_LOOP 0
228#define STATUS_CKSUM_OK 2
225 229
226/* owner bits of status_desc */ 230/* owner bits of status_desc */
227#define STATUS_OWNER_HOST (0x1ULL << 56) 231#define STATUS_OWNER_HOST (0x1ULL << 56)
@@ -555,6 +559,8 @@ struct qlcnic_recv_context {
555#define QLCNIC_CDRP_CMD_GET_ESWITCH_STATUS 0x00000026 559#define QLCNIC_CDRP_CMD_GET_ESWITCH_STATUS 0x00000026
556#define QLCNIC_CDRP_CMD_SET_PORTMIRRORING 0x00000027 560#define QLCNIC_CDRP_CMD_SET_PORTMIRRORING 0x00000027
557#define QLCNIC_CDRP_CMD_CONFIGURE_ESWITCH 0x00000028 561#define QLCNIC_CDRP_CMD_CONFIGURE_ESWITCH 0x00000028
562#define QLCNIC_CDRP_CMD_GET_ESWITCH_PORT_CONFIG 0x00000029
563#define QLCNIC_CDRP_CMD_GET_ESWITCH_STATS 0x0000002a
558 564
559#define QLCNIC_RCODE_SUCCESS 0 565#define QLCNIC_RCODE_SUCCESS 0
560#define QLCNIC_RCODE_TIMEOUT 17 566#define QLCNIC_RCODE_TIMEOUT 17
@@ -717,6 +723,8 @@ struct qlcnic_cardrsp_tx_ctx {
717#define QLCNIC_MAC_NOOP 0 723#define QLCNIC_MAC_NOOP 0
718#define QLCNIC_MAC_ADD 1 724#define QLCNIC_MAC_ADD 1
719#define QLCNIC_MAC_DEL 2 725#define QLCNIC_MAC_DEL 2
726#define QLCNIC_MAC_VLAN_ADD 3
727#define QLCNIC_MAC_VLAN_DEL 4
720 728
721struct qlcnic_mac_list_s { 729struct qlcnic_mac_list_s {
722 struct list_head list; 730 struct list_head list;
@@ -893,9 +901,14 @@ struct qlcnic_mac_req {
893#define QLCNIC_MSI_ENABLED 0x02 901#define QLCNIC_MSI_ENABLED 0x02
894#define QLCNIC_MSIX_ENABLED 0x04 902#define QLCNIC_MSIX_ENABLED 0x04
895#define QLCNIC_LRO_ENABLED 0x08 903#define QLCNIC_LRO_ENABLED 0x08
904#define QLCNIC_LRO_DISABLED 0x00
896#define QLCNIC_BRIDGE_ENABLED 0X10 905#define QLCNIC_BRIDGE_ENABLED 0X10
897#define QLCNIC_DIAG_ENABLED 0x20 906#define QLCNIC_DIAG_ENABLED 0x20
898#define QLCNIC_ESWITCH_ENABLED 0x40 907#define QLCNIC_ESWITCH_ENABLED 0x40
908#define QLCNIC_ADAPTER_INITIALIZED 0x80
909#define QLCNIC_TAGGING_ENABLED 0x100
910#define QLCNIC_MACSPOOF 0x200
911#define QLCNIC_MAC_OVERRIDE_DISABLED 0x400
899#define QLCNIC_IS_MSI_FAMILY(adapter) \ 912#define QLCNIC_IS_MSI_FAMILY(adapter) \
900 ((adapter)->flags & (QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED)) 913 ((adapter)->flags & (QLCNIC_MSI_ENABLED | QLCNIC_MSIX_ENABLED))
901 914
@@ -916,6 +929,22 @@ struct qlcnic_mac_req {
916#define QLCNIC_INTERRUPT_TEST 1 929#define QLCNIC_INTERRUPT_TEST 1
917#define QLCNIC_LOOPBACK_TEST 2 930#define QLCNIC_LOOPBACK_TEST 2
918 931
932#define QLCNIC_FILTER_AGE 80
933#define QLCNIC_LB_MAX_FILTERS 64
934
935struct qlcnic_filter {
936 struct hlist_node fnode;
937 u8 faddr[ETH_ALEN];
938 u16 vlan_id;
939 unsigned long ftime;
940};
941
942struct qlcnic_filter_hash {
943 struct hlist_head *fhead;
944 u8 fnum;
945 u8 fmax;
946};
947
919struct qlcnic_adapter { 948struct qlcnic_adapter {
920 struct qlcnic_hardware_context ahw; 949 struct qlcnic_hardware_context ahw;
921 950
@@ -924,6 +953,7 @@ struct qlcnic_adapter {
924 struct list_head mac_list; 953 struct list_head mac_list;
925 954
926 spinlock_t tx_clean_lock; 955 spinlock_t tx_clean_lock;
956 spinlock_t mac_learn_lock;
927 957
928 u16 num_txd; 958 u16 num_txd;
929 u16 num_rxd; 959 u16 num_rxd;
@@ -931,7 +961,6 @@ struct qlcnic_adapter {
931 961
932 u8 max_rds_rings; 962 u8 max_rds_rings;
933 u8 max_sds_rings; 963 u8 max_sds_rings;
934 u8 driver_mismatch;
935 u8 msix_supported; 964 u8 msix_supported;
936 u8 rx_csum; 965 u8 rx_csum;
937 u8 portnum; 966 u8 portnum;
@@ -961,6 +990,7 @@ struct qlcnic_adapter {
961 u16 max_tx_ques; 990 u16 max_tx_ques;
962 u16 max_rx_ques; 991 u16 max_rx_ques;
963 u16 max_mtu; 992 u16 max_mtu;
993 u16 pvid;
964 994
965 u32 fw_hal_version; 995 u32 fw_hal_version;
966 u32 capabilities; 996 u32 capabilities;
@@ -969,7 +999,7 @@ struct qlcnic_adapter {
969 u32 temp; 999 u32 temp;
970 1000
971 u32 int_vec_bit; 1001 u32 int_vec_bit;
972 u32 heartbit; 1002 u32 heartbeat;
973 1003
974 u8 max_mac_filters; 1004 u8 max_mac_filters;
975 u8 dev_state; 1005 u8 dev_state;
@@ -983,6 +1013,7 @@ struct qlcnic_adapter {
983 1013
984 u64 dev_rst_time; 1014 u64 dev_rst_time;
985 1015
1016 struct vlan_group *vlgrp;
986 struct qlcnic_npar_info *npars; 1017 struct qlcnic_npar_info *npars;
987 struct qlcnic_eswitch *eswitch; 1018 struct qlcnic_eswitch *eswitch;
988 struct qlcnic_nic_template *nic_ops; 1019 struct qlcnic_nic_template *nic_ops;
@@ -1003,6 +1034,8 @@ struct qlcnic_adapter {
1003 1034
1004 struct qlcnic_nic_intr_coalesce coal; 1035 struct qlcnic_nic_intr_coalesce coal;
1005 1036
1037 struct qlcnic_filter_hash fhash;
1038
1006 unsigned long state; 1039 unsigned long state;
1007 __le32 file_prd_off; /*File fw product offset*/ 1040 __le32 file_prd_off; /*File fw product offset*/
1008 u32 fw_version; 1041 u32 fw_version;
@@ -1042,7 +1075,7 @@ struct qlcnic_pci_info {
1042}; 1075};
1043 1076
1044struct qlcnic_npar_info { 1077struct qlcnic_npar_info {
1045 u16 vlan_id; 1078 u16 pvid;
1046 u16 min_bw; 1079 u16 min_bw;
1047 u16 max_bw; 1080 u16 max_bw;
1048 u8 phy_port; 1081 u8 phy_port;
@@ -1050,11 +1083,13 @@ struct qlcnic_npar_info {
1050 u8 active; 1083 u8 active;
1051 u8 enable_pm; 1084 u8 enable_pm;
1052 u8 dest_npar; 1085 u8 dest_npar;
1053 u8 host_vlan_tag;
1054 u8 promisc_mode;
1055 u8 discard_tagged; 1086 u8 discard_tagged;
1056 u8 mac_learning; 1087 u8 mac_override;
1088 u8 mac_anti_spoof;
1089 u8 promisc_mode;
1090 u8 offload_flags;
1057}; 1091};
1092
1058struct qlcnic_eswitch { 1093struct qlcnic_eswitch {
1059 u8 port; 1094 u8 port;
1060 u8 active_vports; 1095 u8 active_vports;
@@ -1086,7 +1121,6 @@ struct qlcnic_eswitch {
1086#define IS_VALID_BW(bw) (bw >= MIN_BW && bw <= MAX_BW) 1121#define IS_VALID_BW(bw) (bw >= MIN_BW && bw <= MAX_BW)
1087#define IS_VALID_TX_QUEUES(que) (que > 0 && que <= MAX_TX_QUEUES) 1122#define IS_VALID_TX_QUEUES(que) (que > 0 && que <= MAX_TX_QUEUES)
1088#define IS_VALID_RX_QUEUES(que) (que > 0 && que <= MAX_RX_QUEUES) 1123#define IS_VALID_RX_QUEUES(que) (que > 0 && que <= MAX_RX_QUEUES)
1089#define IS_VALID_MODE(mode) (mode == 0 || mode == 1)
1090 1124
1091struct qlcnic_pci_func_cfg { 1125struct qlcnic_pci_func_cfg {
1092 u16 func_type; 1126 u16 func_type;
@@ -1118,12 +1152,41 @@ struct qlcnic_pm_func_cfg {
1118 1152
1119struct qlcnic_esw_func_cfg { 1153struct qlcnic_esw_func_cfg {
1120 u16 vlan_id; 1154 u16 vlan_id;
1155 u8 op_mode;
1156 u8 op_type;
1121 u8 pci_func; 1157 u8 pci_func;
1122 u8 host_vlan_tag; 1158 u8 host_vlan_tag;
1123 u8 promisc_mode; 1159 u8 promisc_mode;
1124 u8 discard_tagged; 1160 u8 discard_tagged;
1125 u8 mac_learning; 1161 u8 mac_override;
1126 u8 reserved; 1162 u8 mac_anti_spoof;
1163 u8 offload_flags;
1164 u8 reserved[5];
1165};
1166
1167#define QLCNIC_STATS_VERSION 1
1168#define QLCNIC_STATS_PORT 1
1169#define QLCNIC_STATS_ESWITCH 2
1170#define QLCNIC_QUERY_RX_COUNTER 0
1171#define QLCNIC_QUERY_TX_COUNTER 1
1172struct __qlcnic_esw_statistics {
1173 __le16 context_id;
1174 __le16 version;
1175 __le16 size;
1176 __le16 unused;
1177 __le64 unicast_frames;
1178 __le64 multicast_frames;
1179 __le64 broadcast_frames;
1180 __le64 dropped_frames;
1181 __le64 errors;
1182 __le64 local_frames;
1183 __le64 numbytes;
1184 __le64 rsvd[3];
1185};
1186
1187struct qlcnic_esw_statistics {
1188 struct __qlcnic_esw_statistics rx;
1189 struct __qlcnic_esw_statistics tx;
1127}; 1190};
1128 1191
1129int qlcnic_fw_cmd_query_phy(struct qlcnic_adapter *adapter, u32 reg, u32 *val); 1192int qlcnic_fw_cmd_query_phy(struct qlcnic_adapter *adapter, u32 reg, u32 *val);
@@ -1171,6 +1234,8 @@ void qlcnic_pcie_sem_unlock(struct qlcnic_adapter *, int);
1171int qlcnic_get_board_info(struct qlcnic_adapter *adapter); 1234int qlcnic_get_board_info(struct qlcnic_adapter *adapter);
1172int qlcnic_wol_supported(struct qlcnic_adapter *adapter); 1235int qlcnic_wol_supported(struct qlcnic_adapter *adapter);
1173int qlcnic_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate); 1236int qlcnic_config_led(struct qlcnic_adapter *adapter, u32 state, u32 rate);
1237void qlcnic_prune_lb_filters(struct qlcnic_adapter *adapter);
1238void qlcnic_delete_lb_filters(struct qlcnic_adapter *adapter);
1174 1239
1175/* Functions from qlcnic_init.c */ 1240/* Functions from qlcnic_init.c */
1176int qlcnic_load_firmware(struct qlcnic_adapter *adapter); 1241int qlcnic_load_firmware(struct qlcnic_adapter *adapter);
@@ -1199,7 +1264,7 @@ void qlcnic_reset_rx_buffers_list(struct qlcnic_adapter *adapter);
1199void qlcnic_release_rx_buffers(struct qlcnic_adapter *adapter); 1264void qlcnic_release_rx_buffers(struct qlcnic_adapter *adapter);
1200void qlcnic_release_tx_buffers(struct qlcnic_adapter *adapter); 1265void qlcnic_release_tx_buffers(struct qlcnic_adapter *adapter);
1201 1266
1202int qlcnic_init_firmware(struct qlcnic_adapter *adapter); 1267int qlcnic_check_fw_status(struct qlcnic_adapter *adapter);
1203void qlcnic_watchdog_task(struct work_struct *work); 1268void qlcnic_watchdog_task(struct work_struct *work);
1204void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter, u32 ringid, 1269void qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter, u32 ringid,
1205 struct qlcnic_host_rds_ring *rds_ring); 1270 struct qlcnic_host_rds_ring *rds_ring);
@@ -1220,7 +1285,6 @@ int qlcnic_config_bridged_mode(struct qlcnic_adapter *adapter, u32 enable);
1220int qlcnic_send_lro_cleanup(struct qlcnic_adapter *adapter); 1285int qlcnic_send_lro_cleanup(struct qlcnic_adapter *adapter);
1221void qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter, 1286void qlcnic_update_cmd_producer(struct qlcnic_adapter *adapter,
1222 struct qlcnic_host_tx_ring *tx_ring); 1287 struct qlcnic_host_tx_ring *tx_ring);
1223int qlcnic_get_mac_addr(struct qlcnic_adapter *adapter, u8 *mac);
1224void qlcnic_clear_ilb_mode(struct qlcnic_adapter *adapter); 1288void qlcnic_clear_ilb_mode(struct qlcnic_adapter *adapter);
1225int qlcnic_set_ilb_mode(struct qlcnic_adapter *adapter); 1289int qlcnic_set_ilb_mode(struct qlcnic_adapter *adapter);
1226void qlcnic_fetch_mac(struct qlcnic_adapter *, u32, u32, u8, u8 *); 1290void qlcnic_fetch_mac(struct qlcnic_adapter *, u32, u32, u8, u8 *);
@@ -1249,9 +1313,16 @@ int qlcnic_get_eswitch_capabilities(struct qlcnic_adapter *, u8,
1249int qlcnic_get_eswitch_status(struct qlcnic_adapter *, u8, 1313int qlcnic_get_eswitch_status(struct qlcnic_adapter *, u8,
1250 struct qlcnic_eswitch *); 1314 struct qlcnic_eswitch *);
1251int qlcnic_toggle_eswitch(struct qlcnic_adapter *, u8, u8); 1315int qlcnic_toggle_eswitch(struct qlcnic_adapter *, u8, u8);
1252int qlcnic_config_switch_port(struct qlcnic_adapter *, u8, int, u8, u8, 1316int qlcnic_config_switch_port(struct qlcnic_adapter *,
1253 u8, u8, u16); 1317 struct qlcnic_esw_func_cfg *);
1318int qlcnic_get_eswitch_port_config(struct qlcnic_adapter *,
1319 struct qlcnic_esw_func_cfg *);
1254int qlcnic_config_port_mirroring(struct qlcnic_adapter *, u8, u8, u8); 1320int qlcnic_config_port_mirroring(struct qlcnic_adapter *, u8, u8, u8);
1321int qlcnic_get_port_stats(struct qlcnic_adapter *, const u8, const u8,
1322 struct __qlcnic_esw_statistics *);
1323int qlcnic_get_eswitch_stats(struct qlcnic_adapter *, const u8, u8,
1324 struct __qlcnic_esw_statistics *);
1325int qlcnic_clear_esw_stats(struct qlcnic_adapter *adapter, u8, u8, u8);
1255extern int qlcnic_config_tso; 1326extern int qlcnic_config_tso;
1256 1327
1257/* 1328/*
@@ -1280,6 +1351,8 @@ static const struct qlcnic_brdinfo qlcnic_boards[] = {
1280 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"}, 1351 "3200 Series Quad Port 1Gb Intelligent Ethernet Adapter"},
1281 {0x1077, 0x8020, 0x1077, 0x20f, 1352 {0x1077, 0x8020, 0x1077, 0x20f,
1282 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"}, 1353 "3200 Series Single Port 10Gb Intelligent Ethernet Adapter"},
1354 {0x1077, 0x8020, 0x103c, 0x3733,
1355 "NC523SFP 10Gb 2-port Flex-10 Server Adapter"},
1283 {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"}, 1356 {0x1077, 0x8020, 0x0, 0x0, "cLOM8214 1/10GbE Controller"},
1284}; 1357};
1285 1358
@@ -1298,7 +1371,6 @@ static inline u32 qlcnic_tx_avail(struct qlcnic_host_tx_ring *tx_ring)
1298extern const struct ethtool_ops qlcnic_ethtool_ops; 1371extern const struct ethtool_ops qlcnic_ethtool_ops;
1299 1372
1300struct qlcnic_nic_template { 1373struct qlcnic_nic_template {
1301 int (*get_mac_addr) (struct qlcnic_adapter *, u8*);
1302 int (*config_bridged_mode) (struct qlcnic_adapter *, u32); 1374 int (*config_bridged_mode) (struct qlcnic_adapter *, u32);
1303 int (*config_led) (struct qlcnic_adapter *, u32, u32); 1375 int (*config_led) (struct qlcnic_adapter *, u32, u32);
1304 int (*start_firmware) (struct qlcnic_adapter *); 1376 int (*start_firmware) (struct qlcnic_adapter *);
diff --git a/drivers/net/qlcnic/qlcnic_ctx.c b/drivers/net/qlcnic/qlcnic_ctx.c
index cc5d861d9a12..95a821e0b66f 100644
--- a/drivers/net/qlcnic/qlcnic_ctx.c
+++ b/drivers/net/qlcnic/qlcnic_ctx.c
@@ -813,9 +813,8 @@ int qlcnic_get_eswitch_capabilities(struct qlcnic_adapter *adapter, u8 port,
813 arg2 = QLCRD32(adapter, QLCNIC_ARG2_CRB_OFFSET); 813 arg2 = QLCRD32(adapter, QLCNIC_ARG2_CRB_OFFSET);
814 814
815 eswitch->port = arg1 & 0xf; 815 eswitch->port = arg1 & 0xf;
816 eswitch->active_vports = LSB(arg2); 816 eswitch->max_ucast_filters = LSW(arg2);
817 eswitch->max_ucast_filters = MSB(arg2); 817 eswitch->max_active_vlans = MSW(arg2) & 0xfff;
818 eswitch->max_active_vlans = LSB(MSW(arg2));
819 if (arg1 & BIT_6) 818 if (arg1 & BIT_6)
820 eswitch->flags |= QLCNIC_SWITCH_VLAN_FILTERING; 819 eswitch->flags |= QLCNIC_SWITCH_VLAN_FILTERING;
821 if (arg1 & BIT_7) 820 if (arg1 & BIT_7)
@@ -943,43 +942,271 @@ int qlcnic_config_port_mirroring(struct qlcnic_adapter *adapter, u8 id,
943 return err; 942 return err;
944} 943}
945 944
946/* Configure eSwitch port */ 945int qlcnic_get_port_stats(struct qlcnic_adapter *adapter, const u8 func,
947int qlcnic_config_switch_port(struct qlcnic_adapter *adapter, u8 id, 946 const u8 rx_tx, struct __qlcnic_esw_statistics *esw_stats) {
948 int vlan_tagging, u8 discard_tagged, u8 promsc_mode, 947
949 u8 mac_learn, u8 pci_func, u16 vlan_id) 948 size_t stats_size = sizeof(struct __qlcnic_esw_statistics);
949 struct __qlcnic_esw_statistics *stats;
950 dma_addr_t stats_dma_t;
951 void *stats_addr;
952 u32 arg1;
953 int err;
954
955 if (esw_stats == NULL)
956 return -ENOMEM;
957
958 if (adapter->op_mode != QLCNIC_MGMT_FUNC &&
959 func != adapter->ahw.pci_func) {
960 dev_err(&adapter->pdev->dev,
961 "Not privilege to query stats for func=%d", func);
962 return -EIO;
963 }
964
965 stats_addr = pci_alloc_consistent(adapter->pdev, stats_size,
966 &stats_dma_t);
967 if (!stats_addr) {
968 dev_err(&adapter->pdev->dev, "Unable to allocate memory\n");
969 return -ENOMEM;
970 }
971 memset(stats_addr, 0, stats_size);
972
973 arg1 = func | QLCNIC_STATS_VERSION << 8 | QLCNIC_STATS_PORT << 12;
974 arg1 |= rx_tx << 15 | stats_size << 16;
975
976 err = qlcnic_issue_cmd(adapter,
977 adapter->ahw.pci_func,
978 adapter->fw_hal_version,
979 arg1,
980 MSD(stats_dma_t),
981 LSD(stats_dma_t),
982 QLCNIC_CDRP_CMD_GET_ESWITCH_STATS);
983
984 if (!err) {
985 stats = (struct __qlcnic_esw_statistics *)stats_addr;
986 esw_stats->context_id = le16_to_cpu(stats->context_id);
987 esw_stats->version = le16_to_cpu(stats->version);
988 esw_stats->size = le16_to_cpu(stats->size);
989 esw_stats->multicast_frames =
990 le64_to_cpu(stats->multicast_frames);
991 esw_stats->broadcast_frames =
992 le64_to_cpu(stats->broadcast_frames);
993 esw_stats->unicast_frames = le64_to_cpu(stats->unicast_frames);
994 esw_stats->dropped_frames = le64_to_cpu(stats->dropped_frames);
995 esw_stats->local_frames = le64_to_cpu(stats->local_frames);
996 esw_stats->errors = le64_to_cpu(stats->errors);
997 esw_stats->numbytes = le64_to_cpu(stats->numbytes);
998 }
999
1000 pci_free_consistent(adapter->pdev, stats_size, stats_addr,
1001 stats_dma_t);
1002 return err;
1003}
1004
1005int qlcnic_get_eswitch_stats(struct qlcnic_adapter *adapter, const u8 eswitch,
1006 const u8 rx_tx, struct __qlcnic_esw_statistics *esw_stats) {
1007
1008 struct __qlcnic_esw_statistics port_stats;
1009 u8 i;
1010 int ret = -EIO;
1011
1012 if (esw_stats == NULL)
1013 return -ENOMEM;
1014 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
1015 return -EIO;
1016 if (adapter->npars == NULL)
1017 return -EIO;
1018
1019 memset(esw_stats, 0, sizeof(struct __qlcnic_esw_statistics));
1020 esw_stats->context_id = eswitch;
1021
1022 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
1023 if (adapter->npars[i].phy_port != eswitch)
1024 continue;
1025
1026 memset(&port_stats, 0, sizeof(struct __qlcnic_esw_statistics));
1027 if (qlcnic_get_port_stats(adapter, i, rx_tx, &port_stats))
1028 continue;
1029
1030 esw_stats->size = port_stats.size;
1031 esw_stats->version = port_stats.version;
1032 esw_stats->unicast_frames += port_stats.unicast_frames;
1033 esw_stats->multicast_frames += port_stats.multicast_frames;
1034 esw_stats->broadcast_frames += port_stats.broadcast_frames;
1035 esw_stats->dropped_frames += port_stats.dropped_frames;
1036 esw_stats->errors += port_stats.errors;
1037 esw_stats->local_frames += port_stats.local_frames;
1038 esw_stats->numbytes += port_stats.numbytes;
1039
1040 ret = 0;
1041 }
1042 return ret;
1043}
1044
1045int qlcnic_clear_esw_stats(struct qlcnic_adapter *adapter, const u8 func_esw,
1046 const u8 port, const u8 rx_tx)
950{ 1047{
951 int err = -EIO; 1048
952 u32 arg1; 1049 u32 arg1;
953 struct qlcnic_eswitch *eswitch;
954 1050
955 if (adapter->op_mode != QLCNIC_MGMT_FUNC) 1051 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
956 return err; 1052 return -EIO;
957 1053
958 eswitch = &adapter->eswitch[id]; 1054 if (func_esw == QLCNIC_STATS_PORT) {
959 if (!(eswitch->flags & QLCNIC_SWITCH_ENABLE)) 1055 if (port >= QLCNIC_MAX_PCI_FUNC)
1056 goto err_ret;
1057 } else if (func_esw == QLCNIC_STATS_ESWITCH) {
1058 if (port >= QLCNIC_NIU_MAX_XG_PORTS)
1059 goto err_ret;
1060 } else {
1061 goto err_ret;
1062 }
1063
1064 if (rx_tx > QLCNIC_QUERY_TX_COUNTER)
1065 goto err_ret;
1066
1067 arg1 = port | QLCNIC_STATS_VERSION << 8 | func_esw << 12;
1068 arg1 |= BIT_14 | rx_tx << 15;
1069
1070 return qlcnic_issue_cmd(adapter,
1071 adapter->ahw.pci_func,
1072 adapter->fw_hal_version,
1073 arg1,
1074 0,
1075 0,
1076 QLCNIC_CDRP_CMD_GET_ESWITCH_STATS);
1077
1078err_ret:
1079 dev_err(&adapter->pdev->dev, "Invalid argument func_esw=%d port=%d"
1080 "rx_ctx=%d\n", func_esw, port, rx_tx);
1081 return -EIO;
1082}
1083
1084static int
1085__qlcnic_get_eswitch_port_config(struct qlcnic_adapter *adapter,
1086 u32 *arg1, u32 *arg2)
1087{
1088 int err = -EIO;
1089 u8 pci_func;
1090 pci_func = (*arg1 >> 8);
1091 err = qlcnic_issue_cmd(adapter,
1092 adapter->ahw.pci_func,
1093 adapter->fw_hal_version,
1094 *arg1,
1095 0,
1096 0,
1097 QLCNIC_CDRP_CMD_GET_ESWITCH_PORT_CONFIG);
1098
1099 if (err == QLCNIC_RCODE_SUCCESS) {
1100 *arg1 = QLCRD32(adapter, QLCNIC_ARG1_CRB_OFFSET);
1101 *arg2 = QLCRD32(adapter, QLCNIC_ARG2_CRB_OFFSET);
1102 dev_info(&adapter->pdev->dev,
1103 "eSwitch port config for pci func %d\n", pci_func);
1104 } else {
1105 dev_err(&adapter->pdev->dev,
1106 "Failed to get eswitch port config for pci func %d\n",
1107 pci_func);
1108 }
1109 return err;
1110}
1111/* Configure eSwitch port
1112op_mode = 0 for setting default port behavior
1113op_mode = 1 for setting vlan id
1114op_mode = 2 for deleting vlan id
1115op_type = 0 for vlan_id
1116op_type = 1 for port vlan_id
1117*/
1118int qlcnic_config_switch_port(struct qlcnic_adapter *adapter,
1119 struct qlcnic_esw_func_cfg *esw_cfg)
1120{
1121 int err = -EIO;
1122 u32 arg1, arg2 = 0;
1123 u8 pci_func;
1124
1125 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
960 return err; 1126 return err;
1127 pci_func = esw_cfg->pci_func;
1128 arg1 = (adapter->npars[pci_func].phy_port & BIT_0);
1129 arg1 |= (pci_func << 8);
961 1130
962 arg1 = eswitch->port | (discard_tagged ? BIT_4 : 0); 1131 if (__qlcnic_get_eswitch_port_config(adapter, &arg1, &arg2))
963 arg1 |= (promsc_mode ? BIT_6 : 0) | (mac_learn ? BIT_7 : 0); 1132 return err;
964 arg1 |= pci_func << 8; 1133 arg1 &= ~(0x0ff << 8);
965 if (vlan_tagging) 1134 arg1 |= (pci_func << 8);
966 arg1 |= BIT_5 | (vlan_id << 16); 1135 arg1 &= ~(BIT_2 | BIT_3);
1136 switch (esw_cfg->op_mode) {
1137 case QLCNIC_PORT_DEFAULTS:
1138 arg1 |= (BIT_4 | BIT_6 | BIT_7);
1139 arg2 |= (BIT_0 | BIT_1);
1140 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
1141 arg2 |= (BIT_2 | BIT_3);
1142 if (!(esw_cfg->discard_tagged))
1143 arg1 &= ~BIT_4;
1144 if (!(esw_cfg->promisc_mode))
1145 arg1 &= ~BIT_6;
1146 if (!(esw_cfg->mac_override))
1147 arg1 &= ~BIT_7;
1148 if (!(esw_cfg->mac_anti_spoof))
1149 arg2 &= ~BIT_0;
1150 if (!(esw_cfg->offload_flags & BIT_0))
1151 arg2 &= ~(BIT_1 | BIT_2 | BIT_3);
1152 if (!(esw_cfg->offload_flags & BIT_1))
1153 arg2 &= ~BIT_2;
1154 if (!(esw_cfg->offload_flags & BIT_2))
1155 arg2 &= ~BIT_3;
1156 break;
1157 case QLCNIC_ADD_VLAN:
1158 arg1 |= (BIT_2 | BIT_5);
1159 arg1 |= (esw_cfg->vlan_id << 16);
1160 break;
1161 case QLCNIC_DEL_VLAN:
1162 arg1 |= (BIT_3 | BIT_5);
1163 arg1 &= ~(0x0ffff << 16);
1164 break;
1165 default:
1166 return err;
1167 }
967 1168
968 err = qlcnic_issue_cmd(adapter, 1169 err = qlcnic_issue_cmd(adapter,
969 adapter->ahw.pci_func, 1170 adapter->ahw.pci_func,
970 adapter->fw_hal_version, 1171 adapter->fw_hal_version,
971 arg1, 1172 arg1,
972 0, 1173 arg2,
973 0, 1174 0,
974 QLCNIC_CDRP_CMD_CONFIGURE_ESWITCH); 1175 QLCNIC_CDRP_CMD_CONFIGURE_ESWITCH);
975 1176
976 if (err != QLCNIC_RCODE_SUCCESS) { 1177 if (err != QLCNIC_RCODE_SUCCESS) {
977 dev_err(&adapter->pdev->dev, 1178 dev_err(&adapter->pdev->dev,
978 "Failed to configure eswitch port%d\n", eswitch->port); 1179 "Failed to configure eswitch pci func %d\n", pci_func);
979 } else { 1180 } else {
980 dev_info(&adapter->pdev->dev, 1181 dev_info(&adapter->pdev->dev,
981 "Configured eSwitch for port %d\n", eswitch->port); 1182 "Configured eSwitch for pci func %d\n", pci_func);
982 } 1183 }
983 1184
984 return err; 1185 return err;
985} 1186}
1187
1188int
1189qlcnic_get_eswitch_port_config(struct qlcnic_adapter *adapter,
1190 struct qlcnic_esw_func_cfg *esw_cfg)
1191{
1192 u32 arg1, arg2;
1193 u8 phy_port;
1194 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
1195 phy_port = adapter->npars[esw_cfg->pci_func].phy_port;
1196 else
1197 phy_port = adapter->physical_port;
1198 arg1 = phy_port;
1199 arg1 |= (esw_cfg->pci_func << 8);
1200 if (__qlcnic_get_eswitch_port_config(adapter, &arg1, &arg2))
1201 return -EIO;
1202
1203 esw_cfg->discard_tagged = !!(arg1 & BIT_4);
1204 esw_cfg->host_vlan_tag = !!(arg1 & BIT_5);
1205 esw_cfg->promisc_mode = !!(arg1 & BIT_6);
1206 esw_cfg->mac_override = !!(arg1 & BIT_7);
1207 esw_cfg->vlan_id = LSW(arg1 >> 16);
1208 esw_cfg->mac_anti_spoof = (arg2 & 0x1);
1209 esw_cfg->offload_flags = ((arg2 >> 1) & 0x7);
1210
1211 return 0;
1212}
diff --git a/drivers/net/qlcnic/qlcnic_ethtool.c b/drivers/net/qlcnic/qlcnic_ethtool.c
index 9328d59e21e0..cb9463bd6b1e 100644
--- a/drivers/net/qlcnic/qlcnic_ethtool.c
+++ b/drivers/net/qlcnic/qlcnic_ethtool.c
@@ -99,7 +99,7 @@ static const u32 diag_registers[] = {
99 CRB_XG_STATE_P3, 99 CRB_XG_STATE_P3,
100 CRB_FW_CAPABILITIES_1, 100 CRB_FW_CAPABILITIES_1,
101 ISR_INT_STATE_REG, 101 ISR_INT_STATE_REG,
102 QLCNIC_CRB_DEV_REF_COUNT, 102 QLCNIC_CRB_DRV_ACTIVE,
103 QLCNIC_CRB_DEV_STATE, 103 QLCNIC_CRB_DEV_STATE,
104 QLCNIC_CRB_DRV_STATE, 104 QLCNIC_CRB_DRV_STATE,
105 QLCNIC_CRB_DRV_SCRATCH, 105 QLCNIC_CRB_DRV_SCRATCH,
@@ -115,9 +115,13 @@ static const u32 diag_registers[] = {
115 -1 115 -1
116}; 116};
117 117
118#define QLCNIC_MGMT_API_VERSION 2
119#define QLCNIC_DEV_INFO_SIZE 1
120#define QLCNIC_ETHTOOL_REGS_VER 2
118static int qlcnic_get_regs_len(struct net_device *dev) 121static int qlcnic_get_regs_len(struct net_device *dev)
119{ 122{
120 return sizeof(diag_registers) + QLCNIC_RING_REGS_LEN; 123 return sizeof(diag_registers) + QLCNIC_RING_REGS_LEN +
124 QLCNIC_DEV_INFO_SIZE + 1;
121} 125}
122 126
123static int qlcnic_get_eeprom_len(struct net_device *dev) 127static int qlcnic_get_eeprom_len(struct net_device *dev)
@@ -342,10 +346,13 @@ qlcnic_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *p)
342 int ring, i = 0; 346 int ring, i = 0;
343 347
344 memset(p, 0, qlcnic_get_regs_len(dev)); 348 memset(p, 0, qlcnic_get_regs_len(dev));
345 regs->version = (1 << 24) | (adapter->ahw.revision_id << 16) | 349 regs->version = (QLCNIC_ETHTOOL_REGS_VER << 24) |
346 (adapter->pdev)->device; 350 (adapter->ahw.revision_id << 16) | (adapter->pdev)->device;
347 351
348 for (i = 0; diag_registers[i] != -1; i++) 352 regs_buff[0] = (0xcafe0000 | (QLCNIC_DEV_INFO_SIZE & 0xffff));
353 regs_buff[1] = QLCNIC_MGMT_API_VERSION;
354
355 for (i = QLCNIC_DEV_INFO_SIZE + 1; diag_registers[i] != -1; i++)
349 regs_buff[i] = QLCRD32(adapter, diag_registers[i]); 356 regs_buff[i] = QLCRD32(adapter, diag_registers[i]);
350 357
351 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 358 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
@@ -747,6 +754,14 @@ qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
747{ 754{
748 memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN); 755 memset(data, 0, sizeof(u64) * QLCNIC_TEST_LEN);
749 756
757 data[0] = qlcnic_reg_test(dev);
758 if (data[0])
759 eth_test->flags |= ETH_TEST_FL_FAILED;
760
761 data[1] = (u64) qlcnic_test_link(dev);
762 if (data[1])
763 eth_test->flags |= ETH_TEST_FL_FAILED;
764
750 if (eth_test->flags == ETH_TEST_FL_OFFLINE) { 765 if (eth_test->flags == ETH_TEST_FL_OFFLINE) {
751 data[2] = qlcnic_irq_test(dev); 766 data[2] = qlcnic_irq_test(dev);
752 if (data[2]) 767 if (data[2])
@@ -757,15 +772,6 @@ qlcnic_diag_test(struct net_device *dev, struct ethtool_test *eth_test,
757 eth_test->flags |= ETH_TEST_FL_FAILED; 772 eth_test->flags |= ETH_TEST_FL_FAILED;
758 773
759 } 774 }
760
761 data[0] = qlcnic_reg_test(dev);
762 if (data[0])
763 eth_test->flags |= ETH_TEST_FL_FAILED;
764
765 /* link test */
766 data[1] = (u64) qlcnic_test_link(dev);
767 if (data[1])
768 eth_test->flags |= ETH_TEST_FL_FAILED;
769} 775}
770 776
771static void 777static void
@@ -805,6 +811,20 @@ qlcnic_get_ethtool_stats(struct net_device *dev,
805 } 811 }
806} 812}
807 813
814static int qlcnic_set_tx_csum(struct net_device *dev, u32 data)
815{
816 struct qlcnic_adapter *adapter = netdev_priv(dev);
817
818 if ((adapter->flags & QLCNIC_ESWITCH_ENABLED))
819 return -EOPNOTSUPP;
820 if (data)
821 dev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
822 else
823 dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
824
825 return 0;
826
827}
808static u32 qlcnic_get_tx_csum(struct net_device *dev) 828static u32 qlcnic_get_tx_csum(struct net_device *dev)
809{ 829{
810 return dev->features & NETIF_F_IP_CSUM; 830 return dev->features & NETIF_F_IP_CSUM;
@@ -819,7 +839,23 @@ static u32 qlcnic_get_rx_csum(struct net_device *dev)
819static int qlcnic_set_rx_csum(struct net_device *dev, u32 data) 839static int qlcnic_set_rx_csum(struct net_device *dev, u32 data)
820{ 840{
821 struct qlcnic_adapter *adapter = netdev_priv(dev); 841 struct qlcnic_adapter *adapter = netdev_priv(dev);
842
843 if ((adapter->flags & QLCNIC_ESWITCH_ENABLED))
844 return -EOPNOTSUPP;
845 if (!!data) {
846 adapter->rx_csum = !!data;
847 return 0;
848 }
849
850 if (adapter->flags & QLCNIC_LRO_ENABLED) {
851 if (qlcnic_config_hw_lro(adapter, QLCNIC_LRO_DISABLED))
852 return -EIO;
853
854 dev->features &= ~NETIF_F_LRO;
855 qlcnic_send_lro_cleanup(adapter);
856 }
822 adapter->rx_csum = !!data; 857 adapter->rx_csum = !!data;
858 dev_info(&adapter->pdev->dev, "disabling LRO as rx_csum is off\n");
823 return 0; 859 return 0;
824} 860}
825 861
@@ -1002,6 +1038,15 @@ static int qlcnic_set_flags(struct net_device *netdev, u32 data)
1002 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)) 1038 if (!(adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO))
1003 return -EINVAL; 1039 return -EINVAL;
1004 1040
1041 if (!adapter->rx_csum) {
1042 dev_info(&adapter->pdev->dev, "rx csum is off, "
1043 "cannot toggle lro\n");
1044 return -EINVAL;
1045 }
1046
1047 if ((data & ETH_FLAG_LRO) && (adapter->flags & QLCNIC_LRO_ENABLED))
1048 return 0;
1049
1005 if (data & ETH_FLAG_LRO) { 1050 if (data & ETH_FLAG_LRO) {
1006 hw_lro = QLCNIC_LRO_ENABLED; 1051 hw_lro = QLCNIC_LRO_ENABLED;
1007 netdev->features |= NETIF_F_LRO; 1052 netdev->features |= NETIF_F_LRO;
@@ -1048,7 +1093,7 @@ const struct ethtool_ops qlcnic_ethtool_ops = {
1048 .get_pauseparam = qlcnic_get_pauseparam, 1093 .get_pauseparam = qlcnic_get_pauseparam,
1049 .set_pauseparam = qlcnic_set_pauseparam, 1094 .set_pauseparam = qlcnic_set_pauseparam,
1050 .get_tx_csum = qlcnic_get_tx_csum, 1095 .get_tx_csum = qlcnic_get_tx_csum,
1051 .set_tx_csum = ethtool_op_set_tx_csum, 1096 .set_tx_csum = qlcnic_set_tx_csum,
1052 .set_sg = ethtool_op_set_sg, 1097 .set_sg = ethtool_op_set_sg,
1053 .get_tso = qlcnic_get_tso, 1098 .get_tso = qlcnic_get_tso,
1054 .set_tso = qlcnic_set_tso, 1099 .set_tso = qlcnic_set_tso,
diff --git a/drivers/net/qlcnic/qlcnic_hdr.h b/drivers/net/qlcnic/qlcnic_hdr.h
index 15fc32070be3..716203e41dc7 100644
--- a/drivers/net/qlcnic/qlcnic_hdr.h
+++ b/drivers/net/qlcnic/qlcnic_hdr.h
@@ -698,7 +698,7 @@ enum {
698#define QLCNIC_PEG_ALIVE_COUNTER (QLCNIC_CAM_RAM(0xb0)) 698#define QLCNIC_PEG_ALIVE_COUNTER (QLCNIC_CAM_RAM(0xb0))
699#define QLCNIC_PEG_HALT_STATUS1 (QLCNIC_CAM_RAM(0xa8)) 699#define QLCNIC_PEG_HALT_STATUS1 (QLCNIC_CAM_RAM(0xa8))
700#define QLCNIC_PEG_HALT_STATUS2 (QLCNIC_CAM_RAM(0xac)) 700#define QLCNIC_PEG_HALT_STATUS2 (QLCNIC_CAM_RAM(0xac))
701#define QLCNIC_CRB_DEV_REF_COUNT (QLCNIC_CAM_RAM(0x138)) 701#define QLCNIC_CRB_DRV_ACTIVE (QLCNIC_CAM_RAM(0x138))
702#define QLCNIC_CRB_DEV_STATE (QLCNIC_CAM_RAM(0x140)) 702#define QLCNIC_CRB_DEV_STATE (QLCNIC_CAM_RAM(0x140))
703 703
704#define QLCNIC_CRB_DRV_STATE (QLCNIC_CAM_RAM(0x144)) 704#define QLCNIC_CRB_DRV_STATE (QLCNIC_CAM_RAM(0x144))
@@ -718,8 +718,9 @@ enum {
718#define QLCNIC_DEV_FAILED 0x6 718#define QLCNIC_DEV_FAILED 0x6
719#define QLCNIC_DEV_QUISCENT 0x7 719#define QLCNIC_DEV_QUISCENT 0x7
720 720
721#define QLCNIC_DEV_NPAR_NOT_RDY 0 721#define QLCNIC_DEV_NPAR_NON_OPER 0 /* NON Operational */
722#define QLCNIC_DEV_NPAR_RDY 1 722#define QLCNIC_DEV_NPAR_OPER 1 /* NPAR Operational */
723#define QLCNIC_DEV_NPAR_OPER_TIMEO 30 /* Operational time out */
723 724
724#define QLC_DEV_CHECK_ACTIVE(VAL, FN) ((VAL) &= (1 << (FN * 4))) 725#define QLC_DEV_CHECK_ACTIVE(VAL, FN) ((VAL) &= (1 << (FN * 4)))
725#define QLC_DEV_SET_REF_CNT(VAL, FN) ((VAL) |= (1 << (FN * 4))) 726#define QLC_DEV_SET_REF_CNT(VAL, FN) ((VAL) |= (1 << (FN * 4)))
@@ -744,6 +745,15 @@ enum {
744#define FW_POLL_DELAY (1 * HZ) 745#define FW_POLL_DELAY (1 * HZ)
745#define FW_FAIL_THRESH 2 746#define FW_FAIL_THRESH 2
746 747
748#define QLCNIC_RESET_TIMEOUT_SECS 10
749#define QLCNIC_INIT_TIMEOUT_SECS 30
750#define QLCNIC_RCVPEG_CHECK_RETRY_COUNT 2000
751#define QLCNIC_RCVPEG_CHECK_DELAY 10
752#define QLCNIC_CMDPEG_CHECK_RETRY_COUNT 60
753#define QLCNIC_CMDPEG_CHECK_DELAY 500
754#define QLCNIC_HEARTBEAT_PERIOD_MSECS 200
755#define QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT 45
756
747#define ISR_MSI_INT_TRIGGER(FUNC) (QLCNIC_PCIX_PS_REG(PCIX_MSI_F(FUNC))) 757#define ISR_MSI_INT_TRIGGER(FUNC) (QLCNIC_PCIX_PS_REG(PCIX_MSI_F(FUNC)))
748#define ISR_LEGACY_INT_TRIGGERED(VAL) (((VAL) & 0x300) == 0x200) 758#define ISR_LEGACY_INT_TRIGGERED(VAL) (((VAL) & 0x300) == 0x200)
749 759
@@ -770,6 +780,7 @@ struct qlcnic_legacy_intr_set {
770#define QLCNIC_DRV_OP_MODE 0x1b2170 780#define QLCNIC_DRV_OP_MODE 0x1b2170
771#define QLCNIC_MSIX_BASE 0x132110 781#define QLCNIC_MSIX_BASE 0x132110
772#define QLCNIC_MAX_PCI_FUNC 8 782#define QLCNIC_MAX_PCI_FUNC 8
783#define QLCNIC_MAX_VLAN_FILTERS 64
773 784
774/* PCI function operational mode */ 785/* PCI function operational mode */
775enum { 786enum {
@@ -778,6 +789,12 @@ enum {
778 QLCNIC_NON_PRIV_FUNC = 2 789 QLCNIC_NON_PRIV_FUNC = 2
779}; 790};
780 791
792enum {
793 QLCNIC_PORT_DEFAULTS = 0,
794 QLCNIC_ADD_VLAN = 1,
795 QLCNIC_DEL_VLAN = 2
796};
797
781#define QLC_DEV_DRV_DEFAULT 0x11111111 798#define QLC_DEV_DRV_DEFAULT 0x11111111
782 799
783#define LSB(x) ((uint8_t)(x)) 800#define LSB(x) ((uint8_t)(x))
diff --git a/drivers/net/qlcnic/qlcnic_hw.c b/drivers/net/qlcnic/qlcnic_hw.c
index e08c8b0556a4..c198df90ff3c 100644
--- a/drivers/net/qlcnic/qlcnic_hw.c
+++ b/drivers/net/qlcnic/qlcnic_hw.c
@@ -297,8 +297,8 @@ qlcnic_pcie_sem_lock(struct qlcnic_adapter *adapter, int sem, u32 id_reg)
297 break; 297 break;
298 if (++timeout >= QLCNIC_PCIE_SEM_TIMEOUT) { 298 if (++timeout >= QLCNIC_PCIE_SEM_TIMEOUT) {
299 dev_err(&adapter->pdev->dev, 299 dev_err(&adapter->pdev->dev,
300 "Failed to acquire sem=%d lock;reg_id=%d\n", 300 "Failed to acquire sem=%d lock; holdby=%d\n",
301 sem, id_reg); 301 sem, id_reg ? QLCRD32(adapter, id_reg) : -1);
302 return -EIO; 302 return -EIO;
303 } 303 }
304 msleep(1); 304 msleep(1);
@@ -375,7 +375,7 @@ qlcnic_send_cmd_descs(struct qlcnic_adapter *adapter,
375 375
376static int 376static int
377qlcnic_sre_macaddr_change(struct qlcnic_adapter *adapter, u8 *addr, 377qlcnic_sre_macaddr_change(struct qlcnic_adapter *adapter, u8 *addr,
378 unsigned op) 378 u16 vlan_id, unsigned op)
379{ 379{
380 struct qlcnic_nic_req req; 380 struct qlcnic_nic_req req;
381 struct qlcnic_mac_req *mac_req; 381 struct qlcnic_mac_req *mac_req;
@@ -391,6 +391,8 @@ qlcnic_sre_macaddr_change(struct qlcnic_adapter *adapter, u8 *addr,
391 mac_req->op = op; 391 mac_req->op = op;
392 memcpy(mac_req->mac_addr, addr, 6); 392 memcpy(mac_req->mac_addr, addr, 6);
393 393
394 req.words[1] = cpu_to_le64(vlan_id);
395
394 return qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1); 396 return qlcnic_send_cmd_descs(adapter, (struct cmd_desc_type0 *)&req, 1);
395} 397}
396 398
@@ -415,7 +417,7 @@ static int qlcnic_nic_add_mac(struct qlcnic_adapter *adapter, u8 *addr)
415 memcpy(cur->mac_addr, addr, ETH_ALEN); 417 memcpy(cur->mac_addr, addr, ETH_ALEN);
416 418
417 if (qlcnic_sre_macaddr_change(adapter, 419 if (qlcnic_sre_macaddr_change(adapter,
418 cur->mac_addr, QLCNIC_MAC_ADD)) { 420 cur->mac_addr, 0, QLCNIC_MAC_ADD)) {
419 kfree(cur); 421 kfree(cur);
420 return -EIO; 422 return -EIO;
421 } 423 }
@@ -485,12 +487,63 @@ void qlcnic_free_mac_list(struct qlcnic_adapter *adapter)
485 while (!list_empty(head)) { 487 while (!list_empty(head)) {
486 cur = list_entry(head->next, struct qlcnic_mac_list_s, list); 488 cur = list_entry(head->next, struct qlcnic_mac_list_s, list);
487 qlcnic_sre_macaddr_change(adapter, 489 qlcnic_sre_macaddr_change(adapter,
488 cur->mac_addr, QLCNIC_MAC_DEL); 490 cur->mac_addr, 0, QLCNIC_MAC_DEL);
489 list_del(&cur->list); 491 list_del(&cur->list);
490 kfree(cur); 492 kfree(cur);
491 } 493 }
492} 494}
493 495
496void qlcnic_prune_lb_filters(struct qlcnic_adapter *adapter)
497{
498 struct qlcnic_filter *tmp_fil;
499 struct hlist_node *tmp_hnode, *n;
500 struct hlist_head *head;
501 int i;
502
503 for (i = 0; i < adapter->fhash.fmax; i++) {
504 head = &(adapter->fhash.fhead[i]);
505
506 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode)
507 {
508 if (jiffies >
509 (QLCNIC_FILTER_AGE * HZ + tmp_fil->ftime)) {
510 qlcnic_sre_macaddr_change(adapter,
511 tmp_fil->faddr, tmp_fil->vlan_id,
512 tmp_fil->vlan_id ? QLCNIC_MAC_VLAN_DEL :
513 QLCNIC_MAC_DEL);
514 spin_lock_bh(&adapter->mac_learn_lock);
515 adapter->fhash.fnum--;
516 hlist_del(&tmp_fil->fnode);
517 spin_unlock_bh(&adapter->mac_learn_lock);
518 kfree(tmp_fil);
519 }
520 }
521 }
522}
523
524void qlcnic_delete_lb_filters(struct qlcnic_adapter *adapter)
525{
526 struct qlcnic_filter *tmp_fil;
527 struct hlist_node *tmp_hnode, *n;
528 struct hlist_head *head;
529 int i;
530
531 for (i = 0; i < adapter->fhash.fmax; i++) {
532 head = &(adapter->fhash.fhead[i]);
533
534 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
535 qlcnic_sre_macaddr_change(adapter, tmp_fil->faddr,
536 tmp_fil->vlan_id, tmp_fil->vlan_id ?
537 QLCNIC_MAC_VLAN_DEL : QLCNIC_MAC_DEL);
538 spin_lock_bh(&adapter->mac_learn_lock);
539 adapter->fhash.fnum--;
540 hlist_del(&tmp_fil->fnode);
541 spin_unlock_bh(&adapter->mac_learn_lock);
542 kfree(tmp_fil);
543 }
544 }
545}
546
494#define QLCNIC_CONFIG_INTR_COALESCE 3 547#define QLCNIC_CONFIG_INTR_COALESCE 3
495 548
496/* 549/*
@@ -715,19 +768,6 @@ int qlcnic_change_mtu(struct net_device *netdev, int mtu)
715 return rc; 768 return rc;
716} 769}
717 770
718int qlcnic_get_mac_addr(struct qlcnic_adapter *adapter, u8 *mac)
719{
720 u32 crbaddr;
721 int pci_func = adapter->ahw.pci_func;
722
723 crbaddr = CRB_MAC_BLOCK_START +
724 (4 * ((pci_func/2) * 3)) + (4 * (pci_func & 1));
725
726 qlcnic_fetch_mac(adapter, crbaddr, crbaddr+4, pci_func & 1, mac);
727
728 return 0;
729}
730
731/* 771/*
732 * Changes the CRB window to the specified window. 772 * Changes the CRB window to the specified window.
733 */ 773 */
@@ -1245,4 +1285,5 @@ void qlcnic_clear_ilb_mode(struct qlcnic_adapter *adapter)
1245 mode = VPORT_MISS_MODE_ACCEPT_MULTI; 1285 mode = VPORT_MISS_MODE_ACCEPT_MULTI;
1246 1286
1247 qlcnic_nic_set_promisc(adapter, mode); 1287 qlcnic_nic_set_promisc(adapter, mode);
1288 msleep(1000);
1248} 1289}
diff --git a/drivers/net/qlcnic/qlcnic_init.c b/drivers/net/qlcnic/qlcnic_init.c
index 2c7cf0b64811..5c33d15c874a 100644
--- a/drivers/net/qlcnic/qlcnic_init.c
+++ b/drivers/net/qlcnic/qlcnic_init.c
@@ -25,6 +25,7 @@
25#include <linux/netdevice.h> 25#include <linux/netdevice.h>
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/if_vlan.h>
28#include "qlcnic.h" 29#include "qlcnic.h"
29 30
30struct crb_addr_pair { 31struct crb_addr_pair {
@@ -45,6 +46,9 @@ static void
45qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter, 46qlcnic_post_rx_buffers_nodb(struct qlcnic_adapter *adapter,
46 struct qlcnic_host_rds_ring *rds_ring); 47 struct qlcnic_host_rds_ring *rds_ring);
47 48
49static int
50qlcnic_check_fw_hearbeat(struct qlcnic_adapter *adapter);
51
48static void crb_addr_transform_setup(void) 52static void crb_addr_transform_setup(void)
49{ 53{
50 crb_addr_transform(XDMA); 54 crb_addr_transform(XDMA);
@@ -136,8 +140,6 @@ void qlcnic_reset_rx_buffers_list(struct qlcnic_adapter *adapter)
136 for (ring = 0; ring < adapter->max_rds_rings; ring++) { 140 for (ring = 0; ring < adapter->max_rds_rings; ring++) {
137 rds_ring = &recv_ctx->rds_rings[ring]; 141 rds_ring = &recv_ctx->rds_rings[ring];
138 142
139 spin_lock(&rds_ring->lock);
140
141 INIT_LIST_HEAD(&rds_ring->free_list); 143 INIT_LIST_HEAD(&rds_ring->free_list);
142 144
143 rx_buf = rds_ring->rx_buf_arr; 145 rx_buf = rds_ring->rx_buf_arr;
@@ -146,8 +148,6 @@ void qlcnic_reset_rx_buffers_list(struct qlcnic_adapter *adapter)
146 &rds_ring->free_list); 148 &rds_ring->free_list);
147 rx_buf++; 149 rx_buf++;
148 } 150 }
149
150 spin_unlock(&rds_ring->lock);
151 } 151 }
152} 152}
153 153
@@ -439,11 +439,14 @@ int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter)
439 u32 off; 439 u32 off;
440 struct pci_dev *pdev = adapter->pdev; 440 struct pci_dev *pdev = adapter->pdev;
441 441
442 /* resetall */ 442 QLCWR32(adapter, CRB_CMDPEG_STATE, 0);
443 QLCWR32(adapter, CRB_RCVPEG_STATE, 0);
444
443 qlcnic_rom_lock(adapter); 445 qlcnic_rom_lock(adapter);
444 QLCWR32(adapter, QLCNIC_ROMUSB_GLB_SW_RESET, 0xfeffffff); 446 QLCWR32(adapter, QLCNIC_ROMUSB_GLB_SW_RESET, 0xfeffffff);
445 qlcnic_rom_unlock(adapter); 447 qlcnic_rom_unlock(adapter);
446 448
449 /* Init HW CRB block */
447 if (qlcnic_rom_fast_read(adapter, 0, &n) != 0 || (n != 0xcafecafe) || 450 if (qlcnic_rom_fast_read(adapter, 0, &n) != 0 || (n != 0xcafecafe) ||
448 qlcnic_rom_fast_read(adapter, 4, &n) != 0) { 451 qlcnic_rom_fast_read(adapter, 4, &n) != 0) {
449 dev_err(&pdev->dev, "ERROR Reading crb_init area: val:%x\n", n); 452 dev_err(&pdev->dev, "ERROR Reading crb_init area: val:%x\n", n);
@@ -524,13 +527,10 @@ int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter)
524 } 527 }
525 kfree(buf); 528 kfree(buf);
526 529
527 /* p2dn replyCount */ 530 /* Initialize protocol process engine */
528 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_D + 0xec, 0x1e); 531 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_D + 0xec, 0x1e);
529 /* disable_peg_cache 0 & 1*/
530 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_D + 0x4c, 8); 532 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_D + 0x4c, 8);
531 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_I + 0x4c, 8); 533 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_I + 0x4c, 8);
532
533 /* peg_clr_all */
534 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x8, 0); 534 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0x8, 0);
535 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0xc, 0); 535 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_0 + 0xc, 0);
536 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x8, 0); 536 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_1 + 0x8, 0);
@@ -539,9 +539,87 @@ int qlcnic_pinit_from_rom(struct qlcnic_adapter *adapter)
539 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_2 + 0xc, 0); 539 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_2 + 0xc, 0);
540 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x8, 0); 540 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0x8, 0);
541 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0xc, 0); 541 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_3 + 0xc, 0);
542 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0x8, 0);
543 QLCWR32(adapter, QLCNIC_CRB_PEG_NET_4 + 0xc, 0);
544 msleep(1);
545 QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS1, 0);
546 QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS2, 0);
542 return 0; 547 return 0;
543} 548}
544 549
550static int qlcnic_cmd_peg_ready(struct qlcnic_adapter *adapter)
551{
552 u32 val;
553 int retries = QLCNIC_CMDPEG_CHECK_RETRY_COUNT;
554
555 do {
556 val = QLCRD32(adapter, CRB_CMDPEG_STATE);
557
558 switch (val) {
559 case PHAN_INITIALIZE_COMPLETE:
560 case PHAN_INITIALIZE_ACK:
561 return 0;
562 case PHAN_INITIALIZE_FAILED:
563 goto out_err;
564 default:
565 break;
566 }
567
568 msleep(QLCNIC_CMDPEG_CHECK_DELAY);
569
570 } while (--retries);
571
572 QLCWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED);
573
574out_err:
575 dev_err(&adapter->pdev->dev, "Command Peg initialization not "
576 "complete, state: 0x%x.\n", val);
577 return -EIO;
578}
579
580static int
581qlcnic_receive_peg_ready(struct qlcnic_adapter *adapter)
582{
583 u32 val;
584 int retries = QLCNIC_RCVPEG_CHECK_RETRY_COUNT;
585
586 do {
587 val = QLCRD32(adapter, CRB_RCVPEG_STATE);
588
589 if (val == PHAN_PEG_RCV_INITIALIZED)
590 return 0;
591
592 msleep(QLCNIC_RCVPEG_CHECK_DELAY);
593
594 } while (--retries);
595
596 if (!retries) {
597 dev_err(&adapter->pdev->dev, "Receive Peg initialization not "
598 "complete, state: 0x%x.\n", val);
599 return -EIO;
600 }
601
602 return 0;
603}
604
605int
606qlcnic_check_fw_status(struct qlcnic_adapter *adapter)
607{
608 int err;
609
610 err = qlcnic_cmd_peg_ready(adapter);
611 if (err)
612 return err;
613
614 err = qlcnic_receive_peg_ready(adapter);
615 if (err)
616 return err;
617
618 QLCWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK);
619
620 return err;
621}
622
545int 623int
546qlcnic_setup_idc_param(struct qlcnic_adapter *adapter) { 624qlcnic_setup_idc_param(struct qlcnic_adapter *adapter) {
547 625
@@ -557,12 +635,12 @@ qlcnic_setup_idc_param(struct qlcnic_adapter *adapter) {
557 } 635 }
558 adapter->physical_port = (val >> 2); 636 adapter->physical_port = (val >> 2);
559 if (qlcnic_rom_fast_read(adapter, QLCNIC_ROM_DEV_INIT_TIMEOUT, &timeo)) 637 if (qlcnic_rom_fast_read(adapter, QLCNIC_ROM_DEV_INIT_TIMEOUT, &timeo))
560 timeo = 30; 638 timeo = QLCNIC_INIT_TIMEOUT_SECS;
561 639
562 adapter->dev_init_timeo = timeo; 640 adapter->dev_init_timeo = timeo;
563 641
564 if (qlcnic_rom_fast_read(adapter, QLCNIC_ROM_DRV_RESET_TIMEOUT, &timeo)) 642 if (qlcnic_rom_fast_read(adapter, QLCNIC_ROM_DRV_RESET_TIMEOUT, &timeo))
565 timeo = 10; 643 timeo = QLCNIC_RESET_TIMEOUT_SECS;
566 644
567 adapter->reset_ack_timeo = timeo; 645 adapter->reset_ack_timeo = timeo;
568 646
@@ -906,54 +984,47 @@ qlcnic_get_bios_version(struct qlcnic_adapter *adapter)
906 return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) + (bios_ver >> 24); 984 return (bios_ver << 16) + ((bios_ver >> 8) & 0xff00) + (bios_ver >> 24);
907} 985}
908 986
909int 987static void qlcnic_rom_lock_recovery(struct qlcnic_adapter *adapter)
910qlcnic_need_fw_reset(struct qlcnic_adapter *adapter)
911{ 988{
912 u32 count, old_count; 989 if (qlcnic_pcie_sem_lock(adapter, 2, QLCNIC_ROM_LOCK_ID))
913 u32 val, version, major, minor, build; 990 dev_info(&adapter->pdev->dev, "Resetting rom_lock\n");
914 int i, timeout;
915
916 if (adapter->need_fw_reset)
917 return 1;
918 991
919 /* last attempt had failed */ 992 qlcnic_pcie_sem_unlock(adapter, 2);
920 if (QLCRD32(adapter, CRB_CMDPEG_STATE) == PHAN_INITIALIZE_FAILED) 993}
921 return 1;
922 994
923 old_count = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 995static int
996qlcnic_check_fw_hearbeat(struct qlcnic_adapter *adapter)
997{
998 u32 heartbeat, ret = -EIO;
999 int retries = QLCNIC_HEARTBEAT_CHECK_RETRY_COUNT;
924 1000
925 for (i = 0; i < 10; i++) { 1001 adapter->heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
926 1002
927 timeout = msleep_interruptible(200); 1003 do {
928 if (timeout) { 1004 msleep(QLCNIC_HEARTBEAT_PERIOD_MSECS);
929 QLCWR32(adapter, CRB_CMDPEG_STATE, 1005 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
930 PHAN_INITIALIZE_FAILED); 1006 if (heartbeat != adapter->heartbeat) {
931 return -EINTR; 1007 ret = QLCNIC_RCODE_SUCCESS;
1008 break;
932 } 1009 }
1010 } while (--retries);
933 1011
934 count = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 1012 return ret;
935 if (count != old_count) 1013}
936 break;
937 }
938 1014
939 /* firmware is dead */ 1015int
940 if (count == old_count) 1016qlcnic_need_fw_reset(struct qlcnic_adapter *adapter)
1017{
1018 if (qlcnic_check_fw_hearbeat(adapter)) {
1019 qlcnic_rom_lock_recovery(adapter);
941 return 1; 1020 return 1;
1021 }
942 1022
943 /* check if we have got newer or different file firmware */ 1023 if (adapter->need_fw_reset)
944 if (adapter->fw) { 1024 return 1;
945
946 val = qlcnic_get_fw_version(adapter);
947
948 version = QLCNIC_DECODE_VERSION(val);
949
950 major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
951 minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
952 build = QLCRD32(adapter, QLCNIC_FW_VERSION_SUB);
953 1025
954 if (version > QLCNIC_VERSION_CODE(major, minor, build)) 1026 if (adapter->fw)
955 return 1; 1027 return 1;
956 }
957 1028
958 return 0; 1029 return 0;
959} 1030}
@@ -1089,18 +1160,6 @@ qlcnic_validate_firmware(struct qlcnic_adapter *adapter)
1089 return -EINVAL; 1160 return -EINVAL;
1090 } 1161 }
1091 1162
1092 /* check if flashed firmware is newer */
1093 if (qlcnic_rom_fast_read(adapter,
1094 QLCNIC_FW_VERSION_OFFSET, (int *)&val))
1095 return -EIO;
1096
1097 val = QLCNIC_DECODE_VERSION(val);
1098 if (val > ver) {
1099 dev_info(&pdev->dev, "%s: firmware is older than flash\n",
1100 fw_name[fw_type]);
1101 return -EINVAL;
1102 }
1103
1104 QLCWR32(adapter, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC); 1163 QLCWR32(adapter, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC);
1105 return 0; 1164 return 0;
1106} 1165}
@@ -1162,78 +1221,6 @@ qlcnic_release_firmware(struct qlcnic_adapter *adapter)
1162 adapter->fw = NULL; 1221 adapter->fw = NULL;
1163} 1222}
1164 1223
1165static int qlcnic_cmd_peg_ready(struct qlcnic_adapter *adapter)
1166{
1167 u32 val;
1168 int retries = 60;
1169
1170 do {
1171 val = QLCRD32(adapter, CRB_CMDPEG_STATE);
1172
1173 switch (val) {
1174 case PHAN_INITIALIZE_COMPLETE:
1175 case PHAN_INITIALIZE_ACK:
1176 return 0;
1177 case PHAN_INITIALIZE_FAILED:
1178 goto out_err;
1179 default:
1180 break;
1181 }
1182
1183 msleep(500);
1184
1185 } while (--retries);
1186
1187 QLCWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_FAILED);
1188
1189out_err:
1190 dev_err(&adapter->pdev->dev, "Command Peg initialization not "
1191 "complete, state: 0x%x.\n", val);
1192 return -EIO;
1193}
1194
1195static int
1196qlcnic_receive_peg_ready(struct qlcnic_adapter *adapter)
1197{
1198 u32 val;
1199 int retries = 2000;
1200
1201 do {
1202 val = QLCRD32(adapter, CRB_RCVPEG_STATE);
1203
1204 if (val == PHAN_PEG_RCV_INITIALIZED)
1205 return 0;
1206
1207 msleep(10);
1208
1209 } while (--retries);
1210
1211 if (!retries) {
1212 dev_err(&adapter->pdev->dev, "Receive Peg initialization not "
1213 "complete, state: 0x%x.\n", val);
1214 return -EIO;
1215 }
1216
1217 return 0;
1218}
1219
1220int qlcnic_init_firmware(struct qlcnic_adapter *adapter)
1221{
1222 int err;
1223
1224 err = qlcnic_cmd_peg_ready(adapter);
1225 if (err)
1226 return err;
1227
1228 err = qlcnic_receive_peg_ready(adapter);
1229 if (err)
1230 return err;
1231
1232 QLCWR32(adapter, CRB_CMDPEG_STATE, PHAN_INITIALIZE_ACK);
1233
1234 return err;
1235}
1236
1237static void 1224static void
1238qlcnic_handle_linkevent(struct qlcnic_adapter *adapter, 1225qlcnic_handle_linkevent(struct qlcnic_adapter *adapter,
1239 struct qlcnic_fw_msg *msg) 1226 struct qlcnic_fw_msg *msg)
@@ -1351,11 +1338,12 @@ static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1351 1338
1352 skb = buffer->skb; 1339 skb = buffer->skb;
1353 1340
1354 if (likely(adapter->rx_csum && cksum == STATUS_CKSUM_OK)) { 1341 if (likely(adapter->rx_csum && (cksum == STATUS_CKSUM_OK ||
1342 cksum == STATUS_CKSUM_LOOP))) {
1355 adapter->stats.csummed++; 1343 adapter->stats.csummed++;
1356 skb->ip_summed = CHECKSUM_UNNECESSARY; 1344 skb->ip_summed = CHECKSUM_UNNECESSARY;
1357 } else { 1345 } else {
1358 skb->ip_summed = CHECKSUM_NONE; 1346 skb_checksum_none_assert(skb);
1359 } 1347 }
1360 1348
1361 skb->dev = adapter->netdev; 1349 skb->dev = adapter->netdev;
@@ -1365,6 +1353,31 @@ static struct sk_buff *qlcnic_process_rxbuf(struct qlcnic_adapter *adapter,
1365 return skb; 1353 return skb;
1366} 1354}
1367 1355
1356static int
1357qlcnic_check_rx_tagging(struct qlcnic_adapter *adapter, struct sk_buff *skb,
1358 u16 *vlan_tag)
1359{
1360 struct ethhdr *eth_hdr;
1361
1362 if (!__vlan_get_tag(skb, vlan_tag)) {
1363 eth_hdr = (struct ethhdr *) skb->data;
1364 memmove(skb->data + VLAN_HLEN, eth_hdr, ETH_ALEN * 2);
1365 skb_pull(skb, VLAN_HLEN);
1366 }
1367 if (!adapter->pvid)
1368 return 0;
1369
1370 if (*vlan_tag == adapter->pvid) {
1371 /* Outer vlan tag. Packet should follow non-vlan path */
1372 *vlan_tag = 0xffff;
1373 return 0;
1374 }
1375 if (adapter->flags & QLCNIC_TAGGING_ENABLED)
1376 return 0;
1377
1378 return -EINVAL;
1379}
1380
1368static struct qlcnic_rx_buffer * 1381static struct qlcnic_rx_buffer *
1369qlcnic_process_rcv(struct qlcnic_adapter *adapter, 1382qlcnic_process_rcv(struct qlcnic_adapter *adapter,
1370 struct qlcnic_host_sds_ring *sds_ring, 1383 struct qlcnic_host_sds_ring *sds_ring,
@@ -1376,6 +1389,7 @@ qlcnic_process_rcv(struct qlcnic_adapter *adapter,
1376 struct sk_buff *skb; 1389 struct sk_buff *skb;
1377 struct qlcnic_host_rds_ring *rds_ring; 1390 struct qlcnic_host_rds_ring *rds_ring;
1378 int index, length, cksum, pkt_offset; 1391 int index, length, cksum, pkt_offset;
1392 u16 vid = 0xffff;
1379 1393
1380 if (unlikely(ring >= adapter->max_rds_rings)) 1394 if (unlikely(ring >= adapter->max_rds_rings))
1381 return NULL; 1395 return NULL;
@@ -1404,9 +1418,18 @@ qlcnic_process_rcv(struct qlcnic_adapter *adapter,
1404 if (pkt_offset) 1418 if (pkt_offset)
1405 skb_pull(skb, pkt_offset); 1419 skb_pull(skb, pkt_offset);
1406 1420
1421 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1422 adapter->stats.rxdropped++;
1423 dev_kfree_skb(skb);
1424 return buffer;
1425 }
1426
1407 skb->protocol = eth_type_trans(skb, netdev); 1427 skb->protocol = eth_type_trans(skb, netdev);
1408 1428
1409 napi_gro_receive(&sds_ring->napi, skb); 1429 if ((vid != 0xffff) && adapter->vlgrp)
1430 vlan_gro_receive(&sds_ring->napi, adapter->vlgrp, vid, skb);
1431 else
1432 napi_gro_receive(&sds_ring->napi, skb);
1410 1433
1411 adapter->stats.rx_pkts++; 1434 adapter->stats.rx_pkts++;
1412 adapter->stats.rxbytes += length; 1435 adapter->stats.rxbytes += length;
@@ -1435,6 +1458,7 @@ qlcnic_process_lro(struct qlcnic_adapter *adapter,
1435 int index; 1458 int index;
1436 u16 lro_length, length, data_offset; 1459 u16 lro_length, length, data_offset;
1437 u32 seq_number; 1460 u32 seq_number;
1461 u16 vid = 0xffff;
1438 1462
1439 if (unlikely(ring > adapter->max_rds_rings)) 1463 if (unlikely(ring > adapter->max_rds_rings))
1440 return NULL; 1464 return NULL;
@@ -1466,6 +1490,13 @@ qlcnic_process_lro(struct qlcnic_adapter *adapter,
1466 skb_put(skb, lro_length + data_offset); 1490 skb_put(skb, lro_length + data_offset);
1467 1491
1468 skb_pull(skb, l2_hdr_offset); 1492 skb_pull(skb, l2_hdr_offset);
1493
1494 if (unlikely(qlcnic_check_rx_tagging(adapter, skb, &vid))) {
1495 adapter->stats.rxdropped++;
1496 dev_kfree_skb(skb);
1497 return buffer;
1498 }
1499
1469 skb->protocol = eth_type_trans(skb, netdev); 1500 skb->protocol = eth_type_trans(skb, netdev);
1470 1501
1471 iph = (struct iphdr *)skb->data; 1502 iph = (struct iphdr *)skb->data;
@@ -1480,7 +1511,10 @@ qlcnic_process_lro(struct qlcnic_adapter *adapter,
1480 1511
1481 length = skb->len; 1512 length = skb->len;
1482 1513
1483 netif_receive_skb(skb); 1514 if ((vid != 0xffff) && adapter->vlgrp)
1515 vlan_hwaccel_receive_skb(skb, adapter->vlgrp, vid);
1516 else
1517 netif_receive_skb(skb);
1484 1518
1485 adapter->stats.lro_pkts++; 1519 adapter->stats.lro_pkts++;
1486 adapter->stats.lrobytes += length; 1520 adapter->stats.lrobytes += length;
@@ -1584,8 +1618,6 @@ qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter, u32 ringid,
1584 int producer, count = 0; 1618 int producer, count = 0;
1585 struct list_head *head; 1619 struct list_head *head;
1586 1620
1587 spin_lock(&rds_ring->lock);
1588
1589 producer = rds_ring->producer; 1621 producer = rds_ring->producer;
1590 1622
1591 head = &rds_ring->free_list; 1623 head = &rds_ring->free_list;
@@ -1615,7 +1647,6 @@ qlcnic_post_rx_buffers(struct qlcnic_adapter *adapter, u32 ringid,
1615 writel((producer-1) & (rds_ring->num_desc-1), 1647 writel((producer-1) & (rds_ring->num_desc-1),
1616 rds_ring->crb_rcv_producer); 1648 rds_ring->crb_rcv_producer);
1617 } 1649 }
1618 spin_unlock(&rds_ring->lock);
1619} 1650}
1620 1651
1621static void 1652static void
diff --git a/drivers/net/qlcnic/qlcnic_main.c b/drivers/net/qlcnic/qlcnic_main.c
index 66eea5972020..a3d7705a2dda 100644
--- a/drivers/net/qlcnic/qlcnic_main.c
+++ b/drivers/net/qlcnic/qlcnic_main.c
@@ -50,6 +50,10 @@ static int port_mode = QLCNIC_PORT_MODE_AUTO_NEG;
50/* Default to restricted 1G auto-neg mode */ 50/* Default to restricted 1G auto-neg mode */
51static int wol_port_mode = 5; 51static int wol_port_mode = 5;
52 52
53static int qlcnic_mac_learn;
54module_param(qlcnic_mac_learn, int, 0644);
55MODULE_PARM_DESC(qlcnic_mac_learn, "Mac Filter (0=disabled, 1=enabled)");
56
53static int use_msi = 1; 57static int use_msi = 1;
54module_param(use_msi, int, 0644); 58module_param(use_msi, int, 0644);
55MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled"); 59MODULE_PARM_DESC(use_msi, "MSI interrupt (0=disabled, 1=enabled");
@@ -94,7 +98,7 @@ static void qlcnic_create_diag_entries(struct qlcnic_adapter *adapter);
94static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter); 98static void qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter);
95 99
96static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding); 100static void qlcnic_idc_debug_info(struct qlcnic_adapter *adapter, u8 encoding);
97static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter); 101static void qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8);
98static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter); 102static int qlcnic_can_start_firmware(struct qlcnic_adapter *adapter);
99 103
100static irqreturn_t qlcnic_tmp_intr(int irq, void *data); 104static irqreturn_t qlcnic_tmp_intr(int irq, void *data);
@@ -103,13 +107,17 @@ static irqreturn_t qlcnic_msi_intr(int irq, void *data);
103static irqreturn_t qlcnic_msix_intr(int irq, void *data); 107static irqreturn_t qlcnic_msix_intr(int irq, void *data);
104 108
105static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev); 109static struct net_device_stats *qlcnic_get_stats(struct net_device *netdev);
106static void qlcnic_config_indev_addr(struct net_device *dev, unsigned long); 110static void qlcnic_restore_indev_addr(struct net_device *dev, unsigned long);
107static int qlcnic_start_firmware(struct qlcnic_adapter *); 111static int qlcnic_start_firmware(struct qlcnic_adapter *);
108 112
113static void qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter);
114static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter);
109static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *); 115static void qlcnic_dev_set_npar_ready(struct qlcnic_adapter *);
110static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32); 116static int qlcnicvf_config_led(struct qlcnic_adapter *, u32, u32);
111static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32); 117static int qlcnicvf_config_bridged_mode(struct qlcnic_adapter *, u32);
112static int qlcnicvf_start_firmware(struct qlcnic_adapter *); 118static int qlcnicvf_start_firmware(struct qlcnic_adapter *);
119static void qlcnic_set_netdev_features(struct qlcnic_adapter *,
120 struct qlcnic_esw_func_cfg *);
113/* PCI Device ID Table */ 121/* PCI Device ID Table */
114#define ENTRY(device) \ 122#define ENTRY(device) \
115 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \ 123 {PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, (device)), \
@@ -164,7 +172,7 @@ qlcnic_alloc_sds_rings(struct qlcnic_recv_context *recv_ctx, int count)
164 172
165 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL); 173 recv_ctx->sds_rings = kzalloc(size, GFP_KERNEL);
166 174
167 return (recv_ctx->sds_rings == NULL); 175 return recv_ctx->sds_rings == NULL;
168} 176}
169 177
170static void 178static void
@@ -320,7 +328,7 @@ qlcnic_read_mac_addr(struct qlcnic_adapter *adapter)
320 struct net_device *netdev = adapter->netdev; 328 struct net_device *netdev = adapter->netdev;
321 struct pci_dev *pdev = adapter->pdev; 329 struct pci_dev *pdev = adapter->pdev;
322 330
323 if (adapter->nic_ops->get_mac_addr(adapter, mac_addr) != 0) 331 if (qlcnic_get_mac_address(adapter, mac_addr) != 0)
324 return -EIO; 332 return -EIO;
325 333
326 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN); 334 memcpy(netdev->dev_addr, mac_addr, ETH_ALEN);
@@ -341,6 +349,9 @@ static int qlcnic_set_mac(struct net_device *netdev, void *p)
341 struct qlcnic_adapter *adapter = netdev_priv(netdev); 349 struct qlcnic_adapter *adapter = netdev_priv(netdev);
342 struct sockaddr *addr = p; 350 struct sockaddr *addr = p;
343 351
352 if ((adapter->flags & QLCNIC_MAC_OVERRIDE_DISABLED))
353 return -EOPNOTSUPP;
354
344 if (!is_valid_ether_addr(addr->sa_data)) 355 if (!is_valid_ether_addr(addr->sa_data))
345 return -EINVAL; 356 return -EINVAL;
346 357
@@ -360,6 +371,13 @@ static int qlcnic_set_mac(struct net_device *netdev, void *p)
360 return 0; 371 return 0;
361} 372}
362 373
374static void qlcnic_vlan_rx_register(struct net_device *netdev,
375 struct vlan_group *grp)
376{
377 struct qlcnic_adapter *adapter = netdev_priv(netdev);
378 adapter->vlgrp = grp;
379}
380
363static const struct net_device_ops qlcnic_netdev_ops = { 381static const struct net_device_ops qlcnic_netdev_ops = {
364 .ndo_open = qlcnic_open, 382 .ndo_open = qlcnic_open,
365 .ndo_stop = qlcnic_close, 383 .ndo_stop = qlcnic_close,
@@ -370,20 +388,19 @@ static const struct net_device_ops qlcnic_netdev_ops = {
370 .ndo_set_mac_address = qlcnic_set_mac, 388 .ndo_set_mac_address = qlcnic_set_mac,
371 .ndo_change_mtu = qlcnic_change_mtu, 389 .ndo_change_mtu = qlcnic_change_mtu,
372 .ndo_tx_timeout = qlcnic_tx_timeout, 390 .ndo_tx_timeout = qlcnic_tx_timeout,
391 .ndo_vlan_rx_register = qlcnic_vlan_rx_register,
373#ifdef CONFIG_NET_POLL_CONTROLLER 392#ifdef CONFIG_NET_POLL_CONTROLLER
374 .ndo_poll_controller = qlcnic_poll_controller, 393 .ndo_poll_controller = qlcnic_poll_controller,
375#endif 394#endif
376}; 395};
377 396
378static struct qlcnic_nic_template qlcnic_ops = { 397static struct qlcnic_nic_template qlcnic_ops = {
379 .get_mac_addr = qlcnic_get_mac_address,
380 .config_bridged_mode = qlcnic_config_bridged_mode, 398 .config_bridged_mode = qlcnic_config_bridged_mode,
381 .config_led = qlcnic_config_led, 399 .config_led = qlcnic_config_led,
382 .start_firmware = qlcnic_start_firmware 400 .start_firmware = qlcnic_start_firmware
383}; 401};
384 402
385static struct qlcnic_nic_template qlcnic_vf_ops = { 403static struct qlcnic_nic_template qlcnic_vf_ops = {
386 .get_mac_addr = qlcnic_get_mac_address,
387 .config_bridged_mode = qlcnicvf_config_bridged_mode, 404 .config_bridged_mode = qlcnicvf_config_bridged_mode,
388 .config_led = qlcnicvf_config_led, 405 .config_led = qlcnicvf_config_led,
389 .start_firmware = qlcnicvf_start_firmware 406 .start_firmware = qlcnicvf_start_firmware
@@ -474,7 +491,7 @@ static int
474qlcnic_init_pci_info(struct qlcnic_adapter *adapter) 491qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
475{ 492{
476 struct qlcnic_pci_info *pci_info; 493 struct qlcnic_pci_info *pci_info;
477 int i, ret = 0, err; 494 int i, ret = 0;
478 u8 pfn; 495 u8 pfn;
479 496
480 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL); 497 pci_info = kcalloc(QLCNIC_MAX_PCI_FUNC, sizeof(*pci_info), GFP_KERNEL);
@@ -484,14 +501,14 @@ qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
484 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) * 501 adapter->npars = kzalloc(sizeof(struct qlcnic_npar_info) *
485 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL); 502 QLCNIC_MAX_PCI_FUNC, GFP_KERNEL);
486 if (!adapter->npars) { 503 if (!adapter->npars) {
487 err = -ENOMEM; 504 ret = -ENOMEM;
488 goto err_pci_info; 505 goto err_pci_info;
489 } 506 }
490 507
491 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) * 508 adapter->eswitch = kzalloc(sizeof(struct qlcnic_eswitch) *
492 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL); 509 QLCNIC_NIU_MAX_XG_PORTS, GFP_KERNEL);
493 if (!adapter->eswitch) { 510 if (!adapter->eswitch) {
494 err = -ENOMEM; 511 ret = -ENOMEM;
495 goto err_npars; 512 goto err_npars;
496 } 513 }
497 514
@@ -506,7 +523,6 @@ qlcnic_init_pci_info(struct qlcnic_adapter *adapter)
506 adapter->npars[pfn].active = pci_info[i].active; 523 adapter->npars[pfn].active = pci_info[i].active;
507 adapter->npars[pfn].type = pci_info[i].type; 524 adapter->npars[pfn].type = pci_info[i].type;
508 adapter->npars[pfn].phy_port = pci_info[i].default_port; 525 adapter->npars[pfn].phy_port = pci_info[i].default_port;
509 adapter->npars[pfn].mac_learning = DEFAULT_MAC_LEARN;
510 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw; 526 adapter->npars[pfn].min_bw = pci_info[i].tx_min_bw;
511 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw; 527 adapter->npars[pfn].max_bw = pci_info[i].tx_max_bw;
512 } 528 }
@@ -539,12 +555,10 @@ qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
539 void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; 555 void __iomem *priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
540 556
541 /* If other drivers are not in use set their privilege level */ 557 /* If other drivers are not in use set their privilege level */
542 ref_count = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); 558 ref_count = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
543 ret = qlcnic_api_lock(adapter); 559 ret = qlcnic_api_lock(adapter);
544 if (ret) 560 if (ret)
545 goto err_lock; 561 goto err_lock;
546 if (QLC_DEV_CLR_REF_CNT(ref_count, adapter->ahw.pci_func))
547 goto err_npar;
548 562
549 if (qlcnic_config_npars) { 563 if (qlcnic_config_npars) {
550 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 564 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
@@ -562,18 +576,16 @@ qlcnic_set_function_modes(struct qlcnic_adapter *adapter)
562 adapter->ahw.pci_func)); 576 adapter->ahw.pci_func));
563 } 577 }
564 writel(data, priv_op); 578 writel(data, priv_op);
565err_npar:
566 qlcnic_api_unlock(adapter); 579 qlcnic_api_unlock(adapter);
567err_lock: 580err_lock:
568 return ret; 581 return ret;
569} 582}
570 583
571static u32 584static void
572qlcnic_get_driver_mode(struct qlcnic_adapter *adapter) 585qlcnic_check_vf(struct qlcnic_adapter *adapter)
573{ 586{
574 void __iomem *msix_base_addr; 587 void __iomem *msix_base_addr;
575 void __iomem *priv_op; 588 void __iomem *priv_op;
576 struct qlcnic_info nic_info;
577 u32 func; 589 u32 func;
578 u32 msix_base; 590 u32 msix_base;
579 u32 op_mode, priv_level; 591 u32 op_mode, priv_level;
@@ -588,20 +600,6 @@ qlcnic_get_driver_mode(struct qlcnic_adapter *adapter)
588 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE; 600 func = (func - msix_base)/QLCNIC_MSIX_TBL_PGSIZE;
589 adapter->ahw.pci_func = func; 601 adapter->ahw.pci_func = func;
590 602
591 if (!qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func)) {
592 adapter->capabilities = nic_info.capabilities;
593
594 if (adapter->capabilities & BIT_6)
595 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
596 else
597 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
598 }
599
600 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED)) {
601 adapter->nic_ops = &qlcnic_ops;
602 return adapter->fw_hal_version;
603 }
604
605 /* Determine function privilege level */ 603 /* Determine function privilege level */
606 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE; 604 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
607 op_mode = readl(priv_op); 605 op_mode = readl(priv_op);
@@ -610,37 +608,14 @@ qlcnic_get_driver_mode(struct qlcnic_adapter *adapter)
610 else 608 else
611 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func); 609 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
612 610
613 switch (priv_level) { 611 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
614 case QLCNIC_MGMT_FUNC:
615 adapter->op_mode = QLCNIC_MGMT_FUNC;
616 adapter->nic_ops = &qlcnic_ops;
617 qlcnic_init_pci_info(adapter);
618 /* Set privilege level for other functions */
619 qlcnic_set_function_modes(adapter);
620 dev_info(&adapter->pdev->dev,
621 "HAL Version: %d, Management function\n",
622 adapter->fw_hal_version);
623 break;
624 case QLCNIC_PRIV_FUNC:
625 adapter->op_mode = QLCNIC_PRIV_FUNC;
626 dev_info(&adapter->pdev->dev,
627 "HAL Version: %d, Privileged function\n",
628 adapter->fw_hal_version);
629 adapter->nic_ops = &qlcnic_ops;
630 break;
631 case QLCNIC_NON_PRIV_FUNC:
632 adapter->op_mode = QLCNIC_NON_PRIV_FUNC; 612 adapter->op_mode = QLCNIC_NON_PRIV_FUNC;
633 dev_info(&adapter->pdev->dev, 613 dev_info(&adapter->pdev->dev,
634 "HAL Version: %d Non Privileged function\n", 614 "HAL Version: %d Non Privileged function\n",
635 adapter->fw_hal_version); 615 adapter->fw_hal_version);
636 adapter->nic_ops = &qlcnic_vf_ops; 616 adapter->nic_ops = &qlcnic_vf_ops;
637 break; 617 } else
638 default: 618 adapter->nic_ops = &qlcnic_ops;
639 dev_info(&adapter->pdev->dev, "Unknown function mode: %d\n",
640 priv_level);
641 return 0;
642 }
643 return adapter->fw_hal_version;
644} 619}
645 620
646static int 621static int
@@ -673,10 +648,7 @@ qlcnic_setup_pci_map(struct qlcnic_adapter *adapter)
673 adapter->ahw.pci_base0 = mem_ptr0; 648 adapter->ahw.pci_base0 = mem_ptr0;
674 adapter->ahw.pci_len0 = pci_len0; 649 adapter->ahw.pci_len0 = pci_len0;
675 650
676 if (!qlcnic_get_driver_mode(adapter)) { 651 qlcnic_check_vf(adapter);
677 iounmap(adapter->ahw.pci_base0);
678 return -EIO;
679 }
680 652
681 adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter, 653 adapter->ahw.ocm_win_crb = qlcnic_get_ioaddr(adapter,
682 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func))); 654 QLCNIC_PCIX_PS_REG(PCIX_OCM_WINDOW_REG(adapter->ahw.pci_func)));
@@ -711,25 +683,7 @@ static void
711qlcnic_check_options(struct qlcnic_adapter *adapter) 683qlcnic_check_options(struct qlcnic_adapter *adapter)
712{ 684{
713 u32 fw_major, fw_minor, fw_build; 685 u32 fw_major, fw_minor, fw_build;
714 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
715 char serial_num[32];
716 int i, offset, val;
717 int *ptr32;
718 struct pci_dev *pdev = adapter->pdev; 686 struct pci_dev *pdev = adapter->pdev;
719 struct qlcnic_info nic_info;
720 adapter->driver_mismatch = 0;
721
722 ptr32 = (int *)&serial_num;
723 offset = QLCNIC_FW_SERIAL_NUM_OFFSET;
724 for (i = 0; i < 8; i++) {
725 if (qlcnic_rom_fast_read(adapter, offset, &val) == -1) {
726 dev_err(&pdev->dev, "error reading board info\n");
727 adapter->driver_mismatch = 1;
728 return;
729 }
730 ptr32[i] = cpu_to_le32(val);
731 offset += sizeof(u32);
732 }
733 687
734 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR); 688 fw_major = QLCRD32(adapter, QLCNIC_FW_VERSION_MAJOR);
735 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR); 689 fw_minor = QLCRD32(adapter, QLCNIC_FW_VERSION_MINOR);
@@ -737,14 +691,6 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
737 691
738 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build); 692 adapter->fw_version = QLCNIC_VERSION_CODE(fw_major, fw_minor, fw_build);
739 693
740 if (adapter->portnum == 0) {
741 get_brd_name(adapter, brd_name);
742
743 pr_info("%s: %s Board Chip rev 0x%x\n",
744 module_name(THIS_MODULE),
745 brd_name, adapter->ahw.revision_id);
746 }
747
748 dev_info(&pdev->dev, "firmware v%d.%d.%d\n", 694 dev_info(&pdev->dev, "firmware v%d.%d.%d\n",
749 fw_major, fw_minor, fw_build); 695 fw_major, fw_minor, fw_build);
750 696
@@ -758,109 +704,333 @@ qlcnic_check_options(struct qlcnic_adapter *adapter)
758 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G; 704 adapter->num_jumbo_rxd = MAX_JUMBO_RCV_DESCRIPTORS_1G;
759 } 705 }
760 706
761 if (!qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func)) {
762 adapter->physical_port = nic_info.phys_port;
763 adapter->switch_mode = nic_info.switch_mode;
764 adapter->max_tx_ques = nic_info.max_tx_ques;
765 adapter->max_rx_ques = nic_info.max_rx_ques;
766 adapter->capabilities = nic_info.capabilities;
767 adapter->max_mac_filters = nic_info.max_mac_filters;
768 adapter->max_mtu = nic_info.max_mtu;
769 }
770
771 adapter->msix_supported = !!use_msi_x; 707 adapter->msix_supported = !!use_msi_x;
772 adapter->rss_supported = !!use_msi_x; 708 adapter->rss_supported = !!use_msi_x;
773 709
774 adapter->num_txd = MAX_CMD_DESCRIPTORS; 710 adapter->num_txd = MAX_CMD_DESCRIPTORS;
775 711
776 adapter->max_rds_rings = 2; 712 adapter->max_rds_rings = MAX_RDS_RINGS;
713}
714
715static int
716qlcnic_initialize_nic(struct qlcnic_adapter *adapter)
717{
718 int err;
719 struct qlcnic_info nic_info;
720
721 err = qlcnic_get_nic_info(adapter, &nic_info, adapter->ahw.pci_func);
722 if (err)
723 return err;
724
725 adapter->physical_port = nic_info.phys_port;
726 adapter->switch_mode = nic_info.switch_mode;
727 adapter->max_tx_ques = nic_info.max_tx_ques;
728 adapter->max_rx_ques = nic_info.max_rx_ques;
729 adapter->capabilities = nic_info.capabilities;
730 adapter->max_mac_filters = nic_info.max_mac_filters;
731 adapter->max_mtu = nic_info.max_mtu;
732
733 if (adapter->capabilities & BIT_6)
734 adapter->flags |= QLCNIC_ESWITCH_ENABLED;
735 else
736 adapter->flags &= ~QLCNIC_ESWITCH_ENABLED;
737
738 return err;
739}
740
741static void
742qlcnic_set_vlan_config(struct qlcnic_adapter *adapter,
743 struct qlcnic_esw_func_cfg *esw_cfg)
744{
745 if (esw_cfg->discard_tagged)
746 adapter->flags &= ~QLCNIC_TAGGING_ENABLED;
747 else
748 adapter->flags |= QLCNIC_TAGGING_ENABLED;
749
750 if (esw_cfg->vlan_id)
751 adapter->pvid = esw_cfg->vlan_id;
752 else
753 adapter->pvid = 0;
754}
755
756static void
757qlcnic_set_eswitch_port_features(struct qlcnic_adapter *adapter,
758 struct qlcnic_esw_func_cfg *esw_cfg)
759{
760 adapter->flags &= ~QLCNIC_MACSPOOF;
761 adapter->flags &= ~QLCNIC_MAC_OVERRIDE_DISABLED;
762
763 if (esw_cfg->mac_anti_spoof)
764 adapter->flags |= QLCNIC_MACSPOOF;
765
766 if (!esw_cfg->mac_override)
767 adapter->flags |= QLCNIC_MAC_OVERRIDE_DISABLED;
768
769 qlcnic_set_netdev_features(adapter, esw_cfg);
770}
771
772static int
773qlcnic_set_eswitch_port_config(struct qlcnic_adapter *adapter)
774{
775 struct qlcnic_esw_func_cfg esw_cfg;
776
777 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
778 return 0;
779
780 esw_cfg.pci_func = adapter->ahw.pci_func;
781 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg))
782 return -EIO;
783 qlcnic_set_vlan_config(adapter, &esw_cfg);
784 qlcnic_set_eswitch_port_features(adapter, &esw_cfg);
785
786 return 0;
787}
788
789static void
790qlcnic_set_netdev_features(struct qlcnic_adapter *adapter,
791 struct qlcnic_esw_func_cfg *esw_cfg)
792{
793 struct net_device *netdev = adapter->netdev;
794 unsigned long features, vlan_features;
795
796 features = (NETIF_F_SG | NETIF_F_IP_CSUM |
797 NETIF_F_IPV6_CSUM | NETIF_F_GRO);
798 vlan_features = (NETIF_F_SG | NETIF_F_IP_CSUM |
799 NETIF_F_IPV6_CSUM);
800
801 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO) {
802 features |= (NETIF_F_TSO | NETIF_F_TSO6);
803 vlan_features |= (NETIF_F_TSO | NETIF_F_TSO6);
804 }
805 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
806 features |= NETIF_F_LRO;
807
808 if (esw_cfg->offload_flags & BIT_0) {
809 netdev->features |= features;
810 adapter->rx_csum = 1;
811 if (!(esw_cfg->offload_flags & BIT_1))
812 netdev->features &= ~NETIF_F_TSO;
813 if (!(esw_cfg->offload_flags & BIT_2))
814 netdev->features &= ~NETIF_F_TSO6;
815 } else {
816 netdev->features &= ~features;
817 adapter->rx_csum = 0;
818 }
819
820 netdev->vlan_features = (features & vlan_features);
821}
822
823static int
824qlcnic_check_eswitch_mode(struct qlcnic_adapter *adapter)
825{
826 void __iomem *priv_op;
827 u32 op_mode, priv_level;
828 int err = 0;
829
830 err = qlcnic_initialize_nic(adapter);
831 if (err)
832 return err;
833
834 if (adapter->flags & QLCNIC_ADAPTER_INITIALIZED)
835 return 0;
836
837 priv_op = adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE;
838 op_mode = readl(priv_op);
839 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
840
841 if (op_mode == QLC_DEV_DRV_DEFAULT)
842 priv_level = QLCNIC_MGMT_FUNC;
843 else
844 priv_level = QLC_DEV_GET_DRV(op_mode, adapter->ahw.pci_func);
845
846 if (adapter->flags & QLCNIC_ESWITCH_ENABLED) {
847 if (priv_level == QLCNIC_MGMT_FUNC) {
848 adapter->op_mode = QLCNIC_MGMT_FUNC;
849 err = qlcnic_init_pci_info(adapter);
850 if (err)
851 return err;
852 /* Set privilege level for other functions */
853 qlcnic_set_function_modes(adapter);
854 dev_info(&adapter->pdev->dev,
855 "HAL Version: %d, Management function\n",
856 adapter->fw_hal_version);
857 } else if (priv_level == QLCNIC_PRIV_FUNC) {
858 adapter->op_mode = QLCNIC_PRIV_FUNC;
859 dev_info(&adapter->pdev->dev,
860 "HAL Version: %d, Privileged function\n",
861 adapter->fw_hal_version);
862 }
863 }
864
865 adapter->flags |= QLCNIC_ADAPTER_INITIALIZED;
866
867 return err;
868}
869
870static int
871qlcnic_set_default_offload_settings(struct qlcnic_adapter *adapter)
872{
873 struct qlcnic_esw_func_cfg esw_cfg;
874 struct qlcnic_npar_info *npar;
875 u8 i;
876
877 if (adapter->need_fw_reset)
878 return 0;
879
880 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
881 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
882 continue;
883 memset(&esw_cfg, 0, sizeof(struct qlcnic_esw_func_cfg));
884 esw_cfg.pci_func = i;
885 esw_cfg.offload_flags = BIT_0;
886 esw_cfg.mac_override = BIT_0;
887 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_TSO)
888 esw_cfg.offload_flags |= (BIT_1 | BIT_2);
889 if (qlcnic_config_switch_port(adapter, &esw_cfg))
890 return -EIO;
891 npar = &adapter->npars[i];
892 npar->pvid = esw_cfg.vlan_id;
893 npar->mac_override = esw_cfg.mac_override;
894 npar->mac_anti_spoof = esw_cfg.mac_anti_spoof;
895 npar->discard_tagged = esw_cfg.discard_tagged;
896 npar->promisc_mode = esw_cfg.promisc_mode;
897 npar->offload_flags = esw_cfg.offload_flags;
898 }
899
900 return 0;
901}
902
903static int
904qlcnic_reset_eswitch_config(struct qlcnic_adapter *adapter,
905 struct qlcnic_npar_info *npar, int pci_func)
906{
907 struct qlcnic_esw_func_cfg esw_cfg;
908 esw_cfg.op_mode = QLCNIC_PORT_DEFAULTS;
909 esw_cfg.pci_func = pci_func;
910 esw_cfg.vlan_id = npar->pvid;
911 esw_cfg.mac_override = npar->mac_override;
912 esw_cfg.discard_tagged = npar->discard_tagged;
913 esw_cfg.mac_anti_spoof = npar->mac_anti_spoof;
914 esw_cfg.offload_flags = npar->offload_flags;
915 esw_cfg.promisc_mode = npar->promisc_mode;
916 if (qlcnic_config_switch_port(adapter, &esw_cfg))
917 return -EIO;
918
919 esw_cfg.op_mode = QLCNIC_ADD_VLAN;
920 if (qlcnic_config_switch_port(adapter, &esw_cfg))
921 return -EIO;
922
923 return 0;
777} 924}
778 925
779static int 926static int
780qlcnic_reset_npar_config(struct qlcnic_adapter *adapter) 927qlcnic_reset_npar_config(struct qlcnic_adapter *adapter)
781{ 928{
782 int i, err = 0; 929 int i, err;
783 struct qlcnic_npar_info *npar; 930 struct qlcnic_npar_info *npar;
784 struct qlcnic_info nic_info; 931 struct qlcnic_info nic_info;
785 932
786 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 933 if (!adapter->need_fw_reset)
787 !adapter->need_fw_reset)
788 return 0; 934 return 0;
789 935
790 if (adapter->op_mode == QLCNIC_MGMT_FUNC) { 936 /* Set the NPAR config data after FW reset */
791 /* Set the NPAR config data after FW reset */ 937 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
792 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 938 npar = &adapter->npars[i];
793 npar = &adapter->npars[i]; 939 if (npar->type != QLCNIC_TYPE_NIC)
794 if (npar->type != QLCNIC_TYPE_NIC) 940 continue;
795 continue; 941 err = qlcnic_get_nic_info(adapter, &nic_info, i);
796 err = qlcnic_get_nic_info(adapter, &nic_info, i); 942 if (err)
797 if (err) 943 return err;
798 goto err_out; 944 nic_info.min_tx_bw = npar->min_bw;
799 nic_info.min_tx_bw = npar->min_bw; 945 nic_info.max_tx_bw = npar->max_bw;
800 nic_info.max_tx_bw = npar->max_bw; 946 err = qlcnic_set_nic_info(adapter, &nic_info);
801 err = qlcnic_set_nic_info(adapter, &nic_info); 947 if (err)
948 return err;
949
950 if (npar->enable_pm) {
951 err = qlcnic_config_port_mirroring(adapter,
952 npar->dest_npar, 1, i);
802 if (err) 953 if (err)
803 goto err_out; 954 return err;
955 }
956 err = qlcnic_reset_eswitch_config(adapter, npar, i);
957 if (err)
958 return err;
959 }
960 return 0;
961}
804 962
805 if (npar->enable_pm) { 963static int qlcnic_check_npar_opertional(struct qlcnic_adapter *adapter)
806 err = qlcnic_config_port_mirroring(adapter, 964{
807 npar->dest_npar, 1, i); 965 u8 npar_opt_timeo = QLCNIC_DEV_NPAR_OPER_TIMEO;
808 if (err) 966 u32 npar_state;
809 goto err_out;
810 967
811 } 968 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
812 npar->mac_learning = DEFAULT_MAC_LEARN; 969 return 0;
813 npar->host_vlan_tag = 0; 970
814 npar->promisc_mode = 0; 971 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
815 npar->discard_tagged = 0; 972 while (npar_state != QLCNIC_DEV_NPAR_OPER && --npar_opt_timeo) {
816 npar->vlan_id = 0; 973 msleep(1000);
817 } 974 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
818 } 975 }
819err_out: 976 if (!npar_opt_timeo) {
977 dev_err(&adapter->pdev->dev,
978 "Waiting for NPAR state to opertional timeout\n");
979 return -EIO;
980 }
981 return 0;
982}
983
984static int
985qlcnic_set_mgmt_operations(struct qlcnic_adapter *adapter)
986{
987 int err;
988
989 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
990 adapter->op_mode != QLCNIC_MGMT_FUNC)
991 return 0;
992
993 err = qlcnic_set_default_offload_settings(adapter);
994 if (err)
995 return err;
996
997 err = qlcnic_reset_npar_config(adapter);
998 if (err)
999 return err;
1000
1001 qlcnic_dev_set_npar_ready(adapter);
1002
820 return err; 1003 return err;
821} 1004}
822 1005
823static int 1006static int
824qlcnic_start_firmware(struct qlcnic_adapter *adapter) 1007qlcnic_start_firmware(struct qlcnic_adapter *adapter)
825{ 1008{
826 int val, err, first_boot; 1009 int err;
827 1010
828 err = qlcnic_can_start_firmware(adapter); 1011 err = qlcnic_can_start_firmware(adapter);
829 if (err < 0) 1012 if (err < 0)
830 return err; 1013 return err;
831 else if (!err) 1014 else if (!err)
832 goto wait_init; 1015 goto check_fw_status;
833
834 first_boot = QLCRD32(adapter, QLCNIC_CAM_RAM(0x1fc));
835 if (first_boot == 0x55555555)
836 /* This is the first boot after power up */
837 QLCWR32(adapter, QLCNIC_CAM_RAM(0x1fc), QLCNIC_BDINFO_MAGIC);
838 1016
839 if (load_fw_file) 1017 if (load_fw_file)
840 qlcnic_request_firmware(adapter); 1018 qlcnic_request_firmware(adapter);
841 else { 1019 else {
842 if (qlcnic_check_flash_fw_ver(adapter)) 1020 err = qlcnic_check_flash_fw_ver(adapter);
1021 if (err)
843 goto err_out; 1022 goto err_out;
844 1023
845 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE; 1024 adapter->fw_type = QLCNIC_FLASH_ROMIMAGE;
846 } 1025 }
847 1026
848 err = qlcnic_need_fw_reset(adapter); 1027 err = qlcnic_need_fw_reset(adapter);
849 if (err < 0)
850 goto err_out;
851 if (err == 0) 1028 if (err == 0)
852 goto wait_init; 1029 goto check_fw_status;
853
854 if (first_boot != 0x55555555) {
855 QLCWR32(adapter, CRB_CMDPEG_STATE, 0);
856 QLCWR32(adapter, CRB_RCVPEG_STATE, 0);
857 qlcnic_pinit_from_rom(adapter);
858 msleep(1);
859 }
860
861 QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS1, 0);
862 QLCWR32(adapter, QLCNIC_PEG_HALT_STATUS2, 0);
863 1030
1031 err = qlcnic_pinit_from_rom(adapter);
1032 if (err)
1033 goto err_out;
864 qlcnic_set_port_mode(adapter); 1034 qlcnic_set_port_mode(adapter);
865 1035
866 err = qlcnic_load_firmware(adapter); 1036 err = qlcnic_load_firmware(adapter);
@@ -868,26 +1038,27 @@ qlcnic_start_firmware(struct qlcnic_adapter *adapter)
868 goto err_out; 1038 goto err_out;
869 1039
870 qlcnic_release_firmware(adapter); 1040 qlcnic_release_firmware(adapter);
1041 QLCWR32(adapter, CRB_DRIVER_VERSION, QLCNIC_DRIVER_VERSION);
871 1042
872 val = (_QLCNIC_LINUX_MAJOR << 16) 1043check_fw_status:
873 | ((_QLCNIC_LINUX_MINOR << 8)) 1044 err = qlcnic_check_fw_status(adapter);
874 | (_QLCNIC_LINUX_SUBVERSION);
875 QLCWR32(adapter, CRB_DRIVER_VERSION, val);
876
877wait_init:
878 /* Handshake with the card before we register the devices. */
879 err = qlcnic_init_firmware(adapter);
880 if (err) 1045 if (err)
881 goto err_out; 1046 goto err_out;
882 1047
883 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY); 1048 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_READY);
884 qlcnic_idc_debug_info(adapter, 1); 1049 qlcnic_idc_debug_info(adapter, 1);
885 1050
886 qlcnic_check_options(adapter); 1051 err = qlcnic_check_eswitch_mode(adapter);
887 if (qlcnic_reset_npar_config(adapter)) 1052 if (err) {
1053 dev_err(&adapter->pdev->dev,
1054 "Memory allocation failed for eswitch\n");
1055 goto err_out;
1056 }
1057 err = qlcnic_set_mgmt_operations(adapter);
1058 if (err)
888 goto err_out; 1059 goto err_out;
889 qlcnic_dev_set_npar_ready(adapter);
890 1060
1061 qlcnic_check_options(adapter);
891 adapter->need_fw_reset = 0; 1062 adapter->need_fw_reset = 0;
892 1063
893 qlcnic_release_firmware(adapter); 1064 qlcnic_release_firmware(adapter);
@@ -896,6 +1067,7 @@ wait_init:
896err_out: 1067err_out:
897 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED); 1068 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
898 dev_err(&adapter->pdev->dev, "Device state set to failed\n"); 1069 dev_err(&adapter->pdev->dev, "Device state set to failed\n");
1070
899 qlcnic_release_firmware(adapter); 1071 qlcnic_release_firmware(adapter);
900 return err; 1072 return err;
901} 1073}
@@ -979,6 +1151,8 @@ __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
979 1151
980 if (test_bit(__QLCNIC_DEV_UP, &adapter->state)) 1152 if (test_bit(__QLCNIC_DEV_UP, &adapter->state))
981 return 0; 1153 return 0;
1154 if (qlcnic_set_eswitch_port_config(adapter))
1155 return -EIO;
982 1156
983 if (qlcnic_fw_create_ctx(adapter)) 1157 if (qlcnic_fw_create_ctx(adapter))
984 return -EIO; 1158 return -EIO;
@@ -998,7 +1172,7 @@ __qlcnic_up(struct qlcnic_adapter *adapter, struct net_device *netdev)
998 1172
999 qlcnic_config_intr_coalesce(adapter); 1173 qlcnic_config_intr_coalesce(adapter);
1000 1174
1001 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 1175 if (netdev->features & NETIF_F_LRO)
1002 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED); 1176 qlcnic_config_hw_lro(adapter, QLCNIC_LRO_ENABLED);
1003 1177
1004 qlcnic_napi_enable(adapter); 1178 qlcnic_napi_enable(adapter);
@@ -1041,6 +1215,9 @@ __qlcnic_down(struct qlcnic_adapter *adapter, struct net_device *netdev)
1041 1215
1042 qlcnic_free_mac_list(adapter); 1216 qlcnic_free_mac_list(adapter);
1043 1217
1218 if (adapter->fhash.fnum)
1219 qlcnic_delete_lb_filters(adapter);
1220
1044 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE); 1221 qlcnic_nic_set_promisc(adapter, QLCNIC_NIU_NON_PROMISC_MODE);
1045 1222
1046 qlcnic_napi_disable(adapter); 1223 qlcnic_napi_disable(adapter);
@@ -1277,7 +1454,7 @@ qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1277 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops); 1454 SET_ETHTOOL_OPS(netdev, &qlcnic_ethtool_ops);
1278 1455
1279 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM | 1456 netdev->features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1280 NETIF_F_IPV6_CSUM | NETIF_F_GRO); 1457 NETIF_F_IPV6_CSUM | NETIF_F_GRO | NETIF_F_HW_VLAN_RX);
1281 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM | 1458 netdev->vlan_features |= (NETIF_F_SG | NETIF_F_IP_CSUM |
1282 NETIF_F_IPV6_CSUM); 1459 NETIF_F_IPV6_CSUM);
1283 1460
@@ -1296,12 +1473,8 @@ qlcnic_setup_netdev(struct qlcnic_adapter *adapter,
1296 1473
1297 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO) 1474 if (adapter->capabilities & QLCNIC_FW_CAPABILITY_HW_LRO)
1298 netdev->features |= NETIF_F_LRO; 1475 netdev->features |= NETIF_F_LRO;
1299
1300 netdev->irq = adapter->msix_entries[0].vector; 1476 netdev->irq = adapter->msix_entries[0].vector;
1301 1477
1302 if (qlcnic_read_mac_addr(adapter))
1303 dev_warn(&pdev->dev, "failed to read mac addr\n");
1304
1305 netif_carrier_off(netdev); 1478 netif_carrier_off(netdev);
1306 netif_stop_queue(netdev); 1479 netif_stop_queue(netdev);
1307 1480
@@ -1338,6 +1511,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1338 int err; 1511 int err;
1339 uint8_t revision_id; 1512 uint8_t revision_id;
1340 uint8_t pci_using_dac; 1513 uint8_t pci_using_dac;
1514 char brd_name[QLCNIC_MAX_BOARD_NAME_LEN];
1341 1515
1342 err = pci_enable_device(pdev); 1516 err = pci_enable_device(pdev);
1343 if (err) 1517 if (err)
@@ -1395,10 +1569,8 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1395 goto err_out_iounmap; 1569 goto err_out_iounmap;
1396 } 1570 }
1397 1571
1398 if (qlcnic_read_mac_addr(adapter)) 1572 err = qlcnic_setup_idc_param(adapter);
1399 dev_warn(&pdev->dev, "failed to read mac addr\n"); 1573 if (err)
1400
1401 if (qlcnic_setup_idc_param(adapter))
1402 goto err_out_iounmap; 1574 goto err_out_iounmap;
1403 1575
1404 err = adapter->nic_ops->start_firmware(adapter); 1576 err = adapter->nic_ops->start_firmware(adapter);
@@ -1407,6 +1579,17 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1407 goto err_out_decr_ref; 1579 goto err_out_decr_ref;
1408 } 1580 }
1409 1581
1582 if (qlcnic_read_mac_addr(adapter))
1583 dev_warn(&pdev->dev, "failed to read mac addr\n");
1584
1585 if (adapter->portnum == 0) {
1586 get_brd_name(adapter, brd_name);
1587
1588 pr_info("%s: %s Board Chip rev 0x%x\n",
1589 module_name(THIS_MODULE),
1590 brd_name, adapter->ahw.revision_id);
1591 }
1592
1410 qlcnic_clear_stats(adapter); 1593 qlcnic_clear_stats(adapter);
1411 1594
1412 qlcnic_setup_intr(adapter); 1595 qlcnic_setup_intr(adapter);
@@ -1430,6 +1613,7 @@ qlcnic_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
1430 break; 1613 break;
1431 } 1614 }
1432 1615
1616 qlcnic_alloc_lb_filters_mem(adapter);
1433 qlcnic_create_diag_entries(adapter); 1617 qlcnic_create_diag_entries(adapter);
1434 1618
1435 return 0; 1619 return 0;
@@ -1438,7 +1622,7 @@ err_out_disable_msi:
1438 qlcnic_teardown_intr(adapter); 1622 qlcnic_teardown_intr(adapter);
1439 1623
1440err_out_decr_ref: 1624err_out_decr_ref:
1441 qlcnic_clr_all_drv_state(adapter); 1625 qlcnic_clr_all_drv_state(adapter, 0);
1442 1626
1443err_out_iounmap: 1627err_out_iounmap:
1444 qlcnic_cleanup_pci_map(adapter); 1628 qlcnic_cleanup_pci_map(adapter);
@@ -1477,10 +1661,12 @@ static void __devexit qlcnic_remove(struct pci_dev *pdev)
1477 if (adapter->eswitch != NULL) 1661 if (adapter->eswitch != NULL)
1478 kfree(adapter->eswitch); 1662 kfree(adapter->eswitch);
1479 1663
1480 qlcnic_clr_all_drv_state(adapter); 1664 qlcnic_clr_all_drv_state(adapter, 0);
1481 1665
1482 clear_bit(__QLCNIC_RESETTING, &adapter->state); 1666 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1483 1667
1668 qlcnic_free_lb_filters_mem(adapter);
1669
1484 qlcnic_teardown_intr(adapter); 1670 qlcnic_teardown_intr(adapter);
1485 1671
1486 qlcnic_remove_diag_entries(adapter); 1672 qlcnic_remove_diag_entries(adapter);
@@ -1509,7 +1695,7 @@ static int __qlcnic_shutdown(struct pci_dev *pdev)
1509 if (netif_running(netdev)) 1695 if (netif_running(netdev))
1510 qlcnic_down(adapter, netdev); 1696 qlcnic_down(adapter, netdev);
1511 1697
1512 qlcnic_clr_all_drv_state(adapter); 1698 qlcnic_clr_all_drv_state(adapter, 0);
1513 1699
1514 clear_bit(__QLCNIC_RESETTING, &adapter->state); 1700 clear_bit(__QLCNIC_RESETTING, &adapter->state);
1515 1701
@@ -1573,7 +1759,7 @@ qlcnic_resume(struct pci_dev *pdev)
1573 if (err) 1759 if (err)
1574 goto done; 1760 goto done;
1575 1761
1576 qlcnic_config_indev_addr(netdev, NETDEV_UP); 1762 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
1577 } 1763 }
1578done: 1764done:
1579 netif_device_attach(netdev); 1765 netif_device_attach(netdev);
@@ -1587,9 +1773,6 @@ static int qlcnic_open(struct net_device *netdev)
1587 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1773 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1588 int err; 1774 int err;
1589 1775
1590 if (adapter->driver_mismatch)
1591 return -EIO;
1592
1593 err = qlcnic_attach(adapter); 1776 err = qlcnic_attach(adapter);
1594 if (err) 1777 if (err)
1595 return err; 1778 return err;
@@ -1619,6 +1802,119 @@ static int qlcnic_close(struct net_device *netdev)
1619} 1802}
1620 1803
1621static void 1804static void
1805qlcnic_alloc_lb_filters_mem(struct qlcnic_adapter *adapter)
1806{
1807 void *head;
1808 int i;
1809
1810 if (!qlcnic_mac_learn)
1811 return;
1812
1813 spin_lock_init(&adapter->mac_learn_lock);
1814
1815 head = kcalloc(QLCNIC_LB_MAX_FILTERS, sizeof(struct hlist_head),
1816 GFP_KERNEL);
1817 if (!head)
1818 return;
1819
1820 adapter->fhash.fmax = QLCNIC_LB_MAX_FILTERS;
1821 adapter->fhash.fhead = (struct hlist_head *)head;
1822
1823 for (i = 0; i < adapter->fhash.fmax; i++)
1824 INIT_HLIST_HEAD(&adapter->fhash.fhead[i]);
1825}
1826
1827static void qlcnic_free_lb_filters_mem(struct qlcnic_adapter *adapter)
1828{
1829 if (adapter->fhash.fmax && adapter->fhash.fhead)
1830 kfree(adapter->fhash.fhead);
1831
1832 adapter->fhash.fhead = NULL;
1833 adapter->fhash.fmax = 0;
1834}
1835
1836static void qlcnic_change_filter(struct qlcnic_adapter *adapter,
1837 u64 uaddr, u16 vlan_id, struct qlcnic_host_tx_ring *tx_ring)
1838{
1839 struct cmd_desc_type0 *hwdesc;
1840 struct qlcnic_nic_req *req;
1841 struct qlcnic_mac_req *mac_req;
1842 u32 producer;
1843 u64 word;
1844
1845 producer = tx_ring->producer;
1846 hwdesc = &tx_ring->desc_head[tx_ring->producer];
1847
1848 req = (struct qlcnic_nic_req *)hwdesc;
1849 memset(req, 0, sizeof(struct qlcnic_nic_req));
1850 req->qhdr = cpu_to_le64(QLCNIC_REQUEST << 23);
1851
1852 word = QLCNIC_MAC_EVENT | ((u64)(adapter->portnum) << 16);
1853 req->req_hdr = cpu_to_le64(word);
1854
1855 mac_req = (struct qlcnic_mac_req *)&(req->words[0]);
1856 mac_req->op = vlan_id ? QLCNIC_MAC_VLAN_ADD : QLCNIC_MAC_ADD;
1857 memcpy(mac_req->mac_addr, &uaddr, ETH_ALEN);
1858
1859 req->words[1] = cpu_to_le64(vlan_id);
1860
1861 tx_ring->producer = get_next_index(producer, tx_ring->num_desc);
1862}
1863
1864#define QLCNIC_MAC_HASH(MAC)\
1865 ((((MAC) & 0x70000) >> 0x10) | (((MAC) & 0x70000000000ULL) >> 0x25))
1866
1867static void
1868qlcnic_send_filter(struct qlcnic_adapter *adapter,
1869 struct qlcnic_host_tx_ring *tx_ring,
1870 struct cmd_desc_type0 *first_desc,
1871 struct sk_buff *skb)
1872{
1873 struct ethhdr *phdr = (struct ethhdr *)(skb->data);
1874 struct qlcnic_filter *fil, *tmp_fil;
1875 struct hlist_node *tmp_hnode, *n;
1876 struct hlist_head *head;
1877 u64 src_addr = 0;
1878 u16 vlan_id = 0;
1879 u8 hindex;
1880
1881 if (!compare_ether_addr(phdr->h_source, adapter->mac_addr))
1882 return;
1883
1884 if (adapter->fhash.fnum >= adapter->fhash.fmax)
1885 return;
1886
1887 /* Only NPAR capable devices support vlan based learning*/
1888 if (adapter->flags & QLCNIC_ESWITCH_ENABLED)
1889 vlan_id = first_desc->vlan_TCI;
1890 memcpy(&src_addr, phdr->h_source, ETH_ALEN);
1891 hindex = QLCNIC_MAC_HASH(src_addr) & (QLCNIC_LB_MAX_FILTERS - 1);
1892 head = &(adapter->fhash.fhead[hindex]);
1893
1894 hlist_for_each_entry_safe(tmp_fil, tmp_hnode, n, head, fnode) {
1895 if (!memcmp(tmp_fil->faddr, &src_addr, ETH_ALEN) &&
1896 tmp_fil->vlan_id == vlan_id) {
1897 tmp_fil->ftime = jiffies;
1898 return;
1899 }
1900 }
1901
1902 fil = kzalloc(sizeof(struct qlcnic_filter), GFP_ATOMIC);
1903 if (!fil)
1904 return;
1905
1906 qlcnic_change_filter(adapter, src_addr, vlan_id, tx_ring);
1907
1908 fil->ftime = jiffies;
1909 fil->vlan_id = vlan_id;
1910 memcpy(fil->faddr, &src_addr, ETH_ALEN);
1911 spin_lock(&adapter->mac_learn_lock);
1912 hlist_add_head(&(fil->fnode), head);
1913 adapter->fhash.fnum++;
1914 spin_unlock(&adapter->mac_learn_lock);
1915}
1916
1917static void
1622qlcnic_tso_check(struct net_device *netdev, 1918qlcnic_tso_check(struct net_device *netdev,
1623 struct qlcnic_host_tx_ring *tx_ring, 1919 struct qlcnic_host_tx_ring *tx_ring,
1624 struct cmd_desc_type0 *first_desc, 1920 struct cmd_desc_type0 *first_desc,
@@ -1626,26 +1922,13 @@ qlcnic_tso_check(struct net_device *netdev,
1626{ 1922{
1627 u8 opcode = TX_ETHER_PKT; 1923 u8 opcode = TX_ETHER_PKT;
1628 __be16 protocol = skb->protocol; 1924 __be16 protocol = skb->protocol;
1629 u16 flags = 0, vid = 0; 1925 u16 flags = 0;
1630 int copied, offset, copy_len, hdr_len = 0, tso = 0, vlan_oob = 0; 1926 int copied, offset, copy_len, hdr_len = 0, tso = 0;
1631 struct cmd_desc_type0 *hwdesc; 1927 struct cmd_desc_type0 *hwdesc;
1632 struct vlan_ethhdr *vh; 1928 struct vlan_ethhdr *vh;
1633 struct qlcnic_adapter *adapter = netdev_priv(netdev); 1929 struct qlcnic_adapter *adapter = netdev_priv(netdev);
1634 u32 producer = tx_ring->producer; 1930 u32 producer = tx_ring->producer;
1635 1931 int vlan_oob = first_desc->flags_opcode & cpu_to_le16(FLAGS_VLAN_OOB);
1636 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
1637
1638 vh = (struct vlan_ethhdr *)skb->data;
1639 protocol = vh->h_vlan_encapsulated_proto;
1640 flags = FLAGS_VLAN_TAGGED;
1641
1642 } else if (vlan_tx_tag_present(skb)) {
1643
1644 flags = FLAGS_VLAN_OOB;
1645 vid = vlan_tx_tag_get(skb);
1646 qlcnic_set_tx_vlan_tci(first_desc, vid);
1647 vlan_oob = 1;
1648 }
1649 1932
1650 if (*(skb->data) & BIT_0) { 1933 if (*(skb->data) & BIT_0) {
1651 flags |= BIT_0; 1934 flags |= BIT_0;
@@ -1716,7 +1999,7 @@ qlcnic_tso_check(struct net_device *netdev,
1716 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2); 1999 vh = (struct vlan_ethhdr *)((char *)hwdesc + 2);
1717 skb_copy_from_linear_data(skb, vh, 12); 2000 skb_copy_from_linear_data(skb, vh, 12);
1718 vh->h_vlan_proto = htons(ETH_P_8021Q); 2001 vh->h_vlan_proto = htons(ETH_P_8021Q);
1719 vh->h_vlan_TCI = htons(vid); 2002 vh->h_vlan_TCI = htons(first_desc->vlan_TCI);
1720 skb_copy_from_linear_data_offset(skb, 12, 2003 skb_copy_from_linear_data_offset(skb, 12,
1721 (char *)vh + 16, copy_len - 16); 2004 (char *)vh + 16, copy_len - 16);
1722 2005
@@ -1796,11 +2079,47 @@ out_err:
1796 return -ENOMEM; 2079 return -ENOMEM;
1797} 2080}
1798 2081
2082static int
2083qlcnic_check_tx_tagging(struct qlcnic_adapter *adapter,
2084 struct sk_buff *skb,
2085 struct cmd_desc_type0 *first_desc)
2086{
2087 u8 opcode = 0;
2088 u16 flags = 0;
2089 __be16 protocol = skb->protocol;
2090 struct vlan_ethhdr *vh;
2091
2092 if (protocol == cpu_to_be16(ETH_P_8021Q)) {
2093 vh = (struct vlan_ethhdr *)skb->data;
2094 protocol = vh->h_vlan_encapsulated_proto;
2095 flags = FLAGS_VLAN_TAGGED;
2096 qlcnic_set_tx_vlan_tci(first_desc, ntohs(vh->h_vlan_TCI));
2097 } else if (vlan_tx_tag_present(skb)) {
2098 flags = FLAGS_VLAN_OOB;
2099 qlcnic_set_tx_vlan_tci(first_desc, vlan_tx_tag_get(skb));
2100 }
2101 if (unlikely(adapter->pvid)) {
2102 if (first_desc->vlan_TCI &&
2103 !(adapter->flags & QLCNIC_TAGGING_ENABLED))
2104 return -EIO;
2105 if (first_desc->vlan_TCI &&
2106 (adapter->flags & QLCNIC_TAGGING_ENABLED))
2107 goto set_flags;
2108
2109 flags = FLAGS_VLAN_OOB;
2110 qlcnic_set_tx_vlan_tci(first_desc, adapter->pvid);
2111 }
2112set_flags:
2113 qlcnic_set_tx_flags_opcode(first_desc, flags, opcode);
2114 return 0;
2115}
2116
1799static inline void 2117static inline void
1800qlcnic_clear_cmddesc(u64 *desc) 2118qlcnic_clear_cmddesc(u64 *desc)
1801{ 2119{
1802 desc[0] = 0ULL; 2120 desc[0] = 0ULL;
1803 desc[2] = 0ULL; 2121 desc[2] = 0ULL;
2122 desc[7] = 0ULL;
1804} 2123}
1805 2124
1806netdev_tx_t 2125netdev_tx_t
@@ -1812,6 +2131,7 @@ qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1812 struct qlcnic_skb_frag *buffrag; 2131 struct qlcnic_skb_frag *buffrag;
1813 struct cmd_desc_type0 *hwdesc, *first_desc; 2132 struct cmd_desc_type0 *hwdesc, *first_desc;
1814 struct pci_dev *pdev; 2133 struct pci_dev *pdev;
2134 struct ethhdr *phdr;
1815 int i, k; 2135 int i, k;
1816 2136
1817 u32 producer; 2137 u32 producer;
@@ -1823,6 +2143,13 @@ qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1823 return NETDEV_TX_BUSY; 2143 return NETDEV_TX_BUSY;
1824 } 2144 }
1825 2145
2146 if (adapter->flags & QLCNIC_MACSPOOF) {
2147 phdr = (struct ethhdr *)skb->data;
2148 if (compare_ether_addr(phdr->h_source,
2149 adapter->mac_addr))
2150 goto drop_packet;
2151 }
2152
1826 frag_count = skb_shinfo(skb)->nr_frags + 1; 2153 frag_count = skb_shinfo(skb)->nr_frags + 1;
1827 2154
1828 /* 4 fragments per cmd des */ 2155 /* 4 fragments per cmd des */
@@ -1844,6 +2171,12 @@ qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1844 2171
1845 pdev = adapter->pdev; 2172 pdev = adapter->pdev;
1846 2173
2174 first_desc = hwdesc = &tx_ring->desc_head[producer];
2175 qlcnic_clear_cmddesc((u64 *)hwdesc);
2176
2177 if (qlcnic_check_tx_tagging(adapter, skb, first_desc))
2178 goto drop_packet;
2179
1847 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) { 2180 if (qlcnic_map_tx_skb(pdev, skb, pbuf)) {
1848 adapter->stats.tx_dma_map_error++; 2181 adapter->stats.tx_dma_map_error++;
1849 goto drop_packet; 2182 goto drop_packet;
@@ -1852,9 +2185,6 @@ qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1852 pbuf->skb = skb; 2185 pbuf->skb = skb;
1853 pbuf->frag_count = frag_count; 2186 pbuf->frag_count = frag_count;
1854 2187
1855 first_desc = hwdesc = &tx_ring->desc_head[producer];
1856 qlcnic_clear_cmddesc((u64 *)hwdesc);
1857
1858 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len); 2188 qlcnic_set_tx_frags_len(first_desc, frag_count, skb->len);
1859 qlcnic_set_tx_port(first_desc, adapter->portnum); 2189 qlcnic_set_tx_port(first_desc, adapter->portnum);
1860 2190
@@ -1893,6 +2223,9 @@ qlcnic_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
1893 2223
1894 qlcnic_tso_check(netdev, tx_ring, first_desc, skb); 2224 qlcnic_tso_check(netdev, tx_ring, first_desc, skb);
1895 2225
2226 if (qlcnic_mac_learn)
2227 qlcnic_send_filter(adapter, tx_ring, first_desc, skb);
2228
1896 qlcnic_update_cmd_producer(adapter, tx_ring); 2229 qlcnic_update_cmd_producer(adapter, tx_ring);
1897 2230
1898 adapter->stats.txbytes += skb->len; 2231 adapter->stats.txbytes += skb->len;
@@ -1947,14 +2280,14 @@ void qlcnic_advert_link_change(struct qlcnic_adapter *adapter, int linkup)
1947 struct net_device *netdev = adapter->netdev; 2280 struct net_device *netdev = adapter->netdev;
1948 2281
1949 if (adapter->ahw.linkup && !linkup) { 2282 if (adapter->ahw.linkup && !linkup) {
1950 dev_info(&netdev->dev, "NIC Link is down\n"); 2283 netdev_info(netdev, "NIC Link is down\n");
1951 adapter->ahw.linkup = 0; 2284 adapter->ahw.linkup = 0;
1952 if (netif_running(netdev)) { 2285 if (netif_running(netdev)) {
1953 netif_carrier_off(netdev); 2286 netif_carrier_off(netdev);
1954 netif_stop_queue(netdev); 2287 netif_stop_queue(netdev);
1955 } 2288 }
1956 } else if (!adapter->ahw.linkup && linkup) { 2289 } else if (!adapter->ahw.linkup && linkup) {
1957 dev_info(&netdev->dev, "NIC Link is up\n"); 2290 netdev_info(netdev, "NIC Link is up\n");
1958 adapter->ahw.linkup = 1; 2291 adapter->ahw.linkup = 1;
1959 if (netif_running(netdev)) { 2292 if (netif_running(netdev)) {
1960 netif_carrier_on(netdev); 2293 netif_carrier_on(netdev);
@@ -2258,18 +2591,22 @@ qlcnic_clr_drv_state(struct qlcnic_adapter *adapter)
2258} 2591}
2259 2592
2260static void 2593static void
2261qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter) 2594qlcnic_clr_all_drv_state(struct qlcnic_adapter *adapter, u8 failed)
2262{ 2595{
2263 u32 val; 2596 u32 val;
2264 2597
2265 if (qlcnic_api_lock(adapter)) 2598 if (qlcnic_api_lock(adapter))
2266 goto err; 2599 goto err;
2267 2600
2268 val = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); 2601 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2269 QLC_DEV_CLR_REF_CNT(val, adapter->portnum); 2602 QLC_DEV_CLR_REF_CNT(val, adapter->portnum);
2270 QLCWR32(adapter, QLCNIC_CRB_DEV_REF_COUNT, val); 2603 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2271 2604
2272 if (!(val & 0x11111111)) 2605 if (failed) {
2606 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_FAILED);
2607 dev_info(&adapter->pdev->dev,
2608 "Device state set to Failed. Please Reboot\n");
2609 } else if (!(val & 0x11111111))
2273 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD); 2610 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_COLD);
2274 2611
2275 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2612 val = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
@@ -2290,7 +2627,7 @@ qlcnic_check_drv_state(struct qlcnic_adapter *adapter)
2290 int act, state; 2627 int act, state;
2291 2628
2292 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE); 2629 state = QLCRD32(adapter, QLCNIC_CRB_DRV_STATE);
2293 act = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); 2630 act = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2294 2631
2295 if (((state & 0x11111111) == (act & 0x11111111)) || 2632 if (((state & 0x11111111) == (act & 0x11111111)) ||
2296 ((act & 0x11111111) == ((state >> 1) & 0x11111111))) 2633 ((act & 0x11111111) == ((state >> 1) & 0x11111111)))
@@ -2325,10 +2662,10 @@ qlcnic_can_start_firmware(struct qlcnic_adapter *adapter)
2325 if (qlcnic_api_lock(adapter)) 2662 if (qlcnic_api_lock(adapter))
2326 return -1; 2663 return -1;
2327 2664
2328 val = QLCRD32(adapter, QLCNIC_CRB_DEV_REF_COUNT); 2665 val = QLCRD32(adapter, QLCNIC_CRB_DRV_ACTIVE);
2329 if (!(val & (1 << (portnum * 4)))) { 2666 if (!(val & (1 << (portnum * 4)))) {
2330 QLC_DEV_SET_REF_CNT(val, portnum); 2667 QLC_DEV_SET_REF_CNT(val, portnum);
2331 QLCWR32(adapter, QLCNIC_CRB_DEV_REF_COUNT, val); 2668 QLCWR32(adapter, QLCNIC_CRB_DRV_ACTIVE, val);
2332 } 2669 }
2333 2670
2334 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2671 prev_state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
@@ -2403,7 +2740,7 @@ qlcnic_fwinit_work(struct work_struct *work)
2403{ 2740{
2404 struct qlcnic_adapter *adapter = container_of(work, 2741 struct qlcnic_adapter *adapter = container_of(work,
2405 struct qlcnic_adapter, fw_work.work); 2742 struct qlcnic_adapter, fw_work.work);
2406 u32 dev_state = 0xf, npar_state; 2743 u32 dev_state = 0xf;
2407 2744
2408 if (qlcnic_api_lock(adapter)) 2745 if (qlcnic_api_lock(adapter))
2409 goto err_ret; 2746 goto err_ret;
@@ -2417,16 +2754,8 @@ qlcnic_fwinit_work(struct work_struct *work)
2417 } 2754 }
2418 2755
2419 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) { 2756 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) {
2420 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 2757 qlcnic_api_unlock(adapter);
2421 if (npar_state == QLCNIC_DEV_NPAR_RDY) { 2758 goto wait_npar;
2422 qlcnic_api_unlock(adapter);
2423 goto wait_npar;
2424 } else {
2425 qlcnic_schedule_work(adapter, qlcnic_fwinit_work,
2426 FW_POLL_DELAY);
2427 qlcnic_api_unlock(adapter);
2428 return;
2429 }
2430 } 2759 }
2431 2760
2432 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) { 2761 if (adapter->fw_wait_cnt++ > adapter->reset_ack_timeo) {
@@ -2463,6 +2792,7 @@ skip_ack_check:
2463 2792
2464 if (!adapter->nic_ops->start_firmware(adapter)) { 2793 if (!adapter->nic_ops->start_firmware(adapter)) {
2465 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2794 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2795 adapter->fw_wait_cnt = 0;
2466 return; 2796 return;
2467 } 2797 }
2468 goto err_ret; 2798 goto err_ret;
@@ -2475,27 +2805,25 @@ wait_npar:
2475 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state); 2805 QLCDB(adapter, HW, "Func waiting: Device state=%u\n", dev_state);
2476 2806
2477 switch (dev_state) { 2807 switch (dev_state) {
2478 case QLCNIC_DEV_QUISCENT: 2808 case QLCNIC_DEV_READY:
2479 case QLCNIC_DEV_NEED_QUISCENT:
2480 case QLCNIC_DEV_NEED_RESET:
2481 qlcnic_schedule_work(adapter,
2482 qlcnic_fwinit_work, FW_POLL_DELAY);
2483 return;
2484 case QLCNIC_DEV_FAILED:
2485 break;
2486
2487 default:
2488 if (!adapter->nic_ops->start_firmware(adapter)) { 2809 if (!adapter->nic_ops->start_firmware(adapter)) {
2489 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0); 2810 qlcnic_schedule_work(adapter, qlcnic_attach_work, 0);
2811 adapter->fw_wait_cnt = 0;
2490 return; 2812 return;
2491 } 2813 }
2814 case QLCNIC_DEV_FAILED:
2815 break;
2816 default:
2817 qlcnic_schedule_work(adapter,
2818 qlcnic_fwinit_work, FW_POLL_DELAY);
2819 return;
2492 } 2820 }
2493 2821
2494err_ret: 2822err_ret:
2495 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u " 2823 dev_err(&adapter->pdev->dev, "Fwinit work failed state=%u "
2496 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt); 2824 "fw_wait_cnt=%u\n", dev_state, adapter->fw_wait_cnt);
2497 netif_device_attach(adapter->netdev); 2825 netif_device_attach(adapter->netdev);
2498 qlcnic_clr_all_drv_state(adapter); 2826 qlcnic_clr_all_drv_state(adapter, 0);
2499} 2827}
2500 2828
2501static void 2829static void
@@ -2531,8 +2859,23 @@ err_ret:
2531 dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n", 2859 dev_err(&adapter->pdev->dev, "detach failed; status=%d temp=%d\n",
2532 status, adapter->temp); 2860 status, adapter->temp);
2533 netif_device_attach(netdev); 2861 netif_device_attach(netdev);
2534 qlcnic_clr_all_drv_state(adapter); 2862 qlcnic_clr_all_drv_state(adapter, 1);
2863}
2864
2865/*Transit NPAR state to NON Operational */
2866static void
2867qlcnic_set_npar_non_operational(struct qlcnic_adapter *adapter)
2868{
2869 u32 state;
2870
2871 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2872 if (state == QLCNIC_DEV_NPAR_NON_OPER)
2873 return;
2535 2874
2875 if (qlcnic_api_lock(adapter))
2876 return;
2877 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2878 qlcnic_api_unlock(adapter);
2536} 2879}
2537 2880
2538/*Transit to RESET state from READY state only */ 2881/*Transit to RESET state from READY state only */
@@ -2553,6 +2896,7 @@ qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2553 qlcnic_idc_debug_info(adapter, 0); 2896 qlcnic_idc_debug_info(adapter, 0);
2554 } 2897 }
2555 2898
2899 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_NON_OPER);
2556 qlcnic_api_unlock(adapter); 2900 qlcnic_api_unlock(adapter);
2557} 2901}
2558 2902
@@ -2560,21 +2904,11 @@ qlcnic_dev_request_reset(struct qlcnic_adapter *adapter)
2560static void 2904static void
2561qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter) 2905qlcnic_dev_set_npar_ready(struct qlcnic_adapter *adapter)
2562{ 2906{
2563 u32 state;
2564
2565 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) ||
2566 adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
2567 return;
2568 if (qlcnic_api_lock(adapter)) 2907 if (qlcnic_api_lock(adapter))
2569 return; 2908 return;
2570 2909
2571 state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE); 2910 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE, QLCNIC_DEV_NPAR_OPER);
2572 2911 QLCDB(adapter, DRV, "NPAR operational state set\n");
2573 if (state != QLCNIC_DEV_NPAR_RDY) {
2574 QLCWR32(adapter, QLCNIC_CRB_DEV_NPAR_STATE,
2575 QLCNIC_DEV_NPAR_RDY);
2576 QLCDB(adapter, DRV, "NPAR READY state set\n");
2577 }
2578 2912
2579 qlcnic_api_unlock(adapter); 2913 qlcnic_api_unlock(adapter);
2580} 2914}
@@ -2605,12 +2939,26 @@ qlcnic_attach_work(struct work_struct *work)
2605 struct qlcnic_adapter *adapter = container_of(work, 2939 struct qlcnic_adapter *adapter = container_of(work,
2606 struct qlcnic_adapter, fw_work.work); 2940 struct qlcnic_adapter, fw_work.work);
2607 struct net_device *netdev = adapter->netdev; 2941 struct net_device *netdev = adapter->netdev;
2942 u32 npar_state;
2608 2943
2944 if (adapter->op_mode != QLCNIC_MGMT_FUNC) {
2945 npar_state = QLCRD32(adapter, QLCNIC_CRB_DEV_NPAR_STATE);
2946 if (adapter->fw_wait_cnt++ > QLCNIC_DEV_NPAR_OPER_TIMEO)
2947 qlcnic_clr_all_drv_state(adapter, 0);
2948 else if (npar_state != QLCNIC_DEV_NPAR_OPER)
2949 qlcnic_schedule_work(adapter, qlcnic_attach_work,
2950 FW_POLL_DELAY);
2951 else
2952 goto attach;
2953 QLCDB(adapter, DRV, "Waiting for NPAR state to operational\n");
2954 return;
2955 }
2956attach:
2609 if (netif_running(netdev)) { 2957 if (netif_running(netdev)) {
2610 if (qlcnic_up(adapter, netdev)) 2958 if (qlcnic_up(adapter, netdev))
2611 goto done; 2959 goto done;
2612 2960
2613 qlcnic_config_indev_addr(netdev, NETDEV_UP); 2961 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2614 } 2962 }
2615 2963
2616done: 2964done:
@@ -2626,7 +2974,7 @@ done:
2626static int 2974static int
2627qlcnic_check_health(struct qlcnic_adapter *adapter) 2975qlcnic_check_health(struct qlcnic_adapter *adapter)
2628{ 2976{
2629 u32 state = 0, heartbit; 2977 u32 state = 0, heartbeat;
2630 struct net_device *netdev = adapter->netdev; 2978 struct net_device *netdev = adapter->netdev;
2631 2979
2632 if (qlcnic_check_temp(adapter)) 2980 if (qlcnic_check_temp(adapter))
@@ -2636,12 +2984,15 @@ qlcnic_check_health(struct qlcnic_adapter *adapter)
2636 qlcnic_dev_request_reset(adapter); 2984 qlcnic_dev_request_reset(adapter);
2637 2985
2638 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE); 2986 state = QLCRD32(adapter, QLCNIC_CRB_DEV_STATE);
2639 if (state == QLCNIC_DEV_NEED_RESET || state == QLCNIC_DEV_NEED_QUISCENT) 2987 if (state == QLCNIC_DEV_NEED_RESET ||
2988 state == QLCNIC_DEV_NEED_QUISCENT) {
2989 qlcnic_set_npar_non_operational(adapter);
2640 adapter->need_fw_reset = 1; 2990 adapter->need_fw_reset = 1;
2991 }
2641 2992
2642 heartbit = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER); 2993 heartbeat = QLCRD32(adapter, QLCNIC_PEG_ALIVE_COUNTER);
2643 if (heartbit != adapter->heartbit) { 2994 if (heartbeat != adapter->heartbeat) {
2644 adapter->heartbit = heartbit; 2995 adapter->heartbeat = heartbeat;
2645 adapter->fw_fail_cnt = 0; 2996 adapter->fw_fail_cnt = 0;
2646 if (adapter->need_fw_reset) 2997 if (adapter->need_fw_reset)
2647 goto detach; 2998 goto detach;
@@ -2692,6 +3043,9 @@ qlcnic_fw_poll_work(struct work_struct *work)
2692 if (qlcnic_check_health(adapter)) 3043 if (qlcnic_check_health(adapter))
2693 return; 3044 return;
2694 3045
3046 if (adapter->fhash.fnum)
3047 qlcnic_prune_lb_filters(adapter);
3048
2695reschedule: 3049reschedule:
2696 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY); 3050 qlcnic_schedule_work(adapter, qlcnic_fw_poll_work, FW_POLL_DELAY);
2697} 3051}
@@ -2738,7 +3092,7 @@ static int qlcnic_attach_func(struct pci_dev *pdev)
2738 if (qlcnic_api_lock(adapter)) 3092 if (qlcnic_api_lock(adapter))
2739 return -EINVAL; 3093 return -EINVAL;
2740 3094
2741 if (first_func) { 3095 if (adapter->op_mode != QLCNIC_NON_PRIV_FUNC && first_func) {
2742 adapter->need_fw_reset = 1; 3096 adapter->need_fw_reset = 1;
2743 set_bit(__QLCNIC_START_FW, &adapter->state); 3097 set_bit(__QLCNIC_START_FW, &adapter->state);
2744 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING); 3098 QLCWR32(adapter, QLCNIC_CRB_DEV_STATE, QLCNIC_DEV_INITIALIZING);
@@ -2756,7 +3110,7 @@ static int qlcnic_attach_func(struct pci_dev *pdev)
2756 if (netif_running(netdev)) { 3110 if (netif_running(netdev)) {
2757 err = qlcnic_attach(adapter); 3111 err = qlcnic_attach(adapter);
2758 if (err) { 3112 if (err) {
2759 qlcnic_clr_all_drv_state(adapter); 3113 qlcnic_clr_all_drv_state(adapter, 1);
2760 clear_bit(__QLCNIC_AER, &adapter->state); 3114 clear_bit(__QLCNIC_AER, &adapter->state);
2761 netif_device_attach(netdev); 3115 netif_device_attach(netdev);
2762 return err; 3116 return err;
@@ -2766,7 +3120,7 @@ static int qlcnic_attach_func(struct pci_dev *pdev)
2766 if (err) 3120 if (err)
2767 goto done; 3121 goto done;
2768 3122
2769 qlcnic_config_indev_addr(netdev, NETDEV_UP); 3123 qlcnic_restore_indev_addr(netdev, NETDEV_UP);
2770 } 3124 }
2771 done: 3125 done:
2772 netif_device_attach(netdev); 3126 netif_device_attach(netdev);
@@ -2822,7 +3176,6 @@ static void qlcnic_io_resume(struct pci_dev *pdev)
2822 FW_POLL_DELAY); 3176 FW_POLL_DELAY);
2823} 3177}
2824 3178
2825
2826static int 3179static int
2827qlcnicvf_start_firmware(struct qlcnic_adapter *adapter) 3180qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
2828{ 3181{
@@ -2832,8 +3185,20 @@ qlcnicvf_start_firmware(struct qlcnic_adapter *adapter)
2832 if (err) 3185 if (err)
2833 return err; 3186 return err;
2834 3187
3188 err = qlcnic_check_npar_opertional(adapter);
3189 if (err)
3190 return err;
3191
3192 err = qlcnic_initialize_nic(adapter);
3193 if (err)
3194 return err;
3195
2835 qlcnic_check_options(adapter); 3196 qlcnic_check_options(adapter);
2836 3197
3198 err = qlcnic_set_eswitch_port_config(adapter);
3199 if (err)
3200 return err;
3201
2837 adapter->need_fw_reset = 0; 3202 adapter->need_fw_reset = 0;
2838 3203
2839 return err; 3204 return err;
@@ -3093,9 +3458,6 @@ validate_pm_config(struct qlcnic_adapter *adapter,
3093 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC) 3458 if (adapter->npars[dest_pci_func].type != QLCNIC_TYPE_NIC)
3094 return QL_STATUS_INVALID_PARAM; 3459 return QL_STATUS_INVALID_PARAM;
3095 3460
3096 if (!IS_VALID_MODE(pm_cfg[i].action))
3097 return QL_STATUS_INVALID_PARAM;
3098
3099 s_esw_id = adapter->npars[src_pci_func].phy_port; 3461 s_esw_id = adapter->npars[src_pci_func].phy_port;
3100 d_esw_id = adapter->npars[dest_pci_func].phy_port; 3462 d_esw_id = adapter->npars[dest_pci_func].phy_port;
3101 3463
@@ -3129,7 +3491,7 @@ qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3129 return ret; 3491 return ret;
3130 for (i = 0; i < count; i++) { 3492 for (i = 0; i < count; i++) {
3131 pci_func = pm_cfg[i].pci_func; 3493 pci_func = pm_cfg[i].pci_func;
3132 action = pm_cfg[i].action; 3494 action = !!pm_cfg[i].action;
3133 id = adapter->npars[pci_func].phy_port; 3495 id = adapter->npars[pci_func].phy_port;
3134 ret = qlcnic_config_port_mirroring(adapter, id, 3496 ret = qlcnic_config_port_mirroring(adapter, id,
3135 action, pci_func); 3497 action, pci_func);
@@ -3140,7 +3502,7 @@ qlcnic_sysfs_write_pm_config(struct file *filp, struct kobject *kobj,
3140 for (i = 0; i < count; i++) { 3502 for (i = 0; i < count; i++) {
3141 pci_func = pm_cfg[i].pci_func; 3503 pci_func = pm_cfg[i].pci_func;
3142 id = adapter->npars[pci_func].phy_port; 3504 id = adapter->npars[pci_func].phy_port;
3143 adapter->npars[pci_func].enable_pm = pm_cfg[i].action; 3505 adapter->npars[pci_func].enable_pm = !!pm_cfg[i].action;
3144 adapter->npars[pci_func].dest_npar = id; 3506 adapter->npars[pci_func].dest_npar = id;
3145 } 3507 }
3146 return size; 3508 return size;
@@ -3172,30 +3534,45 @@ qlcnic_sysfs_read_pm_config(struct file *filp, struct kobject *kobj,
3172 3534
3173static int 3535static int
3174validate_esw_config(struct qlcnic_adapter *adapter, 3536validate_esw_config(struct qlcnic_adapter *adapter,
3175 struct qlcnic_esw_func_cfg *esw_cfg, int count) 3537 struct qlcnic_esw_func_cfg *esw_cfg, int count)
3176{ 3538{
3539 u32 op_mode;
3177 u8 pci_func; 3540 u8 pci_func;
3178 int i; 3541 int i;
3179 3542
3543 op_mode = readl(adapter->ahw.pci_base0 + QLCNIC_DRV_OP_MODE);
3544
3180 for (i = 0; i < count; i++) { 3545 for (i = 0; i < count; i++) {
3181 pci_func = esw_cfg[i].pci_func; 3546 pci_func = esw_cfg[i].pci_func;
3182 if (pci_func >= QLCNIC_MAX_PCI_FUNC) 3547 if (pci_func >= QLCNIC_MAX_PCI_FUNC)
3183 return QL_STATUS_INVALID_PARAM; 3548 return QL_STATUS_INVALID_PARAM;
3184 3549
3185 if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 3550 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3186 return QL_STATUS_INVALID_PARAM; 3551 if (adapter->npars[pci_func].type != QLCNIC_TYPE_NIC)
3552 return QL_STATUS_INVALID_PARAM;
3187 3553
3188 if (esw_cfg->host_vlan_tag == 1) 3554 switch (esw_cfg[i].op_mode) {
3555 case QLCNIC_PORT_DEFAULTS:
3556 if (QLC_DEV_GET_DRV(op_mode, pci_func) !=
3557 QLCNIC_NON_PRIV_FUNC) {
3558 esw_cfg[i].mac_anti_spoof = 0;
3559 esw_cfg[i].mac_override = 1;
3560 }
3561 break;
3562 case QLCNIC_ADD_VLAN:
3189 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id)) 3563 if (!IS_VALID_VLAN(esw_cfg[i].vlan_id))
3190 return QL_STATUS_INVALID_PARAM; 3564 return QL_STATUS_INVALID_PARAM;
3191 3565 if (!esw_cfg[i].op_type)
3192 if (!IS_VALID_MODE(esw_cfg[i].promisc_mode) 3566 return QL_STATUS_INVALID_PARAM;
3193 || !IS_VALID_MODE(esw_cfg[i].host_vlan_tag) 3567 break;
3194 || !IS_VALID_MODE(esw_cfg[i].mac_learning) 3568 case QLCNIC_DEL_VLAN:
3195 || !IS_VALID_MODE(esw_cfg[i].discard_tagged)) 3569 if (!esw_cfg[i].op_type)
3570 return QL_STATUS_INVALID_PARAM;
3571 break;
3572 default:
3196 return QL_STATUS_INVALID_PARAM; 3573 return QL_STATUS_INVALID_PARAM;
3574 }
3197 } 3575 }
3198
3199 return 0; 3576 return 0;
3200} 3577}
3201 3578
@@ -3206,8 +3583,9 @@ qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3206 struct device *dev = container_of(kobj, struct device, kobj); 3583 struct device *dev = container_of(kobj, struct device, kobj);
3207 struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3584 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3208 struct qlcnic_esw_func_cfg *esw_cfg; 3585 struct qlcnic_esw_func_cfg *esw_cfg;
3586 struct qlcnic_npar_info *npar;
3209 int count, rem, i, ret; 3587 int count, rem, i, ret;
3210 u8 id, pci_func; 3588 u8 pci_func, op_mode = 0;
3211 3589
3212 count = size / sizeof(struct qlcnic_esw_func_cfg); 3590 count = size / sizeof(struct qlcnic_esw_func_cfg);
3213 rem = size % sizeof(struct qlcnic_esw_func_cfg); 3591 rem = size % sizeof(struct qlcnic_esw_func_cfg);
@@ -3220,30 +3598,55 @@ qlcnic_sysfs_write_esw_config(struct file *file, struct kobject *kobj,
3220 return ret; 3598 return ret;
3221 3599
3222 for (i = 0; i < count; i++) { 3600 for (i = 0; i < count; i++) {
3223 pci_func = esw_cfg[i].pci_func; 3601 if (adapter->op_mode == QLCNIC_MGMT_FUNC)
3224 id = adapter->npars[pci_func].phy_port; 3602 if (qlcnic_config_switch_port(adapter, &esw_cfg[i]))
3225 ret = qlcnic_config_switch_port(adapter, id, 3603 return QL_STATUS_INVALID_PARAM;
3226 esw_cfg[i].host_vlan_tag, 3604
3227 esw_cfg[i].discard_tagged, 3605 if (adapter->ahw.pci_func != esw_cfg[i].pci_func)
3228 esw_cfg[i].promisc_mode, 3606 continue;
3229 esw_cfg[i].mac_learning, 3607
3230 esw_cfg[i].pci_func, 3608 op_mode = esw_cfg[i].op_mode;
3231 esw_cfg[i].vlan_id); 3609 qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]);
3232 if (ret) 3610 esw_cfg[i].op_mode = op_mode;
3233 return ret; 3611 esw_cfg[i].pci_func = adapter->ahw.pci_func;
3612
3613 switch (esw_cfg[i].op_mode) {
3614 case QLCNIC_PORT_DEFAULTS:
3615 qlcnic_set_eswitch_port_features(adapter, &esw_cfg[i]);
3616 break;
3617 case QLCNIC_ADD_VLAN:
3618 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3619 break;
3620 case QLCNIC_DEL_VLAN:
3621 esw_cfg[i].vlan_id = 0;
3622 qlcnic_set_vlan_config(adapter, &esw_cfg[i]);
3623 break;
3624 }
3234 } 3625 }
3235 3626
3627 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3628 goto out;
3629
3236 for (i = 0; i < count; i++) { 3630 for (i = 0; i < count; i++) {
3237 pci_func = esw_cfg[i].pci_func; 3631 pci_func = esw_cfg[i].pci_func;
3238 adapter->npars[pci_func].promisc_mode = esw_cfg[i].promisc_mode; 3632 npar = &adapter->npars[pci_func];
3239 adapter->npars[pci_func].mac_learning = esw_cfg[i].mac_learning; 3633 switch (esw_cfg[i].op_mode) {
3240 adapter->npars[pci_func].vlan_id = esw_cfg[i].vlan_id; 3634 case QLCNIC_PORT_DEFAULTS:
3241 adapter->npars[pci_func].discard_tagged = 3635 npar->promisc_mode = esw_cfg[i].promisc_mode;
3242 esw_cfg[i].discard_tagged; 3636 npar->mac_override = esw_cfg[i].mac_override;
3243 adapter->npars[pci_func].host_vlan_tag = 3637 npar->offload_flags = esw_cfg[i].offload_flags;
3244 esw_cfg[i].host_vlan_tag; 3638 npar->mac_anti_spoof = esw_cfg[i].mac_anti_spoof;
3639 npar->discard_tagged = esw_cfg[i].discard_tagged;
3640 break;
3641 case QLCNIC_ADD_VLAN:
3642 npar->pvid = esw_cfg[i].vlan_id;
3643 break;
3644 case QLCNIC_DEL_VLAN:
3645 npar->pvid = 0;
3646 break;
3647 }
3245 } 3648 }
3246 3649out:
3247 return size; 3650 return size;
3248} 3651}
3249 3652
@@ -3254,7 +3657,7 @@ qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3254 struct device *dev = container_of(kobj, struct device, kobj); 3657 struct device *dev = container_of(kobj, struct device, kobj);
3255 struct qlcnic_adapter *adapter = dev_get_drvdata(dev); 3658 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3256 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC]; 3659 struct qlcnic_esw_func_cfg esw_cfg[QLCNIC_MAX_PCI_FUNC];
3257 int i; 3660 u8 i;
3258 3661
3259 if (size != sizeof(esw_cfg)) 3662 if (size != sizeof(esw_cfg))
3260 return QL_STATUS_INVALID_PARAM; 3663 return QL_STATUS_INVALID_PARAM;
@@ -3262,12 +3665,9 @@ qlcnic_sysfs_read_esw_config(struct file *file, struct kobject *kobj,
3262 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) { 3665 for (i = 0; i < QLCNIC_MAX_PCI_FUNC; i++) {
3263 if (adapter->npars[i].type != QLCNIC_TYPE_NIC) 3666 if (adapter->npars[i].type != QLCNIC_TYPE_NIC)
3264 continue; 3667 continue;
3265 3668 esw_cfg[i].pci_func = i;
3266 esw_cfg[i].host_vlan_tag = adapter->npars[i].host_vlan_tag; 3669 if (qlcnic_get_eswitch_port_config(adapter, &esw_cfg[i]))
3267 esw_cfg[i].promisc_mode = adapter->npars[i].promisc_mode; 3670 return QL_STATUS_INVALID_PARAM;
3268 esw_cfg[i].discard_tagged = adapter->npars[i].discard_tagged;
3269 esw_cfg[i].vlan_id = adapter->npars[i].vlan_id;
3270 esw_cfg[i].mac_learning = adapter->npars[i].mac_learning;
3271 } 3671 }
3272 memcpy(buf, &esw_cfg, size); 3672 memcpy(buf, &esw_cfg, size);
3273 3673
@@ -3370,6 +3770,115 @@ qlcnic_sysfs_read_npar_config(struct file *file, struct kobject *kobj,
3370} 3770}
3371 3771
3372static ssize_t 3772static ssize_t
3773qlcnic_sysfs_get_port_stats(struct file *file, struct kobject *kobj,
3774 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3775{
3776 struct device *dev = container_of(kobj, struct device, kobj);
3777 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3778 struct qlcnic_esw_statistics port_stats;
3779 int ret;
3780
3781 if (size != sizeof(struct qlcnic_esw_statistics))
3782 return QL_STATUS_INVALID_PARAM;
3783
3784 if (offset >= QLCNIC_MAX_PCI_FUNC)
3785 return QL_STATUS_INVALID_PARAM;
3786
3787 memset(&port_stats, 0, size);
3788 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3789 &port_stats.rx);
3790 if (ret)
3791 return ret;
3792
3793 ret = qlcnic_get_port_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3794 &port_stats.tx);
3795 if (ret)
3796 return ret;
3797
3798 memcpy(buf, &port_stats, size);
3799 return size;
3800}
3801
3802static ssize_t
3803qlcnic_sysfs_get_esw_stats(struct file *file, struct kobject *kobj,
3804 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3805{
3806 struct device *dev = container_of(kobj, struct device, kobj);
3807 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3808 struct qlcnic_esw_statistics esw_stats;
3809 int ret;
3810
3811 if (size != sizeof(struct qlcnic_esw_statistics))
3812 return QL_STATUS_INVALID_PARAM;
3813
3814 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3815 return QL_STATUS_INVALID_PARAM;
3816
3817 memset(&esw_stats, 0, size);
3818 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_RX_COUNTER,
3819 &esw_stats.rx);
3820 if (ret)
3821 return ret;
3822
3823 ret = qlcnic_get_eswitch_stats(adapter, offset, QLCNIC_QUERY_TX_COUNTER,
3824 &esw_stats.tx);
3825 if (ret)
3826 return ret;
3827
3828 memcpy(buf, &esw_stats, size);
3829 return size;
3830}
3831
3832static ssize_t
3833qlcnic_sysfs_clear_esw_stats(struct file *file, struct kobject *kobj,
3834 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3835{
3836 struct device *dev = container_of(kobj, struct device, kobj);
3837 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3838 int ret;
3839
3840 if (offset >= QLCNIC_NIU_MAX_XG_PORTS)
3841 return QL_STATUS_INVALID_PARAM;
3842
3843 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3844 QLCNIC_QUERY_RX_COUNTER);
3845 if (ret)
3846 return ret;
3847
3848 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_ESWITCH, offset,
3849 QLCNIC_QUERY_TX_COUNTER);
3850 if (ret)
3851 return ret;
3852
3853 return size;
3854}
3855
3856static ssize_t
3857qlcnic_sysfs_clear_port_stats(struct file *file, struct kobject *kobj,
3858 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3859{
3860
3861 struct device *dev = container_of(kobj, struct device, kobj);
3862 struct qlcnic_adapter *adapter = dev_get_drvdata(dev);
3863 int ret;
3864
3865 if (offset >= QLCNIC_MAX_PCI_FUNC)
3866 return QL_STATUS_INVALID_PARAM;
3867
3868 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3869 QLCNIC_QUERY_RX_COUNTER);
3870 if (ret)
3871 return ret;
3872
3873 ret = qlcnic_clear_esw_stats(adapter, QLCNIC_STATS_PORT, offset,
3874 QLCNIC_QUERY_TX_COUNTER);
3875 if (ret)
3876 return ret;
3877
3878 return size;
3879}
3880
3881static ssize_t
3373qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj, 3882qlcnic_sysfs_read_pci_config(struct file *file, struct kobject *kobj,
3374 struct bin_attribute *attr, char *buf, loff_t offset, size_t size) 3883 struct bin_attribute *attr, char *buf, loff_t offset, size_t size)
3375{ 3884{
@@ -3418,6 +3927,20 @@ static struct bin_attribute bin_attr_pci_config = {
3418 .write = NULL, 3927 .write = NULL,
3419}; 3928};
3420 3929
3930static struct bin_attribute bin_attr_port_stats = {
3931 .attr = {.name = "port_stats", .mode = (S_IRUGO | S_IWUSR)},
3932 .size = 0,
3933 .read = qlcnic_sysfs_get_port_stats,
3934 .write = qlcnic_sysfs_clear_port_stats,
3935};
3936
3937static struct bin_attribute bin_attr_esw_stats = {
3938 .attr = {.name = "esw_stats", .mode = (S_IRUGO | S_IWUSR)},
3939 .size = 0,
3940 .read = qlcnic_sysfs_get_esw_stats,
3941 .write = qlcnic_sysfs_clear_esw_stats,
3942};
3943
3421static struct bin_attribute bin_attr_esw_config = { 3944static struct bin_attribute bin_attr_esw_config = {
3422 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)}, 3945 .attr = {.name = "esw_config", .mode = (S_IRUGO | S_IWUSR)},
3423 .size = 0, 3946 .size = 0,
@@ -3457,6 +3980,9 @@ qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
3457{ 3980{
3458 struct device *dev = &adapter->pdev->dev; 3981 struct device *dev = &adapter->pdev->dev;
3459 3982
3983 if (device_create_bin_file(dev, &bin_attr_port_stats))
3984 dev_info(dev, "failed to create port stats sysfs entry");
3985
3460 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) 3986 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
3461 return; 3987 return;
3462 if (device_create_file(dev, &dev_attr_diag_mode)) 3988 if (device_create_file(dev, &dev_attr_diag_mode))
@@ -3465,18 +3991,20 @@ qlcnic_create_diag_entries(struct qlcnic_adapter *adapter)
3465 dev_info(dev, "failed to create crb sysfs entry\n"); 3991 dev_info(dev, "failed to create crb sysfs entry\n");
3466 if (device_create_bin_file(dev, &bin_attr_mem)) 3992 if (device_create_bin_file(dev, &bin_attr_mem))
3467 dev_info(dev, "failed to create mem sysfs entry\n"); 3993 dev_info(dev, "failed to create mem sysfs entry\n");
3468 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 3994 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
3469 adapter->op_mode != QLCNIC_MGMT_FUNC) 3995 return;
3996 if (device_create_bin_file(dev, &bin_attr_esw_config))
3997 dev_info(dev, "failed to create esw config sysfs entry");
3998 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3470 return; 3999 return;
3471 if (device_create_bin_file(dev, &bin_attr_pci_config)) 4000 if (device_create_bin_file(dev, &bin_attr_pci_config))
3472 dev_info(dev, "failed to create pci config sysfs entry"); 4001 dev_info(dev, "failed to create pci config sysfs entry");
3473 if (device_create_bin_file(dev, &bin_attr_npar_config)) 4002 if (device_create_bin_file(dev, &bin_attr_npar_config))
3474 dev_info(dev, "failed to create npar config sysfs entry"); 4003 dev_info(dev, "failed to create npar config sysfs entry");
3475 if (device_create_bin_file(dev, &bin_attr_esw_config))
3476 dev_info(dev, "failed to create esw config sysfs entry");
3477 if (device_create_bin_file(dev, &bin_attr_pm_config)) 4004 if (device_create_bin_file(dev, &bin_attr_pm_config))
3478 dev_info(dev, "failed to create pm config sysfs entry"); 4005 dev_info(dev, "failed to create pm config sysfs entry");
3479 4006 if (device_create_bin_file(dev, &bin_attr_esw_stats))
4007 dev_info(dev, "failed to create eswitch stats sysfs entry");
3480} 4008}
3481 4009
3482static void 4010static void
@@ -3484,18 +4012,22 @@ qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
3484{ 4012{
3485 struct device *dev = &adapter->pdev->dev; 4013 struct device *dev = &adapter->pdev->dev;
3486 4014
4015 device_remove_bin_file(dev, &bin_attr_port_stats);
4016
3487 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC) 4017 if (adapter->op_mode == QLCNIC_NON_PRIV_FUNC)
3488 return; 4018 return;
3489 device_remove_file(dev, &dev_attr_diag_mode); 4019 device_remove_file(dev, &dev_attr_diag_mode);
3490 device_remove_bin_file(dev, &bin_attr_crb); 4020 device_remove_bin_file(dev, &bin_attr_crb);
3491 device_remove_bin_file(dev, &bin_attr_mem); 4021 device_remove_bin_file(dev, &bin_attr_mem);
3492 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED) || 4022 if (!(adapter->flags & QLCNIC_ESWITCH_ENABLED))
3493 adapter->op_mode != QLCNIC_MGMT_FUNC) 4023 return;
4024 device_remove_bin_file(dev, &bin_attr_esw_config);
4025 if (adapter->op_mode != QLCNIC_MGMT_FUNC)
3494 return; 4026 return;
3495 device_remove_bin_file(dev, &bin_attr_pci_config); 4027 device_remove_bin_file(dev, &bin_attr_pci_config);
3496 device_remove_bin_file(dev, &bin_attr_npar_config); 4028 device_remove_bin_file(dev, &bin_attr_npar_config);
3497 device_remove_bin_file(dev, &bin_attr_esw_config);
3498 device_remove_bin_file(dev, &bin_attr_pm_config); 4029 device_remove_bin_file(dev, &bin_attr_pm_config);
4030 device_remove_bin_file(dev, &bin_attr_esw_stats);
3499} 4031}
3500 4032
3501#ifdef CONFIG_INET 4033#ifdef CONFIG_INET
@@ -3503,10 +4035,10 @@ qlcnic_remove_diag_entries(struct qlcnic_adapter *adapter)
3503#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops) 4035#define is_qlcnic_netdev(dev) (dev->netdev_ops == &qlcnic_netdev_ops)
3504 4036
3505static void 4037static void
3506qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) 4038qlcnic_config_indev_addr(struct qlcnic_adapter *adapter,
4039 struct net_device *dev, unsigned long event)
3507{ 4040{
3508 struct in_device *indev; 4041 struct in_device *indev;
3509 struct qlcnic_adapter *adapter = netdev_priv(dev);
3510 4042
3511 indev = in_dev_get(dev); 4043 indev = in_dev_get(dev);
3512 if (!indev) 4044 if (!indev)
@@ -3530,6 +4062,27 @@ qlcnic_config_indev_addr(struct net_device *dev, unsigned long event)
3530 in_dev_put(indev); 4062 in_dev_put(indev);
3531} 4063}
3532 4064
4065static void
4066qlcnic_restore_indev_addr(struct net_device *netdev, unsigned long event)
4067{
4068 struct qlcnic_adapter *adapter = netdev_priv(netdev);
4069 struct net_device *dev;
4070 u16 vid;
4071
4072 qlcnic_config_indev_addr(adapter, netdev, event);
4073
4074 if (!adapter->vlgrp)
4075 return;
4076
4077 for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) {
4078 dev = vlan_group_get_device(adapter->vlgrp, vid);
4079 if (!dev)
4080 continue;
4081
4082 qlcnic_config_indev_addr(adapter, dev, event);
4083 }
4084}
4085
3533static int qlcnic_netdev_event(struct notifier_block *this, 4086static int qlcnic_netdev_event(struct notifier_block *this,
3534 unsigned long event, void *ptr) 4087 unsigned long event, void *ptr)
3535{ 4088{
@@ -3556,7 +4109,7 @@ recheck:
3556 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state)) 4109 if (!test_bit(__QLCNIC_DEV_UP, &adapter->state))
3557 goto done; 4110 goto done;
3558 4111
3559 qlcnic_config_indev_addr(dev, event); 4112 qlcnic_config_indev_addr(adapter, dev, event);
3560done: 4113done:
3561 return NOTIFY_DONE; 4114 return NOTIFY_DONE;
3562} 4115}
@@ -3573,7 +4126,7 @@ qlcnic_inetaddr_event(struct notifier_block *this,
3573 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL; 4126 dev = ifa->ifa_dev ? ifa->ifa_dev->dev : NULL;
3574 4127
3575recheck: 4128recheck:
3576 if (dev == NULL || !netif_running(dev)) 4129 if (dev == NULL)
3577 goto done; 4130 goto done;
3578 4131
3579 if (dev->priv_flags & IFF_802_1Q_VLAN) { 4132 if (dev->priv_flags & IFF_802_1Q_VLAN) {
@@ -3616,7 +4169,7 @@ static struct notifier_block qlcnic_inetaddr_cb = {
3616}; 4169};
3617#else 4170#else
3618static void 4171static void
3619qlcnic_config_indev_addr(struct net_device *dev, unsigned long event) 4172qlcnic_restore_indev_addr(struct net_device *dev, unsigned long event)
3620{ } 4173{ }
3621#endif 4174#endif
3622static struct pci_error_handlers qlcnic_err_handler = { 4175static struct pci_error_handlers qlcnic_err_handler = {