blob: accd038f3f34a45035f9075a720566feef4a0ac4 [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
Raghu Vatsavayi50579d32016-11-14 15:54:46 -08002 * Author: Cavium, Inc.
3 *
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
6 *
7 * Copyright (c) 2003-2016 Cavium, Inc.
8 *
9 * This file is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License, Version 2, as
11 * published by the Free Software Foundation.
12 *
13 * This file is distributed in the hope that it will be useful, but
14 * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16 * NONINFRINGEMENT. See the GNU General Public License for more details.
17 ***********************************************************************/
Russell Kinge3bfc6e2017-02-07 15:03:03 -080018#include <linux/module.h>
Florian Westphal282ccf62017-03-29 17:17:31 +020019#include <linux/interrupt.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070020#include <linux/pci.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070021#include <linux/firmware.h>
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -070022#include <net/vxlan.h>
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -070023#include <linux/kthread.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070024#include "liquidio_common.h"
25#include "octeon_droq.h"
26#include "octeon_iq.h"
27#include "response_manager.h"
28#include "octeon_device.h"
29#include "octeon_nic.h"
30#include "octeon_main.h"
31#include "octeon_network.h"
32#include "cn66xx_regs.h"
33#include "cn66xx_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070034#include "cn68xx_device.h"
Raghu Vatsavayi72c00912016-08-31 11:03:25 -070035#include "cn23xx_pf_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070036#include "liquidio_image.h"
37
38MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
39MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver");
40MODULE_LICENSE("GPL");
41MODULE_VERSION(LIQUIDIO_VERSION);
Derek Chicklesea6404c82017-08-07 12:22:15 -070042MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210SV_NAME
43 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
44MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210NV_NAME
45 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
46MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_410NV_NAME
47 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
48MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_23XX_NAME
49 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070050
51static int ddr_timeout = 10000;
52module_param(ddr_timeout, int, 0644);
53MODULE_PARM_DESC(ddr_timeout,
54 "Number of milliseconds to wait for DDR initialization. 0 waits for ddr_timeout to be set to non-zero value before starting to check");
55
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070056#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
57
58static int debug = -1;
59module_param(debug, int, 0644);
60MODULE_PARM_DESC(debug, "NETIF_MSG debug bits");
61
Rick Farrington088b8742017-09-22 17:12:43 -070062static char fw_type[LIO_MAX_FW_TYPE_LEN] = LIO_FW_NAME_TYPE_AUTO;
Derek Chicklesd3961792017-08-14 12:17:56 -070063module_param_string(fw_type, fw_type, sizeof(fw_type), 0444);
Rick Farrington088b8742017-09-22 17:12:43 -070064MODULE_PARM_DESC(fw_type, "Type of firmware to be loaded (default is \"auto\"), which uses firmware in flash, if present, else loads \"nic\".");
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070065
Intiyaz Basha2470f3a2017-08-03 15:10:17 -070066static u32 console_bitmask;
67module_param(console_bitmask, int, 0644);
68MODULE_PARM_DESC(console_bitmask,
69 "Bitmask indicating which consoles have debug output redirected to syslog.");
70
71/**
72 * \brief determines if a given console has debug enabled.
73 * @param console console to check
74 * @returns 1 = enabled. 0 otherwise
75 */
Rick Farringtonda1542b2017-08-11 18:43:14 -070076static int octeon_console_debug_enabled(u32 console)
Intiyaz Basha2470f3a2017-08-03 15:10:17 -070077{
78 return (console_bitmask >> (console)) & 0x1;
79}
80
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070081/* Polling interval for determining when NIC application is alive */
82#define LIQUIDIO_STARTER_POLL_INTERVAL_MS 100
83
84/* runtime link query interval */
85#define LIQUIDIO_LINK_QUERY_INTERVAL_MS 1000
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -070086/* update localtime to octeon firmware every 60 seconds.
87 * make firmware to use same time reference, so that it will be easy to
88 * correlate firmware logged events/errors with host events, for debugging.
89 */
90#define LIO_SYNC_OCTEON_TIME_INTERVAL_MS 60000
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070091
92struct liquidio_if_cfg_context {
93 int octeon_id;
94
95 wait_queue_head_t wc;
96
97 int cond;
98};
99
100struct liquidio_if_cfg_resp {
101 u64 rh;
102 struct liquidio_if_cfg_info cfg_info;
103 u64 status;
104};
105
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -0700106struct liquidio_rx_ctl_context {
107 int octeon_id;
108
109 wait_queue_head_t wc;
110
111 int cond;
112};
113
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700114struct oct_link_status_resp {
115 u64 rh;
116 struct oct_link_info link_info;
117 u64 status;
118};
119
120struct oct_timestamp_resp {
121 u64 rh;
122 u64 timestamp;
123 u64 status;
124};
125
126#define OCT_TIMESTAMP_RESP_SIZE (sizeof(struct oct_timestamp_resp))
127
128union tx_info {
129 u64 u64;
130 struct {
131#ifdef __BIG_ENDIAN_BITFIELD
132 u16 gso_size;
133 u16 gso_segs;
134 u32 reserved;
135#else
136 u32 reserved;
137 u16 gso_segs;
138 u16 gso_size;
139#endif
140 } s;
141};
142
143/** Octeon device properties to be used by the NIC module.
144 * Each octeon device in the system will be represented
145 * by this structure in the NIC module.
146 */
147
148#define OCTNIC_MAX_SG (MAX_SKB_FRAGS)
149
150#define OCTNIC_GSO_MAX_HEADER_SIZE 128
Raghu Vatsavayi72c00912016-08-31 11:03:25 -0700151#define OCTNIC_GSO_MAX_SIZE \
152 (CN23XX_DEFAULT_INPUT_JABBER - OCTNIC_GSO_MAX_HEADER_SIZE)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700153
154/** Structure of a node in list of gather components maintained by
155 * NIC driver for each network device.
156 */
157struct octnic_gather {
158 /** List manipulation. Next and prev pointers. */
159 struct list_head list;
160
161 /** Size of the gather component at sg in bytes. */
162 int sg_size;
163
164 /** Number of bytes that sg was adjusted to make it 8B-aligned. */
165 int adjust;
166
167 /** Gather component that can accommodate max sized fragment list
168 * received from the IP layer.
169 */
170 struct octeon_sg_entry *sg;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700171
VSR Burru67e303e2017-03-06 18:45:59 -0800172 dma_addr_t sg_dma_ptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700173};
174
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700175struct handshake {
176 struct completion init;
177 struct completion started;
178 struct pci_dev *pci_dev;
179 int init_ok;
180 int started_ok;
181};
182
Raghu Vatsavayica6139f2016-11-14 15:54:40 -0800183#ifdef CONFIG_PCI_IOV
184static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs);
185#endif
186
Rick Farringtonda1542b2017-08-11 18:43:14 -0700187static int octeon_dbg_console_print(struct octeon_device *oct, u32 console_num,
188 char *prefix, char *suffix);
189
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700190static int octeon_device_init(struct octeon_device *);
Raghu Vatsavayi32581242016-08-31 11:03:20 -0700191static int liquidio_stop(struct net_device *netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700192static void liquidio_remove(struct pci_dev *pdev);
193static int liquidio_probe(struct pci_dev *pdev,
194 const struct pci_device_id *ent);
Felix Manlunasbb54be52017-04-04 19:26:57 -0700195static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
196 int linkstate);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700197
198static struct handshake handshake[MAX_OCTEON_DEVICES];
199static struct completion first_stage;
200
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700201static void octeon_droq_bh(unsigned long pdev)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700202{
203 int q_no;
204 int reschedule = 0;
205 struct octeon_device *oct = (struct octeon_device *)pdev;
206 struct octeon_device_priv *oct_priv =
207 (struct octeon_device_priv *)oct->priv;
208
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700209 for (q_no = 0; q_no < MAX_OCTEON_OUTPUT_QUEUES(oct); q_no++) {
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800210 if (!(oct->io_qmask.oq & BIT_ULL(q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700211 continue;
212 reschedule |= octeon_droq_process_packets(oct, oct->droq[q_no],
213 MAX_PACKET_BUDGET);
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -0700214 lio_enable_irq(oct->droq[q_no], NULL);
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700215
216 if (OCTEON_CN23XX_PF(oct) && oct->msix_on) {
217 /* set time and cnt interrupt thresholds for this DROQ
218 * for NAPI
219 */
220 int adjusted_q_no = q_no + oct->sriov_info.pf_srn;
221
222 octeon_write_csr64(
223 oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(adjusted_q_no),
224 0x5700000040ULL);
225 octeon_write_csr64(
226 oct, CN23XX_SLI_OQ_PKTS_SENT(adjusted_q_no), 0);
227 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700228 }
229
230 if (reschedule)
231 tasklet_schedule(&oct_priv->droq_tasklet);
232}
233
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700234static int lio_wait_for_oq_pkts(struct octeon_device *oct)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700235{
236 struct octeon_device_priv *oct_priv =
237 (struct octeon_device_priv *)oct->priv;
238 int retry = 100, pkt_cnt = 0, pending_pkts = 0;
239 int i;
240
241 do {
242 pending_pkts = 0;
243
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700244 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800245 if (!(oct->io_qmask.oq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700246 continue;
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700247 pkt_cnt += octeon_droq_check_hw_for_pkts(oct->droq[i]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700248 }
249 if (pkt_cnt > 0) {
250 pending_pkts += pkt_cnt;
251 tasklet_schedule(&oct_priv->droq_tasklet);
252 }
253 pkt_cnt = 0;
254 schedule_timeout_uninterruptible(1);
255
256 } while (retry-- && pending_pkts);
257
258 return pkt_cnt;
259}
260
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700261/**
262 * \brief Forces all IO queues off on a given device
263 * @param oct Pointer to Octeon device
264 */
265static void force_io_queues_off(struct octeon_device *oct)
266{
267 if ((oct->chip_id == OCTEON_CN66XX) ||
268 (oct->chip_id == OCTEON_CN68XX)) {
269 /* Reset the Enable bits for Input Queues. */
270 octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
271
272 /* Reset the Enable bits for Output Queues. */
273 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
274 }
275}
276
277/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700278 * \brief Cause device to go quiet so it can be safely removed/reset/etc
279 * @param oct Pointer to Octeon device
280 */
281static inline void pcierror_quiesce_device(struct octeon_device *oct)
282{
283 int i;
284
285 /* Disable the input and output queues now. No more packets will
286 * arrive from Octeon, but we should wait for all packet processing
287 * to finish.
288 */
289 force_io_queues_off(oct);
290
291 /* To allow for in-flight requests */
292 schedule_timeout_uninterruptible(100);
293
294 if (wait_for_pending_requests(oct))
295 dev_err(&oct->pci_dev->dev, "There were pending requests\n");
296
297 /* Force all requests waiting to be fetched by OCTEON to complete. */
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700298 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700299 struct octeon_instr_queue *iq;
300
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800301 if (!(oct->io_qmask.iq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700302 continue;
303 iq = oct->instr_queue[i];
304
305 if (atomic_read(&iq->instr_pending)) {
306 spin_lock_bh(&iq->lock);
307 iq->fill_cnt = 0;
308 iq->octeon_read_index = iq->host_write_index;
309 iq->stats.instr_processed +=
310 atomic_read(&iq->instr_pending);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -0700311 lio_process_iq_request_list(oct, iq, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700312 spin_unlock_bh(&iq->lock);
313 }
314 }
315
316 /* Force all pending ordered list requests to time out. */
317 lio_process_ordered_list(oct, 1);
318
319 /* We do not need to wait for output queue packets to be processed. */
320}
321
322/**
323 * \brief Cleanup PCI AER uncorrectable error status
324 * @param dev Pointer to PCI device
325 */
326static void cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
327{
328 int pos = 0x100;
329 u32 status, mask;
330
331 pr_info("%s :\n", __func__);
332
333 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
334 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
335 if (dev->error_state == pci_channel_io_normal)
336 status &= ~mask; /* Clear corresponding nonfatal bits */
337 else
338 status &= mask; /* Clear corresponding fatal bits */
339 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
340}
341
342/**
343 * \brief Stop all PCI IO to a given device
344 * @param dev Pointer to Octeon device
345 */
346static void stop_pci_io(struct octeon_device *oct)
347{
348 /* No more instructions will be forwarded. */
349 atomic_set(&oct->status, OCT_DEV_IN_RESET);
350
351 pci_disable_device(oct->pci_dev);
352
353 /* Disable interrupts */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700354 oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700355
356 pcierror_quiesce_device(oct);
357
358 /* Release the interrupt line */
359 free_irq(oct->pci_dev->irq, oct);
360
361 if (oct->flags & LIO_FLAG_MSI_ENABLED)
362 pci_disable_msi(oct->pci_dev);
363
364 dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
365 lio_get_state_string(&oct->status));
366
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700367 /* making it a common function for all OCTEON models */
368 cleanup_aer_uncorrect_error_status(oct->pci_dev);
369}
370
371/**
372 * \brief called when PCI error is detected
373 * @param pdev Pointer to PCI device
374 * @param state The current pci connection state
375 *
376 * This function is called after a PCI bus error affecting
377 * this device has been detected.
378 */
379static pci_ers_result_t liquidio_pcie_error_detected(struct pci_dev *pdev,
380 pci_channel_state_t state)
381{
382 struct octeon_device *oct = pci_get_drvdata(pdev);
383
384 /* Non-correctable Non-fatal errors */
385 if (state == pci_channel_io_normal) {
386 dev_err(&oct->pci_dev->dev, "Non-correctable non-fatal error reported:\n");
387 cleanup_aer_uncorrect_error_status(oct->pci_dev);
388 return PCI_ERS_RESULT_CAN_RECOVER;
389 }
390
391 /* Non-correctable Fatal errors */
392 dev_err(&oct->pci_dev->dev, "Non-correctable FATAL reported by PCI AER driver\n");
393 stop_pci_io(oct);
394
395 /* Always return a DISCONNECT. There is no support for recovery but only
396 * for a clean shutdown.
397 */
398 return PCI_ERS_RESULT_DISCONNECT;
399}
400
401/**
402 * \brief mmio handler
403 * @param pdev Pointer to PCI device
404 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700405static pci_ers_result_t liquidio_pcie_mmio_enabled(
406 struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700407{
408 /* We should never hit this since we never ask for a reset for a Fatal
409 * Error. We always return DISCONNECT in io_error above.
410 * But play safe and return RECOVERED for now.
411 */
412 return PCI_ERS_RESULT_RECOVERED;
413}
414
415/**
416 * \brief called after the pci bus has been reset.
417 * @param pdev Pointer to PCI device
418 *
419 * Restart the card from scratch, as if from a cold-boot. Implementation
420 * resembles the first-half of the octeon_resume routine.
421 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700422static pci_ers_result_t liquidio_pcie_slot_reset(
423 struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700424{
425 /* We should never hit this since we never ask for a reset for a Fatal
426 * Error. We always return DISCONNECT in io_error above.
427 * But play safe and return RECOVERED for now.
428 */
429 return PCI_ERS_RESULT_RECOVERED;
430}
431
432/**
433 * \brief called when traffic can start flowing again.
434 * @param pdev Pointer to PCI device
435 *
436 * This callback is called when the error recovery driver tells us that
437 * its OK to resume normal operation. Implementation resembles the
438 * second-half of the octeon_resume routine.
439 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700440static void liquidio_pcie_resume(struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700441{
442 /* Nothing to be done here. */
443}
444
445#ifdef CONFIG_PM
446/**
447 * \brief called when suspending
448 * @param pdev Pointer to PCI device
449 * @param state state to suspend to
450 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700451static int liquidio_suspend(struct pci_dev *pdev __attribute__((unused)),
452 pm_message_t state __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700453{
454 return 0;
455}
456
457/**
458 * \brief called when resuming
459 * @param pdev Pointer to PCI device
460 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700461static int liquidio_resume(struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700462{
463 return 0;
464}
465#endif
466
467/* For PCI-E Advanced Error Recovery (AER) Interface */
Julia Lawall166e2362015-11-14 11:06:53 +0100468static const struct pci_error_handlers liquidio_err_handler = {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700469 .error_detected = liquidio_pcie_error_detected,
470 .mmio_enabled = liquidio_pcie_mmio_enabled,
471 .slot_reset = liquidio_pcie_slot_reset,
472 .resume = liquidio_pcie_resume,
473};
474
475static const struct pci_device_id liquidio_pci_tbl[] = {
476 { /* 68xx */
477 PCI_VENDOR_ID_CAVIUM, 0x91, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
478 },
479 { /* 66xx */
480 PCI_VENDOR_ID_CAVIUM, 0x92, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
481 },
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700482 { /* 23xx pf */
483 PCI_VENDOR_ID_CAVIUM, 0x9702, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
484 },
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700485 {
486 0, 0, 0, 0, 0, 0, 0
487 }
488};
489MODULE_DEVICE_TABLE(pci, liquidio_pci_tbl);
490
491static struct pci_driver liquidio_pci_driver = {
492 .name = "LiquidIO",
493 .id_table = liquidio_pci_tbl,
494 .probe = liquidio_probe,
495 .remove = liquidio_remove,
496 .err_handler = &liquidio_err_handler, /* For AER */
497
498#ifdef CONFIG_PM
499 .suspend = liquidio_suspend,
500 .resume = liquidio_resume,
501#endif
Raghu Vatsavayica6139f2016-11-14 15:54:40 -0800502#ifdef CONFIG_PCI_IOV
503 .sriov_configure = liquidio_enable_sriov,
504#endif
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700505};
506
507/**
508 * \brief register PCI driver
509 */
510static int liquidio_init_pci(void)
511{
512 return pci_register_driver(&liquidio_pci_driver);
513}
514
515/**
516 * \brief unregister PCI driver
517 */
518static void liquidio_deinit_pci(void)
519{
520 pci_unregister_driver(&liquidio_pci_driver);
521}
522
523/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700524 * \brief Stop Tx queues
525 * @param netdev network device
526 */
527static inline void txqs_stop(struct net_device *netdev)
528{
529 if (netif_is_multiqueue(netdev)) {
530 int i;
531
532 for (i = 0; i < netdev->num_tx_queues; i++)
533 netif_stop_subqueue(netdev, i);
534 } else {
535 netif_stop_queue(netdev);
536 }
537}
538
539/**
540 * \brief Start Tx queues
541 * @param netdev network device
542 */
543static inline void txqs_start(struct net_device *netdev)
544{
545 if (netif_is_multiqueue(netdev)) {
546 int i;
547
548 for (i = 0; i < netdev->num_tx_queues; i++)
549 netif_start_subqueue(netdev, i);
550 } else {
551 netif_start_queue(netdev);
552 }
553}
554
555/**
556 * \brief Wake Tx queues
557 * @param netdev network device
558 */
559static inline void txqs_wake(struct net_device *netdev)
560{
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700561 struct lio *lio = GET_LIO(netdev);
562
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700563 if (netif_is_multiqueue(netdev)) {
564 int i;
565
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700566 for (i = 0; i < netdev->num_tx_queues; i++) {
567 int qno = lio->linfo.txpciq[i %
Intiyaz Bashaa82457f2017-08-15 12:46:18 -0700568 lio->oct_dev->num_iqs].s.q_no;
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700569
570 if (__netif_subqueue_stopped(netdev, i)) {
571 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, qno,
572 tx_restart, 1);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700573 netif_wake_subqueue(netdev, i);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700574 }
575 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700576 } else {
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700577 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, lio->txq,
578 tx_restart, 1);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700579 netif_wake_queue(netdev);
580 }
581}
582
583/**
584 * \brief Stop Tx queue
585 * @param netdev network device
586 */
587static void stop_txq(struct net_device *netdev)
588{
589 txqs_stop(netdev);
590}
591
592/**
593 * \brief Start Tx queue
594 * @param netdev network device
595 */
596static void start_txq(struct net_device *netdev)
597{
598 struct lio *lio = GET_LIO(netdev);
599
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700600 if (lio->linfo.link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700601 txqs_start(netdev);
602 return;
603 }
604}
605
606/**
607 * \brief Wake a queue
608 * @param netdev network device
609 * @param q which queue to wake
610 */
611static inline void wake_q(struct net_device *netdev, int q)
612{
613 if (netif_is_multiqueue(netdev))
614 netif_wake_subqueue(netdev, q);
615 else
616 netif_wake_queue(netdev);
617}
618
619/**
620 * \brief Stop a queue
621 * @param netdev network device
622 * @param q which queue to stop
623 */
624static inline void stop_q(struct net_device *netdev, int q)
625{
626 if (netif_is_multiqueue(netdev))
627 netif_stop_subqueue(netdev, q);
628 else
629 netif_stop_queue(netdev);
630}
631
632/**
633 * \brief Check Tx queue status, and take appropriate action
634 * @param lio per-network private data
635 * @returns 0 if full, number of queues woken up otherwise
636 */
637static inline int check_txq_status(struct lio *lio)
638{
639 int ret_val = 0;
640
641 if (netif_is_multiqueue(lio->netdev)) {
642 int numqs = lio->netdev->num_tx_queues;
643 int q, iq = 0;
644
645 /* check each sub-queue state */
646 for (q = 0; q < numqs; q++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700647 iq = lio->linfo.txpciq[q %
Intiyaz Bashaa82457f2017-08-15 12:46:18 -0700648 lio->oct_dev->num_iqs].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700649 if (octnet_iq_is_full(lio->oct_dev, iq))
650 continue;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700651 if (__netif_subqueue_stopped(lio->netdev, q)) {
652 wake_q(lio->netdev, q);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700653 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, iq,
654 tx_restart, 1);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700655 ret_val++;
656 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700657 }
658 } else {
659 if (octnet_iq_is_full(lio->oct_dev, lio->txq))
660 return 0;
661 wake_q(lio->netdev, lio->txq);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700662 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, lio->txq,
663 tx_restart, 1);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700664 ret_val = 1;
665 }
666 return ret_val;
667}
668
669/**
670 * Remove the node at the head of the list. The list would be empty at
671 * the end of this call if there are no more nodes in the list.
672 */
673static inline struct list_head *list_delete_head(struct list_head *root)
674{
675 struct list_head *node;
676
677 if ((root->prev == root) && (root->next == root))
678 node = NULL;
679 else
680 node = root->next;
681
682 if (node)
683 list_del(node);
684
685 return node;
686}
687
688/**
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700689 * \brief Delete gather lists
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700690 * @param lio per-network private data
691 */
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700692static void delete_glists(struct lio *lio)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700693{
694 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700695 int i;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700696
VSR Burru67e303e2017-03-06 18:45:59 -0800697 kfree(lio->glist_lock);
698 lio->glist_lock = NULL;
699
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700700 if (!lio->glist)
701 return;
702
703 for (i = 0; i < lio->linfo.num_txpciq; i++) {
704 do {
705 g = (struct octnic_gather *)
706 list_delete_head(&lio->glist[i]);
VSR Burru67e303e2017-03-06 18:45:59 -0800707 if (g)
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700708 kfree(g);
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700709 } while (g);
VSR Burru67e303e2017-03-06 18:45:59 -0800710
Felix Manlunas58ad3192017-03-20 19:04:48 -0700711 if (lio->glists_virt_base && lio->glists_virt_base[i] &&
712 lio->glists_dma_base && lio->glists_dma_base[i]) {
VSR Burru67e303e2017-03-06 18:45:59 -0800713 lio_dma_free(lio->oct_dev,
714 lio->glist_entry_size * lio->tx_qsize,
715 lio->glists_virt_base[i],
716 lio->glists_dma_base[i]);
717 }
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700718 }
719
VSR Burru67e303e2017-03-06 18:45:59 -0800720 kfree(lio->glists_virt_base);
721 lio->glists_virt_base = NULL;
722
723 kfree(lio->glists_dma_base);
724 lio->glists_dma_base = NULL;
725
726 kfree(lio->glist);
727 lio->glist = NULL;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700728}
729
730/**
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700731 * \brief Setup gather lists
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700732 * @param lio per-network private data
733 */
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700734static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700735{
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700736 int i, j;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700737 struct octnic_gather *g;
738
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700739 lio->glist_lock = kcalloc(num_iqs, sizeof(*lio->glist_lock),
740 GFP_KERNEL);
741 if (!lio->glist_lock)
VSR Burru67e303e2017-03-06 18:45:59 -0800742 return -ENOMEM;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700743
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700744 lio->glist = kcalloc(num_iqs, sizeof(*lio->glist),
745 GFP_KERNEL);
746 if (!lio->glist) {
VSR Burru67e303e2017-03-06 18:45:59 -0800747 kfree(lio->glist_lock);
748 lio->glist_lock = NULL;
749 return -ENOMEM;
750 }
751
752 lio->glist_entry_size =
753 ROUNDUP8((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE);
754
755 /* allocate memory to store virtual and dma base address of
756 * per glist consistent memory
757 */
758 lio->glists_virt_base = kcalloc(num_iqs, sizeof(*lio->glists_virt_base),
759 GFP_KERNEL);
760 lio->glists_dma_base = kcalloc(num_iqs, sizeof(*lio->glists_dma_base),
761 GFP_KERNEL);
762
763 if (!lio->glists_virt_base || !lio->glists_dma_base) {
764 delete_glists(lio);
765 return -ENOMEM;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700766 }
767
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700768 for (i = 0; i < num_iqs; i++) {
VSR Burrub3ca9af2017-03-09 17:03:24 -0800769 int numa_node = dev_to_node(&oct->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700770
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700771 spin_lock_init(&lio->glist_lock[i]);
772
773 INIT_LIST_HEAD(&lio->glist[i]);
774
VSR Burru67e303e2017-03-06 18:45:59 -0800775 lio->glists_virt_base[i] =
776 lio_dma_alloc(oct,
777 lio->glist_entry_size * lio->tx_qsize,
778 &lio->glists_dma_base[i]);
779
780 if (!lio->glists_virt_base[i]) {
781 delete_glists(lio);
782 return -ENOMEM;
783 }
784
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700785 for (j = 0; j < lio->tx_qsize; j++) {
786 g = kzalloc_node(sizeof(*g), GFP_KERNEL,
787 numa_node);
788 if (!g)
789 g = kzalloc(sizeof(*g), GFP_KERNEL);
790 if (!g)
791 break;
792
VSR Burru67e303e2017-03-06 18:45:59 -0800793 g->sg = lio->glists_virt_base[i] +
794 (j * lio->glist_entry_size);
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700795
VSR Burru67e303e2017-03-06 18:45:59 -0800796 g->sg_dma_ptr = lio->glists_dma_base[i] +
797 (j * lio->glist_entry_size);
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700798
799 list_add_tail(&g->list, &lio->glist[i]);
800 }
801
802 if (j != lio->tx_qsize) {
803 delete_glists(lio);
VSR Burru67e303e2017-03-06 18:45:59 -0800804 return -ENOMEM;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700805 }
806 }
807
808 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700809}
810
811/**
812 * \brief Print link information
813 * @param netdev network device
814 */
815static void print_link_info(struct net_device *netdev)
816{
817 struct lio *lio = GET_LIO(netdev);
818
Intiyaz Bashad18ca7d2017-08-14 12:01:56 -0700819 if (!ifstate_check(lio, LIO_IFSTATE_RESETTING) &&
820 ifstate_check(lio, LIO_IFSTATE_REGISTERED)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700821 struct oct_link_info *linfo = &lio->linfo;
822
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700823 if (linfo->link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700824 netif_info(lio, link, lio->netdev, "%d Mbps %s Duplex UP\n",
825 linfo->link.s.speed,
826 (linfo->link.s.duplex) ? "Full" : "Half");
827 } else {
828 netif_info(lio, link, lio->netdev, "Link Down\n");
829 }
830 }
831}
832
833/**
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -0700834 * \brief Routine to notify MTU change
835 * @param work work_struct data structure
836 */
837static void octnet_link_status_change(struct work_struct *work)
838{
839 struct cavium_wk *wk = (struct cavium_wk *)work;
840 struct lio *lio = (struct lio *)wk->ctxptr;
841
842 rtnl_lock();
843 call_netdevice_notifiers(NETDEV_CHANGEMTU, lio->netdev);
844 rtnl_unlock();
845}
846
847/**
848 * \brief Sets up the mtu status change work
849 * @param netdev network device
850 */
851static inline int setup_link_status_change_wq(struct net_device *netdev)
852{
853 struct lio *lio = GET_LIO(netdev);
854 struct octeon_device *oct = lio->oct_dev;
855
856 lio->link_status_wq.wq = alloc_workqueue("link-status",
857 WQ_MEM_RECLAIM, 0);
858 if (!lio->link_status_wq.wq) {
859 dev_err(&oct->pci_dev->dev, "unable to create cavium link status wq\n");
860 return -1;
861 }
862 INIT_DELAYED_WORK(&lio->link_status_wq.wk.work,
863 octnet_link_status_change);
864 lio->link_status_wq.wk.ctxptr = lio;
865
866 return 0;
867}
868
869static inline void cleanup_link_status_change_wq(struct net_device *netdev)
870{
871 struct lio *lio = GET_LIO(netdev);
872
873 if (lio->link_status_wq.wq) {
874 cancel_delayed_work_sync(&lio->link_status_wq.wk.work);
875 destroy_workqueue(lio->link_status_wq.wq);
876 }
877}
878
879/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700880 * \brief Update link status
881 * @param netdev network device
882 * @param ls link status structure
883 *
884 * Called on receipt of a link status response from the core application to
885 * update each interface's link status.
886 */
887static inline void update_link_status(struct net_device *netdev,
888 union oct_link_status *ls)
889{
890 struct lio *lio = GET_LIO(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700891 int changed = (lio->linfo.link.u64 != ls->u64);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700892
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700893 lio->linfo.link.u64 = ls->u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700894
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700895 if ((lio->intf_open) && (changed)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700896 print_link_info(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700897 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700898
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700899 if (lio->linfo.link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700900 netif_carrier_on(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700901 txqs_wake(netdev);
902 } else {
903 netif_carrier_off(netdev);
904 stop_txq(netdev);
905 }
906 }
907}
908
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -0700909/**
910 * lio_sync_octeon_time_cb - callback that is invoked when soft command
911 * sent by lio_sync_octeon_time() has completed successfully or failed
912 *
913 * @oct - octeon device structure
914 * @status - indicates success or failure
915 * @buf - pointer to the command that was sent to firmware
916 **/
917static void lio_sync_octeon_time_cb(struct octeon_device *oct,
918 u32 status, void *buf)
919{
920 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
921
922 if (status)
923 dev_err(&oct->pci_dev->dev,
924 "Failed to sync time to octeon; error=%d\n", status);
925
926 octeon_free_soft_command(oct, sc);
927}
928
929/**
930 * lio_sync_octeon_time - send latest localtime to octeon firmware so that
931 * firmware will correct it's time, in case there is a time skew
932 *
933 * @work: work scheduled to send time update to octeon firmware
934 **/
935static void lio_sync_octeon_time(struct work_struct *work)
936{
937 struct cavium_wk *wk = (struct cavium_wk *)work;
938 struct lio *lio = (struct lio *)wk->ctxptr;
939 struct octeon_device *oct = lio->oct_dev;
940 struct octeon_soft_command *sc;
941 struct timespec64 ts;
942 struct lio_time *lt;
943 int ret;
944
945 sc = octeon_alloc_soft_command(oct, sizeof(struct lio_time), 0, 0);
946 if (!sc) {
947 dev_err(&oct->pci_dev->dev,
948 "Failed to sync time to octeon: soft command allocation failed\n");
949 return;
950 }
951
952 lt = (struct lio_time *)sc->virtdptr;
953
954 /* Get time of the day */
955 getnstimeofday64(&ts);
956 lt->sec = ts.tv_sec;
957 lt->nsec = ts.tv_nsec;
958 octeon_swap_8B_data((u64 *)lt, (sizeof(struct lio_time)) / 8);
959
960 sc->iq_no = lio->linfo.txpciq[0].s.q_no;
961 octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
962 OPCODE_NIC_SYNC_OCTEON_TIME, 0, 0, 0);
963
964 sc->callback = lio_sync_octeon_time_cb;
965 sc->callback_arg = sc;
966 sc->wait_time = 1000;
967
968 ret = octeon_send_soft_command(oct, sc);
969 if (ret == IQ_SEND_FAILED) {
970 dev_err(&oct->pci_dev->dev,
971 "Failed to sync time to octeon: failed to send soft command\n");
972 octeon_free_soft_command(oct, sc);
973 }
974
975 queue_delayed_work(lio->sync_octeon_time_wq.wq,
976 &lio->sync_octeon_time_wq.wk.work,
977 msecs_to_jiffies(LIO_SYNC_OCTEON_TIME_INTERVAL_MS));
978}
979
980/**
981 * setup_sync_octeon_time_wq - Sets up the work to periodically update
982 * local time to octeon firmware
983 *
984 * @netdev - network device which should send time update to firmware
985 **/
986static inline int setup_sync_octeon_time_wq(struct net_device *netdev)
987{
988 struct lio *lio = GET_LIO(netdev);
989 struct octeon_device *oct = lio->oct_dev;
990
991 lio->sync_octeon_time_wq.wq =
992 alloc_workqueue("update-octeon-time", WQ_MEM_RECLAIM, 0);
993 if (!lio->sync_octeon_time_wq.wq) {
994 dev_err(&oct->pci_dev->dev, "Unable to create wq to update octeon time\n");
995 return -1;
996 }
997 INIT_DELAYED_WORK(&lio->sync_octeon_time_wq.wk.work,
998 lio_sync_octeon_time);
999 lio->sync_octeon_time_wq.wk.ctxptr = lio;
1000 queue_delayed_work(lio->sync_octeon_time_wq.wq,
1001 &lio->sync_octeon_time_wq.wk.work,
1002 msecs_to_jiffies(LIO_SYNC_OCTEON_TIME_INTERVAL_MS));
1003
1004 return 0;
1005}
1006
1007/**
1008 * cleanup_sync_octeon_time_wq - stop scheduling and destroy the work created
1009 * to periodically update local time to octeon firmware
1010 *
1011 * @netdev - network device which should send time update to firmware
1012 **/
1013static inline void cleanup_sync_octeon_time_wq(struct net_device *netdev)
1014{
1015 struct lio *lio = GET_LIO(netdev);
1016 struct cavium_wq *time_wq = &lio->sync_octeon_time_wq;
1017
1018 if (time_wq->wq) {
1019 cancel_delayed_work_sync(&time_wq->wk.work);
1020 destroy_workqueue(time_wq->wq);
1021 }
1022}
1023
Felix Manlunasbb54be52017-04-04 19:26:57 -07001024static struct octeon_device *get_other_octeon_device(struct octeon_device *oct)
1025{
1026 struct octeon_device *other_oct;
1027
1028 other_oct = lio_get_device(oct->octeon_id + 1);
1029
1030 if (other_oct && other_oct->pci_dev) {
1031 int oct_busnum, other_oct_busnum;
1032
1033 oct_busnum = oct->pci_dev->bus->number;
1034 other_oct_busnum = other_oct->pci_dev->bus->number;
1035
1036 if (oct_busnum == other_oct_busnum) {
1037 int oct_slot, other_oct_slot;
1038
1039 oct_slot = PCI_SLOT(oct->pci_dev->devfn);
1040 other_oct_slot = PCI_SLOT(other_oct->pci_dev->devfn);
1041
1042 if (oct_slot == other_oct_slot)
1043 return other_oct;
1044 }
1045 }
1046
1047 return NULL;
1048}
1049
1050static void disable_all_vf_links(struct octeon_device *oct)
1051{
1052 struct net_device *netdev;
1053 int max_vfs, vf, i;
1054
1055 if (!oct)
1056 return;
1057
1058 max_vfs = oct->sriov_info.max_vfs;
1059
1060 for (i = 0; i < oct->ifcount; i++) {
1061 netdev = oct->props[i].netdev;
1062 if (!netdev)
1063 continue;
1064
1065 for (vf = 0; vf < max_vfs; vf++)
1066 liquidio_set_vf_link_state(netdev, vf,
1067 IFLA_VF_LINK_STATE_DISABLE);
1068 }
1069}
1070
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001071static int liquidio_watchdog(void *param)
1072{
Felix Manlunasbb54be52017-04-04 19:26:57 -07001073 bool err_msg_was_printed[LIO_MAX_CORES];
1074 u16 mask_of_crashed_or_stuck_cores = 0;
1075 bool all_vf_links_are_disabled = false;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001076 struct octeon_device *oct = param;
Felix Manlunasbb54be52017-04-04 19:26:57 -07001077 struct octeon_device *other_oct;
1078#ifdef CONFIG_MODULE_UNLOAD
1079 long refcount, vfs_referencing_pf;
1080 u64 vfs_mask1, vfs_mask2;
1081#endif
1082 int core;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001083
Felix Manlunasbb54be52017-04-04 19:26:57 -07001084 memset(err_msg_was_printed, 0, sizeof(err_msg_was_printed));
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001085
1086 while (!kthread_should_stop()) {
Felix Manlunasbb54be52017-04-04 19:26:57 -07001087 /* sleep for a couple of seconds so that we don't hog the CPU */
1088 set_current_state(TASK_INTERRUPTIBLE);
1089 schedule_timeout(msecs_to_jiffies(2000));
1090
1091 mask_of_crashed_or_stuck_cores =
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001092 (u16)octeon_read_csr64(oct, CN23XX_SLI_SCRATCH2);
1093
Felix Manlunasbb54be52017-04-04 19:26:57 -07001094 if (!mask_of_crashed_or_stuck_cores)
1095 continue;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001096
Felix Manlunasbb54be52017-04-04 19:26:57 -07001097 WRITE_ONCE(oct->cores_crashed, true);
1098 other_oct = get_other_octeon_device(oct);
1099 if (other_oct)
1100 WRITE_ONCE(other_oct->cores_crashed, true);
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001101
Felix Manlunasbb54be52017-04-04 19:26:57 -07001102 for (core = 0; core < LIO_MAX_CORES; core++) {
1103 bool core_crashed_or_got_stuck;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001104
Felix Manlunasbb54be52017-04-04 19:26:57 -07001105 core_crashed_or_got_stuck =
1106 (mask_of_crashed_or_stuck_cores
1107 >> core) & 1;
1108
1109 if (core_crashed_or_got_stuck &&
1110 !err_msg_was_printed[core]) {
1111 dev_err(&oct->pci_dev->dev,
1112 "ERROR: Octeon core %d crashed or got stuck! See oct-fwdump for details.\n",
1113 core);
1114 err_msg_was_printed[core] = true;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001115 }
1116 }
1117
Felix Manlunasbb54be52017-04-04 19:26:57 -07001118 if (all_vf_links_are_disabled)
1119 continue;
1120
1121 disable_all_vf_links(oct);
1122 disable_all_vf_links(other_oct);
1123 all_vf_links_are_disabled = true;
1124
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001125#ifdef CONFIG_MODULE_UNLOAD
Felix Manlunasbb54be52017-04-04 19:26:57 -07001126 vfs_mask1 = READ_ONCE(oct->sriov_info.vf_drv_loaded_mask);
1127 vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001128
Felix Manlunasbb54be52017-04-04 19:26:57 -07001129 vfs_referencing_pf = hweight64(vfs_mask1);
1130 vfs_referencing_pf += hweight64(vfs_mask2);
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001131
Felix Manlunasbb54be52017-04-04 19:26:57 -07001132 refcount = module_refcount(THIS_MODULE);
1133 if (refcount >= vfs_referencing_pf) {
1134 while (vfs_referencing_pf) {
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001135 module_put(THIS_MODULE);
Felix Manlunasbb54be52017-04-04 19:26:57 -07001136 vfs_referencing_pf--;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001137 }
1138 }
1139#endif
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001140 }
1141
1142 return 0;
1143}
1144
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001145/**
1146 * \brief PCI probe handler
1147 * @param pdev PCI device structure
1148 * @param ent unused
1149 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07001150static int
1151liquidio_probe(struct pci_dev *pdev,
1152 const struct pci_device_id *ent __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001153{
1154 struct octeon_device *oct_dev = NULL;
1155 struct handshake *hs;
1156
1157 oct_dev = octeon_allocate_device(pdev->device,
1158 sizeof(struct octeon_device_priv));
1159 if (!oct_dev) {
1160 dev_err(&pdev->dev, "Unable to allocate device\n");
1161 return -ENOMEM;
1162 }
1163
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001164 if (pdev->device == OCTEON_CN23XX_PF_VID)
1165 oct_dev->msix_on = LIO_FLAG_MSIX_ENABLED;
1166
Intiyaz Bashaaa69ff92017-08-11 11:22:09 -07001167 /* Enable PTP for 6XXX Device */
1168 if (((pdev->device == OCTEON_CN66XX) ||
1169 (pdev->device == OCTEON_CN68XX)))
1170 oct_dev->ptp_enable = true;
1171 else
1172 oct_dev->ptp_enable = false;
1173
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001174 dev_info(&pdev->dev, "Initializing device %x:%x.\n",
1175 (u32)pdev->vendor, (u32)pdev->device);
1176
1177 /* Assign octeon_device for this device to the private data area. */
1178 pci_set_drvdata(pdev, oct_dev);
1179
1180 /* set linux specific device pointer */
1181 oct_dev->pci_dev = (void *)pdev;
1182
1183 hs = &handshake[oct_dev->octeon_id];
1184 init_completion(&hs->init);
1185 init_completion(&hs->started);
1186 hs->pci_dev = pdev;
1187
1188 if (oct_dev->octeon_id == 0)
1189 /* first LiquidIO NIC is detected */
1190 complete(&first_stage);
1191
1192 if (octeon_device_init(oct_dev)) {
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001193 complete(&hs->init);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001194 liquidio_remove(pdev);
1195 return -ENOMEM;
1196 }
1197
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001198 if (OCTEON_CN23XX_PF(oct_dev)) {
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001199 u8 bus, device, function;
1200
Felix Manlunas392209f2017-10-25 18:04:56 -07001201 if (atomic_read(oct_dev->adapter_refcount) == 1) {
1202 /* Each NIC gets one watchdog kernel thread. The first
1203 * PF (of each NIC) that gets pci_driver->probe()'d
1204 * creates that thread.
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001205 */
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001206 bus = pdev->bus->number;
1207 device = PCI_SLOT(pdev->devfn);
1208 function = PCI_FUNC(pdev->devfn);
1209 oct_dev->watchdog_task = kthread_create(
1210 liquidio_watchdog, oct_dev,
1211 "liowd/%02hhx:%02hhx.%hhx", bus, device, function);
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001212 if (!IS_ERR(oct_dev->watchdog_task)) {
1213 wake_up_process(oct_dev->watchdog_task);
1214 } else {
1215 oct_dev->watchdog_task = NULL;
1216 dev_err(&oct_dev->pci_dev->dev,
1217 "failed to create kernel_thread\n");
1218 liquidio_remove(pdev);
1219 return -1;
1220 }
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001221 }
1222 }
1223
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07001224 oct_dev->rx_pause = 1;
1225 oct_dev->tx_pause = 1;
1226
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001227 dev_dbg(&oct_dev->pci_dev->dev, "Device is ready\n");
1228
1229 return 0;
1230}
1231
Rick Farrington088b8742017-09-22 17:12:43 -07001232static bool fw_type_is_auto(void)
Felix Manlunas7cc61db2017-03-23 13:26:28 -07001233{
Rick Farrington088b8742017-09-22 17:12:43 -07001234 return strncmp(fw_type, LIO_FW_NAME_TYPE_AUTO,
1235 sizeof(LIO_FW_NAME_TYPE_AUTO)) == 0;
Felix Manlunas7cc61db2017-03-23 13:26:28 -07001236}
1237
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001238/**
Rick Farrington70535352017-08-17 23:11:25 -07001239 * \brief PCI FLR for each Octeon device.
1240 * @param oct octeon device
1241 */
1242static void octeon_pci_flr(struct octeon_device *oct)
1243{
1244 int rc;
1245
1246 pci_save_state(oct->pci_dev);
1247
1248 pci_cfg_access_lock(oct->pci_dev);
1249
1250 /* Quiesce the device completely */
1251 pci_write_config_word(oct->pci_dev, PCI_COMMAND,
1252 PCI_COMMAND_INTX_DISABLE);
1253
1254 rc = __pci_reset_function_locked(oct->pci_dev);
1255
1256 if (rc != 0)
1257 dev_err(&oct->pci_dev->dev, "Error %d resetting PCI function %d\n",
1258 rc, oct->pf_num);
1259
1260 pci_cfg_access_unlock(oct->pci_dev);
1261
1262 pci_restore_state(oct->pci_dev);
1263}
1264
1265/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001266 *\brief Destroy resources associated with octeon device
1267 * @param pdev PCI device structure
1268 * @param ent unused
1269 */
1270static void octeon_destroy_resources(struct octeon_device *oct)
1271{
Rick Farringtone1e3ce62017-05-16 11:14:50 -07001272 int i, refcount;
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001273 struct msix_entry *msix_entries;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001274 struct octeon_device_priv *oct_priv =
1275 (struct octeon_device_priv *)oct->priv;
1276
1277 struct handshake *hs;
1278
1279 switch (atomic_read(&oct->status)) {
1280 case OCT_DEV_RUNNING:
1281 case OCT_DEV_CORE_OK:
1282
1283 /* No more instructions will be forwarded. */
1284 atomic_set(&oct->status, OCT_DEV_IN_RESET);
1285
1286 oct->app_mode = CVM_DRV_INVALID_APP;
1287 dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
1288 lio_get_state_string(&oct->status));
1289
1290 schedule_timeout_uninterruptible(HZ / 10);
1291
1292 /* fallthrough */
1293 case OCT_DEV_HOST_OK:
1294
1295 /* fallthrough */
1296 case OCT_DEV_CONSOLE_INIT_DONE:
1297 /* Remove any consoles */
1298 octeon_remove_consoles(oct);
1299
1300 /* fallthrough */
1301 case OCT_DEV_IO_QUEUES_DONE:
1302 if (wait_for_pending_requests(oct))
1303 dev_err(&oct->pci_dev->dev, "There were pending requests\n");
1304
1305 if (lio_wait_for_instr_fetch(oct))
1306 dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
1307
1308 /* Disable the input and output queues now. No more packets will
1309 * arrive from Octeon, but we should wait for all packet
1310 * processing to finish.
1311 */
1312 oct->fn_list.disable_io_queues(oct);
1313
1314 if (lio_wait_for_oq_pkts(oct))
1315 dev_err(&oct->pci_dev->dev, "OQ had pending packets\n");
1316
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001317 /* fallthrough */
1318 case OCT_DEV_INTR_SET_DONE:
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001319 /* Disable interrupts */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001320 oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001321
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001322 if (oct->msix_on) {
1323 msix_entries = (struct msix_entry *)oct->msix_entries;
1324 for (i = 0; i < oct->num_msix_irqs - 1; i++) {
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07001325 if (oct->ioq_vector[i].vector) {
1326 /* clear the affinity_cpumask */
1327 irq_set_affinity_hint(
1328 msix_entries[i].vector,
1329 NULL);
1330 free_irq(msix_entries[i].vector,
1331 &oct->ioq_vector[i]);
1332 oct->ioq_vector[i].vector = 0;
1333 }
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001334 }
1335 /* non-iov vector's argument is oct struct */
1336 free_irq(msix_entries[i].vector, oct);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001337
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001338 pci_disable_msix(oct->pci_dev);
1339 kfree(oct->msix_entries);
1340 oct->msix_entries = NULL;
1341 } else {
1342 /* Release the interrupt line */
1343 free_irq(oct->pci_dev->irq, oct);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001344
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001345 if (oct->flags & LIO_FLAG_MSI_ENABLED)
1346 pci_disable_msi(oct->pci_dev);
1347 }
1348
Rick Farrington0c88a762017-03-13 12:58:04 -07001349 kfree(oct->irq_name_storage);
1350 oct->irq_name_storage = NULL;
1351
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001352 /* fallthrough */
1353 case OCT_DEV_MSIX_ALLOC_VECTOR_DONE:
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001354 if (OCTEON_CN23XX_PF(oct))
1355 octeon_free_ioq_vector(oct);
Raghu Vatsavayi5d655562016-11-14 15:54:42 -08001356
1357 /* fallthrough */
1358 case OCT_DEV_MBOX_SETUP_DONE:
1359 if (OCTEON_CN23XX_PF(oct))
1360 oct->fn_list.free_mbox(oct);
1361
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001362 /* fallthrough */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001363 case OCT_DEV_IN_RESET:
1364 case OCT_DEV_DROQ_INIT_DONE:
Raghu Vatsavayi763185a2016-11-14 15:54:45 -08001365 /* Wait for any pending operations */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001366 mdelay(100);
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001367 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001368 if (!(oct->io_qmask.oq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001369 continue;
1370 octeon_delete_droq(oct, i);
1371 }
1372
1373 /* Force any pending handshakes to complete */
1374 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
1375 hs = &handshake[i];
1376
1377 if (hs->pci_dev) {
1378 handshake[oct->octeon_id].init_ok = 0;
1379 complete(&handshake[oct->octeon_id].init);
1380 handshake[oct->octeon_id].started_ok = 0;
1381 complete(&handshake[oct->octeon_id].started);
1382 }
1383 }
1384
1385 /* fallthrough */
1386 case OCT_DEV_RESP_LIST_INIT_DONE:
1387 octeon_delete_response_list(oct);
1388
1389 /* fallthrough */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001390 case OCT_DEV_INSTR_QUEUE_INIT_DONE:
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001391 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001392 if (!(oct->io_qmask.iq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001393 continue;
1394 octeon_delete_instr_queue(oct, i);
1395 }
Raghu Vatsavayica6139f2016-11-14 15:54:40 -08001396#ifdef CONFIG_PCI_IOV
1397 if (oct->sriov_info.sriov_enabled)
1398 pci_disable_sriov(oct->pci_dev);
1399#endif
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001400 /* fallthrough */
1401 case OCT_DEV_SC_BUFF_POOL_INIT_DONE:
1402 octeon_free_sc_buffer_pool(oct);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001403
1404 /* fallthrough */
1405 case OCT_DEV_DISPATCH_INIT_DONE:
1406 octeon_delete_dispatch_list(oct);
1407 cancel_delayed_work_sync(&oct->nic_poll_work.work);
1408
1409 /* fallthrough */
1410 case OCT_DEV_PCI_MAP_DONE:
Rick Farringtone1e3ce62017-05-16 11:14:50 -07001411 refcount = octeon_deregister_device(oct);
1412
Rick Farrington70535352017-08-17 23:11:25 -07001413 /* Soft reset the octeon device before exiting.
1414 * However, if fw was loaded from card (i.e. autoboot),
1415 * perform an FLR instead.
1416 * Implementation note: only soft-reset the device
1417 * if it is a CN6XXX OR the LAST CN23XX device.
1418 */
Rick Farrington088b8742017-09-22 17:12:43 -07001419 if (atomic_read(oct->adapter_fw_state) == FW_IS_PRELOADED)
Rick Farrington70535352017-08-17 23:11:25 -07001420 octeon_pci_flr(oct);
1421 else if (OCTEON_CN6XXX(oct) || !refcount)
1422 oct->fn_list.soft_reset(oct);
Raghu Vatsavayi60b48c52016-06-21 22:53:09 -07001423
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001424 octeon_unmap_pci_barx(oct, 0);
1425 octeon_unmap_pci_barx(oct, 1);
1426
1427 /* fallthrough */
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001428 case OCT_DEV_PCI_ENABLE_DONE:
1429 pci_clear_master(oct->pci_dev);
Raghu Vatsavayi60b48c52016-06-21 22:53:09 -07001430 /* Disable the device, releasing the PCI INT */
1431 pci_disable_device(oct->pci_dev);
1432
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001433 /* fallthrough */
1434 case OCT_DEV_BEGIN_STATE:
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001435 /* Nothing to be done here either */
1436 break;
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07001437 } /* end switch (oct->status) */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001438
1439 tasklet_kill(&oct_priv->droq_tasklet);
1440}
1441
1442/**
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001443 * \brief Callback for rx ctrl
1444 * @param status status of request
1445 * @param buf pointer to resp structure
1446 */
1447static void rx_ctl_callback(struct octeon_device *oct,
1448 u32 status,
1449 void *buf)
1450{
1451 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
1452 struct liquidio_rx_ctl_context *ctx;
1453
1454 ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr;
1455
1456 oct = lio_get_device(ctx->octeon_id);
1457 if (status)
1458 dev_err(&oct->pci_dev->dev, "rx ctl instruction failed. Status: %llx\n",
1459 CVM_CAST64(status));
1460 WRITE_ONCE(ctx->cond, 1);
1461
1462 /* This barrier is required to be sure that the response has been
1463 * written fully before waking up the handler
1464 */
1465 wmb();
1466
1467 wake_up_interruptible(&ctx->wc);
1468}
1469
1470/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001471 * \brief Send Rx control command
1472 * @param lio per-network private data
1473 * @param start_stop whether to start or stop
1474 */
1475static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
1476{
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001477 struct octeon_soft_command *sc;
1478 struct liquidio_rx_ctl_context *ctx;
1479 union octnet_cmd *ncmd;
1480 int ctx_size = sizeof(struct liquidio_rx_ctl_context);
1481 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1482 int retval;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001483
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001484 if (oct->props[lio->ifidx].rx_on == start_stop)
1485 return;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001486
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001487 sc = (struct octeon_soft_command *)
1488 octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
1489 16, ctx_size);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001490
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001491 ncmd = (union octnet_cmd *)sc->virtdptr;
1492 ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr;
1493
1494 WRITE_ONCE(ctx->cond, 0);
1495 ctx->octeon_id = lio_get_device_id(oct);
1496 init_waitqueue_head(&ctx->wc);
1497
1498 ncmd->u64 = 0;
1499 ncmd->s.cmd = OCTNET_CMD_RX_CTL;
1500 ncmd->s.param1 = start_stop;
1501
1502 octeon_swap_8B_data((u64 *)ncmd, (OCTNET_CMD_SIZE >> 3));
1503
1504 sc->iq_no = lio->linfo.txpciq[0].s.q_no;
1505
1506 octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
1507 OPCODE_NIC_CMD, 0, 0, 0);
1508
1509 sc->callback = rx_ctl_callback;
1510 sc->callback_arg = sc;
1511 sc->wait_time = 5000;
1512
1513 retval = octeon_send_soft_command(oct, sc);
1514 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001515 netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n");
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001516 } else {
1517 /* Sleep on a wait queue till the cond flag indicates that the
1518 * response arrived or timed-out.
1519 */
1520 if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR)
1521 return;
1522 oct->props[lio->ifidx].rx_on = start_stop;
1523 }
1524
1525 octeon_free_soft_command(oct, sc);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001526}
1527
1528/**
1529 * \brief Destroy NIC device interface
1530 * @param oct octeon device
1531 * @param ifidx which interface to destroy
1532 *
1533 * Cleanup associated with each interface for an Octeon device when NIC
1534 * module is being unloaded or if initialization fails during load.
1535 */
1536static void liquidio_destroy_nic_device(struct octeon_device *oct, int ifidx)
1537{
1538 struct net_device *netdev = oct->props[ifidx].netdev;
1539 struct lio *lio;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001540 struct napi_struct *napi, *n;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001541
1542 if (!netdev) {
1543 dev_err(&oct->pci_dev->dev, "%s No netdevice ptr for index %d\n",
1544 __func__, ifidx);
1545 return;
1546 }
1547
1548 lio = GET_LIO(netdev);
1549
1550 dev_dbg(&oct->pci_dev->dev, "NIC device cleanup\n");
1551
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001552 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING)
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001553 liquidio_stop(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001554
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001555 if (oct->props[lio->ifidx].napi_enabled == 1) {
1556 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1557 napi_disable(napi);
1558
1559 oct->props[lio->ifidx].napi_enabled = 0;
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07001560
1561 if (OCTEON_CN23XX_PF(oct))
1562 oct->droq[0]->ops.poll_mode = 0;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001563 }
1564
Intiyaz Basha42013e92017-08-08 19:34:28 -07001565 /* Delete NAPI */
1566 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1567 netif_napi_del(napi);
1568
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001569 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED)
1570 unregister_netdev(netdev);
1571
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -07001572 cleanup_sync_octeon_time_wq(netdev);
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07001573 cleanup_link_status_change_wq(netdev);
1574
Satanand Burla031d4f12017-03-22 11:31:13 -07001575 cleanup_rx_oom_poll_fn(netdev);
1576
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001577 delete_glists(lio);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001578
1579 free_netdev(netdev);
1580
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001581 oct->props[ifidx].gmxport = -1;
1582
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001583 oct->props[ifidx].netdev = NULL;
1584}
1585
1586/**
1587 * \brief Stop complete NIC functionality
1588 * @param oct octeon device
1589 */
1590static int liquidio_stop_nic_module(struct octeon_device *oct)
1591{
1592 int i, j;
1593 struct lio *lio;
1594
1595 dev_dbg(&oct->pci_dev->dev, "Stopping network interfaces\n");
1596 if (!oct->ifcount) {
1597 dev_err(&oct->pci_dev->dev, "Init for Octeon was not completed\n");
1598 return 1;
1599 }
1600
Raghu Vatsavayi60441882016-06-21 22:53:08 -07001601 spin_lock_bh(&oct->cmd_resp_wqlock);
1602 oct->cmd_resp_state = OCT_DRV_OFFLINE;
1603 spin_unlock_bh(&oct->cmd_resp_wqlock);
1604
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001605 for (i = 0; i < oct->ifcount; i++) {
1606 lio = GET_LIO(oct->props[i].netdev);
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07001607 for (j = 0; j < oct->num_oqs; j++)
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001608 octeon_unregister_droq_ops(oct,
1609 lio->linfo.rxpciq[j].s.q_no);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001610 }
1611
1612 for (i = 0; i < oct->ifcount; i++)
1613 liquidio_destroy_nic_device(oct, i);
1614
1615 dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
1616 return 0;
1617}
1618
1619/**
1620 * \brief Cleans up resources at unload time
1621 * @param pdev PCI device structure
1622 */
1623static void liquidio_remove(struct pci_dev *pdev)
1624{
1625 struct octeon_device *oct_dev = pci_get_drvdata(pdev);
1626
1627 dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n");
1628
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001629 if (oct_dev->watchdog_task)
1630 kthread_stop(oct_dev->watchdog_task);
1631
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001632 if (oct_dev->app_mode && (oct_dev->app_mode == CVM_DRV_NIC_APP))
1633 liquidio_stop_nic_module(oct_dev);
1634
1635 /* Reset the octeon device and cleanup all memory allocated for
1636 * the octeon device by driver.
1637 */
1638 octeon_destroy_resources(oct_dev);
1639
1640 dev_info(&oct_dev->pci_dev->dev, "Device removed\n");
1641
1642 /* This octeon device has been removed. Update the global
1643 * data structure to reflect this. Free the device structure.
1644 */
1645 octeon_free_device_mem(oct_dev);
1646}
1647
1648/**
1649 * \brief Identify the Octeon device and to map the BAR address space
1650 * @param oct octeon device
1651 */
1652static int octeon_chip_specific_setup(struct octeon_device *oct)
1653{
1654 u32 dev_id, rev_id;
1655 int ret = 1;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001656 char *s;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001657
1658 pci_read_config_dword(oct->pci_dev, 0, &dev_id);
1659 pci_read_config_dword(oct->pci_dev, 8, &rev_id);
1660 oct->rev_id = rev_id & 0xff;
1661
1662 switch (dev_id) {
1663 case OCTEON_CN68XX_PCIID:
1664 oct->chip_id = OCTEON_CN68XX;
1665 ret = lio_setup_cn68xx_octeon_device(oct);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001666 s = "CN68XX";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001667 break;
1668
1669 case OCTEON_CN66XX_PCIID:
1670 oct->chip_id = OCTEON_CN66XX;
1671 ret = lio_setup_cn66xx_octeon_device(oct);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001672 s = "CN66XX";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001673 break;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001674
Raghu Vatsavayi72c00912016-08-31 11:03:25 -07001675 case OCTEON_CN23XX_PCIID_PF:
1676 oct->chip_id = OCTEON_CN23XX_PF_VID;
1677 ret = setup_cn23xx_octeon_pf_device(oct);
Rick Farrington0c45d7f2017-08-18 18:21:49 -07001678 if (ret)
1679 break;
Derek Chicklescf19a8c2017-08-01 15:05:07 -07001680#ifdef CONFIG_PCI_IOV
1681 if (!ret)
1682 pci_sriov_set_totalvfs(oct->pci_dev,
1683 oct->sriov_info.max_vfs);
1684#endif
Raghu Vatsavayi72c00912016-08-31 11:03:25 -07001685 s = "CN23XX";
1686 break;
1687
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001688 default:
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001689 s = "?";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001690 dev_err(&oct->pci_dev->dev, "Unknown device found (dev_id: %x)\n",
1691 dev_id);
1692 }
1693
1694 if (!ret)
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001695 dev_info(&oct->pci_dev->dev, "%s PASS%d.%d %s Version: %s\n", s,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001696 OCTEON_MAJOR_REV(oct),
1697 OCTEON_MINOR_REV(oct),
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001698 octeon_get_conf(oct)->card_name,
1699 LIQUIDIO_VERSION);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001700
1701 return ret;
1702}
1703
1704/**
1705 * \brief PCI initialization for each Octeon device.
1706 * @param oct octeon device
1707 */
1708static int octeon_pci_os_setup(struct octeon_device *oct)
1709{
1710 /* setup PCI stuff first */
1711 if (pci_enable_device(oct->pci_dev)) {
1712 dev_err(&oct->pci_dev->dev, "pci_enable_device failed\n");
1713 return 1;
1714 }
1715
1716 if (dma_set_mask_and_coherent(&oct->pci_dev->dev, DMA_BIT_MASK(64))) {
1717 dev_err(&oct->pci_dev->dev, "Unexpected DMA device capability\n");
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001718 pci_disable_device(oct->pci_dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001719 return 1;
1720 }
1721
1722 /* Enable PCI DMA Master. */
1723 pci_set_master(oct->pci_dev);
1724
1725 return 0;
1726}
1727
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001728static inline int skb_iq(struct lio *lio, struct sk_buff *skb)
1729{
1730 int q = 0;
1731
1732 if (netif_is_multiqueue(lio->netdev))
1733 q = skb->queue_mapping % lio->linfo.num_txpciq;
1734
1735 return q;
1736}
1737
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001738/**
1739 * \brief Check Tx queue state for a given network buffer
1740 * @param lio per-network private data
1741 * @param skb network buffer
1742 */
1743static inline int check_txq_state(struct lio *lio, struct sk_buff *skb)
1744{
1745 int q = 0, iq = 0;
1746
1747 if (netif_is_multiqueue(lio->netdev)) {
1748 q = skb->queue_mapping;
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07001749 iq = lio->linfo.txpciq[(q % lio->oct_dev->num_iqs)].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001750 } else {
1751 iq = lio->txq;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001752 q = iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001753 }
1754
1755 if (octnet_iq_is_full(lio->oct_dev, iq))
1756 return 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001757
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07001758 if (__netif_subqueue_stopped(lio->netdev, q)) {
1759 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, iq, tx_restart, 1);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001760 wake_q(lio->netdev, q);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07001761 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001762 return 1;
1763}
1764
1765/**
1766 * \brief Unmap and free network buffer
1767 * @param buf buffer
1768 */
1769static void free_netbuf(void *buf)
1770{
1771 struct sk_buff *skb;
1772 struct octnet_buf_free_info *finfo;
1773 struct lio *lio;
1774
1775 finfo = (struct octnet_buf_free_info *)buf;
1776 skb = finfo->skb;
1777 lio = finfo->lio;
1778
1779 dma_unmap_single(&lio->oct_dev->pci_dev->dev, finfo->dptr, skb->len,
1780 DMA_TO_DEVICE);
1781
1782 check_txq_state(lio, skb);
1783
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001784 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001785}
1786
1787/**
1788 * \brief Unmap and free gather buffer
1789 * @param buf buffer
1790 */
1791static void free_netsgbuf(void *buf)
1792{
1793 struct octnet_buf_free_info *finfo;
1794 struct sk_buff *skb;
1795 struct lio *lio;
1796 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001797 int i, frags, iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001798
1799 finfo = (struct octnet_buf_free_info *)buf;
1800 skb = finfo->skb;
1801 lio = finfo->lio;
1802 g = finfo->g;
1803 frags = skb_shinfo(skb)->nr_frags;
1804
1805 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1806 g->sg[0].ptr[0], (skb->len - skb->data_len),
1807 DMA_TO_DEVICE);
1808
1809 i = 1;
1810 while (frags--) {
1811 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1812
1813 pci_unmap_page((lio->oct_dev)->pci_dev,
1814 g->sg[(i >> 2)].ptr[(i & 3)],
1815 frag->size, DMA_TO_DEVICE);
1816 i++;
1817 }
1818
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001819 iq = skb_iq(lio, skb);
1820 spin_lock(&lio->glist_lock[iq]);
1821 list_add_tail(&g->list, &lio->glist[iq]);
1822 spin_unlock(&lio->glist_lock[iq]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001823
1824 check_txq_state(lio, skb); /* mq support: sub-queue state check */
1825
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001826 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001827}
1828
1829/**
1830 * \brief Unmap and free gather buffer with response
1831 * @param buf buffer
1832 */
1833static void free_netsgbuf_with_resp(void *buf)
1834{
1835 struct octeon_soft_command *sc;
1836 struct octnet_buf_free_info *finfo;
1837 struct sk_buff *skb;
1838 struct lio *lio;
1839 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001840 int i, frags, iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001841
1842 sc = (struct octeon_soft_command *)buf;
1843 skb = (struct sk_buff *)sc->callback_arg;
1844 finfo = (struct octnet_buf_free_info *)&skb->cb;
1845
1846 lio = finfo->lio;
1847 g = finfo->g;
1848 frags = skb_shinfo(skb)->nr_frags;
1849
1850 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1851 g->sg[0].ptr[0], (skb->len - skb->data_len),
1852 DMA_TO_DEVICE);
1853
1854 i = 1;
1855 while (frags--) {
1856 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1857
1858 pci_unmap_page((lio->oct_dev)->pci_dev,
1859 g->sg[(i >> 2)].ptr[(i & 3)],
1860 frag->size, DMA_TO_DEVICE);
1861 i++;
1862 }
1863
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001864 iq = skb_iq(lio, skb);
1865
1866 spin_lock(&lio->glist_lock[iq]);
1867 list_add_tail(&g->list, &lio->glist[iq]);
1868 spin_unlock(&lio->glist_lock[iq]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001869
1870 /* Don't free the skb yet */
1871
1872 check_txq_state(lio, skb);
1873}
1874
1875/**
1876 * \brief Adjust ptp frequency
1877 * @param ptp PTP clock info
1878 * @param ppb how much to adjust by, in parts-per-billion
1879 */
1880static int liquidio_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
1881{
1882 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1883 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1884 u64 comp, delta;
1885 unsigned long flags;
1886 bool neg_adj = false;
1887
1888 if (ppb < 0) {
1889 neg_adj = true;
1890 ppb = -ppb;
1891 }
1892
1893 /* The hardware adds the clock compensation value to the
1894 * PTP clock on every coprocessor clock cycle, so we
1895 * compute the delta in terms of coprocessor clocks.
1896 */
1897 delta = (u64)ppb << 32;
1898 do_div(delta, oct->coproc_clock_rate);
1899
1900 spin_lock_irqsave(&lio->ptp_lock, flags);
1901 comp = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_COMP);
1902 if (neg_adj)
1903 comp -= delta;
1904 else
1905 comp += delta;
1906 lio_pci_writeq(oct, comp, CN6XXX_MIO_PTP_CLOCK_COMP);
1907 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1908
1909 return 0;
1910}
1911
1912/**
1913 * \brief Adjust ptp time
1914 * @param ptp PTP clock info
1915 * @param delta how much to adjust by, in nanosecs
1916 */
1917static int liquidio_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
1918{
1919 unsigned long flags;
1920 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1921
1922 spin_lock_irqsave(&lio->ptp_lock, flags);
1923 lio->ptp_adjust += delta;
1924 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1925
1926 return 0;
1927}
1928
1929/**
1930 * \brief Get hardware clock time, including any adjustment
1931 * @param ptp PTP clock info
1932 * @param ts timespec
1933 */
1934static int liquidio_ptp_gettime(struct ptp_clock_info *ptp,
1935 struct timespec64 *ts)
1936{
1937 u64 ns;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001938 unsigned long flags;
1939 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1940 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1941
1942 spin_lock_irqsave(&lio->ptp_lock, flags);
1943 ns = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_HI);
1944 ns += lio->ptp_adjust;
1945 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1946
Kefeng Wang286af312016-01-27 17:34:37 +08001947 *ts = ns_to_timespec64(ns);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001948
1949 return 0;
1950}
1951
1952/**
1953 * \brief Set hardware clock time. Reset adjustment
1954 * @param ptp PTP clock info
1955 * @param ts timespec
1956 */
1957static int liquidio_ptp_settime(struct ptp_clock_info *ptp,
1958 const struct timespec64 *ts)
1959{
1960 u64 ns;
1961 unsigned long flags;
1962 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1963 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1964
Arnd Bergmanne7ad9792017-10-12 11:48:31 +02001965 ns = timespec64_to_ns(ts);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001966
1967 spin_lock_irqsave(&lio->ptp_lock, flags);
1968 lio_pci_writeq(oct, ns, CN6XXX_MIO_PTP_CLOCK_HI);
1969 lio->ptp_adjust = 0;
1970 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1971
1972 return 0;
1973}
1974
1975/**
1976 * \brief Check if PTP is enabled
1977 * @param ptp PTP clock info
1978 * @param rq request
1979 * @param on is it on
1980 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07001981static int
1982liquidio_ptp_enable(struct ptp_clock_info *ptp __attribute__((unused)),
1983 struct ptp_clock_request *rq __attribute__((unused)),
1984 int on __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001985{
1986 return -EOPNOTSUPP;
1987}
1988
1989/**
1990 * \brief Open PTP clock source
1991 * @param netdev network device
1992 */
1993static void oct_ptp_open(struct net_device *netdev)
1994{
1995 struct lio *lio = GET_LIO(netdev);
1996 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1997
1998 spin_lock_init(&lio->ptp_lock);
1999
2000 snprintf(lio->ptp_info.name, 16, "%s", netdev->name);
2001 lio->ptp_info.owner = THIS_MODULE;
2002 lio->ptp_info.max_adj = 250000000;
2003 lio->ptp_info.n_alarm = 0;
2004 lio->ptp_info.n_ext_ts = 0;
2005 lio->ptp_info.n_per_out = 0;
2006 lio->ptp_info.pps = 0;
2007 lio->ptp_info.adjfreq = liquidio_ptp_adjfreq;
2008 lio->ptp_info.adjtime = liquidio_ptp_adjtime;
2009 lio->ptp_info.gettime64 = liquidio_ptp_gettime;
2010 lio->ptp_info.settime64 = liquidio_ptp_settime;
2011 lio->ptp_info.enable = liquidio_ptp_enable;
2012
2013 lio->ptp_adjust = 0;
2014
2015 lio->ptp_clock = ptp_clock_register(&lio->ptp_info,
2016 &oct->pci_dev->dev);
2017
2018 if (IS_ERR(lio->ptp_clock))
2019 lio->ptp_clock = NULL;
2020}
2021
2022/**
2023 * \brief Init PTP clock
2024 * @param oct octeon device
2025 */
2026static void liquidio_ptp_init(struct octeon_device *oct)
2027{
2028 u64 clock_comp, cfg;
2029
2030 clock_comp = (u64)NSEC_PER_SEC << 32;
2031 do_div(clock_comp, oct->coproc_clock_rate);
2032 lio_pci_writeq(oct, clock_comp, CN6XXX_MIO_PTP_CLOCK_COMP);
2033
2034 /* Enable */
2035 cfg = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_CFG);
2036 lio_pci_writeq(oct, cfg | 0x01, CN6XXX_MIO_PTP_CLOCK_CFG);
2037}
2038
2039/**
2040 * \brief Load firmware to device
2041 * @param oct octeon device
2042 *
2043 * Maps device to firmware filename, requests firmware, and downloads it
2044 */
2045static int load_firmware(struct octeon_device *oct)
2046{
2047 int ret = 0;
2048 const struct firmware *fw;
2049 char fw_name[LIO_MAX_FW_FILENAME_LEN];
2050 char *tmp_fw_type;
2051
Rick Farrington429cbf62017-09-22 17:12:51 -07002052 if (fw_type_is_auto()) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002053 tmp_fw_type = LIO_FW_NAME_TYPE_NIC;
Rick Farrington429cbf62017-09-22 17:12:51 -07002054 strncpy(fw_type, tmp_fw_type, sizeof(fw_type));
2055 } else {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002056 tmp_fw_type = fw_type;
Rick Farrington429cbf62017-09-22 17:12:51 -07002057 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002058
2059 sprintf(fw_name, "%s%s%s_%s%s", LIO_FW_DIR, LIO_FW_BASE_NAME,
2060 octeon_get_conf(oct)->card_name, tmp_fw_type,
2061 LIO_FW_NAME_SUFFIX);
2062
2063 ret = request_firmware(&fw, fw_name, &oct->pci_dev->dev);
2064 if (ret) {
2065 dev_err(&oct->pci_dev->dev, "Request firmware failed. Could not find file %s.\n.",
2066 fw_name);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07002067 release_firmware(fw);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002068 return ret;
2069 }
2070
2071 ret = octeon_download_firmware(oct, fw->data, fw->size);
2072
2073 release_firmware(fw);
2074
2075 return ret;
2076}
2077
2078/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002079 * \brief Callback for getting interface configuration
2080 * @param status status of request
2081 * @param buf pointer to resp structure
2082 */
2083static void if_cfg_callback(struct octeon_device *oct,
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002084 u32 status __attribute__((unused)),
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002085 void *buf)
2086{
2087 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
2088 struct liquidio_if_cfg_resp *resp;
2089 struct liquidio_if_cfg_context *ctx;
2090
2091 resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
Raghu Vatsavayi30136392016-09-01 11:16:11 -07002092 ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002093
2094 oct = lio_get_device(ctx->octeon_id);
2095 if (resp->status)
Rick Farringtonc5b71e62017-03-17 11:23:08 -07002096 dev_err(&oct->pci_dev->dev, "nic if cfg instruction failed. Status: 0x%llx (0x%08x)\n",
2097 CVM_CAST64(resp->status), status);
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002098 WRITE_ONCE(ctx->cond, 1);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002099
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07002100 snprintf(oct->fw_info.liquidio_firmware_version, 32, "%s",
2101 resp->cfg_info.liquidio_firmware_version);
2102
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002103 /* This barrier is required to be sure that the response has been
2104 * written fully before waking up the handler
2105 */
2106 wmb();
2107
2108 wake_up_interruptible(&ctx->wc);
2109}
2110
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002111/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002112 * \brief Poll routine for checking transmit queue status
2113 * @param work work_struct data structure
2114 */
2115static void octnet_poll_check_txq_status(struct work_struct *work)
2116{
2117 struct cavium_wk *wk = (struct cavium_wk *)work;
2118 struct lio *lio = (struct lio *)wk->ctxptr;
2119
2120 if (!ifstate_check(lio, LIO_IFSTATE_RUNNING))
2121 return;
2122
2123 check_txq_status(lio);
2124 queue_delayed_work(lio->txq_status_wq.wq,
2125 &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
2126}
2127
2128/**
2129 * \brief Sets up the txq poll check
2130 * @param netdev network device
2131 */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002132static inline int setup_tx_poll_fn(struct net_device *netdev)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002133{
2134 struct lio *lio = GET_LIO(netdev);
2135 struct octeon_device *oct = lio->oct_dev;
2136
Bhaktipriya Shridhar292b9da2016-06-08 01:47:59 +05302137 lio->txq_status_wq.wq = alloc_workqueue("txq-status",
2138 WQ_MEM_RECLAIM, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002139 if (!lio->txq_status_wq.wq) {
2140 dev_err(&oct->pci_dev->dev, "unable to create cavium txq status wq\n");
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002141 return -1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002142 }
2143 INIT_DELAYED_WORK(&lio->txq_status_wq.wk.work,
2144 octnet_poll_check_txq_status);
2145 lio->txq_status_wq.wk.ctxptr = lio;
2146 queue_delayed_work(lio->txq_status_wq.wq,
2147 &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002148 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002149}
2150
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002151static inline void cleanup_tx_poll_fn(struct net_device *netdev)
2152{
2153 struct lio *lio = GET_LIO(netdev);
2154
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002155 if (lio->txq_status_wq.wq) {
2156 cancel_delayed_work_sync(&lio->txq_status_wq.wk.work);
2157 destroy_workqueue(lio->txq_status_wq.wq);
2158 }
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002159}
2160
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002161/**
2162 * \brief Net device open for LiquidIO
2163 * @param netdev network device
2164 */
2165static int liquidio_open(struct net_device *netdev)
2166{
2167 struct lio *lio = GET_LIO(netdev);
2168 struct octeon_device *oct = lio->oct_dev;
2169 struct napi_struct *napi, *n;
2170
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002171 if (oct->props[lio->ifidx].napi_enabled == 0) {
2172 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
2173 napi_enable(napi);
2174
2175 oct->props[lio->ifidx].napi_enabled = 1;
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07002176
2177 if (OCTEON_CN23XX_PF(oct))
2178 oct->droq[0]->ops.poll_mode = 1;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002179 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002180
Intiyaz Bashaaa69ff92017-08-11 11:22:09 -07002181 if (oct->ptp_enable)
Prasad Kanneganti9feb16a2017-01-03 11:27:33 -08002182 oct_ptp_open(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002183
2184 ifstate_set(lio, LIO_IFSTATE_RUNNING);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002185
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07002186 /* Ready for link status updates */
2187 lio->intf_open = 1;
2188
2189 netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n");
2190
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002191 if (OCTEON_CN23XX_PF(oct)) {
2192 if (!oct->msix_on)
2193 if (setup_tx_poll_fn(netdev))
2194 return -1;
2195 } else {
2196 if (setup_tx_poll_fn(netdev))
2197 return -1;
2198 }
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002199
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002200 start_txq(netdev);
2201
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002202 /* tell Octeon to start forwarding packets to host */
2203 send_rx_ctrl_cmd(lio, 1);
2204
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002205 dev_info(&oct->pci_dev->dev, "%s interface is opened\n",
2206 netdev->name);
2207
2208 return 0;
2209}
2210
2211/**
2212 * \brief Net device stop for LiquidIO
2213 * @param netdev network device
2214 */
2215static int liquidio_stop(struct net_device *netdev)
2216{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002217 struct lio *lio = GET_LIO(netdev);
2218 struct octeon_device *oct = lio->oct_dev;
Intiyaz Basha42013e92017-08-08 19:34:28 -07002219 struct napi_struct *napi, *n;
2220
2221 if (oct->props[lio->ifidx].napi_enabled) {
2222 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
2223 napi_disable(napi);
2224
2225 oct->props[lio->ifidx].napi_enabled = 0;
2226
2227 if (OCTEON_CN23XX_PF(oct))
2228 oct->droq[0]->ops.poll_mode = 0;
2229 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002230
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002231 ifstate_reset(lio, LIO_IFSTATE_RUNNING);
2232
2233 netif_tx_disable(netdev);
2234
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002235 /* Inform that netif carrier is down */
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002236 netif_carrier_off(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002237 lio->intf_open = 0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002238 lio->linfo.link.s.link_up = 0;
2239 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002240
Felix Manlunascb2336b2017-01-11 17:09:02 -08002241 /* Tell Octeon that nic interface is down. */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002242 send_rx_ctrl_cmd(lio, 0);
2243
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002244 if (OCTEON_CN23XX_PF(oct)) {
2245 if (!oct->msix_on)
2246 cleanup_tx_poll_fn(netdev);
2247 } else {
2248 cleanup_tx_poll_fn(netdev);
2249 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002250
2251 if (lio->ptp_clock) {
2252 ptp_clock_unregister(lio->ptp_clock);
2253 lio->ptp_clock = NULL;
2254 }
2255
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002256 dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002257
2258 return 0;
2259}
2260
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002261/**
2262 * \brief Converts a mask based on net device flags
2263 * @param netdev network device
2264 *
2265 * This routine generates a octnet_ifflags mask from the net device flags
2266 * received from the OS.
2267 */
2268static inline enum octnet_ifflags get_new_flags(struct net_device *netdev)
2269{
2270 enum octnet_ifflags f = OCTNET_IFFLAG_UNICAST;
2271
2272 if (netdev->flags & IFF_PROMISC)
2273 f |= OCTNET_IFFLAG_PROMISC;
2274
2275 if (netdev->flags & IFF_ALLMULTI)
2276 f |= OCTNET_IFFLAG_ALLMULTI;
2277
2278 if (netdev->flags & IFF_MULTICAST) {
2279 f |= OCTNET_IFFLAG_MULTICAST;
2280
2281 /* Accept all multicast addresses if there are more than we
2282 * can handle
2283 */
2284 if (netdev_mc_count(netdev) > MAX_OCTEON_MULTICAST_ADDR)
2285 f |= OCTNET_IFFLAG_ALLMULTI;
2286 }
2287
2288 if (netdev->flags & IFF_BROADCAST)
2289 f |= OCTNET_IFFLAG_BROADCAST;
2290
2291 return f;
2292}
2293
2294/**
2295 * \brief Net device set_multicast_list
2296 * @param netdev network device
2297 */
2298static void liquidio_set_mcast_list(struct net_device *netdev)
2299{
2300 struct lio *lio = GET_LIO(netdev);
2301 struct octeon_device *oct = lio->oct_dev;
2302 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002303 struct netdev_hw_addr *ha;
2304 u64 *mc;
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002305 int ret;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002306 int mc_count = min(netdev_mc_count(netdev), MAX_OCTEON_MULTICAST_ADDR);
2307
2308 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2309
2310 /* Create a ctrl pkt command to be sent to core app. */
2311 nctrl.ncmd.u64 = 0;
2312 nctrl.ncmd.s.cmd = OCTNET_CMD_SET_MULTI_LIST;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002313 nctrl.ncmd.s.param1 = get_new_flags(netdev);
2314 nctrl.ncmd.s.param2 = mc_count;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002315 nctrl.ncmd.s.more = mc_count;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002316 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002317 nctrl.netpndev = (u64)netdev;
2318 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2319
2320 /* copy all the addresses into the udd */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002321 mc = &nctrl.udd[0];
2322 netdev_for_each_mc_addr(ha, netdev) {
2323 *mc = 0;
2324 memcpy(((u8 *)mc) + 2, ha->addr, ETH_ALEN);
2325 /* no need to swap bytes */
2326
2327 if (++mc > &nctrl.udd[mc_count])
2328 break;
2329 }
2330
2331 /* Apparently, any activity in this call from the kernel has to
2332 * be atomic. So we won't wait for response.
2333 */
2334 nctrl.wait_time = 0;
2335
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002336 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002337 if (ret < 0) {
2338 dev_err(&oct->pci_dev->dev, "DEVFLAGS change failed in core (ret: 0x%x)\n",
2339 ret);
2340 }
2341}
2342
2343/**
2344 * \brief Net device set_mac_address
2345 * @param netdev network device
2346 */
2347static int liquidio_set_mac(struct net_device *netdev, void *p)
2348{
2349 int ret = 0;
2350 struct lio *lio = GET_LIO(netdev);
2351 struct octeon_device *oct = lio->oct_dev;
2352 struct sockaddr *addr = (struct sockaddr *)p;
2353 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002354
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002355 if (!is_valid_ether_addr(addr->sa_data))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002356 return -EADDRNOTAVAIL;
2357
2358 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2359
2360 nctrl.ncmd.u64 = 0;
2361 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002362 nctrl.ncmd.s.param1 = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002363 nctrl.ncmd.s.more = 1;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002364 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002365 nctrl.netpndev = (u64)netdev;
2366 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2367 nctrl.wait_time = 100;
2368
2369 nctrl.udd[0] = 0;
2370 /* The MAC Address is presented in network byte order. */
2371 memcpy((u8 *)&nctrl.udd[0] + 2, addr->sa_data, ETH_ALEN);
2372
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002373 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002374 if (ret < 0) {
2375 dev_err(&oct->pci_dev->dev, "MAC Address change failed\n");
2376 return -ENOMEM;
2377 }
2378 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2379 memcpy(((u8 *)&lio->linfo.hw_addr) + 2, addr->sa_data, ETH_ALEN);
2380
2381 return 0;
2382}
2383
2384/**
2385 * \brief Net device get_stats
2386 * @param netdev network device
2387 */
2388static struct net_device_stats *liquidio_get_stats(struct net_device *netdev)
2389{
2390 struct lio *lio = GET_LIO(netdev);
2391 struct net_device_stats *stats = &netdev->stats;
2392 struct octeon_device *oct;
2393 u64 pkts = 0, drop = 0, bytes = 0;
2394 struct oct_droq_stats *oq_stats;
2395 struct oct_iq_stats *iq_stats;
2396 int i, iq_no, oq_no;
2397
2398 oct = lio->oct_dev;
2399
Intiyaz Bashad18ca7d2017-08-14 12:01:56 -07002400 if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
2401 return stats;
2402
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07002403 for (i = 0; i < oct->num_iqs; i++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002404 iq_no = lio->linfo.txpciq[i].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002405 iq_stats = &oct->instr_queue[iq_no]->stats;
2406 pkts += iq_stats->tx_done;
2407 drop += iq_stats->tx_dropped;
2408 bytes += iq_stats->tx_tot_bytes;
2409 }
2410
2411 stats->tx_packets = pkts;
2412 stats->tx_bytes = bytes;
2413 stats->tx_dropped = drop;
2414
2415 pkts = 0;
2416 drop = 0;
2417 bytes = 0;
2418
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07002419 for (i = 0; i < oct->num_oqs; i++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002420 oq_no = lio->linfo.rxpciq[i].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002421 oq_stats = &oct->droq[oq_no]->stats;
2422 pkts += oq_stats->rx_pkts_received;
2423 drop += (oq_stats->rx_dropped +
2424 oq_stats->dropped_nodispatch +
2425 oq_stats->dropped_toomany +
2426 oq_stats->dropped_nomem);
2427 bytes += oq_stats->rx_bytes_received;
2428 }
2429
2430 stats->rx_bytes = bytes;
2431 stats->rx_packets = pkts;
2432 stats->rx_dropped = drop;
2433
2434 return stats;
2435}
2436
2437/**
2438 * \brief Net device change_mtu
2439 * @param netdev network device
2440 */
2441static int liquidio_change_mtu(struct net_device *netdev, int new_mtu)
2442{
2443 struct lio *lio = GET_LIO(netdev);
2444 struct octeon_device *oct = lio->oct_dev;
2445 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002446 int ret = 0;
2447
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002448 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2449
2450 nctrl.ncmd.u64 = 0;
2451 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MTU;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002452 nctrl.ncmd.s.param1 = new_mtu;
2453 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002454 nctrl.wait_time = 100;
2455 nctrl.netpndev = (u64)netdev;
2456 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2457
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002458 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002459 if (ret < 0) {
2460 dev_err(&oct->pci_dev->dev, "Failed to set MTU\n");
2461 return -1;
2462 }
2463
2464 lio->mtu = new_mtu;
2465
2466 return 0;
2467}
2468
2469/**
2470 * \brief Handler for SIOCSHWTSTAMP ioctl
2471 * @param netdev network device
2472 * @param ifr interface request
2473 * @param cmd command
2474 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002475static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002476{
2477 struct hwtstamp_config conf;
2478 struct lio *lio = GET_LIO(netdev);
2479
2480 if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf)))
2481 return -EFAULT;
2482
2483 if (conf.flags)
2484 return -EINVAL;
2485
2486 switch (conf.tx_type) {
2487 case HWTSTAMP_TX_ON:
2488 case HWTSTAMP_TX_OFF:
2489 break;
2490 default:
2491 return -ERANGE;
2492 }
2493
2494 switch (conf.rx_filter) {
2495 case HWTSTAMP_FILTER_NONE:
2496 break;
2497 case HWTSTAMP_FILTER_ALL:
2498 case HWTSTAMP_FILTER_SOME:
2499 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2500 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2501 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2502 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2503 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2504 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2505 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2506 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2507 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2508 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2509 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2510 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Miroslav Lichvare3412572017-05-19 17:52:36 +02002511 case HWTSTAMP_FILTER_NTP_ALL:
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002512 conf.rx_filter = HWTSTAMP_FILTER_ALL;
2513 break;
2514 default:
2515 return -ERANGE;
2516 }
2517
2518 if (conf.rx_filter == HWTSTAMP_FILTER_ALL)
2519 ifstate_set(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
2520
2521 else
2522 ifstate_reset(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
2523
2524 return copy_to_user(ifr->ifr_data, &conf, sizeof(conf)) ? -EFAULT : 0;
2525}
2526
2527/**
2528 * \brief ioctl handler
2529 * @param netdev network device
2530 * @param ifr interface request
2531 * @param cmd command
2532 */
2533static int liquidio_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2534{
Prasad Kanneganti9feb16a2017-01-03 11:27:33 -08002535 struct lio *lio = GET_LIO(netdev);
2536
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002537 switch (cmd) {
2538 case SIOCSHWTSTAMP:
Intiyaz Bashaaa69ff92017-08-11 11:22:09 -07002539 if (lio->oct_dev->ptp_enable)
Prasad Kanneganti9feb16a2017-01-03 11:27:33 -08002540 return hwtstamp_ioctl(netdev, ifr);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002541 default:
2542 return -EOPNOTSUPP;
2543 }
2544}
2545
2546/**
2547 * \brief handle a Tx timestamp response
2548 * @param status response status
2549 * @param buf pointer to skb
2550 */
2551static void handle_timestamp(struct octeon_device *oct,
2552 u32 status,
2553 void *buf)
2554{
2555 struct octnet_buf_free_info *finfo;
2556 struct octeon_soft_command *sc;
2557 struct oct_timestamp_resp *resp;
2558 struct lio *lio;
2559 struct sk_buff *skb = (struct sk_buff *)buf;
2560
2561 finfo = (struct octnet_buf_free_info *)skb->cb;
2562 lio = finfo->lio;
2563 sc = finfo->sc;
2564 oct = lio->oct_dev;
2565 resp = (struct oct_timestamp_resp *)sc->virtrptr;
2566
2567 if (status != OCTEON_REQUEST_DONE) {
2568 dev_err(&oct->pci_dev->dev, "Tx timestamp instruction failed. Status: %llx\n",
2569 CVM_CAST64(status));
2570 resp->timestamp = 0;
2571 }
2572
2573 octeon_swap_8B_data(&resp->timestamp, 1);
2574
Colin Ian King19a6d152016-02-05 16:30:39 +00002575 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) != 0)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002576 struct skb_shared_hwtstamps ts;
2577 u64 ns = resp->timestamp;
2578
2579 netif_info(lio, tx_done, lio->netdev,
2580 "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n",
2581 skb, (unsigned long long)ns);
2582 ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust);
2583 skb_tstamp_tx(skb, &ts);
2584 }
2585
2586 octeon_free_soft_command(oct, sc);
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07002587 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002588}
2589
2590/* \brief Send a data packet that will be timestamped
2591 * @param oct octeon device
2592 * @param ndata pointer to network data
2593 * @param finfo pointer to private network data
2594 */
2595static inline int send_nic_timestamp_pkt(struct octeon_device *oct,
2596 struct octnic_data_pkt *ndata,
Raghu Vatsavayi32581242016-08-31 11:03:20 -07002597 struct octnet_buf_free_info *finfo)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002598{
2599 int retval;
2600 struct octeon_soft_command *sc;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002601 struct lio *lio;
2602 int ring_doorbell;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002603 u32 len;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002604
2605 lio = finfo->lio;
2606
2607 sc = octeon_alloc_soft_command_resp(oct, &ndata->cmd,
2608 sizeof(struct oct_timestamp_resp));
2609 finfo->sc = sc;
2610
2611 if (!sc) {
2612 dev_err(&oct->pci_dev->dev, "No memory for timestamped data packet\n");
2613 return IQ_SEND_FAILED;
2614 }
2615
2616 if (ndata->reqtype == REQTYPE_NORESP_NET)
2617 ndata->reqtype = REQTYPE_RESP_NET;
2618 else if (ndata->reqtype == REQTYPE_NORESP_NET_SG)
2619 ndata->reqtype = REQTYPE_RESP_NET_SG;
2620
2621 sc->callback = handle_timestamp;
2622 sc->callback_arg = finfo->skb;
2623 sc->iq_no = ndata->q_no;
2624
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002625 if (OCTEON_CN23XX_PF(oct))
2626 len = (u32)((struct octeon_instr_ih3 *)
2627 (&sc->cmd.cmd3.ih3))->dlengsz;
2628 else
2629 len = (u32)((struct octeon_instr_ih2 *)
2630 (&sc->cmd.cmd2.ih2))->dlengsz;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002631
Raghu Vatsavayi32581242016-08-31 11:03:20 -07002632 ring_doorbell = 1;
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002633
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002634 retval = octeon_send_command(oct, sc->iq_no, ring_doorbell, &sc->cmd,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002635 sc, len, ndata->reqtype);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002636
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -07002637 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002638 dev_err(&oct->pci_dev->dev, "timestamp data packet failed status: %x\n",
2639 retval);
2640 octeon_free_soft_command(oct, sc);
2641 } else {
2642 netif_info(lio, tx_queued, lio->netdev, "Queued timestamp packet\n");
2643 }
2644
2645 return retval;
2646}
2647
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002648/** \brief Transmit networks packets to the Octeon interface
2649 * @param skbuff skbuff struct to be passed to network layer.
2650 * @param netdev pointer to network device
2651 * @returns whether the packet was transmitted to the device okay or not
2652 * (NETDEV_TX_OK or NETDEV_TX_BUSY)
2653 */
2654static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
2655{
2656 struct lio *lio;
2657 struct octnet_buf_free_info *finfo;
2658 union octnic_cmd_setup cmdsetup;
2659 struct octnic_data_pkt ndata;
2660 struct octeon_device *oct;
2661 struct oct_iq_stats *stats;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002662 struct octeon_instr_irh *irh;
2663 union tx_info *tx_info;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002664 int status = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002665 int q_idx = 0, iq_no = 0;
Raghu Vatsavayi32581242016-08-31 11:03:20 -07002666 int j;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002667 u64 dptr = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002668 u32 tag = 0;
2669
2670 lio = GET_LIO(netdev);
2671 oct = lio->oct_dev;
2672
2673 if (netif_is_multiqueue(netdev)) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002674 q_idx = skb->queue_mapping;
2675 q_idx = (q_idx % (lio->linfo.num_txpciq));
2676 tag = q_idx;
2677 iq_no = lio->linfo.txpciq[q_idx].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002678 } else {
2679 iq_no = lio->txq;
2680 }
2681
2682 stats = &oct->instr_queue[iq_no]->stats;
2683
2684 /* Check for all conditions in which the current packet cannot be
2685 * transmitted.
2686 */
2687 if (!(atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) ||
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002688 (!lio->linfo.link.s.link_up) ||
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002689 (skb->len <= 0)) {
2690 netif_info(lio, tx_err, lio->netdev,
2691 "Transmit failed link_status : %d\n",
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002692 lio->linfo.link.s.link_up);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002693 goto lio_xmit_failed;
2694 }
2695
2696 /* Use space in skb->cb to store info used to unmap and
2697 * free the buffers.
2698 */
2699 finfo = (struct octnet_buf_free_info *)skb->cb;
2700 finfo->lio = lio;
2701 finfo->skb = skb;
2702 finfo->sc = NULL;
2703
2704 /* Prepare the attributes for the data to be passed to OSI. */
2705 memset(&ndata, 0, sizeof(struct octnic_data_pkt));
2706
2707 ndata.buf = (void *)finfo;
2708
2709 ndata.q_no = iq_no;
2710
2711 if (netif_is_multiqueue(netdev)) {
2712 if (octnet_iq_is_full(oct, ndata.q_no)) {
2713 /* defer sending if queue is full */
2714 netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
2715 ndata.q_no);
2716 stats->tx_iq_busy++;
2717 return NETDEV_TX_BUSY;
2718 }
2719 } else {
2720 if (octnet_iq_is_full(oct, lio->txq)) {
2721 /* defer sending if queue is full */
2722 stats->tx_iq_busy++;
2723 netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07002724 lio->txq);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002725 return NETDEV_TX_BUSY;
2726 }
2727 }
2728 /* pr_info(" XMIT - valid Qs: %d, 1st Q no: %d, cpu: %d, q_no:%d\n",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07002729 * lio->linfo.num_txpciq, lio->txq, cpu, ndata.q_no);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002730 */
2731
2732 ndata.datasize = skb->len;
2733
2734 cmdsetup.u64 = 0;
Raghu Vatsavayi7275ebf2016-06-14 16:54:49 -07002735 cmdsetup.s.iq_no = iq_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002736
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002737 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2738 if (skb->encapsulation) {
2739 cmdsetup.s.tnl_csum = 1;
2740 stats->tx_vxlan++;
2741 } else {
2742 cmdsetup.s.transport_csum = 1;
2743 }
2744 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002745 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
2746 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
2747 cmdsetup.s.timestamp = 1;
2748 }
2749
2750 if (skb_shinfo(skb)->nr_frags == 0) {
2751 cmdsetup.s.u.datasize = skb->len;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002752 octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07002753
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002754 /* Offload checksum calculation for TCP/UDP packets */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002755 dptr = dma_map_single(&oct->pci_dev->dev,
2756 skb->data,
2757 skb->len,
2758 DMA_TO_DEVICE);
2759 if (dma_mapping_error(&oct->pci_dev->dev, dptr)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002760 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 1\n",
2761 __func__);
2762 return NETDEV_TX_BUSY;
2763 }
2764
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002765 if (OCTEON_CN23XX_PF(oct))
2766 ndata.cmd.cmd3.dptr = dptr;
2767 else
2768 ndata.cmd.cmd2.dptr = dptr;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002769 finfo->dptr = dptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002770 ndata.reqtype = REQTYPE_NORESP_NET;
2771
2772 } else {
2773 int i, frags;
2774 struct skb_frag_struct *frag;
2775 struct octnic_gather *g;
2776
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002777 spin_lock(&lio->glist_lock[q_idx]);
2778 g = (struct octnic_gather *)
2779 list_delete_head(&lio->glist[q_idx]);
2780 spin_unlock(&lio->glist_lock[q_idx]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002781
2782 if (!g) {
2783 netif_info(lio, tx_err, lio->netdev,
2784 "Transmit scatter gather: glist null!\n");
2785 goto lio_xmit_failed;
2786 }
2787
2788 cmdsetup.s.gather = 1;
2789 cmdsetup.s.u.gatherptrs = (skb_shinfo(skb)->nr_frags + 1);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002790 octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002791
2792 memset(g->sg, 0, g->sg_size);
2793
2794 g->sg[0].ptr[0] = dma_map_single(&oct->pci_dev->dev,
2795 skb->data,
2796 (skb->len - skb->data_len),
2797 DMA_TO_DEVICE);
2798 if (dma_mapping_error(&oct->pci_dev->dev, g->sg[0].ptr[0])) {
2799 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 2\n",
2800 __func__);
2801 return NETDEV_TX_BUSY;
2802 }
2803 add_sg_size(&g->sg[0], (skb->len - skb->data_len), 0);
2804
2805 frags = skb_shinfo(skb)->nr_frags;
2806 i = 1;
2807 while (frags--) {
2808 frag = &skb_shinfo(skb)->frags[i - 1];
2809
2810 g->sg[(i >> 2)].ptr[(i & 3)] =
2811 dma_map_page(&oct->pci_dev->dev,
2812 frag->page.p,
2813 frag->page_offset,
2814 frag->size,
2815 DMA_TO_DEVICE);
2816
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002817 if (dma_mapping_error(&oct->pci_dev->dev,
2818 g->sg[i >> 2].ptr[i & 3])) {
2819 dma_unmap_single(&oct->pci_dev->dev,
2820 g->sg[0].ptr[0],
2821 skb->len - skb->data_len,
2822 DMA_TO_DEVICE);
2823 for (j = 1; j < i; j++) {
2824 frag = &skb_shinfo(skb)->frags[j - 1];
2825 dma_unmap_page(&oct->pci_dev->dev,
2826 g->sg[j >> 2].ptr[j & 3],
2827 frag->size,
2828 DMA_TO_DEVICE);
2829 }
2830 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 3\n",
2831 __func__);
2832 return NETDEV_TX_BUSY;
2833 }
2834
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002835 add_sg_size(&g->sg[(i >> 2)], frag->size, (i & 3));
2836 i++;
2837 }
2838
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002839 dptr = g->sg_dma_ptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002840
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002841 if (OCTEON_CN23XX_PF(oct))
2842 ndata.cmd.cmd3.dptr = dptr;
2843 else
2844 ndata.cmd.cmd2.dptr = dptr;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002845 finfo->dptr = dptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002846 finfo->g = g;
2847
2848 ndata.reqtype = REQTYPE_NORESP_NET_SG;
2849 }
2850
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002851 if (OCTEON_CN23XX_PF(oct)) {
2852 irh = (struct octeon_instr_irh *)&ndata.cmd.cmd3.irh;
2853 tx_info = (union tx_info *)&ndata.cmd.cmd3.ossp[0];
2854 } else {
2855 irh = (struct octeon_instr_irh *)&ndata.cmd.cmd2.irh;
2856 tx_info = (union tx_info *)&ndata.cmd.cmd2.ossp[0];
2857 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002858
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002859 if (skb_shinfo(skb)->gso_size) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002860 tx_info->s.gso_size = skb_shinfo(skb)->gso_size;
2861 tx_info->s.gso_segs = skb_shinfo(skb)->gso_segs;
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07002862 stats->tx_gso++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002863 }
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07002864
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07002865 /* HW insert VLAN tag */
2866 if (skb_vlan_tag_present(skb)) {
2867 irh->priority = skb_vlan_tag_get(skb) >> 13;
2868 irh->vlan = skb_vlan_tag_get(skb) & 0xfff;
2869 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002870
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002871 if (unlikely(cmdsetup.s.timestamp))
Raghu Vatsavayi32581242016-08-31 11:03:20 -07002872 status = send_nic_timestamp_pkt(oct, &ndata, finfo);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002873 else
Raghu Vatsavayi32581242016-08-31 11:03:20 -07002874 status = octnet_send_nic_data_pkt(oct, &ndata);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002875 if (status == IQ_SEND_FAILED)
2876 goto lio_xmit_failed;
2877
2878 netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n");
2879
2880 if (status == IQ_SEND_STOP)
2881 stop_q(lio->netdev, q_idx);
2882
Florian Westphal860e9532016-05-03 16:33:13 +02002883 netif_trans_update(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002884
Satanand Burla80c8eae2017-01-26 11:52:35 -08002885 if (tx_info->s.gso_segs)
2886 stats->tx_done += tx_info->s.gso_segs;
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07002887 else
2888 stats->tx_done++;
Satanand Burla80c8eae2017-01-26 11:52:35 -08002889 stats->tx_tot_bytes += ndata.datasize;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002890
2891 return NETDEV_TX_OK;
2892
2893lio_xmit_failed:
2894 stats->tx_dropped++;
2895 netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n",
2896 iq_no, stats->tx_dropped);
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002897 if (dptr)
2898 dma_unmap_single(&oct->pci_dev->dev, dptr,
2899 ndata.datasize, DMA_TO_DEVICE);
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07002900 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002901 return NETDEV_TX_OK;
2902}
2903
2904/** \brief Network device Tx timeout
2905 * @param netdev pointer to network device
2906 */
2907static void liquidio_tx_timeout(struct net_device *netdev)
2908{
2909 struct lio *lio;
2910
2911 lio = GET_LIO(netdev);
2912
2913 netif_info(lio, tx_err, lio->netdev,
2914 "Transmit timeout tx_dropped:%ld, waking up queues now!!\n",
2915 netdev->stats.tx_dropped);
Florian Westphal860e9532016-05-03 16:33:13 +02002916 netif_trans_update(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002917 txqs_wake(netdev);
2918}
2919
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07002920static int liquidio_vlan_rx_add_vid(struct net_device *netdev,
2921 __be16 proto __attribute__((unused)),
2922 u16 vid)
2923{
2924 struct lio *lio = GET_LIO(netdev);
2925 struct octeon_device *oct = lio->oct_dev;
2926 struct octnic_ctrl_pkt nctrl;
2927 int ret = 0;
2928
2929 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2930
2931 nctrl.ncmd.u64 = 0;
2932 nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER;
2933 nctrl.ncmd.s.param1 = vid;
2934 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
2935 nctrl.wait_time = 100;
2936 nctrl.netpndev = (u64)netdev;
2937 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2938
2939 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
2940 if (ret < 0) {
2941 dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
2942 ret);
2943 }
2944
2945 return ret;
2946}
2947
2948static int liquidio_vlan_rx_kill_vid(struct net_device *netdev,
2949 __be16 proto __attribute__((unused)),
2950 u16 vid)
2951{
2952 struct lio *lio = GET_LIO(netdev);
2953 struct octeon_device *oct = lio->oct_dev;
2954 struct octnic_ctrl_pkt nctrl;
2955 int ret = 0;
2956
2957 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2958
2959 nctrl.ncmd.u64 = 0;
2960 nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER;
2961 nctrl.ncmd.s.param1 = vid;
2962 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
2963 nctrl.wait_time = 100;
2964 nctrl.netpndev = (u64)netdev;
2965 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2966
2967 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
2968 if (ret < 0) {
2969 dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
2970 ret);
2971 }
2972 return ret;
2973}
2974
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002975/** Sending command to enable/disable RX checksum offload
2976 * @param netdev pointer to network device
2977 * @param command OCTNET_CMD_TNL_RX_CSUM_CTL
2978 * @param rx_cmd_bit OCTNET_CMD_RXCSUM_ENABLE/
2979 * OCTNET_CMD_RXCSUM_DISABLE
2980 * @returns SUCCESS or FAILURE
2981 */
Nicholas Mc Guirec41419b2016-08-22 17:52:00 +02002982static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
2983 u8 rx_cmd)
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002984{
2985 struct lio *lio = GET_LIO(netdev);
2986 struct octeon_device *oct = lio->oct_dev;
2987 struct octnic_ctrl_pkt nctrl;
2988 int ret = 0;
2989
Felix Manlunas0c264582017-04-06 19:22:22 -07002990 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2991
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002992 nctrl.ncmd.u64 = 0;
2993 nctrl.ncmd.s.cmd = command;
2994 nctrl.ncmd.s.param1 = rx_cmd;
2995 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
2996 nctrl.wait_time = 100;
2997 nctrl.netpndev = (u64)netdev;
2998 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2999
3000 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
3001 if (ret < 0) {
3002 dev_err(&oct->pci_dev->dev,
3003 "DEVFLAGS RXCSUM change failed in core(ret:0x%x)\n",
3004 ret);
3005 }
3006 return ret;
3007}
3008
3009/** Sending command to add/delete VxLAN UDP port to firmware
3010 * @param netdev pointer to network device
3011 * @param command OCTNET_CMD_VXLAN_PORT_CONFIG
3012 * @param vxlan_port VxLAN port to be added or deleted
3013 * @param vxlan_cmd_bit OCTNET_CMD_VXLAN_PORT_ADD,
3014 * OCTNET_CMD_VXLAN_PORT_DEL
3015 * @returns SUCCESS or FAILURE
3016 */
3017static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
3018 u16 vxlan_port, u8 vxlan_cmd_bit)
3019{
3020 struct lio *lio = GET_LIO(netdev);
3021 struct octeon_device *oct = lio->oct_dev;
3022 struct octnic_ctrl_pkt nctrl;
3023 int ret = 0;
3024
Felix Manlunas0c264582017-04-06 19:22:22 -07003025 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3026
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003027 nctrl.ncmd.u64 = 0;
3028 nctrl.ncmd.s.cmd = command;
3029 nctrl.ncmd.s.more = vxlan_cmd_bit;
3030 nctrl.ncmd.s.param1 = vxlan_port;
3031 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3032 nctrl.wait_time = 100;
3033 nctrl.netpndev = (u64)netdev;
3034 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
3035
3036 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
3037 if (ret < 0) {
3038 dev_err(&oct->pci_dev->dev,
3039 "VxLAN port add/delete failed in core (ret:0x%x)\n",
3040 ret);
3041 }
3042 return ret;
3043}
3044
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003045/** \brief Net device fix features
3046 * @param netdev pointer to network device
3047 * @param request features requested
3048 * @returns updated features list
3049 */
3050static netdev_features_t liquidio_fix_features(struct net_device *netdev,
3051 netdev_features_t request)
3052{
3053 struct lio *lio = netdev_priv(netdev);
3054
3055 if ((request & NETIF_F_RXCSUM) &&
3056 !(lio->dev_capability & NETIF_F_RXCSUM))
3057 request &= ~NETIF_F_RXCSUM;
3058
3059 if ((request & NETIF_F_HW_CSUM) &&
3060 !(lio->dev_capability & NETIF_F_HW_CSUM))
3061 request &= ~NETIF_F_HW_CSUM;
3062
3063 if ((request & NETIF_F_TSO) && !(lio->dev_capability & NETIF_F_TSO))
3064 request &= ~NETIF_F_TSO;
3065
3066 if ((request & NETIF_F_TSO6) && !(lio->dev_capability & NETIF_F_TSO6))
3067 request &= ~NETIF_F_TSO6;
3068
3069 if ((request & NETIF_F_LRO) && !(lio->dev_capability & NETIF_F_LRO))
3070 request &= ~NETIF_F_LRO;
3071
3072 /*Disable LRO if RXCSUM is off */
3073 if (!(request & NETIF_F_RXCSUM) && (netdev->features & NETIF_F_LRO) &&
3074 (lio->dev_capability & NETIF_F_LRO))
3075 request &= ~NETIF_F_LRO;
3076
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003077 if ((request & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3078 !(lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER))
3079 request &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
3080
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003081 return request;
3082}
3083
3084/** \brief Net device set features
3085 * @param netdev pointer to network device
3086 * @param features features to enable/disable
3087 */
3088static int liquidio_set_features(struct net_device *netdev,
3089 netdev_features_t features)
3090{
3091 struct lio *lio = netdev_priv(netdev);
3092
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003093 if ((features & NETIF_F_LRO) &&
3094 (lio->dev_capability & NETIF_F_LRO) &&
3095 !(netdev->features & NETIF_F_LRO))
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003096 liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
3097 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003098 else if (!(features & NETIF_F_LRO) &&
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003099 (lio->dev_capability & NETIF_F_LRO) &&
3100 (netdev->features & NETIF_F_LRO))
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003101 liquidio_set_feature(netdev, OCTNET_CMD_LRO_DISABLE,
3102 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003103
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003104 /* Sending command to firmware to enable/disable RX checksum
3105 * offload settings using ethtool
3106 */
3107 if (!(netdev->features & NETIF_F_RXCSUM) &&
3108 (lio->enc_dev_capability & NETIF_F_RXCSUM) &&
3109 (features & NETIF_F_RXCSUM))
3110 liquidio_set_rxcsum_command(netdev,
3111 OCTNET_CMD_TNL_RX_CSUM_CTL,
3112 OCTNET_CMD_RXCSUM_ENABLE);
3113 else if ((netdev->features & NETIF_F_RXCSUM) &&
3114 (lio->enc_dev_capability & NETIF_F_RXCSUM) &&
3115 !(features & NETIF_F_RXCSUM))
3116 liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
3117 OCTNET_CMD_RXCSUM_DISABLE);
3118
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003119 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3120 (lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3121 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3122 liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL,
3123 OCTNET_CMD_VLAN_FILTER_ENABLE);
3124 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3125 (lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3126 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3127 liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL,
3128 OCTNET_CMD_VLAN_FILTER_DISABLE);
3129
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003130 return 0;
3131}
3132
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003133static void liquidio_add_vxlan_port(struct net_device *netdev,
3134 struct udp_tunnel_info *ti)
3135{
3136 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
3137 return;
3138
3139 liquidio_vxlan_port_command(netdev,
3140 OCTNET_CMD_VXLAN_PORT_CONFIG,
3141 htons(ti->port),
3142 OCTNET_CMD_VXLAN_PORT_ADD);
3143}
3144
3145static void liquidio_del_vxlan_port(struct net_device *netdev,
3146 struct udp_tunnel_info *ti)
3147{
3148 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
3149 return;
3150
3151 liquidio_vxlan_port_command(netdev,
3152 OCTNET_CMD_VXLAN_PORT_CONFIG,
3153 htons(ti->port),
3154 OCTNET_CMD_VXLAN_PORT_DEL);
3155}
3156
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003157static int __liquidio_set_vf_mac(struct net_device *netdev, int vfidx,
3158 u8 *mac, bool is_admin_assigned)
3159{
3160 struct lio *lio = GET_LIO(netdev);
3161 struct octeon_device *oct = lio->oct_dev;
3162 struct octnic_ctrl_pkt nctrl;
3163
3164 if (!is_valid_ether_addr(mac))
3165 return -EINVAL;
3166
3167 if (vfidx < 0 || vfidx >= oct->sriov_info.max_vfs)
3168 return -EINVAL;
3169
3170 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3171
3172 nctrl.ncmd.u64 = 0;
3173 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
3174 /* vfidx is 0 based, but vf_num (param1) is 1 based */
3175 nctrl.ncmd.s.param1 = vfidx + 1;
3176 nctrl.ncmd.s.param2 = (is_admin_assigned ? 1 : 0);
3177 nctrl.ncmd.s.more = 1;
3178 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Rick Farrington9549c6c2017-03-17 15:43:26 -07003179 nctrl.netpndev = (u64)netdev;
3180 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003181 nctrl.wait_time = LIO_CMD_WAIT_TM;
3182
3183 nctrl.udd[0] = 0;
3184 /* The MAC Address is presented in network byte order. */
3185 ether_addr_copy((u8 *)&nctrl.udd[0] + 2, mac);
3186
3187 oct->sriov_info.vf_macaddr[vfidx] = nctrl.udd[0];
3188
3189 octnet_send_nic_ctrl_pkt(oct, &nctrl);
3190
3191 return 0;
3192}
3193
3194static int liquidio_set_vf_mac(struct net_device *netdev, int vfidx, u8 *mac)
3195{
3196 struct lio *lio = GET_LIO(netdev);
3197 struct octeon_device *oct = lio->oct_dev;
3198 int retval;
3199
Felix Manlunas0d9a5992017-05-16 11:28:00 -07003200 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3201 return -EINVAL;
3202
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003203 retval = __liquidio_set_vf_mac(netdev, vfidx, mac, true);
3204 if (!retval)
3205 cn23xx_tell_vf_its_macaddr_changed(oct, vfidx, mac);
3206
3207 return retval;
3208}
3209
3210static int liquidio_set_vf_vlan(struct net_device *netdev, int vfidx,
3211 u16 vlan, u8 qos, __be16 vlan_proto)
3212{
3213 struct lio *lio = GET_LIO(netdev);
3214 struct octeon_device *oct = lio->oct_dev;
3215 struct octnic_ctrl_pkt nctrl;
3216 u16 vlantci;
3217
3218 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3219 return -EINVAL;
3220
3221 if (vlan_proto != htons(ETH_P_8021Q))
3222 return -EPROTONOSUPPORT;
3223
3224 if (vlan >= VLAN_N_VID || qos > 7)
3225 return -EINVAL;
3226
3227 if (vlan)
3228 vlantci = vlan | (u16)qos << VLAN_PRIO_SHIFT;
3229 else
3230 vlantci = 0;
3231
3232 if (oct->sriov_info.vf_vlantci[vfidx] == vlantci)
3233 return 0;
3234
3235 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3236
3237 if (vlan)
3238 nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER;
3239 else
3240 nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER;
3241
3242 nctrl.ncmd.s.param1 = vlantci;
3243 nctrl.ncmd.s.param2 =
3244 vfidx + 1; /* vfidx is 0 based, but vf_num (param2) is 1 based */
3245 nctrl.ncmd.s.more = 0;
3246 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3247 nctrl.cb_fn = 0;
3248 nctrl.wait_time = LIO_CMD_WAIT_TM;
3249
3250 octnet_send_nic_ctrl_pkt(oct, &nctrl);
3251
3252 oct->sriov_info.vf_vlantci[vfidx] = vlantci;
3253
3254 return 0;
3255}
3256
3257static int liquidio_get_vf_config(struct net_device *netdev, int vfidx,
3258 struct ifla_vf_info *ivi)
3259{
3260 struct lio *lio = GET_LIO(netdev);
3261 struct octeon_device *oct = lio->oct_dev;
3262 u8 *macaddr;
3263
3264 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3265 return -EINVAL;
3266
3267 ivi->vf = vfidx;
3268 macaddr = 2 + (u8 *)&oct->sriov_info.vf_macaddr[vfidx];
3269 ether_addr_copy(&ivi->mac[0], macaddr);
3270 ivi->vlan = oct->sriov_info.vf_vlantci[vfidx] & VLAN_VID_MASK;
3271 ivi->qos = oct->sriov_info.vf_vlantci[vfidx] >> VLAN_PRIO_SHIFT;
3272 ivi->linkstate = oct->sriov_info.vf_linkstate[vfidx];
3273 return 0;
3274}
3275
3276static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
3277 int linkstate)
3278{
3279 struct lio *lio = GET_LIO(netdev);
3280 struct octeon_device *oct = lio->oct_dev;
3281 struct octnic_ctrl_pkt nctrl;
3282
3283 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3284 return -EINVAL;
3285
3286 if (oct->sriov_info.vf_linkstate[vfidx] == linkstate)
3287 return 0;
3288
3289 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3290 nctrl.ncmd.s.cmd = OCTNET_CMD_SET_VF_LINKSTATE;
3291 nctrl.ncmd.s.param1 =
3292 vfidx + 1; /* vfidx is 0 based, but vf_num (param1) is 1 based */
3293 nctrl.ncmd.s.param2 = linkstate;
3294 nctrl.ncmd.s.more = 0;
3295 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3296 nctrl.cb_fn = 0;
3297 nctrl.wait_time = LIO_CMD_WAIT_TM;
3298
3299 octnet_send_nic_ctrl_pkt(oct, &nctrl);
3300
3301 oct->sriov_info.vf_linkstate[vfidx] = linkstate;
3302
3303 return 0;
3304}
3305
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08003306static const struct net_device_ops lionetdevops = {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003307 .ndo_open = liquidio_open,
3308 .ndo_stop = liquidio_stop,
3309 .ndo_start_xmit = liquidio_xmit,
3310 .ndo_get_stats = liquidio_get_stats,
3311 .ndo_set_mac_address = liquidio_set_mac,
3312 .ndo_set_rx_mode = liquidio_set_mcast_list,
3313 .ndo_tx_timeout = liquidio_tx_timeout,
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003314
3315 .ndo_vlan_rx_add_vid = liquidio_vlan_rx_add_vid,
3316 .ndo_vlan_rx_kill_vid = liquidio_vlan_rx_kill_vid,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003317 .ndo_change_mtu = liquidio_change_mtu,
3318 .ndo_do_ioctl = liquidio_ioctl,
3319 .ndo_fix_features = liquidio_fix_features,
3320 .ndo_set_features = liquidio_set_features,
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003321 .ndo_udp_tunnel_add = liquidio_add_vxlan_port,
3322 .ndo_udp_tunnel_del = liquidio_del_vxlan_port,
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003323 .ndo_set_vf_mac = liquidio_set_vf_mac,
3324 .ndo_set_vf_vlan = liquidio_set_vf_vlan,
3325 .ndo_get_vf_config = liquidio_get_vf_config,
3326 .ndo_set_vf_link_state = liquidio_set_vf_link_state,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003327};
3328
3329/** \brief Entry point for the liquidio module
3330 */
3331static int __init liquidio_init(void)
3332{
3333 int i;
3334 struct handshake *hs;
3335
3336 init_completion(&first_stage);
3337
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08003338 octeon_init_device_list(OCTEON_CONFIG_TYPE_DEFAULT);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003339
3340 if (liquidio_init_pci())
3341 return -EINVAL;
3342
3343 wait_for_completion_timeout(&first_stage, msecs_to_jiffies(1000));
3344
3345 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
3346 hs = &handshake[i];
3347 if (hs->pci_dev) {
3348 wait_for_completion(&hs->init);
3349 if (!hs->init_ok) {
3350 /* init handshake failed */
3351 dev_err(&hs->pci_dev->dev,
3352 "Failed to init device\n");
3353 liquidio_deinit_pci();
3354 return -EIO;
3355 }
3356 }
3357 }
3358
3359 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
3360 hs = &handshake[i];
3361 if (hs->pci_dev) {
3362 wait_for_completion_timeout(&hs->started,
3363 msecs_to_jiffies(30000));
3364 if (!hs->started_ok) {
3365 /* starter handshake failed */
3366 dev_err(&hs->pci_dev->dev,
3367 "Firmware failed to start\n");
3368 liquidio_deinit_pci();
3369 return -EIO;
3370 }
3371 }
3372 }
3373
3374 return 0;
3375}
3376
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07003377static int lio_nic_info(struct octeon_recv_info *recv_info, void *buf)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003378{
3379 struct octeon_device *oct = (struct octeon_device *)buf;
3380 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003381 int gmxport = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003382 union oct_link_status *ls;
3383 int i;
3384
Prasad Kannegantic4ee5d82017-06-18 05:04:11 -07003385 if (recv_pkt->buffer_size[0] != (sizeof(*ls) + OCT_DROQ_INFO_SIZE)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003386 dev_err(&oct->pci_dev->dev, "Malformed NIC_INFO, len=%d, ifidx=%d\n",
3387 recv_pkt->buffer_size[0],
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003388 recv_pkt->rh.r_nic_info.gmxport);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003389 goto nic_info_err;
3390 }
3391
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003392 gmxport = recv_pkt->rh.r_nic_info.gmxport;
Prasad Kannegantic4ee5d82017-06-18 05:04:11 -07003393 ls = (union oct_link_status *)(get_rbd(recv_pkt->buffer_ptr[0]) +
3394 OCT_DROQ_INFO_SIZE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003395
3396 octeon_swap_8B_data((u64 *)ls, (sizeof(union oct_link_status)) >> 3);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003397 for (i = 0; i < oct->ifcount; i++) {
3398 if (oct->props[i].gmxport == gmxport) {
3399 update_link_status(oct->props[i].netdev, ls);
3400 break;
3401 }
3402 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003403
3404nic_info_err:
3405 for (i = 0; i < recv_pkt->buffer_count; i++)
3406 recv_buffer_free(recv_pkt->buffer_ptr[i]);
3407 octeon_free_recv_info(recv_info);
3408 return 0;
3409}
3410
3411/**
3412 * \brief Setup network interfaces
3413 * @param octeon_dev octeon device
3414 *
3415 * Called during init time for each device. It assumes the NIC
3416 * is already up and running. The link information for each
3417 * interface is passed in link_info.
3418 */
3419static int setup_nic_devices(struct octeon_device *octeon_dev)
3420{
3421 struct lio *lio = NULL;
3422 struct net_device *netdev;
Rick Farringtonb36e4822017-09-22 17:12:47 -07003423 u8 mac[6], i, j, *fw_ver;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003424 struct octeon_soft_command *sc;
3425 struct liquidio_if_cfg_context *ctx;
3426 struct liquidio_if_cfg_resp *resp;
3427 struct octdev_props *props;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003428 int retval, num_iqueues, num_oqueues;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003429 union oct_nic_if_cfg if_cfg;
3430 unsigned int base_queue;
3431 unsigned int gmx_port_id;
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003432 u32 resp_size, ctx_size, data_size;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003433 u32 ifidx_or_pfnum;
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003434 struct lio_version *vdata;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003435
3436 /* This is to handle link status changes */
3437 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
3438 OPCODE_NIC_INFO,
3439 lio_nic_info, octeon_dev);
3440
3441 /* REQTYPE_RESP_NET and REQTYPE_SOFT_COMMAND do not have free functions.
3442 * They are handled directly.
3443 */
3444 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET,
3445 free_netbuf);
3446
3447 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET_SG,
3448 free_netsgbuf);
3449
3450 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_RESP_NET_SG,
3451 free_netsgbuf_with_resp);
3452
3453 for (i = 0; i < octeon_dev->ifcount; i++) {
3454 resp_size = sizeof(struct liquidio_if_cfg_resp);
3455 ctx_size = sizeof(struct liquidio_if_cfg_context);
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003456 data_size = sizeof(struct lio_version);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003457 sc = (struct octeon_soft_command *)
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003458 octeon_alloc_soft_command(octeon_dev, data_size,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003459 resp_size, ctx_size);
3460 resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
3461 ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003462 vdata = (struct lio_version *)sc->virtdptr;
3463
3464 *((u64 *)vdata) = 0;
3465 vdata->major = cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
3466 vdata->minor = cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
3467 vdata->micro = cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003468
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07003469 if (OCTEON_CN23XX_PF(octeon_dev)) {
3470 num_iqueues = octeon_dev->sriov_info.num_pf_rings;
3471 num_oqueues = octeon_dev->sriov_info.num_pf_rings;
3472 base_queue = octeon_dev->sriov_info.pf_srn;
3473
3474 gmx_port_id = octeon_dev->pf_num;
3475 ifidx_or_pfnum = octeon_dev->pf_num;
3476 } else {
3477 num_iqueues = CFG_GET_NUM_TXQS_NIC_IF(
3478 octeon_get_conf(octeon_dev), i);
3479 num_oqueues = CFG_GET_NUM_RXQS_NIC_IF(
3480 octeon_get_conf(octeon_dev), i);
3481 base_queue = CFG_GET_BASE_QUE_NIC_IF(
3482 octeon_get_conf(octeon_dev), i);
3483 gmx_port_id = CFG_GET_GMXID_NIC_IF(
3484 octeon_get_conf(octeon_dev), i);
3485 ifidx_or_pfnum = i;
3486 }
Raghu Vatsavayi3dcef2c2016-07-03 13:56:51 -07003487
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003488 dev_dbg(&octeon_dev->pci_dev->dev,
3489 "requesting config for interface %d, iqs %d, oqs %d\n",
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003490 ifidx_or_pfnum, num_iqueues, num_oqueues);
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07003491 WRITE_ONCE(ctx->cond, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003492 ctx->octeon_id = lio_get_device_id(octeon_dev);
3493 init_waitqueue_head(&ctx->wc);
3494
3495 if_cfg.u64 = 0;
3496 if_cfg.s.num_iqueues = num_iqueues;
3497 if_cfg.s.num_oqueues = num_oqueues;
3498 if_cfg.s.base_queue = base_queue;
3499 if_cfg.s.gmx_port_id = gmx_port_id;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003500
3501 sc->iq_no = 0;
3502
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003503 octeon_prepare_soft_command(octeon_dev, sc, OPCODE_NIC,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003504 OPCODE_NIC_IF_CFG, 0,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003505 if_cfg.u64, 0);
3506
3507 sc->callback = if_cfg_callback;
3508 sc->callback_arg = sc;
Raghu Vatsavayi55893a62016-07-03 13:56:50 -07003509 sc->wait_time = 3000;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003510
3511 retval = octeon_send_soft_command(octeon_dev, sc);
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -07003512 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003513 dev_err(&octeon_dev->pci_dev->dev,
3514 "iq/oq config failed status: %x\n",
3515 retval);
3516 /* Soft instr is freed by driver in case of failure. */
3517 goto setup_nic_dev_fail;
3518 }
3519
3520 /* Sleep on a wait queue till the cond flag indicates that the
3521 * response arrived or timed-out.
3522 */
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07003523 if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
3524 dev_err(&octeon_dev->pci_dev->dev, "Wait interrupted\n");
3525 goto setup_nic_wait_intr;
3526 }
3527
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003528 retval = resp->status;
3529 if (retval) {
3530 dev_err(&octeon_dev->pci_dev->dev, "iq/oq config failed\n");
3531 goto setup_nic_dev_fail;
3532 }
3533
Rick Farringtonb36e4822017-09-22 17:12:47 -07003534 /* Verify f/w version (in case of 'auto' loading from flash) */
3535 fw_ver = octeon_dev->fw_info.liquidio_firmware_version;
3536 if (memcmp(LIQUIDIO_BASE_VERSION,
3537 fw_ver,
3538 strlen(LIQUIDIO_BASE_VERSION))) {
3539 dev_err(&octeon_dev->pci_dev->dev,
3540 "Unmatched firmware version. Expected %s.x, got %s.\n",
3541 LIQUIDIO_BASE_VERSION, fw_ver);
3542 goto setup_nic_dev_fail;
3543 } else if (atomic_read(octeon_dev->adapter_fw_state) ==
3544 FW_IS_PRELOADED) {
3545 dev_info(&octeon_dev->pci_dev->dev,
3546 "Using auto-loaded firmware version %s.\n",
3547 fw_ver);
3548 }
3549
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003550 octeon_swap_8B_data((u64 *)(&resp->cfg_info),
3551 (sizeof(struct liquidio_if_cfg_info)) >> 3);
3552
3553 num_iqueues = hweight64(resp->cfg_info.iqmask);
3554 num_oqueues = hweight64(resp->cfg_info.oqmask);
3555
3556 if (!(num_iqueues) || !(num_oqueues)) {
3557 dev_err(&octeon_dev->pci_dev->dev,
3558 "Got bad iqueues (%016llx) or oqueues (%016llx) from firmware.\n",
3559 resp->cfg_info.iqmask,
3560 resp->cfg_info.oqmask);
3561 goto setup_nic_dev_fail;
3562 }
3563 dev_dbg(&octeon_dev->pci_dev->dev,
3564 "interface %d, iqmask %016llx, oqmask %016llx, numiqueues %d, numoqueues %d\n",
3565 i, resp->cfg_info.iqmask, resp->cfg_info.oqmask,
3566 num_iqueues, num_oqueues);
3567 netdev = alloc_etherdev_mq(LIO_SIZE, num_iqueues);
3568
3569 if (!netdev) {
3570 dev_err(&octeon_dev->pci_dev->dev, "Device allocation failed\n");
3571 goto setup_nic_dev_fail;
3572 }
3573
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003574 SET_NETDEV_DEV(netdev, &octeon_dev->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003575
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003576 /* Associate the routines that will handle different
3577 * netdev tasks.
3578 */
3579 netdev->netdev_ops = &lionetdevops;
3580
3581 lio = GET_LIO(netdev);
3582
3583 memset(lio, 0, sizeof(struct lio));
3584
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003585 lio->ifidx = ifidx_or_pfnum;
3586
3587 props = &octeon_dev->props[i];
3588 props->gmxport = resp->cfg_info.linfo.gmxport;
3589 props->netdev = netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003590
3591 lio->linfo.num_rxpciq = num_oqueues;
3592 lio->linfo.num_txpciq = num_iqueues;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003593 for (j = 0; j < num_oqueues; j++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003594 lio->linfo.rxpciq[j].u64 =
3595 resp->cfg_info.linfo.rxpciq[j].u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003596 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003597 for (j = 0; j < num_iqueues; j++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003598 lio->linfo.txpciq[j].u64 =
3599 resp->cfg_info.linfo.txpciq[j].u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003600 }
3601 lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
3602 lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
3603 lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
3604
3605 lio->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
3606
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07003607 if (OCTEON_CN23XX_PF(octeon_dev) ||
3608 OCTEON_CN6XXX(octeon_dev)) {
3609 lio->dev_capability = NETIF_F_HIGHDMA
3610 | NETIF_F_IP_CSUM
3611 | NETIF_F_IPV6_CSUM
3612 | NETIF_F_SG | NETIF_F_RXCSUM
3613 | NETIF_F_GRO
3614 | NETIF_F_TSO | NETIF_F_TSO6
3615 | NETIF_F_LRO;
3616 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003617 netif_set_gso_max_size(netdev, OCTNIC_GSO_MAX_SIZE);
3618
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003619 /* Copy of transmit encapsulation capabilities:
3620 * TSO, TSO6, Checksums for this device
3621 */
3622 lio->enc_dev_capability = NETIF_F_IP_CSUM
3623 | NETIF_F_IPV6_CSUM
3624 | NETIF_F_GSO_UDP_TUNNEL
3625 | NETIF_F_HW_CSUM | NETIF_F_SG
3626 | NETIF_F_RXCSUM
3627 | NETIF_F_TSO | NETIF_F_TSO6
3628 | NETIF_F_LRO;
3629
3630 netdev->hw_enc_features = (lio->enc_dev_capability &
3631 ~NETIF_F_LRO);
3632
3633 lio->dev_capability |= NETIF_F_GSO_UDP_TUNNEL;
3634
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003635 netdev->vlan_features = lio->dev_capability;
3636 /* Add any unchangeable hw features */
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003637 lio->dev_capability |= NETIF_F_HW_VLAN_CTAG_FILTER |
3638 NETIF_F_HW_VLAN_CTAG_RX |
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003639 NETIF_F_HW_VLAN_CTAG_TX;
3640
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003641 netdev->features = (lio->dev_capability & ~NETIF_F_LRO);
3642
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003643 netdev->hw_features = lio->dev_capability;
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003644 /*HW_VLAN_RX and HW_VLAN_FILTER is always on*/
3645 netdev->hw_features = netdev->hw_features &
3646 ~NETIF_F_HW_VLAN_CTAG_RX;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003647
Jarod Wilson109cc162016-10-17 15:54:13 -04003648 /* MTU range: 68 - 16000 */
3649 netdev->min_mtu = LIO_MIN_MTU_SIZE;
3650 netdev->max_mtu = LIO_MAX_MTU_SIZE;
3651
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003652 /* Point to the properties for octeon device to which this
3653 * interface belongs.
3654 */
3655 lio->oct_dev = octeon_dev;
3656 lio->octprops = props;
3657 lio->netdev = netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003658
3659 dev_dbg(&octeon_dev->pci_dev->dev,
3660 "if%d gmx: %d hw_addr: 0x%llx\n", i,
3661 lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr));
3662
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003663 for (j = 0; j < octeon_dev->sriov_info.max_vfs; j++) {
3664 u8 vfmac[ETH_ALEN];
3665
3666 random_ether_addr(&vfmac[0]);
3667 if (__liquidio_set_vf_mac(netdev, j,
3668 &vfmac[0], false)) {
3669 dev_err(&octeon_dev->pci_dev->dev,
3670 "Error setting VF%d MAC address\n",
3671 j);
3672 goto setup_nic_dev_fail;
3673 }
3674 }
3675
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003676 /* 64-bit swap required on LE machines */
3677 octeon_swap_8B_data(&lio->linfo.hw_addr, 1);
3678 for (j = 0; j < 6; j++)
3679 mac[j] = *((u8 *)(((u8 *)&lio->linfo.hw_addr) + 2 + j));
3680
3681 /* Copy MAC Address to OS network device structure */
3682
3683 ether_addr_copy(netdev->dev_addr, mac);
3684
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003685 /* By default all interfaces on a single Octeon uses the same
3686 * tx and rx queues
3687 */
3688 lio->txq = lio->linfo.txpciq[0].s.q_no;
3689 lio->rxq = lio->linfo.rxpciq[0].s.q_no;
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07003690 if (liquidio_setup_io_queues(octeon_dev, i,
3691 lio->linfo.num_txpciq,
3692 lio->linfo.num_rxpciq)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003693 dev_err(&octeon_dev->pci_dev->dev, "I/O queues creation failed\n");
3694 goto setup_nic_dev_fail;
3695 }
3696
3697 ifstate_set(lio, LIO_IFSTATE_DROQ_OPS);
3698
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003699 lio->tx_qsize = octeon_get_tx_qsize(octeon_dev, lio->txq);
3700 lio->rx_qsize = octeon_get_rx_qsize(octeon_dev, lio->rxq);
3701
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07003702 if (setup_glists(octeon_dev, lio, num_iqueues)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003703 dev_err(&octeon_dev->pci_dev->dev,
3704 "Gather list allocation failed\n");
3705 goto setup_nic_dev_fail;
3706 }
3707
3708 /* Register ethtool support */
3709 liquidio_set_ethtool_ops(netdev);
Raghu Vatsavayi30136392016-09-01 11:16:11 -07003710 if (lio->oct_dev->chip_id == OCTEON_CN23XX_PF_VID)
3711 octeon_dev->priv_flags = OCT_PRIV_FLAG_DEFAULT;
3712 else
3713 octeon_dev->priv_flags = 0x0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003714
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003715 if (netdev->features & NETIF_F_LRO)
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07003716 liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
3717 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003718
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003719 liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL,
3720 OCTNET_CMD_VLAN_FILTER_ENABLE);
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003721
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003722 if ((debug != -1) && (debug & NETIF_MSG_HW))
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003723 liquidio_set_feature(netdev,
3724 OCTNET_CMD_VERBOSE_ENABLE, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003725
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07003726 if (setup_link_status_change_wq(netdev))
3727 goto setup_nic_dev_fail;
3728
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -07003729 if ((octeon_dev->fw_info.app_cap_flags &
3730 LIQUIDIO_TIME_SYNC_CAP) &&
3731 setup_sync_octeon_time_wq(netdev))
3732 goto setup_nic_dev_fail;
3733
Satanand Burla031d4f12017-03-22 11:31:13 -07003734 if (setup_rx_oom_poll_fn(netdev))
3735 goto setup_nic_dev_fail;
3736
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003737 /* Register the network device with the OS */
3738 if (register_netdev(netdev)) {
3739 dev_err(&octeon_dev->pci_dev->dev, "Device registration failed\n");
3740 goto setup_nic_dev_fail;
3741 }
3742
3743 dev_dbg(&octeon_dev->pci_dev->dev,
3744 "Setup NIC ifidx:%d mac:%02x%02x%02x%02x%02x%02x\n",
3745 i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
3746 netif_carrier_off(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003747 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003748
3749 ifstate_set(lio, LIO_IFSTATE_REGISTERED);
3750
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003751 /* Sending command to firmware to enable Rx checksum offload
3752 * by default at the time of setup of Liquidio driver for
3753 * this device
3754 */
3755 liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
3756 OCTNET_CMD_RXCSUM_ENABLE);
3757 liquidio_set_feature(netdev, OCTNET_CMD_TNL_TX_CSUM_CTL,
3758 OCTNET_CMD_TXCSUM_ENABLE);
3759
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003760 dev_dbg(&octeon_dev->pci_dev->dev,
3761 "NIC ifidx:%d Setup successful\n", i);
3762
3763 octeon_free_soft_command(octeon_dev, sc);
3764 }
3765
3766 return 0;
3767
3768setup_nic_dev_fail:
3769
3770 octeon_free_soft_command(octeon_dev, sc);
3771
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07003772setup_nic_wait_intr:
3773
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003774 while (i--) {
3775 dev_err(&octeon_dev->pci_dev->dev,
3776 "NIC ifidx:%d Setup failed\n", i);
3777 liquidio_destroy_nic_device(octeon_dev, i);
3778 }
3779 return -ENODEV;
3780}
3781
Raghu Vatsavayica6139f2016-11-14 15:54:40 -08003782#ifdef CONFIG_PCI_IOV
3783static int octeon_enable_sriov(struct octeon_device *oct)
3784{
3785 unsigned int num_vfs_alloced = oct->sriov_info.num_vfs_alloced;
3786 struct pci_dev *vfdev;
3787 int err;
3788 u32 u;
3789
3790 if (OCTEON_CN23XX_PF(oct) && num_vfs_alloced) {
3791 err = pci_enable_sriov(oct->pci_dev,
3792 oct->sriov_info.num_vfs_alloced);
3793 if (err) {
3794 dev_err(&oct->pci_dev->dev,
3795 "OCTEON: Failed to enable PCI sriov: %d\n",
3796 err);
3797 oct->sriov_info.num_vfs_alloced = 0;
3798 return err;
3799 }
3800 oct->sriov_info.sriov_enabled = 1;
3801
3802 /* init lookup table that maps DPI ring number to VF pci_dev
3803 * struct pointer
3804 */
3805 u = 0;
3806 vfdev = pci_get_device(PCI_VENDOR_ID_CAVIUM,
3807 OCTEON_CN23XX_VF_VID, NULL);
3808 while (vfdev) {
3809 if (vfdev->is_virtfn &&
3810 (vfdev->physfn == oct->pci_dev)) {
3811 oct->sriov_info.dpiring_to_vfpcidev_lut[u] =
3812 vfdev;
3813 u += oct->sriov_info.rings_per_vf;
3814 }
3815 vfdev = pci_get_device(PCI_VENDOR_ID_CAVIUM,
3816 OCTEON_CN23XX_VF_VID, vfdev);
3817 }
3818 }
3819
3820 return num_vfs_alloced;
3821}
3822
3823static int lio_pci_sriov_disable(struct octeon_device *oct)
3824{
3825 int u;
3826
3827 if (pci_vfs_assigned(oct->pci_dev)) {
3828 dev_err(&oct->pci_dev->dev, "VFs are still assigned to VMs.\n");
3829 return -EPERM;
3830 }
3831
3832 pci_disable_sriov(oct->pci_dev);
3833
3834 u = 0;
3835 while (u < MAX_POSSIBLE_VFS) {
3836 oct->sriov_info.dpiring_to_vfpcidev_lut[u] = NULL;
3837 u += oct->sriov_info.rings_per_vf;
3838 }
3839
3840 oct->sriov_info.num_vfs_alloced = 0;
3841 dev_info(&oct->pci_dev->dev, "oct->pf_num:%d disabled VFs\n",
3842 oct->pf_num);
3843
3844 return 0;
3845}
3846
3847static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs)
3848{
3849 struct octeon_device *oct = pci_get_drvdata(dev);
3850 int ret = 0;
3851
3852 if ((num_vfs == oct->sriov_info.num_vfs_alloced) &&
3853 (oct->sriov_info.sriov_enabled)) {
3854 dev_info(&oct->pci_dev->dev, "oct->pf_num:%d already enabled num_vfs:%d\n",
3855 oct->pf_num, num_vfs);
3856 return 0;
3857 }
3858
3859 if (!num_vfs) {
3860 ret = lio_pci_sriov_disable(oct);
3861 } else if (num_vfs > oct->sriov_info.max_vfs) {
3862 dev_err(&oct->pci_dev->dev,
3863 "OCTEON: Max allowed VFs:%d user requested:%d",
3864 oct->sriov_info.max_vfs, num_vfs);
3865 ret = -EPERM;
3866 } else {
3867 oct->sriov_info.num_vfs_alloced = num_vfs;
3868 ret = octeon_enable_sriov(oct);
3869 dev_info(&oct->pci_dev->dev, "oct->pf_num:%d num_vfs:%d\n",
3870 oct->pf_num, num_vfs);
3871 }
3872
3873 return ret;
3874}
3875#endif
3876
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003877/**
3878 * \brief initialize the NIC
3879 * @param oct octeon device
3880 *
3881 * This initialization routine is called once the Octeon device application is
3882 * up and running
3883 */
3884static int liquidio_init_nic_module(struct octeon_device *oct)
3885{
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003886 int i, retval = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003887 int num_nic_ports = CFG_GET_NUM_NIC_PORTS(octeon_get_conf(oct));
3888
3889 dev_dbg(&oct->pci_dev->dev, "Initializing network interfaces\n");
3890
3891 /* only default iq and oq were initialized
3892 * initialize the rest as well
3893 */
3894 /* run port_config command for each port */
3895 oct->ifcount = num_nic_ports;
3896
Raghu Vatsavayi30136392016-09-01 11:16:11 -07003897 memset(oct->props, 0, sizeof(struct octdev_props) * num_nic_ports);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003898
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003899 for (i = 0; i < MAX_OCTEON_LINKS; i++)
3900 oct->props[i].gmxport = -1;
3901
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003902 retval = setup_nic_devices(oct);
3903 if (retval) {
3904 dev_err(&oct->pci_dev->dev, "Setup NIC devices failed\n");
3905 goto octnet_init_failure;
3906 }
3907
3908 liquidio_ptp_init(oct);
3909
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003910 dev_dbg(&oct->pci_dev->dev, "Network interfaces ready\n");
3911
3912 return retval;
3913
3914octnet_init_failure:
3915
3916 oct->ifcount = 0;
3917
3918 return retval;
3919}
3920
3921/**
3922 * \brief starter callback that invokes the remaining initialization work after
3923 * the NIC is up and running.
3924 * @param octptr work struct work_struct
3925 */
3926static void nic_starter(struct work_struct *work)
3927{
3928 struct octeon_device *oct;
3929 struct cavium_wk *wk = (struct cavium_wk *)work;
3930
3931 oct = (struct octeon_device *)wk->ctxptr;
3932
3933 if (atomic_read(&oct->status) == OCT_DEV_RUNNING)
3934 return;
3935
3936 /* If the status of the device is CORE_OK, the core
3937 * application has reported its application type. Call
3938 * any registered handlers now and move to the RUNNING
3939 * state.
3940 */
3941 if (atomic_read(&oct->status) != OCT_DEV_CORE_OK) {
3942 schedule_delayed_work(&oct->nic_poll_work.work,
3943 LIQUIDIO_STARTER_POLL_INTERVAL_MS);
3944 return;
3945 }
3946
3947 atomic_set(&oct->status, OCT_DEV_RUNNING);
3948
3949 if (oct->app_mode && oct->app_mode == CVM_DRV_NIC_APP) {
3950 dev_dbg(&oct->pci_dev->dev, "Starting NIC module\n");
3951
3952 if (liquidio_init_nic_module(oct))
3953 dev_err(&oct->pci_dev->dev, "NIC initialization failed\n");
3954 else
3955 handshake[oct->octeon_id].started_ok = 1;
3956 } else {
3957 dev_err(&oct->pci_dev->dev,
3958 "Unexpected application running on NIC (%d). Check firmware.\n",
3959 oct->app_mode);
3960 }
3961
3962 complete(&handshake[oct->octeon_id].started);
3963}
3964
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003965static int
3966octeon_recv_vf_drv_notice(struct octeon_recv_info *recv_info, void *buf)
3967{
3968 struct octeon_device *oct = (struct octeon_device *)buf;
3969 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
3970 int i, notice, vf_idx;
Felix Manlunasbb54be52017-04-04 19:26:57 -07003971 bool cores_crashed;
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003972 u64 *data, vf_num;
3973
3974 notice = recv_pkt->rh.r.ossp;
Prasad Kannegantic4ee5d82017-06-18 05:04:11 -07003975 data = (u64 *)(get_rbd(recv_pkt->buffer_ptr[0]) + OCT_DROQ_INFO_SIZE);
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003976
3977 /* the first 64-bit word of data is the vf_num */
3978 vf_num = data[0];
3979 octeon_swap_8B_data(&vf_num, 1);
3980 vf_idx = (int)vf_num - 1;
3981
Felix Manlunasbb54be52017-04-04 19:26:57 -07003982 cores_crashed = READ_ONCE(oct->cores_crashed);
3983
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003984 if (notice == VF_DRV_LOADED) {
3985 if (!(oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vf_idx))) {
3986 oct->sriov_info.vf_drv_loaded_mask |= BIT_ULL(vf_idx);
3987 dev_info(&oct->pci_dev->dev,
3988 "driver for VF%d was loaded\n", vf_idx);
Felix Manlunasbb54be52017-04-04 19:26:57 -07003989 if (!cores_crashed)
3990 try_module_get(THIS_MODULE);
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003991 }
3992 } else if (notice == VF_DRV_REMOVED) {
3993 if (oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vf_idx)) {
3994 oct->sriov_info.vf_drv_loaded_mask &= ~BIT_ULL(vf_idx);
3995 dev_info(&oct->pci_dev->dev,
3996 "driver for VF%d was removed\n", vf_idx);
Felix Manlunasbb54be52017-04-04 19:26:57 -07003997 if (!cores_crashed)
3998 module_put(THIS_MODULE);
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003999 }
4000 } else if (notice == VF_DRV_MACADDR_CHANGED) {
4001 u8 *b = (u8 *)&data[1];
4002
4003 oct->sriov_info.vf_macaddr[vf_idx] = data[1];
4004 dev_info(&oct->pci_dev->dev,
4005 "VF driver changed VF%d's MAC address to %pM\n",
4006 vf_idx, b + 2);
4007 }
4008
4009 for (i = 0; i < recv_pkt->buffer_count; i++)
4010 recv_buffer_free(recv_pkt->buffer_ptr[i]);
4011 octeon_free_recv_info(recv_info);
4012
4013 return 0;
4014}
4015
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004016/**
4017 * \brief Device initialization for each Octeon device that is probed
4018 * @param octeon_dev octeon device
4019 */
4020static int octeon_device_init(struct octeon_device *octeon_dev)
4021{
4022 int j, ret;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07004023 char bootcmd[] = "\n";
Rick Farringtonda1542b2017-08-11 18:43:14 -07004024 char *dbg_enb = NULL;
Rick Farrington088b8742017-09-22 17:12:43 -07004025 enum lio_fw_state fw_state;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004026 struct octeon_device_priv *oct_priv =
4027 (struct octeon_device_priv *)octeon_dev->priv;
4028 atomic_set(&octeon_dev->status, OCT_DEV_BEGIN_STATE);
4029
4030 /* Enable access to the octeon device and make its DMA capability
4031 * known to the OS.
4032 */
4033 if (octeon_pci_os_setup(octeon_dev))
4034 return 1;
4035
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08004036 atomic_set(&octeon_dev->status, OCT_DEV_PCI_ENABLE_DONE);
4037
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004038 /* Identify the Octeon type and map the BAR address space. */
4039 if (octeon_chip_specific_setup(octeon_dev)) {
4040 dev_err(&octeon_dev->pci_dev->dev, "Chip specific setup failed\n");
4041 return 1;
4042 }
4043
4044 atomic_set(&octeon_dev->status, OCT_DEV_PCI_MAP_DONE);
4045
Rick Farringtone1e3ce62017-05-16 11:14:50 -07004046 /* Only add a reference after setting status 'OCT_DEV_PCI_MAP_DONE',
4047 * since that is what is required for the reference to be removed
4048 * during de-initialization (see 'octeon_destroy_resources').
4049 */
4050 octeon_register_device(octeon_dev, octeon_dev->pci_dev->bus->number,
4051 PCI_SLOT(octeon_dev->pci_dev->devfn),
4052 PCI_FUNC(octeon_dev->pci_dev->devfn),
4053 true);
4054
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004055 octeon_dev->app_mode = CVM_DRV_INVALID_APP;
4056
Rick Farrington088b8742017-09-22 17:12:43 -07004057 /* CN23XX supports preloaded firmware if the following is true:
4058 *
4059 * The adapter indicates that firmware is currently running AND
4060 * 'fw_type' is 'auto'.
4061 *
4062 * (default state is NEEDS_TO_BE_LOADED, override it if appropriate).
4063 */
4064 if (OCTEON_CN23XX_PF(octeon_dev) &&
4065 cn23xx_fw_loaded(octeon_dev) && fw_type_is_auto()) {
4066 atomic_cmpxchg(octeon_dev->adapter_fw_state,
4067 FW_NEEDS_TO_BE_LOADED, FW_IS_PRELOADED);
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004068 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004069
Rick Farrington088b8742017-09-22 17:12:43 -07004070 /* If loading firmware, only first device of adapter needs to do so. */
4071 fw_state = atomic_cmpxchg(octeon_dev->adapter_fw_state,
4072 FW_NEEDS_TO_BE_LOADED,
4073 FW_IS_BEING_LOADED);
4074
4075 /* Here, [local variable] 'fw_state' is set to one of:
4076 *
4077 * FW_IS_PRELOADED: No firmware is to be loaded (see above)
4078 * FW_NEEDS_TO_BE_LOADED: The driver's first instance will load
4079 * firmware to the adapter.
4080 * FW_IS_BEING_LOADED: The driver's second instance will not load
4081 * firmware to the adapter.
4082 */
4083
4084 /* Prior to f/w load, perform a soft reset of the Octeon device;
4085 * if error resetting, return w/error.
4086 */
4087 if (fw_state == FW_NEEDS_TO_BE_LOADED)
4088 if (octeon_dev->fn_list.soft_reset(octeon_dev))
4089 return 1;
4090
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004091 /* Initialize the dispatch mechanism used to push packets arriving on
4092 * Octeon Output queues.
4093 */
4094 if (octeon_init_dispatch_list(octeon_dev))
4095 return 1;
4096
4097 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
4098 OPCODE_NIC_CORE_DRV_ACTIVE,
4099 octeon_core_drv_init,
4100 octeon_dev);
4101
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004102 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
4103 OPCODE_NIC_VF_DRV_NOTICE,
4104 octeon_recv_vf_drv_notice, octeon_dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004105 INIT_DELAYED_WORK(&octeon_dev->nic_poll_work.work, nic_starter);
4106 octeon_dev->nic_poll_work.ctxptr = (void *)octeon_dev;
4107 schedule_delayed_work(&octeon_dev->nic_poll_work.work,
4108 LIQUIDIO_STARTER_POLL_INTERVAL_MS);
4109
4110 atomic_set(&octeon_dev->status, OCT_DEV_DISPATCH_INIT_DONE);
4111
Raghu Vatsavayic865cdf2016-11-28 16:54:36 -08004112 if (octeon_set_io_queues_off(octeon_dev)) {
4113 dev_err(&octeon_dev->pci_dev->dev, "setting io queues off failed\n");
4114 return 1;
4115 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004116
Raghu Vatsavayi3451b972016-08-31 11:03:26 -07004117 if (OCTEON_CN23XX_PF(octeon_dev)) {
4118 ret = octeon_dev->fn_list.setup_device_regs(octeon_dev);
4119 if (ret) {
4120 dev_err(&octeon_dev->pci_dev->dev, "OCTEON: Failed to configure device registers\n");
4121 return ret;
4122 }
4123 }
4124
4125 /* Initialize soft command buffer pool
4126 */
4127 if (octeon_setup_sc_buffer_pool(octeon_dev)) {
4128 dev_err(&octeon_dev->pci_dev->dev, "sc buffer pool allocation failed\n");
4129 return 1;
4130 }
4131 atomic_set(&octeon_dev->status, OCT_DEV_SC_BUFF_POOL_INIT_DONE);
4132
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004133 /* Setup the data structures that manage this Octeon's Input queues. */
4134 if (octeon_setup_instr_queues(octeon_dev)) {
4135 dev_err(&octeon_dev->pci_dev->dev,
4136 "instruction queue initialization failed\n");
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004137 return 1;
4138 }
4139 atomic_set(&octeon_dev->status, OCT_DEV_INSTR_QUEUE_INIT_DONE);
4140
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004141 /* Initialize lists to manage the requests of different types that
4142 * arrive from user & kernel applications for this octeon device.
4143 */
4144 if (octeon_setup_response_list(octeon_dev)) {
4145 dev_err(&octeon_dev->pci_dev->dev, "Response list allocation failed\n");
4146 return 1;
4147 }
4148 atomic_set(&octeon_dev->status, OCT_DEV_RESP_LIST_INIT_DONE);
4149
4150 if (octeon_setup_output_queues(octeon_dev)) {
4151 dev_err(&octeon_dev->pci_dev->dev, "Output queue initialization failed\n");
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -07004152 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004153 }
4154
4155 atomic_set(&octeon_dev->status, OCT_DEV_DROQ_INIT_DONE);
4156
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004157 if (OCTEON_CN23XX_PF(octeon_dev)) {
Raghu Vatsavayi5d655562016-11-14 15:54:42 -08004158 if (octeon_dev->fn_list.setup_mbox(octeon_dev)) {
4159 dev_err(&octeon_dev->pci_dev->dev, "OCTEON: Mailbox setup failed\n");
4160 return 1;
4161 }
4162 atomic_set(&octeon_dev->status, OCT_DEV_MBOX_SETUP_DONE);
4163
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004164 if (octeon_allocate_ioq_vector(octeon_dev)) {
4165 dev_err(&octeon_dev->pci_dev->dev, "OCTEON: ioq vector allocation failed\n");
4166 return 1;
4167 }
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08004168 atomic_set(&octeon_dev->status, OCT_DEV_MSIX_ALLOC_VECTOR_DONE);
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004169
4170 } else {
4171 /* The input and output queue registers were setup earlier (the
4172 * queues were not enabled). Any additional registers
4173 * that need to be programmed should be done now.
4174 */
4175 ret = octeon_dev->fn_list.setup_device_regs(octeon_dev);
4176 if (ret) {
4177 dev_err(&octeon_dev->pci_dev->dev,
4178 "Failed to configure device registers\n");
4179 return ret;
4180 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004181 }
4182
4183 /* Initialize the tasklet that handles output queue packet processing.*/
4184 dev_dbg(&octeon_dev->pci_dev->dev, "Initializing droq tasklet\n");
4185 tasklet_init(&oct_priv->droq_tasklet, octeon_droq_bh,
4186 (unsigned long)octeon_dev);
4187
4188 /* Setup the interrupt handler and record the INT SUM register address
4189 */
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07004190 if (octeon_setup_interrupt(octeon_dev,
4191 octeon_dev->sriov_info.num_pf_rings))
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -07004192 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004193
4194 /* Enable Octeon device interrupts */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004195 octeon_dev->fn_list.enable_interrupt(octeon_dev, OCTEON_ALL_INTR);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004196
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08004197 atomic_set(&octeon_dev->status, OCT_DEV_INTR_SET_DONE);
4198
Rick Farrington3c57f612017-08-17 23:11:30 -07004199 /* Send Credit for Octeon Output queues. Credits are always sent BEFORE
4200 * the output queue is enabled.
4201 * This ensures that we'll receive the f/w CORE DRV_ACTIVE message in
4202 * case we've configured CN23XX_SLI_GBL_CONTROL[NOPTR_D] = 0.
4203 * Otherwise, it is possible that the DRV_ACTIVE message will be sent
4204 * before any credits have been issued, causing the ring to be reset
4205 * (and the f/w appear to never have started).
4206 */
4207 for (j = 0; j < octeon_dev->num_oqs; j++)
4208 writel(octeon_dev->droq[j]->max_count,
4209 octeon_dev->droq[j]->pkts_credit_reg);
4210
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004211 /* Enable the input and output queues for this Octeon device */
Raghu Vatsavayi1b7c55c2016-08-31 11:03:27 -07004212 ret = octeon_dev->fn_list.enable_io_queues(octeon_dev);
4213 if (ret) {
4214 dev_err(&octeon_dev->pci_dev->dev, "Failed to enable input/output queues");
4215 return ret;
4216 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004217
4218 atomic_set(&octeon_dev->status, OCT_DEV_IO_QUEUES_DONE);
4219
Rick Farrington088b8742017-09-22 17:12:43 -07004220 if (fw_state == FW_NEEDS_TO_BE_LOADED) {
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004221 dev_dbg(&octeon_dev->pci_dev->dev, "Waiting for DDR initialization...\n");
4222 if (!ddr_timeout) {
4223 dev_info(&octeon_dev->pci_dev->dev,
4224 "WAITING. Set ddr_timeout to non-zero value to proceed with initialization.\n");
4225 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004226
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004227 schedule_timeout_uninterruptible(HZ * LIO_RESET_SECS);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004228
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004229 /* Wait for the octeon to initialize DDR after the soft-reset.*/
4230 while (!ddr_timeout) {
4231 set_current_state(TASK_INTERRUPTIBLE);
4232 if (schedule_timeout(HZ / 10)) {
4233 /* user probably pressed Control-C */
4234 return 1;
4235 }
4236 }
4237 ret = octeon_wait_for_ddr_init(octeon_dev, &ddr_timeout);
4238 if (ret) {
4239 dev_err(&octeon_dev->pci_dev->dev,
4240 "DDR not initialized. Please confirm that board is configured to boot from Flash, ret: %d\n",
4241 ret);
Raghu Vatsavayi4b129ae2016-06-21 22:53:15 -07004242 return 1;
4243 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004244
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004245 if (octeon_wait_for_bootloader(octeon_dev, 1000)) {
4246 dev_err(&octeon_dev->pci_dev->dev, "Board not responding\n");
4247 return 1;
4248 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004249
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004250 /* Divert uboot to take commands from host instead. */
4251 ret = octeon_console_send_cmd(octeon_dev, bootcmd, 50);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07004252
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004253 dev_dbg(&octeon_dev->pci_dev->dev, "Initializing consoles\n");
4254 ret = octeon_init_consoles(octeon_dev);
4255 if (ret) {
4256 dev_err(&octeon_dev->pci_dev->dev, "Could not access board consoles\n");
4257 return 1;
4258 }
Rick Farringtonda1542b2017-08-11 18:43:14 -07004259 /* If console debug enabled, specify empty string to use default
4260 * enablement ELSE specify NULL string for 'disabled'.
4261 */
4262 dbg_enb = octeon_console_debug_enabled(0) ? "" : NULL;
4263 ret = octeon_add_console(octeon_dev, 0, dbg_enb);
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004264 if (ret) {
4265 dev_err(&octeon_dev->pci_dev->dev, "Could not access board console\n");
4266 return 1;
Rick Farringtonda1542b2017-08-11 18:43:14 -07004267 } else if (octeon_console_debug_enabled(0)) {
4268 /* If console was added AND we're logging console output
4269 * then set our console print function.
4270 */
4271 octeon_dev->console[0].print = octeon_dbg_console_print;
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004272 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004273
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004274 atomic_set(&octeon_dev->status, OCT_DEV_CONSOLE_INIT_DONE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004275
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004276 dev_dbg(&octeon_dev->pci_dev->dev, "Loading firmware\n");
4277 ret = load_firmware(octeon_dev);
4278 if (ret) {
4279 dev_err(&octeon_dev->pci_dev->dev, "Could not load firmware to board\n");
4280 return 1;
4281 }
Rick Farrington088b8742017-09-22 17:12:43 -07004282
4283 atomic_set(octeon_dev->adapter_fw_state, FW_HAS_BEEN_LOADED);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004284 }
4285
4286 handshake[octeon_dev->octeon_id].init_ok = 1;
4287 complete(&handshake[octeon_dev->octeon_id].init);
4288
4289 atomic_set(&octeon_dev->status, OCT_DEV_HOST_OK);
4290
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004291 return 0;
4292}
4293
4294/**
Rick Farringtonda1542b2017-08-11 18:43:14 -07004295 * \brief Debug console print function
4296 * @param octeon_dev octeon device
4297 * @param console_num console number
4298 * @param prefix first portion of line to display
4299 * @param suffix second portion of line to display
4300 *
4301 * The OCTEON debug console outputs entire lines (excluding '\n').
4302 * Normally, the line will be passed in the 'prefix' parameter.
4303 * However, due to buffering, it is possible for a line to be split into two
4304 * parts, in which case they will be passed as the 'prefix' parameter and
4305 * 'suffix' parameter.
4306 */
4307static int octeon_dbg_console_print(struct octeon_device *oct, u32 console_num,
4308 char *prefix, char *suffix)
4309{
4310 if (prefix && suffix)
4311 dev_info(&oct->pci_dev->dev, "%u: %s%s\n", console_num, prefix,
4312 suffix);
4313 else if (prefix)
4314 dev_info(&oct->pci_dev->dev, "%u: %s\n", console_num, prefix);
4315 else if (suffix)
4316 dev_info(&oct->pci_dev->dev, "%u: %s\n", console_num, suffix);
4317
4318 return 0;
4319}
4320
4321/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004322 * \brief Exits the module
4323 */
4324static void __exit liquidio_exit(void)
4325{
4326 liquidio_deinit_pci();
4327
4328 pr_info("LiquidIO network module is now unloaded\n");
4329}
4330
4331module_init(liquidio_init);
4332module_exit(liquidio_exit);