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