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