Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'Bug-fixes-for-ENA-Ethernet-driver'

Sameeh Jubran says:

====================
Bug fixes for ENA Ethernet driver

Difference from V1:
* Started using netdev_rss_key_fill()
* Dropped superflous changes that are not related to bug fixes as
requested by Jakub
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+115 -44
+58 -38
drivers/net/ethernet/amazon/ena/ena_com.c
··· 200 200 static struct ena_comp_ctx *get_comp_ctxt(struct ena_com_admin_queue *queue, 201 201 u16 command_id, bool capture) 202 202 { 203 + if (unlikely(!queue->comp_ctx)) { 204 + pr_err("Completion context is NULL\n"); 205 + return NULL; 206 + } 207 + 203 208 if (unlikely(command_id >= queue->q_depth)) { 204 209 pr_err("command id is larger than the queue size. cmd_id: %u queue size %d\n", 205 210 command_id, queue->q_depth); ··· 1046 1041 feature_ver); 1047 1042 } 1048 1043 1044 + int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev) 1045 + { 1046 + return ena_dev->rss.hash_func; 1047 + } 1048 + 1049 + static void ena_com_hash_key_fill_default_key(struct ena_com_dev *ena_dev) 1050 + { 1051 + struct ena_admin_feature_rss_flow_hash_control *hash_key = 1052 + (ena_dev->rss).hash_key; 1053 + 1054 + netdev_rss_key_fill(&hash_key->key, sizeof(hash_key->key)); 1055 + /* The key is stored in the device in u32 array 1056 + * as well as the API requires the key to be passed in this 1057 + * format. Thus the size of our array should be divided by 4 1058 + */ 1059 + hash_key->keys_num = sizeof(hash_key->key) / sizeof(u32); 1060 + } 1061 + 1049 1062 static int ena_com_hash_key_allocate(struct ena_com_dev *ena_dev) 1050 1063 { 1051 1064 struct ena_rss *rss = &ena_dev->rss; 1065 + struct ena_admin_feature_rss_flow_hash_control *hash_key; 1066 + struct ena_admin_get_feat_resp get_resp; 1067 + int rc; 1068 + 1069 + hash_key = (ena_dev->rss).hash_key; 1070 + 1071 + rc = ena_com_get_feature_ex(ena_dev, &get_resp, 1072 + ENA_ADMIN_RSS_HASH_FUNCTION, 1073 + ena_dev->rss.hash_key_dma_addr, 1074 + sizeof(ena_dev->rss.hash_key), 0); 1075 + if (unlikely(rc)) { 1076 + hash_key = NULL; 1077 + return -EOPNOTSUPP; 1078 + } 1052 1079 1053 1080 rss->hash_key = 1054 1081 dma_alloc_coherent(ena_dev->dmadev, sizeof(*rss->hash_key), ··· 1286 1249 return -EINVAL; 1287 1250 1288 1251 rss->rss_ind_tbl[i].cq_idx = io_sq->idx; 1289 - } 1290 - 1291 - return 0; 1292 - } 1293 - 1294 - static int ena_com_ind_tbl_convert_from_device(struct ena_com_dev *ena_dev) 1295 - { 1296 - u16 dev_idx_to_host_tbl[ENA_TOTAL_NUM_QUEUES] = { (u16)-1 }; 1297 - struct ena_rss *rss = &ena_dev->rss; 1298 - u8 idx; 1299 - u16 i; 1300 - 1301 - for (i = 0; i < ENA_TOTAL_NUM_QUEUES; i++) 1302 - dev_idx_to_host_tbl[ena_dev->io_sq_queues[i].idx] = i; 1303 - 1304 - for (i = 0; i < 1 << rss->tbl_log_size; i++) { 1305 - if (rss->rss_ind_tbl[i].cq_idx > ENA_TOTAL_NUM_QUEUES) 1306 - return -EINVAL; 1307 - idx = (u8)rss->rss_ind_tbl[i].cq_idx; 1308 - 1309 - if (dev_idx_to_host_tbl[idx] > ENA_TOTAL_NUM_QUEUES) 1310 - return -EINVAL; 1311 - 1312 - rss->host_rss_ind_tbl[i] = dev_idx_to_host_tbl[idx]; 1313 1252 } 1314 1253 1315 1254 return 0; ··· 2310 2297 2311 2298 switch (func) { 2312 2299 case ENA_ADMIN_TOEPLITZ: 2313 - if (key_len > sizeof(hash_key->key)) { 2314 - pr_err("key len (%hu) is bigger than the max supported (%zu)\n", 2315 - key_len, sizeof(hash_key->key)); 2316 - return -EINVAL; 2300 + if (key) { 2301 + if (key_len != sizeof(hash_key->key)) { 2302 + pr_err("key len (%hu) doesn't equal the supported size (%zu)\n", 2303 + key_len, sizeof(hash_key->key)); 2304 + return -EINVAL; 2305 + } 2306 + memcpy(hash_key->key, key, key_len); 2307 + rss->hash_init_val = init_val; 2308 + hash_key->keys_num = key_len >> 2; 2317 2309 } 2318 - 2319 - memcpy(hash_key->key, key, key_len); 2320 - rss->hash_init_val = init_val; 2321 - hash_key->keys_num = key_len >> 2; 2322 2310 break; 2323 2311 case ENA_ADMIN_CRC32: 2324 2312 rss->hash_init_val = init_val; ··· 2356 2342 if (unlikely(rc)) 2357 2343 return rc; 2358 2344 2359 - rss->hash_func = get_resp.u.flow_hash_func.selected_func; 2345 + /* ffs() returns 1 in case the lsb is set */ 2346 + rss->hash_func = ffs(get_resp.u.flow_hash_func.selected_func); 2347 + if (rss->hash_func) 2348 + rss->hash_func--; 2349 + 2360 2350 if (func) 2361 2351 *func = rss->hash_func; 2362 2352 ··· 2624 2606 if (!ind_tbl) 2625 2607 return 0; 2626 2608 2627 - rc = ena_com_ind_tbl_convert_from_device(ena_dev); 2628 - if (unlikely(rc)) 2629 - return rc; 2630 - 2631 2609 for (i = 0; i < (1 << rss->tbl_log_size); i++) 2632 2610 ind_tbl[i] = rss->host_rss_ind_tbl[i]; 2633 2611 ··· 2640 2626 if (unlikely(rc)) 2641 2627 goto err_indr_tbl; 2642 2628 2629 + /* The following function might return unsupported in case the 2630 + * device doesn't support setting the key / hash function. We can safely 2631 + * ignore this error and have indirection table support only. 2632 + */ 2643 2633 rc = ena_com_hash_key_allocate(ena_dev); 2644 - if (unlikely(rc)) 2634 + if (unlikely(rc) && rc != -EOPNOTSUPP) 2645 2635 goto err_hash_key; 2636 + else if (rc != -EOPNOTSUPP) 2637 + ena_com_hash_key_fill_default_key(ena_dev); 2646 2638 2647 2639 rc = ena_com_hash_ctrl_init(ena_dev); 2648 2640 if (unlikely(rc))
+9
drivers/net/ethernet/amazon/ena/ena_com.h
··· 44 44 #include <linux/spinlock.h> 45 45 #include <linux/types.h> 46 46 #include <linux/wait.h> 47 + #include <linux/netdevice.h> 47 48 48 49 #include "ena_common_defs.h" 49 50 #include "ena_admin_defs.h" ··· 655 654 * Free all the RSS/RFS resources. 656 655 */ 657 656 void ena_com_rss_destroy(struct ena_com_dev *ena_dev); 657 + 658 + /* ena_com_get_current_hash_function - Get RSS hash function 659 + * @ena_dev: ENA communication layer struct 660 + * 661 + * Return the current hash function. 662 + * @return: 0 or one of the ena_admin_hash_functions values. 663 + */ 664 + int ena_com_get_current_hash_function(struct ena_com_dev *ena_dev); 658 665 659 666 /* ena_com_fill_hash_function - Fill RSS hash function 660 667 * @ena_dev: ENA communication layer struct
+43 -3
drivers/net/ethernet/amazon/ena/ena_ethtool.c
··· 636 636 return ENA_HASH_KEY_SIZE; 637 637 } 638 638 639 + static int ena_indirection_table_get(struct ena_adapter *adapter, u32 *indir) 640 + { 641 + struct ena_com_dev *ena_dev = adapter->ena_dev; 642 + int i, rc; 643 + 644 + if (!indir) 645 + return 0; 646 + 647 + rc = ena_com_indirect_table_get(ena_dev, indir); 648 + if (rc) 649 + return rc; 650 + 651 + /* Our internal representation of the indices is: even indices 652 + * for Tx and uneven indices for Rx. We need to convert the Rx 653 + * indices to be consecutive 654 + */ 655 + for (i = 0; i < ENA_RX_RSS_TABLE_SIZE; i++) 656 + indir[i] = ENA_IO_RXQ_IDX_TO_COMBINED_IDX(indir[i]); 657 + 658 + return rc; 659 + } 660 + 639 661 static int ena_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key, 640 662 u8 *hfunc) 641 663 { ··· 666 644 u8 func; 667 645 int rc; 668 646 669 - rc = ena_com_indirect_table_get(adapter->ena_dev, indir); 647 + rc = ena_indirection_table_get(adapter, indir); 670 648 if (rc) 671 649 return rc; 672 650 651 + /* We call this function in order to check if the device 652 + * supports getting/setting the hash function. 653 + */ 673 654 rc = ena_com_get_hash_function(adapter->ena_dev, &ena_func, key); 655 + 656 + if (rc) { 657 + if (rc == -EOPNOTSUPP) { 658 + key = NULL; 659 + hfunc = NULL; 660 + rc = 0; 661 + } 662 + 663 + return rc; 664 + } 665 + 674 666 if (rc) 675 667 return rc; 676 668 ··· 693 657 func = ETH_RSS_HASH_TOP; 694 658 break; 695 659 case ENA_ADMIN_CRC32: 696 - func = ETH_RSS_HASH_XOR; 660 + func = ETH_RSS_HASH_CRC32; 697 661 break; 698 662 default: 699 663 netif_err(adapter, drv, netdev, ··· 736 700 } 737 701 738 702 switch (hfunc) { 703 + case ETH_RSS_HASH_NO_CHANGE: 704 + func = ena_com_get_current_hash_function(ena_dev); 705 + break; 739 706 case ETH_RSS_HASH_TOP: 740 707 func = ENA_ADMIN_TOEPLITZ; 741 708 break; 742 - case ETH_RSS_HASH_XOR: 709 + case ETH_RSS_HASH_CRC32: 743 710 func = ENA_ADMIN_CRC32; 744 711 break; 745 712 default: ··· 853 814 .set_channels = ena_set_channels, 854 815 .get_tunable = ena_get_tunable, 855 816 .set_tunable = ena_set_tunable, 817 + .get_ts_info = ethtool_op_get_ts_info, 856 818 }; 857 819 858 820 void ena_set_ethtool_ops(struct net_device *netdev)
+3 -3
drivers/net/ethernet/amazon/ena/ena_netdev.c
··· 3706 3706 if (adapter->keep_alive_timeout == ENA_HW_HINTS_NO_TIMEOUT) 3707 3707 return; 3708 3708 3709 - keep_alive_expired = round_jiffies(adapter->last_keep_alive_jiffies + 3710 - adapter->keep_alive_timeout); 3709 + keep_alive_expired = adapter->last_keep_alive_jiffies + 3710 + adapter->keep_alive_timeout; 3711 3711 if (unlikely(time_is_before_jiffies(keep_alive_expired))) { 3712 3712 netif_err(adapter, drv, adapter->netdev, 3713 3713 "Keep alive watchdog timeout.\n"); ··· 3809 3809 } 3810 3810 3811 3811 /* Reset the timer */ 3812 - mod_timer(&adapter->timer_service, jiffies + HZ); 3812 + mod_timer(&adapter->timer_service, round_jiffies(jiffies + HZ)); 3813 3813 } 3814 3814 3815 3815 static int ena_calc_max_io_queue_num(struct pci_dev *pdev,
+2
drivers/net/ethernet/amazon/ena/ena_netdev.h
··· 130 130 131 131 #define ENA_IO_TXQ_IDX(q) (2 * (q)) 132 132 #define ENA_IO_RXQ_IDX(q) (2 * (q) + 1) 133 + #define ENA_IO_TXQ_IDX_TO_COMBINED_IDX(q) ((q) / 2) 134 + #define ENA_IO_RXQ_IDX_TO_COMBINED_IDX(q) (((q) - 1) / 2) 133 135 134 136 #define ENA_MGMNT_IRQ_IDX 0 135 137 #define ENA_IO_IRQ_FIRST_IDX 1