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