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