Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1 | /* Broadcom NetXtreme-C/E network driver. |
| 2 | * |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 3 | * Copyright (c) 2014-2016 Broadcom Corporation |
Michael Chan | 894aa69 | 2018-01-17 03:21:03 -0500 | [diff] [blame] | 4 | * Copyright (c) 2016-2018 Broadcom Limited |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation. |
| 9 | */ |
| 10 | |
| 11 | #include <linux/module.h> |
| 12 | |
| 13 | #include <linux/stringify.h> |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/timer.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/ioport.h> |
| 18 | #include <linux/slab.h> |
| 19 | #include <linux/vmalloc.h> |
| 20 | #include <linux/interrupt.h> |
| 21 | #include <linux/pci.h> |
| 22 | #include <linux/netdevice.h> |
| 23 | #include <linux/etherdevice.h> |
| 24 | #include <linux/skbuff.h> |
| 25 | #include <linux/dma-mapping.h> |
| 26 | #include <linux/bitops.h> |
| 27 | #include <linux/io.h> |
| 28 | #include <linux/irq.h> |
| 29 | #include <linux/delay.h> |
| 30 | #include <asm/byteorder.h> |
| 31 | #include <asm/page.h> |
| 32 | #include <linux/time.h> |
| 33 | #include <linux/mii.h> |
| 34 | #include <linux/if.h> |
| 35 | #include <linux/if_vlan.h> |
Michael Chan | 32e8239c | 2017-07-24 12:34:21 -0400 | [diff] [blame] | 36 | #include <linux/if_bridge.h> |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 37 | #include <linux/rtc.h> |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 38 | #include <linux/bpf.h> |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 39 | #include <net/ip.h> |
| 40 | #include <net/tcp.h> |
| 41 | #include <net/udp.h> |
| 42 | #include <net/checksum.h> |
| 43 | #include <net/ip6_checksum.h> |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 44 | #include <net/udp_tunnel.h> |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 45 | #include <linux/workqueue.h> |
| 46 | #include <linux/prefetch.h> |
| 47 | #include <linux/cache.h> |
| 48 | #include <linux/log2.h> |
| 49 | #include <linux/aer.h> |
| 50 | #include <linux/bitmap.h> |
| 51 | #include <linux/cpu_rmap.h> |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 52 | #include <linux/cpumask.h> |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 53 | #include <net/pkt_cls.h> |
Vasundhara Volam | cde49a4 | 2018-08-05 16:51:56 -0400 | [diff] [blame] | 54 | #include <linux/hwmon.h> |
| 55 | #include <linux/hwmon-sysfs.h> |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 56 | |
| 57 | #include "bnxt_hsi.h" |
| 58 | #include "bnxt.h" |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 59 | #include "bnxt_ulp.h" |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 60 | #include "bnxt_sriov.h" |
| 61 | #include "bnxt_ethtool.h" |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 62 | #include "bnxt_dcb.h" |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 63 | #include "bnxt_xdp.h" |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 64 | #include "bnxt_vfr.h" |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 65 | #include "bnxt_tc.h" |
Steve Lin | 3c467bf | 2017-10-19 10:45:56 -0400 | [diff] [blame] | 66 | #include "bnxt_devlink.h" |
Andy Gospodarek | cabfb09 | 2018-04-26 17:44:40 -0400 | [diff] [blame] | 67 | #include "bnxt_debugfs.h" |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 68 | |
| 69 | #define BNXT_TX_TIMEOUT (5 * HZ) |
| 70 | |
| 71 | static const char version[] = |
| 72 | "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n"; |
| 73 | |
| 74 | MODULE_LICENSE("GPL"); |
| 75 | MODULE_DESCRIPTION("Broadcom BCM573xx network driver"); |
| 76 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 77 | |
| 78 | #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN) |
| 79 | #define BNXT_RX_DMA_OFFSET NET_SKB_PAD |
| 80 | #define BNXT_RX_COPY_THRESH 256 |
| 81 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 82 | #define BNXT_TX_PUSH_THRESH 164 |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 83 | |
| 84 | enum board_idx { |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 85 | BCM57301, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 86 | BCM57302, |
| 87 | BCM57304, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 88 | BCM57417_NPAR, |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 89 | BCM58700, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 90 | BCM57311, |
| 91 | BCM57312, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 92 | BCM57402, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 93 | BCM57404, |
| 94 | BCM57406, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 95 | BCM57402_NPAR, |
| 96 | BCM57407, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 97 | BCM57412, |
| 98 | BCM57414, |
| 99 | BCM57416, |
| 100 | BCM57417, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 101 | BCM57412_NPAR, |
Michael Chan | 5049e33 | 2016-05-15 03:04:50 -0400 | [diff] [blame] | 102 | BCM57314, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 103 | BCM57417_SFP, |
| 104 | BCM57416_SFP, |
| 105 | BCM57404_NPAR, |
| 106 | BCM57406_NPAR, |
| 107 | BCM57407_SFP, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 108 | BCM57407_NPAR, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 109 | BCM57414_NPAR, |
| 110 | BCM57416_NPAR, |
Deepak Khungar | 32b4079 | 2017-02-12 19:18:18 -0500 | [diff] [blame] | 111 | BCM57452, |
| 112 | BCM57454, |
Vasundhara Volam | 92abef3 | 2018-01-17 03:21:13 -0500 | [diff] [blame] | 113 | BCM5745x_NPAR, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 114 | BCM58802, |
Ray Jui | 8ed693b | 2017-10-26 11:51:20 -0400 | [diff] [blame] | 115 | BCM58804, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 116 | BCM58808, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 117 | NETXTREME_E_VF, |
| 118 | NETXTREME_C_VF, |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 119 | NETXTREME_S_VF, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /* indexed by enum above */ |
| 123 | static const struct { |
| 124 | char *name; |
| 125 | } board_info[] = { |
Scott Branden | 27573a7 | 2017-08-28 13:40:29 -0400 | [diff] [blame] | 126 | [BCM57301] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" }, |
| 127 | [BCM57302] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" }, |
| 128 | [BCM57304] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 129 | [BCM57417_NPAR] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" }, |
| 130 | [BCM58700] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" }, |
| 131 | [BCM57311] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" }, |
| 132 | [BCM57312] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" }, |
| 133 | [BCM57402] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" }, |
| 134 | [BCM57404] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 135 | [BCM57406] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" }, |
| 136 | [BCM57402_NPAR] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" }, |
| 137 | [BCM57407] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" }, |
| 138 | [BCM57412] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" }, |
| 139 | [BCM57414] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 140 | [BCM57416] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" }, |
| 141 | [BCM57417] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" }, |
| 142 | [BCM57412_NPAR] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" }, |
| 143 | [BCM57314] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 144 | [BCM57417_SFP] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 145 | [BCM57416_SFP] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" }, |
| 146 | [BCM57404_NPAR] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" }, |
| 147 | [BCM57406_NPAR] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" }, |
| 148 | [BCM57407_SFP] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" }, |
| 149 | [BCM57407_NPAR] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" }, |
| 150 | [BCM57414_NPAR] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" }, |
| 151 | [BCM57416_NPAR] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" }, |
| 152 | [BCM57452] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 153 | [BCM57454] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" }, |
Vasundhara Volam | 92abef3 | 2018-01-17 03:21:13 -0500 | [diff] [blame] | 154 | [BCM5745x_NPAR] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" }, |
Scott Branden | 27573a7 | 2017-08-28 13:40:29 -0400 | [diff] [blame] | 155 | [BCM58802] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
Ray Jui | 8ed693b | 2017-10-26 11:51:20 -0400 | [diff] [blame] | 156 | [BCM58804] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" }, |
Scott Branden | 27573a7 | 2017-08-28 13:40:29 -0400 | [diff] [blame] | 157 | [BCM58808] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" }, |
| 158 | [NETXTREME_E_VF] = { "Broadcom NetXtreme-E Ethernet Virtual Function" }, |
| 159 | [NETXTREME_C_VF] = { "Broadcom NetXtreme-C Ethernet Virtual Function" }, |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 160 | [NETXTREME_S_VF] = { "Broadcom NetXtreme-S Ethernet Virtual Function" }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 161 | }; |
| 162 | |
| 163 | static const struct pci_device_id bnxt_pci_tbl[] = { |
Vasundhara Volam | 92abef3 | 2018-01-17 03:21:13 -0500 | [diff] [blame] | 164 | { PCI_VDEVICE(BROADCOM, 0x1604), .driver_data = BCM5745x_NPAR }, |
| 165 | { PCI_VDEVICE(BROADCOM, 0x1605), .driver_data = BCM5745x_NPAR }, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 166 | { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 167 | { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR }, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 168 | { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 169 | { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 }, |
| 170 | { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 171 | { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR }, |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 172 | { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 }, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 173 | { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 }, |
| 174 | { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 }, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 175 | { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 176 | { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 }, |
| 177 | { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 178 | { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR }, |
| 179 | { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 }, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 180 | { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 }, |
| 181 | { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 }, |
| 182 | { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 }, |
| 183 | { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 184 | { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR }, |
Michael Chan | 5049e33 | 2016-05-15 03:04:50 -0400 | [diff] [blame] | 185 | { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 186 | { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP }, |
| 187 | { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP }, |
| 188 | { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR }, |
| 189 | { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR }, |
| 190 | { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 191 | { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR }, |
| 192 | { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 193 | { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 194 | { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 195 | { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 196 | { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR }, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 197 | { PCI_VDEVICE(BROADCOM, 0x16f0), .driver_data = BCM58808 }, |
Deepak Khungar | 32b4079 | 2017-02-12 19:18:18 -0500 | [diff] [blame] | 198 | { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 }, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 199 | { PCI_VDEVICE(BROADCOM, 0xd802), .driver_data = BCM58802 }, |
Ray Jui | 8ed693b | 2017-10-26 11:51:20 -0400 | [diff] [blame] | 200 | { PCI_VDEVICE(BROADCOM, 0xd804), .driver_data = BCM58804 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 201 | #ifdef CONFIG_BNXT_SRIOV |
Deepak Khungar | c7ef35e | 2017-05-29 19:06:05 -0400 | [diff] [blame] | 202 | { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF }, |
| 203 | { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 204 | { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF }, |
| 205 | { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF }, |
| 206 | { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF }, |
| 207 | { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF }, |
| 208 | { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF }, |
| 209 | { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF }, |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 210 | { PCI_VDEVICE(BROADCOM, 0xd800), .driver_data = NETXTREME_S_VF }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 211 | #endif |
| 212 | { 0 } |
| 213 | }; |
| 214 | |
| 215 | MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl); |
| 216 | |
| 217 | static const u16 bnxt_vf_req_snif[] = { |
| 218 | HWRM_FUNC_CFG, |
Vasundhara Volam | 91cdda4 | 2018-01-17 03:21:14 -0500 | [diff] [blame] | 219 | HWRM_FUNC_VF_CFG, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 220 | HWRM_PORT_PHY_QCFG, |
| 221 | HWRM_CFA_L2_FILTER_ALLOC, |
| 222 | }; |
| 223 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 224 | static const u16 bnxt_async_events_arr[] = { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 225 | ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE, |
| 226 | ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD, |
| 227 | ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED, |
| 228 | ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE, |
| 229 | ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE, |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 230 | }; |
| 231 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 232 | static struct workqueue_struct *bnxt_pf_wq; |
| 233 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 234 | static bool bnxt_vf_pciid(enum board_idx idx) |
| 235 | { |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 236 | return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF || |
| 237 | idx == NETXTREME_S_VF); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID) |
| 241 | #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS) |
| 242 | #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS) |
| 243 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 244 | #define BNXT_CP_DB_IRQ_DIS(db) \ |
| 245 | writel(DB_CP_IRQ_DIS_FLAGS, db) |
| 246 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 247 | #define BNXT_DB_CQ(db, idx) \ |
| 248 | writel(DB_CP_FLAGS | RING_CMP(idx), (db)->doorbell) |
| 249 | |
| 250 | #define BNXT_DB_NQ_P5(db, idx) \ |
| 251 | writeq((db)->db_key64 | DBR_TYPE_NQ | RING_CMP(idx), (db)->doorbell) |
| 252 | |
| 253 | #define BNXT_DB_CQ_ARM(db, idx) \ |
| 254 | writel(DB_CP_REARM_FLAGS | RING_CMP(idx), (db)->doorbell) |
| 255 | |
| 256 | #define BNXT_DB_NQ_ARM_P5(db, idx) \ |
| 257 | writeq((db)->db_key64 | DBR_TYPE_NQ_ARM | RING_CMP(idx), (db)->doorbell) |
| 258 | |
| 259 | static void bnxt_db_nq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx) |
| 260 | { |
| 261 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 262 | BNXT_DB_NQ_P5(db, idx); |
| 263 | else |
| 264 | BNXT_DB_CQ(db, idx); |
| 265 | } |
| 266 | |
| 267 | static void bnxt_db_nq_arm(struct bnxt *bp, struct bnxt_db_info *db, u32 idx) |
| 268 | { |
| 269 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 270 | BNXT_DB_NQ_ARM_P5(db, idx); |
| 271 | else |
| 272 | BNXT_DB_CQ_ARM(db, idx); |
| 273 | } |
| 274 | |
| 275 | static void bnxt_db_cq(struct bnxt *bp, struct bnxt_db_info *db, u32 idx) |
| 276 | { |
| 277 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 278 | writeq(db->db_key64 | DBR_TYPE_CQ_ARMALL | RING_CMP(idx), |
| 279 | db->doorbell); |
| 280 | else |
| 281 | BNXT_DB_CQ(db, idx); |
| 282 | } |
| 283 | |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 284 | const u16 bnxt_lhint_arr[] = { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 285 | TX_BD_FLAGS_LHINT_512_AND_SMALLER, |
| 286 | TX_BD_FLAGS_LHINT_512_TO_1023, |
| 287 | TX_BD_FLAGS_LHINT_1024_TO_2047, |
| 288 | TX_BD_FLAGS_LHINT_1024_TO_2047, |
| 289 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 290 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 291 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 292 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 293 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 294 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 295 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 296 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 297 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 298 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 299 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 300 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 301 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 302 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 303 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 304 | }; |
| 305 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 306 | static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb) |
| 307 | { |
| 308 | struct metadata_dst *md_dst = skb_metadata_dst(skb); |
| 309 | |
| 310 | if (!md_dst || md_dst->type != METADATA_HW_PORT_MUX) |
| 311 | return 0; |
| 312 | |
| 313 | return md_dst->u.port_info.port_id; |
| 314 | } |
| 315 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 316 | static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 317 | { |
| 318 | struct bnxt *bp = netdev_priv(dev); |
| 319 | struct tx_bd *txbd; |
| 320 | struct tx_bd_ext *txbd1; |
| 321 | struct netdev_queue *txq; |
| 322 | int i; |
| 323 | dma_addr_t mapping; |
| 324 | unsigned int length, pad = 0; |
| 325 | u32 len, free_size, vlan_tag_flags, cfa_action, flags; |
| 326 | u16 prod, last_frag; |
| 327 | struct pci_dev *pdev = bp->pdev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 328 | struct bnxt_tx_ring_info *txr; |
| 329 | struct bnxt_sw_tx_bd *tx_buf; |
| 330 | |
| 331 | i = skb_get_queue_mapping(skb); |
| 332 | if (unlikely(i >= bp->tx_nr_rings)) { |
| 333 | dev_kfree_skb_any(skb); |
| 334 | return NETDEV_TX_OK; |
| 335 | } |
| 336 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 337 | txq = netdev_get_tx_queue(dev, i); |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 338 | txr = &bp->tx_ring[bp->tx_ring_map[i]]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 339 | prod = txr->tx_prod; |
| 340 | |
| 341 | free_size = bnxt_tx_avail(bp, txr); |
| 342 | if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) { |
| 343 | netif_tx_stop_queue(txq); |
| 344 | return NETDEV_TX_BUSY; |
| 345 | } |
| 346 | |
| 347 | length = skb->len; |
| 348 | len = skb_headlen(skb); |
| 349 | last_frag = skb_shinfo(skb)->nr_frags; |
| 350 | |
| 351 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 352 | |
| 353 | txbd->tx_bd_opaque = prod; |
| 354 | |
| 355 | tx_buf = &txr->tx_buf_ring[prod]; |
| 356 | tx_buf->skb = skb; |
| 357 | tx_buf->nr_frags = last_frag; |
| 358 | |
| 359 | vlan_tag_flags = 0; |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 360 | cfa_action = bnxt_xmit_get_cfa_action(skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 361 | if (skb_vlan_tag_present(skb)) { |
| 362 | vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN | |
| 363 | skb_vlan_tag_get(skb); |
| 364 | /* Currently supports 8021Q, 8021AD vlan offloads |
| 365 | * QINQ1, QINQ2, QINQ3 vlan headers are deprecated |
| 366 | */ |
| 367 | if (skb->vlan_proto == htons(ETH_P_8021Q)) |
| 368 | vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT; |
| 369 | } |
| 370 | |
| 371 | if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) { |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 372 | struct tx_push_buffer *tx_push_buf = txr->tx_push; |
| 373 | struct tx_push_bd *tx_push = &tx_push_buf->push_bd; |
| 374 | struct tx_bd_ext *tx_push1 = &tx_push->txbd2; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 375 | void __iomem *db = txr->tx_db.doorbell; |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 376 | void *pdata = tx_push_buf->data; |
| 377 | u64 *end; |
| 378 | int j, push_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 379 | |
| 380 | /* Set COAL_NOW to be ready quickly for the next push */ |
| 381 | tx_push->tx_bd_len_flags_type = |
| 382 | cpu_to_le32((length << TX_BD_LEN_SHIFT) | |
| 383 | TX_BD_TYPE_LONG_TX_BD | |
| 384 | TX_BD_FLAGS_LHINT_512_AND_SMALLER | |
| 385 | TX_BD_FLAGS_COAL_NOW | |
| 386 | TX_BD_FLAGS_PACKET_END | |
| 387 | (2 << TX_BD_FLAGS_BD_CNT_SHIFT)); |
| 388 | |
| 389 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 390 | tx_push1->tx_bd_hsize_lflags = |
| 391 | cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM); |
| 392 | else |
| 393 | tx_push1->tx_bd_hsize_lflags = 0; |
| 394 | |
| 395 | tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags); |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 396 | tx_push1->tx_bd_cfa_action = |
| 397 | cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 398 | |
Michael Chan | fbb0fa8 | 2016-02-22 02:10:26 -0500 | [diff] [blame] | 399 | end = pdata + length; |
| 400 | end = PTR_ALIGN(end, 8) - 1; |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 401 | *end = 0; |
| 402 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 403 | skb_copy_from_linear_data(skb, pdata, len); |
| 404 | pdata += len; |
| 405 | for (j = 0; j < last_frag; j++) { |
| 406 | skb_frag_t *frag = &skb_shinfo(skb)->frags[j]; |
| 407 | void *fptr; |
| 408 | |
| 409 | fptr = skb_frag_address_safe(frag); |
| 410 | if (!fptr) |
| 411 | goto normal_tx; |
| 412 | |
| 413 | memcpy(pdata, fptr, skb_frag_size(frag)); |
| 414 | pdata += skb_frag_size(frag); |
| 415 | } |
| 416 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 417 | txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type; |
| 418 | txbd->tx_bd_haddr = txr->data_mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 419 | prod = NEXT_TX(prod); |
| 420 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 421 | memcpy(txbd, tx_push1, sizeof(*txbd)); |
| 422 | prod = NEXT_TX(prod); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 423 | tx_push->doorbell = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 424 | cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod); |
| 425 | txr->tx_prod = prod; |
| 426 | |
Michael Chan | b9a8460 | 2016-06-06 02:37:14 -0400 | [diff] [blame] | 427 | tx_buf->is_push = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 428 | netdev_tx_sent_queue(txq, skb->len); |
Michael Chan | b9a8460 | 2016-06-06 02:37:14 -0400 | [diff] [blame] | 429 | wmb(); /* Sync is_push and byte queue before pushing data */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 430 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 431 | push_len = (length + sizeof(*tx_push) + 7) / 8; |
| 432 | if (push_len > 16) { |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 433 | __iowrite64_copy(db, tx_push_buf, 16); |
| 434 | __iowrite32_copy(db + 4, tx_push_buf + 1, |
Michael Chan | 9d13744 | 2016-09-05 01:57:35 -0400 | [diff] [blame] | 435 | (push_len - 16) << 1); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 436 | } else { |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 437 | __iowrite64_copy(db, tx_push_buf, push_len); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 438 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 439 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 440 | goto tx_done; |
| 441 | } |
| 442 | |
| 443 | normal_tx: |
| 444 | if (length < BNXT_MIN_PKT_SIZE) { |
| 445 | pad = BNXT_MIN_PKT_SIZE - length; |
| 446 | if (skb_pad(skb, pad)) { |
| 447 | /* SKB already freed. */ |
| 448 | tx_buf->skb = NULL; |
| 449 | return NETDEV_TX_OK; |
| 450 | } |
| 451 | length = BNXT_MIN_PKT_SIZE; |
| 452 | } |
| 453 | |
| 454 | mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE); |
| 455 | |
| 456 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) { |
| 457 | dev_kfree_skb_any(skb); |
| 458 | tx_buf->skb = NULL; |
| 459 | return NETDEV_TX_OK; |
| 460 | } |
| 461 | |
| 462 | dma_unmap_addr_set(tx_buf, mapping, mapping); |
| 463 | flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD | |
| 464 | ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT); |
| 465 | |
| 466 | txbd->tx_bd_haddr = cpu_to_le64(mapping); |
| 467 | |
| 468 | prod = NEXT_TX(prod); |
| 469 | txbd1 = (struct tx_bd_ext *) |
| 470 | &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 471 | |
| 472 | txbd1->tx_bd_hsize_lflags = 0; |
| 473 | if (skb_is_gso(skb)) { |
| 474 | u32 hdr_len; |
| 475 | |
| 476 | if (skb->encapsulation) |
| 477 | hdr_len = skb_inner_network_offset(skb) + |
| 478 | skb_inner_network_header_len(skb) + |
| 479 | inner_tcp_hdrlen(skb); |
| 480 | else |
| 481 | hdr_len = skb_transport_offset(skb) + |
| 482 | tcp_hdrlen(skb); |
| 483 | |
| 484 | txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO | |
| 485 | TX_BD_FLAGS_T_IPID | |
| 486 | (hdr_len << (TX_BD_HSIZE_SHIFT - 1))); |
| 487 | length = skb_shinfo(skb)->gso_size; |
| 488 | txbd1->tx_bd_mss = cpu_to_le32(length); |
| 489 | length += hdr_len; |
| 490 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 491 | txbd1->tx_bd_hsize_lflags = |
| 492 | cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM); |
| 493 | txbd1->tx_bd_mss = 0; |
| 494 | } |
| 495 | |
| 496 | length >>= 9; |
| 497 | flags |= bnxt_lhint_arr[length]; |
| 498 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); |
| 499 | |
| 500 | txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags); |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 501 | txbd1->tx_bd_cfa_action = |
| 502 | cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 503 | for (i = 0; i < last_frag; i++) { |
| 504 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 505 | |
| 506 | prod = NEXT_TX(prod); |
| 507 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 508 | |
| 509 | len = skb_frag_size(frag); |
| 510 | mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len, |
| 511 | DMA_TO_DEVICE); |
| 512 | |
| 513 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) |
| 514 | goto tx_dma_error; |
| 515 | |
| 516 | tx_buf = &txr->tx_buf_ring[prod]; |
| 517 | dma_unmap_addr_set(tx_buf, mapping, mapping); |
| 518 | |
| 519 | txbd->tx_bd_haddr = cpu_to_le64(mapping); |
| 520 | |
| 521 | flags = len << TX_BD_LEN_SHIFT; |
| 522 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); |
| 523 | } |
| 524 | |
| 525 | flags &= ~TX_BD_LEN; |
| 526 | txbd->tx_bd_len_flags_type = |
| 527 | cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags | |
| 528 | TX_BD_FLAGS_PACKET_END); |
| 529 | |
| 530 | netdev_tx_sent_queue(txq, skb->len); |
| 531 | |
| 532 | /* Sync BD data before updating doorbell */ |
| 533 | wmb(); |
| 534 | |
| 535 | prod = NEXT_TX(prod); |
| 536 | txr->tx_prod = prod; |
| 537 | |
Michael Chan | ffe4064 | 2017-05-30 20:03:00 -0400 | [diff] [blame] | 538 | if (!skb->xmit_more || netif_xmit_stopped(txq)) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 539 | bnxt_db_write(bp, &txr->tx_db, prod); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 540 | |
| 541 | tx_done: |
| 542 | |
| 543 | mmiowb(); |
| 544 | |
| 545 | if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) { |
Michael Chan | 4d172f2 | 2017-05-29 19:06:09 -0400 | [diff] [blame] | 546 | if (skb->xmit_more && !tx_buf->is_push) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 547 | bnxt_db_write(bp, &txr->tx_db, prod); |
Michael Chan | 4d172f2 | 2017-05-29 19:06:09 -0400 | [diff] [blame] | 548 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 549 | netif_tx_stop_queue(txq); |
| 550 | |
| 551 | /* netif_tx_stop_queue() must be done before checking |
| 552 | * tx index in bnxt_tx_avail() below, because in |
| 553 | * bnxt_tx_int(), we update tx index before checking for |
| 554 | * netif_tx_queue_stopped(). |
| 555 | */ |
| 556 | smp_mb(); |
| 557 | if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh) |
| 558 | netif_tx_wake_queue(txq); |
| 559 | } |
| 560 | return NETDEV_TX_OK; |
| 561 | |
| 562 | tx_dma_error: |
| 563 | last_frag = i; |
| 564 | |
| 565 | /* start back at beginning and unmap skb */ |
| 566 | prod = txr->tx_prod; |
| 567 | tx_buf = &txr->tx_buf_ring[prod]; |
| 568 | tx_buf->skb = NULL; |
| 569 | dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 570 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 571 | prod = NEXT_TX(prod); |
| 572 | |
| 573 | /* unmap remaining mapped pages */ |
| 574 | for (i = 0; i < last_frag; i++) { |
| 575 | prod = NEXT_TX(prod); |
| 576 | tx_buf = &txr->tx_buf_ring[prod]; |
| 577 | dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 578 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
| 579 | PCI_DMA_TODEVICE); |
| 580 | } |
| 581 | |
| 582 | dev_kfree_skb_any(skb); |
| 583 | return NETDEV_TX_OK; |
| 584 | } |
| 585 | |
| 586 | static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) |
| 587 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 588 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 589 | struct netdev_queue *txq = netdev_get_tx_queue(bp->dev, txr->txq_index); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 590 | u16 cons = txr->tx_cons; |
| 591 | struct pci_dev *pdev = bp->pdev; |
| 592 | int i; |
| 593 | unsigned int tx_bytes = 0; |
| 594 | |
| 595 | for (i = 0; i < nr_pkts; i++) { |
| 596 | struct bnxt_sw_tx_bd *tx_buf; |
| 597 | struct sk_buff *skb; |
| 598 | int j, last; |
| 599 | |
| 600 | tx_buf = &txr->tx_buf_ring[cons]; |
| 601 | cons = NEXT_TX(cons); |
| 602 | skb = tx_buf->skb; |
| 603 | tx_buf->skb = NULL; |
| 604 | |
| 605 | if (tx_buf->is_push) { |
| 606 | tx_buf->is_push = 0; |
| 607 | goto next_tx_int; |
| 608 | } |
| 609 | |
| 610 | dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 611 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 612 | last = tx_buf->nr_frags; |
| 613 | |
| 614 | for (j = 0; j < last; j++) { |
| 615 | cons = NEXT_TX(cons); |
| 616 | tx_buf = &txr->tx_buf_ring[cons]; |
| 617 | dma_unmap_page( |
| 618 | &pdev->dev, |
| 619 | dma_unmap_addr(tx_buf, mapping), |
| 620 | skb_frag_size(&skb_shinfo(skb)->frags[j]), |
| 621 | PCI_DMA_TODEVICE); |
| 622 | } |
| 623 | |
| 624 | next_tx_int: |
| 625 | cons = NEXT_TX(cons); |
| 626 | |
| 627 | tx_bytes += skb->len; |
| 628 | dev_kfree_skb_any(skb); |
| 629 | } |
| 630 | |
| 631 | netdev_tx_completed_queue(txq, nr_pkts, tx_bytes); |
| 632 | txr->tx_cons = cons; |
| 633 | |
| 634 | /* Need to make the tx_cons update visible to bnxt_start_xmit() |
| 635 | * before checking for netif_tx_queue_stopped(). Without the |
| 636 | * memory barrier, there is a small possibility that bnxt_start_xmit() |
| 637 | * will miss it and cause the queue to be stopped forever. |
| 638 | */ |
| 639 | smp_mb(); |
| 640 | |
| 641 | if (unlikely(netif_tx_queue_stopped(txq)) && |
| 642 | (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) { |
| 643 | __netif_tx_lock(txq, smp_processor_id()); |
| 644 | if (netif_tx_queue_stopped(txq) && |
| 645 | bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh && |
| 646 | txr->dev_state != BNXT_DEV_STATE_CLOSING) |
| 647 | netif_tx_wake_queue(txq); |
| 648 | __netif_tx_unlock(txq); |
| 649 | } |
| 650 | } |
| 651 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 652 | static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping, |
| 653 | gfp_t gfp) |
| 654 | { |
| 655 | struct device *dev = &bp->pdev->dev; |
| 656 | struct page *page; |
| 657 | |
| 658 | page = alloc_page(gfp); |
| 659 | if (!page) |
| 660 | return NULL; |
| 661 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 662 | *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir, |
| 663 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 664 | if (dma_mapping_error(dev, *mapping)) { |
| 665 | __free_page(page); |
| 666 | return NULL; |
| 667 | } |
| 668 | *mapping += bp->rx_dma_offset; |
| 669 | return page; |
| 670 | } |
| 671 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 672 | static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping, |
| 673 | gfp_t gfp) |
| 674 | { |
| 675 | u8 *data; |
| 676 | struct pci_dev *pdev = bp->pdev; |
| 677 | |
| 678 | data = kmalloc(bp->rx_buf_size, gfp); |
| 679 | if (!data) |
| 680 | return NULL; |
| 681 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 682 | *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset, |
| 683 | bp->rx_buf_use_size, bp->rx_dir, |
| 684 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 685 | |
| 686 | if (dma_mapping_error(&pdev->dev, *mapping)) { |
| 687 | kfree(data); |
| 688 | data = NULL; |
| 689 | } |
| 690 | return data; |
| 691 | } |
| 692 | |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 693 | int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, |
| 694 | u16 prod, gfp_t gfp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 695 | { |
| 696 | struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 697 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 698 | dma_addr_t mapping; |
| 699 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 700 | if (BNXT_RX_PAGE_MODE(bp)) { |
| 701 | struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 702 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 703 | if (!page) |
| 704 | return -ENOMEM; |
| 705 | |
| 706 | rx_buf->data = page; |
| 707 | rx_buf->data_ptr = page_address(page) + bp->rx_offset; |
| 708 | } else { |
| 709 | u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp); |
| 710 | |
| 711 | if (!data) |
| 712 | return -ENOMEM; |
| 713 | |
| 714 | rx_buf->data = data; |
| 715 | rx_buf->data_ptr = data + bp->rx_offset; |
| 716 | } |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 717 | rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 718 | |
| 719 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 720 | return 0; |
| 721 | } |
| 722 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 723 | void bnxt_reuse_rx_data(struct bnxt_rx_ring_info *rxr, u16 cons, void *data) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 724 | { |
| 725 | u16 prod = rxr->rx_prod; |
| 726 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 727 | struct rx_bd *cons_bd, *prod_bd; |
| 728 | |
| 729 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 730 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 731 | |
| 732 | prod_rx_buf->data = data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 733 | prod_rx_buf->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 734 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 735 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 736 | |
| 737 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 738 | cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)]; |
| 739 | |
| 740 | prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr; |
| 741 | } |
| 742 | |
| 743 | static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx) |
| 744 | { |
| 745 | u16 next, max = rxr->rx_agg_bmap_size; |
| 746 | |
| 747 | next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx); |
| 748 | if (next >= max) |
| 749 | next = find_first_zero_bit(rxr->rx_agg_bmap, max); |
| 750 | return next; |
| 751 | } |
| 752 | |
| 753 | static inline int bnxt_alloc_rx_page(struct bnxt *bp, |
| 754 | struct bnxt_rx_ring_info *rxr, |
| 755 | u16 prod, gfp_t gfp) |
| 756 | { |
| 757 | struct rx_bd *rxbd = |
| 758 | &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 759 | struct bnxt_sw_rx_agg_bd *rx_agg_buf; |
| 760 | struct pci_dev *pdev = bp->pdev; |
| 761 | struct page *page; |
| 762 | dma_addr_t mapping; |
| 763 | u16 sw_prod = rxr->rx_sw_agg_prod; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 764 | unsigned int offset = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 765 | |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 766 | if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) { |
| 767 | page = rxr->rx_page; |
| 768 | if (!page) { |
| 769 | page = alloc_page(gfp); |
| 770 | if (!page) |
| 771 | return -ENOMEM; |
| 772 | rxr->rx_page = page; |
| 773 | rxr->rx_page_offset = 0; |
| 774 | } |
| 775 | offset = rxr->rx_page_offset; |
| 776 | rxr->rx_page_offset += BNXT_RX_PAGE_SIZE; |
| 777 | if (rxr->rx_page_offset == PAGE_SIZE) |
| 778 | rxr->rx_page = NULL; |
| 779 | else |
| 780 | get_page(page); |
| 781 | } else { |
| 782 | page = alloc_page(gfp); |
| 783 | if (!page) |
| 784 | return -ENOMEM; |
| 785 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 786 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 787 | mapping = dma_map_page_attrs(&pdev->dev, page, offset, |
| 788 | BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE, |
| 789 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 790 | if (dma_mapping_error(&pdev->dev, mapping)) { |
| 791 | __free_page(page); |
| 792 | return -EIO; |
| 793 | } |
| 794 | |
| 795 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 796 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 797 | |
| 798 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 799 | rx_agg_buf = &rxr->rx_agg_ring[sw_prod]; |
| 800 | rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod); |
| 801 | |
| 802 | rx_agg_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 803 | rx_agg_buf->offset = offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 804 | rx_agg_buf->mapping = mapping; |
| 805 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
| 806 | rxbd->rx_bd_opaque = sw_prod; |
| 807 | return 0; |
| 808 | } |
| 809 | |
| 810 | static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons, |
| 811 | u32 agg_bufs) |
| 812 | { |
| 813 | struct bnxt *bp = bnapi->bp; |
| 814 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 815 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 816 | u16 prod = rxr->rx_agg_prod; |
| 817 | u16 sw_prod = rxr->rx_sw_agg_prod; |
| 818 | u32 i; |
| 819 | |
| 820 | for (i = 0; i < agg_bufs; i++) { |
| 821 | u16 cons; |
| 822 | struct rx_agg_cmp *agg; |
| 823 | struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf; |
| 824 | struct rx_bd *prod_bd; |
| 825 | struct page *page; |
| 826 | |
| 827 | agg = (struct rx_agg_cmp *) |
| 828 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 829 | cons = agg->rx_agg_cmp_opaque; |
| 830 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 831 | |
| 832 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 833 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 834 | |
| 835 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 836 | prod_rx_buf = &rxr->rx_agg_ring[sw_prod]; |
| 837 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
| 838 | |
| 839 | /* It is possible for sw_prod to be equal to cons, so |
| 840 | * set cons_rx_buf->page to NULL first. |
| 841 | */ |
| 842 | page = cons_rx_buf->page; |
| 843 | cons_rx_buf->page = NULL; |
| 844 | prod_rx_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 845 | prod_rx_buf->offset = cons_rx_buf->offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 846 | |
| 847 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
| 848 | |
| 849 | prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 850 | |
| 851 | prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping); |
| 852 | prod_bd->rx_bd_opaque = sw_prod; |
| 853 | |
| 854 | prod = NEXT_RX_AGG(prod); |
| 855 | sw_prod = NEXT_RX_AGG(sw_prod); |
| 856 | cp_cons = NEXT_CMP(cp_cons); |
| 857 | } |
| 858 | rxr->rx_agg_prod = prod; |
| 859 | rxr->rx_sw_agg_prod = sw_prod; |
| 860 | } |
| 861 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 862 | static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp, |
| 863 | struct bnxt_rx_ring_info *rxr, |
| 864 | u16 cons, void *data, u8 *data_ptr, |
| 865 | dma_addr_t dma_addr, |
| 866 | unsigned int offset_and_len) |
| 867 | { |
| 868 | unsigned int payload = offset_and_len >> 16; |
| 869 | unsigned int len = offset_and_len & 0xffff; |
| 870 | struct skb_frag_struct *frag; |
| 871 | struct page *page = data; |
| 872 | u16 prod = rxr->rx_prod; |
| 873 | struct sk_buff *skb; |
| 874 | int off, err; |
| 875 | |
| 876 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 877 | if (unlikely(err)) { |
| 878 | bnxt_reuse_rx_data(rxr, cons, data); |
| 879 | return NULL; |
| 880 | } |
| 881 | dma_addr -= bp->rx_dma_offset; |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 882 | dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir, |
| 883 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 884 | |
| 885 | if (unlikely(!payload)) |
| 886 | payload = eth_get_headlen(data_ptr, len); |
| 887 | |
| 888 | skb = napi_alloc_skb(&rxr->bnapi->napi, payload); |
| 889 | if (!skb) { |
| 890 | __free_page(page); |
| 891 | return NULL; |
| 892 | } |
| 893 | |
| 894 | off = (void *)data_ptr - page_address(page); |
| 895 | skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE); |
| 896 | memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN, |
| 897 | payload + NET_IP_ALIGN); |
| 898 | |
| 899 | frag = &skb_shinfo(skb)->frags[0]; |
| 900 | skb_frag_size_sub(frag, payload); |
| 901 | frag->page_offset += payload; |
| 902 | skb->data_len -= payload; |
| 903 | skb->tail += payload; |
| 904 | |
| 905 | return skb; |
| 906 | } |
| 907 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 908 | static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, |
| 909 | struct bnxt_rx_ring_info *rxr, u16 cons, |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 910 | void *data, u8 *data_ptr, |
| 911 | dma_addr_t dma_addr, |
| 912 | unsigned int offset_and_len) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 913 | { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 914 | u16 prod = rxr->rx_prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 915 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 916 | int err; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 917 | |
| 918 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 919 | if (unlikely(err)) { |
| 920 | bnxt_reuse_rx_data(rxr, cons, data); |
| 921 | return NULL; |
| 922 | } |
| 923 | |
| 924 | skb = build_skb(data, 0); |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 925 | dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size, |
| 926 | bp->rx_dir, DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 927 | if (!skb) { |
| 928 | kfree(data); |
| 929 | return NULL; |
| 930 | } |
| 931 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 932 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 933 | skb_put(skb, offset_and_len & 0xffff); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 934 | return skb; |
| 935 | } |
| 936 | |
| 937 | static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 938 | struct sk_buff *skb, u16 cp_cons, |
| 939 | u32 agg_bufs) |
| 940 | { |
| 941 | struct pci_dev *pdev = bp->pdev; |
| 942 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 943 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 944 | u16 prod = rxr->rx_agg_prod; |
| 945 | u32 i; |
| 946 | |
| 947 | for (i = 0; i < agg_bufs; i++) { |
| 948 | u16 cons, frag_len; |
| 949 | struct rx_agg_cmp *agg; |
| 950 | struct bnxt_sw_rx_agg_bd *cons_rx_buf; |
| 951 | struct page *page; |
| 952 | dma_addr_t mapping; |
| 953 | |
| 954 | agg = (struct rx_agg_cmp *) |
| 955 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 956 | cons = agg->rx_agg_cmp_opaque; |
| 957 | frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) & |
| 958 | RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT; |
| 959 | |
| 960 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 961 | skb_fill_page_desc(skb, i, cons_rx_buf->page, |
| 962 | cons_rx_buf->offset, frag_len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 963 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 964 | |
| 965 | /* It is possible for bnxt_alloc_rx_page() to allocate |
| 966 | * a sw_prod index that equals the cons index, so we |
| 967 | * need to clear the cons entry now. |
| 968 | */ |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 969 | mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 970 | page = cons_rx_buf->page; |
| 971 | cons_rx_buf->page = NULL; |
| 972 | |
| 973 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) { |
| 974 | struct skb_shared_info *shinfo; |
| 975 | unsigned int nr_frags; |
| 976 | |
| 977 | shinfo = skb_shinfo(skb); |
| 978 | nr_frags = --shinfo->nr_frags; |
| 979 | __skb_frag_set_page(&shinfo->frags[nr_frags], NULL); |
| 980 | |
| 981 | dev_kfree_skb(skb); |
| 982 | |
| 983 | cons_rx_buf->page = page; |
| 984 | |
| 985 | /* Update prod since possibly some pages have been |
| 986 | * allocated already. |
| 987 | */ |
| 988 | rxr->rx_agg_prod = prod; |
| 989 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i); |
| 990 | return NULL; |
| 991 | } |
| 992 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 993 | dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE, |
| 994 | PCI_DMA_FROMDEVICE, |
| 995 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 996 | |
| 997 | skb->data_len += frag_len; |
| 998 | skb->len += frag_len; |
| 999 | skb->truesize += PAGE_SIZE; |
| 1000 | |
| 1001 | prod = NEXT_RX_AGG(prod); |
| 1002 | cp_cons = NEXT_CMP(cp_cons); |
| 1003 | } |
| 1004 | rxr->rx_agg_prod = prod; |
| 1005 | return skb; |
| 1006 | } |
| 1007 | |
| 1008 | static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, |
| 1009 | u8 agg_bufs, u32 *raw_cons) |
| 1010 | { |
| 1011 | u16 last; |
| 1012 | struct rx_agg_cmp *agg; |
| 1013 | |
| 1014 | *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs); |
| 1015 | last = RING_CMP(*raw_cons); |
| 1016 | agg = (struct rx_agg_cmp *) |
| 1017 | &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)]; |
| 1018 | return RX_AGG_CMP_VALID(agg, *raw_cons); |
| 1019 | } |
| 1020 | |
| 1021 | static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, |
| 1022 | unsigned int len, |
| 1023 | dma_addr_t mapping) |
| 1024 | { |
| 1025 | struct bnxt *bp = bnapi->bp; |
| 1026 | struct pci_dev *pdev = bp->pdev; |
| 1027 | struct sk_buff *skb; |
| 1028 | |
| 1029 | skb = napi_alloc_skb(&bnapi->napi, len); |
| 1030 | if (!skb) |
| 1031 | return NULL; |
| 1032 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1033 | dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 1034 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1035 | |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1036 | memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN, |
| 1037 | len + NET_IP_ALIGN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1038 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1039 | dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 1040 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1041 | |
| 1042 | skb_put(skb, len); |
| 1043 | return skb; |
| 1044 | } |
| 1045 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1046 | static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1047 | u32 *raw_cons, void *cmp) |
| 1048 | { |
| 1049 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1050 | struct rx_cmp *rxcmp = cmp; |
| 1051 | u32 tmp_raw_cons = *raw_cons; |
| 1052 | u8 cmp_type, agg_bufs = 0; |
| 1053 | |
| 1054 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1055 | |
| 1056 | if (cmp_type == CMP_TYPE_RX_L2_CMP) { |
| 1057 | agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) & |
| 1058 | RX_CMP_AGG_BUFS) >> |
| 1059 | RX_CMP_AGG_BUFS_SHIFT; |
| 1060 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1061 | struct rx_tpa_end_cmp *tpa_end = cmp; |
| 1062 | |
| 1063 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1064 | RX_TPA_END_CMP_AGG_BUFS) >> |
| 1065 | RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 1066 | } |
| 1067 | |
| 1068 | if (agg_bufs) { |
| 1069 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 1070 | return -EBUSY; |
| 1071 | } |
| 1072 | *raw_cons = tmp_raw_cons; |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1076 | static void bnxt_queue_sp_work(struct bnxt *bp) |
| 1077 | { |
| 1078 | if (BNXT_PF(bp)) |
| 1079 | queue_work(bnxt_pf_wq, &bp->sp_task); |
| 1080 | else |
| 1081 | schedule_work(&bp->sp_task); |
| 1082 | } |
| 1083 | |
| 1084 | static void bnxt_cancel_sp_work(struct bnxt *bp) |
| 1085 | { |
| 1086 | if (BNXT_PF(bp)) |
| 1087 | flush_workqueue(bnxt_pf_wq); |
| 1088 | else |
| 1089 | cancel_work_sync(&bp->sp_task); |
| 1090 | } |
| 1091 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1092 | static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) |
| 1093 | { |
| 1094 | if (!rxr->bnapi->in_reset) { |
| 1095 | rxr->bnapi->in_reset = true; |
| 1096 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1097 | bnxt_queue_sp_work(bp); |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1098 | } |
| 1099 | rxr->rx_next_cons = 0xffff; |
| 1100 | } |
| 1101 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1102 | static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, |
| 1103 | struct rx_tpa_start_cmp *tpa_start, |
| 1104 | struct rx_tpa_start_cmp_ext *tpa_start1) |
| 1105 | { |
| 1106 | u8 agg_id = TPA_START_AGG_ID(tpa_start); |
| 1107 | u16 cons, prod; |
| 1108 | struct bnxt_tpa_info *tpa_info; |
| 1109 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 1110 | struct rx_bd *prod_bd; |
| 1111 | dma_addr_t mapping; |
| 1112 | |
| 1113 | cons = tpa_start->rx_tpa_start_cmp_opaque; |
| 1114 | prod = rxr->rx_prod; |
| 1115 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 1116 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 1117 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1118 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1119 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1120 | bnxt_sched_reset(bp, rxr); |
| 1121 | return; |
| 1122 | } |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1123 | /* Store cfa_code in tpa_info to use in tpa_end |
| 1124 | * completion processing. |
| 1125 | */ |
| 1126 | tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1127 | prod_rx_buf->data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1128 | prod_rx_buf->data_ptr = tpa_info->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1129 | |
| 1130 | mapping = tpa_info->mapping; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1131 | prod_rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1132 | |
| 1133 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 1134 | |
| 1135 | prod_bd->rx_bd_haddr = cpu_to_le64(mapping); |
| 1136 | |
| 1137 | tpa_info->data = cons_rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1138 | tpa_info->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1139 | cons_rx_buf->data = NULL; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1140 | tpa_info->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1141 | |
| 1142 | tpa_info->len = |
| 1143 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >> |
| 1144 | RX_TPA_START_CMP_LEN_SHIFT; |
| 1145 | if (likely(TPA_START_HASH_VALID(tpa_start))) { |
| 1146 | u32 hash_type = TPA_START_HASH_TYPE(tpa_start); |
| 1147 | |
| 1148 | tpa_info->hash_type = PKT_HASH_TYPE_L4; |
| 1149 | tpa_info->gso_type = SKB_GSO_TCPV4; |
| 1150 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
Michael Chan | 50f011b | 2018-08-05 16:51:51 -0400 | [diff] [blame] | 1151 | if (hash_type == 3 || TPA_START_IS_IPV6(tpa_start1)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1152 | tpa_info->gso_type = SKB_GSO_TCPV6; |
| 1153 | tpa_info->rss_hash = |
| 1154 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash); |
| 1155 | } else { |
| 1156 | tpa_info->hash_type = PKT_HASH_TYPE_NONE; |
| 1157 | tpa_info->gso_type = 0; |
| 1158 | if (netif_msg_rx_err(bp)) |
| 1159 | netdev_warn(bp->dev, "TPA packet without valid hash\n"); |
| 1160 | } |
| 1161 | tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2); |
| 1162 | tpa_info->metadata = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_metadata); |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1163 | tpa_info->hdr_info = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_hdr_info); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1164 | |
| 1165 | rxr->rx_prod = NEXT_RX(prod); |
| 1166 | cons = NEXT_RX(cons); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1167 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1168 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 1169 | |
| 1170 | bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data); |
| 1171 | rxr->rx_prod = NEXT_RX(rxr->rx_prod); |
| 1172 | cons_rx_buf->data = NULL; |
| 1173 | } |
| 1174 | |
| 1175 | static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1176 | u16 cp_cons, u32 agg_bufs) |
| 1177 | { |
| 1178 | if (agg_bufs) |
| 1179 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1180 | } |
| 1181 | |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1182 | static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info, |
| 1183 | int payload_off, int tcp_ts, |
| 1184 | struct sk_buff *skb) |
| 1185 | { |
| 1186 | #ifdef CONFIG_INET |
| 1187 | struct tcphdr *th; |
| 1188 | int len, nw_off; |
| 1189 | u16 outer_ip_off, inner_ip_off, inner_mac_off; |
| 1190 | u32 hdr_info = tpa_info->hdr_info; |
| 1191 | bool loopback = false; |
| 1192 | |
| 1193 | inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info); |
| 1194 | inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info); |
| 1195 | outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info); |
| 1196 | |
| 1197 | /* If the packet is an internal loopback packet, the offsets will |
| 1198 | * have an extra 4 bytes. |
| 1199 | */ |
| 1200 | if (inner_mac_off == 4) { |
| 1201 | loopback = true; |
| 1202 | } else if (inner_mac_off > 4) { |
| 1203 | __be16 proto = *((__be16 *)(skb->data + inner_ip_off - |
| 1204 | ETH_HLEN - 2)); |
| 1205 | |
| 1206 | /* We only support inner iPv4/ipv6. If we don't see the |
| 1207 | * correct protocol ID, it must be a loopback packet where |
| 1208 | * the offsets are off by 4. |
| 1209 | */ |
Dan Carpenter | 09a7636 | 2016-07-07 11:23:09 +0300 | [diff] [blame] | 1210 | if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6)) |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1211 | loopback = true; |
| 1212 | } |
| 1213 | if (loopback) { |
| 1214 | /* internal loopback packet, subtract all offsets by 4 */ |
| 1215 | inner_ip_off -= 4; |
| 1216 | inner_mac_off -= 4; |
| 1217 | outer_ip_off -= 4; |
| 1218 | } |
| 1219 | |
| 1220 | nw_off = inner_ip_off - ETH_HLEN; |
| 1221 | skb_set_network_header(skb, nw_off); |
| 1222 | if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) { |
| 1223 | struct ipv6hdr *iph = ipv6_hdr(skb); |
| 1224 | |
| 1225 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1226 | len = skb->len - skb_transport_offset(skb); |
| 1227 | th = tcp_hdr(skb); |
| 1228 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1229 | } else { |
| 1230 | struct iphdr *iph = ip_hdr(skb); |
| 1231 | |
| 1232 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1233 | len = skb->len - skb_transport_offset(skb); |
| 1234 | th = tcp_hdr(skb); |
| 1235 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1236 | } |
| 1237 | |
| 1238 | if (inner_mac_off) { /* tunnel */ |
| 1239 | struct udphdr *uh = NULL; |
| 1240 | __be16 proto = *((__be16 *)(skb->data + outer_ip_off - |
| 1241 | ETH_HLEN - 2)); |
| 1242 | |
| 1243 | if (proto == htons(ETH_P_IP)) { |
| 1244 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1245 | |
| 1246 | if (iph->protocol == IPPROTO_UDP) |
| 1247 | uh = (struct udphdr *)(iph + 1); |
| 1248 | } else { |
| 1249 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1250 | |
| 1251 | if (iph->nexthdr == IPPROTO_UDP) |
| 1252 | uh = (struct udphdr *)(iph + 1); |
| 1253 | } |
| 1254 | if (uh) { |
| 1255 | if (uh->check) |
| 1256 | skb_shinfo(skb)->gso_type |= |
| 1257 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1258 | else |
| 1259 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1260 | } |
| 1261 | } |
| 1262 | #endif |
| 1263 | return skb; |
| 1264 | } |
| 1265 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1266 | #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr)) |
| 1267 | #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr)) |
| 1268 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1269 | static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info, |
| 1270 | int payload_off, int tcp_ts, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1271 | struct sk_buff *skb) |
| 1272 | { |
Michael Chan | d1611c3 | 2015-10-25 22:27:57 -0400 | [diff] [blame] | 1273 | #ifdef CONFIG_INET |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1274 | struct tcphdr *th; |
Michael Chan | 719ca81 | 2017-01-17 22:07:19 -0500 | [diff] [blame] | 1275 | int len, nw_off, tcp_opt_len = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1276 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1277 | if (tcp_ts) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1278 | tcp_opt_len = 12; |
| 1279 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1280 | if (tpa_info->gso_type == SKB_GSO_TCPV4) { |
| 1281 | struct iphdr *iph; |
| 1282 | |
| 1283 | nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len - |
| 1284 | ETH_HLEN; |
| 1285 | skb_set_network_header(skb, nw_off); |
| 1286 | iph = ip_hdr(skb); |
| 1287 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1288 | len = skb->len - skb_transport_offset(skb); |
| 1289 | th = tcp_hdr(skb); |
| 1290 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1291 | } else if (tpa_info->gso_type == SKB_GSO_TCPV6) { |
| 1292 | struct ipv6hdr *iph; |
| 1293 | |
| 1294 | nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len - |
| 1295 | ETH_HLEN; |
| 1296 | skb_set_network_header(skb, nw_off); |
| 1297 | iph = ipv6_hdr(skb); |
| 1298 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1299 | len = skb->len - skb_transport_offset(skb); |
| 1300 | th = tcp_hdr(skb); |
| 1301 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1302 | } else { |
| 1303 | dev_kfree_skb_any(skb); |
| 1304 | return NULL; |
| 1305 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1306 | |
| 1307 | if (nw_off) { /* tunnel */ |
| 1308 | struct udphdr *uh = NULL; |
| 1309 | |
| 1310 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1311 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1312 | |
| 1313 | if (iph->protocol == IPPROTO_UDP) |
| 1314 | uh = (struct udphdr *)(iph + 1); |
| 1315 | } else { |
| 1316 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1317 | |
| 1318 | if (iph->nexthdr == IPPROTO_UDP) |
| 1319 | uh = (struct udphdr *)(iph + 1); |
| 1320 | } |
| 1321 | if (uh) { |
| 1322 | if (uh->check) |
| 1323 | skb_shinfo(skb)->gso_type |= |
| 1324 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1325 | else |
| 1326 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1327 | } |
| 1328 | } |
| 1329 | #endif |
| 1330 | return skb; |
| 1331 | } |
| 1332 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1333 | static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp, |
| 1334 | struct bnxt_tpa_info *tpa_info, |
| 1335 | struct rx_tpa_end_cmp *tpa_end, |
| 1336 | struct rx_tpa_end_cmp_ext *tpa_end1, |
| 1337 | struct sk_buff *skb) |
| 1338 | { |
| 1339 | #ifdef CONFIG_INET |
| 1340 | int payload_off; |
| 1341 | u16 segs; |
| 1342 | |
| 1343 | segs = TPA_END_TPA_SEGS(tpa_end); |
| 1344 | if (segs == 1) |
| 1345 | return skb; |
| 1346 | |
| 1347 | NAPI_GRO_CB(skb)->count = segs; |
| 1348 | skb_shinfo(skb)->gso_size = |
| 1349 | le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len); |
| 1350 | skb_shinfo(skb)->gso_type = tpa_info->gso_type; |
| 1351 | payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1352 | RX_TPA_END_CMP_PAYLOAD_OFFSET) >> |
| 1353 | RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT; |
| 1354 | skb = bp->gro_func(tpa_info, payload_off, TPA_END_GRO_TS(tpa_end), skb); |
Michael Chan | 5910906 | 2016-12-29 12:13:35 -0500 | [diff] [blame] | 1355 | if (likely(skb)) |
| 1356 | tcp_gro_complete(skb); |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1357 | #endif |
| 1358 | return skb; |
| 1359 | } |
| 1360 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1361 | /* Given the cfa_code of a received packet determine which |
| 1362 | * netdev (vf-rep or PF) the packet is destined to. |
| 1363 | */ |
| 1364 | static struct net_device *bnxt_get_pkt_dev(struct bnxt *bp, u16 cfa_code) |
| 1365 | { |
| 1366 | struct net_device *dev = bnxt_get_vf_rep(bp, cfa_code); |
| 1367 | |
| 1368 | /* if vf-rep dev is NULL, the must belongs to the PF */ |
| 1369 | return dev ? dev : bp->dev; |
| 1370 | } |
| 1371 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1372 | static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp, |
| 1373 | struct bnxt_napi *bnapi, |
| 1374 | u32 *raw_cons, |
| 1375 | struct rx_tpa_end_cmp *tpa_end, |
| 1376 | struct rx_tpa_end_cmp_ext *tpa_end1, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1377 | u8 *event) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1378 | { |
| 1379 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1380 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1381 | u8 agg_id = TPA_END_AGG_ID(tpa_end); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1382 | u8 *data_ptr, agg_bufs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1383 | u16 cp_cons = RING_CMP(*raw_cons); |
| 1384 | unsigned int len; |
| 1385 | struct bnxt_tpa_info *tpa_info; |
| 1386 | dma_addr_t mapping; |
| 1387 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1388 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1389 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1390 | if (unlikely(bnapi->in_reset)) { |
| 1391 | int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end); |
| 1392 | |
| 1393 | if (rc < 0) |
| 1394 | return ERR_PTR(-EBUSY); |
| 1395 | return NULL; |
| 1396 | } |
| 1397 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1398 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1399 | data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1400 | data_ptr = tpa_info->data_ptr; |
| 1401 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1402 | len = tpa_info->len; |
| 1403 | mapping = tpa_info->mapping; |
| 1404 | |
| 1405 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1406 | RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 1407 | |
| 1408 | if (agg_bufs) { |
| 1409 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons)) |
| 1410 | return ERR_PTR(-EBUSY); |
| 1411 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1412 | *event |= BNXT_AGG_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1413 | cp_cons = NEXT_CMP(cp_cons); |
| 1414 | } |
| 1415 | |
Michael Chan | 69c149e | 2017-06-23 14:01:00 -0400 | [diff] [blame] | 1416 | if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1417 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
Michael Chan | 69c149e | 2017-06-23 14:01:00 -0400 | [diff] [blame] | 1418 | if (agg_bufs > MAX_SKB_FRAGS) |
| 1419 | netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n", |
| 1420 | agg_bufs, (int)MAX_SKB_FRAGS); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1421 | return NULL; |
| 1422 | } |
| 1423 | |
| 1424 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1425 | skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1426 | if (!skb) { |
| 1427 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1428 | return NULL; |
| 1429 | } |
| 1430 | } else { |
| 1431 | u8 *new_data; |
| 1432 | dma_addr_t new_mapping; |
| 1433 | |
| 1434 | new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC); |
| 1435 | if (!new_data) { |
| 1436 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1437 | return NULL; |
| 1438 | } |
| 1439 | |
| 1440 | tpa_info->data = new_data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 1441 | tpa_info->data_ptr = new_data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1442 | tpa_info->mapping = new_mapping; |
| 1443 | |
| 1444 | skb = build_skb(data, 0); |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 1445 | dma_unmap_single_attrs(&bp->pdev->dev, mapping, |
| 1446 | bp->rx_buf_use_size, bp->rx_dir, |
| 1447 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1448 | |
| 1449 | if (!skb) { |
| 1450 | kfree(data); |
| 1451 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1452 | return NULL; |
| 1453 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 1454 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1455 | skb_put(skb, len); |
| 1456 | } |
| 1457 | |
| 1458 | if (agg_bufs) { |
| 1459 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1460 | if (!skb) { |
| 1461 | /* Page reuse already handled by bnxt_rx_pages(). */ |
| 1462 | return NULL; |
| 1463 | } |
| 1464 | } |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1465 | |
| 1466 | skb->protocol = |
| 1467 | eth_type_trans(skb, bnxt_get_pkt_dev(bp, tpa_info->cfa_code)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1468 | |
| 1469 | if (tpa_info->hash_type != PKT_HASH_TYPE_NONE) |
| 1470 | skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type); |
| 1471 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1472 | if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) && |
| 1473 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1474 | u16 vlan_proto = tpa_info->metadata >> |
| 1475 | RX_CMP_FLAGS2_METADATA_TPID_SFT; |
Michael Chan | ed7bc602 | 2018-03-09 23:46:06 -0500 | [diff] [blame] | 1476 | u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1477 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1478 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | skb_checksum_none_assert(skb); |
| 1482 | if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) { |
| 1483 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1484 | skb->csum_level = |
| 1485 | (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3; |
| 1486 | } |
| 1487 | |
| 1488 | if (TPA_END_GRO(tpa_end)) |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1489 | skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1490 | |
| 1491 | return skb; |
| 1492 | } |
| 1493 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1494 | static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1495 | struct sk_buff *skb) |
| 1496 | { |
| 1497 | if (skb->dev != bp->dev) { |
| 1498 | /* this packet belongs to a vf-rep */ |
| 1499 | bnxt_vf_rep_rx(bp, skb); |
| 1500 | return; |
| 1501 | } |
| 1502 | skb_record_rx_queue(skb, bnapi->index); |
| 1503 | napi_gro_receive(&bnapi->napi, skb); |
| 1504 | } |
| 1505 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1506 | /* returns the following: |
| 1507 | * 1 - 1 packet successfully received |
| 1508 | * 0 - successful TPA_START, packet not completed yet |
| 1509 | * -EBUSY - completion ring does not have all the agg buffers yet |
| 1510 | * -ENOMEM - packet aborted due to out of memory |
| 1511 | * -EIO - packet aborted due to hw error indicated in BD |
| 1512 | */ |
| 1513 | static int bnxt_rx_pkt(struct bnxt *bp, struct bnxt_napi *bnapi, u32 *raw_cons, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1514 | u8 *event) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1515 | { |
| 1516 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1517 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1518 | struct net_device *dev = bp->dev; |
| 1519 | struct rx_cmp *rxcmp; |
| 1520 | struct rx_cmp_ext *rxcmp1; |
| 1521 | u32 tmp_raw_cons = *raw_cons; |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1522 | u16 cfa_code, cons, prod, cp_cons = RING_CMP(tmp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1523 | struct bnxt_sw_rx_bd *rx_buf; |
| 1524 | unsigned int len; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1525 | u8 *data_ptr, agg_bufs, cmp_type; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1526 | dma_addr_t dma_addr; |
| 1527 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1528 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1529 | int rc = 0; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1530 | u32 misc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1531 | |
| 1532 | rxcmp = (struct rx_cmp *) |
| 1533 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1534 | |
| 1535 | tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons); |
| 1536 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1537 | rxcmp1 = (struct rx_cmp_ext *) |
| 1538 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1539 | |
| 1540 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1541 | return -EBUSY; |
| 1542 | |
| 1543 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1544 | |
| 1545 | prod = rxr->rx_prod; |
| 1546 | |
| 1547 | if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) { |
| 1548 | bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp, |
| 1549 | (struct rx_tpa_start_cmp_ext *)rxcmp1); |
| 1550 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1551 | *event |= BNXT_RX_EVENT; |
Colin Ian King | e7e70fa | 2018-01-16 10:22:50 +0000 | [diff] [blame] | 1552 | goto next_rx_no_prod_no_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1553 | |
| 1554 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1555 | skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons, |
| 1556 | (struct rx_tpa_end_cmp *)rxcmp, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1557 | (struct rx_tpa_end_cmp_ext *)rxcmp1, event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1558 | |
Tobias Klauser | 1fac4b2 | 2017-09-26 15:12:26 +0200 | [diff] [blame] | 1559 | if (IS_ERR(skb)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1560 | return -EBUSY; |
| 1561 | |
| 1562 | rc = -ENOMEM; |
| 1563 | if (likely(skb)) { |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1564 | bnxt_deliver_skb(bp, bnapi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1565 | rc = 1; |
| 1566 | } |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1567 | *event |= BNXT_RX_EVENT; |
Colin Ian King | e7e70fa | 2018-01-16 10:22:50 +0000 | [diff] [blame] | 1568 | goto next_rx_no_prod_no_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1569 | } |
| 1570 | |
| 1571 | cons = rxcmp->rx_cmp_opaque; |
| 1572 | rx_buf = &rxr->rx_buf_ring[cons]; |
| 1573 | data = rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1574 | data_ptr = rx_buf->data_ptr; |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1575 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1576 | int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp); |
| 1577 | |
| 1578 | bnxt_sched_reset(bp, rxr); |
| 1579 | return rc1; |
| 1580 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1581 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1582 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1583 | misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1); |
| 1584 | agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1585 | |
| 1586 | if (agg_bufs) { |
| 1587 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 1588 | return -EBUSY; |
| 1589 | |
| 1590 | cp_cons = NEXT_CMP(cp_cons); |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1591 | *event |= BNXT_AGG_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1592 | } |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1593 | *event |= BNXT_RX_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1594 | |
| 1595 | rx_buf->data = NULL; |
| 1596 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) { |
| 1597 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1598 | if (agg_bufs) |
| 1599 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1600 | |
| 1601 | rc = -EIO; |
| 1602 | goto next_rx; |
| 1603 | } |
| 1604 | |
| 1605 | len = le32_to_cpu(rxcmp->rx_cmp_len_flags_type) >> RX_CMP_LEN_SHIFT; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1606 | dma_addr = rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1607 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 1608 | if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) { |
| 1609 | rc = 1; |
| 1610 | goto next_rx; |
| 1611 | } |
| 1612 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1613 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1614 | skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1615 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1616 | if (!skb) { |
| 1617 | rc = -ENOMEM; |
| 1618 | goto next_rx; |
| 1619 | } |
| 1620 | } else { |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1621 | u32 payload; |
| 1622 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 1623 | if (rx_buf->data_ptr == data_ptr) |
| 1624 | payload = misc & RX_CMP_PAYLOAD_OFFSET; |
| 1625 | else |
| 1626 | payload = 0; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1627 | skb = bp->rx_skb_func(bp, rxr, cons, data, data_ptr, dma_addr, |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1628 | payload | len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1629 | if (!skb) { |
| 1630 | rc = -ENOMEM; |
| 1631 | goto next_rx; |
| 1632 | } |
| 1633 | } |
| 1634 | |
| 1635 | if (agg_bufs) { |
| 1636 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1637 | if (!skb) { |
| 1638 | rc = -ENOMEM; |
| 1639 | goto next_rx; |
| 1640 | } |
| 1641 | } |
| 1642 | |
| 1643 | if (RX_CMP_HASH_VALID(rxcmp)) { |
| 1644 | u32 hash_type = RX_CMP_HASH_TYPE(rxcmp); |
| 1645 | enum pkt_hash_types type = PKT_HASH_TYPE_L4; |
| 1646 | |
| 1647 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 1648 | if (hash_type != 1 && hash_type != 3) |
| 1649 | type = PKT_HASH_TYPE_L3; |
| 1650 | skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type); |
| 1651 | } |
| 1652 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1653 | cfa_code = RX_CMP_CFA_CODE(rxcmp1); |
| 1654 | skb->protocol = eth_type_trans(skb, bnxt_get_pkt_dev(bp, cfa_code)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1655 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1656 | if ((rxcmp1->rx_cmp_flags2 & |
| 1657 | cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) && |
| 1658 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1659 | u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data); |
Michael Chan | ed7bc602 | 2018-03-09 23:46:06 -0500 | [diff] [blame] | 1660 | u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1661 | u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT; |
| 1662 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1663 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1664 | } |
| 1665 | |
| 1666 | skb_checksum_none_assert(skb); |
| 1667 | if (RX_CMP_L4_CS_OK(rxcmp1)) { |
| 1668 | if (dev->features & NETIF_F_RXCSUM) { |
| 1669 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1670 | skb->csum_level = RX_CMP_ENCAP(rxcmp1); |
| 1671 | } |
| 1672 | } else { |
Satish Baddipadige | 665e350 | 2015-12-27 18:19:21 -0500 | [diff] [blame] | 1673 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) { |
| 1674 | if (dev->features & NETIF_F_RXCSUM) |
| 1675 | cpr->rx_l4_csum_errors++; |
| 1676 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1677 | } |
| 1678 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1679 | bnxt_deliver_skb(bp, bnapi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1680 | rc = 1; |
| 1681 | |
| 1682 | next_rx: |
| 1683 | rxr->rx_prod = NEXT_RX(prod); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1684 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1685 | |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 1686 | cpr->rx_packets += 1; |
| 1687 | cpr->rx_bytes += len; |
Colin Ian King | e7e70fa | 2018-01-16 10:22:50 +0000 | [diff] [blame] | 1688 | |
| 1689 | next_rx_no_prod_no_len: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1690 | *raw_cons = tmp_raw_cons; |
| 1691 | |
| 1692 | return rc; |
| 1693 | } |
| 1694 | |
Michael Chan | 2270bc5 | 2017-06-23 14:01:01 -0400 | [diff] [blame] | 1695 | /* In netpoll mode, if we are using a combined completion ring, we need to |
| 1696 | * discard the rx packets and recycle the buffers. |
| 1697 | */ |
| 1698 | static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1699 | u32 *raw_cons, u8 *event) |
| 1700 | { |
| 1701 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1702 | u32 tmp_raw_cons = *raw_cons; |
| 1703 | struct rx_cmp_ext *rxcmp1; |
| 1704 | struct rx_cmp *rxcmp; |
| 1705 | u16 cp_cons; |
| 1706 | u8 cmp_type; |
| 1707 | |
| 1708 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1709 | rxcmp = (struct rx_cmp *) |
| 1710 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1711 | |
| 1712 | tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons); |
| 1713 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1714 | rxcmp1 = (struct rx_cmp_ext *) |
| 1715 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1716 | |
| 1717 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1718 | return -EBUSY; |
| 1719 | |
| 1720 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1721 | if (cmp_type == CMP_TYPE_RX_L2_CMP) { |
| 1722 | rxcmp1->rx_cmp_cfa_code_errors_v2 |= |
| 1723 | cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR); |
| 1724 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1725 | struct rx_tpa_end_cmp_ext *tpa_end1; |
| 1726 | |
| 1727 | tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1; |
| 1728 | tpa_end1->rx_tpa_end_cmp_errors_v2 |= |
| 1729 | cpu_to_le32(RX_TPA_END_CMP_ERRORS); |
| 1730 | } |
| 1731 | return bnxt_rx_pkt(bp, bnapi, raw_cons, event); |
| 1732 | } |
| 1733 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1734 | #define BNXT_GET_EVENT_PORT(data) \ |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1735 | ((data) & \ |
| 1736 | ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK) |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1737 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1738 | static int bnxt_async_event_process(struct bnxt *bp, |
| 1739 | struct hwrm_async_event_cmpl *cmpl) |
| 1740 | { |
| 1741 | u16 event_id = le16_to_cpu(cmpl->event_id); |
| 1742 | |
| 1743 | /* TODO CHIMP_FW: Define event id's for link change, error etc */ |
| 1744 | switch (event_id) { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1745 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: { |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1746 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1747 | struct bnxt_link_info *link_info = &bp->link_info; |
| 1748 | |
| 1749 | if (BNXT_VF(bp)) |
| 1750 | goto async_event_process_exit; |
Michael Chan | a8168b6 | 2017-12-06 17:31:22 -0500 | [diff] [blame] | 1751 | |
| 1752 | /* print unsupported speed warning in forced speed mode only */ |
| 1753 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED) && |
| 1754 | (data1 & 0x20000)) { |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1755 | u16 fw_speed = link_info->force_link_speed; |
| 1756 | u32 speed = bnxt_fw_to_ethtool_speed(fw_speed); |
| 1757 | |
Michael Chan | a8168b6 | 2017-12-06 17:31:22 -0500 | [diff] [blame] | 1758 | if (speed != SPEED_UNKNOWN) |
| 1759 | netdev_warn(bp->dev, "Link speed %d no longer supported\n", |
| 1760 | speed); |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1761 | } |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 1762 | set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event); |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1763 | } |
Gustavo A. R. Silva | bc171e8 | 2018-08-07 18:11:14 -0500 | [diff] [blame] | 1764 | /* fall through */ |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1765 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1766 | set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event); |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1767 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1768 | case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1769 | set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1770 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1771 | case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: { |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1772 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1773 | u16 port_id = BNXT_GET_EVENT_PORT(data1); |
| 1774 | |
| 1775 | if (BNXT_VF(bp)) |
| 1776 | break; |
| 1777 | |
| 1778 | if (bp->pf.port_id != port_id) |
| 1779 | break; |
| 1780 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1781 | set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event); |
| 1782 | break; |
| 1783 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1784 | case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE: |
Michael Chan | fc0f192 | 2016-06-13 02:25:30 -0400 | [diff] [blame] | 1785 | if (BNXT_PF(bp)) |
| 1786 | goto async_event_process_exit; |
| 1787 | set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event); |
| 1788 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1789 | default: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1790 | goto async_event_process_exit; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1791 | } |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1792 | bnxt_queue_sp_work(bp); |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1793 | async_event_process_exit: |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 1794 | bnxt_ulp_async_events(bp, cmpl); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1795 | return 0; |
| 1796 | } |
| 1797 | |
| 1798 | static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp) |
| 1799 | { |
| 1800 | u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id; |
| 1801 | struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp; |
| 1802 | struct hwrm_fwd_req_cmpl *fwd_req_cmpl = |
| 1803 | (struct hwrm_fwd_req_cmpl *)txcmp; |
| 1804 | |
| 1805 | switch (cmpl_type) { |
| 1806 | case CMPL_BASE_TYPE_HWRM_DONE: |
| 1807 | seq_id = le16_to_cpu(h_cmpl->sequence_id); |
| 1808 | if (seq_id == bp->hwrm_intr_seq_id) |
| 1809 | bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID; |
| 1810 | else |
| 1811 | netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id); |
| 1812 | break; |
| 1813 | |
| 1814 | case CMPL_BASE_TYPE_HWRM_FWD_REQ: |
| 1815 | vf_id = le16_to_cpu(fwd_req_cmpl->source_id); |
| 1816 | |
| 1817 | if ((vf_id < bp->pf.first_vf_id) || |
| 1818 | (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) { |
| 1819 | netdev_err(bp->dev, "Msg contains invalid VF id %x\n", |
| 1820 | vf_id); |
| 1821 | return -EINVAL; |
| 1822 | } |
| 1823 | |
| 1824 | set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap); |
| 1825 | set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1826 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1827 | break; |
| 1828 | |
| 1829 | case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT: |
| 1830 | bnxt_async_event_process(bp, |
| 1831 | (struct hwrm_async_event_cmpl *)txcmp); |
| 1832 | |
| 1833 | default: |
| 1834 | break; |
| 1835 | } |
| 1836 | |
| 1837 | return 0; |
| 1838 | } |
| 1839 | |
| 1840 | static irqreturn_t bnxt_msix(int irq, void *dev_instance) |
| 1841 | { |
| 1842 | struct bnxt_napi *bnapi = dev_instance; |
| 1843 | struct bnxt *bp = bnapi->bp; |
| 1844 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1845 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1846 | |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 1847 | cpr->event_ctr++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1848 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1849 | napi_schedule(&bnapi->napi); |
| 1850 | return IRQ_HANDLED; |
| 1851 | } |
| 1852 | |
| 1853 | static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) |
| 1854 | { |
| 1855 | u32 raw_cons = cpr->cp_raw_cons; |
| 1856 | u16 cons = RING_CMP(raw_cons); |
| 1857 | struct tx_cmp *txcmp; |
| 1858 | |
| 1859 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1860 | |
| 1861 | return TX_CMP_VALID(txcmp, raw_cons); |
| 1862 | } |
| 1863 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1864 | static irqreturn_t bnxt_inta(int irq, void *dev_instance) |
| 1865 | { |
| 1866 | struct bnxt_napi *bnapi = dev_instance; |
| 1867 | struct bnxt *bp = bnapi->bp; |
| 1868 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1869 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1870 | u32 int_status; |
| 1871 | |
| 1872 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1873 | |
| 1874 | if (!bnxt_has_work(bp, cpr)) { |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 1875 | int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1876 | /* return if erroneous interrupt */ |
| 1877 | if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id))) |
| 1878 | return IRQ_NONE; |
| 1879 | } |
| 1880 | |
| 1881 | /* disable ring IRQ */ |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 1882 | BNXT_CP_DB_IRQ_DIS(cpr->cp_db.doorbell); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1883 | |
| 1884 | /* Return here if interrupt is shared and is disabled. */ |
| 1885 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) |
| 1886 | return IRQ_HANDLED; |
| 1887 | |
| 1888 | napi_schedule(&bnapi->napi); |
| 1889 | return IRQ_HANDLED; |
| 1890 | } |
| 1891 | |
| 1892 | static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget) |
| 1893 | { |
| 1894 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1895 | u32 raw_cons = cpr->cp_raw_cons; |
| 1896 | u32 cons; |
| 1897 | int tx_pkts = 0; |
| 1898 | int rx_pkts = 0; |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1899 | u8 event = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1900 | struct tx_cmp *txcmp; |
| 1901 | |
| 1902 | while (1) { |
| 1903 | int rc; |
| 1904 | |
| 1905 | cons = RING_CMP(raw_cons); |
| 1906 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1907 | |
| 1908 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1909 | break; |
| 1910 | |
Michael Chan | 67a95e2 | 2016-05-04 16:56:43 -0400 | [diff] [blame] | 1911 | /* The valid test of the entry must be done first before |
| 1912 | * reading any further. |
| 1913 | */ |
Michael Chan | b67daab | 2016-05-15 03:04:51 -0400 | [diff] [blame] | 1914 | dma_rmb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1915 | if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) { |
| 1916 | tx_pkts++; |
| 1917 | /* return full budget so NAPI will complete. */ |
Michael Chan | 73f21c6 | 2018-09-26 00:41:04 -0400 | [diff] [blame] | 1918 | if (unlikely(tx_pkts > bp->tx_wake_thresh)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1919 | rx_pkts = budget; |
Michael Chan | 73f21c6 | 2018-09-26 00:41:04 -0400 | [diff] [blame] | 1920 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1921 | break; |
| 1922 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1923 | } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
Michael Chan | 2270bc5 | 2017-06-23 14:01:01 -0400 | [diff] [blame] | 1924 | if (likely(budget)) |
| 1925 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event); |
| 1926 | else |
| 1927 | rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons, |
| 1928 | &event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1929 | if (likely(rc >= 0)) |
| 1930 | rx_pkts += rc; |
Michael Chan | 903649e | 2017-08-28 13:40:30 -0400 | [diff] [blame] | 1931 | /* Increment rx_pkts when rc is -ENOMEM to count towards |
| 1932 | * the NAPI budget. Otherwise, we may potentially loop |
| 1933 | * here forever if we consistently cannot allocate |
| 1934 | * buffers. |
| 1935 | */ |
Calvin Owens | 2edbdb3 | 2017-12-08 09:05:26 -0800 | [diff] [blame] | 1936 | else if (rc == -ENOMEM && budget) |
Michael Chan | 903649e | 2017-08-28 13:40:30 -0400 | [diff] [blame] | 1937 | rx_pkts++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1938 | else if (rc == -EBUSY) /* partial completion */ |
| 1939 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1940 | } else if (unlikely((TX_CMP_TYPE(txcmp) == |
| 1941 | CMPL_BASE_TYPE_HWRM_DONE) || |
| 1942 | (TX_CMP_TYPE(txcmp) == |
| 1943 | CMPL_BASE_TYPE_HWRM_FWD_REQ) || |
| 1944 | (TX_CMP_TYPE(txcmp) == |
| 1945 | CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) { |
| 1946 | bnxt_hwrm_handler(bp, txcmp); |
| 1947 | } |
| 1948 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1949 | |
Michael Chan | 73f21c6 | 2018-09-26 00:41:04 -0400 | [diff] [blame] | 1950 | if (rx_pkts && rx_pkts == budget) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1951 | break; |
| 1952 | } |
| 1953 | |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 1954 | if (event & BNXT_TX_EVENT) { |
| 1955 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 1956 | u16 prod = txr->tx_prod; |
| 1957 | |
| 1958 | /* Sync BD data before updating doorbell */ |
| 1959 | wmb(); |
| 1960 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 1961 | bnxt_db_write_relaxed(bp, &txr->tx_db, prod); |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 1962 | } |
| 1963 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1964 | cpr->cp_raw_cons = raw_cons; |
| 1965 | /* ACK completion ring before freeing tx ring and producing new |
| 1966 | * buffers in rx/agg rings to prevent overflowing the completion |
| 1967 | * ring. |
| 1968 | */ |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 1969 | bnxt_db_cq(bp, &cpr->cp_db, cpr->cp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1970 | |
| 1971 | if (tx_pkts) |
Michael Chan | fa3e93e | 2017-02-06 16:55:41 -0500 | [diff] [blame] | 1972 | bnapi->tx_int(bp, bnapi, tx_pkts); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1973 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1974 | if (event & BNXT_RX_EVENT) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1975 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1976 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 1977 | bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod); |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 1978 | if (event & BNXT_AGG_EVENT) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 1979 | bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1980 | } |
| 1981 | return rx_pkts; |
| 1982 | } |
| 1983 | |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1984 | static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget) |
| 1985 | { |
| 1986 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 1987 | struct bnxt *bp = bnapi->bp; |
| 1988 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1989 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
| 1990 | struct tx_cmp *txcmp; |
| 1991 | struct rx_cmp_ext *rxcmp1; |
| 1992 | u32 cp_cons, tmp_raw_cons; |
| 1993 | u32 raw_cons = cpr->cp_raw_cons; |
| 1994 | u32 rx_pkts = 0; |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1995 | u8 event = 0; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1996 | |
| 1997 | while (1) { |
| 1998 | int rc; |
| 1999 | |
| 2000 | cp_cons = RING_CMP(raw_cons); |
| 2001 | txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 2002 | |
| 2003 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 2004 | break; |
| 2005 | |
| 2006 | if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
| 2007 | tmp_raw_cons = NEXT_RAW_CMP(raw_cons); |
| 2008 | cp_cons = RING_CMP(tmp_raw_cons); |
| 2009 | rxcmp1 = (struct rx_cmp_ext *) |
| 2010 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 2011 | |
| 2012 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 2013 | break; |
| 2014 | |
| 2015 | /* force an error to recycle the buffer */ |
| 2016 | rxcmp1->rx_cmp_cfa_code_errors_v2 |= |
| 2017 | cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR); |
| 2018 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 2019 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event); |
Calvin Owens | 2edbdb3 | 2017-12-08 09:05:26 -0800 | [diff] [blame] | 2020 | if (likely(rc == -EIO) && budget) |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2021 | rx_pkts++; |
| 2022 | else if (rc == -EBUSY) /* partial completion */ |
| 2023 | break; |
| 2024 | } else if (unlikely(TX_CMP_TYPE(txcmp) == |
| 2025 | CMPL_BASE_TYPE_HWRM_DONE)) { |
| 2026 | bnxt_hwrm_handler(bp, txcmp); |
| 2027 | } else { |
| 2028 | netdev_err(bp->dev, |
| 2029 | "Invalid completion received on special ring\n"); |
| 2030 | } |
| 2031 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 2032 | |
| 2033 | if (rx_pkts == budget) |
| 2034 | break; |
| 2035 | } |
| 2036 | |
| 2037 | cpr->cp_raw_cons = raw_cons; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 2038 | BNXT_DB_CQ(&cpr->cp_db, cpr->cp_raw_cons); |
| 2039 | bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2040 | |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 2041 | if (event & BNXT_AGG_EVENT) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 2042 | bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2043 | |
| 2044 | if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 2045 | napi_complete_done(napi, rx_pkts); |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 2046 | BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2047 | } |
| 2048 | return rx_pkts; |
| 2049 | } |
| 2050 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2051 | static int bnxt_poll(struct napi_struct *napi, int budget) |
| 2052 | { |
| 2053 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 2054 | struct bnxt *bp = bnapi->bp; |
| 2055 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2056 | int work_done = 0; |
| 2057 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2058 | while (1) { |
| 2059 | work_done += bnxt_poll_work(bp, bnapi, budget - work_done); |
| 2060 | |
Michael Chan | 73f21c6 | 2018-09-26 00:41:04 -0400 | [diff] [blame] | 2061 | if (work_done >= budget) { |
| 2062 | if (!budget) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 2063 | BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2064 | break; |
Michael Chan | 73f21c6 | 2018-09-26 00:41:04 -0400 | [diff] [blame] | 2065 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2066 | |
| 2067 | if (!bnxt_has_work(bp, cpr)) { |
Michael Chan | e7b9569 | 2016-12-29 12:13:32 -0500 | [diff] [blame] | 2068 | if (napi_complete_done(napi, work_done)) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 2069 | BNXT_DB_CQ_ARM(&cpr->cp_db, cpr->cp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2070 | break; |
| 2071 | } |
| 2072 | } |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 2073 | if (bp->flags & BNXT_FLAG_DIM) { |
| 2074 | struct net_dim_sample dim_sample; |
| 2075 | |
| 2076 | net_dim_sample(cpr->event_ctr, |
| 2077 | cpr->rx_packets, |
| 2078 | cpr->rx_bytes, |
| 2079 | &dim_sample); |
| 2080 | net_dim(&cpr->dim, dim_sample); |
| 2081 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2082 | mmiowb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2083 | return work_done; |
| 2084 | } |
| 2085 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2086 | static void bnxt_free_tx_skbs(struct bnxt *bp) |
| 2087 | { |
| 2088 | int i, max_idx; |
| 2089 | struct pci_dev *pdev = bp->pdev; |
| 2090 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2091 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2092 | return; |
| 2093 | |
| 2094 | max_idx = bp->tx_nr_pages * TX_DESC_CNT; |
| 2095 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2096 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2097 | int j; |
| 2098 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2099 | for (j = 0; j < max_idx;) { |
| 2100 | struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j]; |
| 2101 | struct sk_buff *skb = tx_buf->skb; |
| 2102 | int k, last; |
| 2103 | |
| 2104 | if (!skb) { |
| 2105 | j++; |
| 2106 | continue; |
| 2107 | } |
| 2108 | |
| 2109 | tx_buf->skb = NULL; |
| 2110 | |
| 2111 | if (tx_buf->is_push) { |
| 2112 | dev_kfree_skb(skb); |
| 2113 | j += 2; |
| 2114 | continue; |
| 2115 | } |
| 2116 | |
| 2117 | dma_unmap_single(&pdev->dev, |
| 2118 | dma_unmap_addr(tx_buf, mapping), |
| 2119 | skb_headlen(skb), |
| 2120 | PCI_DMA_TODEVICE); |
| 2121 | |
| 2122 | last = tx_buf->nr_frags; |
| 2123 | j += 2; |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 2124 | for (k = 0; k < last; k++, j++) { |
| 2125 | int ring_idx = j & bp->tx_ring_mask; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2126 | skb_frag_t *frag = &skb_shinfo(skb)->frags[k]; |
| 2127 | |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 2128 | tx_buf = &txr->tx_buf_ring[ring_idx]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2129 | dma_unmap_page( |
| 2130 | &pdev->dev, |
| 2131 | dma_unmap_addr(tx_buf, mapping), |
| 2132 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
| 2133 | } |
| 2134 | dev_kfree_skb(skb); |
| 2135 | } |
| 2136 | netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i)); |
| 2137 | } |
| 2138 | } |
| 2139 | |
| 2140 | static void bnxt_free_rx_skbs(struct bnxt *bp) |
| 2141 | { |
| 2142 | int i, max_idx, max_agg_idx; |
| 2143 | struct pci_dev *pdev = bp->pdev; |
| 2144 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2145 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2146 | return; |
| 2147 | |
| 2148 | max_idx = bp->rx_nr_pages * RX_DESC_CNT; |
| 2149 | max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT; |
| 2150 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2151 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2152 | int j; |
| 2153 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2154 | if (rxr->rx_tpa) { |
| 2155 | for (j = 0; j < MAX_TPA; j++) { |
| 2156 | struct bnxt_tpa_info *tpa_info = |
| 2157 | &rxr->rx_tpa[j]; |
| 2158 | u8 *data = tpa_info->data; |
| 2159 | |
| 2160 | if (!data) |
| 2161 | continue; |
| 2162 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2163 | dma_unmap_single_attrs(&pdev->dev, |
| 2164 | tpa_info->mapping, |
| 2165 | bp->rx_buf_use_size, |
| 2166 | bp->rx_dir, |
| 2167 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2168 | |
| 2169 | tpa_info->data = NULL; |
| 2170 | |
| 2171 | kfree(data); |
| 2172 | } |
| 2173 | } |
| 2174 | |
| 2175 | for (j = 0; j < max_idx; j++) { |
| 2176 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j]; |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2177 | dma_addr_t mapping = rx_buf->mapping; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2178 | void *data = rx_buf->data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2179 | |
| 2180 | if (!data) |
| 2181 | continue; |
| 2182 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2183 | rx_buf->data = NULL; |
| 2184 | |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2185 | if (BNXT_RX_PAGE_MODE(bp)) { |
| 2186 | mapping -= bp->rx_dma_offset; |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2187 | dma_unmap_page_attrs(&pdev->dev, mapping, |
| 2188 | PAGE_SIZE, bp->rx_dir, |
| 2189 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2190 | __free_page(data); |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2191 | } else { |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2192 | dma_unmap_single_attrs(&pdev->dev, mapping, |
| 2193 | bp->rx_buf_use_size, |
| 2194 | bp->rx_dir, |
| 2195 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2196 | kfree(data); |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2197 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2198 | } |
| 2199 | |
| 2200 | for (j = 0; j < max_agg_idx; j++) { |
| 2201 | struct bnxt_sw_rx_agg_bd *rx_agg_buf = |
| 2202 | &rxr->rx_agg_ring[j]; |
| 2203 | struct page *page = rx_agg_buf->page; |
| 2204 | |
| 2205 | if (!page) |
| 2206 | continue; |
| 2207 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2208 | dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping, |
| 2209 | BNXT_RX_PAGE_SIZE, |
| 2210 | PCI_DMA_FROMDEVICE, |
| 2211 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2212 | |
| 2213 | rx_agg_buf->page = NULL; |
| 2214 | __clear_bit(j, rxr->rx_agg_bmap); |
| 2215 | |
| 2216 | __free_page(page); |
| 2217 | } |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 2218 | if (rxr->rx_page) { |
| 2219 | __free_page(rxr->rx_page); |
| 2220 | rxr->rx_page = NULL; |
| 2221 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2222 | } |
| 2223 | } |
| 2224 | |
| 2225 | static void bnxt_free_skbs(struct bnxt *bp) |
| 2226 | { |
| 2227 | bnxt_free_tx_skbs(bp); |
| 2228 | bnxt_free_rx_skbs(bp); |
| 2229 | } |
| 2230 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2231 | static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2232 | { |
| 2233 | struct pci_dev *pdev = bp->pdev; |
| 2234 | int i; |
| 2235 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2236 | for (i = 0; i < rmem->nr_pages; i++) { |
| 2237 | if (!rmem->pg_arr[i]) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2238 | continue; |
| 2239 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2240 | dma_free_coherent(&pdev->dev, rmem->page_size, |
| 2241 | rmem->pg_arr[i], rmem->dma_arr[i]); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2242 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2243 | rmem->pg_arr[i] = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2244 | } |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2245 | if (rmem->pg_tbl) { |
| 2246 | dma_free_coherent(&pdev->dev, rmem->nr_pages * 8, |
| 2247 | rmem->pg_tbl, rmem->pg_tbl_map); |
| 2248 | rmem->pg_tbl = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2249 | } |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2250 | if (rmem->vmem_size && *rmem->vmem) { |
| 2251 | vfree(*rmem->vmem); |
| 2252 | *rmem->vmem = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2253 | } |
| 2254 | } |
| 2255 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2256 | static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_mem_info *rmem) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2257 | { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2258 | struct pci_dev *pdev = bp->pdev; |
Michael Chan | 66cca20 | 2018-10-14 07:02:42 -0400 | [diff] [blame] | 2259 | u64 valid_bit = 0; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2260 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2261 | |
Michael Chan | 66cca20 | 2018-10-14 07:02:42 -0400 | [diff] [blame] | 2262 | if (rmem->flags & (BNXT_RMEM_VALID_PTE_FLAG | BNXT_RMEM_RING_PTE_FLAG)) |
| 2263 | valid_bit = PTU_PTE_VALID; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2264 | if (rmem->nr_pages > 1) { |
| 2265 | rmem->pg_tbl = dma_alloc_coherent(&pdev->dev, |
| 2266 | rmem->nr_pages * 8, |
| 2267 | &rmem->pg_tbl_map, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2268 | GFP_KERNEL); |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2269 | if (!rmem->pg_tbl) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2270 | return -ENOMEM; |
| 2271 | } |
| 2272 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2273 | for (i = 0; i < rmem->nr_pages; i++) { |
Michael Chan | 66cca20 | 2018-10-14 07:02:42 -0400 | [diff] [blame] | 2274 | u64 extra_bits = valid_bit; |
| 2275 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2276 | rmem->pg_arr[i] = dma_alloc_coherent(&pdev->dev, |
| 2277 | rmem->page_size, |
| 2278 | &rmem->dma_arr[i], |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2279 | GFP_KERNEL); |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2280 | if (!rmem->pg_arr[i]) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2281 | return -ENOMEM; |
| 2282 | |
Michael Chan | 66cca20 | 2018-10-14 07:02:42 -0400 | [diff] [blame] | 2283 | if (rmem->nr_pages > 1) { |
| 2284 | if (i == rmem->nr_pages - 2 && |
| 2285 | (rmem->flags & BNXT_RMEM_RING_PTE_FLAG)) |
| 2286 | extra_bits |= PTU_PTE_NEXT_TO_LAST; |
| 2287 | else if (i == rmem->nr_pages - 1 && |
| 2288 | (rmem->flags & BNXT_RMEM_RING_PTE_FLAG)) |
| 2289 | extra_bits |= PTU_PTE_LAST; |
| 2290 | rmem->pg_tbl[i] = |
| 2291 | cpu_to_le64(rmem->dma_arr[i] | extra_bits); |
| 2292 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2293 | } |
| 2294 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2295 | if (rmem->vmem_size) { |
| 2296 | *rmem->vmem = vzalloc(rmem->vmem_size); |
| 2297 | if (!(*rmem->vmem)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2298 | return -ENOMEM; |
| 2299 | } |
| 2300 | return 0; |
| 2301 | } |
| 2302 | |
| 2303 | static void bnxt_free_rx_rings(struct bnxt *bp) |
| 2304 | { |
| 2305 | int i; |
| 2306 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2307 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2308 | return; |
| 2309 | |
| 2310 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2311 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2312 | struct bnxt_ring_struct *ring; |
| 2313 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2314 | if (rxr->xdp_prog) |
| 2315 | bpf_prog_put(rxr->xdp_prog); |
| 2316 | |
Jesper Dangaard Brouer | 96a8604 | 2018-01-03 11:25:44 +0100 | [diff] [blame] | 2317 | if (xdp_rxq_info_is_reg(&rxr->xdp_rxq)) |
| 2318 | xdp_rxq_info_unreg(&rxr->xdp_rxq); |
| 2319 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2320 | kfree(rxr->rx_tpa); |
| 2321 | rxr->rx_tpa = NULL; |
| 2322 | |
| 2323 | kfree(rxr->rx_agg_bmap); |
| 2324 | rxr->rx_agg_bmap = NULL; |
| 2325 | |
| 2326 | ring = &rxr->rx_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2327 | bnxt_free_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2328 | |
| 2329 | ring = &rxr->rx_agg_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2330 | bnxt_free_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2331 | } |
| 2332 | } |
| 2333 | |
| 2334 | static int bnxt_alloc_rx_rings(struct bnxt *bp) |
| 2335 | { |
| 2336 | int i, rc, agg_rings = 0, tpa_rings = 0; |
| 2337 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2338 | if (!bp->rx_ring) |
| 2339 | return -ENOMEM; |
| 2340 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2341 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 2342 | agg_rings = 1; |
| 2343 | |
| 2344 | if (bp->flags & BNXT_FLAG_TPA) |
| 2345 | tpa_rings = 1; |
| 2346 | |
| 2347 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2348 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2349 | struct bnxt_ring_struct *ring; |
| 2350 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2351 | ring = &rxr->rx_ring_struct; |
| 2352 | |
Jesper Dangaard Brouer | 96a8604 | 2018-01-03 11:25:44 +0100 | [diff] [blame] | 2353 | rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i); |
| 2354 | if (rc < 0) |
| 2355 | return rc; |
| 2356 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2357 | rc = bnxt_alloc_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2358 | if (rc) |
| 2359 | return rc; |
| 2360 | |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 2361 | ring->grp_idx = i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2362 | if (agg_rings) { |
| 2363 | u16 mem_size; |
| 2364 | |
| 2365 | ring = &rxr->rx_agg_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2366 | rc = bnxt_alloc_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2367 | if (rc) |
| 2368 | return rc; |
| 2369 | |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 2370 | ring->grp_idx = i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2371 | rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1; |
| 2372 | mem_size = rxr->rx_agg_bmap_size / 8; |
| 2373 | rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL); |
| 2374 | if (!rxr->rx_agg_bmap) |
| 2375 | return -ENOMEM; |
| 2376 | |
| 2377 | if (tpa_rings) { |
| 2378 | rxr->rx_tpa = kcalloc(MAX_TPA, |
| 2379 | sizeof(struct bnxt_tpa_info), |
| 2380 | GFP_KERNEL); |
| 2381 | if (!rxr->rx_tpa) |
| 2382 | return -ENOMEM; |
| 2383 | } |
| 2384 | } |
| 2385 | } |
| 2386 | return 0; |
| 2387 | } |
| 2388 | |
| 2389 | static void bnxt_free_tx_rings(struct bnxt *bp) |
| 2390 | { |
| 2391 | int i; |
| 2392 | struct pci_dev *pdev = bp->pdev; |
| 2393 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2394 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2395 | return; |
| 2396 | |
| 2397 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2398 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2399 | struct bnxt_ring_struct *ring; |
| 2400 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2401 | if (txr->tx_push) { |
| 2402 | dma_free_coherent(&pdev->dev, bp->tx_push_size, |
| 2403 | txr->tx_push, txr->tx_push_mapping); |
| 2404 | txr->tx_push = NULL; |
| 2405 | } |
| 2406 | |
| 2407 | ring = &txr->tx_ring_struct; |
| 2408 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2409 | bnxt_free_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
| 2413 | static int bnxt_alloc_tx_rings(struct bnxt *bp) |
| 2414 | { |
| 2415 | int i, j, rc; |
| 2416 | struct pci_dev *pdev = bp->pdev; |
| 2417 | |
| 2418 | bp->tx_push_size = 0; |
| 2419 | if (bp->tx_push_thresh) { |
| 2420 | int push_size; |
| 2421 | |
| 2422 | push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) + |
| 2423 | bp->tx_push_thresh); |
| 2424 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2425 | if (push_size > 256) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2426 | push_size = 0; |
| 2427 | bp->tx_push_thresh = 0; |
| 2428 | } |
| 2429 | |
| 2430 | bp->tx_push_size = push_size; |
| 2431 | } |
| 2432 | |
| 2433 | for (i = 0, j = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2434 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2435 | struct bnxt_ring_struct *ring; |
Michael Chan | 2e8ef77 | 2018-04-26 17:44:31 -0400 | [diff] [blame] | 2436 | u8 qidx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2437 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2438 | ring = &txr->tx_ring_struct; |
| 2439 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2440 | rc = bnxt_alloc_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2441 | if (rc) |
| 2442 | return rc; |
| 2443 | |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 2444 | ring->grp_idx = txr->bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2445 | if (bp->tx_push_size) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2446 | dma_addr_t mapping; |
| 2447 | |
| 2448 | /* One pre-allocated DMA buffer to backup |
| 2449 | * TX push operation |
| 2450 | */ |
| 2451 | txr->tx_push = dma_alloc_coherent(&pdev->dev, |
| 2452 | bp->tx_push_size, |
| 2453 | &txr->tx_push_mapping, |
| 2454 | GFP_KERNEL); |
| 2455 | |
| 2456 | if (!txr->tx_push) |
| 2457 | return -ENOMEM; |
| 2458 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2459 | mapping = txr->tx_push_mapping + |
| 2460 | sizeof(struct tx_push_bd); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2461 | txr->data_mapping = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2462 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2463 | memset(txr->tx_push, 0, sizeof(struct tx_push_bd)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2464 | } |
Michael Chan | 2e8ef77 | 2018-04-26 17:44:31 -0400 | [diff] [blame] | 2465 | qidx = bp->tc_to_qidx[j]; |
| 2466 | ring->queue_id = bp->q_info[qidx].queue_id; |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 2467 | if (i < bp->tx_nr_rings_xdp) |
| 2468 | continue; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2469 | if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1)) |
| 2470 | j++; |
| 2471 | } |
| 2472 | return 0; |
| 2473 | } |
| 2474 | |
| 2475 | static void bnxt_free_cp_rings(struct bnxt *bp) |
| 2476 | { |
| 2477 | int i; |
| 2478 | |
| 2479 | if (!bp->bnapi) |
| 2480 | return; |
| 2481 | |
| 2482 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2483 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2484 | struct bnxt_cp_ring_info *cpr; |
| 2485 | struct bnxt_ring_struct *ring; |
Michael Chan | 50e3ab7 | 2018-10-14 07:02:49 -0400 | [diff] [blame] | 2486 | int j; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2487 | |
| 2488 | if (!bnapi) |
| 2489 | continue; |
| 2490 | |
| 2491 | cpr = &bnapi->cp_ring; |
| 2492 | ring = &cpr->cp_ring_struct; |
| 2493 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2494 | bnxt_free_ring(bp, &ring->ring_mem); |
Michael Chan | 50e3ab7 | 2018-10-14 07:02:49 -0400 | [diff] [blame] | 2495 | |
| 2496 | for (j = 0; j < 2; j++) { |
| 2497 | struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j]; |
| 2498 | |
| 2499 | if (cpr2) { |
| 2500 | ring = &cpr2->cp_ring_struct; |
| 2501 | bnxt_free_ring(bp, &ring->ring_mem); |
| 2502 | kfree(cpr2); |
| 2503 | cpr->cp_ring_arr[j] = NULL; |
| 2504 | } |
| 2505 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2506 | } |
| 2507 | } |
| 2508 | |
Michael Chan | 50e3ab7 | 2018-10-14 07:02:49 -0400 | [diff] [blame] | 2509 | static struct bnxt_cp_ring_info *bnxt_alloc_cp_sub_ring(struct bnxt *bp) |
| 2510 | { |
| 2511 | struct bnxt_ring_mem_info *rmem; |
| 2512 | struct bnxt_ring_struct *ring; |
| 2513 | struct bnxt_cp_ring_info *cpr; |
| 2514 | int rc; |
| 2515 | |
| 2516 | cpr = kzalloc(sizeof(*cpr), GFP_KERNEL); |
| 2517 | if (!cpr) |
| 2518 | return NULL; |
| 2519 | |
| 2520 | ring = &cpr->cp_ring_struct; |
| 2521 | rmem = &ring->ring_mem; |
| 2522 | rmem->nr_pages = bp->cp_nr_pages; |
| 2523 | rmem->page_size = HW_CMPD_RING_SIZE; |
| 2524 | rmem->pg_arr = (void **)cpr->cp_desc_ring; |
| 2525 | rmem->dma_arr = cpr->cp_desc_mapping; |
| 2526 | rmem->flags = BNXT_RMEM_RING_PTE_FLAG; |
| 2527 | rc = bnxt_alloc_ring(bp, rmem); |
| 2528 | if (rc) { |
| 2529 | bnxt_free_ring(bp, rmem); |
| 2530 | kfree(cpr); |
| 2531 | cpr = NULL; |
| 2532 | } |
| 2533 | return cpr; |
| 2534 | } |
| 2535 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2536 | static int bnxt_alloc_cp_rings(struct bnxt *bp) |
| 2537 | { |
Michael Chan | 50e3ab7 | 2018-10-14 07:02:49 -0400 | [diff] [blame] | 2538 | bool sh = !!(bp->flags & BNXT_FLAG_SHARED_RINGS); |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 2539 | int i, rc, ulp_base_vec, ulp_msix; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2540 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 2541 | ulp_msix = bnxt_get_ulp_msix_num(bp); |
| 2542 | ulp_base_vec = bnxt_get_ulp_msix_base(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2543 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2544 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2545 | struct bnxt_cp_ring_info *cpr; |
| 2546 | struct bnxt_ring_struct *ring; |
| 2547 | |
| 2548 | if (!bnapi) |
| 2549 | continue; |
| 2550 | |
| 2551 | cpr = &bnapi->cp_ring; |
Michael Chan | 50e3ab7 | 2018-10-14 07:02:49 -0400 | [diff] [blame] | 2552 | cpr->bnapi = bnapi; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2553 | ring = &cpr->cp_ring_struct; |
| 2554 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2555 | rc = bnxt_alloc_ring(bp, &ring->ring_mem); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2556 | if (rc) |
| 2557 | return rc; |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 2558 | |
| 2559 | if (ulp_msix && i >= ulp_base_vec) |
| 2560 | ring->map_idx = i + ulp_msix; |
| 2561 | else |
| 2562 | ring->map_idx = i; |
Michael Chan | 50e3ab7 | 2018-10-14 07:02:49 -0400 | [diff] [blame] | 2563 | |
| 2564 | if (!(bp->flags & BNXT_FLAG_CHIP_P5)) |
| 2565 | continue; |
| 2566 | |
| 2567 | if (i < bp->rx_nr_rings) { |
| 2568 | struct bnxt_cp_ring_info *cpr2 = |
| 2569 | bnxt_alloc_cp_sub_ring(bp); |
| 2570 | |
| 2571 | cpr->cp_ring_arr[BNXT_RX_HDL] = cpr2; |
| 2572 | if (!cpr2) |
| 2573 | return -ENOMEM; |
| 2574 | cpr2->bnapi = bnapi; |
| 2575 | } |
| 2576 | if ((sh && i < bp->tx_nr_rings) || |
| 2577 | (!sh && i >= bp->rx_nr_rings)) { |
| 2578 | struct bnxt_cp_ring_info *cpr2 = |
| 2579 | bnxt_alloc_cp_sub_ring(bp); |
| 2580 | |
| 2581 | cpr->cp_ring_arr[BNXT_TX_HDL] = cpr2; |
| 2582 | if (!cpr2) |
| 2583 | return -ENOMEM; |
| 2584 | cpr2->bnapi = bnapi; |
| 2585 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2586 | } |
| 2587 | return 0; |
| 2588 | } |
| 2589 | |
| 2590 | static void bnxt_init_ring_struct(struct bnxt *bp) |
| 2591 | { |
| 2592 | int i; |
| 2593 | |
| 2594 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2595 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2596 | struct bnxt_ring_mem_info *rmem; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2597 | struct bnxt_cp_ring_info *cpr; |
| 2598 | struct bnxt_rx_ring_info *rxr; |
| 2599 | struct bnxt_tx_ring_info *txr; |
| 2600 | struct bnxt_ring_struct *ring; |
| 2601 | |
| 2602 | if (!bnapi) |
| 2603 | continue; |
| 2604 | |
| 2605 | cpr = &bnapi->cp_ring; |
| 2606 | ring = &cpr->cp_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2607 | rmem = &ring->ring_mem; |
| 2608 | rmem->nr_pages = bp->cp_nr_pages; |
| 2609 | rmem->page_size = HW_CMPD_RING_SIZE; |
| 2610 | rmem->pg_arr = (void **)cpr->cp_desc_ring; |
| 2611 | rmem->dma_arr = cpr->cp_desc_mapping; |
| 2612 | rmem->vmem_size = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2613 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2614 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2615 | if (!rxr) |
| 2616 | goto skip_rx; |
| 2617 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2618 | ring = &rxr->rx_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2619 | rmem = &ring->ring_mem; |
| 2620 | rmem->nr_pages = bp->rx_nr_pages; |
| 2621 | rmem->page_size = HW_RXBD_RING_SIZE; |
| 2622 | rmem->pg_arr = (void **)rxr->rx_desc_ring; |
| 2623 | rmem->dma_arr = rxr->rx_desc_mapping; |
| 2624 | rmem->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages; |
| 2625 | rmem->vmem = (void **)&rxr->rx_buf_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2626 | |
| 2627 | ring = &rxr->rx_agg_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2628 | rmem = &ring->ring_mem; |
| 2629 | rmem->nr_pages = bp->rx_agg_nr_pages; |
| 2630 | rmem->page_size = HW_RXBD_RING_SIZE; |
| 2631 | rmem->pg_arr = (void **)rxr->rx_agg_desc_ring; |
| 2632 | rmem->dma_arr = rxr->rx_agg_desc_mapping; |
| 2633 | rmem->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages; |
| 2634 | rmem->vmem = (void **)&rxr->rx_agg_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2635 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2636 | skip_rx: |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2637 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2638 | if (!txr) |
| 2639 | continue; |
| 2640 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2641 | ring = &txr->tx_ring_struct; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2642 | rmem = &ring->ring_mem; |
| 2643 | rmem->nr_pages = bp->tx_nr_pages; |
| 2644 | rmem->page_size = HW_RXBD_RING_SIZE; |
| 2645 | rmem->pg_arr = (void **)txr->tx_desc_ring; |
| 2646 | rmem->dma_arr = txr->tx_desc_mapping; |
| 2647 | rmem->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages; |
| 2648 | rmem->vmem = (void **)&txr->tx_buf_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | |
| 2652 | static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type) |
| 2653 | { |
| 2654 | int i; |
| 2655 | u32 prod; |
| 2656 | struct rx_bd **rx_buf_ring; |
| 2657 | |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 2658 | rx_buf_ring = (struct rx_bd **)ring->ring_mem.pg_arr; |
| 2659 | for (i = 0, prod = 0; i < ring->ring_mem.nr_pages; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2660 | int j; |
| 2661 | struct rx_bd *rxbd; |
| 2662 | |
| 2663 | rxbd = rx_buf_ring[i]; |
| 2664 | if (!rxbd) |
| 2665 | continue; |
| 2666 | |
| 2667 | for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) { |
| 2668 | rxbd->rx_bd_len_flags_type = cpu_to_le32(type); |
| 2669 | rxbd->rx_bd_opaque = prod; |
| 2670 | } |
| 2671 | } |
| 2672 | } |
| 2673 | |
| 2674 | static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr) |
| 2675 | { |
| 2676 | struct net_device *dev = bp->dev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2677 | struct bnxt_rx_ring_info *rxr; |
| 2678 | struct bnxt_ring_struct *ring; |
| 2679 | u32 prod, type; |
| 2680 | int i; |
| 2681 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2682 | type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) | |
| 2683 | RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP; |
| 2684 | |
| 2685 | if (NET_IP_ALIGN == 2) |
| 2686 | type |= RX_BD_FLAGS_SOP; |
| 2687 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2688 | rxr = &bp->rx_ring[ring_nr]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2689 | ring = &rxr->rx_ring_struct; |
| 2690 | bnxt_init_rxbd_pages(ring, type); |
| 2691 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2692 | if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) { |
| 2693 | rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1); |
| 2694 | if (IS_ERR(rxr->xdp_prog)) { |
| 2695 | int rc = PTR_ERR(rxr->xdp_prog); |
| 2696 | |
| 2697 | rxr->xdp_prog = NULL; |
| 2698 | return rc; |
| 2699 | } |
| 2700 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2701 | prod = rxr->rx_prod; |
| 2702 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 2703 | if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2704 | netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n", |
| 2705 | ring_nr, i, bp->rx_ring_size); |
| 2706 | break; |
| 2707 | } |
| 2708 | prod = NEXT_RX(prod); |
| 2709 | } |
| 2710 | rxr->rx_prod = prod; |
| 2711 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2712 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 2713 | ring = &rxr->rx_agg_ring_struct; |
| 2714 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2715 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2716 | if (!(bp->flags & BNXT_FLAG_AGG_RINGS)) |
| 2717 | return 0; |
| 2718 | |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2719 | type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2720 | RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP; |
| 2721 | |
| 2722 | bnxt_init_rxbd_pages(ring, type); |
| 2723 | |
| 2724 | prod = rxr->rx_agg_prod; |
| 2725 | for (i = 0; i < bp->rx_agg_ring_size; i++) { |
| 2726 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2727 | netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n", |
| 2728 | ring_nr, i, bp->rx_ring_size); |
| 2729 | break; |
| 2730 | } |
| 2731 | prod = NEXT_RX_AGG(prod); |
| 2732 | } |
| 2733 | rxr->rx_agg_prod = prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2734 | |
| 2735 | if (bp->flags & BNXT_FLAG_TPA) { |
| 2736 | if (rxr->rx_tpa) { |
| 2737 | u8 *data; |
| 2738 | dma_addr_t mapping; |
| 2739 | |
| 2740 | for (i = 0; i < MAX_TPA; i++) { |
| 2741 | data = __bnxt_alloc_rx_data(bp, &mapping, |
| 2742 | GFP_KERNEL); |
| 2743 | if (!data) |
| 2744 | return -ENOMEM; |
| 2745 | |
| 2746 | rxr->rx_tpa[i].data = data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 2747 | rxr->rx_tpa[i].data_ptr = data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2748 | rxr->rx_tpa[i].mapping = mapping; |
| 2749 | } |
| 2750 | } else { |
| 2751 | netdev_err(bp->dev, "No resource allocated for LRO/GRO\n"); |
| 2752 | return -ENOMEM; |
| 2753 | } |
| 2754 | } |
| 2755 | |
| 2756 | return 0; |
| 2757 | } |
| 2758 | |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 2759 | static void bnxt_init_cp_rings(struct bnxt *bp) |
| 2760 | { |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 2761 | int i, j; |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 2762 | |
| 2763 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2764 | struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; |
| 2765 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
| 2766 | |
| 2767 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 2768 | cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks; |
| 2769 | cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs; |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 2770 | for (j = 0; j < 2; j++) { |
| 2771 | struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j]; |
| 2772 | |
| 2773 | if (!cpr2) |
| 2774 | continue; |
| 2775 | |
| 2776 | ring = &cpr2->cp_ring_struct; |
| 2777 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2778 | cpr2->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks; |
| 2779 | cpr2->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs; |
| 2780 | } |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 2781 | } |
| 2782 | } |
| 2783 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2784 | static int bnxt_init_rx_rings(struct bnxt *bp) |
| 2785 | { |
| 2786 | int i, rc = 0; |
| 2787 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2788 | if (BNXT_RX_PAGE_MODE(bp)) { |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2789 | bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM; |
| 2790 | bp->rx_dma_offset = XDP_PACKET_HEADROOM; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2791 | } else { |
| 2792 | bp->rx_offset = BNXT_RX_OFFSET; |
| 2793 | bp->rx_dma_offset = BNXT_RX_DMA_OFFSET; |
| 2794 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 2795 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2796 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 2797 | rc = bnxt_init_one_rx_ring(bp, i); |
| 2798 | if (rc) |
| 2799 | break; |
| 2800 | } |
| 2801 | |
| 2802 | return rc; |
| 2803 | } |
| 2804 | |
| 2805 | static int bnxt_init_tx_rings(struct bnxt *bp) |
| 2806 | { |
| 2807 | u16 i; |
| 2808 | |
| 2809 | bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2, |
| 2810 | MAX_SKB_FRAGS + 1); |
| 2811 | |
| 2812 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2813 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2814 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
| 2815 | |
| 2816 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2817 | } |
| 2818 | |
| 2819 | return 0; |
| 2820 | } |
| 2821 | |
| 2822 | static void bnxt_free_ring_grps(struct bnxt *bp) |
| 2823 | { |
| 2824 | kfree(bp->grp_info); |
| 2825 | bp->grp_info = NULL; |
| 2826 | } |
| 2827 | |
| 2828 | static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init) |
| 2829 | { |
| 2830 | int i; |
| 2831 | |
| 2832 | if (irq_re_init) { |
| 2833 | bp->grp_info = kcalloc(bp->cp_nr_rings, |
| 2834 | sizeof(struct bnxt_ring_grp_info), |
| 2835 | GFP_KERNEL); |
| 2836 | if (!bp->grp_info) |
| 2837 | return -ENOMEM; |
| 2838 | } |
| 2839 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2840 | if (irq_re_init) |
| 2841 | bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID; |
| 2842 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 2843 | bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID; |
| 2844 | bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID; |
| 2845 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
| 2846 | } |
| 2847 | return 0; |
| 2848 | } |
| 2849 | |
| 2850 | static void bnxt_free_vnics(struct bnxt *bp) |
| 2851 | { |
| 2852 | kfree(bp->vnic_info); |
| 2853 | bp->vnic_info = NULL; |
| 2854 | bp->nr_vnics = 0; |
| 2855 | } |
| 2856 | |
| 2857 | static int bnxt_alloc_vnics(struct bnxt *bp) |
| 2858 | { |
| 2859 | int num_vnics = 1; |
| 2860 | |
| 2861 | #ifdef CONFIG_RFS_ACCEL |
| 2862 | if (bp->flags & BNXT_FLAG_RFS) |
| 2863 | num_vnics += bp->rx_nr_rings; |
| 2864 | #endif |
| 2865 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 2866 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 2867 | num_vnics++; |
| 2868 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2869 | bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info), |
| 2870 | GFP_KERNEL); |
| 2871 | if (!bp->vnic_info) |
| 2872 | return -ENOMEM; |
| 2873 | |
| 2874 | bp->nr_vnics = num_vnics; |
| 2875 | return 0; |
| 2876 | } |
| 2877 | |
| 2878 | static void bnxt_init_vnics(struct bnxt *bp) |
| 2879 | { |
| 2880 | int i; |
| 2881 | |
| 2882 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2883 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 2884 | |
| 2885 | vnic->fw_vnic_id = INVALID_HW_RING_ID; |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 2886 | vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 2887 | vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2888 | vnic->fw_l2_ctx_id = INVALID_HW_RING_ID; |
| 2889 | |
| 2890 | if (bp->vnic_info[i].rss_hash_key) { |
| 2891 | if (i == 0) |
| 2892 | prandom_bytes(vnic->rss_hash_key, |
| 2893 | HW_HASH_KEY_SIZE); |
| 2894 | else |
| 2895 | memcpy(vnic->rss_hash_key, |
| 2896 | bp->vnic_info[0].rss_hash_key, |
| 2897 | HW_HASH_KEY_SIZE); |
| 2898 | } |
| 2899 | } |
| 2900 | } |
| 2901 | |
| 2902 | static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg) |
| 2903 | { |
| 2904 | int pages; |
| 2905 | |
| 2906 | pages = ring_size / desc_per_pg; |
| 2907 | |
| 2908 | if (!pages) |
| 2909 | return 1; |
| 2910 | |
| 2911 | pages++; |
| 2912 | |
| 2913 | while (pages & (pages - 1)) |
| 2914 | pages++; |
| 2915 | |
| 2916 | return pages; |
| 2917 | } |
| 2918 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2919 | void bnxt_set_tpa_flags(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2920 | { |
| 2921 | bp->flags &= ~BNXT_FLAG_TPA; |
Michael Chan | 341138c | 2017-01-13 01:32:01 -0500 | [diff] [blame] | 2922 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 2923 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2924 | if (bp->dev->features & NETIF_F_LRO) |
| 2925 | bp->flags |= BNXT_FLAG_LRO; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 2926 | else if (bp->dev->features & NETIF_F_GRO_HW) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2927 | bp->flags |= BNXT_FLAG_GRO; |
| 2928 | } |
| 2929 | |
| 2930 | /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must |
| 2931 | * be set on entry. |
| 2932 | */ |
| 2933 | void bnxt_set_ring_params(struct bnxt *bp) |
| 2934 | { |
| 2935 | u32 ring_size, rx_size, rx_space; |
| 2936 | u32 agg_factor = 0, agg_ring_size = 0; |
| 2937 | |
| 2938 | /* 8 for CRC and VLAN */ |
| 2939 | rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8); |
| 2940 | |
| 2941 | rx_space = rx_size + NET_SKB_PAD + |
| 2942 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2943 | |
| 2944 | bp->rx_copy_thresh = BNXT_RX_COPY_THRESH; |
| 2945 | ring_size = bp->rx_ring_size; |
| 2946 | bp->rx_agg_ring_size = 0; |
| 2947 | bp->rx_agg_nr_pages = 0; |
| 2948 | |
| 2949 | if (bp->flags & BNXT_FLAG_TPA) |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2950 | agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2951 | |
| 2952 | bp->flags &= ~BNXT_FLAG_JUMBO; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 2953 | if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2954 | u32 jumbo_factor; |
| 2955 | |
| 2956 | bp->flags |= BNXT_FLAG_JUMBO; |
| 2957 | jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT; |
| 2958 | if (jumbo_factor > agg_factor) |
| 2959 | agg_factor = jumbo_factor; |
| 2960 | } |
| 2961 | agg_ring_size = ring_size * agg_factor; |
| 2962 | |
| 2963 | if (agg_ring_size) { |
| 2964 | bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size, |
| 2965 | RX_DESC_CNT); |
| 2966 | if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) { |
| 2967 | u32 tmp = agg_ring_size; |
| 2968 | |
| 2969 | bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES; |
| 2970 | agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1; |
| 2971 | netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n", |
| 2972 | tmp, agg_ring_size); |
| 2973 | } |
| 2974 | bp->rx_agg_ring_size = agg_ring_size; |
| 2975 | bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1; |
| 2976 | rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN); |
| 2977 | rx_space = rx_size + NET_SKB_PAD + |
| 2978 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2979 | } |
| 2980 | |
| 2981 | bp->rx_buf_use_size = rx_size; |
| 2982 | bp->rx_buf_size = rx_space; |
| 2983 | |
| 2984 | bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT); |
| 2985 | bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1; |
| 2986 | |
| 2987 | ring_size = bp->tx_ring_size; |
| 2988 | bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT); |
| 2989 | bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1; |
| 2990 | |
| 2991 | ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size; |
| 2992 | bp->cp_ring_size = ring_size; |
| 2993 | |
| 2994 | bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT); |
| 2995 | if (bp->cp_nr_pages > MAX_CP_PAGES) { |
| 2996 | bp->cp_nr_pages = MAX_CP_PAGES; |
| 2997 | bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1; |
| 2998 | netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n", |
| 2999 | ring_size, bp->cp_ring_size); |
| 3000 | } |
| 3001 | bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT; |
| 3002 | bp->cp_ring_mask = bp->cp_bit - 1; |
| 3003 | } |
| 3004 | |
Jesper Dangaard Brouer | 96a8604 | 2018-01-03 11:25:44 +0100 | [diff] [blame] | 3005 | /* Changing allocation mode of RX rings. |
| 3006 | * TODO: Update when extending xdp_rxq_info to support allocation modes. |
| 3007 | */ |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 3008 | int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode) |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 3009 | { |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 3010 | if (page_mode) { |
| 3011 | if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU) |
| 3012 | return -EOPNOTSUPP; |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 3013 | bp->dev->max_mtu = |
| 3014 | min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 3015 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 3016 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 3017 | bp->rx_dir = DMA_BIDIRECTIONAL; |
| 3018 | bp->rx_skb_func = bnxt_rx_page_skb; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 3019 | /* Disable LRO or GRO_HW */ |
| 3020 | netdev_update_features(bp->dev); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 3021 | } else { |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 3022 | bp->dev->max_mtu = bp->max_mtu; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 3023 | bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE; |
| 3024 | bp->rx_dir = DMA_FROM_DEVICE; |
| 3025 | bp->rx_skb_func = bnxt_rx_skb; |
| 3026 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 3027 | return 0; |
| 3028 | } |
| 3029 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3030 | static void bnxt_free_vnic_attributes(struct bnxt *bp) |
| 3031 | { |
| 3032 | int i; |
| 3033 | struct bnxt_vnic_info *vnic; |
| 3034 | struct pci_dev *pdev = bp->pdev; |
| 3035 | |
| 3036 | if (!bp->vnic_info) |
| 3037 | return; |
| 3038 | |
| 3039 | for (i = 0; i < bp->nr_vnics; i++) { |
| 3040 | vnic = &bp->vnic_info[i]; |
| 3041 | |
| 3042 | kfree(vnic->fw_grp_ids); |
| 3043 | vnic->fw_grp_ids = NULL; |
| 3044 | |
| 3045 | kfree(vnic->uc_list); |
| 3046 | vnic->uc_list = NULL; |
| 3047 | |
| 3048 | if (vnic->mc_list) { |
| 3049 | dma_free_coherent(&pdev->dev, vnic->mc_list_size, |
| 3050 | vnic->mc_list, vnic->mc_list_mapping); |
| 3051 | vnic->mc_list = NULL; |
| 3052 | } |
| 3053 | |
| 3054 | if (vnic->rss_table) { |
| 3055 | dma_free_coherent(&pdev->dev, PAGE_SIZE, |
| 3056 | vnic->rss_table, |
| 3057 | vnic->rss_table_dma_addr); |
| 3058 | vnic->rss_table = NULL; |
| 3059 | } |
| 3060 | |
| 3061 | vnic->rss_hash_key = NULL; |
| 3062 | vnic->flags = 0; |
| 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | static int bnxt_alloc_vnic_attributes(struct bnxt *bp) |
| 3067 | { |
| 3068 | int i, rc = 0, size; |
| 3069 | struct bnxt_vnic_info *vnic; |
| 3070 | struct pci_dev *pdev = bp->pdev; |
| 3071 | int max_rings; |
| 3072 | |
| 3073 | for (i = 0; i < bp->nr_vnics; i++) { |
| 3074 | vnic = &bp->vnic_info[i]; |
| 3075 | |
| 3076 | if (vnic->flags & BNXT_VNIC_UCAST_FLAG) { |
| 3077 | int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN; |
| 3078 | |
| 3079 | if (mem_size > 0) { |
| 3080 | vnic->uc_list = kmalloc(mem_size, GFP_KERNEL); |
| 3081 | if (!vnic->uc_list) { |
| 3082 | rc = -ENOMEM; |
| 3083 | goto out; |
| 3084 | } |
| 3085 | } |
| 3086 | } |
| 3087 | |
| 3088 | if (vnic->flags & BNXT_VNIC_MCAST_FLAG) { |
| 3089 | vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN; |
| 3090 | vnic->mc_list = |
| 3091 | dma_alloc_coherent(&pdev->dev, |
| 3092 | vnic->mc_list_size, |
| 3093 | &vnic->mc_list_mapping, |
| 3094 | GFP_KERNEL); |
| 3095 | if (!vnic->mc_list) { |
| 3096 | rc = -ENOMEM; |
| 3097 | goto out; |
| 3098 | } |
| 3099 | } |
| 3100 | |
| 3101 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
| 3102 | max_rings = bp->rx_nr_rings; |
| 3103 | else |
| 3104 | max_rings = 1; |
| 3105 | |
| 3106 | vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL); |
| 3107 | if (!vnic->fw_grp_ids) { |
| 3108 | rc = -ENOMEM; |
| 3109 | goto out; |
| 3110 | } |
| 3111 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 3112 | if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) && |
| 3113 | !(vnic->flags & BNXT_VNIC_RSS_FLAG)) |
| 3114 | continue; |
| 3115 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3116 | /* Allocate rss table and hash key */ |
| 3117 | vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 3118 | &vnic->rss_table_dma_addr, |
| 3119 | GFP_KERNEL); |
| 3120 | if (!vnic->rss_table) { |
| 3121 | rc = -ENOMEM; |
| 3122 | goto out; |
| 3123 | } |
| 3124 | |
| 3125 | size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16)); |
| 3126 | |
| 3127 | vnic->rss_hash_key = ((void *)vnic->rss_table) + size; |
| 3128 | vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size; |
| 3129 | } |
| 3130 | return 0; |
| 3131 | |
| 3132 | out: |
| 3133 | return rc; |
| 3134 | } |
| 3135 | |
| 3136 | static void bnxt_free_hwrm_resources(struct bnxt *bp) |
| 3137 | { |
| 3138 | struct pci_dev *pdev = bp->pdev; |
| 3139 | |
Venkat Duvvuru | a2bf74f | 2018-10-05 00:26:02 -0400 | [diff] [blame] | 3140 | if (bp->hwrm_cmd_resp_addr) { |
| 3141 | dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr, |
| 3142 | bp->hwrm_cmd_resp_dma_addr); |
| 3143 | bp->hwrm_cmd_resp_addr = NULL; |
| 3144 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3145 | } |
| 3146 | |
| 3147 | static int bnxt_alloc_hwrm_resources(struct bnxt *bp) |
| 3148 | { |
| 3149 | struct pci_dev *pdev = bp->pdev; |
| 3150 | |
| 3151 | bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 3152 | &bp->hwrm_cmd_resp_dma_addr, |
| 3153 | GFP_KERNEL); |
| 3154 | if (!bp->hwrm_cmd_resp_addr) |
| 3155 | return -ENOMEM; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3156 | |
| 3157 | return 0; |
| 3158 | } |
| 3159 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3160 | static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp) |
| 3161 | { |
| 3162 | if (bp->hwrm_short_cmd_req_addr) { |
| 3163 | struct pci_dev *pdev = bp->pdev; |
| 3164 | |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 3165 | dma_free_coherent(&pdev->dev, bp->hwrm_max_ext_req_len, |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3166 | bp->hwrm_short_cmd_req_addr, |
| 3167 | bp->hwrm_short_cmd_req_dma_addr); |
| 3168 | bp->hwrm_short_cmd_req_addr = NULL; |
| 3169 | } |
| 3170 | } |
| 3171 | |
| 3172 | static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp) |
| 3173 | { |
| 3174 | struct pci_dev *pdev = bp->pdev; |
| 3175 | |
| 3176 | bp->hwrm_short_cmd_req_addr = |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 3177 | dma_alloc_coherent(&pdev->dev, bp->hwrm_max_ext_req_len, |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3178 | &bp->hwrm_short_cmd_req_dma_addr, |
| 3179 | GFP_KERNEL); |
| 3180 | if (!bp->hwrm_short_cmd_req_addr) |
| 3181 | return -ENOMEM; |
| 3182 | |
| 3183 | return 0; |
| 3184 | } |
| 3185 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3186 | static void bnxt_free_stats(struct bnxt *bp) |
| 3187 | { |
| 3188 | u32 size, i; |
| 3189 | struct pci_dev *pdev = bp->pdev; |
| 3190 | |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3191 | bp->flags &= ~BNXT_FLAG_PORT_STATS; |
| 3192 | bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT; |
| 3193 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3194 | if (bp->hw_rx_port_stats) { |
| 3195 | dma_free_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 3196 | bp->hw_rx_port_stats, |
| 3197 | bp->hw_rx_port_stats_map); |
| 3198 | bp->hw_rx_port_stats = NULL; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3199 | } |
| 3200 | |
Michael Chan | 36e5334 | 2018-10-14 07:02:38 -0400 | [diff] [blame] | 3201 | if (bp->hw_tx_port_stats_ext) { |
| 3202 | dma_free_coherent(&pdev->dev, sizeof(struct tx_port_stats_ext), |
| 3203 | bp->hw_tx_port_stats_ext, |
| 3204 | bp->hw_tx_port_stats_ext_map); |
| 3205 | bp->hw_tx_port_stats_ext = NULL; |
| 3206 | } |
| 3207 | |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3208 | if (bp->hw_rx_port_stats_ext) { |
| 3209 | dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext), |
| 3210 | bp->hw_rx_port_stats_ext, |
| 3211 | bp->hw_rx_port_stats_ext_map); |
| 3212 | bp->hw_rx_port_stats_ext = NULL; |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3213 | } |
| 3214 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3215 | if (!bp->bnapi) |
| 3216 | return; |
| 3217 | |
| 3218 | size = sizeof(struct ctx_hw_stats); |
| 3219 | |
| 3220 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3221 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3222 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3223 | |
| 3224 | if (cpr->hw_stats) { |
| 3225 | dma_free_coherent(&pdev->dev, size, cpr->hw_stats, |
| 3226 | cpr->hw_stats_map); |
| 3227 | cpr->hw_stats = NULL; |
| 3228 | } |
| 3229 | } |
| 3230 | } |
| 3231 | |
| 3232 | static int bnxt_alloc_stats(struct bnxt *bp) |
| 3233 | { |
| 3234 | u32 size, i; |
| 3235 | struct pci_dev *pdev = bp->pdev; |
| 3236 | |
| 3237 | size = sizeof(struct ctx_hw_stats); |
| 3238 | |
| 3239 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3240 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3241 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3242 | |
| 3243 | cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size, |
| 3244 | &cpr->hw_stats_map, |
| 3245 | GFP_KERNEL); |
| 3246 | if (!cpr->hw_stats) |
| 3247 | return -ENOMEM; |
| 3248 | |
| 3249 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 3250 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3251 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 3252 | if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3253 | bp->hw_port_stats_size = sizeof(struct rx_port_stats) + |
| 3254 | sizeof(struct tx_port_stats) + 1024; |
| 3255 | |
| 3256 | bp->hw_rx_port_stats = |
| 3257 | dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 3258 | &bp->hw_rx_port_stats_map, |
| 3259 | GFP_KERNEL); |
| 3260 | if (!bp->hw_rx_port_stats) |
| 3261 | return -ENOMEM; |
| 3262 | |
| 3263 | bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) + |
| 3264 | 512; |
| 3265 | bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map + |
| 3266 | sizeof(struct rx_port_stats) + 512; |
| 3267 | bp->flags |= BNXT_FLAG_PORT_STATS; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3268 | |
| 3269 | /* Display extended statistics only if FW supports it */ |
| 3270 | if (bp->hwrm_spec_code < 0x10804 || |
| 3271 | bp->hwrm_spec_code == 0x10900) |
| 3272 | return 0; |
| 3273 | |
| 3274 | bp->hw_rx_port_stats_ext = |
| 3275 | dma_zalloc_coherent(&pdev->dev, |
| 3276 | sizeof(struct rx_port_stats_ext), |
| 3277 | &bp->hw_rx_port_stats_ext_map, |
| 3278 | GFP_KERNEL); |
| 3279 | if (!bp->hw_rx_port_stats_ext) |
| 3280 | return 0; |
| 3281 | |
Michael Chan | 36e5334 | 2018-10-14 07:02:38 -0400 | [diff] [blame] | 3282 | if (bp->hwrm_spec_code >= 0x10902) { |
| 3283 | bp->hw_tx_port_stats_ext = |
| 3284 | dma_zalloc_coherent(&pdev->dev, |
| 3285 | sizeof(struct tx_port_stats_ext), |
| 3286 | &bp->hw_tx_port_stats_ext_map, |
| 3287 | GFP_KERNEL); |
| 3288 | } |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3289 | bp->flags |= BNXT_FLAG_PORT_STATS_EXT; |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3290 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3291 | return 0; |
| 3292 | } |
| 3293 | |
| 3294 | static void bnxt_clear_ring_indices(struct bnxt *bp) |
| 3295 | { |
| 3296 | int i; |
| 3297 | |
| 3298 | if (!bp->bnapi) |
| 3299 | return; |
| 3300 | |
| 3301 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3302 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3303 | struct bnxt_cp_ring_info *cpr; |
| 3304 | struct bnxt_rx_ring_info *rxr; |
| 3305 | struct bnxt_tx_ring_info *txr; |
| 3306 | |
| 3307 | if (!bnapi) |
| 3308 | continue; |
| 3309 | |
| 3310 | cpr = &bnapi->cp_ring; |
| 3311 | cpr->cp_raw_cons = 0; |
| 3312 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3313 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 3314 | if (txr) { |
| 3315 | txr->tx_prod = 0; |
| 3316 | txr->tx_cons = 0; |
| 3317 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3318 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3319 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 3320 | if (rxr) { |
| 3321 | rxr->rx_prod = 0; |
| 3322 | rxr->rx_agg_prod = 0; |
| 3323 | rxr->rx_sw_agg_prod = 0; |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 3324 | rxr->rx_next_cons = 0; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 3325 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3326 | } |
| 3327 | } |
| 3328 | |
| 3329 | static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit) |
| 3330 | { |
| 3331 | #ifdef CONFIG_RFS_ACCEL |
| 3332 | int i; |
| 3333 | |
| 3334 | /* Under rtnl_lock and all our NAPIs have been disabled. It's |
| 3335 | * safe to delete the hash table. |
| 3336 | */ |
| 3337 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 3338 | struct hlist_head *head; |
| 3339 | struct hlist_node *tmp; |
| 3340 | struct bnxt_ntuple_filter *fltr; |
| 3341 | |
| 3342 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 3343 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 3344 | hlist_del(&fltr->hash); |
| 3345 | kfree(fltr); |
| 3346 | } |
| 3347 | } |
| 3348 | if (irq_reinit) { |
| 3349 | kfree(bp->ntp_fltr_bmap); |
| 3350 | bp->ntp_fltr_bmap = NULL; |
| 3351 | } |
| 3352 | bp->ntp_fltr_count = 0; |
| 3353 | #endif |
| 3354 | } |
| 3355 | |
| 3356 | static int bnxt_alloc_ntp_fltrs(struct bnxt *bp) |
| 3357 | { |
| 3358 | #ifdef CONFIG_RFS_ACCEL |
| 3359 | int i, rc = 0; |
| 3360 | |
| 3361 | if (!(bp->flags & BNXT_FLAG_RFS)) |
| 3362 | return 0; |
| 3363 | |
| 3364 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) |
| 3365 | INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]); |
| 3366 | |
| 3367 | bp->ntp_fltr_count = 0; |
Dan Carpenter | ac45bd9 | 2017-05-06 03:49:01 +0300 | [diff] [blame] | 3368 | bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR), |
| 3369 | sizeof(long), |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3370 | GFP_KERNEL); |
| 3371 | |
| 3372 | if (!bp->ntp_fltr_bmap) |
| 3373 | rc = -ENOMEM; |
| 3374 | |
| 3375 | return rc; |
| 3376 | #else |
| 3377 | return 0; |
| 3378 | #endif |
| 3379 | } |
| 3380 | |
| 3381 | static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init) |
| 3382 | { |
| 3383 | bnxt_free_vnic_attributes(bp); |
| 3384 | bnxt_free_tx_rings(bp); |
| 3385 | bnxt_free_rx_rings(bp); |
| 3386 | bnxt_free_cp_rings(bp); |
| 3387 | bnxt_free_ntp_fltrs(bp, irq_re_init); |
| 3388 | if (irq_re_init) { |
| 3389 | bnxt_free_stats(bp); |
| 3390 | bnxt_free_ring_grps(bp); |
| 3391 | bnxt_free_vnics(bp); |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 3392 | kfree(bp->tx_ring_map); |
| 3393 | bp->tx_ring_map = NULL; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3394 | kfree(bp->tx_ring); |
| 3395 | bp->tx_ring = NULL; |
| 3396 | kfree(bp->rx_ring); |
| 3397 | bp->rx_ring = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3398 | kfree(bp->bnapi); |
| 3399 | bp->bnapi = NULL; |
| 3400 | } else { |
| 3401 | bnxt_clear_ring_indices(bp); |
| 3402 | } |
| 3403 | } |
| 3404 | |
| 3405 | static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init) |
| 3406 | { |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 3407 | int i, j, rc, size, arr_size; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3408 | void *bnapi; |
| 3409 | |
| 3410 | if (irq_re_init) { |
| 3411 | /* Allocate bnapi mem pointer array and mem block for |
| 3412 | * all queues |
| 3413 | */ |
| 3414 | arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) * |
| 3415 | bp->cp_nr_rings); |
| 3416 | size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi)); |
| 3417 | bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL); |
| 3418 | if (!bnapi) |
| 3419 | return -ENOMEM; |
| 3420 | |
| 3421 | bp->bnapi = bnapi; |
| 3422 | bnapi += arr_size; |
| 3423 | for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) { |
| 3424 | bp->bnapi[i] = bnapi; |
| 3425 | bp->bnapi[i]->index = i; |
| 3426 | bp->bnapi[i]->bp = bp; |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 3427 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 3428 | struct bnxt_cp_ring_info *cpr = |
| 3429 | &bp->bnapi[i]->cp_ring; |
| 3430 | |
| 3431 | cpr->cp_ring_struct.ring_mem.flags = |
| 3432 | BNXT_RMEM_RING_PTE_FLAG; |
| 3433 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3434 | } |
| 3435 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3436 | bp->rx_ring = kcalloc(bp->rx_nr_rings, |
| 3437 | sizeof(struct bnxt_rx_ring_info), |
| 3438 | GFP_KERNEL); |
| 3439 | if (!bp->rx_ring) |
| 3440 | return -ENOMEM; |
| 3441 | |
| 3442 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 3443 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
| 3444 | |
| 3445 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 3446 | rxr->rx_ring_struct.ring_mem.flags = |
| 3447 | BNXT_RMEM_RING_PTE_FLAG; |
| 3448 | rxr->rx_agg_ring_struct.ring_mem.flags = |
| 3449 | BNXT_RMEM_RING_PTE_FLAG; |
| 3450 | } |
| 3451 | rxr->bnapi = bp->bnapi[i]; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3452 | bp->bnapi[i]->rx_ring = &bp->rx_ring[i]; |
| 3453 | } |
| 3454 | |
| 3455 | bp->tx_ring = kcalloc(bp->tx_nr_rings, |
| 3456 | sizeof(struct bnxt_tx_ring_info), |
| 3457 | GFP_KERNEL); |
| 3458 | if (!bp->tx_ring) |
| 3459 | return -ENOMEM; |
| 3460 | |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 3461 | bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16), |
| 3462 | GFP_KERNEL); |
| 3463 | |
| 3464 | if (!bp->tx_ring_map) |
| 3465 | return -ENOMEM; |
| 3466 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 3467 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 3468 | j = 0; |
| 3469 | else |
| 3470 | j = bp->rx_nr_rings; |
| 3471 | |
| 3472 | for (i = 0; i < bp->tx_nr_rings; i++, j++) { |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 3473 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
| 3474 | |
| 3475 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 3476 | txr->tx_ring_struct.ring_mem.flags = |
| 3477 | BNXT_RMEM_RING_PTE_FLAG; |
| 3478 | txr->bnapi = bp->bnapi[j]; |
| 3479 | bp->bnapi[j]->tx_ring = txr; |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 3480 | bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 3481 | if (i >= bp->tx_nr_rings_xdp) { |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 3482 | txr->txq_index = i - bp->tx_nr_rings_xdp; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 3483 | bp->bnapi[j]->tx_int = bnxt_tx_int; |
| 3484 | } else { |
Michael Chan | fa3e93e | 2017-02-06 16:55:41 -0500 | [diff] [blame] | 3485 | bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 3486 | bp->bnapi[j]->tx_int = bnxt_tx_int_xdp; |
| 3487 | } |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3488 | } |
| 3489 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3490 | rc = bnxt_alloc_stats(bp); |
| 3491 | if (rc) |
| 3492 | goto alloc_mem_err; |
| 3493 | |
| 3494 | rc = bnxt_alloc_ntp_fltrs(bp); |
| 3495 | if (rc) |
| 3496 | goto alloc_mem_err; |
| 3497 | |
| 3498 | rc = bnxt_alloc_vnics(bp); |
| 3499 | if (rc) |
| 3500 | goto alloc_mem_err; |
| 3501 | } |
| 3502 | |
| 3503 | bnxt_init_ring_struct(bp); |
| 3504 | |
| 3505 | rc = bnxt_alloc_rx_rings(bp); |
| 3506 | if (rc) |
| 3507 | goto alloc_mem_err; |
| 3508 | |
| 3509 | rc = bnxt_alloc_tx_rings(bp); |
| 3510 | if (rc) |
| 3511 | goto alloc_mem_err; |
| 3512 | |
| 3513 | rc = bnxt_alloc_cp_rings(bp); |
| 3514 | if (rc) |
| 3515 | goto alloc_mem_err; |
| 3516 | |
| 3517 | bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG | |
| 3518 | BNXT_VNIC_UCAST_FLAG; |
| 3519 | rc = bnxt_alloc_vnic_attributes(bp); |
| 3520 | if (rc) |
| 3521 | goto alloc_mem_err; |
| 3522 | return 0; |
| 3523 | |
| 3524 | alloc_mem_err: |
| 3525 | bnxt_free_mem(bp, true); |
| 3526 | return rc; |
| 3527 | } |
| 3528 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3529 | static void bnxt_disable_int(struct bnxt *bp) |
| 3530 | { |
| 3531 | int i; |
| 3532 | |
| 3533 | if (!bp->bnapi) |
| 3534 | return; |
| 3535 | |
| 3536 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3537 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3538 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | daf1f1e | 2017-02-20 19:25:17 -0500 | [diff] [blame] | 3539 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3540 | |
Michael Chan | daf1f1e | 2017-02-20 19:25:17 -0500 | [diff] [blame] | 3541 | if (ring->fw_ring_id != INVALID_HW_RING_ID) |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 3542 | bnxt_db_nq(bp, &cpr->cp_db, cpr->cp_raw_cons); |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3543 | } |
| 3544 | } |
| 3545 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 3546 | static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n) |
| 3547 | { |
| 3548 | struct bnxt_napi *bnapi = bp->bnapi[n]; |
| 3549 | struct bnxt_cp_ring_info *cpr; |
| 3550 | |
| 3551 | cpr = &bnapi->cp_ring; |
| 3552 | return cpr->cp_ring_struct.map_idx; |
| 3553 | } |
| 3554 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3555 | static void bnxt_disable_int_sync(struct bnxt *bp) |
| 3556 | { |
| 3557 | int i; |
| 3558 | |
| 3559 | atomic_inc(&bp->intr_sem); |
| 3560 | |
| 3561 | bnxt_disable_int(bp); |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 3562 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3563 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
| 3564 | |
| 3565 | synchronize_irq(bp->irq_tbl[map_idx].vector); |
| 3566 | } |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3567 | } |
| 3568 | |
| 3569 | static void bnxt_enable_int(struct bnxt *bp) |
| 3570 | { |
| 3571 | int i; |
| 3572 | |
| 3573 | atomic_set(&bp->intr_sem, 0); |
| 3574 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3575 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3576 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3577 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 3578 | bnxt_db_nq_arm(bp, &cpr->cp_db, cpr->cp_raw_cons); |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3582 | void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type, |
| 3583 | u16 cmpl_ring, u16 target_id) |
| 3584 | { |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3585 | struct input *req = request; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3586 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3587 | req->req_type = cpu_to_le16(req_type); |
| 3588 | req->cmpl_ring = cpu_to_le16(cmpl_ring); |
| 3589 | req->target_id = cpu_to_le16(target_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3590 | req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr); |
| 3591 | } |
| 3592 | |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3593 | static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len, |
| 3594 | int timeout, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3595 | { |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3596 | int i, intr_process, rc, tmo_count; |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3597 | struct input *req = msg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3598 | u32 *data = msg; |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3599 | __le32 *resp_len; |
| 3600 | u8 *valid; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3601 | u16 cp_ring_id, len = 0; |
| 3602 | struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3603 | u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN; |
Vasundhara Volam | ebd5818 | 2017-12-01 03:13:05 -0500 | [diff] [blame] | 3604 | struct hwrm_short_input short_input = {0}; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3605 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3606 | req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3607 | memset(resp, 0, PAGE_SIZE); |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3608 | cp_ring_id = le16_to_cpu(req->cmpl_ring); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3609 | intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1; |
| 3610 | |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 3611 | if (msg_len > BNXT_HWRM_MAX_REQ_LEN) { |
| 3612 | if (msg_len > bp->hwrm_max_ext_req_len || |
| 3613 | !bp->hwrm_short_cmd_req_addr) |
| 3614 | return -EINVAL; |
| 3615 | } |
| 3616 | |
| 3617 | if ((bp->fw_cap & BNXT_FW_CAP_SHORT_CMD) || |
| 3618 | msg_len > BNXT_HWRM_MAX_REQ_LEN) { |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3619 | void *short_cmd_req = bp->hwrm_short_cmd_req_addr; |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 3620 | u16 max_msg_len; |
| 3621 | |
| 3622 | /* Set boundary for maximum extended request length for short |
| 3623 | * cmd format. If passed up from device use the max supported |
| 3624 | * internal req length. |
| 3625 | */ |
| 3626 | max_msg_len = bp->hwrm_max_ext_req_len; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3627 | |
| 3628 | memcpy(short_cmd_req, req, msg_len); |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 3629 | if (msg_len < max_msg_len) |
| 3630 | memset(short_cmd_req + msg_len, 0, |
| 3631 | max_msg_len - msg_len); |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3632 | |
| 3633 | short_input.req_type = req->req_type; |
| 3634 | short_input.signature = |
| 3635 | cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD); |
| 3636 | short_input.size = cpu_to_le16(msg_len); |
| 3637 | short_input.req_addr = |
| 3638 | cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr); |
| 3639 | |
| 3640 | data = (u32 *)&short_input; |
| 3641 | msg_len = sizeof(short_input); |
| 3642 | |
| 3643 | /* Sync memory write before updating doorbell */ |
| 3644 | wmb(); |
| 3645 | |
| 3646 | max_req_len = BNXT_HWRM_SHORT_REQ_LEN; |
| 3647 | } |
| 3648 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3649 | /* Write request msg to hwrm channel */ |
| 3650 | __iowrite32_copy(bp->bar0, data, msg_len / 4); |
| 3651 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3652 | for (i = msg_len; i < max_req_len; i += 4) |
Michael Chan | d79979a | 2016-01-07 19:56:57 -0500 | [diff] [blame] | 3653 | writel(0, bp->bar0 + i); |
| 3654 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3655 | /* currently supports only one outstanding message */ |
| 3656 | if (intr_process) |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3657 | bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3658 | |
| 3659 | /* Ring channel doorbell */ |
| 3660 | writel(1, bp->bar0 + 0x100); |
| 3661 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 3662 | if (!timeout) |
| 3663 | timeout = DFLT_HWRM_CMD_TIMEOUT; |
Andy Gospodarek | 9751e8e | 2018-04-26 17:44:39 -0400 | [diff] [blame] | 3664 | /* convert timeout to usec */ |
| 3665 | timeout *= 1000; |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 3666 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3667 | i = 0; |
Andy Gospodarek | 9751e8e | 2018-04-26 17:44:39 -0400 | [diff] [blame] | 3668 | /* Short timeout for the first few iterations: |
| 3669 | * number of loops = number of loops for short timeout + |
| 3670 | * number of loops for standard timeout. |
| 3671 | */ |
| 3672 | tmo_count = HWRM_SHORT_TIMEOUT_COUNTER; |
| 3673 | timeout = timeout - HWRM_SHORT_MIN_TIMEOUT * HWRM_SHORT_TIMEOUT_COUNTER; |
| 3674 | tmo_count += DIV_ROUND_UP(timeout, HWRM_MIN_TIMEOUT); |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3675 | resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3676 | if (intr_process) { |
| 3677 | /* Wait until hwrm response cmpl interrupt is processed */ |
| 3678 | while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID && |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3679 | i++ < tmo_count) { |
Andy Gospodarek | 9751e8e | 2018-04-26 17:44:39 -0400 | [diff] [blame] | 3680 | /* on first few passes, just barely sleep */ |
| 3681 | if (i < HWRM_SHORT_TIMEOUT_COUNTER) |
| 3682 | usleep_range(HWRM_SHORT_MIN_TIMEOUT, |
| 3683 | HWRM_SHORT_MAX_TIMEOUT); |
| 3684 | else |
| 3685 | usleep_range(HWRM_MIN_TIMEOUT, |
| 3686 | HWRM_MAX_TIMEOUT); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3687 | } |
| 3688 | |
| 3689 | if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) { |
| 3690 | netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3691 | le16_to_cpu(req->req_type)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3692 | return -1; |
| 3693 | } |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3694 | len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> |
| 3695 | HWRM_RESP_LEN_SFT; |
| 3696 | valid = bp->hwrm_cmd_resp_addr + len - 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3697 | } else { |
Michael Chan | cc559c1 | 2018-05-08 03:18:38 -0400 | [diff] [blame] | 3698 | int j; |
| 3699 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3700 | /* Check if response len is updated */ |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3701 | for (i = 0; i < tmo_count; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3702 | len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> |
| 3703 | HWRM_RESP_LEN_SFT; |
| 3704 | if (len) |
| 3705 | break; |
Andy Gospodarek | 9751e8e | 2018-04-26 17:44:39 -0400 | [diff] [blame] | 3706 | /* on first few passes, just barely sleep */ |
| 3707 | if (i < DFLT_HWRM_CMD_TIMEOUT) |
| 3708 | usleep_range(HWRM_SHORT_MIN_TIMEOUT, |
| 3709 | HWRM_SHORT_MAX_TIMEOUT); |
| 3710 | else |
| 3711 | usleep_range(HWRM_MIN_TIMEOUT, |
| 3712 | HWRM_MAX_TIMEOUT); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3713 | } |
| 3714 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3715 | if (i >= tmo_count) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3716 | netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n", |
Michael Chan | cc559c1 | 2018-05-08 03:18:38 -0400 | [diff] [blame] | 3717 | HWRM_TOTAL_TIMEOUT(i), |
| 3718 | le16_to_cpu(req->req_type), |
Michael Chan | 8578d6c | 2016-05-15 03:04:48 -0400 | [diff] [blame] | 3719 | le16_to_cpu(req->seq_id), len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3720 | return -1; |
| 3721 | } |
| 3722 | |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3723 | /* Last byte of resp contains valid bit */ |
| 3724 | valid = bp->hwrm_cmd_resp_addr + len - 1; |
Michael Chan | cc559c1 | 2018-05-08 03:18:38 -0400 | [diff] [blame] | 3725 | for (j = 0; j < HWRM_VALID_BIT_DELAY_USEC; j++) { |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3726 | /* make sure we read from updated DMA memory */ |
| 3727 | dma_rmb(); |
| 3728 | if (*valid) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3729 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3730 | udelay(1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3731 | } |
| 3732 | |
Michael Chan | cc559c1 | 2018-05-08 03:18:38 -0400 | [diff] [blame] | 3733 | if (j >= HWRM_VALID_BIT_DELAY_USEC) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3734 | netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n", |
Michael Chan | cc559c1 | 2018-05-08 03:18:38 -0400 | [diff] [blame] | 3735 | HWRM_TOTAL_TIMEOUT(i), |
| 3736 | le16_to_cpu(req->req_type), |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3737 | le16_to_cpu(req->seq_id), len, *valid); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3738 | return -1; |
| 3739 | } |
| 3740 | } |
| 3741 | |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3742 | /* Zero valid bit for compatibility. Valid bit in an older spec |
| 3743 | * may become a new field in a newer spec. We must make sure that |
| 3744 | * a new field not implemented by old spec will read zero. |
| 3745 | */ |
| 3746 | *valid = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3747 | rc = le16_to_cpu(resp->error_code); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3748 | if (rc && !silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3749 | netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n", |
| 3750 | le16_to_cpu(resp->req_type), |
| 3751 | le16_to_cpu(resp->seq_id), rc); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3752 | return rc; |
| 3753 | } |
| 3754 | |
| 3755 | int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3756 | { |
| 3757 | return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3758 | } |
| 3759 | |
Michael Chan | cc72f3b | 2017-10-13 21:09:33 -0400 | [diff] [blame] | 3760 | int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len, |
| 3761 | int timeout) |
| 3762 | { |
| 3763 | return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true); |
| 3764 | } |
| 3765 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3766 | int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3767 | { |
| 3768 | int rc; |
| 3769 | |
| 3770 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3771 | rc = _hwrm_send_message(bp, msg, msg_len, timeout); |
| 3772 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3773 | return rc; |
| 3774 | } |
| 3775 | |
Michael Chan | 90e20921 | 2016-02-26 04:00:08 -0500 | [diff] [blame] | 3776 | int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len, |
| 3777 | int timeout) |
| 3778 | { |
| 3779 | int rc; |
| 3780 | |
| 3781 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3782 | rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true); |
| 3783 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3784 | return rc; |
| 3785 | } |
| 3786 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3787 | int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap, |
| 3788 | int bmap_size) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3789 | { |
| 3790 | struct hwrm_func_drv_rgtr_input req = {0}; |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3791 | DECLARE_BITMAP(async_events_bmap, 256); |
| 3792 | u32 *events = (u32 *)async_events_bmap; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3793 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3794 | |
| 3795 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3796 | |
| 3797 | req.enables = |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3798 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3799 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3800 | memset(async_events_bmap, 0, sizeof(async_events_bmap)); |
| 3801 | for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) |
| 3802 | __set_bit(bnxt_async_events_arr[i], async_events_bmap); |
| 3803 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3804 | if (bmap && bmap_size) { |
| 3805 | for (i = 0; i < bmap_size; i++) { |
| 3806 | if (test_bit(i, bmap)) |
| 3807 | __set_bit(i, async_events_bmap); |
| 3808 | } |
| 3809 | } |
| 3810 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3811 | for (i = 0; i < 8; i++) |
| 3812 | req.async_event_fwd[i] |= cpu_to_le32(events[i]); |
| 3813 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3814 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3815 | } |
| 3816 | |
| 3817 | static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp) |
| 3818 | { |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 3819 | struct hwrm_func_drv_rgtr_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3820 | struct hwrm_func_drv_rgtr_input req = {0}; |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 3821 | int rc; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3822 | |
| 3823 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3824 | |
| 3825 | req.enables = |
| 3826 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE | |
| 3827 | FUNC_DRV_RGTR_REQ_ENABLES_VER); |
| 3828 | |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 3829 | req.os_type = cpu_to_le16(FUNC_DRV_RGTR_REQ_OS_TYPE_LINUX); |
Michael Chan | d4f52de0 | 2018-03-31 13:54:06 -0400 | [diff] [blame] | 3830 | req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE); |
| 3831 | req.ver_maj_8b = DRV_VER_MAJ; |
| 3832 | req.ver_min_8b = DRV_VER_MIN; |
| 3833 | req.ver_upd_8b = DRV_VER_UPD; |
| 3834 | req.ver_maj = cpu_to_le16(DRV_VER_MAJ); |
| 3835 | req.ver_min = cpu_to_le16(DRV_VER_MIN); |
| 3836 | req.ver_upd = cpu_to_le16(DRV_VER_UPD); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3837 | |
| 3838 | if (BNXT_PF(bp)) { |
Michael Chan | 9b0436c | 2017-07-11 13:05:36 -0400 | [diff] [blame] | 3839 | u32 data[8]; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3840 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3841 | |
Michael Chan | 9b0436c | 2017-07-11 13:05:36 -0400 | [diff] [blame] | 3842 | memset(data, 0, sizeof(data)); |
| 3843 | for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) { |
| 3844 | u16 cmd = bnxt_vf_req_snif[i]; |
| 3845 | unsigned int bit, idx; |
| 3846 | |
| 3847 | idx = cmd / 32; |
| 3848 | bit = cmd % 32; |
| 3849 | data[idx] |= 1 << bit; |
| 3850 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3851 | |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3852 | for (i = 0; i < 8; i++) |
| 3853 | req.vf_req_fwd[i] = cpu_to_le32(data[i]); |
| 3854 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3855 | req.enables |= |
| 3856 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD); |
| 3857 | } |
| 3858 | |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 3859 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3860 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3861 | if (rc) |
| 3862 | rc = -EIO; |
| 3863 | else if (resp->flags & |
| 3864 | cpu_to_le32(FUNC_DRV_RGTR_RESP_FLAGS_IF_CHANGE_SUPPORTED)) |
| 3865 | bp->fw_cap |= BNXT_FW_CAP_IF_CHANGE; |
| 3866 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3867 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3868 | } |
| 3869 | |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 3870 | static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp) |
| 3871 | { |
| 3872 | struct hwrm_func_drv_unrgtr_input req = {0}; |
| 3873 | |
| 3874 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1); |
| 3875 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3876 | } |
| 3877 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3878 | static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type) |
| 3879 | { |
| 3880 | u32 rc = 0; |
| 3881 | struct hwrm_tunnel_dst_port_free_input req = {0}; |
| 3882 | |
| 3883 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1); |
| 3884 | req.tunnel_type = tunnel_type; |
| 3885 | |
| 3886 | switch (tunnel_type) { |
| 3887 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN: |
| 3888 | req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id; |
| 3889 | break; |
| 3890 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE: |
| 3891 | req.tunnel_dst_port_id = bp->nge_fw_dst_port_id; |
| 3892 | break; |
| 3893 | default: |
| 3894 | break; |
| 3895 | } |
| 3896 | |
| 3897 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3898 | if (rc) |
| 3899 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n", |
| 3900 | rc); |
| 3901 | return rc; |
| 3902 | } |
| 3903 | |
| 3904 | static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port, |
| 3905 | u8 tunnel_type) |
| 3906 | { |
| 3907 | u32 rc = 0; |
| 3908 | struct hwrm_tunnel_dst_port_alloc_input req = {0}; |
| 3909 | struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3910 | |
| 3911 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1); |
| 3912 | |
| 3913 | req.tunnel_type = tunnel_type; |
| 3914 | req.tunnel_dst_port_val = port; |
| 3915 | |
| 3916 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3917 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3918 | if (rc) { |
| 3919 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n", |
| 3920 | rc); |
| 3921 | goto err_out; |
| 3922 | } |
| 3923 | |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3924 | switch (tunnel_type) { |
| 3925 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3926 | bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3927 | break; |
| 3928 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3929 | bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3930 | break; |
| 3931 | default: |
| 3932 | break; |
| 3933 | } |
| 3934 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3935 | err_out: |
| 3936 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3937 | return rc; |
| 3938 | } |
| 3939 | |
| 3940 | static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id) |
| 3941 | { |
| 3942 | struct hwrm_cfa_l2_set_rx_mask_input req = {0}; |
| 3943 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3944 | |
| 3945 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_SET_RX_MASK, -1, -1); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3946 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3947 | |
| 3948 | req.num_mc_entries = cpu_to_le32(vnic->mc_list_count); |
| 3949 | req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping); |
| 3950 | req.mask = cpu_to_le32(vnic->rx_mask); |
| 3951 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3952 | } |
| 3953 | |
| 3954 | #ifdef CONFIG_RFS_ACCEL |
| 3955 | static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp, |
| 3956 | struct bnxt_ntuple_filter *fltr) |
| 3957 | { |
| 3958 | struct hwrm_cfa_ntuple_filter_free_input req = {0}; |
| 3959 | |
| 3960 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1); |
| 3961 | req.ntuple_filter_id = fltr->filter_id; |
| 3962 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3963 | } |
| 3964 | |
| 3965 | #define BNXT_NTP_FLTR_FLAGS \ |
| 3966 | (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \ |
| 3967 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \ |
| 3968 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \ |
| 3969 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \ |
| 3970 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \ |
| 3971 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \ |
| 3972 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \ |
| 3973 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \ |
| 3974 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \ |
| 3975 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \ |
| 3976 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \ |
| 3977 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \ |
| 3978 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \ |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3979 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3980 | |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 3981 | #define BNXT_NTP_TUNNEL_FLTR_FLAG \ |
| 3982 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE |
| 3983 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3984 | static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp, |
| 3985 | struct bnxt_ntuple_filter *fltr) |
| 3986 | { |
| 3987 | int rc = 0; |
| 3988 | struct hwrm_cfa_ntuple_filter_alloc_input req = {0}; |
| 3989 | struct hwrm_cfa_ntuple_filter_alloc_output *resp = |
| 3990 | bp->hwrm_cmd_resp_addr; |
| 3991 | struct flow_keys *keys = &fltr->fkeys; |
| 3992 | struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1]; |
| 3993 | |
| 3994 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_ALLOC, -1, -1); |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 3995 | req.l2_filter_id = bp->vnic_info[0].fw_l2_filter_id[fltr->l2_fltr_idx]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3996 | |
| 3997 | req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS); |
| 3998 | |
| 3999 | req.ethertype = htons(ETH_P_IP); |
| 4000 | memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4001 | req.ip_addr_type = CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV4; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4002 | req.ip_protocol = keys->basic.ip_proto; |
| 4003 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 4004 | if (keys->basic.n_proto == htons(ETH_P_IPV6)) { |
| 4005 | int i; |
| 4006 | |
| 4007 | req.ethertype = htons(ETH_P_IPV6); |
| 4008 | req.ip_addr_type = |
| 4009 | CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6; |
| 4010 | *(struct in6_addr *)&req.src_ipaddr[0] = |
| 4011 | keys->addrs.v6addrs.src; |
| 4012 | *(struct in6_addr *)&req.dst_ipaddr[0] = |
| 4013 | keys->addrs.v6addrs.dst; |
| 4014 | for (i = 0; i < 4; i++) { |
| 4015 | req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 4016 | req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 4017 | } |
| 4018 | } else { |
| 4019 | req.src_ipaddr[0] = keys->addrs.v4addrs.src; |
| 4020 | req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 4021 | req.dst_ipaddr[0] = keys->addrs.v4addrs.dst; |
| 4022 | req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 4023 | } |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 4024 | if (keys->control.flags & FLOW_DIS_ENCAPSULATION) { |
| 4025 | req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG); |
| 4026 | req.tunnel_type = |
| 4027 | CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL; |
| 4028 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4029 | |
| 4030 | req.src_port = keys->ports.src; |
| 4031 | req.src_port_mask = cpu_to_be16(0xffff); |
| 4032 | req.dst_port = keys->ports.dst; |
| 4033 | req.dst_port_mask = cpu_to_be16(0xffff); |
| 4034 | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4035 | req.dst_id = cpu_to_le16(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4036 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4037 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4038 | if (!rc) |
| 4039 | fltr->filter_id = resp->ntuple_filter_id; |
| 4040 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4041 | return rc; |
| 4042 | } |
| 4043 | #endif |
| 4044 | |
| 4045 | static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx, |
| 4046 | u8 *mac_addr) |
| 4047 | { |
| 4048 | u32 rc = 0; |
| 4049 | struct hwrm_cfa_l2_filter_alloc_input req = {0}; |
| 4050 | struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 4051 | |
| 4052 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_ALLOC, -1, -1); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4053 | req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX); |
| 4054 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4055 | req.flags |= |
| 4056 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4057 | req.dst_id = cpu_to_le16(bp->vnic_info[vnic_id].fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4058 | req.enables = |
| 4059 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4060 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4061 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK); |
| 4062 | memcpy(req.l2_addr, mac_addr, ETH_ALEN); |
| 4063 | req.l2_addr_mask[0] = 0xff; |
| 4064 | req.l2_addr_mask[1] = 0xff; |
| 4065 | req.l2_addr_mask[2] = 0xff; |
| 4066 | req.l2_addr_mask[3] = 0xff; |
| 4067 | req.l2_addr_mask[4] = 0xff; |
| 4068 | req.l2_addr_mask[5] = 0xff; |
| 4069 | |
| 4070 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4071 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4072 | if (!rc) |
| 4073 | bp->vnic_info[vnic_id].fw_l2_filter_id[idx] = |
| 4074 | resp->l2_filter_id; |
| 4075 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4076 | return rc; |
| 4077 | } |
| 4078 | |
| 4079 | static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp) |
| 4080 | { |
| 4081 | u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */ |
| 4082 | int rc = 0; |
| 4083 | |
| 4084 | /* Any associated ntuple filters will also be cleared by firmware. */ |
| 4085 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4086 | for (i = 0; i < num_of_vnics; i++) { |
| 4087 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 4088 | |
| 4089 | for (j = 0; j < vnic->uc_filter_count; j++) { |
| 4090 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 4091 | |
| 4092 | bnxt_hwrm_cmd_hdr_init(bp, &req, |
| 4093 | HWRM_CFA_L2_FILTER_FREE, -1, -1); |
| 4094 | |
| 4095 | req.l2_filter_id = vnic->fw_l2_filter_id[j]; |
| 4096 | |
| 4097 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4098 | HWRM_CMD_TIMEOUT); |
| 4099 | } |
| 4100 | vnic->uc_filter_count = 0; |
| 4101 | } |
| 4102 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4103 | |
| 4104 | return rc; |
| 4105 | } |
| 4106 | |
| 4107 | static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags) |
| 4108 | { |
| 4109 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 4110 | struct hwrm_vnic_tpa_cfg_input req = {0}; |
| 4111 | |
Michael Chan | 3c4fe80 | 2018-03-09 23:46:10 -0500 | [diff] [blame] | 4112 | if (vnic->fw_vnic_id == INVALID_HW_RING_ID) |
| 4113 | return 0; |
| 4114 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4115 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1); |
| 4116 | |
| 4117 | if (tpa_flags) { |
| 4118 | u16 mss = bp->dev->mtu - 40; |
| 4119 | u32 nsegs, n, segs = 0, flags; |
| 4120 | |
| 4121 | flags = VNIC_TPA_CFG_REQ_FLAGS_TPA | |
| 4122 | VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA | |
| 4123 | VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE | |
| 4124 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN | |
| 4125 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ; |
| 4126 | if (tpa_flags & BNXT_FLAG_GRO) |
| 4127 | flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO; |
| 4128 | |
| 4129 | req.flags = cpu_to_le32(flags); |
| 4130 | |
| 4131 | req.enables = |
| 4132 | cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4133 | VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS | |
| 4134 | VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4135 | |
| 4136 | /* Number of segs are log2 units, and first packet is not |
| 4137 | * included as part of this units. |
| 4138 | */ |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 4139 | if (mss <= BNXT_RX_PAGE_SIZE) { |
| 4140 | n = BNXT_RX_PAGE_SIZE / mss; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4141 | nsegs = (MAX_SKB_FRAGS - 1) * n; |
| 4142 | } else { |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 4143 | n = mss / BNXT_RX_PAGE_SIZE; |
| 4144 | if (mss & (BNXT_RX_PAGE_SIZE - 1)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4145 | n++; |
| 4146 | nsegs = (MAX_SKB_FRAGS - n) / n; |
| 4147 | } |
| 4148 | |
| 4149 | segs = ilog2(nsegs); |
| 4150 | req.max_agg_segs = cpu_to_le16(segs); |
| 4151 | req.max_aggs = cpu_to_le16(VNIC_TPA_CFG_REQ_MAX_AGGS_MAX); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 4152 | |
| 4153 | req.min_agg_len = cpu_to_le32(512); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4154 | } |
| 4155 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 4156 | |
| 4157 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4158 | } |
| 4159 | |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4160 | static u16 bnxt_cp_ring_from_grp(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 4161 | { |
| 4162 | struct bnxt_ring_grp_info *grp_info; |
| 4163 | |
| 4164 | grp_info = &bp->grp_info[ring->grp_idx]; |
| 4165 | return grp_info->cp_fw_ring_id; |
| 4166 | } |
| 4167 | |
| 4168 | static u16 bnxt_cp_ring_for_rx(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) |
| 4169 | { |
| 4170 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4171 | struct bnxt_napi *bnapi = rxr->bnapi; |
| 4172 | struct bnxt_cp_ring_info *cpr; |
| 4173 | |
| 4174 | cpr = bnapi->cp_ring.cp_ring_arr[BNXT_RX_HDL]; |
| 4175 | return cpr->cp_ring_struct.fw_ring_id; |
| 4176 | } else { |
| 4177 | return bnxt_cp_ring_from_grp(bp, &rxr->rx_ring_struct); |
| 4178 | } |
| 4179 | } |
| 4180 | |
| 4181 | static u16 bnxt_cp_ring_for_tx(struct bnxt *bp, struct bnxt_tx_ring_info *txr) |
| 4182 | { |
| 4183 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4184 | struct bnxt_napi *bnapi = txr->bnapi; |
| 4185 | struct bnxt_cp_ring_info *cpr; |
| 4186 | |
| 4187 | cpr = bnapi->cp_ring.cp_ring_arr[BNXT_TX_HDL]; |
| 4188 | return cpr->cp_ring_struct.fw_ring_id; |
| 4189 | } else { |
| 4190 | return bnxt_cp_ring_from_grp(bp, &txr->tx_ring_struct); |
| 4191 | } |
| 4192 | } |
| 4193 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4194 | static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss) |
| 4195 | { |
| 4196 | u32 i, j, max_rings; |
| 4197 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 4198 | struct hwrm_vnic_rss_cfg_input req = {0}; |
| 4199 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4200 | if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4201 | return 0; |
| 4202 | |
| 4203 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1); |
| 4204 | if (set_rss) { |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 4205 | req.hash_type = cpu_to_le32(bp->rss_hash_cfg); |
Michael Chan | 50f011b | 2018-08-05 16:51:51 -0400 | [diff] [blame] | 4206 | req.hash_mode_flags = VNIC_RSS_CFG_REQ_HASH_MODE_FLAGS_DEFAULT; |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4207 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) { |
| 4208 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4209 | max_rings = bp->rx_nr_rings - 1; |
| 4210 | else |
| 4211 | max_rings = bp->rx_nr_rings; |
| 4212 | } else { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4213 | max_rings = 1; |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4214 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4215 | |
| 4216 | /* Fill the RSS indirection table with ring group ids */ |
| 4217 | for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) { |
| 4218 | if (j == max_rings) |
| 4219 | j = 0; |
| 4220 | vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]); |
| 4221 | } |
| 4222 | |
| 4223 | req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr); |
| 4224 | req.hash_key_tbl_addr = |
| 4225 | cpu_to_le64(vnic->rss_hash_key_dma_addr); |
| 4226 | } |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4227 | req.rss_ctx_idx = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4228 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4229 | } |
| 4230 | |
| 4231 | static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id) |
| 4232 | { |
| 4233 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 4234 | struct hwrm_vnic_plcmodes_cfg_input req = {0}; |
| 4235 | |
| 4236 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1); |
| 4237 | req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT | |
| 4238 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 | |
| 4239 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6); |
| 4240 | req.enables = |
| 4241 | cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID | |
| 4242 | VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID); |
| 4243 | /* thresholds not implemented in firmware yet */ |
| 4244 | req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh); |
| 4245 | req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh); |
| 4246 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
| 4247 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4248 | } |
| 4249 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4250 | static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id, |
| 4251 | u16 ctx_idx) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4252 | { |
| 4253 | struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0}; |
| 4254 | |
| 4255 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1); |
| 4256 | req.rss_cos_lb_ctx_id = |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4257 | cpu_to_le16(bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx]); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4258 | |
| 4259 | hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4260 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4261 | } |
| 4262 | |
| 4263 | static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp) |
| 4264 | { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4265 | int i, j; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4266 | |
| 4267 | for (i = 0; i < bp->nr_vnics; i++) { |
| 4268 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 4269 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4270 | for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) { |
| 4271 | if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID) |
| 4272 | bnxt_hwrm_vnic_ctx_free_one(bp, i, j); |
| 4273 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4274 | } |
| 4275 | bp->rsscos_nr_ctxs = 0; |
| 4276 | } |
| 4277 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4278 | static int bnxt_hwrm_vnic_ctx_alloc(struct bnxt *bp, u16 vnic_id, u16 ctx_idx) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4279 | { |
| 4280 | int rc; |
| 4281 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0}; |
| 4282 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp = |
| 4283 | bp->hwrm_cmd_resp_addr; |
| 4284 | |
| 4285 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1, |
| 4286 | -1); |
| 4287 | |
| 4288 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4289 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4290 | if (!rc) |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4291 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4292 | le16_to_cpu(resp->rss_cos_lb_ctx_id); |
| 4293 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4294 | |
| 4295 | return rc; |
| 4296 | } |
| 4297 | |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4298 | static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp) |
| 4299 | { |
| 4300 | if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP) |
| 4301 | return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE; |
| 4302 | return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE; |
| 4303 | } |
| 4304 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 4305 | int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4306 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4307 | unsigned int ring = 0, grp_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4308 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 4309 | struct hwrm_vnic_cfg_input req = {0}; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4310 | u16 def_vlan = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4311 | |
| 4312 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4313 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4314 | req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP); |
| 4315 | /* Only RSS support for now TBD: COS & LB */ |
| 4316 | if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) { |
| 4317 | req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]); |
| 4318 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 4319 | VNIC_CFG_REQ_ENABLES_MRU); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4320 | } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) { |
| 4321 | req.rss_rule = |
| 4322 | cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]); |
| 4323 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 4324 | VNIC_CFG_REQ_ENABLES_MRU); |
| 4325 | req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_RSS_DFLT_CR_MODE); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4326 | } else { |
| 4327 | req.rss_rule = cpu_to_le16(0xffff); |
| 4328 | } |
| 4329 | |
| 4330 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && |
| 4331 | (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4332 | req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]); |
| 4333 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE); |
| 4334 | } else { |
| 4335 | req.cos_rule = cpu_to_le16(0xffff); |
| 4336 | } |
| 4337 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4338 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4339 | ring = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4340 | else if (vnic->flags & BNXT_VNIC_RFS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4341 | ring = vnic_id - 1; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4342 | else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4343 | ring = bp->rx_nr_rings - 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4344 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4345 | grp_idx = bp->rx_ring[ring].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4346 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 4347 | req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id); |
| 4348 | |
| 4349 | req.lb_rule = cpu_to_le16(0xffff); |
| 4350 | req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + |
| 4351 | VLAN_HLEN); |
| 4352 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4353 | #ifdef CONFIG_BNXT_SRIOV |
| 4354 | if (BNXT_VF(bp)) |
| 4355 | def_vlan = bp->vf.vlan; |
| 4356 | #endif |
| 4357 | if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4358 | req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 4359 | if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP)) |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4360 | req.flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4361 | |
| 4362 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4363 | } |
| 4364 | |
| 4365 | static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id) |
| 4366 | { |
| 4367 | u32 rc = 0; |
| 4368 | |
| 4369 | if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) { |
| 4370 | struct hwrm_vnic_free_input req = {0}; |
| 4371 | |
| 4372 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1); |
| 4373 | req.vnic_id = |
| 4374 | cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id); |
| 4375 | |
| 4376 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4377 | if (rc) |
| 4378 | return rc; |
| 4379 | bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID; |
| 4380 | } |
| 4381 | return rc; |
| 4382 | } |
| 4383 | |
| 4384 | static void bnxt_hwrm_vnic_free(struct bnxt *bp) |
| 4385 | { |
| 4386 | u16 i; |
| 4387 | |
| 4388 | for (i = 0; i < bp->nr_vnics; i++) |
| 4389 | bnxt_hwrm_vnic_free_one(bp, i); |
| 4390 | } |
| 4391 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4392 | static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id, |
| 4393 | unsigned int start_rx_ring_idx, |
| 4394 | unsigned int nr_rings) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4395 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4396 | int rc = 0; |
| 4397 | unsigned int i, j, grp_idx, end_idx = start_rx_ring_idx + nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4398 | struct hwrm_vnic_alloc_input req = {0}; |
| 4399 | struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 4400 | |
| 4401 | /* map ring groups to this vnic */ |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4402 | for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) { |
| 4403 | grp_idx = bp->rx_ring[i].bnapi->index; |
| 4404 | if (bp->grp_info[grp_idx].fw_grp_id == INVALID_HW_RING_ID) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4405 | netdev_err(bp->dev, "Not enough ring groups avail:%x req:%x\n", |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4406 | j, nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4407 | break; |
| 4408 | } |
| 4409 | bp->vnic_info[vnic_id].fw_grp_ids[j] = |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4410 | bp->grp_info[grp_idx].fw_grp_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4411 | } |
| 4412 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4413 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 4414 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4415 | if (vnic_id == 0) |
| 4416 | req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT); |
| 4417 | |
| 4418 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1); |
| 4419 | |
| 4420 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4421 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4422 | if (!rc) |
| 4423 | bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id); |
| 4424 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4425 | return rc; |
| 4426 | } |
| 4427 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 4428 | static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp) |
| 4429 | { |
| 4430 | struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 4431 | struct hwrm_vnic_qcaps_input req = {0}; |
| 4432 | int rc; |
| 4433 | |
| 4434 | if (bp->hwrm_spec_code < 0x10600) |
| 4435 | return 0; |
| 4436 | |
| 4437 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1); |
| 4438 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4439 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4440 | if (!rc) { |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4441 | u32 flags = le32_to_cpu(resp->flags); |
| 4442 | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 4443 | if (!(bp->flags & BNXT_FLAG_CHIP_P5) && |
| 4444 | (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP)) |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 4445 | bp->flags |= BNXT_FLAG_NEW_RSS_CAP; |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4446 | if (flags & |
| 4447 | VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP) |
| 4448 | bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP; |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 4449 | } |
| 4450 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4451 | return rc; |
| 4452 | } |
| 4453 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4454 | static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp) |
| 4455 | { |
| 4456 | u16 i; |
| 4457 | u32 rc = 0; |
| 4458 | |
| 4459 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4460 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 4461 | struct hwrm_ring_grp_alloc_input req = {0}; |
| 4462 | struct hwrm_ring_grp_alloc_output *resp = |
| 4463 | bp->hwrm_cmd_resp_addr; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4464 | unsigned int grp_idx = bp->rx_ring[i].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4465 | |
| 4466 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1); |
| 4467 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4468 | req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id); |
| 4469 | req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id); |
| 4470 | req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id); |
| 4471 | req.sc = cpu_to_le16(bp->grp_info[grp_idx].fw_stats_ctx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4472 | |
| 4473 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4474 | HWRM_CMD_TIMEOUT); |
| 4475 | if (rc) |
| 4476 | break; |
| 4477 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4478 | bp->grp_info[grp_idx].fw_grp_id = |
| 4479 | le32_to_cpu(resp->ring_group_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4480 | } |
| 4481 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4482 | return rc; |
| 4483 | } |
| 4484 | |
| 4485 | static int bnxt_hwrm_ring_grp_free(struct bnxt *bp) |
| 4486 | { |
| 4487 | u16 i; |
| 4488 | u32 rc = 0; |
| 4489 | struct hwrm_ring_grp_free_input req = {0}; |
| 4490 | |
| 4491 | if (!bp->grp_info) |
| 4492 | return 0; |
| 4493 | |
| 4494 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1); |
| 4495 | |
| 4496 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4497 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4498 | if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID) |
| 4499 | continue; |
| 4500 | req.ring_group_id = |
| 4501 | cpu_to_le32(bp->grp_info[i].fw_grp_id); |
| 4502 | |
| 4503 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4504 | HWRM_CMD_TIMEOUT); |
| 4505 | if (rc) |
| 4506 | break; |
| 4507 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 4508 | } |
| 4509 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4510 | return rc; |
| 4511 | } |
| 4512 | |
| 4513 | static int hwrm_ring_alloc_send_msg(struct bnxt *bp, |
| 4514 | struct bnxt_ring_struct *ring, |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4515 | u32 ring_type, u32 map_index) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4516 | { |
| 4517 | int rc = 0, err = 0; |
| 4518 | struct hwrm_ring_alloc_input req = {0}; |
| 4519 | struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 4520 | struct bnxt_ring_mem_info *rmem = &ring->ring_mem; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4521 | struct bnxt_ring_grp_info *grp_info; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4522 | u16 ring_id; |
| 4523 | |
| 4524 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1); |
| 4525 | |
| 4526 | req.enables = 0; |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 4527 | if (rmem->nr_pages > 1) { |
| 4528 | req.page_tbl_addr = cpu_to_le64(rmem->pg_tbl_map); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4529 | /* Page size is in log2 units */ |
| 4530 | req.page_size = BNXT_PAGE_SHIFT; |
| 4531 | req.page_tbl_depth = 1; |
| 4532 | } else { |
Michael Chan | 6fe1988 | 2018-10-14 07:02:41 -0400 | [diff] [blame] | 4533 | req.page_tbl_addr = cpu_to_le64(rmem->dma_arr[0]); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4534 | } |
| 4535 | req.fbo = 0; |
| 4536 | /* Association of ring index with doorbell index and MSIX number */ |
| 4537 | req.logical_id = cpu_to_le16(map_index); |
| 4538 | |
| 4539 | switch (ring_type) { |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4540 | case HWRM_RING_ALLOC_TX: { |
| 4541 | struct bnxt_tx_ring_info *txr; |
| 4542 | |
| 4543 | txr = container_of(ring, struct bnxt_tx_ring_info, |
| 4544 | tx_ring_struct); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4545 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX; |
| 4546 | /* Association of transmit ring with completion ring */ |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4547 | grp_info = &bp->grp_info[ring->grp_idx]; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4548 | req.cmpl_ring_id = cpu_to_le16(bnxt_cp_ring_for_tx(bp, txr)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4549 | req.length = cpu_to_le32(bp->tx_ring_mask + 1); |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4550 | req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4551 | req.queue_id = cpu_to_le16(ring->queue_id); |
| 4552 | break; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4553 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4554 | case HWRM_RING_ALLOC_RX: |
| 4555 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 4556 | req.length = cpu_to_le32(bp->rx_ring_mask + 1); |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4557 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4558 | u16 flags = 0; |
| 4559 | |
| 4560 | /* Association of rx ring with stats context */ |
| 4561 | grp_info = &bp->grp_info[ring->grp_idx]; |
| 4562 | req.rx_buf_size = cpu_to_le16(bp->rx_buf_use_size); |
| 4563 | req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx); |
| 4564 | req.enables |= cpu_to_le32( |
| 4565 | RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID); |
| 4566 | if (NET_IP_ALIGN == 2) |
| 4567 | flags = RING_ALLOC_REQ_FLAGS_RX_SOP_PAD; |
| 4568 | req.flags = cpu_to_le16(flags); |
| 4569 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4570 | break; |
| 4571 | case HWRM_RING_ALLOC_AGG: |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4572 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4573 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX_AGG; |
| 4574 | /* Association of agg ring with rx ring */ |
| 4575 | grp_info = &bp->grp_info[ring->grp_idx]; |
| 4576 | req.rx_ring_id = cpu_to_le16(grp_info->rx_fw_ring_id); |
| 4577 | req.rx_buf_size = cpu_to_le16(BNXT_RX_PAGE_SIZE); |
| 4578 | req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx); |
| 4579 | req.enables |= cpu_to_le32( |
| 4580 | RING_ALLOC_REQ_ENABLES_RX_RING_ID_VALID | |
| 4581 | RING_ALLOC_REQ_ENABLES_RX_BUF_SIZE_VALID); |
| 4582 | } else { |
| 4583 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 4584 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4585 | req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1); |
| 4586 | break; |
| 4587 | case HWRM_RING_ALLOC_CMPL: |
Michael Chan | bac9a7e | 2017-02-12 19:18:10 -0500 | [diff] [blame] | 4588 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4589 | req.length = cpu_to_le32(bp->cp_ring_mask + 1); |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4590 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4591 | /* Association of cp ring with nq */ |
| 4592 | grp_info = &bp->grp_info[map_index]; |
| 4593 | req.nq_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id); |
| 4594 | req.cq_handle = cpu_to_le64(ring->handle); |
| 4595 | req.enables |= cpu_to_le32( |
| 4596 | RING_ALLOC_REQ_ENABLES_NQ_RING_ID_VALID); |
| 4597 | } else if (bp->flags & BNXT_FLAG_USING_MSIX) { |
| 4598 | req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX; |
| 4599 | } |
| 4600 | break; |
| 4601 | case HWRM_RING_ALLOC_NQ: |
| 4602 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_NQ; |
| 4603 | req.length = cpu_to_le32(bp->cp_ring_mask + 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4604 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 4605 | req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX; |
| 4606 | break; |
| 4607 | default: |
| 4608 | netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n", |
| 4609 | ring_type); |
| 4610 | return -1; |
| 4611 | } |
| 4612 | |
| 4613 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4614 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4615 | err = le16_to_cpu(resp->error_code); |
| 4616 | ring_id = le16_to_cpu(resp->ring_id); |
| 4617 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4618 | |
| 4619 | if (rc || err) { |
Michael Chan | 2727c88 | 2018-04-26 17:44:35 -0400 | [diff] [blame] | 4620 | netdev_err(bp->dev, "hwrm_ring_alloc type %d failed. rc:%x err:%x\n", |
| 4621 | ring_type, rc, err); |
| 4622 | return -EIO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4623 | } |
| 4624 | ring->fw_ring_id = ring_id; |
| 4625 | return rc; |
| 4626 | } |
| 4627 | |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 4628 | static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx) |
| 4629 | { |
| 4630 | int rc; |
| 4631 | |
| 4632 | if (BNXT_PF(bp)) { |
| 4633 | struct hwrm_func_cfg_input req = {0}; |
| 4634 | |
| 4635 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 4636 | req.fid = cpu_to_le16(0xffff); |
| 4637 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 4638 | req.async_event_cr = cpu_to_le16(idx); |
| 4639 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4640 | } else { |
| 4641 | struct hwrm_func_vf_cfg_input req = {0}; |
| 4642 | |
| 4643 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); |
| 4644 | req.enables = |
| 4645 | cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 4646 | req.async_event_cr = cpu_to_le16(idx); |
| 4647 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4648 | } |
| 4649 | return rc; |
| 4650 | } |
| 4651 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4652 | static void bnxt_set_db(struct bnxt *bp, struct bnxt_db_info *db, u32 ring_type, |
| 4653 | u32 map_idx, u32 xid) |
| 4654 | { |
| 4655 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4656 | if (BNXT_PF(bp)) |
| 4657 | db->doorbell = bp->bar1 + 0x10000; |
| 4658 | else |
| 4659 | db->doorbell = bp->bar1 + 0x4000; |
| 4660 | switch (ring_type) { |
| 4661 | case HWRM_RING_ALLOC_TX: |
| 4662 | db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SQ; |
| 4663 | break; |
| 4664 | case HWRM_RING_ALLOC_RX: |
| 4665 | case HWRM_RING_ALLOC_AGG: |
| 4666 | db->db_key64 = DBR_PATH_L2 | DBR_TYPE_SRQ; |
| 4667 | break; |
| 4668 | case HWRM_RING_ALLOC_CMPL: |
| 4669 | db->db_key64 = DBR_PATH_L2; |
| 4670 | break; |
| 4671 | case HWRM_RING_ALLOC_NQ: |
| 4672 | db->db_key64 = DBR_PATH_L2; |
| 4673 | break; |
| 4674 | } |
| 4675 | db->db_key64 |= (u64)xid << DBR_XID_SFT; |
| 4676 | } else { |
| 4677 | db->doorbell = bp->bar1 + map_idx * 0x80; |
| 4678 | switch (ring_type) { |
| 4679 | case HWRM_RING_ALLOC_TX: |
| 4680 | db->db_key32 = DB_KEY_TX; |
| 4681 | break; |
| 4682 | case HWRM_RING_ALLOC_RX: |
| 4683 | case HWRM_RING_ALLOC_AGG: |
| 4684 | db->db_key32 = DB_KEY_RX; |
| 4685 | break; |
| 4686 | case HWRM_RING_ALLOC_CMPL: |
| 4687 | db->db_key32 = DB_KEY_CP; |
| 4688 | break; |
| 4689 | } |
| 4690 | } |
| 4691 | } |
| 4692 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4693 | static int bnxt_hwrm_ring_alloc(struct bnxt *bp) |
| 4694 | { |
| 4695 | int i, rc = 0; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4696 | u32 type; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4697 | |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4698 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 4699 | type = HWRM_RING_ALLOC_NQ; |
| 4700 | else |
| 4701 | type = HWRM_RING_ALLOC_CMPL; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4702 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4703 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4704 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4705 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4706 | u32 map_idx = ring->map_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4707 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4708 | rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4709 | if (rc) |
| 4710 | goto err_out; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4711 | bnxt_set_db(bp, &cpr->cp_db, type, map_idx, ring->fw_ring_id); |
| 4712 | bnxt_db_nq(bp, &cpr->cp_db, cpr->cp_raw_cons); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4713 | bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id; |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 4714 | |
| 4715 | if (!i) { |
| 4716 | rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id); |
| 4717 | if (rc) |
| 4718 | netdev_warn(bp->dev, "Failed to set async event completion ring.\n"); |
| 4719 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4720 | } |
| 4721 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4722 | type = HWRM_RING_ALLOC_TX; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4723 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4724 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 4725 | struct bnxt_ring_struct *ring; |
| 4726 | u32 map_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4727 | |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 4728 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4729 | struct bnxt_napi *bnapi = txr->bnapi; |
| 4730 | struct bnxt_cp_ring_info *cpr, *cpr2; |
| 4731 | u32 type2 = HWRM_RING_ALLOC_CMPL; |
| 4732 | |
| 4733 | cpr = &bnapi->cp_ring; |
| 4734 | cpr2 = cpr->cp_ring_arr[BNXT_TX_HDL]; |
| 4735 | ring = &cpr2->cp_ring_struct; |
| 4736 | ring->handle = BNXT_TX_HDL; |
| 4737 | map_idx = bnapi->index; |
| 4738 | rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx); |
| 4739 | if (rc) |
| 4740 | goto err_out; |
| 4741 | bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx, |
| 4742 | ring->fw_ring_id); |
| 4743 | bnxt_db_cq(bp, &cpr2->cp_db, cpr2->cp_raw_cons); |
| 4744 | } |
| 4745 | ring = &txr->tx_ring_struct; |
| 4746 | map_idx = i; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4747 | rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4748 | if (rc) |
| 4749 | goto err_out; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4750 | bnxt_set_db(bp, &txr->tx_db, type, map_idx, ring->fw_ring_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4751 | } |
| 4752 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4753 | type = HWRM_RING_ALLOC_RX; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4754 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4755 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4756 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 4757 | struct bnxt_napi *bnapi = rxr->bnapi; |
| 4758 | u32 map_idx = bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4759 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4760 | rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4761 | if (rc) |
| 4762 | goto err_out; |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4763 | bnxt_set_db(bp, &rxr->rx_db, type, map_idx, ring->fw_ring_id); |
| 4764 | bnxt_db_write(bp, &rxr->rx_db, rxr->rx_prod); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4765 | bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id; |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 4766 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4767 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4768 | u32 type2 = HWRM_RING_ALLOC_CMPL; |
| 4769 | struct bnxt_cp_ring_info *cpr2; |
| 4770 | |
| 4771 | cpr2 = cpr->cp_ring_arr[BNXT_RX_HDL]; |
| 4772 | ring = &cpr2->cp_ring_struct; |
| 4773 | ring->handle = BNXT_RX_HDL; |
| 4774 | rc = hwrm_ring_alloc_send_msg(bp, ring, type2, map_idx); |
| 4775 | if (rc) |
| 4776 | goto err_out; |
| 4777 | bnxt_set_db(bp, &cpr2->cp_db, type2, map_idx, |
| 4778 | ring->fw_ring_id); |
| 4779 | bnxt_db_cq(bp, &cpr2->cp_db, cpr2->cp_raw_cons); |
| 4780 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4781 | } |
| 4782 | |
| 4783 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4784 | type = HWRM_RING_ALLOC_AGG; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4785 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4786 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4787 | struct bnxt_ring_struct *ring = |
| 4788 | &rxr->rx_agg_ring_struct; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4789 | u32 grp_idx = ring->grp_idx; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4790 | u32 map_idx = grp_idx + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4791 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4792 | rc = hwrm_ring_alloc_send_msg(bp, ring, type, map_idx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4793 | if (rc) |
| 4794 | goto err_out; |
| 4795 | |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 4796 | bnxt_set_db(bp, &rxr->rx_agg_db, type, map_idx, |
| 4797 | ring->fw_ring_id); |
| 4798 | bnxt_db_write(bp, &rxr->rx_agg_db, rxr->rx_agg_prod); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4799 | bp->grp_info[grp_idx].agg_fw_ring_id = ring->fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4800 | } |
| 4801 | } |
| 4802 | err_out: |
| 4803 | return rc; |
| 4804 | } |
| 4805 | |
| 4806 | static int hwrm_ring_free_send_msg(struct bnxt *bp, |
| 4807 | struct bnxt_ring_struct *ring, |
| 4808 | u32 ring_type, int cmpl_ring_id) |
| 4809 | { |
| 4810 | int rc; |
| 4811 | struct hwrm_ring_free_input req = {0}; |
| 4812 | struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr; |
| 4813 | u16 error_code; |
| 4814 | |
Prashant Sreedharan | 74608fc | 2016-01-28 03:11:20 -0500 | [diff] [blame] | 4815 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_FREE, cmpl_ring_id, -1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4816 | req.ring_type = ring_type; |
| 4817 | req.ring_id = cpu_to_le16(ring->fw_ring_id); |
| 4818 | |
| 4819 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4820 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4821 | error_code = le16_to_cpu(resp->error_code); |
| 4822 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4823 | |
| 4824 | if (rc || error_code) { |
Michael Chan | 2727c88 | 2018-04-26 17:44:35 -0400 | [diff] [blame] | 4825 | netdev_err(bp->dev, "hwrm_ring_free type %d failed. rc:%x err:%x\n", |
| 4826 | ring_type, rc, error_code); |
| 4827 | return -EIO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4828 | } |
| 4829 | return 0; |
| 4830 | } |
| 4831 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4832 | static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4833 | { |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4834 | u32 type; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4835 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4836 | |
| 4837 | if (!bp->bnapi) |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4838 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4839 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4840 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4841 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4842 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4843 | u32 cmpl_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4844 | |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4845 | cmpl_ring_id = bnxt_cp_ring_for_tx(bp, txr); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4846 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4847 | hwrm_ring_free_send_msg(bp, ring, |
| 4848 | RING_FREE_REQ_RING_TYPE_TX, |
| 4849 | close_path ? cmpl_ring_id : |
| 4850 | INVALID_HW_RING_ID); |
| 4851 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4852 | } |
| 4853 | } |
| 4854 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4855 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4856 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4857 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4858 | u32 grp_idx = rxr->bnapi->index; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4859 | u32 cmpl_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4860 | |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4861 | cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4862 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4863 | hwrm_ring_free_send_msg(bp, ring, |
| 4864 | RING_FREE_REQ_RING_TYPE_RX, |
| 4865 | close_path ? cmpl_ring_id : |
| 4866 | INVALID_HW_RING_ID); |
| 4867 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4868 | bp->grp_info[grp_idx].rx_fw_ring_id = |
| 4869 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4870 | } |
| 4871 | } |
| 4872 | |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4873 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 4874 | type = RING_FREE_REQ_RING_TYPE_RX_AGG; |
| 4875 | else |
| 4876 | type = RING_FREE_REQ_RING_TYPE_RX; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4877 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4878 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4879 | struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4880 | u32 grp_idx = rxr->bnapi->index; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4881 | u32 cmpl_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4882 | |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 4883 | cmpl_ring_id = bnxt_cp_ring_for_rx(bp, rxr); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4884 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4885 | hwrm_ring_free_send_msg(bp, ring, type, |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4886 | close_path ? cmpl_ring_id : |
| 4887 | INVALID_HW_RING_ID); |
| 4888 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4889 | bp->grp_info[grp_idx].agg_fw_ring_id = |
| 4890 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4891 | } |
| 4892 | } |
| 4893 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 4894 | /* The completion rings are about to be freed. After that the |
| 4895 | * IRQ doorbell will not work anymore. So we need to disable |
| 4896 | * IRQ here. |
| 4897 | */ |
| 4898 | bnxt_disable_int_sync(bp); |
| 4899 | |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4900 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 4901 | type = RING_FREE_REQ_RING_TYPE_NQ; |
| 4902 | else |
| 4903 | type = RING_FREE_REQ_RING_TYPE_L2_CMPL; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4904 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4905 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4906 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 4907 | struct bnxt_ring_struct *ring; |
| 4908 | int j; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4909 | |
Michael Chan | 3e08b18 | 2018-10-14 07:02:52 -0400 | [diff] [blame^] | 4910 | for (j = 0; j < 2; j++) { |
| 4911 | struct bnxt_cp_ring_info *cpr2 = cpr->cp_ring_arr[j]; |
| 4912 | |
| 4913 | if (cpr2) { |
| 4914 | ring = &cpr2->cp_ring_struct; |
| 4915 | if (ring->fw_ring_id == INVALID_HW_RING_ID) |
| 4916 | continue; |
| 4917 | hwrm_ring_free_send_msg(bp, ring, |
| 4918 | RING_FREE_REQ_RING_TYPE_L2_CMPL, |
| 4919 | INVALID_HW_RING_ID); |
| 4920 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 4921 | } |
| 4922 | } |
| 4923 | ring = &cpr->cp_ring_struct; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4924 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
Michael Chan | 23aefdd | 2018-10-14 07:02:51 -0400 | [diff] [blame] | 4925 | hwrm_ring_free_send_msg(bp, ring, type, |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4926 | INVALID_HW_RING_ID); |
| 4927 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 4928 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4929 | } |
| 4930 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4931 | } |
| 4932 | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 4933 | static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, |
| 4934 | bool shared); |
| 4935 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4936 | static int bnxt_hwrm_get_rings(struct bnxt *bp) |
| 4937 | { |
| 4938 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4939 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 4940 | struct hwrm_func_qcfg_input req = {0}; |
| 4941 | int rc; |
| 4942 | |
| 4943 | if (bp->hwrm_spec_code < 0x10601) |
| 4944 | return 0; |
| 4945 | |
| 4946 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4947 | req.fid = cpu_to_le16(0xffff); |
| 4948 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4949 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4950 | if (rc) { |
| 4951 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4952 | return -EIO; |
| 4953 | } |
| 4954 | |
| 4955 | hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings); |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 4956 | if (BNXT_NEW_RM(bp)) { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4957 | u16 cp, stats; |
| 4958 | |
| 4959 | hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings); |
| 4960 | hw_resc->resv_hw_ring_grps = |
| 4961 | le32_to_cpu(resp->alloc_hw_ring_grps); |
| 4962 | hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics); |
| 4963 | cp = le16_to_cpu(resp->alloc_cmpl_rings); |
| 4964 | stats = le16_to_cpu(resp->alloc_stat_ctx); |
| 4965 | cp = min_t(u16, cp, stats); |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 4966 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 4967 | int rx = hw_resc->resv_rx_rings; |
| 4968 | int tx = hw_resc->resv_tx_rings; |
| 4969 | |
| 4970 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 4971 | rx >>= 1; |
| 4972 | if (cp < (rx + tx)) { |
| 4973 | bnxt_trim_rings(bp, &rx, &tx, cp, false); |
| 4974 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 4975 | rx <<= 1; |
| 4976 | hw_resc->resv_rx_rings = rx; |
| 4977 | hw_resc->resv_tx_rings = tx; |
| 4978 | } |
| 4979 | cp = le16_to_cpu(resp->alloc_msix); |
| 4980 | hw_resc->resv_hw_ring_grps = rx; |
| 4981 | } |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4982 | hw_resc->resv_cp_rings = cp; |
| 4983 | } |
| 4984 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4985 | return 0; |
| 4986 | } |
| 4987 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4988 | /* Caller must hold bp->hwrm_cmd_lock */ |
| 4989 | int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings) |
| 4990 | { |
| 4991 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4992 | struct hwrm_func_qcfg_input req = {0}; |
| 4993 | int rc; |
| 4994 | |
| 4995 | if (bp->hwrm_spec_code < 0x10601) |
| 4996 | return 0; |
| 4997 | |
| 4998 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4999 | req.fid = cpu_to_le16(fid); |
| 5000 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5001 | if (!rc) |
| 5002 | *tx_rings = le16_to_cpu(resp->alloc_tx_rings); |
| 5003 | |
| 5004 | return rc; |
| 5005 | } |
| 5006 | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5007 | static bool bnxt_rfs_supported(struct bnxt *bp); |
| 5008 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5009 | static void |
| 5010 | __bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req, |
| 5011 | int tx_rings, int rx_rings, int ring_grps, |
| 5012 | int cp_rings, int vnics) |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 5013 | { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5014 | u32 enables = 0; |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 5015 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5016 | bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1); |
| 5017 | req->fid = cpu_to_le16(0xffff); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5018 | enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0; |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5019 | req->num_tx_rings = cpu_to_le16(tx_rings); |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 5020 | if (BNXT_NEW_RM(bp)) { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5021 | enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0; |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5022 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 5023 | enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_MSIX : 0; |
| 5024 | enables |= tx_rings + ring_grps ? |
| 5025 | FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 5026 | FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0; |
| 5027 | enables |= rx_rings ? |
| 5028 | FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0; |
| 5029 | } else { |
| 5030 | enables |= cp_rings ? |
| 5031 | FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 5032 | FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0; |
| 5033 | enables |= ring_grps ? |
| 5034 | FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS | |
| 5035 | FUNC_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0; |
| 5036 | } |
Michael Chan | dbe80d4 | 2018-10-05 00:26:00 -0400 | [diff] [blame] | 5037 | enables |= vnics ? FUNC_CFG_REQ_ENABLES_NUM_VNICS : 0; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5038 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5039 | req->num_rx_rings = cpu_to_le16(rx_rings); |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5040 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 5041 | req->num_cmpl_rings = cpu_to_le16(tx_rings + ring_grps); |
| 5042 | req->num_msix = cpu_to_le16(cp_rings); |
| 5043 | req->num_rsscos_ctxs = |
| 5044 | cpu_to_le16(DIV_ROUND_UP(ring_grps, 64)); |
| 5045 | } else { |
| 5046 | req->num_cmpl_rings = cpu_to_le16(cp_rings); |
| 5047 | req->num_hw_ring_grps = cpu_to_le16(ring_grps); |
| 5048 | req->num_rsscos_ctxs = cpu_to_le16(1); |
| 5049 | if (!(bp->flags & BNXT_FLAG_NEW_RSS_CAP) && |
| 5050 | bnxt_rfs_supported(bp)) |
| 5051 | req->num_rsscos_ctxs = |
| 5052 | cpu_to_le16(ring_grps + 1); |
| 5053 | } |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5054 | req->num_stat_ctxs = req->num_cmpl_rings; |
| 5055 | req->num_vnics = cpu_to_le16(vnics); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5056 | } |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5057 | req->enables = cpu_to_le32(enables); |
| 5058 | } |
| 5059 | |
| 5060 | static void |
| 5061 | __bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, |
| 5062 | struct hwrm_func_vf_cfg_input *req, int tx_rings, |
| 5063 | int rx_rings, int ring_grps, int cp_rings, |
| 5064 | int vnics) |
| 5065 | { |
| 5066 | u32 enables = 0; |
| 5067 | |
| 5068 | bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1); |
| 5069 | enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0; |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5070 | enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS | |
| 5071 | FUNC_VF_CFG_REQ_ENABLES_NUM_RSSCOS_CTXS : 0; |
| 5072 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 5073 | enables |= tx_rings + ring_grps ? |
| 5074 | FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 5075 | FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0; |
| 5076 | } else { |
| 5077 | enables |= cp_rings ? |
| 5078 | FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 5079 | FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0; |
| 5080 | enables |= ring_grps ? |
| 5081 | FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0; |
| 5082 | } |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5083 | enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0; |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5084 | enables |= FUNC_VF_CFG_REQ_ENABLES_NUM_L2_CTXS; |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5085 | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5086 | req->num_l2_ctxs = cpu_to_le16(BNXT_VF_MAX_L2_CTX); |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5087 | req->num_tx_rings = cpu_to_le16(tx_rings); |
| 5088 | req->num_rx_rings = cpu_to_le16(rx_rings); |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5089 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 5090 | req->num_cmpl_rings = cpu_to_le16(tx_rings + ring_grps); |
| 5091 | req->num_rsscos_ctxs = cpu_to_le16(DIV_ROUND_UP(ring_grps, 64)); |
| 5092 | } else { |
| 5093 | req->num_cmpl_rings = cpu_to_le16(cp_rings); |
| 5094 | req->num_hw_ring_grps = cpu_to_le16(ring_grps); |
| 5095 | req->num_rsscos_ctxs = cpu_to_le16(BNXT_VF_MAX_RSS_CTX); |
| 5096 | } |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5097 | req->num_stat_ctxs = req->num_cmpl_rings; |
| 5098 | req->num_vnics = cpu_to_le16(vnics); |
| 5099 | |
| 5100 | req->enables = cpu_to_le32(enables); |
| 5101 | } |
| 5102 | |
| 5103 | static int |
| 5104 | bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
| 5105 | int ring_grps, int cp_rings, int vnics) |
| 5106 | { |
| 5107 | struct hwrm_func_cfg_input req = {0}; |
| 5108 | int rc; |
| 5109 | |
| 5110 | __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 5111 | cp_rings, vnics); |
| 5112 | if (!req.enables) |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5113 | return 0; |
| 5114 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5115 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5116 | if (rc) |
| 5117 | return -ENOMEM; |
| 5118 | |
| 5119 | if (bp->hwrm_spec_code < 0x10601) |
| 5120 | bp->hw_resc.resv_tx_rings = tx_rings; |
| 5121 | |
| 5122 | rc = bnxt_hwrm_get_rings(bp); |
| 5123 | return rc; |
| 5124 | } |
| 5125 | |
| 5126 | static int |
| 5127 | bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
| 5128 | int ring_grps, int cp_rings, int vnics) |
| 5129 | { |
| 5130 | struct hwrm_func_vf_cfg_input req = {0}; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5131 | int rc; |
| 5132 | |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 5133 | if (!BNXT_NEW_RM(bp)) { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5134 | bp->hw_resc.resv_tx_rings = tx_rings; |
| 5135 | return 0; |
| 5136 | } |
| 5137 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 5138 | __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 5139 | cp_rings, vnics); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5140 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5141 | if (rc) |
| 5142 | return -ENOMEM; |
| 5143 | |
| 5144 | rc = bnxt_hwrm_get_rings(bp); |
| 5145 | return rc; |
| 5146 | } |
| 5147 | |
| 5148 | static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp, |
| 5149 | int cp, int vnic) |
| 5150 | { |
| 5151 | if (BNXT_PF(bp)) |
| 5152 | return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic); |
| 5153 | else |
| 5154 | return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic); |
| 5155 | } |
| 5156 | |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 5157 | static int bnxt_cp_rings_in_use(struct bnxt *bp) |
| 5158 | { |
| 5159 | int cp = bp->cp_nr_rings; |
| 5160 | int ulp_msix, ulp_base; |
| 5161 | |
| 5162 | ulp_msix = bnxt_get_ulp_msix_num(bp); |
| 5163 | if (ulp_msix) { |
| 5164 | ulp_base = bnxt_get_ulp_msix_base(bp); |
| 5165 | cp += ulp_msix; |
| 5166 | if ((ulp_base + ulp_msix) > cp) |
| 5167 | cp = ulp_base + ulp_msix; |
| 5168 | } |
| 5169 | return cp; |
| 5170 | } |
| 5171 | |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 5172 | static bool bnxt_need_reserve_rings(struct bnxt *bp) |
| 5173 | { |
| 5174 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 5175 | int cp = bnxt_cp_rings_in_use(bp); |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 5176 | int rx = bp->rx_nr_rings; |
| 5177 | int vnic = 1, grp = rx; |
| 5178 | |
| 5179 | if (bp->hwrm_spec_code < 0x10601) |
| 5180 | return false; |
| 5181 | |
| 5182 | if (hw_resc->resv_tx_rings != bp->tx_nr_rings) |
| 5183 | return true; |
| 5184 | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5185 | if ((bp->flags & BNXT_FLAG_RFS) && !(bp->flags & BNXT_FLAG_CHIP_P5)) |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 5186 | vnic = rx + 1; |
| 5187 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 5188 | rx <<= 1; |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 5189 | if (BNXT_NEW_RM(bp) && |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 5190 | (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp || |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5191 | hw_resc->resv_vnics != vnic || |
| 5192 | (hw_resc->resv_hw_ring_grps != grp && |
| 5193 | !(bp->flags & BNXT_FLAG_CHIP_P5)))) |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 5194 | return true; |
| 5195 | return false; |
| 5196 | } |
| 5197 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5198 | static int __bnxt_reserve_rings(struct bnxt *bp) |
| 5199 | { |
| 5200 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 5201 | int cp = bnxt_cp_rings_in_use(bp); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5202 | int tx = bp->tx_nr_rings; |
| 5203 | int rx = bp->rx_nr_rings; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5204 | int grp, rx_rings, rc; |
| 5205 | bool sh = false; |
| 5206 | int vnic = 1; |
| 5207 | |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 5208 | if (!bnxt_need_reserve_rings(bp)) |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 5209 | return 0; |
| 5210 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5211 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 5212 | sh = true; |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5213 | if ((bp->flags & BNXT_FLAG_RFS) && !(bp->flags & BNXT_FLAG_CHIP_P5)) |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5214 | vnic = rx + 1; |
| 5215 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 5216 | rx <<= 1; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5217 | grp = bp->rx_nr_rings; |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 5218 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5219 | rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 5220 | if (rc) |
| 5221 | return rc; |
| 5222 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5223 | tx = hw_resc->resv_tx_rings; |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 5224 | if (BNXT_NEW_RM(bp)) { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 5225 | rx = hw_resc->resv_rx_rings; |
| 5226 | cp = hw_resc->resv_cp_rings; |
| 5227 | grp = hw_resc->resv_hw_ring_grps; |
| 5228 | vnic = hw_resc->resv_vnics; |
| 5229 | } |
| 5230 | |
| 5231 | rx_rings = rx; |
| 5232 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 5233 | if (rx >= 2) { |
| 5234 | rx_rings = rx >> 1; |
| 5235 | } else { |
| 5236 | if (netif_running(bp->dev)) |
| 5237 | return -ENOMEM; |
| 5238 | |
| 5239 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 5240 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS; |
| 5241 | bp->dev->hw_features &= ~NETIF_F_LRO; |
| 5242 | bp->dev->features &= ~NETIF_F_LRO; |
| 5243 | bnxt_set_ring_params(bp); |
| 5244 | } |
| 5245 | } |
| 5246 | rx_rings = min_t(int, rx_rings, grp); |
| 5247 | rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh); |
| 5248 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 5249 | rx = rx_rings << 1; |
| 5250 | cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings; |
| 5251 | bp->tx_nr_rings = tx; |
| 5252 | bp->rx_nr_rings = rx_rings; |
| 5253 | bp->cp_nr_rings = cp; |
| 5254 | |
| 5255 | if (!tx || !rx || !cp || !grp || !vnic) |
| 5256 | return -ENOMEM; |
| 5257 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 5258 | return rc; |
| 5259 | } |
| 5260 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5261 | static int bnxt_hwrm_check_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5262 | int ring_grps, int cp_rings, int vnics) |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 5263 | { |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5264 | struct hwrm_func_vf_cfg_input req = {0}; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5265 | u32 flags; |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 5266 | int rc; |
| 5267 | |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 5268 | if (!BNXT_NEW_RM(bp)) |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 5269 | return 0; |
| 5270 | |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5271 | __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 5272 | cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5273 | flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST | |
| 5274 | FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST | |
| 5275 | FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5276 | FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5277 | FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST | |
| 5278 | FUNC_VF_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST; |
| 5279 | if (!(bp->flags & BNXT_FLAG_CHIP_P5)) |
| 5280 | flags |= FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST; |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 5281 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5282 | req.flags = cpu_to_le32(flags); |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 5283 | rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5284 | if (rc) |
| 5285 | return -ENOMEM; |
| 5286 | return 0; |
| 5287 | } |
| 5288 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5289 | static int bnxt_hwrm_check_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5290 | int ring_grps, int cp_rings, int vnics) |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5291 | { |
| 5292 | struct hwrm_func_cfg_input req = {0}; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5293 | u32 flags; |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5294 | int rc; |
| 5295 | |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5296 | __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 5297 | cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5298 | flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST; |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5299 | if (BNXT_NEW_RM(bp)) { |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5300 | flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST | |
| 5301 | FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5302 | FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST | |
| 5303 | FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST; |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 5304 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 5305 | flags |= FUNC_CFG_REQ_FLAGS_RSSCOS_CTX_ASSETS_TEST; |
| 5306 | else |
| 5307 | flags |= FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST; |
| 5308 | } |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5309 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5310 | req.flags = cpu_to_le32(flags); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5311 | rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5312 | if (rc) |
| 5313 | return -ENOMEM; |
| 5314 | return 0; |
| 5315 | } |
| 5316 | |
| 5317 | static int bnxt_hwrm_check_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5318 | int ring_grps, int cp_rings, int vnics) |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5319 | { |
| 5320 | if (bp->hwrm_spec_code < 0x10801) |
| 5321 | return 0; |
| 5322 | |
| 5323 | if (BNXT_PF(bp)) |
| 5324 | return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings, |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5325 | ring_grps, cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5326 | |
| 5327 | return bnxt_hwrm_check_vf_rings(bp, tx_rings, rx_rings, ring_grps, |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 5328 | cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 5329 | } |
| 5330 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5331 | static void bnxt_hwrm_coal_params_qcaps(struct bnxt *bp) |
| 5332 | { |
| 5333 | struct hwrm_ring_aggint_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 5334 | struct bnxt_coal_cap *coal_cap = &bp->coal_cap; |
| 5335 | struct hwrm_ring_aggint_qcaps_input req = {0}; |
| 5336 | int rc; |
| 5337 | |
| 5338 | coal_cap->cmpl_params = BNXT_LEGACY_COAL_CMPL_PARAMS; |
| 5339 | coal_cap->num_cmpl_dma_aggr_max = 63; |
| 5340 | coal_cap->num_cmpl_dma_aggr_during_int_max = 63; |
| 5341 | coal_cap->cmpl_aggr_dma_tmr_max = 65535; |
| 5342 | coal_cap->cmpl_aggr_dma_tmr_during_int_max = 65535; |
| 5343 | coal_cap->int_lat_tmr_min_max = 65535; |
| 5344 | coal_cap->int_lat_tmr_max_max = 65535; |
| 5345 | coal_cap->num_cmpl_aggr_int_max = 65535; |
| 5346 | coal_cap->timer_units = 80; |
| 5347 | |
| 5348 | if (bp->hwrm_spec_code < 0x10902) |
| 5349 | return; |
| 5350 | |
| 5351 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_AGGINT_QCAPS, -1, -1); |
| 5352 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5353 | rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5354 | if (!rc) { |
| 5355 | coal_cap->cmpl_params = le32_to_cpu(resp->cmpl_params); |
| 5356 | coal_cap->num_cmpl_dma_aggr_max = |
| 5357 | le16_to_cpu(resp->num_cmpl_dma_aggr_max); |
| 5358 | coal_cap->num_cmpl_dma_aggr_during_int_max = |
| 5359 | le16_to_cpu(resp->num_cmpl_dma_aggr_during_int_max); |
| 5360 | coal_cap->cmpl_aggr_dma_tmr_max = |
| 5361 | le16_to_cpu(resp->cmpl_aggr_dma_tmr_max); |
| 5362 | coal_cap->cmpl_aggr_dma_tmr_during_int_max = |
| 5363 | le16_to_cpu(resp->cmpl_aggr_dma_tmr_during_int_max); |
| 5364 | coal_cap->int_lat_tmr_min_max = |
| 5365 | le16_to_cpu(resp->int_lat_tmr_min_max); |
| 5366 | coal_cap->int_lat_tmr_max_max = |
| 5367 | le16_to_cpu(resp->int_lat_tmr_max_max); |
| 5368 | coal_cap->num_cmpl_aggr_int_max = |
| 5369 | le16_to_cpu(resp->num_cmpl_aggr_int_max); |
| 5370 | coal_cap->timer_units = le16_to_cpu(resp->timer_units); |
| 5371 | } |
| 5372 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5373 | } |
| 5374 | |
| 5375 | static u16 bnxt_usec_to_coal_tmr(struct bnxt *bp, u16 usec) |
| 5376 | { |
| 5377 | struct bnxt_coal_cap *coal_cap = &bp->coal_cap; |
| 5378 | |
| 5379 | return usec * 1000 / coal_cap->timer_units; |
| 5380 | } |
| 5381 | |
| 5382 | static void bnxt_hwrm_set_coal_params(struct bnxt *bp, |
| 5383 | struct bnxt_coal *hw_coal, |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 5384 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req) |
| 5385 | { |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5386 | struct bnxt_coal_cap *coal_cap = &bp->coal_cap; |
| 5387 | u32 cmpl_params = coal_cap->cmpl_params; |
| 5388 | u16 val, tmr, max, flags = 0; |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5389 | |
| 5390 | max = hw_coal->bufs_per_record * 128; |
| 5391 | if (hw_coal->budget) |
| 5392 | max = hw_coal->bufs_per_record * hw_coal->budget; |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5393 | max = min_t(u16, max, coal_cap->num_cmpl_aggr_int_max); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5394 | |
| 5395 | val = clamp_t(u16, hw_coal->coal_bufs, 1, max); |
| 5396 | req->num_cmpl_aggr_int = cpu_to_le16(val); |
Michael Chan | b153cbc | 2017-11-03 03:32:39 -0400 | [diff] [blame] | 5397 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5398 | val = min_t(u16, val, coal_cap->num_cmpl_dma_aggr_max); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5399 | req->num_cmpl_dma_aggr = cpu_to_le16(val); |
| 5400 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5401 | val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, |
| 5402 | coal_cap->num_cmpl_dma_aggr_during_int_max); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5403 | req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val); |
| 5404 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5405 | tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks); |
| 5406 | tmr = clamp_t(u16, tmr, 1, coal_cap->int_lat_tmr_max_max); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5407 | req->int_lat_tmr_max = cpu_to_le16(tmr); |
| 5408 | |
| 5409 | /* min timer set to 1/2 of interrupt timer */ |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5410 | if (cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_INT_LAT_TMR_MIN) { |
| 5411 | val = tmr / 2; |
| 5412 | val = clamp_t(u16, val, 1, coal_cap->int_lat_tmr_min_max); |
| 5413 | req->int_lat_tmr_min = cpu_to_le16(val); |
| 5414 | req->enables |= cpu_to_le16(BNXT_COAL_CMPL_MIN_TMR_ENABLE); |
| 5415 | } |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5416 | |
| 5417 | /* buf timer set to 1/4 of interrupt timer */ |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5418 | val = clamp_t(u16, tmr / 4, 1, coal_cap->cmpl_aggr_dma_tmr_max); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5419 | req->cmpl_aggr_dma_tmr = cpu_to_le16(val); |
| 5420 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5421 | if (cmpl_params & |
| 5422 | RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_NUM_CMPL_DMA_AGGR_DURING_INT) { |
| 5423 | tmr = bnxt_usec_to_coal_tmr(bp, hw_coal->coal_ticks_irq); |
| 5424 | val = clamp_t(u16, tmr, 1, |
| 5425 | coal_cap->cmpl_aggr_dma_tmr_during_int_max); |
| 5426 | req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr); |
| 5427 | req->enables |= |
| 5428 | cpu_to_le16(BNXT_COAL_CMPL_AGGR_TMR_DURING_INT_ENABLE); |
| 5429 | } |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5430 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5431 | if (cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_TIMER_RESET) |
| 5432 | flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET; |
| 5433 | if ((cmpl_params & RING_AGGINT_QCAPS_RESP_CMPL_PARAMS_RING_IDLE) && |
| 5434 | hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh) |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 5435 | flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE; |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 5436 | req->flags = cpu_to_le16(flags); |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5437 | req->enables |= cpu_to_le16(BNXT_COAL_CMPL_ENABLES); |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 5438 | } |
| 5439 | |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 5440 | int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi) |
| 5441 | { |
| 5442 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0}; |
| 5443 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 5444 | struct bnxt_coal coal; |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 5445 | |
| 5446 | /* Tick values in micro seconds. |
| 5447 | * 1 coal_buf x bufs_per_record = 1 completion record. |
| 5448 | */ |
| 5449 | memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal)); |
| 5450 | |
| 5451 | coal.coal_ticks = cpr->rx_ring_coal.coal_ticks; |
| 5452 | coal.coal_bufs = cpr->rx_ring_coal.coal_bufs; |
| 5453 | |
| 5454 | if (!bnapi->rx_ring) |
| 5455 | return -ENODEV; |
| 5456 | |
| 5457 | bnxt_hwrm_cmd_hdr_init(bp, &req_rx, |
| 5458 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
| 5459 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5460 | bnxt_hwrm_set_coal_params(bp, &coal, &req_rx); |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 5461 | |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 5462 | req_rx.ring_id = cpu_to_le16(bnxt_cp_ring_for_rx(bp, bnapi->rx_ring)); |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 5463 | |
| 5464 | return hwrm_send_message(bp, &req_rx, sizeof(req_rx), |
| 5465 | HWRM_CMD_TIMEOUT); |
| 5466 | } |
| 5467 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5468 | int bnxt_hwrm_set_coal(struct bnxt *bp) |
| 5469 | { |
| 5470 | int i, rc = 0; |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5471 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0}, |
| 5472 | req_tx = {0}, *req; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5473 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5474 | bnxt_hwrm_cmd_hdr_init(bp, &req_rx, |
| 5475 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
| 5476 | bnxt_hwrm_cmd_hdr_init(bp, &req_tx, |
| 5477 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5478 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 5479 | bnxt_hwrm_set_coal_params(bp, &bp->rx_coal, &req_rx); |
| 5480 | bnxt_hwrm_set_coal_params(bp, &bp->tx_coal, &req_tx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5481 | |
| 5482 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5483 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5484 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 5485 | u16 ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5486 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5487 | req = &req_rx; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 5488 | if (!bnapi->rx_ring) { |
| 5489 | ring_id = bnxt_cp_ring_for_tx(bp, bnapi->tx_ring); |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5490 | req = &req_tx; |
Michael Chan | 2c61d21 | 2018-10-14 07:02:50 -0400 | [diff] [blame] | 5491 | } else { |
| 5492 | ring_id = bnxt_cp_ring_for_rx(bp, bnapi->rx_ring); |
| 5493 | } |
| 5494 | req->ring_id = cpu_to_le16(ring_id); |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5495 | |
| 5496 | rc = _hwrm_send_message(bp, req, sizeof(*req), |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5497 | HWRM_CMD_TIMEOUT); |
| 5498 | if (rc) |
| 5499 | break; |
| 5500 | } |
| 5501 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5502 | return rc; |
| 5503 | } |
| 5504 | |
| 5505 | static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp) |
| 5506 | { |
| 5507 | int rc = 0, i; |
| 5508 | struct hwrm_stat_ctx_free_input req = {0}; |
| 5509 | |
| 5510 | if (!bp->bnapi) |
| 5511 | return 0; |
| 5512 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 5513 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5514 | return 0; |
| 5515 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5516 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1); |
| 5517 | |
| 5518 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5519 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5520 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5521 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 5522 | |
| 5523 | if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) { |
| 5524 | req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id); |
| 5525 | |
| 5526 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 5527 | HWRM_CMD_TIMEOUT); |
| 5528 | if (rc) |
| 5529 | break; |
| 5530 | |
| 5531 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 5532 | } |
| 5533 | } |
| 5534 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5535 | return rc; |
| 5536 | } |
| 5537 | |
| 5538 | static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp) |
| 5539 | { |
| 5540 | int rc = 0, i; |
| 5541 | struct hwrm_stat_ctx_alloc_input req = {0}; |
| 5542 | struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 5543 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 5544 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5545 | return 0; |
| 5546 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5547 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1); |
| 5548 | |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 5549 | req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5550 | |
| 5551 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5552 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5553 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5554 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 5555 | |
| 5556 | req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map); |
| 5557 | |
| 5558 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 5559 | HWRM_CMD_TIMEOUT); |
| 5560 | if (rc) |
| 5561 | break; |
| 5562 | |
| 5563 | cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id); |
| 5564 | |
| 5565 | bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; |
| 5566 | } |
| 5567 | mutex_unlock(&bp->hwrm_cmd_lock); |
Pan Bian | 89aa844 | 2016-12-03 17:56:17 +0800 | [diff] [blame] | 5568 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5569 | } |
| 5570 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5571 | static int bnxt_hwrm_func_qcfg(struct bnxt *bp) |
| 5572 | { |
| 5573 | struct hwrm_func_qcfg_input req = {0}; |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 5574 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5575 | u16 flags; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5576 | int rc; |
| 5577 | |
| 5578 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 5579 | req.fid = cpu_to_le16(0xffff); |
| 5580 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5581 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5582 | if (rc) |
| 5583 | goto func_qcfg_exit; |
| 5584 | |
| 5585 | #ifdef CONFIG_BNXT_SRIOV |
| 5586 | if (BNXT_VF(bp)) { |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5587 | struct bnxt_vf_info *vf = &bp->vf; |
| 5588 | |
| 5589 | vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK; |
| 5590 | } |
| 5591 | #endif |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5592 | flags = le16_to_cpu(resp->flags); |
| 5593 | if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED | |
| 5594 | FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) { |
Michael Chan | 97381a1 | 2018-08-05 16:51:54 -0400 | [diff] [blame] | 5595 | bp->fw_cap |= BNXT_FW_CAP_LLDP_AGENT; |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5596 | if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED) |
Michael Chan | 97381a1 | 2018-08-05 16:51:54 -0400 | [diff] [blame] | 5597 | bp->fw_cap |= BNXT_FW_CAP_DCBX_AGENT; |
Deepak Khungar | 9e54e32 | 2017-04-21 20:11:26 -0400 | [diff] [blame] | 5598 | } |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5599 | if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)) |
| 5600 | bp->flags |= BNXT_FLAG_MULTI_HOST; |
Michael Chan | bc39f88 | 2017-03-08 18:44:34 -0500 | [diff] [blame] | 5601 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 5602 | switch (resp->port_partition_type) { |
| 5603 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0: |
| 5604 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5: |
| 5605 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0: |
| 5606 | bp->port_partition_type = resp->port_partition_type; |
| 5607 | break; |
| 5608 | } |
Michael Chan | 32e8239c | 2017-07-24 12:34:21 -0400 | [diff] [blame] | 5609 | if (bp->hwrm_spec_code < 0x10707 || |
| 5610 | resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB) |
| 5611 | bp->br_mode = BRIDGE_MODE_VEB; |
| 5612 | else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA) |
| 5613 | bp->br_mode = BRIDGE_MODE_VEPA; |
| 5614 | else |
| 5615 | bp->br_mode = BRIDGE_MODE_UNDEF; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5616 | |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 5617 | bp->max_mtu = le16_to_cpu(resp->max_mtu_configured); |
| 5618 | if (!bp->max_mtu) |
| 5619 | bp->max_mtu = BNXT_MAX_MTU; |
| 5620 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5621 | func_qcfg_exit: |
| 5622 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5623 | return rc; |
| 5624 | } |
| 5625 | |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5626 | static int bnxt_hwrm_func_backing_store_qcaps(struct bnxt *bp) |
| 5627 | { |
| 5628 | struct hwrm_func_backing_store_qcaps_input req = {0}; |
| 5629 | struct hwrm_func_backing_store_qcaps_output *resp = |
| 5630 | bp->hwrm_cmd_resp_addr; |
| 5631 | int rc; |
| 5632 | |
| 5633 | if (bp->hwrm_spec_code < 0x10902 || BNXT_VF(bp) || bp->ctx) |
| 5634 | return 0; |
| 5635 | |
| 5636 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_BACKING_STORE_QCAPS, -1, -1); |
| 5637 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5638 | rc = _hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5639 | if (!rc) { |
| 5640 | struct bnxt_ctx_pg_info *ctx_pg; |
| 5641 | struct bnxt_ctx_mem_info *ctx; |
| 5642 | int i; |
| 5643 | |
| 5644 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); |
| 5645 | if (!ctx) { |
| 5646 | rc = -ENOMEM; |
| 5647 | goto ctx_err; |
| 5648 | } |
| 5649 | ctx_pg = kzalloc(sizeof(*ctx_pg) * (bp->max_q + 1), GFP_KERNEL); |
| 5650 | if (!ctx_pg) { |
| 5651 | kfree(ctx); |
| 5652 | rc = -ENOMEM; |
| 5653 | goto ctx_err; |
| 5654 | } |
| 5655 | for (i = 0; i < bp->max_q + 1; i++, ctx_pg++) |
| 5656 | ctx->tqm_mem[i] = ctx_pg; |
| 5657 | |
| 5658 | bp->ctx = ctx; |
| 5659 | ctx->qp_max_entries = le32_to_cpu(resp->qp_max_entries); |
| 5660 | ctx->qp_min_qp1_entries = le16_to_cpu(resp->qp_min_qp1_entries); |
| 5661 | ctx->qp_max_l2_entries = le16_to_cpu(resp->qp_max_l2_entries); |
| 5662 | ctx->qp_entry_size = le16_to_cpu(resp->qp_entry_size); |
| 5663 | ctx->srq_max_l2_entries = le16_to_cpu(resp->srq_max_l2_entries); |
| 5664 | ctx->srq_max_entries = le32_to_cpu(resp->srq_max_entries); |
| 5665 | ctx->srq_entry_size = le16_to_cpu(resp->srq_entry_size); |
| 5666 | ctx->cq_max_l2_entries = le16_to_cpu(resp->cq_max_l2_entries); |
| 5667 | ctx->cq_max_entries = le32_to_cpu(resp->cq_max_entries); |
| 5668 | ctx->cq_entry_size = le16_to_cpu(resp->cq_entry_size); |
| 5669 | ctx->vnic_max_vnic_entries = |
| 5670 | le16_to_cpu(resp->vnic_max_vnic_entries); |
| 5671 | ctx->vnic_max_ring_table_entries = |
| 5672 | le16_to_cpu(resp->vnic_max_ring_table_entries); |
| 5673 | ctx->vnic_entry_size = le16_to_cpu(resp->vnic_entry_size); |
| 5674 | ctx->stat_max_entries = le32_to_cpu(resp->stat_max_entries); |
| 5675 | ctx->stat_entry_size = le16_to_cpu(resp->stat_entry_size); |
| 5676 | ctx->tqm_entry_size = le16_to_cpu(resp->tqm_entry_size); |
| 5677 | ctx->tqm_min_entries_per_ring = |
| 5678 | le32_to_cpu(resp->tqm_min_entries_per_ring); |
| 5679 | ctx->tqm_max_entries_per_ring = |
| 5680 | le32_to_cpu(resp->tqm_max_entries_per_ring); |
| 5681 | ctx->tqm_entries_multiple = resp->tqm_entries_multiple; |
| 5682 | if (!ctx->tqm_entries_multiple) |
| 5683 | ctx->tqm_entries_multiple = 1; |
| 5684 | ctx->mrav_max_entries = le32_to_cpu(resp->mrav_max_entries); |
| 5685 | ctx->mrav_entry_size = le16_to_cpu(resp->mrav_entry_size); |
| 5686 | ctx->tim_entry_size = le16_to_cpu(resp->tim_entry_size); |
| 5687 | ctx->tim_max_entries = le32_to_cpu(resp->tim_max_entries); |
| 5688 | } else { |
| 5689 | rc = 0; |
| 5690 | } |
| 5691 | ctx_err: |
| 5692 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5693 | return rc; |
| 5694 | } |
| 5695 | |
Michael Chan | 1b9394e | 2018-10-14 07:02:44 -0400 | [diff] [blame] | 5696 | static void bnxt_hwrm_set_pg_attr(struct bnxt_ring_mem_info *rmem, u8 *pg_attr, |
| 5697 | __le64 *pg_dir) |
| 5698 | { |
| 5699 | u8 pg_size = 0; |
| 5700 | |
| 5701 | if (BNXT_PAGE_SHIFT == 13) |
| 5702 | pg_size = 1 << 4; |
| 5703 | else if (BNXT_PAGE_SIZE == 16) |
| 5704 | pg_size = 2 << 4; |
| 5705 | |
| 5706 | *pg_attr = pg_size; |
| 5707 | if (rmem->nr_pages > 1) { |
| 5708 | *pg_attr |= 1; |
| 5709 | *pg_dir = cpu_to_le64(rmem->pg_tbl_map); |
| 5710 | } else { |
| 5711 | *pg_dir = cpu_to_le64(rmem->dma_arr[0]); |
| 5712 | } |
| 5713 | } |
| 5714 | |
| 5715 | #define FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES \ |
| 5716 | (FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP | \ |
| 5717 | FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ | \ |
| 5718 | FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ | \ |
| 5719 | FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC | \ |
| 5720 | FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT) |
| 5721 | |
| 5722 | static int bnxt_hwrm_func_backing_store_cfg(struct bnxt *bp, u32 enables) |
| 5723 | { |
| 5724 | struct hwrm_func_backing_store_cfg_input req = {0}; |
| 5725 | struct bnxt_ctx_mem_info *ctx = bp->ctx; |
| 5726 | struct bnxt_ctx_pg_info *ctx_pg; |
| 5727 | __le32 *num_entries; |
| 5728 | __le64 *pg_dir; |
| 5729 | u8 *pg_attr; |
| 5730 | int i, rc; |
| 5731 | u32 ena; |
| 5732 | |
| 5733 | if (!ctx) |
| 5734 | return 0; |
| 5735 | |
| 5736 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_BACKING_STORE_CFG, -1, -1); |
| 5737 | req.enables = cpu_to_le32(enables); |
| 5738 | |
| 5739 | if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_QP) { |
| 5740 | ctx_pg = &ctx->qp_mem; |
| 5741 | req.qp_num_entries = cpu_to_le32(ctx_pg->entries); |
| 5742 | req.qp_num_qp1_entries = cpu_to_le16(ctx->qp_min_qp1_entries); |
| 5743 | req.qp_num_l2_entries = cpu_to_le16(ctx->qp_max_l2_entries); |
| 5744 | req.qp_entry_size = cpu_to_le16(ctx->qp_entry_size); |
| 5745 | bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, |
| 5746 | &req.qpc_pg_size_qpc_lvl, |
| 5747 | &req.qpc_page_dir); |
| 5748 | } |
| 5749 | if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_SRQ) { |
| 5750 | ctx_pg = &ctx->srq_mem; |
| 5751 | req.srq_num_entries = cpu_to_le32(ctx_pg->entries); |
| 5752 | req.srq_num_l2_entries = cpu_to_le16(ctx->srq_max_l2_entries); |
| 5753 | req.srq_entry_size = cpu_to_le16(ctx->srq_entry_size); |
| 5754 | bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, |
| 5755 | &req.srq_pg_size_srq_lvl, |
| 5756 | &req.srq_page_dir); |
| 5757 | } |
| 5758 | if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_CQ) { |
| 5759 | ctx_pg = &ctx->cq_mem; |
| 5760 | req.cq_num_entries = cpu_to_le32(ctx_pg->entries); |
| 5761 | req.cq_num_l2_entries = cpu_to_le16(ctx->cq_max_l2_entries); |
| 5762 | req.cq_entry_size = cpu_to_le16(ctx->cq_entry_size); |
| 5763 | bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, &req.cq_pg_size_cq_lvl, |
| 5764 | &req.cq_page_dir); |
| 5765 | } |
| 5766 | if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_VNIC) { |
| 5767 | ctx_pg = &ctx->vnic_mem; |
| 5768 | req.vnic_num_vnic_entries = |
| 5769 | cpu_to_le16(ctx->vnic_max_vnic_entries); |
| 5770 | req.vnic_num_ring_table_entries = |
| 5771 | cpu_to_le16(ctx->vnic_max_ring_table_entries); |
| 5772 | req.vnic_entry_size = cpu_to_le16(ctx->vnic_entry_size); |
| 5773 | bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, |
| 5774 | &req.vnic_pg_size_vnic_lvl, |
| 5775 | &req.vnic_page_dir); |
| 5776 | } |
| 5777 | if (enables & FUNC_BACKING_STORE_CFG_REQ_ENABLES_STAT) { |
| 5778 | ctx_pg = &ctx->stat_mem; |
| 5779 | req.stat_num_entries = cpu_to_le32(ctx->stat_max_entries); |
| 5780 | req.stat_entry_size = cpu_to_le16(ctx->stat_entry_size); |
| 5781 | bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, |
| 5782 | &req.stat_pg_size_stat_lvl, |
| 5783 | &req.stat_page_dir); |
| 5784 | } |
| 5785 | for (i = 0, num_entries = &req.tqm_sp_num_entries, |
| 5786 | pg_attr = &req.tqm_sp_pg_size_tqm_sp_lvl, |
| 5787 | pg_dir = &req.tqm_sp_page_dir, |
| 5788 | ena = FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP; |
| 5789 | i < 9; i++, num_entries++, pg_attr++, pg_dir++, ena <<= 1) { |
| 5790 | if (!(enables & ena)) |
| 5791 | continue; |
| 5792 | |
| 5793 | req.tqm_entry_size = cpu_to_le16(ctx->tqm_entry_size); |
| 5794 | ctx_pg = ctx->tqm_mem[i]; |
| 5795 | *num_entries = cpu_to_le32(ctx_pg->entries); |
| 5796 | bnxt_hwrm_set_pg_attr(&ctx_pg->ring_mem, pg_attr, pg_dir); |
| 5797 | } |
| 5798 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5799 | if (rc) |
| 5800 | rc = -EIO; |
| 5801 | return rc; |
| 5802 | } |
| 5803 | |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5804 | static int bnxt_alloc_ctx_mem_blk(struct bnxt *bp, |
| 5805 | struct bnxt_ctx_pg_info *ctx_pg, u32 mem_size) |
| 5806 | { |
| 5807 | struct bnxt_ring_mem_info *rmem = &ctx_pg->ring_mem; |
| 5808 | |
| 5809 | if (!mem_size) |
| 5810 | return 0; |
| 5811 | |
| 5812 | rmem->nr_pages = DIV_ROUND_UP(mem_size, BNXT_PAGE_SIZE); |
| 5813 | if (rmem->nr_pages > MAX_CTX_PAGES) { |
| 5814 | rmem->nr_pages = 0; |
| 5815 | return -EINVAL; |
| 5816 | } |
| 5817 | rmem->page_size = BNXT_PAGE_SIZE; |
| 5818 | rmem->pg_arr = ctx_pg->ctx_pg_arr; |
| 5819 | rmem->dma_arr = ctx_pg->ctx_dma_arr; |
Michael Chan | 1b9394e | 2018-10-14 07:02:44 -0400 | [diff] [blame] | 5820 | rmem->flags = BNXT_RMEM_VALID_PTE_FLAG; |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5821 | return bnxt_alloc_ring(bp, rmem); |
| 5822 | } |
| 5823 | |
| 5824 | static void bnxt_free_ctx_mem(struct bnxt *bp) |
| 5825 | { |
| 5826 | struct bnxt_ctx_mem_info *ctx = bp->ctx; |
| 5827 | int i; |
| 5828 | |
| 5829 | if (!ctx) |
| 5830 | return; |
| 5831 | |
| 5832 | if (ctx->tqm_mem[0]) { |
| 5833 | for (i = 0; i < bp->max_q + 1; i++) |
| 5834 | bnxt_free_ring(bp, &ctx->tqm_mem[i]->ring_mem); |
| 5835 | kfree(ctx->tqm_mem[0]); |
| 5836 | ctx->tqm_mem[0] = NULL; |
| 5837 | } |
| 5838 | |
| 5839 | bnxt_free_ring(bp, &ctx->stat_mem.ring_mem); |
| 5840 | bnxt_free_ring(bp, &ctx->vnic_mem.ring_mem); |
| 5841 | bnxt_free_ring(bp, &ctx->cq_mem.ring_mem); |
| 5842 | bnxt_free_ring(bp, &ctx->srq_mem.ring_mem); |
| 5843 | bnxt_free_ring(bp, &ctx->qp_mem.ring_mem); |
| 5844 | ctx->flags &= ~BNXT_CTX_FLAG_INITED; |
| 5845 | } |
| 5846 | |
| 5847 | static int bnxt_alloc_ctx_mem(struct bnxt *bp) |
| 5848 | { |
| 5849 | struct bnxt_ctx_pg_info *ctx_pg; |
| 5850 | struct bnxt_ctx_mem_info *ctx; |
Michael Chan | 1b9394e | 2018-10-14 07:02:44 -0400 | [diff] [blame] | 5851 | u32 mem_size, ena, entries; |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5852 | int i, rc; |
| 5853 | |
| 5854 | rc = bnxt_hwrm_func_backing_store_qcaps(bp); |
| 5855 | if (rc) { |
| 5856 | netdev_err(bp->dev, "Failed querying context mem capability, rc = %d.\n", |
| 5857 | rc); |
| 5858 | return rc; |
| 5859 | } |
| 5860 | ctx = bp->ctx; |
| 5861 | if (!ctx || (ctx->flags & BNXT_CTX_FLAG_INITED)) |
| 5862 | return 0; |
| 5863 | |
| 5864 | ctx_pg = &ctx->qp_mem; |
| 5865 | ctx_pg->entries = ctx->qp_min_qp1_entries + ctx->qp_max_l2_entries; |
| 5866 | mem_size = ctx->qp_entry_size * ctx_pg->entries; |
| 5867 | rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size); |
| 5868 | if (rc) |
| 5869 | return rc; |
| 5870 | |
| 5871 | ctx_pg = &ctx->srq_mem; |
| 5872 | ctx_pg->entries = ctx->srq_max_l2_entries; |
| 5873 | mem_size = ctx->srq_entry_size * ctx_pg->entries; |
| 5874 | rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size); |
| 5875 | if (rc) |
| 5876 | return rc; |
| 5877 | |
| 5878 | ctx_pg = &ctx->cq_mem; |
| 5879 | ctx_pg->entries = ctx->cq_max_l2_entries; |
| 5880 | mem_size = ctx->cq_entry_size * ctx_pg->entries; |
| 5881 | rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size); |
| 5882 | if (rc) |
| 5883 | return rc; |
| 5884 | |
| 5885 | ctx_pg = &ctx->vnic_mem; |
| 5886 | ctx_pg->entries = ctx->vnic_max_vnic_entries + |
| 5887 | ctx->vnic_max_ring_table_entries; |
| 5888 | mem_size = ctx->vnic_entry_size * ctx_pg->entries; |
| 5889 | rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size); |
| 5890 | if (rc) |
| 5891 | return rc; |
| 5892 | |
| 5893 | ctx_pg = &ctx->stat_mem; |
| 5894 | ctx_pg->entries = ctx->stat_max_entries; |
| 5895 | mem_size = ctx->stat_entry_size * ctx_pg->entries; |
| 5896 | rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size); |
| 5897 | if (rc) |
| 5898 | return rc; |
| 5899 | |
| 5900 | entries = ctx->qp_max_l2_entries; |
| 5901 | entries = roundup(entries, ctx->tqm_entries_multiple); |
| 5902 | entries = clamp_t(u32, entries, ctx->tqm_min_entries_per_ring, |
| 5903 | ctx->tqm_max_entries_per_ring); |
Michael Chan | 1b9394e | 2018-10-14 07:02:44 -0400 | [diff] [blame] | 5904 | for (i = 0, ena = 0; i < bp->max_q + 1; i++) { |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5905 | ctx_pg = ctx->tqm_mem[i]; |
| 5906 | ctx_pg->entries = entries; |
| 5907 | mem_size = ctx->tqm_entry_size * entries; |
| 5908 | rc = bnxt_alloc_ctx_mem_blk(bp, ctx_pg, mem_size); |
| 5909 | if (rc) |
| 5910 | return rc; |
Michael Chan | 1b9394e | 2018-10-14 07:02:44 -0400 | [diff] [blame] | 5911 | ena |= FUNC_BACKING_STORE_CFG_REQ_ENABLES_TQM_SP << i; |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5912 | } |
Michael Chan | 1b9394e | 2018-10-14 07:02:44 -0400 | [diff] [blame] | 5913 | ena |= FUNC_BACKING_STORE_CFG_REQ_DFLT_ENABLES; |
| 5914 | rc = bnxt_hwrm_func_backing_store_cfg(bp, ena); |
| 5915 | if (rc) |
| 5916 | netdev_err(bp->dev, "Failed configuring context mem, rc = %d.\n", |
| 5917 | rc); |
| 5918 | else |
| 5919 | ctx->flags |= BNXT_CTX_FLAG_INITED; |
| 5920 | |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 5921 | return 0; |
| 5922 | } |
| 5923 | |
Michael Chan | db4723b | 2018-03-31 13:54:13 -0400 | [diff] [blame] | 5924 | int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all) |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5925 | { |
| 5926 | struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 5927 | struct hwrm_func_resource_qcaps_input req = {0}; |
| 5928 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 5929 | int rc; |
| 5930 | |
| 5931 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESOURCE_QCAPS, -1, -1); |
| 5932 | req.fid = cpu_to_le16(0xffff); |
| 5933 | |
| 5934 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5935 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5936 | if (rc) { |
| 5937 | rc = -EIO; |
| 5938 | goto hwrm_func_resc_qcaps_exit; |
| 5939 | } |
| 5940 | |
Michael Chan | db4723b | 2018-03-31 13:54:13 -0400 | [diff] [blame] | 5941 | hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs); |
| 5942 | if (!all) |
| 5943 | goto hwrm_func_resc_qcaps_exit; |
| 5944 | |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5945 | hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx); |
| 5946 | hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 5947 | hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings); |
| 5948 | hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 5949 | hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings); |
| 5950 | hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
| 5951 | hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings); |
| 5952 | hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
| 5953 | hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps); |
| 5954 | hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps); |
| 5955 | hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs); |
| 5956 | hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 5957 | hw_resc->min_vnics = le16_to_cpu(resp->min_vnics); |
| 5958 | hw_resc->max_vnics = le16_to_cpu(resp->max_vnics); |
| 5959 | hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx); |
| 5960 | hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
| 5961 | |
Michael Chan | 9c1fabd | 2018-10-14 07:02:47 -0400 | [diff] [blame] | 5962 | if (bp->flags & BNXT_FLAG_CHIP_P5) { |
| 5963 | u16 max_msix = le16_to_cpu(resp->max_msix); |
| 5964 | |
| 5965 | hw_resc->max_irqs = min_t(u16, hw_resc->max_irqs, max_msix); |
| 5966 | hw_resc->max_hw_ring_grps = hw_resc->max_rx_rings; |
| 5967 | } |
| 5968 | |
Michael Chan | 4673d66 | 2018-01-17 03:21:11 -0500 | [diff] [blame] | 5969 | if (BNXT_PF(bp)) { |
| 5970 | struct bnxt_pf_info *pf = &bp->pf; |
| 5971 | |
| 5972 | pf->vf_resv_strategy = |
| 5973 | le16_to_cpu(resp->vf_reservation_strategy); |
Michael Chan | bf82736 | 2018-08-05 16:51:50 -0400 | [diff] [blame] | 5974 | if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL_STATIC) |
Michael Chan | 4673d66 | 2018-01-17 03:21:11 -0500 | [diff] [blame] | 5975 | pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL; |
| 5976 | } |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5977 | hwrm_func_resc_qcaps_exit: |
| 5978 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5979 | return rc; |
| 5980 | } |
| 5981 | |
| 5982 | static int __bnxt_hwrm_func_qcaps(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5983 | { |
| 5984 | int rc = 0; |
| 5985 | struct hwrm_func_qcaps_input req = {0}; |
| 5986 | struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5987 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 5988 | u32 flags; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5989 | |
| 5990 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1); |
| 5991 | req.fid = cpu_to_le16(0xffff); |
| 5992 | |
| 5993 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5994 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5995 | if (rc) |
| 5996 | goto hwrm_func_qcaps_exit; |
| 5997 | |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5998 | flags = le32_to_cpu(resp->flags); |
| 5999 | if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED) |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 6000 | bp->flags |= BNXT_FLAG_ROCEV1_CAP; |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6001 | if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED) |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 6002 | bp->flags |= BNXT_FLAG_ROCEV2_CAP; |
| 6003 | |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 6004 | bp->tx_push_thresh = 0; |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6005 | if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 6006 | bp->tx_push_thresh = BNXT_TX_PUSH_THRESH; |
| 6007 | |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6008 | hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 6009 | hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 6010 | hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
| 6011 | hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
| 6012 | hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps); |
| 6013 | if (!hw_resc->max_hw_ring_grps) |
| 6014 | hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings; |
| 6015 | hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 6016 | hw_resc->max_vnics = le16_to_cpu(resp->max_vnics); |
| 6017 | hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
| 6018 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6019 | if (BNXT_PF(bp)) { |
| 6020 | struct bnxt_pf_info *pf = &bp->pf; |
| 6021 | |
| 6022 | pf->fw_fid = le16_to_cpu(resp->fid); |
| 6023 | pf->port_id = le16_to_cpu(resp->port_id); |
Michael Chan | 87027db | 2016-07-01 18:46:28 -0400 | [diff] [blame] | 6024 | bp->dev->dev_port = pf->port_id; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 6025 | memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6026 | pf->first_vf_id = le16_to_cpu(resp->first_vf_id); |
| 6027 | pf->max_vfs = le16_to_cpu(resp->max_vfs); |
| 6028 | pf->max_encap_records = le32_to_cpu(resp->max_encap_records); |
| 6029 | pf->max_decap_records = le32_to_cpu(resp->max_decap_records); |
| 6030 | pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows); |
| 6031 | pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows); |
| 6032 | pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows); |
| 6033 | pf->max_rx_wm_flows = le32_to_cpu(resp->max_rx_wm_flows); |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6034 | if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED) |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 6035 | bp->flags |= BNXT_FLAG_WOL_CAP; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6036 | } else { |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 6037 | #ifdef CONFIG_BNXT_SRIOV |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6038 | struct bnxt_vf_info *vf = &bp->vf; |
| 6039 | |
| 6040 | vf->fw_fid = le16_to_cpu(resp->fid); |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 6041 | memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN); |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 6042 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6043 | } |
| 6044 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6045 | hwrm_func_qcaps_exit: |
| 6046 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6047 | return rc; |
| 6048 | } |
| 6049 | |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 6050 | static int bnxt_hwrm_func_qcaps(struct bnxt *bp) |
| 6051 | { |
| 6052 | int rc; |
| 6053 | |
| 6054 | rc = __bnxt_hwrm_func_qcaps(bp); |
| 6055 | if (rc) |
| 6056 | return rc; |
| 6057 | if (bp->hwrm_spec_code >= 0x10803) { |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 6058 | rc = bnxt_alloc_ctx_mem(bp); |
| 6059 | if (rc) |
| 6060 | return rc; |
Michael Chan | db4723b | 2018-03-31 13:54:13 -0400 | [diff] [blame] | 6061 | rc = bnxt_hwrm_func_resc_qcaps(bp, true); |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 6062 | if (!rc) |
Michael Chan | 97381a1 | 2018-08-05 16:51:54 -0400 | [diff] [blame] | 6063 | bp->fw_cap |= BNXT_FW_CAP_NEW_RM; |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 6064 | } |
| 6065 | return 0; |
| 6066 | } |
| 6067 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6068 | static int bnxt_hwrm_func_reset(struct bnxt *bp) |
| 6069 | { |
| 6070 | struct hwrm_func_reset_input req = {0}; |
| 6071 | |
| 6072 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1); |
| 6073 | req.enables = 0; |
| 6074 | |
| 6075 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT); |
| 6076 | } |
| 6077 | |
| 6078 | static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp) |
| 6079 | { |
| 6080 | int rc = 0; |
| 6081 | struct hwrm_queue_qportcfg_input req = {0}; |
| 6082 | struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | aabfc01 | 2018-08-05 16:51:58 -0400 | [diff] [blame] | 6083 | u8 i, j, *qptr; |
| 6084 | bool no_rdma; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6085 | |
| 6086 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1); |
| 6087 | |
| 6088 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6089 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6090 | if (rc) |
| 6091 | goto qportcfg_exit; |
| 6092 | |
| 6093 | if (!resp->max_configurable_queues) { |
| 6094 | rc = -EINVAL; |
| 6095 | goto qportcfg_exit; |
| 6096 | } |
| 6097 | bp->max_tc = resp->max_configurable_queues; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 6098 | bp->max_lltc = resp->max_configurable_lossless_queues; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6099 | if (bp->max_tc > BNXT_MAX_QUEUE) |
| 6100 | bp->max_tc = BNXT_MAX_QUEUE; |
| 6101 | |
Michael Chan | aabfc01 | 2018-08-05 16:51:58 -0400 | [diff] [blame] | 6102 | no_rdma = !(bp->flags & BNXT_FLAG_ROCE_CAP); |
| 6103 | qptr = &resp->queue_id0; |
| 6104 | for (i = 0, j = 0; i < bp->max_tc; i++) { |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 6105 | bp->q_info[j].queue_id = *qptr; |
| 6106 | bp->q_ids[i] = *qptr++; |
Michael Chan | aabfc01 | 2018-08-05 16:51:58 -0400 | [diff] [blame] | 6107 | bp->q_info[j].queue_profile = *qptr++; |
| 6108 | bp->tc_to_qidx[j] = j; |
| 6109 | if (!BNXT_CNPQ(bp->q_info[j].queue_profile) || |
| 6110 | (no_rdma && BNXT_PF(bp))) |
| 6111 | j++; |
| 6112 | } |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 6113 | bp->max_q = bp->max_tc; |
Michael Chan | aabfc01 | 2018-08-05 16:51:58 -0400 | [diff] [blame] | 6114 | bp->max_tc = max_t(u8, j, 1); |
| 6115 | |
Michael Chan | 441cabb | 2016-09-19 03:58:02 -0400 | [diff] [blame] | 6116 | if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG) |
| 6117 | bp->max_tc = 1; |
| 6118 | |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 6119 | if (bp->max_lltc > bp->max_tc) |
| 6120 | bp->max_lltc = bp->max_tc; |
| 6121 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6122 | qportcfg_exit: |
| 6123 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6124 | return rc; |
| 6125 | } |
| 6126 | |
| 6127 | static int bnxt_hwrm_ver_get(struct bnxt *bp) |
| 6128 | { |
| 6129 | int rc; |
| 6130 | struct hwrm_ver_get_input req = {0}; |
| 6131 | struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 6132 | u32 dev_caps_cfg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6133 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 6134 | bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6135 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1); |
| 6136 | req.hwrm_intf_maj = HWRM_VERSION_MAJOR; |
| 6137 | req.hwrm_intf_min = HWRM_VERSION_MINOR; |
| 6138 | req.hwrm_intf_upd = HWRM_VERSION_UPDATE; |
| 6139 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6140 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6141 | if (rc) |
| 6142 | goto hwrm_ver_get_exit; |
| 6143 | |
| 6144 | memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output)); |
| 6145 | |
Michael Chan | 894aa69 | 2018-01-17 03:21:03 -0500 | [diff] [blame] | 6146 | bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 | |
| 6147 | resp->hwrm_intf_min_8b << 8 | |
| 6148 | resp->hwrm_intf_upd_8b; |
| 6149 | if (resp->hwrm_intf_maj_8b < 1) { |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 6150 | netdev_warn(bp->dev, "HWRM interface %d.%d.%d is older than 1.0.0.\n", |
Michael Chan | 894aa69 | 2018-01-17 03:21:03 -0500 | [diff] [blame] | 6151 | resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b, |
| 6152 | resp->hwrm_intf_upd_8b); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 6153 | netdev_warn(bp->dev, "Please update firmware with HWRM interface 1.0.0 or newer.\n"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6154 | } |
Michael Chan | 431aa1e | 2017-10-26 11:51:23 -0400 | [diff] [blame] | 6155 | snprintf(bp->fw_ver_str, BC_HWRM_STR_LEN, "%d.%d.%d.%d", |
Michael Chan | 894aa69 | 2018-01-17 03:21:03 -0500 | [diff] [blame] | 6156 | resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b, |
| 6157 | resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6158 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 6159 | bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout); |
| 6160 | if (!bp->hwrm_cmd_timeout) |
| 6161 | bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 6162 | |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 6163 | if (resp->hwrm_intf_maj_8b >= 1) { |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 6164 | bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len); |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 6165 | bp->hwrm_max_ext_req_len = le16_to_cpu(resp->max_ext_req_len); |
| 6166 | } |
| 6167 | if (bp->hwrm_max_ext_req_len < HWRM_MAX_REQ_LEN) |
| 6168 | bp->hwrm_max_ext_req_len = HWRM_MAX_REQ_LEN; |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 6169 | |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 6170 | bp->chip_num = le16_to_cpu(resp->chip_num); |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 6171 | if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev && |
| 6172 | !resp->chip_metal) |
| 6173 | bp->flags |= BNXT_FLAG_CHIP_NITRO_A0; |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 6174 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 6175 | dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg); |
| 6176 | if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) && |
| 6177 | (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) |
Michael Chan | 97381a1 | 2018-08-05 16:51:54 -0400 | [diff] [blame] | 6178 | bp->fw_cap |= BNXT_FW_CAP_SHORT_CMD; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 6179 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6180 | hwrm_ver_get_exit: |
| 6181 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6182 | return rc; |
| 6183 | } |
| 6184 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 6185 | int bnxt_hwrm_fw_set_time(struct bnxt *bp) |
| 6186 | { |
| 6187 | struct hwrm_fw_set_time_input req = {0}; |
Arnd Bergmann | 7dfaa7b | 2017-11-06 15:04:39 +0100 | [diff] [blame] | 6188 | struct tm tm; |
| 6189 | time64_t now = ktime_get_real_seconds(); |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 6190 | |
Michael Chan | ca2c39e | 2018-04-26 17:44:34 -0400 | [diff] [blame] | 6191 | if ((BNXT_VF(bp) && bp->hwrm_spec_code < 0x10901) || |
| 6192 | bp->hwrm_spec_code < 0x10400) |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 6193 | return -EOPNOTSUPP; |
| 6194 | |
Arnd Bergmann | 7dfaa7b | 2017-11-06 15:04:39 +0100 | [diff] [blame] | 6195 | time64_to_tm(now, 0, &tm); |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 6196 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1); |
| 6197 | req.year = cpu_to_le16(1900 + tm.tm_year); |
| 6198 | req.month = 1 + tm.tm_mon; |
| 6199 | req.day = tm.tm_mday; |
| 6200 | req.hour = tm.tm_hour; |
| 6201 | req.minute = tm.tm_min; |
| 6202 | req.second = tm.tm_sec; |
| 6203 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6204 | } |
| 6205 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 6206 | static int bnxt_hwrm_port_qstats(struct bnxt *bp) |
| 6207 | { |
| 6208 | int rc; |
| 6209 | struct bnxt_pf_info *pf = &bp->pf; |
| 6210 | struct hwrm_port_qstats_input req = {0}; |
| 6211 | |
| 6212 | if (!(bp->flags & BNXT_FLAG_PORT_STATS)) |
| 6213 | return 0; |
| 6214 | |
| 6215 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1); |
| 6216 | req.port_id = cpu_to_le16(pf->port_id); |
| 6217 | req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map); |
| 6218 | req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map); |
| 6219 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6220 | return rc; |
| 6221 | } |
| 6222 | |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 6223 | static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp) |
| 6224 | { |
Michael Chan | 36e5334 | 2018-10-14 07:02:38 -0400 | [diff] [blame] | 6225 | struct hwrm_port_qstats_ext_output *resp = bp->hwrm_cmd_resp_addr; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 6226 | struct hwrm_port_qstats_ext_input req = {0}; |
| 6227 | struct bnxt_pf_info *pf = &bp->pf; |
Michael Chan | 36e5334 | 2018-10-14 07:02:38 -0400 | [diff] [blame] | 6228 | int rc; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 6229 | |
| 6230 | if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT)) |
| 6231 | return 0; |
| 6232 | |
| 6233 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1); |
| 6234 | req.port_id = cpu_to_le16(pf->port_id); |
| 6235 | req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext)); |
| 6236 | req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map); |
Michael Chan | 36e5334 | 2018-10-14 07:02:38 -0400 | [diff] [blame] | 6237 | req.tx_stat_size = cpu_to_le16(sizeof(struct tx_port_stats_ext)); |
| 6238 | req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_ext_map); |
| 6239 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6240 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6241 | if (!rc) { |
| 6242 | bp->fw_rx_stats_ext_size = le16_to_cpu(resp->rx_stat_size) / 8; |
| 6243 | bp->fw_tx_stats_ext_size = le16_to_cpu(resp->tx_stat_size) / 8; |
| 6244 | } else { |
| 6245 | bp->fw_rx_stats_ext_size = 0; |
| 6246 | bp->fw_tx_stats_ext_size = 0; |
| 6247 | } |
| 6248 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6249 | return rc; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 6250 | } |
| 6251 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6252 | static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp) |
| 6253 | { |
| 6254 | if (bp->vxlan_port_cnt) { |
| 6255 | bnxt_hwrm_tunnel_dst_port_free( |
| 6256 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 6257 | } |
| 6258 | bp->vxlan_port_cnt = 0; |
| 6259 | if (bp->nge_port_cnt) { |
| 6260 | bnxt_hwrm_tunnel_dst_port_free( |
| 6261 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 6262 | } |
| 6263 | bp->nge_port_cnt = 0; |
| 6264 | } |
| 6265 | |
| 6266 | static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa) |
| 6267 | { |
| 6268 | int rc, i; |
| 6269 | u32 tpa_flags = 0; |
| 6270 | |
| 6271 | if (set_tpa) |
| 6272 | tpa_flags = bp->flags & BNXT_FLAG_TPA; |
| 6273 | for (i = 0; i < bp->nr_vnics; i++) { |
| 6274 | rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags); |
| 6275 | if (rc) { |
| 6276 | netdev_err(bp->dev, "hwrm vnic set tpa failure rc for vnic %d: %x\n", |
Sankar Patchineelam | 23e12c8 | 2017-03-28 19:47:30 -0400 | [diff] [blame] | 6277 | i, rc); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6278 | return rc; |
| 6279 | } |
| 6280 | } |
| 6281 | return 0; |
| 6282 | } |
| 6283 | |
| 6284 | static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp) |
| 6285 | { |
| 6286 | int i; |
| 6287 | |
| 6288 | for (i = 0; i < bp->nr_vnics; i++) |
| 6289 | bnxt_hwrm_vnic_set_rss(bp, i, false); |
| 6290 | } |
| 6291 | |
| 6292 | static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path, |
| 6293 | bool irq_re_init) |
| 6294 | { |
| 6295 | if (bp->vnic_info) { |
| 6296 | bnxt_hwrm_clear_vnic_filter(bp); |
| 6297 | /* clear all RSS setting before free vnic ctx */ |
| 6298 | bnxt_hwrm_clear_vnic_rss(bp); |
| 6299 | bnxt_hwrm_vnic_ctx_free(bp); |
| 6300 | /* before free the vnic, undo the vnic tpa settings */ |
| 6301 | if (bp->flags & BNXT_FLAG_TPA) |
| 6302 | bnxt_set_tpa(bp, false); |
| 6303 | bnxt_hwrm_vnic_free(bp); |
| 6304 | } |
| 6305 | bnxt_hwrm_ring_free(bp, close_path); |
| 6306 | bnxt_hwrm_ring_grp_free(bp); |
| 6307 | if (irq_re_init) { |
| 6308 | bnxt_hwrm_stat_ctx_free(bp); |
| 6309 | bnxt_hwrm_free_tunnel_ports(bp); |
| 6310 | } |
| 6311 | } |
| 6312 | |
Michael Chan | 39d8ba2 | 2017-07-24 12:34:22 -0400 | [diff] [blame] | 6313 | static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode) |
| 6314 | { |
| 6315 | struct hwrm_func_cfg_input req = {0}; |
| 6316 | int rc; |
| 6317 | |
| 6318 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 6319 | req.fid = cpu_to_le16(0xffff); |
| 6320 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE); |
| 6321 | if (br_mode == BRIDGE_MODE_VEB) |
| 6322 | req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB; |
| 6323 | else if (br_mode == BRIDGE_MODE_VEPA) |
| 6324 | req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA; |
| 6325 | else |
| 6326 | return -EINVAL; |
| 6327 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6328 | if (rc) |
| 6329 | rc = -EIO; |
| 6330 | return rc; |
| 6331 | } |
| 6332 | |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 6333 | static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size) |
| 6334 | { |
| 6335 | struct hwrm_func_cfg_input req = {0}; |
| 6336 | int rc; |
| 6337 | |
| 6338 | if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803) |
| 6339 | return 0; |
| 6340 | |
| 6341 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 6342 | req.fid = cpu_to_le16(0xffff); |
| 6343 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE); |
Michael Chan | d4f52de0 | 2018-03-31 13:54:06 -0400 | [diff] [blame] | 6344 | req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64; |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 6345 | if (size == 128) |
Michael Chan | d4f52de0 | 2018-03-31 13:54:06 -0400 | [diff] [blame] | 6346 | req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128; |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 6347 | |
| 6348 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6349 | if (rc) |
| 6350 | rc = -EIO; |
| 6351 | return rc; |
| 6352 | } |
| 6353 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6354 | static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id) |
| 6355 | { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6356 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6357 | int rc; |
| 6358 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6359 | if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) |
| 6360 | goto skip_rss_ctx; |
| 6361 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6362 | /* allocate context for vnic */ |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 6363 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6364 | if (rc) { |
| 6365 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 6366 | vnic_id, rc); |
| 6367 | goto vnic_setup_err; |
| 6368 | } |
| 6369 | bp->rsscos_nr_ctxs++; |
| 6370 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 6371 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 6372 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1); |
| 6373 | if (rc) { |
| 6374 | netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n", |
| 6375 | vnic_id, rc); |
| 6376 | goto vnic_setup_err; |
| 6377 | } |
| 6378 | bp->rsscos_nr_ctxs++; |
| 6379 | } |
| 6380 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6381 | skip_rss_ctx: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6382 | /* configure default vnic, ring grp */ |
| 6383 | rc = bnxt_hwrm_vnic_cfg(bp, vnic_id); |
| 6384 | if (rc) { |
| 6385 | netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n", |
| 6386 | vnic_id, rc); |
| 6387 | goto vnic_setup_err; |
| 6388 | } |
| 6389 | |
| 6390 | /* Enable RSS hashing on vnic */ |
| 6391 | rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true); |
| 6392 | if (rc) { |
| 6393 | netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n", |
| 6394 | vnic_id, rc); |
| 6395 | goto vnic_setup_err; |
| 6396 | } |
| 6397 | |
| 6398 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 6399 | rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id); |
| 6400 | if (rc) { |
| 6401 | netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n", |
| 6402 | vnic_id, rc); |
| 6403 | } |
| 6404 | } |
| 6405 | |
| 6406 | vnic_setup_err: |
| 6407 | return rc; |
| 6408 | } |
| 6409 | |
| 6410 | static int bnxt_alloc_rfs_vnics(struct bnxt *bp) |
| 6411 | { |
| 6412 | #ifdef CONFIG_RFS_ACCEL |
| 6413 | int i, rc = 0; |
| 6414 | |
| 6415 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6416 | struct bnxt_vnic_info *vnic; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6417 | u16 vnic_id = i + 1; |
| 6418 | u16 ring_id = i; |
| 6419 | |
| 6420 | if (vnic_id >= bp->nr_vnics) |
| 6421 | break; |
| 6422 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 6423 | vnic = &bp->vnic_info[vnic_id]; |
| 6424 | vnic->flags |= BNXT_VNIC_RFS_FLAG; |
| 6425 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 6426 | vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6427 | rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6428 | if (rc) { |
| 6429 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 6430 | vnic_id, rc); |
| 6431 | break; |
| 6432 | } |
| 6433 | rc = bnxt_setup_vnic(bp, vnic_id); |
| 6434 | if (rc) |
| 6435 | break; |
| 6436 | } |
| 6437 | return rc; |
| 6438 | #else |
| 6439 | return 0; |
| 6440 | #endif |
| 6441 | } |
| 6442 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 6443 | /* Allow PF and VF with default VLAN to be in promiscuous mode */ |
| 6444 | static bool bnxt_promisc_ok(struct bnxt *bp) |
| 6445 | { |
| 6446 | #ifdef CONFIG_BNXT_SRIOV |
| 6447 | if (BNXT_VF(bp) && !bp->vf.vlan) |
| 6448 | return false; |
| 6449 | #endif |
| 6450 | return true; |
| 6451 | } |
| 6452 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 6453 | static int bnxt_setup_nitroa0_vnic(struct bnxt *bp) |
| 6454 | { |
| 6455 | unsigned int rc = 0; |
| 6456 | |
| 6457 | rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1); |
| 6458 | if (rc) { |
| 6459 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 6460 | rc); |
| 6461 | return rc; |
| 6462 | } |
| 6463 | |
| 6464 | rc = bnxt_hwrm_vnic_cfg(bp, 1); |
| 6465 | if (rc) { |
| 6466 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 6467 | rc); |
| 6468 | return rc; |
| 6469 | } |
| 6470 | return rc; |
| 6471 | } |
| 6472 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6473 | static int bnxt_cfg_rx_mode(struct bnxt *); |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 6474 | static bool bnxt_mc_list_updated(struct bnxt *, u32 *); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6475 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6476 | static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init) |
| 6477 | { |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 6478 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6479 | int rc = 0; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 6480 | unsigned int rx_nr_rings = bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6481 | |
| 6482 | if (irq_re_init) { |
| 6483 | rc = bnxt_hwrm_stat_ctx_alloc(bp); |
| 6484 | if (rc) { |
| 6485 | netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n", |
| 6486 | rc); |
| 6487 | goto err_out; |
| 6488 | } |
| 6489 | } |
| 6490 | |
| 6491 | rc = bnxt_hwrm_ring_alloc(bp); |
| 6492 | if (rc) { |
| 6493 | netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc); |
| 6494 | goto err_out; |
| 6495 | } |
| 6496 | |
| 6497 | rc = bnxt_hwrm_ring_grp_alloc(bp); |
| 6498 | if (rc) { |
| 6499 | netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc); |
| 6500 | goto err_out; |
| 6501 | } |
| 6502 | |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 6503 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 6504 | rx_nr_rings--; |
| 6505 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6506 | /* default vnic 0 */ |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 6507 | rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6508 | if (rc) { |
| 6509 | netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc); |
| 6510 | goto err_out; |
| 6511 | } |
| 6512 | |
| 6513 | rc = bnxt_setup_vnic(bp, 0); |
| 6514 | if (rc) |
| 6515 | goto err_out; |
| 6516 | |
| 6517 | if (bp->flags & BNXT_FLAG_RFS) { |
| 6518 | rc = bnxt_alloc_rfs_vnics(bp); |
| 6519 | if (rc) |
| 6520 | goto err_out; |
| 6521 | } |
| 6522 | |
| 6523 | if (bp->flags & BNXT_FLAG_TPA) { |
| 6524 | rc = bnxt_set_tpa(bp, true); |
| 6525 | if (rc) |
| 6526 | goto err_out; |
| 6527 | } |
| 6528 | |
| 6529 | if (BNXT_VF(bp)) |
| 6530 | bnxt_update_vf_mac(bp); |
| 6531 | |
| 6532 | /* Filter for default vnic 0 */ |
| 6533 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr); |
| 6534 | if (rc) { |
| 6535 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc); |
| 6536 | goto err_out; |
| 6537 | } |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 6538 | vnic->uc_filter_count = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6539 | |
Michael Chan | 30e3384 | 2018-07-09 02:24:50 -0400 | [diff] [blame] | 6540 | vnic->rx_mask = 0; |
| 6541 | if (bp->dev->flags & IFF_BROADCAST) |
| 6542 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6543 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 6544 | if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 6545 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 6546 | |
| 6547 | if (bp->dev->flags & IFF_ALLMULTI) { |
| 6548 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 6549 | vnic->mc_list_count = 0; |
| 6550 | } else { |
| 6551 | u32 mask = 0; |
| 6552 | |
| 6553 | bnxt_mc_list_updated(bp, &mask); |
| 6554 | vnic->rx_mask |= mask; |
| 6555 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6556 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 6557 | rc = bnxt_cfg_rx_mode(bp); |
| 6558 | if (rc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6559 | goto err_out; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6560 | |
| 6561 | rc = bnxt_hwrm_set_coal(bp); |
| 6562 | if (rc) |
| 6563 | netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n", |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 6564 | rc); |
| 6565 | |
| 6566 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 6567 | rc = bnxt_setup_nitroa0_vnic(bp); |
| 6568 | if (rc) |
| 6569 | netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n", |
| 6570 | rc); |
| 6571 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6572 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 6573 | if (BNXT_VF(bp)) { |
| 6574 | bnxt_hwrm_func_qcfg(bp); |
| 6575 | netdev_update_features(bp->dev); |
| 6576 | } |
| 6577 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6578 | return 0; |
| 6579 | |
| 6580 | err_out: |
| 6581 | bnxt_hwrm_resource_free(bp, 0, true); |
| 6582 | |
| 6583 | return rc; |
| 6584 | } |
| 6585 | |
| 6586 | static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init) |
| 6587 | { |
| 6588 | bnxt_hwrm_resource_free(bp, 1, irq_re_init); |
| 6589 | return 0; |
| 6590 | } |
| 6591 | |
| 6592 | static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init) |
| 6593 | { |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 6594 | bnxt_init_cp_rings(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6595 | bnxt_init_rx_rings(bp); |
| 6596 | bnxt_init_tx_rings(bp); |
| 6597 | bnxt_init_ring_grps(bp, irq_re_init); |
| 6598 | bnxt_init_vnics(bp); |
| 6599 | |
| 6600 | return bnxt_init_chip(bp, irq_re_init); |
| 6601 | } |
| 6602 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6603 | static int bnxt_set_real_num_queues(struct bnxt *bp) |
| 6604 | { |
| 6605 | int rc; |
| 6606 | struct net_device *dev = bp->dev; |
| 6607 | |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 6608 | rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings - |
| 6609 | bp->tx_nr_rings_xdp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6610 | if (rc) |
| 6611 | return rc; |
| 6612 | |
| 6613 | rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings); |
| 6614 | if (rc) |
| 6615 | return rc; |
| 6616 | |
| 6617 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 45019a1 | 2015-12-27 18:19:22 -0500 | [diff] [blame] | 6618 | if (bp->flags & BNXT_FLAG_RFS) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6619 | dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6620 | #endif |
| 6621 | |
| 6622 | return rc; |
| 6623 | } |
| 6624 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 6625 | static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, |
| 6626 | bool shared) |
| 6627 | { |
| 6628 | int _rx = *rx, _tx = *tx; |
| 6629 | |
| 6630 | if (shared) { |
| 6631 | *rx = min_t(int, _rx, max); |
| 6632 | *tx = min_t(int, _tx, max); |
| 6633 | } else { |
| 6634 | if (max < 2) |
| 6635 | return -ENOMEM; |
| 6636 | |
| 6637 | while (_rx + _tx > max) { |
| 6638 | if (_rx > _tx && _rx > 1) |
| 6639 | _rx--; |
| 6640 | else if (_tx > 1) |
| 6641 | _tx--; |
| 6642 | } |
| 6643 | *rx = _rx; |
| 6644 | *tx = _tx; |
| 6645 | } |
| 6646 | return 0; |
| 6647 | } |
| 6648 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6649 | static void bnxt_setup_msix(struct bnxt *bp) |
| 6650 | { |
| 6651 | const int len = sizeof(bp->irq_tbl[0].name); |
| 6652 | struct net_device *dev = bp->dev; |
| 6653 | int tcs, i; |
| 6654 | |
| 6655 | tcs = netdev_get_num_tc(dev); |
| 6656 | if (tcs > 1) { |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 6657 | int i, off, count; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6658 | |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 6659 | for (i = 0; i < tcs; i++) { |
| 6660 | count = bp->tx_nr_rings_per_tc; |
| 6661 | off = i * count; |
| 6662 | netdev_set_tc_queue(dev, i, count, off); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6663 | } |
| 6664 | } |
| 6665 | |
| 6666 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6667 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6668 | char *attr; |
| 6669 | |
| 6670 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 6671 | attr = "TxRx"; |
| 6672 | else if (i < bp->rx_nr_rings) |
| 6673 | attr = "rx"; |
| 6674 | else |
| 6675 | attr = "tx"; |
| 6676 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6677 | snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name, |
| 6678 | attr, i); |
| 6679 | bp->irq_tbl[map_idx].handler = bnxt_msix; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6680 | } |
| 6681 | } |
| 6682 | |
| 6683 | static void bnxt_setup_inta(struct bnxt *bp) |
| 6684 | { |
| 6685 | const int len = sizeof(bp->irq_tbl[0].name); |
| 6686 | |
| 6687 | if (netdev_get_num_tc(bp->dev)) |
| 6688 | netdev_reset_tc(bp->dev); |
| 6689 | |
| 6690 | snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx", |
| 6691 | 0); |
| 6692 | bp->irq_tbl[0].handler = bnxt_inta; |
| 6693 | } |
| 6694 | |
| 6695 | static int bnxt_setup_int_mode(struct bnxt *bp) |
| 6696 | { |
| 6697 | int rc; |
| 6698 | |
| 6699 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 6700 | bnxt_setup_msix(bp); |
| 6701 | else |
| 6702 | bnxt_setup_inta(bp); |
| 6703 | |
| 6704 | rc = bnxt_set_real_num_queues(bp); |
| 6705 | return rc; |
| 6706 | } |
| 6707 | |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 6708 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6709 | static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp) |
| 6710 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6711 | return bp->hw_resc.max_rsscos_ctxs; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6712 | } |
| 6713 | |
| 6714 | static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp) |
| 6715 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6716 | return bp->hw_resc.max_vnics; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6717 | } |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 6718 | #endif |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 6719 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 6720 | unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp) |
| 6721 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6722 | return bp->hw_resc.max_stat_ctxs; |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 6723 | } |
| 6724 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 6725 | void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max) |
| 6726 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6727 | bp->hw_resc.max_stat_ctxs = max; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 6728 | } |
| 6729 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 6730 | unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp) |
| 6731 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6732 | return bp->hw_resc.max_cp_rings; |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 6733 | } |
| 6734 | |
Michael Chan | 00fe9c3 | 2018-09-03 04:23:19 -0400 | [diff] [blame] | 6735 | unsigned int bnxt_get_max_func_cp_rings_for_en(struct bnxt *bp) |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 6736 | { |
Michael Chan | 00fe9c3 | 2018-09-03 04:23:19 -0400 | [diff] [blame] | 6737 | return bp->hw_resc.max_cp_rings - bnxt_get_ulp_msix_num(bp); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 6738 | } |
| 6739 | |
Michael Chan | ad95c27 | 2018-09-03 04:23:18 -0400 | [diff] [blame] | 6740 | static unsigned int bnxt_get_max_func_irqs(struct bnxt *bp) |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6741 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6742 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 6743 | |
| 6744 | return min_t(unsigned int, hw_resc->max_irqs, hw_resc->max_cp_rings); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6745 | } |
| 6746 | |
Michael Chan | 30f5294 | 2018-07-09 02:24:51 -0400 | [diff] [blame] | 6747 | static void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs) |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 6748 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 6749 | bp->hw_resc.max_irqs = max_irqs; |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 6750 | } |
| 6751 | |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 6752 | int bnxt_get_avail_msix(struct bnxt *bp, int num) |
| 6753 | { |
| 6754 | int max_cp = bnxt_get_max_func_cp_rings(bp); |
| 6755 | int max_irq = bnxt_get_max_func_irqs(bp); |
| 6756 | int total_req = bp->cp_nr_rings + num; |
| 6757 | int max_idx, avail_msix; |
| 6758 | |
| 6759 | max_idx = min_t(int, bp->total_irqs, max_cp); |
| 6760 | avail_msix = max_idx - bp->cp_nr_rings; |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 6761 | if (!BNXT_NEW_RM(bp) || avail_msix >= num) |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 6762 | return avail_msix; |
| 6763 | |
| 6764 | if (max_irq < total_req) { |
| 6765 | num = max_irq - bp->cp_nr_rings; |
| 6766 | if (num <= 0) |
| 6767 | return 0; |
| 6768 | } |
| 6769 | return num; |
| 6770 | } |
| 6771 | |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 6772 | static int bnxt_get_num_msix(struct bnxt *bp) |
| 6773 | { |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 6774 | if (!BNXT_NEW_RM(bp)) |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 6775 | return bnxt_get_max_func_irqs(bp); |
| 6776 | |
| 6777 | return bnxt_cp_rings_in_use(bp); |
| 6778 | } |
| 6779 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6780 | static int bnxt_init_msix(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6781 | { |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 6782 | int i, total_vecs, max, rc = 0, min = 1, ulp_msix; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6783 | struct msix_entry *msix_ent; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6784 | |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 6785 | total_vecs = bnxt_get_num_msix(bp); |
| 6786 | max = bnxt_get_max_func_irqs(bp); |
| 6787 | if (total_vecs > max) |
| 6788 | total_vecs = max; |
| 6789 | |
Michael Chan | 2773dfb | 2018-04-26 17:44:42 -0400 | [diff] [blame] | 6790 | if (!total_vecs) |
| 6791 | return 0; |
| 6792 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6793 | msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL); |
| 6794 | if (!msix_ent) |
| 6795 | return -ENOMEM; |
| 6796 | |
| 6797 | for (i = 0; i < total_vecs; i++) { |
| 6798 | msix_ent[i].entry = i; |
| 6799 | msix_ent[i].vector = 0; |
| 6800 | } |
| 6801 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 6802 | if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) |
| 6803 | min = 2; |
| 6804 | |
| 6805 | total_vecs = pci_enable_msix_range(bp->pdev, msix_ent, min, total_vecs); |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 6806 | ulp_msix = bnxt_get_ulp_msix_num(bp); |
| 6807 | if (total_vecs < 0 || total_vecs < ulp_msix) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6808 | rc = -ENODEV; |
| 6809 | goto msix_setup_exit; |
| 6810 | } |
| 6811 | |
| 6812 | bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL); |
| 6813 | if (bp->irq_tbl) { |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6814 | for (i = 0; i < total_vecs; i++) |
| 6815 | bp->irq_tbl[i].vector = msix_ent[i].vector; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6816 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6817 | bp->total_irqs = total_vecs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6818 | /* Trim rings based upon num of vectors allocated */ |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 6819 | rc = bnxt_trim_rings(bp, &bp->rx_nr_rings, &bp->tx_nr_rings, |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 6820 | total_vecs - ulp_msix, min == 1); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 6821 | if (rc) |
| 6822 | goto msix_setup_exit; |
| 6823 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6824 | bp->cp_nr_rings = (min == 1) ? |
| 6825 | max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 6826 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6827 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6828 | } else { |
| 6829 | rc = -ENOMEM; |
| 6830 | goto msix_setup_exit; |
| 6831 | } |
| 6832 | bp->flags |= BNXT_FLAG_USING_MSIX; |
| 6833 | kfree(msix_ent); |
| 6834 | return 0; |
| 6835 | |
| 6836 | msix_setup_exit: |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6837 | netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc); |
| 6838 | kfree(bp->irq_tbl); |
| 6839 | bp->irq_tbl = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6840 | pci_disable_msix(bp->pdev); |
| 6841 | kfree(msix_ent); |
| 6842 | return rc; |
| 6843 | } |
| 6844 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6845 | static int bnxt_init_inta(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6846 | { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6847 | bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6848 | if (!bp->irq_tbl) |
| 6849 | return -ENOMEM; |
| 6850 | |
| 6851 | bp->total_irqs = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6852 | bp->rx_nr_rings = 1; |
| 6853 | bp->tx_nr_rings = 1; |
| 6854 | bp->cp_nr_rings = 1; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 6855 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6856 | bp->irq_tbl[0].vector = bp->pdev->irq; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6857 | return 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6858 | } |
| 6859 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6860 | static int bnxt_init_int_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6861 | { |
| 6862 | int rc = 0; |
| 6863 | |
| 6864 | if (bp->flags & BNXT_FLAG_MSIX_CAP) |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6865 | rc = bnxt_init_msix(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6866 | |
Michael Chan | 1fa72e2 | 2016-04-25 02:30:49 -0400 | [diff] [blame] | 6867 | if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6868 | /* fallback to INTA */ |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6869 | rc = bnxt_init_inta(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6870 | } |
| 6871 | return rc; |
| 6872 | } |
| 6873 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6874 | static void bnxt_clear_int_mode(struct bnxt *bp) |
| 6875 | { |
| 6876 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 6877 | pci_disable_msix(bp->pdev); |
| 6878 | |
| 6879 | kfree(bp->irq_tbl); |
| 6880 | bp->irq_tbl = NULL; |
| 6881 | bp->flags &= ~BNXT_FLAG_USING_MSIX; |
| 6882 | } |
| 6883 | |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame] | 6884 | int bnxt_reserve_rings(struct bnxt *bp) |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6885 | { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6886 | int tcs = netdev_get_num_tc(bp->dev); |
| 6887 | int rc; |
| 6888 | |
| 6889 | if (!bnxt_need_reserve_rings(bp)) |
| 6890 | return 0; |
| 6891 | |
| 6892 | rc = __bnxt_reserve_rings(bp); |
| 6893 | if (rc) { |
| 6894 | netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc); |
| 6895 | return rc; |
| 6896 | } |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 6897 | if (BNXT_NEW_RM(bp) && (bnxt_get_num_msix(bp) != bp->total_irqs)) { |
Michael Chan | ec86f14 | 2018-03-31 13:54:21 -0400 | [diff] [blame] | 6898 | bnxt_ulp_irq_stop(bp); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6899 | bnxt_clear_int_mode(bp); |
| 6900 | rc = bnxt_init_int_mode(bp); |
Michael Chan | ec86f14 | 2018-03-31 13:54:21 -0400 | [diff] [blame] | 6901 | bnxt_ulp_irq_restart(bp, rc); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6902 | if (rc) |
| 6903 | return rc; |
| 6904 | } |
| 6905 | if (tcs && (bp->tx_nr_rings_per_tc * tcs != bp->tx_nr_rings)) { |
| 6906 | netdev_err(bp->dev, "tx ring reservation failure\n"); |
| 6907 | netdev_reset_tc(bp->dev); |
| 6908 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 6909 | return -ENOMEM; |
| 6910 | } |
| 6911 | bp->num_stat_ctxs = bp->cp_nr_rings; |
| 6912 | return 0; |
| 6913 | } |
| 6914 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6915 | static void bnxt_free_irq(struct bnxt *bp) |
| 6916 | { |
| 6917 | struct bnxt_irq *irq; |
| 6918 | int i; |
| 6919 | |
| 6920 | #ifdef CONFIG_RFS_ACCEL |
| 6921 | free_irq_cpu_rmap(bp->dev->rx_cpu_rmap); |
| 6922 | bp->dev->rx_cpu_rmap = NULL; |
| 6923 | #endif |
Michael Chan | cb98526 | 2018-04-11 11:50:18 -0400 | [diff] [blame] | 6924 | if (!bp->irq_tbl || !bp->bnapi) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6925 | return; |
| 6926 | |
| 6927 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6928 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
| 6929 | |
| 6930 | irq = &bp->irq_tbl[map_idx]; |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 6931 | if (irq->requested) { |
| 6932 | if (irq->have_cpumask) { |
| 6933 | irq_set_affinity_hint(irq->vector, NULL); |
| 6934 | free_cpumask_var(irq->cpu_mask); |
| 6935 | irq->have_cpumask = 0; |
| 6936 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6937 | free_irq(irq->vector, bp->bnapi[i]); |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 6938 | } |
| 6939 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6940 | irq->requested = 0; |
| 6941 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6942 | } |
| 6943 | |
| 6944 | static int bnxt_request_irq(struct bnxt *bp) |
| 6945 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6946 | int i, j, rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6947 | unsigned long flags = 0; |
| 6948 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6949 | struct cpu_rmap *rmap; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6950 | #endif |
| 6951 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6952 | rc = bnxt_setup_int_mode(bp); |
| 6953 | if (rc) { |
| 6954 | netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n", |
| 6955 | rc); |
| 6956 | return rc; |
| 6957 | } |
| 6958 | #ifdef CONFIG_RFS_ACCEL |
| 6959 | rmap = bp->dev->rx_cpu_rmap; |
| 6960 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6961 | if (!(bp->flags & BNXT_FLAG_USING_MSIX)) |
| 6962 | flags = IRQF_SHARED; |
| 6963 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6964 | for (i = 0, j = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6965 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
| 6966 | struct bnxt_irq *irq = &bp->irq_tbl[map_idx]; |
| 6967 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6968 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6969 | if (rmap && bp->bnapi[i]->rx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6970 | rc = irq_cpu_rmap_add(rmap, irq->vector); |
| 6971 | if (rc) |
| 6972 | netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n", |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6973 | j); |
| 6974 | j++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6975 | } |
| 6976 | #endif |
| 6977 | rc = request_irq(irq->vector, irq->handler, flags, irq->name, |
| 6978 | bp->bnapi[i]); |
| 6979 | if (rc) |
| 6980 | break; |
| 6981 | |
| 6982 | irq->requested = 1; |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 6983 | |
| 6984 | if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) { |
| 6985 | int numa_node = dev_to_node(&bp->pdev->dev); |
| 6986 | |
| 6987 | irq->have_cpumask = 1; |
| 6988 | cpumask_set_cpu(cpumask_local_spread(i, numa_node), |
| 6989 | irq->cpu_mask); |
| 6990 | rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask); |
| 6991 | if (rc) { |
| 6992 | netdev_warn(bp->dev, |
| 6993 | "Set affinity failed, IRQ = %d\n", |
| 6994 | irq->vector); |
| 6995 | break; |
| 6996 | } |
| 6997 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6998 | } |
| 6999 | return rc; |
| 7000 | } |
| 7001 | |
| 7002 | static void bnxt_del_napi(struct bnxt *bp) |
| 7003 | { |
| 7004 | int i; |
| 7005 | |
| 7006 | if (!bp->bnapi) |
| 7007 | return; |
| 7008 | |
| 7009 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 7010 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 7011 | |
| 7012 | napi_hash_del(&bnapi->napi); |
| 7013 | netif_napi_del(&bnapi->napi); |
| 7014 | } |
Eric Dumazet | e5f6f56 | 2016-11-16 06:31:52 -0800 | [diff] [blame] | 7015 | /* We called napi_hash_del() before netif_napi_del(), we need |
| 7016 | * to respect an RCU grace period before freeing napi structures. |
| 7017 | */ |
| 7018 | synchronize_net(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7019 | } |
| 7020 | |
| 7021 | static void bnxt_init_napi(struct bnxt *bp) |
| 7022 | { |
| 7023 | int i; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 7024 | unsigned int cp_nr_rings = bp->cp_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7025 | struct bnxt_napi *bnapi; |
| 7026 | |
| 7027 | if (bp->flags & BNXT_FLAG_USING_MSIX) { |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 7028 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 7029 | cp_nr_rings--; |
| 7030 | for (i = 0; i < cp_nr_rings; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7031 | bnapi = bp->bnapi[i]; |
| 7032 | netif_napi_add(bp->dev, &bnapi->napi, |
| 7033 | bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7034 | } |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 7035 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 7036 | bnapi = bp->bnapi[cp_nr_rings]; |
| 7037 | netif_napi_add(bp->dev, &bnapi->napi, |
| 7038 | bnxt_poll_nitroa0, 64); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 7039 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7040 | } else { |
| 7041 | bnapi = bp->bnapi[0]; |
| 7042 | netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7043 | } |
| 7044 | } |
| 7045 | |
| 7046 | static void bnxt_disable_napi(struct bnxt *bp) |
| 7047 | { |
| 7048 | int i; |
| 7049 | |
| 7050 | if (!bp->bnapi) |
| 7051 | return; |
| 7052 | |
Andy Gospodarek | 0bc0b97 | 2018-01-26 10:27:47 -0500 | [diff] [blame] | 7053 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 7054 | struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; |
| 7055 | |
| 7056 | if (bp->bnapi[i]->rx_ring) |
| 7057 | cancel_work_sync(&cpr->dim.work); |
| 7058 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7059 | napi_disable(&bp->bnapi[i]->napi); |
Andy Gospodarek | 0bc0b97 | 2018-01-26 10:27:47 -0500 | [diff] [blame] | 7060 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | static void bnxt_enable_napi(struct bnxt *bp) |
| 7064 | { |
| 7065 | int i; |
| 7066 | |
| 7067 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 7068 | struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 7069 | bp->bnapi[i]->in_reset = false; |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 7070 | |
| 7071 | if (bp->bnapi[i]->rx_ring) { |
| 7072 | INIT_WORK(&cpr->dim.work, bnxt_dim_work); |
| 7073 | cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; |
| 7074 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7075 | napi_enable(&bp->bnapi[i]->napi); |
| 7076 | } |
| 7077 | } |
| 7078 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 7079 | void bnxt_tx_disable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7080 | { |
| 7081 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7082 | struct bnxt_tx_ring_info *txr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7083 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 7084 | if (bp->tx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7085 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 7086 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7087 | txr->dev_state = BNXT_DEV_STATE_CLOSING; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7088 | } |
| 7089 | } |
| 7090 | /* Stop all TX queues */ |
| 7091 | netif_tx_disable(bp->dev); |
| 7092 | netif_carrier_off(bp->dev); |
| 7093 | } |
| 7094 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 7095 | void bnxt_tx_enable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7096 | { |
| 7097 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7098 | struct bnxt_tx_ring_info *txr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7099 | |
| 7100 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 7101 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7102 | txr->dev_state = 0; |
| 7103 | } |
| 7104 | netif_tx_wake_all_queues(bp->dev); |
| 7105 | if (bp->link_info.link_up) |
| 7106 | netif_carrier_on(bp->dev); |
| 7107 | } |
| 7108 | |
| 7109 | static void bnxt_report_link(struct bnxt *bp) |
| 7110 | { |
| 7111 | if (bp->link_info.link_up) { |
| 7112 | const char *duplex; |
| 7113 | const char *flow_ctrl; |
Deepak Khungar | 38a21b3 | 2017-04-21 20:11:24 -0400 | [diff] [blame] | 7114 | u32 speed; |
| 7115 | u16 fec; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7116 | |
| 7117 | netif_carrier_on(bp->dev); |
| 7118 | if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL) |
| 7119 | duplex = "full"; |
| 7120 | else |
| 7121 | duplex = "half"; |
| 7122 | if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH) |
| 7123 | flow_ctrl = "ON - receive & transmit"; |
| 7124 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX) |
| 7125 | flow_ctrl = "ON - transmit"; |
| 7126 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX) |
| 7127 | flow_ctrl = "ON - receive"; |
| 7128 | else |
| 7129 | flow_ctrl = "none"; |
| 7130 | speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed); |
Deepak Khungar | 38a21b3 | 2017-04-21 20:11:24 -0400 | [diff] [blame] | 7131 | netdev_info(bp->dev, "NIC Link is Up, %u Mbps %s duplex, Flow control: %s\n", |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7132 | speed, duplex, flow_ctrl); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7133 | if (bp->flags & BNXT_FLAG_EEE_CAP) |
| 7134 | netdev_info(bp->dev, "EEE is %s\n", |
| 7135 | bp->eee.eee_active ? "active" : |
| 7136 | "not active"); |
Michael Chan | e70c752 | 2017-02-12 19:18:16 -0500 | [diff] [blame] | 7137 | fec = bp->link_info.fec_cfg; |
| 7138 | if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED)) |
| 7139 | netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n", |
| 7140 | (fec & BNXT_FEC_AUTONEG) ? "on" : "off", |
| 7141 | (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" : |
| 7142 | (fec & BNXT_FEC_ENC_RS) ? "RS" : "None"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7143 | } else { |
| 7144 | netif_carrier_off(bp->dev); |
| 7145 | netdev_err(bp->dev, "NIC Link is Down\n"); |
| 7146 | } |
| 7147 | } |
| 7148 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7149 | static int bnxt_hwrm_phy_qcaps(struct bnxt *bp) |
| 7150 | { |
| 7151 | int rc = 0; |
| 7152 | struct hwrm_port_phy_qcaps_input req = {0}; |
| 7153 | struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 7154 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7155 | |
| 7156 | if (bp->hwrm_spec_code < 0x10201) |
| 7157 | return 0; |
| 7158 | |
| 7159 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); |
| 7160 | |
| 7161 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7162 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7163 | if (rc) |
| 7164 | goto hwrm_phy_qcaps_exit; |
| 7165 | |
Michael Chan | acb2005 | 2017-07-24 12:34:20 -0400 | [diff] [blame] | 7166 | if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) { |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7167 | struct ethtool_eee *eee = &bp->eee; |
| 7168 | u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode); |
| 7169 | |
| 7170 | bp->flags |= BNXT_FLAG_EEE_CAP; |
| 7171 | eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 7172 | bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) & |
| 7173 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK; |
| 7174 | bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) & |
| 7175 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK; |
| 7176 | } |
Michael Chan | 55fd0cf | 2018-08-05 16:51:48 -0400 | [diff] [blame] | 7177 | if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EXTERNAL_LPBK_SUPPORTED) { |
| 7178 | if (bp->test_info) |
| 7179 | bp->test_info->flags |= BNXT_TEST_FL_EXT_LPBK; |
| 7180 | } |
Michael Chan | 520ad89 | 2017-03-08 18:44:35 -0500 | [diff] [blame] | 7181 | if (resp->supported_speeds_auto_mode) |
| 7182 | link_info->support_auto_speeds = |
| 7183 | le16_to_cpu(resp->supported_speeds_auto_mode); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7184 | |
Michael Chan | d5430d3 | 2017-08-28 13:40:31 -0400 | [diff] [blame] | 7185 | bp->port_count = resp->port_cnt; |
| 7186 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7187 | hwrm_phy_qcaps_exit: |
| 7188 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7189 | return rc; |
| 7190 | } |
| 7191 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7192 | static int bnxt_update_link(struct bnxt *bp, bool chng_link_state) |
| 7193 | { |
| 7194 | int rc = 0; |
| 7195 | struct bnxt_link_info *link_info = &bp->link_info; |
| 7196 | struct hwrm_port_phy_qcfg_input req = {0}; |
| 7197 | struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 7198 | u8 link_up = link_info->link_up; |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7199 | u16 diff; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7200 | |
| 7201 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1); |
| 7202 | |
| 7203 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7204 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7205 | if (rc) { |
| 7206 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7207 | return rc; |
| 7208 | } |
| 7209 | |
| 7210 | memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp)); |
| 7211 | link_info->phy_link_status = resp->link; |
Michael Chan | acb2005 | 2017-07-24 12:34:20 -0400 | [diff] [blame] | 7212 | link_info->duplex = resp->duplex_cfg; |
| 7213 | if (bp->hwrm_spec_code >= 0x10800) |
| 7214 | link_info->duplex = resp->duplex_state; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7215 | link_info->pause = resp->pause; |
| 7216 | link_info->auto_mode = resp->auto_mode; |
| 7217 | link_info->auto_pause_setting = resp->auto_pause; |
Michael Chan | 3277360 | 2016-03-07 15:38:42 -0500 | [diff] [blame] | 7218 | link_info->lp_pause = resp->link_partner_adv_pause; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7219 | link_info->force_pause_setting = resp->force_pause; |
Michael Chan | acb2005 | 2017-07-24 12:34:20 -0400 | [diff] [blame] | 7220 | link_info->duplex_setting = resp->duplex_cfg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7221 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 7222 | link_info->link_speed = le16_to_cpu(resp->link_speed); |
| 7223 | else |
| 7224 | link_info->link_speed = 0; |
| 7225 | link_info->force_link_speed = le16_to_cpu(resp->force_link_speed); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7226 | link_info->support_speeds = le16_to_cpu(resp->support_speeds); |
| 7227 | link_info->auto_link_speeds = le16_to_cpu(resp->auto_link_speed_mask); |
Michael Chan | 3277360 | 2016-03-07 15:38:42 -0500 | [diff] [blame] | 7228 | link_info->lp_auto_link_speeds = |
| 7229 | le16_to_cpu(resp->link_partner_adv_speeds); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7230 | link_info->preemphasis = le32_to_cpu(resp->preemphasis); |
| 7231 | link_info->phy_ver[0] = resp->phy_maj; |
| 7232 | link_info->phy_ver[1] = resp->phy_min; |
| 7233 | link_info->phy_ver[2] = resp->phy_bld; |
| 7234 | link_info->media_type = resp->media_type; |
Michael Chan | 03efbec | 2016-04-11 04:11:11 -0400 | [diff] [blame] | 7235 | link_info->phy_type = resp->phy_type; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 7236 | link_info->transceiver = resp->xcvr_pkg_type; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7237 | link_info->phy_addr = resp->eee_config_phy_addr & |
| 7238 | PORT_PHY_QCFG_RESP_PHY_ADDR_MASK; |
Ajit Khaparde | 42ee18f | 2016-05-15 03:04:44 -0400 | [diff] [blame] | 7239 | link_info->module_status = resp->module_status; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7240 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 7241 | if (bp->flags & BNXT_FLAG_EEE_CAP) { |
| 7242 | struct ethtool_eee *eee = &bp->eee; |
| 7243 | u16 fw_speeds; |
| 7244 | |
| 7245 | eee->eee_active = 0; |
| 7246 | if (resp->eee_config_phy_addr & |
| 7247 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) { |
| 7248 | eee->eee_active = 1; |
| 7249 | fw_speeds = le16_to_cpu( |
| 7250 | resp->link_partner_adv_eee_link_speed_mask); |
| 7251 | eee->lp_advertised = |
| 7252 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 7253 | } |
| 7254 | |
| 7255 | /* Pull initial EEE config */ |
| 7256 | if (!chng_link_state) { |
| 7257 | if (resp->eee_config_phy_addr & |
| 7258 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED) |
| 7259 | eee->eee_enabled = 1; |
| 7260 | |
| 7261 | fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask); |
| 7262 | eee->advertised = |
| 7263 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 7264 | |
| 7265 | if (resp->eee_config_phy_addr & |
| 7266 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) { |
| 7267 | __le32 tmr; |
| 7268 | |
| 7269 | eee->tx_lpi_enabled = 1; |
| 7270 | tmr = resp->xcvr_identifier_type_tx_lpi_timer; |
| 7271 | eee->tx_lpi_timer = le32_to_cpu(tmr) & |
| 7272 | PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK; |
| 7273 | } |
| 7274 | } |
| 7275 | } |
Michael Chan | e70c752 | 2017-02-12 19:18:16 -0500 | [diff] [blame] | 7276 | |
| 7277 | link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED; |
| 7278 | if (bp->hwrm_spec_code >= 0x10504) |
| 7279 | link_info->fec_cfg = le16_to_cpu(resp->fec_cfg); |
| 7280 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7281 | /* TODO: need to add more logic to report VF link */ |
| 7282 | if (chng_link_state) { |
| 7283 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 7284 | link_info->link_up = 1; |
| 7285 | else |
| 7286 | link_info->link_up = 0; |
| 7287 | if (link_up != link_info->link_up) |
| 7288 | bnxt_report_link(bp); |
| 7289 | } else { |
| 7290 | /* alwasy link down if not require to update link state */ |
| 7291 | link_info->link_up = 0; |
| 7292 | } |
| 7293 | mutex_unlock(&bp->hwrm_cmd_lock); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7294 | |
Michael Chan | dac04907 | 2018-05-08 03:18:39 -0400 | [diff] [blame] | 7295 | if (!BNXT_SINGLE_PF(bp)) |
| 7296 | return 0; |
| 7297 | |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7298 | diff = link_info->support_auto_speeds ^ link_info->advertising; |
| 7299 | if ((link_info->support_auto_speeds | diff) != |
| 7300 | link_info->support_auto_speeds) { |
| 7301 | /* An advertised speed is no longer supported, so we need to |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 7302 | * update the advertisement settings. Caller holds RTNL |
| 7303 | * so we can modify link settings. |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7304 | */ |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7305 | link_info->advertising = link_info->support_auto_speeds; |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 7306 | if (link_info->autoneg & BNXT_AUTONEG_SPEED) |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7307 | bnxt_hwrm_set_link_setting(bp, true, false); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 7308 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7309 | return 0; |
| 7310 | } |
| 7311 | |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 7312 | static void bnxt_get_port_module_status(struct bnxt *bp) |
| 7313 | { |
| 7314 | struct bnxt_link_info *link_info = &bp->link_info; |
| 7315 | struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp; |
| 7316 | u8 module_status; |
| 7317 | |
| 7318 | if (bnxt_update_link(bp, true)) |
| 7319 | return; |
| 7320 | |
| 7321 | module_status = link_info->module_status; |
| 7322 | switch (module_status) { |
| 7323 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX: |
| 7324 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN: |
| 7325 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG: |
| 7326 | netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n", |
| 7327 | bp->pf.port_id); |
| 7328 | if (bp->hwrm_spec_code >= 0x10201) { |
| 7329 | netdev_warn(bp->dev, "Module part number %s\n", |
| 7330 | resp->phy_vendor_partnumber); |
| 7331 | } |
| 7332 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX) |
| 7333 | netdev_warn(bp->dev, "TX is disabled\n"); |
| 7334 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN) |
| 7335 | netdev_warn(bp->dev, "SFP+ module is shutdown\n"); |
| 7336 | } |
| 7337 | } |
| 7338 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7339 | static void |
| 7340 | bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req) |
| 7341 | { |
| 7342 | if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7343 | if (bp->hwrm_spec_code >= 0x10201) |
| 7344 | req->auto_pause = |
| 7345 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7346 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 7347 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX; |
| 7348 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
Michael Chan | 49b5c7a | 2016-03-28 19:46:06 -0400 | [diff] [blame] | 7349 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7350 | req->enables |= |
| 7351 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 7352 | } else { |
| 7353 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 7354 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX; |
| 7355 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
| 7356 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX; |
| 7357 | req->enables |= |
| 7358 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE); |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7359 | if (bp->hwrm_spec_code >= 0x10201) { |
| 7360 | req->auto_pause = req->force_pause; |
| 7361 | req->enables |= cpu_to_le32( |
| 7362 | PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 7363 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7364 | } |
| 7365 | } |
| 7366 | |
| 7367 | static void bnxt_hwrm_set_link_common(struct bnxt *bp, |
| 7368 | struct hwrm_port_phy_cfg_input *req) |
| 7369 | { |
| 7370 | u8 autoneg = bp->link_info.autoneg; |
| 7371 | u16 fw_link_speed = bp->link_info.req_link_speed; |
Michael Chan | 68515a1 | 2016-12-29 12:13:34 -0500 | [diff] [blame] | 7372 | u16 advertising = bp->link_info.advertising; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7373 | |
| 7374 | if (autoneg & BNXT_AUTONEG_SPEED) { |
| 7375 | req->auto_mode |= |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 7376 | PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7377 | |
| 7378 | req->enables |= cpu_to_le32( |
| 7379 | PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK); |
| 7380 | req->auto_link_speed_mask = cpu_to_le16(advertising); |
| 7381 | |
| 7382 | req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE); |
| 7383 | req->flags |= |
| 7384 | cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG); |
| 7385 | } else { |
| 7386 | req->force_link_speed = cpu_to_le16(fw_link_speed); |
| 7387 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE); |
| 7388 | } |
| 7389 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7390 | /* tell chimp that the setting takes effect immediately */ |
| 7391 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); |
| 7392 | } |
| 7393 | |
| 7394 | int bnxt_hwrm_set_pause(struct bnxt *bp) |
| 7395 | { |
| 7396 | struct hwrm_port_phy_cfg_input req = {0}; |
| 7397 | int rc; |
| 7398 | |
| 7399 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 7400 | bnxt_hwrm_set_pause_common(bp, &req); |
| 7401 | |
| 7402 | if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) || |
| 7403 | bp->link_info.force_link_chng) |
| 7404 | bnxt_hwrm_set_link_common(bp, &req); |
| 7405 | |
| 7406 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7407 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7408 | if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) { |
| 7409 | /* since changing of pause setting doesn't trigger any link |
| 7410 | * change event, the driver needs to update the current pause |
| 7411 | * result upon successfully return of the phy_cfg command |
| 7412 | */ |
| 7413 | bp->link_info.pause = |
| 7414 | bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl; |
| 7415 | bp->link_info.auto_pause_setting = 0; |
| 7416 | if (!bp->link_info.force_link_chng) |
| 7417 | bnxt_report_link(bp); |
| 7418 | } |
| 7419 | bp->link_info.force_link_chng = false; |
| 7420 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7421 | return rc; |
| 7422 | } |
| 7423 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 7424 | static void bnxt_hwrm_set_eee(struct bnxt *bp, |
| 7425 | struct hwrm_port_phy_cfg_input *req) |
| 7426 | { |
| 7427 | struct ethtool_eee *eee = &bp->eee; |
| 7428 | |
| 7429 | if (eee->eee_enabled) { |
| 7430 | u16 eee_speeds; |
| 7431 | u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE; |
| 7432 | |
| 7433 | if (eee->tx_lpi_enabled) |
| 7434 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE; |
| 7435 | else |
| 7436 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE; |
| 7437 | |
| 7438 | req->flags |= cpu_to_le32(flags); |
| 7439 | eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised); |
| 7440 | req->eee_link_speed_mask = cpu_to_le16(eee_speeds); |
| 7441 | req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer); |
| 7442 | } else { |
| 7443 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE); |
| 7444 | } |
| 7445 | } |
| 7446 | |
| 7447 | int bnxt_hwrm_set_link_setting(struct bnxt *bp, bool set_pause, bool set_eee) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7448 | { |
| 7449 | struct hwrm_port_phy_cfg_input req = {0}; |
| 7450 | |
| 7451 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 7452 | if (set_pause) |
| 7453 | bnxt_hwrm_set_pause_common(bp, &req); |
| 7454 | |
| 7455 | bnxt_hwrm_set_link_common(bp, &req); |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 7456 | |
| 7457 | if (set_eee) |
| 7458 | bnxt_hwrm_set_eee(bp, &req); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7459 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7460 | } |
| 7461 | |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 7462 | static int bnxt_hwrm_shutdown_link(struct bnxt *bp) |
| 7463 | { |
| 7464 | struct hwrm_port_phy_cfg_input req = {0}; |
| 7465 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 7466 | if (!BNXT_SINGLE_PF(bp)) |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 7467 | return 0; |
| 7468 | |
| 7469 | if (pci_num_vf(bp->pdev)) |
| 7470 | return 0; |
| 7471 | |
| 7472 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
Michael Chan | 16d663a | 2016-11-16 21:13:07 -0500 | [diff] [blame] | 7473 | req.flags = cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE_LINK_DWN); |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 7474 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7475 | } |
| 7476 | |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 7477 | static int bnxt_hwrm_if_change(struct bnxt *bp, bool up) |
| 7478 | { |
| 7479 | struct hwrm_func_drv_if_change_output *resp = bp->hwrm_cmd_resp_addr; |
| 7480 | struct hwrm_func_drv_if_change_input req = {0}; |
| 7481 | bool resc_reinit = false; |
| 7482 | int rc; |
| 7483 | |
| 7484 | if (!(bp->fw_cap & BNXT_FW_CAP_IF_CHANGE)) |
| 7485 | return 0; |
| 7486 | |
| 7487 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_IF_CHANGE, -1, -1); |
| 7488 | if (up) |
| 7489 | req.flags = cpu_to_le32(FUNC_DRV_IF_CHANGE_REQ_FLAGS_UP); |
| 7490 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7491 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7492 | if (!rc && (resp->flags & |
| 7493 | cpu_to_le32(FUNC_DRV_IF_CHANGE_RESP_FLAGS_RESC_CHANGE))) |
| 7494 | resc_reinit = true; |
| 7495 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7496 | |
| 7497 | if (up && resc_reinit && BNXT_NEW_RM(bp)) { |
| 7498 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 7499 | |
| 7500 | rc = bnxt_hwrm_func_resc_qcaps(bp, true); |
| 7501 | hw_resc->resv_cp_rings = 0; |
| 7502 | hw_resc->resv_tx_rings = 0; |
| 7503 | hw_resc->resv_rx_rings = 0; |
| 7504 | hw_resc->resv_hw_ring_grps = 0; |
| 7505 | hw_resc->resv_vnics = 0; |
Michael Chan | 6b95c3e | 2018-09-03 04:23:17 -0400 | [diff] [blame] | 7506 | bp->tx_nr_rings = 0; |
| 7507 | bp->rx_nr_rings = 0; |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 7508 | } |
| 7509 | return rc; |
| 7510 | } |
| 7511 | |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 7512 | static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp) |
| 7513 | { |
| 7514 | struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 7515 | struct hwrm_port_led_qcaps_input req = {0}; |
| 7516 | struct bnxt_pf_info *pf = &bp->pf; |
| 7517 | int rc; |
| 7518 | |
| 7519 | if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601) |
| 7520 | return 0; |
| 7521 | |
| 7522 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1); |
| 7523 | req.port_id = cpu_to_le16(pf->port_id); |
| 7524 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7525 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7526 | if (rc) { |
| 7527 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7528 | return rc; |
| 7529 | } |
| 7530 | if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) { |
| 7531 | int i; |
| 7532 | |
| 7533 | bp->num_leds = resp->num_leds; |
| 7534 | memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) * |
| 7535 | bp->num_leds); |
| 7536 | for (i = 0; i < bp->num_leds; i++) { |
| 7537 | struct bnxt_led_info *led = &bp->leds[i]; |
| 7538 | __le16 caps = led->led_state_caps; |
| 7539 | |
| 7540 | if (!led->led_group_id || |
| 7541 | !BNXT_LED_ALT_BLINK_CAP(caps)) { |
| 7542 | bp->num_leds = 0; |
| 7543 | break; |
| 7544 | } |
| 7545 | } |
| 7546 | } |
| 7547 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7548 | return 0; |
| 7549 | } |
| 7550 | |
Michael Chan | 5282db6 | 2017-04-04 18:14:10 -0400 | [diff] [blame] | 7551 | int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp) |
| 7552 | { |
| 7553 | struct hwrm_wol_filter_alloc_input req = {0}; |
| 7554 | struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 7555 | int rc; |
| 7556 | |
| 7557 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1); |
| 7558 | req.port_id = cpu_to_le16(bp->pf.port_id); |
| 7559 | req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT; |
| 7560 | req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS); |
| 7561 | memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN); |
| 7562 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7563 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7564 | if (!rc) |
| 7565 | bp->wol_filter_id = resp->wol_filter_id; |
| 7566 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7567 | return rc; |
| 7568 | } |
| 7569 | |
| 7570 | int bnxt_hwrm_free_wol_fltr(struct bnxt *bp) |
| 7571 | { |
| 7572 | struct hwrm_wol_filter_free_input req = {0}; |
| 7573 | int rc; |
| 7574 | |
| 7575 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1); |
| 7576 | req.port_id = cpu_to_le16(bp->pf.port_id); |
| 7577 | req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID); |
| 7578 | req.wol_filter_id = bp->wol_filter_id; |
| 7579 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7580 | return rc; |
| 7581 | } |
| 7582 | |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 7583 | static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle) |
| 7584 | { |
| 7585 | struct hwrm_wol_filter_qcfg_input req = {0}; |
| 7586 | struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 7587 | u16 next_handle = 0; |
| 7588 | int rc; |
| 7589 | |
| 7590 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1); |
| 7591 | req.port_id = cpu_to_le16(bp->pf.port_id); |
| 7592 | req.handle = cpu_to_le16(handle); |
| 7593 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7594 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 7595 | if (!rc) { |
| 7596 | next_handle = le16_to_cpu(resp->next_handle); |
| 7597 | if (next_handle != 0) { |
| 7598 | if (resp->wol_type == |
| 7599 | WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) { |
| 7600 | bp->wol = 1; |
| 7601 | bp->wol_filter_id = resp->wol_filter_id; |
| 7602 | } |
| 7603 | } |
| 7604 | } |
| 7605 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7606 | return next_handle; |
| 7607 | } |
| 7608 | |
| 7609 | static void bnxt_get_wol_settings(struct bnxt *bp) |
| 7610 | { |
| 7611 | u16 handle = 0; |
| 7612 | |
| 7613 | if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP)) |
| 7614 | return; |
| 7615 | |
| 7616 | do { |
| 7617 | handle = bnxt_hwrm_get_wol_fltrs(bp, handle); |
| 7618 | } while (handle && handle != 0xffff); |
| 7619 | } |
| 7620 | |
Vasundhara Volam | cde49a4 | 2018-08-05 16:51:56 -0400 | [diff] [blame] | 7621 | #ifdef CONFIG_BNXT_HWMON |
| 7622 | static ssize_t bnxt_show_temp(struct device *dev, |
| 7623 | struct device_attribute *devattr, char *buf) |
| 7624 | { |
| 7625 | struct hwrm_temp_monitor_query_input req = {0}; |
| 7626 | struct hwrm_temp_monitor_query_output *resp; |
| 7627 | struct bnxt *bp = dev_get_drvdata(dev); |
| 7628 | u32 temp = 0; |
| 7629 | |
| 7630 | resp = bp->hwrm_cmd_resp_addr; |
| 7631 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TEMP_MONITOR_QUERY, -1, -1); |
| 7632 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7633 | if (!_hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT)) |
| 7634 | temp = resp->temp * 1000; /* display millidegree */ |
| 7635 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7636 | |
| 7637 | return sprintf(buf, "%u\n", temp); |
| 7638 | } |
| 7639 | static SENSOR_DEVICE_ATTR(temp1_input, 0444, bnxt_show_temp, NULL, 0); |
| 7640 | |
| 7641 | static struct attribute *bnxt_attrs[] = { |
| 7642 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 7643 | NULL |
| 7644 | }; |
| 7645 | ATTRIBUTE_GROUPS(bnxt); |
| 7646 | |
| 7647 | static void bnxt_hwmon_close(struct bnxt *bp) |
| 7648 | { |
| 7649 | if (bp->hwmon_dev) { |
| 7650 | hwmon_device_unregister(bp->hwmon_dev); |
| 7651 | bp->hwmon_dev = NULL; |
| 7652 | } |
| 7653 | } |
| 7654 | |
| 7655 | static void bnxt_hwmon_open(struct bnxt *bp) |
| 7656 | { |
| 7657 | struct pci_dev *pdev = bp->pdev; |
| 7658 | |
| 7659 | bp->hwmon_dev = hwmon_device_register_with_groups(&pdev->dev, |
| 7660 | DRV_MODULE_NAME, bp, |
| 7661 | bnxt_groups); |
| 7662 | if (IS_ERR(bp->hwmon_dev)) { |
| 7663 | bp->hwmon_dev = NULL; |
| 7664 | dev_warn(&pdev->dev, "Cannot register hwmon device\n"); |
| 7665 | } |
| 7666 | } |
| 7667 | #else |
| 7668 | static void bnxt_hwmon_close(struct bnxt *bp) |
| 7669 | { |
| 7670 | } |
| 7671 | |
| 7672 | static void bnxt_hwmon_open(struct bnxt *bp) |
| 7673 | { |
| 7674 | } |
| 7675 | #endif |
| 7676 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 7677 | static bool bnxt_eee_config_ok(struct bnxt *bp) |
| 7678 | { |
| 7679 | struct ethtool_eee *eee = &bp->eee; |
| 7680 | struct bnxt_link_info *link_info = &bp->link_info; |
| 7681 | |
| 7682 | if (!(bp->flags & BNXT_FLAG_EEE_CAP)) |
| 7683 | return true; |
| 7684 | |
| 7685 | if (eee->eee_enabled) { |
| 7686 | u32 advertising = |
| 7687 | _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); |
| 7688 | |
| 7689 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 7690 | eee->eee_enabled = 0; |
| 7691 | return false; |
| 7692 | } |
| 7693 | if (eee->advertised & ~advertising) { |
| 7694 | eee->advertised = advertising & eee->supported; |
| 7695 | return false; |
| 7696 | } |
| 7697 | } |
| 7698 | return true; |
| 7699 | } |
| 7700 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7701 | static int bnxt_update_phy_setting(struct bnxt *bp) |
| 7702 | { |
| 7703 | int rc; |
| 7704 | bool update_link = false; |
| 7705 | bool update_pause = false; |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 7706 | bool update_eee = false; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7707 | struct bnxt_link_info *link_info = &bp->link_info; |
| 7708 | |
| 7709 | rc = bnxt_update_link(bp, true); |
| 7710 | if (rc) { |
| 7711 | netdev_err(bp->dev, "failed to update link (rc: %x)\n", |
| 7712 | rc); |
| 7713 | return rc; |
| 7714 | } |
Michael Chan | 33dac24 | 2017-02-12 19:18:15 -0500 | [diff] [blame] | 7715 | if (!BNXT_SINGLE_PF(bp)) |
| 7716 | return 0; |
| 7717 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7718 | if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 7719 | (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) != |
| 7720 | link_info->req_flow_ctrl) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7721 | update_pause = true; |
| 7722 | if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
| 7723 | link_info->force_pause_setting != link_info->req_flow_ctrl) |
| 7724 | update_pause = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7725 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 7726 | if (BNXT_AUTO_MODE(link_info->auto_mode)) |
| 7727 | update_link = true; |
| 7728 | if (link_info->req_link_speed != link_info->force_link_speed) |
| 7729 | update_link = true; |
Michael Chan | de73018 | 2016-02-19 19:43:20 -0500 | [diff] [blame] | 7730 | if (link_info->req_duplex != link_info->duplex_setting) |
| 7731 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7732 | } else { |
| 7733 | if (link_info->auto_mode == BNXT_LINK_AUTO_NONE) |
| 7734 | update_link = true; |
| 7735 | if (link_info->advertising != link_info->auto_link_speeds) |
| 7736 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7737 | } |
| 7738 | |
Michael Chan | 16d663a | 2016-11-16 21:13:07 -0500 | [diff] [blame] | 7739 | /* The last close may have shutdown the link, so need to call |
| 7740 | * PHY_CFG to bring it back up. |
| 7741 | */ |
| 7742 | if (!netif_carrier_ok(bp->dev)) |
| 7743 | update_link = true; |
| 7744 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 7745 | if (!bnxt_eee_config_ok(bp)) |
| 7746 | update_eee = true; |
| 7747 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7748 | if (update_link) |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 7749 | rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7750 | else if (update_pause) |
| 7751 | rc = bnxt_hwrm_set_pause(bp); |
| 7752 | if (rc) { |
| 7753 | netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n", |
| 7754 | rc); |
| 7755 | return rc; |
| 7756 | } |
| 7757 | |
| 7758 | return rc; |
| 7759 | } |
| 7760 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 7761 | /* Common routine to pre-map certain register block to different GRC window. |
| 7762 | * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows |
| 7763 | * in PF and 3 windows in VF that can be customized to map in different |
| 7764 | * register blocks. |
| 7765 | */ |
| 7766 | static void bnxt_preset_reg_win(struct bnxt *bp) |
| 7767 | { |
| 7768 | if (BNXT_PF(bp)) { |
| 7769 | /* CAG registers map to GRC window #4 */ |
| 7770 | writel(BNXT_CAG_REG_BASE, |
| 7771 | bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12); |
| 7772 | } |
| 7773 | } |
| 7774 | |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 7775 | static int bnxt_init_dflt_ring_mode(struct bnxt *bp); |
| 7776 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7777 | static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 7778 | { |
| 7779 | int rc = 0; |
| 7780 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 7781 | bnxt_preset_reg_win(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7782 | netif_carrier_off(bp->dev); |
| 7783 | if (irq_re_init) { |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 7784 | /* Reserve rings now if none were reserved at driver probe. */ |
| 7785 | rc = bnxt_init_dflt_ring_mode(bp); |
| 7786 | if (rc) { |
| 7787 | netdev_err(bp->dev, "Failed to reserve default rings at open\n"); |
| 7788 | return rc; |
| 7789 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7790 | } |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 7791 | rc = bnxt_reserve_rings(bp); |
| 7792 | if (rc) |
| 7793 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7794 | if ((bp->flags & BNXT_FLAG_RFS) && |
| 7795 | !(bp->flags & BNXT_FLAG_USING_MSIX)) { |
| 7796 | /* disable RFS if falling back to INTA */ |
| 7797 | bp->dev->hw_features &= ~NETIF_F_NTUPLE; |
| 7798 | bp->flags &= ~BNXT_FLAG_RFS; |
| 7799 | } |
| 7800 | |
| 7801 | rc = bnxt_alloc_mem(bp, irq_re_init); |
| 7802 | if (rc) { |
| 7803 | netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); |
| 7804 | goto open_err_free_mem; |
| 7805 | } |
| 7806 | |
| 7807 | if (irq_re_init) { |
| 7808 | bnxt_init_napi(bp); |
| 7809 | rc = bnxt_request_irq(bp); |
| 7810 | if (rc) { |
| 7811 | netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc); |
Vikas Gupta | c58387a | 2018-07-09 02:24:52 -0400 | [diff] [blame] | 7812 | goto open_err_irq; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7813 | } |
| 7814 | } |
| 7815 | |
| 7816 | bnxt_enable_napi(bp); |
Andy Gospodarek | cabfb09 | 2018-04-26 17:44:40 -0400 | [diff] [blame] | 7817 | bnxt_debug_dev_init(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7818 | |
| 7819 | rc = bnxt_init_nic(bp, irq_re_init); |
| 7820 | if (rc) { |
| 7821 | netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc); |
| 7822 | goto open_err; |
| 7823 | } |
| 7824 | |
| 7825 | if (link_re_init) { |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 7826 | mutex_lock(&bp->link_lock); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7827 | rc = bnxt_update_phy_setting(bp); |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 7828 | mutex_unlock(&bp->link_lock); |
Michael Chan | a1ef4a7 | 2018-08-05 16:51:49 -0400 | [diff] [blame] | 7829 | if (rc) { |
Michael Chan | ba41d46 | 2016-02-19 19:43:21 -0500 | [diff] [blame] | 7830 | netdev_warn(bp->dev, "failed to update phy settings\n"); |
Michael Chan | a1ef4a7 | 2018-08-05 16:51:49 -0400 | [diff] [blame] | 7831 | if (BNXT_SINGLE_PF(bp)) { |
| 7832 | bp->link_info.phy_retry = true; |
| 7833 | bp->link_info.phy_retry_expires = |
| 7834 | jiffies + 5 * HZ; |
| 7835 | } |
| 7836 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7837 | } |
| 7838 | |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 7839 | if (irq_re_init) |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 7840 | udp_tunnel_get_rx_info(bp->dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7841 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 7842 | set_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7843 | bnxt_enable_int(bp); |
| 7844 | /* Enable TX queues */ |
| 7845 | bnxt_tx_enable(bp); |
| 7846 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 7847 | /* Poll link status and check for SFP+ module status */ |
| 7848 | bnxt_get_port_module_status(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7849 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 7850 | /* VF-reps may need to be re-opened after the PF is re-opened */ |
| 7851 | if (BNXT_PF(bp)) |
| 7852 | bnxt_vf_reps_open(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7853 | return 0; |
| 7854 | |
| 7855 | open_err: |
Andy Gospodarek | cabfb09 | 2018-04-26 17:44:40 -0400 | [diff] [blame] | 7856 | bnxt_debug_dev_exit(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7857 | bnxt_disable_napi(bp); |
Vikas Gupta | c58387a | 2018-07-09 02:24:52 -0400 | [diff] [blame] | 7858 | |
| 7859 | open_err_irq: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7860 | bnxt_del_napi(bp); |
| 7861 | |
| 7862 | open_err_free_mem: |
| 7863 | bnxt_free_skbs(bp); |
| 7864 | bnxt_free_irq(bp); |
| 7865 | bnxt_free_mem(bp, true); |
| 7866 | return rc; |
| 7867 | } |
| 7868 | |
| 7869 | /* rtnl_lock held */ |
| 7870 | int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 7871 | { |
| 7872 | int rc = 0; |
| 7873 | |
| 7874 | rc = __bnxt_open_nic(bp, irq_re_init, link_re_init); |
| 7875 | if (rc) { |
| 7876 | netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc); |
| 7877 | dev_close(bp->dev); |
| 7878 | } |
| 7879 | return rc; |
| 7880 | } |
| 7881 | |
Michael Chan | f7dc1ea | 2017-04-04 18:14:13 -0400 | [diff] [blame] | 7882 | /* rtnl_lock held, open the NIC half way by allocating all resources, but |
| 7883 | * NAPI, IRQ, and TX are not enabled. This is mainly used for offline |
| 7884 | * self tests. |
| 7885 | */ |
| 7886 | int bnxt_half_open_nic(struct bnxt *bp) |
| 7887 | { |
| 7888 | int rc = 0; |
| 7889 | |
| 7890 | rc = bnxt_alloc_mem(bp, false); |
| 7891 | if (rc) { |
| 7892 | netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); |
| 7893 | goto half_open_err; |
| 7894 | } |
| 7895 | rc = bnxt_init_nic(bp, false); |
| 7896 | if (rc) { |
| 7897 | netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc); |
| 7898 | goto half_open_err; |
| 7899 | } |
| 7900 | return 0; |
| 7901 | |
| 7902 | half_open_err: |
| 7903 | bnxt_free_skbs(bp); |
| 7904 | bnxt_free_mem(bp, false); |
| 7905 | dev_close(bp->dev); |
| 7906 | return rc; |
| 7907 | } |
| 7908 | |
| 7909 | /* rtnl_lock held, this call can only be made after a previous successful |
| 7910 | * call to bnxt_half_open_nic(). |
| 7911 | */ |
| 7912 | void bnxt_half_close_nic(struct bnxt *bp) |
| 7913 | { |
| 7914 | bnxt_hwrm_resource_free(bp, false, false); |
| 7915 | bnxt_free_skbs(bp); |
| 7916 | bnxt_free_mem(bp, false); |
| 7917 | } |
| 7918 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7919 | static int bnxt_open(struct net_device *dev) |
| 7920 | { |
| 7921 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 7922 | int rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7923 | |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 7924 | bnxt_hwrm_if_change(bp, true); |
| 7925 | rc = __bnxt_open_nic(bp, true, true); |
| 7926 | if (rc) |
| 7927 | bnxt_hwrm_if_change(bp, false); |
Vasundhara Volam | cde49a4 | 2018-08-05 16:51:56 -0400 | [diff] [blame] | 7928 | |
| 7929 | bnxt_hwmon_open(bp); |
| 7930 | |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 7931 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7932 | } |
| 7933 | |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 7934 | static bool bnxt_drv_busy(struct bnxt *bp) |
| 7935 | { |
| 7936 | return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) || |
| 7937 | test_bit(BNXT_STATE_READ_STATS, &bp->state)); |
| 7938 | } |
| 7939 | |
Michael Chan | 86e953d | 2018-01-17 03:21:04 -0500 | [diff] [blame] | 7940 | static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init, |
| 7941 | bool link_re_init) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7942 | { |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 7943 | /* Close the VF-reps before closing PF */ |
| 7944 | if (BNXT_PF(bp)) |
| 7945 | bnxt_vf_reps_close(bp); |
Michael Chan | 86e953d | 2018-01-17 03:21:04 -0500 | [diff] [blame] | 7946 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7947 | /* Change device state to avoid TX queue wake up's */ |
| 7948 | bnxt_tx_disable(bp); |
| 7949 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 7950 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 7951 | smp_mb__after_atomic(); |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 7952 | while (bnxt_drv_busy(bp)) |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 7953 | msleep(20); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7954 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 7955 | /* Flush rings and and disable interrupts */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7956 | bnxt_shutdown_nic(bp, irq_re_init); |
| 7957 | |
| 7958 | /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */ |
| 7959 | |
Andy Gospodarek | cabfb09 | 2018-04-26 17:44:40 -0400 | [diff] [blame] | 7960 | bnxt_debug_dev_exit(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7961 | bnxt_disable_napi(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7962 | del_timer_sync(&bp->timer); |
| 7963 | bnxt_free_skbs(bp); |
| 7964 | |
| 7965 | if (irq_re_init) { |
| 7966 | bnxt_free_irq(bp); |
| 7967 | bnxt_del_napi(bp); |
| 7968 | } |
| 7969 | bnxt_free_mem(bp, irq_re_init); |
Michael Chan | 86e953d | 2018-01-17 03:21:04 -0500 | [diff] [blame] | 7970 | } |
| 7971 | |
| 7972 | int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 7973 | { |
| 7974 | int rc = 0; |
| 7975 | |
| 7976 | #ifdef CONFIG_BNXT_SRIOV |
| 7977 | if (bp->sriov_cfg) { |
| 7978 | rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait, |
| 7979 | !bp->sriov_cfg, |
| 7980 | BNXT_SRIOV_CFG_WAIT_TMO); |
| 7981 | if (rc) |
| 7982 | netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n"); |
| 7983 | } |
| 7984 | #endif |
| 7985 | __bnxt_close_nic(bp, irq_re_init, link_re_init); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7986 | return rc; |
| 7987 | } |
| 7988 | |
| 7989 | static int bnxt_close(struct net_device *dev) |
| 7990 | { |
| 7991 | struct bnxt *bp = netdev_priv(dev); |
| 7992 | |
Vasundhara Volam | cde49a4 | 2018-08-05 16:51:56 -0400 | [diff] [blame] | 7993 | bnxt_hwmon_close(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7994 | bnxt_close_nic(bp, true, true); |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 7995 | bnxt_hwrm_shutdown_link(bp); |
Michael Chan | 25e1acd | 2018-08-05 16:51:55 -0400 | [diff] [blame] | 7996 | bnxt_hwrm_if_change(bp, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7997 | return 0; |
| 7998 | } |
| 7999 | |
| 8000 | /* rtnl_lock held */ |
| 8001 | static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 8002 | { |
| 8003 | switch (cmd) { |
| 8004 | case SIOCGMIIPHY: |
| 8005 | /* fallthru */ |
| 8006 | case SIOCGMIIREG: { |
| 8007 | if (!netif_running(dev)) |
| 8008 | return -EAGAIN; |
| 8009 | |
| 8010 | return 0; |
| 8011 | } |
| 8012 | |
| 8013 | case SIOCSMIIREG: |
| 8014 | if (!netif_running(dev)) |
| 8015 | return -EAGAIN; |
| 8016 | |
| 8017 | return 0; |
| 8018 | |
| 8019 | default: |
| 8020 | /* do nothing */ |
| 8021 | break; |
| 8022 | } |
| 8023 | return -EOPNOTSUPP; |
| 8024 | } |
| 8025 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8026 | static void |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8027 | bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
| 8028 | { |
| 8029 | u32 i; |
| 8030 | struct bnxt *bp = netdev_priv(dev); |
| 8031 | |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 8032 | set_bit(BNXT_STATE_READ_STATS, &bp->state); |
| 8033 | /* Make sure bnxt_close_nic() sees that we are reading stats before |
| 8034 | * we check the BNXT_STATE_OPEN flag. |
| 8035 | */ |
| 8036 | smp_mb__after_atomic(); |
| 8037 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
| 8038 | clear_bit(BNXT_STATE_READ_STATS, &bp->state); |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 8039 | return; |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 8040 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8041 | |
| 8042 | /* TODO check if we need to synchronize with bnxt_close path */ |
| 8043 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 8044 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 8045 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 8046 | struct ctx_hw_stats *hw_stats = cpr->hw_stats; |
| 8047 | |
| 8048 | stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts); |
| 8049 | stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 8050 | stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts); |
| 8051 | |
| 8052 | stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts); |
| 8053 | stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts); |
| 8054 | stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts); |
| 8055 | |
| 8056 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes); |
| 8057 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes); |
| 8058 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes); |
| 8059 | |
| 8060 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes); |
| 8061 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes); |
| 8062 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes); |
| 8063 | |
| 8064 | stats->rx_missed_errors += |
| 8065 | le64_to_cpu(hw_stats->rx_discard_pkts); |
| 8066 | |
| 8067 | stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 8068 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8069 | stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts); |
| 8070 | } |
| 8071 | |
Michael Chan | 9947f83 | 2016-03-07 15:38:46 -0500 | [diff] [blame] | 8072 | if (bp->flags & BNXT_FLAG_PORT_STATS) { |
| 8073 | struct rx_port_stats *rx = bp->hw_rx_port_stats; |
| 8074 | struct tx_port_stats *tx = bp->hw_tx_port_stats; |
| 8075 | |
| 8076 | stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames); |
| 8077 | stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames); |
| 8078 | stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) + |
| 8079 | le64_to_cpu(rx->rx_ovrsz_frames) + |
| 8080 | le64_to_cpu(rx->rx_runt_frames); |
| 8081 | stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) + |
| 8082 | le64_to_cpu(rx->rx_jbr_frames); |
| 8083 | stats->collisions = le64_to_cpu(tx->tx_total_collisions); |
| 8084 | stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns); |
| 8085 | stats->tx_errors = le64_to_cpu(tx->tx_err); |
| 8086 | } |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 8087 | clear_bit(BNXT_STATE_READ_STATS, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8088 | } |
| 8089 | |
| 8090 | static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask) |
| 8091 | { |
| 8092 | struct net_device *dev = bp->dev; |
| 8093 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 8094 | struct netdev_hw_addr *ha; |
| 8095 | u8 *haddr; |
| 8096 | int mc_count = 0; |
| 8097 | bool update = false; |
| 8098 | int off = 0; |
| 8099 | |
| 8100 | netdev_for_each_mc_addr(ha, dev) { |
| 8101 | if (mc_count >= BNXT_MAX_MC_ADDRS) { |
| 8102 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 8103 | vnic->mc_list_count = 0; |
| 8104 | return false; |
| 8105 | } |
| 8106 | haddr = ha->addr; |
| 8107 | if (!ether_addr_equal(haddr, vnic->mc_list + off)) { |
| 8108 | memcpy(vnic->mc_list + off, haddr, ETH_ALEN); |
| 8109 | update = true; |
| 8110 | } |
| 8111 | off += ETH_ALEN; |
| 8112 | mc_count++; |
| 8113 | } |
| 8114 | if (mc_count) |
| 8115 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST; |
| 8116 | |
| 8117 | if (mc_count != vnic->mc_list_count) { |
| 8118 | vnic->mc_list_count = mc_count; |
| 8119 | update = true; |
| 8120 | } |
| 8121 | return update; |
| 8122 | } |
| 8123 | |
| 8124 | static bool bnxt_uc_list_updated(struct bnxt *bp) |
| 8125 | { |
| 8126 | struct net_device *dev = bp->dev; |
| 8127 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 8128 | struct netdev_hw_addr *ha; |
| 8129 | int off = 0; |
| 8130 | |
| 8131 | if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1)) |
| 8132 | return true; |
| 8133 | |
| 8134 | netdev_for_each_uc_addr(ha, dev) { |
| 8135 | if (!ether_addr_equal(ha->addr, vnic->uc_list + off)) |
| 8136 | return true; |
| 8137 | |
| 8138 | off += ETH_ALEN; |
| 8139 | } |
| 8140 | return false; |
| 8141 | } |
| 8142 | |
| 8143 | static void bnxt_set_rx_mode(struct net_device *dev) |
| 8144 | { |
| 8145 | struct bnxt *bp = netdev_priv(dev); |
| 8146 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 8147 | u32 mask = vnic->rx_mask; |
| 8148 | bool mc_update = false; |
| 8149 | bool uc_update; |
| 8150 | |
| 8151 | if (!netif_running(dev)) |
| 8152 | return; |
| 8153 | |
| 8154 | mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS | |
| 8155 | CFA_L2_SET_RX_MASK_REQ_MASK_MCAST | |
Michael Chan | 30e3384 | 2018-07-09 02:24:50 -0400 | [diff] [blame] | 8156 | CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST | |
| 8157 | CFA_L2_SET_RX_MASK_REQ_MASK_BCAST); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8158 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 8159 | if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8160 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 8161 | |
| 8162 | uc_update = bnxt_uc_list_updated(bp); |
| 8163 | |
Michael Chan | 30e3384 | 2018-07-09 02:24:50 -0400 | [diff] [blame] | 8164 | if (dev->flags & IFF_BROADCAST) |
| 8165 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_BCAST; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8166 | if (dev->flags & IFF_ALLMULTI) { |
| 8167 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 8168 | vnic->mc_list_count = 0; |
| 8169 | } else { |
| 8170 | mc_update = bnxt_mc_list_updated(bp, &mask); |
| 8171 | } |
| 8172 | |
| 8173 | if (mask != vnic->rx_mask || uc_update || mc_update) { |
| 8174 | vnic->rx_mask = mask; |
| 8175 | |
| 8176 | set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8177 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8178 | } |
| 8179 | } |
| 8180 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 8181 | static int bnxt_cfg_rx_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8182 | { |
| 8183 | struct net_device *dev = bp->dev; |
| 8184 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 8185 | struct netdev_hw_addr *ha; |
| 8186 | int i, off = 0, rc; |
| 8187 | bool uc_update; |
| 8188 | |
| 8189 | netif_addr_lock_bh(dev); |
| 8190 | uc_update = bnxt_uc_list_updated(bp); |
| 8191 | netif_addr_unlock_bh(dev); |
| 8192 | |
| 8193 | if (!uc_update) |
| 8194 | goto skip_uc; |
| 8195 | |
| 8196 | mutex_lock(&bp->hwrm_cmd_lock); |
| 8197 | for (i = 1; i < vnic->uc_filter_count; i++) { |
| 8198 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 8199 | |
| 8200 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1, |
| 8201 | -1); |
| 8202 | |
| 8203 | req.l2_filter_id = vnic->fw_l2_filter_id[i]; |
| 8204 | |
| 8205 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 8206 | HWRM_CMD_TIMEOUT); |
| 8207 | } |
| 8208 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 8209 | |
| 8210 | vnic->uc_filter_count = 1; |
| 8211 | |
| 8212 | netif_addr_lock_bh(dev); |
| 8213 | if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) { |
| 8214 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 8215 | } else { |
| 8216 | netdev_for_each_uc_addr(ha, dev) { |
| 8217 | memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN); |
| 8218 | off += ETH_ALEN; |
| 8219 | vnic->uc_filter_count++; |
| 8220 | } |
| 8221 | } |
| 8222 | netif_addr_unlock_bh(dev); |
| 8223 | |
| 8224 | for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) { |
| 8225 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off); |
| 8226 | if (rc) { |
| 8227 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", |
| 8228 | rc); |
| 8229 | vnic->uc_filter_count = i; |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 8230 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8231 | } |
| 8232 | } |
| 8233 | |
| 8234 | skip_uc: |
| 8235 | rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0); |
| 8236 | if (rc) |
| 8237 | netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n", |
| 8238 | rc); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 8239 | |
| 8240 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8241 | } |
| 8242 | |
Michael Chan | 2773dfb | 2018-04-26 17:44:42 -0400 | [diff] [blame] | 8243 | static bool bnxt_can_reserve_rings(struct bnxt *bp) |
| 8244 | { |
| 8245 | #ifdef CONFIG_BNXT_SRIOV |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 8246 | if (BNXT_NEW_RM(bp) && BNXT_VF(bp)) { |
Michael Chan | 2773dfb | 2018-04-26 17:44:42 -0400 | [diff] [blame] | 8247 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 8248 | |
| 8249 | /* No minimum rings were provisioned by the PF. Don't |
| 8250 | * reserve rings by default when device is down. |
| 8251 | */ |
| 8252 | if (hw_resc->min_tx_rings || hw_resc->resv_tx_rings) |
| 8253 | return true; |
| 8254 | |
| 8255 | if (!netif_running(bp->dev)) |
| 8256 | return false; |
| 8257 | } |
| 8258 | #endif |
| 8259 | return true; |
| 8260 | } |
| 8261 | |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8262 | /* If the chip and firmware supports RFS */ |
| 8263 | static bool bnxt_rfs_supported(struct bnxt *bp) |
| 8264 | { |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 8265 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 8266 | return false; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8267 | if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 8268 | return true; |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 8269 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 8270 | return true; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8271 | return false; |
| 8272 | } |
| 8273 | |
| 8274 | /* If runtime conditions support RFS */ |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8275 | static bool bnxt_rfs_capable(struct bnxt *bp) |
| 8276 | { |
| 8277 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8278 | int vnics, max_vnics, max_rss_ctxs; |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8279 | |
Michael Chan | 41e8d79 | 2018-10-14 07:02:48 -0400 | [diff] [blame] | 8280 | if (bp->flags & BNXT_FLAG_CHIP_P5) |
| 8281 | return false; |
Michael Chan | 2773dfb | 2018-04-26 17:44:42 -0400 | [diff] [blame] | 8282 | if (!(bp->flags & BNXT_FLAG_MSIX_CAP) || !bnxt_can_reserve_rings(bp)) |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8283 | return false; |
| 8284 | |
| 8285 | vnics = 1 + bp->rx_nr_rings; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8286 | max_vnics = bnxt_get_max_func_vnics(bp); |
| 8287 | max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 8288 | |
| 8289 | /* RSS contexts not a limiting factor */ |
| 8290 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 8291 | max_rss_ctxs = max_vnics; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8292 | if (vnics > max_vnics || vnics > max_rss_ctxs) { |
Michael Chan | 6a1eef5 | 2018-01-17 03:21:10 -0500 | [diff] [blame] | 8293 | if (bp->rx_nr_rings > 1) |
| 8294 | netdev_warn(bp->dev, |
| 8295 | "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n", |
| 8296 | min(max_rss_ctxs - 1, max_vnics - 1)); |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8297 | return false; |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 8298 | } |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8299 | |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 8300 | if (!BNXT_NEW_RM(bp)) |
Michael Chan | 6a1eef5 | 2018-01-17 03:21:10 -0500 | [diff] [blame] | 8301 | return true; |
| 8302 | |
| 8303 | if (vnics == bp->hw_resc.resv_vnics) |
| 8304 | return true; |
| 8305 | |
| 8306 | bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics); |
| 8307 | if (vnics <= bp->hw_resc.resv_vnics) |
| 8308 | return true; |
| 8309 | |
| 8310 | netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n"); |
| 8311 | bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1); |
| 8312 | return false; |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8313 | #else |
| 8314 | return false; |
| 8315 | #endif |
| 8316 | } |
| 8317 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8318 | static netdev_features_t bnxt_fix_features(struct net_device *dev, |
| 8319 | netdev_features_t features) |
| 8320 | { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8321 | struct bnxt *bp = netdev_priv(dev); |
| 8322 | |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 8323 | if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp)) |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8324 | features &= ~NETIF_F_NTUPLE; |
Michael Chan | 5a9f6b2 | 2016-06-06 02:37:15 -0400 | [diff] [blame] | 8325 | |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 8326 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 8327 | features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); |
| 8328 | |
| 8329 | if (!(features & NETIF_F_GRO)) |
| 8330 | features &= ~NETIF_F_GRO_HW; |
| 8331 | |
| 8332 | if (features & NETIF_F_GRO_HW) |
| 8333 | features &= ~NETIF_F_LRO; |
| 8334 | |
Michael Chan | 5a9f6b2 | 2016-06-06 02:37:15 -0400 | [diff] [blame] | 8335 | /* Both CTAG and STAG VLAN accelaration on the RX side have to be |
| 8336 | * turned on or off together. |
| 8337 | */ |
| 8338 | if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) != |
| 8339 | (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) { |
| 8340 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8341 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 8342 | NETIF_F_HW_VLAN_STAG_RX); |
| 8343 | else |
| 8344 | features |= NETIF_F_HW_VLAN_CTAG_RX | |
| 8345 | NETIF_F_HW_VLAN_STAG_RX; |
| 8346 | } |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 8347 | #ifdef CONFIG_BNXT_SRIOV |
| 8348 | if (BNXT_VF(bp)) { |
| 8349 | if (bp->vf.vlan) { |
| 8350 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 8351 | NETIF_F_HW_VLAN_STAG_RX); |
| 8352 | } |
| 8353 | } |
| 8354 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8355 | return features; |
| 8356 | } |
| 8357 | |
| 8358 | static int bnxt_set_features(struct net_device *dev, netdev_features_t features) |
| 8359 | { |
| 8360 | struct bnxt *bp = netdev_priv(dev); |
| 8361 | u32 flags = bp->flags; |
| 8362 | u32 changes; |
| 8363 | int rc = 0; |
| 8364 | bool re_init = false; |
| 8365 | bool update_tpa = false; |
| 8366 | |
| 8367 | flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 8368 | if (features & NETIF_F_GRO_HW) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8369 | flags |= BNXT_FLAG_GRO; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 8370 | else if (features & NETIF_F_LRO) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8371 | flags |= BNXT_FLAG_LRO; |
| 8372 | |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 8373 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 8374 | flags &= ~BNXT_FLAG_TPA; |
| 8375 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8376 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8377 | flags |= BNXT_FLAG_STRIP_VLAN; |
| 8378 | |
| 8379 | if (features & NETIF_F_NTUPLE) |
| 8380 | flags |= BNXT_FLAG_RFS; |
| 8381 | |
| 8382 | changes = flags ^ bp->flags; |
| 8383 | if (changes & BNXT_FLAG_TPA) { |
| 8384 | update_tpa = true; |
| 8385 | if ((bp->flags & BNXT_FLAG_TPA) == 0 || |
| 8386 | (flags & BNXT_FLAG_TPA) == 0) |
| 8387 | re_init = true; |
| 8388 | } |
| 8389 | |
| 8390 | if (changes & ~BNXT_FLAG_TPA) |
| 8391 | re_init = true; |
| 8392 | |
| 8393 | if (flags != bp->flags) { |
| 8394 | u32 old_flags = bp->flags; |
| 8395 | |
| 8396 | bp->flags = flags; |
| 8397 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8398 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8399 | if (update_tpa) |
| 8400 | bnxt_set_ring_params(bp); |
| 8401 | return rc; |
| 8402 | } |
| 8403 | |
| 8404 | if (re_init) { |
| 8405 | bnxt_close_nic(bp, false, false); |
| 8406 | if (update_tpa) |
| 8407 | bnxt_set_ring_params(bp); |
| 8408 | |
| 8409 | return bnxt_open_nic(bp, false, false); |
| 8410 | } |
| 8411 | if (update_tpa) { |
| 8412 | rc = bnxt_set_tpa(bp, |
| 8413 | (flags & BNXT_FLAG_TPA) ? |
| 8414 | true : false); |
| 8415 | if (rc) |
| 8416 | bp->flags = old_flags; |
| 8417 | } |
| 8418 | } |
| 8419 | return rc; |
| 8420 | } |
| 8421 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 8422 | static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi) |
| 8423 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 8424 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 8425 | int i = bnapi->index; |
| 8426 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 8427 | if (!txr) |
| 8428 | return; |
| 8429 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 8430 | netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n", |
| 8431 | i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod, |
| 8432 | txr->tx_cons); |
| 8433 | } |
| 8434 | |
| 8435 | static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi) |
| 8436 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 8437 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 8438 | int i = bnapi->index; |
| 8439 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 8440 | if (!rxr) |
| 8441 | return; |
| 8442 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 8443 | netdev_info(bnapi->bp->dev, "[%d]: rx{fw_ring: %d prod: %x} rx_agg{fw_ring: %d agg_prod: %x sw_agg_prod: %x}\n", |
| 8444 | i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod, |
| 8445 | rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod, |
| 8446 | rxr->rx_sw_agg_prod); |
| 8447 | } |
| 8448 | |
| 8449 | static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi) |
| 8450 | { |
| 8451 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 8452 | int i = bnapi->index; |
| 8453 | |
| 8454 | netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n", |
| 8455 | i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons); |
| 8456 | } |
| 8457 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8458 | static void bnxt_dbg_dump_states(struct bnxt *bp) |
| 8459 | { |
| 8460 | int i; |
| 8461 | struct bnxt_napi *bnapi; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8462 | |
| 8463 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 8464 | bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8465 | if (netif_msg_drv(bp)) { |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 8466 | bnxt_dump_tx_sw_state(bnapi); |
| 8467 | bnxt_dump_rx_sw_state(bnapi); |
| 8468 | bnxt_dump_cp_sw_state(bnapi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8469 | } |
| 8470 | } |
| 8471 | } |
| 8472 | |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 8473 | static void bnxt_reset_task(struct bnxt *bp, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8474 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 8475 | if (!silent) |
| 8476 | bnxt_dbg_dump_states(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 8477 | if (netif_running(bp->dev)) { |
Michael Chan | b386cd3 | 2017-03-08 18:44:33 -0500 | [diff] [blame] | 8478 | int rc; |
| 8479 | |
| 8480 | if (!silent) |
| 8481 | bnxt_ulp_stop(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 8482 | bnxt_close_nic(bp, false, false); |
Michael Chan | b386cd3 | 2017-03-08 18:44:33 -0500 | [diff] [blame] | 8483 | rc = bnxt_open_nic(bp, false, false); |
| 8484 | if (!silent && !rc) |
| 8485 | bnxt_ulp_start(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 8486 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8487 | } |
| 8488 | |
| 8489 | static void bnxt_tx_timeout(struct net_device *dev) |
| 8490 | { |
| 8491 | struct bnxt *bp = netdev_priv(dev); |
| 8492 | |
| 8493 | netdev_err(bp->dev, "TX timeout detected, starting reset task!\n"); |
| 8494 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8495 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8496 | } |
| 8497 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 8498 | static void bnxt_timer(struct timer_list *t) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8499 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 8500 | struct bnxt *bp = from_timer(bp, t, timer); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8501 | struct net_device *dev = bp->dev; |
| 8502 | |
| 8503 | if (!netif_running(dev)) |
| 8504 | return; |
| 8505 | |
| 8506 | if (atomic_read(&bp->intr_sem) != 0) |
| 8507 | goto bnxt_restart_timer; |
| 8508 | |
Michael Chan | adcc331 | 2017-07-24 12:34:24 -0400 | [diff] [blame] | 8509 | if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) && |
| 8510 | bp->stats_coal_ticks) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 8511 | set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8512 | bnxt_queue_sp_work(bp); |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 8513 | } |
Sathya Perla | 5a84acb | 2017-10-26 11:51:31 -0400 | [diff] [blame] | 8514 | |
| 8515 | if (bnxt_tc_flower_enabled(bp)) { |
| 8516 | set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event); |
| 8517 | bnxt_queue_sp_work(bp); |
| 8518 | } |
Michael Chan | a1ef4a7 | 2018-08-05 16:51:49 -0400 | [diff] [blame] | 8519 | |
| 8520 | if (bp->link_info.phy_retry) { |
| 8521 | if (time_after(jiffies, bp->link_info.phy_retry_expires)) { |
| 8522 | bp->link_info.phy_retry = 0; |
| 8523 | netdev_warn(bp->dev, "failed to update phy settings after maximum retries.\n"); |
| 8524 | } else { |
| 8525 | set_bit(BNXT_UPDATE_PHY_SP_EVENT, &bp->sp_event); |
| 8526 | bnxt_queue_sp_work(bp); |
| 8527 | } |
| 8528 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8529 | bnxt_restart_timer: |
| 8530 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 8531 | } |
| 8532 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 8533 | static void bnxt_rtnl_lock_sp(struct bnxt *bp) |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 8534 | { |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 8535 | /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK |
| 8536 | * set. If the device is being closed, bnxt_close() may be holding |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 8537 | * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we |
| 8538 | * must clear BNXT_STATE_IN_SP_TASK before holding rtnl(). |
| 8539 | */ |
| 8540 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 8541 | rtnl_lock(); |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 8542 | } |
| 8543 | |
| 8544 | static void bnxt_rtnl_unlock_sp(struct bnxt *bp) |
| 8545 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 8546 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 8547 | rtnl_unlock(); |
| 8548 | } |
| 8549 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 8550 | /* Only called from bnxt_sp_task() */ |
| 8551 | static void bnxt_reset(struct bnxt *bp, bool silent) |
| 8552 | { |
| 8553 | bnxt_rtnl_lock_sp(bp); |
| 8554 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 8555 | bnxt_reset_task(bp, silent); |
| 8556 | bnxt_rtnl_unlock_sp(bp); |
| 8557 | } |
| 8558 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8559 | static void bnxt_cfg_ntp_filters(struct bnxt *); |
| 8560 | |
| 8561 | static void bnxt_sp_task(struct work_struct *work) |
| 8562 | { |
| 8563 | struct bnxt *bp = container_of(work, struct bnxt, sp_task); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8564 | |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 8565 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 8566 | smp_mb__after_atomic(); |
| 8567 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
| 8568 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8569 | return; |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 8570 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8571 | |
| 8572 | if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event)) |
| 8573 | bnxt_cfg_rx_mode(bp); |
| 8574 | |
| 8575 | if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event)) |
| 8576 | bnxt_cfg_ntp_filters(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8577 | if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event)) |
| 8578 | bnxt_hwrm_exec_fwd_req(bp); |
| 8579 | if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 8580 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 8581 | bp, bp->vxlan_port, |
| 8582 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 8583 | } |
| 8584 | if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 8585 | bnxt_hwrm_tunnel_dst_port_free( |
| 8586 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 8587 | } |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 8588 | if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 8589 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 8590 | bp, bp->nge_port, |
| 8591 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 8592 | } |
| 8593 | if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 8594 | bnxt_hwrm_tunnel_dst_port_free( |
| 8595 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 8596 | } |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 8597 | if (test_and_clear_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event)) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 8598 | bnxt_hwrm_port_qstats(bp); |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 8599 | bnxt_hwrm_port_qstats_ext(bp); |
| 8600 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 8601 | |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 8602 | if (test_and_clear_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event)) { |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 8603 | int rc; |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 8604 | |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 8605 | mutex_lock(&bp->link_lock); |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 8606 | if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, |
| 8607 | &bp->sp_event)) |
| 8608 | bnxt_hwrm_phy_qcaps(bp); |
| 8609 | |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 8610 | rc = bnxt_update_link(bp, true); |
| 8611 | mutex_unlock(&bp->link_lock); |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 8612 | if (rc) |
| 8613 | netdev_err(bp->dev, "SP task can't update link (rc: %x)\n", |
| 8614 | rc); |
| 8615 | } |
Michael Chan | a1ef4a7 | 2018-08-05 16:51:49 -0400 | [diff] [blame] | 8616 | if (test_and_clear_bit(BNXT_UPDATE_PHY_SP_EVENT, &bp->sp_event)) { |
| 8617 | int rc; |
| 8618 | |
| 8619 | mutex_lock(&bp->link_lock); |
| 8620 | rc = bnxt_update_phy_setting(bp); |
| 8621 | mutex_unlock(&bp->link_lock); |
| 8622 | if (rc) { |
| 8623 | netdev_warn(bp->dev, "update phy settings retry failed\n"); |
| 8624 | } else { |
| 8625 | bp->link_info.phy_retry = false; |
| 8626 | netdev_info(bp->dev, "update phy settings retry succeeded\n"); |
| 8627 | } |
| 8628 | } |
Michael Chan | 90c694b | 2017-01-25 02:55:09 -0500 | [diff] [blame] | 8629 | if (test_and_clear_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event)) { |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 8630 | mutex_lock(&bp->link_lock); |
| 8631 | bnxt_get_port_module_status(bp); |
| 8632 | mutex_unlock(&bp->link_lock); |
Michael Chan | 90c694b | 2017-01-25 02:55:09 -0500 | [diff] [blame] | 8633 | } |
Sathya Perla | 5a84acb | 2017-10-26 11:51:31 -0400 | [diff] [blame] | 8634 | |
| 8635 | if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event)) |
| 8636 | bnxt_tc_flow_stats_work(bp); |
| 8637 | |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 8638 | /* These functions below will clear BNXT_STATE_IN_SP_TASK. They |
| 8639 | * must be the last functions to be called before exiting. |
| 8640 | */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8641 | if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event)) |
| 8642 | bnxt_reset(bp, false); |
| 8643 | |
| 8644 | if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event)) |
| 8645 | bnxt_reset(bp, true); |
| 8646 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8647 | smp_mb__before_atomic(); |
| 8648 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 8649 | } |
| 8650 | |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8651 | /* Under rtnl_lock */ |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 8652 | int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, |
| 8653 | int tx_xdp) |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8654 | { |
| 8655 | int max_rx, max_tx, tx_sets = 1; |
| 8656 | int tx_rings_needed; |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 8657 | int rx_rings = rx; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 8658 | int cp, vnics, rc; |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8659 | |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8660 | if (tcs) |
| 8661 | tx_sets = tcs; |
| 8662 | |
| 8663 | rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh); |
| 8664 | if (rc) |
| 8665 | return rc; |
| 8666 | |
| 8667 | if (max_rx < rx) |
| 8668 | return -ENOMEM; |
| 8669 | |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 8670 | tx_rings_needed = tx * tx_sets + tx_xdp; |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8671 | if (max_tx < tx_rings_needed) |
| 8672 | return -ENOMEM; |
| 8673 | |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 8674 | vnics = 1; |
| 8675 | if (bp->flags & BNXT_FLAG_RFS) |
| 8676 | vnics += rx_rings; |
| 8677 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 8678 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 8679 | rx_rings <<= 1; |
| 8680 | cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx; |
Michael Chan | f1ca94d | 2018-08-05 16:51:53 -0400 | [diff] [blame] | 8681 | if (BNXT_NEW_RM(bp)) |
Michael Chan | 11c3ec7 | 2018-04-11 11:50:17 -0400 | [diff] [blame] | 8682 | cp += bnxt_get_ulp_msix_num(bp); |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 8683 | return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp, |
| 8684 | vnics); |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8685 | } |
| 8686 | |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8687 | static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev) |
| 8688 | { |
| 8689 | if (bp->bar2) { |
| 8690 | pci_iounmap(pdev, bp->bar2); |
| 8691 | bp->bar2 = NULL; |
| 8692 | } |
| 8693 | |
| 8694 | if (bp->bar1) { |
| 8695 | pci_iounmap(pdev, bp->bar1); |
| 8696 | bp->bar1 = NULL; |
| 8697 | } |
| 8698 | |
| 8699 | if (bp->bar0) { |
| 8700 | pci_iounmap(pdev, bp->bar0); |
| 8701 | bp->bar0 = NULL; |
| 8702 | } |
| 8703 | } |
| 8704 | |
| 8705 | static void bnxt_cleanup_pci(struct bnxt *bp) |
| 8706 | { |
| 8707 | bnxt_unmap_bars(bp, bp->pdev); |
| 8708 | pci_release_regions(bp->pdev); |
| 8709 | pci_disable_device(bp->pdev); |
| 8710 | } |
| 8711 | |
Michael Chan | 18775aa | 2017-10-26 11:51:27 -0400 | [diff] [blame] | 8712 | static void bnxt_init_dflt_coal(struct bnxt *bp) |
| 8713 | { |
| 8714 | struct bnxt_coal *coal; |
| 8715 | |
| 8716 | /* Tick values in micro seconds. |
| 8717 | * 1 coal_buf x bufs_per_record = 1 completion record. |
| 8718 | */ |
| 8719 | coal = &bp->rx_coal; |
| 8720 | coal->coal_ticks = 14; |
| 8721 | coal->coal_bufs = 30; |
| 8722 | coal->coal_ticks_irq = 1; |
| 8723 | coal->coal_bufs_irq = 2; |
Andy Gospodarek | 05abe4dd | 2018-04-26 17:44:38 -0400 | [diff] [blame] | 8724 | coal->idle_thresh = 50; |
Michael Chan | 18775aa | 2017-10-26 11:51:27 -0400 | [diff] [blame] | 8725 | coal->bufs_per_record = 2; |
| 8726 | coal->budget = 64; /* NAPI budget */ |
| 8727 | |
| 8728 | coal = &bp->tx_coal; |
| 8729 | coal->coal_ticks = 28; |
| 8730 | coal->coal_bufs = 30; |
| 8731 | coal->coal_ticks_irq = 2; |
| 8732 | coal->coal_bufs_irq = 2; |
| 8733 | coal->bufs_per_record = 1; |
| 8734 | |
| 8735 | bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS; |
| 8736 | } |
| 8737 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8738 | static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) |
| 8739 | { |
| 8740 | int rc; |
| 8741 | struct bnxt *bp = netdev_priv(dev); |
| 8742 | |
| 8743 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 8744 | |
| 8745 | /* enable device (incl. PCI PM wakeup), and bus-mastering */ |
| 8746 | rc = pci_enable_device(pdev); |
| 8747 | if (rc) { |
| 8748 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
| 8749 | goto init_err; |
| 8750 | } |
| 8751 | |
| 8752 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 8753 | dev_err(&pdev->dev, |
| 8754 | "Cannot find PCI device base address, aborting\n"); |
| 8755 | rc = -ENODEV; |
| 8756 | goto init_err_disable; |
| 8757 | } |
| 8758 | |
| 8759 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 8760 | if (rc) { |
| 8761 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
| 8762 | goto init_err_disable; |
| 8763 | } |
| 8764 | |
| 8765 | if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 && |
| 8766 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) { |
| 8767 | dev_err(&pdev->dev, "System does not support DMA, aborting\n"); |
| 8768 | goto init_err_disable; |
| 8769 | } |
| 8770 | |
| 8771 | pci_set_master(pdev); |
| 8772 | |
| 8773 | bp->dev = dev; |
| 8774 | bp->pdev = pdev; |
| 8775 | |
| 8776 | bp->bar0 = pci_ioremap_bar(pdev, 0); |
| 8777 | if (!bp->bar0) { |
| 8778 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
| 8779 | rc = -ENOMEM; |
| 8780 | goto init_err_release; |
| 8781 | } |
| 8782 | |
| 8783 | bp->bar1 = pci_ioremap_bar(pdev, 2); |
| 8784 | if (!bp->bar1) { |
| 8785 | dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n"); |
| 8786 | rc = -ENOMEM; |
| 8787 | goto init_err_release; |
| 8788 | } |
| 8789 | |
| 8790 | bp->bar2 = pci_ioremap_bar(pdev, 4); |
| 8791 | if (!bp->bar2) { |
| 8792 | dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n"); |
| 8793 | rc = -ENOMEM; |
| 8794 | goto init_err_release; |
| 8795 | } |
| 8796 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 8797 | pci_enable_pcie_error_reporting(pdev); |
| 8798 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8799 | INIT_WORK(&bp->sp_task, bnxt_sp_task); |
| 8800 | |
| 8801 | spin_lock_init(&bp->ntp_fltr_lock); |
Michael Chan | 697197e | 2018-10-14 07:02:46 -0400 | [diff] [blame] | 8802 | #if BITS_PER_LONG == 32 |
| 8803 | spin_lock_init(&bp->db_lock); |
| 8804 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8805 | |
| 8806 | bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE; |
| 8807 | bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE; |
| 8808 | |
Michael Chan | 18775aa | 2017-10-26 11:51:27 -0400 | [diff] [blame] | 8809 | bnxt_init_dflt_coal(bp); |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 8810 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 8811 | timer_setup(&bp->timer, bnxt_timer, 0); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8812 | bp->current_interval = BNXT_TIMER_INTERVAL; |
| 8813 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 8814 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8815 | return 0; |
| 8816 | |
| 8817 | init_err_release: |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8818 | bnxt_unmap_bars(bp, pdev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8819 | pci_release_regions(pdev); |
| 8820 | |
| 8821 | init_err_disable: |
| 8822 | pci_disable_device(pdev); |
| 8823 | |
| 8824 | init_err: |
| 8825 | return rc; |
| 8826 | } |
| 8827 | |
| 8828 | /* rtnl_lock held */ |
| 8829 | static int bnxt_change_mac_addr(struct net_device *dev, void *p) |
| 8830 | { |
| 8831 | struct sockaddr *addr = p; |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 8832 | struct bnxt *bp = netdev_priv(dev); |
| 8833 | int rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8834 | |
| 8835 | if (!is_valid_ether_addr(addr->sa_data)) |
| 8836 | return -EADDRNOTAVAIL; |
| 8837 | |
Michael Chan | c1a7bdf | 2017-10-26 11:51:24 -0400 | [diff] [blame] | 8838 | if (ether_addr_equal(addr->sa_data, dev->dev_addr)) |
| 8839 | return 0; |
| 8840 | |
Michael Chan | 28ea334 | 2018-09-14 15:41:29 -0400 | [diff] [blame] | 8841 | rc = bnxt_approve_mac(bp, addr->sa_data, true); |
Michael Chan | 84c33dd | 2016-04-11 04:11:13 -0400 | [diff] [blame] | 8842 | if (rc) |
| 8843 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8844 | |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 8845 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 8846 | if (netif_running(dev)) { |
| 8847 | bnxt_close_nic(bp, false, false); |
| 8848 | rc = bnxt_open_nic(bp, false, false); |
| 8849 | } |
| 8850 | |
| 8851 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8852 | } |
| 8853 | |
| 8854 | /* rtnl_lock held */ |
| 8855 | static int bnxt_change_mtu(struct net_device *dev, int new_mtu) |
| 8856 | { |
| 8857 | struct bnxt *bp = netdev_priv(dev); |
| 8858 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8859 | if (netif_running(dev)) |
| 8860 | bnxt_close_nic(bp, false, false); |
| 8861 | |
| 8862 | dev->mtu = new_mtu; |
| 8863 | bnxt_set_ring_params(bp); |
| 8864 | |
| 8865 | if (netif_running(dev)) |
| 8866 | return bnxt_open_nic(bp, false, false); |
| 8867 | |
| 8868 | return 0; |
| 8869 | } |
| 8870 | |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 8871 | int bnxt_setup_mq_tc(struct net_device *dev, u8 tc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8872 | { |
| 8873 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 8874 | bool sh = false; |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8875 | int rc; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 8876 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8877 | if (tc > bp->max_tc) { |
Michael Chan | b451c8b | 2017-02-12 19:18:17 -0500 | [diff] [blame] | 8878 | netdev_err(dev, "Too many traffic classes requested: %d. Max supported is %d.\n", |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8879 | tc, bp->max_tc); |
| 8880 | return -EINVAL; |
| 8881 | } |
| 8882 | |
| 8883 | if (netdev_get_num_tc(dev) == tc) |
| 8884 | return 0; |
| 8885 | |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 8886 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 8887 | sh = true; |
| 8888 | |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 8889 | rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings, |
| 8890 | sh, tc, bp->tx_nr_rings_xdp); |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 8891 | if (rc) |
| 8892 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8893 | |
| 8894 | /* Needs to close the device and do hw resource re-allocations */ |
| 8895 | if (netif_running(bp->dev)) |
| 8896 | bnxt_close_nic(bp, true, false); |
| 8897 | |
| 8898 | if (tc) { |
| 8899 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc; |
| 8900 | netdev_set_num_tc(dev, tc); |
| 8901 | } else { |
| 8902 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 8903 | netdev_reset_tc(dev); |
| 8904 | } |
Michael Chan | 87e9b37 | 2017-08-23 19:34:03 -0400 | [diff] [blame] | 8905 | bp->tx_nr_rings += bp->tx_nr_rings_xdp; |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 8906 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 8907 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8908 | bp->num_stat_ctxs = bp->cp_nr_rings; |
| 8909 | |
| 8910 | if (netif_running(bp->dev)) |
| 8911 | return bnxt_open_nic(bp, true, false); |
| 8912 | |
| 8913 | return 0; |
| 8914 | } |
| 8915 | |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 8916 | static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data, |
| 8917 | void *cb_priv) |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8918 | { |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 8919 | struct bnxt *bp = cb_priv; |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8920 | |
Jakub Kicinski | 312324f | 2018-01-25 14:00:48 -0800 | [diff] [blame] | 8921 | if (!bnxt_tc_flower_enabled(bp) || |
| 8922 | !tc_cls_can_offload_and_chain0(bp->dev, type_data)) |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8923 | return -EOPNOTSUPP; |
| 8924 | |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 8925 | switch (type) { |
| 8926 | case TC_SETUP_CLSFLOWER: |
| 8927 | return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data); |
| 8928 | default: |
| 8929 | return -EOPNOTSUPP; |
| 8930 | } |
| 8931 | } |
| 8932 | |
| 8933 | static int bnxt_setup_tc_block(struct net_device *dev, |
| 8934 | struct tc_block_offload *f) |
| 8935 | { |
| 8936 | struct bnxt *bp = netdev_priv(dev); |
| 8937 | |
| 8938 | if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS) |
| 8939 | return -EOPNOTSUPP; |
| 8940 | |
| 8941 | switch (f->command) { |
| 8942 | case TC_BLOCK_BIND: |
| 8943 | return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb, |
John Hurley | 60513bd | 2018-06-25 14:30:04 -0700 | [diff] [blame] | 8944 | bp, bp, f->extack); |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 8945 | case TC_BLOCK_UNBIND: |
| 8946 | tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp); |
| 8947 | return 0; |
| 8948 | default: |
| 8949 | return -EOPNOTSUPP; |
| 8950 | } |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8951 | } |
| 8952 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 8953 | static int bnxt_setup_tc(struct net_device *dev, enum tc_setup_type type, |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 8954 | void *type_data) |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 8955 | { |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8956 | switch (type) { |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 8957 | case TC_SETUP_BLOCK: |
| 8958 | return bnxt_setup_tc_block(dev, type_data); |
Nogah Frankel | 575ed7d | 2017-11-06 07:23:42 +0100 | [diff] [blame] | 8959 | case TC_SETUP_QDISC_MQPRIO: { |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8960 | struct tc_mqprio_qopt *mqprio = type_data; |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 8961 | |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8962 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 8963 | |
| 8964 | return bnxt_setup_mq_tc(dev, mqprio->num_tc); |
| 8965 | } |
| 8966 | default: |
Jiri Pirko | 38cf042 | 2017-08-07 10:15:31 +0200 | [diff] [blame] | 8967 | return -EOPNOTSUPP; |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8968 | } |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 8969 | } |
| 8970 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8971 | #ifdef CONFIG_RFS_ACCEL |
| 8972 | static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1, |
| 8973 | struct bnxt_ntuple_filter *f2) |
| 8974 | { |
| 8975 | struct flow_keys *keys1 = &f1->fkeys; |
| 8976 | struct flow_keys *keys2 = &f2->fkeys; |
| 8977 | |
| 8978 | if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src && |
| 8979 | keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst && |
| 8980 | keys1->ports.ports == keys2->ports.ports && |
| 8981 | keys1->basic.ip_proto == keys2->basic.ip_proto && |
| 8982 | keys1->basic.n_proto == keys2->basic.n_proto && |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 8983 | keys1->control.flags == keys2->control.flags && |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 8984 | ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) && |
| 8985 | ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8986 | return true; |
| 8987 | |
| 8988 | return false; |
| 8989 | } |
| 8990 | |
| 8991 | static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, |
| 8992 | u16 rxq_index, u32 flow_id) |
| 8993 | { |
| 8994 | struct bnxt *bp = netdev_priv(dev); |
| 8995 | struct bnxt_ntuple_filter *fltr, *new_fltr; |
| 8996 | struct flow_keys *fkeys; |
| 8997 | struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb); |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 8998 | int rc = 0, idx, bit_id, l2_idx = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8999 | struct hlist_head *head; |
| 9000 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 9001 | if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) { |
| 9002 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 9003 | int off = 0, j; |
| 9004 | |
| 9005 | netif_addr_lock_bh(dev); |
| 9006 | for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) { |
| 9007 | if (ether_addr_equal(eth->h_dest, |
| 9008 | vnic->uc_list + off)) { |
| 9009 | l2_idx = j + 1; |
| 9010 | break; |
| 9011 | } |
| 9012 | } |
| 9013 | netif_addr_unlock_bh(dev); |
| 9014 | if (!l2_idx) |
| 9015 | return -EINVAL; |
| 9016 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9017 | new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC); |
| 9018 | if (!new_fltr) |
| 9019 | return -ENOMEM; |
| 9020 | |
| 9021 | fkeys = &new_fltr->fkeys; |
| 9022 | if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) { |
| 9023 | rc = -EPROTONOSUPPORT; |
| 9024 | goto err_free; |
| 9025 | } |
| 9026 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 9027 | if ((fkeys->basic.n_proto != htons(ETH_P_IP) && |
| 9028 | fkeys->basic.n_proto != htons(ETH_P_IPV6)) || |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9029 | ((fkeys->basic.ip_proto != IPPROTO_TCP) && |
| 9030 | (fkeys->basic.ip_proto != IPPROTO_UDP))) { |
| 9031 | rc = -EPROTONOSUPPORT; |
| 9032 | goto err_free; |
| 9033 | } |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 9034 | if (fkeys->basic.n_proto == htons(ETH_P_IPV6) && |
| 9035 | bp->hwrm_spec_code < 0x10601) { |
| 9036 | rc = -EPROTONOSUPPORT; |
| 9037 | goto err_free; |
| 9038 | } |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 9039 | if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) && |
| 9040 | bp->hwrm_spec_code < 0x10601) { |
| 9041 | rc = -EPROTONOSUPPORT; |
| 9042 | goto err_free; |
| 9043 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9044 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 9045 | memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9046 | memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN); |
| 9047 | |
| 9048 | idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK; |
| 9049 | head = &bp->ntp_fltr_hash_tbl[idx]; |
| 9050 | rcu_read_lock(); |
| 9051 | hlist_for_each_entry_rcu(fltr, head, hash) { |
| 9052 | if (bnxt_fltr_match(fltr, new_fltr)) { |
| 9053 | rcu_read_unlock(); |
| 9054 | rc = 0; |
| 9055 | goto err_free; |
| 9056 | } |
| 9057 | } |
| 9058 | rcu_read_unlock(); |
| 9059 | |
| 9060 | spin_lock_bh(&bp->ntp_fltr_lock); |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 9061 | bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, |
| 9062 | BNXT_NTP_FLTR_MAX_FLTR, 0); |
| 9063 | if (bit_id < 0) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9064 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 9065 | rc = -ENOMEM; |
| 9066 | goto err_free; |
| 9067 | } |
| 9068 | |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 9069 | new_fltr->sw_id = (u16)bit_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9070 | new_fltr->flow_id = flow_id; |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 9071 | new_fltr->l2_fltr_idx = l2_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9072 | new_fltr->rxq = rxq_index; |
| 9073 | hlist_add_head_rcu(&new_fltr->hash, head); |
| 9074 | bp->ntp_fltr_count++; |
| 9075 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 9076 | |
| 9077 | set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9078 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9079 | |
| 9080 | return new_fltr->sw_id; |
| 9081 | |
| 9082 | err_free: |
| 9083 | kfree(new_fltr); |
| 9084 | return rc; |
| 9085 | } |
| 9086 | |
| 9087 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 9088 | { |
| 9089 | int i; |
| 9090 | |
| 9091 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 9092 | struct hlist_head *head; |
| 9093 | struct hlist_node *tmp; |
| 9094 | struct bnxt_ntuple_filter *fltr; |
| 9095 | int rc; |
| 9096 | |
| 9097 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 9098 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 9099 | bool del = false; |
| 9100 | |
| 9101 | if (test_bit(BNXT_FLTR_VALID, &fltr->state)) { |
| 9102 | if (rps_may_expire_flow(bp->dev, fltr->rxq, |
| 9103 | fltr->flow_id, |
| 9104 | fltr->sw_id)) { |
| 9105 | bnxt_hwrm_cfa_ntuple_filter_free(bp, |
| 9106 | fltr); |
| 9107 | del = true; |
| 9108 | } |
| 9109 | } else { |
| 9110 | rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp, |
| 9111 | fltr); |
| 9112 | if (rc) |
| 9113 | del = true; |
| 9114 | else |
| 9115 | set_bit(BNXT_FLTR_VALID, &fltr->state); |
| 9116 | } |
| 9117 | |
| 9118 | if (del) { |
| 9119 | spin_lock_bh(&bp->ntp_fltr_lock); |
| 9120 | hlist_del_rcu(&fltr->hash); |
| 9121 | bp->ntp_fltr_count--; |
| 9122 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 9123 | synchronize_rcu(); |
| 9124 | clear_bit(fltr->sw_id, bp->ntp_fltr_bmap); |
| 9125 | kfree(fltr); |
| 9126 | } |
| 9127 | } |
| 9128 | } |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 9129 | if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event)) |
| 9130 | netdev_info(bp->dev, "Receive PF driver unload event!"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9131 | } |
| 9132 | |
| 9133 | #else |
| 9134 | |
| 9135 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 9136 | { |
| 9137 | } |
| 9138 | |
| 9139 | #endif /* CONFIG_RFS_ACCEL */ |
| 9140 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9141 | static void bnxt_udp_tunnel_add(struct net_device *dev, |
| 9142 | struct udp_tunnel_info *ti) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9143 | { |
| 9144 | struct bnxt *bp = netdev_priv(dev); |
| 9145 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9146 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 9147 | return; |
| 9148 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9149 | if (!netif_running(dev)) |
| 9150 | return; |
| 9151 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9152 | switch (ti->type) { |
| 9153 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9154 | if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port) |
| 9155 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9156 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9157 | bp->vxlan_port_cnt++; |
| 9158 | if (bp->vxlan_port_cnt == 1) { |
| 9159 | bp->vxlan_port = ti->port; |
| 9160 | set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9161 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9162 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9163 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 9164 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9165 | if (bp->nge_port_cnt && bp->nge_port != ti->port) |
| 9166 | return; |
| 9167 | |
| 9168 | bp->nge_port_cnt++; |
| 9169 | if (bp->nge_port_cnt == 1) { |
| 9170 | bp->nge_port = ti->port; |
| 9171 | set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event); |
| 9172 | } |
| 9173 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9174 | default: |
| 9175 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9176 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9177 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9178 | bnxt_queue_sp_work(bp); |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9179 | } |
| 9180 | |
| 9181 | static void bnxt_udp_tunnel_del(struct net_device *dev, |
| 9182 | struct udp_tunnel_info *ti) |
| 9183 | { |
| 9184 | struct bnxt *bp = netdev_priv(dev); |
| 9185 | |
| 9186 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 9187 | return; |
| 9188 | |
| 9189 | if (!netif_running(dev)) |
| 9190 | return; |
| 9191 | |
| 9192 | switch (ti->type) { |
| 9193 | case UDP_TUNNEL_TYPE_VXLAN: |
| 9194 | if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port) |
| 9195 | return; |
| 9196 | bp->vxlan_port_cnt--; |
| 9197 | |
| 9198 | if (bp->vxlan_port_cnt != 0) |
| 9199 | return; |
| 9200 | |
| 9201 | set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 9202 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 9203 | case UDP_TUNNEL_TYPE_GENEVE: |
| 9204 | if (!bp->nge_port_cnt || bp->nge_port != ti->port) |
| 9205 | return; |
| 9206 | bp->nge_port_cnt--; |
| 9207 | |
| 9208 | if (bp->nge_port_cnt != 0) |
| 9209 | return; |
| 9210 | |
| 9211 | set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 9212 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9213 | default: |
| 9214 | return; |
| 9215 | } |
| 9216 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9217 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9218 | } |
| 9219 | |
Michael Chan | 39d8ba2 | 2017-07-24 12:34:22 -0400 | [diff] [blame] | 9220 | static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 9221 | struct net_device *dev, u32 filter_mask, |
| 9222 | int nlflags) |
| 9223 | { |
| 9224 | struct bnxt *bp = netdev_priv(dev); |
| 9225 | |
| 9226 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0, |
| 9227 | nlflags, filter_mask, NULL); |
| 9228 | } |
| 9229 | |
| 9230 | static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, |
| 9231 | u16 flags) |
| 9232 | { |
| 9233 | struct bnxt *bp = netdev_priv(dev); |
| 9234 | struct nlattr *attr, *br_spec; |
| 9235 | int rem, rc = 0; |
| 9236 | |
| 9237 | if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp)) |
| 9238 | return -EOPNOTSUPP; |
| 9239 | |
| 9240 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 9241 | if (!br_spec) |
| 9242 | return -EINVAL; |
| 9243 | |
| 9244 | nla_for_each_nested(attr, br_spec, rem) { |
| 9245 | u16 mode; |
| 9246 | |
| 9247 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 9248 | continue; |
| 9249 | |
| 9250 | if (nla_len(attr) < sizeof(mode)) |
| 9251 | return -EINVAL; |
| 9252 | |
| 9253 | mode = nla_get_u16(attr); |
| 9254 | if (mode == bp->br_mode) |
| 9255 | break; |
| 9256 | |
| 9257 | rc = bnxt_hwrm_set_br_mode(bp, mode); |
| 9258 | if (!rc) |
| 9259 | bp->br_mode = mode; |
| 9260 | break; |
| 9261 | } |
| 9262 | return rc; |
| 9263 | } |
| 9264 | |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 9265 | static int bnxt_get_phys_port_name(struct net_device *dev, char *buf, |
| 9266 | size_t len) |
| 9267 | { |
| 9268 | struct bnxt *bp = netdev_priv(dev); |
| 9269 | int rc; |
| 9270 | |
| 9271 | /* The PF and it's VF-reps only support the switchdev framework */ |
| 9272 | if (!BNXT_PF(bp)) |
| 9273 | return -EOPNOTSUPP; |
| 9274 | |
Sathya Perla | 53f70b8 | 2017-07-25 13:28:41 -0400 | [diff] [blame] | 9275 | rc = snprintf(buf, len, "p%d", bp->pf.port_id); |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 9276 | |
| 9277 | if (rc >= len) |
| 9278 | return -EOPNOTSUPP; |
| 9279 | return 0; |
| 9280 | } |
| 9281 | |
| 9282 | int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr) |
| 9283 | { |
| 9284 | if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV) |
| 9285 | return -EOPNOTSUPP; |
| 9286 | |
| 9287 | /* The PF and it's VF-reps only support the switchdev framework */ |
| 9288 | if (!BNXT_PF(bp)) |
| 9289 | return -EOPNOTSUPP; |
| 9290 | |
| 9291 | switch (attr->id) { |
| 9292 | case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: |
Sathya Perla | dd4ea1d | 2018-01-17 03:21:16 -0500 | [diff] [blame] | 9293 | attr->u.ppid.id_len = sizeof(bp->switch_id); |
| 9294 | memcpy(attr->u.ppid.id, bp->switch_id, attr->u.ppid.id_len); |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 9295 | break; |
| 9296 | default: |
| 9297 | return -EOPNOTSUPP; |
| 9298 | } |
| 9299 | return 0; |
| 9300 | } |
| 9301 | |
| 9302 | static int bnxt_swdev_port_attr_get(struct net_device *dev, |
| 9303 | struct switchdev_attr *attr) |
| 9304 | { |
| 9305 | return bnxt_port_attr_get(netdev_priv(dev), attr); |
| 9306 | } |
| 9307 | |
| 9308 | static const struct switchdev_ops bnxt_switchdev_ops = { |
| 9309 | .switchdev_port_attr_get = bnxt_swdev_port_attr_get |
| 9310 | }; |
| 9311 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9312 | static const struct net_device_ops bnxt_netdev_ops = { |
| 9313 | .ndo_open = bnxt_open, |
| 9314 | .ndo_start_xmit = bnxt_start_xmit, |
| 9315 | .ndo_stop = bnxt_close, |
| 9316 | .ndo_get_stats64 = bnxt_get_stats64, |
| 9317 | .ndo_set_rx_mode = bnxt_set_rx_mode, |
| 9318 | .ndo_do_ioctl = bnxt_ioctl, |
| 9319 | .ndo_validate_addr = eth_validate_addr, |
| 9320 | .ndo_set_mac_address = bnxt_change_mac_addr, |
| 9321 | .ndo_change_mtu = bnxt_change_mtu, |
| 9322 | .ndo_fix_features = bnxt_fix_features, |
| 9323 | .ndo_set_features = bnxt_set_features, |
| 9324 | .ndo_tx_timeout = bnxt_tx_timeout, |
| 9325 | #ifdef CONFIG_BNXT_SRIOV |
| 9326 | .ndo_get_vf_config = bnxt_get_vf_config, |
| 9327 | .ndo_set_vf_mac = bnxt_set_vf_mac, |
| 9328 | .ndo_set_vf_vlan = bnxt_set_vf_vlan, |
| 9329 | .ndo_set_vf_rate = bnxt_set_vf_bw, |
| 9330 | .ndo_set_vf_link_state = bnxt_set_vf_link_state, |
| 9331 | .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk, |
Vasundhara Volam | 746df13 | 2018-03-31 13:54:10 -0400 | [diff] [blame] | 9332 | .ndo_set_vf_trust = bnxt_set_vf_trust, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9333 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9334 | .ndo_setup_tc = bnxt_setup_tc, |
| 9335 | #ifdef CONFIG_RFS_ACCEL |
| 9336 | .ndo_rx_flow_steer = bnxt_rx_flow_steer, |
| 9337 | #endif |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 9338 | .ndo_udp_tunnel_add = bnxt_udp_tunnel_add, |
| 9339 | .ndo_udp_tunnel_del = bnxt_udp_tunnel_del, |
Jakub Kicinski | f4e6352 | 2017-11-03 13:56:16 -0700 | [diff] [blame] | 9340 | .ndo_bpf = bnxt_xdp, |
Michael Chan | 39d8ba2 | 2017-07-24 12:34:22 -0400 | [diff] [blame] | 9341 | .ndo_bridge_getlink = bnxt_bridge_getlink, |
| 9342 | .ndo_bridge_setlink = bnxt_bridge_setlink, |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 9343 | .ndo_get_phys_port_name = bnxt_get_phys_port_name |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9344 | }; |
| 9345 | |
| 9346 | static void bnxt_remove_one(struct pci_dev *pdev) |
| 9347 | { |
| 9348 | struct net_device *dev = pci_get_drvdata(pdev); |
| 9349 | struct bnxt *bp = netdev_priv(dev); |
| 9350 | |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 9351 | if (BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9352 | bnxt_sriov_disable(bp); |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 9353 | bnxt_dl_unregister(bp); |
| 9354 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9355 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9356 | pci_disable_pcie_error_reporting(pdev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9357 | unregister_netdev(dev); |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 9358 | bnxt_shutdown_tc(bp); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9359 | bnxt_cancel_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9360 | bp->sp_event = 0; |
| 9361 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 9362 | bnxt_clear_int_mode(bp); |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 9363 | bnxt_hwrm_func_drv_unrgtr(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9364 | bnxt_free_hwrm_resources(bp); |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 9365 | bnxt_free_hwrm_short_cmd_req(bp); |
Michael Chan | eb51365 | 2017-04-04 18:14:12 -0400 | [diff] [blame] | 9366 | bnxt_ethtool_free(bp); |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 9367 | bnxt_dcb_free(bp); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 9368 | kfree(bp->edev); |
| 9369 | bp->edev = NULL; |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 9370 | bnxt_free_ctx_mem(bp); |
| 9371 | kfree(bp->ctx); |
| 9372 | bp->ctx = NULL; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9373 | bnxt_cleanup_pci(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9374 | free_netdev(dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9375 | } |
| 9376 | |
| 9377 | static int bnxt_probe_phy(struct bnxt *bp) |
| 9378 | { |
| 9379 | int rc = 0; |
| 9380 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9381 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 9382 | rc = bnxt_hwrm_phy_qcaps(bp); |
| 9383 | if (rc) { |
| 9384 | netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n", |
| 9385 | rc); |
| 9386 | return rc; |
| 9387 | } |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 9388 | mutex_init(&bp->link_lock); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 9389 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9390 | rc = bnxt_update_link(bp, false); |
| 9391 | if (rc) { |
| 9392 | netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n", |
| 9393 | rc); |
| 9394 | return rc; |
| 9395 | } |
| 9396 | |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 9397 | /* Older firmware does not have supported_auto_speeds, so assume |
| 9398 | * that all supported speeds can be autonegotiated. |
| 9399 | */ |
| 9400 | if (link_info->auto_link_speeds && !link_info->support_auto_speeds) |
| 9401 | link_info->support_auto_speeds = link_info->support_speeds; |
| 9402 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9403 | /*initialize the ethool setting copy with NVM settings */ |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 9404 | if (BNXT_AUTO_MODE(link_info->auto_mode)) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 9405 | link_info->autoneg = BNXT_AUTONEG_SPEED; |
| 9406 | if (bp->hwrm_spec_code >= 0x10201) { |
| 9407 | if (link_info->auto_pause_setting & |
| 9408 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE) |
| 9409 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 9410 | } else { |
| 9411 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 9412 | } |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 9413 | link_info->advertising = link_info->auto_link_speeds; |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 9414 | } else { |
| 9415 | link_info->req_link_speed = link_info->force_link_speed; |
| 9416 | link_info->req_duplex = link_info->duplex_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9417 | } |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 9418 | if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) |
| 9419 | link_info->req_flow_ctrl = |
| 9420 | link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH; |
| 9421 | else |
| 9422 | link_info->req_flow_ctrl = link_info->force_pause_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9423 | return rc; |
| 9424 | } |
| 9425 | |
| 9426 | static int bnxt_get_max_irq(struct pci_dev *pdev) |
| 9427 | { |
| 9428 | u16 ctrl; |
| 9429 | |
| 9430 | if (!pdev->msix_cap) |
| 9431 | return 1; |
| 9432 | |
| 9433 | pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl); |
| 9434 | return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 9435 | } |
| 9436 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9437 | static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 9438 | int *max_cp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9439 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 9440 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9441 | int max_ring_grps = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9442 | |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 9443 | *max_tx = hw_resc->max_tx_rings; |
| 9444 | *max_rx = hw_resc->max_rx_rings; |
Michael Chan | 00fe9c3 | 2018-09-03 04:23:19 -0400 | [diff] [blame] | 9445 | *max_cp = min_t(int, bnxt_get_max_func_cp_rings_for_en(bp), |
Vasundhara Volam | c78fe05 | 2018-10-05 00:26:03 -0400 | [diff] [blame] | 9446 | hw_resc->max_irqs - bnxt_get_ulp_msix_num(bp)); |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 9447 | *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs); |
| 9448 | max_ring_grps = hw_resc->max_hw_ring_grps; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 9449 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) { |
| 9450 | *max_cp -= 1; |
| 9451 | *max_rx -= 2; |
| 9452 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9453 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 9454 | *max_rx >>= 1; |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 9455 | *max_rx = min_t(int, *max_rx, max_ring_grps); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9456 | } |
| 9457 | |
| 9458 | int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared) |
| 9459 | { |
| 9460 | int rx, tx, cp; |
| 9461 | |
| 9462 | _bnxt_get_max_rings(bp, &rx, &tx, &cp); |
Michael Chan | 78f058a | 2018-07-09 02:24:49 -0400 | [diff] [blame] | 9463 | *max_rx = rx; |
| 9464 | *max_tx = tx; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9465 | if (!rx || !tx || !cp) |
| 9466 | return -ENOMEM; |
| 9467 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9468 | return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared); |
| 9469 | } |
| 9470 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 9471 | static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 9472 | bool shared) |
| 9473 | { |
| 9474 | int rc; |
| 9475 | |
| 9476 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 9477 | if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) { |
| 9478 | /* Not enough rings, try disabling agg rings. */ |
| 9479 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 9480 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
Michael Chan | 07f4fde | 2018-07-09 02:24:48 -0400 | [diff] [blame] | 9481 | if (rc) { |
| 9482 | /* set BNXT_FLAG_AGG_RINGS back for consistency */ |
| 9483 | bp->flags |= BNXT_FLAG_AGG_RINGS; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 9484 | return rc; |
Michael Chan | 07f4fde | 2018-07-09 02:24:48 -0400 | [diff] [blame] | 9485 | } |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 9486 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 9487 | bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); |
| 9488 | bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 9489 | bnxt_set_ring_params(bp); |
| 9490 | } |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 9491 | |
| 9492 | if (bp->flags & BNXT_FLAG_ROCE_CAP) { |
| 9493 | int max_cp, max_stat, max_irq; |
| 9494 | |
| 9495 | /* Reserve minimum resources for RoCE */ |
| 9496 | max_cp = bnxt_get_max_func_cp_rings(bp); |
| 9497 | max_stat = bnxt_get_max_func_stat_ctxs(bp); |
| 9498 | max_irq = bnxt_get_max_func_irqs(bp); |
| 9499 | if (max_cp <= BNXT_MIN_ROCE_CP_RINGS || |
| 9500 | max_irq <= BNXT_MIN_ROCE_CP_RINGS || |
| 9501 | max_stat <= BNXT_MIN_ROCE_STAT_CTXS) |
| 9502 | return 0; |
| 9503 | |
| 9504 | max_cp -= BNXT_MIN_ROCE_CP_RINGS; |
| 9505 | max_irq -= BNXT_MIN_ROCE_CP_RINGS; |
| 9506 | max_stat -= BNXT_MIN_ROCE_STAT_CTXS; |
| 9507 | max_cp = min_t(int, max_cp, max_irq); |
| 9508 | max_cp = min_t(int, max_cp, max_stat); |
| 9509 | rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared); |
| 9510 | if (rc) |
| 9511 | rc = 0; |
| 9512 | } |
| 9513 | return rc; |
| 9514 | } |
| 9515 | |
Michael Chan | 58ea801 | 2018-01-17 03:21:08 -0500 | [diff] [blame] | 9516 | /* In initial default shared ring setting, each shared ring must have a |
| 9517 | * RX/TX ring pair. |
| 9518 | */ |
| 9519 | static void bnxt_trim_dflt_sh_rings(struct bnxt *bp) |
| 9520 | { |
| 9521 | bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings); |
| 9522 | bp->rx_nr_rings = bp->cp_nr_rings; |
| 9523 | bp->tx_nr_rings_per_tc = bp->cp_nr_rings; |
| 9524 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 9525 | } |
| 9526 | |
Michael Chan | 702c221 | 2017-05-29 19:06:10 -0400 | [diff] [blame] | 9527 | static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9528 | { |
| 9529 | int dflt_rings, max_rx_rings, max_tx_rings, rc; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9530 | |
Michael Chan | 2773dfb | 2018-04-26 17:44:42 -0400 | [diff] [blame] | 9531 | if (!bnxt_can_reserve_rings(bp)) |
| 9532 | return 0; |
| 9533 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9534 | if (sh) |
| 9535 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
| 9536 | dflt_rings = netif_get_num_default_rss_queues(); |
Michael Chan | 1d3ef13 | 2018-03-31 13:54:07 -0400 | [diff] [blame] | 9537 | /* Reduce default rings on multi-port cards so that total default |
| 9538 | * rings do not exceed CPU count. |
| 9539 | */ |
| 9540 | if (bp->port_count > 1) { |
| 9541 | int max_rings = |
| 9542 | max_t(int, num_online_cpus() / bp->port_count, 1); |
| 9543 | |
| 9544 | dflt_rings = min_t(int, dflt_rings, max_rings); |
| 9545 | } |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 9546 | rc = bnxt_get_dflt_rings(bp, &max_rx_rings, &max_tx_rings, sh); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9547 | if (rc) |
| 9548 | return rc; |
| 9549 | bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings); |
| 9550 | bp->tx_nr_rings_per_tc = min_t(int, dflt_rings, max_tx_rings); |
Michael Chan | 58ea801 | 2018-01-17 03:21:08 -0500 | [diff] [blame] | 9551 | if (sh) |
| 9552 | bnxt_trim_dflt_sh_rings(bp); |
| 9553 | else |
| 9554 | bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings; |
| 9555 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 9556 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 9557 | rc = __bnxt_reserve_rings(bp); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 9558 | if (rc) |
| 9559 | netdev_warn(bp->dev, "Unable to reserve tx rings\n"); |
Michael Chan | 58ea801 | 2018-01-17 03:21:08 -0500 | [diff] [blame] | 9560 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 9561 | if (sh) |
| 9562 | bnxt_trim_dflt_sh_rings(bp); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 9563 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 9564 | /* Rings may have been trimmed, re-reserve the trimmed rings. */ |
| 9565 | if (bnxt_need_reserve_rings(bp)) { |
| 9566 | rc = __bnxt_reserve_rings(bp); |
| 9567 | if (rc) |
| 9568 | netdev_warn(bp->dev, "2nd rings reservation failed.\n"); |
| 9569 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 9570 | } |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9571 | bp->num_stat_ctxs = bp->cp_nr_rings; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 9572 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 9573 | bp->rx_nr_rings++; |
| 9574 | bp->cp_nr_rings++; |
| 9575 | } |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9576 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9577 | } |
| 9578 | |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 9579 | static int bnxt_init_dflt_ring_mode(struct bnxt *bp) |
| 9580 | { |
| 9581 | int rc; |
| 9582 | |
| 9583 | if (bp->tx_nr_rings) |
| 9584 | return 0; |
| 9585 | |
Michael Chan | 6b95c3e | 2018-09-03 04:23:17 -0400 | [diff] [blame] | 9586 | bnxt_ulp_irq_stop(bp); |
| 9587 | bnxt_clear_int_mode(bp); |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 9588 | rc = bnxt_set_dflt_rings(bp, true); |
| 9589 | if (rc) { |
| 9590 | netdev_err(bp->dev, "Not enough rings available.\n"); |
Michael Chan | 6b95c3e | 2018-09-03 04:23:17 -0400 | [diff] [blame] | 9591 | goto init_dflt_ring_err; |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 9592 | } |
| 9593 | rc = bnxt_init_int_mode(bp); |
| 9594 | if (rc) |
Michael Chan | 6b95c3e | 2018-09-03 04:23:17 -0400 | [diff] [blame] | 9595 | goto init_dflt_ring_err; |
| 9596 | |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 9597 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 9598 | if (bnxt_rfs_supported(bp) && bnxt_rfs_capable(bp)) { |
| 9599 | bp->flags |= BNXT_FLAG_RFS; |
| 9600 | bp->dev->features |= NETIF_F_NTUPLE; |
| 9601 | } |
Michael Chan | 6b95c3e | 2018-09-03 04:23:17 -0400 | [diff] [blame] | 9602 | init_dflt_ring_err: |
| 9603 | bnxt_ulp_irq_restart(bp, rc); |
| 9604 | return rc; |
Michael Chan | 47558ac | 2018-04-26 17:44:44 -0400 | [diff] [blame] | 9605 | } |
| 9606 | |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 9607 | int bnxt_restore_pf_fw_resources(struct bnxt *bp) |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 9608 | { |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 9609 | int rc; |
| 9610 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 9611 | ASSERT_RTNL(); |
| 9612 | bnxt_hwrm_func_qcaps(bp); |
Venkat Duvvuru | 1a03778 | 2018-03-09 23:46:09 -0500 | [diff] [blame] | 9613 | |
| 9614 | if (netif_running(bp->dev)) |
| 9615 | __bnxt_close_nic(bp, true, false); |
| 9616 | |
Michael Chan | ec86f14 | 2018-03-31 13:54:21 -0400 | [diff] [blame] | 9617 | bnxt_ulp_irq_stop(bp); |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 9618 | bnxt_clear_int_mode(bp); |
| 9619 | rc = bnxt_init_int_mode(bp); |
Michael Chan | ec86f14 | 2018-03-31 13:54:21 -0400 | [diff] [blame] | 9620 | bnxt_ulp_irq_restart(bp, rc); |
Venkat Duvvuru | 1a03778 | 2018-03-09 23:46:09 -0500 | [diff] [blame] | 9621 | |
| 9622 | if (netif_running(bp->dev)) { |
| 9623 | if (rc) |
| 9624 | dev_close(bp->dev); |
| 9625 | else |
| 9626 | rc = bnxt_open_nic(bp, true, false); |
| 9627 | } |
| 9628 | |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 9629 | return rc; |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 9630 | } |
| 9631 | |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9632 | static int bnxt_init_mac_addr(struct bnxt *bp) |
| 9633 | { |
| 9634 | int rc = 0; |
| 9635 | |
| 9636 | if (BNXT_PF(bp)) { |
| 9637 | memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN); |
| 9638 | } else { |
| 9639 | #ifdef CONFIG_BNXT_SRIOV |
| 9640 | struct bnxt_vf_info *vf = &bp->vf; |
Michael Chan | 28ea334 | 2018-09-14 15:41:29 -0400 | [diff] [blame] | 9641 | bool strict_approval = true; |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9642 | |
| 9643 | if (is_valid_ether_addr(vf->mac_addr)) { |
Vasundhara Volam | 91cdda4 | 2018-01-17 03:21:14 -0500 | [diff] [blame] | 9644 | /* overwrite netdev dev_addr with admin VF MAC */ |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9645 | memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN); |
Michael Chan | 28ea334 | 2018-09-14 15:41:29 -0400 | [diff] [blame] | 9646 | /* Older PF driver or firmware may not approve this |
| 9647 | * correctly. |
| 9648 | */ |
| 9649 | strict_approval = false; |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9650 | } else { |
| 9651 | eth_hw_addr_random(bp->dev); |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9652 | } |
Michael Chan | 28ea334 | 2018-09-14 15:41:29 -0400 | [diff] [blame] | 9653 | rc = bnxt_approve_mac(bp, bp->dev->dev_addr, strict_approval); |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9654 | #endif |
| 9655 | } |
| 9656 | return rc; |
| 9657 | } |
| 9658 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9659 | static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 9660 | { |
| 9661 | static int version_printed; |
| 9662 | struct net_device *dev; |
| 9663 | struct bnxt *bp; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 9664 | int rc, max_irqs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9665 | |
Ray Jui | 4e00338 | 2017-02-20 19:25:16 -0500 | [diff] [blame] | 9666 | if (pci_is_bridge(pdev)) |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 9667 | return -ENODEV; |
| 9668 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9669 | if (version_printed++ == 0) |
| 9670 | pr_info("%s", version); |
| 9671 | |
| 9672 | max_irqs = bnxt_get_max_irq(pdev); |
| 9673 | dev = alloc_etherdev_mq(sizeof(*bp), max_irqs); |
| 9674 | if (!dev) |
| 9675 | return -ENOMEM; |
| 9676 | |
| 9677 | bp = netdev_priv(dev); |
Michael Chan | 9c1fabd | 2018-10-14 07:02:47 -0400 | [diff] [blame] | 9678 | bnxt_set_max_func_irqs(bp, max_irqs); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9679 | |
| 9680 | if (bnxt_vf_pciid(ent->driver_data)) |
| 9681 | bp->flags |= BNXT_FLAG_VF; |
| 9682 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 9683 | if (pdev->msix_cap) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9684 | bp->flags |= BNXT_FLAG_MSIX_CAP; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9685 | |
| 9686 | rc = bnxt_init_board(pdev, dev); |
| 9687 | if (rc < 0) |
| 9688 | goto init_err_free; |
| 9689 | |
| 9690 | dev->netdev_ops = &bnxt_netdev_ops; |
| 9691 | dev->watchdog_timeo = BNXT_TX_TIMEOUT; |
| 9692 | dev->ethtool_ops = &bnxt_ethtool_ops; |
David S. Miller | bc88055 | 2017-07-24 21:20:16 -0700 | [diff] [blame] | 9693 | SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9694 | pci_set_drvdata(pdev, dev); |
| 9695 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 9696 | rc = bnxt_alloc_hwrm_resources(bp); |
| 9697 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9698 | goto init_err_pci_clean; |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 9699 | |
| 9700 | mutex_init(&bp->hwrm_cmd_lock); |
| 9701 | rc = bnxt_hwrm_ver_get(bp); |
| 9702 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9703 | goto init_err_pci_clean; |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 9704 | |
Michael Chan | 1dfddc4 | 2018-10-14 07:02:39 -0400 | [diff] [blame] | 9705 | if ((bp->fw_cap & BNXT_FW_CAP_SHORT_CMD) || |
| 9706 | bp->hwrm_max_ext_req_len > BNXT_HWRM_MAX_REQ_LEN) { |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 9707 | rc = bnxt_alloc_hwrm_short_cmd_req(bp); |
| 9708 | if (rc) |
| 9709 | goto init_err_pci_clean; |
| 9710 | } |
| 9711 | |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 9712 | if (BNXT_CHIP_P5(bp)) |
| 9713 | bp->flags |= BNXT_FLAG_CHIP_P5; |
| 9714 | |
Michael Chan | 3c2217a | 2017-03-08 18:44:32 -0500 | [diff] [blame] | 9715 | rc = bnxt_hwrm_func_reset(bp); |
| 9716 | if (rc) |
| 9717 | goto init_err_pci_clean; |
| 9718 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 9719 | bnxt_hwrm_fw_set_time(bp); |
| 9720 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9721 | dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 9722 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 9723 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9724 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 9725 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
| 9726 | NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 9727 | NETIF_F_RXCSUM | NETIF_F_GRO; |
| 9728 | |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 9729 | if (BNXT_SUPPORTS_TPA(bp)) |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 9730 | dev->hw_features |= NETIF_F_LRO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9731 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9732 | dev->hw_enc_features = |
| 9733 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 9734 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 9735 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 9736 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 9737 | NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL; |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 9738 | dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 9739 | NETIF_F_GSO_GRE_CSUM; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9740 | dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA; |
| 9741 | dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX | |
| 9742 | NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX; |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 9743 | if (BNXT_SUPPORTS_TPA(bp)) |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 9744 | dev->hw_features |= NETIF_F_GRO_HW; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9745 | dev->features |= dev->hw_features | NETIF_F_HIGHDMA; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 9746 | if (dev->features & NETIF_F_GRO_HW) |
| 9747 | dev->features &= ~NETIF_F_LRO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9748 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 9749 | |
| 9750 | #ifdef CONFIG_BNXT_SRIOV |
| 9751 | init_waitqueue_head(&bp->sriov_cfg_wait); |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 9752 | mutex_init(&bp->sriov_lock); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9753 | #endif |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 9754 | if (BNXT_SUPPORTS_TPA(bp)) { |
| 9755 | bp->gro_func = bnxt_gro_func_5730x; |
| 9756 | if (BNXT_CHIP_P4(bp)) |
| 9757 | bp->gro_func = bnxt_gro_func_5731x; |
| 9758 | } |
| 9759 | if (!BNXT_CHIP_P4_PLUS(bp)) |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 9760 | bp->flags |= BNXT_FLAG_DOUBLE_DB; |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 9761 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9762 | rc = bnxt_hwrm_func_drv_rgtr(bp); |
| 9763 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9764 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9765 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 9766 | rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0); |
| 9767 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9768 | goto init_err_pci_clean; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 9769 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 9770 | bp->ulp_probe = bnxt_ulp_probe; |
| 9771 | |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 9772 | rc = bnxt_hwrm_queue_qportcfg(bp); |
| 9773 | if (rc) { |
| 9774 | netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n", |
| 9775 | rc); |
| 9776 | rc = -1; |
| 9777 | goto init_err_pci_clean; |
| 9778 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9779 | /* Get the MAX capabilities for this function */ |
| 9780 | rc = bnxt_hwrm_func_qcaps(bp); |
| 9781 | if (rc) { |
| 9782 | netdev_err(bp->dev, "hwrm query capability failure rc: %x\n", |
| 9783 | rc); |
| 9784 | rc = -1; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9785 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9786 | } |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 9787 | rc = bnxt_init_mac_addr(bp); |
| 9788 | if (rc) { |
| 9789 | dev_err(&pdev->dev, "Unable to initialize mac address.\n"); |
| 9790 | rc = -EADDRNOTAVAIL; |
| 9791 | goto init_err_pci_clean; |
| 9792 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9793 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 9794 | bnxt_hwrm_func_qcfg(bp); |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 9795 | bnxt_hwrm_port_led_qcaps(bp); |
Michael Chan | eb51365 | 2017-04-04 18:14:12 -0400 | [diff] [blame] | 9796 | bnxt_ethtool_init(bp); |
Michael Chan | 87fe603 | 2017-05-16 16:39:43 -0400 | [diff] [blame] | 9797 | bnxt_dcb_init(bp); |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 9798 | |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 9799 | /* MTU range: 60 - FW defined max */ |
| 9800 | dev->min_mtu = ETH_ZLEN; |
| 9801 | dev->max_mtu = bp->max_mtu; |
| 9802 | |
Michael Chan | d5430d3 | 2017-08-28 13:40:31 -0400 | [diff] [blame] | 9803 | rc = bnxt_probe_phy(bp); |
| 9804 | if (rc) |
| 9805 | goto init_err_pci_clean; |
| 9806 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 9807 | bnxt_set_rx_skb_mode(bp, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9808 | bnxt_set_tpa_flags(bp); |
| 9809 | bnxt_set_ring_params(bp); |
Michael Chan | 702c221 | 2017-05-29 19:06:10 -0400 | [diff] [blame] | 9810 | rc = bnxt_set_dflt_rings(bp, true); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 9811 | if (rc) { |
| 9812 | netdev_err(bp->dev, "Not enough rings available.\n"); |
| 9813 | rc = -ENOMEM; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9814 | goto init_err_pci_clean; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 9815 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9816 | |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 9817 | /* Default RSS hash cfg. */ |
| 9818 | bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 | |
| 9819 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 | |
| 9820 | VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | |
| 9821 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; |
Michael Chan | e38287b | 2018-10-14 07:02:45 -0400 | [diff] [blame] | 9822 | if (BNXT_CHIP_P4(bp) && bp->hwrm_spec_code >= 0x10501) { |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 9823 | bp->flags |= BNXT_FLAG_UDP_RSS_CAP; |
| 9824 | bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 | |
| 9825 | VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; |
| 9826 | } |
| 9827 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 9828 | bnxt_hwrm_vnic_qcaps(bp); |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 9829 | if (bnxt_rfs_supported(bp)) { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 9830 | dev->hw_features |= NETIF_F_NTUPLE; |
| 9831 | if (bnxt_rfs_capable(bp)) { |
| 9832 | bp->flags |= BNXT_FLAG_RFS; |
| 9833 | dev->features |= NETIF_F_NTUPLE; |
| 9834 | } |
| 9835 | } |
| 9836 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9837 | if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX) |
| 9838 | bp->flags |= BNXT_FLAG_STRIP_VLAN; |
| 9839 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 9840 | rc = bnxt_init_int_mode(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9841 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9842 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9843 | |
Michael Chan | 832aed1 | 2018-03-09 23:46:07 -0500 | [diff] [blame] | 9844 | /* No TC has been set yet and rings may have been trimmed due to |
| 9845 | * limited MSIX, so we re-initialize the TX rings per TC. |
| 9846 | */ |
| 9847 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 9848 | |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 9849 | bnxt_get_wol_settings(bp); |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 9850 | if (bp->flags & BNXT_FLAG_WOL_CAP) |
| 9851 | device_set_wakeup_enable(&pdev->dev, bp->wol); |
| 9852 | else |
| 9853 | device_set_wakeup_capable(&pdev->dev, false); |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 9854 | |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 9855 | bnxt_hwrm_set_cache_line_size(bp, cache_line_size()); |
| 9856 | |
Michael Chan | 74706af | 2018-10-14 07:02:40 -0400 | [diff] [blame] | 9857 | bnxt_hwrm_coal_params_qcaps(bp); |
| 9858 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9859 | if (BNXT_PF(bp)) { |
| 9860 | if (!bnxt_pf_wq) { |
| 9861 | bnxt_pf_wq = |
| 9862 | create_singlethread_workqueue("bnxt_pf_wq"); |
| 9863 | if (!bnxt_pf_wq) { |
| 9864 | dev_err(&pdev->dev, "Unable to create workqueue.\n"); |
| 9865 | goto init_err_pci_clean; |
| 9866 | } |
| 9867 | } |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 9868 | bnxt_init_tc(bp); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9869 | } |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 9870 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 9871 | rc = register_netdev(dev); |
| 9872 | if (rc) |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 9873 | goto init_err_cleanup_tc; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 9874 | |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 9875 | if (BNXT_PF(bp)) |
| 9876 | bnxt_dl_register(bp); |
| 9877 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9878 | netdev_info(dev, "%s found at mem %lx, node addr %pM\n", |
| 9879 | board_info[ent->driver_data].name, |
| 9880 | (long)pci_resource_start(pdev, 0), dev->dev_addr); |
Bjorn Helgaas | af125b7 | 2018-03-30 14:09:54 -0500 | [diff] [blame] | 9881 | pcie_print_link_status(pdev); |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 9882 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9883 | return 0; |
| 9884 | |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 9885 | init_err_cleanup_tc: |
| 9886 | bnxt_shutdown_tc(bp); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 9887 | bnxt_clear_int_mode(bp); |
| 9888 | |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9889 | init_err_pci_clean: |
Venkat Duvvuru | a2bf74f | 2018-10-05 00:26:02 -0400 | [diff] [blame] | 9890 | bnxt_free_hwrm_resources(bp); |
Michael Chan | 98f04cf | 2018-10-14 07:02:43 -0400 | [diff] [blame] | 9891 | bnxt_free_ctx_mem(bp); |
| 9892 | kfree(bp->ctx); |
| 9893 | bp->ctx = NULL; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 9894 | bnxt_cleanup_pci(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9895 | |
| 9896 | init_err_free: |
| 9897 | free_netdev(dev); |
| 9898 | return rc; |
| 9899 | } |
| 9900 | |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 9901 | static void bnxt_shutdown(struct pci_dev *pdev) |
| 9902 | { |
| 9903 | struct net_device *dev = pci_get_drvdata(pdev); |
| 9904 | struct bnxt *bp; |
| 9905 | |
| 9906 | if (!dev) |
| 9907 | return; |
| 9908 | |
| 9909 | rtnl_lock(); |
| 9910 | bp = netdev_priv(dev); |
| 9911 | if (!bp) |
| 9912 | goto shutdown_exit; |
| 9913 | |
| 9914 | if (netif_running(dev)) |
| 9915 | dev_close(dev); |
| 9916 | |
Ray Jui | a7f3f93 | 2017-12-01 03:13:02 -0500 | [diff] [blame] | 9917 | bnxt_ulp_shutdown(bp); |
| 9918 | |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 9919 | if (system_state == SYSTEM_POWER_OFF) { |
| 9920 | bnxt_clear_int_mode(bp); |
| 9921 | pci_wake_from_d3(pdev, bp->wol); |
| 9922 | pci_set_power_state(pdev, PCI_D3hot); |
| 9923 | } |
| 9924 | |
| 9925 | shutdown_exit: |
| 9926 | rtnl_unlock(); |
| 9927 | } |
| 9928 | |
Michael Chan | f65a204 | 2017-04-04 18:14:11 -0400 | [diff] [blame] | 9929 | #ifdef CONFIG_PM_SLEEP |
| 9930 | static int bnxt_suspend(struct device *device) |
| 9931 | { |
| 9932 | struct pci_dev *pdev = to_pci_dev(device); |
| 9933 | struct net_device *dev = pci_get_drvdata(pdev); |
| 9934 | struct bnxt *bp = netdev_priv(dev); |
| 9935 | int rc = 0; |
| 9936 | |
| 9937 | rtnl_lock(); |
| 9938 | if (netif_running(dev)) { |
| 9939 | netif_device_detach(dev); |
| 9940 | rc = bnxt_close(dev); |
| 9941 | } |
| 9942 | bnxt_hwrm_func_drv_unrgtr(bp); |
| 9943 | rtnl_unlock(); |
| 9944 | return rc; |
| 9945 | } |
| 9946 | |
| 9947 | static int bnxt_resume(struct device *device) |
| 9948 | { |
| 9949 | struct pci_dev *pdev = to_pci_dev(device); |
| 9950 | struct net_device *dev = pci_get_drvdata(pdev); |
| 9951 | struct bnxt *bp = netdev_priv(dev); |
| 9952 | int rc = 0; |
| 9953 | |
| 9954 | rtnl_lock(); |
| 9955 | if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) { |
| 9956 | rc = -ENODEV; |
| 9957 | goto resume_exit; |
| 9958 | } |
| 9959 | rc = bnxt_hwrm_func_reset(bp); |
| 9960 | if (rc) { |
| 9961 | rc = -EBUSY; |
| 9962 | goto resume_exit; |
| 9963 | } |
| 9964 | bnxt_get_wol_settings(bp); |
| 9965 | if (netif_running(dev)) { |
| 9966 | rc = bnxt_open(dev); |
| 9967 | if (!rc) |
| 9968 | netif_device_attach(dev); |
| 9969 | } |
| 9970 | |
| 9971 | resume_exit: |
| 9972 | rtnl_unlock(); |
| 9973 | return rc; |
| 9974 | } |
| 9975 | |
| 9976 | static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume); |
| 9977 | #define BNXT_PM_OPS (&bnxt_pm_ops) |
| 9978 | |
| 9979 | #else |
| 9980 | |
| 9981 | #define BNXT_PM_OPS NULL |
| 9982 | |
| 9983 | #endif /* CONFIG_PM_SLEEP */ |
| 9984 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9985 | /** |
| 9986 | * bnxt_io_error_detected - called when PCI error is detected |
| 9987 | * @pdev: Pointer to PCI device |
| 9988 | * @state: The current pci connection state |
| 9989 | * |
| 9990 | * This function is called after a PCI bus error affecting |
| 9991 | * this device has been detected. |
| 9992 | */ |
| 9993 | static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev, |
| 9994 | pci_channel_state_t state) |
| 9995 | { |
| 9996 | struct net_device *netdev = pci_get_drvdata(pdev); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 9997 | struct bnxt *bp = netdev_priv(netdev); |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9998 | |
| 9999 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 10000 | |
| 10001 | rtnl_lock(); |
| 10002 | netif_device_detach(netdev); |
| 10003 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 10004 | bnxt_ulp_stop(bp); |
| 10005 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 10006 | if (state == pci_channel_io_perm_failure) { |
| 10007 | rtnl_unlock(); |
| 10008 | return PCI_ERS_RESULT_DISCONNECT; |
| 10009 | } |
| 10010 | |
| 10011 | if (netif_running(netdev)) |
| 10012 | bnxt_close(netdev); |
| 10013 | |
| 10014 | pci_disable_device(pdev); |
| 10015 | rtnl_unlock(); |
| 10016 | |
| 10017 | /* Request a slot slot reset. */ |
| 10018 | return PCI_ERS_RESULT_NEED_RESET; |
| 10019 | } |
| 10020 | |
| 10021 | /** |
| 10022 | * bnxt_io_slot_reset - called after the pci bus has been reset. |
| 10023 | * @pdev: Pointer to PCI device |
| 10024 | * |
| 10025 | * Restart the card from scratch, as if from a cold-boot. |
| 10026 | * At this point, the card has exprienced a hard reset, |
| 10027 | * followed by fixups by BIOS, and has its config space |
| 10028 | * set up identically to what it was at cold boot. |
| 10029 | */ |
| 10030 | static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev) |
| 10031 | { |
| 10032 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 10033 | struct bnxt *bp = netdev_priv(netdev); |
| 10034 | int err = 0; |
| 10035 | pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT; |
| 10036 | |
| 10037 | netdev_info(bp->dev, "PCI Slot Reset\n"); |
| 10038 | |
| 10039 | rtnl_lock(); |
| 10040 | |
| 10041 | if (pci_enable_device(pdev)) { |
| 10042 | dev_err(&pdev->dev, |
| 10043 | "Cannot re-enable PCI device after reset.\n"); |
| 10044 | } else { |
| 10045 | pci_set_master(pdev); |
| 10046 | |
Michael Chan | aa8ed02 | 2016-12-07 00:26:17 -0500 | [diff] [blame] | 10047 | err = bnxt_hwrm_func_reset(bp); |
| 10048 | if (!err && netif_running(netdev)) |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 10049 | err = bnxt_open(netdev); |
| 10050 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 10051 | if (!err) { |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 10052 | result = PCI_ERS_RESULT_RECOVERED; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 10053 | bnxt_ulp_start(bp); |
| 10054 | } |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 10055 | } |
| 10056 | |
| 10057 | if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev)) |
| 10058 | dev_close(netdev); |
| 10059 | |
| 10060 | rtnl_unlock(); |
| 10061 | |
| 10062 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 10063 | if (err) { |
| 10064 | dev_err(&pdev->dev, |
| 10065 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 10066 | err); /* non-fatal, continue */ |
| 10067 | } |
| 10068 | |
| 10069 | return PCI_ERS_RESULT_RECOVERED; |
| 10070 | } |
| 10071 | |
| 10072 | /** |
| 10073 | * bnxt_io_resume - called when traffic can start flowing again. |
| 10074 | * @pdev: Pointer to PCI device |
| 10075 | * |
| 10076 | * This callback is called when the error recovery driver tells |
| 10077 | * us that its OK to resume normal operation. |
| 10078 | */ |
| 10079 | static void bnxt_io_resume(struct pci_dev *pdev) |
| 10080 | { |
| 10081 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 10082 | |
| 10083 | rtnl_lock(); |
| 10084 | |
| 10085 | netif_device_attach(netdev); |
| 10086 | |
| 10087 | rtnl_unlock(); |
| 10088 | } |
| 10089 | |
| 10090 | static const struct pci_error_handlers bnxt_err_handler = { |
| 10091 | .error_detected = bnxt_io_error_detected, |
| 10092 | .slot_reset = bnxt_io_slot_reset, |
| 10093 | .resume = bnxt_io_resume |
| 10094 | }; |
| 10095 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 10096 | static struct pci_driver bnxt_pci_driver = { |
| 10097 | .name = DRV_MODULE_NAME, |
| 10098 | .id_table = bnxt_pci_tbl, |
| 10099 | .probe = bnxt_init_one, |
| 10100 | .remove = bnxt_remove_one, |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 10101 | .shutdown = bnxt_shutdown, |
Michael Chan | f65a204 | 2017-04-04 18:14:11 -0400 | [diff] [blame] | 10102 | .driver.pm = BNXT_PM_OPS, |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 10103 | .err_handler = &bnxt_err_handler, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 10104 | #if defined(CONFIG_BNXT_SRIOV) |
| 10105 | .sriov_configure = bnxt_sriov_configure, |
| 10106 | #endif |
| 10107 | }; |
| 10108 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 10109 | static int __init bnxt_init(void) |
| 10110 | { |
Andy Gospodarek | cabfb09 | 2018-04-26 17:44:40 -0400 | [diff] [blame] | 10111 | bnxt_debug_init(); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 10112 | return pci_register_driver(&bnxt_pci_driver); |
| 10113 | } |
| 10114 | |
| 10115 | static void __exit bnxt_exit(void) |
| 10116 | { |
| 10117 | pci_unregister_driver(&bnxt_pci_driver); |
| 10118 | if (bnxt_pf_wq) |
| 10119 | destroy_workqueue(bnxt_pf_wq); |
Andy Gospodarek | cabfb09 | 2018-04-26 17:44:40 -0400 | [diff] [blame] | 10120 | bnxt_debug_exit(); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 10121 | } |
| 10122 | |
| 10123 | module_init(bnxt_init); |
| 10124 | module_exit(bnxt_exit); |