Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1 | /********************************************************************** |
Raghu Vatsavayi | 50579d3 | 2016-11-14 15:54:46 -0800 | [diff] [blame] | 2 | * Author: Cavium, Inc. |
| 3 | * |
| 4 | * Contact: support@cavium.com |
| 5 | * Please include "LiquidIO" in the subject. |
| 6 | * |
| 7 | * Copyright (c) 2003-2016 Cavium, Inc. |
| 8 | * |
| 9 | * This file is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License, Version 2, as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * This file is distributed in the hope that it will be useful, but |
| 14 | * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty |
| 15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or |
| 16 | * NONINFRINGEMENT. See the GNU General Public License for more details. |
| 17 | ***********************************************************************/ |
Russell King | e3bfc6e | 2017-02-07 15:03:03 -0800 | [diff] [blame] | 18 | #include <linux/module.h> |
Florian Westphal | 282ccf6 | 2017-03-29 17:17:31 +0200 | [diff] [blame] | 19 | #include <linux/interrupt.h> |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 20 | #include <linux/pci.h> |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 21 | #include <linux/firmware.h> |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 22 | #include <net/vxlan.h> |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 23 | #include <linux/kthread.h> |
Vijaya Mohan Guvva | 1f233f3 | 2017-10-31 16:04:53 -0700 | [diff] [blame] | 24 | #include <net/switchdev.h> |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 25 | #include "liquidio_common.h" |
| 26 | #include "octeon_droq.h" |
| 27 | #include "octeon_iq.h" |
| 28 | #include "response_manager.h" |
| 29 | #include "octeon_device.h" |
| 30 | #include "octeon_nic.h" |
| 31 | #include "octeon_main.h" |
| 32 | #include "octeon_network.h" |
| 33 | #include "cn66xx_regs.h" |
| 34 | #include "cn66xx_device.h" |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 35 | #include "cn68xx_device.h" |
Raghu Vatsavayi | 72c0091 | 2016-08-31 11:03:25 -0700 | [diff] [blame] | 36 | #include "cn23xx_pf_device.h" |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 37 | #include "liquidio_image.h" |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 38 | #include "lio_vf_rep.h" |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 39 | |
| 40 | MODULE_AUTHOR("Cavium Networks, <support@cavium.com>"); |
| 41 | MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | MODULE_VERSION(LIQUIDIO_VERSION); |
Derek Chickles | ea6404c8 | 2017-08-07 12:22:15 -0700 | [diff] [blame] | 44 | MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210SV_NAME |
| 45 | "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX); |
| 46 | MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210NV_NAME |
| 47 | "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX); |
| 48 | MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_410NV_NAME |
| 49 | "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX); |
| 50 | MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_23XX_NAME |
| 51 | "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 52 | |
| 53 | static int ddr_timeout = 10000; |
| 54 | module_param(ddr_timeout, int, 0644); |
| 55 | MODULE_PARM_DESC(ddr_timeout, |
| 56 | "Number of milliseconds to wait for DDR initialization. 0 waits for ddr_timeout to be set to non-zero value before starting to check"); |
| 57 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 58 | #define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK) |
| 59 | |
| 60 | static int debug = -1; |
| 61 | module_param(debug, int, 0644); |
| 62 | MODULE_PARM_DESC(debug, "NETIF_MSG debug bits"); |
| 63 | |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 64 | static char fw_type[LIO_MAX_FW_TYPE_LEN] = LIO_FW_NAME_TYPE_AUTO; |
Derek Chickles | d396179 | 2017-08-14 12:17:56 -0700 | [diff] [blame] | 65 | module_param_string(fw_type, fw_type, sizeof(fw_type), 0444); |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 66 | MODULE_PARM_DESC(fw_type, "Type of firmware to be loaded (default is \"auto\"), which uses firmware in flash, if present, else loads \"nic\"."); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 67 | |
Intiyaz Basha | 2470f3a | 2017-08-03 15:10:17 -0700 | [diff] [blame] | 68 | static u32 console_bitmask; |
| 69 | module_param(console_bitmask, int, 0644); |
| 70 | MODULE_PARM_DESC(console_bitmask, |
| 71 | "Bitmask indicating which consoles have debug output redirected to syslog."); |
| 72 | |
| 73 | /** |
| 74 | * \brief determines if a given console has debug enabled. |
| 75 | * @param console console to check |
| 76 | * @returns 1 = enabled. 0 otherwise |
| 77 | */ |
Rick Farrington | da1542b | 2017-08-11 18:43:14 -0700 | [diff] [blame] | 78 | static int octeon_console_debug_enabled(u32 console) |
Intiyaz Basha | 2470f3a | 2017-08-03 15:10:17 -0700 | [diff] [blame] | 79 | { |
| 80 | return (console_bitmask >> (console)) & 0x1; |
| 81 | } |
| 82 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 83 | /* Polling interval for determining when NIC application is alive */ |
| 84 | #define LIQUIDIO_STARTER_POLL_INTERVAL_MS 100 |
| 85 | |
| 86 | /* runtime link query interval */ |
| 87 | #define LIQUIDIO_LINK_QUERY_INTERVAL_MS 1000 |
Veerasenareddy Burru | 907aaa6 | 2017-10-23 20:33:25 -0700 | [diff] [blame] | 88 | /* update localtime to octeon firmware every 60 seconds. |
| 89 | * make firmware to use same time reference, so that it will be easy to |
| 90 | * correlate firmware logged events/errors with host events, for debugging. |
| 91 | */ |
| 92 | #define LIO_SYNC_OCTEON_TIME_INTERVAL_MS 60000 |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 93 | |
| 94 | struct liquidio_if_cfg_context { |
| 95 | int octeon_id; |
| 96 | |
| 97 | wait_queue_head_t wc; |
| 98 | |
| 99 | int cond; |
| 100 | }; |
| 101 | |
| 102 | struct liquidio_if_cfg_resp { |
| 103 | u64 rh; |
| 104 | struct liquidio_if_cfg_info cfg_info; |
| 105 | u64 status; |
| 106 | }; |
| 107 | |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 108 | struct liquidio_rx_ctl_context { |
| 109 | int octeon_id; |
| 110 | |
| 111 | wait_queue_head_t wc; |
| 112 | |
| 113 | int cond; |
| 114 | }; |
| 115 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 116 | struct oct_link_status_resp { |
| 117 | u64 rh; |
| 118 | struct oct_link_info link_info; |
| 119 | u64 status; |
| 120 | }; |
| 121 | |
| 122 | struct oct_timestamp_resp { |
| 123 | u64 rh; |
| 124 | u64 timestamp; |
| 125 | u64 status; |
| 126 | }; |
| 127 | |
| 128 | #define OCT_TIMESTAMP_RESP_SIZE (sizeof(struct oct_timestamp_resp)) |
| 129 | |
| 130 | union tx_info { |
| 131 | u64 u64; |
| 132 | struct { |
| 133 | #ifdef __BIG_ENDIAN_BITFIELD |
| 134 | u16 gso_size; |
| 135 | u16 gso_segs; |
| 136 | u32 reserved; |
| 137 | #else |
| 138 | u32 reserved; |
| 139 | u16 gso_segs; |
| 140 | u16 gso_size; |
| 141 | #endif |
| 142 | } s; |
| 143 | }; |
| 144 | |
| 145 | /** Octeon device properties to be used by the NIC module. |
| 146 | * Each octeon device in the system will be represented |
| 147 | * by this structure in the NIC module. |
| 148 | */ |
| 149 | |
| 150 | #define OCTNIC_MAX_SG (MAX_SKB_FRAGS) |
| 151 | |
| 152 | #define OCTNIC_GSO_MAX_HEADER_SIZE 128 |
Raghu Vatsavayi | 72c0091 | 2016-08-31 11:03:25 -0700 | [diff] [blame] | 153 | #define OCTNIC_GSO_MAX_SIZE \ |
| 154 | (CN23XX_DEFAULT_INPUT_JABBER - OCTNIC_GSO_MAX_HEADER_SIZE) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 155 | |
| 156 | /** Structure of a node in list of gather components maintained by |
| 157 | * NIC driver for each network device. |
| 158 | */ |
| 159 | struct octnic_gather { |
| 160 | /** List manipulation. Next and prev pointers. */ |
| 161 | struct list_head list; |
| 162 | |
| 163 | /** Size of the gather component at sg in bytes. */ |
| 164 | int sg_size; |
| 165 | |
| 166 | /** Number of bytes that sg was adjusted to make it 8B-aligned. */ |
| 167 | int adjust; |
| 168 | |
| 169 | /** Gather component that can accommodate max sized fragment list |
| 170 | * received from the IP layer. |
| 171 | */ |
| 172 | struct octeon_sg_entry *sg; |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 173 | |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 174 | dma_addr_t sg_dma_ptr; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 175 | }; |
| 176 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 177 | struct handshake { |
| 178 | struct completion init; |
| 179 | struct completion started; |
| 180 | struct pci_dev *pci_dev; |
| 181 | int init_ok; |
| 182 | int started_ok; |
| 183 | }; |
| 184 | |
Raghu Vatsavayi | ca6139f | 2016-11-14 15:54:40 -0800 | [diff] [blame] | 185 | #ifdef CONFIG_PCI_IOV |
| 186 | static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs); |
| 187 | #endif |
| 188 | |
Rick Farrington | da1542b | 2017-08-11 18:43:14 -0700 | [diff] [blame] | 189 | static int octeon_dbg_console_print(struct octeon_device *oct, u32 console_num, |
| 190 | char *prefix, char *suffix); |
| 191 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 192 | static int octeon_device_init(struct octeon_device *); |
Raghu Vatsavayi | 3258124 | 2016-08-31 11:03:20 -0700 | [diff] [blame] | 193 | static int liquidio_stop(struct net_device *netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 194 | static void liquidio_remove(struct pci_dev *pdev); |
| 195 | static int liquidio_probe(struct pci_dev *pdev, |
| 196 | const struct pci_device_id *ent); |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 197 | static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx, |
| 198 | int linkstate); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 199 | |
| 200 | static struct handshake handshake[MAX_OCTEON_DEVICES]; |
| 201 | static struct completion first_stage; |
| 202 | |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 203 | static void octeon_droq_bh(unsigned long pdev) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 204 | { |
| 205 | int q_no; |
| 206 | int reschedule = 0; |
| 207 | struct octeon_device *oct = (struct octeon_device *)pdev; |
| 208 | struct octeon_device_priv *oct_priv = |
| 209 | (struct octeon_device_priv *)oct->priv; |
| 210 | |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 211 | for (q_no = 0; q_no < MAX_OCTEON_OUTPUT_QUEUES(oct); q_no++) { |
Raghu Vatsavayi | 763185a | 2016-11-14 15:54:45 -0800 | [diff] [blame] | 212 | if (!(oct->io_qmask.oq & BIT_ULL(q_no))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 213 | continue; |
| 214 | reschedule |= octeon_droq_process_packets(oct, oct->droq[q_no], |
| 215 | MAX_PACKET_BUDGET); |
Raghu Vatsavayi | cd8b1eb | 2016-08-31 11:03:22 -0700 | [diff] [blame] | 216 | lio_enable_irq(oct->droq[q_no], NULL); |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 217 | |
| 218 | if (OCTEON_CN23XX_PF(oct) && oct->msix_on) { |
| 219 | /* set time and cnt interrupt thresholds for this DROQ |
| 220 | * for NAPI |
| 221 | */ |
| 222 | int adjusted_q_no = q_no + oct->sriov_info.pf_srn; |
| 223 | |
| 224 | octeon_write_csr64( |
| 225 | oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(adjusted_q_no), |
| 226 | 0x5700000040ULL); |
| 227 | octeon_write_csr64( |
| 228 | oct, CN23XX_SLI_OQ_PKTS_SENT(adjusted_q_no), 0); |
| 229 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | if (reschedule) |
| 233 | tasklet_schedule(&oct_priv->droq_tasklet); |
| 234 | } |
| 235 | |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 236 | static int lio_wait_for_oq_pkts(struct octeon_device *oct) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 237 | { |
| 238 | struct octeon_device_priv *oct_priv = |
| 239 | (struct octeon_device_priv *)oct->priv; |
| 240 | int retry = 100, pkt_cnt = 0, pending_pkts = 0; |
| 241 | int i; |
| 242 | |
| 243 | do { |
| 244 | pending_pkts = 0; |
| 245 | |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 246 | for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) { |
Raghu Vatsavayi | 763185a | 2016-11-14 15:54:45 -0800 | [diff] [blame] | 247 | if (!(oct->io_qmask.oq & BIT_ULL(i))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 248 | continue; |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 249 | pkt_cnt += octeon_droq_check_hw_for_pkts(oct->droq[i]); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 250 | } |
| 251 | if (pkt_cnt > 0) { |
| 252 | pending_pkts += pkt_cnt; |
| 253 | tasklet_schedule(&oct_priv->droq_tasklet); |
| 254 | } |
| 255 | pkt_cnt = 0; |
| 256 | schedule_timeout_uninterruptible(1); |
| 257 | |
| 258 | } while (retry-- && pending_pkts); |
| 259 | |
| 260 | return pkt_cnt; |
| 261 | } |
| 262 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 263 | /** |
| 264 | * \brief Forces all IO queues off on a given device |
| 265 | * @param oct Pointer to Octeon device |
| 266 | */ |
| 267 | static void force_io_queues_off(struct octeon_device *oct) |
| 268 | { |
| 269 | if ((oct->chip_id == OCTEON_CN66XX) || |
| 270 | (oct->chip_id == OCTEON_CN68XX)) { |
| 271 | /* Reset the Enable bits for Input Queues. */ |
| 272 | octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0); |
| 273 | |
| 274 | /* Reset the Enable bits for Output Queues. */ |
| 275 | octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0); |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 280 | * \brief Cause device to go quiet so it can be safely removed/reset/etc |
| 281 | * @param oct Pointer to Octeon device |
| 282 | */ |
| 283 | static inline void pcierror_quiesce_device(struct octeon_device *oct) |
| 284 | { |
| 285 | int i; |
| 286 | |
| 287 | /* Disable the input and output queues now. No more packets will |
| 288 | * arrive from Octeon, but we should wait for all packet processing |
| 289 | * to finish. |
| 290 | */ |
| 291 | force_io_queues_off(oct); |
| 292 | |
| 293 | /* To allow for in-flight requests */ |
| 294 | schedule_timeout_uninterruptible(100); |
| 295 | |
| 296 | if (wait_for_pending_requests(oct)) |
| 297 | dev_err(&oct->pci_dev->dev, "There were pending requests\n"); |
| 298 | |
| 299 | /* Force all requests waiting to be fetched by OCTEON to complete. */ |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 300 | for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 301 | struct octeon_instr_queue *iq; |
| 302 | |
Raghu Vatsavayi | 763185a | 2016-11-14 15:54:45 -0800 | [diff] [blame] | 303 | if (!(oct->io_qmask.iq & BIT_ULL(i))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 304 | continue; |
| 305 | iq = oct->instr_queue[i]; |
| 306 | |
| 307 | if (atomic_read(&iq->instr_pending)) { |
| 308 | spin_lock_bh(&iq->lock); |
| 309 | iq->fill_cnt = 0; |
| 310 | iq->octeon_read_index = iq->host_write_index; |
| 311 | iq->stats.instr_processed += |
| 312 | atomic_read(&iq->instr_pending); |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 313 | lio_process_iq_request_list(oct, iq, 0); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 314 | spin_unlock_bh(&iq->lock); |
| 315 | } |
| 316 | } |
| 317 | |
| 318 | /* Force all pending ordered list requests to time out. */ |
| 319 | lio_process_ordered_list(oct, 1); |
| 320 | |
| 321 | /* We do not need to wait for output queue packets to be processed. */ |
| 322 | } |
| 323 | |
| 324 | /** |
| 325 | * \brief Cleanup PCI AER uncorrectable error status |
| 326 | * @param dev Pointer to PCI device |
| 327 | */ |
| 328 | static void cleanup_aer_uncorrect_error_status(struct pci_dev *dev) |
| 329 | { |
| 330 | int pos = 0x100; |
| 331 | u32 status, mask; |
| 332 | |
| 333 | pr_info("%s :\n", __func__); |
| 334 | |
| 335 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status); |
| 336 | pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask); |
| 337 | if (dev->error_state == pci_channel_io_normal) |
| 338 | status &= ~mask; /* Clear corresponding nonfatal bits */ |
| 339 | else |
| 340 | status &= mask; /* Clear corresponding fatal bits */ |
| 341 | pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * \brief Stop all PCI IO to a given device |
| 346 | * @param dev Pointer to Octeon device |
| 347 | */ |
| 348 | static void stop_pci_io(struct octeon_device *oct) |
| 349 | { |
| 350 | /* No more instructions will be forwarded. */ |
| 351 | atomic_set(&oct->status, OCT_DEV_IN_RESET); |
| 352 | |
| 353 | pci_disable_device(oct->pci_dev); |
| 354 | |
| 355 | /* Disable interrupts */ |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 356 | oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 357 | |
| 358 | pcierror_quiesce_device(oct); |
| 359 | |
| 360 | /* Release the interrupt line */ |
| 361 | free_irq(oct->pci_dev->irq, oct); |
| 362 | |
| 363 | if (oct->flags & LIO_FLAG_MSI_ENABLED) |
| 364 | pci_disable_msi(oct->pci_dev); |
| 365 | |
| 366 | dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n", |
| 367 | lio_get_state_string(&oct->status)); |
| 368 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 369 | /* making it a common function for all OCTEON models */ |
| 370 | cleanup_aer_uncorrect_error_status(oct->pci_dev); |
| 371 | } |
| 372 | |
| 373 | /** |
| 374 | * \brief called when PCI error is detected |
| 375 | * @param pdev Pointer to PCI device |
| 376 | * @param state The current pci connection state |
| 377 | * |
| 378 | * This function is called after a PCI bus error affecting |
| 379 | * this device has been detected. |
| 380 | */ |
| 381 | static pci_ers_result_t liquidio_pcie_error_detected(struct pci_dev *pdev, |
| 382 | pci_channel_state_t state) |
| 383 | { |
| 384 | struct octeon_device *oct = pci_get_drvdata(pdev); |
| 385 | |
| 386 | /* Non-correctable Non-fatal errors */ |
| 387 | if (state == pci_channel_io_normal) { |
| 388 | dev_err(&oct->pci_dev->dev, "Non-correctable non-fatal error reported:\n"); |
| 389 | cleanup_aer_uncorrect_error_status(oct->pci_dev); |
| 390 | return PCI_ERS_RESULT_CAN_RECOVER; |
| 391 | } |
| 392 | |
| 393 | /* Non-correctable Fatal errors */ |
| 394 | dev_err(&oct->pci_dev->dev, "Non-correctable FATAL reported by PCI AER driver\n"); |
| 395 | stop_pci_io(oct); |
| 396 | |
| 397 | /* Always return a DISCONNECT. There is no support for recovery but only |
| 398 | * for a clean shutdown. |
| 399 | */ |
| 400 | return PCI_ERS_RESULT_DISCONNECT; |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * \brief mmio handler |
| 405 | * @param pdev Pointer to PCI device |
| 406 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 407 | static pci_ers_result_t liquidio_pcie_mmio_enabled( |
| 408 | struct pci_dev *pdev __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 409 | { |
| 410 | /* We should never hit this since we never ask for a reset for a Fatal |
| 411 | * Error. We always return DISCONNECT in io_error above. |
| 412 | * But play safe and return RECOVERED for now. |
| 413 | */ |
| 414 | return PCI_ERS_RESULT_RECOVERED; |
| 415 | } |
| 416 | |
| 417 | /** |
| 418 | * \brief called after the pci bus has been reset. |
| 419 | * @param pdev Pointer to PCI device |
| 420 | * |
| 421 | * Restart the card from scratch, as if from a cold-boot. Implementation |
| 422 | * resembles the first-half of the octeon_resume routine. |
| 423 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 424 | static pci_ers_result_t liquidio_pcie_slot_reset( |
| 425 | struct pci_dev *pdev __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 426 | { |
| 427 | /* We should never hit this since we never ask for a reset for a Fatal |
| 428 | * Error. We always return DISCONNECT in io_error above. |
| 429 | * But play safe and return RECOVERED for now. |
| 430 | */ |
| 431 | return PCI_ERS_RESULT_RECOVERED; |
| 432 | } |
| 433 | |
| 434 | /** |
| 435 | * \brief called when traffic can start flowing again. |
| 436 | * @param pdev Pointer to PCI device |
| 437 | * |
| 438 | * This callback is called when the error recovery driver tells us that |
| 439 | * its OK to resume normal operation. Implementation resembles the |
| 440 | * second-half of the octeon_resume routine. |
| 441 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 442 | static void liquidio_pcie_resume(struct pci_dev *pdev __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 443 | { |
| 444 | /* Nothing to be done here. */ |
| 445 | } |
| 446 | |
| 447 | #ifdef CONFIG_PM |
| 448 | /** |
| 449 | * \brief called when suspending |
| 450 | * @param pdev Pointer to PCI device |
| 451 | * @param state state to suspend to |
| 452 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 453 | static int liquidio_suspend(struct pci_dev *pdev __attribute__((unused)), |
| 454 | pm_message_t state __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 455 | { |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | /** |
| 460 | * \brief called when resuming |
| 461 | * @param pdev Pointer to PCI device |
| 462 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 463 | static int liquidio_resume(struct pci_dev *pdev __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 464 | { |
| 465 | return 0; |
| 466 | } |
| 467 | #endif |
| 468 | |
| 469 | /* For PCI-E Advanced Error Recovery (AER) Interface */ |
Julia Lawall | 166e236 | 2015-11-14 11:06:53 +0100 | [diff] [blame] | 470 | static const struct pci_error_handlers liquidio_err_handler = { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 471 | .error_detected = liquidio_pcie_error_detected, |
| 472 | .mmio_enabled = liquidio_pcie_mmio_enabled, |
| 473 | .slot_reset = liquidio_pcie_slot_reset, |
| 474 | .resume = liquidio_pcie_resume, |
| 475 | }; |
| 476 | |
| 477 | static const struct pci_device_id liquidio_pci_tbl[] = { |
| 478 | { /* 68xx */ |
| 479 | PCI_VENDOR_ID_CAVIUM, 0x91, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 |
| 480 | }, |
| 481 | { /* 66xx */ |
| 482 | PCI_VENDOR_ID_CAVIUM, 0x92, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 |
| 483 | }, |
Raghu Vatsavayi | e86b1ab | 2016-08-31 11:03:24 -0700 | [diff] [blame] | 484 | { /* 23xx pf */ |
| 485 | PCI_VENDOR_ID_CAVIUM, 0x9702, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 |
| 486 | }, |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 487 | { |
| 488 | 0, 0, 0, 0, 0, 0, 0 |
| 489 | } |
| 490 | }; |
| 491 | MODULE_DEVICE_TABLE(pci, liquidio_pci_tbl); |
| 492 | |
| 493 | static struct pci_driver liquidio_pci_driver = { |
| 494 | .name = "LiquidIO", |
| 495 | .id_table = liquidio_pci_tbl, |
| 496 | .probe = liquidio_probe, |
| 497 | .remove = liquidio_remove, |
| 498 | .err_handler = &liquidio_err_handler, /* For AER */ |
| 499 | |
| 500 | #ifdef CONFIG_PM |
| 501 | .suspend = liquidio_suspend, |
| 502 | .resume = liquidio_resume, |
| 503 | #endif |
Raghu Vatsavayi | ca6139f | 2016-11-14 15:54:40 -0800 | [diff] [blame] | 504 | #ifdef CONFIG_PCI_IOV |
| 505 | .sriov_configure = liquidio_enable_sriov, |
| 506 | #endif |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 507 | }; |
| 508 | |
| 509 | /** |
| 510 | * \brief register PCI driver |
| 511 | */ |
| 512 | static int liquidio_init_pci(void) |
| 513 | { |
| 514 | return pci_register_driver(&liquidio_pci_driver); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * \brief unregister PCI driver |
| 519 | */ |
| 520 | static void liquidio_deinit_pci(void) |
| 521 | { |
| 522 | pci_unregister_driver(&liquidio_pci_driver); |
| 523 | } |
| 524 | |
| 525 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 526 | * \brief Stop Tx queues |
| 527 | * @param netdev network device |
| 528 | */ |
| 529 | static inline void txqs_stop(struct net_device *netdev) |
| 530 | { |
| 531 | if (netif_is_multiqueue(netdev)) { |
| 532 | int i; |
| 533 | |
| 534 | for (i = 0; i < netdev->num_tx_queues; i++) |
| 535 | netif_stop_subqueue(netdev, i); |
| 536 | } else { |
| 537 | netif_stop_queue(netdev); |
| 538 | } |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * \brief Start Tx queues |
| 543 | * @param netdev network device |
| 544 | */ |
| 545 | static inline void txqs_start(struct net_device *netdev) |
| 546 | { |
| 547 | if (netif_is_multiqueue(netdev)) { |
| 548 | int i; |
| 549 | |
| 550 | for (i = 0; i < netdev->num_tx_queues; i++) |
| 551 | netif_start_subqueue(netdev, i); |
| 552 | } else { |
| 553 | netif_start_queue(netdev); |
| 554 | } |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * \brief Wake Tx queues |
| 559 | * @param netdev network device |
| 560 | */ |
| 561 | static inline void txqs_wake(struct net_device *netdev) |
| 562 | { |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 563 | struct lio *lio = GET_LIO(netdev); |
| 564 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 565 | if (netif_is_multiqueue(netdev)) { |
| 566 | int i; |
| 567 | |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 568 | for (i = 0; i < netdev->num_tx_queues; i++) { |
| 569 | int qno = lio->linfo.txpciq[i % |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 570 | lio->oct_dev->num_iqs].s.q_no; |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 571 | |
| 572 | if (__netif_subqueue_stopped(netdev, i)) { |
| 573 | INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, qno, |
| 574 | tx_restart, 1); |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 575 | netif_wake_subqueue(netdev, i); |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 576 | } |
| 577 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 578 | } else { |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 579 | INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, lio->txq, |
| 580 | tx_restart, 1); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 581 | netif_wake_queue(netdev); |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * \brief Stop Tx queue |
| 587 | * @param netdev network device |
| 588 | */ |
| 589 | static void stop_txq(struct net_device *netdev) |
| 590 | { |
| 591 | txqs_stop(netdev); |
| 592 | } |
| 593 | |
| 594 | /** |
| 595 | * \brief Start Tx queue |
| 596 | * @param netdev network device |
| 597 | */ |
| 598 | static void start_txq(struct net_device *netdev) |
| 599 | { |
| 600 | struct lio *lio = GET_LIO(netdev); |
| 601 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 602 | if (lio->linfo.link.s.link_up) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 603 | txqs_start(netdev); |
| 604 | return; |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | /** |
| 609 | * \brief Wake a queue |
| 610 | * @param netdev network device |
| 611 | * @param q which queue to wake |
| 612 | */ |
| 613 | static inline void wake_q(struct net_device *netdev, int q) |
| 614 | { |
| 615 | if (netif_is_multiqueue(netdev)) |
| 616 | netif_wake_subqueue(netdev, q); |
| 617 | else |
| 618 | netif_wake_queue(netdev); |
| 619 | } |
| 620 | |
| 621 | /** |
| 622 | * \brief Stop a queue |
| 623 | * @param netdev network device |
| 624 | * @param q which queue to stop |
| 625 | */ |
| 626 | static inline void stop_q(struct net_device *netdev, int q) |
| 627 | { |
| 628 | if (netif_is_multiqueue(netdev)) |
| 629 | netif_stop_subqueue(netdev, q); |
| 630 | else |
| 631 | netif_stop_queue(netdev); |
| 632 | } |
| 633 | |
| 634 | /** |
| 635 | * \brief Check Tx queue status, and take appropriate action |
| 636 | * @param lio per-network private data |
| 637 | * @returns 0 if full, number of queues woken up otherwise |
| 638 | */ |
| 639 | static inline int check_txq_status(struct lio *lio) |
| 640 | { |
| 641 | int ret_val = 0; |
| 642 | |
| 643 | if (netif_is_multiqueue(lio->netdev)) { |
| 644 | int numqs = lio->netdev->num_tx_queues; |
| 645 | int q, iq = 0; |
| 646 | |
| 647 | /* check each sub-queue state */ |
| 648 | for (q = 0; q < numqs; q++) { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 649 | iq = lio->linfo.txpciq[q % |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 650 | lio->oct_dev->num_iqs].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 651 | if (octnet_iq_is_full(lio->oct_dev, iq)) |
| 652 | continue; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 653 | if (__netif_subqueue_stopped(lio->netdev, q)) { |
| 654 | wake_q(lio->netdev, q); |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 655 | INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, iq, |
| 656 | tx_restart, 1); |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 657 | ret_val++; |
| 658 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 659 | } |
| 660 | } else { |
| 661 | if (octnet_iq_is_full(lio->oct_dev, lio->txq)) |
| 662 | return 0; |
| 663 | wake_q(lio->netdev, lio->txq); |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 664 | INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, lio->txq, |
| 665 | tx_restart, 1); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 666 | ret_val = 1; |
| 667 | } |
| 668 | return ret_val; |
| 669 | } |
| 670 | |
| 671 | /** |
| 672 | * Remove the node at the head of the list. The list would be empty at |
| 673 | * the end of this call if there are no more nodes in the list. |
| 674 | */ |
| 675 | static inline struct list_head *list_delete_head(struct list_head *root) |
| 676 | { |
| 677 | struct list_head *node; |
| 678 | |
| 679 | if ((root->prev == root) && (root->next == root)) |
| 680 | node = NULL; |
| 681 | else |
| 682 | node = root->next; |
| 683 | |
| 684 | if (node) |
| 685 | list_del(node); |
| 686 | |
| 687 | return node; |
| 688 | } |
| 689 | |
| 690 | /** |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 691 | * \brief Delete gather lists |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 692 | * @param lio per-network private data |
| 693 | */ |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 694 | static void delete_glists(struct lio *lio) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 695 | { |
| 696 | struct octnic_gather *g; |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 697 | int i; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 698 | |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 699 | kfree(lio->glist_lock); |
| 700 | lio->glist_lock = NULL; |
| 701 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 702 | if (!lio->glist) |
| 703 | return; |
| 704 | |
| 705 | for (i = 0; i < lio->linfo.num_txpciq; i++) { |
| 706 | do { |
| 707 | g = (struct octnic_gather *) |
| 708 | list_delete_head(&lio->glist[i]); |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 709 | if (g) |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 710 | kfree(g); |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 711 | } while (g); |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 712 | |
Felix Manlunas | 58ad319 | 2017-03-20 19:04:48 -0700 | [diff] [blame] | 713 | if (lio->glists_virt_base && lio->glists_virt_base[i] && |
| 714 | lio->glists_dma_base && lio->glists_dma_base[i]) { |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 715 | lio_dma_free(lio->oct_dev, |
| 716 | lio->glist_entry_size * lio->tx_qsize, |
| 717 | lio->glists_virt_base[i], |
| 718 | lio->glists_dma_base[i]); |
| 719 | } |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 720 | } |
| 721 | |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 722 | kfree(lio->glists_virt_base); |
| 723 | lio->glists_virt_base = NULL; |
| 724 | |
| 725 | kfree(lio->glists_dma_base); |
| 726 | lio->glists_dma_base = NULL; |
| 727 | |
| 728 | kfree(lio->glist); |
| 729 | lio->glist = NULL; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /** |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 733 | * \brief Setup gather lists |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 734 | * @param lio per-network private data |
| 735 | */ |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 736 | static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 737 | { |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 738 | int i, j; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 739 | struct octnic_gather *g; |
| 740 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 741 | lio->glist_lock = kcalloc(num_iqs, sizeof(*lio->glist_lock), |
| 742 | GFP_KERNEL); |
| 743 | if (!lio->glist_lock) |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 744 | return -ENOMEM; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 745 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 746 | lio->glist = kcalloc(num_iqs, sizeof(*lio->glist), |
| 747 | GFP_KERNEL); |
| 748 | if (!lio->glist) { |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 749 | kfree(lio->glist_lock); |
| 750 | lio->glist_lock = NULL; |
| 751 | return -ENOMEM; |
| 752 | } |
| 753 | |
| 754 | lio->glist_entry_size = |
| 755 | ROUNDUP8((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE); |
| 756 | |
| 757 | /* allocate memory to store virtual and dma base address of |
| 758 | * per glist consistent memory |
| 759 | */ |
| 760 | lio->glists_virt_base = kcalloc(num_iqs, sizeof(*lio->glists_virt_base), |
| 761 | GFP_KERNEL); |
| 762 | lio->glists_dma_base = kcalloc(num_iqs, sizeof(*lio->glists_dma_base), |
| 763 | GFP_KERNEL); |
| 764 | |
| 765 | if (!lio->glists_virt_base || !lio->glists_dma_base) { |
| 766 | delete_glists(lio); |
| 767 | return -ENOMEM; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 770 | for (i = 0; i < num_iqs; i++) { |
VSR Burru | b3ca9af | 2017-03-09 17:03:24 -0800 | [diff] [blame] | 771 | int numa_node = dev_to_node(&oct->pci_dev->dev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 772 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 773 | spin_lock_init(&lio->glist_lock[i]); |
| 774 | |
| 775 | INIT_LIST_HEAD(&lio->glist[i]); |
| 776 | |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 777 | lio->glists_virt_base[i] = |
| 778 | lio_dma_alloc(oct, |
| 779 | lio->glist_entry_size * lio->tx_qsize, |
| 780 | &lio->glists_dma_base[i]); |
| 781 | |
| 782 | if (!lio->glists_virt_base[i]) { |
| 783 | delete_glists(lio); |
| 784 | return -ENOMEM; |
| 785 | } |
| 786 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 787 | for (j = 0; j < lio->tx_qsize; j++) { |
| 788 | g = kzalloc_node(sizeof(*g), GFP_KERNEL, |
| 789 | numa_node); |
| 790 | if (!g) |
| 791 | g = kzalloc(sizeof(*g), GFP_KERNEL); |
| 792 | if (!g) |
| 793 | break; |
| 794 | |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 795 | g->sg = lio->glists_virt_base[i] + |
| 796 | (j * lio->glist_entry_size); |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 797 | |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 798 | g->sg_dma_ptr = lio->glists_dma_base[i] + |
| 799 | (j * lio->glist_entry_size); |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 800 | |
| 801 | list_add_tail(&g->list, &lio->glist[i]); |
| 802 | } |
| 803 | |
| 804 | if (j != lio->tx_qsize) { |
| 805 | delete_glists(lio); |
VSR Burru | 67e303e | 2017-03-06 18:45:59 -0800 | [diff] [blame] | 806 | return -ENOMEM; |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 807 | } |
| 808 | } |
| 809 | |
| 810 | return 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /** |
| 814 | * \brief Print link information |
| 815 | * @param netdev network device |
| 816 | */ |
| 817 | static void print_link_info(struct net_device *netdev) |
| 818 | { |
| 819 | struct lio *lio = GET_LIO(netdev); |
| 820 | |
Intiyaz Basha | d18ca7d | 2017-08-14 12:01:56 -0700 | [diff] [blame] | 821 | if (!ifstate_check(lio, LIO_IFSTATE_RESETTING) && |
| 822 | ifstate_check(lio, LIO_IFSTATE_REGISTERED)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 823 | struct oct_link_info *linfo = &lio->linfo; |
| 824 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 825 | if (linfo->link.s.link_up) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 826 | netif_info(lio, link, lio->netdev, "%d Mbps %s Duplex UP\n", |
| 827 | linfo->link.s.speed, |
| 828 | (linfo->link.s.duplex) ? "Full" : "Half"); |
| 829 | } else { |
| 830 | netif_info(lio, link, lio->netdev, "Link Down\n"); |
| 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | /** |
Raghu Vatsavayi | 7b6b6c9 | 2016-09-01 11:16:04 -0700 | [diff] [blame] | 836 | * \brief Routine to notify MTU change |
| 837 | * @param work work_struct data structure |
| 838 | */ |
| 839 | static void octnet_link_status_change(struct work_struct *work) |
| 840 | { |
| 841 | struct cavium_wk *wk = (struct cavium_wk *)work; |
| 842 | struct lio *lio = (struct lio *)wk->ctxptr; |
| 843 | |
| 844 | rtnl_lock(); |
| 845 | call_netdevice_notifiers(NETDEV_CHANGEMTU, lio->netdev); |
| 846 | rtnl_unlock(); |
| 847 | } |
| 848 | |
| 849 | /** |
| 850 | * \brief Sets up the mtu status change work |
| 851 | * @param netdev network device |
| 852 | */ |
| 853 | static inline int setup_link_status_change_wq(struct net_device *netdev) |
| 854 | { |
| 855 | struct lio *lio = GET_LIO(netdev); |
| 856 | struct octeon_device *oct = lio->oct_dev; |
| 857 | |
| 858 | lio->link_status_wq.wq = alloc_workqueue("link-status", |
| 859 | WQ_MEM_RECLAIM, 0); |
| 860 | if (!lio->link_status_wq.wq) { |
| 861 | dev_err(&oct->pci_dev->dev, "unable to create cavium link status wq\n"); |
| 862 | return -1; |
| 863 | } |
| 864 | INIT_DELAYED_WORK(&lio->link_status_wq.wk.work, |
| 865 | octnet_link_status_change); |
| 866 | lio->link_status_wq.wk.ctxptr = lio; |
| 867 | |
| 868 | return 0; |
| 869 | } |
| 870 | |
| 871 | static inline void cleanup_link_status_change_wq(struct net_device *netdev) |
| 872 | { |
| 873 | struct lio *lio = GET_LIO(netdev); |
| 874 | |
| 875 | if (lio->link_status_wq.wq) { |
| 876 | cancel_delayed_work_sync(&lio->link_status_wq.wk.work); |
| 877 | destroy_workqueue(lio->link_status_wq.wq); |
| 878 | } |
| 879 | } |
| 880 | |
| 881 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 882 | * \brief Update link status |
| 883 | * @param netdev network device |
| 884 | * @param ls link status structure |
| 885 | * |
| 886 | * Called on receipt of a link status response from the core application to |
| 887 | * update each interface's link status. |
| 888 | */ |
| 889 | static inline void update_link_status(struct net_device *netdev, |
| 890 | union oct_link_status *ls) |
| 891 | { |
| 892 | struct lio *lio = GET_LIO(netdev); |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 893 | int changed = (lio->linfo.link.u64 != ls->u64); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 894 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 895 | lio->linfo.link.u64 = ls->u64; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 896 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 897 | if ((lio->intf_open) && (changed)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 898 | print_link_info(netdev); |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 899 | lio->link_changes++; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 900 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 901 | if (lio->linfo.link.s.link_up) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 902 | netif_carrier_on(netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 903 | txqs_wake(netdev); |
| 904 | } else { |
| 905 | netif_carrier_off(netdev); |
| 906 | stop_txq(netdev); |
| 907 | } |
| 908 | } |
| 909 | } |
| 910 | |
Veerasenareddy Burru | 907aaa6 | 2017-10-23 20:33:25 -0700 | [diff] [blame] | 911 | /** |
| 912 | * lio_sync_octeon_time_cb - callback that is invoked when soft command |
| 913 | * sent by lio_sync_octeon_time() has completed successfully or failed |
| 914 | * |
| 915 | * @oct - octeon device structure |
| 916 | * @status - indicates success or failure |
| 917 | * @buf - pointer to the command that was sent to firmware |
| 918 | **/ |
| 919 | static void lio_sync_octeon_time_cb(struct octeon_device *oct, |
| 920 | u32 status, void *buf) |
| 921 | { |
| 922 | struct octeon_soft_command *sc = (struct octeon_soft_command *)buf; |
| 923 | |
| 924 | if (status) |
| 925 | dev_err(&oct->pci_dev->dev, |
| 926 | "Failed to sync time to octeon; error=%d\n", status); |
| 927 | |
| 928 | octeon_free_soft_command(oct, sc); |
| 929 | } |
| 930 | |
| 931 | /** |
| 932 | * lio_sync_octeon_time - send latest localtime to octeon firmware so that |
| 933 | * firmware will correct it's time, in case there is a time skew |
| 934 | * |
| 935 | * @work: work scheduled to send time update to octeon firmware |
| 936 | **/ |
| 937 | static void lio_sync_octeon_time(struct work_struct *work) |
| 938 | { |
| 939 | struct cavium_wk *wk = (struct cavium_wk *)work; |
| 940 | struct lio *lio = (struct lio *)wk->ctxptr; |
| 941 | struct octeon_device *oct = lio->oct_dev; |
| 942 | struct octeon_soft_command *sc; |
| 943 | struct timespec64 ts; |
| 944 | struct lio_time *lt; |
| 945 | int ret; |
| 946 | |
| 947 | sc = octeon_alloc_soft_command(oct, sizeof(struct lio_time), 0, 0); |
| 948 | if (!sc) { |
| 949 | dev_err(&oct->pci_dev->dev, |
| 950 | "Failed to sync time to octeon: soft command allocation failed\n"); |
| 951 | return; |
| 952 | } |
| 953 | |
| 954 | lt = (struct lio_time *)sc->virtdptr; |
| 955 | |
| 956 | /* Get time of the day */ |
| 957 | getnstimeofday64(&ts); |
| 958 | lt->sec = ts.tv_sec; |
| 959 | lt->nsec = ts.tv_nsec; |
| 960 | octeon_swap_8B_data((u64 *)lt, (sizeof(struct lio_time)) / 8); |
| 961 | |
| 962 | sc->iq_no = lio->linfo.txpciq[0].s.q_no; |
| 963 | octeon_prepare_soft_command(oct, sc, OPCODE_NIC, |
| 964 | OPCODE_NIC_SYNC_OCTEON_TIME, 0, 0, 0); |
| 965 | |
| 966 | sc->callback = lio_sync_octeon_time_cb; |
| 967 | sc->callback_arg = sc; |
| 968 | sc->wait_time = 1000; |
| 969 | |
| 970 | ret = octeon_send_soft_command(oct, sc); |
| 971 | if (ret == IQ_SEND_FAILED) { |
| 972 | dev_err(&oct->pci_dev->dev, |
| 973 | "Failed to sync time to octeon: failed to send soft command\n"); |
| 974 | octeon_free_soft_command(oct, sc); |
| 975 | } |
| 976 | |
| 977 | queue_delayed_work(lio->sync_octeon_time_wq.wq, |
| 978 | &lio->sync_octeon_time_wq.wk.work, |
| 979 | msecs_to_jiffies(LIO_SYNC_OCTEON_TIME_INTERVAL_MS)); |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * setup_sync_octeon_time_wq - Sets up the work to periodically update |
| 984 | * local time to octeon firmware |
| 985 | * |
| 986 | * @netdev - network device which should send time update to firmware |
| 987 | **/ |
| 988 | static inline int setup_sync_octeon_time_wq(struct net_device *netdev) |
| 989 | { |
| 990 | struct lio *lio = GET_LIO(netdev); |
| 991 | struct octeon_device *oct = lio->oct_dev; |
| 992 | |
| 993 | lio->sync_octeon_time_wq.wq = |
| 994 | alloc_workqueue("update-octeon-time", WQ_MEM_RECLAIM, 0); |
| 995 | if (!lio->sync_octeon_time_wq.wq) { |
| 996 | dev_err(&oct->pci_dev->dev, "Unable to create wq to update octeon time\n"); |
| 997 | return -1; |
| 998 | } |
| 999 | INIT_DELAYED_WORK(&lio->sync_octeon_time_wq.wk.work, |
| 1000 | lio_sync_octeon_time); |
| 1001 | lio->sync_octeon_time_wq.wk.ctxptr = lio; |
| 1002 | queue_delayed_work(lio->sync_octeon_time_wq.wq, |
| 1003 | &lio->sync_octeon_time_wq.wk.work, |
| 1004 | msecs_to_jiffies(LIO_SYNC_OCTEON_TIME_INTERVAL_MS)); |
| 1005 | |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | /** |
| 1010 | * cleanup_sync_octeon_time_wq - stop scheduling and destroy the work created |
| 1011 | * to periodically update local time to octeon firmware |
| 1012 | * |
| 1013 | * @netdev - network device which should send time update to firmware |
| 1014 | **/ |
| 1015 | static inline void cleanup_sync_octeon_time_wq(struct net_device *netdev) |
| 1016 | { |
| 1017 | struct lio *lio = GET_LIO(netdev); |
| 1018 | struct cavium_wq *time_wq = &lio->sync_octeon_time_wq; |
| 1019 | |
| 1020 | if (time_wq->wq) { |
| 1021 | cancel_delayed_work_sync(&time_wq->wk.work); |
| 1022 | destroy_workqueue(time_wq->wq); |
| 1023 | } |
| 1024 | } |
| 1025 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1026 | static struct octeon_device *get_other_octeon_device(struct octeon_device *oct) |
| 1027 | { |
| 1028 | struct octeon_device *other_oct; |
| 1029 | |
| 1030 | other_oct = lio_get_device(oct->octeon_id + 1); |
| 1031 | |
| 1032 | if (other_oct && other_oct->pci_dev) { |
| 1033 | int oct_busnum, other_oct_busnum; |
| 1034 | |
| 1035 | oct_busnum = oct->pci_dev->bus->number; |
| 1036 | other_oct_busnum = other_oct->pci_dev->bus->number; |
| 1037 | |
| 1038 | if (oct_busnum == other_oct_busnum) { |
| 1039 | int oct_slot, other_oct_slot; |
| 1040 | |
| 1041 | oct_slot = PCI_SLOT(oct->pci_dev->devfn); |
| 1042 | other_oct_slot = PCI_SLOT(other_oct->pci_dev->devfn); |
| 1043 | |
| 1044 | if (oct_slot == other_oct_slot) |
| 1045 | return other_oct; |
| 1046 | } |
| 1047 | } |
| 1048 | |
| 1049 | return NULL; |
| 1050 | } |
| 1051 | |
| 1052 | static void disable_all_vf_links(struct octeon_device *oct) |
| 1053 | { |
| 1054 | struct net_device *netdev; |
| 1055 | int max_vfs, vf, i; |
| 1056 | |
| 1057 | if (!oct) |
| 1058 | return; |
| 1059 | |
| 1060 | max_vfs = oct->sriov_info.max_vfs; |
| 1061 | |
| 1062 | for (i = 0; i < oct->ifcount; i++) { |
| 1063 | netdev = oct->props[i].netdev; |
| 1064 | if (!netdev) |
| 1065 | continue; |
| 1066 | |
| 1067 | for (vf = 0; vf < max_vfs; vf++) |
| 1068 | liquidio_set_vf_link_state(netdev, vf, |
| 1069 | IFLA_VF_LINK_STATE_DISABLE); |
| 1070 | } |
| 1071 | } |
| 1072 | |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1073 | static int liquidio_watchdog(void *param) |
| 1074 | { |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1075 | bool err_msg_was_printed[LIO_MAX_CORES]; |
| 1076 | u16 mask_of_crashed_or_stuck_cores = 0; |
| 1077 | bool all_vf_links_are_disabled = false; |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1078 | struct octeon_device *oct = param; |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1079 | struct octeon_device *other_oct; |
| 1080 | #ifdef CONFIG_MODULE_UNLOAD |
| 1081 | long refcount, vfs_referencing_pf; |
| 1082 | u64 vfs_mask1, vfs_mask2; |
| 1083 | #endif |
| 1084 | int core; |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1085 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1086 | memset(err_msg_was_printed, 0, sizeof(err_msg_was_printed)); |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1087 | |
| 1088 | while (!kthread_should_stop()) { |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1089 | /* sleep for a couple of seconds so that we don't hog the CPU */ |
| 1090 | set_current_state(TASK_INTERRUPTIBLE); |
| 1091 | schedule_timeout(msecs_to_jiffies(2000)); |
| 1092 | |
| 1093 | mask_of_crashed_or_stuck_cores = |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1094 | (u16)octeon_read_csr64(oct, CN23XX_SLI_SCRATCH2); |
| 1095 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1096 | if (!mask_of_crashed_or_stuck_cores) |
| 1097 | continue; |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1098 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1099 | WRITE_ONCE(oct->cores_crashed, true); |
| 1100 | other_oct = get_other_octeon_device(oct); |
| 1101 | if (other_oct) |
| 1102 | WRITE_ONCE(other_oct->cores_crashed, true); |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1103 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1104 | for (core = 0; core < LIO_MAX_CORES; core++) { |
| 1105 | bool core_crashed_or_got_stuck; |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1106 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1107 | core_crashed_or_got_stuck = |
| 1108 | (mask_of_crashed_or_stuck_cores |
| 1109 | >> core) & 1; |
| 1110 | |
| 1111 | if (core_crashed_or_got_stuck && |
| 1112 | !err_msg_was_printed[core]) { |
| 1113 | dev_err(&oct->pci_dev->dev, |
| 1114 | "ERROR: Octeon core %d crashed or got stuck! See oct-fwdump for details.\n", |
| 1115 | core); |
| 1116 | err_msg_was_printed[core] = true; |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1117 | } |
| 1118 | } |
| 1119 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1120 | if (all_vf_links_are_disabled) |
| 1121 | continue; |
| 1122 | |
| 1123 | disable_all_vf_links(oct); |
| 1124 | disable_all_vf_links(other_oct); |
| 1125 | all_vf_links_are_disabled = true; |
| 1126 | |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1127 | #ifdef CONFIG_MODULE_UNLOAD |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1128 | vfs_mask1 = READ_ONCE(oct->sriov_info.vf_drv_loaded_mask); |
| 1129 | vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask); |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1130 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1131 | vfs_referencing_pf = hweight64(vfs_mask1); |
| 1132 | vfs_referencing_pf += hweight64(vfs_mask2); |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1133 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1134 | refcount = module_refcount(THIS_MODULE); |
| 1135 | if (refcount >= vfs_referencing_pf) { |
| 1136 | while (vfs_referencing_pf) { |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1137 | module_put(THIS_MODULE); |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 1138 | vfs_referencing_pf--; |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | #endif |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1142 | } |
| 1143 | |
| 1144 | return 0; |
| 1145 | } |
| 1146 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1147 | /** |
| 1148 | * \brief PCI probe handler |
| 1149 | * @param pdev PCI device structure |
| 1150 | * @param ent unused |
| 1151 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 1152 | static int |
| 1153 | liquidio_probe(struct pci_dev *pdev, |
| 1154 | const struct pci_device_id *ent __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1155 | { |
| 1156 | struct octeon_device *oct_dev = NULL; |
| 1157 | struct handshake *hs; |
| 1158 | |
| 1159 | oct_dev = octeon_allocate_device(pdev->device, |
| 1160 | sizeof(struct octeon_device_priv)); |
| 1161 | if (!oct_dev) { |
| 1162 | dev_err(&pdev->dev, "Unable to allocate device\n"); |
| 1163 | return -ENOMEM; |
| 1164 | } |
| 1165 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1166 | if (pdev->device == OCTEON_CN23XX_PF_VID) |
| 1167 | oct_dev->msix_on = LIO_FLAG_MSIX_ENABLED; |
| 1168 | |
Intiyaz Basha | aa69ff9 | 2017-08-11 11:22:09 -0700 | [diff] [blame] | 1169 | /* Enable PTP for 6XXX Device */ |
| 1170 | if (((pdev->device == OCTEON_CN66XX) || |
| 1171 | (pdev->device == OCTEON_CN68XX))) |
| 1172 | oct_dev->ptp_enable = true; |
| 1173 | else |
| 1174 | oct_dev->ptp_enable = false; |
| 1175 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1176 | dev_info(&pdev->dev, "Initializing device %x:%x.\n", |
| 1177 | (u32)pdev->vendor, (u32)pdev->device); |
| 1178 | |
| 1179 | /* Assign octeon_device for this device to the private data area. */ |
| 1180 | pci_set_drvdata(pdev, oct_dev); |
| 1181 | |
| 1182 | /* set linux specific device pointer */ |
| 1183 | oct_dev->pci_dev = (void *)pdev; |
| 1184 | |
| 1185 | hs = &handshake[oct_dev->octeon_id]; |
| 1186 | init_completion(&hs->init); |
| 1187 | init_completion(&hs->started); |
| 1188 | hs->pci_dev = pdev; |
| 1189 | |
| 1190 | if (oct_dev->octeon_id == 0) |
| 1191 | /* first LiquidIO NIC is detected */ |
| 1192 | complete(&first_stage); |
| 1193 | |
| 1194 | if (octeon_device_init(oct_dev)) { |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1195 | complete(&hs->init); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1196 | liquidio_remove(pdev); |
| 1197 | return -ENOMEM; |
| 1198 | } |
| 1199 | |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1200 | if (OCTEON_CN23XX_PF(oct_dev)) { |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1201 | u8 bus, device, function; |
| 1202 | |
Felix Manlunas | 392209f | 2017-10-25 18:04:56 -0700 | [diff] [blame] | 1203 | if (atomic_read(oct_dev->adapter_refcount) == 1) { |
| 1204 | /* Each NIC gets one watchdog kernel thread. The first |
| 1205 | * PF (of each NIC) that gets pci_driver->probe()'d |
| 1206 | * creates that thread. |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1207 | */ |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1208 | bus = pdev->bus->number; |
| 1209 | device = PCI_SLOT(pdev->devfn); |
| 1210 | function = PCI_FUNC(pdev->devfn); |
| 1211 | oct_dev->watchdog_task = kthread_create( |
| 1212 | liquidio_watchdog, oct_dev, |
| 1213 | "liowd/%02hhx:%02hhx.%hhx", bus, device, function); |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1214 | if (!IS_ERR(oct_dev->watchdog_task)) { |
| 1215 | wake_up_process(oct_dev->watchdog_task); |
| 1216 | } else { |
| 1217 | oct_dev->watchdog_task = NULL; |
| 1218 | dev_err(&oct_dev->pci_dev->dev, |
| 1219 | "failed to create kernel_thread\n"); |
| 1220 | liquidio_remove(pdev); |
| 1221 | return -1; |
| 1222 | } |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1223 | } |
| 1224 | } |
| 1225 | |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 1226 | oct_dev->rx_pause = 1; |
| 1227 | oct_dev->tx_pause = 1; |
| 1228 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1229 | dev_dbg(&oct_dev->pci_dev->dev, "Device is ready\n"); |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 1234 | static bool fw_type_is_auto(void) |
Felix Manlunas | 7cc61db | 2017-03-23 13:26:28 -0700 | [diff] [blame] | 1235 | { |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 1236 | return strncmp(fw_type, LIO_FW_NAME_TYPE_AUTO, |
| 1237 | sizeof(LIO_FW_NAME_TYPE_AUTO)) == 0; |
Felix Manlunas | 7cc61db | 2017-03-23 13:26:28 -0700 | [diff] [blame] | 1238 | } |
| 1239 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1240 | /** |
Rick Farrington | 7053535 | 2017-08-17 23:11:25 -0700 | [diff] [blame] | 1241 | * \brief PCI FLR for each Octeon device. |
| 1242 | * @param oct octeon device |
| 1243 | */ |
| 1244 | static void octeon_pci_flr(struct octeon_device *oct) |
| 1245 | { |
| 1246 | int rc; |
| 1247 | |
| 1248 | pci_save_state(oct->pci_dev); |
| 1249 | |
| 1250 | pci_cfg_access_lock(oct->pci_dev); |
| 1251 | |
| 1252 | /* Quiesce the device completely */ |
| 1253 | pci_write_config_word(oct->pci_dev, PCI_COMMAND, |
| 1254 | PCI_COMMAND_INTX_DISABLE); |
| 1255 | |
| 1256 | rc = __pci_reset_function_locked(oct->pci_dev); |
| 1257 | |
| 1258 | if (rc != 0) |
| 1259 | dev_err(&oct->pci_dev->dev, "Error %d resetting PCI function %d\n", |
| 1260 | rc, oct->pf_num); |
| 1261 | |
| 1262 | pci_cfg_access_unlock(oct->pci_dev); |
| 1263 | |
| 1264 | pci_restore_state(oct->pci_dev); |
| 1265 | } |
| 1266 | |
| 1267 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1268 | *\brief Destroy resources associated with octeon device |
| 1269 | * @param pdev PCI device structure |
| 1270 | * @param ent unused |
| 1271 | */ |
| 1272 | static void octeon_destroy_resources(struct octeon_device *oct) |
| 1273 | { |
Rick Farrington | e1e3ce6 | 2017-05-16 11:14:50 -0700 | [diff] [blame] | 1274 | int i, refcount; |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1275 | struct msix_entry *msix_entries; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1276 | struct octeon_device_priv *oct_priv = |
| 1277 | (struct octeon_device_priv *)oct->priv; |
| 1278 | |
| 1279 | struct handshake *hs; |
| 1280 | |
| 1281 | switch (atomic_read(&oct->status)) { |
| 1282 | case OCT_DEV_RUNNING: |
| 1283 | case OCT_DEV_CORE_OK: |
| 1284 | |
| 1285 | /* No more instructions will be forwarded. */ |
| 1286 | atomic_set(&oct->status, OCT_DEV_IN_RESET); |
| 1287 | |
| 1288 | oct->app_mode = CVM_DRV_INVALID_APP; |
| 1289 | dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n", |
| 1290 | lio_get_state_string(&oct->status)); |
| 1291 | |
| 1292 | schedule_timeout_uninterruptible(HZ / 10); |
| 1293 | |
| 1294 | /* fallthrough */ |
| 1295 | case OCT_DEV_HOST_OK: |
| 1296 | |
| 1297 | /* fallthrough */ |
| 1298 | case OCT_DEV_CONSOLE_INIT_DONE: |
| 1299 | /* Remove any consoles */ |
| 1300 | octeon_remove_consoles(oct); |
| 1301 | |
| 1302 | /* fallthrough */ |
| 1303 | case OCT_DEV_IO_QUEUES_DONE: |
| 1304 | if (wait_for_pending_requests(oct)) |
| 1305 | dev_err(&oct->pci_dev->dev, "There were pending requests\n"); |
| 1306 | |
| 1307 | if (lio_wait_for_instr_fetch(oct)) |
| 1308 | dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n"); |
| 1309 | |
| 1310 | /* Disable the input and output queues now. No more packets will |
| 1311 | * arrive from Octeon, but we should wait for all packet |
| 1312 | * processing to finish. |
| 1313 | */ |
| 1314 | oct->fn_list.disable_io_queues(oct); |
| 1315 | |
| 1316 | if (lio_wait_for_oq_pkts(oct)) |
| 1317 | dev_err(&oct->pci_dev->dev, "OQ had pending packets\n"); |
| 1318 | |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1319 | /* fallthrough */ |
| 1320 | case OCT_DEV_INTR_SET_DONE: |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1321 | /* Disable interrupts */ |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1322 | oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1323 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1324 | if (oct->msix_on) { |
| 1325 | msix_entries = (struct msix_entry *)oct->msix_entries; |
| 1326 | for (i = 0; i < oct->num_msix_irqs - 1; i++) { |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 1327 | if (oct->ioq_vector[i].vector) { |
| 1328 | /* clear the affinity_cpumask */ |
| 1329 | irq_set_affinity_hint( |
| 1330 | msix_entries[i].vector, |
| 1331 | NULL); |
| 1332 | free_irq(msix_entries[i].vector, |
| 1333 | &oct->ioq_vector[i]); |
| 1334 | oct->ioq_vector[i].vector = 0; |
| 1335 | } |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1336 | } |
| 1337 | /* non-iov vector's argument is oct struct */ |
| 1338 | free_irq(msix_entries[i].vector, oct); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1339 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1340 | pci_disable_msix(oct->pci_dev); |
| 1341 | kfree(oct->msix_entries); |
| 1342 | oct->msix_entries = NULL; |
| 1343 | } else { |
| 1344 | /* Release the interrupt line */ |
| 1345 | free_irq(oct->pci_dev->irq, oct); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1346 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1347 | if (oct->flags & LIO_FLAG_MSI_ENABLED) |
| 1348 | pci_disable_msi(oct->pci_dev); |
| 1349 | } |
| 1350 | |
Rick Farrington | 0c88a76 | 2017-03-13 12:58:04 -0700 | [diff] [blame] | 1351 | kfree(oct->irq_name_storage); |
| 1352 | oct->irq_name_storage = NULL; |
| 1353 | |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1354 | /* fallthrough */ |
| 1355 | case OCT_DEV_MSIX_ALLOC_VECTOR_DONE: |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1356 | if (OCTEON_CN23XX_PF(oct)) |
| 1357 | octeon_free_ioq_vector(oct); |
Raghu Vatsavayi | 5d65556 | 2016-11-14 15:54:42 -0800 | [diff] [blame] | 1358 | |
| 1359 | /* fallthrough */ |
| 1360 | case OCT_DEV_MBOX_SETUP_DONE: |
| 1361 | if (OCTEON_CN23XX_PF(oct)) |
| 1362 | oct->fn_list.free_mbox(oct); |
| 1363 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1364 | /* fallthrough */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1365 | case OCT_DEV_IN_RESET: |
| 1366 | case OCT_DEV_DROQ_INIT_DONE: |
Raghu Vatsavayi | 763185a | 2016-11-14 15:54:45 -0800 | [diff] [blame] | 1367 | /* Wait for any pending operations */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1368 | mdelay(100); |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 1369 | for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) { |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 1370 | if (!(oct->io_qmask.oq & BIT_ULL(i))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1371 | continue; |
| 1372 | octeon_delete_droq(oct, i); |
| 1373 | } |
| 1374 | |
| 1375 | /* Force any pending handshakes to complete */ |
| 1376 | for (i = 0; i < MAX_OCTEON_DEVICES; i++) { |
| 1377 | hs = &handshake[i]; |
| 1378 | |
| 1379 | if (hs->pci_dev) { |
| 1380 | handshake[oct->octeon_id].init_ok = 0; |
| 1381 | complete(&handshake[oct->octeon_id].init); |
| 1382 | handshake[oct->octeon_id].started_ok = 0; |
| 1383 | complete(&handshake[oct->octeon_id].started); |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | /* fallthrough */ |
| 1388 | case OCT_DEV_RESP_LIST_INIT_DONE: |
| 1389 | octeon_delete_response_list(oct); |
| 1390 | |
| 1391 | /* fallthrough */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1392 | case OCT_DEV_INSTR_QUEUE_INIT_DONE: |
Raghu Vatsavayi | 63da840 | 2016-06-21 22:53:03 -0700 | [diff] [blame] | 1393 | for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) { |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 1394 | if (!(oct->io_qmask.iq & BIT_ULL(i))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1395 | continue; |
| 1396 | octeon_delete_instr_queue(oct, i); |
| 1397 | } |
Raghu Vatsavayi | ca6139f | 2016-11-14 15:54:40 -0800 | [diff] [blame] | 1398 | #ifdef CONFIG_PCI_IOV |
| 1399 | if (oct->sriov_info.sriov_enabled) |
| 1400 | pci_disable_sriov(oct->pci_dev); |
| 1401 | #endif |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 1402 | /* fallthrough */ |
| 1403 | case OCT_DEV_SC_BUFF_POOL_INIT_DONE: |
| 1404 | octeon_free_sc_buffer_pool(oct); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1405 | |
| 1406 | /* fallthrough */ |
| 1407 | case OCT_DEV_DISPATCH_INIT_DONE: |
| 1408 | octeon_delete_dispatch_list(oct); |
| 1409 | cancel_delayed_work_sync(&oct->nic_poll_work.work); |
| 1410 | |
| 1411 | /* fallthrough */ |
| 1412 | case OCT_DEV_PCI_MAP_DONE: |
Rick Farrington | e1e3ce6 | 2017-05-16 11:14:50 -0700 | [diff] [blame] | 1413 | refcount = octeon_deregister_device(oct); |
| 1414 | |
Rick Farrington | 7053535 | 2017-08-17 23:11:25 -0700 | [diff] [blame] | 1415 | /* Soft reset the octeon device before exiting. |
| 1416 | * However, if fw was loaded from card (i.e. autoboot), |
| 1417 | * perform an FLR instead. |
| 1418 | * Implementation note: only soft-reset the device |
| 1419 | * if it is a CN6XXX OR the LAST CN23XX device. |
| 1420 | */ |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 1421 | if (atomic_read(oct->adapter_fw_state) == FW_IS_PRELOADED) |
Rick Farrington | 7053535 | 2017-08-17 23:11:25 -0700 | [diff] [blame] | 1422 | octeon_pci_flr(oct); |
| 1423 | else if (OCTEON_CN6XXX(oct) || !refcount) |
| 1424 | oct->fn_list.soft_reset(oct); |
Raghu Vatsavayi | 60b48c5 | 2016-06-21 22:53:09 -0700 | [diff] [blame] | 1425 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1426 | octeon_unmap_pci_barx(oct, 0); |
| 1427 | octeon_unmap_pci_barx(oct, 1); |
| 1428 | |
| 1429 | /* fallthrough */ |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1430 | case OCT_DEV_PCI_ENABLE_DONE: |
| 1431 | pci_clear_master(oct->pci_dev); |
Raghu Vatsavayi | 60b48c5 | 2016-06-21 22:53:09 -0700 | [diff] [blame] | 1432 | /* Disable the device, releasing the PCI INT */ |
| 1433 | pci_disable_device(oct->pci_dev); |
| 1434 | |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1435 | /* fallthrough */ |
| 1436 | case OCT_DEV_BEGIN_STATE: |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1437 | /* Nothing to be done here either */ |
| 1438 | break; |
Raghu Vatsavayi | a2c64b6 | 2016-07-03 13:56:55 -0700 | [diff] [blame] | 1439 | } /* end switch (oct->status) */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1440 | |
| 1441 | tasklet_kill(&oct_priv->droq_tasklet); |
| 1442 | } |
| 1443 | |
| 1444 | /** |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1445 | * \brief Callback for rx ctrl |
| 1446 | * @param status status of request |
| 1447 | * @param buf pointer to resp structure |
| 1448 | */ |
| 1449 | static void rx_ctl_callback(struct octeon_device *oct, |
| 1450 | u32 status, |
| 1451 | void *buf) |
| 1452 | { |
| 1453 | struct octeon_soft_command *sc = (struct octeon_soft_command *)buf; |
| 1454 | struct liquidio_rx_ctl_context *ctx; |
| 1455 | |
| 1456 | ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr; |
| 1457 | |
| 1458 | oct = lio_get_device(ctx->octeon_id); |
| 1459 | if (status) |
| 1460 | dev_err(&oct->pci_dev->dev, "rx ctl instruction failed. Status: %llx\n", |
| 1461 | CVM_CAST64(status)); |
| 1462 | WRITE_ONCE(ctx->cond, 1); |
| 1463 | |
| 1464 | /* This barrier is required to be sure that the response has been |
| 1465 | * written fully before waking up the handler |
| 1466 | */ |
| 1467 | wmb(); |
| 1468 | |
| 1469 | wake_up_interruptible(&ctx->wc); |
| 1470 | } |
| 1471 | |
| 1472 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1473 | * \brief Send Rx control command |
| 1474 | * @param lio per-network private data |
| 1475 | * @param start_stop whether to start or stop |
| 1476 | */ |
| 1477 | static void send_rx_ctrl_cmd(struct lio *lio, int start_stop) |
| 1478 | { |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1479 | struct octeon_soft_command *sc; |
| 1480 | struct liquidio_rx_ctl_context *ctx; |
| 1481 | union octnet_cmd *ncmd; |
| 1482 | int ctx_size = sizeof(struct liquidio_rx_ctl_context); |
| 1483 | struct octeon_device *oct = (struct octeon_device *)lio->oct_dev; |
| 1484 | int retval; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1485 | |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1486 | if (oct->props[lio->ifidx].rx_on == start_stop) |
| 1487 | return; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1488 | |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1489 | sc = (struct octeon_soft_command *) |
| 1490 | octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE, |
| 1491 | 16, ctx_size); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1492 | |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1493 | ncmd = (union octnet_cmd *)sc->virtdptr; |
| 1494 | ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr; |
| 1495 | |
| 1496 | WRITE_ONCE(ctx->cond, 0); |
| 1497 | ctx->octeon_id = lio_get_device_id(oct); |
| 1498 | init_waitqueue_head(&ctx->wc); |
| 1499 | |
| 1500 | ncmd->u64 = 0; |
| 1501 | ncmd->s.cmd = OCTNET_CMD_RX_CTL; |
| 1502 | ncmd->s.param1 = start_stop; |
| 1503 | |
| 1504 | octeon_swap_8B_data((u64 *)ncmd, (OCTNET_CMD_SIZE >> 3)); |
| 1505 | |
| 1506 | sc->iq_no = lio->linfo.txpciq[0].s.q_no; |
| 1507 | |
| 1508 | octeon_prepare_soft_command(oct, sc, OPCODE_NIC, |
| 1509 | OPCODE_NIC_CMD, 0, 0, 0); |
| 1510 | |
| 1511 | sc->callback = rx_ctl_callback; |
| 1512 | sc->callback_arg = sc; |
| 1513 | sc->wait_time = 5000; |
| 1514 | |
| 1515 | retval = octeon_send_soft_command(oct, sc); |
| 1516 | if (retval == IQ_SEND_FAILED) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1517 | netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n"); |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1518 | } else { |
| 1519 | /* Sleep on a wait queue till the cond flag indicates that the |
| 1520 | * response arrived or timed-out. |
| 1521 | */ |
| 1522 | if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) |
| 1523 | return; |
| 1524 | oct->props[lio->ifidx].rx_on = start_stop; |
| 1525 | } |
| 1526 | |
| 1527 | octeon_free_soft_command(oct, sc); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | /** |
| 1531 | * \brief Destroy NIC device interface |
| 1532 | * @param oct octeon device |
| 1533 | * @param ifidx which interface to destroy |
| 1534 | * |
| 1535 | * Cleanup associated with each interface for an Octeon device when NIC |
| 1536 | * module is being unloaded or if initialization fails during load. |
| 1537 | */ |
| 1538 | static void liquidio_destroy_nic_device(struct octeon_device *oct, int ifidx) |
| 1539 | { |
| 1540 | struct net_device *netdev = oct->props[ifidx].netdev; |
| 1541 | struct lio *lio; |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 1542 | struct napi_struct *napi, *n; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1543 | |
| 1544 | if (!netdev) { |
| 1545 | dev_err(&oct->pci_dev->dev, "%s No netdevice ptr for index %d\n", |
| 1546 | __func__, ifidx); |
| 1547 | return; |
| 1548 | } |
| 1549 | |
| 1550 | lio = GET_LIO(netdev); |
| 1551 | |
| 1552 | dev_dbg(&oct->pci_dev->dev, "NIC device cleanup\n"); |
| 1553 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1554 | if (atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 1555 | liquidio_stop(netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1556 | |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 1557 | if (oct->props[lio->ifidx].napi_enabled == 1) { |
| 1558 | list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) |
| 1559 | napi_disable(napi); |
| 1560 | |
| 1561 | oct->props[lio->ifidx].napi_enabled = 0; |
Raghu Vatsavayi | 7b6b6c9 | 2016-09-01 11:16:04 -0700 | [diff] [blame] | 1562 | |
| 1563 | if (OCTEON_CN23XX_PF(oct)) |
| 1564 | oct->droq[0]->ops.poll_mode = 0; |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
Intiyaz Basha | 42013e9 | 2017-08-08 19:34:28 -0700 | [diff] [blame] | 1567 | /* Delete NAPI */ |
| 1568 | list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) |
| 1569 | netif_napi_del(napi); |
| 1570 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1571 | if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED) |
| 1572 | unregister_netdev(netdev); |
| 1573 | |
Veerasenareddy Burru | 907aaa6 | 2017-10-23 20:33:25 -0700 | [diff] [blame] | 1574 | cleanup_sync_octeon_time_wq(netdev); |
Raghu Vatsavayi | 7b6b6c9 | 2016-09-01 11:16:04 -0700 | [diff] [blame] | 1575 | cleanup_link_status_change_wq(netdev); |
| 1576 | |
Satanand Burla | 031d4f1 | 2017-03-22 11:31:13 -0700 | [diff] [blame] | 1577 | cleanup_rx_oom_poll_fn(netdev); |
| 1578 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 1579 | delete_glists(lio); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1580 | |
| 1581 | free_netdev(netdev); |
| 1582 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 1583 | oct->props[ifidx].gmxport = -1; |
| 1584 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1585 | oct->props[ifidx].netdev = NULL; |
| 1586 | } |
| 1587 | |
| 1588 | /** |
| 1589 | * \brief Stop complete NIC functionality |
| 1590 | * @param oct octeon device |
| 1591 | */ |
| 1592 | static int liquidio_stop_nic_module(struct octeon_device *oct) |
| 1593 | { |
| 1594 | int i, j; |
| 1595 | struct lio *lio; |
| 1596 | |
| 1597 | dev_dbg(&oct->pci_dev->dev, "Stopping network interfaces\n"); |
| 1598 | if (!oct->ifcount) { |
| 1599 | dev_err(&oct->pci_dev->dev, "Init for Octeon was not completed\n"); |
| 1600 | return 1; |
| 1601 | } |
| 1602 | |
Raghu Vatsavayi | 6044188 | 2016-06-21 22:53:08 -0700 | [diff] [blame] | 1603 | spin_lock_bh(&oct->cmd_resp_wqlock); |
| 1604 | oct->cmd_resp_state = OCT_DRV_OFFLINE; |
| 1605 | spin_unlock_bh(&oct->cmd_resp_wqlock); |
| 1606 | |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 1607 | lio_vf_rep_destroy(oct); |
| 1608 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1609 | for (i = 0; i < oct->ifcount; i++) { |
| 1610 | lio = GET_LIO(oct->props[i].netdev); |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 1611 | for (j = 0; j < oct->num_oqs; j++) |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 1612 | octeon_unregister_droq_ops(oct, |
| 1613 | lio->linfo.rxpciq[j].s.q_no); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1614 | } |
| 1615 | |
| 1616 | for (i = 0; i < oct->ifcount; i++) |
| 1617 | liquidio_destroy_nic_device(oct, i); |
| 1618 | |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 1619 | if (oct->devlink) { |
| 1620 | devlink_unregister(oct->devlink); |
| 1621 | devlink_free(oct->devlink); |
| 1622 | oct->devlink = NULL; |
| 1623 | } |
| 1624 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1625 | dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n"); |
| 1626 | return 0; |
| 1627 | } |
| 1628 | |
| 1629 | /** |
| 1630 | * \brief Cleans up resources at unload time |
| 1631 | * @param pdev PCI device structure |
| 1632 | */ |
| 1633 | static void liquidio_remove(struct pci_dev *pdev) |
| 1634 | { |
| 1635 | struct octeon_device *oct_dev = pci_get_drvdata(pdev); |
| 1636 | |
| 1637 | dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n"); |
| 1638 | |
Raghu Vatsavayi | 9ff1a9b | 2016-09-01 11:16:09 -0700 | [diff] [blame] | 1639 | if (oct_dev->watchdog_task) |
| 1640 | kthread_stop(oct_dev->watchdog_task); |
| 1641 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1642 | if (oct_dev->app_mode && (oct_dev->app_mode == CVM_DRV_NIC_APP)) |
| 1643 | liquidio_stop_nic_module(oct_dev); |
| 1644 | |
| 1645 | /* Reset the octeon device and cleanup all memory allocated for |
| 1646 | * the octeon device by driver. |
| 1647 | */ |
| 1648 | octeon_destroy_resources(oct_dev); |
| 1649 | |
| 1650 | dev_info(&oct_dev->pci_dev->dev, "Device removed\n"); |
| 1651 | |
| 1652 | /* This octeon device has been removed. Update the global |
| 1653 | * data structure to reflect this. Free the device structure. |
| 1654 | */ |
| 1655 | octeon_free_device_mem(oct_dev); |
| 1656 | } |
| 1657 | |
| 1658 | /** |
| 1659 | * \brief Identify the Octeon device and to map the BAR address space |
| 1660 | * @param oct octeon device |
| 1661 | */ |
| 1662 | static int octeon_chip_specific_setup(struct octeon_device *oct) |
| 1663 | { |
| 1664 | u32 dev_id, rev_id; |
| 1665 | int ret = 1; |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1666 | char *s; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1667 | |
| 1668 | pci_read_config_dword(oct->pci_dev, 0, &dev_id); |
| 1669 | pci_read_config_dword(oct->pci_dev, 8, &rev_id); |
| 1670 | oct->rev_id = rev_id & 0xff; |
| 1671 | |
| 1672 | switch (dev_id) { |
| 1673 | case OCTEON_CN68XX_PCIID: |
| 1674 | oct->chip_id = OCTEON_CN68XX; |
| 1675 | ret = lio_setup_cn68xx_octeon_device(oct); |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1676 | s = "CN68XX"; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1677 | break; |
| 1678 | |
| 1679 | case OCTEON_CN66XX_PCIID: |
| 1680 | oct->chip_id = OCTEON_CN66XX; |
| 1681 | ret = lio_setup_cn66xx_octeon_device(oct); |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1682 | s = "CN66XX"; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1683 | break; |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1684 | |
Raghu Vatsavayi | 72c0091 | 2016-08-31 11:03:25 -0700 | [diff] [blame] | 1685 | case OCTEON_CN23XX_PCIID_PF: |
| 1686 | oct->chip_id = OCTEON_CN23XX_PF_VID; |
| 1687 | ret = setup_cn23xx_octeon_pf_device(oct); |
Rick Farrington | 0c45d7f | 2017-08-18 18:21:49 -0700 | [diff] [blame] | 1688 | if (ret) |
| 1689 | break; |
Derek Chickles | cf19a8c | 2017-08-01 15:05:07 -0700 | [diff] [blame] | 1690 | #ifdef CONFIG_PCI_IOV |
| 1691 | if (!ret) |
| 1692 | pci_sriov_set_totalvfs(oct->pci_dev, |
| 1693 | oct->sriov_info.max_vfs); |
| 1694 | #endif |
Raghu Vatsavayi | 72c0091 | 2016-08-31 11:03:25 -0700 | [diff] [blame] | 1695 | s = "CN23XX"; |
| 1696 | break; |
| 1697 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1698 | default: |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1699 | s = "?"; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1700 | dev_err(&oct->pci_dev->dev, "Unknown device found (dev_id: %x)\n", |
| 1701 | dev_id); |
| 1702 | } |
| 1703 | |
| 1704 | if (!ret) |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1705 | dev_info(&oct->pci_dev->dev, "%s PASS%d.%d %s Version: %s\n", s, |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1706 | OCTEON_MAJOR_REV(oct), |
| 1707 | OCTEON_MINOR_REV(oct), |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 1708 | octeon_get_conf(oct)->card_name, |
| 1709 | LIQUIDIO_VERSION); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1710 | |
| 1711 | return ret; |
| 1712 | } |
| 1713 | |
| 1714 | /** |
| 1715 | * \brief PCI initialization for each Octeon device. |
| 1716 | * @param oct octeon device |
| 1717 | */ |
| 1718 | static int octeon_pci_os_setup(struct octeon_device *oct) |
| 1719 | { |
| 1720 | /* setup PCI stuff first */ |
| 1721 | if (pci_enable_device(oct->pci_dev)) { |
| 1722 | dev_err(&oct->pci_dev->dev, "pci_enable_device failed\n"); |
| 1723 | return 1; |
| 1724 | } |
| 1725 | |
| 1726 | if (dma_set_mask_and_coherent(&oct->pci_dev->dev, DMA_BIT_MASK(64))) { |
| 1727 | dev_err(&oct->pci_dev->dev, "Unexpected DMA device capability\n"); |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 1728 | pci_disable_device(oct->pci_dev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1729 | return 1; |
| 1730 | } |
| 1731 | |
| 1732 | /* Enable PCI DMA Master. */ |
| 1733 | pci_set_master(oct->pci_dev); |
| 1734 | |
| 1735 | return 0; |
| 1736 | } |
| 1737 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 1738 | static inline int skb_iq(struct lio *lio, struct sk_buff *skb) |
| 1739 | { |
| 1740 | int q = 0; |
| 1741 | |
| 1742 | if (netif_is_multiqueue(lio->netdev)) |
| 1743 | q = skb->queue_mapping % lio->linfo.num_txpciq; |
| 1744 | |
| 1745 | return q; |
| 1746 | } |
| 1747 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1748 | /** |
| 1749 | * \brief Check Tx queue state for a given network buffer |
| 1750 | * @param lio per-network private data |
| 1751 | * @param skb network buffer |
| 1752 | */ |
| 1753 | static inline int check_txq_state(struct lio *lio, struct sk_buff *skb) |
| 1754 | { |
| 1755 | int q = 0, iq = 0; |
| 1756 | |
| 1757 | if (netif_is_multiqueue(lio->netdev)) { |
| 1758 | q = skb->queue_mapping; |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 1759 | iq = lio->linfo.txpciq[(q % lio->oct_dev->num_iqs)].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1760 | } else { |
| 1761 | iq = lio->txq; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 1762 | q = iq; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1763 | } |
| 1764 | |
| 1765 | if (octnet_iq_is_full(lio->oct_dev, iq)) |
| 1766 | return 0; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 1767 | |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 1768 | if (__netif_subqueue_stopped(lio->netdev, q)) { |
| 1769 | INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, iq, tx_restart, 1); |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 1770 | wake_q(lio->netdev, q); |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 1771 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1772 | return 1; |
| 1773 | } |
| 1774 | |
| 1775 | /** |
| 1776 | * \brief Unmap and free network buffer |
| 1777 | * @param buf buffer |
| 1778 | */ |
| 1779 | static void free_netbuf(void *buf) |
| 1780 | { |
| 1781 | struct sk_buff *skb; |
| 1782 | struct octnet_buf_free_info *finfo; |
| 1783 | struct lio *lio; |
| 1784 | |
| 1785 | finfo = (struct octnet_buf_free_info *)buf; |
| 1786 | skb = finfo->skb; |
| 1787 | lio = finfo->lio; |
| 1788 | |
| 1789 | dma_unmap_single(&lio->oct_dev->pci_dev->dev, finfo->dptr, skb->len, |
| 1790 | DMA_TO_DEVICE); |
| 1791 | |
| 1792 | check_txq_state(lio, skb); |
| 1793 | |
Raghu Vatsavayi | cabeb13 | 2016-06-14 16:54:47 -0700 | [diff] [blame] | 1794 | tx_buffer_free(skb); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | /** |
| 1798 | * \brief Unmap and free gather buffer |
| 1799 | * @param buf buffer |
| 1800 | */ |
| 1801 | static void free_netsgbuf(void *buf) |
| 1802 | { |
| 1803 | struct octnet_buf_free_info *finfo; |
| 1804 | struct sk_buff *skb; |
| 1805 | struct lio *lio; |
| 1806 | struct octnic_gather *g; |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 1807 | int i, frags, iq; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1808 | |
| 1809 | finfo = (struct octnet_buf_free_info *)buf; |
| 1810 | skb = finfo->skb; |
| 1811 | lio = finfo->lio; |
| 1812 | g = finfo->g; |
| 1813 | frags = skb_shinfo(skb)->nr_frags; |
| 1814 | |
| 1815 | dma_unmap_single(&lio->oct_dev->pci_dev->dev, |
| 1816 | g->sg[0].ptr[0], (skb->len - skb->data_len), |
| 1817 | DMA_TO_DEVICE); |
| 1818 | |
| 1819 | i = 1; |
| 1820 | while (frags--) { |
| 1821 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1822 | |
| 1823 | pci_unmap_page((lio->oct_dev)->pci_dev, |
| 1824 | g->sg[(i >> 2)].ptr[(i & 3)], |
| 1825 | frag->size, DMA_TO_DEVICE); |
| 1826 | i++; |
| 1827 | } |
| 1828 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 1829 | iq = skb_iq(lio, skb); |
| 1830 | spin_lock(&lio->glist_lock[iq]); |
| 1831 | list_add_tail(&g->list, &lio->glist[iq]); |
| 1832 | spin_unlock(&lio->glist_lock[iq]); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1833 | |
| 1834 | check_txq_state(lio, skb); /* mq support: sub-queue state check */ |
| 1835 | |
Raghu Vatsavayi | cabeb13 | 2016-06-14 16:54:47 -0700 | [diff] [blame] | 1836 | tx_buffer_free(skb); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1837 | } |
| 1838 | |
| 1839 | /** |
| 1840 | * \brief Unmap and free gather buffer with response |
| 1841 | * @param buf buffer |
| 1842 | */ |
| 1843 | static void free_netsgbuf_with_resp(void *buf) |
| 1844 | { |
| 1845 | struct octeon_soft_command *sc; |
| 1846 | struct octnet_buf_free_info *finfo; |
| 1847 | struct sk_buff *skb; |
| 1848 | struct lio *lio; |
| 1849 | struct octnic_gather *g; |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 1850 | int i, frags, iq; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1851 | |
| 1852 | sc = (struct octeon_soft_command *)buf; |
| 1853 | skb = (struct sk_buff *)sc->callback_arg; |
| 1854 | finfo = (struct octnet_buf_free_info *)&skb->cb; |
| 1855 | |
| 1856 | lio = finfo->lio; |
| 1857 | g = finfo->g; |
| 1858 | frags = skb_shinfo(skb)->nr_frags; |
| 1859 | |
| 1860 | dma_unmap_single(&lio->oct_dev->pci_dev->dev, |
| 1861 | g->sg[0].ptr[0], (skb->len - skb->data_len), |
| 1862 | DMA_TO_DEVICE); |
| 1863 | |
| 1864 | i = 1; |
| 1865 | while (frags--) { |
| 1866 | struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1]; |
| 1867 | |
| 1868 | pci_unmap_page((lio->oct_dev)->pci_dev, |
| 1869 | g->sg[(i >> 2)].ptr[(i & 3)], |
| 1870 | frag->size, DMA_TO_DEVICE); |
| 1871 | i++; |
| 1872 | } |
| 1873 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 1874 | iq = skb_iq(lio, skb); |
| 1875 | |
| 1876 | spin_lock(&lio->glist_lock[iq]); |
| 1877 | list_add_tail(&g->list, &lio->glist[iq]); |
| 1878 | spin_unlock(&lio->glist_lock[iq]); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1879 | |
| 1880 | /* Don't free the skb yet */ |
| 1881 | |
| 1882 | check_txq_state(lio, skb); |
| 1883 | } |
| 1884 | |
| 1885 | /** |
| 1886 | * \brief Adjust ptp frequency |
| 1887 | * @param ptp PTP clock info |
| 1888 | * @param ppb how much to adjust by, in parts-per-billion |
| 1889 | */ |
| 1890 | static int liquidio_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb) |
| 1891 | { |
| 1892 | struct lio *lio = container_of(ptp, struct lio, ptp_info); |
| 1893 | struct octeon_device *oct = (struct octeon_device *)lio->oct_dev; |
| 1894 | u64 comp, delta; |
| 1895 | unsigned long flags; |
| 1896 | bool neg_adj = false; |
| 1897 | |
| 1898 | if (ppb < 0) { |
| 1899 | neg_adj = true; |
| 1900 | ppb = -ppb; |
| 1901 | } |
| 1902 | |
| 1903 | /* The hardware adds the clock compensation value to the |
| 1904 | * PTP clock on every coprocessor clock cycle, so we |
| 1905 | * compute the delta in terms of coprocessor clocks. |
| 1906 | */ |
| 1907 | delta = (u64)ppb << 32; |
| 1908 | do_div(delta, oct->coproc_clock_rate); |
| 1909 | |
| 1910 | spin_lock_irqsave(&lio->ptp_lock, flags); |
| 1911 | comp = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_COMP); |
| 1912 | if (neg_adj) |
| 1913 | comp -= delta; |
| 1914 | else |
| 1915 | comp += delta; |
| 1916 | lio_pci_writeq(oct, comp, CN6XXX_MIO_PTP_CLOCK_COMP); |
| 1917 | spin_unlock_irqrestore(&lio->ptp_lock, flags); |
| 1918 | |
| 1919 | return 0; |
| 1920 | } |
| 1921 | |
| 1922 | /** |
| 1923 | * \brief Adjust ptp time |
| 1924 | * @param ptp PTP clock info |
| 1925 | * @param delta how much to adjust by, in nanosecs |
| 1926 | */ |
| 1927 | static int liquidio_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta) |
| 1928 | { |
| 1929 | unsigned long flags; |
| 1930 | struct lio *lio = container_of(ptp, struct lio, ptp_info); |
| 1931 | |
| 1932 | spin_lock_irqsave(&lio->ptp_lock, flags); |
| 1933 | lio->ptp_adjust += delta; |
| 1934 | spin_unlock_irqrestore(&lio->ptp_lock, flags); |
| 1935 | |
| 1936 | return 0; |
| 1937 | } |
| 1938 | |
| 1939 | /** |
| 1940 | * \brief Get hardware clock time, including any adjustment |
| 1941 | * @param ptp PTP clock info |
| 1942 | * @param ts timespec |
| 1943 | */ |
| 1944 | static int liquidio_ptp_gettime(struct ptp_clock_info *ptp, |
| 1945 | struct timespec64 *ts) |
| 1946 | { |
| 1947 | u64 ns; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1948 | unsigned long flags; |
| 1949 | struct lio *lio = container_of(ptp, struct lio, ptp_info); |
| 1950 | struct octeon_device *oct = (struct octeon_device *)lio->oct_dev; |
| 1951 | |
| 1952 | spin_lock_irqsave(&lio->ptp_lock, flags); |
| 1953 | ns = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_HI); |
| 1954 | ns += lio->ptp_adjust; |
| 1955 | spin_unlock_irqrestore(&lio->ptp_lock, flags); |
| 1956 | |
Kefeng Wang | 286af31 | 2016-01-27 17:34:37 +0800 | [diff] [blame] | 1957 | *ts = ns_to_timespec64(ns); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1958 | |
| 1959 | return 0; |
| 1960 | } |
| 1961 | |
| 1962 | /** |
| 1963 | * \brief Set hardware clock time. Reset adjustment |
| 1964 | * @param ptp PTP clock info |
| 1965 | * @param ts timespec |
| 1966 | */ |
| 1967 | static int liquidio_ptp_settime(struct ptp_clock_info *ptp, |
| 1968 | const struct timespec64 *ts) |
| 1969 | { |
| 1970 | u64 ns; |
| 1971 | unsigned long flags; |
| 1972 | struct lio *lio = container_of(ptp, struct lio, ptp_info); |
| 1973 | struct octeon_device *oct = (struct octeon_device *)lio->oct_dev; |
| 1974 | |
Arnd Bergmann | e7ad979 | 2017-10-12 11:48:31 +0200 | [diff] [blame] | 1975 | ns = timespec64_to_ns(ts); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1976 | |
| 1977 | spin_lock_irqsave(&lio->ptp_lock, flags); |
| 1978 | lio_pci_writeq(oct, ns, CN6XXX_MIO_PTP_CLOCK_HI); |
| 1979 | lio->ptp_adjust = 0; |
| 1980 | spin_unlock_irqrestore(&lio->ptp_lock, flags); |
| 1981 | |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
| 1985 | /** |
| 1986 | * \brief Check if PTP is enabled |
| 1987 | * @param ptp PTP clock info |
| 1988 | * @param rq request |
| 1989 | * @param on is it on |
| 1990 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 1991 | static int |
| 1992 | liquidio_ptp_enable(struct ptp_clock_info *ptp __attribute__((unused)), |
| 1993 | struct ptp_clock_request *rq __attribute__((unused)), |
| 1994 | int on __attribute__((unused))) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 1995 | { |
| 1996 | return -EOPNOTSUPP; |
| 1997 | } |
| 1998 | |
| 1999 | /** |
| 2000 | * \brief Open PTP clock source |
| 2001 | * @param netdev network device |
| 2002 | */ |
| 2003 | static void oct_ptp_open(struct net_device *netdev) |
| 2004 | { |
| 2005 | struct lio *lio = GET_LIO(netdev); |
| 2006 | struct octeon_device *oct = (struct octeon_device *)lio->oct_dev; |
| 2007 | |
| 2008 | spin_lock_init(&lio->ptp_lock); |
| 2009 | |
| 2010 | snprintf(lio->ptp_info.name, 16, "%s", netdev->name); |
| 2011 | lio->ptp_info.owner = THIS_MODULE; |
| 2012 | lio->ptp_info.max_adj = 250000000; |
| 2013 | lio->ptp_info.n_alarm = 0; |
| 2014 | lio->ptp_info.n_ext_ts = 0; |
| 2015 | lio->ptp_info.n_per_out = 0; |
| 2016 | lio->ptp_info.pps = 0; |
| 2017 | lio->ptp_info.adjfreq = liquidio_ptp_adjfreq; |
| 2018 | lio->ptp_info.adjtime = liquidio_ptp_adjtime; |
| 2019 | lio->ptp_info.gettime64 = liquidio_ptp_gettime; |
| 2020 | lio->ptp_info.settime64 = liquidio_ptp_settime; |
| 2021 | lio->ptp_info.enable = liquidio_ptp_enable; |
| 2022 | |
| 2023 | lio->ptp_adjust = 0; |
| 2024 | |
| 2025 | lio->ptp_clock = ptp_clock_register(&lio->ptp_info, |
| 2026 | &oct->pci_dev->dev); |
| 2027 | |
| 2028 | if (IS_ERR(lio->ptp_clock)) |
| 2029 | lio->ptp_clock = NULL; |
| 2030 | } |
| 2031 | |
| 2032 | /** |
| 2033 | * \brief Init PTP clock |
| 2034 | * @param oct octeon device |
| 2035 | */ |
| 2036 | static void liquidio_ptp_init(struct octeon_device *oct) |
| 2037 | { |
| 2038 | u64 clock_comp, cfg; |
| 2039 | |
| 2040 | clock_comp = (u64)NSEC_PER_SEC << 32; |
| 2041 | do_div(clock_comp, oct->coproc_clock_rate); |
| 2042 | lio_pci_writeq(oct, clock_comp, CN6XXX_MIO_PTP_CLOCK_COMP); |
| 2043 | |
| 2044 | /* Enable */ |
| 2045 | cfg = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_CFG); |
| 2046 | lio_pci_writeq(oct, cfg | 0x01, CN6XXX_MIO_PTP_CLOCK_CFG); |
| 2047 | } |
| 2048 | |
| 2049 | /** |
| 2050 | * \brief Load firmware to device |
| 2051 | * @param oct octeon device |
| 2052 | * |
| 2053 | * Maps device to firmware filename, requests firmware, and downloads it |
| 2054 | */ |
| 2055 | static int load_firmware(struct octeon_device *oct) |
| 2056 | { |
| 2057 | int ret = 0; |
| 2058 | const struct firmware *fw; |
| 2059 | char fw_name[LIO_MAX_FW_FILENAME_LEN]; |
| 2060 | char *tmp_fw_type; |
| 2061 | |
Rick Farrington | 429cbf6 | 2017-09-22 17:12:51 -0700 | [diff] [blame] | 2062 | if (fw_type_is_auto()) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2063 | tmp_fw_type = LIO_FW_NAME_TYPE_NIC; |
Rick Farrington | 429cbf6 | 2017-09-22 17:12:51 -0700 | [diff] [blame] | 2064 | strncpy(fw_type, tmp_fw_type, sizeof(fw_type)); |
| 2065 | } else { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2066 | tmp_fw_type = fw_type; |
Rick Farrington | 429cbf6 | 2017-09-22 17:12:51 -0700 | [diff] [blame] | 2067 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2068 | |
| 2069 | sprintf(fw_name, "%s%s%s_%s%s", LIO_FW_DIR, LIO_FW_BASE_NAME, |
| 2070 | octeon_get_conf(oct)->card_name, tmp_fw_type, |
| 2071 | LIO_FW_NAME_SUFFIX); |
| 2072 | |
| 2073 | ret = request_firmware(&fw, fw_name, &oct->pci_dev->dev); |
| 2074 | if (ret) { |
| 2075 | dev_err(&oct->pci_dev->dev, "Request firmware failed. Could not find file %s.\n.", |
| 2076 | fw_name); |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 2077 | release_firmware(fw); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2078 | return ret; |
| 2079 | } |
| 2080 | |
| 2081 | ret = octeon_download_firmware(oct, fw->data, fw->size); |
| 2082 | |
| 2083 | release_firmware(fw); |
| 2084 | |
| 2085 | return ret; |
| 2086 | } |
| 2087 | |
| 2088 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2089 | * \brief Callback for getting interface configuration |
| 2090 | * @param status status of request |
| 2091 | * @param buf pointer to resp structure |
| 2092 | */ |
| 2093 | static void if_cfg_callback(struct octeon_device *oct, |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 2094 | u32 status __attribute__((unused)), |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2095 | void *buf) |
| 2096 | { |
| 2097 | struct octeon_soft_command *sc = (struct octeon_soft_command *)buf; |
| 2098 | struct liquidio_if_cfg_resp *resp; |
| 2099 | struct liquidio_if_cfg_context *ctx; |
| 2100 | |
| 2101 | resp = (struct liquidio_if_cfg_resp *)sc->virtrptr; |
Raghu Vatsavayi | 3013639 | 2016-09-01 11:16:11 -0700 | [diff] [blame] | 2102 | ctx = (struct liquidio_if_cfg_context *)sc->ctxptr; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2103 | |
| 2104 | oct = lio_get_device(ctx->octeon_id); |
| 2105 | if (resp->status) |
Rick Farrington | c5b71e6 | 2017-03-17 11:23:08 -0700 | [diff] [blame] | 2106 | dev_err(&oct->pci_dev->dev, "nic if cfg instruction failed. Status: 0x%llx (0x%08x)\n", |
| 2107 | CVM_CAST64(resp->status), status); |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 2108 | WRITE_ONCE(ctx->cond, 1); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2109 | |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 2110 | snprintf(oct->fw_info.liquidio_firmware_version, 32, "%s", |
| 2111 | resp->cfg_info.liquidio_firmware_version); |
| 2112 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2113 | /* This barrier is required to be sure that the response has been |
| 2114 | * written fully before waking up the handler |
| 2115 | */ |
| 2116 | wmb(); |
| 2117 | |
| 2118 | wake_up_interruptible(&ctx->wc); |
| 2119 | } |
| 2120 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2121 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2122 | * \brief Poll routine for checking transmit queue status |
| 2123 | * @param work work_struct data structure |
| 2124 | */ |
| 2125 | static void octnet_poll_check_txq_status(struct work_struct *work) |
| 2126 | { |
| 2127 | struct cavium_wk *wk = (struct cavium_wk *)work; |
| 2128 | struct lio *lio = (struct lio *)wk->ctxptr; |
| 2129 | |
| 2130 | if (!ifstate_check(lio, LIO_IFSTATE_RUNNING)) |
| 2131 | return; |
| 2132 | |
| 2133 | check_txq_status(lio); |
| 2134 | queue_delayed_work(lio->txq_status_wq.wq, |
| 2135 | &lio->txq_status_wq.wk.work, msecs_to_jiffies(1)); |
| 2136 | } |
| 2137 | |
| 2138 | /** |
| 2139 | * \brief Sets up the txq poll check |
| 2140 | * @param netdev network device |
| 2141 | */ |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 2142 | static inline int setup_tx_poll_fn(struct net_device *netdev) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2143 | { |
| 2144 | struct lio *lio = GET_LIO(netdev); |
| 2145 | struct octeon_device *oct = lio->oct_dev; |
| 2146 | |
Bhaktipriya Shridhar | 292b9da | 2016-06-08 01:47:59 +0530 | [diff] [blame] | 2147 | lio->txq_status_wq.wq = alloc_workqueue("txq-status", |
| 2148 | WQ_MEM_RECLAIM, 0); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2149 | if (!lio->txq_status_wq.wq) { |
| 2150 | dev_err(&oct->pci_dev->dev, "unable to create cavium txq status wq\n"); |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 2151 | return -1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2152 | } |
| 2153 | INIT_DELAYED_WORK(&lio->txq_status_wq.wk.work, |
| 2154 | octnet_poll_check_txq_status); |
| 2155 | lio->txq_status_wq.wk.ctxptr = lio; |
| 2156 | queue_delayed_work(lio->txq_status_wq.wq, |
| 2157 | &lio->txq_status_wq.wk.work, msecs_to_jiffies(1)); |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 2158 | return 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2159 | } |
| 2160 | |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2161 | static inline void cleanup_tx_poll_fn(struct net_device *netdev) |
| 2162 | { |
| 2163 | struct lio *lio = GET_LIO(netdev); |
| 2164 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 2165 | if (lio->txq_status_wq.wq) { |
| 2166 | cancel_delayed_work_sync(&lio->txq_status_wq.wk.work); |
| 2167 | destroy_workqueue(lio->txq_status_wq.wq); |
| 2168 | } |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2169 | } |
| 2170 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2171 | /** |
| 2172 | * \brief Net device open for LiquidIO |
| 2173 | * @param netdev network device |
| 2174 | */ |
| 2175 | static int liquidio_open(struct net_device *netdev) |
| 2176 | { |
| 2177 | struct lio *lio = GET_LIO(netdev); |
| 2178 | struct octeon_device *oct = lio->oct_dev; |
| 2179 | struct napi_struct *napi, *n; |
| 2180 | |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2181 | if (oct->props[lio->ifidx].napi_enabled == 0) { |
| 2182 | list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) |
| 2183 | napi_enable(napi); |
| 2184 | |
| 2185 | oct->props[lio->ifidx].napi_enabled = 1; |
Raghu Vatsavayi | 7b6b6c9 | 2016-09-01 11:16:04 -0700 | [diff] [blame] | 2186 | |
| 2187 | if (OCTEON_CN23XX_PF(oct)) |
| 2188 | oct->droq[0]->ops.poll_mode = 1; |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2189 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2190 | |
Intiyaz Basha | aa69ff9 | 2017-08-11 11:22:09 -0700 | [diff] [blame] | 2191 | if (oct->ptp_enable) |
Prasad Kanneganti | 9feb16a | 2017-01-03 11:27:33 -0800 | [diff] [blame] | 2192 | oct_ptp_open(netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2193 | |
| 2194 | ifstate_set(lio, LIO_IFSTATE_RUNNING); |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2195 | |
Raghu Vatsavayi | 7b6b6c9 | 2016-09-01 11:16:04 -0700 | [diff] [blame] | 2196 | /* Ready for link status updates */ |
| 2197 | lio->intf_open = 1; |
| 2198 | |
| 2199 | netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n"); |
| 2200 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 2201 | if (OCTEON_CN23XX_PF(oct)) { |
| 2202 | if (!oct->msix_on) |
| 2203 | if (setup_tx_poll_fn(netdev)) |
| 2204 | return -1; |
| 2205 | } else { |
| 2206 | if (setup_tx_poll_fn(netdev)) |
| 2207 | return -1; |
| 2208 | } |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2209 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2210 | start_txq(netdev); |
| 2211 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2212 | /* tell Octeon to start forwarding packets to host */ |
| 2213 | send_rx_ctrl_cmd(lio, 1); |
| 2214 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2215 | dev_info(&oct->pci_dev->dev, "%s interface is opened\n", |
| 2216 | netdev->name); |
| 2217 | |
| 2218 | return 0; |
| 2219 | } |
| 2220 | |
| 2221 | /** |
| 2222 | * \brief Net device stop for LiquidIO |
| 2223 | * @param netdev network device |
| 2224 | */ |
| 2225 | static int liquidio_stop(struct net_device *netdev) |
| 2226 | { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2227 | struct lio *lio = GET_LIO(netdev); |
| 2228 | struct octeon_device *oct = lio->oct_dev; |
Intiyaz Basha | 42013e9 | 2017-08-08 19:34:28 -0700 | [diff] [blame] | 2229 | struct napi_struct *napi, *n; |
| 2230 | |
| 2231 | if (oct->props[lio->ifidx].napi_enabled) { |
| 2232 | list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list) |
| 2233 | napi_disable(napi); |
| 2234 | |
| 2235 | oct->props[lio->ifidx].napi_enabled = 0; |
| 2236 | |
| 2237 | if (OCTEON_CN23XX_PF(oct)) |
| 2238 | oct->droq[0]->ops.poll_mode = 0; |
| 2239 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2240 | |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2241 | ifstate_reset(lio, LIO_IFSTATE_RUNNING); |
| 2242 | |
| 2243 | netif_tx_disable(netdev); |
| 2244 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2245 | /* Inform that netif carrier is down */ |
Raghu Vatsavayi | 9a96bde | 2016-06-21 22:53:06 -0700 | [diff] [blame] | 2246 | netif_carrier_off(netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2247 | lio->intf_open = 0; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2248 | lio->linfo.link.s.link_up = 0; |
| 2249 | lio->link_changes++; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2250 | |
Felix Manlunas | cb2336b | 2017-01-11 17:09:02 -0800 | [diff] [blame] | 2251 | /* Tell Octeon that nic interface is down. */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2252 | send_rx_ctrl_cmd(lio, 0); |
| 2253 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 2254 | if (OCTEON_CN23XX_PF(oct)) { |
| 2255 | if (!oct->msix_on) |
| 2256 | cleanup_tx_poll_fn(netdev); |
| 2257 | } else { |
| 2258 | cleanup_tx_poll_fn(netdev); |
| 2259 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2260 | |
| 2261 | if (lio->ptp_clock) { |
| 2262 | ptp_clock_unregister(lio->ptp_clock); |
| 2263 | lio->ptp_clock = NULL; |
| 2264 | } |
| 2265 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2266 | dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2267 | |
| 2268 | return 0; |
| 2269 | } |
| 2270 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2271 | /** |
| 2272 | * \brief Converts a mask based on net device flags |
| 2273 | * @param netdev network device |
| 2274 | * |
| 2275 | * This routine generates a octnet_ifflags mask from the net device flags |
| 2276 | * received from the OS. |
| 2277 | */ |
| 2278 | static inline enum octnet_ifflags get_new_flags(struct net_device *netdev) |
| 2279 | { |
| 2280 | enum octnet_ifflags f = OCTNET_IFFLAG_UNICAST; |
| 2281 | |
| 2282 | if (netdev->flags & IFF_PROMISC) |
| 2283 | f |= OCTNET_IFFLAG_PROMISC; |
| 2284 | |
| 2285 | if (netdev->flags & IFF_ALLMULTI) |
| 2286 | f |= OCTNET_IFFLAG_ALLMULTI; |
| 2287 | |
| 2288 | if (netdev->flags & IFF_MULTICAST) { |
| 2289 | f |= OCTNET_IFFLAG_MULTICAST; |
| 2290 | |
| 2291 | /* Accept all multicast addresses if there are more than we |
| 2292 | * can handle |
| 2293 | */ |
| 2294 | if (netdev_mc_count(netdev) > MAX_OCTEON_MULTICAST_ADDR) |
| 2295 | f |= OCTNET_IFFLAG_ALLMULTI; |
| 2296 | } |
| 2297 | |
| 2298 | if (netdev->flags & IFF_BROADCAST) |
| 2299 | f |= OCTNET_IFFLAG_BROADCAST; |
| 2300 | |
| 2301 | return f; |
| 2302 | } |
| 2303 | |
| 2304 | /** |
| 2305 | * \brief Net device set_multicast_list |
| 2306 | * @param netdev network device |
| 2307 | */ |
| 2308 | static void liquidio_set_mcast_list(struct net_device *netdev) |
| 2309 | { |
| 2310 | struct lio *lio = GET_LIO(netdev); |
| 2311 | struct octeon_device *oct = lio->oct_dev; |
| 2312 | struct octnic_ctrl_pkt nctrl; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2313 | struct netdev_hw_addr *ha; |
| 2314 | u64 *mc; |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 2315 | int ret; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2316 | int mc_count = min(netdev_mc_count(netdev), MAX_OCTEON_MULTICAST_ADDR); |
| 2317 | |
| 2318 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 2319 | |
| 2320 | /* Create a ctrl pkt command to be sent to core app. */ |
| 2321 | nctrl.ncmd.u64 = 0; |
| 2322 | nctrl.ncmd.s.cmd = OCTNET_CMD_SET_MULTI_LIST; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2323 | nctrl.ncmd.s.param1 = get_new_flags(netdev); |
| 2324 | nctrl.ncmd.s.param2 = mc_count; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2325 | nctrl.ncmd.s.more = mc_count; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2326 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2327 | nctrl.netpndev = (u64)netdev; |
| 2328 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 2329 | |
| 2330 | /* copy all the addresses into the udd */ |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2331 | mc = &nctrl.udd[0]; |
| 2332 | netdev_for_each_mc_addr(ha, netdev) { |
| 2333 | *mc = 0; |
| 2334 | memcpy(((u8 *)mc) + 2, ha->addr, ETH_ALEN); |
| 2335 | /* no need to swap bytes */ |
| 2336 | |
| 2337 | if (++mc > &nctrl.udd[mc_count]) |
| 2338 | break; |
| 2339 | } |
| 2340 | |
| 2341 | /* Apparently, any activity in this call from the kernel has to |
| 2342 | * be atomic. So we won't wait for response. |
| 2343 | */ |
| 2344 | nctrl.wait_time = 0; |
| 2345 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2346 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2347 | if (ret < 0) { |
| 2348 | dev_err(&oct->pci_dev->dev, "DEVFLAGS change failed in core (ret: 0x%x)\n", |
| 2349 | ret); |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | /** |
| 2354 | * \brief Net device set_mac_address |
| 2355 | * @param netdev network device |
| 2356 | */ |
| 2357 | static int liquidio_set_mac(struct net_device *netdev, void *p) |
| 2358 | { |
| 2359 | int ret = 0; |
| 2360 | struct lio *lio = GET_LIO(netdev); |
| 2361 | struct octeon_device *oct = lio->oct_dev; |
| 2362 | struct sockaddr *addr = (struct sockaddr *)p; |
| 2363 | struct octnic_ctrl_pkt nctrl; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2364 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2365 | if (!is_valid_ether_addr(addr->sa_data)) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2366 | return -EADDRNOTAVAIL; |
| 2367 | |
| 2368 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 2369 | |
| 2370 | nctrl.ncmd.u64 = 0; |
| 2371 | nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2372 | nctrl.ncmd.s.param1 = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2373 | nctrl.ncmd.s.more = 1; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2374 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2375 | nctrl.netpndev = (u64)netdev; |
| 2376 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 2377 | nctrl.wait_time = 100; |
| 2378 | |
| 2379 | nctrl.udd[0] = 0; |
| 2380 | /* The MAC Address is presented in network byte order. */ |
| 2381 | memcpy((u8 *)&nctrl.udd[0] + 2, addr->sa_data, ETH_ALEN); |
| 2382 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2383 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2384 | if (ret < 0) { |
| 2385 | dev_err(&oct->pci_dev->dev, "MAC Address change failed\n"); |
| 2386 | return -ENOMEM; |
| 2387 | } |
| 2388 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
| 2389 | memcpy(((u8 *)&lio->linfo.hw_addr) + 2, addr->sa_data, ETH_ALEN); |
| 2390 | |
| 2391 | return 0; |
| 2392 | } |
| 2393 | |
| 2394 | /** |
| 2395 | * \brief Net device get_stats |
| 2396 | * @param netdev network device |
| 2397 | */ |
| 2398 | static struct net_device_stats *liquidio_get_stats(struct net_device *netdev) |
| 2399 | { |
| 2400 | struct lio *lio = GET_LIO(netdev); |
| 2401 | struct net_device_stats *stats = &netdev->stats; |
| 2402 | struct octeon_device *oct; |
| 2403 | u64 pkts = 0, drop = 0, bytes = 0; |
| 2404 | struct oct_droq_stats *oq_stats; |
| 2405 | struct oct_iq_stats *iq_stats; |
| 2406 | int i, iq_no, oq_no; |
| 2407 | |
| 2408 | oct = lio->oct_dev; |
| 2409 | |
Intiyaz Basha | d18ca7d | 2017-08-14 12:01:56 -0700 | [diff] [blame] | 2410 | if (ifstate_check(lio, LIO_IFSTATE_RESETTING)) |
| 2411 | return stats; |
| 2412 | |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 2413 | for (i = 0; i < oct->num_iqs; i++) { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 2414 | iq_no = lio->linfo.txpciq[i].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2415 | iq_stats = &oct->instr_queue[iq_no]->stats; |
| 2416 | pkts += iq_stats->tx_done; |
| 2417 | drop += iq_stats->tx_dropped; |
| 2418 | bytes += iq_stats->tx_tot_bytes; |
| 2419 | } |
| 2420 | |
| 2421 | stats->tx_packets = pkts; |
| 2422 | stats->tx_bytes = bytes; |
| 2423 | stats->tx_dropped = drop; |
| 2424 | |
| 2425 | pkts = 0; |
| 2426 | drop = 0; |
| 2427 | bytes = 0; |
| 2428 | |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 2429 | for (i = 0; i < oct->num_oqs; i++) { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 2430 | oq_no = lio->linfo.rxpciq[i].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2431 | oq_stats = &oct->droq[oq_no]->stats; |
| 2432 | pkts += oq_stats->rx_pkts_received; |
| 2433 | drop += (oq_stats->rx_dropped + |
| 2434 | oq_stats->dropped_nodispatch + |
| 2435 | oq_stats->dropped_toomany + |
| 2436 | oq_stats->dropped_nomem); |
| 2437 | bytes += oq_stats->rx_bytes_received; |
| 2438 | } |
| 2439 | |
| 2440 | stats->rx_bytes = bytes; |
| 2441 | stats->rx_packets = pkts; |
| 2442 | stats->rx_dropped = drop; |
| 2443 | |
| 2444 | return stats; |
| 2445 | } |
| 2446 | |
| 2447 | /** |
| 2448 | * \brief Net device change_mtu |
| 2449 | * @param netdev network device |
| 2450 | */ |
| 2451 | static int liquidio_change_mtu(struct net_device *netdev, int new_mtu) |
| 2452 | { |
| 2453 | struct lio *lio = GET_LIO(netdev); |
| 2454 | struct octeon_device *oct = lio->oct_dev; |
| 2455 | struct octnic_ctrl_pkt nctrl; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2456 | int ret = 0; |
| 2457 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2458 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 2459 | |
| 2460 | nctrl.ncmd.u64 = 0; |
| 2461 | nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MTU; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2462 | nctrl.ncmd.s.param1 = new_mtu; |
| 2463 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2464 | nctrl.wait_time = 100; |
| 2465 | nctrl.netpndev = (u64)netdev; |
| 2466 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 2467 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2468 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2469 | if (ret < 0) { |
| 2470 | dev_err(&oct->pci_dev->dev, "Failed to set MTU\n"); |
| 2471 | return -1; |
| 2472 | } |
| 2473 | |
| 2474 | lio->mtu = new_mtu; |
| 2475 | |
| 2476 | return 0; |
| 2477 | } |
| 2478 | |
| 2479 | /** |
| 2480 | * \brief Handler for SIOCSHWTSTAMP ioctl |
| 2481 | * @param netdev network device |
| 2482 | * @param ifr interface request |
| 2483 | * @param cmd command |
| 2484 | */ |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 2485 | static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2486 | { |
| 2487 | struct hwtstamp_config conf; |
| 2488 | struct lio *lio = GET_LIO(netdev); |
| 2489 | |
| 2490 | if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf))) |
| 2491 | return -EFAULT; |
| 2492 | |
| 2493 | if (conf.flags) |
| 2494 | return -EINVAL; |
| 2495 | |
| 2496 | switch (conf.tx_type) { |
| 2497 | case HWTSTAMP_TX_ON: |
| 2498 | case HWTSTAMP_TX_OFF: |
| 2499 | break; |
| 2500 | default: |
| 2501 | return -ERANGE; |
| 2502 | } |
| 2503 | |
| 2504 | switch (conf.rx_filter) { |
| 2505 | case HWTSTAMP_FILTER_NONE: |
| 2506 | break; |
| 2507 | case HWTSTAMP_FILTER_ALL: |
| 2508 | case HWTSTAMP_FILTER_SOME: |
| 2509 | case HWTSTAMP_FILTER_PTP_V1_L4_EVENT: |
| 2510 | case HWTSTAMP_FILTER_PTP_V1_L4_SYNC: |
| 2511 | case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ: |
| 2512 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT: |
| 2513 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC: |
| 2514 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ: |
| 2515 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: |
| 2516 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC: |
| 2517 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ: |
| 2518 | case HWTSTAMP_FILTER_PTP_V2_EVENT: |
| 2519 | case HWTSTAMP_FILTER_PTP_V2_SYNC: |
| 2520 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ: |
Miroslav Lichvar | e341257 | 2017-05-19 17:52:36 +0200 | [diff] [blame] | 2521 | case HWTSTAMP_FILTER_NTP_ALL: |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2522 | conf.rx_filter = HWTSTAMP_FILTER_ALL; |
| 2523 | break; |
| 2524 | default: |
| 2525 | return -ERANGE; |
| 2526 | } |
| 2527 | |
| 2528 | if (conf.rx_filter == HWTSTAMP_FILTER_ALL) |
| 2529 | ifstate_set(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED); |
| 2530 | |
| 2531 | else |
| 2532 | ifstate_reset(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED); |
| 2533 | |
| 2534 | return copy_to_user(ifr->ifr_data, &conf, sizeof(conf)) ? -EFAULT : 0; |
| 2535 | } |
| 2536 | |
| 2537 | /** |
| 2538 | * \brief ioctl handler |
| 2539 | * @param netdev network device |
| 2540 | * @param ifr interface request |
| 2541 | * @param cmd command |
| 2542 | */ |
| 2543 | static int liquidio_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd) |
| 2544 | { |
Prasad Kanneganti | 9feb16a | 2017-01-03 11:27:33 -0800 | [diff] [blame] | 2545 | struct lio *lio = GET_LIO(netdev); |
| 2546 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2547 | switch (cmd) { |
| 2548 | case SIOCSHWTSTAMP: |
Intiyaz Basha | aa69ff9 | 2017-08-11 11:22:09 -0700 | [diff] [blame] | 2549 | if (lio->oct_dev->ptp_enable) |
Prasad Kanneganti | 9feb16a | 2017-01-03 11:27:33 -0800 | [diff] [blame] | 2550 | return hwtstamp_ioctl(netdev, ifr); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2551 | default: |
| 2552 | return -EOPNOTSUPP; |
| 2553 | } |
| 2554 | } |
| 2555 | |
| 2556 | /** |
| 2557 | * \brief handle a Tx timestamp response |
| 2558 | * @param status response status |
| 2559 | * @param buf pointer to skb |
| 2560 | */ |
| 2561 | static void handle_timestamp(struct octeon_device *oct, |
| 2562 | u32 status, |
| 2563 | void *buf) |
| 2564 | { |
| 2565 | struct octnet_buf_free_info *finfo; |
| 2566 | struct octeon_soft_command *sc; |
| 2567 | struct oct_timestamp_resp *resp; |
| 2568 | struct lio *lio; |
| 2569 | struct sk_buff *skb = (struct sk_buff *)buf; |
| 2570 | |
| 2571 | finfo = (struct octnet_buf_free_info *)skb->cb; |
| 2572 | lio = finfo->lio; |
| 2573 | sc = finfo->sc; |
| 2574 | oct = lio->oct_dev; |
| 2575 | resp = (struct oct_timestamp_resp *)sc->virtrptr; |
| 2576 | |
| 2577 | if (status != OCTEON_REQUEST_DONE) { |
| 2578 | dev_err(&oct->pci_dev->dev, "Tx timestamp instruction failed. Status: %llx\n", |
| 2579 | CVM_CAST64(status)); |
| 2580 | resp->timestamp = 0; |
| 2581 | } |
| 2582 | |
| 2583 | octeon_swap_8B_data(&resp->timestamp, 1); |
| 2584 | |
Colin Ian King | 19a6d15 | 2016-02-05 16:30:39 +0000 | [diff] [blame] | 2585 | if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) != 0)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2586 | struct skb_shared_hwtstamps ts; |
| 2587 | u64 ns = resp->timestamp; |
| 2588 | |
| 2589 | netif_info(lio, tx_done, lio->netdev, |
| 2590 | "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n", |
| 2591 | skb, (unsigned long long)ns); |
| 2592 | ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust); |
| 2593 | skb_tstamp_tx(skb, &ts); |
| 2594 | } |
| 2595 | |
| 2596 | octeon_free_soft_command(oct, sc); |
Raghu Vatsavayi | cabeb13 | 2016-06-14 16:54:47 -0700 | [diff] [blame] | 2597 | tx_buffer_free(skb); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | /* \brief Send a data packet that will be timestamped |
| 2601 | * @param oct octeon device |
| 2602 | * @param ndata pointer to network data |
| 2603 | * @param finfo pointer to private network data |
| 2604 | */ |
| 2605 | static inline int send_nic_timestamp_pkt(struct octeon_device *oct, |
| 2606 | struct octnic_data_pkt *ndata, |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2607 | struct octnet_buf_free_info *finfo, |
| 2608 | int xmit_more) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2609 | { |
| 2610 | int retval; |
| 2611 | struct octeon_soft_command *sc; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2612 | struct lio *lio; |
| 2613 | int ring_doorbell; |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2614 | u32 len; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2615 | |
| 2616 | lio = finfo->lio; |
| 2617 | |
| 2618 | sc = octeon_alloc_soft_command_resp(oct, &ndata->cmd, |
| 2619 | sizeof(struct oct_timestamp_resp)); |
| 2620 | finfo->sc = sc; |
| 2621 | |
| 2622 | if (!sc) { |
| 2623 | dev_err(&oct->pci_dev->dev, "No memory for timestamped data packet\n"); |
| 2624 | return IQ_SEND_FAILED; |
| 2625 | } |
| 2626 | |
| 2627 | if (ndata->reqtype == REQTYPE_NORESP_NET) |
| 2628 | ndata->reqtype = REQTYPE_RESP_NET; |
| 2629 | else if (ndata->reqtype == REQTYPE_NORESP_NET_SG) |
| 2630 | ndata->reqtype = REQTYPE_RESP_NET_SG; |
| 2631 | |
| 2632 | sc->callback = handle_timestamp; |
| 2633 | sc->callback_arg = finfo->skb; |
| 2634 | sc->iq_no = ndata->q_no; |
| 2635 | |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 2636 | if (OCTEON_CN23XX_PF(oct)) |
| 2637 | len = (u32)((struct octeon_instr_ih3 *) |
| 2638 | (&sc->cmd.cmd3.ih3))->dlengsz; |
| 2639 | else |
| 2640 | len = (u32)((struct octeon_instr_ih2 *) |
| 2641 | (&sc->cmd.cmd2.ih2))->dlengsz; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2642 | |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2643 | ring_doorbell = !xmit_more; |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 2644 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2645 | retval = octeon_send_command(oct, sc->iq_no, ring_doorbell, &sc->cmd, |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2646 | sc, len, ndata->reqtype); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2647 | |
Raghu Vatsavayi | ddc173a | 2016-06-14 16:54:43 -0700 | [diff] [blame] | 2648 | if (retval == IQ_SEND_FAILED) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2649 | dev_err(&oct->pci_dev->dev, "timestamp data packet failed status: %x\n", |
| 2650 | retval); |
| 2651 | octeon_free_soft_command(oct, sc); |
| 2652 | } else { |
| 2653 | netif_info(lio, tx_queued, lio->netdev, "Queued timestamp packet\n"); |
| 2654 | } |
| 2655 | |
| 2656 | return retval; |
| 2657 | } |
| 2658 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2659 | /** \brief Transmit networks packets to the Octeon interface |
| 2660 | * @param skbuff skbuff struct to be passed to network layer. |
| 2661 | * @param netdev pointer to network device |
| 2662 | * @returns whether the packet was transmitted to the device okay or not |
| 2663 | * (NETDEV_TX_OK or NETDEV_TX_BUSY) |
| 2664 | */ |
| 2665 | static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev) |
| 2666 | { |
| 2667 | struct lio *lio; |
| 2668 | struct octnet_buf_free_info *finfo; |
| 2669 | union octnic_cmd_setup cmdsetup; |
| 2670 | struct octnic_data_pkt ndata; |
| 2671 | struct octeon_device *oct; |
| 2672 | struct oct_iq_stats *stats; |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2673 | struct octeon_instr_irh *irh; |
| 2674 | union tx_info *tx_info; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 2675 | int status = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2676 | int q_idx = 0, iq_no = 0; |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2677 | int j, xmit_more = 0; |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 2678 | u64 dptr = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2679 | u32 tag = 0; |
| 2680 | |
| 2681 | lio = GET_LIO(netdev); |
| 2682 | oct = lio->oct_dev; |
| 2683 | |
| 2684 | if (netif_is_multiqueue(netdev)) { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 2685 | q_idx = skb->queue_mapping; |
| 2686 | q_idx = (q_idx % (lio->linfo.num_txpciq)); |
| 2687 | tag = q_idx; |
| 2688 | iq_no = lio->linfo.txpciq[q_idx].s.q_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2689 | } else { |
| 2690 | iq_no = lio->txq; |
| 2691 | } |
| 2692 | |
| 2693 | stats = &oct->instr_queue[iq_no]->stats; |
| 2694 | |
| 2695 | /* Check for all conditions in which the current packet cannot be |
| 2696 | * transmitted. |
| 2697 | */ |
| 2698 | if (!(atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) || |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2699 | (!lio->linfo.link.s.link_up) || |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2700 | (skb->len <= 0)) { |
| 2701 | netif_info(lio, tx_err, lio->netdev, |
| 2702 | "Transmit failed link_status : %d\n", |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2703 | lio->linfo.link.s.link_up); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2704 | goto lio_xmit_failed; |
| 2705 | } |
| 2706 | |
| 2707 | /* Use space in skb->cb to store info used to unmap and |
| 2708 | * free the buffers. |
| 2709 | */ |
| 2710 | finfo = (struct octnet_buf_free_info *)skb->cb; |
| 2711 | finfo->lio = lio; |
| 2712 | finfo->skb = skb; |
| 2713 | finfo->sc = NULL; |
| 2714 | |
| 2715 | /* Prepare the attributes for the data to be passed to OSI. */ |
| 2716 | memset(&ndata, 0, sizeof(struct octnic_data_pkt)); |
| 2717 | |
| 2718 | ndata.buf = (void *)finfo; |
| 2719 | |
| 2720 | ndata.q_no = iq_no; |
| 2721 | |
| 2722 | if (netif_is_multiqueue(netdev)) { |
| 2723 | if (octnet_iq_is_full(oct, ndata.q_no)) { |
| 2724 | /* defer sending if queue is full */ |
| 2725 | netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n", |
| 2726 | ndata.q_no); |
| 2727 | stats->tx_iq_busy++; |
| 2728 | return NETDEV_TX_BUSY; |
| 2729 | } |
| 2730 | } else { |
| 2731 | if (octnet_iq_is_full(oct, lio->txq)) { |
| 2732 | /* defer sending if queue is full */ |
| 2733 | stats->tx_iq_busy++; |
| 2734 | netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n", |
Raghu Vatsavayi | a2c64b6 | 2016-07-03 13:56:55 -0700 | [diff] [blame] | 2735 | lio->txq); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2736 | return NETDEV_TX_BUSY; |
| 2737 | } |
| 2738 | } |
| 2739 | /* pr_info(" XMIT - valid Qs: %d, 1st Q no: %d, cpu: %d, q_no:%d\n", |
Raghu Vatsavayi | a2c64b6 | 2016-07-03 13:56:55 -0700 | [diff] [blame] | 2740 | * lio->linfo.num_txpciq, lio->txq, cpu, ndata.q_no); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2741 | */ |
| 2742 | |
| 2743 | ndata.datasize = skb->len; |
| 2744 | |
| 2745 | cmdsetup.u64 = 0; |
Raghu Vatsavayi | 7275ebf | 2016-06-14 16:54:49 -0700 | [diff] [blame] | 2746 | cmdsetup.s.iq_no = iq_no; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2747 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 2748 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 2749 | if (skb->encapsulation) { |
| 2750 | cmdsetup.s.tnl_csum = 1; |
| 2751 | stats->tx_vxlan++; |
| 2752 | } else { |
| 2753 | cmdsetup.s.transport_csum = 1; |
| 2754 | } |
| 2755 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2756 | if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) { |
| 2757 | skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS; |
| 2758 | cmdsetup.s.timestamp = 1; |
| 2759 | } |
| 2760 | |
| 2761 | if (skb_shinfo(skb)->nr_frags == 0) { |
| 2762 | cmdsetup.s.u.datasize = skb->len; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2763 | octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag); |
Raghu Vatsavayi | a2c64b6 | 2016-07-03 13:56:55 -0700 | [diff] [blame] | 2764 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2765 | /* Offload checksum calculation for TCP/UDP packets */ |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2766 | dptr = dma_map_single(&oct->pci_dev->dev, |
| 2767 | skb->data, |
| 2768 | skb->len, |
| 2769 | DMA_TO_DEVICE); |
| 2770 | if (dma_mapping_error(&oct->pci_dev->dev, dptr)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2771 | dev_err(&oct->pci_dev->dev, "%s DMA mapping error 1\n", |
| 2772 | __func__); |
| 2773 | return NETDEV_TX_BUSY; |
| 2774 | } |
| 2775 | |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 2776 | if (OCTEON_CN23XX_PF(oct)) |
| 2777 | ndata.cmd.cmd3.dptr = dptr; |
| 2778 | else |
| 2779 | ndata.cmd.cmd2.dptr = dptr; |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2780 | finfo->dptr = dptr; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2781 | ndata.reqtype = REQTYPE_NORESP_NET; |
| 2782 | |
| 2783 | } else { |
| 2784 | int i, frags; |
| 2785 | struct skb_frag_struct *frag; |
| 2786 | struct octnic_gather *g; |
| 2787 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 2788 | spin_lock(&lio->glist_lock[q_idx]); |
| 2789 | g = (struct octnic_gather *) |
| 2790 | list_delete_head(&lio->glist[q_idx]); |
| 2791 | spin_unlock(&lio->glist_lock[q_idx]); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2792 | |
| 2793 | if (!g) { |
| 2794 | netif_info(lio, tx_err, lio->netdev, |
| 2795 | "Transmit scatter gather: glist null!\n"); |
| 2796 | goto lio_xmit_failed; |
| 2797 | } |
| 2798 | |
| 2799 | cmdsetup.s.gather = 1; |
| 2800 | cmdsetup.s.u.gatherptrs = (skb_shinfo(skb)->nr_frags + 1); |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 2801 | octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2802 | |
| 2803 | memset(g->sg, 0, g->sg_size); |
| 2804 | |
| 2805 | g->sg[0].ptr[0] = dma_map_single(&oct->pci_dev->dev, |
| 2806 | skb->data, |
| 2807 | (skb->len - skb->data_len), |
| 2808 | DMA_TO_DEVICE); |
| 2809 | if (dma_mapping_error(&oct->pci_dev->dev, g->sg[0].ptr[0])) { |
| 2810 | dev_err(&oct->pci_dev->dev, "%s DMA mapping error 2\n", |
| 2811 | __func__); |
| 2812 | return NETDEV_TX_BUSY; |
| 2813 | } |
| 2814 | add_sg_size(&g->sg[0], (skb->len - skb->data_len), 0); |
| 2815 | |
| 2816 | frags = skb_shinfo(skb)->nr_frags; |
| 2817 | i = 1; |
| 2818 | while (frags--) { |
| 2819 | frag = &skb_shinfo(skb)->frags[i - 1]; |
| 2820 | |
| 2821 | g->sg[(i >> 2)].ptr[(i & 3)] = |
| 2822 | dma_map_page(&oct->pci_dev->dev, |
| 2823 | frag->page.p, |
| 2824 | frag->page_offset, |
| 2825 | frag->size, |
| 2826 | DMA_TO_DEVICE); |
| 2827 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 2828 | if (dma_mapping_error(&oct->pci_dev->dev, |
| 2829 | g->sg[i >> 2].ptr[i & 3])) { |
| 2830 | dma_unmap_single(&oct->pci_dev->dev, |
| 2831 | g->sg[0].ptr[0], |
| 2832 | skb->len - skb->data_len, |
| 2833 | DMA_TO_DEVICE); |
| 2834 | for (j = 1; j < i; j++) { |
| 2835 | frag = &skb_shinfo(skb)->frags[j - 1]; |
| 2836 | dma_unmap_page(&oct->pci_dev->dev, |
| 2837 | g->sg[j >> 2].ptr[j & 3], |
| 2838 | frag->size, |
| 2839 | DMA_TO_DEVICE); |
| 2840 | } |
| 2841 | dev_err(&oct->pci_dev->dev, "%s DMA mapping error 3\n", |
| 2842 | __func__); |
| 2843 | return NETDEV_TX_BUSY; |
| 2844 | } |
| 2845 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2846 | add_sg_size(&g->sg[(i >> 2)], frag->size, (i & 3)); |
| 2847 | i++; |
| 2848 | } |
| 2849 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 2850 | dptr = g->sg_dma_ptr; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2851 | |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 2852 | if (OCTEON_CN23XX_PF(oct)) |
| 2853 | ndata.cmd.cmd3.dptr = dptr; |
| 2854 | else |
| 2855 | ndata.cmd.cmd2.dptr = dptr; |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2856 | finfo->dptr = dptr; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2857 | finfo->g = g; |
| 2858 | |
| 2859 | ndata.reqtype = REQTYPE_NORESP_NET_SG; |
| 2860 | } |
| 2861 | |
Raghu Vatsavayi | 5b82351 | 2016-09-01 11:16:07 -0700 | [diff] [blame] | 2862 | if (OCTEON_CN23XX_PF(oct)) { |
| 2863 | irh = (struct octeon_instr_irh *)&ndata.cmd.cmd3.irh; |
| 2864 | tx_info = (union tx_info *)&ndata.cmd.cmd3.ossp[0]; |
| 2865 | } else { |
| 2866 | irh = (struct octeon_instr_irh *)&ndata.cmd.cmd2.irh; |
| 2867 | tx_info = (union tx_info *)&ndata.cmd.cmd2.ossp[0]; |
| 2868 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2869 | |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2870 | if (skb_shinfo(skb)->gso_size) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2871 | tx_info->s.gso_size = skb_shinfo(skb)->gso_size; |
| 2872 | tx_info->s.gso_segs = skb_shinfo(skb)->gso_segs; |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 2873 | stats->tx_gso++; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2874 | } |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 2875 | |
Raghu Vatsavayi | 0da0b77 | 2016-06-21 22:53:04 -0700 | [diff] [blame] | 2876 | /* HW insert VLAN tag */ |
| 2877 | if (skb_vlan_tag_present(skb)) { |
| 2878 | irh->priority = skb_vlan_tag_get(skb) >> 13; |
| 2879 | irh->vlan = skb_vlan_tag_get(skb) & 0xfff; |
| 2880 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2881 | |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2882 | xmit_more = skb->xmit_more; |
| 2883 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2884 | if (unlikely(cmdsetup.s.timestamp)) |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2885 | status = send_nic_timestamp_pkt(oct, &ndata, finfo, xmit_more); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2886 | else |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2887 | status = octnet_send_nic_data_pkt(oct, &ndata, xmit_more); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2888 | if (status == IQ_SEND_FAILED) |
| 2889 | goto lio_xmit_failed; |
| 2890 | |
| 2891 | netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n"); |
| 2892 | |
| 2893 | if (status == IQ_SEND_STOP) |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2894 | stop_q(netdev, q_idx); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2895 | |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 2896 | netif_trans_update(netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2897 | |
Satanand Burla | 80c8eae | 2017-01-26 11:52:35 -0800 | [diff] [blame] | 2898 | if (tx_info->s.gso_segs) |
| 2899 | stats->tx_done += tx_info->s.gso_segs; |
Raghu Vatsavayi | 1f16471 | 2016-06-21 22:53:11 -0700 | [diff] [blame] | 2900 | else |
| 2901 | stats->tx_done++; |
Satanand Burla | 80c8eae | 2017-01-26 11:52:35 -0800 | [diff] [blame] | 2902 | stats->tx_tot_bytes += ndata.datasize; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2903 | |
| 2904 | return NETDEV_TX_OK; |
| 2905 | |
| 2906 | lio_xmit_failed: |
| 2907 | stats->tx_dropped++; |
| 2908 | netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n", |
| 2909 | iq_no, stats->tx_dropped); |
Raghu Vatsavayi | 6a885b6 | 2016-06-14 16:54:51 -0700 | [diff] [blame] | 2910 | if (dptr) |
| 2911 | dma_unmap_single(&oct->pci_dev->dev, dptr, |
| 2912 | ndata.datasize, DMA_TO_DEVICE); |
Intiyaz Basha | c859e21 | 2017-10-26 16:18:20 -0700 | [diff] [blame] | 2913 | |
| 2914 | octeon_ring_doorbell_locked(oct, iq_no); |
| 2915 | |
Raghu Vatsavayi | cabeb13 | 2016-06-14 16:54:47 -0700 | [diff] [blame] | 2916 | tx_buffer_free(skb); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2917 | return NETDEV_TX_OK; |
| 2918 | } |
| 2919 | |
| 2920 | /** \brief Network device Tx timeout |
| 2921 | * @param netdev pointer to network device |
| 2922 | */ |
| 2923 | static void liquidio_tx_timeout(struct net_device *netdev) |
| 2924 | { |
| 2925 | struct lio *lio; |
| 2926 | |
| 2927 | lio = GET_LIO(netdev); |
| 2928 | |
| 2929 | netif_info(lio, tx_err, lio->netdev, |
| 2930 | "Transmit timeout tx_dropped:%ld, waking up queues now!!\n", |
| 2931 | netdev->stats.tx_dropped); |
Florian Westphal | 860e953 | 2016-05-03 16:33:13 +0200 | [diff] [blame] | 2932 | netif_trans_update(netdev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 2933 | txqs_wake(netdev); |
| 2934 | } |
| 2935 | |
Raghu Vatsavayi | 63245f2 | 2016-06-21 22:53:05 -0700 | [diff] [blame] | 2936 | static int liquidio_vlan_rx_add_vid(struct net_device *netdev, |
| 2937 | __be16 proto __attribute__((unused)), |
| 2938 | u16 vid) |
| 2939 | { |
| 2940 | struct lio *lio = GET_LIO(netdev); |
| 2941 | struct octeon_device *oct = lio->oct_dev; |
| 2942 | struct octnic_ctrl_pkt nctrl; |
| 2943 | int ret = 0; |
| 2944 | |
| 2945 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 2946 | |
| 2947 | nctrl.ncmd.u64 = 0; |
| 2948 | nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER; |
| 2949 | nctrl.ncmd.s.param1 = vid; |
| 2950 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
| 2951 | nctrl.wait_time = 100; |
| 2952 | nctrl.netpndev = (u64)netdev; |
| 2953 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 2954 | |
| 2955 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
| 2956 | if (ret < 0) { |
| 2957 | dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n", |
| 2958 | ret); |
| 2959 | } |
| 2960 | |
| 2961 | return ret; |
| 2962 | } |
| 2963 | |
| 2964 | static int liquidio_vlan_rx_kill_vid(struct net_device *netdev, |
| 2965 | __be16 proto __attribute__((unused)), |
| 2966 | u16 vid) |
| 2967 | { |
| 2968 | struct lio *lio = GET_LIO(netdev); |
| 2969 | struct octeon_device *oct = lio->oct_dev; |
| 2970 | struct octnic_ctrl_pkt nctrl; |
| 2971 | int ret = 0; |
| 2972 | |
| 2973 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 2974 | |
| 2975 | nctrl.ncmd.u64 = 0; |
| 2976 | nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER; |
| 2977 | nctrl.ncmd.s.param1 = vid; |
| 2978 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
| 2979 | nctrl.wait_time = 100; |
| 2980 | nctrl.netpndev = (u64)netdev; |
| 2981 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 2982 | |
| 2983 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
| 2984 | if (ret < 0) { |
| 2985 | dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n", |
| 2986 | ret); |
| 2987 | } |
| 2988 | return ret; |
| 2989 | } |
| 2990 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 2991 | /** Sending command to enable/disable RX checksum offload |
| 2992 | * @param netdev pointer to network device |
| 2993 | * @param command OCTNET_CMD_TNL_RX_CSUM_CTL |
| 2994 | * @param rx_cmd_bit OCTNET_CMD_RXCSUM_ENABLE/ |
| 2995 | * OCTNET_CMD_RXCSUM_DISABLE |
| 2996 | * @returns SUCCESS or FAILURE |
| 2997 | */ |
Nicholas Mc Guire | c41419b | 2016-08-22 17:52:00 +0200 | [diff] [blame] | 2998 | static int liquidio_set_rxcsum_command(struct net_device *netdev, int command, |
| 2999 | u8 rx_cmd) |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3000 | { |
| 3001 | struct lio *lio = GET_LIO(netdev); |
| 3002 | struct octeon_device *oct = lio->oct_dev; |
| 3003 | struct octnic_ctrl_pkt nctrl; |
| 3004 | int ret = 0; |
| 3005 | |
Felix Manlunas | 0c26458 | 2017-04-06 19:22:22 -0700 | [diff] [blame] | 3006 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 3007 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3008 | nctrl.ncmd.u64 = 0; |
| 3009 | nctrl.ncmd.s.cmd = command; |
| 3010 | nctrl.ncmd.s.param1 = rx_cmd; |
| 3011 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
| 3012 | nctrl.wait_time = 100; |
| 3013 | nctrl.netpndev = (u64)netdev; |
| 3014 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 3015 | |
| 3016 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
| 3017 | if (ret < 0) { |
| 3018 | dev_err(&oct->pci_dev->dev, |
| 3019 | "DEVFLAGS RXCSUM change failed in core(ret:0x%x)\n", |
| 3020 | ret); |
| 3021 | } |
| 3022 | return ret; |
| 3023 | } |
| 3024 | |
| 3025 | /** Sending command to add/delete VxLAN UDP port to firmware |
| 3026 | * @param netdev pointer to network device |
| 3027 | * @param command OCTNET_CMD_VXLAN_PORT_CONFIG |
| 3028 | * @param vxlan_port VxLAN port to be added or deleted |
| 3029 | * @param vxlan_cmd_bit OCTNET_CMD_VXLAN_PORT_ADD, |
| 3030 | * OCTNET_CMD_VXLAN_PORT_DEL |
| 3031 | * @returns SUCCESS or FAILURE |
| 3032 | */ |
| 3033 | static int liquidio_vxlan_port_command(struct net_device *netdev, int command, |
| 3034 | u16 vxlan_port, u8 vxlan_cmd_bit) |
| 3035 | { |
| 3036 | struct lio *lio = GET_LIO(netdev); |
| 3037 | struct octeon_device *oct = lio->oct_dev; |
| 3038 | struct octnic_ctrl_pkt nctrl; |
| 3039 | int ret = 0; |
| 3040 | |
Felix Manlunas | 0c26458 | 2017-04-06 19:22:22 -0700 | [diff] [blame] | 3041 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 3042 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3043 | nctrl.ncmd.u64 = 0; |
| 3044 | nctrl.ncmd.s.cmd = command; |
| 3045 | nctrl.ncmd.s.more = vxlan_cmd_bit; |
| 3046 | nctrl.ncmd.s.param1 = vxlan_port; |
| 3047 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
| 3048 | nctrl.wait_time = 100; |
| 3049 | nctrl.netpndev = (u64)netdev; |
| 3050 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
| 3051 | |
| 3052 | ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl); |
| 3053 | if (ret < 0) { |
| 3054 | dev_err(&oct->pci_dev->dev, |
| 3055 | "VxLAN port add/delete failed in core (ret:0x%x)\n", |
| 3056 | ret); |
| 3057 | } |
| 3058 | return ret; |
| 3059 | } |
| 3060 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3061 | /** \brief Net device fix features |
| 3062 | * @param netdev pointer to network device |
| 3063 | * @param request features requested |
| 3064 | * @returns updated features list |
| 3065 | */ |
| 3066 | static netdev_features_t liquidio_fix_features(struct net_device *netdev, |
| 3067 | netdev_features_t request) |
| 3068 | { |
| 3069 | struct lio *lio = netdev_priv(netdev); |
| 3070 | |
| 3071 | if ((request & NETIF_F_RXCSUM) && |
| 3072 | !(lio->dev_capability & NETIF_F_RXCSUM)) |
| 3073 | request &= ~NETIF_F_RXCSUM; |
| 3074 | |
| 3075 | if ((request & NETIF_F_HW_CSUM) && |
| 3076 | !(lio->dev_capability & NETIF_F_HW_CSUM)) |
| 3077 | request &= ~NETIF_F_HW_CSUM; |
| 3078 | |
| 3079 | if ((request & NETIF_F_TSO) && !(lio->dev_capability & NETIF_F_TSO)) |
| 3080 | request &= ~NETIF_F_TSO; |
| 3081 | |
| 3082 | if ((request & NETIF_F_TSO6) && !(lio->dev_capability & NETIF_F_TSO6)) |
| 3083 | request &= ~NETIF_F_TSO6; |
| 3084 | |
| 3085 | if ((request & NETIF_F_LRO) && !(lio->dev_capability & NETIF_F_LRO)) |
| 3086 | request &= ~NETIF_F_LRO; |
| 3087 | |
| 3088 | /*Disable LRO if RXCSUM is off */ |
| 3089 | if (!(request & NETIF_F_RXCSUM) && (netdev->features & NETIF_F_LRO) && |
| 3090 | (lio->dev_capability & NETIF_F_LRO)) |
| 3091 | request &= ~NETIF_F_LRO; |
| 3092 | |
Prasad Kanneganti | 836d57e | 2017-06-18 12:41:34 -0700 | [diff] [blame] | 3093 | if ((request & NETIF_F_HW_VLAN_CTAG_FILTER) && |
| 3094 | !(lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 3095 | request &= ~NETIF_F_HW_VLAN_CTAG_FILTER; |
| 3096 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3097 | return request; |
| 3098 | } |
| 3099 | |
| 3100 | /** \brief Net device set features |
| 3101 | * @param netdev pointer to network device |
| 3102 | * @param features features to enable/disable |
| 3103 | */ |
| 3104 | static int liquidio_set_features(struct net_device *netdev, |
| 3105 | netdev_features_t features) |
| 3106 | { |
| 3107 | struct lio *lio = netdev_priv(netdev); |
| 3108 | |
Prasad Kanneganti | 836d57e | 2017-06-18 12:41:34 -0700 | [diff] [blame] | 3109 | if ((features & NETIF_F_LRO) && |
| 3110 | (lio->dev_capability & NETIF_F_LRO) && |
| 3111 | !(netdev->features & NETIF_F_LRO)) |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3112 | liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE, |
| 3113 | OCTNIC_LROIPV4 | OCTNIC_LROIPV6); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3114 | else if (!(features & NETIF_F_LRO) && |
Prasad Kanneganti | 836d57e | 2017-06-18 12:41:34 -0700 | [diff] [blame] | 3115 | (lio->dev_capability & NETIF_F_LRO) && |
| 3116 | (netdev->features & NETIF_F_LRO)) |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3117 | liquidio_set_feature(netdev, OCTNET_CMD_LRO_DISABLE, |
| 3118 | OCTNIC_LROIPV4 | OCTNIC_LROIPV6); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3119 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3120 | /* Sending command to firmware to enable/disable RX checksum |
| 3121 | * offload settings using ethtool |
| 3122 | */ |
| 3123 | if (!(netdev->features & NETIF_F_RXCSUM) && |
| 3124 | (lio->enc_dev_capability & NETIF_F_RXCSUM) && |
| 3125 | (features & NETIF_F_RXCSUM)) |
| 3126 | liquidio_set_rxcsum_command(netdev, |
| 3127 | OCTNET_CMD_TNL_RX_CSUM_CTL, |
| 3128 | OCTNET_CMD_RXCSUM_ENABLE); |
| 3129 | else if ((netdev->features & NETIF_F_RXCSUM) && |
| 3130 | (lio->enc_dev_capability & NETIF_F_RXCSUM) && |
| 3131 | !(features & NETIF_F_RXCSUM)) |
| 3132 | liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL, |
| 3133 | OCTNET_CMD_RXCSUM_DISABLE); |
| 3134 | |
Prasad Kanneganti | 836d57e | 2017-06-18 12:41:34 -0700 | [diff] [blame] | 3135 | if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) && |
| 3136 | (lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER) && |
| 3137 | !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 3138 | liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL, |
| 3139 | OCTNET_CMD_VLAN_FILTER_ENABLE); |
| 3140 | else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && |
| 3141 | (lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER) && |
| 3142 | (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER)) |
| 3143 | liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL, |
| 3144 | OCTNET_CMD_VLAN_FILTER_DISABLE); |
| 3145 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3146 | return 0; |
| 3147 | } |
| 3148 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3149 | static void liquidio_add_vxlan_port(struct net_device *netdev, |
| 3150 | struct udp_tunnel_info *ti) |
| 3151 | { |
| 3152 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN) |
| 3153 | return; |
| 3154 | |
| 3155 | liquidio_vxlan_port_command(netdev, |
| 3156 | OCTNET_CMD_VXLAN_PORT_CONFIG, |
| 3157 | htons(ti->port), |
| 3158 | OCTNET_CMD_VXLAN_PORT_ADD); |
| 3159 | } |
| 3160 | |
| 3161 | static void liquidio_del_vxlan_port(struct net_device *netdev, |
| 3162 | struct udp_tunnel_info *ti) |
| 3163 | { |
| 3164 | if (ti->type != UDP_TUNNEL_TYPE_VXLAN) |
| 3165 | return; |
| 3166 | |
| 3167 | liquidio_vxlan_port_command(netdev, |
| 3168 | OCTNET_CMD_VXLAN_PORT_CONFIG, |
| 3169 | htons(ti->port), |
| 3170 | OCTNET_CMD_VXLAN_PORT_DEL); |
| 3171 | } |
| 3172 | |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 3173 | static int __liquidio_set_vf_mac(struct net_device *netdev, int vfidx, |
| 3174 | u8 *mac, bool is_admin_assigned) |
| 3175 | { |
| 3176 | struct lio *lio = GET_LIO(netdev); |
| 3177 | struct octeon_device *oct = lio->oct_dev; |
| 3178 | struct octnic_ctrl_pkt nctrl; |
| 3179 | |
| 3180 | if (!is_valid_ether_addr(mac)) |
| 3181 | return -EINVAL; |
| 3182 | |
| 3183 | if (vfidx < 0 || vfidx >= oct->sriov_info.max_vfs) |
| 3184 | return -EINVAL; |
| 3185 | |
| 3186 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 3187 | |
| 3188 | nctrl.ncmd.u64 = 0; |
| 3189 | nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR; |
| 3190 | /* vfidx is 0 based, but vf_num (param1) is 1 based */ |
| 3191 | nctrl.ncmd.s.param1 = vfidx + 1; |
| 3192 | nctrl.ncmd.s.param2 = (is_admin_assigned ? 1 : 0); |
| 3193 | nctrl.ncmd.s.more = 1; |
| 3194 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
Rick Farrington | 9549c6c | 2017-03-17 15:43:26 -0700 | [diff] [blame] | 3195 | nctrl.netpndev = (u64)netdev; |
| 3196 | nctrl.cb_fn = liquidio_link_ctrl_cmd_completion; |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 3197 | nctrl.wait_time = LIO_CMD_WAIT_TM; |
| 3198 | |
| 3199 | nctrl.udd[0] = 0; |
| 3200 | /* The MAC Address is presented in network byte order. */ |
| 3201 | ether_addr_copy((u8 *)&nctrl.udd[0] + 2, mac); |
| 3202 | |
| 3203 | oct->sriov_info.vf_macaddr[vfidx] = nctrl.udd[0]; |
| 3204 | |
| 3205 | octnet_send_nic_ctrl_pkt(oct, &nctrl); |
| 3206 | |
| 3207 | return 0; |
| 3208 | } |
| 3209 | |
| 3210 | static int liquidio_set_vf_mac(struct net_device *netdev, int vfidx, u8 *mac) |
| 3211 | { |
| 3212 | struct lio *lio = GET_LIO(netdev); |
| 3213 | struct octeon_device *oct = lio->oct_dev; |
| 3214 | int retval; |
| 3215 | |
Felix Manlunas | 0d9a599 | 2017-05-16 11:28:00 -0700 | [diff] [blame] | 3216 | if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced) |
| 3217 | return -EINVAL; |
| 3218 | |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 3219 | retval = __liquidio_set_vf_mac(netdev, vfidx, mac, true); |
| 3220 | if (!retval) |
| 3221 | cn23xx_tell_vf_its_macaddr_changed(oct, vfidx, mac); |
| 3222 | |
| 3223 | return retval; |
| 3224 | } |
| 3225 | |
| 3226 | static int liquidio_set_vf_vlan(struct net_device *netdev, int vfidx, |
| 3227 | u16 vlan, u8 qos, __be16 vlan_proto) |
| 3228 | { |
| 3229 | struct lio *lio = GET_LIO(netdev); |
| 3230 | struct octeon_device *oct = lio->oct_dev; |
| 3231 | struct octnic_ctrl_pkt nctrl; |
| 3232 | u16 vlantci; |
| 3233 | |
| 3234 | if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced) |
| 3235 | return -EINVAL; |
| 3236 | |
| 3237 | if (vlan_proto != htons(ETH_P_8021Q)) |
| 3238 | return -EPROTONOSUPPORT; |
| 3239 | |
| 3240 | if (vlan >= VLAN_N_VID || qos > 7) |
| 3241 | return -EINVAL; |
| 3242 | |
| 3243 | if (vlan) |
| 3244 | vlantci = vlan | (u16)qos << VLAN_PRIO_SHIFT; |
| 3245 | else |
| 3246 | vlantci = 0; |
| 3247 | |
| 3248 | if (oct->sriov_info.vf_vlantci[vfidx] == vlantci) |
| 3249 | return 0; |
| 3250 | |
| 3251 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 3252 | |
| 3253 | if (vlan) |
| 3254 | nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER; |
| 3255 | else |
| 3256 | nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER; |
| 3257 | |
| 3258 | nctrl.ncmd.s.param1 = vlantci; |
| 3259 | nctrl.ncmd.s.param2 = |
| 3260 | vfidx + 1; /* vfidx is 0 based, but vf_num (param2) is 1 based */ |
| 3261 | nctrl.ncmd.s.more = 0; |
| 3262 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
| 3263 | nctrl.cb_fn = 0; |
| 3264 | nctrl.wait_time = LIO_CMD_WAIT_TM; |
| 3265 | |
| 3266 | octnet_send_nic_ctrl_pkt(oct, &nctrl); |
| 3267 | |
| 3268 | oct->sriov_info.vf_vlantci[vfidx] = vlantci; |
| 3269 | |
| 3270 | return 0; |
| 3271 | } |
| 3272 | |
| 3273 | static int liquidio_get_vf_config(struct net_device *netdev, int vfidx, |
| 3274 | struct ifla_vf_info *ivi) |
| 3275 | { |
| 3276 | struct lio *lio = GET_LIO(netdev); |
| 3277 | struct octeon_device *oct = lio->oct_dev; |
| 3278 | u8 *macaddr; |
| 3279 | |
| 3280 | if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced) |
| 3281 | return -EINVAL; |
| 3282 | |
| 3283 | ivi->vf = vfidx; |
| 3284 | macaddr = 2 + (u8 *)&oct->sriov_info.vf_macaddr[vfidx]; |
| 3285 | ether_addr_copy(&ivi->mac[0], macaddr); |
| 3286 | ivi->vlan = oct->sriov_info.vf_vlantci[vfidx] & VLAN_VID_MASK; |
| 3287 | ivi->qos = oct->sriov_info.vf_vlantci[vfidx] >> VLAN_PRIO_SHIFT; |
| 3288 | ivi->linkstate = oct->sriov_info.vf_linkstate[vfidx]; |
| 3289 | return 0; |
| 3290 | } |
| 3291 | |
| 3292 | static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx, |
| 3293 | int linkstate) |
| 3294 | { |
| 3295 | struct lio *lio = GET_LIO(netdev); |
| 3296 | struct octeon_device *oct = lio->oct_dev; |
| 3297 | struct octnic_ctrl_pkt nctrl; |
| 3298 | |
| 3299 | if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced) |
| 3300 | return -EINVAL; |
| 3301 | |
| 3302 | if (oct->sriov_info.vf_linkstate[vfidx] == linkstate) |
| 3303 | return 0; |
| 3304 | |
| 3305 | memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt)); |
| 3306 | nctrl.ncmd.s.cmd = OCTNET_CMD_SET_VF_LINKSTATE; |
| 3307 | nctrl.ncmd.s.param1 = |
| 3308 | vfidx + 1; /* vfidx is 0 based, but vf_num (param1) is 1 based */ |
| 3309 | nctrl.ncmd.s.param2 = linkstate; |
| 3310 | nctrl.ncmd.s.more = 0; |
| 3311 | nctrl.iq_no = lio->linfo.txpciq[0].s.q_no; |
| 3312 | nctrl.cb_fn = 0; |
| 3313 | nctrl.wait_time = LIO_CMD_WAIT_TM; |
| 3314 | |
| 3315 | octnet_send_nic_ctrl_pkt(oct, &nctrl); |
| 3316 | |
| 3317 | oct->sriov_info.vf_linkstate[vfidx] = linkstate; |
| 3318 | |
| 3319 | return 0; |
| 3320 | } |
| 3321 | |
Vijaya Mohan Guvva | 1f233f3 | 2017-10-31 16:04:53 -0700 | [diff] [blame] | 3322 | static int |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 3323 | liquidio_eswitch_mode_get(struct devlink *devlink, u16 *mode) |
| 3324 | { |
| 3325 | struct lio_devlink_priv *priv; |
| 3326 | struct octeon_device *oct; |
| 3327 | |
| 3328 | priv = devlink_priv(devlink); |
| 3329 | oct = priv->oct; |
| 3330 | |
| 3331 | *mode = oct->eswitch_mode; |
| 3332 | |
| 3333 | return 0; |
| 3334 | } |
| 3335 | |
| 3336 | static int |
| 3337 | liquidio_eswitch_mode_set(struct devlink *devlink, u16 mode) |
| 3338 | { |
| 3339 | struct lio_devlink_priv *priv; |
| 3340 | struct octeon_device *oct; |
| 3341 | int ret = 0; |
| 3342 | |
| 3343 | priv = devlink_priv(devlink); |
| 3344 | oct = priv->oct; |
| 3345 | |
| 3346 | if (!(oct->fw_info.app_cap_flags & LIQUIDIO_SWITCHDEV_CAP)) |
| 3347 | return -EINVAL; |
| 3348 | |
| 3349 | if (oct->eswitch_mode == mode) |
| 3350 | return 0; |
| 3351 | |
| 3352 | switch (mode) { |
| 3353 | case DEVLINK_ESWITCH_MODE_SWITCHDEV: |
| 3354 | oct->eswitch_mode = mode; |
| 3355 | ret = lio_vf_rep_create(oct); |
| 3356 | break; |
| 3357 | |
| 3358 | case DEVLINK_ESWITCH_MODE_LEGACY: |
| 3359 | lio_vf_rep_destroy(oct); |
| 3360 | oct->eswitch_mode = mode; |
| 3361 | break; |
| 3362 | |
| 3363 | default: |
| 3364 | ret = -EINVAL; |
| 3365 | } |
| 3366 | |
| 3367 | return ret; |
| 3368 | } |
| 3369 | |
| 3370 | static const struct devlink_ops liquidio_devlink_ops = { |
| 3371 | .eswitch_mode_get = liquidio_eswitch_mode_get, |
| 3372 | .eswitch_mode_set = liquidio_eswitch_mode_set, |
| 3373 | }; |
| 3374 | |
| 3375 | static int |
Vijaya Mohan Guvva | 1f233f3 | 2017-10-31 16:04:53 -0700 | [diff] [blame] | 3376 | lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr) |
| 3377 | { |
| 3378 | struct lio *lio = GET_LIO(dev); |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 3379 | struct octeon_device *oct = lio->oct_dev; |
| 3380 | |
| 3381 | if (oct->eswitch_mode != DEVLINK_ESWITCH_MODE_SWITCHDEV) |
| 3382 | return -EOPNOTSUPP; |
Vijaya Mohan Guvva | 1f233f3 | 2017-10-31 16:04:53 -0700 | [diff] [blame] | 3383 | |
| 3384 | switch (attr->id) { |
| 3385 | case SWITCHDEV_ATTR_ID_PORT_PARENT_ID: |
| 3386 | attr->u.ppid.id_len = ETH_ALEN; |
| 3387 | ether_addr_copy(attr->u.ppid.id, |
| 3388 | (void *)&lio->linfo.hw_addr + 2); |
| 3389 | break; |
| 3390 | |
| 3391 | default: |
| 3392 | return -EOPNOTSUPP; |
| 3393 | } |
| 3394 | |
| 3395 | return 0; |
| 3396 | } |
| 3397 | |
| 3398 | static const struct switchdev_ops lio_pf_switchdev_ops = { |
| 3399 | .switchdev_port_attr_get = lio_pf_switchdev_attr_get, |
| 3400 | }; |
| 3401 | |
Raghu Vatsavayi | 97a2532 | 2016-11-14 15:54:47 -0800 | [diff] [blame] | 3402 | static const struct net_device_ops lionetdevops = { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3403 | .ndo_open = liquidio_open, |
| 3404 | .ndo_stop = liquidio_stop, |
| 3405 | .ndo_start_xmit = liquidio_xmit, |
| 3406 | .ndo_get_stats = liquidio_get_stats, |
| 3407 | .ndo_set_mac_address = liquidio_set_mac, |
| 3408 | .ndo_set_rx_mode = liquidio_set_mcast_list, |
| 3409 | .ndo_tx_timeout = liquidio_tx_timeout, |
Raghu Vatsavayi | 63245f2 | 2016-06-21 22:53:05 -0700 | [diff] [blame] | 3410 | |
| 3411 | .ndo_vlan_rx_add_vid = liquidio_vlan_rx_add_vid, |
| 3412 | .ndo_vlan_rx_kill_vid = liquidio_vlan_rx_kill_vid, |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3413 | .ndo_change_mtu = liquidio_change_mtu, |
| 3414 | .ndo_do_ioctl = liquidio_ioctl, |
| 3415 | .ndo_fix_features = liquidio_fix_features, |
| 3416 | .ndo_set_features = liquidio_set_features, |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3417 | .ndo_udp_tunnel_add = liquidio_add_vxlan_port, |
| 3418 | .ndo_udp_tunnel_del = liquidio_del_vxlan_port, |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 3419 | .ndo_set_vf_mac = liquidio_set_vf_mac, |
| 3420 | .ndo_set_vf_vlan = liquidio_set_vf_vlan, |
| 3421 | .ndo_get_vf_config = liquidio_get_vf_config, |
| 3422 | .ndo_set_vf_link_state = liquidio_set_vf_link_state, |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3423 | }; |
| 3424 | |
| 3425 | /** \brief Entry point for the liquidio module |
| 3426 | */ |
| 3427 | static int __init liquidio_init(void) |
| 3428 | { |
| 3429 | int i; |
| 3430 | struct handshake *hs; |
| 3431 | |
| 3432 | init_completion(&first_stage); |
| 3433 | |
Raghu Vatsavayi | 97a2532 | 2016-11-14 15:54:47 -0800 | [diff] [blame] | 3434 | octeon_init_device_list(OCTEON_CONFIG_TYPE_DEFAULT); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3435 | |
| 3436 | if (liquidio_init_pci()) |
| 3437 | return -EINVAL; |
| 3438 | |
| 3439 | wait_for_completion_timeout(&first_stage, msecs_to_jiffies(1000)); |
| 3440 | |
| 3441 | for (i = 0; i < MAX_OCTEON_DEVICES; i++) { |
| 3442 | hs = &handshake[i]; |
| 3443 | if (hs->pci_dev) { |
| 3444 | wait_for_completion(&hs->init); |
| 3445 | if (!hs->init_ok) { |
| 3446 | /* init handshake failed */ |
| 3447 | dev_err(&hs->pci_dev->dev, |
| 3448 | "Failed to init device\n"); |
| 3449 | liquidio_deinit_pci(); |
| 3450 | return -EIO; |
| 3451 | } |
| 3452 | } |
| 3453 | } |
| 3454 | |
| 3455 | for (i = 0; i < MAX_OCTEON_DEVICES; i++) { |
| 3456 | hs = &handshake[i]; |
| 3457 | if (hs->pci_dev) { |
| 3458 | wait_for_completion_timeout(&hs->started, |
| 3459 | msecs_to_jiffies(30000)); |
| 3460 | if (!hs->started_ok) { |
| 3461 | /* starter handshake failed */ |
| 3462 | dev_err(&hs->pci_dev->dev, |
| 3463 | "Firmware failed to start\n"); |
| 3464 | liquidio_deinit_pci(); |
| 3465 | return -EIO; |
| 3466 | } |
| 3467 | } |
| 3468 | } |
| 3469 | |
| 3470 | return 0; |
| 3471 | } |
| 3472 | |
Raghu Vatsavayi | 5b173cf | 2015-06-12 18:11:50 -0700 | [diff] [blame] | 3473 | static int lio_nic_info(struct octeon_recv_info *recv_info, void *buf) |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3474 | { |
| 3475 | struct octeon_device *oct = (struct octeon_device *)buf; |
| 3476 | struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3477 | int gmxport = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3478 | union oct_link_status *ls; |
| 3479 | int i; |
| 3480 | |
Prasad Kanneganti | c4ee5d8 | 2017-06-18 05:04:11 -0700 | [diff] [blame] | 3481 | if (recv_pkt->buffer_size[0] != (sizeof(*ls) + OCT_DROQ_INFO_SIZE)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3482 | dev_err(&oct->pci_dev->dev, "Malformed NIC_INFO, len=%d, ifidx=%d\n", |
| 3483 | recv_pkt->buffer_size[0], |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3484 | recv_pkt->rh.r_nic_info.gmxport); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3485 | goto nic_info_err; |
| 3486 | } |
| 3487 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3488 | gmxport = recv_pkt->rh.r_nic_info.gmxport; |
Prasad Kanneganti | c4ee5d8 | 2017-06-18 05:04:11 -0700 | [diff] [blame] | 3489 | ls = (union oct_link_status *)(get_rbd(recv_pkt->buffer_ptr[0]) + |
| 3490 | OCT_DROQ_INFO_SIZE); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3491 | |
| 3492 | octeon_swap_8B_data((u64 *)ls, (sizeof(union oct_link_status)) >> 3); |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3493 | for (i = 0; i < oct->ifcount; i++) { |
| 3494 | if (oct->props[i].gmxport == gmxport) { |
| 3495 | update_link_status(oct->props[i].netdev, ls); |
| 3496 | break; |
| 3497 | } |
| 3498 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3499 | |
| 3500 | nic_info_err: |
| 3501 | for (i = 0; i < recv_pkt->buffer_count; i++) |
| 3502 | recv_buffer_free(recv_pkt->buffer_ptr[i]); |
| 3503 | octeon_free_recv_info(recv_info); |
| 3504 | return 0; |
| 3505 | } |
| 3506 | |
| 3507 | /** |
| 3508 | * \brief Setup network interfaces |
| 3509 | * @param octeon_dev octeon device |
| 3510 | * |
| 3511 | * Called during init time for each device. It assumes the NIC |
| 3512 | * is already up and running. The link information for each |
| 3513 | * interface is passed in link_info. |
| 3514 | */ |
| 3515 | static int setup_nic_devices(struct octeon_device *octeon_dev) |
| 3516 | { |
| 3517 | struct lio *lio = NULL; |
| 3518 | struct net_device *netdev; |
Rick Farrington | b36e482 | 2017-09-22 17:12:47 -0700 | [diff] [blame] | 3519 | u8 mac[6], i, j, *fw_ver; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3520 | struct octeon_soft_command *sc; |
| 3521 | struct liquidio_if_cfg_context *ctx; |
| 3522 | struct liquidio_if_cfg_resp *resp; |
| 3523 | struct octdev_props *props; |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 3524 | int retval, num_iqueues, num_oqueues; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3525 | union oct_nic_if_cfg if_cfg; |
| 3526 | unsigned int base_queue; |
| 3527 | unsigned int gmx_port_id; |
Raghu Vatsavayi | 83101ce | 2016-08-31 11:03:21 -0700 | [diff] [blame] | 3528 | u32 resp_size, ctx_size, data_size; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3529 | u32 ifidx_or_pfnum; |
Raghu Vatsavayi | 83101ce | 2016-08-31 11:03:21 -0700 | [diff] [blame] | 3530 | struct lio_version *vdata; |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 3531 | struct devlink *devlink; |
| 3532 | struct lio_devlink_priv *lio_devlink; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3533 | |
| 3534 | /* This is to handle link status changes */ |
| 3535 | octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC, |
| 3536 | OPCODE_NIC_INFO, |
| 3537 | lio_nic_info, octeon_dev); |
| 3538 | |
| 3539 | /* REQTYPE_RESP_NET and REQTYPE_SOFT_COMMAND do not have free functions. |
| 3540 | * They are handled directly. |
| 3541 | */ |
| 3542 | octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET, |
| 3543 | free_netbuf); |
| 3544 | |
| 3545 | octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET_SG, |
| 3546 | free_netsgbuf); |
| 3547 | |
| 3548 | octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_RESP_NET_SG, |
| 3549 | free_netsgbuf_with_resp); |
| 3550 | |
| 3551 | for (i = 0; i < octeon_dev->ifcount; i++) { |
| 3552 | resp_size = sizeof(struct liquidio_if_cfg_resp); |
| 3553 | ctx_size = sizeof(struct liquidio_if_cfg_context); |
Raghu Vatsavayi | 83101ce | 2016-08-31 11:03:21 -0700 | [diff] [blame] | 3554 | data_size = sizeof(struct lio_version); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3555 | sc = (struct octeon_soft_command *) |
Raghu Vatsavayi | 83101ce | 2016-08-31 11:03:21 -0700 | [diff] [blame] | 3556 | octeon_alloc_soft_command(octeon_dev, data_size, |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3557 | resp_size, ctx_size); |
| 3558 | resp = (struct liquidio_if_cfg_resp *)sc->virtrptr; |
| 3559 | ctx = (struct liquidio_if_cfg_context *)sc->ctxptr; |
Raghu Vatsavayi | 83101ce | 2016-08-31 11:03:21 -0700 | [diff] [blame] | 3560 | vdata = (struct lio_version *)sc->virtdptr; |
| 3561 | |
| 3562 | *((u64 *)vdata) = 0; |
| 3563 | vdata->major = cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION); |
| 3564 | vdata->minor = cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION); |
| 3565 | vdata->micro = cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3566 | |
Raghu Vatsavayi | e86b1ab | 2016-08-31 11:03:24 -0700 | [diff] [blame] | 3567 | if (OCTEON_CN23XX_PF(octeon_dev)) { |
| 3568 | num_iqueues = octeon_dev->sriov_info.num_pf_rings; |
| 3569 | num_oqueues = octeon_dev->sriov_info.num_pf_rings; |
| 3570 | base_queue = octeon_dev->sriov_info.pf_srn; |
| 3571 | |
| 3572 | gmx_port_id = octeon_dev->pf_num; |
| 3573 | ifidx_or_pfnum = octeon_dev->pf_num; |
| 3574 | } else { |
| 3575 | num_iqueues = CFG_GET_NUM_TXQS_NIC_IF( |
| 3576 | octeon_get_conf(octeon_dev), i); |
| 3577 | num_oqueues = CFG_GET_NUM_RXQS_NIC_IF( |
| 3578 | octeon_get_conf(octeon_dev), i); |
| 3579 | base_queue = CFG_GET_BASE_QUE_NIC_IF( |
| 3580 | octeon_get_conf(octeon_dev), i); |
| 3581 | gmx_port_id = CFG_GET_GMXID_NIC_IF( |
| 3582 | octeon_get_conf(octeon_dev), i); |
| 3583 | ifidx_or_pfnum = i; |
| 3584 | } |
Raghu Vatsavayi | 3dcef2c | 2016-07-03 13:56:51 -0700 | [diff] [blame] | 3585 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3586 | dev_dbg(&octeon_dev->pci_dev->dev, |
| 3587 | "requesting config for interface %d, iqs %d, oqs %d\n", |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3588 | ifidx_or_pfnum, num_iqueues, num_oqueues); |
Raghu Vatsavayi | a7d5a3d | 2016-07-03 13:56:48 -0700 | [diff] [blame] | 3589 | WRITE_ONCE(ctx->cond, 0); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3590 | ctx->octeon_id = lio_get_device_id(octeon_dev); |
| 3591 | init_waitqueue_head(&ctx->wc); |
| 3592 | |
| 3593 | if_cfg.u64 = 0; |
| 3594 | if_cfg.s.num_iqueues = num_iqueues; |
| 3595 | if_cfg.s.num_oqueues = num_oqueues; |
| 3596 | if_cfg.s.base_queue = base_queue; |
| 3597 | if_cfg.s.gmx_port_id = gmx_port_id; |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3598 | |
| 3599 | sc->iq_no = 0; |
| 3600 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3601 | octeon_prepare_soft_command(octeon_dev, sc, OPCODE_NIC, |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3602 | OPCODE_NIC_IF_CFG, 0, |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3603 | if_cfg.u64, 0); |
| 3604 | |
| 3605 | sc->callback = if_cfg_callback; |
| 3606 | sc->callback_arg = sc; |
Raghu Vatsavayi | 55893a6 | 2016-07-03 13:56:50 -0700 | [diff] [blame] | 3607 | sc->wait_time = 3000; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3608 | |
| 3609 | retval = octeon_send_soft_command(octeon_dev, sc); |
Raghu Vatsavayi | ddc173a | 2016-06-14 16:54:43 -0700 | [diff] [blame] | 3610 | if (retval == IQ_SEND_FAILED) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3611 | dev_err(&octeon_dev->pci_dev->dev, |
| 3612 | "iq/oq config failed status: %x\n", |
| 3613 | retval); |
| 3614 | /* Soft instr is freed by driver in case of failure. */ |
| 3615 | goto setup_nic_dev_fail; |
| 3616 | } |
| 3617 | |
| 3618 | /* Sleep on a wait queue till the cond flag indicates that the |
| 3619 | * response arrived or timed-out. |
| 3620 | */ |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 3621 | if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) { |
| 3622 | dev_err(&octeon_dev->pci_dev->dev, "Wait interrupted\n"); |
| 3623 | goto setup_nic_wait_intr; |
| 3624 | } |
| 3625 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3626 | retval = resp->status; |
| 3627 | if (retval) { |
| 3628 | dev_err(&octeon_dev->pci_dev->dev, "iq/oq config failed\n"); |
| 3629 | goto setup_nic_dev_fail; |
| 3630 | } |
| 3631 | |
Rick Farrington | b36e482 | 2017-09-22 17:12:47 -0700 | [diff] [blame] | 3632 | /* Verify f/w version (in case of 'auto' loading from flash) */ |
| 3633 | fw_ver = octeon_dev->fw_info.liquidio_firmware_version; |
| 3634 | if (memcmp(LIQUIDIO_BASE_VERSION, |
| 3635 | fw_ver, |
| 3636 | strlen(LIQUIDIO_BASE_VERSION))) { |
| 3637 | dev_err(&octeon_dev->pci_dev->dev, |
| 3638 | "Unmatched firmware version. Expected %s.x, got %s.\n", |
| 3639 | LIQUIDIO_BASE_VERSION, fw_ver); |
| 3640 | goto setup_nic_dev_fail; |
| 3641 | } else if (atomic_read(octeon_dev->adapter_fw_state) == |
| 3642 | FW_IS_PRELOADED) { |
| 3643 | dev_info(&octeon_dev->pci_dev->dev, |
| 3644 | "Using auto-loaded firmware version %s.\n", |
| 3645 | fw_ver); |
| 3646 | } |
| 3647 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3648 | octeon_swap_8B_data((u64 *)(&resp->cfg_info), |
| 3649 | (sizeof(struct liquidio_if_cfg_info)) >> 3); |
| 3650 | |
| 3651 | num_iqueues = hweight64(resp->cfg_info.iqmask); |
| 3652 | num_oqueues = hweight64(resp->cfg_info.oqmask); |
| 3653 | |
| 3654 | if (!(num_iqueues) || !(num_oqueues)) { |
| 3655 | dev_err(&octeon_dev->pci_dev->dev, |
| 3656 | "Got bad iqueues (%016llx) or oqueues (%016llx) from firmware.\n", |
| 3657 | resp->cfg_info.iqmask, |
| 3658 | resp->cfg_info.oqmask); |
| 3659 | goto setup_nic_dev_fail; |
| 3660 | } |
| 3661 | dev_dbg(&octeon_dev->pci_dev->dev, |
| 3662 | "interface %d, iqmask %016llx, oqmask %016llx, numiqueues %d, numoqueues %d\n", |
| 3663 | i, resp->cfg_info.iqmask, resp->cfg_info.oqmask, |
| 3664 | num_iqueues, num_oqueues); |
| 3665 | netdev = alloc_etherdev_mq(LIO_SIZE, num_iqueues); |
| 3666 | |
| 3667 | if (!netdev) { |
| 3668 | dev_err(&octeon_dev->pci_dev->dev, "Device allocation failed\n"); |
| 3669 | goto setup_nic_dev_fail; |
| 3670 | } |
| 3671 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3672 | SET_NETDEV_DEV(netdev, &octeon_dev->pci_dev->dev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3673 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3674 | /* Associate the routines that will handle different |
| 3675 | * netdev tasks. |
| 3676 | */ |
| 3677 | netdev->netdev_ops = &lionetdevops; |
Vijaya Mohan Guvva | 1f233f3 | 2017-10-31 16:04:53 -0700 | [diff] [blame] | 3678 | SWITCHDEV_SET_OPS(netdev, &lio_pf_switchdev_ops); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3679 | |
| 3680 | lio = GET_LIO(netdev); |
| 3681 | |
| 3682 | memset(lio, 0, sizeof(struct lio)); |
| 3683 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3684 | lio->ifidx = ifidx_or_pfnum; |
| 3685 | |
| 3686 | props = &octeon_dev->props[i]; |
| 3687 | props->gmxport = resp->cfg_info.linfo.gmxport; |
| 3688 | props->netdev = netdev; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3689 | |
| 3690 | lio->linfo.num_rxpciq = num_oqueues; |
| 3691 | lio->linfo.num_txpciq = num_iqueues; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3692 | for (j = 0; j < num_oqueues; j++) { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 3693 | lio->linfo.rxpciq[j].u64 = |
| 3694 | resp->cfg_info.linfo.rxpciq[j].u64; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3695 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3696 | for (j = 0; j < num_iqueues; j++) { |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 3697 | lio->linfo.txpciq[j].u64 = |
| 3698 | resp->cfg_info.linfo.txpciq[j].u64; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3699 | } |
| 3700 | lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr; |
| 3701 | lio->linfo.gmxport = resp->cfg_info.linfo.gmxport; |
| 3702 | lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64; |
| 3703 | |
| 3704 | lio->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE); |
| 3705 | |
Raghu Vatsavayi | e86b1ab | 2016-08-31 11:03:24 -0700 | [diff] [blame] | 3706 | if (OCTEON_CN23XX_PF(octeon_dev) || |
| 3707 | OCTEON_CN6XXX(octeon_dev)) { |
| 3708 | lio->dev_capability = NETIF_F_HIGHDMA |
| 3709 | | NETIF_F_IP_CSUM |
| 3710 | | NETIF_F_IPV6_CSUM |
| 3711 | | NETIF_F_SG | NETIF_F_RXCSUM |
| 3712 | | NETIF_F_GRO |
| 3713 | | NETIF_F_TSO | NETIF_F_TSO6 |
| 3714 | | NETIF_F_LRO; |
| 3715 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3716 | netif_set_gso_max_size(netdev, OCTNIC_GSO_MAX_SIZE); |
| 3717 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3718 | /* Copy of transmit encapsulation capabilities: |
| 3719 | * TSO, TSO6, Checksums for this device |
| 3720 | */ |
| 3721 | lio->enc_dev_capability = NETIF_F_IP_CSUM |
| 3722 | | NETIF_F_IPV6_CSUM |
| 3723 | | NETIF_F_GSO_UDP_TUNNEL |
| 3724 | | NETIF_F_HW_CSUM | NETIF_F_SG |
| 3725 | | NETIF_F_RXCSUM |
| 3726 | | NETIF_F_TSO | NETIF_F_TSO6 |
| 3727 | | NETIF_F_LRO; |
| 3728 | |
| 3729 | netdev->hw_enc_features = (lio->enc_dev_capability & |
| 3730 | ~NETIF_F_LRO); |
| 3731 | |
| 3732 | lio->dev_capability |= NETIF_F_GSO_UDP_TUNNEL; |
| 3733 | |
Raghu Vatsavayi | 0da0b77 | 2016-06-21 22:53:04 -0700 | [diff] [blame] | 3734 | netdev->vlan_features = lio->dev_capability; |
| 3735 | /* Add any unchangeable hw features */ |
Raghu Vatsavayi | 63245f2 | 2016-06-21 22:53:05 -0700 | [diff] [blame] | 3736 | lio->dev_capability |= NETIF_F_HW_VLAN_CTAG_FILTER | |
| 3737 | NETIF_F_HW_VLAN_CTAG_RX | |
Raghu Vatsavayi | 0da0b77 | 2016-06-21 22:53:04 -0700 | [diff] [blame] | 3738 | NETIF_F_HW_VLAN_CTAG_TX; |
| 3739 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3740 | netdev->features = (lio->dev_capability & ~NETIF_F_LRO); |
| 3741 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3742 | netdev->hw_features = lio->dev_capability; |
Raghu Vatsavayi | 0da0b77 | 2016-06-21 22:53:04 -0700 | [diff] [blame] | 3743 | /*HW_VLAN_RX and HW_VLAN_FILTER is always on*/ |
| 3744 | netdev->hw_features = netdev->hw_features & |
| 3745 | ~NETIF_F_HW_VLAN_CTAG_RX; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3746 | |
Jarod Wilson | 109cc16 | 2016-10-17 15:54:13 -0400 | [diff] [blame] | 3747 | /* MTU range: 68 - 16000 */ |
| 3748 | netdev->min_mtu = LIO_MIN_MTU_SIZE; |
| 3749 | netdev->max_mtu = LIO_MAX_MTU_SIZE; |
| 3750 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3751 | /* Point to the properties for octeon device to which this |
| 3752 | * interface belongs. |
| 3753 | */ |
| 3754 | lio->oct_dev = octeon_dev; |
| 3755 | lio->octprops = props; |
| 3756 | lio->netdev = netdev; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3757 | |
| 3758 | dev_dbg(&octeon_dev->pci_dev->dev, |
| 3759 | "if%d gmx: %d hw_addr: 0x%llx\n", i, |
| 3760 | lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr)); |
| 3761 | |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 3762 | for (j = 0; j < octeon_dev->sriov_info.max_vfs; j++) { |
| 3763 | u8 vfmac[ETH_ALEN]; |
| 3764 | |
| 3765 | random_ether_addr(&vfmac[0]); |
| 3766 | if (__liquidio_set_vf_mac(netdev, j, |
| 3767 | &vfmac[0], false)) { |
| 3768 | dev_err(&octeon_dev->pci_dev->dev, |
| 3769 | "Error setting VF%d MAC address\n", |
| 3770 | j); |
| 3771 | goto setup_nic_dev_fail; |
| 3772 | } |
| 3773 | } |
| 3774 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3775 | /* 64-bit swap required on LE machines */ |
| 3776 | octeon_swap_8B_data(&lio->linfo.hw_addr, 1); |
| 3777 | for (j = 0; j < 6; j++) |
| 3778 | mac[j] = *((u8 *)(((u8 *)&lio->linfo.hw_addr) + 2 + j)); |
| 3779 | |
| 3780 | /* Copy MAC Address to OS network device structure */ |
| 3781 | |
| 3782 | ether_addr_copy(netdev->dev_addr, mac); |
| 3783 | |
Raghu Vatsavayi | 26236fa | 2016-06-14 16:54:44 -0700 | [diff] [blame] | 3784 | /* By default all interfaces on a single Octeon uses the same |
| 3785 | * tx and rx queues |
| 3786 | */ |
| 3787 | lio->txq = lio->linfo.txpciq[0].s.q_no; |
| 3788 | lio->rxq = lio->linfo.rxpciq[0].s.q_no; |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 3789 | if (liquidio_setup_io_queues(octeon_dev, i, |
| 3790 | lio->linfo.num_txpciq, |
| 3791 | lio->linfo.num_rxpciq)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3792 | dev_err(&octeon_dev->pci_dev->dev, "I/O queues creation failed\n"); |
| 3793 | goto setup_nic_dev_fail; |
| 3794 | } |
| 3795 | |
| 3796 | ifstate_set(lio, LIO_IFSTATE_DROQ_OPS); |
| 3797 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3798 | lio->tx_qsize = octeon_get_tx_qsize(octeon_dev, lio->txq); |
| 3799 | lio->rx_qsize = octeon_get_rx_qsize(octeon_dev, lio->rxq); |
| 3800 | |
Raghu Vatsavayi | fcd2b5e | 2016-06-14 16:54:45 -0700 | [diff] [blame] | 3801 | if (setup_glists(octeon_dev, lio, num_iqueues)) { |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3802 | dev_err(&octeon_dev->pci_dev->dev, |
| 3803 | "Gather list allocation failed\n"); |
| 3804 | goto setup_nic_dev_fail; |
| 3805 | } |
| 3806 | |
| 3807 | /* Register ethtool support */ |
| 3808 | liquidio_set_ethtool_ops(netdev); |
Raghu Vatsavayi | 3013639 | 2016-09-01 11:16:11 -0700 | [diff] [blame] | 3809 | if (lio->oct_dev->chip_id == OCTEON_CN23XX_PF_VID) |
| 3810 | octeon_dev->priv_flags = OCT_PRIV_FLAG_DEFAULT; |
| 3811 | else |
| 3812 | octeon_dev->priv_flags = 0x0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3813 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3814 | if (netdev->features & NETIF_F_LRO) |
Raghu Vatsavayi | a2c64b6 | 2016-07-03 13:56:55 -0700 | [diff] [blame] | 3815 | liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE, |
| 3816 | OCTNIC_LROIPV4 | OCTNIC_LROIPV6); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3817 | |
Prasad Kanneganti | 836d57e | 2017-06-18 12:41:34 -0700 | [diff] [blame] | 3818 | liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL, |
| 3819 | OCTNET_CMD_VLAN_FILTER_ENABLE); |
Raghu Vatsavayi | 63245f2 | 2016-06-21 22:53:05 -0700 | [diff] [blame] | 3820 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3821 | if ((debug != -1) && (debug & NETIF_MSG_HW)) |
Raghu Vatsavayi | 63245f2 | 2016-06-21 22:53:05 -0700 | [diff] [blame] | 3822 | liquidio_set_feature(netdev, |
| 3823 | OCTNET_CMD_VERBOSE_ENABLE, 0); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3824 | |
Raghu Vatsavayi | 7b6b6c9 | 2016-09-01 11:16:04 -0700 | [diff] [blame] | 3825 | if (setup_link_status_change_wq(netdev)) |
| 3826 | goto setup_nic_dev_fail; |
| 3827 | |
Veerasenareddy Burru | 907aaa6 | 2017-10-23 20:33:25 -0700 | [diff] [blame] | 3828 | if ((octeon_dev->fw_info.app_cap_flags & |
| 3829 | LIQUIDIO_TIME_SYNC_CAP) && |
| 3830 | setup_sync_octeon_time_wq(netdev)) |
| 3831 | goto setup_nic_dev_fail; |
| 3832 | |
Satanand Burla | 031d4f1 | 2017-03-22 11:31:13 -0700 | [diff] [blame] | 3833 | if (setup_rx_oom_poll_fn(netdev)) |
| 3834 | goto setup_nic_dev_fail; |
| 3835 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3836 | /* Register the network device with the OS */ |
| 3837 | if (register_netdev(netdev)) { |
| 3838 | dev_err(&octeon_dev->pci_dev->dev, "Device registration failed\n"); |
| 3839 | goto setup_nic_dev_fail; |
| 3840 | } |
| 3841 | |
| 3842 | dev_dbg(&octeon_dev->pci_dev->dev, |
| 3843 | "Setup NIC ifidx:%d mac:%02x%02x%02x%02x%02x%02x\n", |
| 3844 | i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); |
| 3845 | netif_carrier_off(netdev); |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 3846 | lio->link_changes++; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3847 | |
| 3848 | ifstate_set(lio, LIO_IFSTATE_REGISTERED); |
| 3849 | |
Raghu Vatsavayi | 01fb237 | 2016-07-03 13:56:47 -0700 | [diff] [blame] | 3850 | /* Sending command to firmware to enable Rx checksum offload |
| 3851 | * by default at the time of setup of Liquidio driver for |
| 3852 | * this device |
| 3853 | */ |
| 3854 | liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL, |
| 3855 | OCTNET_CMD_RXCSUM_ENABLE); |
| 3856 | liquidio_set_feature(netdev, OCTNET_CMD_TNL_TX_CSUM_CTL, |
| 3857 | OCTNET_CMD_TXCSUM_ENABLE); |
| 3858 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3859 | dev_dbg(&octeon_dev->pci_dev->dev, |
| 3860 | "NIC ifidx:%d Setup successful\n", i); |
| 3861 | |
| 3862 | octeon_free_soft_command(octeon_dev, sc); |
| 3863 | } |
| 3864 | |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 3865 | devlink = devlink_alloc(&liquidio_devlink_ops, |
| 3866 | sizeof(struct lio_devlink_priv)); |
| 3867 | if (!devlink) { |
| 3868 | dev_err(&octeon_dev->pci_dev->dev, "devlink alloc failed\n"); |
| 3869 | goto setup_nic_wait_intr; |
| 3870 | } |
| 3871 | |
| 3872 | lio_devlink = devlink_priv(devlink); |
| 3873 | lio_devlink->oct = octeon_dev; |
| 3874 | |
| 3875 | if (devlink_register(devlink, &octeon_dev->pci_dev->dev)) { |
| 3876 | devlink_free(devlink); |
| 3877 | dev_err(&octeon_dev->pci_dev->dev, |
| 3878 | "devlink registration failed\n"); |
| 3879 | goto setup_nic_wait_intr; |
| 3880 | } |
| 3881 | |
| 3882 | octeon_dev->devlink = devlink; |
| 3883 | octeon_dev->eswitch_mode = DEVLINK_ESWITCH_MODE_LEGACY; |
| 3884 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3885 | return 0; |
| 3886 | |
| 3887 | setup_nic_dev_fail: |
| 3888 | |
| 3889 | octeon_free_soft_command(octeon_dev, sc); |
| 3890 | |
Raghu Vatsavayi | afdf841 | 2016-09-01 11:16:05 -0700 | [diff] [blame] | 3891 | setup_nic_wait_intr: |
| 3892 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 3893 | while (i--) { |
| 3894 | dev_err(&octeon_dev->pci_dev->dev, |
| 3895 | "NIC ifidx:%d Setup failed\n", i); |
| 3896 | liquidio_destroy_nic_device(octeon_dev, i); |
| 3897 | } |
| 3898 | return -ENODEV; |
| 3899 | } |
| 3900 | |
Raghu Vatsavayi | ca6139f | 2016-11-14 15:54:40 -0800 | [diff] [blame] | 3901 | #ifdef CONFIG_PCI_IOV |
| 3902 | static int octeon_enable_sriov(struct octeon_device *oct) |
| 3903 | { |
| 3904 | unsigned int num_vfs_alloced = oct->sriov_info.num_vfs_alloced; |
| 3905 | struct pci_dev *vfdev; |
| 3906 | int err; |
| 3907 | u32 u; |
| 3908 | |
| 3909 | if (OCTEON_CN23XX_PF(oct) && num_vfs_alloced) { |
| 3910 | err = pci_enable_sriov(oct->pci_dev, |
| 3911 | oct->sriov_info.num_vfs_alloced); |
| 3912 | if (err) { |
| 3913 | dev_err(&oct->pci_dev->dev, |
| 3914 | "OCTEON: Failed to enable PCI sriov: %d\n", |
| 3915 | err); |
| 3916 | oct->sriov_info.num_vfs_alloced = 0; |
| 3917 | return err; |
| 3918 | } |
| 3919 | oct->sriov_info.sriov_enabled = 1; |
| 3920 | |
| 3921 | /* init lookup table that maps DPI ring number to VF pci_dev |
| 3922 | * struct pointer |
| 3923 | */ |
| 3924 | u = 0; |
| 3925 | vfdev = pci_get_device(PCI_VENDOR_ID_CAVIUM, |
| 3926 | OCTEON_CN23XX_VF_VID, NULL); |
| 3927 | while (vfdev) { |
| 3928 | if (vfdev->is_virtfn && |
| 3929 | (vfdev->physfn == oct->pci_dev)) { |
| 3930 | oct->sriov_info.dpiring_to_vfpcidev_lut[u] = |
| 3931 | vfdev; |
| 3932 | u += oct->sriov_info.rings_per_vf; |
| 3933 | } |
| 3934 | vfdev = pci_get_device(PCI_VENDOR_ID_CAVIUM, |
| 3935 | OCTEON_CN23XX_VF_VID, vfdev); |
| 3936 | } |
| 3937 | } |
| 3938 | |
| 3939 | return num_vfs_alloced; |
| 3940 | } |
| 3941 | |
| 3942 | static int lio_pci_sriov_disable(struct octeon_device *oct) |
| 3943 | { |
| 3944 | int u; |
| 3945 | |
| 3946 | if (pci_vfs_assigned(oct->pci_dev)) { |
| 3947 | dev_err(&oct->pci_dev->dev, "VFs are still assigned to VMs.\n"); |
| 3948 | return -EPERM; |
| 3949 | } |
| 3950 | |
| 3951 | pci_disable_sriov(oct->pci_dev); |
| 3952 | |
| 3953 | u = 0; |
| 3954 | while (u < MAX_POSSIBLE_VFS) { |
| 3955 | oct->sriov_info.dpiring_to_vfpcidev_lut[u] = NULL; |
| 3956 | u += oct->sriov_info.rings_per_vf; |
| 3957 | } |
| 3958 | |
| 3959 | oct->sriov_info.num_vfs_alloced = 0; |
| 3960 | dev_info(&oct->pci_dev->dev, "oct->pf_num:%d disabled VFs\n", |
| 3961 | oct->pf_num); |
| 3962 | |
| 3963 | return 0; |
| 3964 | } |
| 3965 | |
| 3966 | static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs) |
| 3967 | { |
| 3968 | struct octeon_device *oct = pci_get_drvdata(dev); |
| 3969 | int ret = 0; |
| 3970 | |
| 3971 | if ((num_vfs == oct->sriov_info.num_vfs_alloced) && |
| 3972 | (oct->sriov_info.sriov_enabled)) { |
| 3973 | dev_info(&oct->pci_dev->dev, "oct->pf_num:%d already enabled num_vfs:%d\n", |
| 3974 | oct->pf_num, num_vfs); |
| 3975 | return 0; |
| 3976 | } |
| 3977 | |
| 3978 | if (!num_vfs) { |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 3979 | lio_vf_rep_destroy(oct); |
Raghu Vatsavayi | ca6139f | 2016-11-14 15:54:40 -0800 | [diff] [blame] | 3980 | ret = lio_pci_sriov_disable(oct); |
| 3981 | } else if (num_vfs > oct->sriov_info.max_vfs) { |
| 3982 | dev_err(&oct->pci_dev->dev, |
| 3983 | "OCTEON: Max allowed VFs:%d user requested:%d", |
| 3984 | oct->sriov_info.max_vfs, num_vfs); |
| 3985 | ret = -EPERM; |
| 3986 | } else { |
| 3987 | oct->sriov_info.num_vfs_alloced = num_vfs; |
| 3988 | ret = octeon_enable_sriov(oct); |
| 3989 | dev_info(&oct->pci_dev->dev, "oct->pf_num:%d num_vfs:%d\n", |
| 3990 | oct->pf_num, num_vfs); |
Vijaya Mohan Guvva | d4be8eb | 2017-10-31 16:04:57 -0700 | [diff] [blame] | 3991 | ret = lio_vf_rep_create(oct); |
| 3992 | if (ret) |
| 3993 | dev_info(&oct->pci_dev->dev, |
| 3994 | "vf representor create failed"); |
Raghu Vatsavayi | ca6139f | 2016-11-14 15:54:40 -0800 | [diff] [blame] | 3995 | } |
| 3996 | |
| 3997 | return ret; |
| 3998 | } |
| 3999 | #endif |
| 4000 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4001 | /** |
| 4002 | * \brief initialize the NIC |
| 4003 | * @param oct octeon device |
| 4004 | * |
| 4005 | * This initialization routine is called once the Octeon device application is |
| 4006 | * up and running |
| 4007 | */ |
| 4008 | static int liquidio_init_nic_module(struct octeon_device *oct) |
| 4009 | { |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 4010 | int i, retval = 0; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4011 | int num_nic_ports = CFG_GET_NUM_NIC_PORTS(octeon_get_conf(oct)); |
| 4012 | |
| 4013 | dev_dbg(&oct->pci_dev->dev, "Initializing network interfaces\n"); |
| 4014 | |
| 4015 | /* only default iq and oq were initialized |
| 4016 | * initialize the rest as well |
| 4017 | */ |
| 4018 | /* run port_config command for each port */ |
| 4019 | oct->ifcount = num_nic_ports; |
| 4020 | |
Raghu Vatsavayi | 3013639 | 2016-09-01 11:16:11 -0700 | [diff] [blame] | 4021 | memset(oct->props, 0, sizeof(struct octdev_props) * num_nic_ports); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4022 | |
Raghu Vatsavayi | 0cece6c | 2016-06-14 16:54:50 -0700 | [diff] [blame] | 4023 | for (i = 0; i < MAX_OCTEON_LINKS; i++) |
| 4024 | oct->props[i].gmxport = -1; |
| 4025 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4026 | retval = setup_nic_devices(oct); |
| 4027 | if (retval) { |
| 4028 | dev_err(&oct->pci_dev->dev, "Setup NIC devices failed\n"); |
| 4029 | goto octnet_init_failure; |
| 4030 | } |
| 4031 | |
| 4032 | liquidio_ptp_init(oct); |
| 4033 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4034 | dev_dbg(&oct->pci_dev->dev, "Network interfaces ready\n"); |
| 4035 | |
| 4036 | return retval; |
| 4037 | |
| 4038 | octnet_init_failure: |
| 4039 | |
| 4040 | oct->ifcount = 0; |
| 4041 | |
| 4042 | return retval; |
| 4043 | } |
| 4044 | |
| 4045 | /** |
| 4046 | * \brief starter callback that invokes the remaining initialization work after |
| 4047 | * the NIC is up and running. |
| 4048 | * @param octptr work struct work_struct |
| 4049 | */ |
| 4050 | static void nic_starter(struct work_struct *work) |
| 4051 | { |
| 4052 | struct octeon_device *oct; |
| 4053 | struct cavium_wk *wk = (struct cavium_wk *)work; |
| 4054 | |
| 4055 | oct = (struct octeon_device *)wk->ctxptr; |
| 4056 | |
| 4057 | if (atomic_read(&oct->status) == OCT_DEV_RUNNING) |
| 4058 | return; |
| 4059 | |
| 4060 | /* If the status of the device is CORE_OK, the core |
| 4061 | * application has reported its application type. Call |
| 4062 | * any registered handlers now and move to the RUNNING |
| 4063 | * state. |
| 4064 | */ |
| 4065 | if (atomic_read(&oct->status) != OCT_DEV_CORE_OK) { |
| 4066 | schedule_delayed_work(&oct->nic_poll_work.work, |
| 4067 | LIQUIDIO_STARTER_POLL_INTERVAL_MS); |
| 4068 | return; |
| 4069 | } |
| 4070 | |
| 4071 | atomic_set(&oct->status, OCT_DEV_RUNNING); |
| 4072 | |
| 4073 | if (oct->app_mode && oct->app_mode == CVM_DRV_NIC_APP) { |
| 4074 | dev_dbg(&oct->pci_dev->dev, "Starting NIC module\n"); |
| 4075 | |
| 4076 | if (liquidio_init_nic_module(oct)) |
| 4077 | dev_err(&oct->pci_dev->dev, "NIC initialization failed\n"); |
| 4078 | else |
| 4079 | handshake[oct->octeon_id].started_ok = 1; |
| 4080 | } else { |
| 4081 | dev_err(&oct->pci_dev->dev, |
| 4082 | "Unexpected application running on NIC (%d). Check firmware.\n", |
| 4083 | oct->app_mode); |
| 4084 | } |
| 4085 | |
| 4086 | complete(&handshake[oct->octeon_id].started); |
| 4087 | } |
| 4088 | |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4089 | static int |
| 4090 | octeon_recv_vf_drv_notice(struct octeon_recv_info *recv_info, void *buf) |
| 4091 | { |
| 4092 | struct octeon_device *oct = (struct octeon_device *)buf; |
| 4093 | struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt; |
| 4094 | int i, notice, vf_idx; |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 4095 | bool cores_crashed; |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4096 | u64 *data, vf_num; |
| 4097 | |
| 4098 | notice = recv_pkt->rh.r.ossp; |
Prasad Kanneganti | c4ee5d8 | 2017-06-18 05:04:11 -0700 | [diff] [blame] | 4099 | data = (u64 *)(get_rbd(recv_pkt->buffer_ptr[0]) + OCT_DROQ_INFO_SIZE); |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4100 | |
| 4101 | /* the first 64-bit word of data is the vf_num */ |
| 4102 | vf_num = data[0]; |
| 4103 | octeon_swap_8B_data(&vf_num, 1); |
| 4104 | vf_idx = (int)vf_num - 1; |
| 4105 | |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 4106 | cores_crashed = READ_ONCE(oct->cores_crashed); |
| 4107 | |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4108 | if (notice == VF_DRV_LOADED) { |
| 4109 | if (!(oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vf_idx))) { |
| 4110 | oct->sriov_info.vf_drv_loaded_mask |= BIT_ULL(vf_idx); |
| 4111 | dev_info(&oct->pci_dev->dev, |
| 4112 | "driver for VF%d was loaded\n", vf_idx); |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 4113 | if (!cores_crashed) |
| 4114 | try_module_get(THIS_MODULE); |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4115 | } |
| 4116 | } else if (notice == VF_DRV_REMOVED) { |
| 4117 | if (oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vf_idx)) { |
| 4118 | oct->sriov_info.vf_drv_loaded_mask &= ~BIT_ULL(vf_idx); |
| 4119 | dev_info(&oct->pci_dev->dev, |
| 4120 | "driver for VF%d was removed\n", vf_idx); |
Felix Manlunas | bb54be5 | 2017-04-04 19:26:57 -0700 | [diff] [blame] | 4121 | if (!cores_crashed) |
| 4122 | module_put(THIS_MODULE); |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4123 | } |
| 4124 | } else if (notice == VF_DRV_MACADDR_CHANGED) { |
| 4125 | u8 *b = (u8 *)&data[1]; |
| 4126 | |
| 4127 | oct->sriov_info.vf_macaddr[vf_idx] = data[1]; |
| 4128 | dev_info(&oct->pci_dev->dev, |
| 4129 | "VF driver changed VF%d's MAC address to %pM\n", |
| 4130 | vf_idx, b + 2); |
| 4131 | } |
| 4132 | |
| 4133 | for (i = 0; i < recv_pkt->buffer_count; i++) |
| 4134 | recv_buffer_free(recv_pkt->buffer_ptr[i]); |
| 4135 | octeon_free_recv_info(recv_info); |
| 4136 | |
| 4137 | return 0; |
| 4138 | } |
| 4139 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4140 | /** |
| 4141 | * \brief Device initialization for each Octeon device that is probed |
| 4142 | * @param octeon_dev octeon device |
| 4143 | */ |
| 4144 | static int octeon_device_init(struct octeon_device *octeon_dev) |
| 4145 | { |
| 4146 | int j, ret; |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 4147 | char bootcmd[] = "\n"; |
Rick Farrington | da1542b | 2017-08-11 18:43:14 -0700 | [diff] [blame] | 4148 | char *dbg_enb = NULL; |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 4149 | enum lio_fw_state fw_state; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4150 | struct octeon_device_priv *oct_priv = |
| 4151 | (struct octeon_device_priv *)octeon_dev->priv; |
| 4152 | atomic_set(&octeon_dev->status, OCT_DEV_BEGIN_STATE); |
| 4153 | |
| 4154 | /* Enable access to the octeon device and make its DMA capability |
| 4155 | * known to the OS. |
| 4156 | */ |
| 4157 | if (octeon_pci_os_setup(octeon_dev)) |
| 4158 | return 1; |
| 4159 | |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 4160 | atomic_set(&octeon_dev->status, OCT_DEV_PCI_ENABLE_DONE); |
| 4161 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4162 | /* Identify the Octeon type and map the BAR address space. */ |
| 4163 | if (octeon_chip_specific_setup(octeon_dev)) { |
| 4164 | dev_err(&octeon_dev->pci_dev->dev, "Chip specific setup failed\n"); |
| 4165 | return 1; |
| 4166 | } |
| 4167 | |
| 4168 | atomic_set(&octeon_dev->status, OCT_DEV_PCI_MAP_DONE); |
| 4169 | |
Rick Farrington | e1e3ce6 | 2017-05-16 11:14:50 -0700 | [diff] [blame] | 4170 | /* Only add a reference after setting status 'OCT_DEV_PCI_MAP_DONE', |
| 4171 | * since that is what is required for the reference to be removed |
| 4172 | * during de-initialization (see 'octeon_destroy_resources'). |
| 4173 | */ |
| 4174 | octeon_register_device(octeon_dev, octeon_dev->pci_dev->bus->number, |
| 4175 | PCI_SLOT(octeon_dev->pci_dev->devfn), |
| 4176 | PCI_FUNC(octeon_dev->pci_dev->devfn), |
| 4177 | true); |
| 4178 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4179 | octeon_dev->app_mode = CVM_DRV_INVALID_APP; |
| 4180 | |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 4181 | /* CN23XX supports preloaded firmware if the following is true: |
| 4182 | * |
| 4183 | * The adapter indicates that firmware is currently running AND |
| 4184 | * 'fw_type' is 'auto'. |
| 4185 | * |
| 4186 | * (default state is NEEDS_TO_BE_LOADED, override it if appropriate). |
| 4187 | */ |
| 4188 | if (OCTEON_CN23XX_PF(octeon_dev) && |
| 4189 | cn23xx_fw_loaded(octeon_dev) && fw_type_is_auto()) { |
| 4190 | atomic_cmpxchg(octeon_dev->adapter_fw_state, |
| 4191 | FW_NEEDS_TO_BE_LOADED, FW_IS_PRELOADED); |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4192 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4193 | |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 4194 | /* If loading firmware, only first device of adapter needs to do so. */ |
| 4195 | fw_state = atomic_cmpxchg(octeon_dev->adapter_fw_state, |
| 4196 | FW_NEEDS_TO_BE_LOADED, |
| 4197 | FW_IS_BEING_LOADED); |
| 4198 | |
| 4199 | /* Here, [local variable] 'fw_state' is set to one of: |
| 4200 | * |
| 4201 | * FW_IS_PRELOADED: No firmware is to be loaded (see above) |
| 4202 | * FW_NEEDS_TO_BE_LOADED: The driver's first instance will load |
| 4203 | * firmware to the adapter. |
| 4204 | * FW_IS_BEING_LOADED: The driver's second instance will not load |
| 4205 | * firmware to the adapter. |
| 4206 | */ |
| 4207 | |
| 4208 | /* Prior to f/w load, perform a soft reset of the Octeon device; |
| 4209 | * if error resetting, return w/error. |
| 4210 | */ |
| 4211 | if (fw_state == FW_NEEDS_TO_BE_LOADED) |
| 4212 | if (octeon_dev->fn_list.soft_reset(octeon_dev)) |
| 4213 | return 1; |
| 4214 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4215 | /* Initialize the dispatch mechanism used to push packets arriving on |
| 4216 | * Octeon Output queues. |
| 4217 | */ |
| 4218 | if (octeon_init_dispatch_list(octeon_dev)) |
| 4219 | return 1; |
| 4220 | |
| 4221 | octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC, |
| 4222 | OPCODE_NIC_CORE_DRV_ACTIVE, |
| 4223 | octeon_core_drv_init, |
| 4224 | octeon_dev); |
| 4225 | |
Raghu Vatsavayi | 86dea55 | 2016-11-14 15:54:43 -0800 | [diff] [blame] | 4226 | octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC, |
| 4227 | OPCODE_NIC_VF_DRV_NOTICE, |
| 4228 | octeon_recv_vf_drv_notice, octeon_dev); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4229 | INIT_DELAYED_WORK(&octeon_dev->nic_poll_work.work, nic_starter); |
| 4230 | octeon_dev->nic_poll_work.ctxptr = (void *)octeon_dev; |
| 4231 | schedule_delayed_work(&octeon_dev->nic_poll_work.work, |
| 4232 | LIQUIDIO_STARTER_POLL_INTERVAL_MS); |
| 4233 | |
| 4234 | atomic_set(&octeon_dev->status, OCT_DEV_DISPATCH_INIT_DONE); |
| 4235 | |
Raghu Vatsavayi | c865cdf | 2016-11-28 16:54:36 -0800 | [diff] [blame] | 4236 | if (octeon_set_io_queues_off(octeon_dev)) { |
| 4237 | dev_err(&octeon_dev->pci_dev->dev, "setting io queues off failed\n"); |
| 4238 | return 1; |
| 4239 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4240 | |
Raghu Vatsavayi | 3451b97 | 2016-08-31 11:03:26 -0700 | [diff] [blame] | 4241 | if (OCTEON_CN23XX_PF(octeon_dev)) { |
| 4242 | ret = octeon_dev->fn_list.setup_device_regs(octeon_dev); |
| 4243 | if (ret) { |
| 4244 | dev_err(&octeon_dev->pci_dev->dev, "OCTEON: Failed to configure device registers\n"); |
| 4245 | return ret; |
| 4246 | } |
| 4247 | } |
| 4248 | |
| 4249 | /* Initialize soft command buffer pool |
| 4250 | */ |
| 4251 | if (octeon_setup_sc_buffer_pool(octeon_dev)) { |
| 4252 | dev_err(&octeon_dev->pci_dev->dev, "sc buffer pool allocation failed\n"); |
| 4253 | return 1; |
| 4254 | } |
| 4255 | atomic_set(&octeon_dev->status, OCT_DEV_SC_BUFF_POOL_INIT_DONE); |
| 4256 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4257 | /* Setup the data structures that manage this Octeon's Input queues. */ |
| 4258 | if (octeon_setup_instr_queues(octeon_dev)) { |
| 4259 | dev_err(&octeon_dev->pci_dev->dev, |
| 4260 | "instruction queue initialization failed\n"); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4261 | return 1; |
| 4262 | } |
| 4263 | atomic_set(&octeon_dev->status, OCT_DEV_INSTR_QUEUE_INIT_DONE); |
| 4264 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4265 | /* Initialize lists to manage the requests of different types that |
| 4266 | * arrive from user & kernel applications for this octeon device. |
| 4267 | */ |
| 4268 | if (octeon_setup_response_list(octeon_dev)) { |
| 4269 | dev_err(&octeon_dev->pci_dev->dev, "Response list allocation failed\n"); |
| 4270 | return 1; |
| 4271 | } |
| 4272 | atomic_set(&octeon_dev->status, OCT_DEV_RESP_LIST_INIT_DONE); |
| 4273 | |
| 4274 | if (octeon_setup_output_queues(octeon_dev)) { |
| 4275 | dev_err(&octeon_dev->pci_dev->dev, "Output queue initialization failed\n"); |
Raghu Vatsavayi | 1e0d30f | 2016-07-03 13:56:52 -0700 | [diff] [blame] | 4276 | return 1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4277 | } |
| 4278 | |
| 4279 | atomic_set(&octeon_dev->status, OCT_DEV_DROQ_INIT_DONE); |
| 4280 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 4281 | if (OCTEON_CN23XX_PF(octeon_dev)) { |
Raghu Vatsavayi | 5d65556 | 2016-11-14 15:54:42 -0800 | [diff] [blame] | 4282 | if (octeon_dev->fn_list.setup_mbox(octeon_dev)) { |
| 4283 | dev_err(&octeon_dev->pci_dev->dev, "OCTEON: Mailbox setup failed\n"); |
| 4284 | return 1; |
| 4285 | } |
| 4286 | atomic_set(&octeon_dev->status, OCT_DEV_MBOX_SETUP_DONE); |
| 4287 | |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 4288 | if (octeon_allocate_ioq_vector(octeon_dev)) { |
| 4289 | dev_err(&octeon_dev->pci_dev->dev, "OCTEON: ioq vector allocation failed\n"); |
| 4290 | return 1; |
| 4291 | } |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 4292 | atomic_set(&octeon_dev->status, OCT_DEV_MSIX_ALLOC_VECTOR_DONE); |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 4293 | |
| 4294 | } else { |
| 4295 | /* The input and output queue registers were setup earlier (the |
| 4296 | * queues were not enabled). Any additional registers |
| 4297 | * that need to be programmed should be done now. |
| 4298 | */ |
| 4299 | ret = octeon_dev->fn_list.setup_device_regs(octeon_dev); |
| 4300 | if (ret) { |
| 4301 | dev_err(&octeon_dev->pci_dev->dev, |
| 4302 | "Failed to configure device registers\n"); |
| 4303 | return ret; |
| 4304 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4305 | } |
| 4306 | |
| 4307 | /* Initialize the tasklet that handles output queue packet processing.*/ |
| 4308 | dev_dbg(&octeon_dev->pci_dev->dev, "Initializing droq tasklet\n"); |
| 4309 | tasklet_init(&oct_priv->droq_tasklet, octeon_droq_bh, |
| 4310 | (unsigned long)octeon_dev); |
| 4311 | |
| 4312 | /* Setup the interrupt handler and record the INT SUM register address |
| 4313 | */ |
Intiyaz Basha | a82457f | 2017-08-15 12:46:18 -0700 | [diff] [blame] | 4314 | if (octeon_setup_interrupt(octeon_dev, |
| 4315 | octeon_dev->sriov_info.num_pf_rings)) |
Raghu Vatsavayi | 1e0d30f | 2016-07-03 13:56:52 -0700 | [diff] [blame] | 4316 | return 1; |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4317 | |
| 4318 | /* Enable Octeon device interrupts */ |
Raghu Vatsavayi | 5b07aee | 2016-08-31 11:03:28 -0700 | [diff] [blame] | 4319 | octeon_dev->fn_list.enable_interrupt(octeon_dev, OCTEON_ALL_INTR); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4320 | |
Raghu Vatsavayi | 515e752 | 2016-11-14 15:54:44 -0800 | [diff] [blame] | 4321 | atomic_set(&octeon_dev->status, OCT_DEV_INTR_SET_DONE); |
| 4322 | |
Rick Farrington | 3c57f61 | 2017-08-17 23:11:30 -0700 | [diff] [blame] | 4323 | /* Send Credit for Octeon Output queues. Credits are always sent BEFORE |
| 4324 | * the output queue is enabled. |
| 4325 | * This ensures that we'll receive the f/w CORE DRV_ACTIVE message in |
| 4326 | * case we've configured CN23XX_SLI_GBL_CONTROL[NOPTR_D] = 0. |
| 4327 | * Otherwise, it is possible that the DRV_ACTIVE message will be sent |
| 4328 | * before any credits have been issued, causing the ring to be reset |
| 4329 | * (and the f/w appear to never have started). |
| 4330 | */ |
| 4331 | for (j = 0; j < octeon_dev->num_oqs; j++) |
| 4332 | writel(octeon_dev->droq[j]->max_count, |
| 4333 | octeon_dev->droq[j]->pkts_credit_reg); |
| 4334 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4335 | /* Enable the input and output queues for this Octeon device */ |
Raghu Vatsavayi | 1b7c55c | 2016-08-31 11:03:27 -0700 | [diff] [blame] | 4336 | ret = octeon_dev->fn_list.enable_io_queues(octeon_dev); |
| 4337 | if (ret) { |
| 4338 | dev_err(&octeon_dev->pci_dev->dev, "Failed to enable input/output queues"); |
| 4339 | return ret; |
| 4340 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4341 | |
| 4342 | atomic_set(&octeon_dev->status, OCT_DEV_IO_QUEUES_DONE); |
| 4343 | |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 4344 | if (fw_state == FW_NEEDS_TO_BE_LOADED) { |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4345 | dev_dbg(&octeon_dev->pci_dev->dev, "Waiting for DDR initialization...\n"); |
| 4346 | if (!ddr_timeout) { |
| 4347 | dev_info(&octeon_dev->pci_dev->dev, |
| 4348 | "WAITING. Set ddr_timeout to non-zero value to proceed with initialization.\n"); |
| 4349 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4350 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4351 | schedule_timeout_uninterruptible(HZ * LIO_RESET_SECS); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4352 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4353 | /* Wait for the octeon to initialize DDR after the soft-reset.*/ |
| 4354 | while (!ddr_timeout) { |
| 4355 | set_current_state(TASK_INTERRUPTIBLE); |
| 4356 | if (schedule_timeout(HZ / 10)) { |
| 4357 | /* user probably pressed Control-C */ |
| 4358 | return 1; |
| 4359 | } |
| 4360 | } |
| 4361 | ret = octeon_wait_for_ddr_init(octeon_dev, &ddr_timeout); |
| 4362 | if (ret) { |
| 4363 | dev_err(&octeon_dev->pci_dev->dev, |
| 4364 | "DDR not initialized. Please confirm that board is configured to boot from Flash, ret: %d\n", |
| 4365 | ret); |
Raghu Vatsavayi | 4b129ae | 2016-06-21 22:53:15 -0700 | [diff] [blame] | 4366 | return 1; |
| 4367 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4368 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4369 | if (octeon_wait_for_bootloader(octeon_dev, 1000)) { |
| 4370 | dev_err(&octeon_dev->pci_dev->dev, "Board not responding\n"); |
| 4371 | return 1; |
| 4372 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4373 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4374 | /* Divert uboot to take commands from host instead. */ |
| 4375 | ret = octeon_console_send_cmd(octeon_dev, bootcmd, 50); |
Raghu Vatsavayi | d3d7e6c | 2016-06-21 22:53:07 -0700 | [diff] [blame] | 4376 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4377 | dev_dbg(&octeon_dev->pci_dev->dev, "Initializing consoles\n"); |
| 4378 | ret = octeon_init_consoles(octeon_dev); |
| 4379 | if (ret) { |
| 4380 | dev_err(&octeon_dev->pci_dev->dev, "Could not access board consoles\n"); |
| 4381 | return 1; |
| 4382 | } |
Rick Farrington | da1542b | 2017-08-11 18:43:14 -0700 | [diff] [blame] | 4383 | /* If console debug enabled, specify empty string to use default |
| 4384 | * enablement ELSE specify NULL string for 'disabled'. |
| 4385 | */ |
| 4386 | dbg_enb = octeon_console_debug_enabled(0) ? "" : NULL; |
| 4387 | ret = octeon_add_console(octeon_dev, 0, dbg_enb); |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4388 | if (ret) { |
| 4389 | dev_err(&octeon_dev->pci_dev->dev, "Could not access board console\n"); |
| 4390 | return 1; |
Rick Farrington | da1542b | 2017-08-11 18:43:14 -0700 | [diff] [blame] | 4391 | } else if (octeon_console_debug_enabled(0)) { |
| 4392 | /* If console was added AND we're logging console output |
| 4393 | * then set our console print function. |
| 4394 | */ |
| 4395 | octeon_dev->console[0].print = octeon_dbg_console_print; |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4396 | } |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4397 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4398 | atomic_set(&octeon_dev->status, OCT_DEV_CONSOLE_INIT_DONE); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4399 | |
Raghu Vatsavayi | c0eab5b | 2016-08-31 11:03:29 -0700 | [diff] [blame] | 4400 | dev_dbg(&octeon_dev->pci_dev->dev, "Loading firmware\n"); |
| 4401 | ret = load_firmware(octeon_dev); |
| 4402 | if (ret) { |
| 4403 | dev_err(&octeon_dev->pci_dev->dev, "Could not load firmware to board\n"); |
| 4404 | return 1; |
| 4405 | } |
Rick Farrington | 088b874 | 2017-09-22 17:12:43 -0700 | [diff] [blame] | 4406 | |
| 4407 | atomic_set(octeon_dev->adapter_fw_state, FW_HAS_BEEN_LOADED); |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | handshake[octeon_dev->octeon_id].init_ok = 1; |
| 4411 | complete(&handshake[octeon_dev->octeon_id].init); |
| 4412 | |
| 4413 | atomic_set(&octeon_dev->status, OCT_DEV_HOST_OK); |
| 4414 | |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4415 | return 0; |
| 4416 | } |
| 4417 | |
| 4418 | /** |
Rick Farrington | da1542b | 2017-08-11 18:43:14 -0700 | [diff] [blame] | 4419 | * \brief Debug console print function |
| 4420 | * @param octeon_dev octeon device |
| 4421 | * @param console_num console number |
| 4422 | * @param prefix first portion of line to display |
| 4423 | * @param suffix second portion of line to display |
| 4424 | * |
| 4425 | * The OCTEON debug console outputs entire lines (excluding '\n'). |
| 4426 | * Normally, the line will be passed in the 'prefix' parameter. |
| 4427 | * However, due to buffering, it is possible for a line to be split into two |
| 4428 | * parts, in which case they will be passed as the 'prefix' parameter and |
| 4429 | * 'suffix' parameter. |
| 4430 | */ |
| 4431 | static int octeon_dbg_console_print(struct octeon_device *oct, u32 console_num, |
| 4432 | char *prefix, char *suffix) |
| 4433 | { |
| 4434 | if (prefix && suffix) |
| 4435 | dev_info(&oct->pci_dev->dev, "%u: %s%s\n", console_num, prefix, |
| 4436 | suffix); |
| 4437 | else if (prefix) |
| 4438 | dev_info(&oct->pci_dev->dev, "%u: %s\n", console_num, prefix); |
| 4439 | else if (suffix) |
| 4440 | dev_info(&oct->pci_dev->dev, "%u: %s\n", console_num, suffix); |
| 4441 | |
| 4442 | return 0; |
| 4443 | } |
| 4444 | |
| 4445 | /** |
Raghu Vatsavayi | f21fb3e | 2015-06-09 18:15:23 -0700 | [diff] [blame] | 4446 | * \brief Exits the module |
| 4447 | */ |
| 4448 | static void __exit liquidio_exit(void) |
| 4449 | { |
| 4450 | liquidio_deinit_pci(); |
| 4451 | |
| 4452 | pr_info("LiquidIO network module is now unloaded\n"); |
| 4453 | } |
| 4454 | |
| 4455 | module_init(liquidio_init); |
| 4456 | module_exit(liquidio_exit); |