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