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