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> |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 54 | |
| 55 | #include "bnxt_hsi.h" |
| 56 | #include "bnxt.h" |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 57 | #include "bnxt_ulp.h" |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 58 | #include "bnxt_sriov.h" |
| 59 | #include "bnxt_ethtool.h" |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 60 | #include "bnxt_dcb.h" |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 61 | #include "bnxt_xdp.h" |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 62 | #include "bnxt_vfr.h" |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 63 | #include "bnxt_tc.h" |
Steve Lin | 3c467bf | 2017-10-19 10:45:56 -0400 | [diff] [blame] | 64 | #include "bnxt_devlink.h" |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 65 | |
| 66 | #define BNXT_TX_TIMEOUT (5 * HZ) |
| 67 | |
| 68 | static const char version[] = |
| 69 | "Broadcom NetXtreme-C/E driver " DRV_MODULE_NAME " v" DRV_MODULE_VERSION "\n"; |
| 70 | |
| 71 | MODULE_LICENSE("GPL"); |
| 72 | MODULE_DESCRIPTION("Broadcom BCM573xx network driver"); |
| 73 | MODULE_VERSION(DRV_MODULE_VERSION); |
| 74 | |
| 75 | #define BNXT_RX_OFFSET (NET_SKB_PAD + NET_IP_ALIGN) |
| 76 | #define BNXT_RX_DMA_OFFSET NET_SKB_PAD |
| 77 | #define BNXT_RX_COPY_THRESH 256 |
| 78 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 79 | #define BNXT_TX_PUSH_THRESH 164 |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 80 | |
| 81 | enum board_idx { |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 82 | BCM57301, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 83 | BCM57302, |
| 84 | BCM57304, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 85 | BCM57417_NPAR, |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 86 | BCM58700, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 87 | BCM57311, |
| 88 | BCM57312, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 89 | BCM57402, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 90 | BCM57404, |
| 91 | BCM57406, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 92 | BCM57402_NPAR, |
| 93 | BCM57407, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 94 | BCM57412, |
| 95 | BCM57414, |
| 96 | BCM57416, |
| 97 | BCM57417, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 98 | BCM57412_NPAR, |
Michael Chan | 5049e33 | 2016-05-15 03:04:50 -0400 | [diff] [blame] | 99 | BCM57314, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 100 | BCM57417_SFP, |
| 101 | BCM57416_SFP, |
| 102 | BCM57404_NPAR, |
| 103 | BCM57406_NPAR, |
| 104 | BCM57407_SFP, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 105 | BCM57407_NPAR, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 106 | BCM57414_NPAR, |
| 107 | BCM57416_NPAR, |
Deepak Khungar | 32b4079 | 2017-02-12 19:18:18 -0500 | [diff] [blame] | 108 | BCM57452, |
| 109 | BCM57454, |
Vasundhara Volam | 92abef3 | 2018-01-17 03:21:13 -0500 | [diff] [blame] | 110 | BCM5745x_NPAR, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 111 | BCM58802, |
Ray Jui | 8ed693b | 2017-10-26 11:51:20 -0400 | [diff] [blame] | 112 | BCM58804, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 113 | BCM58808, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 114 | NETXTREME_E_VF, |
| 115 | NETXTREME_C_VF, |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 116 | NETXTREME_S_VF, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 117 | }; |
| 118 | |
| 119 | /* indexed by enum above */ |
| 120 | static const struct { |
| 121 | char *name; |
| 122 | } board_info[] = { |
Scott Branden | 27573a7 | 2017-08-28 13:40:29 -0400 | [diff] [blame] | 123 | [BCM57301] = { "Broadcom BCM57301 NetXtreme-C 10Gb Ethernet" }, |
| 124 | [BCM57302] = { "Broadcom BCM57302 NetXtreme-C 10Gb/25Gb Ethernet" }, |
| 125 | [BCM57304] = { "Broadcom BCM57304 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 126 | [BCM57417_NPAR] = { "Broadcom BCM57417 NetXtreme-E Ethernet Partition" }, |
| 127 | [BCM58700] = { "Broadcom BCM58700 Nitro 1Gb/2.5Gb/10Gb Ethernet" }, |
| 128 | [BCM57311] = { "Broadcom BCM57311 NetXtreme-C 10Gb Ethernet" }, |
| 129 | [BCM57312] = { "Broadcom BCM57312 NetXtreme-C 10Gb/25Gb Ethernet" }, |
| 130 | [BCM57402] = { "Broadcom BCM57402 NetXtreme-E 10Gb Ethernet" }, |
| 131 | [BCM57404] = { "Broadcom BCM57404 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 132 | [BCM57406] = { "Broadcom BCM57406 NetXtreme-E 10GBase-T Ethernet" }, |
| 133 | [BCM57402_NPAR] = { "Broadcom BCM57402 NetXtreme-E Ethernet Partition" }, |
| 134 | [BCM57407] = { "Broadcom BCM57407 NetXtreme-E 10GBase-T Ethernet" }, |
| 135 | [BCM57412] = { "Broadcom BCM57412 NetXtreme-E 10Gb Ethernet" }, |
| 136 | [BCM57414] = { "Broadcom BCM57414 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 137 | [BCM57416] = { "Broadcom BCM57416 NetXtreme-E 10GBase-T Ethernet" }, |
| 138 | [BCM57417] = { "Broadcom BCM57417 NetXtreme-E 10GBase-T Ethernet" }, |
| 139 | [BCM57412_NPAR] = { "Broadcom BCM57412 NetXtreme-E Ethernet Partition" }, |
| 140 | [BCM57314] = { "Broadcom BCM57314 NetXtreme-C 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 141 | [BCM57417_SFP] = { "Broadcom BCM57417 NetXtreme-E 10Gb/25Gb Ethernet" }, |
| 142 | [BCM57416_SFP] = { "Broadcom BCM57416 NetXtreme-E 10Gb Ethernet" }, |
| 143 | [BCM57404_NPAR] = { "Broadcom BCM57404 NetXtreme-E Ethernet Partition" }, |
| 144 | [BCM57406_NPAR] = { "Broadcom BCM57406 NetXtreme-E Ethernet Partition" }, |
| 145 | [BCM57407_SFP] = { "Broadcom BCM57407 NetXtreme-E 25Gb Ethernet" }, |
| 146 | [BCM57407_NPAR] = { "Broadcom BCM57407 NetXtreme-E Ethernet Partition" }, |
| 147 | [BCM57414_NPAR] = { "Broadcom BCM57414 NetXtreme-E Ethernet Partition" }, |
| 148 | [BCM57416_NPAR] = { "Broadcom BCM57416 NetXtreme-E Ethernet Partition" }, |
| 149 | [BCM57452] = { "Broadcom BCM57452 NetXtreme-E 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
| 150 | [BCM57454] = { "Broadcom BCM57454 NetXtreme-E 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" }, |
Vasundhara Volam | 92abef3 | 2018-01-17 03:21:13 -0500 | [diff] [blame] | 151 | [BCM5745x_NPAR] = { "Broadcom BCM5745x NetXtreme-E Ethernet Partition" }, |
Scott Branden | 27573a7 | 2017-08-28 13:40:29 -0400 | [diff] [blame] | 152 | [BCM58802] = { "Broadcom BCM58802 NetXtreme-S 10Gb/25Gb/40Gb/50Gb Ethernet" }, |
Ray Jui | 8ed693b | 2017-10-26 11:51:20 -0400 | [diff] [blame] | 153 | [BCM58804] = { "Broadcom BCM58804 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" }, |
Scott Branden | 27573a7 | 2017-08-28 13:40:29 -0400 | [diff] [blame] | 154 | [BCM58808] = { "Broadcom BCM58808 NetXtreme-S 10Gb/25Gb/40Gb/50Gb/100Gb Ethernet" }, |
| 155 | [NETXTREME_E_VF] = { "Broadcom NetXtreme-E Ethernet Virtual Function" }, |
| 156 | [NETXTREME_C_VF] = { "Broadcom NetXtreme-C Ethernet Virtual Function" }, |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 157 | [NETXTREME_S_VF] = { "Broadcom NetXtreme-S Ethernet Virtual Function" }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | static const struct pci_device_id bnxt_pci_tbl[] = { |
Vasundhara Volam | 92abef3 | 2018-01-17 03:21:13 -0500 | [diff] [blame] | 161 | { PCI_VDEVICE(BROADCOM, 0x1604), .driver_data = BCM5745x_NPAR }, |
| 162 | { PCI_VDEVICE(BROADCOM, 0x1605), .driver_data = BCM5745x_NPAR }, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 163 | { PCI_VDEVICE(BROADCOM, 0x1614), .driver_data = BCM57454 }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 164 | { PCI_VDEVICE(BROADCOM, 0x16c0), .driver_data = BCM57417_NPAR }, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 165 | { PCI_VDEVICE(BROADCOM, 0x16c8), .driver_data = BCM57301 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 166 | { PCI_VDEVICE(BROADCOM, 0x16c9), .driver_data = BCM57302 }, |
| 167 | { PCI_VDEVICE(BROADCOM, 0x16ca), .driver_data = BCM57304 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 168 | { PCI_VDEVICE(BROADCOM, 0x16cc), .driver_data = BCM57417_NPAR }, |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 169 | { PCI_VDEVICE(BROADCOM, 0x16cd), .driver_data = BCM58700 }, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 170 | { PCI_VDEVICE(BROADCOM, 0x16ce), .driver_data = BCM57311 }, |
| 171 | { PCI_VDEVICE(BROADCOM, 0x16cf), .driver_data = BCM57312 }, |
David Christensen | fbc9a52 | 2015-12-27 18:19:29 -0500 | [diff] [blame] | 172 | { PCI_VDEVICE(BROADCOM, 0x16d0), .driver_data = BCM57402 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 173 | { PCI_VDEVICE(BROADCOM, 0x16d1), .driver_data = BCM57404 }, |
| 174 | { PCI_VDEVICE(BROADCOM, 0x16d2), .driver_data = BCM57406 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 175 | { PCI_VDEVICE(BROADCOM, 0x16d4), .driver_data = BCM57402_NPAR }, |
| 176 | { PCI_VDEVICE(BROADCOM, 0x16d5), .driver_data = BCM57407 }, |
Michael Chan | b24eb6a | 2016-06-13 02:25:36 -0400 | [diff] [blame] | 177 | { PCI_VDEVICE(BROADCOM, 0x16d6), .driver_data = BCM57412 }, |
| 178 | { PCI_VDEVICE(BROADCOM, 0x16d7), .driver_data = BCM57414 }, |
| 179 | { PCI_VDEVICE(BROADCOM, 0x16d8), .driver_data = BCM57416 }, |
| 180 | { PCI_VDEVICE(BROADCOM, 0x16d9), .driver_data = BCM57417 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 181 | { PCI_VDEVICE(BROADCOM, 0x16de), .driver_data = BCM57412_NPAR }, |
Michael Chan | 5049e33 | 2016-05-15 03:04:50 -0400 | [diff] [blame] | 182 | { PCI_VDEVICE(BROADCOM, 0x16df), .driver_data = BCM57314 }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 183 | { PCI_VDEVICE(BROADCOM, 0x16e2), .driver_data = BCM57417_SFP }, |
| 184 | { PCI_VDEVICE(BROADCOM, 0x16e3), .driver_data = BCM57416_SFP }, |
| 185 | { PCI_VDEVICE(BROADCOM, 0x16e7), .driver_data = BCM57404_NPAR }, |
| 186 | { PCI_VDEVICE(BROADCOM, 0x16e8), .driver_data = BCM57406_NPAR }, |
| 187 | { PCI_VDEVICE(BROADCOM, 0x16e9), .driver_data = BCM57407_SFP }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 188 | { PCI_VDEVICE(BROADCOM, 0x16ea), .driver_data = BCM57407_NPAR }, |
| 189 | { PCI_VDEVICE(BROADCOM, 0x16eb), .driver_data = BCM57412_NPAR }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 190 | { PCI_VDEVICE(BROADCOM, 0x16ec), .driver_data = BCM57414_NPAR }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 191 | { PCI_VDEVICE(BROADCOM, 0x16ed), .driver_data = BCM57414_NPAR }, |
Michael Chan | 1f68168 | 2016-07-25 12:33:37 -0400 | [diff] [blame] | 192 | { PCI_VDEVICE(BROADCOM, 0x16ee), .driver_data = BCM57416_NPAR }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 193 | { PCI_VDEVICE(BROADCOM, 0x16ef), .driver_data = BCM57416_NPAR }, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 194 | { PCI_VDEVICE(BROADCOM, 0x16f0), .driver_data = BCM58808 }, |
Deepak Khungar | 32b4079 | 2017-02-12 19:18:18 -0500 | [diff] [blame] | 195 | { PCI_VDEVICE(BROADCOM, 0x16f1), .driver_data = BCM57452 }, |
Ray Jui | 4a58139 | 2017-08-28 13:40:28 -0400 | [diff] [blame] | 196 | { PCI_VDEVICE(BROADCOM, 0xd802), .driver_data = BCM58802 }, |
Ray Jui | 8ed693b | 2017-10-26 11:51:20 -0400 | [diff] [blame] | 197 | { PCI_VDEVICE(BROADCOM, 0xd804), .driver_data = BCM58804 }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 198 | #ifdef CONFIG_BNXT_SRIOV |
Deepak Khungar | c7ef35e | 2017-05-29 19:06:05 -0400 | [diff] [blame] | 199 | { PCI_VDEVICE(BROADCOM, 0x1606), .driver_data = NETXTREME_E_VF }, |
| 200 | { PCI_VDEVICE(BROADCOM, 0x1609), .driver_data = NETXTREME_E_VF }, |
Michael Chan | adbc830 | 2016-09-19 03:58:01 -0400 | [diff] [blame] | 201 | { PCI_VDEVICE(BROADCOM, 0x16c1), .driver_data = NETXTREME_E_VF }, |
| 202 | { PCI_VDEVICE(BROADCOM, 0x16cb), .driver_data = NETXTREME_C_VF }, |
| 203 | { PCI_VDEVICE(BROADCOM, 0x16d3), .driver_data = NETXTREME_E_VF }, |
| 204 | { PCI_VDEVICE(BROADCOM, 0x16dc), .driver_data = NETXTREME_E_VF }, |
| 205 | { PCI_VDEVICE(BROADCOM, 0x16e1), .driver_data = NETXTREME_C_VF }, |
| 206 | { PCI_VDEVICE(BROADCOM, 0x16e5), .driver_data = NETXTREME_C_VF }, |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 207 | { PCI_VDEVICE(BROADCOM, 0xd800), .driver_data = NETXTREME_S_VF }, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 208 | #endif |
| 209 | { 0 } |
| 210 | }; |
| 211 | |
| 212 | MODULE_DEVICE_TABLE(pci, bnxt_pci_tbl); |
| 213 | |
| 214 | static const u16 bnxt_vf_req_snif[] = { |
| 215 | HWRM_FUNC_CFG, |
Vasundhara Volam | 91cdda4 | 2018-01-17 03:21:14 -0500 | [diff] [blame] | 216 | HWRM_FUNC_VF_CFG, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 217 | HWRM_PORT_PHY_QCFG, |
| 218 | HWRM_CFA_L2_FILTER_ALLOC, |
| 219 | }; |
| 220 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 221 | static const u16 bnxt_async_events_arr[] = { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 222 | ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE, |
| 223 | ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD, |
| 224 | ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED, |
| 225 | ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE, |
| 226 | ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE, |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 227 | }; |
| 228 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 229 | static struct workqueue_struct *bnxt_pf_wq; |
| 230 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 231 | static bool bnxt_vf_pciid(enum board_idx idx) |
| 232 | { |
Rob Miller | 618784e | 2017-10-26 11:51:21 -0400 | [diff] [blame] | 233 | return (idx == NETXTREME_C_VF || idx == NETXTREME_E_VF || |
| 234 | idx == NETXTREME_S_VF); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | #define DB_CP_REARM_FLAGS (DB_KEY_CP | DB_IDX_VALID) |
| 238 | #define DB_CP_FLAGS (DB_KEY_CP | DB_IDX_VALID | DB_IRQ_DIS) |
| 239 | #define DB_CP_IRQ_DIS_FLAGS (DB_KEY_CP | DB_IRQ_DIS) |
| 240 | |
| 241 | #define BNXT_CP_DB_REARM(db, raw_cons) \ |
| 242 | writel(DB_CP_REARM_FLAGS | RING_CMP(raw_cons), db) |
| 243 | |
| 244 | #define BNXT_CP_DB(db, raw_cons) \ |
| 245 | writel(DB_CP_FLAGS | RING_CMP(raw_cons), db) |
| 246 | |
| 247 | #define BNXT_CP_DB_IRQ_DIS(db) \ |
| 248 | writel(DB_CP_IRQ_DIS_FLAGS, db) |
| 249 | |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 250 | const u16 bnxt_lhint_arr[] = { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 251 | TX_BD_FLAGS_LHINT_512_AND_SMALLER, |
| 252 | TX_BD_FLAGS_LHINT_512_TO_1023, |
| 253 | TX_BD_FLAGS_LHINT_1024_TO_2047, |
| 254 | TX_BD_FLAGS_LHINT_1024_TO_2047, |
| 255 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 256 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 257 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 258 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 259 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 260 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 261 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 262 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 263 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 264 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 265 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 266 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 267 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 268 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 269 | TX_BD_FLAGS_LHINT_2048_AND_LARGER, |
| 270 | }; |
| 271 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 272 | static u16 bnxt_xmit_get_cfa_action(struct sk_buff *skb) |
| 273 | { |
| 274 | struct metadata_dst *md_dst = skb_metadata_dst(skb); |
| 275 | |
| 276 | if (!md_dst || md_dst->type != METADATA_HW_PORT_MUX) |
| 277 | return 0; |
| 278 | |
| 279 | return md_dst->u.port_info.port_id; |
| 280 | } |
| 281 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 282 | static netdev_tx_t bnxt_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 283 | { |
| 284 | struct bnxt *bp = netdev_priv(dev); |
| 285 | struct tx_bd *txbd; |
| 286 | struct tx_bd_ext *txbd1; |
| 287 | struct netdev_queue *txq; |
| 288 | int i; |
| 289 | dma_addr_t mapping; |
| 290 | unsigned int length, pad = 0; |
| 291 | u32 len, free_size, vlan_tag_flags, cfa_action, flags; |
| 292 | u16 prod, last_frag; |
| 293 | struct pci_dev *pdev = bp->pdev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 294 | struct bnxt_tx_ring_info *txr; |
| 295 | struct bnxt_sw_tx_bd *tx_buf; |
| 296 | |
| 297 | i = skb_get_queue_mapping(skb); |
| 298 | if (unlikely(i >= bp->tx_nr_rings)) { |
| 299 | dev_kfree_skb_any(skb); |
| 300 | return NETDEV_TX_OK; |
| 301 | } |
| 302 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 303 | txq = netdev_get_tx_queue(dev, i); |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 304 | txr = &bp->tx_ring[bp->tx_ring_map[i]]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 305 | prod = txr->tx_prod; |
| 306 | |
| 307 | free_size = bnxt_tx_avail(bp, txr); |
| 308 | if (unlikely(free_size < skb_shinfo(skb)->nr_frags + 2)) { |
| 309 | netif_tx_stop_queue(txq); |
| 310 | return NETDEV_TX_BUSY; |
| 311 | } |
| 312 | |
| 313 | length = skb->len; |
| 314 | len = skb_headlen(skb); |
| 315 | last_frag = skb_shinfo(skb)->nr_frags; |
| 316 | |
| 317 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 318 | |
| 319 | txbd->tx_bd_opaque = prod; |
| 320 | |
| 321 | tx_buf = &txr->tx_buf_ring[prod]; |
| 322 | tx_buf->skb = skb; |
| 323 | tx_buf->nr_frags = last_frag; |
| 324 | |
| 325 | vlan_tag_flags = 0; |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 326 | cfa_action = bnxt_xmit_get_cfa_action(skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 327 | if (skb_vlan_tag_present(skb)) { |
| 328 | vlan_tag_flags = TX_BD_CFA_META_KEY_VLAN | |
| 329 | skb_vlan_tag_get(skb); |
| 330 | /* Currently supports 8021Q, 8021AD vlan offloads |
| 331 | * QINQ1, QINQ2, QINQ3 vlan headers are deprecated |
| 332 | */ |
| 333 | if (skb->vlan_proto == htons(ETH_P_8021Q)) |
| 334 | vlan_tag_flags |= 1 << TX_BD_CFA_META_TPID_SHIFT; |
| 335 | } |
| 336 | |
| 337 | if (free_size == bp->tx_ring_size && length <= bp->tx_push_thresh) { |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 338 | struct tx_push_buffer *tx_push_buf = txr->tx_push; |
| 339 | struct tx_push_bd *tx_push = &tx_push_buf->push_bd; |
| 340 | struct tx_bd_ext *tx_push1 = &tx_push->txbd2; |
| 341 | void *pdata = tx_push_buf->data; |
| 342 | u64 *end; |
| 343 | int j, push_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 344 | |
| 345 | /* Set COAL_NOW to be ready quickly for the next push */ |
| 346 | tx_push->tx_bd_len_flags_type = |
| 347 | cpu_to_le32((length << TX_BD_LEN_SHIFT) | |
| 348 | TX_BD_TYPE_LONG_TX_BD | |
| 349 | TX_BD_FLAGS_LHINT_512_AND_SMALLER | |
| 350 | TX_BD_FLAGS_COAL_NOW | |
| 351 | TX_BD_FLAGS_PACKET_END | |
| 352 | (2 << TX_BD_FLAGS_BD_CNT_SHIFT)); |
| 353 | |
| 354 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 355 | tx_push1->tx_bd_hsize_lflags = |
| 356 | cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM); |
| 357 | else |
| 358 | tx_push1->tx_bd_hsize_lflags = 0; |
| 359 | |
| 360 | tx_push1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags); |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 361 | tx_push1->tx_bd_cfa_action = |
| 362 | cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 363 | |
Michael Chan | fbb0fa8 | 2016-02-22 02:10:26 -0500 | [diff] [blame] | 364 | end = pdata + length; |
| 365 | end = PTR_ALIGN(end, 8) - 1; |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 366 | *end = 0; |
| 367 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 368 | skb_copy_from_linear_data(skb, pdata, len); |
| 369 | pdata += len; |
| 370 | for (j = 0; j < last_frag; j++) { |
| 371 | skb_frag_t *frag = &skb_shinfo(skb)->frags[j]; |
| 372 | void *fptr; |
| 373 | |
| 374 | fptr = skb_frag_address_safe(frag); |
| 375 | if (!fptr) |
| 376 | goto normal_tx; |
| 377 | |
| 378 | memcpy(pdata, fptr, skb_frag_size(frag)); |
| 379 | pdata += skb_frag_size(frag); |
| 380 | } |
| 381 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 382 | txbd->tx_bd_len_flags_type = tx_push->tx_bd_len_flags_type; |
| 383 | txbd->tx_bd_haddr = txr->data_mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 384 | prod = NEXT_TX(prod); |
| 385 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 386 | memcpy(txbd, tx_push1, sizeof(*txbd)); |
| 387 | prod = NEXT_TX(prod); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 388 | tx_push->doorbell = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 389 | cpu_to_le32(DB_KEY_TX_PUSH | DB_LONG_TX_PUSH | prod); |
| 390 | txr->tx_prod = prod; |
| 391 | |
Michael Chan | b9a8460 | 2016-06-06 02:37:14 -0400 | [diff] [blame] | 392 | tx_buf->is_push = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 393 | netdev_tx_sent_queue(txq, skb->len); |
Michael Chan | b9a8460 | 2016-06-06 02:37:14 -0400 | [diff] [blame] | 394 | wmb(); /* Sync is_push and byte queue before pushing data */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 395 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 396 | push_len = (length + sizeof(*tx_push) + 7) / 8; |
| 397 | if (push_len > 16) { |
| 398 | __iowrite64_copy(txr->tx_doorbell, tx_push_buf, 16); |
Michael Chan | 9d13744 | 2016-09-05 01:57:35 -0400 | [diff] [blame] | 399 | __iowrite32_copy(txr->tx_doorbell + 4, tx_push_buf + 1, |
| 400 | (push_len - 16) << 1); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 401 | } else { |
| 402 | __iowrite64_copy(txr->tx_doorbell, tx_push_buf, |
| 403 | push_len); |
| 404 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 405 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 406 | goto tx_done; |
| 407 | } |
| 408 | |
| 409 | normal_tx: |
| 410 | if (length < BNXT_MIN_PKT_SIZE) { |
| 411 | pad = BNXT_MIN_PKT_SIZE - length; |
| 412 | if (skb_pad(skb, pad)) { |
| 413 | /* SKB already freed. */ |
| 414 | tx_buf->skb = NULL; |
| 415 | return NETDEV_TX_OK; |
| 416 | } |
| 417 | length = BNXT_MIN_PKT_SIZE; |
| 418 | } |
| 419 | |
| 420 | mapping = dma_map_single(&pdev->dev, skb->data, len, DMA_TO_DEVICE); |
| 421 | |
| 422 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) { |
| 423 | dev_kfree_skb_any(skb); |
| 424 | tx_buf->skb = NULL; |
| 425 | return NETDEV_TX_OK; |
| 426 | } |
| 427 | |
| 428 | dma_unmap_addr_set(tx_buf, mapping, mapping); |
| 429 | flags = (len << TX_BD_LEN_SHIFT) | TX_BD_TYPE_LONG_TX_BD | |
| 430 | ((last_frag + 2) << TX_BD_FLAGS_BD_CNT_SHIFT); |
| 431 | |
| 432 | txbd->tx_bd_haddr = cpu_to_le64(mapping); |
| 433 | |
| 434 | prod = NEXT_TX(prod); |
| 435 | txbd1 = (struct tx_bd_ext *) |
| 436 | &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 437 | |
| 438 | txbd1->tx_bd_hsize_lflags = 0; |
| 439 | if (skb_is_gso(skb)) { |
| 440 | u32 hdr_len; |
| 441 | |
| 442 | if (skb->encapsulation) |
| 443 | hdr_len = skb_inner_network_offset(skb) + |
| 444 | skb_inner_network_header_len(skb) + |
| 445 | inner_tcp_hdrlen(skb); |
| 446 | else |
| 447 | hdr_len = skb_transport_offset(skb) + |
| 448 | tcp_hdrlen(skb); |
| 449 | |
| 450 | txbd1->tx_bd_hsize_lflags = cpu_to_le32(TX_BD_FLAGS_LSO | |
| 451 | TX_BD_FLAGS_T_IPID | |
| 452 | (hdr_len << (TX_BD_HSIZE_SHIFT - 1))); |
| 453 | length = skb_shinfo(skb)->gso_size; |
| 454 | txbd1->tx_bd_mss = cpu_to_le32(length); |
| 455 | length += hdr_len; |
| 456 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 457 | txbd1->tx_bd_hsize_lflags = |
| 458 | cpu_to_le32(TX_BD_FLAGS_TCP_UDP_CHKSUM); |
| 459 | txbd1->tx_bd_mss = 0; |
| 460 | } |
| 461 | |
| 462 | length >>= 9; |
| 463 | flags |= bnxt_lhint_arr[length]; |
| 464 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); |
| 465 | |
| 466 | txbd1->tx_bd_cfa_meta = cpu_to_le32(vlan_tag_flags); |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 467 | txbd1->tx_bd_cfa_action = |
| 468 | cpu_to_le32(cfa_action << TX_BD_CFA_ACTION_SHIFT); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 469 | for (i = 0; i < last_frag; i++) { |
| 470 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 471 | |
| 472 | prod = NEXT_TX(prod); |
| 473 | txbd = &txr->tx_desc_ring[TX_RING(prod)][TX_IDX(prod)]; |
| 474 | |
| 475 | len = skb_frag_size(frag); |
| 476 | mapping = skb_frag_dma_map(&pdev->dev, frag, 0, len, |
| 477 | DMA_TO_DEVICE); |
| 478 | |
| 479 | if (unlikely(dma_mapping_error(&pdev->dev, mapping))) |
| 480 | goto tx_dma_error; |
| 481 | |
| 482 | tx_buf = &txr->tx_buf_ring[prod]; |
| 483 | dma_unmap_addr_set(tx_buf, mapping, mapping); |
| 484 | |
| 485 | txbd->tx_bd_haddr = cpu_to_le64(mapping); |
| 486 | |
| 487 | flags = len << TX_BD_LEN_SHIFT; |
| 488 | txbd->tx_bd_len_flags_type = cpu_to_le32(flags); |
| 489 | } |
| 490 | |
| 491 | flags &= ~TX_BD_LEN; |
| 492 | txbd->tx_bd_len_flags_type = |
| 493 | cpu_to_le32(((len + pad) << TX_BD_LEN_SHIFT) | flags | |
| 494 | TX_BD_FLAGS_PACKET_END); |
| 495 | |
| 496 | netdev_tx_sent_queue(txq, skb->len); |
| 497 | |
| 498 | /* Sync BD data before updating doorbell */ |
| 499 | wmb(); |
| 500 | |
| 501 | prod = NEXT_TX(prod); |
| 502 | txr->tx_prod = prod; |
| 503 | |
Michael Chan | ffe4064 | 2017-05-30 20:03:00 -0400 | [diff] [blame] | 504 | if (!skb->xmit_more || netif_xmit_stopped(txq)) |
Michael Chan | 4d172f2 | 2017-05-29 19:06:09 -0400 | [diff] [blame] | 505 | bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 506 | |
| 507 | tx_done: |
| 508 | |
| 509 | mmiowb(); |
| 510 | |
| 511 | if (unlikely(bnxt_tx_avail(bp, txr) <= MAX_SKB_FRAGS + 1)) { |
Michael Chan | 4d172f2 | 2017-05-29 19:06:09 -0400 | [diff] [blame] | 512 | if (skb->xmit_more && !tx_buf->is_push) |
| 513 | bnxt_db_write(bp, txr->tx_doorbell, DB_KEY_TX | prod); |
| 514 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 515 | netif_tx_stop_queue(txq); |
| 516 | |
| 517 | /* netif_tx_stop_queue() must be done before checking |
| 518 | * tx index in bnxt_tx_avail() below, because in |
| 519 | * bnxt_tx_int(), we update tx index before checking for |
| 520 | * netif_tx_queue_stopped(). |
| 521 | */ |
| 522 | smp_mb(); |
| 523 | if (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh) |
| 524 | netif_tx_wake_queue(txq); |
| 525 | } |
| 526 | return NETDEV_TX_OK; |
| 527 | |
| 528 | tx_dma_error: |
| 529 | last_frag = i; |
| 530 | |
| 531 | /* start back at beginning and unmap skb */ |
| 532 | prod = txr->tx_prod; |
| 533 | tx_buf = &txr->tx_buf_ring[prod]; |
| 534 | tx_buf->skb = NULL; |
| 535 | dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 536 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 537 | prod = NEXT_TX(prod); |
| 538 | |
| 539 | /* unmap remaining mapped pages */ |
| 540 | for (i = 0; i < last_frag; i++) { |
| 541 | prod = NEXT_TX(prod); |
| 542 | tx_buf = &txr->tx_buf_ring[prod]; |
| 543 | dma_unmap_page(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 544 | skb_frag_size(&skb_shinfo(skb)->frags[i]), |
| 545 | PCI_DMA_TODEVICE); |
| 546 | } |
| 547 | |
| 548 | dev_kfree_skb_any(skb); |
| 549 | return NETDEV_TX_OK; |
| 550 | } |
| 551 | |
| 552 | static void bnxt_tx_int(struct bnxt *bp, struct bnxt_napi *bnapi, int nr_pkts) |
| 553 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 554 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 555 | 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] | 556 | u16 cons = txr->tx_cons; |
| 557 | struct pci_dev *pdev = bp->pdev; |
| 558 | int i; |
| 559 | unsigned int tx_bytes = 0; |
| 560 | |
| 561 | for (i = 0; i < nr_pkts; i++) { |
| 562 | struct bnxt_sw_tx_bd *tx_buf; |
| 563 | struct sk_buff *skb; |
| 564 | int j, last; |
| 565 | |
| 566 | tx_buf = &txr->tx_buf_ring[cons]; |
| 567 | cons = NEXT_TX(cons); |
| 568 | skb = tx_buf->skb; |
| 569 | tx_buf->skb = NULL; |
| 570 | |
| 571 | if (tx_buf->is_push) { |
| 572 | tx_buf->is_push = 0; |
| 573 | goto next_tx_int; |
| 574 | } |
| 575 | |
| 576 | dma_unmap_single(&pdev->dev, dma_unmap_addr(tx_buf, mapping), |
| 577 | skb_headlen(skb), PCI_DMA_TODEVICE); |
| 578 | last = tx_buf->nr_frags; |
| 579 | |
| 580 | for (j = 0; j < last; j++) { |
| 581 | cons = NEXT_TX(cons); |
| 582 | tx_buf = &txr->tx_buf_ring[cons]; |
| 583 | dma_unmap_page( |
| 584 | &pdev->dev, |
| 585 | dma_unmap_addr(tx_buf, mapping), |
| 586 | skb_frag_size(&skb_shinfo(skb)->frags[j]), |
| 587 | PCI_DMA_TODEVICE); |
| 588 | } |
| 589 | |
| 590 | next_tx_int: |
| 591 | cons = NEXT_TX(cons); |
| 592 | |
| 593 | tx_bytes += skb->len; |
| 594 | dev_kfree_skb_any(skb); |
| 595 | } |
| 596 | |
| 597 | netdev_tx_completed_queue(txq, nr_pkts, tx_bytes); |
| 598 | txr->tx_cons = cons; |
| 599 | |
| 600 | /* Need to make the tx_cons update visible to bnxt_start_xmit() |
| 601 | * before checking for netif_tx_queue_stopped(). Without the |
| 602 | * memory barrier, there is a small possibility that bnxt_start_xmit() |
| 603 | * will miss it and cause the queue to be stopped forever. |
| 604 | */ |
| 605 | smp_mb(); |
| 606 | |
| 607 | if (unlikely(netif_tx_queue_stopped(txq)) && |
| 608 | (bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh)) { |
| 609 | __netif_tx_lock(txq, smp_processor_id()); |
| 610 | if (netif_tx_queue_stopped(txq) && |
| 611 | bnxt_tx_avail(bp, txr) > bp->tx_wake_thresh && |
| 612 | txr->dev_state != BNXT_DEV_STATE_CLOSING) |
| 613 | netif_tx_wake_queue(txq); |
| 614 | __netif_tx_unlock(txq); |
| 615 | } |
| 616 | } |
| 617 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 618 | static struct page *__bnxt_alloc_rx_page(struct bnxt *bp, dma_addr_t *mapping, |
| 619 | gfp_t gfp) |
| 620 | { |
| 621 | struct device *dev = &bp->pdev->dev; |
| 622 | struct page *page; |
| 623 | |
| 624 | page = alloc_page(gfp); |
| 625 | if (!page) |
| 626 | return NULL; |
| 627 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 628 | *mapping = dma_map_page_attrs(dev, page, 0, PAGE_SIZE, bp->rx_dir, |
| 629 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 630 | if (dma_mapping_error(dev, *mapping)) { |
| 631 | __free_page(page); |
| 632 | return NULL; |
| 633 | } |
| 634 | *mapping += bp->rx_dma_offset; |
| 635 | return page; |
| 636 | } |
| 637 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 638 | static inline u8 *__bnxt_alloc_rx_data(struct bnxt *bp, dma_addr_t *mapping, |
| 639 | gfp_t gfp) |
| 640 | { |
| 641 | u8 *data; |
| 642 | struct pci_dev *pdev = bp->pdev; |
| 643 | |
| 644 | data = kmalloc(bp->rx_buf_size, gfp); |
| 645 | if (!data) |
| 646 | return NULL; |
| 647 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 648 | *mapping = dma_map_single_attrs(&pdev->dev, data + bp->rx_dma_offset, |
| 649 | bp->rx_buf_use_size, bp->rx_dir, |
| 650 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 651 | |
| 652 | if (dma_mapping_error(&pdev->dev, *mapping)) { |
| 653 | kfree(data); |
| 654 | data = NULL; |
| 655 | } |
| 656 | return data; |
| 657 | } |
| 658 | |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 659 | int bnxt_alloc_rx_data(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, |
| 660 | u16 prod, gfp_t gfp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 661 | { |
| 662 | struct rx_bd *rxbd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 663 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[prod]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 664 | dma_addr_t mapping; |
| 665 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 666 | if (BNXT_RX_PAGE_MODE(bp)) { |
| 667 | struct page *page = __bnxt_alloc_rx_page(bp, &mapping, gfp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 668 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 669 | if (!page) |
| 670 | return -ENOMEM; |
| 671 | |
| 672 | rx_buf->data = page; |
| 673 | rx_buf->data_ptr = page_address(page) + bp->rx_offset; |
| 674 | } else { |
| 675 | u8 *data = __bnxt_alloc_rx_data(bp, &mapping, gfp); |
| 676 | |
| 677 | if (!data) |
| 678 | return -ENOMEM; |
| 679 | |
| 680 | rx_buf->data = data; |
| 681 | rx_buf->data_ptr = data + bp->rx_offset; |
| 682 | } |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 683 | rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 684 | |
| 685 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 686 | return 0; |
| 687 | } |
| 688 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 689 | 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] | 690 | { |
| 691 | u16 prod = rxr->rx_prod; |
| 692 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 693 | struct rx_bd *cons_bd, *prod_bd; |
| 694 | |
| 695 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 696 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 697 | |
| 698 | prod_rx_buf->data = data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 699 | prod_rx_buf->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 700 | |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 701 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 702 | |
| 703 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 704 | cons_bd = &rxr->rx_desc_ring[RX_RING(cons)][RX_IDX(cons)]; |
| 705 | |
| 706 | prod_bd->rx_bd_haddr = cons_bd->rx_bd_haddr; |
| 707 | } |
| 708 | |
| 709 | static inline u16 bnxt_find_next_agg_idx(struct bnxt_rx_ring_info *rxr, u16 idx) |
| 710 | { |
| 711 | u16 next, max = rxr->rx_agg_bmap_size; |
| 712 | |
| 713 | next = find_next_zero_bit(rxr->rx_agg_bmap, max, idx); |
| 714 | if (next >= max) |
| 715 | next = find_first_zero_bit(rxr->rx_agg_bmap, max); |
| 716 | return next; |
| 717 | } |
| 718 | |
| 719 | static inline int bnxt_alloc_rx_page(struct bnxt *bp, |
| 720 | struct bnxt_rx_ring_info *rxr, |
| 721 | u16 prod, gfp_t gfp) |
| 722 | { |
| 723 | struct rx_bd *rxbd = |
| 724 | &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 725 | struct bnxt_sw_rx_agg_bd *rx_agg_buf; |
| 726 | struct pci_dev *pdev = bp->pdev; |
| 727 | struct page *page; |
| 728 | dma_addr_t mapping; |
| 729 | u16 sw_prod = rxr->rx_sw_agg_prod; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 730 | unsigned int offset = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 731 | |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 732 | if (PAGE_SIZE > BNXT_RX_PAGE_SIZE) { |
| 733 | page = rxr->rx_page; |
| 734 | if (!page) { |
| 735 | page = alloc_page(gfp); |
| 736 | if (!page) |
| 737 | return -ENOMEM; |
| 738 | rxr->rx_page = page; |
| 739 | rxr->rx_page_offset = 0; |
| 740 | } |
| 741 | offset = rxr->rx_page_offset; |
| 742 | rxr->rx_page_offset += BNXT_RX_PAGE_SIZE; |
| 743 | if (rxr->rx_page_offset == PAGE_SIZE) |
| 744 | rxr->rx_page = NULL; |
| 745 | else |
| 746 | get_page(page); |
| 747 | } else { |
| 748 | page = alloc_page(gfp); |
| 749 | if (!page) |
| 750 | return -ENOMEM; |
| 751 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 752 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 753 | mapping = dma_map_page_attrs(&pdev->dev, page, offset, |
| 754 | BNXT_RX_PAGE_SIZE, PCI_DMA_FROMDEVICE, |
| 755 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 756 | if (dma_mapping_error(&pdev->dev, mapping)) { |
| 757 | __free_page(page); |
| 758 | return -EIO; |
| 759 | } |
| 760 | |
| 761 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 762 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 763 | |
| 764 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 765 | rx_agg_buf = &rxr->rx_agg_ring[sw_prod]; |
| 766 | rxr->rx_sw_agg_prod = NEXT_RX_AGG(sw_prod); |
| 767 | |
| 768 | rx_agg_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 769 | rx_agg_buf->offset = offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 770 | rx_agg_buf->mapping = mapping; |
| 771 | rxbd->rx_bd_haddr = cpu_to_le64(mapping); |
| 772 | rxbd->rx_bd_opaque = sw_prod; |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | static void bnxt_reuse_rx_agg_bufs(struct bnxt_napi *bnapi, u16 cp_cons, |
| 777 | u32 agg_bufs) |
| 778 | { |
| 779 | struct bnxt *bp = bnapi->bp; |
| 780 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 781 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 782 | u16 prod = rxr->rx_agg_prod; |
| 783 | u16 sw_prod = rxr->rx_sw_agg_prod; |
| 784 | u32 i; |
| 785 | |
| 786 | for (i = 0; i < agg_bufs; i++) { |
| 787 | u16 cons; |
| 788 | struct rx_agg_cmp *agg; |
| 789 | struct bnxt_sw_rx_agg_bd *cons_rx_buf, *prod_rx_buf; |
| 790 | struct rx_bd *prod_bd; |
| 791 | struct page *page; |
| 792 | |
| 793 | agg = (struct rx_agg_cmp *) |
| 794 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 795 | cons = agg->rx_agg_cmp_opaque; |
| 796 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 797 | |
| 798 | if (unlikely(test_bit(sw_prod, rxr->rx_agg_bmap))) |
| 799 | sw_prod = bnxt_find_next_agg_idx(rxr, sw_prod); |
| 800 | |
| 801 | __set_bit(sw_prod, rxr->rx_agg_bmap); |
| 802 | prod_rx_buf = &rxr->rx_agg_ring[sw_prod]; |
| 803 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
| 804 | |
| 805 | /* It is possible for sw_prod to be equal to cons, so |
| 806 | * set cons_rx_buf->page to NULL first. |
| 807 | */ |
| 808 | page = cons_rx_buf->page; |
| 809 | cons_rx_buf->page = NULL; |
| 810 | prod_rx_buf->page = page; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 811 | prod_rx_buf->offset = cons_rx_buf->offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 812 | |
| 813 | prod_rx_buf->mapping = cons_rx_buf->mapping; |
| 814 | |
| 815 | prod_bd = &rxr->rx_agg_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 816 | |
| 817 | prod_bd->rx_bd_haddr = cpu_to_le64(cons_rx_buf->mapping); |
| 818 | prod_bd->rx_bd_opaque = sw_prod; |
| 819 | |
| 820 | prod = NEXT_RX_AGG(prod); |
| 821 | sw_prod = NEXT_RX_AGG(sw_prod); |
| 822 | cp_cons = NEXT_CMP(cp_cons); |
| 823 | } |
| 824 | rxr->rx_agg_prod = prod; |
| 825 | rxr->rx_sw_agg_prod = sw_prod; |
| 826 | } |
| 827 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 828 | static struct sk_buff *bnxt_rx_page_skb(struct bnxt *bp, |
| 829 | struct bnxt_rx_ring_info *rxr, |
| 830 | u16 cons, void *data, u8 *data_ptr, |
| 831 | dma_addr_t dma_addr, |
| 832 | unsigned int offset_and_len) |
| 833 | { |
| 834 | unsigned int payload = offset_and_len >> 16; |
| 835 | unsigned int len = offset_and_len & 0xffff; |
| 836 | struct skb_frag_struct *frag; |
| 837 | struct page *page = data; |
| 838 | u16 prod = rxr->rx_prod; |
| 839 | struct sk_buff *skb; |
| 840 | int off, err; |
| 841 | |
| 842 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 843 | if (unlikely(err)) { |
| 844 | bnxt_reuse_rx_data(rxr, cons, data); |
| 845 | return NULL; |
| 846 | } |
| 847 | dma_addr -= bp->rx_dma_offset; |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 848 | dma_unmap_page_attrs(&bp->pdev->dev, dma_addr, PAGE_SIZE, bp->rx_dir, |
| 849 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 850 | |
| 851 | if (unlikely(!payload)) |
| 852 | payload = eth_get_headlen(data_ptr, len); |
| 853 | |
| 854 | skb = napi_alloc_skb(&rxr->bnapi->napi, payload); |
| 855 | if (!skb) { |
| 856 | __free_page(page); |
| 857 | return NULL; |
| 858 | } |
| 859 | |
| 860 | off = (void *)data_ptr - page_address(page); |
| 861 | skb_add_rx_frag(skb, 0, page, off, len, PAGE_SIZE); |
| 862 | memcpy(skb->data - NET_IP_ALIGN, data_ptr - NET_IP_ALIGN, |
| 863 | payload + NET_IP_ALIGN); |
| 864 | |
| 865 | frag = &skb_shinfo(skb)->frags[0]; |
| 866 | skb_frag_size_sub(frag, payload); |
| 867 | frag->page_offset += payload; |
| 868 | skb->data_len -= payload; |
| 869 | skb->tail += payload; |
| 870 | |
| 871 | return skb; |
| 872 | } |
| 873 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 874 | static struct sk_buff *bnxt_rx_skb(struct bnxt *bp, |
| 875 | struct bnxt_rx_ring_info *rxr, u16 cons, |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 876 | void *data, u8 *data_ptr, |
| 877 | dma_addr_t dma_addr, |
| 878 | unsigned int offset_and_len) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 879 | { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 880 | u16 prod = rxr->rx_prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 881 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 882 | int err; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 883 | |
| 884 | err = bnxt_alloc_rx_data(bp, rxr, prod, GFP_ATOMIC); |
| 885 | if (unlikely(err)) { |
| 886 | bnxt_reuse_rx_data(rxr, cons, data); |
| 887 | return NULL; |
| 888 | } |
| 889 | |
| 890 | skb = build_skb(data, 0); |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 891 | dma_unmap_single_attrs(&bp->pdev->dev, dma_addr, bp->rx_buf_use_size, |
| 892 | bp->rx_dir, DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 893 | if (!skb) { |
| 894 | kfree(data); |
| 895 | return NULL; |
| 896 | } |
| 897 | |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 898 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 899 | skb_put(skb, offset_and_len & 0xffff); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 900 | return skb; |
| 901 | } |
| 902 | |
| 903 | static struct sk_buff *bnxt_rx_pages(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 904 | struct sk_buff *skb, u16 cp_cons, |
| 905 | u32 agg_bufs) |
| 906 | { |
| 907 | struct pci_dev *pdev = bp->pdev; |
| 908 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 909 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 910 | u16 prod = rxr->rx_agg_prod; |
| 911 | u32 i; |
| 912 | |
| 913 | for (i = 0; i < agg_bufs; i++) { |
| 914 | u16 cons, frag_len; |
| 915 | struct rx_agg_cmp *agg; |
| 916 | struct bnxt_sw_rx_agg_bd *cons_rx_buf; |
| 917 | struct page *page; |
| 918 | dma_addr_t mapping; |
| 919 | |
| 920 | agg = (struct rx_agg_cmp *) |
| 921 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 922 | cons = agg->rx_agg_cmp_opaque; |
| 923 | frag_len = (le32_to_cpu(agg->rx_agg_cmp_len_flags_type) & |
| 924 | RX_AGG_CMP_LEN) >> RX_AGG_CMP_LEN_SHIFT; |
| 925 | |
| 926 | cons_rx_buf = &rxr->rx_agg_ring[cons]; |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 927 | skb_fill_page_desc(skb, i, cons_rx_buf->page, |
| 928 | cons_rx_buf->offset, frag_len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 929 | __clear_bit(cons, rxr->rx_agg_bmap); |
| 930 | |
| 931 | /* It is possible for bnxt_alloc_rx_page() to allocate |
| 932 | * a sw_prod index that equals the cons index, so we |
| 933 | * need to clear the cons entry now. |
| 934 | */ |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 935 | mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 936 | page = cons_rx_buf->page; |
| 937 | cons_rx_buf->page = NULL; |
| 938 | |
| 939 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_ATOMIC) != 0) { |
| 940 | struct skb_shared_info *shinfo; |
| 941 | unsigned int nr_frags; |
| 942 | |
| 943 | shinfo = skb_shinfo(skb); |
| 944 | nr_frags = --shinfo->nr_frags; |
| 945 | __skb_frag_set_page(&shinfo->frags[nr_frags], NULL); |
| 946 | |
| 947 | dev_kfree_skb(skb); |
| 948 | |
| 949 | cons_rx_buf->page = page; |
| 950 | |
| 951 | /* Update prod since possibly some pages have been |
| 952 | * allocated already. |
| 953 | */ |
| 954 | rxr->rx_agg_prod = prod; |
| 955 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs - i); |
| 956 | return NULL; |
| 957 | } |
| 958 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 959 | dma_unmap_page_attrs(&pdev->dev, mapping, BNXT_RX_PAGE_SIZE, |
| 960 | PCI_DMA_FROMDEVICE, |
| 961 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 962 | |
| 963 | skb->data_len += frag_len; |
| 964 | skb->len += frag_len; |
| 965 | skb->truesize += PAGE_SIZE; |
| 966 | |
| 967 | prod = NEXT_RX_AGG(prod); |
| 968 | cp_cons = NEXT_CMP(cp_cons); |
| 969 | } |
| 970 | rxr->rx_agg_prod = prod; |
| 971 | return skb; |
| 972 | } |
| 973 | |
| 974 | static int bnxt_agg_bufs_valid(struct bnxt *bp, struct bnxt_cp_ring_info *cpr, |
| 975 | u8 agg_bufs, u32 *raw_cons) |
| 976 | { |
| 977 | u16 last; |
| 978 | struct rx_agg_cmp *agg; |
| 979 | |
| 980 | *raw_cons = ADV_RAW_CMP(*raw_cons, agg_bufs); |
| 981 | last = RING_CMP(*raw_cons); |
| 982 | agg = (struct rx_agg_cmp *) |
| 983 | &cpr->cp_desc_ring[CP_RING(last)][CP_IDX(last)]; |
| 984 | return RX_AGG_CMP_VALID(agg, *raw_cons); |
| 985 | } |
| 986 | |
| 987 | static inline struct sk_buff *bnxt_copy_skb(struct bnxt_napi *bnapi, u8 *data, |
| 988 | unsigned int len, |
| 989 | dma_addr_t mapping) |
| 990 | { |
| 991 | struct bnxt *bp = bnapi->bp; |
| 992 | struct pci_dev *pdev = bp->pdev; |
| 993 | struct sk_buff *skb; |
| 994 | |
| 995 | skb = napi_alloc_skb(&bnapi->napi, len); |
| 996 | if (!skb) |
| 997 | return NULL; |
| 998 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 999 | dma_sync_single_for_cpu(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 1000 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1001 | |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1002 | memcpy(skb->data - NET_IP_ALIGN, data - NET_IP_ALIGN, |
| 1003 | len + NET_IP_ALIGN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1004 | |
Michael Chan | 745fc05 | 2017-02-06 16:55:34 -0500 | [diff] [blame] | 1005 | dma_sync_single_for_device(&pdev->dev, mapping, bp->rx_copy_thresh, |
| 1006 | bp->rx_dir); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1007 | |
| 1008 | skb_put(skb, len); |
| 1009 | return skb; |
| 1010 | } |
| 1011 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1012 | static int bnxt_discard_rx(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1013 | u32 *raw_cons, void *cmp) |
| 1014 | { |
| 1015 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1016 | struct rx_cmp *rxcmp = cmp; |
| 1017 | u32 tmp_raw_cons = *raw_cons; |
| 1018 | u8 cmp_type, agg_bufs = 0; |
| 1019 | |
| 1020 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1021 | |
| 1022 | if (cmp_type == CMP_TYPE_RX_L2_CMP) { |
| 1023 | agg_bufs = (le32_to_cpu(rxcmp->rx_cmp_misc_v1) & |
| 1024 | RX_CMP_AGG_BUFS) >> |
| 1025 | RX_CMP_AGG_BUFS_SHIFT; |
| 1026 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1027 | struct rx_tpa_end_cmp *tpa_end = cmp; |
| 1028 | |
| 1029 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1030 | RX_TPA_END_CMP_AGG_BUFS) >> |
| 1031 | RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 1032 | } |
| 1033 | |
| 1034 | if (agg_bufs) { |
| 1035 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 1036 | return -EBUSY; |
| 1037 | } |
| 1038 | *raw_cons = tmp_raw_cons; |
| 1039 | return 0; |
| 1040 | } |
| 1041 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1042 | static void bnxt_queue_sp_work(struct bnxt *bp) |
| 1043 | { |
| 1044 | if (BNXT_PF(bp)) |
| 1045 | queue_work(bnxt_pf_wq, &bp->sp_task); |
| 1046 | else |
| 1047 | schedule_work(&bp->sp_task); |
| 1048 | } |
| 1049 | |
| 1050 | static void bnxt_cancel_sp_work(struct bnxt *bp) |
| 1051 | { |
| 1052 | if (BNXT_PF(bp)) |
| 1053 | flush_workqueue(bnxt_pf_wq); |
| 1054 | else |
| 1055 | cancel_work_sync(&bp->sp_task); |
| 1056 | } |
| 1057 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1058 | static void bnxt_sched_reset(struct bnxt *bp, struct bnxt_rx_ring_info *rxr) |
| 1059 | { |
| 1060 | if (!rxr->bnapi->in_reset) { |
| 1061 | rxr->bnapi->in_reset = true; |
| 1062 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1063 | bnxt_queue_sp_work(bp); |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1064 | } |
| 1065 | rxr->rx_next_cons = 0xffff; |
| 1066 | } |
| 1067 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1068 | static void bnxt_tpa_start(struct bnxt *bp, struct bnxt_rx_ring_info *rxr, |
| 1069 | struct rx_tpa_start_cmp *tpa_start, |
| 1070 | struct rx_tpa_start_cmp_ext *tpa_start1) |
| 1071 | { |
| 1072 | u8 agg_id = TPA_START_AGG_ID(tpa_start); |
| 1073 | u16 cons, prod; |
| 1074 | struct bnxt_tpa_info *tpa_info; |
| 1075 | struct bnxt_sw_rx_bd *cons_rx_buf, *prod_rx_buf; |
| 1076 | struct rx_bd *prod_bd; |
| 1077 | dma_addr_t mapping; |
| 1078 | |
| 1079 | cons = tpa_start->rx_tpa_start_cmp_opaque; |
| 1080 | prod = rxr->rx_prod; |
| 1081 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 1082 | prod_rx_buf = &rxr->rx_buf_ring[prod]; |
| 1083 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1084 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1085 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1086 | bnxt_sched_reset(bp, rxr); |
| 1087 | return; |
| 1088 | } |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1089 | /* Store cfa_code in tpa_info to use in tpa_end |
| 1090 | * completion processing. |
| 1091 | */ |
| 1092 | tpa_info->cfa_code = TPA_START_CFA_CODE(tpa_start1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1093 | prod_rx_buf->data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1094 | prod_rx_buf->data_ptr = tpa_info->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1095 | |
| 1096 | mapping = tpa_info->mapping; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1097 | prod_rx_buf->mapping = mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1098 | |
| 1099 | prod_bd = &rxr->rx_desc_ring[RX_RING(prod)][RX_IDX(prod)]; |
| 1100 | |
| 1101 | prod_bd->rx_bd_haddr = cpu_to_le64(mapping); |
| 1102 | |
| 1103 | tpa_info->data = cons_rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1104 | tpa_info->data_ptr = cons_rx_buf->data_ptr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1105 | cons_rx_buf->data = NULL; |
Michael Chan | 11cd119 | 2017-02-06 16:55:33 -0500 | [diff] [blame] | 1106 | tpa_info->mapping = cons_rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1107 | |
| 1108 | tpa_info->len = |
| 1109 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_len_flags_type) >> |
| 1110 | RX_TPA_START_CMP_LEN_SHIFT; |
| 1111 | if (likely(TPA_START_HASH_VALID(tpa_start))) { |
| 1112 | u32 hash_type = TPA_START_HASH_TYPE(tpa_start); |
| 1113 | |
| 1114 | tpa_info->hash_type = PKT_HASH_TYPE_L4; |
| 1115 | tpa_info->gso_type = SKB_GSO_TCPV4; |
| 1116 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 1117 | if (hash_type == 3) |
| 1118 | tpa_info->gso_type = SKB_GSO_TCPV6; |
| 1119 | tpa_info->rss_hash = |
| 1120 | le32_to_cpu(tpa_start->rx_tpa_start_cmp_rss_hash); |
| 1121 | } else { |
| 1122 | tpa_info->hash_type = PKT_HASH_TYPE_NONE; |
| 1123 | tpa_info->gso_type = 0; |
| 1124 | if (netif_msg_rx_err(bp)) |
| 1125 | netdev_warn(bp->dev, "TPA packet without valid hash\n"); |
| 1126 | } |
| 1127 | tpa_info->flags2 = le32_to_cpu(tpa_start1->rx_tpa_start_cmp_flags2); |
| 1128 | 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] | 1129 | 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] | 1130 | |
| 1131 | rxr->rx_prod = NEXT_RX(prod); |
| 1132 | cons = NEXT_RX(cons); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1133 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1134 | cons_rx_buf = &rxr->rx_buf_ring[cons]; |
| 1135 | |
| 1136 | bnxt_reuse_rx_data(rxr, cons, cons_rx_buf->data); |
| 1137 | rxr->rx_prod = NEXT_RX(rxr->rx_prod); |
| 1138 | cons_rx_buf->data = NULL; |
| 1139 | } |
| 1140 | |
| 1141 | static void bnxt_abort_tpa(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1142 | u16 cp_cons, u32 agg_bufs) |
| 1143 | { |
| 1144 | if (agg_bufs) |
| 1145 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1146 | } |
| 1147 | |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1148 | static struct sk_buff *bnxt_gro_func_5731x(struct bnxt_tpa_info *tpa_info, |
| 1149 | int payload_off, int tcp_ts, |
| 1150 | struct sk_buff *skb) |
| 1151 | { |
| 1152 | #ifdef CONFIG_INET |
| 1153 | struct tcphdr *th; |
| 1154 | int len, nw_off; |
| 1155 | u16 outer_ip_off, inner_ip_off, inner_mac_off; |
| 1156 | u32 hdr_info = tpa_info->hdr_info; |
| 1157 | bool loopback = false; |
| 1158 | |
| 1159 | inner_ip_off = BNXT_TPA_INNER_L3_OFF(hdr_info); |
| 1160 | inner_mac_off = BNXT_TPA_INNER_L2_OFF(hdr_info); |
| 1161 | outer_ip_off = BNXT_TPA_OUTER_L3_OFF(hdr_info); |
| 1162 | |
| 1163 | /* If the packet is an internal loopback packet, the offsets will |
| 1164 | * have an extra 4 bytes. |
| 1165 | */ |
| 1166 | if (inner_mac_off == 4) { |
| 1167 | loopback = true; |
| 1168 | } else if (inner_mac_off > 4) { |
| 1169 | __be16 proto = *((__be16 *)(skb->data + inner_ip_off - |
| 1170 | ETH_HLEN - 2)); |
| 1171 | |
| 1172 | /* We only support inner iPv4/ipv6. If we don't see the |
| 1173 | * correct protocol ID, it must be a loopback packet where |
| 1174 | * the offsets are off by 4. |
| 1175 | */ |
Dan Carpenter | 09a7636 | 2016-07-07 11:23:09 +0300 | [diff] [blame] | 1176 | if (proto != htons(ETH_P_IP) && proto != htons(ETH_P_IPV6)) |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 1177 | loopback = true; |
| 1178 | } |
| 1179 | if (loopback) { |
| 1180 | /* internal loopback packet, subtract all offsets by 4 */ |
| 1181 | inner_ip_off -= 4; |
| 1182 | inner_mac_off -= 4; |
| 1183 | outer_ip_off -= 4; |
| 1184 | } |
| 1185 | |
| 1186 | nw_off = inner_ip_off - ETH_HLEN; |
| 1187 | skb_set_network_header(skb, nw_off); |
| 1188 | if (tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_IP_TYPE) { |
| 1189 | struct ipv6hdr *iph = ipv6_hdr(skb); |
| 1190 | |
| 1191 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1192 | len = skb->len - skb_transport_offset(skb); |
| 1193 | th = tcp_hdr(skb); |
| 1194 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1195 | } else { |
| 1196 | struct iphdr *iph = ip_hdr(skb); |
| 1197 | |
| 1198 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1199 | len = skb->len - skb_transport_offset(skb); |
| 1200 | th = tcp_hdr(skb); |
| 1201 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1202 | } |
| 1203 | |
| 1204 | if (inner_mac_off) { /* tunnel */ |
| 1205 | struct udphdr *uh = NULL; |
| 1206 | __be16 proto = *((__be16 *)(skb->data + outer_ip_off - |
| 1207 | ETH_HLEN - 2)); |
| 1208 | |
| 1209 | if (proto == htons(ETH_P_IP)) { |
| 1210 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1211 | |
| 1212 | if (iph->protocol == IPPROTO_UDP) |
| 1213 | uh = (struct udphdr *)(iph + 1); |
| 1214 | } else { |
| 1215 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1216 | |
| 1217 | if (iph->nexthdr == IPPROTO_UDP) |
| 1218 | uh = (struct udphdr *)(iph + 1); |
| 1219 | } |
| 1220 | if (uh) { |
| 1221 | if (uh->check) |
| 1222 | skb_shinfo(skb)->gso_type |= |
| 1223 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1224 | else |
| 1225 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1226 | } |
| 1227 | } |
| 1228 | #endif |
| 1229 | return skb; |
| 1230 | } |
| 1231 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1232 | #define BNXT_IPV4_HDR_SIZE (sizeof(struct iphdr) + sizeof(struct tcphdr)) |
| 1233 | #define BNXT_IPV6_HDR_SIZE (sizeof(struct ipv6hdr) + sizeof(struct tcphdr)) |
| 1234 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1235 | static struct sk_buff *bnxt_gro_func_5730x(struct bnxt_tpa_info *tpa_info, |
| 1236 | int payload_off, int tcp_ts, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1237 | struct sk_buff *skb) |
| 1238 | { |
Michael Chan | d1611c3 | 2015-10-25 22:27:57 -0400 | [diff] [blame] | 1239 | #ifdef CONFIG_INET |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1240 | struct tcphdr *th; |
Michael Chan | 719ca81 | 2017-01-17 22:07:19 -0500 | [diff] [blame] | 1241 | int len, nw_off, tcp_opt_len = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1242 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1243 | if (tcp_ts) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1244 | tcp_opt_len = 12; |
| 1245 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1246 | if (tpa_info->gso_type == SKB_GSO_TCPV4) { |
| 1247 | struct iphdr *iph; |
| 1248 | |
| 1249 | nw_off = payload_off - BNXT_IPV4_HDR_SIZE - tcp_opt_len - |
| 1250 | ETH_HLEN; |
| 1251 | skb_set_network_header(skb, nw_off); |
| 1252 | iph = ip_hdr(skb); |
| 1253 | skb_set_transport_header(skb, nw_off + sizeof(struct iphdr)); |
| 1254 | len = skb->len - skb_transport_offset(skb); |
| 1255 | th = tcp_hdr(skb); |
| 1256 | th->check = ~tcp_v4_check(len, iph->saddr, iph->daddr, 0); |
| 1257 | } else if (tpa_info->gso_type == SKB_GSO_TCPV6) { |
| 1258 | struct ipv6hdr *iph; |
| 1259 | |
| 1260 | nw_off = payload_off - BNXT_IPV6_HDR_SIZE - tcp_opt_len - |
| 1261 | ETH_HLEN; |
| 1262 | skb_set_network_header(skb, nw_off); |
| 1263 | iph = ipv6_hdr(skb); |
| 1264 | skb_set_transport_header(skb, nw_off + sizeof(struct ipv6hdr)); |
| 1265 | len = skb->len - skb_transport_offset(skb); |
| 1266 | th = tcp_hdr(skb); |
| 1267 | th->check = ~tcp_v6_check(len, &iph->saddr, &iph->daddr, 0); |
| 1268 | } else { |
| 1269 | dev_kfree_skb_any(skb); |
| 1270 | return NULL; |
| 1271 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1272 | |
| 1273 | if (nw_off) { /* tunnel */ |
| 1274 | struct udphdr *uh = NULL; |
| 1275 | |
| 1276 | if (skb->protocol == htons(ETH_P_IP)) { |
| 1277 | struct iphdr *iph = (struct iphdr *)skb->data; |
| 1278 | |
| 1279 | if (iph->protocol == IPPROTO_UDP) |
| 1280 | uh = (struct udphdr *)(iph + 1); |
| 1281 | } else { |
| 1282 | struct ipv6hdr *iph = (struct ipv6hdr *)skb->data; |
| 1283 | |
| 1284 | if (iph->nexthdr == IPPROTO_UDP) |
| 1285 | uh = (struct udphdr *)(iph + 1); |
| 1286 | } |
| 1287 | if (uh) { |
| 1288 | if (uh->check) |
| 1289 | skb_shinfo(skb)->gso_type |= |
| 1290 | SKB_GSO_UDP_TUNNEL_CSUM; |
| 1291 | else |
| 1292 | skb_shinfo(skb)->gso_type |= SKB_GSO_UDP_TUNNEL; |
| 1293 | } |
| 1294 | } |
| 1295 | #endif |
| 1296 | return skb; |
| 1297 | } |
| 1298 | |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1299 | static inline struct sk_buff *bnxt_gro_skb(struct bnxt *bp, |
| 1300 | struct bnxt_tpa_info *tpa_info, |
| 1301 | struct rx_tpa_end_cmp *tpa_end, |
| 1302 | struct rx_tpa_end_cmp_ext *tpa_end1, |
| 1303 | struct sk_buff *skb) |
| 1304 | { |
| 1305 | #ifdef CONFIG_INET |
| 1306 | int payload_off; |
| 1307 | u16 segs; |
| 1308 | |
| 1309 | segs = TPA_END_TPA_SEGS(tpa_end); |
| 1310 | if (segs == 1) |
| 1311 | return skb; |
| 1312 | |
| 1313 | NAPI_GRO_CB(skb)->count = segs; |
| 1314 | skb_shinfo(skb)->gso_size = |
| 1315 | le32_to_cpu(tpa_end1->rx_tpa_end_cmp_seg_len); |
| 1316 | skb_shinfo(skb)->gso_type = tpa_info->gso_type; |
| 1317 | payload_off = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1318 | RX_TPA_END_CMP_PAYLOAD_OFFSET) >> |
| 1319 | RX_TPA_END_CMP_PAYLOAD_OFFSET_SHIFT; |
| 1320 | 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] | 1321 | if (likely(skb)) |
| 1322 | tcp_gro_complete(skb); |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1323 | #endif |
| 1324 | return skb; |
| 1325 | } |
| 1326 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1327 | /* Given the cfa_code of a received packet determine which |
| 1328 | * netdev (vf-rep or PF) the packet is destined to. |
| 1329 | */ |
| 1330 | static struct net_device *bnxt_get_pkt_dev(struct bnxt *bp, u16 cfa_code) |
| 1331 | { |
| 1332 | struct net_device *dev = bnxt_get_vf_rep(bp, cfa_code); |
| 1333 | |
| 1334 | /* if vf-rep dev is NULL, the must belongs to the PF */ |
| 1335 | return dev ? dev : bp->dev; |
| 1336 | } |
| 1337 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1338 | static inline struct sk_buff *bnxt_tpa_end(struct bnxt *bp, |
| 1339 | struct bnxt_napi *bnapi, |
| 1340 | u32 *raw_cons, |
| 1341 | struct rx_tpa_end_cmp *tpa_end, |
| 1342 | struct rx_tpa_end_cmp_ext *tpa_end1, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1343 | u8 *event) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1344 | { |
| 1345 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1346 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1347 | u8 agg_id = TPA_END_AGG_ID(tpa_end); |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1348 | u8 *data_ptr, agg_bufs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1349 | u16 cp_cons = RING_CMP(*raw_cons); |
| 1350 | unsigned int len; |
| 1351 | struct bnxt_tpa_info *tpa_info; |
| 1352 | dma_addr_t mapping; |
| 1353 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1354 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1355 | |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1356 | if (unlikely(bnapi->in_reset)) { |
| 1357 | int rc = bnxt_discard_rx(bp, bnapi, raw_cons, tpa_end); |
| 1358 | |
| 1359 | if (rc < 0) |
| 1360 | return ERR_PTR(-EBUSY); |
| 1361 | return NULL; |
| 1362 | } |
| 1363 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1364 | tpa_info = &rxr->rx_tpa[agg_id]; |
| 1365 | data = tpa_info->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1366 | data_ptr = tpa_info->data_ptr; |
| 1367 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1368 | len = tpa_info->len; |
| 1369 | mapping = tpa_info->mapping; |
| 1370 | |
| 1371 | agg_bufs = (le32_to_cpu(tpa_end->rx_tpa_end_cmp_misc_v1) & |
| 1372 | RX_TPA_END_CMP_AGG_BUFS) >> RX_TPA_END_CMP_AGG_BUFS_SHIFT; |
| 1373 | |
| 1374 | if (agg_bufs) { |
| 1375 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, raw_cons)) |
| 1376 | return ERR_PTR(-EBUSY); |
| 1377 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1378 | *event |= BNXT_AGG_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1379 | cp_cons = NEXT_CMP(cp_cons); |
| 1380 | } |
| 1381 | |
Michael Chan | 69c149e | 2017-06-23 14:01:00 -0400 | [diff] [blame] | 1382 | if (unlikely(agg_bufs > MAX_SKB_FRAGS || TPA_END_ERRORS(tpa_end1))) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1383 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
Michael Chan | 69c149e | 2017-06-23 14:01:00 -0400 | [diff] [blame] | 1384 | if (agg_bufs > MAX_SKB_FRAGS) |
| 1385 | netdev_warn(bp->dev, "TPA frags %d exceeded MAX_SKB_FRAGS %d\n", |
| 1386 | agg_bufs, (int)MAX_SKB_FRAGS); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1387 | return NULL; |
| 1388 | } |
| 1389 | |
| 1390 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1391 | skb = bnxt_copy_skb(bnapi, data_ptr, len, mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1392 | if (!skb) { |
| 1393 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1394 | return NULL; |
| 1395 | } |
| 1396 | } else { |
| 1397 | u8 *new_data; |
| 1398 | dma_addr_t new_mapping; |
| 1399 | |
| 1400 | new_data = __bnxt_alloc_rx_data(bp, &new_mapping, GFP_ATOMIC); |
| 1401 | if (!new_data) { |
| 1402 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1403 | return NULL; |
| 1404 | } |
| 1405 | |
| 1406 | tpa_info->data = new_data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 1407 | tpa_info->data_ptr = new_data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1408 | tpa_info->mapping = new_mapping; |
| 1409 | |
| 1410 | skb = build_skb(data, 0); |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 1411 | dma_unmap_single_attrs(&bp->pdev->dev, mapping, |
| 1412 | bp->rx_buf_use_size, bp->rx_dir, |
| 1413 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1414 | |
| 1415 | if (!skb) { |
| 1416 | kfree(data); |
| 1417 | bnxt_abort_tpa(bp, bnapi, cp_cons, agg_bufs); |
| 1418 | return NULL; |
| 1419 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 1420 | skb_reserve(skb, bp->rx_offset); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1421 | skb_put(skb, len); |
| 1422 | } |
| 1423 | |
| 1424 | if (agg_bufs) { |
| 1425 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1426 | if (!skb) { |
| 1427 | /* Page reuse already handled by bnxt_rx_pages(). */ |
| 1428 | return NULL; |
| 1429 | } |
| 1430 | } |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1431 | |
| 1432 | skb->protocol = |
| 1433 | 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] | 1434 | |
| 1435 | if (tpa_info->hash_type != PKT_HASH_TYPE_NONE) |
| 1436 | skb_set_hash(skb, tpa_info->rss_hash, tpa_info->hash_type); |
| 1437 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1438 | if ((tpa_info->flags2 & RX_CMP_FLAGS2_META_FORMAT_VLAN) && |
| 1439 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1440 | u16 vlan_proto = tpa_info->metadata >> |
| 1441 | RX_CMP_FLAGS2_METADATA_TPID_SFT; |
Michael Chan | ed7bc602 | 2018-03-09 23:46:06 -0500 | [diff] [blame] | 1442 | u16 vtag = tpa_info->metadata & RX_CMP_FLAGS2_METADATA_TCI_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1443 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1444 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1445 | } |
| 1446 | |
| 1447 | skb_checksum_none_assert(skb); |
| 1448 | if (likely(tpa_info->flags2 & RX_TPA_START_CMP_FLAGS2_L4_CS_CALC)) { |
| 1449 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1450 | skb->csum_level = |
| 1451 | (tpa_info->flags2 & RX_CMP_FLAGS2_T_L4_CS_CALC) >> 3; |
| 1452 | } |
| 1453 | |
| 1454 | if (TPA_END_GRO(tpa_end)) |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 1455 | skb = bnxt_gro_skb(bp, tpa_info, tpa_end, tpa_end1, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1456 | |
| 1457 | return skb; |
| 1458 | } |
| 1459 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1460 | static void bnxt_deliver_skb(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1461 | struct sk_buff *skb) |
| 1462 | { |
| 1463 | if (skb->dev != bp->dev) { |
| 1464 | /* this packet belongs to a vf-rep */ |
| 1465 | bnxt_vf_rep_rx(bp, skb); |
| 1466 | return; |
| 1467 | } |
| 1468 | skb_record_rx_queue(skb, bnapi->index); |
| 1469 | napi_gro_receive(&bnapi->napi, skb); |
| 1470 | } |
| 1471 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1472 | /* returns the following: |
| 1473 | * 1 - 1 packet successfully received |
| 1474 | * 0 - successful TPA_START, packet not completed yet |
| 1475 | * -EBUSY - completion ring does not have all the agg buffers yet |
| 1476 | * -ENOMEM - packet aborted due to out of memory |
| 1477 | * -EIO - packet aborted due to hw error indicated in BD |
| 1478 | */ |
| 1479 | 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] | 1480 | u8 *event) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1481 | { |
| 1482 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1483 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1484 | struct net_device *dev = bp->dev; |
| 1485 | struct rx_cmp *rxcmp; |
| 1486 | struct rx_cmp_ext *rxcmp1; |
| 1487 | u32 tmp_raw_cons = *raw_cons; |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1488 | u16 cfa_code, cons, prod, cp_cons = RING_CMP(tmp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1489 | struct bnxt_sw_rx_bd *rx_buf; |
| 1490 | unsigned int len; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1491 | u8 *data_ptr, agg_bufs, cmp_type; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1492 | dma_addr_t dma_addr; |
| 1493 | struct sk_buff *skb; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1494 | void *data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1495 | int rc = 0; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1496 | u32 misc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1497 | |
| 1498 | rxcmp = (struct rx_cmp *) |
| 1499 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1500 | |
| 1501 | tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons); |
| 1502 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1503 | rxcmp1 = (struct rx_cmp_ext *) |
| 1504 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1505 | |
| 1506 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1507 | return -EBUSY; |
| 1508 | |
| 1509 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1510 | |
| 1511 | prod = rxr->rx_prod; |
| 1512 | |
| 1513 | if (cmp_type == CMP_TYPE_RX_L2_TPA_START_CMP) { |
| 1514 | bnxt_tpa_start(bp, rxr, (struct rx_tpa_start_cmp *)rxcmp, |
| 1515 | (struct rx_tpa_start_cmp_ext *)rxcmp1); |
| 1516 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1517 | *event |= BNXT_RX_EVENT; |
Colin Ian King | e7e70fa | 2018-01-16 10:22:50 +0000 | [diff] [blame] | 1518 | goto next_rx_no_prod_no_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1519 | |
| 1520 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1521 | skb = bnxt_tpa_end(bp, bnapi, &tmp_raw_cons, |
| 1522 | (struct rx_tpa_end_cmp *)rxcmp, |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1523 | (struct rx_tpa_end_cmp_ext *)rxcmp1, event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1524 | |
Tobias Klauser | 1fac4b2 | 2017-09-26 15:12:26 +0200 | [diff] [blame] | 1525 | if (IS_ERR(skb)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1526 | return -EBUSY; |
| 1527 | |
| 1528 | rc = -ENOMEM; |
| 1529 | if (likely(skb)) { |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1530 | bnxt_deliver_skb(bp, bnapi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1531 | rc = 1; |
| 1532 | } |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1533 | *event |= BNXT_RX_EVENT; |
Colin Ian King | e7e70fa | 2018-01-16 10:22:50 +0000 | [diff] [blame] | 1534 | goto next_rx_no_prod_no_len; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1535 | } |
| 1536 | |
| 1537 | cons = rxcmp->rx_cmp_opaque; |
| 1538 | rx_buf = &rxr->rx_buf_ring[cons]; |
| 1539 | data = rx_buf->data; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1540 | data_ptr = rx_buf->data_ptr; |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 1541 | if (unlikely(cons != rxr->rx_next_cons)) { |
| 1542 | int rc1 = bnxt_discard_rx(bp, bnapi, raw_cons, rxcmp); |
| 1543 | |
| 1544 | bnxt_sched_reset(bp, rxr); |
| 1545 | return rc1; |
| 1546 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1547 | prefetch(data_ptr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1548 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1549 | misc = le32_to_cpu(rxcmp->rx_cmp_misc_v1); |
| 1550 | agg_bufs = (misc & RX_CMP_AGG_BUFS) >> RX_CMP_AGG_BUFS_SHIFT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1551 | |
| 1552 | if (agg_bufs) { |
| 1553 | if (!bnxt_agg_bufs_valid(bp, cpr, agg_bufs, &tmp_raw_cons)) |
| 1554 | return -EBUSY; |
| 1555 | |
| 1556 | cp_cons = NEXT_CMP(cp_cons); |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1557 | *event |= BNXT_AGG_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1558 | } |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1559 | *event |= BNXT_RX_EVENT; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1560 | |
| 1561 | rx_buf->data = NULL; |
| 1562 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L2_ERRORS) { |
| 1563 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1564 | if (agg_bufs) |
| 1565 | bnxt_reuse_rx_agg_bufs(bnapi, cp_cons, agg_bufs); |
| 1566 | |
| 1567 | rc = -EIO; |
| 1568 | goto next_rx; |
| 1569 | } |
| 1570 | |
| 1571 | 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] | 1572 | dma_addr = rx_buf->mapping; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1573 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 1574 | if (bnxt_rx_xdp(bp, rxr, cons, data, &data_ptr, &len, event)) { |
| 1575 | rc = 1; |
| 1576 | goto next_rx; |
| 1577 | } |
| 1578 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1579 | if (len <= bp->rx_copy_thresh) { |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1580 | skb = bnxt_copy_skb(bnapi, data_ptr, len, dma_addr); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1581 | bnxt_reuse_rx_data(rxr, cons, data); |
| 1582 | if (!skb) { |
| 1583 | rc = -ENOMEM; |
| 1584 | goto next_rx; |
| 1585 | } |
| 1586 | } else { |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 1587 | u32 payload; |
| 1588 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 1589 | if (rx_buf->data_ptr == data_ptr) |
| 1590 | payload = misc & RX_CMP_PAYLOAD_OFFSET; |
| 1591 | else |
| 1592 | payload = 0; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 1593 | 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] | 1594 | payload | len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1595 | if (!skb) { |
| 1596 | rc = -ENOMEM; |
| 1597 | goto next_rx; |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | if (agg_bufs) { |
| 1602 | skb = bnxt_rx_pages(bp, bnapi, skb, cp_cons, agg_bufs); |
| 1603 | if (!skb) { |
| 1604 | rc = -ENOMEM; |
| 1605 | goto next_rx; |
| 1606 | } |
| 1607 | } |
| 1608 | |
| 1609 | if (RX_CMP_HASH_VALID(rxcmp)) { |
| 1610 | u32 hash_type = RX_CMP_HASH_TYPE(rxcmp); |
| 1611 | enum pkt_hash_types type = PKT_HASH_TYPE_L4; |
| 1612 | |
| 1613 | /* RSS profiles 1 and 3 with extract code 0 for inner 4-tuple */ |
| 1614 | if (hash_type != 1 && hash_type != 3) |
| 1615 | type = PKT_HASH_TYPE_L3; |
| 1616 | skb_set_hash(skb, le32_to_cpu(rxcmp->rx_cmp_rss_hash), type); |
| 1617 | } |
| 1618 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1619 | cfa_code = RX_CMP_CFA_CODE(rxcmp1); |
| 1620 | 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] | 1621 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1622 | if ((rxcmp1->rx_cmp_flags2 & |
| 1623 | cpu_to_le32(RX_CMP_FLAGS2_META_FORMAT_VLAN)) && |
| 1624 | (skb->dev->features & NETIF_F_HW_VLAN_CTAG_RX)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1625 | u32 meta_data = le32_to_cpu(rxcmp1->rx_cmp_meta_data); |
Michael Chan | ed7bc602 | 2018-03-09 23:46:06 -0500 | [diff] [blame] | 1626 | u16 vtag = meta_data & RX_CMP_FLAGS2_METADATA_TCI_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1627 | u16 vlan_proto = meta_data >> RX_CMP_FLAGS2_METADATA_TPID_SFT; |
| 1628 | |
Michael Chan | 8852ddb | 2016-06-06 02:37:16 -0400 | [diff] [blame] | 1629 | __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vtag); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | skb_checksum_none_assert(skb); |
| 1633 | if (RX_CMP_L4_CS_OK(rxcmp1)) { |
| 1634 | if (dev->features & NETIF_F_RXCSUM) { |
| 1635 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 1636 | skb->csum_level = RX_CMP_ENCAP(rxcmp1); |
| 1637 | } |
| 1638 | } else { |
Satish Baddipadige | 665e350 | 2015-12-27 18:19:21 -0500 | [diff] [blame] | 1639 | if (rxcmp1->rx_cmp_cfa_code_errors_v2 & RX_CMP_L4_CS_ERR_BITS) { |
| 1640 | if (dev->features & NETIF_F_RXCSUM) |
| 1641 | cpr->rx_l4_csum_errors++; |
| 1642 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1643 | } |
| 1644 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 1645 | bnxt_deliver_skb(bp, bnapi, skb); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1646 | rc = 1; |
| 1647 | |
| 1648 | next_rx: |
| 1649 | rxr->rx_prod = NEXT_RX(prod); |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 1650 | rxr->rx_next_cons = NEXT_RX(cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1651 | |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 1652 | cpr->rx_packets += 1; |
| 1653 | cpr->rx_bytes += len; |
Colin Ian King | e7e70fa | 2018-01-16 10:22:50 +0000 | [diff] [blame] | 1654 | |
| 1655 | next_rx_no_prod_no_len: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1656 | *raw_cons = tmp_raw_cons; |
| 1657 | |
| 1658 | return rc; |
| 1659 | } |
| 1660 | |
Michael Chan | 2270bc5 | 2017-06-23 14:01:01 -0400 | [diff] [blame] | 1661 | /* In netpoll mode, if we are using a combined completion ring, we need to |
| 1662 | * discard the rx packets and recycle the buffers. |
| 1663 | */ |
| 1664 | static int bnxt_force_rx_discard(struct bnxt *bp, struct bnxt_napi *bnapi, |
| 1665 | u32 *raw_cons, u8 *event) |
| 1666 | { |
| 1667 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1668 | u32 tmp_raw_cons = *raw_cons; |
| 1669 | struct rx_cmp_ext *rxcmp1; |
| 1670 | struct rx_cmp *rxcmp; |
| 1671 | u16 cp_cons; |
| 1672 | u8 cmp_type; |
| 1673 | |
| 1674 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1675 | rxcmp = (struct rx_cmp *) |
| 1676 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1677 | |
| 1678 | tmp_raw_cons = NEXT_RAW_CMP(tmp_raw_cons); |
| 1679 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1680 | rxcmp1 = (struct rx_cmp_ext *) |
| 1681 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1682 | |
| 1683 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1684 | return -EBUSY; |
| 1685 | |
| 1686 | cmp_type = RX_CMP_TYPE(rxcmp); |
| 1687 | if (cmp_type == CMP_TYPE_RX_L2_CMP) { |
| 1688 | rxcmp1->rx_cmp_cfa_code_errors_v2 |= |
| 1689 | cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR); |
| 1690 | } else if (cmp_type == CMP_TYPE_RX_L2_TPA_END_CMP) { |
| 1691 | struct rx_tpa_end_cmp_ext *tpa_end1; |
| 1692 | |
| 1693 | tpa_end1 = (struct rx_tpa_end_cmp_ext *)rxcmp1; |
| 1694 | tpa_end1->rx_tpa_end_cmp_errors_v2 |= |
| 1695 | cpu_to_le32(RX_TPA_END_CMP_ERRORS); |
| 1696 | } |
| 1697 | return bnxt_rx_pkt(bp, bnapi, raw_cons, event); |
| 1698 | } |
| 1699 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1700 | #define BNXT_GET_EVENT_PORT(data) \ |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1701 | ((data) & \ |
| 1702 | ASYNC_EVENT_CMPL_PORT_CONN_NOT_ALLOWED_EVENT_DATA1_PORT_ID_MASK) |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1703 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1704 | static int bnxt_async_event_process(struct bnxt *bp, |
| 1705 | struct hwrm_async_event_cmpl *cmpl) |
| 1706 | { |
| 1707 | u16 event_id = le16_to_cpu(cmpl->event_id); |
| 1708 | |
| 1709 | /* TODO CHIMP_FW: Define event id's for link change, error etc */ |
| 1710 | switch (event_id) { |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1711 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_SPEED_CFG_CHANGE: { |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1712 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1713 | struct bnxt_link_info *link_info = &bp->link_info; |
| 1714 | |
| 1715 | if (BNXT_VF(bp)) |
| 1716 | goto async_event_process_exit; |
Michael Chan | a8168b6 | 2017-12-06 17:31:22 -0500 | [diff] [blame] | 1717 | |
| 1718 | /* print unsupported speed warning in forced speed mode only */ |
| 1719 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED) && |
| 1720 | (data1 & 0x20000)) { |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1721 | u16 fw_speed = link_info->force_link_speed; |
| 1722 | u32 speed = bnxt_fw_to_ethtool_speed(fw_speed); |
| 1723 | |
Michael Chan | a8168b6 | 2017-12-06 17:31:22 -0500 | [diff] [blame] | 1724 | if (speed != SPEED_UNKNOWN) |
| 1725 | netdev_warn(bp->dev, "Link speed %d no longer supported\n", |
| 1726 | speed); |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1727 | } |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 1728 | set_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, &bp->sp_event); |
Michael Chan | 8cbde11 | 2016-04-11 04:11:14 -0400 | [diff] [blame] | 1729 | /* fall thru */ |
| 1730 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1731 | case ASYNC_EVENT_CMPL_EVENT_ID_LINK_STATUS_CHANGE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1732 | set_bit(BNXT_LINK_CHNG_SP_EVENT, &bp->sp_event); |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1733 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1734 | case ASYNC_EVENT_CMPL_EVENT_ID_PF_DRVR_UNLOAD: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1735 | set_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1736 | break; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1737 | case ASYNC_EVENT_CMPL_EVENT_ID_PORT_CONN_NOT_ALLOWED: { |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1738 | u32 data1 = le32_to_cpu(cmpl->event_data1); |
| 1739 | u16 port_id = BNXT_GET_EVENT_PORT(data1); |
| 1740 | |
| 1741 | if (BNXT_VF(bp)) |
| 1742 | break; |
| 1743 | |
| 1744 | if (bp->pf.port_id != port_id) |
| 1745 | break; |
| 1746 | |
Michael Chan | 4bb13ab | 2016-04-05 14:09:01 -0400 | [diff] [blame] | 1747 | set_bit(BNXT_HWRM_PORT_MODULE_SP_EVENT, &bp->sp_event); |
| 1748 | break; |
| 1749 | } |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 1750 | case ASYNC_EVENT_CMPL_EVENT_ID_VF_CFG_CHANGE: |
Michael Chan | fc0f192 | 2016-06-13 02:25:30 -0400 | [diff] [blame] | 1751 | if (BNXT_PF(bp)) |
| 1752 | goto async_event_process_exit; |
| 1753 | set_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event); |
| 1754 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1755 | default: |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1756 | goto async_event_process_exit; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1757 | } |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1758 | bnxt_queue_sp_work(bp); |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 1759 | async_event_process_exit: |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 1760 | bnxt_ulp_async_events(bp, cmpl); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1761 | return 0; |
| 1762 | } |
| 1763 | |
| 1764 | static int bnxt_hwrm_handler(struct bnxt *bp, struct tx_cmp *txcmp) |
| 1765 | { |
| 1766 | u16 cmpl_type = TX_CMP_TYPE(txcmp), vf_id, seq_id; |
| 1767 | struct hwrm_cmpl *h_cmpl = (struct hwrm_cmpl *)txcmp; |
| 1768 | struct hwrm_fwd_req_cmpl *fwd_req_cmpl = |
| 1769 | (struct hwrm_fwd_req_cmpl *)txcmp; |
| 1770 | |
| 1771 | switch (cmpl_type) { |
| 1772 | case CMPL_BASE_TYPE_HWRM_DONE: |
| 1773 | seq_id = le16_to_cpu(h_cmpl->sequence_id); |
| 1774 | if (seq_id == bp->hwrm_intr_seq_id) |
| 1775 | bp->hwrm_intr_seq_id = HWRM_SEQ_ID_INVALID; |
| 1776 | else |
| 1777 | netdev_err(bp->dev, "Invalid hwrm seq id %d\n", seq_id); |
| 1778 | break; |
| 1779 | |
| 1780 | case CMPL_BASE_TYPE_HWRM_FWD_REQ: |
| 1781 | vf_id = le16_to_cpu(fwd_req_cmpl->source_id); |
| 1782 | |
| 1783 | if ((vf_id < bp->pf.first_vf_id) || |
| 1784 | (vf_id >= bp->pf.first_vf_id + bp->pf.active_vfs)) { |
| 1785 | netdev_err(bp->dev, "Msg contains invalid VF id %x\n", |
| 1786 | vf_id); |
| 1787 | return -EINVAL; |
| 1788 | } |
| 1789 | |
| 1790 | set_bit(vf_id - bp->pf.first_vf_id, bp->pf.vf_event_bmap); |
| 1791 | set_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 1792 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1793 | break; |
| 1794 | |
| 1795 | case CMPL_BASE_TYPE_HWRM_ASYNC_EVENT: |
| 1796 | bnxt_async_event_process(bp, |
| 1797 | (struct hwrm_async_event_cmpl *)txcmp); |
| 1798 | |
| 1799 | default: |
| 1800 | break; |
| 1801 | } |
| 1802 | |
| 1803 | return 0; |
| 1804 | } |
| 1805 | |
| 1806 | static irqreturn_t bnxt_msix(int irq, void *dev_instance) |
| 1807 | { |
| 1808 | struct bnxt_napi *bnapi = dev_instance; |
| 1809 | struct bnxt *bp = bnapi->bp; |
| 1810 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1811 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1812 | |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 1813 | cpr->event_ctr++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1814 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1815 | napi_schedule(&bnapi->napi); |
| 1816 | return IRQ_HANDLED; |
| 1817 | } |
| 1818 | |
| 1819 | static inline int bnxt_has_work(struct bnxt *bp, struct bnxt_cp_ring_info *cpr) |
| 1820 | { |
| 1821 | u32 raw_cons = cpr->cp_raw_cons; |
| 1822 | u16 cons = RING_CMP(raw_cons); |
| 1823 | struct tx_cmp *txcmp; |
| 1824 | |
| 1825 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1826 | |
| 1827 | return TX_CMP_VALID(txcmp, raw_cons); |
| 1828 | } |
| 1829 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1830 | static irqreturn_t bnxt_inta(int irq, void *dev_instance) |
| 1831 | { |
| 1832 | struct bnxt_napi *bnapi = dev_instance; |
| 1833 | struct bnxt *bp = bnapi->bp; |
| 1834 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1835 | u32 cons = RING_CMP(cpr->cp_raw_cons); |
| 1836 | u32 int_status; |
| 1837 | |
| 1838 | prefetch(&cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]); |
| 1839 | |
| 1840 | if (!bnxt_has_work(bp, cpr)) { |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 1841 | int_status = readl(bp->bar0 + BNXT_CAG_REG_LEGACY_INT_STATUS); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1842 | /* return if erroneous interrupt */ |
| 1843 | if (!(int_status & (0x10000 << cpr->cp_ring_struct.fw_ring_id))) |
| 1844 | return IRQ_NONE; |
| 1845 | } |
| 1846 | |
| 1847 | /* disable ring IRQ */ |
| 1848 | BNXT_CP_DB_IRQ_DIS(cpr->cp_doorbell); |
| 1849 | |
| 1850 | /* Return here if interrupt is shared and is disabled. */ |
| 1851 | if (unlikely(atomic_read(&bp->intr_sem) != 0)) |
| 1852 | return IRQ_HANDLED; |
| 1853 | |
| 1854 | napi_schedule(&bnapi->napi); |
| 1855 | return IRQ_HANDLED; |
| 1856 | } |
| 1857 | |
| 1858 | static int bnxt_poll_work(struct bnxt *bp, struct bnxt_napi *bnapi, int budget) |
| 1859 | { |
| 1860 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1861 | u32 raw_cons = cpr->cp_raw_cons; |
| 1862 | u32 cons; |
| 1863 | int tx_pkts = 0; |
| 1864 | int rx_pkts = 0; |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1865 | u8 event = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1866 | struct tx_cmp *txcmp; |
| 1867 | |
| 1868 | while (1) { |
| 1869 | int rc; |
| 1870 | |
| 1871 | cons = RING_CMP(raw_cons); |
| 1872 | txcmp = &cpr->cp_desc_ring[CP_RING(cons)][CP_IDX(cons)]; |
| 1873 | |
| 1874 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1875 | break; |
| 1876 | |
Michael Chan | 67a95e2 | 2016-05-04 16:56:43 -0400 | [diff] [blame] | 1877 | /* The valid test of the entry must be done first before |
| 1878 | * reading any further. |
| 1879 | */ |
Michael Chan | b67daab | 2016-05-15 03:04:51 -0400 | [diff] [blame] | 1880 | dma_rmb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1881 | if (TX_CMP_TYPE(txcmp) == CMP_TYPE_TX_L2_CMP) { |
| 1882 | tx_pkts++; |
| 1883 | /* return full budget so NAPI will complete. */ |
| 1884 | if (unlikely(tx_pkts > bp->tx_wake_thresh)) |
| 1885 | rx_pkts = budget; |
| 1886 | } else if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
Michael Chan | 2270bc5 | 2017-06-23 14:01:01 -0400 | [diff] [blame] | 1887 | if (likely(budget)) |
| 1888 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event); |
| 1889 | else |
| 1890 | rc = bnxt_force_rx_discard(bp, bnapi, &raw_cons, |
| 1891 | &event); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1892 | if (likely(rc >= 0)) |
| 1893 | rx_pkts += rc; |
Michael Chan | 903649e | 2017-08-28 13:40:30 -0400 | [diff] [blame] | 1894 | /* Increment rx_pkts when rc is -ENOMEM to count towards |
| 1895 | * the NAPI budget. Otherwise, we may potentially loop |
| 1896 | * here forever if we consistently cannot allocate |
| 1897 | * buffers. |
| 1898 | */ |
Calvin Owens | 2edbdb3 | 2017-12-08 09:05:26 -0800 | [diff] [blame] | 1899 | else if (rc == -ENOMEM && budget) |
Michael Chan | 903649e | 2017-08-28 13:40:30 -0400 | [diff] [blame] | 1900 | rx_pkts++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1901 | else if (rc == -EBUSY) /* partial completion */ |
| 1902 | break; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1903 | } else if (unlikely((TX_CMP_TYPE(txcmp) == |
| 1904 | CMPL_BASE_TYPE_HWRM_DONE) || |
| 1905 | (TX_CMP_TYPE(txcmp) == |
| 1906 | CMPL_BASE_TYPE_HWRM_FWD_REQ) || |
| 1907 | (TX_CMP_TYPE(txcmp) == |
| 1908 | CMPL_BASE_TYPE_HWRM_ASYNC_EVENT))) { |
| 1909 | bnxt_hwrm_handler(bp, txcmp); |
| 1910 | } |
| 1911 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1912 | |
| 1913 | if (rx_pkts == budget) |
| 1914 | break; |
| 1915 | } |
| 1916 | |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 1917 | if (event & BNXT_TX_EVENT) { |
| 1918 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
| 1919 | void __iomem *db = txr->tx_doorbell; |
| 1920 | u16 prod = txr->tx_prod; |
| 1921 | |
| 1922 | /* Sync BD data before updating doorbell */ |
| 1923 | wmb(); |
| 1924 | |
Sinan Kaya | fd141fa | 2018-03-25 10:39:20 -0400 | [diff] [blame] | 1925 | bnxt_db_write_relaxed(bp, db, DB_KEY_TX | prod); |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 1926 | } |
| 1927 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1928 | cpr->cp_raw_cons = raw_cons; |
| 1929 | /* ACK completion ring before freeing tx ring and producing new |
| 1930 | * buffers in rx/agg rings to prevent overflowing the completion |
| 1931 | * ring. |
| 1932 | */ |
| 1933 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 1934 | |
| 1935 | if (tx_pkts) |
Michael Chan | fa3e93e | 2017-02-06 16:55:41 -0500 | [diff] [blame] | 1936 | bnapi->tx_int(bp, bnapi, tx_pkts); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1937 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1938 | if (event & BNXT_RX_EVENT) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 1939 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1940 | |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 1941 | bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod); |
| 1942 | if (event & BNXT_AGG_EVENT) |
| 1943 | bnxt_db_write(bp, rxr->rx_agg_doorbell, |
| 1944 | DB_KEY_RX | rxr->rx_agg_prod); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 1945 | } |
| 1946 | return rx_pkts; |
| 1947 | } |
| 1948 | |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1949 | static int bnxt_poll_nitroa0(struct napi_struct *napi, int budget) |
| 1950 | { |
| 1951 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 1952 | struct bnxt *bp = bnapi->bp; |
| 1953 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 1954 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
| 1955 | struct tx_cmp *txcmp; |
| 1956 | struct rx_cmp_ext *rxcmp1; |
| 1957 | u32 cp_cons, tmp_raw_cons; |
| 1958 | u32 raw_cons = cpr->cp_raw_cons; |
| 1959 | u32 rx_pkts = 0; |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1960 | u8 event = 0; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1961 | |
| 1962 | while (1) { |
| 1963 | int rc; |
| 1964 | |
| 1965 | cp_cons = RING_CMP(raw_cons); |
| 1966 | txcmp = &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1967 | |
| 1968 | if (!TX_CMP_VALID(txcmp, raw_cons)) |
| 1969 | break; |
| 1970 | |
| 1971 | if ((TX_CMP_TYPE(txcmp) & 0x30) == 0x10) { |
| 1972 | tmp_raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1973 | cp_cons = RING_CMP(tmp_raw_cons); |
| 1974 | rxcmp1 = (struct rx_cmp_ext *) |
| 1975 | &cpr->cp_desc_ring[CP_RING(cp_cons)][CP_IDX(cp_cons)]; |
| 1976 | |
| 1977 | if (!RX_CMP_VALID(rxcmp1, tmp_raw_cons)) |
| 1978 | break; |
| 1979 | |
| 1980 | /* force an error to recycle the buffer */ |
| 1981 | rxcmp1->rx_cmp_cfa_code_errors_v2 |= |
| 1982 | cpu_to_le32(RX_CMPL_ERRORS_CRC_ERROR); |
| 1983 | |
Michael Chan | 4e5dbbda | 2017-02-06 16:55:37 -0500 | [diff] [blame] | 1984 | rc = bnxt_rx_pkt(bp, bnapi, &raw_cons, &event); |
Calvin Owens | 2edbdb3 | 2017-12-08 09:05:26 -0800 | [diff] [blame] | 1985 | if (likely(rc == -EIO) && budget) |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 1986 | rx_pkts++; |
| 1987 | else if (rc == -EBUSY) /* partial completion */ |
| 1988 | break; |
| 1989 | } else if (unlikely(TX_CMP_TYPE(txcmp) == |
| 1990 | CMPL_BASE_TYPE_HWRM_DONE)) { |
| 1991 | bnxt_hwrm_handler(bp, txcmp); |
| 1992 | } else { |
| 1993 | netdev_err(bp->dev, |
| 1994 | "Invalid completion received on special ring\n"); |
| 1995 | } |
| 1996 | raw_cons = NEXT_RAW_CMP(raw_cons); |
| 1997 | |
| 1998 | if (rx_pkts == budget) |
| 1999 | break; |
| 2000 | } |
| 2001 | |
| 2002 | cpr->cp_raw_cons = raw_cons; |
| 2003 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 2004 | bnxt_db_write(bp, rxr->rx_doorbell, DB_KEY_RX | rxr->rx_prod); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2005 | |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 2006 | if (event & BNXT_AGG_EVENT) |
| 2007 | bnxt_db_write(bp, rxr->rx_agg_doorbell, |
| 2008 | DB_KEY_RX | rxr->rx_agg_prod); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2009 | |
| 2010 | if (!bnxt_has_work(bp, cpr) && rx_pkts < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 2011 | napi_complete_done(napi, rx_pkts); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 2012 | BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 2013 | } |
| 2014 | return rx_pkts; |
| 2015 | } |
| 2016 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2017 | static int bnxt_poll(struct napi_struct *napi, int budget) |
| 2018 | { |
| 2019 | struct bnxt_napi *bnapi = container_of(napi, struct bnxt_napi, napi); |
| 2020 | struct bnxt *bp = bnapi->bp; |
| 2021 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 2022 | int work_done = 0; |
| 2023 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2024 | while (1) { |
| 2025 | work_done += bnxt_poll_work(bp, bnapi, budget - work_done); |
| 2026 | |
| 2027 | if (work_done >= budget) |
| 2028 | break; |
| 2029 | |
| 2030 | if (!bnxt_has_work(bp, cpr)) { |
Michael Chan | e7b9569 | 2016-12-29 12:13:32 -0500 | [diff] [blame] | 2031 | if (napi_complete_done(napi, work_done)) |
| 2032 | BNXT_CP_DB_REARM(cpr->cp_doorbell, |
| 2033 | cpr->cp_raw_cons); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2034 | break; |
| 2035 | } |
| 2036 | } |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 2037 | if (bp->flags & BNXT_FLAG_DIM) { |
| 2038 | struct net_dim_sample dim_sample; |
| 2039 | |
| 2040 | net_dim_sample(cpr->event_ctr, |
| 2041 | cpr->rx_packets, |
| 2042 | cpr->rx_bytes, |
| 2043 | &dim_sample); |
| 2044 | net_dim(&cpr->dim, dim_sample); |
| 2045 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2046 | mmiowb(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2047 | return work_done; |
| 2048 | } |
| 2049 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2050 | static void bnxt_free_tx_skbs(struct bnxt *bp) |
| 2051 | { |
| 2052 | int i, max_idx; |
| 2053 | struct pci_dev *pdev = bp->pdev; |
| 2054 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2055 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2056 | return; |
| 2057 | |
| 2058 | max_idx = bp->tx_nr_pages * TX_DESC_CNT; |
| 2059 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2060 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2061 | int j; |
| 2062 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2063 | for (j = 0; j < max_idx;) { |
| 2064 | struct bnxt_sw_tx_bd *tx_buf = &txr->tx_buf_ring[j]; |
| 2065 | struct sk_buff *skb = tx_buf->skb; |
| 2066 | int k, last; |
| 2067 | |
| 2068 | if (!skb) { |
| 2069 | j++; |
| 2070 | continue; |
| 2071 | } |
| 2072 | |
| 2073 | tx_buf->skb = NULL; |
| 2074 | |
| 2075 | if (tx_buf->is_push) { |
| 2076 | dev_kfree_skb(skb); |
| 2077 | j += 2; |
| 2078 | continue; |
| 2079 | } |
| 2080 | |
| 2081 | dma_unmap_single(&pdev->dev, |
| 2082 | dma_unmap_addr(tx_buf, mapping), |
| 2083 | skb_headlen(skb), |
| 2084 | PCI_DMA_TODEVICE); |
| 2085 | |
| 2086 | last = tx_buf->nr_frags; |
| 2087 | j += 2; |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 2088 | for (k = 0; k < last; k++, j++) { |
| 2089 | int ring_idx = j & bp->tx_ring_mask; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2090 | skb_frag_t *frag = &skb_shinfo(skb)->frags[k]; |
| 2091 | |
Michael Chan | d612a57 | 2016-01-28 03:11:22 -0500 | [diff] [blame] | 2092 | tx_buf = &txr->tx_buf_ring[ring_idx]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2093 | dma_unmap_page( |
| 2094 | &pdev->dev, |
| 2095 | dma_unmap_addr(tx_buf, mapping), |
| 2096 | skb_frag_size(frag), PCI_DMA_TODEVICE); |
| 2097 | } |
| 2098 | dev_kfree_skb(skb); |
| 2099 | } |
| 2100 | netdev_tx_reset_queue(netdev_get_tx_queue(bp->dev, i)); |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | static void bnxt_free_rx_skbs(struct bnxt *bp) |
| 2105 | { |
| 2106 | int i, max_idx, max_agg_idx; |
| 2107 | struct pci_dev *pdev = bp->pdev; |
| 2108 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2109 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2110 | return; |
| 2111 | |
| 2112 | max_idx = bp->rx_nr_pages * RX_DESC_CNT; |
| 2113 | max_agg_idx = bp->rx_agg_nr_pages * RX_DESC_CNT; |
| 2114 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2115 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2116 | int j; |
| 2117 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2118 | if (rxr->rx_tpa) { |
| 2119 | for (j = 0; j < MAX_TPA; j++) { |
| 2120 | struct bnxt_tpa_info *tpa_info = |
| 2121 | &rxr->rx_tpa[j]; |
| 2122 | u8 *data = tpa_info->data; |
| 2123 | |
| 2124 | if (!data) |
| 2125 | continue; |
| 2126 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2127 | dma_unmap_single_attrs(&pdev->dev, |
| 2128 | tpa_info->mapping, |
| 2129 | bp->rx_buf_use_size, |
| 2130 | bp->rx_dir, |
| 2131 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2132 | |
| 2133 | tpa_info->data = NULL; |
| 2134 | |
| 2135 | kfree(data); |
| 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | for (j = 0; j < max_idx; j++) { |
| 2140 | struct bnxt_sw_rx_bd *rx_buf = &rxr->rx_buf_ring[j]; |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2141 | dma_addr_t mapping = rx_buf->mapping; |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2142 | void *data = rx_buf->data; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2143 | |
| 2144 | if (!data) |
| 2145 | continue; |
| 2146 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2147 | rx_buf->data = NULL; |
| 2148 | |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2149 | if (BNXT_RX_PAGE_MODE(bp)) { |
| 2150 | mapping -= bp->rx_dma_offset; |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2151 | dma_unmap_page_attrs(&pdev->dev, mapping, |
| 2152 | PAGE_SIZE, bp->rx_dir, |
| 2153 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2154 | __free_page(data); |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2155 | } else { |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2156 | dma_unmap_single_attrs(&pdev->dev, mapping, |
| 2157 | bp->rx_buf_use_size, |
| 2158 | bp->rx_dir, |
| 2159 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2160 | kfree(data); |
Michael Chan | 3ed3a83 | 2017-03-28 19:47:31 -0400 | [diff] [blame] | 2161 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2162 | } |
| 2163 | |
| 2164 | for (j = 0; j < max_agg_idx; j++) { |
| 2165 | struct bnxt_sw_rx_agg_bd *rx_agg_buf = |
| 2166 | &rxr->rx_agg_ring[j]; |
| 2167 | struct page *page = rx_agg_buf->page; |
| 2168 | |
| 2169 | if (!page) |
| 2170 | continue; |
| 2171 | |
Shannon Nelson | c519fe9 | 2017-05-09 18:30:12 -0700 | [diff] [blame] | 2172 | dma_unmap_page_attrs(&pdev->dev, rx_agg_buf->mapping, |
| 2173 | BNXT_RX_PAGE_SIZE, |
| 2174 | PCI_DMA_FROMDEVICE, |
| 2175 | DMA_ATTR_WEAK_ORDERING); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2176 | |
| 2177 | rx_agg_buf->page = NULL; |
| 2178 | __clear_bit(j, rxr->rx_agg_bmap); |
| 2179 | |
| 2180 | __free_page(page); |
| 2181 | } |
Michael Chan | 89d0a06 | 2016-04-25 02:30:51 -0400 | [diff] [blame] | 2182 | if (rxr->rx_page) { |
| 2183 | __free_page(rxr->rx_page); |
| 2184 | rxr->rx_page = NULL; |
| 2185 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | static void bnxt_free_skbs(struct bnxt *bp) |
| 2190 | { |
| 2191 | bnxt_free_tx_skbs(bp); |
| 2192 | bnxt_free_rx_skbs(bp); |
| 2193 | } |
| 2194 | |
| 2195 | static void bnxt_free_ring(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 2196 | { |
| 2197 | struct pci_dev *pdev = bp->pdev; |
| 2198 | int i; |
| 2199 | |
| 2200 | for (i = 0; i < ring->nr_pages; i++) { |
| 2201 | if (!ring->pg_arr[i]) |
| 2202 | continue; |
| 2203 | |
| 2204 | dma_free_coherent(&pdev->dev, ring->page_size, |
| 2205 | ring->pg_arr[i], ring->dma_arr[i]); |
| 2206 | |
| 2207 | ring->pg_arr[i] = NULL; |
| 2208 | } |
| 2209 | if (ring->pg_tbl) { |
| 2210 | dma_free_coherent(&pdev->dev, ring->nr_pages * 8, |
| 2211 | ring->pg_tbl, ring->pg_tbl_map); |
| 2212 | ring->pg_tbl = NULL; |
| 2213 | } |
| 2214 | if (ring->vmem_size && *ring->vmem) { |
| 2215 | vfree(*ring->vmem); |
| 2216 | *ring->vmem = NULL; |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | static int bnxt_alloc_ring(struct bnxt *bp, struct bnxt_ring_struct *ring) |
| 2221 | { |
| 2222 | int i; |
| 2223 | struct pci_dev *pdev = bp->pdev; |
| 2224 | |
| 2225 | if (ring->nr_pages > 1) { |
| 2226 | ring->pg_tbl = dma_alloc_coherent(&pdev->dev, |
| 2227 | ring->nr_pages * 8, |
| 2228 | &ring->pg_tbl_map, |
| 2229 | GFP_KERNEL); |
| 2230 | if (!ring->pg_tbl) |
| 2231 | return -ENOMEM; |
| 2232 | } |
| 2233 | |
| 2234 | for (i = 0; i < ring->nr_pages; i++) { |
| 2235 | ring->pg_arr[i] = dma_alloc_coherent(&pdev->dev, |
| 2236 | ring->page_size, |
| 2237 | &ring->dma_arr[i], |
| 2238 | GFP_KERNEL); |
| 2239 | if (!ring->pg_arr[i]) |
| 2240 | return -ENOMEM; |
| 2241 | |
| 2242 | if (ring->nr_pages > 1) |
| 2243 | ring->pg_tbl[i] = cpu_to_le64(ring->dma_arr[i]); |
| 2244 | } |
| 2245 | |
| 2246 | if (ring->vmem_size) { |
| 2247 | *ring->vmem = vzalloc(ring->vmem_size); |
| 2248 | if (!(*ring->vmem)) |
| 2249 | return -ENOMEM; |
| 2250 | } |
| 2251 | return 0; |
| 2252 | } |
| 2253 | |
| 2254 | static void bnxt_free_rx_rings(struct bnxt *bp) |
| 2255 | { |
| 2256 | int i; |
| 2257 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2258 | if (!bp->rx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2259 | return; |
| 2260 | |
| 2261 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2262 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2263 | struct bnxt_ring_struct *ring; |
| 2264 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2265 | if (rxr->xdp_prog) |
| 2266 | bpf_prog_put(rxr->xdp_prog); |
| 2267 | |
Jesper Dangaard Brouer | 96a8604 | 2018-01-03 11:25:44 +0100 | [diff] [blame] | 2268 | if (xdp_rxq_info_is_reg(&rxr->xdp_rxq)) |
| 2269 | xdp_rxq_info_unreg(&rxr->xdp_rxq); |
| 2270 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2271 | kfree(rxr->rx_tpa); |
| 2272 | rxr->rx_tpa = NULL; |
| 2273 | |
| 2274 | kfree(rxr->rx_agg_bmap); |
| 2275 | rxr->rx_agg_bmap = NULL; |
| 2276 | |
| 2277 | ring = &rxr->rx_ring_struct; |
| 2278 | bnxt_free_ring(bp, ring); |
| 2279 | |
| 2280 | ring = &rxr->rx_agg_ring_struct; |
| 2281 | bnxt_free_ring(bp, ring); |
| 2282 | } |
| 2283 | } |
| 2284 | |
| 2285 | static int bnxt_alloc_rx_rings(struct bnxt *bp) |
| 2286 | { |
| 2287 | int i, rc, agg_rings = 0, tpa_rings = 0; |
| 2288 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2289 | if (!bp->rx_ring) |
| 2290 | return -ENOMEM; |
| 2291 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2292 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 2293 | agg_rings = 1; |
| 2294 | |
| 2295 | if (bp->flags & BNXT_FLAG_TPA) |
| 2296 | tpa_rings = 1; |
| 2297 | |
| 2298 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2299 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2300 | struct bnxt_ring_struct *ring; |
| 2301 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2302 | ring = &rxr->rx_ring_struct; |
| 2303 | |
Jesper Dangaard Brouer | 96a8604 | 2018-01-03 11:25:44 +0100 | [diff] [blame] | 2304 | rc = xdp_rxq_info_reg(&rxr->xdp_rxq, bp->dev, i); |
| 2305 | if (rc < 0) |
| 2306 | return rc; |
| 2307 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2308 | rc = bnxt_alloc_ring(bp, ring); |
| 2309 | if (rc) |
| 2310 | return rc; |
| 2311 | |
| 2312 | if (agg_rings) { |
| 2313 | u16 mem_size; |
| 2314 | |
| 2315 | ring = &rxr->rx_agg_ring_struct; |
| 2316 | rc = bnxt_alloc_ring(bp, ring); |
| 2317 | if (rc) |
| 2318 | return rc; |
| 2319 | |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 2320 | ring->grp_idx = i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2321 | rxr->rx_agg_bmap_size = bp->rx_agg_ring_mask + 1; |
| 2322 | mem_size = rxr->rx_agg_bmap_size / 8; |
| 2323 | rxr->rx_agg_bmap = kzalloc(mem_size, GFP_KERNEL); |
| 2324 | if (!rxr->rx_agg_bmap) |
| 2325 | return -ENOMEM; |
| 2326 | |
| 2327 | if (tpa_rings) { |
| 2328 | rxr->rx_tpa = kcalloc(MAX_TPA, |
| 2329 | sizeof(struct bnxt_tpa_info), |
| 2330 | GFP_KERNEL); |
| 2331 | if (!rxr->rx_tpa) |
| 2332 | return -ENOMEM; |
| 2333 | } |
| 2334 | } |
| 2335 | } |
| 2336 | return 0; |
| 2337 | } |
| 2338 | |
| 2339 | static void bnxt_free_tx_rings(struct bnxt *bp) |
| 2340 | { |
| 2341 | int i; |
| 2342 | struct pci_dev *pdev = bp->pdev; |
| 2343 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2344 | if (!bp->tx_ring) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2345 | return; |
| 2346 | |
| 2347 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2348 | struct bnxt_tx_ring_info *txr = &bp->tx_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 | if (txr->tx_push) { |
| 2352 | dma_free_coherent(&pdev->dev, bp->tx_push_size, |
| 2353 | txr->tx_push, txr->tx_push_mapping); |
| 2354 | txr->tx_push = NULL; |
| 2355 | } |
| 2356 | |
| 2357 | ring = &txr->tx_ring_struct; |
| 2358 | |
| 2359 | bnxt_free_ring(bp, ring); |
| 2360 | } |
| 2361 | } |
| 2362 | |
| 2363 | static int bnxt_alloc_tx_rings(struct bnxt *bp) |
| 2364 | { |
| 2365 | int i, j, rc; |
| 2366 | struct pci_dev *pdev = bp->pdev; |
| 2367 | |
| 2368 | bp->tx_push_size = 0; |
| 2369 | if (bp->tx_push_thresh) { |
| 2370 | int push_size; |
| 2371 | |
| 2372 | push_size = L1_CACHE_ALIGN(sizeof(struct tx_push_bd) + |
| 2373 | bp->tx_push_thresh); |
| 2374 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2375 | if (push_size > 256) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2376 | push_size = 0; |
| 2377 | bp->tx_push_thresh = 0; |
| 2378 | } |
| 2379 | |
| 2380 | bp->tx_push_size = push_size; |
| 2381 | } |
| 2382 | |
| 2383 | for (i = 0, j = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2384 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2385 | struct bnxt_ring_struct *ring; |
| 2386 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2387 | ring = &txr->tx_ring_struct; |
| 2388 | |
| 2389 | rc = bnxt_alloc_ring(bp, ring); |
| 2390 | if (rc) |
| 2391 | return rc; |
| 2392 | |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 2393 | ring->grp_idx = txr->bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2394 | if (bp->tx_push_size) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2395 | dma_addr_t mapping; |
| 2396 | |
| 2397 | /* One pre-allocated DMA buffer to backup |
| 2398 | * TX push operation |
| 2399 | */ |
| 2400 | txr->tx_push = dma_alloc_coherent(&pdev->dev, |
| 2401 | bp->tx_push_size, |
| 2402 | &txr->tx_push_mapping, |
| 2403 | GFP_KERNEL); |
| 2404 | |
| 2405 | if (!txr->tx_push) |
| 2406 | return -ENOMEM; |
| 2407 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2408 | mapping = txr->tx_push_mapping + |
| 2409 | sizeof(struct tx_push_bd); |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2410 | txr->data_mapping = cpu_to_le64(mapping); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2411 | |
Michael Chan | 4419dbe | 2016-02-10 17:33:49 -0500 | [diff] [blame] | 2412 | memset(txr->tx_push, 0, sizeof(struct tx_push_bd)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2413 | } |
| 2414 | ring->queue_id = bp->q_info[j].queue_id; |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 2415 | if (i < bp->tx_nr_rings_xdp) |
| 2416 | continue; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2417 | if (i % bp->tx_nr_rings_per_tc == (bp->tx_nr_rings_per_tc - 1)) |
| 2418 | j++; |
| 2419 | } |
| 2420 | return 0; |
| 2421 | } |
| 2422 | |
| 2423 | static void bnxt_free_cp_rings(struct bnxt *bp) |
| 2424 | { |
| 2425 | int i; |
| 2426 | |
| 2427 | if (!bp->bnapi) |
| 2428 | return; |
| 2429 | |
| 2430 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2431 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2432 | struct bnxt_cp_ring_info *cpr; |
| 2433 | struct bnxt_ring_struct *ring; |
| 2434 | |
| 2435 | if (!bnapi) |
| 2436 | continue; |
| 2437 | |
| 2438 | cpr = &bnapi->cp_ring; |
| 2439 | ring = &cpr->cp_ring_struct; |
| 2440 | |
| 2441 | bnxt_free_ring(bp, ring); |
| 2442 | } |
| 2443 | } |
| 2444 | |
| 2445 | static int bnxt_alloc_cp_rings(struct bnxt *bp) |
| 2446 | { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 2447 | int i, rc, ulp_base_vec, ulp_msix; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2448 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 2449 | ulp_msix = bnxt_get_ulp_msix_num(bp); |
| 2450 | ulp_base_vec = bnxt_get_ulp_msix_base(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2451 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2452 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2453 | struct bnxt_cp_ring_info *cpr; |
| 2454 | struct bnxt_ring_struct *ring; |
| 2455 | |
| 2456 | if (!bnapi) |
| 2457 | continue; |
| 2458 | |
| 2459 | cpr = &bnapi->cp_ring; |
| 2460 | ring = &cpr->cp_ring_struct; |
| 2461 | |
| 2462 | rc = bnxt_alloc_ring(bp, ring); |
| 2463 | if (rc) |
| 2464 | return rc; |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 2465 | |
| 2466 | if (ulp_msix && i >= ulp_base_vec) |
| 2467 | ring->map_idx = i + ulp_msix; |
| 2468 | else |
| 2469 | ring->map_idx = i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2470 | } |
| 2471 | return 0; |
| 2472 | } |
| 2473 | |
| 2474 | static void bnxt_init_ring_struct(struct bnxt *bp) |
| 2475 | { |
| 2476 | int i; |
| 2477 | |
| 2478 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2479 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 2480 | struct bnxt_cp_ring_info *cpr; |
| 2481 | struct bnxt_rx_ring_info *rxr; |
| 2482 | struct bnxt_tx_ring_info *txr; |
| 2483 | struct bnxt_ring_struct *ring; |
| 2484 | |
| 2485 | if (!bnapi) |
| 2486 | continue; |
| 2487 | |
| 2488 | cpr = &bnapi->cp_ring; |
| 2489 | ring = &cpr->cp_ring_struct; |
| 2490 | ring->nr_pages = bp->cp_nr_pages; |
| 2491 | ring->page_size = HW_CMPD_RING_SIZE; |
| 2492 | ring->pg_arr = (void **)cpr->cp_desc_ring; |
| 2493 | ring->dma_arr = cpr->cp_desc_mapping; |
| 2494 | ring->vmem_size = 0; |
| 2495 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2496 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2497 | if (!rxr) |
| 2498 | goto skip_rx; |
| 2499 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2500 | ring = &rxr->rx_ring_struct; |
| 2501 | ring->nr_pages = bp->rx_nr_pages; |
| 2502 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2503 | ring->pg_arr = (void **)rxr->rx_desc_ring; |
| 2504 | ring->dma_arr = rxr->rx_desc_mapping; |
| 2505 | ring->vmem_size = SW_RXBD_RING_SIZE * bp->rx_nr_pages; |
| 2506 | ring->vmem = (void **)&rxr->rx_buf_ring; |
| 2507 | |
| 2508 | ring = &rxr->rx_agg_ring_struct; |
| 2509 | ring->nr_pages = bp->rx_agg_nr_pages; |
| 2510 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2511 | ring->pg_arr = (void **)rxr->rx_agg_desc_ring; |
| 2512 | ring->dma_arr = rxr->rx_agg_desc_mapping; |
| 2513 | ring->vmem_size = SW_RXBD_AGG_RING_SIZE * bp->rx_agg_nr_pages; |
| 2514 | ring->vmem = (void **)&rxr->rx_agg_ring; |
| 2515 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2516 | skip_rx: |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2517 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 2518 | if (!txr) |
| 2519 | continue; |
| 2520 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2521 | ring = &txr->tx_ring_struct; |
| 2522 | ring->nr_pages = bp->tx_nr_pages; |
| 2523 | ring->page_size = HW_RXBD_RING_SIZE; |
| 2524 | ring->pg_arr = (void **)txr->tx_desc_ring; |
| 2525 | ring->dma_arr = txr->tx_desc_mapping; |
| 2526 | ring->vmem_size = SW_TXBD_RING_SIZE * bp->tx_nr_pages; |
| 2527 | ring->vmem = (void **)&txr->tx_buf_ring; |
| 2528 | } |
| 2529 | } |
| 2530 | |
| 2531 | static void bnxt_init_rxbd_pages(struct bnxt_ring_struct *ring, u32 type) |
| 2532 | { |
| 2533 | int i; |
| 2534 | u32 prod; |
| 2535 | struct rx_bd **rx_buf_ring; |
| 2536 | |
| 2537 | rx_buf_ring = (struct rx_bd **)ring->pg_arr; |
| 2538 | for (i = 0, prod = 0; i < ring->nr_pages; i++) { |
| 2539 | int j; |
| 2540 | struct rx_bd *rxbd; |
| 2541 | |
| 2542 | rxbd = rx_buf_ring[i]; |
| 2543 | if (!rxbd) |
| 2544 | continue; |
| 2545 | |
| 2546 | for (j = 0; j < RX_DESC_CNT; j++, rxbd++, prod++) { |
| 2547 | rxbd->rx_bd_len_flags_type = cpu_to_le32(type); |
| 2548 | rxbd->rx_bd_opaque = prod; |
| 2549 | } |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | static int bnxt_init_one_rx_ring(struct bnxt *bp, int ring_nr) |
| 2554 | { |
| 2555 | struct net_device *dev = bp->dev; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2556 | struct bnxt_rx_ring_info *rxr; |
| 2557 | struct bnxt_ring_struct *ring; |
| 2558 | u32 prod, type; |
| 2559 | int i; |
| 2560 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2561 | type = (bp->rx_buf_use_size << RX_BD_LEN_SHIFT) | |
| 2562 | RX_BD_TYPE_RX_PACKET_BD | RX_BD_FLAGS_EOP; |
| 2563 | |
| 2564 | if (NET_IP_ALIGN == 2) |
| 2565 | type |= RX_BD_FLAGS_SOP; |
| 2566 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2567 | rxr = &bp->rx_ring[ring_nr]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2568 | ring = &rxr->rx_ring_struct; |
| 2569 | bnxt_init_rxbd_pages(ring, type); |
| 2570 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2571 | if (BNXT_RX_PAGE_MODE(bp) && bp->xdp_prog) { |
| 2572 | rxr->xdp_prog = bpf_prog_add(bp->xdp_prog, 1); |
| 2573 | if (IS_ERR(rxr->xdp_prog)) { |
| 2574 | int rc = PTR_ERR(rxr->xdp_prog); |
| 2575 | |
| 2576 | rxr->xdp_prog = NULL; |
| 2577 | return rc; |
| 2578 | } |
| 2579 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2580 | prod = rxr->rx_prod; |
| 2581 | for (i = 0; i < bp->rx_ring_size; i++) { |
| 2582 | if (bnxt_alloc_rx_data(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2583 | netdev_warn(dev, "init'ed rx ring %d with %d/%d skbs only\n", |
| 2584 | ring_nr, i, bp->rx_ring_size); |
| 2585 | break; |
| 2586 | } |
| 2587 | prod = NEXT_RX(prod); |
| 2588 | } |
| 2589 | rxr->rx_prod = prod; |
| 2590 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2591 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 2592 | ring = &rxr->rx_agg_ring_struct; |
| 2593 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2594 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2595 | if (!(bp->flags & BNXT_FLAG_AGG_RINGS)) |
| 2596 | return 0; |
| 2597 | |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2598 | type = ((u32)BNXT_RX_PAGE_SIZE << RX_BD_LEN_SHIFT) | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2599 | RX_BD_TYPE_RX_AGG_BD | RX_BD_FLAGS_SOP; |
| 2600 | |
| 2601 | bnxt_init_rxbd_pages(ring, type); |
| 2602 | |
| 2603 | prod = rxr->rx_agg_prod; |
| 2604 | for (i = 0; i < bp->rx_agg_ring_size; i++) { |
| 2605 | if (bnxt_alloc_rx_page(bp, rxr, prod, GFP_KERNEL) != 0) { |
| 2606 | netdev_warn(dev, "init'ed rx ring %d with %d/%d pages only\n", |
| 2607 | ring_nr, i, bp->rx_ring_size); |
| 2608 | break; |
| 2609 | } |
| 2610 | prod = NEXT_RX_AGG(prod); |
| 2611 | } |
| 2612 | rxr->rx_agg_prod = prod; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2613 | |
| 2614 | if (bp->flags & BNXT_FLAG_TPA) { |
| 2615 | if (rxr->rx_tpa) { |
| 2616 | u8 *data; |
| 2617 | dma_addr_t mapping; |
| 2618 | |
| 2619 | for (i = 0; i < MAX_TPA; i++) { |
| 2620 | data = __bnxt_alloc_rx_data(bp, &mapping, |
| 2621 | GFP_KERNEL); |
| 2622 | if (!data) |
| 2623 | return -ENOMEM; |
| 2624 | |
| 2625 | rxr->rx_tpa[i].data = data; |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 2626 | rxr->rx_tpa[i].data_ptr = data + bp->rx_offset; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2627 | rxr->rx_tpa[i].mapping = mapping; |
| 2628 | } |
| 2629 | } else { |
| 2630 | netdev_err(bp->dev, "No resource allocated for LRO/GRO\n"); |
| 2631 | return -ENOMEM; |
| 2632 | } |
| 2633 | } |
| 2634 | |
| 2635 | return 0; |
| 2636 | } |
| 2637 | |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 2638 | static void bnxt_init_cp_rings(struct bnxt *bp) |
| 2639 | { |
| 2640 | int i; |
| 2641 | |
| 2642 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2643 | struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; |
| 2644 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
| 2645 | |
| 2646 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 2647 | cpr->rx_ring_coal.coal_ticks = bp->rx_coal.coal_ticks; |
| 2648 | cpr->rx_ring_coal.coal_bufs = bp->rx_coal.coal_bufs; |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 2649 | } |
| 2650 | } |
| 2651 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2652 | static int bnxt_init_rx_rings(struct bnxt *bp) |
| 2653 | { |
| 2654 | int i, rc = 0; |
| 2655 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2656 | if (BNXT_RX_PAGE_MODE(bp)) { |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2657 | bp->rx_offset = NET_IP_ALIGN + XDP_PACKET_HEADROOM; |
| 2658 | bp->rx_dma_offset = XDP_PACKET_HEADROOM; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2659 | } else { |
| 2660 | bp->rx_offset = BNXT_RX_OFFSET; |
| 2661 | bp->rx_dma_offset = BNXT_RX_DMA_OFFSET; |
| 2662 | } |
Michael Chan | b3dba77 | 2017-02-06 16:55:35 -0500 | [diff] [blame] | 2663 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2664 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 2665 | rc = bnxt_init_one_rx_ring(bp, i); |
| 2666 | if (rc) |
| 2667 | break; |
| 2668 | } |
| 2669 | |
| 2670 | return rc; |
| 2671 | } |
| 2672 | |
| 2673 | static int bnxt_init_tx_rings(struct bnxt *bp) |
| 2674 | { |
| 2675 | u16 i; |
| 2676 | |
| 2677 | bp->tx_wake_thresh = max_t(int, bp->tx_ring_size / 2, |
| 2678 | MAX_SKB_FRAGS + 1); |
| 2679 | |
| 2680 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 2681 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2682 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
| 2683 | |
| 2684 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 2685 | } |
| 2686 | |
| 2687 | return 0; |
| 2688 | } |
| 2689 | |
| 2690 | static void bnxt_free_ring_grps(struct bnxt *bp) |
| 2691 | { |
| 2692 | kfree(bp->grp_info); |
| 2693 | bp->grp_info = NULL; |
| 2694 | } |
| 2695 | |
| 2696 | static int bnxt_init_ring_grps(struct bnxt *bp, bool irq_re_init) |
| 2697 | { |
| 2698 | int i; |
| 2699 | |
| 2700 | if (irq_re_init) { |
| 2701 | bp->grp_info = kcalloc(bp->cp_nr_rings, |
| 2702 | sizeof(struct bnxt_ring_grp_info), |
| 2703 | GFP_KERNEL); |
| 2704 | if (!bp->grp_info) |
| 2705 | return -ENOMEM; |
| 2706 | } |
| 2707 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 2708 | if (irq_re_init) |
| 2709 | bp->grp_info[i].fw_stats_ctx = INVALID_HW_RING_ID; |
| 2710 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 2711 | bp->grp_info[i].rx_fw_ring_id = INVALID_HW_RING_ID; |
| 2712 | bp->grp_info[i].agg_fw_ring_id = INVALID_HW_RING_ID; |
| 2713 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
| 2714 | } |
| 2715 | return 0; |
| 2716 | } |
| 2717 | |
| 2718 | static void bnxt_free_vnics(struct bnxt *bp) |
| 2719 | { |
| 2720 | kfree(bp->vnic_info); |
| 2721 | bp->vnic_info = NULL; |
| 2722 | bp->nr_vnics = 0; |
| 2723 | } |
| 2724 | |
| 2725 | static int bnxt_alloc_vnics(struct bnxt *bp) |
| 2726 | { |
| 2727 | int num_vnics = 1; |
| 2728 | |
| 2729 | #ifdef CONFIG_RFS_ACCEL |
| 2730 | if (bp->flags & BNXT_FLAG_RFS) |
| 2731 | num_vnics += bp->rx_nr_rings; |
| 2732 | #endif |
| 2733 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 2734 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 2735 | num_vnics++; |
| 2736 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2737 | bp->vnic_info = kcalloc(num_vnics, sizeof(struct bnxt_vnic_info), |
| 2738 | GFP_KERNEL); |
| 2739 | if (!bp->vnic_info) |
| 2740 | return -ENOMEM; |
| 2741 | |
| 2742 | bp->nr_vnics = num_vnics; |
| 2743 | return 0; |
| 2744 | } |
| 2745 | |
| 2746 | static void bnxt_init_vnics(struct bnxt *bp) |
| 2747 | { |
| 2748 | int i; |
| 2749 | |
| 2750 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2751 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 2752 | |
| 2753 | vnic->fw_vnic_id = INVALID_HW_RING_ID; |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 2754 | vnic->fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 2755 | vnic->fw_rss_cos_lb_ctx[1] = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2756 | vnic->fw_l2_ctx_id = INVALID_HW_RING_ID; |
| 2757 | |
| 2758 | if (bp->vnic_info[i].rss_hash_key) { |
| 2759 | if (i == 0) |
| 2760 | prandom_bytes(vnic->rss_hash_key, |
| 2761 | HW_HASH_KEY_SIZE); |
| 2762 | else |
| 2763 | memcpy(vnic->rss_hash_key, |
| 2764 | bp->vnic_info[0].rss_hash_key, |
| 2765 | HW_HASH_KEY_SIZE); |
| 2766 | } |
| 2767 | } |
| 2768 | } |
| 2769 | |
| 2770 | static int bnxt_calc_nr_ring_pages(u32 ring_size, int desc_per_pg) |
| 2771 | { |
| 2772 | int pages; |
| 2773 | |
| 2774 | pages = ring_size / desc_per_pg; |
| 2775 | |
| 2776 | if (!pages) |
| 2777 | return 1; |
| 2778 | |
| 2779 | pages++; |
| 2780 | |
| 2781 | while (pages & (pages - 1)) |
| 2782 | pages++; |
| 2783 | |
| 2784 | return pages; |
| 2785 | } |
| 2786 | |
Michael Chan | c6d30e8 | 2017-02-06 16:55:42 -0500 | [diff] [blame] | 2787 | void bnxt_set_tpa_flags(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2788 | { |
| 2789 | bp->flags &= ~BNXT_FLAG_TPA; |
Michael Chan | 341138c | 2017-01-13 01:32:01 -0500 | [diff] [blame] | 2790 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 2791 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2792 | if (bp->dev->features & NETIF_F_LRO) |
| 2793 | bp->flags |= BNXT_FLAG_LRO; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 2794 | else if (bp->dev->features & NETIF_F_GRO_HW) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2795 | bp->flags |= BNXT_FLAG_GRO; |
| 2796 | } |
| 2797 | |
| 2798 | /* bp->rx_ring_size, bp->tx_ring_size, dev->mtu, BNXT_FLAG_{G|L}RO flags must |
| 2799 | * be set on entry. |
| 2800 | */ |
| 2801 | void bnxt_set_ring_params(struct bnxt *bp) |
| 2802 | { |
| 2803 | u32 ring_size, rx_size, rx_space; |
| 2804 | u32 agg_factor = 0, agg_ring_size = 0; |
| 2805 | |
| 2806 | /* 8 for CRC and VLAN */ |
| 2807 | rx_size = SKB_DATA_ALIGN(bp->dev->mtu + ETH_HLEN + NET_IP_ALIGN + 8); |
| 2808 | |
| 2809 | rx_space = rx_size + NET_SKB_PAD + |
| 2810 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2811 | |
| 2812 | bp->rx_copy_thresh = BNXT_RX_COPY_THRESH; |
| 2813 | ring_size = bp->rx_ring_size; |
| 2814 | bp->rx_agg_ring_size = 0; |
| 2815 | bp->rx_agg_nr_pages = 0; |
| 2816 | |
| 2817 | if (bp->flags & BNXT_FLAG_TPA) |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 2818 | agg_factor = min_t(u32, 4, 65536 / BNXT_RX_PAGE_SIZE); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2819 | |
| 2820 | bp->flags &= ~BNXT_FLAG_JUMBO; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 2821 | if (rx_space > PAGE_SIZE && !(bp->flags & BNXT_FLAG_NO_AGG_RINGS)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2822 | u32 jumbo_factor; |
| 2823 | |
| 2824 | bp->flags |= BNXT_FLAG_JUMBO; |
| 2825 | jumbo_factor = PAGE_ALIGN(bp->dev->mtu - 40) >> PAGE_SHIFT; |
| 2826 | if (jumbo_factor > agg_factor) |
| 2827 | agg_factor = jumbo_factor; |
| 2828 | } |
| 2829 | agg_ring_size = ring_size * agg_factor; |
| 2830 | |
| 2831 | if (agg_ring_size) { |
| 2832 | bp->rx_agg_nr_pages = bnxt_calc_nr_ring_pages(agg_ring_size, |
| 2833 | RX_DESC_CNT); |
| 2834 | if (bp->rx_agg_nr_pages > MAX_RX_AGG_PAGES) { |
| 2835 | u32 tmp = agg_ring_size; |
| 2836 | |
| 2837 | bp->rx_agg_nr_pages = MAX_RX_AGG_PAGES; |
| 2838 | agg_ring_size = MAX_RX_AGG_PAGES * RX_DESC_CNT - 1; |
| 2839 | netdev_warn(bp->dev, "rx agg ring size %d reduced to %d.\n", |
| 2840 | tmp, agg_ring_size); |
| 2841 | } |
| 2842 | bp->rx_agg_ring_size = agg_ring_size; |
| 2843 | bp->rx_agg_ring_mask = (bp->rx_agg_nr_pages * RX_DESC_CNT) - 1; |
| 2844 | rx_size = SKB_DATA_ALIGN(BNXT_RX_COPY_THRESH + NET_IP_ALIGN); |
| 2845 | rx_space = rx_size + NET_SKB_PAD + |
| 2846 | SKB_DATA_ALIGN(sizeof(struct skb_shared_info)); |
| 2847 | } |
| 2848 | |
| 2849 | bp->rx_buf_use_size = rx_size; |
| 2850 | bp->rx_buf_size = rx_space; |
| 2851 | |
| 2852 | bp->rx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, RX_DESC_CNT); |
| 2853 | bp->rx_ring_mask = (bp->rx_nr_pages * RX_DESC_CNT) - 1; |
| 2854 | |
| 2855 | ring_size = bp->tx_ring_size; |
| 2856 | bp->tx_nr_pages = bnxt_calc_nr_ring_pages(ring_size, TX_DESC_CNT); |
| 2857 | bp->tx_ring_mask = (bp->tx_nr_pages * TX_DESC_CNT) - 1; |
| 2858 | |
| 2859 | ring_size = bp->rx_ring_size * (2 + agg_factor) + bp->tx_ring_size; |
| 2860 | bp->cp_ring_size = ring_size; |
| 2861 | |
| 2862 | bp->cp_nr_pages = bnxt_calc_nr_ring_pages(ring_size, CP_DESC_CNT); |
| 2863 | if (bp->cp_nr_pages > MAX_CP_PAGES) { |
| 2864 | bp->cp_nr_pages = MAX_CP_PAGES; |
| 2865 | bp->cp_ring_size = MAX_CP_PAGES * CP_DESC_CNT - 1; |
| 2866 | netdev_warn(bp->dev, "completion ring size %d reduced to %d.\n", |
| 2867 | ring_size, bp->cp_ring_size); |
| 2868 | } |
| 2869 | bp->cp_bit = bp->cp_nr_pages * CP_DESC_CNT; |
| 2870 | bp->cp_ring_mask = bp->cp_bit - 1; |
| 2871 | } |
| 2872 | |
Jesper Dangaard Brouer | 96a8604 | 2018-01-03 11:25:44 +0100 | [diff] [blame] | 2873 | /* Changing allocation mode of RX rings. |
| 2874 | * TODO: Update when extending xdp_rxq_info to support allocation modes. |
| 2875 | */ |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2876 | int bnxt_set_rx_skb_mode(struct bnxt *bp, bool page_mode) |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2877 | { |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2878 | if (page_mode) { |
| 2879 | if (bp->dev->mtu > BNXT_MAX_PAGE_MODE_MTU) |
| 2880 | return -EOPNOTSUPP; |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 2881 | bp->dev->max_mtu = |
| 2882 | min_t(u16, bp->max_mtu, BNXT_MAX_PAGE_MODE_MTU); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2883 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 2884 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS | BNXT_FLAG_RX_PAGE_MODE; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2885 | bp->rx_dir = DMA_BIDIRECTIONAL; |
| 2886 | bp->rx_skb_func = bnxt_rx_page_skb; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 2887 | /* Disable LRO or GRO_HW */ |
| 2888 | netdev_update_features(bp->dev); |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2889 | } else { |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 2890 | bp->dev->max_mtu = bp->max_mtu; |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 2891 | bp->flags &= ~BNXT_FLAG_RX_PAGE_MODE; |
| 2892 | bp->rx_dir = DMA_FROM_DEVICE; |
| 2893 | bp->rx_skb_func = bnxt_rx_skb; |
| 2894 | } |
Michael Chan | 6bb1947 | 2017-02-06 16:55:32 -0500 | [diff] [blame] | 2895 | return 0; |
| 2896 | } |
| 2897 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2898 | static void bnxt_free_vnic_attributes(struct bnxt *bp) |
| 2899 | { |
| 2900 | int i; |
| 2901 | struct bnxt_vnic_info *vnic; |
| 2902 | struct pci_dev *pdev = bp->pdev; |
| 2903 | |
| 2904 | if (!bp->vnic_info) |
| 2905 | return; |
| 2906 | |
| 2907 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2908 | vnic = &bp->vnic_info[i]; |
| 2909 | |
| 2910 | kfree(vnic->fw_grp_ids); |
| 2911 | vnic->fw_grp_ids = NULL; |
| 2912 | |
| 2913 | kfree(vnic->uc_list); |
| 2914 | vnic->uc_list = NULL; |
| 2915 | |
| 2916 | if (vnic->mc_list) { |
| 2917 | dma_free_coherent(&pdev->dev, vnic->mc_list_size, |
| 2918 | vnic->mc_list, vnic->mc_list_mapping); |
| 2919 | vnic->mc_list = NULL; |
| 2920 | } |
| 2921 | |
| 2922 | if (vnic->rss_table) { |
| 2923 | dma_free_coherent(&pdev->dev, PAGE_SIZE, |
| 2924 | vnic->rss_table, |
| 2925 | vnic->rss_table_dma_addr); |
| 2926 | vnic->rss_table = NULL; |
| 2927 | } |
| 2928 | |
| 2929 | vnic->rss_hash_key = NULL; |
| 2930 | vnic->flags = 0; |
| 2931 | } |
| 2932 | } |
| 2933 | |
| 2934 | static int bnxt_alloc_vnic_attributes(struct bnxt *bp) |
| 2935 | { |
| 2936 | int i, rc = 0, size; |
| 2937 | struct bnxt_vnic_info *vnic; |
| 2938 | struct pci_dev *pdev = bp->pdev; |
| 2939 | int max_rings; |
| 2940 | |
| 2941 | for (i = 0; i < bp->nr_vnics; i++) { |
| 2942 | vnic = &bp->vnic_info[i]; |
| 2943 | |
| 2944 | if (vnic->flags & BNXT_VNIC_UCAST_FLAG) { |
| 2945 | int mem_size = (BNXT_MAX_UC_ADDRS - 1) * ETH_ALEN; |
| 2946 | |
| 2947 | if (mem_size > 0) { |
| 2948 | vnic->uc_list = kmalloc(mem_size, GFP_KERNEL); |
| 2949 | if (!vnic->uc_list) { |
| 2950 | rc = -ENOMEM; |
| 2951 | goto out; |
| 2952 | } |
| 2953 | } |
| 2954 | } |
| 2955 | |
| 2956 | if (vnic->flags & BNXT_VNIC_MCAST_FLAG) { |
| 2957 | vnic->mc_list_size = BNXT_MAX_MC_ADDRS * ETH_ALEN; |
| 2958 | vnic->mc_list = |
| 2959 | dma_alloc_coherent(&pdev->dev, |
| 2960 | vnic->mc_list_size, |
| 2961 | &vnic->mc_list_mapping, |
| 2962 | GFP_KERNEL); |
| 2963 | if (!vnic->mc_list) { |
| 2964 | rc = -ENOMEM; |
| 2965 | goto out; |
| 2966 | } |
| 2967 | } |
| 2968 | |
| 2969 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
| 2970 | max_rings = bp->rx_nr_rings; |
| 2971 | else |
| 2972 | max_rings = 1; |
| 2973 | |
| 2974 | vnic->fw_grp_ids = kcalloc(max_rings, sizeof(u16), GFP_KERNEL); |
| 2975 | if (!vnic->fw_grp_ids) { |
| 2976 | rc = -ENOMEM; |
| 2977 | goto out; |
| 2978 | } |
| 2979 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 2980 | if ((bp->flags & BNXT_FLAG_NEW_RSS_CAP) && |
| 2981 | !(vnic->flags & BNXT_VNIC_RSS_FLAG)) |
| 2982 | continue; |
| 2983 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 2984 | /* Allocate rss table and hash key */ |
| 2985 | vnic->rss_table = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 2986 | &vnic->rss_table_dma_addr, |
| 2987 | GFP_KERNEL); |
| 2988 | if (!vnic->rss_table) { |
| 2989 | rc = -ENOMEM; |
| 2990 | goto out; |
| 2991 | } |
| 2992 | |
| 2993 | size = L1_CACHE_ALIGN(HW_HASH_INDEX_SIZE * sizeof(u16)); |
| 2994 | |
| 2995 | vnic->rss_hash_key = ((void *)vnic->rss_table) + size; |
| 2996 | vnic->rss_hash_key_dma_addr = vnic->rss_table_dma_addr + size; |
| 2997 | } |
| 2998 | return 0; |
| 2999 | |
| 3000 | out: |
| 3001 | return rc; |
| 3002 | } |
| 3003 | |
| 3004 | static void bnxt_free_hwrm_resources(struct bnxt *bp) |
| 3005 | { |
| 3006 | struct pci_dev *pdev = bp->pdev; |
| 3007 | |
| 3008 | dma_free_coherent(&pdev->dev, PAGE_SIZE, bp->hwrm_cmd_resp_addr, |
| 3009 | bp->hwrm_cmd_resp_dma_addr); |
| 3010 | |
| 3011 | bp->hwrm_cmd_resp_addr = NULL; |
| 3012 | if (bp->hwrm_dbg_resp_addr) { |
| 3013 | dma_free_coherent(&pdev->dev, HWRM_DBG_REG_BUF_SIZE, |
| 3014 | bp->hwrm_dbg_resp_addr, |
| 3015 | bp->hwrm_dbg_resp_dma_addr); |
| 3016 | |
| 3017 | bp->hwrm_dbg_resp_addr = NULL; |
| 3018 | } |
| 3019 | } |
| 3020 | |
| 3021 | static int bnxt_alloc_hwrm_resources(struct bnxt *bp) |
| 3022 | { |
| 3023 | struct pci_dev *pdev = bp->pdev; |
| 3024 | |
| 3025 | bp->hwrm_cmd_resp_addr = dma_alloc_coherent(&pdev->dev, PAGE_SIZE, |
| 3026 | &bp->hwrm_cmd_resp_dma_addr, |
| 3027 | GFP_KERNEL); |
| 3028 | if (!bp->hwrm_cmd_resp_addr) |
| 3029 | return -ENOMEM; |
| 3030 | bp->hwrm_dbg_resp_addr = dma_alloc_coherent(&pdev->dev, |
| 3031 | HWRM_DBG_REG_BUF_SIZE, |
| 3032 | &bp->hwrm_dbg_resp_dma_addr, |
| 3033 | GFP_KERNEL); |
| 3034 | if (!bp->hwrm_dbg_resp_addr) |
| 3035 | netdev_warn(bp->dev, "fail to alloc debug register dma mem\n"); |
| 3036 | |
| 3037 | return 0; |
| 3038 | } |
| 3039 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3040 | static void bnxt_free_hwrm_short_cmd_req(struct bnxt *bp) |
| 3041 | { |
| 3042 | if (bp->hwrm_short_cmd_req_addr) { |
| 3043 | struct pci_dev *pdev = bp->pdev; |
| 3044 | |
| 3045 | dma_free_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN, |
| 3046 | bp->hwrm_short_cmd_req_addr, |
| 3047 | bp->hwrm_short_cmd_req_dma_addr); |
| 3048 | bp->hwrm_short_cmd_req_addr = NULL; |
| 3049 | } |
| 3050 | } |
| 3051 | |
| 3052 | static int bnxt_alloc_hwrm_short_cmd_req(struct bnxt *bp) |
| 3053 | { |
| 3054 | struct pci_dev *pdev = bp->pdev; |
| 3055 | |
| 3056 | bp->hwrm_short_cmd_req_addr = |
| 3057 | dma_alloc_coherent(&pdev->dev, BNXT_HWRM_MAX_REQ_LEN, |
| 3058 | &bp->hwrm_short_cmd_req_dma_addr, |
| 3059 | GFP_KERNEL); |
| 3060 | if (!bp->hwrm_short_cmd_req_addr) |
| 3061 | return -ENOMEM; |
| 3062 | |
| 3063 | return 0; |
| 3064 | } |
| 3065 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3066 | static void bnxt_free_stats(struct bnxt *bp) |
| 3067 | { |
| 3068 | u32 size, i; |
| 3069 | struct pci_dev *pdev = bp->pdev; |
| 3070 | |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3071 | bp->flags &= ~BNXT_FLAG_PORT_STATS; |
| 3072 | bp->flags &= ~BNXT_FLAG_PORT_STATS_EXT; |
| 3073 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3074 | if (bp->hw_rx_port_stats) { |
| 3075 | dma_free_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 3076 | bp->hw_rx_port_stats, |
| 3077 | bp->hw_rx_port_stats_map); |
| 3078 | bp->hw_rx_port_stats = NULL; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | if (bp->hw_rx_port_stats_ext) { |
| 3082 | dma_free_coherent(&pdev->dev, sizeof(struct rx_port_stats_ext), |
| 3083 | bp->hw_rx_port_stats_ext, |
| 3084 | bp->hw_rx_port_stats_ext_map); |
| 3085 | bp->hw_rx_port_stats_ext = NULL; |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3086 | } |
| 3087 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3088 | if (!bp->bnapi) |
| 3089 | return; |
| 3090 | |
| 3091 | size = sizeof(struct ctx_hw_stats); |
| 3092 | |
| 3093 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3094 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3095 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3096 | |
| 3097 | if (cpr->hw_stats) { |
| 3098 | dma_free_coherent(&pdev->dev, size, cpr->hw_stats, |
| 3099 | cpr->hw_stats_map); |
| 3100 | cpr->hw_stats = NULL; |
| 3101 | } |
| 3102 | } |
| 3103 | } |
| 3104 | |
| 3105 | static int bnxt_alloc_stats(struct bnxt *bp) |
| 3106 | { |
| 3107 | u32 size, i; |
| 3108 | struct pci_dev *pdev = bp->pdev; |
| 3109 | |
| 3110 | size = sizeof(struct ctx_hw_stats); |
| 3111 | |
| 3112 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3113 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3114 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3115 | |
| 3116 | cpr->hw_stats = dma_alloc_coherent(&pdev->dev, size, |
| 3117 | &cpr->hw_stats_map, |
| 3118 | GFP_KERNEL); |
| 3119 | if (!cpr->hw_stats) |
| 3120 | return -ENOMEM; |
| 3121 | |
| 3122 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 3123 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3124 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 3125 | if (BNXT_PF(bp) && bp->chip_num != CHIP_NUM_58700) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3126 | bp->hw_port_stats_size = sizeof(struct rx_port_stats) + |
| 3127 | sizeof(struct tx_port_stats) + 1024; |
| 3128 | |
| 3129 | bp->hw_rx_port_stats = |
| 3130 | dma_alloc_coherent(&pdev->dev, bp->hw_port_stats_size, |
| 3131 | &bp->hw_rx_port_stats_map, |
| 3132 | GFP_KERNEL); |
| 3133 | if (!bp->hw_rx_port_stats) |
| 3134 | return -ENOMEM; |
| 3135 | |
| 3136 | bp->hw_tx_port_stats = (void *)(bp->hw_rx_port_stats + 1) + |
| 3137 | 512; |
| 3138 | bp->hw_tx_port_stats_map = bp->hw_rx_port_stats_map + |
| 3139 | sizeof(struct rx_port_stats) + 512; |
| 3140 | bp->flags |= BNXT_FLAG_PORT_STATS; |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 3141 | |
| 3142 | /* Display extended statistics only if FW supports it */ |
| 3143 | if (bp->hwrm_spec_code < 0x10804 || |
| 3144 | bp->hwrm_spec_code == 0x10900) |
| 3145 | return 0; |
| 3146 | |
| 3147 | bp->hw_rx_port_stats_ext = |
| 3148 | dma_zalloc_coherent(&pdev->dev, |
| 3149 | sizeof(struct rx_port_stats_ext), |
| 3150 | &bp->hw_rx_port_stats_ext_map, |
| 3151 | GFP_KERNEL); |
| 3152 | if (!bp->hw_rx_port_stats_ext) |
| 3153 | return 0; |
| 3154 | |
| 3155 | bp->flags |= BNXT_FLAG_PORT_STATS_EXT; |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 3156 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3157 | return 0; |
| 3158 | } |
| 3159 | |
| 3160 | static void bnxt_clear_ring_indices(struct bnxt *bp) |
| 3161 | { |
| 3162 | int i; |
| 3163 | |
| 3164 | if (!bp->bnapi) |
| 3165 | return; |
| 3166 | |
| 3167 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3168 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3169 | struct bnxt_cp_ring_info *cpr; |
| 3170 | struct bnxt_rx_ring_info *rxr; |
| 3171 | struct bnxt_tx_ring_info *txr; |
| 3172 | |
| 3173 | if (!bnapi) |
| 3174 | continue; |
| 3175 | |
| 3176 | cpr = &bnapi->cp_ring; |
| 3177 | cpr->cp_raw_cons = 0; |
| 3178 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3179 | txr = bnapi->tx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 3180 | if (txr) { |
| 3181 | txr->tx_prod = 0; |
| 3182 | txr->tx_cons = 0; |
| 3183 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3184 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3185 | rxr = bnapi->rx_ring; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 3186 | if (rxr) { |
| 3187 | rxr->rx_prod = 0; |
| 3188 | rxr->rx_agg_prod = 0; |
| 3189 | rxr->rx_sw_agg_prod = 0; |
Michael Chan | 376a5b8 | 2016-05-10 19:17:59 -0400 | [diff] [blame] | 3190 | rxr->rx_next_cons = 0; |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 3191 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3192 | } |
| 3193 | } |
| 3194 | |
| 3195 | static void bnxt_free_ntp_fltrs(struct bnxt *bp, bool irq_reinit) |
| 3196 | { |
| 3197 | #ifdef CONFIG_RFS_ACCEL |
| 3198 | int i; |
| 3199 | |
| 3200 | /* Under rtnl_lock and all our NAPIs have been disabled. It's |
| 3201 | * safe to delete the hash table. |
| 3202 | */ |
| 3203 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 3204 | struct hlist_head *head; |
| 3205 | struct hlist_node *tmp; |
| 3206 | struct bnxt_ntuple_filter *fltr; |
| 3207 | |
| 3208 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 3209 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 3210 | hlist_del(&fltr->hash); |
| 3211 | kfree(fltr); |
| 3212 | } |
| 3213 | } |
| 3214 | if (irq_reinit) { |
| 3215 | kfree(bp->ntp_fltr_bmap); |
| 3216 | bp->ntp_fltr_bmap = NULL; |
| 3217 | } |
| 3218 | bp->ntp_fltr_count = 0; |
| 3219 | #endif |
| 3220 | } |
| 3221 | |
| 3222 | static int bnxt_alloc_ntp_fltrs(struct bnxt *bp) |
| 3223 | { |
| 3224 | #ifdef CONFIG_RFS_ACCEL |
| 3225 | int i, rc = 0; |
| 3226 | |
| 3227 | if (!(bp->flags & BNXT_FLAG_RFS)) |
| 3228 | return 0; |
| 3229 | |
| 3230 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) |
| 3231 | INIT_HLIST_HEAD(&bp->ntp_fltr_hash_tbl[i]); |
| 3232 | |
| 3233 | bp->ntp_fltr_count = 0; |
Dan Carpenter | ac45bd9 | 2017-05-06 03:49:01 +0300 | [diff] [blame] | 3234 | bp->ntp_fltr_bmap = kcalloc(BITS_TO_LONGS(BNXT_NTP_FLTR_MAX_FLTR), |
| 3235 | sizeof(long), |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3236 | GFP_KERNEL); |
| 3237 | |
| 3238 | if (!bp->ntp_fltr_bmap) |
| 3239 | rc = -ENOMEM; |
| 3240 | |
| 3241 | return rc; |
| 3242 | #else |
| 3243 | return 0; |
| 3244 | #endif |
| 3245 | } |
| 3246 | |
| 3247 | static void bnxt_free_mem(struct bnxt *bp, bool irq_re_init) |
| 3248 | { |
| 3249 | bnxt_free_vnic_attributes(bp); |
| 3250 | bnxt_free_tx_rings(bp); |
| 3251 | bnxt_free_rx_rings(bp); |
| 3252 | bnxt_free_cp_rings(bp); |
| 3253 | bnxt_free_ntp_fltrs(bp, irq_re_init); |
| 3254 | if (irq_re_init) { |
| 3255 | bnxt_free_stats(bp); |
| 3256 | bnxt_free_ring_grps(bp); |
| 3257 | bnxt_free_vnics(bp); |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 3258 | kfree(bp->tx_ring_map); |
| 3259 | bp->tx_ring_map = NULL; |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3260 | kfree(bp->tx_ring); |
| 3261 | bp->tx_ring = NULL; |
| 3262 | kfree(bp->rx_ring); |
| 3263 | bp->rx_ring = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3264 | kfree(bp->bnapi); |
| 3265 | bp->bnapi = NULL; |
| 3266 | } else { |
| 3267 | bnxt_clear_ring_indices(bp); |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | static int bnxt_alloc_mem(struct bnxt *bp, bool irq_re_init) |
| 3272 | { |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 3273 | int i, j, rc, size, arr_size; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3274 | void *bnapi; |
| 3275 | |
| 3276 | if (irq_re_init) { |
| 3277 | /* Allocate bnapi mem pointer array and mem block for |
| 3278 | * all queues |
| 3279 | */ |
| 3280 | arr_size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi *) * |
| 3281 | bp->cp_nr_rings); |
| 3282 | size = L1_CACHE_ALIGN(sizeof(struct bnxt_napi)); |
| 3283 | bnapi = kzalloc(arr_size + size * bp->cp_nr_rings, GFP_KERNEL); |
| 3284 | if (!bnapi) |
| 3285 | return -ENOMEM; |
| 3286 | |
| 3287 | bp->bnapi = bnapi; |
| 3288 | bnapi += arr_size; |
| 3289 | for (i = 0; i < bp->cp_nr_rings; i++, bnapi += size) { |
| 3290 | bp->bnapi[i] = bnapi; |
| 3291 | bp->bnapi[i]->index = i; |
| 3292 | bp->bnapi[i]->bp = bp; |
| 3293 | } |
| 3294 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3295 | bp->rx_ring = kcalloc(bp->rx_nr_rings, |
| 3296 | sizeof(struct bnxt_rx_ring_info), |
| 3297 | GFP_KERNEL); |
| 3298 | if (!bp->rx_ring) |
| 3299 | return -ENOMEM; |
| 3300 | |
| 3301 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 3302 | bp->rx_ring[i].bnapi = bp->bnapi[i]; |
| 3303 | bp->bnapi[i]->rx_ring = &bp->rx_ring[i]; |
| 3304 | } |
| 3305 | |
| 3306 | bp->tx_ring = kcalloc(bp->tx_nr_rings, |
| 3307 | sizeof(struct bnxt_tx_ring_info), |
| 3308 | GFP_KERNEL); |
| 3309 | if (!bp->tx_ring) |
| 3310 | return -ENOMEM; |
| 3311 | |
Michael Chan | a960dec | 2017-02-06 16:55:39 -0500 | [diff] [blame] | 3312 | bp->tx_ring_map = kcalloc(bp->tx_nr_rings, sizeof(u16), |
| 3313 | GFP_KERNEL); |
| 3314 | |
| 3315 | if (!bp->tx_ring_map) |
| 3316 | return -ENOMEM; |
| 3317 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 3318 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 3319 | j = 0; |
| 3320 | else |
| 3321 | j = bp->rx_nr_rings; |
| 3322 | |
| 3323 | for (i = 0; i < bp->tx_nr_rings; i++, j++) { |
| 3324 | bp->tx_ring[i].bnapi = bp->bnapi[j]; |
| 3325 | bp->bnapi[j]->tx_ring = &bp->tx_ring[i]; |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 3326 | bp->tx_ring_map[i] = bp->tx_nr_rings_xdp + i; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 3327 | if (i >= bp->tx_nr_rings_xdp) { |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 3328 | bp->tx_ring[i].txq_index = i - |
| 3329 | bp->tx_nr_rings_xdp; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 3330 | bp->bnapi[j]->tx_int = bnxt_tx_int; |
| 3331 | } else { |
Michael Chan | fa3e93e | 2017-02-06 16:55:41 -0500 | [diff] [blame] | 3332 | bp->bnapi[j]->flags |= BNXT_NAPI_FLAG_XDP; |
Michael Chan | 3841340 | 2017-02-06 16:55:43 -0500 | [diff] [blame] | 3333 | bp->bnapi[j]->tx_int = bnxt_tx_int_xdp; |
| 3334 | } |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 3335 | } |
| 3336 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3337 | rc = bnxt_alloc_stats(bp); |
| 3338 | if (rc) |
| 3339 | goto alloc_mem_err; |
| 3340 | |
| 3341 | rc = bnxt_alloc_ntp_fltrs(bp); |
| 3342 | if (rc) |
| 3343 | goto alloc_mem_err; |
| 3344 | |
| 3345 | rc = bnxt_alloc_vnics(bp); |
| 3346 | if (rc) |
| 3347 | goto alloc_mem_err; |
| 3348 | } |
| 3349 | |
| 3350 | bnxt_init_ring_struct(bp); |
| 3351 | |
| 3352 | rc = bnxt_alloc_rx_rings(bp); |
| 3353 | if (rc) |
| 3354 | goto alloc_mem_err; |
| 3355 | |
| 3356 | rc = bnxt_alloc_tx_rings(bp); |
| 3357 | if (rc) |
| 3358 | goto alloc_mem_err; |
| 3359 | |
| 3360 | rc = bnxt_alloc_cp_rings(bp); |
| 3361 | if (rc) |
| 3362 | goto alloc_mem_err; |
| 3363 | |
| 3364 | bp->vnic_info[0].flags |= BNXT_VNIC_RSS_FLAG | BNXT_VNIC_MCAST_FLAG | |
| 3365 | BNXT_VNIC_UCAST_FLAG; |
| 3366 | rc = bnxt_alloc_vnic_attributes(bp); |
| 3367 | if (rc) |
| 3368 | goto alloc_mem_err; |
| 3369 | return 0; |
| 3370 | |
| 3371 | alloc_mem_err: |
| 3372 | bnxt_free_mem(bp, true); |
| 3373 | return rc; |
| 3374 | } |
| 3375 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3376 | static void bnxt_disable_int(struct bnxt *bp) |
| 3377 | { |
| 3378 | int i; |
| 3379 | |
| 3380 | if (!bp->bnapi) |
| 3381 | return; |
| 3382 | |
| 3383 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3384 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3385 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
Michael Chan | daf1f1e | 2017-02-20 19:25:17 -0500 | [diff] [blame] | 3386 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3387 | |
Michael Chan | daf1f1e | 2017-02-20 19:25:17 -0500 | [diff] [blame] | 3388 | if (ring->fw_ring_id != INVALID_HW_RING_ID) |
| 3389 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3390 | } |
| 3391 | } |
| 3392 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 3393 | static int bnxt_cp_num_to_irq_num(struct bnxt *bp, int n) |
| 3394 | { |
| 3395 | struct bnxt_napi *bnapi = bp->bnapi[n]; |
| 3396 | struct bnxt_cp_ring_info *cpr; |
| 3397 | |
| 3398 | cpr = &bnapi->cp_ring; |
| 3399 | return cpr->cp_ring_struct.map_idx; |
| 3400 | } |
| 3401 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3402 | static void bnxt_disable_int_sync(struct bnxt *bp) |
| 3403 | { |
| 3404 | int i; |
| 3405 | |
| 3406 | atomic_inc(&bp->intr_sem); |
| 3407 | |
| 3408 | bnxt_disable_int(bp); |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 3409 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3410 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
| 3411 | |
| 3412 | synchronize_irq(bp->irq_tbl[map_idx].vector); |
| 3413 | } |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 3414 | } |
| 3415 | |
| 3416 | static void bnxt_enable_int(struct bnxt *bp) |
| 3417 | { |
| 3418 | int i; |
| 3419 | |
| 3420 | atomic_set(&bp->intr_sem, 0); |
| 3421 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 3422 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 3423 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 3424 | |
| 3425 | BNXT_CP_DB_REARM(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 3426 | } |
| 3427 | } |
| 3428 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3429 | void bnxt_hwrm_cmd_hdr_init(struct bnxt *bp, void *request, u16 req_type, |
| 3430 | u16 cmpl_ring, u16 target_id) |
| 3431 | { |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3432 | struct input *req = request; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3433 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3434 | req->req_type = cpu_to_le16(req_type); |
| 3435 | req->cmpl_ring = cpu_to_le16(cmpl_ring); |
| 3436 | req->target_id = cpu_to_le16(target_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3437 | req->resp_addr = cpu_to_le64(bp->hwrm_cmd_resp_dma_addr); |
| 3438 | } |
| 3439 | |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3440 | static int bnxt_hwrm_do_send_msg(struct bnxt *bp, void *msg, u32 msg_len, |
| 3441 | int timeout, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3442 | { |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3443 | int i, intr_process, rc, tmo_count; |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3444 | struct input *req = msg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3445 | u32 *data = msg; |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3446 | __le32 *resp_len; |
| 3447 | u8 *valid; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3448 | u16 cp_ring_id, len = 0; |
| 3449 | struct hwrm_err_output *resp = bp->hwrm_cmd_resp_addr; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3450 | u16 max_req_len = BNXT_HWRM_MAX_REQ_LEN; |
Vasundhara Volam | ebd5818 | 2017-12-01 03:13:05 -0500 | [diff] [blame] | 3451 | struct hwrm_short_input short_input = {0}; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3452 | |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3453 | req->seq_id = cpu_to_le16(bp->hwrm_cmd_seq++); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3454 | memset(resp, 0, PAGE_SIZE); |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3455 | cp_ring_id = le16_to_cpu(req->cmpl_ring); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3456 | intr_process = (cp_ring_id == INVALID_HW_RING_ID) ? 0 : 1; |
| 3457 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3458 | if (bp->flags & BNXT_FLAG_SHORT_CMD) { |
| 3459 | void *short_cmd_req = bp->hwrm_short_cmd_req_addr; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3460 | |
| 3461 | memcpy(short_cmd_req, req, msg_len); |
| 3462 | memset(short_cmd_req + msg_len, 0, BNXT_HWRM_MAX_REQ_LEN - |
| 3463 | msg_len); |
| 3464 | |
| 3465 | short_input.req_type = req->req_type; |
| 3466 | short_input.signature = |
| 3467 | cpu_to_le16(SHORT_REQ_SIGNATURE_SHORT_CMD); |
| 3468 | short_input.size = cpu_to_le16(msg_len); |
| 3469 | short_input.req_addr = |
| 3470 | cpu_to_le64(bp->hwrm_short_cmd_req_dma_addr); |
| 3471 | |
| 3472 | data = (u32 *)&short_input; |
| 3473 | msg_len = sizeof(short_input); |
| 3474 | |
| 3475 | /* Sync memory write before updating doorbell */ |
| 3476 | wmb(); |
| 3477 | |
| 3478 | max_req_len = BNXT_HWRM_SHORT_REQ_LEN; |
| 3479 | } |
| 3480 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3481 | /* Write request msg to hwrm channel */ |
| 3482 | __iowrite32_copy(bp->bar0, data, msg_len / 4); |
| 3483 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 3484 | for (i = msg_len; i < max_req_len; i += 4) |
Michael Chan | d79979a | 2016-01-07 19:56:57 -0500 | [diff] [blame] | 3485 | writel(0, bp->bar0 + i); |
| 3486 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3487 | /* currently supports only one outstanding message */ |
| 3488 | if (intr_process) |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3489 | bp->hwrm_intr_seq_id = le16_to_cpu(req->seq_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3490 | |
| 3491 | /* Ring channel doorbell */ |
| 3492 | writel(1, bp->bar0 + 0x100); |
| 3493 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 3494 | if (!timeout) |
| 3495 | timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 3496 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3497 | i = 0; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3498 | tmo_count = timeout * 40; |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3499 | resp_len = bp->hwrm_cmd_resp_addr + HWRM_RESP_LEN_OFFSET; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3500 | if (intr_process) { |
| 3501 | /* Wait until hwrm response cmpl interrupt is processed */ |
| 3502 | while (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID && |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3503 | i++ < tmo_count) { |
| 3504 | usleep_range(25, 40); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3505 | } |
| 3506 | |
| 3507 | if (bp->hwrm_intr_seq_id != HWRM_SEQ_ID_INVALID) { |
| 3508 | netdev_err(bp->dev, "Resp cmpl intr err msg: 0x%x\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3509 | le16_to_cpu(req->req_type)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3510 | return -1; |
| 3511 | } |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3512 | len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> |
| 3513 | HWRM_RESP_LEN_SFT; |
| 3514 | valid = bp->hwrm_cmd_resp_addr + len - 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3515 | } else { |
| 3516 | /* Check if response len is updated */ |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3517 | for (i = 0; i < tmo_count; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3518 | len = (le32_to_cpu(*resp_len) & HWRM_RESP_LEN_MASK) >> |
| 3519 | HWRM_RESP_LEN_SFT; |
| 3520 | if (len) |
| 3521 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3522 | usleep_range(25, 40); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3523 | } |
| 3524 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3525 | if (i >= tmo_count) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3526 | netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3527 | timeout, le16_to_cpu(req->req_type), |
Michael Chan | 8578d6c | 2016-05-15 03:04:48 -0400 | [diff] [blame] | 3528 | le16_to_cpu(req->seq_id), len); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3529 | return -1; |
| 3530 | } |
| 3531 | |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3532 | /* Last byte of resp contains valid bit */ |
| 3533 | valid = bp->hwrm_cmd_resp_addr + len - 1; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3534 | for (i = 0; i < 5; i++) { |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3535 | /* make sure we read from updated DMA memory */ |
| 3536 | dma_rmb(); |
| 3537 | if (*valid) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3538 | break; |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3539 | udelay(1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3540 | } |
| 3541 | |
Michael Chan | a11fa2b | 2016-05-15 03:04:47 -0400 | [diff] [blame] | 3542 | if (i >= 5) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3543 | netdev_err(bp->dev, "Error (timeout: %d) msg {0x%x 0x%x} len:%d v:%d\n", |
Michael Chan | a8643e1 | 2016-02-26 04:00:05 -0500 | [diff] [blame] | 3544 | timeout, le16_to_cpu(req->req_type), |
| 3545 | le16_to_cpu(req->seq_id), len, *valid); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3546 | return -1; |
| 3547 | } |
| 3548 | } |
| 3549 | |
Michael Chan | 845adfe | 2018-03-31 13:54:15 -0400 | [diff] [blame] | 3550 | /* Zero valid bit for compatibility. Valid bit in an older spec |
| 3551 | * may become a new field in a newer spec. We must make sure that |
| 3552 | * a new field not implemented by old spec will read zero. |
| 3553 | */ |
| 3554 | *valid = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3555 | rc = le16_to_cpu(resp->error_code); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3556 | if (rc && !silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3557 | netdev_err(bp->dev, "hwrm req_type 0x%x seq id 0x%x error 0x%x\n", |
| 3558 | le16_to_cpu(resp->req_type), |
| 3559 | le16_to_cpu(resp->seq_id), rc); |
Michael Chan | fbfbc48 | 2016-02-26 04:00:07 -0500 | [diff] [blame] | 3560 | return rc; |
| 3561 | } |
| 3562 | |
| 3563 | int _hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3564 | { |
| 3565 | return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3566 | } |
| 3567 | |
Michael Chan | cc72f3b | 2017-10-13 21:09:33 -0400 | [diff] [blame] | 3568 | int _hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len, |
| 3569 | int timeout) |
| 3570 | { |
| 3571 | return bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true); |
| 3572 | } |
| 3573 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3574 | int hwrm_send_message(struct bnxt *bp, void *msg, u32 msg_len, int timeout) |
| 3575 | { |
| 3576 | int rc; |
| 3577 | |
| 3578 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3579 | rc = _hwrm_send_message(bp, msg, msg_len, timeout); |
| 3580 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3581 | return rc; |
| 3582 | } |
| 3583 | |
Michael Chan | 90e20921 | 2016-02-26 04:00:08 -0500 | [diff] [blame] | 3584 | int hwrm_send_message_silent(struct bnxt *bp, void *msg, u32 msg_len, |
| 3585 | int timeout) |
| 3586 | { |
| 3587 | int rc; |
| 3588 | |
| 3589 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3590 | rc = bnxt_hwrm_do_send_msg(bp, msg, msg_len, timeout, true); |
| 3591 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3592 | return rc; |
| 3593 | } |
| 3594 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3595 | int bnxt_hwrm_func_rgtr_async_events(struct bnxt *bp, unsigned long *bmap, |
| 3596 | int bmap_size) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3597 | { |
| 3598 | struct hwrm_func_drv_rgtr_input req = {0}; |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3599 | DECLARE_BITMAP(async_events_bmap, 256); |
| 3600 | u32 *events = (u32 *)async_events_bmap; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3601 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3602 | |
| 3603 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3604 | |
| 3605 | req.enables = |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3606 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_ASYNC_EVENT_FWD); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3607 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3608 | memset(async_events_bmap, 0, sizeof(async_events_bmap)); |
| 3609 | for (i = 0; i < ARRAY_SIZE(bnxt_async_events_arr); i++) |
| 3610 | __set_bit(bnxt_async_events_arr[i], async_events_bmap); |
| 3611 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3612 | if (bmap && bmap_size) { |
| 3613 | for (i = 0; i < bmap_size; i++) { |
| 3614 | if (test_bit(i, bmap)) |
| 3615 | __set_bit(i, async_events_bmap); |
| 3616 | } |
| 3617 | } |
| 3618 | |
Michael Chan | 25be862 | 2016-04-05 14:09:00 -0400 | [diff] [blame] | 3619 | for (i = 0; i < 8; i++) |
| 3620 | req.async_event_fwd[i] |= cpu_to_le32(events[i]); |
| 3621 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3622 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3623 | } |
| 3624 | |
| 3625 | static int bnxt_hwrm_func_drv_rgtr(struct bnxt *bp) |
| 3626 | { |
| 3627 | struct hwrm_func_drv_rgtr_input req = {0}; |
| 3628 | |
| 3629 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_RGTR, -1, -1); |
| 3630 | |
| 3631 | req.enables = |
| 3632 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_OS_TYPE | |
| 3633 | FUNC_DRV_RGTR_REQ_ENABLES_VER); |
| 3634 | |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 3635 | 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] | 3636 | req.flags = cpu_to_le32(FUNC_DRV_RGTR_REQ_FLAGS_16BIT_VER_MODE); |
| 3637 | req.ver_maj_8b = DRV_VER_MAJ; |
| 3638 | req.ver_min_8b = DRV_VER_MIN; |
| 3639 | req.ver_upd_8b = DRV_VER_UPD; |
| 3640 | req.ver_maj = cpu_to_le16(DRV_VER_MAJ); |
| 3641 | req.ver_min = cpu_to_le16(DRV_VER_MIN); |
| 3642 | req.ver_upd = cpu_to_le16(DRV_VER_UPD); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3643 | |
| 3644 | if (BNXT_PF(bp)) { |
Michael Chan | 9b0436c | 2017-07-11 13:05:36 -0400 | [diff] [blame] | 3645 | u32 data[8]; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 3646 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3647 | |
Michael Chan | 9b0436c | 2017-07-11 13:05:36 -0400 | [diff] [blame] | 3648 | memset(data, 0, sizeof(data)); |
| 3649 | for (i = 0; i < ARRAY_SIZE(bnxt_vf_req_snif); i++) { |
| 3650 | u16 cmd = bnxt_vf_req_snif[i]; |
| 3651 | unsigned int bit, idx; |
| 3652 | |
| 3653 | idx = cmd / 32; |
| 3654 | bit = cmd % 32; |
| 3655 | data[idx] |= 1 << bit; |
| 3656 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3657 | |
Michael Chan | de68f5de | 2015-12-09 19:35:41 -0500 | [diff] [blame] | 3658 | for (i = 0; i < 8; i++) |
| 3659 | req.vf_req_fwd[i] = cpu_to_le32(data[i]); |
| 3660 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3661 | req.enables |= |
| 3662 | cpu_to_le32(FUNC_DRV_RGTR_REQ_ENABLES_VF_REQ_FWD); |
| 3663 | } |
| 3664 | |
| 3665 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3666 | } |
| 3667 | |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 3668 | static int bnxt_hwrm_func_drv_unrgtr(struct bnxt *bp) |
| 3669 | { |
| 3670 | struct hwrm_func_drv_unrgtr_input req = {0}; |
| 3671 | |
| 3672 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_DRV_UNRGTR, -1, -1); |
| 3673 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3674 | } |
| 3675 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3676 | static int bnxt_hwrm_tunnel_dst_port_free(struct bnxt *bp, u8 tunnel_type) |
| 3677 | { |
| 3678 | u32 rc = 0; |
| 3679 | struct hwrm_tunnel_dst_port_free_input req = {0}; |
| 3680 | |
| 3681 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_FREE, -1, -1); |
| 3682 | req.tunnel_type = tunnel_type; |
| 3683 | |
| 3684 | switch (tunnel_type) { |
| 3685 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN: |
| 3686 | req.tunnel_dst_port_id = bp->vxlan_fw_dst_port_id; |
| 3687 | break; |
| 3688 | case TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE: |
| 3689 | req.tunnel_dst_port_id = bp->nge_fw_dst_port_id; |
| 3690 | break; |
| 3691 | default: |
| 3692 | break; |
| 3693 | } |
| 3694 | |
| 3695 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3696 | if (rc) |
| 3697 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_free failed. rc:%d\n", |
| 3698 | rc); |
| 3699 | return rc; |
| 3700 | } |
| 3701 | |
| 3702 | static int bnxt_hwrm_tunnel_dst_port_alloc(struct bnxt *bp, __be16 port, |
| 3703 | u8 tunnel_type) |
| 3704 | { |
| 3705 | u32 rc = 0; |
| 3706 | struct hwrm_tunnel_dst_port_alloc_input req = {0}; |
| 3707 | struct hwrm_tunnel_dst_port_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3708 | |
| 3709 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_TUNNEL_DST_PORT_ALLOC, -1, -1); |
| 3710 | |
| 3711 | req.tunnel_type = tunnel_type; |
| 3712 | req.tunnel_dst_port_val = port; |
| 3713 | |
| 3714 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3715 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3716 | if (rc) { |
| 3717 | netdev_err(bp->dev, "hwrm_tunnel_dst_port_alloc failed. rc:%d\n", |
| 3718 | rc); |
| 3719 | goto err_out; |
| 3720 | } |
| 3721 | |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3722 | switch (tunnel_type) { |
| 3723 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_VXLAN: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3724 | bp->vxlan_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3725 | break; |
| 3726 | case TUNNEL_DST_PORT_ALLOC_REQ_TUNNEL_TYPE_GENEVE: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3727 | bp->nge_fw_dst_port_id = resp->tunnel_dst_port_id; |
Christophe Jaillet | 57aac71 | 2016-11-22 06:14:40 +0100 | [diff] [blame] | 3728 | break; |
| 3729 | default: |
| 3730 | break; |
| 3731 | } |
| 3732 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3733 | err_out: |
| 3734 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3735 | return rc; |
| 3736 | } |
| 3737 | |
| 3738 | static int bnxt_hwrm_cfa_l2_set_rx_mask(struct bnxt *bp, u16 vnic_id) |
| 3739 | { |
| 3740 | struct hwrm_cfa_l2_set_rx_mask_input req = {0}; |
| 3741 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3742 | |
| 3743 | 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] | 3744 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3745 | |
| 3746 | req.num_mc_entries = cpu_to_le32(vnic->mc_list_count); |
| 3747 | req.mc_tbl_addr = cpu_to_le64(vnic->mc_list_mapping); |
| 3748 | req.mask = cpu_to_le32(vnic->rx_mask); |
| 3749 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3750 | } |
| 3751 | |
| 3752 | #ifdef CONFIG_RFS_ACCEL |
| 3753 | static int bnxt_hwrm_cfa_ntuple_filter_free(struct bnxt *bp, |
| 3754 | struct bnxt_ntuple_filter *fltr) |
| 3755 | { |
| 3756 | struct hwrm_cfa_ntuple_filter_free_input req = {0}; |
| 3757 | |
| 3758 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_NTUPLE_FILTER_FREE, -1, -1); |
| 3759 | req.ntuple_filter_id = fltr->filter_id; |
| 3760 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3761 | } |
| 3762 | |
| 3763 | #define BNXT_NTP_FLTR_FLAGS \ |
| 3764 | (CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_L2_FILTER_ID | \ |
| 3765 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_ETHERTYPE | \ |
| 3766 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_MACADDR | \ |
| 3767 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IPADDR_TYPE | \ |
| 3768 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR | \ |
| 3769 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_IPADDR_MASK | \ |
| 3770 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR | \ |
| 3771 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_IPADDR_MASK | \ |
| 3772 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_IP_PROTOCOL | \ |
| 3773 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT | \ |
| 3774 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_SRC_PORT_MASK | \ |
| 3775 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT | \ |
| 3776 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_PORT_MASK | \ |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3777 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_DST_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3778 | |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 3779 | #define BNXT_NTP_TUNNEL_FLTR_FLAG \ |
| 3780 | CFA_NTUPLE_FILTER_ALLOC_REQ_ENABLES_TUNNEL_TYPE |
| 3781 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3782 | static int bnxt_hwrm_cfa_ntuple_filter_alloc(struct bnxt *bp, |
| 3783 | struct bnxt_ntuple_filter *fltr) |
| 3784 | { |
| 3785 | int rc = 0; |
| 3786 | struct hwrm_cfa_ntuple_filter_alloc_input req = {0}; |
| 3787 | struct hwrm_cfa_ntuple_filter_alloc_output *resp = |
| 3788 | bp->hwrm_cmd_resp_addr; |
| 3789 | struct flow_keys *keys = &fltr->fkeys; |
| 3790 | struct bnxt_vnic_info *vnic = &bp->vnic_info[fltr->rxq + 1]; |
| 3791 | |
| 3792 | 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] | 3793 | 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] | 3794 | |
| 3795 | req.enables = cpu_to_le32(BNXT_NTP_FLTR_FLAGS); |
| 3796 | |
| 3797 | req.ethertype = htons(ETH_P_IP); |
| 3798 | memcpy(req.src_macaddr, fltr->src_mac_addr, ETH_ALEN); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3799 | 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] | 3800 | req.ip_protocol = keys->basic.ip_proto; |
| 3801 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 3802 | if (keys->basic.n_proto == htons(ETH_P_IPV6)) { |
| 3803 | int i; |
| 3804 | |
| 3805 | req.ethertype = htons(ETH_P_IPV6); |
| 3806 | req.ip_addr_type = |
| 3807 | CFA_NTUPLE_FILTER_ALLOC_REQ_IP_ADDR_TYPE_IPV6; |
| 3808 | *(struct in6_addr *)&req.src_ipaddr[0] = |
| 3809 | keys->addrs.v6addrs.src; |
| 3810 | *(struct in6_addr *)&req.dst_ipaddr[0] = |
| 3811 | keys->addrs.v6addrs.dst; |
| 3812 | for (i = 0; i < 4; i++) { |
| 3813 | req.src_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 3814 | req.dst_ipaddr_mask[i] = cpu_to_be32(0xffffffff); |
| 3815 | } |
| 3816 | } else { |
| 3817 | req.src_ipaddr[0] = keys->addrs.v4addrs.src; |
| 3818 | req.src_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 3819 | req.dst_ipaddr[0] = keys->addrs.v4addrs.dst; |
| 3820 | req.dst_ipaddr_mask[0] = cpu_to_be32(0xffffffff); |
| 3821 | } |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 3822 | if (keys->control.flags & FLOW_DIS_ENCAPSULATION) { |
| 3823 | req.enables |= cpu_to_le32(BNXT_NTP_TUNNEL_FLTR_FLAG); |
| 3824 | req.tunnel_type = |
| 3825 | CFA_NTUPLE_FILTER_ALLOC_REQ_TUNNEL_TYPE_ANYTUNNEL; |
| 3826 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3827 | |
| 3828 | req.src_port = keys->ports.src; |
| 3829 | req.src_port_mask = cpu_to_be16(0xffff); |
| 3830 | req.dst_port = keys->ports.dst; |
| 3831 | req.dst_port_mask = cpu_to_be16(0xffff); |
| 3832 | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3833 | req.dst_id = cpu_to_le16(vnic->fw_vnic_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3834 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3835 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3836 | if (!rc) |
| 3837 | fltr->filter_id = resp->ntuple_filter_id; |
| 3838 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3839 | return rc; |
| 3840 | } |
| 3841 | #endif |
| 3842 | |
| 3843 | static int bnxt_hwrm_set_vnic_filter(struct bnxt *bp, u16 vnic_id, u16 idx, |
| 3844 | u8 *mac_addr) |
| 3845 | { |
| 3846 | u32 rc = 0; |
| 3847 | struct hwrm_cfa_l2_filter_alloc_input req = {0}; |
| 3848 | struct hwrm_cfa_l2_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 3849 | |
| 3850 | 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] | 3851 | req.flags = cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_PATH_RX); |
| 3852 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3853 | req.flags |= |
| 3854 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_FLAGS_OUTERMOST); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3855 | 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] | 3856 | req.enables = |
| 3857 | cpu_to_le32(CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3858 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_DST_ID | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3859 | CFA_L2_FILTER_ALLOC_REQ_ENABLES_L2_ADDR_MASK); |
| 3860 | memcpy(req.l2_addr, mac_addr, ETH_ALEN); |
| 3861 | req.l2_addr_mask[0] = 0xff; |
| 3862 | req.l2_addr_mask[1] = 0xff; |
| 3863 | req.l2_addr_mask[2] = 0xff; |
| 3864 | req.l2_addr_mask[3] = 0xff; |
| 3865 | req.l2_addr_mask[4] = 0xff; |
| 3866 | req.l2_addr_mask[5] = 0xff; |
| 3867 | |
| 3868 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3869 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3870 | if (!rc) |
| 3871 | bp->vnic_info[vnic_id].fw_l2_filter_id[idx] = |
| 3872 | resp->l2_filter_id; |
| 3873 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3874 | return rc; |
| 3875 | } |
| 3876 | |
| 3877 | static int bnxt_hwrm_clear_vnic_filter(struct bnxt *bp) |
| 3878 | { |
| 3879 | u16 i, j, num_of_vnics = 1; /* only vnic 0 supported */ |
| 3880 | int rc = 0; |
| 3881 | |
| 3882 | /* Any associated ntuple filters will also be cleared by firmware. */ |
| 3883 | mutex_lock(&bp->hwrm_cmd_lock); |
| 3884 | for (i = 0; i < num_of_vnics; i++) { |
| 3885 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 3886 | |
| 3887 | for (j = 0; j < vnic->uc_filter_count; j++) { |
| 3888 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 3889 | |
| 3890 | bnxt_hwrm_cmd_hdr_init(bp, &req, |
| 3891 | HWRM_CFA_L2_FILTER_FREE, -1, -1); |
| 3892 | |
| 3893 | req.l2_filter_id = vnic->fw_l2_filter_id[j]; |
| 3894 | |
| 3895 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 3896 | HWRM_CMD_TIMEOUT); |
| 3897 | } |
| 3898 | vnic->uc_filter_count = 0; |
| 3899 | } |
| 3900 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 3901 | |
| 3902 | return rc; |
| 3903 | } |
| 3904 | |
| 3905 | static int bnxt_hwrm_vnic_set_tpa(struct bnxt *bp, u16 vnic_id, u32 tpa_flags) |
| 3906 | { |
| 3907 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3908 | struct hwrm_vnic_tpa_cfg_input req = {0}; |
| 3909 | |
Michael Chan | 3c4fe80 | 2018-03-09 23:46:10 -0500 | [diff] [blame] | 3910 | if (vnic->fw_vnic_id == INVALID_HW_RING_ID) |
| 3911 | return 0; |
| 3912 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3913 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_TPA_CFG, -1, -1); |
| 3914 | |
| 3915 | if (tpa_flags) { |
| 3916 | u16 mss = bp->dev->mtu - 40; |
| 3917 | u32 nsegs, n, segs = 0, flags; |
| 3918 | |
| 3919 | flags = VNIC_TPA_CFG_REQ_FLAGS_TPA | |
| 3920 | VNIC_TPA_CFG_REQ_FLAGS_ENCAP_TPA | |
| 3921 | VNIC_TPA_CFG_REQ_FLAGS_RSC_WND_UPDATE | |
| 3922 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_ECN | |
| 3923 | VNIC_TPA_CFG_REQ_FLAGS_AGG_WITH_SAME_GRE_SEQ; |
| 3924 | if (tpa_flags & BNXT_FLAG_GRO) |
| 3925 | flags |= VNIC_TPA_CFG_REQ_FLAGS_GRO; |
| 3926 | |
| 3927 | req.flags = cpu_to_le32(flags); |
| 3928 | |
| 3929 | req.enables = |
| 3930 | cpu_to_le32(VNIC_TPA_CFG_REQ_ENABLES_MAX_AGG_SEGS | |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 3931 | VNIC_TPA_CFG_REQ_ENABLES_MAX_AGGS | |
| 3932 | VNIC_TPA_CFG_REQ_ENABLES_MIN_AGG_LEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3933 | |
| 3934 | /* Number of segs are log2 units, and first packet is not |
| 3935 | * included as part of this units. |
| 3936 | */ |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 3937 | if (mss <= BNXT_RX_PAGE_SIZE) { |
| 3938 | n = BNXT_RX_PAGE_SIZE / mss; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3939 | nsegs = (MAX_SKB_FRAGS - 1) * n; |
| 3940 | } else { |
Michael Chan | 2839f28 | 2016-04-25 02:30:50 -0400 | [diff] [blame] | 3941 | n = mss / BNXT_RX_PAGE_SIZE; |
| 3942 | if (mss & (BNXT_RX_PAGE_SIZE - 1)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3943 | n++; |
| 3944 | nsegs = (MAX_SKB_FRAGS - n) / n; |
| 3945 | } |
| 3946 | |
| 3947 | segs = ilog2(nsegs); |
| 3948 | req.max_agg_segs = cpu_to_le16(segs); |
| 3949 | 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] | 3950 | |
| 3951 | req.min_agg_len = cpu_to_le32(512); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3952 | } |
| 3953 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 3954 | |
| 3955 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3956 | } |
| 3957 | |
| 3958 | static int bnxt_hwrm_vnic_set_rss(struct bnxt *bp, u16 vnic_id, bool set_rss) |
| 3959 | { |
| 3960 | u32 i, j, max_rings; |
| 3961 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3962 | struct hwrm_vnic_rss_cfg_input req = {0}; |
| 3963 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3964 | if (vnic->fw_rss_cos_lb_ctx[0] == INVALID_HW_RING_ID) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3965 | return 0; |
| 3966 | |
| 3967 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_CFG, -1, -1); |
| 3968 | if (set_rss) { |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 3969 | req.hash_type = cpu_to_le32(bp->rss_hash_cfg); |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3970 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) { |
| 3971 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 3972 | max_rings = bp->rx_nr_rings - 1; |
| 3973 | else |
| 3974 | max_rings = bp->rx_nr_rings; |
| 3975 | } else { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3976 | max_rings = 1; |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 3977 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 3978 | |
| 3979 | /* Fill the RSS indirection table with ring group ids */ |
| 3980 | for (i = 0, j = 0; i < HW_HASH_INDEX_SIZE; i++, j++) { |
| 3981 | if (j == max_rings) |
| 3982 | j = 0; |
| 3983 | vnic->rss_table[i] = cpu_to_le16(vnic->fw_grp_ids[j]); |
| 3984 | } |
| 3985 | |
| 3986 | req.ring_grp_tbl_addr = cpu_to_le64(vnic->rss_table_dma_addr); |
| 3987 | req.hash_key_tbl_addr = |
| 3988 | cpu_to_le64(vnic->rss_hash_key_dma_addr); |
| 3989 | } |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 3990 | 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] | 3991 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 3992 | } |
| 3993 | |
| 3994 | static int bnxt_hwrm_vnic_set_hds(struct bnxt *bp, u16 vnic_id) |
| 3995 | { |
| 3996 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 3997 | struct hwrm_vnic_plcmodes_cfg_input req = {0}; |
| 3998 | |
| 3999 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_PLCMODES_CFG, -1, -1); |
| 4000 | req.flags = cpu_to_le32(VNIC_PLCMODES_CFG_REQ_FLAGS_JUMBO_PLACEMENT | |
| 4001 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV4 | |
| 4002 | VNIC_PLCMODES_CFG_REQ_FLAGS_HDS_IPV6); |
| 4003 | req.enables = |
| 4004 | cpu_to_le32(VNIC_PLCMODES_CFG_REQ_ENABLES_JUMBO_THRESH_VALID | |
| 4005 | VNIC_PLCMODES_CFG_REQ_ENABLES_HDS_THRESHOLD_VALID); |
| 4006 | /* thresholds not implemented in firmware yet */ |
| 4007 | req.jumbo_thresh = cpu_to_le16(bp->rx_copy_thresh); |
| 4008 | req.hds_threshold = cpu_to_le16(bp->rx_copy_thresh); |
| 4009 | req.vnic_id = cpu_to_le32(vnic->fw_vnic_id); |
| 4010 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4011 | } |
| 4012 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4013 | static void bnxt_hwrm_vnic_ctx_free_one(struct bnxt *bp, u16 vnic_id, |
| 4014 | u16 ctx_idx) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4015 | { |
| 4016 | struct hwrm_vnic_rss_cos_lb_ctx_free_input req = {0}; |
| 4017 | |
| 4018 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_FREE, -1, -1); |
| 4019 | req.rss_cos_lb_ctx_id = |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4020 | 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] | 4021 | |
| 4022 | hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4023 | 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] | 4024 | } |
| 4025 | |
| 4026 | static void bnxt_hwrm_vnic_ctx_free(struct bnxt *bp) |
| 4027 | { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4028 | int i, j; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4029 | |
| 4030 | for (i = 0; i < bp->nr_vnics; i++) { |
| 4031 | struct bnxt_vnic_info *vnic = &bp->vnic_info[i]; |
| 4032 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4033 | for (j = 0; j < BNXT_MAX_CTX_PER_VNIC; j++) { |
| 4034 | if (vnic->fw_rss_cos_lb_ctx[j] != INVALID_HW_RING_ID) |
| 4035 | bnxt_hwrm_vnic_ctx_free_one(bp, i, j); |
| 4036 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4037 | } |
| 4038 | bp->rsscos_nr_ctxs = 0; |
| 4039 | } |
| 4040 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4041 | 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] | 4042 | { |
| 4043 | int rc; |
| 4044 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_input req = {0}; |
| 4045 | struct hwrm_vnic_rss_cos_lb_ctx_alloc_output *resp = |
| 4046 | bp->hwrm_cmd_resp_addr; |
| 4047 | |
| 4048 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_RSS_COS_LB_CTX_ALLOC, -1, |
| 4049 | -1); |
| 4050 | |
| 4051 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4052 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4053 | if (!rc) |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4054 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[ctx_idx] = |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4055 | le16_to_cpu(resp->rss_cos_lb_ctx_id); |
| 4056 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4057 | |
| 4058 | return rc; |
| 4059 | } |
| 4060 | |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4061 | static u32 bnxt_get_roce_vnic_mode(struct bnxt *bp) |
| 4062 | { |
| 4063 | if (bp->flags & BNXT_FLAG_ROCE_MIRROR_CAP) |
| 4064 | return VNIC_CFG_REQ_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_MODE; |
| 4065 | return VNIC_CFG_REQ_FLAGS_ROCE_DUAL_VNIC_MODE; |
| 4066 | } |
| 4067 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 4068 | int bnxt_hwrm_vnic_cfg(struct bnxt *bp, u16 vnic_id) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4069 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4070 | unsigned int ring = 0, grp_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4071 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
| 4072 | struct hwrm_vnic_cfg_input req = {0}; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4073 | u16 def_vlan = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4074 | |
| 4075 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_CFG, -1, -1); |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4076 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 4077 | req.enables = cpu_to_le32(VNIC_CFG_REQ_ENABLES_DFLT_RING_GRP); |
| 4078 | /* Only RSS support for now TBD: COS & LB */ |
| 4079 | if (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID) { |
| 4080 | req.rss_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[0]); |
| 4081 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 4082 | VNIC_CFG_REQ_ENABLES_MRU); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 4083 | } else if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) { |
| 4084 | req.rss_rule = |
| 4085 | cpu_to_le16(bp->vnic_info[0].fw_rss_cos_lb_ctx[0]); |
| 4086 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_RSS_RULE | |
| 4087 | VNIC_CFG_REQ_ENABLES_MRU); |
| 4088 | 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] | 4089 | } else { |
| 4090 | req.rss_rule = cpu_to_le16(0xffff); |
| 4091 | } |
| 4092 | |
| 4093 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && |
| 4094 | (vnic->fw_rss_cos_lb_ctx[0] != INVALID_HW_RING_ID)) { |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4095 | req.cos_rule = cpu_to_le16(vnic->fw_rss_cos_lb_ctx[1]); |
| 4096 | req.enables |= cpu_to_le32(VNIC_CFG_REQ_ENABLES_COS_RULE); |
| 4097 | } else { |
| 4098 | req.cos_rule = cpu_to_le16(0xffff); |
| 4099 | } |
| 4100 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4101 | if (vnic->flags & BNXT_VNIC_RSS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4102 | ring = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4103 | else if (vnic->flags & BNXT_VNIC_RFS_FLAG) |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4104 | ring = vnic_id - 1; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 4105 | else if ((vnic_id == 1) && BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 4106 | ring = bp->rx_nr_rings - 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4107 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4108 | grp_idx = bp->rx_ring[ring].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4109 | req.vnic_id = cpu_to_le16(vnic->fw_vnic_id); |
| 4110 | req.dflt_ring_grp = cpu_to_le16(bp->grp_info[grp_idx].fw_grp_id); |
| 4111 | |
| 4112 | req.lb_rule = cpu_to_le16(0xffff); |
| 4113 | req.mru = cpu_to_le16(bp->dev->mtu + ETH_HLEN + ETH_FCS_LEN + |
| 4114 | VLAN_HLEN); |
| 4115 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 4116 | #ifdef CONFIG_BNXT_SRIOV |
| 4117 | if (BNXT_VF(bp)) |
| 4118 | def_vlan = bp->vf.vlan; |
| 4119 | #endif |
| 4120 | if ((bp->flags & BNXT_FLAG_STRIP_VLAN) || def_vlan) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4121 | req.flags |= cpu_to_le32(VNIC_CFG_REQ_FLAGS_VLAN_STRIP_MODE); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 4122 | if (!vnic_id && bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP)) |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4123 | req.flags |= cpu_to_le32(bnxt_get_roce_vnic_mode(bp)); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4124 | |
| 4125 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4126 | } |
| 4127 | |
| 4128 | static int bnxt_hwrm_vnic_free_one(struct bnxt *bp, u16 vnic_id) |
| 4129 | { |
| 4130 | u32 rc = 0; |
| 4131 | |
| 4132 | if (bp->vnic_info[vnic_id].fw_vnic_id != INVALID_HW_RING_ID) { |
| 4133 | struct hwrm_vnic_free_input req = {0}; |
| 4134 | |
| 4135 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_FREE, -1, -1); |
| 4136 | req.vnic_id = |
| 4137 | cpu_to_le32(bp->vnic_info[vnic_id].fw_vnic_id); |
| 4138 | |
| 4139 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4140 | if (rc) |
| 4141 | return rc; |
| 4142 | bp->vnic_info[vnic_id].fw_vnic_id = INVALID_HW_RING_ID; |
| 4143 | } |
| 4144 | return rc; |
| 4145 | } |
| 4146 | |
| 4147 | static void bnxt_hwrm_vnic_free(struct bnxt *bp) |
| 4148 | { |
| 4149 | u16 i; |
| 4150 | |
| 4151 | for (i = 0; i < bp->nr_vnics; i++) |
| 4152 | bnxt_hwrm_vnic_free_one(bp, i); |
| 4153 | } |
| 4154 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4155 | static int bnxt_hwrm_vnic_alloc(struct bnxt *bp, u16 vnic_id, |
| 4156 | unsigned int start_rx_ring_idx, |
| 4157 | unsigned int nr_rings) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4158 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4159 | int rc = 0; |
| 4160 | 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] | 4161 | struct hwrm_vnic_alloc_input req = {0}; |
| 4162 | struct hwrm_vnic_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 4163 | |
| 4164 | /* map ring groups to this vnic */ |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4165 | for (i = start_rx_ring_idx, j = 0; i < end_idx; i++, j++) { |
| 4166 | grp_idx = bp->rx_ring[i].bnapi->index; |
| 4167 | 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] | 4168 | 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] | 4169 | j, nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4170 | break; |
| 4171 | } |
| 4172 | bp->vnic_info[vnic_id].fw_grp_ids[j] = |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4173 | bp->grp_info[grp_idx].fw_grp_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4174 | } |
| 4175 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 4176 | bp->vnic_info[vnic_id].fw_rss_cos_lb_ctx[0] = INVALID_HW_RING_ID; |
| 4177 | 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] | 4178 | if (vnic_id == 0) |
| 4179 | req.flags = cpu_to_le32(VNIC_ALLOC_REQ_FLAGS_DEFAULT); |
| 4180 | |
| 4181 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_ALLOC, -1, -1); |
| 4182 | |
| 4183 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4184 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4185 | if (!rc) |
| 4186 | bp->vnic_info[vnic_id].fw_vnic_id = le32_to_cpu(resp->vnic_id); |
| 4187 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4188 | return rc; |
| 4189 | } |
| 4190 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 4191 | static int bnxt_hwrm_vnic_qcaps(struct bnxt *bp) |
| 4192 | { |
| 4193 | struct hwrm_vnic_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 4194 | struct hwrm_vnic_qcaps_input req = {0}; |
| 4195 | int rc; |
| 4196 | |
| 4197 | if (bp->hwrm_spec_code < 0x10600) |
| 4198 | return 0; |
| 4199 | |
| 4200 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VNIC_QCAPS, -1, -1); |
| 4201 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4202 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4203 | if (!rc) { |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4204 | u32 flags = le32_to_cpu(resp->flags); |
| 4205 | |
| 4206 | if (flags & VNIC_QCAPS_RESP_FLAGS_RSS_DFLT_CR_CAP) |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 4207 | bp->flags |= BNXT_FLAG_NEW_RSS_CAP; |
Michael Chan | abe93ad | 2018-03-31 13:54:08 -0400 | [diff] [blame] | 4208 | if (flags & |
| 4209 | VNIC_QCAPS_RESP_FLAGS_ROCE_MIRRORING_CAPABLE_VNIC_CAP) |
| 4210 | bp->flags |= BNXT_FLAG_ROCE_MIRROR_CAP; |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 4211 | } |
| 4212 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4213 | return rc; |
| 4214 | } |
| 4215 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4216 | static int bnxt_hwrm_ring_grp_alloc(struct bnxt *bp) |
| 4217 | { |
| 4218 | u16 i; |
| 4219 | u32 rc = 0; |
| 4220 | |
| 4221 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4222 | for (i = 0; i < bp->rx_nr_rings; i++) { |
| 4223 | struct hwrm_ring_grp_alloc_input req = {0}; |
| 4224 | struct hwrm_ring_grp_alloc_output *resp = |
| 4225 | bp->hwrm_cmd_resp_addr; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4226 | unsigned int grp_idx = bp->rx_ring[i].bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4227 | |
| 4228 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_ALLOC, -1, -1); |
| 4229 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4230 | req.cr = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id); |
| 4231 | req.rr = cpu_to_le16(bp->grp_info[grp_idx].rx_fw_ring_id); |
| 4232 | req.ar = cpu_to_le16(bp->grp_info[grp_idx].agg_fw_ring_id); |
| 4233 | 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] | 4234 | |
| 4235 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4236 | HWRM_CMD_TIMEOUT); |
| 4237 | if (rc) |
| 4238 | break; |
| 4239 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4240 | bp->grp_info[grp_idx].fw_grp_id = |
| 4241 | le32_to_cpu(resp->ring_group_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4242 | } |
| 4243 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4244 | return rc; |
| 4245 | } |
| 4246 | |
| 4247 | static int bnxt_hwrm_ring_grp_free(struct bnxt *bp) |
| 4248 | { |
| 4249 | u16 i; |
| 4250 | u32 rc = 0; |
| 4251 | struct hwrm_ring_grp_free_input req = {0}; |
| 4252 | |
| 4253 | if (!bp->grp_info) |
| 4254 | return 0; |
| 4255 | |
| 4256 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_GRP_FREE, -1, -1); |
| 4257 | |
| 4258 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4259 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4260 | if (bp->grp_info[i].fw_grp_id == INVALID_HW_RING_ID) |
| 4261 | continue; |
| 4262 | req.ring_group_id = |
| 4263 | cpu_to_le32(bp->grp_info[i].fw_grp_id); |
| 4264 | |
| 4265 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 4266 | HWRM_CMD_TIMEOUT); |
| 4267 | if (rc) |
| 4268 | break; |
| 4269 | bp->grp_info[i].fw_grp_id = INVALID_HW_RING_ID; |
| 4270 | } |
| 4271 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4272 | return rc; |
| 4273 | } |
| 4274 | |
| 4275 | static int hwrm_ring_alloc_send_msg(struct bnxt *bp, |
| 4276 | struct bnxt_ring_struct *ring, |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4277 | u32 ring_type, u32 map_index) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4278 | { |
| 4279 | int rc = 0, err = 0; |
| 4280 | struct hwrm_ring_alloc_input req = {0}; |
| 4281 | struct hwrm_ring_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4282 | struct bnxt_ring_grp_info *grp_info; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4283 | u16 ring_id; |
| 4284 | |
| 4285 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_RING_ALLOC, -1, -1); |
| 4286 | |
| 4287 | req.enables = 0; |
| 4288 | if (ring->nr_pages > 1) { |
| 4289 | req.page_tbl_addr = cpu_to_le64(ring->pg_tbl_map); |
| 4290 | /* Page size is in log2 units */ |
| 4291 | req.page_size = BNXT_PAGE_SHIFT; |
| 4292 | req.page_tbl_depth = 1; |
| 4293 | } else { |
| 4294 | req.page_tbl_addr = cpu_to_le64(ring->dma_arr[0]); |
| 4295 | } |
| 4296 | req.fbo = 0; |
| 4297 | /* Association of ring index with doorbell index and MSIX number */ |
| 4298 | req.logical_id = cpu_to_le16(map_index); |
| 4299 | |
| 4300 | switch (ring_type) { |
| 4301 | case HWRM_RING_ALLOC_TX: |
| 4302 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_TX; |
| 4303 | /* Association of transmit ring with completion ring */ |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4304 | grp_info = &bp->grp_info[ring->grp_idx]; |
| 4305 | req.cmpl_ring_id = cpu_to_le16(grp_info->cp_fw_ring_id); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4306 | req.length = cpu_to_le32(bp->tx_ring_mask + 1); |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4307 | req.stat_ctx_id = cpu_to_le32(grp_info->fw_stats_ctx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4308 | req.queue_id = cpu_to_le16(ring->queue_id); |
| 4309 | break; |
| 4310 | case HWRM_RING_ALLOC_RX: |
| 4311 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 4312 | req.length = cpu_to_le32(bp->rx_ring_mask + 1); |
| 4313 | break; |
| 4314 | case HWRM_RING_ALLOC_AGG: |
| 4315 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_RX; |
| 4316 | req.length = cpu_to_le32(bp->rx_agg_ring_mask + 1); |
| 4317 | break; |
| 4318 | case HWRM_RING_ALLOC_CMPL: |
Michael Chan | bac9a7e | 2017-02-12 19:18:10 -0500 | [diff] [blame] | 4319 | req.ring_type = RING_ALLOC_REQ_RING_TYPE_L2_CMPL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4320 | req.length = cpu_to_le32(bp->cp_ring_mask + 1); |
| 4321 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 4322 | req.int_mode = RING_ALLOC_REQ_INT_MODE_MSIX; |
| 4323 | break; |
| 4324 | default: |
| 4325 | netdev_err(bp->dev, "hwrm alloc invalid ring type %d\n", |
| 4326 | ring_type); |
| 4327 | return -1; |
| 4328 | } |
| 4329 | |
| 4330 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4331 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4332 | err = le16_to_cpu(resp->error_code); |
| 4333 | ring_id = le16_to_cpu(resp->ring_id); |
| 4334 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4335 | |
| 4336 | if (rc || err) { |
| 4337 | switch (ring_type) { |
Michael Chan | bac9a7e | 2017-02-12 19:18:10 -0500 | [diff] [blame] | 4338 | case RING_FREE_REQ_RING_TYPE_L2_CMPL: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4339 | netdev_err(bp->dev, "hwrm_ring_alloc cp failed. rc:%x err:%x\n", |
| 4340 | rc, err); |
| 4341 | return -1; |
| 4342 | |
| 4343 | case RING_FREE_REQ_RING_TYPE_RX: |
| 4344 | netdev_err(bp->dev, "hwrm_ring_alloc rx failed. rc:%x err:%x\n", |
| 4345 | rc, err); |
| 4346 | return -1; |
| 4347 | |
| 4348 | case RING_FREE_REQ_RING_TYPE_TX: |
| 4349 | netdev_err(bp->dev, "hwrm_ring_alloc tx failed. rc:%x err:%x\n", |
| 4350 | rc, err); |
| 4351 | return -1; |
| 4352 | |
| 4353 | default: |
| 4354 | netdev_err(bp->dev, "Invalid ring\n"); |
| 4355 | return -1; |
| 4356 | } |
| 4357 | } |
| 4358 | ring->fw_ring_id = ring_id; |
| 4359 | return rc; |
| 4360 | } |
| 4361 | |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 4362 | static int bnxt_hwrm_set_async_event_cr(struct bnxt *bp, int idx) |
| 4363 | { |
| 4364 | int rc; |
| 4365 | |
| 4366 | if (BNXT_PF(bp)) { |
| 4367 | struct hwrm_func_cfg_input req = {0}; |
| 4368 | |
| 4369 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 4370 | req.fid = cpu_to_le16(0xffff); |
| 4371 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 4372 | req.async_event_cr = cpu_to_le16(idx); |
| 4373 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4374 | } else { |
| 4375 | struct hwrm_func_vf_cfg_input req = {0}; |
| 4376 | |
| 4377 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_VF_CFG, -1, -1); |
| 4378 | req.enables = |
| 4379 | cpu_to_le32(FUNC_VF_CFG_REQ_ENABLES_ASYNC_EVENT_CR); |
| 4380 | req.async_event_cr = cpu_to_le16(idx); |
| 4381 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4382 | } |
| 4383 | return rc; |
| 4384 | } |
| 4385 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4386 | static int bnxt_hwrm_ring_alloc(struct bnxt *bp) |
| 4387 | { |
| 4388 | int i, rc = 0; |
| 4389 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4390 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4391 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4392 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4393 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4394 | u32 map_idx = ring->map_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4395 | |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4396 | cpr->cp_doorbell = bp->bar1 + map_idx * 0x80; |
| 4397 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_CMPL, |
| 4398 | map_idx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4399 | if (rc) |
| 4400 | goto err_out; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4401 | BNXT_CP_DB(cpr->cp_doorbell, cpr->cp_raw_cons); |
| 4402 | bp->grp_info[i].cp_fw_ring_id = ring->fw_ring_id; |
Michael Chan | 486b5c2 | 2016-12-29 12:13:42 -0500 | [diff] [blame] | 4403 | |
| 4404 | if (!i) { |
| 4405 | rc = bnxt_hwrm_set_async_event_cr(bp, ring->fw_ring_id); |
| 4406 | if (rc) |
| 4407 | netdev_warn(bp->dev, "Failed to set async event completion ring.\n"); |
| 4408 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4409 | } |
| 4410 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4411 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4412 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4413 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4414 | u32 map_idx = i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4415 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4416 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_TX, |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4417 | map_idx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4418 | if (rc) |
| 4419 | goto err_out; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4420 | txr->tx_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4421 | } |
| 4422 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4423 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4424 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4425 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4426 | u32 map_idx = rxr->bnapi->index; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4427 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4428 | rc = hwrm_ring_alloc_send_msg(bp, ring, HWRM_RING_ALLOC_RX, |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4429 | map_idx); |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4430 | if (rc) |
| 4431 | goto err_out; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4432 | rxr->rx_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4433 | writel(DB_KEY_RX | rxr->rx_prod, rxr->rx_doorbell); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4434 | bp->grp_info[map_idx].rx_fw_ring_id = ring->fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4435 | } |
| 4436 | |
| 4437 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 4438 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4439 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4440 | struct bnxt_ring_struct *ring = |
| 4441 | &rxr->rx_agg_ring_struct; |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4442 | u32 grp_idx = ring->grp_idx; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4443 | u32 map_idx = grp_idx + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4444 | |
| 4445 | rc = hwrm_ring_alloc_send_msg(bp, ring, |
| 4446 | HWRM_RING_ALLOC_AGG, |
Michael Chan | 9899bb5 | 2018-03-31 13:54:16 -0400 | [diff] [blame] | 4447 | map_idx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4448 | if (rc) |
| 4449 | goto err_out; |
| 4450 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4451 | rxr->rx_agg_doorbell = bp->bar1 + map_idx * 0x80; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4452 | writel(DB_KEY_RX | rxr->rx_agg_prod, |
| 4453 | rxr->rx_agg_doorbell); |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4454 | 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] | 4455 | } |
| 4456 | } |
| 4457 | err_out: |
| 4458 | return rc; |
| 4459 | } |
| 4460 | |
| 4461 | static int hwrm_ring_free_send_msg(struct bnxt *bp, |
| 4462 | struct bnxt_ring_struct *ring, |
| 4463 | u32 ring_type, int cmpl_ring_id) |
| 4464 | { |
| 4465 | int rc; |
| 4466 | struct hwrm_ring_free_input req = {0}; |
| 4467 | struct hwrm_ring_free_output *resp = bp->hwrm_cmd_resp_addr; |
| 4468 | u16 error_code; |
| 4469 | |
Prashant Sreedharan | 74608fc | 2016-01-28 03:11:20 -0500 | [diff] [blame] | 4470 | 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] | 4471 | req.ring_type = ring_type; |
| 4472 | req.ring_id = cpu_to_le16(ring->fw_ring_id); |
| 4473 | |
| 4474 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4475 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4476 | error_code = le16_to_cpu(resp->error_code); |
| 4477 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4478 | |
| 4479 | if (rc || error_code) { |
| 4480 | switch (ring_type) { |
Michael Chan | bac9a7e | 2017-02-12 19:18:10 -0500 | [diff] [blame] | 4481 | case RING_FREE_REQ_RING_TYPE_L2_CMPL: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4482 | netdev_err(bp->dev, "hwrm_ring_free cp failed. rc:%d\n", |
| 4483 | rc); |
| 4484 | return rc; |
| 4485 | case RING_FREE_REQ_RING_TYPE_RX: |
| 4486 | netdev_err(bp->dev, "hwrm_ring_free rx failed. rc:%d\n", |
| 4487 | rc); |
| 4488 | return rc; |
| 4489 | case RING_FREE_REQ_RING_TYPE_TX: |
| 4490 | netdev_err(bp->dev, "hwrm_ring_free tx failed. rc:%d\n", |
| 4491 | rc); |
| 4492 | return rc; |
| 4493 | default: |
| 4494 | netdev_err(bp->dev, "Invalid ring\n"); |
| 4495 | return -1; |
| 4496 | } |
| 4497 | } |
| 4498 | return 0; |
| 4499 | } |
| 4500 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4501 | static void bnxt_hwrm_ring_free(struct bnxt *bp, bool close_path) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4502 | { |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4503 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4504 | |
| 4505 | if (!bp->bnapi) |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4506 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4507 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4508 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4509 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4510 | struct bnxt_ring_struct *ring = &txr->tx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4511 | u32 grp_idx = txr->bnapi->index; |
| 4512 | u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4513 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4514 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4515 | hwrm_ring_free_send_msg(bp, ring, |
| 4516 | RING_FREE_REQ_RING_TYPE_TX, |
| 4517 | close_path ? cmpl_ring_id : |
| 4518 | INVALID_HW_RING_ID); |
| 4519 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4520 | } |
| 4521 | } |
| 4522 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4523 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4524 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4525 | struct bnxt_ring_struct *ring = &rxr->rx_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4526 | u32 grp_idx = rxr->bnapi->index; |
| 4527 | u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4528 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4529 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4530 | hwrm_ring_free_send_msg(bp, ring, |
| 4531 | RING_FREE_REQ_RING_TYPE_RX, |
| 4532 | close_path ? cmpl_ring_id : |
| 4533 | INVALID_HW_RING_ID); |
| 4534 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4535 | bp->grp_info[grp_idx].rx_fw_ring_id = |
| 4536 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4537 | } |
| 4538 | } |
| 4539 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4540 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 4541 | struct bnxt_rx_ring_info *rxr = &bp->rx_ring[i]; |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4542 | struct bnxt_ring_struct *ring = &rxr->rx_agg_ring_struct; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4543 | u32 grp_idx = rxr->bnapi->index; |
| 4544 | u32 cmpl_ring_id = bp->grp_info[grp_idx].cp_fw_ring_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4545 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4546 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4547 | hwrm_ring_free_send_msg(bp, ring, |
| 4548 | RING_FREE_REQ_RING_TYPE_RX, |
| 4549 | close_path ? cmpl_ring_id : |
| 4550 | INVALID_HW_RING_ID); |
| 4551 | ring->fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 4552 | bp->grp_info[grp_idx].agg_fw_ring_id = |
| 4553 | INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4554 | } |
| 4555 | } |
| 4556 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 4557 | /* The completion rings are about to be freed. After that the |
| 4558 | * IRQ doorbell will not work anymore. So we need to disable |
| 4559 | * IRQ here. |
| 4560 | */ |
| 4561 | bnxt_disable_int_sync(bp); |
| 4562 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4563 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 4564 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 4565 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4566 | struct bnxt_ring_struct *ring = &cpr->cp_ring_struct; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4567 | |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4568 | if (ring->fw_ring_id != INVALID_HW_RING_ID) { |
| 4569 | hwrm_ring_free_send_msg(bp, ring, |
Michael Chan | bac9a7e | 2017-02-12 19:18:10 -0500 | [diff] [blame] | 4570 | RING_FREE_REQ_RING_TYPE_L2_CMPL, |
Michael Chan | edd0c2c | 2015-12-27 18:19:19 -0500 | [diff] [blame] | 4571 | INVALID_HW_RING_ID); |
| 4572 | ring->fw_ring_id = INVALID_HW_RING_ID; |
| 4573 | bp->grp_info[i].cp_fw_ring_id = INVALID_HW_RING_ID; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4574 | } |
| 4575 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4576 | } |
| 4577 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4578 | static int bnxt_hwrm_get_rings(struct bnxt *bp) |
| 4579 | { |
| 4580 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4581 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 4582 | struct hwrm_func_qcfg_input req = {0}; |
| 4583 | int rc; |
| 4584 | |
| 4585 | if (bp->hwrm_spec_code < 0x10601) |
| 4586 | return 0; |
| 4587 | |
| 4588 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4589 | req.fid = cpu_to_le16(0xffff); |
| 4590 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4591 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4592 | if (rc) { |
| 4593 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4594 | return -EIO; |
| 4595 | } |
| 4596 | |
| 4597 | hw_resc->resv_tx_rings = le16_to_cpu(resp->alloc_tx_rings); |
| 4598 | if (bp->flags & BNXT_FLAG_NEW_RM) { |
| 4599 | u16 cp, stats; |
| 4600 | |
| 4601 | hw_resc->resv_rx_rings = le16_to_cpu(resp->alloc_rx_rings); |
| 4602 | hw_resc->resv_hw_ring_grps = |
| 4603 | le32_to_cpu(resp->alloc_hw_ring_grps); |
| 4604 | hw_resc->resv_vnics = le16_to_cpu(resp->alloc_vnics); |
| 4605 | cp = le16_to_cpu(resp->alloc_cmpl_rings); |
| 4606 | stats = le16_to_cpu(resp->alloc_stat_ctx); |
| 4607 | cp = min_t(u16, cp, stats); |
| 4608 | hw_resc->resv_cp_rings = cp; |
| 4609 | } |
| 4610 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 4611 | return 0; |
| 4612 | } |
| 4613 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4614 | /* Caller must hold bp->hwrm_cmd_lock */ |
| 4615 | int __bnxt_hwrm_get_tx_rings(struct bnxt *bp, u16 fid, int *tx_rings) |
| 4616 | { |
| 4617 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 4618 | struct hwrm_func_qcfg_input req = {0}; |
| 4619 | int rc; |
| 4620 | |
| 4621 | if (bp->hwrm_spec_code < 0x10601) |
| 4622 | return 0; |
| 4623 | |
| 4624 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 4625 | req.fid = cpu_to_le16(fid); |
| 4626 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4627 | if (!rc) |
| 4628 | *tx_rings = le16_to_cpu(resp->alloc_tx_rings); |
| 4629 | |
| 4630 | return rc; |
| 4631 | } |
| 4632 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 4633 | static void |
| 4634 | __bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, struct hwrm_func_cfg_input *req, |
| 4635 | int tx_rings, int rx_rings, int ring_grps, |
| 4636 | int cp_rings, int vnics) |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4637 | { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4638 | u32 enables = 0; |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4639 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 4640 | bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_CFG, -1, -1); |
| 4641 | req->fid = cpu_to_le16(0xffff); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4642 | enables |= tx_rings ? FUNC_CFG_REQ_ENABLES_NUM_TX_RINGS : 0; |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 4643 | req->num_tx_rings = cpu_to_le16(tx_rings); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4644 | if (bp->flags & BNXT_FLAG_NEW_RM) { |
| 4645 | enables |= rx_rings ? FUNC_CFG_REQ_ENABLES_NUM_RX_RINGS : 0; |
| 4646 | enables |= cp_rings ? FUNC_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 4647 | FUNC_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0; |
| 4648 | enables |= ring_grps ? |
| 4649 | FUNC_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0; |
| 4650 | enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0; |
| 4651 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 4652 | req->num_rx_rings = cpu_to_le16(rx_rings); |
| 4653 | req->num_hw_ring_grps = cpu_to_le16(ring_grps); |
| 4654 | req->num_cmpl_rings = cpu_to_le16(cp_rings); |
| 4655 | req->num_stat_ctxs = req->num_cmpl_rings; |
| 4656 | req->num_vnics = cpu_to_le16(vnics); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4657 | } |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 4658 | req->enables = cpu_to_le32(enables); |
| 4659 | } |
| 4660 | |
| 4661 | static void |
| 4662 | __bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, |
| 4663 | struct hwrm_func_vf_cfg_input *req, int tx_rings, |
| 4664 | int rx_rings, int ring_grps, int cp_rings, |
| 4665 | int vnics) |
| 4666 | { |
| 4667 | u32 enables = 0; |
| 4668 | |
| 4669 | bnxt_hwrm_cmd_hdr_init(bp, req, HWRM_FUNC_VF_CFG, -1, -1); |
| 4670 | enables |= tx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_TX_RINGS : 0; |
| 4671 | enables |= rx_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_RX_RINGS : 0; |
| 4672 | enables |= cp_rings ? FUNC_VF_CFG_REQ_ENABLES_NUM_CMPL_RINGS | |
| 4673 | FUNC_VF_CFG_REQ_ENABLES_NUM_STAT_CTXS : 0; |
| 4674 | enables |= ring_grps ? FUNC_VF_CFG_REQ_ENABLES_NUM_HW_RING_GRPS : 0; |
| 4675 | enables |= vnics ? FUNC_VF_CFG_REQ_ENABLES_NUM_VNICS : 0; |
| 4676 | |
| 4677 | req->num_tx_rings = cpu_to_le16(tx_rings); |
| 4678 | req->num_rx_rings = cpu_to_le16(rx_rings); |
| 4679 | req->num_hw_ring_grps = cpu_to_le16(ring_grps); |
| 4680 | req->num_cmpl_rings = cpu_to_le16(cp_rings); |
| 4681 | req->num_stat_ctxs = req->num_cmpl_rings; |
| 4682 | req->num_vnics = cpu_to_le16(vnics); |
| 4683 | |
| 4684 | req->enables = cpu_to_le32(enables); |
| 4685 | } |
| 4686 | |
| 4687 | static int |
| 4688 | bnxt_hwrm_reserve_pf_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
| 4689 | int ring_grps, int cp_rings, int vnics) |
| 4690 | { |
| 4691 | struct hwrm_func_cfg_input req = {0}; |
| 4692 | int rc; |
| 4693 | |
| 4694 | __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 4695 | cp_rings, vnics); |
| 4696 | if (!req.enables) |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4697 | return 0; |
| 4698 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4699 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4700 | if (rc) |
| 4701 | return -ENOMEM; |
| 4702 | |
| 4703 | if (bp->hwrm_spec_code < 0x10601) |
| 4704 | bp->hw_resc.resv_tx_rings = tx_rings; |
| 4705 | |
| 4706 | rc = bnxt_hwrm_get_rings(bp); |
| 4707 | return rc; |
| 4708 | } |
| 4709 | |
| 4710 | static int |
| 4711 | bnxt_hwrm_reserve_vf_rings(struct bnxt *bp, int tx_rings, int rx_rings, |
| 4712 | int ring_grps, int cp_rings, int vnics) |
| 4713 | { |
| 4714 | struct hwrm_func_vf_cfg_input req = {0}; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4715 | int rc; |
| 4716 | |
| 4717 | if (!(bp->flags & BNXT_FLAG_NEW_RM)) { |
| 4718 | bp->hw_resc.resv_tx_rings = tx_rings; |
| 4719 | return 0; |
| 4720 | } |
| 4721 | |
Michael Chan | 4ed50ef | 2018-03-09 23:46:03 -0500 | [diff] [blame] | 4722 | __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 4723 | cp_rings, vnics); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4724 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4725 | if (rc) |
| 4726 | return -ENOMEM; |
| 4727 | |
| 4728 | rc = bnxt_hwrm_get_rings(bp); |
| 4729 | return rc; |
| 4730 | } |
| 4731 | |
| 4732 | static int bnxt_hwrm_reserve_rings(struct bnxt *bp, int tx, int rx, int grp, |
| 4733 | int cp, int vnic) |
| 4734 | { |
| 4735 | if (BNXT_PF(bp)) |
| 4736 | return bnxt_hwrm_reserve_pf_rings(bp, tx, rx, grp, cp, vnic); |
| 4737 | else |
| 4738 | return bnxt_hwrm_reserve_vf_rings(bp, tx, rx, grp, cp, vnic); |
| 4739 | } |
| 4740 | |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 4741 | static int bnxt_cp_rings_in_use(struct bnxt *bp) |
| 4742 | { |
| 4743 | int cp = bp->cp_nr_rings; |
| 4744 | int ulp_msix, ulp_base; |
| 4745 | |
| 4746 | ulp_msix = bnxt_get_ulp_msix_num(bp); |
| 4747 | if (ulp_msix) { |
| 4748 | ulp_base = bnxt_get_ulp_msix_base(bp); |
| 4749 | cp += ulp_msix; |
| 4750 | if ((ulp_base + ulp_msix) > cp) |
| 4751 | cp = ulp_base + ulp_msix; |
| 4752 | } |
| 4753 | return cp; |
| 4754 | } |
| 4755 | |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 4756 | static bool bnxt_need_reserve_rings(struct bnxt *bp) |
| 4757 | { |
| 4758 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 4759 | int cp = bnxt_cp_rings_in_use(bp); |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 4760 | int rx = bp->rx_nr_rings; |
| 4761 | int vnic = 1, grp = rx; |
| 4762 | |
| 4763 | if (bp->hwrm_spec_code < 0x10601) |
| 4764 | return false; |
| 4765 | |
| 4766 | if (hw_resc->resv_tx_rings != bp->tx_nr_rings) |
| 4767 | return true; |
| 4768 | |
| 4769 | if (bp->flags & BNXT_FLAG_RFS) |
| 4770 | vnic = rx + 1; |
| 4771 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 4772 | rx <<= 1; |
| 4773 | if ((bp->flags & BNXT_FLAG_NEW_RM) && |
| 4774 | (hw_resc->resv_rx_rings != rx || hw_resc->resv_cp_rings != cp || |
| 4775 | hw_resc->resv_hw_ring_grps != grp || hw_resc->resv_vnics != vnic)) |
| 4776 | return true; |
| 4777 | return false; |
| 4778 | } |
| 4779 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4780 | static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, |
| 4781 | bool shared); |
| 4782 | |
| 4783 | static int __bnxt_reserve_rings(struct bnxt *bp) |
| 4784 | { |
| 4785 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 4786 | int cp = bnxt_cp_rings_in_use(bp); |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4787 | int tx = bp->tx_nr_rings; |
| 4788 | int rx = bp->rx_nr_rings; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4789 | int grp, rx_rings, rc; |
| 4790 | bool sh = false; |
| 4791 | int vnic = 1; |
| 4792 | |
Michael Chan | 4e41dc5 | 2018-03-31 13:54:19 -0400 | [diff] [blame] | 4793 | if (!bnxt_need_reserve_rings(bp)) |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4794 | return 0; |
| 4795 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4796 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 4797 | sh = true; |
| 4798 | if (bp->flags & BNXT_FLAG_RFS) |
| 4799 | vnic = rx + 1; |
| 4800 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 4801 | rx <<= 1; |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4802 | grp = bp->rx_nr_rings; |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4803 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4804 | rc = bnxt_hwrm_reserve_rings(bp, tx, rx, grp, cp, vnic); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4805 | if (rc) |
| 4806 | return rc; |
| 4807 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 4808 | tx = hw_resc->resv_tx_rings; |
| 4809 | if (bp->flags & BNXT_FLAG_NEW_RM) { |
| 4810 | rx = hw_resc->resv_rx_rings; |
| 4811 | cp = hw_resc->resv_cp_rings; |
| 4812 | grp = hw_resc->resv_hw_ring_grps; |
| 4813 | vnic = hw_resc->resv_vnics; |
| 4814 | } |
| 4815 | |
| 4816 | rx_rings = rx; |
| 4817 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 4818 | if (rx >= 2) { |
| 4819 | rx_rings = rx >> 1; |
| 4820 | } else { |
| 4821 | if (netif_running(bp->dev)) |
| 4822 | return -ENOMEM; |
| 4823 | |
| 4824 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 4825 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS; |
| 4826 | bp->dev->hw_features &= ~NETIF_F_LRO; |
| 4827 | bp->dev->features &= ~NETIF_F_LRO; |
| 4828 | bnxt_set_ring_params(bp); |
| 4829 | } |
| 4830 | } |
| 4831 | rx_rings = min_t(int, rx_rings, grp); |
| 4832 | rc = bnxt_trim_rings(bp, &rx_rings, &tx, cp, sh); |
| 4833 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 4834 | rx = rx_rings << 1; |
| 4835 | cp = sh ? max_t(int, tx, rx_rings) : tx + rx_rings; |
| 4836 | bp->tx_nr_rings = tx; |
| 4837 | bp->rx_nr_rings = rx_rings; |
| 4838 | bp->cp_nr_rings = cp; |
| 4839 | |
| 4840 | if (!tx || !rx || !cp || !grp || !vnic) |
| 4841 | return -ENOMEM; |
| 4842 | |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 4843 | return rc; |
| 4844 | } |
| 4845 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4846 | 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] | 4847 | int ring_grps, int cp_rings, int vnics) |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 4848 | { |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4849 | struct hwrm_func_vf_cfg_input req = {0}; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4850 | u32 flags; |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 4851 | int rc; |
| 4852 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4853 | if (!(bp->flags & BNXT_FLAG_NEW_RM)) |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 4854 | return 0; |
| 4855 | |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4856 | __bnxt_hwrm_reserve_vf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 4857 | cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4858 | flags = FUNC_VF_CFG_REQ_FLAGS_TX_ASSETS_TEST | |
| 4859 | FUNC_VF_CFG_REQ_FLAGS_RX_ASSETS_TEST | |
| 4860 | FUNC_VF_CFG_REQ_FLAGS_CMPL_ASSETS_TEST | |
| 4861 | FUNC_VF_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST | |
| 4862 | FUNC_VF_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST | |
| 4863 | FUNC_VF_CFG_REQ_FLAGS_VNIC_ASSETS_TEST; |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 4864 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4865 | req.flags = cpu_to_le32(flags); |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 4866 | rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4867 | if (rc) |
| 4868 | return -ENOMEM; |
| 4869 | return 0; |
| 4870 | } |
| 4871 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4872 | 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] | 4873 | int ring_grps, int cp_rings, int vnics) |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4874 | { |
| 4875 | struct hwrm_func_cfg_input req = {0}; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4876 | u32 flags; |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4877 | int rc; |
| 4878 | |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4879 | __bnxt_hwrm_reserve_pf_rings(bp, &req, tx_rings, rx_rings, ring_grps, |
| 4880 | cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4881 | flags = FUNC_CFG_REQ_FLAGS_TX_ASSETS_TEST; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4882 | if (bp->flags & BNXT_FLAG_NEW_RM) |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4883 | flags |= FUNC_CFG_REQ_FLAGS_RX_ASSETS_TEST | |
| 4884 | FUNC_CFG_REQ_FLAGS_CMPL_ASSETS_TEST | |
| 4885 | FUNC_CFG_REQ_FLAGS_RING_GRP_ASSETS_TEST | |
| 4886 | FUNC_CFG_REQ_FLAGS_STAT_CTX_ASSETS_TEST | |
| 4887 | FUNC_CFG_REQ_FLAGS_VNIC_ASSETS_TEST; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4888 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4889 | req.flags = cpu_to_le32(flags); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4890 | rc = hwrm_send_message_silent(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 4891 | if (rc) |
| 4892 | return -ENOMEM; |
| 4893 | return 0; |
| 4894 | } |
| 4895 | |
| 4896 | 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] | 4897 | int ring_grps, int cp_rings, int vnics) |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4898 | { |
| 4899 | if (bp->hwrm_spec_code < 0x10801) |
| 4900 | return 0; |
| 4901 | |
| 4902 | if (BNXT_PF(bp)) |
| 4903 | return bnxt_hwrm_check_pf_rings(bp, tx_rings, rx_rings, |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 4904 | ring_grps, cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4905 | |
| 4906 | 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] | 4907 | cp_rings, vnics); |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 4908 | } |
| 4909 | |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 4910 | static void bnxt_hwrm_set_coal_params(struct bnxt_coal *hw_coal, |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4911 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input *req) |
| 4912 | { |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 4913 | u16 val, tmr, max, flags; |
| 4914 | |
| 4915 | max = hw_coal->bufs_per_record * 128; |
| 4916 | if (hw_coal->budget) |
| 4917 | max = hw_coal->bufs_per_record * hw_coal->budget; |
| 4918 | |
| 4919 | val = clamp_t(u16, hw_coal->coal_bufs, 1, max); |
| 4920 | req->num_cmpl_aggr_int = cpu_to_le16(val); |
Michael Chan | b153cbc | 2017-11-03 03:32:39 -0400 | [diff] [blame] | 4921 | |
| 4922 | /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */ |
| 4923 | val = min_t(u16, val, 63); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 4924 | req->num_cmpl_dma_aggr = cpu_to_le16(val); |
| 4925 | |
Michael Chan | b153cbc | 2017-11-03 03:32:39 -0400 | [diff] [blame] | 4926 | /* This is a 6-bit value and must not be 0, or we'll get non stop IRQ */ |
| 4927 | val = clamp_t(u16, hw_coal->coal_bufs_irq, 1, 63); |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 4928 | req->num_cmpl_dma_aggr_during_int = cpu_to_le16(val); |
| 4929 | |
| 4930 | tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks); |
| 4931 | tmr = max_t(u16, tmr, 1); |
| 4932 | req->int_lat_tmr_max = cpu_to_le16(tmr); |
| 4933 | |
| 4934 | /* min timer set to 1/2 of interrupt timer */ |
| 4935 | val = tmr / 2; |
| 4936 | req->int_lat_tmr_min = cpu_to_le16(val); |
| 4937 | |
| 4938 | /* buf timer set to 1/4 of interrupt timer */ |
| 4939 | val = max_t(u16, tmr / 4, 1); |
| 4940 | req->cmpl_aggr_dma_tmr = cpu_to_le16(val); |
| 4941 | |
| 4942 | tmr = BNXT_USEC_TO_COAL_TIMER(hw_coal->coal_ticks_irq); |
| 4943 | tmr = max_t(u16, tmr, 1); |
| 4944 | req->cmpl_aggr_dma_tmr_during_int = cpu_to_le16(tmr); |
| 4945 | |
| 4946 | flags = RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_TIMER_RESET; |
| 4947 | if (hw_coal->idle_thresh && hw_coal->coal_ticks < hw_coal->idle_thresh) |
| 4948 | flags |= RING_CMPL_RING_CFG_AGGINT_PARAMS_REQ_FLAGS_RING_IDLE; |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4949 | req->flags = cpu_to_le16(flags); |
Michael Chan | bb053f5 | 2016-02-26 04:00:02 -0500 | [diff] [blame] | 4950 | } |
| 4951 | |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 4952 | int bnxt_hwrm_set_ring_coal(struct bnxt *bp, struct bnxt_napi *bnapi) |
| 4953 | { |
| 4954 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0}; |
| 4955 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 4956 | struct bnxt_coal coal; |
| 4957 | unsigned int grp_idx; |
| 4958 | |
| 4959 | /* Tick values in micro seconds. |
| 4960 | * 1 coal_buf x bufs_per_record = 1 completion record. |
| 4961 | */ |
| 4962 | memcpy(&coal, &bp->rx_coal, sizeof(struct bnxt_coal)); |
| 4963 | |
| 4964 | coal.coal_ticks = cpr->rx_ring_coal.coal_ticks; |
| 4965 | coal.coal_bufs = cpr->rx_ring_coal.coal_bufs; |
| 4966 | |
| 4967 | if (!bnapi->rx_ring) |
| 4968 | return -ENODEV; |
| 4969 | |
| 4970 | bnxt_hwrm_cmd_hdr_init(bp, &req_rx, |
| 4971 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
| 4972 | |
| 4973 | bnxt_hwrm_set_coal_params(&coal, &req_rx); |
| 4974 | |
| 4975 | grp_idx = bnapi->index; |
| 4976 | req_rx.ring_id = cpu_to_le16(bp->grp_info[grp_idx].cp_fw_ring_id); |
| 4977 | |
| 4978 | return hwrm_send_message(bp, &req_rx, sizeof(req_rx), |
| 4979 | HWRM_CMD_TIMEOUT); |
| 4980 | } |
| 4981 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4982 | int bnxt_hwrm_set_coal(struct bnxt *bp) |
| 4983 | { |
| 4984 | int i, rc = 0; |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4985 | struct hwrm_ring_cmpl_ring_cfg_aggint_params_input req_rx = {0}, |
| 4986 | req_tx = {0}, *req; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4987 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4988 | bnxt_hwrm_cmd_hdr_init(bp, &req_rx, |
| 4989 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
| 4990 | bnxt_hwrm_cmd_hdr_init(bp, &req_tx, |
| 4991 | HWRM_RING_CMPL_RING_CFG_AGGINT_PARAMS, -1, -1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4992 | |
Michael Chan | f850396 | 2017-10-26 11:51:28 -0400 | [diff] [blame] | 4993 | bnxt_hwrm_set_coal_params(&bp->rx_coal, &req_rx); |
| 4994 | bnxt_hwrm_set_coal_params(&bp->tx_coal, &req_tx); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4995 | |
| 4996 | mutex_lock(&bp->hwrm_cmd_lock); |
| 4997 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 4998 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 4999 | |
Michael Chan | dfc9c94 | 2016-02-26 04:00:03 -0500 | [diff] [blame] | 5000 | req = &req_rx; |
| 5001 | if (!bnapi->rx_ring) |
| 5002 | req = &req_tx; |
| 5003 | req->ring_id = cpu_to_le16(bp->grp_info[i].cp_fw_ring_id); |
| 5004 | |
| 5005 | rc = _hwrm_send_message(bp, req, sizeof(*req), |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5006 | HWRM_CMD_TIMEOUT); |
| 5007 | if (rc) |
| 5008 | break; |
| 5009 | } |
| 5010 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5011 | return rc; |
| 5012 | } |
| 5013 | |
| 5014 | static int bnxt_hwrm_stat_ctx_free(struct bnxt *bp) |
| 5015 | { |
| 5016 | int rc = 0, i; |
| 5017 | struct hwrm_stat_ctx_free_input req = {0}; |
| 5018 | |
| 5019 | if (!bp->bnapi) |
| 5020 | return 0; |
| 5021 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 5022 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5023 | return 0; |
| 5024 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5025 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_FREE, -1, -1); |
| 5026 | |
| 5027 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5028 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5029 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5030 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 5031 | |
| 5032 | if (cpr->hw_stats_ctx_id != INVALID_STATS_CTX_ID) { |
| 5033 | req.stat_ctx_id = cpu_to_le32(cpr->hw_stats_ctx_id); |
| 5034 | |
| 5035 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 5036 | HWRM_CMD_TIMEOUT); |
| 5037 | if (rc) |
| 5038 | break; |
| 5039 | |
| 5040 | cpr->hw_stats_ctx_id = INVALID_STATS_CTX_ID; |
| 5041 | } |
| 5042 | } |
| 5043 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5044 | return rc; |
| 5045 | } |
| 5046 | |
| 5047 | static int bnxt_hwrm_stat_ctx_alloc(struct bnxt *bp) |
| 5048 | { |
| 5049 | int rc = 0, i; |
| 5050 | struct hwrm_stat_ctx_alloc_input req = {0}; |
| 5051 | struct hwrm_stat_ctx_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 5052 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 5053 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5054 | return 0; |
| 5055 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5056 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_STAT_CTX_ALLOC, -1, -1); |
| 5057 | |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 5058 | req.update_period_ms = cpu_to_le32(bp->stats_coal_ticks / 1000); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5059 | |
| 5060 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5061 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 5062 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 5063 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 5064 | |
| 5065 | req.stats_dma_addr = cpu_to_le64(cpr->hw_stats_map); |
| 5066 | |
| 5067 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 5068 | HWRM_CMD_TIMEOUT); |
| 5069 | if (rc) |
| 5070 | break; |
| 5071 | |
| 5072 | cpr->hw_stats_ctx_id = le32_to_cpu(resp->stat_ctx_id); |
| 5073 | |
| 5074 | bp->grp_info[i].fw_stats_ctx = cpr->hw_stats_ctx_id; |
| 5075 | } |
| 5076 | mutex_unlock(&bp->hwrm_cmd_lock); |
Pan Bian | 89aa844 | 2016-12-03 17:56:17 +0800 | [diff] [blame] | 5077 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5078 | } |
| 5079 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5080 | static int bnxt_hwrm_func_qcfg(struct bnxt *bp) |
| 5081 | { |
| 5082 | struct hwrm_func_qcfg_input req = {0}; |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 5083 | struct hwrm_func_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5084 | u16 flags; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5085 | int rc; |
| 5086 | |
| 5087 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCFG, -1, -1); |
| 5088 | req.fid = cpu_to_le16(0xffff); |
| 5089 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5090 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5091 | if (rc) |
| 5092 | goto func_qcfg_exit; |
| 5093 | |
| 5094 | #ifdef CONFIG_BNXT_SRIOV |
| 5095 | if (BNXT_VF(bp)) { |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5096 | struct bnxt_vf_info *vf = &bp->vf; |
| 5097 | |
| 5098 | vf->vlan = le16_to_cpu(resp->vlan) & VLAN_VID_MASK; |
| 5099 | } |
| 5100 | #endif |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5101 | flags = le16_to_cpu(resp->flags); |
| 5102 | if (flags & (FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED | |
| 5103 | FUNC_QCFG_RESP_FLAGS_FW_LLDP_AGENT_ENABLED)) { |
| 5104 | bp->flags |= BNXT_FLAG_FW_LLDP_AGENT; |
| 5105 | if (flags & FUNC_QCFG_RESP_FLAGS_FW_DCBX_AGENT_ENABLED) |
| 5106 | bp->flags |= BNXT_FLAG_FW_DCBX_AGENT; |
Deepak Khungar | 9e54e32 | 2017-04-21 20:11:26 -0400 | [diff] [blame] | 5107 | } |
Michael Chan | 9315edc | 2017-07-24 12:34:25 -0400 | [diff] [blame] | 5108 | if (BNXT_PF(bp) && (flags & FUNC_QCFG_RESP_FLAGS_MULTI_HOST)) |
| 5109 | bp->flags |= BNXT_FLAG_MULTI_HOST; |
Michael Chan | bc39f88 | 2017-03-08 18:44:34 -0500 | [diff] [blame] | 5110 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 5111 | switch (resp->port_partition_type) { |
| 5112 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_0: |
| 5113 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR1_5: |
| 5114 | case FUNC_QCFG_RESP_PORT_PARTITION_TYPE_NPAR2_0: |
| 5115 | bp->port_partition_type = resp->port_partition_type; |
| 5116 | break; |
| 5117 | } |
Michael Chan | 32e8239c | 2017-07-24 12:34:21 -0400 | [diff] [blame] | 5118 | if (bp->hwrm_spec_code < 0x10707 || |
| 5119 | resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEB) |
| 5120 | bp->br_mode = BRIDGE_MODE_VEB; |
| 5121 | else if (resp->evb_mode == FUNC_QCFG_RESP_EVB_MODE_VEPA) |
| 5122 | bp->br_mode = BRIDGE_MODE_VEPA; |
| 5123 | else |
| 5124 | bp->br_mode = BRIDGE_MODE_UNDEF; |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5125 | |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 5126 | bp->max_mtu = le16_to_cpu(resp->max_mtu_configured); |
| 5127 | if (!bp->max_mtu) |
| 5128 | bp->max_mtu = BNXT_MAX_MTU; |
| 5129 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5130 | func_qcfg_exit: |
| 5131 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5132 | return rc; |
| 5133 | } |
| 5134 | |
Michael Chan | db4723b | 2018-03-31 13:54:13 -0400 | [diff] [blame] | 5135 | int bnxt_hwrm_func_resc_qcaps(struct bnxt *bp, bool all) |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5136 | { |
| 5137 | struct hwrm_func_resource_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 5138 | struct hwrm_func_resource_qcaps_input req = {0}; |
| 5139 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 5140 | int rc; |
| 5141 | |
| 5142 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESOURCE_QCAPS, -1, -1); |
| 5143 | req.fid = cpu_to_le16(0xffff); |
| 5144 | |
| 5145 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5146 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5147 | if (rc) { |
| 5148 | rc = -EIO; |
| 5149 | goto hwrm_func_resc_qcaps_exit; |
| 5150 | } |
| 5151 | |
Michael Chan | db4723b | 2018-03-31 13:54:13 -0400 | [diff] [blame] | 5152 | hw_resc->max_tx_sch_inputs = le16_to_cpu(resp->max_tx_scheduler_inputs); |
| 5153 | if (!all) |
| 5154 | goto hwrm_func_resc_qcaps_exit; |
| 5155 | |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5156 | hw_resc->min_rsscos_ctxs = le16_to_cpu(resp->min_rsscos_ctx); |
| 5157 | hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 5158 | hw_resc->min_cp_rings = le16_to_cpu(resp->min_cmpl_rings); |
| 5159 | hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 5160 | hw_resc->min_tx_rings = le16_to_cpu(resp->min_tx_rings); |
| 5161 | hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
| 5162 | hw_resc->min_rx_rings = le16_to_cpu(resp->min_rx_rings); |
| 5163 | hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
| 5164 | hw_resc->min_hw_ring_grps = le16_to_cpu(resp->min_hw_ring_grps); |
| 5165 | hw_resc->max_hw_ring_grps = le16_to_cpu(resp->max_hw_ring_grps); |
| 5166 | hw_resc->min_l2_ctxs = le16_to_cpu(resp->min_l2_ctxs); |
| 5167 | hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 5168 | hw_resc->min_vnics = le16_to_cpu(resp->min_vnics); |
| 5169 | hw_resc->max_vnics = le16_to_cpu(resp->max_vnics); |
| 5170 | hw_resc->min_stat_ctxs = le16_to_cpu(resp->min_stat_ctx); |
| 5171 | hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
| 5172 | |
Michael Chan | 4673d66 | 2018-01-17 03:21:11 -0500 | [diff] [blame] | 5173 | if (BNXT_PF(bp)) { |
| 5174 | struct bnxt_pf_info *pf = &bp->pf; |
| 5175 | |
| 5176 | pf->vf_resv_strategy = |
| 5177 | le16_to_cpu(resp->vf_reservation_strategy); |
| 5178 | if (pf->vf_resv_strategy > BNXT_VF_RESV_STRATEGY_MINIMAL) |
| 5179 | pf->vf_resv_strategy = BNXT_VF_RESV_STRATEGY_MAXIMAL; |
| 5180 | } |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5181 | hwrm_func_resc_qcaps_exit: |
| 5182 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5183 | return rc; |
| 5184 | } |
| 5185 | |
| 5186 | static int __bnxt_hwrm_func_qcaps(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5187 | { |
| 5188 | int rc = 0; |
| 5189 | struct hwrm_func_qcaps_input req = {0}; |
| 5190 | struct hwrm_func_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5191 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 5192 | u32 flags; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5193 | |
| 5194 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_QCAPS, -1, -1); |
| 5195 | req.fid = cpu_to_le16(0xffff); |
| 5196 | |
| 5197 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5198 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5199 | if (rc) |
| 5200 | goto hwrm_func_qcaps_exit; |
| 5201 | |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5202 | flags = le32_to_cpu(resp->flags); |
| 5203 | if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V1_SUPPORTED) |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5204 | bp->flags |= BNXT_FLAG_ROCEV1_CAP; |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5205 | if (flags & FUNC_QCAPS_RESP_FLAGS_ROCE_V2_SUPPORTED) |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5206 | bp->flags |= BNXT_FLAG_ROCEV2_CAP; |
| 5207 | |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 5208 | bp->tx_push_thresh = 0; |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5209 | if (flags & FUNC_QCAPS_RESP_FLAGS_PUSH_MODE_SUPPORTED) |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 5210 | bp->tx_push_thresh = BNXT_TX_PUSH_THRESH; |
| 5211 | |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5212 | hw_resc->max_rsscos_ctxs = le16_to_cpu(resp->max_rsscos_ctx); |
| 5213 | hw_resc->max_cp_rings = le16_to_cpu(resp->max_cmpl_rings); |
| 5214 | hw_resc->max_tx_rings = le16_to_cpu(resp->max_tx_rings); |
| 5215 | hw_resc->max_rx_rings = le16_to_cpu(resp->max_rx_rings); |
| 5216 | hw_resc->max_hw_ring_grps = le32_to_cpu(resp->max_hw_ring_grps); |
| 5217 | if (!hw_resc->max_hw_ring_grps) |
| 5218 | hw_resc->max_hw_ring_grps = hw_resc->max_tx_rings; |
| 5219 | hw_resc->max_l2_ctxs = le16_to_cpu(resp->max_l2_ctxs); |
| 5220 | hw_resc->max_vnics = le16_to_cpu(resp->max_vnics); |
| 5221 | hw_resc->max_stat_ctxs = le16_to_cpu(resp->max_stat_ctx); |
| 5222 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5223 | if (BNXT_PF(bp)) { |
| 5224 | struct bnxt_pf_info *pf = &bp->pf; |
| 5225 | |
| 5226 | pf->fw_fid = le16_to_cpu(resp->fid); |
| 5227 | pf->port_id = le16_to_cpu(resp->port_id); |
Michael Chan | 87027db | 2016-07-01 18:46:28 -0400 | [diff] [blame] | 5228 | bp->dev->dev_port = pf->port_id; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 5229 | memcpy(pf->mac_addr, resp->mac_address, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5230 | pf->first_vf_id = le16_to_cpu(resp->first_vf_id); |
| 5231 | pf->max_vfs = le16_to_cpu(resp->max_vfs); |
| 5232 | pf->max_encap_records = le32_to_cpu(resp->max_encap_records); |
| 5233 | pf->max_decap_records = le32_to_cpu(resp->max_decap_records); |
| 5234 | pf->max_tx_em_flows = le32_to_cpu(resp->max_tx_em_flows); |
| 5235 | pf->max_tx_wm_flows = le32_to_cpu(resp->max_tx_wm_flows); |
| 5236 | pf->max_rx_em_flows = le32_to_cpu(resp->max_rx_em_flows); |
| 5237 | 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] | 5238 | if (flags & FUNC_QCAPS_RESP_FLAGS_WOL_MAGICPKT_SUPPORTED) |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 5239 | bp->flags |= BNXT_FLAG_WOL_CAP; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5240 | } else { |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 5241 | #ifdef CONFIG_BNXT_SRIOV |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5242 | struct bnxt_vf_info *vf = &bp->vf; |
| 5243 | |
| 5244 | vf->fw_fid = le16_to_cpu(resp->fid); |
Michael Chan | 7cc5a20 | 2016-09-19 03:58:05 -0400 | [diff] [blame] | 5245 | memcpy(vf->mac_addr, resp->mac_address, ETH_ALEN); |
Michael Chan | 379a80a | 2015-10-23 15:06:19 -0400 | [diff] [blame] | 5246 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5247 | } |
| 5248 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5249 | hwrm_func_qcaps_exit: |
| 5250 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5251 | return rc; |
| 5252 | } |
| 5253 | |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5254 | static int bnxt_hwrm_func_qcaps(struct bnxt *bp) |
| 5255 | { |
| 5256 | int rc; |
| 5257 | |
| 5258 | rc = __bnxt_hwrm_func_qcaps(bp); |
| 5259 | if (rc) |
| 5260 | return rc; |
| 5261 | if (bp->hwrm_spec_code >= 0x10803) { |
Michael Chan | db4723b | 2018-03-31 13:54:13 -0400 | [diff] [blame] | 5262 | rc = bnxt_hwrm_func_resc_qcaps(bp, true); |
Michael Chan | be0dd9c | 2018-01-17 03:21:07 -0500 | [diff] [blame] | 5263 | if (!rc) |
| 5264 | bp->flags |= BNXT_FLAG_NEW_RM; |
| 5265 | } |
| 5266 | return 0; |
| 5267 | } |
| 5268 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5269 | static int bnxt_hwrm_func_reset(struct bnxt *bp) |
| 5270 | { |
| 5271 | struct hwrm_func_reset_input req = {0}; |
| 5272 | |
| 5273 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_RESET, -1, -1); |
| 5274 | req.enables = 0; |
| 5275 | |
| 5276 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_RESET_TIMEOUT); |
| 5277 | } |
| 5278 | |
| 5279 | static int bnxt_hwrm_queue_qportcfg(struct bnxt *bp) |
| 5280 | { |
| 5281 | int rc = 0; |
| 5282 | struct hwrm_queue_qportcfg_input req = {0}; |
| 5283 | struct hwrm_queue_qportcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 5284 | u8 i, *qptr; |
| 5285 | |
| 5286 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_QUEUE_QPORTCFG, -1, -1); |
| 5287 | |
| 5288 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5289 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5290 | if (rc) |
| 5291 | goto qportcfg_exit; |
| 5292 | |
| 5293 | if (!resp->max_configurable_queues) { |
| 5294 | rc = -EINVAL; |
| 5295 | goto qportcfg_exit; |
| 5296 | } |
| 5297 | bp->max_tc = resp->max_configurable_queues; |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 5298 | bp->max_lltc = resp->max_configurable_lossless_queues; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5299 | if (bp->max_tc > BNXT_MAX_QUEUE) |
| 5300 | bp->max_tc = BNXT_MAX_QUEUE; |
| 5301 | |
Michael Chan | 441cabb | 2016-09-19 03:58:02 -0400 | [diff] [blame] | 5302 | if (resp->queue_cfg_info & QUEUE_QPORTCFG_RESP_QUEUE_CFG_INFO_ASYM_CFG) |
| 5303 | bp->max_tc = 1; |
| 5304 | |
Michael Chan | 87c374d | 2016-12-02 21:17:16 -0500 | [diff] [blame] | 5305 | if (bp->max_lltc > bp->max_tc) |
| 5306 | bp->max_lltc = bp->max_tc; |
| 5307 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5308 | qptr = &resp->queue_id0; |
| 5309 | for (i = 0; i < bp->max_tc; i++) { |
| 5310 | bp->q_info[i].queue_id = *qptr++; |
| 5311 | bp->q_info[i].queue_profile = *qptr++; |
| 5312 | } |
| 5313 | |
| 5314 | qportcfg_exit: |
| 5315 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5316 | return rc; |
| 5317 | } |
| 5318 | |
| 5319 | static int bnxt_hwrm_ver_get(struct bnxt *bp) |
| 5320 | { |
| 5321 | int rc; |
| 5322 | struct hwrm_ver_get_input req = {0}; |
| 5323 | struct hwrm_ver_get_output *resp = bp->hwrm_cmd_resp_addr; |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 5324 | u32 dev_caps_cfg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5325 | |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 5326 | bp->hwrm_max_req_len = HWRM_MAX_REQ_LEN; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5327 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_VER_GET, -1, -1); |
| 5328 | req.hwrm_intf_maj = HWRM_VERSION_MAJOR; |
| 5329 | req.hwrm_intf_min = HWRM_VERSION_MINOR; |
| 5330 | req.hwrm_intf_upd = HWRM_VERSION_UPDATE; |
| 5331 | mutex_lock(&bp->hwrm_cmd_lock); |
| 5332 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5333 | if (rc) |
| 5334 | goto hwrm_ver_get_exit; |
| 5335 | |
| 5336 | memcpy(&bp->ver_resp, resp, sizeof(struct hwrm_ver_get_output)); |
| 5337 | |
Michael Chan | 894aa69 | 2018-01-17 03:21:03 -0500 | [diff] [blame] | 5338 | bp->hwrm_spec_code = resp->hwrm_intf_maj_8b << 16 | |
| 5339 | resp->hwrm_intf_min_8b << 8 | |
| 5340 | resp->hwrm_intf_upd_8b; |
| 5341 | if (resp->hwrm_intf_maj_8b < 1) { |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 5342 | 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] | 5343 | resp->hwrm_intf_maj_8b, resp->hwrm_intf_min_8b, |
| 5344 | resp->hwrm_intf_upd_8b); |
Michael Chan | c193554 | 2015-12-27 18:19:28 -0500 | [diff] [blame] | 5345 | 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] | 5346 | } |
Michael Chan | 431aa1e | 2017-10-26 11:51:23 -0400 | [diff] [blame] | 5347 | 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] | 5348 | resp->hwrm_fw_maj_8b, resp->hwrm_fw_min_8b, |
| 5349 | resp->hwrm_fw_bld_8b, resp->hwrm_fw_rsvd_8b); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5350 | |
Michael Chan | ff4fe81 | 2016-02-26 04:00:04 -0500 | [diff] [blame] | 5351 | bp->hwrm_cmd_timeout = le16_to_cpu(resp->def_req_timeout); |
| 5352 | if (!bp->hwrm_cmd_timeout) |
| 5353 | bp->hwrm_cmd_timeout = DFLT_HWRM_CMD_TIMEOUT; |
| 5354 | |
Michael Chan | 894aa69 | 2018-01-17 03:21:03 -0500 | [diff] [blame] | 5355 | if (resp->hwrm_intf_maj_8b >= 1) |
Michael Chan | e6ef269 | 2016-03-28 19:46:05 -0400 | [diff] [blame] | 5356 | bp->hwrm_max_req_len = le16_to_cpu(resp->max_req_win_len); |
| 5357 | |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 5358 | bp->chip_num = le16_to_cpu(resp->chip_num); |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 5359 | if (bp->chip_num == CHIP_NUM_58700 && !resp->chip_rev && |
| 5360 | !resp->chip_metal) |
| 5361 | bp->flags |= BNXT_FLAG_CHIP_NITRO_A0; |
Michael Chan | 659c805 | 2016-06-13 02:25:33 -0400 | [diff] [blame] | 5362 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 5363 | dev_caps_cfg = le32_to_cpu(resp->dev_caps_cfg); |
| 5364 | if ((dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_SUPPORTED) && |
| 5365 | (dev_caps_cfg & VER_GET_RESP_DEV_CAPS_CFG_SHORT_CMD_REQUIRED)) |
| 5366 | bp->flags |= BNXT_FLAG_SHORT_CMD; |
| 5367 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5368 | hwrm_ver_get_exit: |
| 5369 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 5370 | return rc; |
| 5371 | } |
| 5372 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 5373 | int bnxt_hwrm_fw_set_time(struct bnxt *bp) |
| 5374 | { |
| 5375 | struct hwrm_fw_set_time_input req = {0}; |
Arnd Bergmann | 7dfaa7b | 2017-11-06 15:04:39 +0100 | [diff] [blame] | 5376 | struct tm tm; |
| 5377 | time64_t now = ktime_get_real_seconds(); |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 5378 | |
| 5379 | if (bp->hwrm_spec_code < 0x10400) |
| 5380 | return -EOPNOTSUPP; |
| 5381 | |
Arnd Bergmann | 7dfaa7b | 2017-11-06 15:04:39 +0100 | [diff] [blame] | 5382 | time64_to_tm(now, 0, &tm); |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 5383 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FW_SET_TIME, -1, -1); |
| 5384 | req.year = cpu_to_le16(1900 + tm.tm_year); |
| 5385 | req.month = 1 + tm.tm_mon; |
| 5386 | req.day = tm.tm_mday; |
| 5387 | req.hour = tm.tm_hour; |
| 5388 | req.minute = tm.tm_min; |
| 5389 | req.second = tm.tm_sec; |
| 5390 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5391 | } |
| 5392 | |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 5393 | static int bnxt_hwrm_port_qstats(struct bnxt *bp) |
| 5394 | { |
| 5395 | int rc; |
| 5396 | struct bnxt_pf_info *pf = &bp->pf; |
| 5397 | struct hwrm_port_qstats_input req = {0}; |
| 5398 | |
| 5399 | if (!(bp->flags & BNXT_FLAG_PORT_STATS)) |
| 5400 | return 0; |
| 5401 | |
| 5402 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS, -1, -1); |
| 5403 | req.port_id = cpu_to_le16(pf->port_id); |
| 5404 | req.tx_stat_host_addr = cpu_to_le64(bp->hw_tx_port_stats_map); |
| 5405 | req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_map); |
| 5406 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5407 | return rc; |
| 5408 | } |
| 5409 | |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 5410 | static int bnxt_hwrm_port_qstats_ext(struct bnxt *bp) |
| 5411 | { |
| 5412 | struct hwrm_port_qstats_ext_input req = {0}; |
| 5413 | struct bnxt_pf_info *pf = &bp->pf; |
| 5414 | |
| 5415 | if (!(bp->flags & BNXT_FLAG_PORT_STATS_EXT)) |
| 5416 | return 0; |
| 5417 | |
| 5418 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_QSTATS_EXT, -1, -1); |
| 5419 | req.port_id = cpu_to_le16(pf->port_id); |
| 5420 | req.rx_stat_size = cpu_to_le16(sizeof(struct rx_port_stats_ext)); |
| 5421 | req.rx_stat_host_addr = cpu_to_le64(bp->hw_rx_port_stats_ext_map); |
| 5422 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5423 | } |
| 5424 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5425 | static void bnxt_hwrm_free_tunnel_ports(struct bnxt *bp) |
| 5426 | { |
| 5427 | if (bp->vxlan_port_cnt) { |
| 5428 | bnxt_hwrm_tunnel_dst_port_free( |
| 5429 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 5430 | } |
| 5431 | bp->vxlan_port_cnt = 0; |
| 5432 | if (bp->nge_port_cnt) { |
| 5433 | bnxt_hwrm_tunnel_dst_port_free( |
| 5434 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 5435 | } |
| 5436 | bp->nge_port_cnt = 0; |
| 5437 | } |
| 5438 | |
| 5439 | static int bnxt_set_tpa(struct bnxt *bp, bool set_tpa) |
| 5440 | { |
| 5441 | int rc, i; |
| 5442 | u32 tpa_flags = 0; |
| 5443 | |
| 5444 | if (set_tpa) |
| 5445 | tpa_flags = bp->flags & BNXT_FLAG_TPA; |
| 5446 | for (i = 0; i < bp->nr_vnics; i++) { |
| 5447 | rc = bnxt_hwrm_vnic_set_tpa(bp, i, tpa_flags); |
| 5448 | if (rc) { |
| 5449 | 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] | 5450 | i, rc); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5451 | return rc; |
| 5452 | } |
| 5453 | } |
| 5454 | return 0; |
| 5455 | } |
| 5456 | |
| 5457 | static void bnxt_hwrm_clear_vnic_rss(struct bnxt *bp) |
| 5458 | { |
| 5459 | int i; |
| 5460 | |
| 5461 | for (i = 0; i < bp->nr_vnics; i++) |
| 5462 | bnxt_hwrm_vnic_set_rss(bp, i, false); |
| 5463 | } |
| 5464 | |
| 5465 | static void bnxt_hwrm_resource_free(struct bnxt *bp, bool close_path, |
| 5466 | bool irq_re_init) |
| 5467 | { |
| 5468 | if (bp->vnic_info) { |
| 5469 | bnxt_hwrm_clear_vnic_filter(bp); |
| 5470 | /* clear all RSS setting before free vnic ctx */ |
| 5471 | bnxt_hwrm_clear_vnic_rss(bp); |
| 5472 | bnxt_hwrm_vnic_ctx_free(bp); |
| 5473 | /* before free the vnic, undo the vnic tpa settings */ |
| 5474 | if (bp->flags & BNXT_FLAG_TPA) |
| 5475 | bnxt_set_tpa(bp, false); |
| 5476 | bnxt_hwrm_vnic_free(bp); |
| 5477 | } |
| 5478 | bnxt_hwrm_ring_free(bp, close_path); |
| 5479 | bnxt_hwrm_ring_grp_free(bp); |
| 5480 | if (irq_re_init) { |
| 5481 | bnxt_hwrm_stat_ctx_free(bp); |
| 5482 | bnxt_hwrm_free_tunnel_ports(bp); |
| 5483 | } |
| 5484 | } |
| 5485 | |
Michael Chan | 39d8ba2 | 2017-07-24 12:34:22 -0400 | [diff] [blame] | 5486 | static int bnxt_hwrm_set_br_mode(struct bnxt *bp, u16 br_mode) |
| 5487 | { |
| 5488 | struct hwrm_func_cfg_input req = {0}; |
| 5489 | int rc; |
| 5490 | |
| 5491 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 5492 | req.fid = cpu_to_le16(0xffff); |
| 5493 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_EVB_MODE); |
| 5494 | if (br_mode == BRIDGE_MODE_VEB) |
| 5495 | req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEB; |
| 5496 | else if (br_mode == BRIDGE_MODE_VEPA) |
| 5497 | req.evb_mode = FUNC_CFG_REQ_EVB_MODE_VEPA; |
| 5498 | else |
| 5499 | return -EINVAL; |
| 5500 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5501 | if (rc) |
| 5502 | rc = -EIO; |
| 5503 | return rc; |
| 5504 | } |
| 5505 | |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 5506 | static int bnxt_hwrm_set_cache_line_size(struct bnxt *bp, int size) |
| 5507 | { |
| 5508 | struct hwrm_func_cfg_input req = {0}; |
| 5509 | int rc; |
| 5510 | |
| 5511 | if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10803) |
| 5512 | return 0; |
| 5513 | |
| 5514 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_FUNC_CFG, -1, -1); |
| 5515 | req.fid = cpu_to_le16(0xffff); |
| 5516 | req.enables = cpu_to_le32(FUNC_CFG_REQ_ENABLES_CACHE_LINESIZE); |
Michael Chan | d4f52de0 | 2018-03-31 13:54:06 -0400 | [diff] [blame] | 5517 | req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_64; |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 5518 | if (size == 128) |
Michael Chan | d4f52de0 | 2018-03-31 13:54:06 -0400 | [diff] [blame] | 5519 | req.options = FUNC_CFG_REQ_OPTIONS_CACHE_LINESIZE_SIZE_128; |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 5520 | |
| 5521 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 5522 | if (rc) |
| 5523 | rc = -EIO; |
| 5524 | return rc; |
| 5525 | } |
| 5526 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5527 | static int bnxt_setup_vnic(struct bnxt *bp, u16 vnic_id) |
| 5528 | { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 5529 | struct bnxt_vnic_info *vnic = &bp->vnic_info[vnic_id]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5530 | int rc; |
| 5531 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 5532 | if (vnic->flags & BNXT_VNIC_RFS_NEW_RSS_FLAG) |
| 5533 | goto skip_rss_ctx; |
| 5534 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5535 | /* allocate context for vnic */ |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 5536 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 0); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5537 | if (rc) { |
| 5538 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 5539 | vnic_id, rc); |
| 5540 | goto vnic_setup_err; |
| 5541 | } |
| 5542 | bp->rsscos_nr_ctxs++; |
| 5543 | |
Prashant Sreedharan | 94ce9ca | 2016-07-18 07:15:21 -0400 | [diff] [blame] | 5544 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 5545 | rc = bnxt_hwrm_vnic_ctx_alloc(bp, vnic_id, 1); |
| 5546 | if (rc) { |
| 5547 | netdev_err(bp->dev, "hwrm vnic %d cos ctx alloc failure rc: %x\n", |
| 5548 | vnic_id, rc); |
| 5549 | goto vnic_setup_err; |
| 5550 | } |
| 5551 | bp->rsscos_nr_ctxs++; |
| 5552 | } |
| 5553 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 5554 | skip_rss_ctx: |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5555 | /* configure default vnic, ring grp */ |
| 5556 | rc = bnxt_hwrm_vnic_cfg(bp, vnic_id); |
| 5557 | if (rc) { |
| 5558 | netdev_err(bp->dev, "hwrm vnic %d cfg failure rc: %x\n", |
| 5559 | vnic_id, rc); |
| 5560 | goto vnic_setup_err; |
| 5561 | } |
| 5562 | |
| 5563 | /* Enable RSS hashing on vnic */ |
| 5564 | rc = bnxt_hwrm_vnic_set_rss(bp, vnic_id, true); |
| 5565 | if (rc) { |
| 5566 | netdev_err(bp->dev, "hwrm vnic %d set rss failure rc: %x\n", |
| 5567 | vnic_id, rc); |
| 5568 | goto vnic_setup_err; |
| 5569 | } |
| 5570 | |
| 5571 | if (bp->flags & BNXT_FLAG_AGG_RINGS) { |
| 5572 | rc = bnxt_hwrm_vnic_set_hds(bp, vnic_id); |
| 5573 | if (rc) { |
| 5574 | netdev_err(bp->dev, "hwrm vnic %d set hds failure rc: %x\n", |
| 5575 | vnic_id, rc); |
| 5576 | } |
| 5577 | } |
| 5578 | |
| 5579 | vnic_setup_err: |
| 5580 | return rc; |
| 5581 | } |
| 5582 | |
| 5583 | static int bnxt_alloc_rfs_vnics(struct bnxt *bp) |
| 5584 | { |
| 5585 | #ifdef CONFIG_RFS_ACCEL |
| 5586 | int i, rc = 0; |
| 5587 | |
| 5588 | for (i = 0; i < bp->rx_nr_rings; i++) { |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 5589 | struct bnxt_vnic_info *vnic; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5590 | u16 vnic_id = i + 1; |
| 5591 | u16 ring_id = i; |
| 5592 | |
| 5593 | if (vnic_id >= bp->nr_vnics) |
| 5594 | break; |
| 5595 | |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 5596 | vnic = &bp->vnic_info[vnic_id]; |
| 5597 | vnic->flags |= BNXT_VNIC_RFS_FLAG; |
| 5598 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 5599 | vnic->flags |= BNXT_VNIC_RFS_NEW_RSS_FLAG; |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 5600 | rc = bnxt_hwrm_vnic_alloc(bp, vnic_id, ring_id, 1); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5601 | if (rc) { |
| 5602 | netdev_err(bp->dev, "hwrm vnic %d alloc failure rc: %x\n", |
| 5603 | vnic_id, rc); |
| 5604 | break; |
| 5605 | } |
| 5606 | rc = bnxt_setup_vnic(bp, vnic_id); |
| 5607 | if (rc) |
| 5608 | break; |
| 5609 | } |
| 5610 | return rc; |
| 5611 | #else |
| 5612 | return 0; |
| 5613 | #endif |
| 5614 | } |
| 5615 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 5616 | /* Allow PF and VF with default VLAN to be in promiscuous mode */ |
| 5617 | static bool bnxt_promisc_ok(struct bnxt *bp) |
| 5618 | { |
| 5619 | #ifdef CONFIG_BNXT_SRIOV |
| 5620 | if (BNXT_VF(bp) && !bp->vf.vlan) |
| 5621 | return false; |
| 5622 | #endif |
| 5623 | return true; |
| 5624 | } |
| 5625 | |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 5626 | static int bnxt_setup_nitroa0_vnic(struct bnxt *bp) |
| 5627 | { |
| 5628 | unsigned int rc = 0; |
| 5629 | |
| 5630 | rc = bnxt_hwrm_vnic_alloc(bp, 1, bp->rx_nr_rings - 1, 1); |
| 5631 | if (rc) { |
| 5632 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 5633 | rc); |
| 5634 | return rc; |
| 5635 | } |
| 5636 | |
| 5637 | rc = bnxt_hwrm_vnic_cfg(bp, 1); |
| 5638 | if (rc) { |
| 5639 | netdev_err(bp->dev, "Cannot allocate special vnic for NS2 A0: %x\n", |
| 5640 | rc); |
| 5641 | return rc; |
| 5642 | } |
| 5643 | return rc; |
| 5644 | } |
| 5645 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 5646 | static int bnxt_cfg_rx_mode(struct bnxt *); |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 5647 | static bool bnxt_mc_list_updated(struct bnxt *, u32 *); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 5648 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5649 | static int bnxt_init_chip(struct bnxt *bp, bool irq_re_init) |
| 5650 | { |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 5651 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5652 | int rc = 0; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 5653 | unsigned int rx_nr_rings = bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5654 | |
| 5655 | if (irq_re_init) { |
| 5656 | rc = bnxt_hwrm_stat_ctx_alloc(bp); |
| 5657 | if (rc) { |
| 5658 | netdev_err(bp->dev, "hwrm stat ctx alloc failure rc: %x\n", |
| 5659 | rc); |
| 5660 | goto err_out; |
| 5661 | } |
| 5662 | } |
| 5663 | |
| 5664 | rc = bnxt_hwrm_ring_alloc(bp); |
| 5665 | if (rc) { |
| 5666 | netdev_err(bp->dev, "hwrm ring alloc failure rc: %x\n", rc); |
| 5667 | goto err_out; |
| 5668 | } |
| 5669 | |
| 5670 | rc = bnxt_hwrm_ring_grp_alloc(bp); |
| 5671 | if (rc) { |
| 5672 | netdev_err(bp->dev, "hwrm_ring_grp alloc failure: %x\n", rc); |
| 5673 | goto err_out; |
| 5674 | } |
| 5675 | |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 5676 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 5677 | rx_nr_rings--; |
| 5678 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5679 | /* default vnic 0 */ |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 5680 | rc = bnxt_hwrm_vnic_alloc(bp, 0, 0, rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5681 | if (rc) { |
| 5682 | netdev_err(bp->dev, "hwrm vnic alloc failure rc: %x\n", rc); |
| 5683 | goto err_out; |
| 5684 | } |
| 5685 | |
| 5686 | rc = bnxt_setup_vnic(bp, 0); |
| 5687 | if (rc) |
| 5688 | goto err_out; |
| 5689 | |
| 5690 | if (bp->flags & BNXT_FLAG_RFS) { |
| 5691 | rc = bnxt_alloc_rfs_vnics(bp); |
| 5692 | if (rc) |
| 5693 | goto err_out; |
| 5694 | } |
| 5695 | |
| 5696 | if (bp->flags & BNXT_FLAG_TPA) { |
| 5697 | rc = bnxt_set_tpa(bp, true); |
| 5698 | if (rc) |
| 5699 | goto err_out; |
| 5700 | } |
| 5701 | |
| 5702 | if (BNXT_VF(bp)) |
| 5703 | bnxt_update_vf_mac(bp); |
| 5704 | |
| 5705 | /* Filter for default vnic 0 */ |
| 5706 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, 0, bp->dev->dev_addr); |
| 5707 | if (rc) { |
| 5708 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", rc); |
| 5709 | goto err_out; |
| 5710 | } |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 5711 | vnic->uc_filter_count = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5712 | |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 5713 | vnic->rx_mask = CFA_L2_SET_RX_MASK_REQ_MASK_BCAST; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5714 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 5715 | if ((bp->dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | 7d2837d | 2016-05-04 16:56:44 -0400 | [diff] [blame] | 5716 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 5717 | |
| 5718 | if (bp->dev->flags & IFF_ALLMULTI) { |
| 5719 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 5720 | vnic->mc_list_count = 0; |
| 5721 | } else { |
| 5722 | u32 mask = 0; |
| 5723 | |
| 5724 | bnxt_mc_list_updated(bp, &mask); |
| 5725 | vnic->rx_mask |= mask; |
| 5726 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5727 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 5728 | rc = bnxt_cfg_rx_mode(bp); |
| 5729 | if (rc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5730 | goto err_out; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5731 | |
| 5732 | rc = bnxt_hwrm_set_coal(bp); |
| 5733 | if (rc) |
| 5734 | netdev_warn(bp->dev, "HWRM set coalescing failure rc: %x\n", |
Prashant Sreedharan | dc52c6c | 2016-07-18 07:15:24 -0400 | [diff] [blame] | 5735 | rc); |
| 5736 | |
| 5737 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 5738 | rc = bnxt_setup_nitroa0_vnic(bp); |
| 5739 | if (rc) |
| 5740 | netdev_err(bp->dev, "Special vnic setup failure for NS2 A0 rc: %x\n", |
| 5741 | rc); |
| 5742 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5743 | |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 5744 | if (BNXT_VF(bp)) { |
| 5745 | bnxt_hwrm_func_qcfg(bp); |
| 5746 | netdev_update_features(bp->dev); |
| 5747 | } |
| 5748 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5749 | return 0; |
| 5750 | |
| 5751 | err_out: |
| 5752 | bnxt_hwrm_resource_free(bp, 0, true); |
| 5753 | |
| 5754 | return rc; |
| 5755 | } |
| 5756 | |
| 5757 | static int bnxt_shutdown_nic(struct bnxt *bp, bool irq_re_init) |
| 5758 | { |
| 5759 | bnxt_hwrm_resource_free(bp, 1, irq_re_init); |
| 5760 | return 0; |
| 5761 | } |
| 5762 | |
| 5763 | static int bnxt_init_nic(struct bnxt *bp, bool irq_re_init) |
| 5764 | { |
Sankar Patchineelam | 2247925 | 2017-03-28 19:47:29 -0400 | [diff] [blame] | 5765 | bnxt_init_cp_rings(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5766 | bnxt_init_rx_rings(bp); |
| 5767 | bnxt_init_tx_rings(bp); |
| 5768 | bnxt_init_ring_grps(bp, irq_re_init); |
| 5769 | bnxt_init_vnics(bp); |
| 5770 | |
| 5771 | return bnxt_init_chip(bp, irq_re_init); |
| 5772 | } |
| 5773 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5774 | static int bnxt_set_real_num_queues(struct bnxt *bp) |
| 5775 | { |
| 5776 | int rc; |
| 5777 | struct net_device *dev = bp->dev; |
| 5778 | |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 5779 | rc = netif_set_real_num_tx_queues(dev, bp->tx_nr_rings - |
| 5780 | bp->tx_nr_rings_xdp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5781 | if (rc) |
| 5782 | return rc; |
| 5783 | |
| 5784 | rc = netif_set_real_num_rx_queues(dev, bp->rx_nr_rings); |
| 5785 | if (rc) |
| 5786 | return rc; |
| 5787 | |
| 5788 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 45019a1 | 2015-12-27 18:19:22 -0500 | [diff] [blame] | 5789 | if (bp->flags & BNXT_FLAG_RFS) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5790 | dev->rx_cpu_rmap = alloc_irq_cpu_rmap(bp->rx_nr_rings); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5791 | #endif |
| 5792 | |
| 5793 | return rc; |
| 5794 | } |
| 5795 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5796 | static int bnxt_trim_rings(struct bnxt *bp, int *rx, int *tx, int max, |
| 5797 | bool shared) |
| 5798 | { |
| 5799 | int _rx = *rx, _tx = *tx; |
| 5800 | |
| 5801 | if (shared) { |
| 5802 | *rx = min_t(int, _rx, max); |
| 5803 | *tx = min_t(int, _tx, max); |
| 5804 | } else { |
| 5805 | if (max < 2) |
| 5806 | return -ENOMEM; |
| 5807 | |
| 5808 | while (_rx + _tx > max) { |
| 5809 | if (_rx > _tx && _rx > 1) |
| 5810 | _rx--; |
| 5811 | else if (_tx > 1) |
| 5812 | _tx--; |
| 5813 | } |
| 5814 | *rx = _rx; |
| 5815 | *tx = _tx; |
| 5816 | } |
| 5817 | return 0; |
| 5818 | } |
| 5819 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5820 | static void bnxt_setup_msix(struct bnxt *bp) |
| 5821 | { |
| 5822 | const int len = sizeof(bp->irq_tbl[0].name); |
| 5823 | struct net_device *dev = bp->dev; |
| 5824 | int tcs, i; |
| 5825 | |
| 5826 | tcs = netdev_get_num_tc(dev); |
| 5827 | if (tcs > 1) { |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 5828 | int i, off, count; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5829 | |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 5830 | for (i = 0; i < tcs; i++) { |
| 5831 | count = bp->tx_nr_rings_per_tc; |
| 5832 | off = i * count; |
| 5833 | netdev_set_tc_queue(dev, i, count, off); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5834 | } |
| 5835 | } |
| 5836 | |
| 5837 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 5838 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5839 | char *attr; |
| 5840 | |
| 5841 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 5842 | attr = "TxRx"; |
| 5843 | else if (i < bp->rx_nr_rings) |
| 5844 | attr = "rx"; |
| 5845 | else |
| 5846 | attr = "tx"; |
| 5847 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 5848 | snprintf(bp->irq_tbl[map_idx].name, len, "%s-%s-%d", dev->name, |
| 5849 | attr, i); |
| 5850 | bp->irq_tbl[map_idx].handler = bnxt_msix; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5851 | } |
| 5852 | } |
| 5853 | |
| 5854 | static void bnxt_setup_inta(struct bnxt *bp) |
| 5855 | { |
| 5856 | const int len = sizeof(bp->irq_tbl[0].name); |
| 5857 | |
| 5858 | if (netdev_get_num_tc(bp->dev)) |
| 5859 | netdev_reset_tc(bp->dev); |
| 5860 | |
| 5861 | snprintf(bp->irq_tbl[0].name, len, "%s-%s-%d", bp->dev->name, "TxRx", |
| 5862 | 0); |
| 5863 | bp->irq_tbl[0].handler = bnxt_inta; |
| 5864 | } |
| 5865 | |
| 5866 | static int bnxt_setup_int_mode(struct bnxt *bp) |
| 5867 | { |
| 5868 | int rc; |
| 5869 | |
| 5870 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 5871 | bnxt_setup_msix(bp); |
| 5872 | else |
| 5873 | bnxt_setup_inta(bp); |
| 5874 | |
| 5875 | rc = bnxt_set_real_num_queues(bp); |
| 5876 | return rc; |
| 5877 | } |
| 5878 | |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 5879 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 5880 | static unsigned int bnxt_get_max_func_rss_ctxs(struct bnxt *bp) |
| 5881 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5882 | return bp->hw_resc.max_rsscos_ctxs; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 5883 | } |
| 5884 | |
| 5885 | static unsigned int bnxt_get_max_func_vnics(struct bnxt *bp) |
| 5886 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5887 | return bp->hw_resc.max_vnics; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 5888 | } |
Michael Chan | b742995 | 2017-01-13 01:32:00 -0500 | [diff] [blame] | 5889 | #endif |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 5890 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5891 | unsigned int bnxt_get_max_func_stat_ctxs(struct bnxt *bp) |
| 5892 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5893 | return bp->hw_resc.max_stat_ctxs; |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5894 | } |
| 5895 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5896 | void bnxt_set_max_func_stat_ctxs(struct bnxt *bp, unsigned int max) |
| 5897 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5898 | bp->hw_resc.max_stat_ctxs = max; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5899 | } |
| 5900 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5901 | unsigned int bnxt_get_max_func_cp_rings(struct bnxt *bp) |
| 5902 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5903 | return bp->hw_resc.max_cp_rings; |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 5904 | } |
| 5905 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5906 | void bnxt_set_max_func_cp_rings(struct bnxt *bp, unsigned int max) |
| 5907 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5908 | bp->hw_resc.max_cp_rings = max; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 5909 | } |
| 5910 | |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 5911 | unsigned int bnxt_get_max_func_irqs(struct bnxt *bp) |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5912 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5913 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
| 5914 | |
| 5915 | 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] | 5916 | } |
| 5917 | |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 5918 | void bnxt_set_max_func_irqs(struct bnxt *bp, unsigned int max_irqs) |
| 5919 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 5920 | bp->hw_resc.max_irqs = max_irqs; |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 5921 | } |
| 5922 | |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 5923 | int bnxt_get_avail_msix(struct bnxt *bp, int num) |
| 5924 | { |
| 5925 | int max_cp = bnxt_get_max_func_cp_rings(bp); |
| 5926 | int max_irq = bnxt_get_max_func_irqs(bp); |
| 5927 | int total_req = bp->cp_nr_rings + num; |
| 5928 | int max_idx, avail_msix; |
| 5929 | |
| 5930 | max_idx = min_t(int, bp->total_irqs, max_cp); |
| 5931 | avail_msix = max_idx - bp->cp_nr_rings; |
| 5932 | if (!(bp->flags & BNXT_FLAG_NEW_RM) || avail_msix >= num) |
| 5933 | return avail_msix; |
| 5934 | |
| 5935 | if (max_irq < total_req) { |
| 5936 | num = max_irq - bp->cp_nr_rings; |
| 5937 | if (num <= 0) |
| 5938 | return 0; |
| 5939 | } |
| 5940 | return num; |
| 5941 | } |
| 5942 | |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 5943 | static int bnxt_get_num_msix(struct bnxt *bp) |
| 5944 | { |
| 5945 | if (!(bp->flags & BNXT_FLAG_NEW_RM)) |
| 5946 | return bnxt_get_max_func_irqs(bp); |
| 5947 | |
| 5948 | return bnxt_cp_rings_in_use(bp); |
| 5949 | } |
| 5950 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5951 | static int bnxt_init_msix(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5952 | { |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 5953 | int i, total_vecs, max, rc = 0, min = 1, ulp_msix; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5954 | struct msix_entry *msix_ent; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5955 | |
Michael Chan | 08654eb | 2018-03-31 13:54:17 -0400 | [diff] [blame] | 5956 | total_vecs = bnxt_get_num_msix(bp); |
| 5957 | max = bnxt_get_max_func_irqs(bp); |
| 5958 | if (total_vecs > max) |
| 5959 | total_vecs = max; |
| 5960 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5961 | msix_ent = kcalloc(total_vecs, sizeof(struct msix_entry), GFP_KERNEL); |
| 5962 | if (!msix_ent) |
| 5963 | return -ENOMEM; |
| 5964 | |
| 5965 | for (i = 0; i < total_vecs; i++) { |
| 5966 | msix_ent[i].entry = i; |
| 5967 | msix_ent[i].vector = 0; |
| 5968 | } |
| 5969 | |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 5970 | if (!(bp->flags & BNXT_FLAG_SHARED_RINGS)) |
| 5971 | min = 2; |
| 5972 | |
| 5973 | 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^] | 5974 | ulp_msix = bnxt_get_ulp_msix_num(bp); |
| 5975 | if (total_vecs < 0 || total_vecs < ulp_msix) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5976 | rc = -ENODEV; |
| 5977 | goto msix_setup_exit; |
| 5978 | } |
| 5979 | |
| 5980 | bp->irq_tbl = kcalloc(total_vecs, sizeof(struct bnxt_irq), GFP_KERNEL); |
| 5981 | if (bp->irq_tbl) { |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5982 | for (i = 0; i < total_vecs; i++) |
| 5983 | bp->irq_tbl[i].vector = msix_ent[i].vector; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5984 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5985 | bp->total_irqs = total_vecs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5986 | /* Trim rings based upon num of vectors allocated */ |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5987 | 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^] | 5988 | total_vecs - ulp_msix, min == 1); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 5989 | if (rc) |
| 5990 | goto msix_setup_exit; |
| 5991 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 5992 | bp->cp_nr_rings = (min == 1) ? |
| 5993 | max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 5994 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5995 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 5996 | } else { |
| 5997 | rc = -ENOMEM; |
| 5998 | goto msix_setup_exit; |
| 5999 | } |
| 6000 | bp->flags |= BNXT_FLAG_USING_MSIX; |
| 6001 | kfree(msix_ent); |
| 6002 | return 0; |
| 6003 | |
| 6004 | msix_setup_exit: |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6005 | netdev_err(bp->dev, "bnxt_init_msix err: %x\n", rc); |
| 6006 | kfree(bp->irq_tbl); |
| 6007 | bp->irq_tbl = NULL; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6008 | pci_disable_msix(bp->pdev); |
| 6009 | kfree(msix_ent); |
| 6010 | return rc; |
| 6011 | } |
| 6012 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6013 | static int bnxt_init_inta(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6014 | { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6015 | bp->irq_tbl = kcalloc(1, sizeof(struct bnxt_irq), GFP_KERNEL); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6016 | if (!bp->irq_tbl) |
| 6017 | return -ENOMEM; |
| 6018 | |
| 6019 | bp->total_irqs = 1; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6020 | bp->rx_nr_rings = 1; |
| 6021 | bp->tx_nr_rings = 1; |
| 6022 | bp->cp_nr_rings = 1; |
Michael Chan | 01657bc | 2016-01-02 23:45:03 -0500 | [diff] [blame] | 6023 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6024 | bp->irq_tbl[0].vector = bp->pdev->irq; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6025 | return 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6026 | } |
| 6027 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6028 | static int bnxt_init_int_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6029 | { |
| 6030 | int rc = 0; |
| 6031 | |
| 6032 | if (bp->flags & BNXT_FLAG_MSIX_CAP) |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6033 | rc = bnxt_init_msix(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6034 | |
Michael Chan | 1fa72e2 | 2016-04-25 02:30:49 -0400 | [diff] [blame] | 6035 | if (!(bp->flags & BNXT_FLAG_USING_MSIX) && BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6036 | /* fallback to INTA */ |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6037 | rc = bnxt_init_inta(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6038 | } |
| 6039 | return rc; |
| 6040 | } |
| 6041 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 6042 | static void bnxt_clear_int_mode(struct bnxt *bp) |
| 6043 | { |
| 6044 | if (bp->flags & BNXT_FLAG_USING_MSIX) |
| 6045 | pci_disable_msix(bp->pdev); |
| 6046 | |
| 6047 | kfree(bp->irq_tbl); |
| 6048 | bp->irq_tbl = NULL; |
| 6049 | bp->flags &= ~BNXT_FLAG_USING_MSIX; |
| 6050 | } |
| 6051 | |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 6052 | int bnxt_reserve_rings(struct bnxt *bp) |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6053 | { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6054 | int tcs = netdev_get_num_tc(bp->dev); |
| 6055 | int rc; |
| 6056 | |
| 6057 | if (!bnxt_need_reserve_rings(bp)) |
| 6058 | return 0; |
| 6059 | |
| 6060 | rc = __bnxt_reserve_rings(bp); |
| 6061 | if (rc) { |
| 6062 | netdev_err(bp->dev, "ring reservation failure rc: %d\n", rc); |
| 6063 | return rc; |
| 6064 | } |
Michael Chan | fbcfc8e | 2018-03-31 13:54:20 -0400 | [diff] [blame^] | 6065 | if ((bp->flags & BNXT_FLAG_NEW_RM) && |
| 6066 | (bnxt_get_num_msix(bp) != bp->total_irqs)) { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6067 | bnxt_clear_int_mode(bp); |
| 6068 | rc = bnxt_init_int_mode(bp); |
| 6069 | if (rc) |
| 6070 | return rc; |
| 6071 | } |
| 6072 | if (tcs && (bp->tx_nr_rings_per_tc * tcs != bp->tx_nr_rings)) { |
| 6073 | netdev_err(bp->dev, "tx ring reservation failure\n"); |
| 6074 | netdev_reset_tc(bp->dev); |
| 6075 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 6076 | return -ENOMEM; |
| 6077 | } |
| 6078 | bp->num_stat_ctxs = bp->cp_nr_rings; |
| 6079 | return 0; |
| 6080 | } |
| 6081 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6082 | static void bnxt_free_irq(struct bnxt *bp) |
| 6083 | { |
| 6084 | struct bnxt_irq *irq; |
| 6085 | int i; |
| 6086 | |
| 6087 | #ifdef CONFIG_RFS_ACCEL |
| 6088 | free_irq_cpu_rmap(bp->dev->rx_cpu_rmap); |
| 6089 | bp->dev->rx_cpu_rmap = NULL; |
| 6090 | #endif |
| 6091 | if (!bp->irq_tbl) |
| 6092 | return; |
| 6093 | |
| 6094 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6095 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
| 6096 | |
| 6097 | irq = &bp->irq_tbl[map_idx]; |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 6098 | if (irq->requested) { |
| 6099 | if (irq->have_cpumask) { |
| 6100 | irq_set_affinity_hint(irq->vector, NULL); |
| 6101 | free_cpumask_var(irq->cpu_mask); |
| 6102 | irq->have_cpumask = 0; |
| 6103 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6104 | free_irq(irq->vector, bp->bnapi[i]); |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 6105 | } |
| 6106 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6107 | irq->requested = 0; |
| 6108 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | static int bnxt_request_irq(struct bnxt *bp) |
| 6112 | { |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6113 | int i, j, rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6114 | unsigned long flags = 0; |
| 6115 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6116 | struct cpu_rmap *rmap; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6117 | #endif |
| 6118 | |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6119 | rc = bnxt_setup_int_mode(bp); |
| 6120 | if (rc) { |
| 6121 | netdev_err(bp->dev, "bnxt_setup_int_mode err: %x\n", |
| 6122 | rc); |
| 6123 | return rc; |
| 6124 | } |
| 6125 | #ifdef CONFIG_RFS_ACCEL |
| 6126 | rmap = bp->dev->rx_cpu_rmap; |
| 6127 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6128 | if (!(bp->flags & BNXT_FLAG_USING_MSIX)) |
| 6129 | flags = IRQF_SHARED; |
| 6130 | |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6131 | for (i = 0, j = 0; i < bp->cp_nr_rings; i++) { |
Michael Chan | e5811b8 | 2018-03-31 13:54:18 -0400 | [diff] [blame] | 6132 | int map_idx = bnxt_cp_num_to_irq_num(bp, i); |
| 6133 | struct bnxt_irq *irq = &bp->irq_tbl[map_idx]; |
| 6134 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6135 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6136 | if (rmap && bp->bnapi[i]->rx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6137 | rc = irq_cpu_rmap_add(rmap, irq->vector); |
| 6138 | if (rc) |
| 6139 | netdev_warn(bp->dev, "failed adding irq rmap for ring %d\n", |
Michael Chan | b81a90d | 2016-01-02 23:45:01 -0500 | [diff] [blame] | 6140 | j); |
| 6141 | j++; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6142 | } |
| 6143 | #endif |
| 6144 | rc = request_irq(irq->vector, irq->handler, flags, irq->name, |
| 6145 | bp->bnapi[i]); |
| 6146 | if (rc) |
| 6147 | break; |
| 6148 | |
| 6149 | irq->requested = 1; |
Vasundhara Volam | 56f0fd8 | 2017-08-28 13:40:27 -0400 | [diff] [blame] | 6150 | |
| 6151 | if (zalloc_cpumask_var(&irq->cpu_mask, GFP_KERNEL)) { |
| 6152 | int numa_node = dev_to_node(&bp->pdev->dev); |
| 6153 | |
| 6154 | irq->have_cpumask = 1; |
| 6155 | cpumask_set_cpu(cpumask_local_spread(i, numa_node), |
| 6156 | irq->cpu_mask); |
| 6157 | rc = irq_set_affinity_hint(irq->vector, irq->cpu_mask); |
| 6158 | if (rc) { |
| 6159 | netdev_warn(bp->dev, |
| 6160 | "Set affinity failed, IRQ = %d\n", |
| 6161 | irq->vector); |
| 6162 | break; |
| 6163 | } |
| 6164 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6165 | } |
| 6166 | return rc; |
| 6167 | } |
| 6168 | |
| 6169 | static void bnxt_del_napi(struct bnxt *bp) |
| 6170 | { |
| 6171 | int i; |
| 6172 | |
| 6173 | if (!bp->bnapi) |
| 6174 | return; |
| 6175 | |
| 6176 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6177 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 6178 | |
| 6179 | napi_hash_del(&bnapi->napi); |
| 6180 | netif_napi_del(&bnapi->napi); |
| 6181 | } |
Eric Dumazet | e5f6f56 | 2016-11-16 06:31:52 -0800 | [diff] [blame] | 6182 | /* We called napi_hash_del() before netif_napi_del(), we need |
| 6183 | * to respect an RCU grace period before freeing napi structures. |
| 6184 | */ |
| 6185 | synchronize_net(); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6186 | } |
| 6187 | |
| 6188 | static void bnxt_init_napi(struct bnxt *bp) |
| 6189 | { |
| 6190 | int i; |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 6191 | unsigned int cp_nr_rings = bp->cp_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6192 | struct bnxt_napi *bnapi; |
| 6193 | |
| 6194 | if (bp->flags & BNXT_FLAG_USING_MSIX) { |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 6195 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 6196 | cp_nr_rings--; |
| 6197 | for (i = 0; i < cp_nr_rings; i++) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6198 | bnapi = bp->bnapi[i]; |
| 6199 | netif_napi_add(bp->dev, &bnapi->napi, |
| 6200 | bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6201 | } |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 6202 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 6203 | bnapi = bp->bnapi[cp_nr_rings]; |
| 6204 | netif_napi_add(bp->dev, &bnapi->napi, |
| 6205 | bnxt_poll_nitroa0, 64); |
Prashant Sreedharan | 10bbdaf | 2016-07-18 07:15:23 -0400 | [diff] [blame] | 6206 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6207 | } else { |
| 6208 | bnapi = bp->bnapi[0]; |
| 6209 | netif_napi_add(bp->dev, &bnapi->napi, bnxt_poll, 64); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6210 | } |
| 6211 | } |
| 6212 | |
| 6213 | static void bnxt_disable_napi(struct bnxt *bp) |
| 6214 | { |
| 6215 | int i; |
| 6216 | |
| 6217 | if (!bp->bnapi) |
| 6218 | return; |
| 6219 | |
Andy Gospodarek | 0bc0b97 | 2018-01-26 10:27:47 -0500 | [diff] [blame] | 6220 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 6221 | struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; |
| 6222 | |
| 6223 | if (bp->bnapi[i]->rx_ring) |
| 6224 | cancel_work_sync(&cpr->dim.work); |
| 6225 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6226 | napi_disable(&bp->bnapi[i]->napi); |
Andy Gospodarek | 0bc0b97 | 2018-01-26 10:27:47 -0500 | [diff] [blame] | 6227 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6228 | } |
| 6229 | |
| 6230 | static void bnxt_enable_napi(struct bnxt *bp) |
| 6231 | { |
| 6232 | int i; |
| 6233 | |
| 6234 | for (i = 0; i < bp->cp_nr_rings; i++) { |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 6235 | struct bnxt_cp_ring_info *cpr = &bp->bnapi[i]->cp_ring; |
Michael Chan | fa7e281 | 2016-05-10 19:18:00 -0400 | [diff] [blame] | 6236 | bp->bnapi[i]->in_reset = false; |
Andy Gospodarek | 6a8788f | 2018-01-09 16:06:20 -0500 | [diff] [blame] | 6237 | |
| 6238 | if (bp->bnapi[i]->rx_ring) { |
| 6239 | INIT_WORK(&cpr->dim.work, bnxt_dim_work); |
| 6240 | cpr->dim.mode = NET_DIM_CQ_PERIOD_MODE_START_FROM_EQE; |
| 6241 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6242 | napi_enable(&bp->bnapi[i]->napi); |
| 6243 | } |
| 6244 | } |
| 6245 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 6246 | void bnxt_tx_disable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6247 | { |
| 6248 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6249 | struct bnxt_tx_ring_info *txr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6250 | |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6251 | if (bp->tx_ring) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6252 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6253 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6254 | txr->dev_state = BNXT_DEV_STATE_CLOSING; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6255 | } |
| 6256 | } |
| 6257 | /* Stop all TX queues */ |
| 6258 | netif_tx_disable(bp->dev); |
| 6259 | netif_carrier_off(bp->dev); |
| 6260 | } |
| 6261 | |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 6262 | void bnxt_tx_enable(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6263 | { |
| 6264 | int i; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6265 | struct bnxt_tx_ring_info *txr; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6266 | |
| 6267 | for (i = 0; i < bp->tx_nr_rings; i++) { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 6268 | txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6269 | txr->dev_state = 0; |
| 6270 | } |
| 6271 | netif_tx_wake_all_queues(bp->dev); |
| 6272 | if (bp->link_info.link_up) |
| 6273 | netif_carrier_on(bp->dev); |
| 6274 | } |
| 6275 | |
| 6276 | static void bnxt_report_link(struct bnxt *bp) |
| 6277 | { |
| 6278 | if (bp->link_info.link_up) { |
| 6279 | const char *duplex; |
| 6280 | const char *flow_ctrl; |
Deepak Khungar | 38a21b3 | 2017-04-21 20:11:24 -0400 | [diff] [blame] | 6281 | u32 speed; |
| 6282 | u16 fec; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6283 | |
| 6284 | netif_carrier_on(bp->dev); |
| 6285 | if (bp->link_info.duplex == BNXT_LINK_DUPLEX_FULL) |
| 6286 | duplex = "full"; |
| 6287 | else |
| 6288 | duplex = "half"; |
| 6289 | if (bp->link_info.pause == BNXT_LINK_PAUSE_BOTH) |
| 6290 | flow_ctrl = "ON - receive & transmit"; |
| 6291 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_TX) |
| 6292 | flow_ctrl = "ON - transmit"; |
| 6293 | else if (bp->link_info.pause == BNXT_LINK_PAUSE_RX) |
| 6294 | flow_ctrl = "ON - receive"; |
| 6295 | else |
| 6296 | flow_ctrl = "none"; |
| 6297 | speed = bnxt_fw_to_ethtool_speed(bp->link_info.link_speed); |
Deepak Khungar | 38a21b3 | 2017-04-21 20:11:24 -0400 | [diff] [blame] | 6298 | 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] | 6299 | speed, duplex, flow_ctrl); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6300 | if (bp->flags & BNXT_FLAG_EEE_CAP) |
| 6301 | netdev_info(bp->dev, "EEE is %s\n", |
| 6302 | bp->eee.eee_active ? "active" : |
| 6303 | "not active"); |
Michael Chan | e70c752 | 2017-02-12 19:18:16 -0500 | [diff] [blame] | 6304 | fec = bp->link_info.fec_cfg; |
| 6305 | if (!(fec & PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED)) |
| 6306 | netdev_info(bp->dev, "FEC autoneg %s encodings: %s\n", |
| 6307 | (fec & BNXT_FEC_AUTONEG) ? "on" : "off", |
| 6308 | (fec & BNXT_FEC_ENC_BASE_R) ? "BaseR" : |
| 6309 | (fec & BNXT_FEC_ENC_RS) ? "RS" : "None"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6310 | } else { |
| 6311 | netif_carrier_off(bp->dev); |
| 6312 | netdev_err(bp->dev, "NIC Link is Down\n"); |
| 6313 | } |
| 6314 | } |
| 6315 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6316 | static int bnxt_hwrm_phy_qcaps(struct bnxt *bp) |
| 6317 | { |
| 6318 | int rc = 0; |
| 6319 | struct hwrm_port_phy_qcaps_input req = {0}; |
| 6320 | struct hwrm_port_phy_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 6321 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6322 | |
| 6323 | if (bp->hwrm_spec_code < 0x10201) |
| 6324 | return 0; |
| 6325 | |
| 6326 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCAPS, -1, -1); |
| 6327 | |
| 6328 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6329 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6330 | if (rc) |
| 6331 | goto hwrm_phy_qcaps_exit; |
| 6332 | |
Michael Chan | acb2005 | 2017-07-24 12:34:20 -0400 | [diff] [blame] | 6333 | if (resp->flags & PORT_PHY_QCAPS_RESP_FLAGS_EEE_SUPPORTED) { |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6334 | struct ethtool_eee *eee = &bp->eee; |
| 6335 | u16 fw_speeds = le16_to_cpu(resp->supported_speeds_eee_mode); |
| 6336 | |
| 6337 | bp->flags |= BNXT_FLAG_EEE_CAP; |
| 6338 | eee->supported = _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 6339 | bp->lpi_tmr_lo = le32_to_cpu(resp->tx_lpi_timer_low) & |
| 6340 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_LOW_MASK; |
| 6341 | bp->lpi_tmr_hi = le32_to_cpu(resp->valid_tx_lpi_timer_high) & |
| 6342 | PORT_PHY_QCAPS_RESP_TX_LPI_TIMER_HIGH_MASK; |
| 6343 | } |
Michael Chan | 520ad89 | 2017-03-08 18:44:35 -0500 | [diff] [blame] | 6344 | if (resp->supported_speeds_auto_mode) |
| 6345 | link_info->support_auto_speeds = |
| 6346 | le16_to_cpu(resp->supported_speeds_auto_mode); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6347 | |
Michael Chan | d5430d3 | 2017-08-28 13:40:31 -0400 | [diff] [blame] | 6348 | bp->port_count = resp->port_cnt; |
| 6349 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6350 | hwrm_phy_qcaps_exit: |
| 6351 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6352 | return rc; |
| 6353 | } |
| 6354 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6355 | static int bnxt_update_link(struct bnxt *bp, bool chng_link_state) |
| 6356 | { |
| 6357 | int rc = 0; |
| 6358 | struct bnxt_link_info *link_info = &bp->link_info; |
| 6359 | struct hwrm_port_phy_qcfg_input req = {0}; |
| 6360 | struct hwrm_port_phy_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 6361 | u8 link_up = link_info->link_up; |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 6362 | u16 diff; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6363 | |
| 6364 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_QCFG, -1, -1); |
| 6365 | |
| 6366 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6367 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6368 | if (rc) { |
| 6369 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6370 | return rc; |
| 6371 | } |
| 6372 | |
| 6373 | memcpy(&link_info->phy_qcfg_resp, resp, sizeof(*resp)); |
| 6374 | link_info->phy_link_status = resp->link; |
Michael Chan | acb2005 | 2017-07-24 12:34:20 -0400 | [diff] [blame] | 6375 | link_info->duplex = resp->duplex_cfg; |
| 6376 | if (bp->hwrm_spec_code >= 0x10800) |
| 6377 | link_info->duplex = resp->duplex_state; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6378 | link_info->pause = resp->pause; |
| 6379 | link_info->auto_mode = resp->auto_mode; |
| 6380 | link_info->auto_pause_setting = resp->auto_pause; |
Michael Chan | 3277360 | 2016-03-07 15:38:42 -0500 | [diff] [blame] | 6381 | link_info->lp_pause = resp->link_partner_adv_pause; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6382 | link_info->force_pause_setting = resp->force_pause; |
Michael Chan | acb2005 | 2017-07-24 12:34:20 -0400 | [diff] [blame] | 6383 | link_info->duplex_setting = resp->duplex_cfg; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6384 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 6385 | link_info->link_speed = le16_to_cpu(resp->link_speed); |
| 6386 | else |
| 6387 | link_info->link_speed = 0; |
| 6388 | link_info->force_link_speed = le16_to_cpu(resp->force_link_speed); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6389 | link_info->support_speeds = le16_to_cpu(resp->support_speeds); |
| 6390 | 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] | 6391 | link_info->lp_auto_link_speeds = |
| 6392 | le16_to_cpu(resp->link_partner_adv_speeds); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6393 | link_info->preemphasis = le32_to_cpu(resp->preemphasis); |
| 6394 | link_info->phy_ver[0] = resp->phy_maj; |
| 6395 | link_info->phy_ver[1] = resp->phy_min; |
| 6396 | link_info->phy_ver[2] = resp->phy_bld; |
| 6397 | link_info->media_type = resp->media_type; |
Michael Chan | 03efbec | 2016-04-11 04:11:11 -0400 | [diff] [blame] | 6398 | link_info->phy_type = resp->phy_type; |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 6399 | link_info->transceiver = resp->xcvr_pkg_type; |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6400 | link_info->phy_addr = resp->eee_config_phy_addr & |
| 6401 | PORT_PHY_QCFG_RESP_PHY_ADDR_MASK; |
Ajit Khaparde | 42ee18f | 2016-05-15 03:04:44 -0400 | [diff] [blame] | 6402 | link_info->module_status = resp->module_status; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6403 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 6404 | if (bp->flags & BNXT_FLAG_EEE_CAP) { |
| 6405 | struct ethtool_eee *eee = &bp->eee; |
| 6406 | u16 fw_speeds; |
| 6407 | |
| 6408 | eee->eee_active = 0; |
| 6409 | if (resp->eee_config_phy_addr & |
| 6410 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ACTIVE) { |
| 6411 | eee->eee_active = 1; |
| 6412 | fw_speeds = le16_to_cpu( |
| 6413 | resp->link_partner_adv_eee_link_speed_mask); |
| 6414 | eee->lp_advertised = |
| 6415 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 6416 | } |
| 6417 | |
| 6418 | /* Pull initial EEE config */ |
| 6419 | if (!chng_link_state) { |
| 6420 | if (resp->eee_config_phy_addr & |
| 6421 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_ENABLED) |
| 6422 | eee->eee_enabled = 1; |
| 6423 | |
| 6424 | fw_speeds = le16_to_cpu(resp->adv_eee_link_speed_mask); |
| 6425 | eee->advertised = |
| 6426 | _bnxt_fw_to_ethtool_adv_spds(fw_speeds, 0); |
| 6427 | |
| 6428 | if (resp->eee_config_phy_addr & |
| 6429 | PORT_PHY_QCFG_RESP_EEE_CONFIG_EEE_TX_LPI) { |
| 6430 | __le32 tmr; |
| 6431 | |
| 6432 | eee->tx_lpi_enabled = 1; |
| 6433 | tmr = resp->xcvr_identifier_type_tx_lpi_timer; |
| 6434 | eee->tx_lpi_timer = le32_to_cpu(tmr) & |
| 6435 | PORT_PHY_QCFG_RESP_TX_LPI_TIMER_MASK; |
| 6436 | } |
| 6437 | } |
| 6438 | } |
Michael Chan | e70c752 | 2017-02-12 19:18:16 -0500 | [diff] [blame] | 6439 | |
| 6440 | link_info->fec_cfg = PORT_PHY_QCFG_RESP_FEC_CFG_FEC_NONE_SUPPORTED; |
| 6441 | if (bp->hwrm_spec_code >= 0x10504) |
| 6442 | link_info->fec_cfg = le16_to_cpu(resp->fec_cfg); |
| 6443 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6444 | /* TODO: need to add more logic to report VF link */ |
| 6445 | if (chng_link_state) { |
| 6446 | if (link_info->phy_link_status == BNXT_LINK_LINK) |
| 6447 | link_info->link_up = 1; |
| 6448 | else |
| 6449 | link_info->link_up = 0; |
| 6450 | if (link_up != link_info->link_up) |
| 6451 | bnxt_report_link(bp); |
| 6452 | } else { |
| 6453 | /* alwasy link down if not require to update link state */ |
| 6454 | link_info->link_up = 0; |
| 6455 | } |
| 6456 | mutex_unlock(&bp->hwrm_cmd_lock); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 6457 | |
| 6458 | diff = link_info->support_auto_speeds ^ link_info->advertising; |
| 6459 | if ((link_info->support_auto_speeds | diff) != |
| 6460 | link_info->support_auto_speeds) { |
| 6461 | /* An advertised speed is no longer supported, so we need to |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 6462 | * update the advertisement settings. Caller holds RTNL |
| 6463 | * so we can modify link settings. |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 6464 | */ |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 6465 | link_info->advertising = link_info->support_auto_speeds; |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 6466 | if (link_info->autoneg & BNXT_AUTONEG_SPEED) |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 6467 | bnxt_hwrm_set_link_setting(bp, true, false); |
Michael Chan | 286ef9d | 2016-11-16 21:13:08 -0500 | [diff] [blame] | 6468 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6469 | return 0; |
| 6470 | } |
| 6471 | |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 6472 | static void bnxt_get_port_module_status(struct bnxt *bp) |
| 6473 | { |
| 6474 | struct bnxt_link_info *link_info = &bp->link_info; |
| 6475 | struct hwrm_port_phy_qcfg_output *resp = &link_info->phy_qcfg_resp; |
| 6476 | u8 module_status; |
| 6477 | |
| 6478 | if (bnxt_update_link(bp, true)) |
| 6479 | return; |
| 6480 | |
| 6481 | module_status = link_info->module_status; |
| 6482 | switch (module_status) { |
| 6483 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX: |
| 6484 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN: |
| 6485 | case PORT_PHY_QCFG_RESP_MODULE_STATUS_WARNINGMSG: |
| 6486 | netdev_warn(bp->dev, "Unqualified SFP+ module detected on port %d\n", |
| 6487 | bp->pf.port_id); |
| 6488 | if (bp->hwrm_spec_code >= 0x10201) { |
| 6489 | netdev_warn(bp->dev, "Module part number %s\n", |
| 6490 | resp->phy_vendor_partnumber); |
| 6491 | } |
| 6492 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_DISABLETX) |
| 6493 | netdev_warn(bp->dev, "TX is disabled\n"); |
| 6494 | if (module_status == PORT_PHY_QCFG_RESP_MODULE_STATUS_PWRDOWN) |
| 6495 | netdev_warn(bp->dev, "SFP+ module is shutdown\n"); |
| 6496 | } |
| 6497 | } |
| 6498 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6499 | static void |
| 6500 | bnxt_hwrm_set_pause_common(struct bnxt *bp, struct hwrm_port_phy_cfg_input *req) |
| 6501 | { |
| 6502 | if (bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 6503 | if (bp->hwrm_spec_code >= 0x10201) |
| 6504 | req->auto_pause = |
| 6505 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6506 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 6507 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_RX; |
| 6508 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
Michael Chan | 49b5c7a | 2016-03-28 19:46:06 -0400 | [diff] [blame] | 6509 | req->auto_pause |= PORT_PHY_CFG_REQ_AUTO_PAUSE_TX; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6510 | req->enables |= |
| 6511 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 6512 | } else { |
| 6513 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_RX) |
| 6514 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_RX; |
| 6515 | if (bp->link_info.req_flow_ctrl & BNXT_LINK_PAUSE_TX) |
| 6516 | req->force_pause |= PORT_PHY_CFG_REQ_FORCE_PAUSE_TX; |
| 6517 | req->enables |= |
| 6518 | cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_FORCE_PAUSE); |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 6519 | if (bp->hwrm_spec_code >= 0x10201) { |
| 6520 | req->auto_pause = req->force_pause; |
| 6521 | req->enables |= cpu_to_le32( |
| 6522 | PORT_PHY_CFG_REQ_ENABLES_AUTO_PAUSE); |
| 6523 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6524 | } |
| 6525 | } |
| 6526 | |
| 6527 | static void bnxt_hwrm_set_link_common(struct bnxt *bp, |
| 6528 | struct hwrm_port_phy_cfg_input *req) |
| 6529 | { |
| 6530 | u8 autoneg = bp->link_info.autoneg; |
| 6531 | u16 fw_link_speed = bp->link_info.req_link_speed; |
Michael Chan | 68515a1 | 2016-12-29 12:13:34 -0500 | [diff] [blame] | 6532 | u16 advertising = bp->link_info.advertising; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6533 | |
| 6534 | if (autoneg & BNXT_AUTONEG_SPEED) { |
| 6535 | req->auto_mode |= |
Michael Chan | 11f15ed | 2016-04-05 14:08:55 -0400 | [diff] [blame] | 6536 | PORT_PHY_CFG_REQ_AUTO_MODE_SPEED_MASK; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6537 | |
| 6538 | req->enables |= cpu_to_le32( |
| 6539 | PORT_PHY_CFG_REQ_ENABLES_AUTO_LINK_SPEED_MASK); |
| 6540 | req->auto_link_speed_mask = cpu_to_le16(advertising); |
| 6541 | |
| 6542 | req->enables |= cpu_to_le32(PORT_PHY_CFG_REQ_ENABLES_AUTO_MODE); |
| 6543 | req->flags |= |
| 6544 | cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESTART_AUTONEG); |
| 6545 | } else { |
| 6546 | req->force_link_speed = cpu_to_le16(fw_link_speed); |
| 6547 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_FORCE); |
| 6548 | } |
| 6549 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6550 | /* tell chimp that the setting takes effect immediately */ |
| 6551 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_RESET_PHY); |
| 6552 | } |
| 6553 | |
| 6554 | int bnxt_hwrm_set_pause(struct bnxt *bp) |
| 6555 | { |
| 6556 | struct hwrm_port_phy_cfg_input req = {0}; |
| 6557 | int rc; |
| 6558 | |
| 6559 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 6560 | bnxt_hwrm_set_pause_common(bp, &req); |
| 6561 | |
| 6562 | if ((bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL) || |
| 6563 | bp->link_info.force_link_chng) |
| 6564 | bnxt_hwrm_set_link_common(bp, &req); |
| 6565 | |
| 6566 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6567 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6568 | if (!rc && !(bp->link_info.autoneg & BNXT_AUTONEG_FLOW_CTRL)) { |
| 6569 | /* since changing of pause setting doesn't trigger any link |
| 6570 | * change event, the driver needs to update the current pause |
| 6571 | * result upon successfully return of the phy_cfg command |
| 6572 | */ |
| 6573 | bp->link_info.pause = |
| 6574 | bp->link_info.force_pause_setting = bp->link_info.req_flow_ctrl; |
| 6575 | bp->link_info.auto_pause_setting = 0; |
| 6576 | if (!bp->link_info.force_link_chng) |
| 6577 | bnxt_report_link(bp); |
| 6578 | } |
| 6579 | bp->link_info.force_link_chng = false; |
| 6580 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6581 | return rc; |
| 6582 | } |
| 6583 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 6584 | static void bnxt_hwrm_set_eee(struct bnxt *bp, |
| 6585 | struct hwrm_port_phy_cfg_input *req) |
| 6586 | { |
| 6587 | struct ethtool_eee *eee = &bp->eee; |
| 6588 | |
| 6589 | if (eee->eee_enabled) { |
| 6590 | u16 eee_speeds; |
| 6591 | u32 flags = PORT_PHY_CFG_REQ_FLAGS_EEE_ENABLE; |
| 6592 | |
| 6593 | if (eee->tx_lpi_enabled) |
| 6594 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_ENABLE; |
| 6595 | else |
| 6596 | flags |= PORT_PHY_CFG_REQ_FLAGS_EEE_TX_LPI_DISABLE; |
| 6597 | |
| 6598 | req->flags |= cpu_to_le32(flags); |
| 6599 | eee_speeds = bnxt_get_fw_auto_link_speeds(eee->advertised); |
| 6600 | req->eee_link_speed_mask = cpu_to_le16(eee_speeds); |
| 6601 | req->tx_lpi_timer = cpu_to_le32(eee->tx_lpi_timer); |
| 6602 | } else { |
| 6603 | req->flags |= cpu_to_le32(PORT_PHY_CFG_REQ_FLAGS_EEE_DISABLE); |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | 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] | 6608 | { |
| 6609 | struct hwrm_port_phy_cfg_input req = {0}; |
| 6610 | |
| 6611 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_PHY_CFG, -1, -1); |
| 6612 | if (set_pause) |
| 6613 | bnxt_hwrm_set_pause_common(bp, &req); |
| 6614 | |
| 6615 | bnxt_hwrm_set_link_common(bp, &req); |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 6616 | |
| 6617 | if (set_eee) |
| 6618 | bnxt_hwrm_set_eee(bp, &req); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6619 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6620 | } |
| 6621 | |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 6622 | static int bnxt_hwrm_shutdown_link(struct bnxt *bp) |
| 6623 | { |
| 6624 | struct hwrm_port_phy_cfg_input req = {0}; |
| 6625 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 6626 | if (!BNXT_SINGLE_PF(bp)) |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 6627 | return 0; |
| 6628 | |
| 6629 | if (pci_num_vf(bp->pdev)) |
| 6630 | return 0; |
| 6631 | |
| 6632 | 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] | 6633 | 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] | 6634 | return hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6635 | } |
| 6636 | |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 6637 | static int bnxt_hwrm_port_led_qcaps(struct bnxt *bp) |
| 6638 | { |
| 6639 | struct hwrm_port_led_qcaps_output *resp = bp->hwrm_cmd_resp_addr; |
| 6640 | struct hwrm_port_led_qcaps_input req = {0}; |
| 6641 | struct bnxt_pf_info *pf = &bp->pf; |
| 6642 | int rc; |
| 6643 | |
| 6644 | if (BNXT_VF(bp) || bp->hwrm_spec_code < 0x10601) |
| 6645 | return 0; |
| 6646 | |
| 6647 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_PORT_LED_QCAPS, -1, -1); |
| 6648 | req.port_id = cpu_to_le16(pf->port_id); |
| 6649 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6650 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6651 | if (rc) { |
| 6652 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6653 | return rc; |
| 6654 | } |
| 6655 | if (resp->num_leds > 0 && resp->num_leds < BNXT_MAX_LED) { |
| 6656 | int i; |
| 6657 | |
| 6658 | bp->num_leds = resp->num_leds; |
| 6659 | memcpy(bp->leds, &resp->led0_id, sizeof(bp->leds[0]) * |
| 6660 | bp->num_leds); |
| 6661 | for (i = 0; i < bp->num_leds; i++) { |
| 6662 | struct bnxt_led_info *led = &bp->leds[i]; |
| 6663 | __le16 caps = led->led_state_caps; |
| 6664 | |
| 6665 | if (!led->led_group_id || |
| 6666 | !BNXT_LED_ALT_BLINK_CAP(caps)) { |
| 6667 | bp->num_leds = 0; |
| 6668 | break; |
| 6669 | } |
| 6670 | } |
| 6671 | } |
| 6672 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6673 | return 0; |
| 6674 | } |
| 6675 | |
Michael Chan | 5282db6 | 2017-04-04 18:14:10 -0400 | [diff] [blame] | 6676 | int bnxt_hwrm_alloc_wol_fltr(struct bnxt *bp) |
| 6677 | { |
| 6678 | struct hwrm_wol_filter_alloc_input req = {0}; |
| 6679 | struct hwrm_wol_filter_alloc_output *resp = bp->hwrm_cmd_resp_addr; |
| 6680 | int rc; |
| 6681 | |
| 6682 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_ALLOC, -1, -1); |
| 6683 | req.port_id = cpu_to_le16(bp->pf.port_id); |
| 6684 | req.wol_type = WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT; |
| 6685 | req.enables = cpu_to_le32(WOL_FILTER_ALLOC_REQ_ENABLES_MAC_ADDRESS); |
| 6686 | memcpy(req.mac_address, bp->dev->dev_addr, ETH_ALEN); |
| 6687 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6688 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6689 | if (!rc) |
| 6690 | bp->wol_filter_id = resp->wol_filter_id; |
| 6691 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6692 | return rc; |
| 6693 | } |
| 6694 | |
| 6695 | int bnxt_hwrm_free_wol_fltr(struct bnxt *bp) |
| 6696 | { |
| 6697 | struct hwrm_wol_filter_free_input req = {0}; |
| 6698 | int rc; |
| 6699 | |
| 6700 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_FREE, -1, -1); |
| 6701 | req.port_id = cpu_to_le16(bp->pf.port_id); |
| 6702 | req.enables = cpu_to_le32(WOL_FILTER_FREE_REQ_ENABLES_WOL_FILTER_ID); |
| 6703 | req.wol_filter_id = bp->wol_filter_id; |
| 6704 | rc = hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6705 | return rc; |
| 6706 | } |
| 6707 | |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 6708 | static u16 bnxt_hwrm_get_wol_fltrs(struct bnxt *bp, u16 handle) |
| 6709 | { |
| 6710 | struct hwrm_wol_filter_qcfg_input req = {0}; |
| 6711 | struct hwrm_wol_filter_qcfg_output *resp = bp->hwrm_cmd_resp_addr; |
| 6712 | u16 next_handle = 0; |
| 6713 | int rc; |
| 6714 | |
| 6715 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_WOL_FILTER_QCFG, -1, -1); |
| 6716 | req.port_id = cpu_to_le16(bp->pf.port_id); |
| 6717 | req.handle = cpu_to_le16(handle); |
| 6718 | mutex_lock(&bp->hwrm_cmd_lock); |
| 6719 | rc = _hwrm_send_message(bp, &req, sizeof(req), HWRM_CMD_TIMEOUT); |
| 6720 | if (!rc) { |
| 6721 | next_handle = le16_to_cpu(resp->next_handle); |
| 6722 | if (next_handle != 0) { |
| 6723 | if (resp->wol_type == |
| 6724 | WOL_FILTER_ALLOC_REQ_WOL_TYPE_MAGICPKT) { |
| 6725 | bp->wol = 1; |
| 6726 | bp->wol_filter_id = resp->wol_filter_id; |
| 6727 | } |
| 6728 | } |
| 6729 | } |
| 6730 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 6731 | return next_handle; |
| 6732 | } |
| 6733 | |
| 6734 | static void bnxt_get_wol_settings(struct bnxt *bp) |
| 6735 | { |
| 6736 | u16 handle = 0; |
| 6737 | |
| 6738 | if (!BNXT_PF(bp) || !(bp->flags & BNXT_FLAG_WOL_CAP)) |
| 6739 | return; |
| 6740 | |
| 6741 | do { |
| 6742 | handle = bnxt_hwrm_get_wol_fltrs(bp, handle); |
| 6743 | } while (handle && handle != 0xffff); |
| 6744 | } |
| 6745 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 6746 | static bool bnxt_eee_config_ok(struct bnxt *bp) |
| 6747 | { |
| 6748 | struct ethtool_eee *eee = &bp->eee; |
| 6749 | struct bnxt_link_info *link_info = &bp->link_info; |
| 6750 | |
| 6751 | if (!(bp->flags & BNXT_FLAG_EEE_CAP)) |
| 6752 | return true; |
| 6753 | |
| 6754 | if (eee->eee_enabled) { |
| 6755 | u32 advertising = |
| 6756 | _bnxt_fw_to_ethtool_adv_spds(link_info->advertising, 0); |
| 6757 | |
| 6758 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 6759 | eee->eee_enabled = 0; |
| 6760 | return false; |
| 6761 | } |
| 6762 | if (eee->advertised & ~advertising) { |
| 6763 | eee->advertised = advertising & eee->supported; |
| 6764 | return false; |
| 6765 | } |
| 6766 | } |
| 6767 | return true; |
| 6768 | } |
| 6769 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6770 | static int bnxt_update_phy_setting(struct bnxt *bp) |
| 6771 | { |
| 6772 | int rc; |
| 6773 | bool update_link = false; |
| 6774 | bool update_pause = false; |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 6775 | bool update_eee = false; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6776 | struct bnxt_link_info *link_info = &bp->link_info; |
| 6777 | |
| 6778 | rc = bnxt_update_link(bp, true); |
| 6779 | if (rc) { |
| 6780 | netdev_err(bp->dev, "failed to update link (rc: %x)\n", |
| 6781 | rc); |
| 6782 | return rc; |
| 6783 | } |
Michael Chan | 33dac24 | 2017-02-12 19:18:15 -0500 | [diff] [blame] | 6784 | if (!BNXT_SINGLE_PF(bp)) |
| 6785 | return 0; |
| 6786 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6787 | if ((link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 6788 | (link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH) != |
| 6789 | link_info->req_flow_ctrl) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6790 | update_pause = true; |
| 6791 | if (!(link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) && |
| 6792 | link_info->force_pause_setting != link_info->req_flow_ctrl) |
| 6793 | update_pause = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6794 | if (!(link_info->autoneg & BNXT_AUTONEG_SPEED)) { |
| 6795 | if (BNXT_AUTO_MODE(link_info->auto_mode)) |
| 6796 | update_link = true; |
| 6797 | if (link_info->req_link_speed != link_info->force_link_speed) |
| 6798 | update_link = true; |
Michael Chan | de73018 | 2016-02-19 19:43:20 -0500 | [diff] [blame] | 6799 | if (link_info->req_duplex != link_info->duplex_setting) |
| 6800 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6801 | } else { |
| 6802 | if (link_info->auto_mode == BNXT_LINK_AUTO_NONE) |
| 6803 | update_link = true; |
| 6804 | if (link_info->advertising != link_info->auto_link_speeds) |
| 6805 | update_link = true; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6806 | } |
| 6807 | |
Michael Chan | 16d663a | 2016-11-16 21:13:07 -0500 | [diff] [blame] | 6808 | /* The last close may have shutdown the link, so need to call |
| 6809 | * PHY_CFG to bring it back up. |
| 6810 | */ |
| 6811 | if (!netif_carrier_ok(bp->dev)) |
| 6812 | update_link = true; |
| 6813 | |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 6814 | if (!bnxt_eee_config_ok(bp)) |
| 6815 | update_eee = true; |
| 6816 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6817 | if (update_link) |
Michael Chan | 939f7f0 | 2016-04-05 14:08:58 -0400 | [diff] [blame] | 6818 | rc = bnxt_hwrm_set_link_setting(bp, update_pause, update_eee); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6819 | else if (update_pause) |
| 6820 | rc = bnxt_hwrm_set_pause(bp); |
| 6821 | if (rc) { |
| 6822 | netdev_err(bp->dev, "failed to update phy setting (rc: %x)\n", |
| 6823 | rc); |
| 6824 | return rc; |
| 6825 | } |
| 6826 | |
| 6827 | return rc; |
| 6828 | } |
| 6829 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 6830 | /* Common routine to pre-map certain register block to different GRC window. |
| 6831 | * A PF has 16 4K windows and a VF has 4 4K windows. However, only 15 windows |
| 6832 | * in PF and 3 windows in VF that can be customized to map in different |
| 6833 | * register blocks. |
| 6834 | */ |
| 6835 | static void bnxt_preset_reg_win(struct bnxt *bp) |
| 6836 | { |
| 6837 | if (BNXT_PF(bp)) { |
| 6838 | /* CAG registers map to GRC window #4 */ |
| 6839 | writel(BNXT_CAG_REG_BASE, |
| 6840 | bp->bar0 + BNXT_GRCPF_REG_WINDOW_BASE_OUT + 12); |
| 6841 | } |
| 6842 | } |
| 6843 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6844 | static int __bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 6845 | { |
| 6846 | int rc = 0; |
| 6847 | |
Jeffrey Huang | 1180949 | 2015-11-05 16:25:49 -0500 | [diff] [blame] | 6848 | bnxt_preset_reg_win(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6849 | netif_carrier_off(bp->dev); |
| 6850 | if (irq_re_init) { |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 6851 | rc = bnxt_reserve_rings(bp); |
| 6852 | if (rc) |
| 6853 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6854 | } |
| 6855 | if ((bp->flags & BNXT_FLAG_RFS) && |
| 6856 | !(bp->flags & BNXT_FLAG_USING_MSIX)) { |
| 6857 | /* disable RFS if falling back to INTA */ |
| 6858 | bp->dev->hw_features &= ~NETIF_F_NTUPLE; |
| 6859 | bp->flags &= ~BNXT_FLAG_RFS; |
| 6860 | } |
| 6861 | |
| 6862 | rc = bnxt_alloc_mem(bp, irq_re_init); |
| 6863 | if (rc) { |
| 6864 | netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); |
| 6865 | goto open_err_free_mem; |
| 6866 | } |
| 6867 | |
| 6868 | if (irq_re_init) { |
| 6869 | bnxt_init_napi(bp); |
| 6870 | rc = bnxt_request_irq(bp); |
| 6871 | if (rc) { |
| 6872 | netdev_err(bp->dev, "bnxt_request_irq err: %x\n", rc); |
| 6873 | goto open_err; |
| 6874 | } |
| 6875 | } |
| 6876 | |
| 6877 | bnxt_enable_napi(bp); |
| 6878 | |
| 6879 | rc = bnxt_init_nic(bp, irq_re_init); |
| 6880 | if (rc) { |
| 6881 | netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc); |
| 6882 | goto open_err; |
| 6883 | } |
| 6884 | |
| 6885 | if (link_re_init) { |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 6886 | mutex_lock(&bp->link_lock); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6887 | rc = bnxt_update_phy_setting(bp); |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 6888 | mutex_unlock(&bp->link_lock); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6889 | if (rc) |
Michael Chan | ba41d46 | 2016-02-19 19:43:21 -0500 | [diff] [blame] | 6890 | netdev_warn(bp->dev, "failed to update phy settings\n"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6891 | } |
| 6892 | |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 6893 | if (irq_re_init) |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 6894 | udp_tunnel_get_rx_info(bp->dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6895 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 6896 | set_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6897 | bnxt_enable_int(bp); |
| 6898 | /* Enable TX queues */ |
| 6899 | bnxt_tx_enable(bp); |
| 6900 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
Michael Chan | 10289be | 2016-05-15 03:04:49 -0400 | [diff] [blame] | 6901 | /* Poll link status and check for SFP+ module status */ |
| 6902 | bnxt_get_port_module_status(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6903 | |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 6904 | /* VF-reps may need to be re-opened after the PF is re-opened */ |
| 6905 | if (BNXT_PF(bp)) |
| 6906 | bnxt_vf_reps_open(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6907 | return 0; |
| 6908 | |
| 6909 | open_err: |
| 6910 | bnxt_disable_napi(bp); |
| 6911 | bnxt_del_napi(bp); |
| 6912 | |
| 6913 | open_err_free_mem: |
| 6914 | bnxt_free_skbs(bp); |
| 6915 | bnxt_free_irq(bp); |
| 6916 | bnxt_free_mem(bp, true); |
| 6917 | return rc; |
| 6918 | } |
| 6919 | |
| 6920 | /* rtnl_lock held */ |
| 6921 | int bnxt_open_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 6922 | { |
| 6923 | int rc = 0; |
| 6924 | |
| 6925 | rc = __bnxt_open_nic(bp, irq_re_init, link_re_init); |
| 6926 | if (rc) { |
| 6927 | netdev_err(bp->dev, "nic open fail (rc: %x)\n", rc); |
| 6928 | dev_close(bp->dev); |
| 6929 | } |
| 6930 | return rc; |
| 6931 | } |
| 6932 | |
Michael Chan | f7dc1ea | 2017-04-04 18:14:13 -0400 | [diff] [blame] | 6933 | /* rtnl_lock held, open the NIC half way by allocating all resources, but |
| 6934 | * NAPI, IRQ, and TX are not enabled. This is mainly used for offline |
| 6935 | * self tests. |
| 6936 | */ |
| 6937 | int bnxt_half_open_nic(struct bnxt *bp) |
| 6938 | { |
| 6939 | int rc = 0; |
| 6940 | |
| 6941 | rc = bnxt_alloc_mem(bp, false); |
| 6942 | if (rc) { |
| 6943 | netdev_err(bp->dev, "bnxt_alloc_mem err: %x\n", rc); |
| 6944 | goto half_open_err; |
| 6945 | } |
| 6946 | rc = bnxt_init_nic(bp, false); |
| 6947 | if (rc) { |
| 6948 | netdev_err(bp->dev, "bnxt_init_nic err: %x\n", rc); |
| 6949 | goto half_open_err; |
| 6950 | } |
| 6951 | return 0; |
| 6952 | |
| 6953 | half_open_err: |
| 6954 | bnxt_free_skbs(bp); |
| 6955 | bnxt_free_mem(bp, false); |
| 6956 | dev_close(bp->dev); |
| 6957 | return rc; |
| 6958 | } |
| 6959 | |
| 6960 | /* rtnl_lock held, this call can only be made after a previous successful |
| 6961 | * call to bnxt_half_open_nic(). |
| 6962 | */ |
| 6963 | void bnxt_half_close_nic(struct bnxt *bp) |
| 6964 | { |
| 6965 | bnxt_hwrm_resource_free(bp, false, false); |
| 6966 | bnxt_free_skbs(bp); |
| 6967 | bnxt_free_mem(bp, false); |
| 6968 | } |
| 6969 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6970 | static int bnxt_open(struct net_device *dev) |
| 6971 | { |
| 6972 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6973 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6974 | return __bnxt_open_nic(bp, true, true); |
| 6975 | } |
| 6976 | |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 6977 | static bool bnxt_drv_busy(struct bnxt *bp) |
| 6978 | { |
| 6979 | return (test_bit(BNXT_STATE_IN_SP_TASK, &bp->state) || |
| 6980 | test_bit(BNXT_STATE_READ_STATS, &bp->state)); |
| 6981 | } |
| 6982 | |
Michael Chan | 86e953d | 2018-01-17 03:21:04 -0500 | [diff] [blame] | 6983 | static void __bnxt_close_nic(struct bnxt *bp, bool irq_re_init, |
| 6984 | bool link_re_init) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6985 | { |
Sathya Perla | ee5c7fb | 2017-07-24 12:34:28 -0400 | [diff] [blame] | 6986 | /* Close the VF-reps before closing PF */ |
| 6987 | if (BNXT_PF(bp)) |
| 6988 | bnxt_vf_reps_close(bp); |
Michael Chan | 86e953d | 2018-01-17 03:21:04 -0500 | [diff] [blame] | 6989 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6990 | /* Change device state to avoid TX queue wake up's */ |
| 6991 | bnxt_tx_disable(bp); |
| 6992 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 6993 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 6994 | smp_mb__after_atomic(); |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 6995 | while (bnxt_drv_busy(bp)) |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 6996 | msleep(20); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6997 | |
Michael Chan | 9d8bc09 | 2016-12-29 12:13:33 -0500 | [diff] [blame] | 6998 | /* Flush rings and and disable interrupts */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 6999 | bnxt_shutdown_nic(bp, irq_re_init); |
| 7000 | |
| 7001 | /* TODO CHIMP_FW: Link/PHY related cleanup if (link_re_init) */ |
| 7002 | |
| 7003 | bnxt_disable_napi(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7004 | del_timer_sync(&bp->timer); |
| 7005 | bnxt_free_skbs(bp); |
| 7006 | |
| 7007 | if (irq_re_init) { |
| 7008 | bnxt_free_irq(bp); |
| 7009 | bnxt_del_napi(bp); |
| 7010 | } |
| 7011 | bnxt_free_mem(bp, irq_re_init); |
Michael Chan | 86e953d | 2018-01-17 03:21:04 -0500 | [diff] [blame] | 7012 | } |
| 7013 | |
| 7014 | int bnxt_close_nic(struct bnxt *bp, bool irq_re_init, bool link_re_init) |
| 7015 | { |
| 7016 | int rc = 0; |
| 7017 | |
| 7018 | #ifdef CONFIG_BNXT_SRIOV |
| 7019 | if (bp->sriov_cfg) { |
| 7020 | rc = wait_event_interruptible_timeout(bp->sriov_cfg_wait, |
| 7021 | !bp->sriov_cfg, |
| 7022 | BNXT_SRIOV_CFG_WAIT_TMO); |
| 7023 | if (rc) |
| 7024 | netdev_warn(bp->dev, "timeout waiting for SRIOV config operation to complete!\n"); |
| 7025 | } |
| 7026 | #endif |
| 7027 | __bnxt_close_nic(bp, irq_re_init, link_re_init); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7028 | return rc; |
| 7029 | } |
| 7030 | |
| 7031 | static int bnxt_close(struct net_device *dev) |
| 7032 | { |
| 7033 | struct bnxt *bp = netdev_priv(dev); |
| 7034 | |
| 7035 | bnxt_close_nic(bp, true, true); |
Michael Chan | 33f7d55 | 2016-04-11 04:11:12 -0400 | [diff] [blame] | 7036 | bnxt_hwrm_shutdown_link(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7037 | return 0; |
| 7038 | } |
| 7039 | |
| 7040 | /* rtnl_lock held */ |
| 7041 | static int bnxt_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 7042 | { |
| 7043 | switch (cmd) { |
| 7044 | case SIOCGMIIPHY: |
| 7045 | /* fallthru */ |
| 7046 | case SIOCGMIIREG: { |
| 7047 | if (!netif_running(dev)) |
| 7048 | return -EAGAIN; |
| 7049 | |
| 7050 | return 0; |
| 7051 | } |
| 7052 | |
| 7053 | case SIOCSMIIREG: |
| 7054 | if (!netif_running(dev)) |
| 7055 | return -EAGAIN; |
| 7056 | |
| 7057 | return 0; |
| 7058 | |
| 7059 | default: |
| 7060 | /* do nothing */ |
| 7061 | break; |
| 7062 | } |
| 7063 | return -EOPNOTSUPP; |
| 7064 | } |
| 7065 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7066 | static void |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7067 | bnxt_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
| 7068 | { |
| 7069 | u32 i; |
| 7070 | struct bnxt *bp = netdev_priv(dev); |
| 7071 | |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 7072 | set_bit(BNXT_STATE_READ_STATS, &bp->state); |
| 7073 | /* Make sure bnxt_close_nic() sees that we are reading stats before |
| 7074 | * we check the BNXT_STATE_OPEN flag. |
| 7075 | */ |
| 7076 | smp_mb__after_atomic(); |
| 7077 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
| 7078 | clear_bit(BNXT_STATE_READ_STATS, &bp->state); |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7079 | return; |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 7080 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7081 | |
| 7082 | /* TODO check if we need to synchronize with bnxt_close path */ |
| 7083 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 7084 | struct bnxt_napi *bnapi = bp->bnapi[i]; |
| 7085 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 7086 | struct ctx_hw_stats *hw_stats = cpr->hw_stats; |
| 7087 | |
| 7088 | stats->rx_packets += le64_to_cpu(hw_stats->rx_ucast_pkts); |
| 7089 | stats->rx_packets += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 7090 | stats->rx_packets += le64_to_cpu(hw_stats->rx_bcast_pkts); |
| 7091 | |
| 7092 | stats->tx_packets += le64_to_cpu(hw_stats->tx_ucast_pkts); |
| 7093 | stats->tx_packets += le64_to_cpu(hw_stats->tx_mcast_pkts); |
| 7094 | stats->tx_packets += le64_to_cpu(hw_stats->tx_bcast_pkts); |
| 7095 | |
| 7096 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_ucast_bytes); |
| 7097 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_mcast_bytes); |
| 7098 | stats->rx_bytes += le64_to_cpu(hw_stats->rx_bcast_bytes); |
| 7099 | |
| 7100 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_ucast_bytes); |
| 7101 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_mcast_bytes); |
| 7102 | stats->tx_bytes += le64_to_cpu(hw_stats->tx_bcast_bytes); |
| 7103 | |
| 7104 | stats->rx_missed_errors += |
| 7105 | le64_to_cpu(hw_stats->rx_discard_pkts); |
| 7106 | |
| 7107 | stats->multicast += le64_to_cpu(hw_stats->rx_mcast_pkts); |
| 7108 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7109 | stats->tx_dropped += le64_to_cpu(hw_stats->tx_drop_pkts); |
| 7110 | } |
| 7111 | |
Michael Chan | 9947f83 | 2016-03-07 15:38:46 -0500 | [diff] [blame] | 7112 | if (bp->flags & BNXT_FLAG_PORT_STATS) { |
| 7113 | struct rx_port_stats *rx = bp->hw_rx_port_stats; |
| 7114 | struct tx_port_stats *tx = bp->hw_tx_port_stats; |
| 7115 | |
| 7116 | stats->rx_crc_errors = le64_to_cpu(rx->rx_fcs_err_frames); |
| 7117 | stats->rx_frame_errors = le64_to_cpu(rx->rx_align_err_frames); |
| 7118 | stats->rx_length_errors = le64_to_cpu(rx->rx_undrsz_frames) + |
| 7119 | le64_to_cpu(rx->rx_ovrsz_frames) + |
| 7120 | le64_to_cpu(rx->rx_runt_frames); |
| 7121 | stats->rx_errors = le64_to_cpu(rx->rx_false_carrier_frames) + |
| 7122 | le64_to_cpu(rx->rx_jbr_frames); |
| 7123 | stats->collisions = le64_to_cpu(tx->tx_total_collisions); |
| 7124 | stats->tx_fifo_errors = le64_to_cpu(tx->tx_fifo_underruns); |
| 7125 | stats->tx_errors = le64_to_cpu(tx->tx_err); |
| 7126 | } |
Michael Chan | f9b76eb | 2017-07-11 13:05:34 -0400 | [diff] [blame] | 7127 | clear_bit(BNXT_STATE_READ_STATS, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7128 | } |
| 7129 | |
| 7130 | static bool bnxt_mc_list_updated(struct bnxt *bp, u32 *rx_mask) |
| 7131 | { |
| 7132 | struct net_device *dev = bp->dev; |
| 7133 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 7134 | struct netdev_hw_addr *ha; |
| 7135 | u8 *haddr; |
| 7136 | int mc_count = 0; |
| 7137 | bool update = false; |
| 7138 | int off = 0; |
| 7139 | |
| 7140 | netdev_for_each_mc_addr(ha, dev) { |
| 7141 | if (mc_count >= BNXT_MAX_MC_ADDRS) { |
| 7142 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 7143 | vnic->mc_list_count = 0; |
| 7144 | return false; |
| 7145 | } |
| 7146 | haddr = ha->addr; |
| 7147 | if (!ether_addr_equal(haddr, vnic->mc_list + off)) { |
| 7148 | memcpy(vnic->mc_list + off, haddr, ETH_ALEN); |
| 7149 | update = true; |
| 7150 | } |
| 7151 | off += ETH_ALEN; |
| 7152 | mc_count++; |
| 7153 | } |
| 7154 | if (mc_count) |
| 7155 | *rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_MCAST; |
| 7156 | |
| 7157 | if (mc_count != vnic->mc_list_count) { |
| 7158 | vnic->mc_list_count = mc_count; |
| 7159 | update = true; |
| 7160 | } |
| 7161 | return update; |
| 7162 | } |
| 7163 | |
| 7164 | static bool bnxt_uc_list_updated(struct bnxt *bp) |
| 7165 | { |
| 7166 | struct net_device *dev = bp->dev; |
| 7167 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 7168 | struct netdev_hw_addr *ha; |
| 7169 | int off = 0; |
| 7170 | |
| 7171 | if (netdev_uc_count(dev) != (vnic->uc_filter_count - 1)) |
| 7172 | return true; |
| 7173 | |
| 7174 | netdev_for_each_uc_addr(ha, dev) { |
| 7175 | if (!ether_addr_equal(ha->addr, vnic->uc_list + off)) |
| 7176 | return true; |
| 7177 | |
| 7178 | off += ETH_ALEN; |
| 7179 | } |
| 7180 | return false; |
| 7181 | } |
| 7182 | |
| 7183 | static void bnxt_set_rx_mode(struct net_device *dev) |
| 7184 | { |
| 7185 | struct bnxt *bp = netdev_priv(dev); |
| 7186 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 7187 | u32 mask = vnic->rx_mask; |
| 7188 | bool mc_update = false; |
| 7189 | bool uc_update; |
| 7190 | |
| 7191 | if (!netif_running(dev)) |
| 7192 | return; |
| 7193 | |
| 7194 | mask &= ~(CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS | |
| 7195 | CFA_L2_SET_RX_MASK_REQ_MASK_MCAST | |
| 7196 | CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST); |
| 7197 | |
Michael Chan | 17c71ac | 2016-07-01 18:46:27 -0400 | [diff] [blame] | 7198 | if ((dev->flags & IFF_PROMISC) && bnxt_promisc_ok(bp)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7199 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 7200 | |
| 7201 | uc_update = bnxt_uc_list_updated(bp); |
| 7202 | |
| 7203 | if (dev->flags & IFF_ALLMULTI) { |
| 7204 | mask |= CFA_L2_SET_RX_MASK_REQ_MASK_ALL_MCAST; |
| 7205 | vnic->mc_list_count = 0; |
| 7206 | } else { |
| 7207 | mc_update = bnxt_mc_list_updated(bp, &mask); |
| 7208 | } |
| 7209 | |
| 7210 | if (mask != vnic->rx_mask || uc_update || mc_update) { |
| 7211 | vnic->rx_mask = mask; |
| 7212 | |
| 7213 | set_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 7214 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7215 | } |
| 7216 | } |
| 7217 | |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 7218 | static int bnxt_cfg_rx_mode(struct bnxt *bp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7219 | { |
| 7220 | struct net_device *dev = bp->dev; |
| 7221 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 7222 | struct netdev_hw_addr *ha; |
| 7223 | int i, off = 0, rc; |
| 7224 | bool uc_update; |
| 7225 | |
| 7226 | netif_addr_lock_bh(dev); |
| 7227 | uc_update = bnxt_uc_list_updated(bp); |
| 7228 | netif_addr_unlock_bh(dev); |
| 7229 | |
| 7230 | if (!uc_update) |
| 7231 | goto skip_uc; |
| 7232 | |
| 7233 | mutex_lock(&bp->hwrm_cmd_lock); |
| 7234 | for (i = 1; i < vnic->uc_filter_count; i++) { |
| 7235 | struct hwrm_cfa_l2_filter_free_input req = {0}; |
| 7236 | |
| 7237 | bnxt_hwrm_cmd_hdr_init(bp, &req, HWRM_CFA_L2_FILTER_FREE, -1, |
| 7238 | -1); |
| 7239 | |
| 7240 | req.l2_filter_id = vnic->fw_l2_filter_id[i]; |
| 7241 | |
| 7242 | rc = _hwrm_send_message(bp, &req, sizeof(req), |
| 7243 | HWRM_CMD_TIMEOUT); |
| 7244 | } |
| 7245 | mutex_unlock(&bp->hwrm_cmd_lock); |
| 7246 | |
| 7247 | vnic->uc_filter_count = 1; |
| 7248 | |
| 7249 | netif_addr_lock_bh(dev); |
| 7250 | if (netdev_uc_count(dev) > (BNXT_MAX_UC_ADDRS - 1)) { |
| 7251 | vnic->rx_mask |= CFA_L2_SET_RX_MASK_REQ_MASK_PROMISCUOUS; |
| 7252 | } else { |
| 7253 | netdev_for_each_uc_addr(ha, dev) { |
| 7254 | memcpy(vnic->uc_list + off, ha->addr, ETH_ALEN); |
| 7255 | off += ETH_ALEN; |
| 7256 | vnic->uc_filter_count++; |
| 7257 | } |
| 7258 | } |
| 7259 | netif_addr_unlock_bh(dev); |
| 7260 | |
| 7261 | for (i = 1, off = 0; i < vnic->uc_filter_count; i++, off += ETH_ALEN) { |
| 7262 | rc = bnxt_hwrm_set_vnic_filter(bp, 0, i, vnic->uc_list + off); |
| 7263 | if (rc) { |
| 7264 | netdev_err(bp->dev, "HWRM vnic filter failure rc: %x\n", |
| 7265 | rc); |
| 7266 | vnic->uc_filter_count = i; |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 7267 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7268 | } |
| 7269 | } |
| 7270 | |
| 7271 | skip_uc: |
| 7272 | rc = bnxt_hwrm_cfa_l2_set_rx_mask(bp, 0); |
| 7273 | if (rc) |
| 7274 | netdev_err(bp->dev, "HWRM cfa l2 rx mask failure rc: %x\n", |
| 7275 | rc); |
Michael Chan | b664f00 | 2015-12-02 01:54:08 -0500 | [diff] [blame] | 7276 | |
| 7277 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7278 | } |
| 7279 | |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7280 | /* If the chip and firmware supports RFS */ |
| 7281 | static bool bnxt_rfs_supported(struct bnxt *bp) |
| 7282 | { |
| 7283 | if (BNXT_PF(bp) && !BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 7284 | return true; |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 7285 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 7286 | return true; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7287 | return false; |
| 7288 | } |
| 7289 | |
| 7290 | /* If runtime conditions support RFS */ |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7291 | static bool bnxt_rfs_capable(struct bnxt *bp) |
| 7292 | { |
| 7293 | #ifdef CONFIG_RFS_ACCEL |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7294 | int vnics, max_vnics, max_rss_ctxs; |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7295 | |
Michael Chan | 964fd48 | 2017-02-12 19:18:13 -0500 | [diff] [blame] | 7296 | if (!(bp->flags & BNXT_FLAG_MSIX_CAP)) |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7297 | return false; |
| 7298 | |
| 7299 | vnics = 1 + bp->rx_nr_rings; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7300 | max_vnics = bnxt_get_max_func_vnics(bp); |
| 7301 | max_rss_ctxs = bnxt_get_max_func_rss_ctxs(bp); |
Michael Chan | ae10ae7 | 2016-12-29 12:13:38 -0500 | [diff] [blame] | 7302 | |
| 7303 | /* RSS contexts not a limiting factor */ |
| 7304 | if (bp->flags & BNXT_FLAG_NEW_RSS_CAP) |
| 7305 | max_rss_ctxs = max_vnics; |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 7306 | if (vnics > max_vnics || vnics > max_rss_ctxs) { |
Michael Chan | 6a1eef5 | 2018-01-17 03:21:10 -0500 | [diff] [blame] | 7307 | if (bp->rx_nr_rings > 1) |
| 7308 | netdev_warn(bp->dev, |
| 7309 | "Not enough resources to support NTUPLE filters, enough resources for up to %d rx rings\n", |
| 7310 | min(max_rss_ctxs - 1, max_vnics - 1)); |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7311 | return false; |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 7312 | } |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7313 | |
Michael Chan | 6a1eef5 | 2018-01-17 03:21:10 -0500 | [diff] [blame] | 7314 | if (!(bp->flags & BNXT_FLAG_NEW_RM)) |
| 7315 | return true; |
| 7316 | |
| 7317 | if (vnics == bp->hw_resc.resv_vnics) |
| 7318 | return true; |
| 7319 | |
| 7320 | bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, vnics); |
| 7321 | if (vnics <= bp->hw_resc.resv_vnics) |
| 7322 | return true; |
| 7323 | |
| 7324 | netdev_warn(bp->dev, "Unable to reserve resources to support NTUPLE filters.\n"); |
| 7325 | bnxt_hwrm_reserve_rings(bp, 0, 0, 0, 0, 1); |
| 7326 | return false; |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7327 | #else |
| 7328 | return false; |
| 7329 | #endif |
| 7330 | } |
| 7331 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7332 | static netdev_features_t bnxt_fix_features(struct net_device *dev, |
| 7333 | netdev_features_t features) |
| 7334 | { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7335 | struct bnxt *bp = netdev_priv(dev); |
| 7336 | |
Vasundhara Volam | a230490 | 2016-07-25 12:33:36 -0400 | [diff] [blame] | 7337 | if ((features & NETIF_F_NTUPLE) && !bnxt_rfs_capable(bp)) |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7338 | features &= ~NETIF_F_NTUPLE; |
Michael Chan | 5a9f6b2 | 2016-06-06 02:37:15 -0400 | [diff] [blame] | 7339 | |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 7340 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 7341 | features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); |
| 7342 | |
| 7343 | if (!(features & NETIF_F_GRO)) |
| 7344 | features &= ~NETIF_F_GRO_HW; |
| 7345 | |
| 7346 | if (features & NETIF_F_GRO_HW) |
| 7347 | features &= ~NETIF_F_LRO; |
| 7348 | |
Michael Chan | 5a9f6b2 | 2016-06-06 02:37:15 -0400 | [diff] [blame] | 7349 | /* Both CTAG and STAG VLAN accelaration on the RX side have to be |
| 7350 | * turned on or off together. |
| 7351 | */ |
| 7352 | if ((features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) != |
| 7353 | (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX)) { |
| 7354 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7355 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 7356 | NETIF_F_HW_VLAN_STAG_RX); |
| 7357 | else |
| 7358 | features |= NETIF_F_HW_VLAN_CTAG_RX | |
| 7359 | NETIF_F_HW_VLAN_STAG_RX; |
| 7360 | } |
Michael Chan | cf6645f | 2016-06-13 02:25:28 -0400 | [diff] [blame] | 7361 | #ifdef CONFIG_BNXT_SRIOV |
| 7362 | if (BNXT_VF(bp)) { |
| 7363 | if (bp->vf.vlan) { |
| 7364 | features &= ~(NETIF_F_HW_VLAN_CTAG_RX | |
| 7365 | NETIF_F_HW_VLAN_STAG_RX); |
| 7366 | } |
| 7367 | } |
| 7368 | #endif |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7369 | return features; |
| 7370 | } |
| 7371 | |
| 7372 | static int bnxt_set_features(struct net_device *dev, netdev_features_t features) |
| 7373 | { |
| 7374 | struct bnxt *bp = netdev_priv(dev); |
| 7375 | u32 flags = bp->flags; |
| 7376 | u32 changes; |
| 7377 | int rc = 0; |
| 7378 | bool re_init = false; |
| 7379 | bool update_tpa = false; |
| 7380 | |
| 7381 | flags &= ~BNXT_FLAG_ALL_CONFIG_FEATS; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 7382 | if (features & NETIF_F_GRO_HW) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7383 | flags |= BNXT_FLAG_GRO; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 7384 | else if (features & NETIF_F_LRO) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7385 | flags |= BNXT_FLAG_LRO; |
| 7386 | |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 7387 | if (bp->flags & BNXT_FLAG_NO_AGG_RINGS) |
| 7388 | flags &= ~BNXT_FLAG_TPA; |
| 7389 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7390 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 7391 | flags |= BNXT_FLAG_STRIP_VLAN; |
| 7392 | |
| 7393 | if (features & NETIF_F_NTUPLE) |
| 7394 | flags |= BNXT_FLAG_RFS; |
| 7395 | |
| 7396 | changes = flags ^ bp->flags; |
| 7397 | if (changes & BNXT_FLAG_TPA) { |
| 7398 | update_tpa = true; |
| 7399 | if ((bp->flags & BNXT_FLAG_TPA) == 0 || |
| 7400 | (flags & BNXT_FLAG_TPA) == 0) |
| 7401 | re_init = true; |
| 7402 | } |
| 7403 | |
| 7404 | if (changes & ~BNXT_FLAG_TPA) |
| 7405 | re_init = true; |
| 7406 | |
| 7407 | if (flags != bp->flags) { |
| 7408 | u32 old_flags = bp->flags; |
| 7409 | |
| 7410 | bp->flags = flags; |
| 7411 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 7412 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7413 | if (update_tpa) |
| 7414 | bnxt_set_ring_params(bp); |
| 7415 | return rc; |
| 7416 | } |
| 7417 | |
| 7418 | if (re_init) { |
| 7419 | bnxt_close_nic(bp, false, false); |
| 7420 | if (update_tpa) |
| 7421 | bnxt_set_ring_params(bp); |
| 7422 | |
| 7423 | return bnxt_open_nic(bp, false, false); |
| 7424 | } |
| 7425 | if (update_tpa) { |
| 7426 | rc = bnxt_set_tpa(bp, |
| 7427 | (flags & BNXT_FLAG_TPA) ? |
| 7428 | true : false); |
| 7429 | if (rc) |
| 7430 | bp->flags = old_flags; |
| 7431 | } |
| 7432 | } |
| 7433 | return rc; |
| 7434 | } |
| 7435 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 7436 | static void bnxt_dump_tx_sw_state(struct bnxt_napi *bnapi) |
| 7437 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 7438 | struct bnxt_tx_ring_info *txr = bnapi->tx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 7439 | int i = bnapi->index; |
| 7440 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 7441 | if (!txr) |
| 7442 | return; |
| 7443 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 7444 | netdev_info(bnapi->bp->dev, "[%d]: tx{fw_ring: %d prod: %x cons: %x}\n", |
| 7445 | i, txr->tx_ring_struct.fw_ring_id, txr->tx_prod, |
| 7446 | txr->tx_cons); |
| 7447 | } |
| 7448 | |
| 7449 | static void bnxt_dump_rx_sw_state(struct bnxt_napi *bnapi) |
| 7450 | { |
Michael Chan | b6ab4b0 | 2016-01-02 23:44:59 -0500 | [diff] [blame] | 7451 | struct bnxt_rx_ring_info *rxr = bnapi->rx_ring; |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 7452 | int i = bnapi->index; |
| 7453 | |
Michael Chan | 3b2b7d9 | 2016-01-02 23:45:00 -0500 | [diff] [blame] | 7454 | if (!rxr) |
| 7455 | return; |
| 7456 | |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 7457 | 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", |
| 7458 | i, rxr->rx_ring_struct.fw_ring_id, rxr->rx_prod, |
| 7459 | rxr->rx_agg_ring_struct.fw_ring_id, rxr->rx_agg_prod, |
| 7460 | rxr->rx_sw_agg_prod); |
| 7461 | } |
| 7462 | |
| 7463 | static void bnxt_dump_cp_sw_state(struct bnxt_napi *bnapi) |
| 7464 | { |
| 7465 | struct bnxt_cp_ring_info *cpr = &bnapi->cp_ring; |
| 7466 | int i = bnapi->index; |
| 7467 | |
| 7468 | netdev_info(bnapi->bp->dev, "[%d]: cp{fw_ring: %d raw_cons: %x}\n", |
| 7469 | i, cpr->cp_ring_struct.fw_ring_id, cpr->cp_raw_cons); |
| 7470 | } |
| 7471 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7472 | static void bnxt_dbg_dump_states(struct bnxt *bp) |
| 7473 | { |
| 7474 | int i; |
| 7475 | struct bnxt_napi *bnapi; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7476 | |
| 7477 | for (i = 0; i < bp->cp_nr_rings; i++) { |
| 7478 | bnapi = bp->bnapi[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7479 | if (netif_msg_drv(bp)) { |
Michael Chan | 9f55459 | 2016-01-02 23:44:58 -0500 | [diff] [blame] | 7480 | bnxt_dump_tx_sw_state(bnapi); |
| 7481 | bnxt_dump_rx_sw_state(bnapi); |
| 7482 | bnxt_dump_cp_sw_state(bnapi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7483 | } |
| 7484 | } |
| 7485 | } |
| 7486 | |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 7487 | static void bnxt_reset_task(struct bnxt *bp, bool silent) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7488 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 7489 | if (!silent) |
| 7490 | bnxt_dbg_dump_states(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 7491 | if (netif_running(bp->dev)) { |
Michael Chan | b386cd3 | 2017-03-08 18:44:33 -0500 | [diff] [blame] | 7492 | int rc; |
| 7493 | |
| 7494 | if (!silent) |
| 7495 | bnxt_ulp_stop(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 7496 | bnxt_close_nic(bp, false, false); |
Michael Chan | b386cd3 | 2017-03-08 18:44:33 -0500 | [diff] [blame] | 7497 | rc = bnxt_open_nic(bp, false, false); |
| 7498 | if (!silent && !rc) |
| 7499 | bnxt_ulp_start(bp); |
Michael Chan | 028de14 | 2015-12-09 19:35:44 -0500 | [diff] [blame] | 7500 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7501 | } |
| 7502 | |
| 7503 | static void bnxt_tx_timeout(struct net_device *dev) |
| 7504 | { |
| 7505 | struct bnxt *bp = netdev_priv(dev); |
| 7506 | |
| 7507 | netdev_err(bp->dev, "TX timeout detected, starting reset task!\n"); |
| 7508 | set_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 7509 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7513 | static void bnxt_poll_controller(struct net_device *dev) |
| 7514 | { |
| 7515 | struct bnxt *bp = netdev_priv(dev); |
| 7516 | int i; |
| 7517 | |
Michael Chan | 2270bc5 | 2017-06-23 14:01:01 -0400 | [diff] [blame] | 7518 | /* Only process tx rings/combined rings in netpoll mode. */ |
| 7519 | for (i = 0; i < bp->tx_nr_rings; i++) { |
| 7520 | struct bnxt_tx_ring_info *txr = &bp->tx_ring[i]; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7521 | |
Michael Chan | 2270bc5 | 2017-06-23 14:01:01 -0400 | [diff] [blame] | 7522 | napi_schedule(&txr->bnapi->napi); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7523 | } |
| 7524 | } |
| 7525 | #endif |
| 7526 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 7527 | static void bnxt_timer(struct timer_list *t) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7528 | { |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 7529 | struct bnxt *bp = from_timer(bp, t, timer); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7530 | struct net_device *dev = bp->dev; |
| 7531 | |
| 7532 | if (!netif_running(dev)) |
| 7533 | return; |
| 7534 | |
| 7535 | if (atomic_read(&bp->intr_sem) != 0) |
| 7536 | goto bnxt_restart_timer; |
| 7537 | |
Michael Chan | adcc331 | 2017-07-24 12:34:24 -0400 | [diff] [blame] | 7538 | if (bp->link_info.link_up && (bp->flags & BNXT_FLAG_PORT_STATS) && |
| 7539 | bp->stats_coal_ticks) { |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 7540 | set_bit(BNXT_PERIODIC_STATS_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 7541 | bnxt_queue_sp_work(bp); |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 7542 | } |
Sathya Perla | 5a84acb | 2017-10-26 11:51:31 -0400 | [diff] [blame] | 7543 | |
| 7544 | if (bnxt_tc_flower_enabled(bp)) { |
| 7545 | set_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event); |
| 7546 | bnxt_queue_sp_work(bp); |
| 7547 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7548 | bnxt_restart_timer: |
| 7549 | mod_timer(&bp->timer, jiffies + bp->current_interval); |
| 7550 | } |
| 7551 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 7552 | static void bnxt_rtnl_lock_sp(struct bnxt *bp) |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 7553 | { |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 7554 | /* We are called from bnxt_sp_task which has BNXT_STATE_IN_SP_TASK |
| 7555 | * set. If the device is being closed, bnxt_close() may be holding |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 7556 | * rtnl() and waiting for BNXT_STATE_IN_SP_TASK to clear. So we |
| 7557 | * must clear BNXT_STATE_IN_SP_TASK before holding rtnl(). |
| 7558 | */ |
| 7559 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 7560 | rtnl_lock(); |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 7561 | } |
| 7562 | |
| 7563 | static void bnxt_rtnl_unlock_sp(struct bnxt *bp) |
| 7564 | { |
Michael Chan | 6988bd9 | 2016-06-13 02:25:29 -0400 | [diff] [blame] | 7565 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 7566 | rtnl_unlock(); |
| 7567 | } |
| 7568 | |
Michael Chan | a551ee9 | 2017-01-25 02:55:07 -0500 | [diff] [blame] | 7569 | /* Only called from bnxt_sp_task() */ |
| 7570 | static void bnxt_reset(struct bnxt *bp, bool silent) |
| 7571 | { |
| 7572 | bnxt_rtnl_lock_sp(bp); |
| 7573 | if (test_bit(BNXT_STATE_OPEN, &bp->state)) |
| 7574 | bnxt_reset_task(bp, silent); |
| 7575 | bnxt_rtnl_unlock_sp(bp); |
| 7576 | } |
| 7577 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7578 | static void bnxt_cfg_ntp_filters(struct bnxt *); |
| 7579 | |
| 7580 | static void bnxt_sp_task(struct work_struct *work) |
| 7581 | { |
| 7582 | struct bnxt *bp = container_of(work, struct bnxt, sp_task); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7583 | |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 7584 | set_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 7585 | smp_mb__after_atomic(); |
| 7586 | if (!test_bit(BNXT_STATE_OPEN, &bp->state)) { |
| 7587 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7588 | return; |
Michael Chan | 4cebdce | 2015-12-09 19:35:43 -0500 | [diff] [blame] | 7589 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7590 | |
| 7591 | if (test_and_clear_bit(BNXT_RX_MASK_SP_EVENT, &bp->sp_event)) |
| 7592 | bnxt_cfg_rx_mode(bp); |
| 7593 | |
| 7594 | if (test_and_clear_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event)) |
| 7595 | bnxt_cfg_ntp_filters(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7596 | if (test_and_clear_bit(BNXT_HWRM_EXEC_FWD_REQ_SP_EVENT, &bp->sp_event)) |
| 7597 | bnxt_hwrm_exec_fwd_req(bp); |
| 7598 | if (test_and_clear_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 7599 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 7600 | bp, bp->vxlan_port, |
| 7601 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 7602 | } |
| 7603 | if (test_and_clear_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 7604 | bnxt_hwrm_tunnel_dst_port_free( |
| 7605 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_VXLAN); |
| 7606 | } |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 7607 | if (test_and_clear_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event)) { |
| 7608 | bnxt_hwrm_tunnel_dst_port_alloc( |
| 7609 | bp, bp->nge_port, |
| 7610 | TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 7611 | } |
| 7612 | if (test_and_clear_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event)) { |
| 7613 | bnxt_hwrm_tunnel_dst_port_free( |
| 7614 | bp, TUNNEL_DST_PORT_FREE_REQ_TUNNEL_TYPE_GENEVE); |
| 7615 | } |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 7616 | 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] | 7617 | bnxt_hwrm_port_qstats(bp); |
Vasundhara Volam | 00db3cb | 2018-03-31 13:54:12 -0400 | [diff] [blame] | 7618 | bnxt_hwrm_port_qstats_ext(bp); |
| 7619 | } |
Michael Chan | 3bdf56c | 2016-03-07 15:38:45 -0500 | [diff] [blame] | 7620 | |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 7621 | 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] | 7622 | int rc; |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 7623 | |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 7624 | mutex_lock(&bp->link_lock); |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 7625 | if (test_and_clear_bit(BNXT_LINK_SPEED_CHNG_SP_EVENT, |
| 7626 | &bp->sp_event)) |
| 7627 | bnxt_hwrm_phy_qcaps(bp); |
| 7628 | |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 7629 | rc = bnxt_update_link(bp, true); |
| 7630 | mutex_unlock(&bp->link_lock); |
Michael Chan | 0eaa24b | 2017-01-25 02:55:08 -0500 | [diff] [blame] | 7631 | if (rc) |
| 7632 | netdev_err(bp->dev, "SP task can't update link (rc: %x)\n", |
| 7633 | rc); |
| 7634 | } |
Michael Chan | 90c694b | 2017-01-25 02:55:09 -0500 | [diff] [blame] | 7635 | 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] | 7636 | mutex_lock(&bp->link_lock); |
| 7637 | bnxt_get_port_module_status(bp); |
| 7638 | mutex_unlock(&bp->link_lock); |
Michael Chan | 90c694b | 2017-01-25 02:55:09 -0500 | [diff] [blame] | 7639 | } |
Sathya Perla | 5a84acb | 2017-10-26 11:51:31 -0400 | [diff] [blame] | 7640 | |
| 7641 | if (test_and_clear_bit(BNXT_FLOW_STATS_SP_EVENT, &bp->sp_event)) |
| 7642 | bnxt_tc_flow_stats_work(bp); |
| 7643 | |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 7644 | /* These functions below will clear BNXT_STATE_IN_SP_TASK. They |
| 7645 | * must be the last functions to be called before exiting. |
| 7646 | */ |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7647 | if (test_and_clear_bit(BNXT_RESET_TASK_SP_EVENT, &bp->sp_event)) |
| 7648 | bnxt_reset(bp, false); |
| 7649 | |
| 7650 | if (test_and_clear_bit(BNXT_RESET_TASK_SILENT_SP_EVENT, &bp->sp_event)) |
| 7651 | bnxt_reset(bp, true); |
| 7652 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7653 | smp_mb__before_atomic(); |
| 7654 | clear_bit(BNXT_STATE_IN_SP_TASK, &bp->state); |
| 7655 | } |
| 7656 | |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7657 | /* Under rtnl_lock */ |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 7658 | int bnxt_check_rings(struct bnxt *bp, int tx, int rx, bool sh, int tcs, |
| 7659 | int tx_xdp) |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7660 | { |
| 7661 | int max_rx, max_tx, tx_sets = 1; |
| 7662 | int tx_rings_needed; |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 7663 | int rx_rings = rx; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 7664 | int cp, vnics, rc; |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7665 | |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7666 | if (tcs) |
| 7667 | tx_sets = tcs; |
| 7668 | |
| 7669 | rc = bnxt_get_max_rings(bp, &max_rx, &max_tx, sh); |
| 7670 | if (rc) |
| 7671 | return rc; |
| 7672 | |
| 7673 | if (max_rx < rx) |
| 7674 | return -ENOMEM; |
| 7675 | |
Michael Chan | 5f44924 | 2017-02-06 16:55:40 -0500 | [diff] [blame] | 7676 | tx_rings_needed = tx * tx_sets + tx_xdp; |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7677 | if (max_tx < tx_rings_needed) |
| 7678 | return -ENOMEM; |
| 7679 | |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 7680 | vnics = 1; |
| 7681 | if (bp->flags & BNXT_FLAG_RFS) |
| 7682 | vnics += rx_rings; |
| 7683 | |
Michael Chan | 8f23d63 | 2018-01-17 03:21:12 -0500 | [diff] [blame] | 7684 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 7685 | rx_rings <<= 1; |
| 7686 | cp = sh ? max_t(int, tx_rings_needed, rx) : tx_rings_needed + rx; |
Eddie Wai | 6fc2ffd | 2018-03-09 23:46:04 -0500 | [diff] [blame] | 7687 | return bnxt_hwrm_check_rings(bp, tx_rings_needed, rx_rings, rx, cp, |
| 7688 | vnics); |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7689 | } |
| 7690 | |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 7691 | static void bnxt_unmap_bars(struct bnxt *bp, struct pci_dev *pdev) |
| 7692 | { |
| 7693 | if (bp->bar2) { |
| 7694 | pci_iounmap(pdev, bp->bar2); |
| 7695 | bp->bar2 = NULL; |
| 7696 | } |
| 7697 | |
| 7698 | if (bp->bar1) { |
| 7699 | pci_iounmap(pdev, bp->bar1); |
| 7700 | bp->bar1 = NULL; |
| 7701 | } |
| 7702 | |
| 7703 | if (bp->bar0) { |
| 7704 | pci_iounmap(pdev, bp->bar0); |
| 7705 | bp->bar0 = NULL; |
| 7706 | } |
| 7707 | } |
| 7708 | |
| 7709 | static void bnxt_cleanup_pci(struct bnxt *bp) |
| 7710 | { |
| 7711 | bnxt_unmap_bars(bp, bp->pdev); |
| 7712 | pci_release_regions(bp->pdev); |
| 7713 | pci_disable_device(bp->pdev); |
| 7714 | } |
| 7715 | |
Michael Chan | 18775aa | 2017-10-26 11:51:27 -0400 | [diff] [blame] | 7716 | static void bnxt_init_dflt_coal(struct bnxt *bp) |
| 7717 | { |
| 7718 | struct bnxt_coal *coal; |
| 7719 | |
| 7720 | /* Tick values in micro seconds. |
| 7721 | * 1 coal_buf x bufs_per_record = 1 completion record. |
| 7722 | */ |
| 7723 | coal = &bp->rx_coal; |
| 7724 | coal->coal_ticks = 14; |
| 7725 | coal->coal_bufs = 30; |
| 7726 | coal->coal_ticks_irq = 1; |
| 7727 | coal->coal_bufs_irq = 2; |
| 7728 | coal->idle_thresh = 25; |
| 7729 | coal->bufs_per_record = 2; |
| 7730 | coal->budget = 64; /* NAPI budget */ |
| 7731 | |
| 7732 | coal = &bp->tx_coal; |
| 7733 | coal->coal_ticks = 28; |
| 7734 | coal->coal_bufs = 30; |
| 7735 | coal->coal_ticks_irq = 2; |
| 7736 | coal->coal_bufs_irq = 2; |
| 7737 | coal->bufs_per_record = 1; |
| 7738 | |
| 7739 | bp->stats_coal_ticks = BNXT_DEF_STATS_COAL_TICKS; |
| 7740 | } |
| 7741 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7742 | static int bnxt_init_board(struct pci_dev *pdev, struct net_device *dev) |
| 7743 | { |
| 7744 | int rc; |
| 7745 | struct bnxt *bp = netdev_priv(dev); |
| 7746 | |
| 7747 | SET_NETDEV_DEV(dev, &pdev->dev); |
| 7748 | |
| 7749 | /* enable device (incl. PCI PM wakeup), and bus-mastering */ |
| 7750 | rc = pci_enable_device(pdev); |
| 7751 | if (rc) { |
| 7752 | dev_err(&pdev->dev, "Cannot enable PCI device, aborting\n"); |
| 7753 | goto init_err; |
| 7754 | } |
| 7755 | |
| 7756 | if (!(pci_resource_flags(pdev, 0) & IORESOURCE_MEM)) { |
| 7757 | dev_err(&pdev->dev, |
| 7758 | "Cannot find PCI device base address, aborting\n"); |
| 7759 | rc = -ENODEV; |
| 7760 | goto init_err_disable; |
| 7761 | } |
| 7762 | |
| 7763 | rc = pci_request_regions(pdev, DRV_MODULE_NAME); |
| 7764 | if (rc) { |
| 7765 | dev_err(&pdev->dev, "Cannot obtain PCI resources, aborting\n"); |
| 7766 | goto init_err_disable; |
| 7767 | } |
| 7768 | |
| 7769 | if (dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64)) != 0 && |
| 7770 | dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32)) != 0) { |
| 7771 | dev_err(&pdev->dev, "System does not support DMA, aborting\n"); |
| 7772 | goto init_err_disable; |
| 7773 | } |
| 7774 | |
| 7775 | pci_set_master(pdev); |
| 7776 | |
| 7777 | bp->dev = dev; |
| 7778 | bp->pdev = pdev; |
| 7779 | |
| 7780 | bp->bar0 = pci_ioremap_bar(pdev, 0); |
| 7781 | if (!bp->bar0) { |
| 7782 | dev_err(&pdev->dev, "Cannot map device registers, aborting\n"); |
| 7783 | rc = -ENOMEM; |
| 7784 | goto init_err_release; |
| 7785 | } |
| 7786 | |
| 7787 | bp->bar1 = pci_ioremap_bar(pdev, 2); |
| 7788 | if (!bp->bar1) { |
| 7789 | dev_err(&pdev->dev, "Cannot map doorbell registers, aborting\n"); |
| 7790 | rc = -ENOMEM; |
| 7791 | goto init_err_release; |
| 7792 | } |
| 7793 | |
| 7794 | bp->bar2 = pci_ioremap_bar(pdev, 4); |
| 7795 | if (!bp->bar2) { |
| 7796 | dev_err(&pdev->dev, "Cannot map bar4 registers, aborting\n"); |
| 7797 | rc = -ENOMEM; |
| 7798 | goto init_err_release; |
| 7799 | } |
| 7800 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 7801 | pci_enable_pcie_error_reporting(pdev); |
| 7802 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7803 | INIT_WORK(&bp->sp_task, bnxt_sp_task); |
| 7804 | |
| 7805 | spin_lock_init(&bp->ntp_fltr_lock); |
| 7806 | |
| 7807 | bp->rx_ring_size = BNXT_DEFAULT_RX_RING_SIZE; |
| 7808 | bp->tx_ring_size = BNXT_DEFAULT_TX_RING_SIZE; |
| 7809 | |
Michael Chan | 18775aa | 2017-10-26 11:51:27 -0400 | [diff] [blame] | 7810 | bnxt_init_dflt_coal(bp); |
Michael Chan | 51f3078 | 2016-07-01 18:46:29 -0400 | [diff] [blame] | 7811 | |
Kees Cook | e99e88a | 2017-10-16 14:43:17 -0700 | [diff] [blame] | 7812 | timer_setup(&bp->timer, bnxt_timer, 0); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7813 | bp->current_interval = BNXT_TIMER_INTERVAL; |
| 7814 | |
Michael Chan | caefe52 | 2015-12-09 19:35:42 -0500 | [diff] [blame] | 7815 | clear_bit(BNXT_STATE_OPEN, &bp->state); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7816 | return 0; |
| 7817 | |
| 7818 | init_err_release: |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 7819 | bnxt_unmap_bars(bp, pdev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7820 | pci_release_regions(pdev); |
| 7821 | |
| 7822 | init_err_disable: |
| 7823 | pci_disable_device(pdev); |
| 7824 | |
| 7825 | init_err: |
| 7826 | return rc; |
| 7827 | } |
| 7828 | |
| 7829 | /* rtnl_lock held */ |
| 7830 | static int bnxt_change_mac_addr(struct net_device *dev, void *p) |
| 7831 | { |
| 7832 | struct sockaddr *addr = p; |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 7833 | struct bnxt *bp = netdev_priv(dev); |
| 7834 | int rc = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7835 | |
| 7836 | if (!is_valid_ether_addr(addr->sa_data)) |
| 7837 | return -EADDRNOTAVAIL; |
| 7838 | |
Michael Chan | c1a7bdf | 2017-10-26 11:51:24 -0400 | [diff] [blame] | 7839 | if (ether_addr_equal(addr->sa_data, dev->dev_addr)) |
| 7840 | return 0; |
| 7841 | |
Michael Chan | 84c33dd | 2016-04-11 04:11:13 -0400 | [diff] [blame] | 7842 | rc = bnxt_approve_mac(bp, addr->sa_data); |
| 7843 | if (rc) |
| 7844 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7845 | |
Jeffrey Huang | 1fc2cfd | 2015-12-02 01:54:06 -0500 | [diff] [blame] | 7846 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 7847 | if (netif_running(dev)) { |
| 7848 | bnxt_close_nic(bp, false, false); |
| 7849 | rc = bnxt_open_nic(bp, false, false); |
| 7850 | } |
| 7851 | |
| 7852 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7853 | } |
| 7854 | |
| 7855 | /* rtnl_lock held */ |
| 7856 | static int bnxt_change_mtu(struct net_device *dev, int new_mtu) |
| 7857 | { |
| 7858 | struct bnxt *bp = netdev_priv(dev); |
| 7859 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7860 | if (netif_running(dev)) |
| 7861 | bnxt_close_nic(bp, false, false); |
| 7862 | |
| 7863 | dev->mtu = new_mtu; |
| 7864 | bnxt_set_ring_params(bp); |
| 7865 | |
| 7866 | if (netif_running(dev)) |
| 7867 | return bnxt_open_nic(bp, false, false); |
| 7868 | |
| 7869 | return 0; |
| 7870 | } |
| 7871 | |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 7872 | int bnxt_setup_mq_tc(struct net_device *dev, u8 tc) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7873 | { |
| 7874 | struct bnxt *bp = netdev_priv(dev); |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 7875 | bool sh = false; |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7876 | int rc; |
John Fastabend | 16e5cc6 | 2016-02-16 21:16:43 -0800 | [diff] [blame] | 7877 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7878 | if (tc > bp->max_tc) { |
Michael Chan | b451c8b | 2017-02-12 19:18:17 -0500 | [diff] [blame] | 7879 | 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] | 7880 | tc, bp->max_tc); |
| 7881 | return -EINVAL; |
| 7882 | } |
| 7883 | |
| 7884 | if (netdev_get_num_tc(dev) == tc) |
| 7885 | return 0; |
| 7886 | |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 7887 | if (bp->flags & BNXT_FLAG_SHARED_RINGS) |
| 7888 | sh = true; |
| 7889 | |
Michael Chan | 98fdbe7 | 2017-08-28 13:40:26 -0400 | [diff] [blame] | 7890 | rc = bnxt_check_rings(bp, bp->tx_nr_rings_per_tc, bp->rx_nr_rings, |
| 7891 | sh, tc, bp->tx_nr_rings_xdp); |
Michael Chan | d1e7925 | 2017-02-06 16:55:38 -0500 | [diff] [blame] | 7892 | if (rc) |
| 7893 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7894 | |
| 7895 | /* Needs to close the device and do hw resource re-allocations */ |
| 7896 | if (netif_running(bp->dev)) |
| 7897 | bnxt_close_nic(bp, true, false); |
| 7898 | |
| 7899 | if (tc) { |
| 7900 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc * tc; |
| 7901 | netdev_set_num_tc(dev, tc); |
| 7902 | } else { |
| 7903 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 7904 | netdev_reset_tc(dev); |
| 7905 | } |
Michael Chan | 87e9b37 | 2017-08-23 19:34:03 -0400 | [diff] [blame] | 7906 | bp->tx_nr_rings += bp->tx_nr_rings_xdp; |
Michael Chan | 3ffb6a3 | 2016-11-11 00:11:42 -0500 | [diff] [blame] | 7907 | bp->cp_nr_rings = sh ? max_t(int, bp->tx_nr_rings, bp->rx_nr_rings) : |
| 7908 | bp->tx_nr_rings + bp->rx_nr_rings; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7909 | bp->num_stat_ctxs = bp->cp_nr_rings; |
| 7910 | |
| 7911 | if (netif_running(bp->dev)) |
| 7912 | return bnxt_open_nic(bp, true, false); |
| 7913 | |
| 7914 | return 0; |
| 7915 | } |
| 7916 | |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 7917 | static int bnxt_setup_tc_block_cb(enum tc_setup_type type, void *type_data, |
| 7918 | void *cb_priv) |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7919 | { |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 7920 | struct bnxt *bp = cb_priv; |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7921 | |
Jakub Kicinski | 312324f | 2018-01-25 14:00:48 -0800 | [diff] [blame] | 7922 | if (!bnxt_tc_flower_enabled(bp) || |
| 7923 | !tc_cls_can_offload_and_chain0(bp->dev, type_data)) |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7924 | return -EOPNOTSUPP; |
| 7925 | |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 7926 | switch (type) { |
| 7927 | case TC_SETUP_CLSFLOWER: |
| 7928 | return bnxt_tc_setup_flower(bp, bp->pf.fw_fid, type_data); |
| 7929 | default: |
| 7930 | return -EOPNOTSUPP; |
| 7931 | } |
| 7932 | } |
| 7933 | |
| 7934 | static int bnxt_setup_tc_block(struct net_device *dev, |
| 7935 | struct tc_block_offload *f) |
| 7936 | { |
| 7937 | struct bnxt *bp = netdev_priv(dev); |
| 7938 | |
| 7939 | if (f->binder_type != TCF_BLOCK_BINDER_TYPE_CLSACT_INGRESS) |
| 7940 | return -EOPNOTSUPP; |
| 7941 | |
| 7942 | switch (f->command) { |
| 7943 | case TC_BLOCK_BIND: |
| 7944 | return tcf_block_cb_register(f->block, bnxt_setup_tc_block_cb, |
| 7945 | bp, bp); |
| 7946 | case TC_BLOCK_UNBIND: |
| 7947 | tcf_block_cb_unregister(f->block, bnxt_setup_tc_block_cb, bp); |
| 7948 | return 0; |
| 7949 | default: |
| 7950 | return -EOPNOTSUPP; |
| 7951 | } |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7952 | } |
| 7953 | |
Jiri Pirko | 2572ac5 | 2017-08-07 10:15:17 +0200 | [diff] [blame] | 7954 | 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] | 7955 | void *type_data) |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 7956 | { |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7957 | switch (type) { |
Jiri Pirko | 9e0fd15 | 2017-10-19 15:50:39 +0200 | [diff] [blame] | 7958 | case TC_SETUP_BLOCK: |
| 7959 | return bnxt_setup_tc_block(dev, type_data); |
Nogah Frankel | 575ed7d | 2017-11-06 07:23:42 +0100 | [diff] [blame] | 7960 | case TC_SETUP_QDISC_MQPRIO: { |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7961 | struct tc_mqprio_qopt *mqprio = type_data; |
Jiri Pirko | de4784c | 2017-08-07 10:15:32 +0200 | [diff] [blame] | 7962 | |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7963 | mqprio->hw = TC_MQPRIO_HW_OFFLOAD_TCS; |
| 7964 | |
| 7965 | return bnxt_setup_mq_tc(dev, mqprio->num_tc); |
| 7966 | } |
| 7967 | default: |
Jiri Pirko | 38cf042 | 2017-08-07 10:15:31 +0200 | [diff] [blame] | 7968 | return -EOPNOTSUPP; |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 7969 | } |
Michael Chan | c5e3deb | 2016-12-02 21:17:15 -0500 | [diff] [blame] | 7970 | } |
| 7971 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7972 | #ifdef CONFIG_RFS_ACCEL |
| 7973 | static bool bnxt_fltr_match(struct bnxt_ntuple_filter *f1, |
| 7974 | struct bnxt_ntuple_filter *f2) |
| 7975 | { |
| 7976 | struct flow_keys *keys1 = &f1->fkeys; |
| 7977 | struct flow_keys *keys2 = &f2->fkeys; |
| 7978 | |
| 7979 | if (keys1->addrs.v4addrs.src == keys2->addrs.v4addrs.src && |
| 7980 | keys1->addrs.v4addrs.dst == keys2->addrs.v4addrs.dst && |
| 7981 | keys1->ports.ports == keys2->ports.ports && |
| 7982 | keys1->basic.ip_proto == keys2->basic.ip_proto && |
| 7983 | keys1->basic.n_proto == keys2->basic.n_proto && |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 7984 | keys1->control.flags == keys2->control.flags && |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 7985 | ether_addr_equal(f1->src_mac_addr, f2->src_mac_addr) && |
| 7986 | ether_addr_equal(f1->dst_mac_addr, f2->dst_mac_addr)) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 7987 | return true; |
| 7988 | |
| 7989 | return false; |
| 7990 | } |
| 7991 | |
| 7992 | static int bnxt_rx_flow_steer(struct net_device *dev, const struct sk_buff *skb, |
| 7993 | u16 rxq_index, u32 flow_id) |
| 7994 | { |
| 7995 | struct bnxt *bp = netdev_priv(dev); |
| 7996 | struct bnxt_ntuple_filter *fltr, *new_fltr; |
| 7997 | struct flow_keys *fkeys; |
| 7998 | struct ethhdr *eth = (struct ethhdr *)skb_mac_header(skb); |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 7999 | int rc = 0, idx, bit_id, l2_idx = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8000 | struct hlist_head *head; |
| 8001 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 8002 | if (!ether_addr_equal(dev->dev_addr, eth->h_dest)) { |
| 8003 | struct bnxt_vnic_info *vnic = &bp->vnic_info[0]; |
| 8004 | int off = 0, j; |
| 8005 | |
| 8006 | netif_addr_lock_bh(dev); |
| 8007 | for (j = 0; j < vnic->uc_filter_count; j++, off += ETH_ALEN) { |
| 8008 | if (ether_addr_equal(eth->h_dest, |
| 8009 | vnic->uc_list + off)) { |
| 8010 | l2_idx = j + 1; |
| 8011 | break; |
| 8012 | } |
| 8013 | } |
| 8014 | netif_addr_unlock_bh(dev); |
| 8015 | if (!l2_idx) |
| 8016 | return -EINVAL; |
| 8017 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8018 | new_fltr = kzalloc(sizeof(*new_fltr), GFP_ATOMIC); |
| 8019 | if (!new_fltr) |
| 8020 | return -ENOMEM; |
| 8021 | |
| 8022 | fkeys = &new_fltr->fkeys; |
| 8023 | if (!skb_flow_dissect_flow_keys(skb, fkeys, 0)) { |
| 8024 | rc = -EPROTONOSUPPORT; |
| 8025 | goto err_free; |
| 8026 | } |
| 8027 | |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 8028 | if ((fkeys->basic.n_proto != htons(ETH_P_IP) && |
| 8029 | fkeys->basic.n_proto != htons(ETH_P_IPV6)) || |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8030 | ((fkeys->basic.ip_proto != IPPROTO_TCP) && |
| 8031 | (fkeys->basic.ip_proto != IPPROTO_UDP))) { |
| 8032 | rc = -EPROTONOSUPPORT; |
| 8033 | goto err_free; |
| 8034 | } |
Michael Chan | dda0e74 | 2016-12-29 12:13:40 -0500 | [diff] [blame] | 8035 | if (fkeys->basic.n_proto == htons(ETH_P_IPV6) && |
| 8036 | bp->hwrm_spec_code < 0x10601) { |
| 8037 | rc = -EPROTONOSUPPORT; |
| 8038 | goto err_free; |
| 8039 | } |
Michael Chan | 61aad72 | 2017-02-12 19:18:14 -0500 | [diff] [blame] | 8040 | if ((fkeys->control.flags & FLOW_DIS_ENCAPSULATION) && |
| 8041 | bp->hwrm_spec_code < 0x10601) { |
| 8042 | rc = -EPROTONOSUPPORT; |
| 8043 | goto err_free; |
| 8044 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8045 | |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 8046 | memcpy(new_fltr->dst_mac_addr, eth->h_dest, ETH_ALEN); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8047 | memcpy(new_fltr->src_mac_addr, eth->h_source, ETH_ALEN); |
| 8048 | |
| 8049 | idx = skb_get_hash_raw(skb) & BNXT_NTP_FLTR_HASH_MASK; |
| 8050 | head = &bp->ntp_fltr_hash_tbl[idx]; |
| 8051 | rcu_read_lock(); |
| 8052 | hlist_for_each_entry_rcu(fltr, head, hash) { |
| 8053 | if (bnxt_fltr_match(fltr, new_fltr)) { |
| 8054 | rcu_read_unlock(); |
| 8055 | rc = 0; |
| 8056 | goto err_free; |
| 8057 | } |
| 8058 | } |
| 8059 | rcu_read_unlock(); |
| 8060 | |
| 8061 | spin_lock_bh(&bp->ntp_fltr_lock); |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 8062 | bit_id = bitmap_find_free_region(bp->ntp_fltr_bmap, |
| 8063 | BNXT_NTP_FLTR_MAX_FLTR, 0); |
| 8064 | if (bit_id < 0) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8065 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 8066 | rc = -ENOMEM; |
| 8067 | goto err_free; |
| 8068 | } |
| 8069 | |
Michael Chan | 84e86b9 | 2015-11-05 16:25:50 -0500 | [diff] [blame] | 8070 | new_fltr->sw_id = (u16)bit_id; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8071 | new_fltr->flow_id = flow_id; |
Michael Chan | a54c4d7 | 2016-07-25 12:33:35 -0400 | [diff] [blame] | 8072 | new_fltr->l2_fltr_idx = l2_idx; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8073 | new_fltr->rxq = rxq_index; |
| 8074 | hlist_add_head_rcu(&new_fltr->hash, head); |
| 8075 | bp->ntp_fltr_count++; |
| 8076 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 8077 | |
| 8078 | set_bit(BNXT_RX_NTP_FLTR_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8079 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8080 | |
| 8081 | return new_fltr->sw_id; |
| 8082 | |
| 8083 | err_free: |
| 8084 | kfree(new_fltr); |
| 8085 | return rc; |
| 8086 | } |
| 8087 | |
| 8088 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 8089 | { |
| 8090 | int i; |
| 8091 | |
| 8092 | for (i = 0; i < BNXT_NTP_FLTR_HASH_SIZE; i++) { |
| 8093 | struct hlist_head *head; |
| 8094 | struct hlist_node *tmp; |
| 8095 | struct bnxt_ntuple_filter *fltr; |
| 8096 | int rc; |
| 8097 | |
| 8098 | head = &bp->ntp_fltr_hash_tbl[i]; |
| 8099 | hlist_for_each_entry_safe(fltr, tmp, head, hash) { |
| 8100 | bool del = false; |
| 8101 | |
| 8102 | if (test_bit(BNXT_FLTR_VALID, &fltr->state)) { |
| 8103 | if (rps_may_expire_flow(bp->dev, fltr->rxq, |
| 8104 | fltr->flow_id, |
| 8105 | fltr->sw_id)) { |
| 8106 | bnxt_hwrm_cfa_ntuple_filter_free(bp, |
| 8107 | fltr); |
| 8108 | del = true; |
| 8109 | } |
| 8110 | } else { |
| 8111 | rc = bnxt_hwrm_cfa_ntuple_filter_alloc(bp, |
| 8112 | fltr); |
| 8113 | if (rc) |
| 8114 | del = true; |
| 8115 | else |
| 8116 | set_bit(BNXT_FLTR_VALID, &fltr->state); |
| 8117 | } |
| 8118 | |
| 8119 | if (del) { |
| 8120 | spin_lock_bh(&bp->ntp_fltr_lock); |
| 8121 | hlist_del_rcu(&fltr->hash); |
| 8122 | bp->ntp_fltr_count--; |
| 8123 | spin_unlock_bh(&bp->ntp_fltr_lock); |
| 8124 | synchronize_rcu(); |
| 8125 | clear_bit(fltr->sw_id, bp->ntp_fltr_bmap); |
| 8126 | kfree(fltr); |
| 8127 | } |
| 8128 | } |
| 8129 | } |
Jeffrey Huang | 1924136 | 2016-02-26 04:00:00 -0500 | [diff] [blame] | 8130 | if (test_and_clear_bit(BNXT_HWRM_PF_UNLOAD_SP_EVENT, &bp->sp_event)) |
| 8131 | netdev_info(bp->dev, "Receive PF driver unload event!"); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8132 | } |
| 8133 | |
| 8134 | #else |
| 8135 | |
| 8136 | static void bnxt_cfg_ntp_filters(struct bnxt *bp) |
| 8137 | { |
| 8138 | } |
| 8139 | |
| 8140 | #endif /* CONFIG_RFS_ACCEL */ |
| 8141 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8142 | static void bnxt_udp_tunnel_add(struct net_device *dev, |
| 8143 | struct udp_tunnel_info *ti) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8144 | { |
| 8145 | struct bnxt *bp = netdev_priv(dev); |
| 8146 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8147 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 8148 | return; |
| 8149 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8150 | if (!netif_running(dev)) |
| 8151 | return; |
| 8152 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8153 | switch (ti->type) { |
| 8154 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8155 | if (bp->vxlan_port_cnt && bp->vxlan_port != ti->port) |
| 8156 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8157 | |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8158 | bp->vxlan_port_cnt++; |
| 8159 | if (bp->vxlan_port_cnt == 1) { |
| 8160 | bp->vxlan_port = ti->port; |
| 8161 | set_bit(BNXT_VXLAN_ADD_PORT_SP_EVENT, &bp->sp_event); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8162 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8163 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8164 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 8165 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8166 | if (bp->nge_port_cnt && bp->nge_port != ti->port) |
| 8167 | return; |
| 8168 | |
| 8169 | bp->nge_port_cnt++; |
| 8170 | if (bp->nge_port_cnt == 1) { |
| 8171 | bp->nge_port = ti->port; |
| 8172 | set_bit(BNXT_GENEVE_ADD_PORT_SP_EVENT, &bp->sp_event); |
| 8173 | } |
| 8174 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8175 | default: |
| 8176 | return; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8177 | } |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8178 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8179 | bnxt_queue_sp_work(bp); |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8180 | } |
| 8181 | |
| 8182 | static void bnxt_udp_tunnel_del(struct net_device *dev, |
| 8183 | struct udp_tunnel_info *ti) |
| 8184 | { |
| 8185 | struct bnxt *bp = netdev_priv(dev); |
| 8186 | |
| 8187 | if (ti->sa_family != AF_INET6 && ti->sa_family != AF_INET) |
| 8188 | return; |
| 8189 | |
| 8190 | if (!netif_running(dev)) |
| 8191 | return; |
| 8192 | |
| 8193 | switch (ti->type) { |
| 8194 | case UDP_TUNNEL_TYPE_VXLAN: |
| 8195 | if (!bp->vxlan_port_cnt || bp->vxlan_port != ti->port) |
| 8196 | return; |
| 8197 | bp->vxlan_port_cnt--; |
| 8198 | |
| 8199 | if (bp->vxlan_port_cnt != 0) |
| 8200 | return; |
| 8201 | |
| 8202 | set_bit(BNXT_VXLAN_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 8203 | break; |
Alexander Duyck | 7cdd5fc | 2016-06-16 12:21:36 -0700 | [diff] [blame] | 8204 | case UDP_TUNNEL_TYPE_GENEVE: |
| 8205 | if (!bp->nge_port_cnt || bp->nge_port != ti->port) |
| 8206 | return; |
| 8207 | bp->nge_port_cnt--; |
| 8208 | |
| 8209 | if (bp->nge_port_cnt != 0) |
| 8210 | return; |
| 8211 | |
| 8212 | set_bit(BNXT_GENEVE_DEL_PORT_SP_EVENT, &bp->sp_event); |
| 8213 | break; |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8214 | default: |
| 8215 | return; |
| 8216 | } |
| 8217 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8218 | bnxt_queue_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8219 | } |
| 8220 | |
Michael Chan | 39d8ba2 | 2017-07-24 12:34:22 -0400 | [diff] [blame] | 8221 | static int bnxt_bridge_getlink(struct sk_buff *skb, u32 pid, u32 seq, |
| 8222 | struct net_device *dev, u32 filter_mask, |
| 8223 | int nlflags) |
| 8224 | { |
| 8225 | struct bnxt *bp = netdev_priv(dev); |
| 8226 | |
| 8227 | return ndo_dflt_bridge_getlink(skb, pid, seq, dev, bp->br_mode, 0, 0, |
| 8228 | nlflags, filter_mask, NULL); |
| 8229 | } |
| 8230 | |
| 8231 | static int bnxt_bridge_setlink(struct net_device *dev, struct nlmsghdr *nlh, |
| 8232 | u16 flags) |
| 8233 | { |
| 8234 | struct bnxt *bp = netdev_priv(dev); |
| 8235 | struct nlattr *attr, *br_spec; |
| 8236 | int rem, rc = 0; |
| 8237 | |
| 8238 | if (bp->hwrm_spec_code < 0x10708 || !BNXT_SINGLE_PF(bp)) |
| 8239 | return -EOPNOTSUPP; |
| 8240 | |
| 8241 | br_spec = nlmsg_find_attr(nlh, sizeof(struct ifinfomsg), IFLA_AF_SPEC); |
| 8242 | if (!br_spec) |
| 8243 | return -EINVAL; |
| 8244 | |
| 8245 | nla_for_each_nested(attr, br_spec, rem) { |
| 8246 | u16 mode; |
| 8247 | |
| 8248 | if (nla_type(attr) != IFLA_BRIDGE_MODE) |
| 8249 | continue; |
| 8250 | |
| 8251 | if (nla_len(attr) < sizeof(mode)) |
| 8252 | return -EINVAL; |
| 8253 | |
| 8254 | mode = nla_get_u16(attr); |
| 8255 | if (mode == bp->br_mode) |
| 8256 | break; |
| 8257 | |
| 8258 | rc = bnxt_hwrm_set_br_mode(bp, mode); |
| 8259 | if (!rc) |
| 8260 | bp->br_mode = mode; |
| 8261 | break; |
| 8262 | } |
| 8263 | return rc; |
| 8264 | } |
| 8265 | |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 8266 | static int bnxt_get_phys_port_name(struct net_device *dev, char *buf, |
| 8267 | size_t len) |
| 8268 | { |
| 8269 | struct bnxt *bp = netdev_priv(dev); |
| 8270 | int rc; |
| 8271 | |
| 8272 | /* The PF and it's VF-reps only support the switchdev framework */ |
| 8273 | if (!BNXT_PF(bp)) |
| 8274 | return -EOPNOTSUPP; |
| 8275 | |
Sathya Perla | 53f70b8 | 2017-07-25 13:28:41 -0400 | [diff] [blame] | 8276 | rc = snprintf(buf, len, "p%d", bp->pf.port_id); |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 8277 | |
| 8278 | if (rc >= len) |
| 8279 | return -EOPNOTSUPP; |
| 8280 | return 0; |
| 8281 | } |
| 8282 | |
| 8283 | int bnxt_port_attr_get(struct bnxt *bp, struct switchdev_attr *attr) |
| 8284 | { |
| 8285 | if (bp->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV) |
| 8286 | return -EOPNOTSUPP; |
| 8287 | |
| 8288 | /* The PF and it's VF-reps only support the switchdev framework */ |
| 8289 | if (!BNXT_PF(bp)) |
| 8290 | return -EOPNOTSUPP; |
| 8291 | |
| 8292 | switch (attr->id) { |
| 8293 | case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: |
Sathya Perla | dd4ea1d | 2018-01-17 03:21:16 -0500 | [diff] [blame] | 8294 | attr->u.ppid.id_len = sizeof(bp->switch_id); |
| 8295 | 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] | 8296 | break; |
| 8297 | default: |
| 8298 | return -EOPNOTSUPP; |
| 8299 | } |
| 8300 | return 0; |
| 8301 | } |
| 8302 | |
| 8303 | static int bnxt_swdev_port_attr_get(struct net_device *dev, |
| 8304 | struct switchdev_attr *attr) |
| 8305 | { |
| 8306 | return bnxt_port_attr_get(netdev_priv(dev), attr); |
| 8307 | } |
| 8308 | |
| 8309 | static const struct switchdev_ops bnxt_switchdev_ops = { |
| 8310 | .switchdev_port_attr_get = bnxt_swdev_port_attr_get |
| 8311 | }; |
| 8312 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8313 | static const struct net_device_ops bnxt_netdev_ops = { |
| 8314 | .ndo_open = bnxt_open, |
| 8315 | .ndo_start_xmit = bnxt_start_xmit, |
| 8316 | .ndo_stop = bnxt_close, |
| 8317 | .ndo_get_stats64 = bnxt_get_stats64, |
| 8318 | .ndo_set_rx_mode = bnxt_set_rx_mode, |
| 8319 | .ndo_do_ioctl = bnxt_ioctl, |
| 8320 | .ndo_validate_addr = eth_validate_addr, |
| 8321 | .ndo_set_mac_address = bnxt_change_mac_addr, |
| 8322 | .ndo_change_mtu = bnxt_change_mtu, |
| 8323 | .ndo_fix_features = bnxt_fix_features, |
| 8324 | .ndo_set_features = bnxt_set_features, |
| 8325 | .ndo_tx_timeout = bnxt_tx_timeout, |
| 8326 | #ifdef CONFIG_BNXT_SRIOV |
| 8327 | .ndo_get_vf_config = bnxt_get_vf_config, |
| 8328 | .ndo_set_vf_mac = bnxt_set_vf_mac, |
| 8329 | .ndo_set_vf_vlan = bnxt_set_vf_vlan, |
| 8330 | .ndo_set_vf_rate = bnxt_set_vf_bw, |
| 8331 | .ndo_set_vf_link_state = bnxt_set_vf_link_state, |
| 8332 | .ndo_set_vf_spoofchk = bnxt_set_vf_spoofchk, |
Vasundhara Volam | 746df13 | 2018-03-31 13:54:10 -0400 | [diff] [blame] | 8333 | .ndo_set_vf_trust = bnxt_set_vf_trust, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8334 | #endif |
| 8335 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8336 | .ndo_poll_controller = bnxt_poll_controller, |
| 8337 | #endif |
| 8338 | .ndo_setup_tc = bnxt_setup_tc, |
| 8339 | #ifdef CONFIG_RFS_ACCEL |
| 8340 | .ndo_rx_flow_steer = bnxt_rx_flow_steer, |
| 8341 | #endif |
Alexander Duyck | ad51b8e | 2016-06-16 12:21:19 -0700 | [diff] [blame] | 8342 | .ndo_udp_tunnel_add = bnxt_udp_tunnel_add, |
| 8343 | .ndo_udp_tunnel_del = bnxt_udp_tunnel_del, |
Jakub Kicinski | f4e6352 | 2017-11-03 13:56:16 -0700 | [diff] [blame] | 8344 | .ndo_bpf = bnxt_xdp, |
Michael Chan | 39d8ba2 | 2017-07-24 12:34:22 -0400 | [diff] [blame] | 8345 | .ndo_bridge_getlink = bnxt_bridge_getlink, |
| 8346 | .ndo_bridge_setlink = bnxt_bridge_setlink, |
Sathya Perla | c124a62 | 2017-07-24 12:34:29 -0400 | [diff] [blame] | 8347 | .ndo_get_phys_port_name = bnxt_get_phys_port_name |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8348 | }; |
| 8349 | |
| 8350 | static void bnxt_remove_one(struct pci_dev *pdev) |
| 8351 | { |
| 8352 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8353 | struct bnxt *bp = netdev_priv(dev); |
| 8354 | |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 8355 | if (BNXT_PF(bp)) { |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8356 | bnxt_sriov_disable(bp); |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 8357 | bnxt_dl_unregister(bp); |
| 8358 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8359 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 8360 | pci_disable_pcie_error_reporting(pdev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8361 | unregister_netdev(dev); |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8362 | bnxt_shutdown_tc(bp); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8363 | bnxt_cancel_sp_work(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8364 | bp->sp_event = 0; |
| 8365 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 8366 | bnxt_clear_int_mode(bp); |
Jeffrey Huang | be58a0d | 2015-12-27 18:19:18 -0500 | [diff] [blame] | 8367 | bnxt_hwrm_func_drv_unrgtr(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8368 | bnxt_free_hwrm_resources(bp); |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 8369 | bnxt_free_hwrm_short_cmd_req(bp); |
Michael Chan | eb51365 | 2017-04-04 18:14:12 -0400 | [diff] [blame] | 8370 | bnxt_ethtool_free(bp); |
Michael Chan | 7df4ae9 | 2016-12-02 21:17:17 -0500 | [diff] [blame] | 8371 | bnxt_dcb_free(bp); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 8372 | kfree(bp->edev); |
| 8373 | bp->edev = NULL; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8374 | bnxt_cleanup_pci(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8375 | free_netdev(dev); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8376 | } |
| 8377 | |
| 8378 | static int bnxt_probe_phy(struct bnxt *bp) |
| 8379 | { |
| 8380 | int rc = 0; |
| 8381 | struct bnxt_link_info *link_info = &bp->link_info; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8382 | |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 8383 | rc = bnxt_hwrm_phy_qcaps(bp); |
| 8384 | if (rc) { |
| 8385 | netdev_err(bp->dev, "Probe phy can't get phy capabilities (rc: %x)\n", |
| 8386 | rc); |
| 8387 | return rc; |
| 8388 | } |
Michael Chan | e2dc9b6 | 2017-10-13 21:09:30 -0400 | [diff] [blame] | 8389 | mutex_init(&bp->link_lock); |
Michael Chan | 170ce01 | 2016-04-05 14:08:57 -0400 | [diff] [blame] | 8390 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8391 | rc = bnxt_update_link(bp, false); |
| 8392 | if (rc) { |
| 8393 | netdev_err(bp->dev, "Probe phy can't update link (rc: %x)\n", |
| 8394 | rc); |
| 8395 | return rc; |
| 8396 | } |
| 8397 | |
Michael Chan | 93ed811 | 2016-06-13 02:25:37 -0400 | [diff] [blame] | 8398 | /* Older firmware does not have supported_auto_speeds, so assume |
| 8399 | * that all supported speeds can be autonegotiated. |
| 8400 | */ |
| 8401 | if (link_info->auto_link_speeds && !link_info->support_auto_speeds) |
| 8402 | link_info->support_auto_speeds = link_info->support_speeds; |
| 8403 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8404 | /*initialize the ethool setting copy with NVM settings */ |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 8405 | if (BNXT_AUTO_MODE(link_info->auto_mode)) { |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 8406 | link_info->autoneg = BNXT_AUTONEG_SPEED; |
| 8407 | if (bp->hwrm_spec_code >= 0x10201) { |
| 8408 | if (link_info->auto_pause_setting & |
| 8409 | PORT_PHY_CFG_REQ_AUTO_PAUSE_AUTONEG_PAUSE) |
| 8410 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 8411 | } else { |
| 8412 | link_info->autoneg |= BNXT_AUTONEG_FLOW_CTRL; |
| 8413 | } |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 8414 | link_info->advertising = link_info->auto_link_speeds; |
Michael Chan | 0d8abf0 | 2016-02-10 17:33:47 -0500 | [diff] [blame] | 8415 | } else { |
| 8416 | link_info->req_link_speed = link_info->force_link_speed; |
| 8417 | link_info->req_duplex = link_info->duplex_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8418 | } |
Michael Chan | c9ee951 | 2016-04-05 14:08:56 -0400 | [diff] [blame] | 8419 | if (link_info->autoneg & BNXT_AUTONEG_FLOW_CTRL) |
| 8420 | link_info->req_flow_ctrl = |
| 8421 | link_info->auto_pause_setting & BNXT_LINK_PAUSE_BOTH; |
| 8422 | else |
| 8423 | link_info->req_flow_ctrl = link_info->force_pause_setting; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8424 | return rc; |
| 8425 | } |
| 8426 | |
| 8427 | static int bnxt_get_max_irq(struct pci_dev *pdev) |
| 8428 | { |
| 8429 | u16 ctrl; |
| 8430 | |
| 8431 | if (!pdev->msix_cap) |
| 8432 | return 1; |
| 8433 | |
| 8434 | pci_read_config_word(pdev, pdev->msix_cap + PCI_MSIX_FLAGS, &ctrl); |
| 8435 | return (ctrl & PCI_MSIX_FLAGS_QSIZE) + 1; |
| 8436 | } |
| 8437 | |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8438 | static void _bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 8439 | int *max_cp) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8440 | { |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 8441 | struct bnxt_hw_resc *hw_resc = &bp->hw_resc; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8442 | int max_ring_grps = 0; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8443 | |
Michael Chan | 6a4f294 | 2018-01-17 03:21:06 -0500 | [diff] [blame] | 8444 | *max_tx = hw_resc->max_tx_rings; |
| 8445 | *max_rx = hw_resc->max_rx_rings; |
| 8446 | *max_cp = min_t(int, hw_resc->max_irqs, hw_resc->max_cp_rings); |
| 8447 | *max_cp = min_t(int, *max_cp, hw_resc->max_stat_ctxs); |
| 8448 | max_ring_grps = hw_resc->max_hw_ring_grps; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 8449 | if (BNXT_CHIP_TYPE_NITRO_A0(bp) && BNXT_PF(bp)) { |
| 8450 | *max_cp -= 1; |
| 8451 | *max_rx -= 2; |
| 8452 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8453 | if (bp->flags & BNXT_FLAG_AGG_RINGS) |
| 8454 | *max_rx >>= 1; |
Michael Chan | b72d4a6 | 2015-12-27 18:19:27 -0500 | [diff] [blame] | 8455 | *max_rx = min_t(int, *max_rx, max_ring_grps); |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8456 | } |
| 8457 | |
| 8458 | int bnxt_get_max_rings(struct bnxt *bp, int *max_rx, int *max_tx, bool shared) |
| 8459 | { |
| 8460 | int rx, tx, cp; |
| 8461 | |
| 8462 | _bnxt_get_max_rings(bp, &rx, &tx, &cp); |
| 8463 | if (!rx || !tx || !cp) |
| 8464 | return -ENOMEM; |
| 8465 | |
| 8466 | *max_rx = rx; |
| 8467 | *max_tx = tx; |
| 8468 | return bnxt_trim_rings(bp, max_rx, max_tx, cp, shared); |
| 8469 | } |
| 8470 | |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 8471 | static int bnxt_get_dflt_rings(struct bnxt *bp, int *max_rx, int *max_tx, |
| 8472 | bool shared) |
| 8473 | { |
| 8474 | int rc; |
| 8475 | |
| 8476 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 8477 | if (rc && (bp->flags & BNXT_FLAG_AGG_RINGS)) { |
| 8478 | /* Not enough rings, try disabling agg rings. */ |
| 8479 | bp->flags &= ~BNXT_FLAG_AGG_RINGS; |
| 8480 | rc = bnxt_get_max_rings(bp, max_rx, max_tx, shared); |
| 8481 | if (rc) |
| 8482 | return rc; |
| 8483 | bp->flags |= BNXT_FLAG_NO_AGG_RINGS; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 8484 | bp->dev->hw_features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); |
| 8485 | bp->dev->features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 8486 | bnxt_set_ring_params(bp); |
| 8487 | } |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 8488 | |
| 8489 | if (bp->flags & BNXT_FLAG_ROCE_CAP) { |
| 8490 | int max_cp, max_stat, max_irq; |
| 8491 | |
| 8492 | /* Reserve minimum resources for RoCE */ |
| 8493 | max_cp = bnxt_get_max_func_cp_rings(bp); |
| 8494 | max_stat = bnxt_get_max_func_stat_ctxs(bp); |
| 8495 | max_irq = bnxt_get_max_func_irqs(bp); |
| 8496 | if (max_cp <= BNXT_MIN_ROCE_CP_RINGS || |
| 8497 | max_irq <= BNXT_MIN_ROCE_CP_RINGS || |
| 8498 | max_stat <= BNXT_MIN_ROCE_STAT_CTXS) |
| 8499 | return 0; |
| 8500 | |
| 8501 | max_cp -= BNXT_MIN_ROCE_CP_RINGS; |
| 8502 | max_irq -= BNXT_MIN_ROCE_CP_RINGS; |
| 8503 | max_stat -= BNXT_MIN_ROCE_STAT_CTXS; |
| 8504 | max_cp = min_t(int, max_cp, max_irq); |
| 8505 | max_cp = min_t(int, max_cp, max_stat); |
| 8506 | rc = bnxt_trim_rings(bp, max_rx, max_tx, max_cp, shared); |
| 8507 | if (rc) |
| 8508 | rc = 0; |
| 8509 | } |
| 8510 | return rc; |
| 8511 | } |
| 8512 | |
Michael Chan | 58ea801 | 2018-01-17 03:21:08 -0500 | [diff] [blame] | 8513 | /* In initial default shared ring setting, each shared ring must have a |
| 8514 | * RX/TX ring pair. |
| 8515 | */ |
| 8516 | static void bnxt_trim_dflt_sh_rings(struct bnxt *bp) |
| 8517 | { |
| 8518 | bp->cp_nr_rings = min_t(int, bp->tx_nr_rings_per_tc, bp->rx_nr_rings); |
| 8519 | bp->rx_nr_rings = bp->cp_nr_rings; |
| 8520 | bp->tx_nr_rings_per_tc = bp->cp_nr_rings; |
| 8521 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
| 8522 | } |
| 8523 | |
Michael Chan | 702c221 | 2017-05-29 19:06:10 -0400 | [diff] [blame] | 8524 | static int bnxt_set_dflt_rings(struct bnxt *bp, bool sh) |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8525 | { |
| 8526 | int dflt_rings, max_rx_rings, max_tx_rings, rc; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8527 | |
| 8528 | if (sh) |
| 8529 | bp->flags |= BNXT_FLAG_SHARED_RINGS; |
| 8530 | dflt_rings = netif_get_num_default_rss_queues(); |
Michael Chan | 1d3ef13 | 2018-03-31 13:54:07 -0400 | [diff] [blame] | 8531 | /* Reduce default rings on multi-port cards so that total default |
| 8532 | * rings do not exceed CPU count. |
| 8533 | */ |
| 8534 | if (bp->port_count > 1) { |
| 8535 | int max_rings = |
| 8536 | max_t(int, num_online_cpus() / bp->port_count, 1); |
| 8537 | |
| 8538 | dflt_rings = min_t(int, dflt_rings, max_rings); |
| 8539 | } |
Michael Chan | e4060d3 | 2016-12-07 00:26:19 -0500 | [diff] [blame] | 8540 | 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] | 8541 | if (rc) |
| 8542 | return rc; |
| 8543 | bp->rx_nr_rings = min_t(int, dflt_rings, max_rx_rings); |
| 8544 | 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] | 8545 | if (sh) |
| 8546 | bnxt_trim_dflt_sh_rings(bp); |
| 8547 | else |
| 8548 | bp->cp_nr_rings = bp->tx_nr_rings_per_tc + bp->rx_nr_rings; |
| 8549 | bp->tx_nr_rings = bp->tx_nr_rings_per_tc; |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 8550 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 8551 | rc = __bnxt_reserve_rings(bp); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 8552 | if (rc) |
| 8553 | netdev_warn(bp->dev, "Unable to reserve tx rings\n"); |
Michael Chan | 58ea801 | 2018-01-17 03:21:08 -0500 | [diff] [blame] | 8554 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 8555 | if (sh) |
| 8556 | bnxt_trim_dflt_sh_rings(bp); |
Michael Chan | 391be5c | 2016-12-29 12:13:41 -0500 | [diff] [blame] | 8557 | |
Michael Chan | 674f50a | 2018-01-17 03:21:09 -0500 | [diff] [blame] | 8558 | /* Rings may have been trimmed, re-reserve the trimmed rings. */ |
| 8559 | if (bnxt_need_reserve_rings(bp)) { |
| 8560 | rc = __bnxt_reserve_rings(bp); |
| 8561 | if (rc) |
| 8562 | netdev_warn(bp->dev, "2nd rings reservation failed.\n"); |
| 8563 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 8564 | } |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8565 | bp->num_stat_ctxs = bp->cp_nr_rings; |
Prashant Sreedharan | 7659519 | 2016-07-18 07:15:22 -0400 | [diff] [blame] | 8566 | if (BNXT_CHIP_TYPE_NITRO_A0(bp)) { |
| 8567 | bp->rx_nr_rings++; |
| 8568 | bp->cp_nr_rings++; |
| 8569 | } |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8570 | return rc; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8571 | } |
| 8572 | |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 8573 | int bnxt_restore_pf_fw_resources(struct bnxt *bp) |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 8574 | { |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 8575 | int rc; |
| 8576 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 8577 | ASSERT_RTNL(); |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 8578 | if (bnxt_ulp_registered(bp->edev, BNXT_ROCE_ULP)) |
| 8579 | return 0; |
| 8580 | |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 8581 | bnxt_hwrm_func_qcaps(bp); |
Venkat Duvvuru | 1a03778 | 2018-03-09 23:46:09 -0500 | [diff] [blame] | 8582 | |
| 8583 | if (netif_running(bp->dev)) |
| 8584 | __bnxt_close_nic(bp, true, false); |
| 8585 | |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 8586 | bnxt_clear_int_mode(bp); |
| 8587 | rc = bnxt_init_int_mode(bp); |
Venkat Duvvuru | 1a03778 | 2018-03-09 23:46:09 -0500 | [diff] [blame] | 8588 | |
| 8589 | if (netif_running(bp->dev)) { |
| 8590 | if (rc) |
| 8591 | dev_close(bp->dev); |
| 8592 | else |
| 8593 | rc = bnxt_open_nic(bp, true, false); |
| 8594 | } |
| 8595 | |
Michael Chan | 80fcaf4 | 2018-01-17 03:21:05 -0500 | [diff] [blame] | 8596 | return rc; |
Michael Chan | 7b08f66 | 2016-12-07 00:26:18 -0500 | [diff] [blame] | 8597 | } |
| 8598 | |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 8599 | static int bnxt_init_mac_addr(struct bnxt *bp) |
| 8600 | { |
| 8601 | int rc = 0; |
| 8602 | |
| 8603 | if (BNXT_PF(bp)) { |
| 8604 | memcpy(bp->dev->dev_addr, bp->pf.mac_addr, ETH_ALEN); |
| 8605 | } else { |
| 8606 | #ifdef CONFIG_BNXT_SRIOV |
| 8607 | struct bnxt_vf_info *vf = &bp->vf; |
| 8608 | |
| 8609 | if (is_valid_ether_addr(vf->mac_addr)) { |
Vasundhara Volam | 91cdda4 | 2018-01-17 03:21:14 -0500 | [diff] [blame] | 8610 | /* overwrite netdev dev_addr with admin VF MAC */ |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 8611 | memcpy(bp->dev->dev_addr, vf->mac_addr, ETH_ALEN); |
| 8612 | } else { |
| 8613 | eth_hw_addr_random(bp->dev); |
| 8614 | rc = bnxt_approve_mac(bp, bp->dev->dev_addr); |
| 8615 | } |
| 8616 | #endif |
| 8617 | } |
| 8618 | return rc; |
| 8619 | } |
| 8620 | |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 8621 | static void bnxt_parse_log_pcie_link(struct bnxt *bp) |
| 8622 | { |
| 8623 | enum pcie_link_width width = PCIE_LNK_WIDTH_UNKNOWN; |
| 8624 | enum pci_bus_speed speed = PCI_SPEED_UNKNOWN; |
| 8625 | |
Vasundhara Volam | 7ab0760 | 2017-10-13 21:09:31 -0400 | [diff] [blame] | 8626 | if (pcie_get_minimum_link(pci_physfn(bp->pdev), &speed, &width) || |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 8627 | speed == PCI_SPEED_UNKNOWN || width == PCIE_LNK_WIDTH_UNKNOWN) |
| 8628 | netdev_info(bp->dev, "Failed to determine PCIe Link Info\n"); |
| 8629 | else |
| 8630 | netdev_info(bp->dev, "PCIe: Speed %s Width x%d\n", |
| 8631 | speed == PCIE_SPEED_2_5GT ? "2.5GT/s" : |
| 8632 | speed == PCIE_SPEED_5_0GT ? "5.0GT/s" : |
| 8633 | speed == PCIE_SPEED_8_0GT ? "8.0GT/s" : |
| 8634 | "Unknown", width); |
| 8635 | } |
| 8636 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8637 | static int bnxt_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 8638 | { |
| 8639 | static int version_printed; |
| 8640 | struct net_device *dev; |
| 8641 | struct bnxt *bp; |
Michael Chan | 6e6c5a5 | 2016-01-02 23:45:02 -0500 | [diff] [blame] | 8642 | int rc, max_irqs; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8643 | |
Ray Jui | 4e00338 | 2017-02-20 19:25:16 -0500 | [diff] [blame] | 8644 | if (pci_is_bridge(pdev)) |
Prashant Sreedharan | fa853dd | 2016-07-18 07:15:25 -0400 | [diff] [blame] | 8645 | return -ENODEV; |
| 8646 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8647 | if (version_printed++ == 0) |
| 8648 | pr_info("%s", version); |
| 8649 | |
| 8650 | max_irqs = bnxt_get_max_irq(pdev); |
| 8651 | dev = alloc_etherdev_mq(sizeof(*bp), max_irqs); |
| 8652 | if (!dev) |
| 8653 | return -ENOMEM; |
| 8654 | |
| 8655 | bp = netdev_priv(dev); |
| 8656 | |
| 8657 | if (bnxt_vf_pciid(ent->driver_data)) |
| 8658 | bp->flags |= BNXT_FLAG_VF; |
| 8659 | |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8660 | if (pdev->msix_cap) |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8661 | bp->flags |= BNXT_FLAG_MSIX_CAP; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8662 | |
| 8663 | rc = bnxt_init_board(pdev, dev); |
| 8664 | if (rc < 0) |
| 8665 | goto init_err_free; |
| 8666 | |
| 8667 | dev->netdev_ops = &bnxt_netdev_ops; |
| 8668 | dev->watchdog_timeo = BNXT_TX_TIMEOUT; |
| 8669 | dev->ethtool_ops = &bnxt_ethtool_ops; |
David S. Miller | bc88055 | 2017-07-24 21:20:16 -0700 | [diff] [blame] | 8670 | SWITCHDEV_SET_OPS(dev, &bnxt_switchdev_ops); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8671 | pci_set_drvdata(pdev, dev); |
| 8672 | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 8673 | rc = bnxt_alloc_hwrm_resources(bp); |
| 8674 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8675 | goto init_err_pci_clean; |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 8676 | |
| 8677 | mutex_init(&bp->hwrm_cmd_lock); |
| 8678 | rc = bnxt_hwrm_ver_get(bp); |
| 8679 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8680 | goto init_err_pci_clean; |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 8681 | |
Deepak Khungar | e605db8 | 2017-05-29 19:06:04 -0400 | [diff] [blame] | 8682 | if (bp->flags & BNXT_FLAG_SHORT_CMD) { |
| 8683 | rc = bnxt_alloc_hwrm_short_cmd_req(bp); |
| 8684 | if (rc) |
| 8685 | goto init_err_pci_clean; |
| 8686 | } |
| 8687 | |
Michael Chan | 3c2217a | 2017-03-08 18:44:32 -0500 | [diff] [blame] | 8688 | rc = bnxt_hwrm_func_reset(bp); |
| 8689 | if (rc) |
| 8690 | goto init_err_pci_clean; |
| 8691 | |
Rob Swindell | 5ac67d8 | 2016-09-19 03:58:03 -0400 | [diff] [blame] | 8692 | bnxt_hwrm_fw_set_time(bp); |
| 8693 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8694 | dev->hw_features = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 8695 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 8696 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 8697 | NETIF_F_GSO_IPXIP4 | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 8698 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
| 8699 | NETIF_F_GSO_PARTIAL | NETIF_F_RXHASH | |
Prashant Sreedharan | 3e8060f | 2016-07-18 07:15:20 -0400 | [diff] [blame] | 8700 | NETIF_F_RXCSUM | NETIF_F_GRO; |
| 8701 | |
| 8702 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 8703 | dev->hw_features |= NETIF_F_LRO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8704 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8705 | dev->hw_enc_features = |
| 8706 | NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM | NETIF_F_SG | |
| 8707 | NETIF_F_TSO | NETIF_F_TSO6 | |
| 8708 | NETIF_F_GSO_UDP_TUNNEL | NETIF_F_GSO_GRE | |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 8709 | NETIF_F_GSO_UDP_TUNNEL_CSUM | NETIF_F_GSO_GRE_CSUM | |
Tom Herbert | 7e13318 | 2016-05-18 09:06:10 -0700 | [diff] [blame] | 8710 | NETIF_F_GSO_IPXIP4 | NETIF_F_GSO_PARTIAL; |
Alexander Duyck | 152971e | 2016-05-02 09:38:55 -0700 | [diff] [blame] | 8711 | dev->gso_partial_features = NETIF_F_GSO_UDP_TUNNEL_CSUM | |
| 8712 | NETIF_F_GSO_GRE_CSUM; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8713 | dev->vlan_features = dev->hw_features | NETIF_F_HIGHDMA; |
| 8714 | dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_CTAG_TX | |
| 8715 | NETIF_F_HW_VLAN_STAG_RX | NETIF_F_HW_VLAN_STAG_TX; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 8716 | if (!BNXT_CHIP_TYPE_NITRO_A0(bp)) |
| 8717 | dev->hw_features |= NETIF_F_GRO_HW; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8718 | dev->features |= dev->hw_features | NETIF_F_HIGHDMA; |
Michael Chan | 1054aee | 2017-12-16 03:09:42 -0500 | [diff] [blame] | 8719 | if (dev->features & NETIF_F_GRO_HW) |
| 8720 | dev->features &= ~NETIF_F_LRO; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8721 | dev->priv_flags |= IFF_UNICAST_FLT; |
| 8722 | |
| 8723 | #ifdef CONFIG_BNXT_SRIOV |
| 8724 | init_waitqueue_head(&bp->sriov_cfg_wait); |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 8725 | mutex_init(&bp->sriov_lock); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8726 | #endif |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 8727 | bp->gro_func = bnxt_gro_func_5730x; |
Michael Chan | 3284f9e | 2017-05-29 19:06:07 -0400 | [diff] [blame] | 8728 | if (BNXT_CHIP_P4_PLUS(bp)) |
Michael Chan | 94758f8 | 2016-06-13 02:25:35 -0400 | [diff] [blame] | 8729 | bp->gro_func = bnxt_gro_func_5731x; |
Michael Chan | 434c975 | 2017-05-29 19:06:08 -0400 | [diff] [blame] | 8730 | else |
| 8731 | bp->flags |= BNXT_FLAG_DOUBLE_DB; |
Michael Chan | 309369c | 2016-06-13 02:25:34 -0400 | [diff] [blame] | 8732 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8733 | rc = bnxt_hwrm_func_drv_rgtr(bp); |
| 8734 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8735 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8736 | |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 8737 | rc = bnxt_hwrm_func_rgtr_async_events(bp, NULL, 0); |
| 8738 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8739 | goto init_err_pci_clean; |
Michael Chan | a1653b1 | 2016-12-07 00:26:20 -0500 | [diff] [blame] | 8740 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 8741 | bp->ulp_probe = bnxt_ulp_probe; |
| 8742 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8743 | /* Get the MAX capabilities for this function */ |
| 8744 | rc = bnxt_hwrm_func_qcaps(bp); |
| 8745 | if (rc) { |
| 8746 | netdev_err(bp->dev, "hwrm query capability failure rc: %x\n", |
| 8747 | rc); |
| 8748 | rc = -1; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8749 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8750 | } |
Michael Chan | a22a6ac | 2017-08-23 19:34:05 -0400 | [diff] [blame] | 8751 | rc = bnxt_init_mac_addr(bp); |
| 8752 | if (rc) { |
| 8753 | dev_err(&pdev->dev, "Unable to initialize mac address.\n"); |
| 8754 | rc = -EADDRNOTAVAIL; |
| 8755 | goto init_err_pci_clean; |
| 8756 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8757 | rc = bnxt_hwrm_queue_qportcfg(bp); |
| 8758 | if (rc) { |
| 8759 | netdev_err(bp->dev, "hwrm query qportcfg failure rc: %x\n", |
| 8760 | rc); |
| 8761 | rc = -1; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8762 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8763 | } |
| 8764 | |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 8765 | bnxt_hwrm_func_qcfg(bp); |
Michael Chan | 5ad2cbe | 2017-01-13 01:32:03 -0500 | [diff] [blame] | 8766 | bnxt_hwrm_port_led_qcaps(bp); |
Michael Chan | eb51365 | 2017-04-04 18:14:12 -0400 | [diff] [blame] | 8767 | bnxt_ethtool_init(bp); |
Michael Chan | 87fe603 | 2017-05-16 16:39:43 -0400 | [diff] [blame] | 8768 | bnxt_dcb_init(bp); |
Satish Baddipadige | 567b2ab | 2016-06-13 02:25:31 -0400 | [diff] [blame] | 8769 | |
Michael Chan | 7eb9bb3 | 2017-10-26 11:51:25 -0400 | [diff] [blame] | 8770 | /* MTU range: 60 - FW defined max */ |
| 8771 | dev->min_mtu = ETH_ZLEN; |
| 8772 | dev->max_mtu = bp->max_mtu; |
| 8773 | |
Michael Chan | d5430d3 | 2017-08-28 13:40:31 -0400 | [diff] [blame] | 8774 | rc = bnxt_probe_phy(bp); |
| 8775 | if (rc) |
| 8776 | goto init_err_pci_clean; |
| 8777 | |
Michael Chan | c61fb99 | 2017-02-06 16:55:36 -0500 | [diff] [blame] | 8778 | bnxt_set_rx_skb_mode(bp, false); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8779 | bnxt_set_tpa_flags(bp); |
| 8780 | bnxt_set_ring_params(bp); |
Michael Chan | 33c2657 | 2016-12-07 00:26:15 -0500 | [diff] [blame] | 8781 | bnxt_set_max_func_irqs(bp, max_irqs); |
Michael Chan | 702c221 | 2017-05-29 19:06:10 -0400 | [diff] [blame] | 8782 | rc = bnxt_set_dflt_rings(bp, true); |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 8783 | if (rc) { |
| 8784 | netdev_err(bp->dev, "Not enough rings available.\n"); |
| 8785 | rc = -ENOMEM; |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8786 | goto init_err_pci_clean; |
Michael Chan | bdbd1eb | 2016-12-29 12:13:43 -0500 | [diff] [blame] | 8787 | } |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8788 | |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 8789 | /* Default RSS hash cfg. */ |
| 8790 | bp->rss_hash_cfg = VNIC_RSS_CFG_REQ_HASH_TYPE_IPV4 | |
| 8791 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV4 | |
| 8792 | VNIC_RSS_CFG_REQ_HASH_TYPE_IPV6 | |
| 8793 | VNIC_RSS_CFG_REQ_HASH_TYPE_TCP_IPV6; |
Michael Chan | 3284f9e | 2017-05-29 19:06:07 -0400 | [diff] [blame] | 8794 | if (BNXT_CHIP_P4_PLUS(bp) && bp->hwrm_spec_code >= 0x10501) { |
Michael Chan | 87da7f7 | 2016-11-16 21:13:09 -0500 | [diff] [blame] | 8795 | bp->flags |= BNXT_FLAG_UDP_RSS_CAP; |
| 8796 | bp->rss_hash_cfg |= VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV4 | |
| 8797 | VNIC_RSS_CFG_REQ_HASH_TYPE_UDP_IPV6; |
| 8798 | } |
| 8799 | |
Michael Chan | 8fdefd6 | 2016-12-29 12:13:36 -0500 | [diff] [blame] | 8800 | bnxt_hwrm_vnic_qcaps(bp); |
Michael Chan | 8079e8f | 2016-12-29 12:13:37 -0500 | [diff] [blame] | 8801 | if (bnxt_rfs_supported(bp)) { |
Michael Chan | 2bcfa6f | 2015-12-27 18:19:24 -0500 | [diff] [blame] | 8802 | dev->hw_features |= NETIF_F_NTUPLE; |
| 8803 | if (bnxt_rfs_capable(bp)) { |
| 8804 | bp->flags |= BNXT_FLAG_RFS; |
| 8805 | dev->features |= NETIF_F_NTUPLE; |
| 8806 | } |
| 8807 | } |
| 8808 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8809 | if (dev->hw_features & NETIF_F_HW_VLAN_CTAG_RX) |
| 8810 | bp->flags |= BNXT_FLAG_STRIP_VLAN; |
| 8811 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 8812 | rc = bnxt_init_int_mode(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8813 | if (rc) |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8814 | goto init_err_pci_clean; |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8815 | |
Michael Chan | 832aed1 | 2018-03-09 23:46:07 -0500 | [diff] [blame] | 8816 | /* No TC has been set yet and rings may have been trimmed due to |
| 8817 | * limited MSIX, so we re-initialize the TX rings per TC. |
| 8818 | */ |
| 8819 | bp->tx_nr_rings_per_tc = bp->tx_nr_rings; |
| 8820 | |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 8821 | bnxt_get_wol_settings(bp); |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 8822 | if (bp->flags & BNXT_FLAG_WOL_CAP) |
| 8823 | device_set_wakeup_enable(&pdev->dev, bp->wol); |
| 8824 | else |
| 8825 | device_set_wakeup_capable(&pdev->dev, false); |
Michael Chan | c1ef146 | 2017-04-04 18:14:07 -0400 | [diff] [blame] | 8826 | |
Michael Chan | c3480a6 | 2018-01-17 03:21:15 -0500 | [diff] [blame] | 8827 | bnxt_hwrm_set_cache_line_size(bp, cache_line_size()); |
| 8828 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8829 | if (BNXT_PF(bp)) { |
| 8830 | if (!bnxt_pf_wq) { |
| 8831 | bnxt_pf_wq = |
| 8832 | create_singlethread_workqueue("bnxt_pf_wq"); |
| 8833 | if (!bnxt_pf_wq) { |
| 8834 | dev_err(&pdev->dev, "Unable to create workqueue.\n"); |
| 8835 | goto init_err_pci_clean; |
| 8836 | } |
| 8837 | } |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8838 | bnxt_init_tc(bp); |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 8839 | } |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8840 | |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 8841 | rc = register_netdev(dev); |
| 8842 | if (rc) |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8843 | goto init_err_cleanup_tc; |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 8844 | |
Sathya Perla | 4ab0c6a | 2017-07-24 12:34:27 -0400 | [diff] [blame] | 8845 | if (BNXT_PF(bp)) |
| 8846 | bnxt_dl_register(bp); |
| 8847 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8848 | netdev_info(dev, "%s found at mem %lx, node addr %pM\n", |
| 8849 | board_info[ent->driver_data].name, |
| 8850 | (long)pci_resource_start(pdev, 0), dev->dev_addr); |
| 8851 | |
Ajit Khaparde | 90c4f78 | 2016-05-15 03:04:45 -0400 | [diff] [blame] | 8852 | bnxt_parse_log_pcie_link(bp); |
| 8853 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8854 | return 0; |
| 8855 | |
Sathya Perla | 2ae7408 | 2017-08-28 13:40:33 -0400 | [diff] [blame] | 8856 | init_err_cleanup_tc: |
| 8857 | bnxt_shutdown_tc(bp); |
Michael Chan | 7809592 | 2016-12-07 00:26:16 -0500 | [diff] [blame] | 8858 | bnxt_clear_int_mode(bp); |
| 8859 | |
Sathya Perla | 1708639 | 2017-02-20 19:25:18 -0500 | [diff] [blame] | 8860 | init_err_pci_clean: |
| 8861 | bnxt_cleanup_pci(bp); |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 8862 | |
| 8863 | init_err_free: |
| 8864 | free_netdev(dev); |
| 8865 | return rc; |
| 8866 | } |
| 8867 | |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 8868 | static void bnxt_shutdown(struct pci_dev *pdev) |
| 8869 | { |
| 8870 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8871 | struct bnxt *bp; |
| 8872 | |
| 8873 | if (!dev) |
| 8874 | return; |
| 8875 | |
| 8876 | rtnl_lock(); |
| 8877 | bp = netdev_priv(dev); |
| 8878 | if (!bp) |
| 8879 | goto shutdown_exit; |
| 8880 | |
| 8881 | if (netif_running(dev)) |
| 8882 | dev_close(dev); |
| 8883 | |
Ray Jui | a7f3f93 | 2017-12-01 03:13:02 -0500 | [diff] [blame] | 8884 | bnxt_ulp_shutdown(bp); |
| 8885 | |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 8886 | if (system_state == SYSTEM_POWER_OFF) { |
| 8887 | bnxt_clear_int_mode(bp); |
| 8888 | pci_wake_from_d3(pdev, bp->wol); |
| 8889 | pci_set_power_state(pdev, PCI_D3hot); |
| 8890 | } |
| 8891 | |
| 8892 | shutdown_exit: |
| 8893 | rtnl_unlock(); |
| 8894 | } |
| 8895 | |
Michael Chan | f65a204 | 2017-04-04 18:14:11 -0400 | [diff] [blame] | 8896 | #ifdef CONFIG_PM_SLEEP |
| 8897 | static int bnxt_suspend(struct device *device) |
| 8898 | { |
| 8899 | struct pci_dev *pdev = to_pci_dev(device); |
| 8900 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8901 | struct bnxt *bp = netdev_priv(dev); |
| 8902 | int rc = 0; |
| 8903 | |
| 8904 | rtnl_lock(); |
| 8905 | if (netif_running(dev)) { |
| 8906 | netif_device_detach(dev); |
| 8907 | rc = bnxt_close(dev); |
| 8908 | } |
| 8909 | bnxt_hwrm_func_drv_unrgtr(bp); |
| 8910 | rtnl_unlock(); |
| 8911 | return rc; |
| 8912 | } |
| 8913 | |
| 8914 | static int bnxt_resume(struct device *device) |
| 8915 | { |
| 8916 | struct pci_dev *pdev = to_pci_dev(device); |
| 8917 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8918 | struct bnxt *bp = netdev_priv(dev); |
| 8919 | int rc = 0; |
| 8920 | |
| 8921 | rtnl_lock(); |
| 8922 | if (bnxt_hwrm_ver_get(bp) || bnxt_hwrm_func_drv_rgtr(bp)) { |
| 8923 | rc = -ENODEV; |
| 8924 | goto resume_exit; |
| 8925 | } |
| 8926 | rc = bnxt_hwrm_func_reset(bp); |
| 8927 | if (rc) { |
| 8928 | rc = -EBUSY; |
| 8929 | goto resume_exit; |
| 8930 | } |
| 8931 | bnxt_get_wol_settings(bp); |
| 8932 | if (netif_running(dev)) { |
| 8933 | rc = bnxt_open(dev); |
| 8934 | if (!rc) |
| 8935 | netif_device_attach(dev); |
| 8936 | } |
| 8937 | |
| 8938 | resume_exit: |
| 8939 | rtnl_unlock(); |
| 8940 | return rc; |
| 8941 | } |
| 8942 | |
| 8943 | static SIMPLE_DEV_PM_OPS(bnxt_pm_ops, bnxt_suspend, bnxt_resume); |
| 8944 | #define BNXT_PM_OPS (&bnxt_pm_ops) |
| 8945 | |
| 8946 | #else |
| 8947 | |
| 8948 | #define BNXT_PM_OPS NULL |
| 8949 | |
| 8950 | #endif /* CONFIG_PM_SLEEP */ |
| 8951 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 8952 | /** |
| 8953 | * bnxt_io_error_detected - called when PCI error is detected |
| 8954 | * @pdev: Pointer to PCI device |
| 8955 | * @state: The current pci connection state |
| 8956 | * |
| 8957 | * This function is called after a PCI bus error affecting |
| 8958 | * this device has been detected. |
| 8959 | */ |
| 8960 | static pci_ers_result_t bnxt_io_error_detected(struct pci_dev *pdev, |
| 8961 | pci_channel_state_t state) |
| 8962 | { |
| 8963 | struct net_device *netdev = pci_get_drvdata(pdev); |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 8964 | struct bnxt *bp = netdev_priv(netdev); |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 8965 | |
| 8966 | netdev_info(netdev, "PCI I/O error detected\n"); |
| 8967 | |
| 8968 | rtnl_lock(); |
| 8969 | netif_device_detach(netdev); |
| 8970 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 8971 | bnxt_ulp_stop(bp); |
| 8972 | |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 8973 | if (state == pci_channel_io_perm_failure) { |
| 8974 | rtnl_unlock(); |
| 8975 | return PCI_ERS_RESULT_DISCONNECT; |
| 8976 | } |
| 8977 | |
| 8978 | if (netif_running(netdev)) |
| 8979 | bnxt_close(netdev); |
| 8980 | |
| 8981 | pci_disable_device(pdev); |
| 8982 | rtnl_unlock(); |
| 8983 | |
| 8984 | /* Request a slot slot reset. */ |
| 8985 | return PCI_ERS_RESULT_NEED_RESET; |
| 8986 | } |
| 8987 | |
| 8988 | /** |
| 8989 | * bnxt_io_slot_reset - called after the pci bus has been reset. |
| 8990 | * @pdev: Pointer to PCI device |
| 8991 | * |
| 8992 | * Restart the card from scratch, as if from a cold-boot. |
| 8993 | * At this point, the card has exprienced a hard reset, |
| 8994 | * followed by fixups by BIOS, and has its config space |
| 8995 | * set up identically to what it was at cold boot. |
| 8996 | */ |
| 8997 | static pci_ers_result_t bnxt_io_slot_reset(struct pci_dev *pdev) |
| 8998 | { |
| 8999 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 9000 | struct bnxt *bp = netdev_priv(netdev); |
| 9001 | int err = 0; |
| 9002 | pci_ers_result_t result = PCI_ERS_RESULT_DISCONNECT; |
| 9003 | |
| 9004 | netdev_info(bp->dev, "PCI Slot Reset\n"); |
| 9005 | |
| 9006 | rtnl_lock(); |
| 9007 | |
| 9008 | if (pci_enable_device(pdev)) { |
| 9009 | dev_err(&pdev->dev, |
| 9010 | "Cannot re-enable PCI device after reset.\n"); |
| 9011 | } else { |
| 9012 | pci_set_master(pdev); |
| 9013 | |
Michael Chan | aa8ed02 | 2016-12-07 00:26:17 -0500 | [diff] [blame] | 9014 | err = bnxt_hwrm_func_reset(bp); |
| 9015 | if (!err && netif_running(netdev)) |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9016 | err = bnxt_open(netdev); |
| 9017 | |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 9018 | if (!err) { |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9019 | result = PCI_ERS_RESULT_RECOVERED; |
Michael Chan | a588e45 | 2016-12-07 00:26:21 -0500 | [diff] [blame] | 9020 | bnxt_ulp_start(bp); |
| 9021 | } |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9022 | } |
| 9023 | |
| 9024 | if (result != PCI_ERS_RESULT_RECOVERED && netif_running(netdev)) |
| 9025 | dev_close(netdev); |
| 9026 | |
| 9027 | rtnl_unlock(); |
| 9028 | |
| 9029 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 9030 | if (err) { |
| 9031 | dev_err(&pdev->dev, |
| 9032 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", |
| 9033 | err); /* non-fatal, continue */ |
| 9034 | } |
| 9035 | |
| 9036 | return PCI_ERS_RESULT_RECOVERED; |
| 9037 | } |
| 9038 | |
| 9039 | /** |
| 9040 | * bnxt_io_resume - called when traffic can start flowing again. |
| 9041 | * @pdev: Pointer to PCI device |
| 9042 | * |
| 9043 | * This callback is called when the error recovery driver tells |
| 9044 | * us that its OK to resume normal operation. |
| 9045 | */ |
| 9046 | static void bnxt_io_resume(struct pci_dev *pdev) |
| 9047 | { |
| 9048 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 9049 | |
| 9050 | rtnl_lock(); |
| 9051 | |
| 9052 | netif_device_attach(netdev); |
| 9053 | |
| 9054 | rtnl_unlock(); |
| 9055 | } |
| 9056 | |
| 9057 | static const struct pci_error_handlers bnxt_err_handler = { |
| 9058 | .error_detected = bnxt_io_error_detected, |
| 9059 | .slot_reset = bnxt_io_slot_reset, |
| 9060 | .resume = bnxt_io_resume |
| 9061 | }; |
| 9062 | |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9063 | static struct pci_driver bnxt_pci_driver = { |
| 9064 | .name = DRV_MODULE_NAME, |
| 9065 | .id_table = bnxt_pci_tbl, |
| 9066 | .probe = bnxt_init_one, |
| 9067 | .remove = bnxt_remove_one, |
Michael Chan | d196ece | 2017-04-04 18:14:08 -0400 | [diff] [blame] | 9068 | .shutdown = bnxt_shutdown, |
Michael Chan | f65a204 | 2017-04-04 18:14:11 -0400 | [diff] [blame] | 9069 | .driver.pm = BNXT_PM_OPS, |
Satish Baddipadige | 6316ea6 | 2016-03-07 15:38:48 -0500 | [diff] [blame] | 9070 | .err_handler = &bnxt_err_handler, |
Michael Chan | c0c050c | 2015-10-22 16:01:17 -0400 | [diff] [blame] | 9071 | #if defined(CONFIG_BNXT_SRIOV) |
| 9072 | .sriov_configure = bnxt_sriov_configure, |
| 9073 | #endif |
| 9074 | }; |
| 9075 | |
Michael Chan | c213eae | 2017-10-13 21:09:29 -0400 | [diff] [blame] | 9076 | static int __init bnxt_init(void) |
| 9077 | { |
| 9078 | return pci_register_driver(&bnxt_pci_driver); |
| 9079 | } |
| 9080 | |
| 9081 | static void __exit bnxt_exit(void) |
| 9082 | { |
| 9083 | pci_unregister_driver(&bnxt_pci_driver); |
| 9084 | if (bnxt_pf_wq) |
| 9085 | destroy_workqueue(bnxt_pf_wq); |
| 9086 | } |
| 9087 | |
| 9088 | module_init(bnxt_init); |
| 9089 | module_exit(bnxt_exit); |