blob: 80784122e6e9a95b7d240de6028e16d13d93c079 [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>
Vijaya Mohan Guvva1f233f32017-10-31 16:04:53 -070024#include <net/switchdev.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070025#include "liquidio_common.h"
26#include "octeon_droq.h"
27#include "octeon_iq.h"
28#include "response_manager.h"
29#include "octeon_device.h"
30#include "octeon_nic.h"
31#include "octeon_main.h"
32#include "octeon_network.h"
33#include "cn66xx_regs.h"
34#include "cn66xx_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070035#include "cn68xx_device.h"
Raghu Vatsavayi72c00912016-08-31 11:03:25 -070036#include "cn23xx_pf_device.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070037#include "liquidio_image.h"
38
39MODULE_AUTHOR("Cavium Networks, <support@cavium.com>");
40MODULE_DESCRIPTION("Cavium LiquidIO Intelligent Server Adapter Driver");
41MODULE_LICENSE("GPL");
42MODULE_VERSION(LIQUIDIO_VERSION);
Derek Chicklesea6404c82017-08-07 12:22:15 -070043MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210SV_NAME
44 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
45MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_210NV_NAME
46 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
47MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_410NV_NAME
48 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
49MODULE_FIRMWARE(LIO_FW_DIR LIO_FW_BASE_NAME LIO_23XX_NAME
50 "_" LIO_FW_NAME_TYPE_NIC LIO_FW_NAME_SUFFIX);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070051
52static int ddr_timeout = 10000;
53module_param(ddr_timeout, int, 0644);
54MODULE_PARM_DESC(ddr_timeout,
55 "Number of milliseconds to wait for DDR initialization. 0 waits for ddr_timeout to be set to non-zero value before starting to check");
56
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070057#define DEFAULT_MSG_ENABLE (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_LINK)
58
59static int debug = -1;
60module_param(debug, int, 0644);
61MODULE_PARM_DESC(debug, "NETIF_MSG debug bits");
62
Rick Farrington088b8742017-09-22 17:12:43 -070063static char fw_type[LIO_MAX_FW_TYPE_LEN] = LIO_FW_NAME_TYPE_AUTO;
Derek Chicklesd3961792017-08-14 12:17:56 -070064module_param_string(fw_type, fw_type, sizeof(fw_type), 0444);
Rick Farrington088b8742017-09-22 17:12:43 -070065MODULE_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 -070066
Intiyaz Basha2470f3a2017-08-03 15:10:17 -070067static u32 console_bitmask;
68module_param(console_bitmask, int, 0644);
69MODULE_PARM_DESC(console_bitmask,
70 "Bitmask indicating which consoles have debug output redirected to syslog.");
71
72/**
73 * \brief determines if a given console has debug enabled.
74 * @param console console to check
75 * @returns 1 = enabled. 0 otherwise
76 */
Rick Farringtonda1542b2017-08-11 18:43:14 -070077static int octeon_console_debug_enabled(u32 console)
Intiyaz Basha2470f3a2017-08-03 15:10:17 -070078{
79 return (console_bitmask >> (console)) & 0x1;
80}
81
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070082/* Polling interval for determining when NIC application is alive */
83#define LIQUIDIO_STARTER_POLL_INTERVAL_MS 100
84
85/* runtime link query interval */
86#define LIQUIDIO_LINK_QUERY_INTERVAL_MS 1000
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -070087/* update localtime to octeon firmware every 60 seconds.
88 * make firmware to use same time reference, so that it will be easy to
89 * correlate firmware logged events/errors with host events, for debugging.
90 */
91#define LIO_SYNC_OCTEON_TIME_INTERVAL_MS 60000
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070092
93struct liquidio_if_cfg_context {
94 int octeon_id;
95
96 wait_queue_head_t wc;
97
98 int cond;
99};
100
101struct liquidio_if_cfg_resp {
102 u64 rh;
103 struct liquidio_if_cfg_info cfg_info;
104 u64 status;
105};
106
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -0700107struct liquidio_rx_ctl_context {
108 int octeon_id;
109
110 wait_queue_head_t wc;
111
112 int cond;
113};
114
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700115struct oct_link_status_resp {
116 u64 rh;
117 struct oct_link_info link_info;
118 u64 status;
119};
120
121struct oct_timestamp_resp {
122 u64 rh;
123 u64 timestamp;
124 u64 status;
125};
126
127#define OCT_TIMESTAMP_RESP_SIZE (sizeof(struct oct_timestamp_resp))
128
129union tx_info {
130 u64 u64;
131 struct {
132#ifdef __BIG_ENDIAN_BITFIELD
133 u16 gso_size;
134 u16 gso_segs;
135 u32 reserved;
136#else
137 u32 reserved;
138 u16 gso_segs;
139 u16 gso_size;
140#endif
141 } s;
142};
143
144/** Octeon device properties to be used by the NIC module.
145 * Each octeon device in the system will be represented
146 * by this structure in the NIC module.
147 */
148
149#define OCTNIC_MAX_SG (MAX_SKB_FRAGS)
150
151#define OCTNIC_GSO_MAX_HEADER_SIZE 128
Raghu Vatsavayi72c00912016-08-31 11:03:25 -0700152#define OCTNIC_GSO_MAX_SIZE \
153 (CN23XX_DEFAULT_INPUT_JABBER - OCTNIC_GSO_MAX_HEADER_SIZE)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700154
155/** Structure of a node in list of gather components maintained by
156 * NIC driver for each network device.
157 */
158struct octnic_gather {
159 /** List manipulation. Next and prev pointers. */
160 struct list_head list;
161
162 /** Size of the gather component at sg in bytes. */
163 int sg_size;
164
165 /** Number of bytes that sg was adjusted to make it 8B-aligned. */
166 int adjust;
167
168 /** Gather component that can accommodate max sized fragment list
169 * received from the IP layer.
170 */
171 struct octeon_sg_entry *sg;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700172
VSR Burru67e303e2017-03-06 18:45:59 -0800173 dma_addr_t sg_dma_ptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700174};
175
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700176struct handshake {
177 struct completion init;
178 struct completion started;
179 struct pci_dev *pci_dev;
180 int init_ok;
181 int started_ok;
182};
183
Raghu Vatsavayica6139f2016-11-14 15:54:40 -0800184#ifdef CONFIG_PCI_IOV
185static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs);
186#endif
187
Rick Farringtonda1542b2017-08-11 18:43:14 -0700188static int octeon_dbg_console_print(struct octeon_device *oct, u32 console_num,
189 char *prefix, char *suffix);
190
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700191static int octeon_device_init(struct octeon_device *);
Raghu Vatsavayi32581242016-08-31 11:03:20 -0700192static int liquidio_stop(struct net_device *netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700193static void liquidio_remove(struct pci_dev *pdev);
194static int liquidio_probe(struct pci_dev *pdev,
195 const struct pci_device_id *ent);
Felix Manlunasbb54be52017-04-04 19:26:57 -0700196static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
197 int linkstate);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700198
199static struct handshake handshake[MAX_OCTEON_DEVICES];
200static struct completion first_stage;
201
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700202static void octeon_droq_bh(unsigned long pdev)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700203{
204 int q_no;
205 int reschedule = 0;
206 struct octeon_device *oct = (struct octeon_device *)pdev;
207 struct octeon_device_priv *oct_priv =
208 (struct octeon_device_priv *)oct->priv;
209
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700210 for (q_no = 0; q_no < MAX_OCTEON_OUTPUT_QUEUES(oct); q_no++) {
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800211 if (!(oct->io_qmask.oq & BIT_ULL(q_no)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700212 continue;
213 reschedule |= octeon_droq_process_packets(oct, oct->droq[q_no],
214 MAX_PACKET_BUDGET);
Raghu Vatsavayicd8b1eb2016-08-31 11:03:22 -0700215 lio_enable_irq(oct->droq[q_no], NULL);
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700216
217 if (OCTEON_CN23XX_PF(oct) && oct->msix_on) {
218 /* set time and cnt interrupt thresholds for this DROQ
219 * for NAPI
220 */
221 int adjusted_q_no = q_no + oct->sriov_info.pf_srn;
222
223 octeon_write_csr64(
224 oct, CN23XX_SLI_OQ_PKT_INT_LEVELS(adjusted_q_no),
225 0x5700000040ULL);
226 octeon_write_csr64(
227 oct, CN23XX_SLI_OQ_PKTS_SENT(adjusted_q_no), 0);
228 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700229 }
230
231 if (reschedule)
232 tasklet_schedule(&oct_priv->droq_tasklet);
233}
234
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -0700235static int lio_wait_for_oq_pkts(struct octeon_device *oct)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700236{
237 struct octeon_device_priv *oct_priv =
238 (struct octeon_device_priv *)oct->priv;
239 int retry = 100, pkt_cnt = 0, pending_pkts = 0;
240 int i;
241
242 do {
243 pending_pkts = 0;
244
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700245 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800246 if (!(oct->io_qmask.oq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700247 continue;
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700248 pkt_cnt += octeon_droq_check_hw_for_pkts(oct->droq[i]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700249 }
250 if (pkt_cnt > 0) {
251 pending_pkts += pkt_cnt;
252 tasklet_schedule(&oct_priv->droq_tasklet);
253 }
254 pkt_cnt = 0;
255 schedule_timeout_uninterruptible(1);
256
257 } while (retry-- && pending_pkts);
258
259 return pkt_cnt;
260}
261
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700262/**
263 * \brief Forces all IO queues off on a given device
264 * @param oct Pointer to Octeon device
265 */
266static void force_io_queues_off(struct octeon_device *oct)
267{
268 if ((oct->chip_id == OCTEON_CN66XX) ||
269 (oct->chip_id == OCTEON_CN68XX)) {
270 /* Reset the Enable bits for Input Queues. */
271 octeon_write_csr(oct, CN6XXX_SLI_PKT_INSTR_ENB, 0);
272
273 /* Reset the Enable bits for Output Queues. */
274 octeon_write_csr(oct, CN6XXX_SLI_PKT_OUT_ENB, 0);
275 }
276}
277
278/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700279 * \brief Cause device to go quiet so it can be safely removed/reset/etc
280 * @param oct Pointer to Octeon device
281 */
282static inline void pcierror_quiesce_device(struct octeon_device *oct)
283{
284 int i;
285
286 /* Disable the input and output queues now. No more packets will
287 * arrive from Octeon, but we should wait for all packet processing
288 * to finish.
289 */
290 force_io_queues_off(oct);
291
292 /* To allow for in-flight requests */
293 schedule_timeout_uninterruptible(100);
294
295 if (wait_for_pending_requests(oct))
296 dev_err(&oct->pci_dev->dev, "There were pending requests\n");
297
298 /* Force all requests waiting to be fetched by OCTEON to complete. */
Raghu Vatsavayi63da8402016-06-21 22:53:03 -0700299 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700300 struct octeon_instr_queue *iq;
301
Raghu Vatsavayi763185a2016-11-14 15:54:45 -0800302 if (!(oct->io_qmask.iq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700303 continue;
304 iq = oct->instr_queue[i];
305
306 if (atomic_read(&iq->instr_pending)) {
307 spin_lock_bh(&iq->lock);
308 iq->fill_cnt = 0;
309 iq->octeon_read_index = iq->host_write_index;
310 iq->stats.instr_processed +=
311 atomic_read(&iq->instr_pending);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -0700312 lio_process_iq_request_list(oct, iq, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700313 spin_unlock_bh(&iq->lock);
314 }
315 }
316
317 /* Force all pending ordered list requests to time out. */
318 lio_process_ordered_list(oct, 1);
319
320 /* We do not need to wait for output queue packets to be processed. */
321}
322
323/**
324 * \brief Cleanup PCI AER uncorrectable error status
325 * @param dev Pointer to PCI device
326 */
327static void cleanup_aer_uncorrect_error_status(struct pci_dev *dev)
328{
329 int pos = 0x100;
330 u32 status, mask;
331
332 pr_info("%s :\n", __func__);
333
334 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, &status);
335 pci_read_config_dword(dev, pos + PCI_ERR_UNCOR_SEVER, &mask);
336 if (dev->error_state == pci_channel_io_normal)
337 status &= ~mask; /* Clear corresponding nonfatal bits */
338 else
339 status &= mask; /* Clear corresponding fatal bits */
340 pci_write_config_dword(dev, pos + PCI_ERR_UNCOR_STATUS, status);
341}
342
343/**
344 * \brief Stop all PCI IO to a given device
345 * @param dev Pointer to Octeon device
346 */
347static void stop_pci_io(struct octeon_device *oct)
348{
349 /* No more instructions will be forwarded. */
350 atomic_set(&oct->status, OCT_DEV_IN_RESET);
351
352 pci_disable_device(oct->pci_dev);
353
354 /* Disable interrupts */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -0700355 oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700356
357 pcierror_quiesce_device(oct);
358
359 /* Release the interrupt line */
360 free_irq(oct->pci_dev->irq, oct);
361
362 if (oct->flags & LIO_FLAG_MSI_ENABLED)
363 pci_disable_msi(oct->pci_dev);
364
365 dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
366 lio_get_state_string(&oct->status));
367
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700368 /* making it a common function for all OCTEON models */
369 cleanup_aer_uncorrect_error_status(oct->pci_dev);
370}
371
372/**
373 * \brief called when PCI error is detected
374 * @param pdev Pointer to PCI device
375 * @param state The current pci connection state
376 *
377 * This function is called after a PCI bus error affecting
378 * this device has been detected.
379 */
380static pci_ers_result_t liquidio_pcie_error_detected(struct pci_dev *pdev,
381 pci_channel_state_t state)
382{
383 struct octeon_device *oct = pci_get_drvdata(pdev);
384
385 /* Non-correctable Non-fatal errors */
386 if (state == pci_channel_io_normal) {
387 dev_err(&oct->pci_dev->dev, "Non-correctable non-fatal error reported:\n");
388 cleanup_aer_uncorrect_error_status(oct->pci_dev);
389 return PCI_ERS_RESULT_CAN_RECOVER;
390 }
391
392 /* Non-correctable Fatal errors */
393 dev_err(&oct->pci_dev->dev, "Non-correctable FATAL reported by PCI AER driver\n");
394 stop_pci_io(oct);
395
396 /* Always return a DISCONNECT. There is no support for recovery but only
397 * for a clean shutdown.
398 */
399 return PCI_ERS_RESULT_DISCONNECT;
400}
401
402/**
403 * \brief mmio handler
404 * @param pdev Pointer to PCI device
405 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700406static pci_ers_result_t liquidio_pcie_mmio_enabled(
407 struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700408{
409 /* We should never hit this since we never ask for a reset for a Fatal
410 * Error. We always return DISCONNECT in io_error above.
411 * But play safe and return RECOVERED for now.
412 */
413 return PCI_ERS_RESULT_RECOVERED;
414}
415
416/**
417 * \brief called after the pci bus has been reset.
418 * @param pdev Pointer to PCI device
419 *
420 * Restart the card from scratch, as if from a cold-boot. Implementation
421 * resembles the first-half of the octeon_resume routine.
422 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700423static pci_ers_result_t liquidio_pcie_slot_reset(
424 struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700425{
426 /* We should never hit this since we never ask for a reset for a Fatal
427 * Error. We always return DISCONNECT in io_error above.
428 * But play safe and return RECOVERED for now.
429 */
430 return PCI_ERS_RESULT_RECOVERED;
431}
432
433/**
434 * \brief called when traffic can start flowing again.
435 * @param pdev Pointer to PCI device
436 *
437 * This callback is called when the error recovery driver tells us that
438 * its OK to resume normal operation. Implementation resembles the
439 * second-half of the octeon_resume routine.
440 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700441static void liquidio_pcie_resume(struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700442{
443 /* Nothing to be done here. */
444}
445
446#ifdef CONFIG_PM
447/**
448 * \brief called when suspending
449 * @param pdev Pointer to PCI device
450 * @param state state to suspend to
451 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700452static int liquidio_suspend(struct pci_dev *pdev __attribute__((unused)),
453 pm_message_t state __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700454{
455 return 0;
456}
457
458/**
459 * \brief called when resuming
460 * @param pdev Pointer to PCI device
461 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -0700462static int liquidio_resume(struct pci_dev *pdev __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700463{
464 return 0;
465}
466#endif
467
468/* For PCI-E Advanced Error Recovery (AER) Interface */
Julia Lawall166e2362015-11-14 11:06:53 +0100469static const struct pci_error_handlers liquidio_err_handler = {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700470 .error_detected = liquidio_pcie_error_detected,
471 .mmio_enabled = liquidio_pcie_mmio_enabled,
472 .slot_reset = liquidio_pcie_slot_reset,
473 .resume = liquidio_pcie_resume,
474};
475
476static const struct pci_device_id liquidio_pci_tbl[] = {
477 { /* 68xx */
478 PCI_VENDOR_ID_CAVIUM, 0x91, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
479 },
480 { /* 66xx */
481 PCI_VENDOR_ID_CAVIUM, 0x92, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
482 },
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -0700483 { /* 23xx pf */
484 PCI_VENDOR_ID_CAVIUM, 0x9702, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0
485 },
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700486 {
487 0, 0, 0, 0, 0, 0, 0
488 }
489};
490MODULE_DEVICE_TABLE(pci, liquidio_pci_tbl);
491
492static struct pci_driver liquidio_pci_driver = {
493 .name = "LiquidIO",
494 .id_table = liquidio_pci_tbl,
495 .probe = liquidio_probe,
496 .remove = liquidio_remove,
497 .err_handler = &liquidio_err_handler, /* For AER */
498
499#ifdef CONFIG_PM
500 .suspend = liquidio_suspend,
501 .resume = liquidio_resume,
502#endif
Raghu Vatsavayica6139f2016-11-14 15:54:40 -0800503#ifdef CONFIG_PCI_IOV
504 .sriov_configure = liquidio_enable_sriov,
505#endif
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700506};
507
508/**
509 * \brief register PCI driver
510 */
511static int liquidio_init_pci(void)
512{
513 return pci_register_driver(&liquidio_pci_driver);
514}
515
516/**
517 * \brief unregister PCI driver
518 */
519static void liquidio_deinit_pci(void)
520{
521 pci_unregister_driver(&liquidio_pci_driver);
522}
523
524/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700525 * \brief Stop Tx queues
526 * @param netdev network device
527 */
528static inline void txqs_stop(struct net_device *netdev)
529{
530 if (netif_is_multiqueue(netdev)) {
531 int i;
532
533 for (i = 0; i < netdev->num_tx_queues; i++)
534 netif_stop_subqueue(netdev, i);
535 } else {
536 netif_stop_queue(netdev);
537 }
538}
539
540/**
541 * \brief Start Tx queues
542 * @param netdev network device
543 */
544static inline void txqs_start(struct net_device *netdev)
545{
546 if (netif_is_multiqueue(netdev)) {
547 int i;
548
549 for (i = 0; i < netdev->num_tx_queues; i++)
550 netif_start_subqueue(netdev, i);
551 } else {
552 netif_start_queue(netdev);
553 }
554}
555
556/**
557 * \brief Wake Tx queues
558 * @param netdev network device
559 */
560static inline void txqs_wake(struct net_device *netdev)
561{
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700562 struct lio *lio = GET_LIO(netdev);
563
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700564 if (netif_is_multiqueue(netdev)) {
565 int i;
566
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700567 for (i = 0; i < netdev->num_tx_queues; i++) {
568 int qno = lio->linfo.txpciq[i %
Intiyaz Bashaa82457f2017-08-15 12:46:18 -0700569 lio->oct_dev->num_iqs].s.q_no;
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700570
571 if (__netif_subqueue_stopped(netdev, i)) {
572 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, qno,
573 tx_restart, 1);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700574 netif_wake_subqueue(netdev, i);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700575 }
576 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700577 } else {
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700578 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, lio->txq,
579 tx_restart, 1);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700580 netif_wake_queue(netdev);
581 }
582}
583
584/**
585 * \brief Stop Tx queue
586 * @param netdev network device
587 */
588static void stop_txq(struct net_device *netdev)
589{
590 txqs_stop(netdev);
591}
592
593/**
594 * \brief Start Tx queue
595 * @param netdev network device
596 */
597static void start_txq(struct net_device *netdev)
598{
599 struct lio *lio = GET_LIO(netdev);
600
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700601 if (lio->linfo.link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700602 txqs_start(netdev);
603 return;
604 }
605}
606
607/**
608 * \brief Wake a queue
609 * @param netdev network device
610 * @param q which queue to wake
611 */
612static inline void wake_q(struct net_device *netdev, int q)
613{
614 if (netif_is_multiqueue(netdev))
615 netif_wake_subqueue(netdev, q);
616 else
617 netif_wake_queue(netdev);
618}
619
620/**
621 * \brief Stop a queue
622 * @param netdev network device
623 * @param q which queue to stop
624 */
625static inline void stop_q(struct net_device *netdev, int q)
626{
627 if (netif_is_multiqueue(netdev))
628 netif_stop_subqueue(netdev, q);
629 else
630 netif_stop_queue(netdev);
631}
632
633/**
634 * \brief Check Tx queue status, and take appropriate action
635 * @param lio per-network private data
636 * @returns 0 if full, number of queues woken up otherwise
637 */
638static inline int check_txq_status(struct lio *lio)
639{
640 int ret_val = 0;
641
642 if (netif_is_multiqueue(lio->netdev)) {
643 int numqs = lio->netdev->num_tx_queues;
644 int q, iq = 0;
645
646 /* check each sub-queue state */
647 for (q = 0; q < numqs; q++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700648 iq = lio->linfo.txpciq[q %
Intiyaz Bashaa82457f2017-08-15 12:46:18 -0700649 lio->oct_dev->num_iqs].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700650 if (octnet_iq_is_full(lio->oct_dev, iq))
651 continue;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700652 if (__netif_subqueue_stopped(lio->netdev, q)) {
653 wake_q(lio->netdev, q);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700654 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, iq,
655 tx_restart, 1);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -0700656 ret_val++;
657 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700658 }
659 } else {
660 if (octnet_iq_is_full(lio->oct_dev, lio->txq))
661 return 0;
662 wake_q(lio->netdev, lio->txq);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -0700663 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, lio->txq,
664 tx_restart, 1);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700665 ret_val = 1;
666 }
667 return ret_val;
668}
669
670/**
671 * Remove the node at the head of the list. The list would be empty at
672 * the end of this call if there are no more nodes in the list.
673 */
674static inline struct list_head *list_delete_head(struct list_head *root)
675{
676 struct list_head *node;
677
678 if ((root->prev == root) && (root->next == root))
679 node = NULL;
680 else
681 node = root->next;
682
683 if (node)
684 list_del(node);
685
686 return node;
687}
688
689/**
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700690 * \brief Delete gather lists
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700691 * @param lio per-network private data
692 */
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700693static void delete_glists(struct lio *lio)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700694{
695 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700696 int i;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700697
VSR Burru67e303e2017-03-06 18:45:59 -0800698 kfree(lio->glist_lock);
699 lio->glist_lock = NULL;
700
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700701 if (!lio->glist)
702 return;
703
704 for (i = 0; i < lio->linfo.num_txpciq; i++) {
705 do {
706 g = (struct octnic_gather *)
707 list_delete_head(&lio->glist[i]);
VSR Burru67e303e2017-03-06 18:45:59 -0800708 if (g)
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700709 kfree(g);
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700710 } while (g);
VSR Burru67e303e2017-03-06 18:45:59 -0800711
Felix Manlunas58ad3192017-03-20 19:04:48 -0700712 if (lio->glists_virt_base && lio->glists_virt_base[i] &&
713 lio->glists_dma_base && lio->glists_dma_base[i]) {
VSR Burru67e303e2017-03-06 18:45:59 -0800714 lio_dma_free(lio->oct_dev,
715 lio->glist_entry_size * lio->tx_qsize,
716 lio->glists_virt_base[i],
717 lio->glists_dma_base[i]);
718 }
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700719 }
720
VSR Burru67e303e2017-03-06 18:45:59 -0800721 kfree(lio->glists_virt_base);
722 lio->glists_virt_base = NULL;
723
724 kfree(lio->glists_dma_base);
725 lio->glists_dma_base = NULL;
726
727 kfree(lio->glist);
728 lio->glist = NULL;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700729}
730
731/**
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700732 * \brief Setup gather lists
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700733 * @param lio per-network private data
734 */
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700735static int setup_glists(struct octeon_device *oct, struct lio *lio, int num_iqs)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700736{
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700737 int i, j;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700738 struct octnic_gather *g;
739
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700740 lio->glist_lock = kcalloc(num_iqs, sizeof(*lio->glist_lock),
741 GFP_KERNEL);
742 if (!lio->glist_lock)
VSR Burru67e303e2017-03-06 18:45:59 -0800743 return -ENOMEM;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700744
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700745 lio->glist = kcalloc(num_iqs, sizeof(*lio->glist),
746 GFP_KERNEL);
747 if (!lio->glist) {
VSR Burru67e303e2017-03-06 18:45:59 -0800748 kfree(lio->glist_lock);
749 lio->glist_lock = NULL;
750 return -ENOMEM;
751 }
752
753 lio->glist_entry_size =
754 ROUNDUP8((ROUNDUP4(OCTNIC_MAX_SG) >> 2) * OCT_SG_ENTRY_SIZE);
755
756 /* allocate memory to store virtual and dma base address of
757 * per glist consistent memory
758 */
759 lio->glists_virt_base = kcalloc(num_iqs, sizeof(*lio->glists_virt_base),
760 GFP_KERNEL);
761 lio->glists_dma_base = kcalloc(num_iqs, sizeof(*lio->glists_dma_base),
762 GFP_KERNEL);
763
764 if (!lio->glists_virt_base || !lio->glists_dma_base) {
765 delete_glists(lio);
766 return -ENOMEM;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700767 }
768
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700769 for (i = 0; i < num_iqs; i++) {
VSR Burrub3ca9af2017-03-09 17:03:24 -0800770 int numa_node = dev_to_node(&oct->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700771
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700772 spin_lock_init(&lio->glist_lock[i]);
773
774 INIT_LIST_HEAD(&lio->glist[i]);
775
VSR Burru67e303e2017-03-06 18:45:59 -0800776 lio->glists_virt_base[i] =
777 lio_dma_alloc(oct,
778 lio->glist_entry_size * lio->tx_qsize,
779 &lio->glists_dma_base[i]);
780
781 if (!lio->glists_virt_base[i]) {
782 delete_glists(lio);
783 return -ENOMEM;
784 }
785
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700786 for (j = 0; j < lio->tx_qsize; j++) {
787 g = kzalloc_node(sizeof(*g), GFP_KERNEL,
788 numa_node);
789 if (!g)
790 g = kzalloc(sizeof(*g), GFP_KERNEL);
791 if (!g)
792 break;
793
VSR Burru67e303e2017-03-06 18:45:59 -0800794 g->sg = lio->glists_virt_base[i] +
795 (j * lio->glist_entry_size);
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700796
VSR Burru67e303e2017-03-06 18:45:59 -0800797 g->sg_dma_ptr = lio->glists_dma_base[i] +
798 (j * lio->glist_entry_size);
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700799
800 list_add_tail(&g->list, &lio->glist[i]);
801 }
802
803 if (j != lio->tx_qsize) {
804 delete_glists(lio);
VSR Burru67e303e2017-03-06 18:45:59 -0800805 return -ENOMEM;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -0700806 }
807 }
808
809 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700810}
811
812/**
813 * \brief Print link information
814 * @param netdev network device
815 */
816static void print_link_info(struct net_device *netdev)
817{
818 struct lio *lio = GET_LIO(netdev);
819
Intiyaz Bashad18ca7d2017-08-14 12:01:56 -0700820 if (!ifstate_check(lio, LIO_IFSTATE_RESETTING) &&
821 ifstate_check(lio, LIO_IFSTATE_REGISTERED)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700822 struct oct_link_info *linfo = &lio->linfo;
823
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700824 if (linfo->link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700825 netif_info(lio, link, lio->netdev, "%d Mbps %s Duplex UP\n",
826 linfo->link.s.speed,
827 (linfo->link.s.duplex) ? "Full" : "Half");
828 } else {
829 netif_info(lio, link, lio->netdev, "Link Down\n");
830 }
831 }
832}
833
834/**
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -0700835 * \brief Routine to notify MTU change
836 * @param work work_struct data structure
837 */
838static void octnet_link_status_change(struct work_struct *work)
839{
840 struct cavium_wk *wk = (struct cavium_wk *)work;
841 struct lio *lio = (struct lio *)wk->ctxptr;
842
843 rtnl_lock();
844 call_netdevice_notifiers(NETDEV_CHANGEMTU, lio->netdev);
845 rtnl_unlock();
846}
847
848/**
849 * \brief Sets up the mtu status change work
850 * @param netdev network device
851 */
852static inline int setup_link_status_change_wq(struct net_device *netdev)
853{
854 struct lio *lio = GET_LIO(netdev);
855 struct octeon_device *oct = lio->oct_dev;
856
857 lio->link_status_wq.wq = alloc_workqueue("link-status",
858 WQ_MEM_RECLAIM, 0);
859 if (!lio->link_status_wq.wq) {
860 dev_err(&oct->pci_dev->dev, "unable to create cavium link status wq\n");
861 return -1;
862 }
863 INIT_DELAYED_WORK(&lio->link_status_wq.wk.work,
864 octnet_link_status_change);
865 lio->link_status_wq.wk.ctxptr = lio;
866
867 return 0;
868}
869
870static inline void cleanup_link_status_change_wq(struct net_device *netdev)
871{
872 struct lio *lio = GET_LIO(netdev);
873
874 if (lio->link_status_wq.wq) {
875 cancel_delayed_work_sync(&lio->link_status_wq.wk.work);
876 destroy_workqueue(lio->link_status_wq.wq);
877 }
878}
879
880/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700881 * \brief Update link status
882 * @param netdev network device
883 * @param ls link status structure
884 *
885 * Called on receipt of a link status response from the core application to
886 * update each interface's link status.
887 */
888static inline void update_link_status(struct net_device *netdev,
889 union oct_link_status *ls)
890{
891 struct lio *lio = GET_LIO(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700892 int changed = (lio->linfo.link.u64 != ls->u64);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700893
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700894 lio->linfo.link.u64 = ls->u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700895
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700896 if ((lio->intf_open) && (changed)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700897 print_link_info(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700898 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700899
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700900 if (lio->linfo.link.s.link_up) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700901 netif_carrier_on(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700902 txqs_wake(netdev);
903 } else {
904 netif_carrier_off(netdev);
905 stop_txq(netdev);
906 }
907 }
908}
909
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -0700910/**
911 * lio_sync_octeon_time_cb - callback that is invoked when soft command
912 * sent by lio_sync_octeon_time() has completed successfully or failed
913 *
914 * @oct - octeon device structure
915 * @status - indicates success or failure
916 * @buf - pointer to the command that was sent to firmware
917 **/
918static void lio_sync_octeon_time_cb(struct octeon_device *oct,
919 u32 status, void *buf)
920{
921 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
922
923 if (status)
924 dev_err(&oct->pci_dev->dev,
925 "Failed to sync time to octeon; error=%d\n", status);
926
927 octeon_free_soft_command(oct, sc);
928}
929
930/**
931 * lio_sync_octeon_time - send latest localtime to octeon firmware so that
932 * firmware will correct it's time, in case there is a time skew
933 *
934 * @work: work scheduled to send time update to octeon firmware
935 **/
936static void lio_sync_octeon_time(struct work_struct *work)
937{
938 struct cavium_wk *wk = (struct cavium_wk *)work;
939 struct lio *lio = (struct lio *)wk->ctxptr;
940 struct octeon_device *oct = lio->oct_dev;
941 struct octeon_soft_command *sc;
942 struct timespec64 ts;
943 struct lio_time *lt;
944 int ret;
945
946 sc = octeon_alloc_soft_command(oct, sizeof(struct lio_time), 0, 0);
947 if (!sc) {
948 dev_err(&oct->pci_dev->dev,
949 "Failed to sync time to octeon: soft command allocation failed\n");
950 return;
951 }
952
953 lt = (struct lio_time *)sc->virtdptr;
954
955 /* Get time of the day */
956 getnstimeofday64(&ts);
957 lt->sec = ts.tv_sec;
958 lt->nsec = ts.tv_nsec;
959 octeon_swap_8B_data((u64 *)lt, (sizeof(struct lio_time)) / 8);
960
961 sc->iq_no = lio->linfo.txpciq[0].s.q_no;
962 octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
963 OPCODE_NIC_SYNC_OCTEON_TIME, 0, 0, 0);
964
965 sc->callback = lio_sync_octeon_time_cb;
966 sc->callback_arg = sc;
967 sc->wait_time = 1000;
968
969 ret = octeon_send_soft_command(oct, sc);
970 if (ret == IQ_SEND_FAILED) {
971 dev_err(&oct->pci_dev->dev,
972 "Failed to sync time to octeon: failed to send soft command\n");
973 octeon_free_soft_command(oct, sc);
974 }
975
976 queue_delayed_work(lio->sync_octeon_time_wq.wq,
977 &lio->sync_octeon_time_wq.wk.work,
978 msecs_to_jiffies(LIO_SYNC_OCTEON_TIME_INTERVAL_MS));
979}
980
981/**
982 * setup_sync_octeon_time_wq - Sets up the work to periodically update
983 * local time to octeon firmware
984 *
985 * @netdev - network device which should send time update to firmware
986 **/
987static inline int setup_sync_octeon_time_wq(struct net_device *netdev)
988{
989 struct lio *lio = GET_LIO(netdev);
990 struct octeon_device *oct = lio->oct_dev;
991
992 lio->sync_octeon_time_wq.wq =
993 alloc_workqueue("update-octeon-time", WQ_MEM_RECLAIM, 0);
994 if (!lio->sync_octeon_time_wq.wq) {
995 dev_err(&oct->pci_dev->dev, "Unable to create wq to update octeon time\n");
996 return -1;
997 }
998 INIT_DELAYED_WORK(&lio->sync_octeon_time_wq.wk.work,
999 lio_sync_octeon_time);
1000 lio->sync_octeon_time_wq.wk.ctxptr = lio;
1001 queue_delayed_work(lio->sync_octeon_time_wq.wq,
1002 &lio->sync_octeon_time_wq.wk.work,
1003 msecs_to_jiffies(LIO_SYNC_OCTEON_TIME_INTERVAL_MS));
1004
1005 return 0;
1006}
1007
1008/**
1009 * cleanup_sync_octeon_time_wq - stop scheduling and destroy the work created
1010 * to periodically update local time to octeon firmware
1011 *
1012 * @netdev - network device which should send time update to firmware
1013 **/
1014static inline void cleanup_sync_octeon_time_wq(struct net_device *netdev)
1015{
1016 struct lio *lio = GET_LIO(netdev);
1017 struct cavium_wq *time_wq = &lio->sync_octeon_time_wq;
1018
1019 if (time_wq->wq) {
1020 cancel_delayed_work_sync(&time_wq->wk.work);
1021 destroy_workqueue(time_wq->wq);
1022 }
1023}
1024
Felix Manlunasbb54be52017-04-04 19:26:57 -07001025static struct octeon_device *get_other_octeon_device(struct octeon_device *oct)
1026{
1027 struct octeon_device *other_oct;
1028
1029 other_oct = lio_get_device(oct->octeon_id + 1);
1030
1031 if (other_oct && other_oct->pci_dev) {
1032 int oct_busnum, other_oct_busnum;
1033
1034 oct_busnum = oct->pci_dev->bus->number;
1035 other_oct_busnum = other_oct->pci_dev->bus->number;
1036
1037 if (oct_busnum == other_oct_busnum) {
1038 int oct_slot, other_oct_slot;
1039
1040 oct_slot = PCI_SLOT(oct->pci_dev->devfn);
1041 other_oct_slot = PCI_SLOT(other_oct->pci_dev->devfn);
1042
1043 if (oct_slot == other_oct_slot)
1044 return other_oct;
1045 }
1046 }
1047
1048 return NULL;
1049}
1050
1051static void disable_all_vf_links(struct octeon_device *oct)
1052{
1053 struct net_device *netdev;
1054 int max_vfs, vf, i;
1055
1056 if (!oct)
1057 return;
1058
1059 max_vfs = oct->sriov_info.max_vfs;
1060
1061 for (i = 0; i < oct->ifcount; i++) {
1062 netdev = oct->props[i].netdev;
1063 if (!netdev)
1064 continue;
1065
1066 for (vf = 0; vf < max_vfs; vf++)
1067 liquidio_set_vf_link_state(netdev, vf,
1068 IFLA_VF_LINK_STATE_DISABLE);
1069 }
1070}
1071
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001072static int liquidio_watchdog(void *param)
1073{
Felix Manlunasbb54be52017-04-04 19:26:57 -07001074 bool err_msg_was_printed[LIO_MAX_CORES];
1075 u16 mask_of_crashed_or_stuck_cores = 0;
1076 bool all_vf_links_are_disabled = false;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001077 struct octeon_device *oct = param;
Felix Manlunasbb54be52017-04-04 19:26:57 -07001078 struct octeon_device *other_oct;
1079#ifdef CONFIG_MODULE_UNLOAD
1080 long refcount, vfs_referencing_pf;
1081 u64 vfs_mask1, vfs_mask2;
1082#endif
1083 int core;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001084
Felix Manlunasbb54be52017-04-04 19:26:57 -07001085 memset(err_msg_was_printed, 0, sizeof(err_msg_was_printed));
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001086
1087 while (!kthread_should_stop()) {
Felix Manlunasbb54be52017-04-04 19:26:57 -07001088 /* sleep for a couple of seconds so that we don't hog the CPU */
1089 set_current_state(TASK_INTERRUPTIBLE);
1090 schedule_timeout(msecs_to_jiffies(2000));
1091
1092 mask_of_crashed_or_stuck_cores =
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001093 (u16)octeon_read_csr64(oct, CN23XX_SLI_SCRATCH2);
1094
Felix Manlunasbb54be52017-04-04 19:26:57 -07001095 if (!mask_of_crashed_or_stuck_cores)
1096 continue;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001097
Felix Manlunasbb54be52017-04-04 19:26:57 -07001098 WRITE_ONCE(oct->cores_crashed, true);
1099 other_oct = get_other_octeon_device(oct);
1100 if (other_oct)
1101 WRITE_ONCE(other_oct->cores_crashed, true);
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001102
Felix Manlunasbb54be52017-04-04 19:26:57 -07001103 for (core = 0; core < LIO_MAX_CORES; core++) {
1104 bool core_crashed_or_got_stuck;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001105
Felix Manlunasbb54be52017-04-04 19:26:57 -07001106 core_crashed_or_got_stuck =
1107 (mask_of_crashed_or_stuck_cores
1108 >> core) & 1;
1109
1110 if (core_crashed_or_got_stuck &&
1111 !err_msg_was_printed[core]) {
1112 dev_err(&oct->pci_dev->dev,
1113 "ERROR: Octeon core %d crashed or got stuck! See oct-fwdump for details.\n",
1114 core);
1115 err_msg_was_printed[core] = true;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001116 }
1117 }
1118
Felix Manlunasbb54be52017-04-04 19:26:57 -07001119 if (all_vf_links_are_disabled)
1120 continue;
1121
1122 disable_all_vf_links(oct);
1123 disable_all_vf_links(other_oct);
1124 all_vf_links_are_disabled = true;
1125
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001126#ifdef CONFIG_MODULE_UNLOAD
Felix Manlunasbb54be52017-04-04 19:26:57 -07001127 vfs_mask1 = READ_ONCE(oct->sriov_info.vf_drv_loaded_mask);
1128 vfs_mask2 = READ_ONCE(other_oct->sriov_info.vf_drv_loaded_mask);
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001129
Felix Manlunasbb54be52017-04-04 19:26:57 -07001130 vfs_referencing_pf = hweight64(vfs_mask1);
1131 vfs_referencing_pf += hweight64(vfs_mask2);
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001132
Felix Manlunasbb54be52017-04-04 19:26:57 -07001133 refcount = module_refcount(THIS_MODULE);
1134 if (refcount >= vfs_referencing_pf) {
1135 while (vfs_referencing_pf) {
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001136 module_put(THIS_MODULE);
Felix Manlunasbb54be52017-04-04 19:26:57 -07001137 vfs_referencing_pf--;
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001138 }
1139 }
1140#endif
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001141 }
1142
1143 return 0;
1144}
1145
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001146/**
1147 * \brief PCI probe handler
1148 * @param pdev PCI device structure
1149 * @param ent unused
1150 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07001151static int
1152liquidio_probe(struct pci_dev *pdev,
1153 const struct pci_device_id *ent __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001154{
1155 struct octeon_device *oct_dev = NULL;
1156 struct handshake *hs;
1157
1158 oct_dev = octeon_allocate_device(pdev->device,
1159 sizeof(struct octeon_device_priv));
1160 if (!oct_dev) {
1161 dev_err(&pdev->dev, "Unable to allocate device\n");
1162 return -ENOMEM;
1163 }
1164
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001165 if (pdev->device == OCTEON_CN23XX_PF_VID)
1166 oct_dev->msix_on = LIO_FLAG_MSIX_ENABLED;
1167
Intiyaz Bashaaa69ff92017-08-11 11:22:09 -07001168 /* Enable PTP for 6XXX Device */
1169 if (((pdev->device == OCTEON_CN66XX) ||
1170 (pdev->device == OCTEON_CN68XX)))
1171 oct_dev->ptp_enable = true;
1172 else
1173 oct_dev->ptp_enable = false;
1174
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001175 dev_info(&pdev->dev, "Initializing device %x:%x.\n",
1176 (u32)pdev->vendor, (u32)pdev->device);
1177
1178 /* Assign octeon_device for this device to the private data area. */
1179 pci_set_drvdata(pdev, oct_dev);
1180
1181 /* set linux specific device pointer */
1182 oct_dev->pci_dev = (void *)pdev;
1183
1184 hs = &handshake[oct_dev->octeon_id];
1185 init_completion(&hs->init);
1186 init_completion(&hs->started);
1187 hs->pci_dev = pdev;
1188
1189 if (oct_dev->octeon_id == 0)
1190 /* first LiquidIO NIC is detected */
1191 complete(&first_stage);
1192
1193 if (octeon_device_init(oct_dev)) {
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001194 complete(&hs->init);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001195 liquidio_remove(pdev);
1196 return -ENOMEM;
1197 }
1198
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001199 if (OCTEON_CN23XX_PF(oct_dev)) {
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001200 u8 bus, device, function;
1201
Felix Manlunas392209f2017-10-25 18:04:56 -07001202 if (atomic_read(oct_dev->adapter_refcount) == 1) {
1203 /* Each NIC gets one watchdog kernel thread. The first
1204 * PF (of each NIC) that gets pci_driver->probe()'d
1205 * creates that thread.
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001206 */
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001207 bus = pdev->bus->number;
1208 device = PCI_SLOT(pdev->devfn);
1209 function = PCI_FUNC(pdev->devfn);
1210 oct_dev->watchdog_task = kthread_create(
1211 liquidio_watchdog, oct_dev,
1212 "liowd/%02hhx:%02hhx.%hhx", bus, device, function);
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001213 if (!IS_ERR(oct_dev->watchdog_task)) {
1214 wake_up_process(oct_dev->watchdog_task);
1215 } else {
1216 oct_dev->watchdog_task = NULL;
1217 dev_err(&oct_dev->pci_dev->dev,
1218 "failed to create kernel_thread\n");
1219 liquidio_remove(pdev);
1220 return -1;
1221 }
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001222 }
1223 }
1224
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07001225 oct_dev->rx_pause = 1;
1226 oct_dev->tx_pause = 1;
1227
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001228 dev_dbg(&oct_dev->pci_dev->dev, "Device is ready\n");
1229
1230 return 0;
1231}
1232
Rick Farrington088b8742017-09-22 17:12:43 -07001233static bool fw_type_is_auto(void)
Felix Manlunas7cc61db2017-03-23 13:26:28 -07001234{
Rick Farrington088b8742017-09-22 17:12:43 -07001235 return strncmp(fw_type, LIO_FW_NAME_TYPE_AUTO,
1236 sizeof(LIO_FW_NAME_TYPE_AUTO)) == 0;
Felix Manlunas7cc61db2017-03-23 13:26:28 -07001237}
1238
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001239/**
Rick Farrington70535352017-08-17 23:11:25 -07001240 * \brief PCI FLR for each Octeon device.
1241 * @param oct octeon device
1242 */
1243static void octeon_pci_flr(struct octeon_device *oct)
1244{
1245 int rc;
1246
1247 pci_save_state(oct->pci_dev);
1248
1249 pci_cfg_access_lock(oct->pci_dev);
1250
1251 /* Quiesce the device completely */
1252 pci_write_config_word(oct->pci_dev, PCI_COMMAND,
1253 PCI_COMMAND_INTX_DISABLE);
1254
1255 rc = __pci_reset_function_locked(oct->pci_dev);
1256
1257 if (rc != 0)
1258 dev_err(&oct->pci_dev->dev, "Error %d resetting PCI function %d\n",
1259 rc, oct->pf_num);
1260
1261 pci_cfg_access_unlock(oct->pci_dev);
1262
1263 pci_restore_state(oct->pci_dev);
1264}
1265
1266/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001267 *\brief Destroy resources associated with octeon device
1268 * @param pdev PCI device structure
1269 * @param ent unused
1270 */
1271static void octeon_destroy_resources(struct octeon_device *oct)
1272{
Rick Farringtone1e3ce62017-05-16 11:14:50 -07001273 int i, refcount;
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001274 struct msix_entry *msix_entries;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001275 struct octeon_device_priv *oct_priv =
1276 (struct octeon_device_priv *)oct->priv;
1277
1278 struct handshake *hs;
1279
1280 switch (atomic_read(&oct->status)) {
1281 case OCT_DEV_RUNNING:
1282 case OCT_DEV_CORE_OK:
1283
1284 /* No more instructions will be forwarded. */
1285 atomic_set(&oct->status, OCT_DEV_IN_RESET);
1286
1287 oct->app_mode = CVM_DRV_INVALID_APP;
1288 dev_dbg(&oct->pci_dev->dev, "Device state is now %s\n",
1289 lio_get_state_string(&oct->status));
1290
1291 schedule_timeout_uninterruptible(HZ / 10);
1292
1293 /* fallthrough */
1294 case OCT_DEV_HOST_OK:
1295
1296 /* fallthrough */
1297 case OCT_DEV_CONSOLE_INIT_DONE:
1298 /* Remove any consoles */
1299 octeon_remove_consoles(oct);
1300
1301 /* fallthrough */
1302 case OCT_DEV_IO_QUEUES_DONE:
1303 if (wait_for_pending_requests(oct))
1304 dev_err(&oct->pci_dev->dev, "There were pending requests\n");
1305
1306 if (lio_wait_for_instr_fetch(oct))
1307 dev_err(&oct->pci_dev->dev, "IQ had pending instructions\n");
1308
1309 /* Disable the input and output queues now. No more packets will
1310 * arrive from Octeon, but we should wait for all packet
1311 * processing to finish.
1312 */
1313 oct->fn_list.disable_io_queues(oct);
1314
1315 if (lio_wait_for_oq_pkts(oct))
1316 dev_err(&oct->pci_dev->dev, "OQ had pending packets\n");
1317
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001318 /* fallthrough */
1319 case OCT_DEV_INTR_SET_DONE:
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001320 /* Disable interrupts */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001321 oct->fn_list.disable_interrupt(oct, OCTEON_ALL_INTR);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001322
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001323 if (oct->msix_on) {
1324 msix_entries = (struct msix_entry *)oct->msix_entries;
1325 for (i = 0; i < oct->num_msix_irqs - 1; i++) {
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07001326 if (oct->ioq_vector[i].vector) {
1327 /* clear the affinity_cpumask */
1328 irq_set_affinity_hint(
1329 msix_entries[i].vector,
1330 NULL);
1331 free_irq(msix_entries[i].vector,
1332 &oct->ioq_vector[i]);
1333 oct->ioq_vector[i].vector = 0;
1334 }
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001335 }
1336 /* non-iov vector's argument is oct struct */
1337 free_irq(msix_entries[i].vector, oct);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001338
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001339 pci_disable_msix(oct->pci_dev);
1340 kfree(oct->msix_entries);
1341 oct->msix_entries = NULL;
1342 } else {
1343 /* Release the interrupt line */
1344 free_irq(oct->pci_dev->irq, oct);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001345
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001346 if (oct->flags & LIO_FLAG_MSI_ENABLED)
1347 pci_disable_msi(oct->pci_dev);
1348 }
1349
Rick Farrington0c88a762017-03-13 12:58:04 -07001350 kfree(oct->irq_name_storage);
1351 oct->irq_name_storage = NULL;
1352
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001353 /* fallthrough */
1354 case OCT_DEV_MSIX_ALLOC_VECTOR_DONE:
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001355 if (OCTEON_CN23XX_PF(oct))
1356 octeon_free_ioq_vector(oct);
Raghu Vatsavayi5d655562016-11-14 15:54:42 -08001357
1358 /* fallthrough */
1359 case OCT_DEV_MBOX_SETUP_DONE:
1360 if (OCTEON_CN23XX_PF(oct))
1361 oct->fn_list.free_mbox(oct);
1362
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001363 /* fallthrough */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001364 case OCT_DEV_IN_RESET:
1365 case OCT_DEV_DROQ_INIT_DONE:
Raghu Vatsavayi763185a2016-11-14 15:54:45 -08001366 /* Wait for any pending operations */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001367 mdelay(100);
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001368 for (i = 0; i < MAX_OCTEON_OUTPUT_QUEUES(oct); i++) {
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07001369 if (!(oct->io_qmask.oq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001370 continue;
1371 octeon_delete_droq(oct, i);
1372 }
1373
1374 /* Force any pending handshakes to complete */
1375 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
1376 hs = &handshake[i];
1377
1378 if (hs->pci_dev) {
1379 handshake[oct->octeon_id].init_ok = 0;
1380 complete(&handshake[oct->octeon_id].init);
1381 handshake[oct->octeon_id].started_ok = 0;
1382 complete(&handshake[oct->octeon_id].started);
1383 }
1384 }
1385
1386 /* fallthrough */
1387 case OCT_DEV_RESP_LIST_INIT_DONE:
1388 octeon_delete_response_list(oct);
1389
1390 /* fallthrough */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001391 case OCT_DEV_INSTR_QUEUE_INIT_DONE:
Raghu Vatsavayi63da8402016-06-21 22:53:03 -07001392 for (i = 0; i < MAX_OCTEON_INSTR_QUEUES(oct); i++) {
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001393 if (!(oct->io_qmask.iq & BIT_ULL(i)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001394 continue;
1395 octeon_delete_instr_queue(oct, i);
1396 }
Raghu Vatsavayica6139f2016-11-14 15:54:40 -08001397#ifdef CONFIG_PCI_IOV
1398 if (oct->sriov_info.sriov_enabled)
1399 pci_disable_sriov(oct->pci_dev);
1400#endif
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07001401 /* fallthrough */
1402 case OCT_DEV_SC_BUFF_POOL_INIT_DONE:
1403 octeon_free_sc_buffer_pool(oct);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001404
1405 /* fallthrough */
1406 case OCT_DEV_DISPATCH_INIT_DONE:
1407 octeon_delete_dispatch_list(oct);
1408 cancel_delayed_work_sync(&oct->nic_poll_work.work);
1409
1410 /* fallthrough */
1411 case OCT_DEV_PCI_MAP_DONE:
Rick Farringtone1e3ce62017-05-16 11:14:50 -07001412 refcount = octeon_deregister_device(oct);
1413
Rick Farrington70535352017-08-17 23:11:25 -07001414 /* Soft reset the octeon device before exiting.
1415 * However, if fw was loaded from card (i.e. autoboot),
1416 * perform an FLR instead.
1417 * Implementation note: only soft-reset the device
1418 * if it is a CN6XXX OR the LAST CN23XX device.
1419 */
Rick Farrington088b8742017-09-22 17:12:43 -07001420 if (atomic_read(oct->adapter_fw_state) == FW_IS_PRELOADED)
Rick Farrington70535352017-08-17 23:11:25 -07001421 octeon_pci_flr(oct);
1422 else if (OCTEON_CN6XXX(oct) || !refcount)
1423 oct->fn_list.soft_reset(oct);
Raghu Vatsavayi60b48c52016-06-21 22:53:09 -07001424
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001425 octeon_unmap_pci_barx(oct, 0);
1426 octeon_unmap_pci_barx(oct, 1);
1427
1428 /* fallthrough */
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001429 case OCT_DEV_PCI_ENABLE_DONE:
1430 pci_clear_master(oct->pci_dev);
Raghu Vatsavayi60b48c52016-06-21 22:53:09 -07001431 /* Disable the device, releasing the PCI INT */
1432 pci_disable_device(oct->pci_dev);
1433
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001434 /* fallthrough */
1435 case OCT_DEV_BEGIN_STATE:
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001436 /* Nothing to be done here either */
1437 break;
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07001438 } /* end switch (oct->status) */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001439
1440 tasklet_kill(&oct_priv->droq_tasklet);
1441}
1442
1443/**
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001444 * \brief Callback for rx ctrl
1445 * @param status status of request
1446 * @param buf pointer to resp structure
1447 */
1448static void rx_ctl_callback(struct octeon_device *oct,
1449 u32 status,
1450 void *buf)
1451{
1452 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
1453 struct liquidio_rx_ctl_context *ctx;
1454
1455 ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr;
1456
1457 oct = lio_get_device(ctx->octeon_id);
1458 if (status)
1459 dev_err(&oct->pci_dev->dev, "rx ctl instruction failed. Status: %llx\n",
1460 CVM_CAST64(status));
1461 WRITE_ONCE(ctx->cond, 1);
1462
1463 /* This barrier is required to be sure that the response has been
1464 * written fully before waking up the handler
1465 */
1466 wmb();
1467
1468 wake_up_interruptible(&ctx->wc);
1469}
1470
1471/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001472 * \brief Send Rx control command
1473 * @param lio per-network private data
1474 * @param start_stop whether to start or stop
1475 */
1476static void send_rx_ctrl_cmd(struct lio *lio, int start_stop)
1477{
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001478 struct octeon_soft_command *sc;
1479 struct liquidio_rx_ctl_context *ctx;
1480 union octnet_cmd *ncmd;
1481 int ctx_size = sizeof(struct liquidio_rx_ctl_context);
1482 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1483 int retval;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001484
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001485 if (oct->props[lio->ifidx].rx_on == start_stop)
1486 return;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001487
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001488 sc = (struct octeon_soft_command *)
1489 octeon_alloc_soft_command(oct, OCTNET_CMD_SIZE,
1490 16, ctx_size);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001491
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001492 ncmd = (union octnet_cmd *)sc->virtdptr;
1493 ctx = (struct liquidio_rx_ctl_context *)sc->ctxptr;
1494
1495 WRITE_ONCE(ctx->cond, 0);
1496 ctx->octeon_id = lio_get_device_id(oct);
1497 init_waitqueue_head(&ctx->wc);
1498
1499 ncmd->u64 = 0;
1500 ncmd->s.cmd = OCTNET_CMD_RX_CTL;
1501 ncmd->s.param1 = start_stop;
1502
1503 octeon_swap_8B_data((u64 *)ncmd, (OCTNET_CMD_SIZE >> 3));
1504
1505 sc->iq_no = lio->linfo.txpciq[0].s.q_no;
1506
1507 octeon_prepare_soft_command(oct, sc, OPCODE_NIC,
1508 OPCODE_NIC_CMD, 0, 0, 0);
1509
1510 sc->callback = rx_ctl_callback;
1511 sc->callback_arg = sc;
1512 sc->wait_time = 5000;
1513
1514 retval = octeon_send_soft_command(oct, sc);
1515 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001516 netif_info(lio, rx_err, lio->netdev, "Failed to send RX Control message\n");
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001517 } else {
1518 /* Sleep on a wait queue till the cond flag indicates that the
1519 * response arrived or timed-out.
1520 */
1521 if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR)
1522 return;
1523 oct->props[lio->ifidx].rx_on = start_stop;
1524 }
1525
1526 octeon_free_soft_command(oct, sc);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001527}
1528
1529/**
1530 * \brief Destroy NIC device interface
1531 * @param oct octeon device
1532 * @param ifidx which interface to destroy
1533 *
1534 * Cleanup associated with each interface for an Octeon device when NIC
1535 * module is being unloaded or if initialization fails during load.
1536 */
1537static void liquidio_destroy_nic_device(struct octeon_device *oct, int ifidx)
1538{
1539 struct net_device *netdev = oct->props[ifidx].netdev;
1540 struct lio *lio;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001541 struct napi_struct *napi, *n;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001542
1543 if (!netdev) {
1544 dev_err(&oct->pci_dev->dev, "%s No netdevice ptr for index %d\n",
1545 __func__, ifidx);
1546 return;
1547 }
1548
1549 lio = GET_LIO(netdev);
1550
1551 dev_dbg(&oct->pci_dev->dev, "NIC device cleanup\n");
1552
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001553 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING)
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07001554 liquidio_stop(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001555
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001556 if (oct->props[lio->ifidx].napi_enabled == 1) {
1557 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1558 napi_disable(napi);
1559
1560 oct->props[lio->ifidx].napi_enabled = 0;
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07001561
1562 if (OCTEON_CN23XX_PF(oct))
1563 oct->droq[0]->ops.poll_mode = 0;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07001564 }
1565
Intiyaz Basha42013e92017-08-08 19:34:28 -07001566 /* Delete NAPI */
1567 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
1568 netif_napi_del(napi);
1569
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001570 if (atomic_read(&lio->ifstate) & LIO_IFSTATE_REGISTERED)
1571 unregister_netdev(netdev);
1572
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -07001573 cleanup_sync_octeon_time_wq(netdev);
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07001574 cleanup_link_status_change_wq(netdev);
1575
Satanand Burla031d4f12017-03-22 11:31:13 -07001576 cleanup_rx_oom_poll_fn(netdev);
1577
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001578 delete_glists(lio);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001579
1580 free_netdev(netdev);
1581
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07001582 oct->props[ifidx].gmxport = -1;
1583
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001584 oct->props[ifidx].netdev = NULL;
1585}
1586
1587/**
1588 * \brief Stop complete NIC functionality
1589 * @param oct octeon device
1590 */
1591static int liquidio_stop_nic_module(struct octeon_device *oct)
1592{
1593 int i, j;
1594 struct lio *lio;
1595
1596 dev_dbg(&oct->pci_dev->dev, "Stopping network interfaces\n");
1597 if (!oct->ifcount) {
1598 dev_err(&oct->pci_dev->dev, "Init for Octeon was not completed\n");
1599 return 1;
1600 }
1601
Raghu Vatsavayi60441882016-06-21 22:53:08 -07001602 spin_lock_bh(&oct->cmd_resp_wqlock);
1603 oct->cmd_resp_state = OCT_DRV_OFFLINE;
1604 spin_unlock_bh(&oct->cmd_resp_wqlock);
1605
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001606 for (i = 0; i < oct->ifcount; i++) {
1607 lio = GET_LIO(oct->props[i].netdev);
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07001608 for (j = 0; j < oct->num_oqs; j++)
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001609 octeon_unregister_droq_ops(oct,
1610 lio->linfo.rxpciq[j].s.q_no);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001611 }
1612
1613 for (i = 0; i < oct->ifcount; i++)
1614 liquidio_destroy_nic_device(oct, i);
1615
1616 dev_dbg(&oct->pci_dev->dev, "Network interfaces stopped\n");
1617 return 0;
1618}
1619
1620/**
1621 * \brief Cleans up resources at unload time
1622 * @param pdev PCI device structure
1623 */
1624static void liquidio_remove(struct pci_dev *pdev)
1625{
1626 struct octeon_device *oct_dev = pci_get_drvdata(pdev);
1627
1628 dev_dbg(&oct_dev->pci_dev->dev, "Stopping device\n");
1629
Raghu Vatsavayi9ff1a9b2016-09-01 11:16:09 -07001630 if (oct_dev->watchdog_task)
1631 kthread_stop(oct_dev->watchdog_task);
1632
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001633 if (oct_dev->app_mode && (oct_dev->app_mode == CVM_DRV_NIC_APP))
1634 liquidio_stop_nic_module(oct_dev);
1635
1636 /* Reset the octeon device and cleanup all memory allocated for
1637 * the octeon device by driver.
1638 */
1639 octeon_destroy_resources(oct_dev);
1640
1641 dev_info(&oct_dev->pci_dev->dev, "Device removed\n");
1642
1643 /* This octeon device has been removed. Update the global
1644 * data structure to reflect this. Free the device structure.
1645 */
1646 octeon_free_device_mem(oct_dev);
1647}
1648
1649/**
1650 * \brief Identify the Octeon device and to map the BAR address space
1651 * @param oct octeon device
1652 */
1653static int octeon_chip_specific_setup(struct octeon_device *oct)
1654{
1655 u32 dev_id, rev_id;
1656 int ret = 1;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001657 char *s;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001658
1659 pci_read_config_dword(oct->pci_dev, 0, &dev_id);
1660 pci_read_config_dword(oct->pci_dev, 8, &rev_id);
1661 oct->rev_id = rev_id & 0xff;
1662
1663 switch (dev_id) {
1664 case OCTEON_CN68XX_PCIID:
1665 oct->chip_id = OCTEON_CN68XX;
1666 ret = lio_setup_cn68xx_octeon_device(oct);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001667 s = "CN68XX";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001668 break;
1669
1670 case OCTEON_CN66XX_PCIID:
1671 oct->chip_id = OCTEON_CN66XX;
1672 ret = lio_setup_cn66xx_octeon_device(oct);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001673 s = "CN66XX";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001674 break;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001675
Raghu Vatsavayi72c00912016-08-31 11:03:25 -07001676 case OCTEON_CN23XX_PCIID_PF:
1677 oct->chip_id = OCTEON_CN23XX_PF_VID;
1678 ret = setup_cn23xx_octeon_pf_device(oct);
Rick Farrington0c45d7f2017-08-18 18:21:49 -07001679 if (ret)
1680 break;
Derek Chicklescf19a8c2017-08-01 15:05:07 -07001681#ifdef CONFIG_PCI_IOV
1682 if (!ret)
1683 pci_sriov_set_totalvfs(oct->pci_dev,
1684 oct->sriov_info.max_vfs);
1685#endif
Raghu Vatsavayi72c00912016-08-31 11:03:25 -07001686 s = "CN23XX";
1687 break;
1688
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001689 default:
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001690 s = "?";
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001691 dev_err(&oct->pci_dev->dev, "Unknown device found (dev_id: %x)\n",
1692 dev_id);
1693 }
1694
1695 if (!ret)
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001696 dev_info(&oct->pci_dev->dev, "%s PASS%d.%d %s Version: %s\n", s,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001697 OCTEON_MAJOR_REV(oct),
1698 OCTEON_MINOR_REV(oct),
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07001699 octeon_get_conf(oct)->card_name,
1700 LIQUIDIO_VERSION);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001701
1702 return ret;
1703}
1704
1705/**
1706 * \brief PCI initialization for each Octeon device.
1707 * @param oct octeon device
1708 */
1709static int octeon_pci_os_setup(struct octeon_device *oct)
1710{
1711 /* setup PCI stuff first */
1712 if (pci_enable_device(oct->pci_dev)) {
1713 dev_err(&oct->pci_dev->dev, "pci_enable_device failed\n");
1714 return 1;
1715 }
1716
1717 if (dma_set_mask_and_coherent(&oct->pci_dev->dev, DMA_BIT_MASK(64))) {
1718 dev_err(&oct->pci_dev->dev, "Unexpected DMA device capability\n");
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08001719 pci_disable_device(oct->pci_dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001720 return 1;
1721 }
1722
1723 /* Enable PCI DMA Master. */
1724 pci_set_master(oct->pci_dev);
1725
1726 return 0;
1727}
1728
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001729static inline int skb_iq(struct lio *lio, struct sk_buff *skb)
1730{
1731 int q = 0;
1732
1733 if (netif_is_multiqueue(lio->netdev))
1734 q = skb->queue_mapping % lio->linfo.num_txpciq;
1735
1736 return q;
1737}
1738
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001739/**
1740 * \brief Check Tx queue state for a given network buffer
1741 * @param lio per-network private data
1742 * @param skb network buffer
1743 */
1744static inline int check_txq_state(struct lio *lio, struct sk_buff *skb)
1745{
1746 int q = 0, iq = 0;
1747
1748 if (netif_is_multiqueue(lio->netdev)) {
1749 q = skb->queue_mapping;
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07001750 iq = lio->linfo.txpciq[(q % lio->oct_dev->num_iqs)].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001751 } else {
1752 iq = lio->txq;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001753 q = iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001754 }
1755
1756 if (octnet_iq_is_full(lio->oct_dev, iq))
1757 return 0;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001758
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07001759 if (__netif_subqueue_stopped(lio->netdev, q)) {
1760 INCR_INSTRQUEUE_PKT_COUNT(lio->oct_dev, iq, tx_restart, 1);
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07001761 wake_q(lio->netdev, q);
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07001762 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001763 return 1;
1764}
1765
1766/**
1767 * \brief Unmap and free network buffer
1768 * @param buf buffer
1769 */
1770static void free_netbuf(void *buf)
1771{
1772 struct sk_buff *skb;
1773 struct octnet_buf_free_info *finfo;
1774 struct lio *lio;
1775
1776 finfo = (struct octnet_buf_free_info *)buf;
1777 skb = finfo->skb;
1778 lio = finfo->lio;
1779
1780 dma_unmap_single(&lio->oct_dev->pci_dev->dev, finfo->dptr, skb->len,
1781 DMA_TO_DEVICE);
1782
1783 check_txq_state(lio, skb);
1784
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001785 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001786}
1787
1788/**
1789 * \brief Unmap and free gather buffer
1790 * @param buf buffer
1791 */
1792static void free_netsgbuf(void *buf)
1793{
1794 struct octnet_buf_free_info *finfo;
1795 struct sk_buff *skb;
1796 struct lio *lio;
1797 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001798 int i, frags, iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001799
1800 finfo = (struct octnet_buf_free_info *)buf;
1801 skb = finfo->skb;
1802 lio = finfo->lio;
1803 g = finfo->g;
1804 frags = skb_shinfo(skb)->nr_frags;
1805
1806 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1807 g->sg[0].ptr[0], (skb->len - skb->data_len),
1808 DMA_TO_DEVICE);
1809
1810 i = 1;
1811 while (frags--) {
1812 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1813
1814 pci_unmap_page((lio->oct_dev)->pci_dev,
1815 g->sg[(i >> 2)].ptr[(i & 3)],
1816 frag->size, DMA_TO_DEVICE);
1817 i++;
1818 }
1819
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001820 iq = skb_iq(lio, skb);
1821 spin_lock(&lio->glist_lock[iq]);
1822 list_add_tail(&g->list, &lio->glist[iq]);
1823 spin_unlock(&lio->glist_lock[iq]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001824
1825 check_txq_state(lio, skb); /* mq support: sub-queue state check */
1826
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07001827 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001828}
1829
1830/**
1831 * \brief Unmap and free gather buffer with response
1832 * @param buf buffer
1833 */
1834static void free_netsgbuf_with_resp(void *buf)
1835{
1836 struct octeon_soft_command *sc;
1837 struct octnet_buf_free_info *finfo;
1838 struct sk_buff *skb;
1839 struct lio *lio;
1840 struct octnic_gather *g;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001841 int i, frags, iq;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001842
1843 sc = (struct octeon_soft_command *)buf;
1844 skb = (struct sk_buff *)sc->callback_arg;
1845 finfo = (struct octnet_buf_free_info *)&skb->cb;
1846
1847 lio = finfo->lio;
1848 g = finfo->g;
1849 frags = skb_shinfo(skb)->nr_frags;
1850
1851 dma_unmap_single(&lio->oct_dev->pci_dev->dev,
1852 g->sg[0].ptr[0], (skb->len - skb->data_len),
1853 DMA_TO_DEVICE);
1854
1855 i = 1;
1856 while (frags--) {
1857 struct skb_frag_struct *frag = &skb_shinfo(skb)->frags[i - 1];
1858
1859 pci_unmap_page((lio->oct_dev)->pci_dev,
1860 g->sg[(i >> 2)].ptr[(i & 3)],
1861 frag->size, DMA_TO_DEVICE);
1862 i++;
1863 }
1864
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07001865 iq = skb_iq(lio, skb);
1866
1867 spin_lock(&lio->glist_lock[iq]);
1868 list_add_tail(&g->list, &lio->glist[iq]);
1869 spin_unlock(&lio->glist_lock[iq]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001870
1871 /* Don't free the skb yet */
1872
1873 check_txq_state(lio, skb);
1874}
1875
1876/**
1877 * \brief Adjust ptp frequency
1878 * @param ptp PTP clock info
1879 * @param ppb how much to adjust by, in parts-per-billion
1880 */
1881static int liquidio_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
1882{
1883 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1884 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1885 u64 comp, delta;
1886 unsigned long flags;
1887 bool neg_adj = false;
1888
1889 if (ppb < 0) {
1890 neg_adj = true;
1891 ppb = -ppb;
1892 }
1893
1894 /* The hardware adds the clock compensation value to the
1895 * PTP clock on every coprocessor clock cycle, so we
1896 * compute the delta in terms of coprocessor clocks.
1897 */
1898 delta = (u64)ppb << 32;
1899 do_div(delta, oct->coproc_clock_rate);
1900
1901 spin_lock_irqsave(&lio->ptp_lock, flags);
1902 comp = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_COMP);
1903 if (neg_adj)
1904 comp -= delta;
1905 else
1906 comp += delta;
1907 lio_pci_writeq(oct, comp, CN6XXX_MIO_PTP_CLOCK_COMP);
1908 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1909
1910 return 0;
1911}
1912
1913/**
1914 * \brief Adjust ptp time
1915 * @param ptp PTP clock info
1916 * @param delta how much to adjust by, in nanosecs
1917 */
1918static int liquidio_ptp_adjtime(struct ptp_clock_info *ptp, s64 delta)
1919{
1920 unsigned long flags;
1921 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1922
1923 spin_lock_irqsave(&lio->ptp_lock, flags);
1924 lio->ptp_adjust += delta;
1925 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1926
1927 return 0;
1928}
1929
1930/**
1931 * \brief Get hardware clock time, including any adjustment
1932 * @param ptp PTP clock info
1933 * @param ts timespec
1934 */
1935static int liquidio_ptp_gettime(struct ptp_clock_info *ptp,
1936 struct timespec64 *ts)
1937{
1938 u64 ns;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001939 unsigned long flags;
1940 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1941 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1942
1943 spin_lock_irqsave(&lio->ptp_lock, flags);
1944 ns = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_HI);
1945 ns += lio->ptp_adjust;
1946 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1947
Kefeng Wang286af312016-01-27 17:34:37 +08001948 *ts = ns_to_timespec64(ns);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001949
1950 return 0;
1951}
1952
1953/**
1954 * \brief Set hardware clock time. Reset adjustment
1955 * @param ptp PTP clock info
1956 * @param ts timespec
1957 */
1958static int liquidio_ptp_settime(struct ptp_clock_info *ptp,
1959 const struct timespec64 *ts)
1960{
1961 u64 ns;
1962 unsigned long flags;
1963 struct lio *lio = container_of(ptp, struct lio, ptp_info);
1964 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1965
Arnd Bergmanne7ad9792017-10-12 11:48:31 +02001966 ns = timespec64_to_ns(ts);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001967
1968 spin_lock_irqsave(&lio->ptp_lock, flags);
1969 lio_pci_writeq(oct, ns, CN6XXX_MIO_PTP_CLOCK_HI);
1970 lio->ptp_adjust = 0;
1971 spin_unlock_irqrestore(&lio->ptp_lock, flags);
1972
1973 return 0;
1974}
1975
1976/**
1977 * \brief Check if PTP is enabled
1978 * @param ptp PTP clock info
1979 * @param rq request
1980 * @param on is it on
1981 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07001982static int
1983liquidio_ptp_enable(struct ptp_clock_info *ptp __attribute__((unused)),
1984 struct ptp_clock_request *rq __attribute__((unused)),
1985 int on __attribute__((unused)))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001986{
1987 return -EOPNOTSUPP;
1988}
1989
1990/**
1991 * \brief Open PTP clock source
1992 * @param netdev network device
1993 */
1994static void oct_ptp_open(struct net_device *netdev)
1995{
1996 struct lio *lio = GET_LIO(netdev);
1997 struct octeon_device *oct = (struct octeon_device *)lio->oct_dev;
1998
1999 spin_lock_init(&lio->ptp_lock);
2000
2001 snprintf(lio->ptp_info.name, 16, "%s", netdev->name);
2002 lio->ptp_info.owner = THIS_MODULE;
2003 lio->ptp_info.max_adj = 250000000;
2004 lio->ptp_info.n_alarm = 0;
2005 lio->ptp_info.n_ext_ts = 0;
2006 lio->ptp_info.n_per_out = 0;
2007 lio->ptp_info.pps = 0;
2008 lio->ptp_info.adjfreq = liquidio_ptp_adjfreq;
2009 lio->ptp_info.adjtime = liquidio_ptp_adjtime;
2010 lio->ptp_info.gettime64 = liquidio_ptp_gettime;
2011 lio->ptp_info.settime64 = liquidio_ptp_settime;
2012 lio->ptp_info.enable = liquidio_ptp_enable;
2013
2014 lio->ptp_adjust = 0;
2015
2016 lio->ptp_clock = ptp_clock_register(&lio->ptp_info,
2017 &oct->pci_dev->dev);
2018
2019 if (IS_ERR(lio->ptp_clock))
2020 lio->ptp_clock = NULL;
2021}
2022
2023/**
2024 * \brief Init PTP clock
2025 * @param oct octeon device
2026 */
2027static void liquidio_ptp_init(struct octeon_device *oct)
2028{
2029 u64 clock_comp, cfg;
2030
2031 clock_comp = (u64)NSEC_PER_SEC << 32;
2032 do_div(clock_comp, oct->coproc_clock_rate);
2033 lio_pci_writeq(oct, clock_comp, CN6XXX_MIO_PTP_CLOCK_COMP);
2034
2035 /* Enable */
2036 cfg = lio_pci_readq(oct, CN6XXX_MIO_PTP_CLOCK_CFG);
2037 lio_pci_writeq(oct, cfg | 0x01, CN6XXX_MIO_PTP_CLOCK_CFG);
2038}
2039
2040/**
2041 * \brief Load firmware to device
2042 * @param oct octeon device
2043 *
2044 * Maps device to firmware filename, requests firmware, and downloads it
2045 */
2046static int load_firmware(struct octeon_device *oct)
2047{
2048 int ret = 0;
2049 const struct firmware *fw;
2050 char fw_name[LIO_MAX_FW_FILENAME_LEN];
2051 char *tmp_fw_type;
2052
Rick Farrington429cbf62017-09-22 17:12:51 -07002053 if (fw_type_is_auto()) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002054 tmp_fw_type = LIO_FW_NAME_TYPE_NIC;
Rick Farrington429cbf62017-09-22 17:12:51 -07002055 strncpy(fw_type, tmp_fw_type, sizeof(fw_type));
2056 } else {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002057 tmp_fw_type = fw_type;
Rick Farrington429cbf62017-09-22 17:12:51 -07002058 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002059
2060 sprintf(fw_name, "%s%s%s_%s%s", LIO_FW_DIR, LIO_FW_BASE_NAME,
2061 octeon_get_conf(oct)->card_name, tmp_fw_type,
2062 LIO_FW_NAME_SUFFIX);
2063
2064 ret = request_firmware(&fw, fw_name, &oct->pci_dev->dev);
2065 if (ret) {
2066 dev_err(&oct->pci_dev->dev, "Request firmware failed. Could not find file %s.\n.",
2067 fw_name);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07002068 release_firmware(fw);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002069 return ret;
2070 }
2071
2072 ret = octeon_download_firmware(oct, fw->data, fw->size);
2073
2074 release_firmware(fw);
2075
2076 return ret;
2077}
2078
2079/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002080 * \brief Callback for getting interface configuration
2081 * @param status status of request
2082 * @param buf pointer to resp structure
2083 */
2084static void if_cfg_callback(struct octeon_device *oct,
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002085 u32 status __attribute__((unused)),
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002086 void *buf)
2087{
2088 struct octeon_soft_command *sc = (struct octeon_soft_command *)buf;
2089 struct liquidio_if_cfg_resp *resp;
2090 struct liquidio_if_cfg_context *ctx;
2091
2092 resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
Raghu Vatsavayi30136392016-09-01 11:16:11 -07002093 ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002094
2095 oct = lio_get_device(ctx->octeon_id);
2096 if (resp->status)
Rick Farringtonc5b71e62017-03-17 11:23:08 -07002097 dev_err(&oct->pci_dev->dev, "nic if cfg instruction failed. Status: 0x%llx (0x%08x)\n",
2098 CVM_CAST64(resp->status), status);
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002099 WRITE_ONCE(ctx->cond, 1);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002100
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07002101 snprintf(oct->fw_info.liquidio_firmware_version, 32, "%s",
2102 resp->cfg_info.liquidio_firmware_version);
2103
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002104 /* This barrier is required to be sure that the response has been
2105 * written fully before waking up the handler
2106 */
2107 wmb();
2108
2109 wake_up_interruptible(&ctx->wc);
2110}
2111
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002112/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002113 * \brief Poll routine for checking transmit queue status
2114 * @param work work_struct data structure
2115 */
2116static void octnet_poll_check_txq_status(struct work_struct *work)
2117{
2118 struct cavium_wk *wk = (struct cavium_wk *)work;
2119 struct lio *lio = (struct lio *)wk->ctxptr;
2120
2121 if (!ifstate_check(lio, LIO_IFSTATE_RUNNING))
2122 return;
2123
2124 check_txq_status(lio);
2125 queue_delayed_work(lio->txq_status_wq.wq,
2126 &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
2127}
2128
2129/**
2130 * \brief Sets up the txq poll check
2131 * @param netdev network device
2132 */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002133static inline int setup_tx_poll_fn(struct net_device *netdev)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002134{
2135 struct lio *lio = GET_LIO(netdev);
2136 struct octeon_device *oct = lio->oct_dev;
2137
Bhaktipriya Shridhar292b9da2016-06-08 01:47:59 +05302138 lio->txq_status_wq.wq = alloc_workqueue("txq-status",
2139 WQ_MEM_RECLAIM, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002140 if (!lio->txq_status_wq.wq) {
2141 dev_err(&oct->pci_dev->dev, "unable to create cavium txq status wq\n");
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002142 return -1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002143 }
2144 INIT_DELAYED_WORK(&lio->txq_status_wq.wk.work,
2145 octnet_poll_check_txq_status);
2146 lio->txq_status_wq.wk.ctxptr = lio;
2147 queue_delayed_work(lio->txq_status_wq.wq,
2148 &lio->txq_status_wq.wk.work, msecs_to_jiffies(1));
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002149 return 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002150}
2151
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002152static inline void cleanup_tx_poll_fn(struct net_device *netdev)
2153{
2154 struct lio *lio = GET_LIO(netdev);
2155
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002156 if (lio->txq_status_wq.wq) {
2157 cancel_delayed_work_sync(&lio->txq_status_wq.wk.work);
2158 destroy_workqueue(lio->txq_status_wq.wq);
2159 }
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002160}
2161
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002162/**
2163 * \brief Net device open for LiquidIO
2164 * @param netdev network device
2165 */
2166static int liquidio_open(struct net_device *netdev)
2167{
2168 struct lio *lio = GET_LIO(netdev);
2169 struct octeon_device *oct = lio->oct_dev;
2170 struct napi_struct *napi, *n;
2171
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002172 if (oct->props[lio->ifidx].napi_enabled == 0) {
2173 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
2174 napi_enable(napi);
2175
2176 oct->props[lio->ifidx].napi_enabled = 1;
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07002177
2178 if (OCTEON_CN23XX_PF(oct))
2179 oct->droq[0]->ops.poll_mode = 1;
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002180 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002181
Intiyaz Bashaaa69ff92017-08-11 11:22:09 -07002182 if (oct->ptp_enable)
Prasad Kanneganti9feb16a2017-01-03 11:27:33 -08002183 oct_ptp_open(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002184
2185 ifstate_set(lio, LIO_IFSTATE_RUNNING);
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002186
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07002187 /* Ready for link status updates */
2188 lio->intf_open = 1;
2189
2190 netif_info(lio, ifup, lio->netdev, "Interface Open, ready for traffic\n");
2191
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002192 if (OCTEON_CN23XX_PF(oct)) {
2193 if (!oct->msix_on)
2194 if (setup_tx_poll_fn(netdev))
2195 return -1;
2196 } else {
2197 if (setup_tx_poll_fn(netdev))
2198 return -1;
2199 }
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002200
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002201 start_txq(netdev);
2202
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002203 /* tell Octeon to start forwarding packets to host */
2204 send_rx_ctrl_cmd(lio, 1);
2205
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002206 dev_info(&oct->pci_dev->dev, "%s interface is opened\n",
2207 netdev->name);
2208
2209 return 0;
2210}
2211
2212/**
2213 * \brief Net device stop for LiquidIO
2214 * @param netdev network device
2215 */
2216static int liquidio_stop(struct net_device *netdev)
2217{
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002218 struct lio *lio = GET_LIO(netdev);
2219 struct octeon_device *oct = lio->oct_dev;
Intiyaz Basha42013e92017-08-08 19:34:28 -07002220 struct napi_struct *napi, *n;
2221
2222 if (oct->props[lio->ifidx].napi_enabled) {
2223 list_for_each_entry_safe(napi, n, &netdev->napi_list, dev_list)
2224 napi_disable(napi);
2225
2226 oct->props[lio->ifidx].napi_enabled = 0;
2227
2228 if (OCTEON_CN23XX_PF(oct))
2229 oct->droq[0]->ops.poll_mode = 0;
2230 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002231
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002232 ifstate_reset(lio, LIO_IFSTATE_RUNNING);
2233
2234 netif_tx_disable(netdev);
2235
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002236 /* Inform that netif carrier is down */
Raghu Vatsavayi9a96bde2016-06-21 22:53:06 -07002237 netif_carrier_off(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002238 lio->intf_open = 0;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002239 lio->linfo.link.s.link_up = 0;
2240 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002241
Felix Manlunascb2336b2017-01-11 17:09:02 -08002242 /* Tell Octeon that nic interface is down. */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002243 send_rx_ctrl_cmd(lio, 0);
2244
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07002245 if (OCTEON_CN23XX_PF(oct)) {
2246 if (!oct->msix_on)
2247 cleanup_tx_poll_fn(netdev);
2248 } else {
2249 cleanup_tx_poll_fn(netdev);
2250 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002251
2252 if (lio->ptp_clock) {
2253 ptp_clock_unregister(lio->ptp_clock);
2254 lio->ptp_clock = NULL;
2255 }
2256
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002257 dev_info(&oct->pci_dev->dev, "%s interface is stopped\n", netdev->name);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002258
2259 return 0;
2260}
2261
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002262/**
2263 * \brief Converts a mask based on net device flags
2264 * @param netdev network device
2265 *
2266 * This routine generates a octnet_ifflags mask from the net device flags
2267 * received from the OS.
2268 */
2269static inline enum octnet_ifflags get_new_flags(struct net_device *netdev)
2270{
2271 enum octnet_ifflags f = OCTNET_IFFLAG_UNICAST;
2272
2273 if (netdev->flags & IFF_PROMISC)
2274 f |= OCTNET_IFFLAG_PROMISC;
2275
2276 if (netdev->flags & IFF_ALLMULTI)
2277 f |= OCTNET_IFFLAG_ALLMULTI;
2278
2279 if (netdev->flags & IFF_MULTICAST) {
2280 f |= OCTNET_IFFLAG_MULTICAST;
2281
2282 /* Accept all multicast addresses if there are more than we
2283 * can handle
2284 */
2285 if (netdev_mc_count(netdev) > MAX_OCTEON_MULTICAST_ADDR)
2286 f |= OCTNET_IFFLAG_ALLMULTI;
2287 }
2288
2289 if (netdev->flags & IFF_BROADCAST)
2290 f |= OCTNET_IFFLAG_BROADCAST;
2291
2292 return f;
2293}
2294
2295/**
2296 * \brief Net device set_multicast_list
2297 * @param netdev network device
2298 */
2299static void liquidio_set_mcast_list(struct net_device *netdev)
2300{
2301 struct lio *lio = GET_LIO(netdev);
2302 struct octeon_device *oct = lio->oct_dev;
2303 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002304 struct netdev_hw_addr *ha;
2305 u64 *mc;
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002306 int ret;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002307 int mc_count = min(netdev_mc_count(netdev), MAX_OCTEON_MULTICAST_ADDR);
2308
2309 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2310
2311 /* Create a ctrl pkt command to be sent to core app. */
2312 nctrl.ncmd.u64 = 0;
2313 nctrl.ncmd.s.cmd = OCTNET_CMD_SET_MULTI_LIST;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002314 nctrl.ncmd.s.param1 = get_new_flags(netdev);
2315 nctrl.ncmd.s.param2 = mc_count;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002316 nctrl.ncmd.s.more = mc_count;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002317 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002318 nctrl.netpndev = (u64)netdev;
2319 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2320
2321 /* copy all the addresses into the udd */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002322 mc = &nctrl.udd[0];
2323 netdev_for_each_mc_addr(ha, netdev) {
2324 *mc = 0;
2325 memcpy(((u8 *)mc) + 2, ha->addr, ETH_ALEN);
2326 /* no need to swap bytes */
2327
2328 if (++mc > &nctrl.udd[mc_count])
2329 break;
2330 }
2331
2332 /* Apparently, any activity in this call from the kernel has to
2333 * be atomic. So we won't wait for response.
2334 */
2335 nctrl.wait_time = 0;
2336
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002337 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002338 if (ret < 0) {
2339 dev_err(&oct->pci_dev->dev, "DEVFLAGS change failed in core (ret: 0x%x)\n",
2340 ret);
2341 }
2342}
2343
2344/**
2345 * \brief Net device set_mac_address
2346 * @param netdev network device
2347 */
2348static int liquidio_set_mac(struct net_device *netdev, void *p)
2349{
2350 int ret = 0;
2351 struct lio *lio = GET_LIO(netdev);
2352 struct octeon_device *oct = lio->oct_dev;
2353 struct sockaddr *addr = (struct sockaddr *)p;
2354 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002355
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002356 if (!is_valid_ether_addr(addr->sa_data))
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002357 return -EADDRNOTAVAIL;
2358
2359 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2360
2361 nctrl.ncmd.u64 = 0;
2362 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002363 nctrl.ncmd.s.param1 = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002364 nctrl.ncmd.s.more = 1;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002365 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002366 nctrl.netpndev = (u64)netdev;
2367 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2368 nctrl.wait_time = 100;
2369
2370 nctrl.udd[0] = 0;
2371 /* The MAC Address is presented in network byte order. */
2372 memcpy((u8 *)&nctrl.udd[0] + 2, addr->sa_data, ETH_ALEN);
2373
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002374 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002375 if (ret < 0) {
2376 dev_err(&oct->pci_dev->dev, "MAC Address change failed\n");
2377 return -ENOMEM;
2378 }
2379 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
2380 memcpy(((u8 *)&lio->linfo.hw_addr) + 2, addr->sa_data, ETH_ALEN);
2381
2382 return 0;
2383}
2384
2385/**
2386 * \brief Net device get_stats
2387 * @param netdev network device
2388 */
2389static struct net_device_stats *liquidio_get_stats(struct net_device *netdev)
2390{
2391 struct lio *lio = GET_LIO(netdev);
2392 struct net_device_stats *stats = &netdev->stats;
2393 struct octeon_device *oct;
2394 u64 pkts = 0, drop = 0, bytes = 0;
2395 struct oct_droq_stats *oq_stats;
2396 struct oct_iq_stats *iq_stats;
2397 int i, iq_no, oq_no;
2398
2399 oct = lio->oct_dev;
2400
Intiyaz Bashad18ca7d2017-08-14 12:01:56 -07002401 if (ifstate_check(lio, LIO_IFSTATE_RESETTING))
2402 return stats;
2403
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07002404 for (i = 0; i < oct->num_iqs; i++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002405 iq_no = lio->linfo.txpciq[i].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002406 iq_stats = &oct->instr_queue[iq_no]->stats;
2407 pkts += iq_stats->tx_done;
2408 drop += iq_stats->tx_dropped;
2409 bytes += iq_stats->tx_tot_bytes;
2410 }
2411
2412 stats->tx_packets = pkts;
2413 stats->tx_bytes = bytes;
2414 stats->tx_dropped = drop;
2415
2416 pkts = 0;
2417 drop = 0;
2418 bytes = 0;
2419
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07002420 for (i = 0; i < oct->num_oqs; i++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002421 oq_no = lio->linfo.rxpciq[i].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002422 oq_stats = &oct->droq[oq_no]->stats;
2423 pkts += oq_stats->rx_pkts_received;
2424 drop += (oq_stats->rx_dropped +
2425 oq_stats->dropped_nodispatch +
2426 oq_stats->dropped_toomany +
2427 oq_stats->dropped_nomem);
2428 bytes += oq_stats->rx_bytes_received;
2429 }
2430
2431 stats->rx_bytes = bytes;
2432 stats->rx_packets = pkts;
2433 stats->rx_dropped = drop;
2434
2435 return stats;
2436}
2437
2438/**
2439 * \brief Net device change_mtu
2440 * @param netdev network device
2441 */
2442static int liquidio_change_mtu(struct net_device *netdev, int new_mtu)
2443{
2444 struct lio *lio = GET_LIO(netdev);
2445 struct octeon_device *oct = lio->oct_dev;
2446 struct octnic_ctrl_pkt nctrl;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002447 int ret = 0;
2448
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002449 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2450
2451 nctrl.ncmd.u64 = 0;
2452 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MTU;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002453 nctrl.ncmd.s.param1 = new_mtu;
2454 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002455 nctrl.wait_time = 100;
2456 nctrl.netpndev = (u64)netdev;
2457 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2458
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002459 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002460 if (ret < 0) {
2461 dev_err(&oct->pci_dev->dev, "Failed to set MTU\n");
2462 return -1;
2463 }
2464
2465 lio->mtu = new_mtu;
2466
2467 return 0;
2468}
2469
2470/**
2471 * \brief Handler for SIOCSHWTSTAMP ioctl
2472 * @param netdev network device
2473 * @param ifr interface request
2474 * @param cmd command
2475 */
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07002476static int hwtstamp_ioctl(struct net_device *netdev, struct ifreq *ifr)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002477{
2478 struct hwtstamp_config conf;
2479 struct lio *lio = GET_LIO(netdev);
2480
2481 if (copy_from_user(&conf, ifr->ifr_data, sizeof(conf)))
2482 return -EFAULT;
2483
2484 if (conf.flags)
2485 return -EINVAL;
2486
2487 switch (conf.tx_type) {
2488 case HWTSTAMP_TX_ON:
2489 case HWTSTAMP_TX_OFF:
2490 break;
2491 default:
2492 return -ERANGE;
2493 }
2494
2495 switch (conf.rx_filter) {
2496 case HWTSTAMP_FILTER_NONE:
2497 break;
2498 case HWTSTAMP_FILTER_ALL:
2499 case HWTSTAMP_FILTER_SOME:
2500 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
2501 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
2502 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
2503 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
2504 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
2505 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
2506 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
2507 case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
2508 case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
2509 case HWTSTAMP_FILTER_PTP_V2_EVENT:
2510 case HWTSTAMP_FILTER_PTP_V2_SYNC:
2511 case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
Miroslav Lichvare3412572017-05-19 17:52:36 +02002512 case HWTSTAMP_FILTER_NTP_ALL:
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002513 conf.rx_filter = HWTSTAMP_FILTER_ALL;
2514 break;
2515 default:
2516 return -ERANGE;
2517 }
2518
2519 if (conf.rx_filter == HWTSTAMP_FILTER_ALL)
2520 ifstate_set(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
2521
2522 else
2523 ifstate_reset(lio, LIO_IFSTATE_RX_TIMESTAMP_ENABLED);
2524
2525 return copy_to_user(ifr->ifr_data, &conf, sizeof(conf)) ? -EFAULT : 0;
2526}
2527
2528/**
2529 * \brief ioctl handler
2530 * @param netdev network device
2531 * @param ifr interface request
2532 * @param cmd command
2533 */
2534static int liquidio_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
2535{
Prasad Kanneganti9feb16a2017-01-03 11:27:33 -08002536 struct lio *lio = GET_LIO(netdev);
2537
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002538 switch (cmd) {
2539 case SIOCSHWTSTAMP:
Intiyaz Bashaaa69ff92017-08-11 11:22:09 -07002540 if (lio->oct_dev->ptp_enable)
Prasad Kanneganti9feb16a2017-01-03 11:27:33 -08002541 return hwtstamp_ioctl(netdev, ifr);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002542 default:
2543 return -EOPNOTSUPP;
2544 }
2545}
2546
2547/**
2548 * \brief handle a Tx timestamp response
2549 * @param status response status
2550 * @param buf pointer to skb
2551 */
2552static void handle_timestamp(struct octeon_device *oct,
2553 u32 status,
2554 void *buf)
2555{
2556 struct octnet_buf_free_info *finfo;
2557 struct octeon_soft_command *sc;
2558 struct oct_timestamp_resp *resp;
2559 struct lio *lio;
2560 struct sk_buff *skb = (struct sk_buff *)buf;
2561
2562 finfo = (struct octnet_buf_free_info *)skb->cb;
2563 lio = finfo->lio;
2564 sc = finfo->sc;
2565 oct = lio->oct_dev;
2566 resp = (struct oct_timestamp_resp *)sc->virtrptr;
2567
2568 if (status != OCTEON_REQUEST_DONE) {
2569 dev_err(&oct->pci_dev->dev, "Tx timestamp instruction failed. Status: %llx\n",
2570 CVM_CAST64(status));
2571 resp->timestamp = 0;
2572 }
2573
2574 octeon_swap_8B_data(&resp->timestamp, 1);
2575
Colin Ian King19a6d152016-02-05 16:30:39 +00002576 if (unlikely((skb_shinfo(skb)->tx_flags & SKBTX_IN_PROGRESS) != 0)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002577 struct skb_shared_hwtstamps ts;
2578 u64 ns = resp->timestamp;
2579
2580 netif_info(lio, tx_done, lio->netdev,
2581 "Got resulting SKBTX_HW_TSTAMP skb=%p ns=%016llu\n",
2582 skb, (unsigned long long)ns);
2583 ts.hwtstamp = ns_to_ktime(ns + lio->ptp_adjust);
2584 skb_tstamp_tx(skb, &ts);
2585 }
2586
2587 octeon_free_soft_command(oct, sc);
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07002588 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002589}
2590
2591/* \brief Send a data packet that will be timestamped
2592 * @param oct octeon device
2593 * @param ndata pointer to network data
2594 * @param finfo pointer to private network data
2595 */
2596static inline int send_nic_timestamp_pkt(struct octeon_device *oct,
2597 struct octnic_data_pkt *ndata,
Intiyaz Bashac859e212017-10-26 16:18:20 -07002598 struct octnet_buf_free_info *finfo,
2599 int xmit_more)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002600{
2601 int retval;
2602 struct octeon_soft_command *sc;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002603 struct lio *lio;
2604 int ring_doorbell;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002605 u32 len;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002606
2607 lio = finfo->lio;
2608
2609 sc = octeon_alloc_soft_command_resp(oct, &ndata->cmd,
2610 sizeof(struct oct_timestamp_resp));
2611 finfo->sc = sc;
2612
2613 if (!sc) {
2614 dev_err(&oct->pci_dev->dev, "No memory for timestamped data packet\n");
2615 return IQ_SEND_FAILED;
2616 }
2617
2618 if (ndata->reqtype == REQTYPE_NORESP_NET)
2619 ndata->reqtype = REQTYPE_RESP_NET;
2620 else if (ndata->reqtype == REQTYPE_NORESP_NET_SG)
2621 ndata->reqtype = REQTYPE_RESP_NET_SG;
2622
2623 sc->callback = handle_timestamp;
2624 sc->callback_arg = finfo->skb;
2625 sc->iq_no = ndata->q_no;
2626
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002627 if (OCTEON_CN23XX_PF(oct))
2628 len = (u32)((struct octeon_instr_ih3 *)
2629 (&sc->cmd.cmd3.ih3))->dlengsz;
2630 else
2631 len = (u32)((struct octeon_instr_ih2 *)
2632 (&sc->cmd.cmd2.ih2))->dlengsz;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002633
Intiyaz Bashac859e212017-10-26 16:18:20 -07002634 ring_doorbell = !xmit_more;
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002635
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002636 retval = octeon_send_command(oct, sc->iq_no, ring_doorbell, &sc->cmd,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002637 sc, len, ndata->reqtype);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002638
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -07002639 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002640 dev_err(&oct->pci_dev->dev, "timestamp data packet failed status: %x\n",
2641 retval);
2642 octeon_free_soft_command(oct, sc);
2643 } else {
2644 netif_info(lio, tx_queued, lio->netdev, "Queued timestamp packet\n");
2645 }
2646
2647 return retval;
2648}
2649
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002650/** \brief Transmit networks packets to the Octeon interface
2651 * @param skbuff skbuff struct to be passed to network layer.
2652 * @param netdev pointer to network device
2653 * @returns whether the packet was transmitted to the device okay or not
2654 * (NETDEV_TX_OK or NETDEV_TX_BUSY)
2655 */
2656static int liquidio_xmit(struct sk_buff *skb, struct net_device *netdev)
2657{
2658 struct lio *lio;
2659 struct octnet_buf_free_info *finfo;
2660 union octnic_cmd_setup cmdsetup;
2661 struct octnic_data_pkt ndata;
2662 struct octeon_device *oct;
2663 struct oct_iq_stats *stats;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002664 struct octeon_instr_irh *irh;
2665 union tx_info *tx_info;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002666 int status = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002667 int q_idx = 0, iq_no = 0;
Intiyaz Bashac859e212017-10-26 16:18:20 -07002668 int j, xmit_more = 0;
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002669 u64 dptr = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002670 u32 tag = 0;
2671
2672 lio = GET_LIO(netdev);
2673 oct = lio->oct_dev;
2674
2675 if (netif_is_multiqueue(netdev)) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07002676 q_idx = skb->queue_mapping;
2677 q_idx = (q_idx % (lio->linfo.num_txpciq));
2678 tag = q_idx;
2679 iq_no = lio->linfo.txpciq[q_idx].s.q_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002680 } else {
2681 iq_no = lio->txq;
2682 }
2683
2684 stats = &oct->instr_queue[iq_no]->stats;
2685
2686 /* Check for all conditions in which the current packet cannot be
2687 * transmitted.
2688 */
2689 if (!(atomic_read(&lio->ifstate) & LIO_IFSTATE_RUNNING) ||
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002690 (!lio->linfo.link.s.link_up) ||
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002691 (skb->len <= 0)) {
2692 netif_info(lio, tx_err, lio->netdev,
2693 "Transmit failed link_status : %d\n",
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002694 lio->linfo.link.s.link_up);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002695 goto lio_xmit_failed;
2696 }
2697
2698 /* Use space in skb->cb to store info used to unmap and
2699 * free the buffers.
2700 */
2701 finfo = (struct octnet_buf_free_info *)skb->cb;
2702 finfo->lio = lio;
2703 finfo->skb = skb;
2704 finfo->sc = NULL;
2705
2706 /* Prepare the attributes for the data to be passed to OSI. */
2707 memset(&ndata, 0, sizeof(struct octnic_data_pkt));
2708
2709 ndata.buf = (void *)finfo;
2710
2711 ndata.q_no = iq_no;
2712
2713 if (netif_is_multiqueue(netdev)) {
2714 if (octnet_iq_is_full(oct, ndata.q_no)) {
2715 /* defer sending if queue is full */
2716 netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
2717 ndata.q_no);
2718 stats->tx_iq_busy++;
2719 return NETDEV_TX_BUSY;
2720 }
2721 } else {
2722 if (octnet_iq_is_full(oct, lio->txq)) {
2723 /* defer sending if queue is full */
2724 stats->tx_iq_busy++;
2725 netif_info(lio, tx_err, lio->netdev, "Transmit failed iq:%d full\n",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07002726 lio->txq);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002727 return NETDEV_TX_BUSY;
2728 }
2729 }
2730 /* pr_info(" XMIT - valid Qs: %d, 1st Q no: %d, cpu: %d, q_no:%d\n",
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07002731 * lio->linfo.num_txpciq, lio->txq, cpu, ndata.q_no);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002732 */
2733
2734 ndata.datasize = skb->len;
2735
2736 cmdsetup.u64 = 0;
Raghu Vatsavayi7275ebf2016-06-14 16:54:49 -07002737 cmdsetup.s.iq_no = iq_no;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002738
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002739 if (skb->ip_summed == CHECKSUM_PARTIAL) {
2740 if (skb->encapsulation) {
2741 cmdsetup.s.tnl_csum = 1;
2742 stats->tx_vxlan++;
2743 } else {
2744 cmdsetup.s.transport_csum = 1;
2745 }
2746 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002747 if (unlikely(skb_shinfo(skb)->tx_flags & SKBTX_HW_TSTAMP)) {
2748 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
2749 cmdsetup.s.timestamp = 1;
2750 }
2751
2752 if (skb_shinfo(skb)->nr_frags == 0) {
2753 cmdsetup.s.u.datasize = skb->len;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002754 octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07002755
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002756 /* Offload checksum calculation for TCP/UDP packets */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002757 dptr = dma_map_single(&oct->pci_dev->dev,
2758 skb->data,
2759 skb->len,
2760 DMA_TO_DEVICE);
2761 if (dma_mapping_error(&oct->pci_dev->dev, dptr)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002762 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 1\n",
2763 __func__);
2764 return NETDEV_TX_BUSY;
2765 }
2766
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002767 if (OCTEON_CN23XX_PF(oct))
2768 ndata.cmd.cmd3.dptr = dptr;
2769 else
2770 ndata.cmd.cmd2.dptr = dptr;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002771 finfo->dptr = dptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002772 ndata.reqtype = REQTYPE_NORESP_NET;
2773
2774 } else {
2775 int i, frags;
2776 struct skb_frag_struct *frag;
2777 struct octnic_gather *g;
2778
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002779 spin_lock(&lio->glist_lock[q_idx]);
2780 g = (struct octnic_gather *)
2781 list_delete_head(&lio->glist[q_idx]);
2782 spin_unlock(&lio->glist_lock[q_idx]);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002783
2784 if (!g) {
2785 netif_info(lio, tx_err, lio->netdev,
2786 "Transmit scatter gather: glist null!\n");
2787 goto lio_xmit_failed;
2788 }
2789
2790 cmdsetup.s.gather = 1;
2791 cmdsetup.s.u.gatherptrs = (skb_shinfo(skb)->nr_frags + 1);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07002792 octnet_prepare_pci_cmd(oct, &ndata.cmd, &cmdsetup, tag);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002793
2794 memset(g->sg, 0, g->sg_size);
2795
2796 g->sg[0].ptr[0] = dma_map_single(&oct->pci_dev->dev,
2797 skb->data,
2798 (skb->len - skb->data_len),
2799 DMA_TO_DEVICE);
2800 if (dma_mapping_error(&oct->pci_dev->dev, g->sg[0].ptr[0])) {
2801 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 2\n",
2802 __func__);
2803 return NETDEV_TX_BUSY;
2804 }
2805 add_sg_size(&g->sg[0], (skb->len - skb->data_len), 0);
2806
2807 frags = skb_shinfo(skb)->nr_frags;
2808 i = 1;
2809 while (frags--) {
2810 frag = &skb_shinfo(skb)->frags[i - 1];
2811
2812 g->sg[(i >> 2)].ptr[(i & 3)] =
2813 dma_map_page(&oct->pci_dev->dev,
2814 frag->page.p,
2815 frag->page_offset,
2816 frag->size,
2817 DMA_TO_DEVICE);
2818
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002819 if (dma_mapping_error(&oct->pci_dev->dev,
2820 g->sg[i >> 2].ptr[i & 3])) {
2821 dma_unmap_single(&oct->pci_dev->dev,
2822 g->sg[0].ptr[0],
2823 skb->len - skb->data_len,
2824 DMA_TO_DEVICE);
2825 for (j = 1; j < i; j++) {
2826 frag = &skb_shinfo(skb)->frags[j - 1];
2827 dma_unmap_page(&oct->pci_dev->dev,
2828 g->sg[j >> 2].ptr[j & 3],
2829 frag->size,
2830 DMA_TO_DEVICE);
2831 }
2832 dev_err(&oct->pci_dev->dev, "%s DMA mapping error 3\n",
2833 __func__);
2834 return NETDEV_TX_BUSY;
2835 }
2836
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002837 add_sg_size(&g->sg[(i >> 2)], frag->size, (i & 3));
2838 i++;
2839 }
2840
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07002841 dptr = g->sg_dma_ptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002842
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002843 if (OCTEON_CN23XX_PF(oct))
2844 ndata.cmd.cmd3.dptr = dptr;
2845 else
2846 ndata.cmd.cmd2.dptr = dptr;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002847 finfo->dptr = dptr;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002848 finfo->g = g;
2849
2850 ndata.reqtype = REQTYPE_NORESP_NET_SG;
2851 }
2852
Raghu Vatsavayi5b823512016-09-01 11:16:07 -07002853 if (OCTEON_CN23XX_PF(oct)) {
2854 irh = (struct octeon_instr_irh *)&ndata.cmd.cmd3.irh;
2855 tx_info = (union tx_info *)&ndata.cmd.cmd3.ossp[0];
2856 } else {
2857 irh = (struct octeon_instr_irh *)&ndata.cmd.cmd2.irh;
2858 tx_info = (union tx_info *)&ndata.cmd.cmd2.ossp[0];
2859 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002860
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002861 if (skb_shinfo(skb)->gso_size) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002862 tx_info->s.gso_size = skb_shinfo(skb)->gso_size;
2863 tx_info->s.gso_segs = skb_shinfo(skb)->gso_segs;
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07002864 stats->tx_gso++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002865 }
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07002866
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07002867 /* HW insert VLAN tag */
2868 if (skb_vlan_tag_present(skb)) {
2869 irh->priority = skb_vlan_tag_get(skb) >> 13;
2870 irh->vlan = skb_vlan_tag_get(skb) & 0xfff;
2871 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002872
Intiyaz Bashac859e212017-10-26 16:18:20 -07002873 xmit_more = skb->xmit_more;
2874
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002875 if (unlikely(cmdsetup.s.timestamp))
Intiyaz Bashac859e212017-10-26 16:18:20 -07002876 status = send_nic_timestamp_pkt(oct, &ndata, finfo, xmit_more);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002877 else
Intiyaz Bashac859e212017-10-26 16:18:20 -07002878 status = octnet_send_nic_data_pkt(oct, &ndata, xmit_more);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002879 if (status == IQ_SEND_FAILED)
2880 goto lio_xmit_failed;
2881
2882 netif_info(lio, tx_queued, lio->netdev, "Transmit queued successfully\n");
2883
2884 if (status == IQ_SEND_STOP)
Intiyaz Bashac859e212017-10-26 16:18:20 -07002885 stop_q(netdev, q_idx);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002886
Florian Westphal860e9532016-05-03 16:33:13 +02002887 netif_trans_update(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002888
Satanand Burla80c8eae2017-01-26 11:52:35 -08002889 if (tx_info->s.gso_segs)
2890 stats->tx_done += tx_info->s.gso_segs;
Raghu Vatsavayi1f164712016-06-21 22:53:11 -07002891 else
2892 stats->tx_done++;
Satanand Burla80c8eae2017-01-26 11:52:35 -08002893 stats->tx_tot_bytes += ndata.datasize;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002894
2895 return NETDEV_TX_OK;
2896
2897lio_xmit_failed:
2898 stats->tx_dropped++;
2899 netif_info(lio, tx_err, lio->netdev, "IQ%d Transmit dropped:%llu\n",
2900 iq_no, stats->tx_dropped);
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -07002901 if (dptr)
2902 dma_unmap_single(&oct->pci_dev->dev, dptr,
2903 ndata.datasize, DMA_TO_DEVICE);
Intiyaz Bashac859e212017-10-26 16:18:20 -07002904
2905 octeon_ring_doorbell_locked(oct, iq_no);
2906
Raghu Vatsavayicabeb132016-06-14 16:54:47 -07002907 tx_buffer_free(skb);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002908 return NETDEV_TX_OK;
2909}
2910
2911/** \brief Network device Tx timeout
2912 * @param netdev pointer to network device
2913 */
2914static void liquidio_tx_timeout(struct net_device *netdev)
2915{
2916 struct lio *lio;
2917
2918 lio = GET_LIO(netdev);
2919
2920 netif_info(lio, tx_err, lio->netdev,
2921 "Transmit timeout tx_dropped:%ld, waking up queues now!!\n",
2922 netdev->stats.tx_dropped);
Florian Westphal860e9532016-05-03 16:33:13 +02002923 netif_trans_update(netdev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07002924 txqs_wake(netdev);
2925}
2926
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07002927static int liquidio_vlan_rx_add_vid(struct net_device *netdev,
2928 __be16 proto __attribute__((unused)),
2929 u16 vid)
2930{
2931 struct lio *lio = GET_LIO(netdev);
2932 struct octeon_device *oct = lio->oct_dev;
2933 struct octnic_ctrl_pkt nctrl;
2934 int ret = 0;
2935
2936 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2937
2938 nctrl.ncmd.u64 = 0;
2939 nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER;
2940 nctrl.ncmd.s.param1 = vid;
2941 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
2942 nctrl.wait_time = 100;
2943 nctrl.netpndev = (u64)netdev;
2944 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2945
2946 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
2947 if (ret < 0) {
2948 dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
2949 ret);
2950 }
2951
2952 return ret;
2953}
2954
2955static int liquidio_vlan_rx_kill_vid(struct net_device *netdev,
2956 __be16 proto __attribute__((unused)),
2957 u16 vid)
2958{
2959 struct lio *lio = GET_LIO(netdev);
2960 struct octeon_device *oct = lio->oct_dev;
2961 struct octnic_ctrl_pkt nctrl;
2962 int ret = 0;
2963
2964 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2965
2966 nctrl.ncmd.u64 = 0;
2967 nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER;
2968 nctrl.ncmd.s.param1 = vid;
2969 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
2970 nctrl.wait_time = 100;
2971 nctrl.netpndev = (u64)netdev;
2972 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
2973
2974 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
2975 if (ret < 0) {
2976 dev_err(&oct->pci_dev->dev, "Add VLAN filter failed in core (ret: 0x%x)\n",
2977 ret);
2978 }
2979 return ret;
2980}
2981
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002982/** Sending command to enable/disable RX checksum offload
2983 * @param netdev pointer to network device
2984 * @param command OCTNET_CMD_TNL_RX_CSUM_CTL
2985 * @param rx_cmd_bit OCTNET_CMD_RXCSUM_ENABLE/
2986 * OCTNET_CMD_RXCSUM_DISABLE
2987 * @returns SUCCESS or FAILURE
2988 */
Nicholas Mc Guirec41419b2016-08-22 17:52:00 +02002989static int liquidio_set_rxcsum_command(struct net_device *netdev, int command,
2990 u8 rx_cmd)
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002991{
2992 struct lio *lio = GET_LIO(netdev);
2993 struct octeon_device *oct = lio->oct_dev;
2994 struct octnic_ctrl_pkt nctrl;
2995 int ret = 0;
2996
Felix Manlunas0c264582017-04-06 19:22:22 -07002997 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
2998
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07002999 nctrl.ncmd.u64 = 0;
3000 nctrl.ncmd.s.cmd = command;
3001 nctrl.ncmd.s.param1 = rx_cmd;
3002 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3003 nctrl.wait_time = 100;
3004 nctrl.netpndev = (u64)netdev;
3005 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
3006
3007 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
3008 if (ret < 0) {
3009 dev_err(&oct->pci_dev->dev,
3010 "DEVFLAGS RXCSUM change failed in core(ret:0x%x)\n",
3011 ret);
3012 }
3013 return ret;
3014}
3015
3016/** Sending command to add/delete VxLAN UDP port to firmware
3017 * @param netdev pointer to network device
3018 * @param command OCTNET_CMD_VXLAN_PORT_CONFIG
3019 * @param vxlan_port VxLAN port to be added or deleted
3020 * @param vxlan_cmd_bit OCTNET_CMD_VXLAN_PORT_ADD,
3021 * OCTNET_CMD_VXLAN_PORT_DEL
3022 * @returns SUCCESS or FAILURE
3023 */
3024static int liquidio_vxlan_port_command(struct net_device *netdev, int command,
3025 u16 vxlan_port, u8 vxlan_cmd_bit)
3026{
3027 struct lio *lio = GET_LIO(netdev);
3028 struct octeon_device *oct = lio->oct_dev;
3029 struct octnic_ctrl_pkt nctrl;
3030 int ret = 0;
3031
Felix Manlunas0c264582017-04-06 19:22:22 -07003032 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3033
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003034 nctrl.ncmd.u64 = 0;
3035 nctrl.ncmd.s.cmd = command;
3036 nctrl.ncmd.s.more = vxlan_cmd_bit;
3037 nctrl.ncmd.s.param1 = vxlan_port;
3038 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3039 nctrl.wait_time = 100;
3040 nctrl.netpndev = (u64)netdev;
3041 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
3042
3043 ret = octnet_send_nic_ctrl_pkt(lio->oct_dev, &nctrl);
3044 if (ret < 0) {
3045 dev_err(&oct->pci_dev->dev,
3046 "VxLAN port add/delete failed in core (ret:0x%x)\n",
3047 ret);
3048 }
3049 return ret;
3050}
3051
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003052/** \brief Net device fix features
3053 * @param netdev pointer to network device
3054 * @param request features requested
3055 * @returns updated features list
3056 */
3057static netdev_features_t liquidio_fix_features(struct net_device *netdev,
3058 netdev_features_t request)
3059{
3060 struct lio *lio = netdev_priv(netdev);
3061
3062 if ((request & NETIF_F_RXCSUM) &&
3063 !(lio->dev_capability & NETIF_F_RXCSUM))
3064 request &= ~NETIF_F_RXCSUM;
3065
3066 if ((request & NETIF_F_HW_CSUM) &&
3067 !(lio->dev_capability & NETIF_F_HW_CSUM))
3068 request &= ~NETIF_F_HW_CSUM;
3069
3070 if ((request & NETIF_F_TSO) && !(lio->dev_capability & NETIF_F_TSO))
3071 request &= ~NETIF_F_TSO;
3072
3073 if ((request & NETIF_F_TSO6) && !(lio->dev_capability & NETIF_F_TSO6))
3074 request &= ~NETIF_F_TSO6;
3075
3076 if ((request & NETIF_F_LRO) && !(lio->dev_capability & NETIF_F_LRO))
3077 request &= ~NETIF_F_LRO;
3078
3079 /*Disable LRO if RXCSUM is off */
3080 if (!(request & NETIF_F_RXCSUM) && (netdev->features & NETIF_F_LRO) &&
3081 (lio->dev_capability & NETIF_F_LRO))
3082 request &= ~NETIF_F_LRO;
3083
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003084 if ((request & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3085 !(lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER))
3086 request &= ~NETIF_F_HW_VLAN_CTAG_FILTER;
3087
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003088 return request;
3089}
3090
3091/** \brief Net device set features
3092 * @param netdev pointer to network device
3093 * @param features features to enable/disable
3094 */
3095static int liquidio_set_features(struct net_device *netdev,
3096 netdev_features_t features)
3097{
3098 struct lio *lio = netdev_priv(netdev);
3099
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003100 if ((features & NETIF_F_LRO) &&
3101 (lio->dev_capability & NETIF_F_LRO) &&
3102 !(netdev->features & NETIF_F_LRO))
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003103 liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
3104 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003105 else if (!(features & NETIF_F_LRO) &&
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003106 (lio->dev_capability & NETIF_F_LRO) &&
3107 (netdev->features & NETIF_F_LRO))
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003108 liquidio_set_feature(netdev, OCTNET_CMD_LRO_DISABLE,
3109 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003110
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003111 /* Sending command to firmware to enable/disable RX checksum
3112 * offload settings using ethtool
3113 */
3114 if (!(netdev->features & NETIF_F_RXCSUM) &&
3115 (lio->enc_dev_capability & NETIF_F_RXCSUM) &&
3116 (features & NETIF_F_RXCSUM))
3117 liquidio_set_rxcsum_command(netdev,
3118 OCTNET_CMD_TNL_RX_CSUM_CTL,
3119 OCTNET_CMD_RXCSUM_ENABLE);
3120 else if ((netdev->features & NETIF_F_RXCSUM) &&
3121 (lio->enc_dev_capability & NETIF_F_RXCSUM) &&
3122 !(features & NETIF_F_RXCSUM))
3123 liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
3124 OCTNET_CMD_RXCSUM_DISABLE);
3125
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003126 if ((features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3127 (lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3128 !(netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3129 liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL,
3130 OCTNET_CMD_VLAN_FILTER_ENABLE);
3131 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3132 (lio->dev_capability & NETIF_F_HW_VLAN_CTAG_FILTER) &&
3133 (netdev->features & NETIF_F_HW_VLAN_CTAG_FILTER))
3134 liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL,
3135 OCTNET_CMD_VLAN_FILTER_DISABLE);
3136
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003137 return 0;
3138}
3139
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003140static void liquidio_add_vxlan_port(struct net_device *netdev,
3141 struct udp_tunnel_info *ti)
3142{
3143 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
3144 return;
3145
3146 liquidio_vxlan_port_command(netdev,
3147 OCTNET_CMD_VXLAN_PORT_CONFIG,
3148 htons(ti->port),
3149 OCTNET_CMD_VXLAN_PORT_ADD);
3150}
3151
3152static void liquidio_del_vxlan_port(struct net_device *netdev,
3153 struct udp_tunnel_info *ti)
3154{
3155 if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
3156 return;
3157
3158 liquidio_vxlan_port_command(netdev,
3159 OCTNET_CMD_VXLAN_PORT_CONFIG,
3160 htons(ti->port),
3161 OCTNET_CMD_VXLAN_PORT_DEL);
3162}
3163
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003164static int __liquidio_set_vf_mac(struct net_device *netdev, int vfidx,
3165 u8 *mac, bool is_admin_assigned)
3166{
3167 struct lio *lio = GET_LIO(netdev);
3168 struct octeon_device *oct = lio->oct_dev;
3169 struct octnic_ctrl_pkt nctrl;
3170
3171 if (!is_valid_ether_addr(mac))
3172 return -EINVAL;
3173
3174 if (vfidx < 0 || vfidx >= oct->sriov_info.max_vfs)
3175 return -EINVAL;
3176
3177 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3178
3179 nctrl.ncmd.u64 = 0;
3180 nctrl.ncmd.s.cmd = OCTNET_CMD_CHANGE_MACADDR;
3181 /* vfidx is 0 based, but vf_num (param1) is 1 based */
3182 nctrl.ncmd.s.param1 = vfidx + 1;
3183 nctrl.ncmd.s.param2 = (is_admin_assigned ? 1 : 0);
3184 nctrl.ncmd.s.more = 1;
3185 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
Rick Farrington9549c6c2017-03-17 15:43:26 -07003186 nctrl.netpndev = (u64)netdev;
3187 nctrl.cb_fn = liquidio_link_ctrl_cmd_completion;
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003188 nctrl.wait_time = LIO_CMD_WAIT_TM;
3189
3190 nctrl.udd[0] = 0;
3191 /* The MAC Address is presented in network byte order. */
3192 ether_addr_copy((u8 *)&nctrl.udd[0] + 2, mac);
3193
3194 oct->sriov_info.vf_macaddr[vfidx] = nctrl.udd[0];
3195
3196 octnet_send_nic_ctrl_pkt(oct, &nctrl);
3197
3198 return 0;
3199}
3200
3201static int liquidio_set_vf_mac(struct net_device *netdev, int vfidx, u8 *mac)
3202{
3203 struct lio *lio = GET_LIO(netdev);
3204 struct octeon_device *oct = lio->oct_dev;
3205 int retval;
3206
Felix Manlunas0d9a5992017-05-16 11:28:00 -07003207 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3208 return -EINVAL;
3209
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003210 retval = __liquidio_set_vf_mac(netdev, vfidx, mac, true);
3211 if (!retval)
3212 cn23xx_tell_vf_its_macaddr_changed(oct, vfidx, mac);
3213
3214 return retval;
3215}
3216
3217static int liquidio_set_vf_vlan(struct net_device *netdev, int vfidx,
3218 u16 vlan, u8 qos, __be16 vlan_proto)
3219{
3220 struct lio *lio = GET_LIO(netdev);
3221 struct octeon_device *oct = lio->oct_dev;
3222 struct octnic_ctrl_pkt nctrl;
3223 u16 vlantci;
3224
3225 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3226 return -EINVAL;
3227
3228 if (vlan_proto != htons(ETH_P_8021Q))
3229 return -EPROTONOSUPPORT;
3230
3231 if (vlan >= VLAN_N_VID || qos > 7)
3232 return -EINVAL;
3233
3234 if (vlan)
3235 vlantci = vlan | (u16)qos << VLAN_PRIO_SHIFT;
3236 else
3237 vlantci = 0;
3238
3239 if (oct->sriov_info.vf_vlantci[vfidx] == vlantci)
3240 return 0;
3241
3242 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3243
3244 if (vlan)
3245 nctrl.ncmd.s.cmd = OCTNET_CMD_ADD_VLAN_FILTER;
3246 else
3247 nctrl.ncmd.s.cmd = OCTNET_CMD_DEL_VLAN_FILTER;
3248
3249 nctrl.ncmd.s.param1 = vlantci;
3250 nctrl.ncmd.s.param2 =
3251 vfidx + 1; /* vfidx is 0 based, but vf_num (param2) is 1 based */
3252 nctrl.ncmd.s.more = 0;
3253 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3254 nctrl.cb_fn = 0;
3255 nctrl.wait_time = LIO_CMD_WAIT_TM;
3256
3257 octnet_send_nic_ctrl_pkt(oct, &nctrl);
3258
3259 oct->sriov_info.vf_vlantci[vfidx] = vlantci;
3260
3261 return 0;
3262}
3263
3264static int liquidio_get_vf_config(struct net_device *netdev, int vfidx,
3265 struct ifla_vf_info *ivi)
3266{
3267 struct lio *lio = GET_LIO(netdev);
3268 struct octeon_device *oct = lio->oct_dev;
3269 u8 *macaddr;
3270
3271 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3272 return -EINVAL;
3273
3274 ivi->vf = vfidx;
3275 macaddr = 2 + (u8 *)&oct->sriov_info.vf_macaddr[vfidx];
3276 ether_addr_copy(&ivi->mac[0], macaddr);
3277 ivi->vlan = oct->sriov_info.vf_vlantci[vfidx] & VLAN_VID_MASK;
3278 ivi->qos = oct->sriov_info.vf_vlantci[vfidx] >> VLAN_PRIO_SHIFT;
3279 ivi->linkstate = oct->sriov_info.vf_linkstate[vfidx];
3280 return 0;
3281}
3282
3283static int liquidio_set_vf_link_state(struct net_device *netdev, int vfidx,
3284 int linkstate)
3285{
3286 struct lio *lio = GET_LIO(netdev);
3287 struct octeon_device *oct = lio->oct_dev;
3288 struct octnic_ctrl_pkt nctrl;
3289
3290 if (vfidx < 0 || vfidx >= oct->sriov_info.num_vfs_alloced)
3291 return -EINVAL;
3292
3293 if (oct->sriov_info.vf_linkstate[vfidx] == linkstate)
3294 return 0;
3295
3296 memset(&nctrl, 0, sizeof(struct octnic_ctrl_pkt));
3297 nctrl.ncmd.s.cmd = OCTNET_CMD_SET_VF_LINKSTATE;
3298 nctrl.ncmd.s.param1 =
3299 vfidx + 1; /* vfidx is 0 based, but vf_num (param1) is 1 based */
3300 nctrl.ncmd.s.param2 = linkstate;
3301 nctrl.ncmd.s.more = 0;
3302 nctrl.iq_no = lio->linfo.txpciq[0].s.q_no;
3303 nctrl.cb_fn = 0;
3304 nctrl.wait_time = LIO_CMD_WAIT_TM;
3305
3306 octnet_send_nic_ctrl_pkt(oct, &nctrl);
3307
3308 oct->sriov_info.vf_linkstate[vfidx] = linkstate;
3309
3310 return 0;
3311}
3312
Vijaya Mohan Guvva1f233f32017-10-31 16:04:53 -07003313static int
3314lio_pf_switchdev_attr_get(struct net_device *dev, struct switchdev_attr *attr)
3315{
3316 struct lio *lio = GET_LIO(dev);
3317
3318 switch (attr->id) {
3319 case SWITCHDEV_ATTR_ID_PORT_PARENT_ID:
3320 attr->u.ppid.id_len = ETH_ALEN;
3321 ether_addr_copy(attr->u.ppid.id,
3322 (void *)&lio->linfo.hw_addr + 2);
3323 break;
3324
3325 default:
3326 return -EOPNOTSUPP;
3327 }
3328
3329 return 0;
3330}
3331
3332static const struct switchdev_ops lio_pf_switchdev_ops = {
3333 .switchdev_port_attr_get = lio_pf_switchdev_attr_get,
3334};
3335
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08003336static const struct net_device_ops lionetdevops = {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003337 .ndo_open = liquidio_open,
3338 .ndo_stop = liquidio_stop,
3339 .ndo_start_xmit = liquidio_xmit,
3340 .ndo_get_stats = liquidio_get_stats,
3341 .ndo_set_mac_address = liquidio_set_mac,
3342 .ndo_set_rx_mode = liquidio_set_mcast_list,
3343 .ndo_tx_timeout = liquidio_tx_timeout,
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003344
3345 .ndo_vlan_rx_add_vid = liquidio_vlan_rx_add_vid,
3346 .ndo_vlan_rx_kill_vid = liquidio_vlan_rx_kill_vid,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003347 .ndo_change_mtu = liquidio_change_mtu,
3348 .ndo_do_ioctl = liquidio_ioctl,
3349 .ndo_fix_features = liquidio_fix_features,
3350 .ndo_set_features = liquidio_set_features,
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003351 .ndo_udp_tunnel_add = liquidio_add_vxlan_port,
3352 .ndo_udp_tunnel_del = liquidio_del_vxlan_port,
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003353 .ndo_set_vf_mac = liquidio_set_vf_mac,
3354 .ndo_set_vf_vlan = liquidio_set_vf_vlan,
3355 .ndo_get_vf_config = liquidio_get_vf_config,
3356 .ndo_set_vf_link_state = liquidio_set_vf_link_state,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003357};
3358
3359/** \brief Entry point for the liquidio module
3360 */
3361static int __init liquidio_init(void)
3362{
3363 int i;
3364 struct handshake *hs;
3365
3366 init_completion(&first_stage);
3367
Raghu Vatsavayi97a25322016-11-14 15:54:47 -08003368 octeon_init_device_list(OCTEON_CONFIG_TYPE_DEFAULT);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003369
3370 if (liquidio_init_pci())
3371 return -EINVAL;
3372
3373 wait_for_completion_timeout(&first_stage, msecs_to_jiffies(1000));
3374
3375 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
3376 hs = &handshake[i];
3377 if (hs->pci_dev) {
3378 wait_for_completion(&hs->init);
3379 if (!hs->init_ok) {
3380 /* init handshake failed */
3381 dev_err(&hs->pci_dev->dev,
3382 "Failed to init device\n");
3383 liquidio_deinit_pci();
3384 return -EIO;
3385 }
3386 }
3387 }
3388
3389 for (i = 0; i < MAX_OCTEON_DEVICES; i++) {
3390 hs = &handshake[i];
3391 if (hs->pci_dev) {
3392 wait_for_completion_timeout(&hs->started,
3393 msecs_to_jiffies(30000));
3394 if (!hs->started_ok) {
3395 /* starter handshake failed */
3396 dev_err(&hs->pci_dev->dev,
3397 "Firmware failed to start\n");
3398 liquidio_deinit_pci();
3399 return -EIO;
3400 }
3401 }
3402 }
3403
3404 return 0;
3405}
3406
Raghu Vatsavayi5b173cf2015-06-12 18:11:50 -07003407static int lio_nic_info(struct octeon_recv_info *recv_info, void *buf)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003408{
3409 struct octeon_device *oct = (struct octeon_device *)buf;
3410 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003411 int gmxport = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003412 union oct_link_status *ls;
3413 int i;
3414
Prasad Kannegantic4ee5d82017-06-18 05:04:11 -07003415 if (recv_pkt->buffer_size[0] != (sizeof(*ls) + OCT_DROQ_INFO_SIZE)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003416 dev_err(&oct->pci_dev->dev, "Malformed NIC_INFO, len=%d, ifidx=%d\n",
3417 recv_pkt->buffer_size[0],
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003418 recv_pkt->rh.r_nic_info.gmxport);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003419 goto nic_info_err;
3420 }
3421
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003422 gmxport = recv_pkt->rh.r_nic_info.gmxport;
Prasad Kannegantic4ee5d82017-06-18 05:04:11 -07003423 ls = (union oct_link_status *)(get_rbd(recv_pkt->buffer_ptr[0]) +
3424 OCT_DROQ_INFO_SIZE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003425
3426 octeon_swap_8B_data((u64 *)ls, (sizeof(union oct_link_status)) >> 3);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003427 for (i = 0; i < oct->ifcount; i++) {
3428 if (oct->props[i].gmxport == gmxport) {
3429 update_link_status(oct->props[i].netdev, ls);
3430 break;
3431 }
3432 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003433
3434nic_info_err:
3435 for (i = 0; i < recv_pkt->buffer_count; i++)
3436 recv_buffer_free(recv_pkt->buffer_ptr[i]);
3437 octeon_free_recv_info(recv_info);
3438 return 0;
3439}
3440
3441/**
3442 * \brief Setup network interfaces
3443 * @param octeon_dev octeon device
3444 *
3445 * Called during init time for each device. It assumes the NIC
3446 * is already up and running. The link information for each
3447 * interface is passed in link_info.
3448 */
3449static int setup_nic_devices(struct octeon_device *octeon_dev)
3450{
3451 struct lio *lio = NULL;
3452 struct net_device *netdev;
Rick Farringtonb36e4822017-09-22 17:12:47 -07003453 u8 mac[6], i, j, *fw_ver;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003454 struct octeon_soft_command *sc;
3455 struct liquidio_if_cfg_context *ctx;
3456 struct liquidio_if_cfg_resp *resp;
3457 struct octdev_props *props;
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003458 int retval, num_iqueues, num_oqueues;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003459 union oct_nic_if_cfg if_cfg;
3460 unsigned int base_queue;
3461 unsigned int gmx_port_id;
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003462 u32 resp_size, ctx_size, data_size;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003463 u32 ifidx_or_pfnum;
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003464 struct lio_version *vdata;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003465
3466 /* This is to handle link status changes */
3467 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
3468 OPCODE_NIC_INFO,
3469 lio_nic_info, octeon_dev);
3470
3471 /* REQTYPE_RESP_NET and REQTYPE_SOFT_COMMAND do not have free functions.
3472 * They are handled directly.
3473 */
3474 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET,
3475 free_netbuf);
3476
3477 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_NORESP_NET_SG,
3478 free_netsgbuf);
3479
3480 octeon_register_reqtype_free_fn(octeon_dev, REQTYPE_RESP_NET_SG,
3481 free_netsgbuf_with_resp);
3482
3483 for (i = 0; i < octeon_dev->ifcount; i++) {
3484 resp_size = sizeof(struct liquidio_if_cfg_resp);
3485 ctx_size = sizeof(struct liquidio_if_cfg_context);
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003486 data_size = sizeof(struct lio_version);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003487 sc = (struct octeon_soft_command *)
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003488 octeon_alloc_soft_command(octeon_dev, data_size,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003489 resp_size, ctx_size);
3490 resp = (struct liquidio_if_cfg_resp *)sc->virtrptr;
3491 ctx = (struct liquidio_if_cfg_context *)sc->ctxptr;
Raghu Vatsavayi83101ce2016-08-31 11:03:21 -07003492 vdata = (struct lio_version *)sc->virtdptr;
3493
3494 *((u64 *)vdata) = 0;
3495 vdata->major = cpu_to_be16(LIQUIDIO_BASE_MAJOR_VERSION);
3496 vdata->minor = cpu_to_be16(LIQUIDIO_BASE_MINOR_VERSION);
3497 vdata->micro = cpu_to_be16(LIQUIDIO_BASE_MICRO_VERSION);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003498
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07003499 if (OCTEON_CN23XX_PF(octeon_dev)) {
3500 num_iqueues = octeon_dev->sriov_info.num_pf_rings;
3501 num_oqueues = octeon_dev->sriov_info.num_pf_rings;
3502 base_queue = octeon_dev->sriov_info.pf_srn;
3503
3504 gmx_port_id = octeon_dev->pf_num;
3505 ifidx_or_pfnum = octeon_dev->pf_num;
3506 } else {
3507 num_iqueues = CFG_GET_NUM_TXQS_NIC_IF(
3508 octeon_get_conf(octeon_dev), i);
3509 num_oqueues = CFG_GET_NUM_RXQS_NIC_IF(
3510 octeon_get_conf(octeon_dev), i);
3511 base_queue = CFG_GET_BASE_QUE_NIC_IF(
3512 octeon_get_conf(octeon_dev), i);
3513 gmx_port_id = CFG_GET_GMXID_NIC_IF(
3514 octeon_get_conf(octeon_dev), i);
3515 ifidx_or_pfnum = i;
3516 }
Raghu Vatsavayi3dcef2c2016-07-03 13:56:51 -07003517
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003518 dev_dbg(&octeon_dev->pci_dev->dev,
3519 "requesting config for interface %d, iqs %d, oqs %d\n",
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003520 ifidx_or_pfnum, num_iqueues, num_oqueues);
Raghu Vatsavayia7d5a3d2016-07-03 13:56:48 -07003521 WRITE_ONCE(ctx->cond, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003522 ctx->octeon_id = lio_get_device_id(octeon_dev);
3523 init_waitqueue_head(&ctx->wc);
3524
3525 if_cfg.u64 = 0;
3526 if_cfg.s.num_iqueues = num_iqueues;
3527 if_cfg.s.num_oqueues = num_oqueues;
3528 if_cfg.s.base_queue = base_queue;
3529 if_cfg.s.gmx_port_id = gmx_port_id;
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003530
3531 sc->iq_no = 0;
3532
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003533 octeon_prepare_soft_command(octeon_dev, sc, OPCODE_NIC,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003534 OPCODE_NIC_IF_CFG, 0,
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003535 if_cfg.u64, 0);
3536
3537 sc->callback = if_cfg_callback;
3538 sc->callback_arg = sc;
Raghu Vatsavayi55893a62016-07-03 13:56:50 -07003539 sc->wait_time = 3000;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003540
3541 retval = octeon_send_soft_command(octeon_dev, sc);
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -07003542 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003543 dev_err(&octeon_dev->pci_dev->dev,
3544 "iq/oq config failed status: %x\n",
3545 retval);
3546 /* Soft instr is freed by driver in case of failure. */
3547 goto setup_nic_dev_fail;
3548 }
3549
3550 /* Sleep on a wait queue till the cond flag indicates that the
3551 * response arrived or timed-out.
3552 */
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07003553 if (sleep_cond(&ctx->wc, &ctx->cond) == -EINTR) {
3554 dev_err(&octeon_dev->pci_dev->dev, "Wait interrupted\n");
3555 goto setup_nic_wait_intr;
3556 }
3557
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003558 retval = resp->status;
3559 if (retval) {
3560 dev_err(&octeon_dev->pci_dev->dev, "iq/oq config failed\n");
3561 goto setup_nic_dev_fail;
3562 }
3563
Rick Farringtonb36e4822017-09-22 17:12:47 -07003564 /* Verify f/w version (in case of 'auto' loading from flash) */
3565 fw_ver = octeon_dev->fw_info.liquidio_firmware_version;
3566 if (memcmp(LIQUIDIO_BASE_VERSION,
3567 fw_ver,
3568 strlen(LIQUIDIO_BASE_VERSION))) {
3569 dev_err(&octeon_dev->pci_dev->dev,
3570 "Unmatched firmware version. Expected %s.x, got %s.\n",
3571 LIQUIDIO_BASE_VERSION, fw_ver);
3572 goto setup_nic_dev_fail;
3573 } else if (atomic_read(octeon_dev->adapter_fw_state) ==
3574 FW_IS_PRELOADED) {
3575 dev_info(&octeon_dev->pci_dev->dev,
3576 "Using auto-loaded firmware version %s.\n",
3577 fw_ver);
3578 }
3579
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003580 octeon_swap_8B_data((u64 *)(&resp->cfg_info),
3581 (sizeof(struct liquidio_if_cfg_info)) >> 3);
3582
3583 num_iqueues = hweight64(resp->cfg_info.iqmask);
3584 num_oqueues = hweight64(resp->cfg_info.oqmask);
3585
3586 if (!(num_iqueues) || !(num_oqueues)) {
3587 dev_err(&octeon_dev->pci_dev->dev,
3588 "Got bad iqueues (%016llx) or oqueues (%016llx) from firmware.\n",
3589 resp->cfg_info.iqmask,
3590 resp->cfg_info.oqmask);
3591 goto setup_nic_dev_fail;
3592 }
3593 dev_dbg(&octeon_dev->pci_dev->dev,
3594 "interface %d, iqmask %016llx, oqmask %016llx, numiqueues %d, numoqueues %d\n",
3595 i, resp->cfg_info.iqmask, resp->cfg_info.oqmask,
3596 num_iqueues, num_oqueues);
3597 netdev = alloc_etherdev_mq(LIO_SIZE, num_iqueues);
3598
3599 if (!netdev) {
3600 dev_err(&octeon_dev->pci_dev->dev, "Device allocation failed\n");
3601 goto setup_nic_dev_fail;
3602 }
3603
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003604 SET_NETDEV_DEV(netdev, &octeon_dev->pci_dev->dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003605
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003606 /* Associate the routines that will handle different
3607 * netdev tasks.
3608 */
3609 netdev->netdev_ops = &lionetdevops;
Vijaya Mohan Guvva1f233f32017-10-31 16:04:53 -07003610 SWITCHDEV_SET_OPS(netdev, &lio_pf_switchdev_ops);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003611
3612 lio = GET_LIO(netdev);
3613
3614 memset(lio, 0, sizeof(struct lio));
3615
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003616 lio->ifidx = ifidx_or_pfnum;
3617
3618 props = &octeon_dev->props[i];
3619 props->gmxport = resp->cfg_info.linfo.gmxport;
3620 props->netdev = netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003621
3622 lio->linfo.num_rxpciq = num_oqueues;
3623 lio->linfo.num_txpciq = num_iqueues;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003624 for (j = 0; j < num_oqueues; j++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003625 lio->linfo.rxpciq[j].u64 =
3626 resp->cfg_info.linfo.rxpciq[j].u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003627 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003628 for (j = 0; j < num_iqueues; j++) {
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003629 lio->linfo.txpciq[j].u64 =
3630 resp->cfg_info.linfo.txpciq[j].u64;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003631 }
3632 lio->linfo.hw_addr = resp->cfg_info.linfo.hw_addr;
3633 lio->linfo.gmxport = resp->cfg_info.linfo.gmxport;
3634 lio->linfo.link.u64 = resp->cfg_info.linfo.link.u64;
3635
3636 lio->msg_enable = netif_msg_init(debug, DEFAULT_MSG_ENABLE);
3637
Raghu Vatsavayie86b1ab2016-08-31 11:03:24 -07003638 if (OCTEON_CN23XX_PF(octeon_dev) ||
3639 OCTEON_CN6XXX(octeon_dev)) {
3640 lio->dev_capability = NETIF_F_HIGHDMA
3641 | NETIF_F_IP_CSUM
3642 | NETIF_F_IPV6_CSUM
3643 | NETIF_F_SG | NETIF_F_RXCSUM
3644 | NETIF_F_GRO
3645 | NETIF_F_TSO | NETIF_F_TSO6
3646 | NETIF_F_LRO;
3647 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003648 netif_set_gso_max_size(netdev, OCTNIC_GSO_MAX_SIZE);
3649
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003650 /* Copy of transmit encapsulation capabilities:
3651 * TSO, TSO6, Checksums for this device
3652 */
3653 lio->enc_dev_capability = NETIF_F_IP_CSUM
3654 | NETIF_F_IPV6_CSUM
3655 | NETIF_F_GSO_UDP_TUNNEL
3656 | NETIF_F_HW_CSUM | NETIF_F_SG
3657 | NETIF_F_RXCSUM
3658 | NETIF_F_TSO | NETIF_F_TSO6
3659 | NETIF_F_LRO;
3660
3661 netdev->hw_enc_features = (lio->enc_dev_capability &
3662 ~NETIF_F_LRO);
3663
3664 lio->dev_capability |= NETIF_F_GSO_UDP_TUNNEL;
3665
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003666 netdev->vlan_features = lio->dev_capability;
3667 /* Add any unchangeable hw features */
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003668 lio->dev_capability |= NETIF_F_HW_VLAN_CTAG_FILTER |
3669 NETIF_F_HW_VLAN_CTAG_RX |
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003670 NETIF_F_HW_VLAN_CTAG_TX;
3671
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003672 netdev->features = (lio->dev_capability & ~NETIF_F_LRO);
3673
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003674 netdev->hw_features = lio->dev_capability;
Raghu Vatsavayi0da0b772016-06-21 22:53:04 -07003675 /*HW_VLAN_RX and HW_VLAN_FILTER is always on*/
3676 netdev->hw_features = netdev->hw_features &
3677 ~NETIF_F_HW_VLAN_CTAG_RX;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003678
Jarod Wilson109cc162016-10-17 15:54:13 -04003679 /* MTU range: 68 - 16000 */
3680 netdev->min_mtu = LIO_MIN_MTU_SIZE;
3681 netdev->max_mtu = LIO_MAX_MTU_SIZE;
3682
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003683 /* Point to the properties for octeon device to which this
3684 * interface belongs.
3685 */
3686 lio->oct_dev = octeon_dev;
3687 lio->octprops = props;
3688 lio->netdev = netdev;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003689
3690 dev_dbg(&octeon_dev->pci_dev->dev,
3691 "if%d gmx: %d hw_addr: 0x%llx\n", i,
3692 lio->linfo.gmxport, CVM_CAST64(lio->linfo.hw_addr));
3693
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003694 for (j = 0; j < octeon_dev->sriov_info.max_vfs; j++) {
3695 u8 vfmac[ETH_ALEN];
3696
3697 random_ether_addr(&vfmac[0]);
3698 if (__liquidio_set_vf_mac(netdev, j,
3699 &vfmac[0], false)) {
3700 dev_err(&octeon_dev->pci_dev->dev,
3701 "Error setting VF%d MAC address\n",
3702 j);
3703 goto setup_nic_dev_fail;
3704 }
3705 }
3706
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003707 /* 64-bit swap required on LE machines */
3708 octeon_swap_8B_data(&lio->linfo.hw_addr, 1);
3709 for (j = 0; j < 6; j++)
3710 mac[j] = *((u8 *)(((u8 *)&lio->linfo.hw_addr) + 2 + j));
3711
3712 /* Copy MAC Address to OS network device structure */
3713
3714 ether_addr_copy(netdev->dev_addr, mac);
3715
Raghu Vatsavayi26236fa2016-06-14 16:54:44 -07003716 /* By default all interfaces on a single Octeon uses the same
3717 * tx and rx queues
3718 */
3719 lio->txq = lio->linfo.txpciq[0].s.q_no;
3720 lio->rxq = lio->linfo.rxpciq[0].s.q_no;
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07003721 if (liquidio_setup_io_queues(octeon_dev, i,
3722 lio->linfo.num_txpciq,
3723 lio->linfo.num_rxpciq)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003724 dev_err(&octeon_dev->pci_dev->dev, "I/O queues creation failed\n");
3725 goto setup_nic_dev_fail;
3726 }
3727
3728 ifstate_set(lio, LIO_IFSTATE_DROQ_OPS);
3729
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003730 lio->tx_qsize = octeon_get_tx_qsize(octeon_dev, lio->txq);
3731 lio->rx_qsize = octeon_get_rx_qsize(octeon_dev, lio->rxq);
3732
Raghu Vatsavayifcd2b5e2016-06-14 16:54:45 -07003733 if (setup_glists(octeon_dev, lio, num_iqueues)) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003734 dev_err(&octeon_dev->pci_dev->dev,
3735 "Gather list allocation failed\n");
3736 goto setup_nic_dev_fail;
3737 }
3738
3739 /* Register ethtool support */
3740 liquidio_set_ethtool_ops(netdev);
Raghu Vatsavayi30136392016-09-01 11:16:11 -07003741 if (lio->oct_dev->chip_id == OCTEON_CN23XX_PF_VID)
3742 octeon_dev->priv_flags = OCT_PRIV_FLAG_DEFAULT;
3743 else
3744 octeon_dev->priv_flags = 0x0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003745
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003746 if (netdev->features & NETIF_F_LRO)
Raghu Vatsavayia2c64b62016-07-03 13:56:55 -07003747 liquidio_set_feature(netdev, OCTNET_CMD_LRO_ENABLE,
3748 OCTNIC_LROIPV4 | OCTNIC_LROIPV6);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003749
Prasad Kanneganti836d57e2017-06-18 12:41:34 -07003750 liquidio_set_feature(netdev, OCTNET_CMD_VLAN_FILTER_CTL,
3751 OCTNET_CMD_VLAN_FILTER_ENABLE);
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003752
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003753 if ((debug != -1) && (debug & NETIF_MSG_HW))
Raghu Vatsavayi63245f22016-06-21 22:53:05 -07003754 liquidio_set_feature(netdev,
3755 OCTNET_CMD_VERBOSE_ENABLE, 0);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003756
Raghu Vatsavayi7b6b6c92016-09-01 11:16:04 -07003757 if (setup_link_status_change_wq(netdev))
3758 goto setup_nic_dev_fail;
3759
Veerasenareddy Burru907aaa62017-10-23 20:33:25 -07003760 if ((octeon_dev->fw_info.app_cap_flags &
3761 LIQUIDIO_TIME_SYNC_CAP) &&
3762 setup_sync_octeon_time_wq(netdev))
3763 goto setup_nic_dev_fail;
3764
Satanand Burla031d4f12017-03-22 11:31:13 -07003765 if (setup_rx_oom_poll_fn(netdev))
3766 goto setup_nic_dev_fail;
3767
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003768 /* Register the network device with the OS */
3769 if (register_netdev(netdev)) {
3770 dev_err(&octeon_dev->pci_dev->dev, "Device registration failed\n");
3771 goto setup_nic_dev_fail;
3772 }
3773
3774 dev_dbg(&octeon_dev->pci_dev->dev,
3775 "Setup NIC ifidx:%d mac:%02x%02x%02x%02x%02x%02x\n",
3776 i, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
3777 netif_carrier_off(netdev);
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003778 lio->link_changes++;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003779
3780 ifstate_set(lio, LIO_IFSTATE_REGISTERED);
3781
Raghu Vatsavayi01fb2372016-07-03 13:56:47 -07003782 /* Sending command to firmware to enable Rx checksum offload
3783 * by default at the time of setup of Liquidio driver for
3784 * this device
3785 */
3786 liquidio_set_rxcsum_command(netdev, OCTNET_CMD_TNL_RX_CSUM_CTL,
3787 OCTNET_CMD_RXCSUM_ENABLE);
3788 liquidio_set_feature(netdev, OCTNET_CMD_TNL_TX_CSUM_CTL,
3789 OCTNET_CMD_TXCSUM_ENABLE);
3790
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003791 dev_dbg(&octeon_dev->pci_dev->dev,
3792 "NIC ifidx:%d Setup successful\n", i);
3793
3794 octeon_free_soft_command(octeon_dev, sc);
3795 }
3796
3797 return 0;
3798
3799setup_nic_dev_fail:
3800
3801 octeon_free_soft_command(octeon_dev, sc);
3802
Raghu Vatsavayiafdf8412016-09-01 11:16:05 -07003803setup_nic_wait_intr:
3804
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003805 while (i--) {
3806 dev_err(&octeon_dev->pci_dev->dev,
3807 "NIC ifidx:%d Setup failed\n", i);
3808 liquidio_destroy_nic_device(octeon_dev, i);
3809 }
3810 return -ENODEV;
3811}
3812
Raghu Vatsavayica6139f2016-11-14 15:54:40 -08003813#ifdef CONFIG_PCI_IOV
3814static int octeon_enable_sriov(struct octeon_device *oct)
3815{
3816 unsigned int num_vfs_alloced = oct->sriov_info.num_vfs_alloced;
3817 struct pci_dev *vfdev;
3818 int err;
3819 u32 u;
3820
3821 if (OCTEON_CN23XX_PF(oct) && num_vfs_alloced) {
3822 err = pci_enable_sriov(oct->pci_dev,
3823 oct->sriov_info.num_vfs_alloced);
3824 if (err) {
3825 dev_err(&oct->pci_dev->dev,
3826 "OCTEON: Failed to enable PCI sriov: %d\n",
3827 err);
3828 oct->sriov_info.num_vfs_alloced = 0;
3829 return err;
3830 }
3831 oct->sriov_info.sriov_enabled = 1;
3832
3833 /* init lookup table that maps DPI ring number to VF pci_dev
3834 * struct pointer
3835 */
3836 u = 0;
3837 vfdev = pci_get_device(PCI_VENDOR_ID_CAVIUM,
3838 OCTEON_CN23XX_VF_VID, NULL);
3839 while (vfdev) {
3840 if (vfdev->is_virtfn &&
3841 (vfdev->physfn == oct->pci_dev)) {
3842 oct->sriov_info.dpiring_to_vfpcidev_lut[u] =
3843 vfdev;
3844 u += oct->sriov_info.rings_per_vf;
3845 }
3846 vfdev = pci_get_device(PCI_VENDOR_ID_CAVIUM,
3847 OCTEON_CN23XX_VF_VID, vfdev);
3848 }
3849 }
3850
3851 return num_vfs_alloced;
3852}
3853
3854static int lio_pci_sriov_disable(struct octeon_device *oct)
3855{
3856 int u;
3857
3858 if (pci_vfs_assigned(oct->pci_dev)) {
3859 dev_err(&oct->pci_dev->dev, "VFs are still assigned to VMs.\n");
3860 return -EPERM;
3861 }
3862
3863 pci_disable_sriov(oct->pci_dev);
3864
3865 u = 0;
3866 while (u < MAX_POSSIBLE_VFS) {
3867 oct->sriov_info.dpiring_to_vfpcidev_lut[u] = NULL;
3868 u += oct->sriov_info.rings_per_vf;
3869 }
3870
3871 oct->sriov_info.num_vfs_alloced = 0;
3872 dev_info(&oct->pci_dev->dev, "oct->pf_num:%d disabled VFs\n",
3873 oct->pf_num);
3874
3875 return 0;
3876}
3877
3878static int liquidio_enable_sriov(struct pci_dev *dev, int num_vfs)
3879{
3880 struct octeon_device *oct = pci_get_drvdata(dev);
3881 int ret = 0;
3882
3883 if ((num_vfs == oct->sriov_info.num_vfs_alloced) &&
3884 (oct->sriov_info.sriov_enabled)) {
3885 dev_info(&oct->pci_dev->dev, "oct->pf_num:%d already enabled num_vfs:%d\n",
3886 oct->pf_num, num_vfs);
3887 return 0;
3888 }
3889
3890 if (!num_vfs) {
3891 ret = lio_pci_sriov_disable(oct);
3892 } else if (num_vfs > oct->sriov_info.max_vfs) {
3893 dev_err(&oct->pci_dev->dev,
3894 "OCTEON: Max allowed VFs:%d user requested:%d",
3895 oct->sriov_info.max_vfs, num_vfs);
3896 ret = -EPERM;
3897 } else {
3898 oct->sriov_info.num_vfs_alloced = num_vfs;
3899 ret = octeon_enable_sriov(oct);
3900 dev_info(&oct->pci_dev->dev, "oct->pf_num:%d num_vfs:%d\n",
3901 oct->pf_num, num_vfs);
3902 }
3903
3904 return ret;
3905}
3906#endif
3907
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003908/**
3909 * \brief initialize the NIC
3910 * @param oct octeon device
3911 *
3912 * This initialization routine is called once the Octeon device application is
3913 * up and running
3914 */
3915static int liquidio_init_nic_module(struct octeon_device *oct)
3916{
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003917 int i, retval = 0;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003918 int num_nic_ports = CFG_GET_NUM_NIC_PORTS(octeon_get_conf(oct));
3919
3920 dev_dbg(&oct->pci_dev->dev, "Initializing network interfaces\n");
3921
3922 /* only default iq and oq were initialized
3923 * initialize the rest as well
3924 */
3925 /* run port_config command for each port */
3926 oct->ifcount = num_nic_ports;
3927
Raghu Vatsavayi30136392016-09-01 11:16:11 -07003928 memset(oct->props, 0, sizeof(struct octdev_props) * num_nic_ports);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003929
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -07003930 for (i = 0; i < MAX_OCTEON_LINKS; i++)
3931 oct->props[i].gmxport = -1;
3932
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003933 retval = setup_nic_devices(oct);
3934 if (retval) {
3935 dev_err(&oct->pci_dev->dev, "Setup NIC devices failed\n");
3936 goto octnet_init_failure;
3937 }
3938
3939 liquidio_ptp_init(oct);
3940
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07003941 dev_dbg(&oct->pci_dev->dev, "Network interfaces ready\n");
3942
3943 return retval;
3944
3945octnet_init_failure:
3946
3947 oct->ifcount = 0;
3948
3949 return retval;
3950}
3951
3952/**
3953 * \brief starter callback that invokes the remaining initialization work after
3954 * the NIC is up and running.
3955 * @param octptr work struct work_struct
3956 */
3957static void nic_starter(struct work_struct *work)
3958{
3959 struct octeon_device *oct;
3960 struct cavium_wk *wk = (struct cavium_wk *)work;
3961
3962 oct = (struct octeon_device *)wk->ctxptr;
3963
3964 if (atomic_read(&oct->status) == OCT_DEV_RUNNING)
3965 return;
3966
3967 /* If the status of the device is CORE_OK, the core
3968 * application has reported its application type. Call
3969 * any registered handlers now and move to the RUNNING
3970 * state.
3971 */
3972 if (atomic_read(&oct->status) != OCT_DEV_CORE_OK) {
3973 schedule_delayed_work(&oct->nic_poll_work.work,
3974 LIQUIDIO_STARTER_POLL_INTERVAL_MS);
3975 return;
3976 }
3977
3978 atomic_set(&oct->status, OCT_DEV_RUNNING);
3979
3980 if (oct->app_mode && oct->app_mode == CVM_DRV_NIC_APP) {
3981 dev_dbg(&oct->pci_dev->dev, "Starting NIC module\n");
3982
3983 if (liquidio_init_nic_module(oct))
3984 dev_err(&oct->pci_dev->dev, "NIC initialization failed\n");
3985 else
3986 handshake[oct->octeon_id].started_ok = 1;
3987 } else {
3988 dev_err(&oct->pci_dev->dev,
3989 "Unexpected application running on NIC (%d). Check firmware.\n",
3990 oct->app_mode);
3991 }
3992
3993 complete(&handshake[oct->octeon_id].started);
3994}
3995
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08003996static int
3997octeon_recv_vf_drv_notice(struct octeon_recv_info *recv_info, void *buf)
3998{
3999 struct octeon_device *oct = (struct octeon_device *)buf;
4000 struct octeon_recv_pkt *recv_pkt = recv_info->recv_pkt;
4001 int i, notice, vf_idx;
Felix Manlunasbb54be52017-04-04 19:26:57 -07004002 bool cores_crashed;
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004003 u64 *data, vf_num;
4004
4005 notice = recv_pkt->rh.r.ossp;
Prasad Kannegantic4ee5d82017-06-18 05:04:11 -07004006 data = (u64 *)(get_rbd(recv_pkt->buffer_ptr[0]) + OCT_DROQ_INFO_SIZE);
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004007
4008 /* the first 64-bit word of data is the vf_num */
4009 vf_num = data[0];
4010 octeon_swap_8B_data(&vf_num, 1);
4011 vf_idx = (int)vf_num - 1;
4012
Felix Manlunasbb54be52017-04-04 19:26:57 -07004013 cores_crashed = READ_ONCE(oct->cores_crashed);
4014
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004015 if (notice == VF_DRV_LOADED) {
4016 if (!(oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vf_idx))) {
4017 oct->sriov_info.vf_drv_loaded_mask |= BIT_ULL(vf_idx);
4018 dev_info(&oct->pci_dev->dev,
4019 "driver for VF%d was loaded\n", vf_idx);
Felix Manlunasbb54be52017-04-04 19:26:57 -07004020 if (!cores_crashed)
4021 try_module_get(THIS_MODULE);
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004022 }
4023 } else if (notice == VF_DRV_REMOVED) {
4024 if (oct->sriov_info.vf_drv_loaded_mask & BIT_ULL(vf_idx)) {
4025 oct->sriov_info.vf_drv_loaded_mask &= ~BIT_ULL(vf_idx);
4026 dev_info(&oct->pci_dev->dev,
4027 "driver for VF%d was removed\n", vf_idx);
Felix Manlunasbb54be52017-04-04 19:26:57 -07004028 if (!cores_crashed)
4029 module_put(THIS_MODULE);
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004030 }
4031 } else if (notice == VF_DRV_MACADDR_CHANGED) {
4032 u8 *b = (u8 *)&data[1];
4033
4034 oct->sriov_info.vf_macaddr[vf_idx] = data[1];
4035 dev_info(&oct->pci_dev->dev,
4036 "VF driver changed VF%d's MAC address to %pM\n",
4037 vf_idx, b + 2);
4038 }
4039
4040 for (i = 0; i < recv_pkt->buffer_count; i++)
4041 recv_buffer_free(recv_pkt->buffer_ptr[i]);
4042 octeon_free_recv_info(recv_info);
4043
4044 return 0;
4045}
4046
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004047/**
4048 * \brief Device initialization for each Octeon device that is probed
4049 * @param octeon_dev octeon device
4050 */
4051static int octeon_device_init(struct octeon_device *octeon_dev)
4052{
4053 int j, ret;
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07004054 char bootcmd[] = "\n";
Rick Farringtonda1542b2017-08-11 18:43:14 -07004055 char *dbg_enb = NULL;
Rick Farrington088b8742017-09-22 17:12:43 -07004056 enum lio_fw_state fw_state;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004057 struct octeon_device_priv *oct_priv =
4058 (struct octeon_device_priv *)octeon_dev->priv;
4059 atomic_set(&octeon_dev->status, OCT_DEV_BEGIN_STATE);
4060
4061 /* Enable access to the octeon device and make its DMA capability
4062 * known to the OS.
4063 */
4064 if (octeon_pci_os_setup(octeon_dev))
4065 return 1;
4066
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08004067 atomic_set(&octeon_dev->status, OCT_DEV_PCI_ENABLE_DONE);
4068
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004069 /* Identify the Octeon type and map the BAR address space. */
4070 if (octeon_chip_specific_setup(octeon_dev)) {
4071 dev_err(&octeon_dev->pci_dev->dev, "Chip specific setup failed\n");
4072 return 1;
4073 }
4074
4075 atomic_set(&octeon_dev->status, OCT_DEV_PCI_MAP_DONE);
4076
Rick Farringtone1e3ce62017-05-16 11:14:50 -07004077 /* Only add a reference after setting status 'OCT_DEV_PCI_MAP_DONE',
4078 * since that is what is required for the reference to be removed
4079 * during de-initialization (see 'octeon_destroy_resources').
4080 */
4081 octeon_register_device(octeon_dev, octeon_dev->pci_dev->bus->number,
4082 PCI_SLOT(octeon_dev->pci_dev->devfn),
4083 PCI_FUNC(octeon_dev->pci_dev->devfn),
4084 true);
4085
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004086 octeon_dev->app_mode = CVM_DRV_INVALID_APP;
4087
Rick Farrington088b8742017-09-22 17:12:43 -07004088 /* CN23XX supports preloaded firmware if the following is true:
4089 *
4090 * The adapter indicates that firmware is currently running AND
4091 * 'fw_type' is 'auto'.
4092 *
4093 * (default state is NEEDS_TO_BE_LOADED, override it if appropriate).
4094 */
4095 if (OCTEON_CN23XX_PF(octeon_dev) &&
4096 cn23xx_fw_loaded(octeon_dev) && fw_type_is_auto()) {
4097 atomic_cmpxchg(octeon_dev->adapter_fw_state,
4098 FW_NEEDS_TO_BE_LOADED, FW_IS_PRELOADED);
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004099 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004100
Rick Farrington088b8742017-09-22 17:12:43 -07004101 /* If loading firmware, only first device of adapter needs to do so. */
4102 fw_state = atomic_cmpxchg(octeon_dev->adapter_fw_state,
4103 FW_NEEDS_TO_BE_LOADED,
4104 FW_IS_BEING_LOADED);
4105
4106 /* Here, [local variable] 'fw_state' is set to one of:
4107 *
4108 * FW_IS_PRELOADED: No firmware is to be loaded (see above)
4109 * FW_NEEDS_TO_BE_LOADED: The driver's first instance will load
4110 * firmware to the adapter.
4111 * FW_IS_BEING_LOADED: The driver's second instance will not load
4112 * firmware to the adapter.
4113 */
4114
4115 /* Prior to f/w load, perform a soft reset of the Octeon device;
4116 * if error resetting, return w/error.
4117 */
4118 if (fw_state == FW_NEEDS_TO_BE_LOADED)
4119 if (octeon_dev->fn_list.soft_reset(octeon_dev))
4120 return 1;
4121
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004122 /* Initialize the dispatch mechanism used to push packets arriving on
4123 * Octeon Output queues.
4124 */
4125 if (octeon_init_dispatch_list(octeon_dev))
4126 return 1;
4127
4128 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
4129 OPCODE_NIC_CORE_DRV_ACTIVE,
4130 octeon_core_drv_init,
4131 octeon_dev);
4132
Raghu Vatsavayi86dea552016-11-14 15:54:43 -08004133 octeon_register_dispatch_fn(octeon_dev, OPCODE_NIC,
4134 OPCODE_NIC_VF_DRV_NOTICE,
4135 octeon_recv_vf_drv_notice, octeon_dev);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004136 INIT_DELAYED_WORK(&octeon_dev->nic_poll_work.work, nic_starter);
4137 octeon_dev->nic_poll_work.ctxptr = (void *)octeon_dev;
4138 schedule_delayed_work(&octeon_dev->nic_poll_work.work,
4139 LIQUIDIO_STARTER_POLL_INTERVAL_MS);
4140
4141 atomic_set(&octeon_dev->status, OCT_DEV_DISPATCH_INIT_DONE);
4142
Raghu Vatsavayic865cdf2016-11-28 16:54:36 -08004143 if (octeon_set_io_queues_off(octeon_dev)) {
4144 dev_err(&octeon_dev->pci_dev->dev, "setting io queues off failed\n");
4145 return 1;
4146 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004147
Raghu Vatsavayi3451b972016-08-31 11:03:26 -07004148 if (OCTEON_CN23XX_PF(octeon_dev)) {
4149 ret = octeon_dev->fn_list.setup_device_regs(octeon_dev);
4150 if (ret) {
4151 dev_err(&octeon_dev->pci_dev->dev, "OCTEON: Failed to configure device registers\n");
4152 return ret;
4153 }
4154 }
4155
4156 /* Initialize soft command buffer pool
4157 */
4158 if (octeon_setup_sc_buffer_pool(octeon_dev)) {
4159 dev_err(&octeon_dev->pci_dev->dev, "sc buffer pool allocation failed\n");
4160 return 1;
4161 }
4162 atomic_set(&octeon_dev->status, OCT_DEV_SC_BUFF_POOL_INIT_DONE);
4163
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004164 /* Setup the data structures that manage this Octeon's Input queues. */
4165 if (octeon_setup_instr_queues(octeon_dev)) {
4166 dev_err(&octeon_dev->pci_dev->dev,
4167 "instruction queue initialization failed\n");
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004168 return 1;
4169 }
4170 atomic_set(&octeon_dev->status, OCT_DEV_INSTR_QUEUE_INIT_DONE);
4171
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004172 /* Initialize lists to manage the requests of different types that
4173 * arrive from user & kernel applications for this octeon device.
4174 */
4175 if (octeon_setup_response_list(octeon_dev)) {
4176 dev_err(&octeon_dev->pci_dev->dev, "Response list allocation failed\n");
4177 return 1;
4178 }
4179 atomic_set(&octeon_dev->status, OCT_DEV_RESP_LIST_INIT_DONE);
4180
4181 if (octeon_setup_output_queues(octeon_dev)) {
4182 dev_err(&octeon_dev->pci_dev->dev, "Output queue initialization failed\n");
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -07004183 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004184 }
4185
4186 atomic_set(&octeon_dev->status, OCT_DEV_DROQ_INIT_DONE);
4187
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004188 if (OCTEON_CN23XX_PF(octeon_dev)) {
Raghu Vatsavayi5d655562016-11-14 15:54:42 -08004189 if (octeon_dev->fn_list.setup_mbox(octeon_dev)) {
4190 dev_err(&octeon_dev->pci_dev->dev, "OCTEON: Mailbox setup failed\n");
4191 return 1;
4192 }
4193 atomic_set(&octeon_dev->status, OCT_DEV_MBOX_SETUP_DONE);
4194
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004195 if (octeon_allocate_ioq_vector(octeon_dev)) {
4196 dev_err(&octeon_dev->pci_dev->dev, "OCTEON: ioq vector allocation failed\n");
4197 return 1;
4198 }
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08004199 atomic_set(&octeon_dev->status, OCT_DEV_MSIX_ALLOC_VECTOR_DONE);
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004200
4201 } else {
4202 /* The input and output queue registers were setup earlier (the
4203 * queues were not enabled). Any additional registers
4204 * that need to be programmed should be done now.
4205 */
4206 ret = octeon_dev->fn_list.setup_device_regs(octeon_dev);
4207 if (ret) {
4208 dev_err(&octeon_dev->pci_dev->dev,
4209 "Failed to configure device registers\n");
4210 return ret;
4211 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004212 }
4213
4214 /* Initialize the tasklet that handles output queue packet processing.*/
4215 dev_dbg(&octeon_dev->pci_dev->dev, "Initializing droq tasklet\n");
4216 tasklet_init(&oct_priv->droq_tasklet, octeon_droq_bh,
4217 (unsigned long)octeon_dev);
4218
4219 /* Setup the interrupt handler and record the INT SUM register address
4220 */
Intiyaz Bashaa82457f2017-08-15 12:46:18 -07004221 if (octeon_setup_interrupt(octeon_dev,
4222 octeon_dev->sriov_info.num_pf_rings))
Raghu Vatsavayi1e0d30f2016-07-03 13:56:52 -07004223 return 1;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004224
4225 /* Enable Octeon device interrupts */
Raghu Vatsavayi5b07aee2016-08-31 11:03:28 -07004226 octeon_dev->fn_list.enable_interrupt(octeon_dev, OCTEON_ALL_INTR);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004227
Raghu Vatsavayi515e7522016-11-14 15:54:44 -08004228 atomic_set(&octeon_dev->status, OCT_DEV_INTR_SET_DONE);
4229
Rick Farrington3c57f612017-08-17 23:11:30 -07004230 /* Send Credit for Octeon Output queues. Credits are always sent BEFORE
4231 * the output queue is enabled.
4232 * This ensures that we'll receive the f/w CORE DRV_ACTIVE message in
4233 * case we've configured CN23XX_SLI_GBL_CONTROL[NOPTR_D] = 0.
4234 * Otherwise, it is possible that the DRV_ACTIVE message will be sent
4235 * before any credits have been issued, causing the ring to be reset
4236 * (and the f/w appear to never have started).
4237 */
4238 for (j = 0; j < octeon_dev->num_oqs; j++)
4239 writel(octeon_dev->droq[j]->max_count,
4240 octeon_dev->droq[j]->pkts_credit_reg);
4241
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004242 /* Enable the input and output queues for this Octeon device */
Raghu Vatsavayi1b7c55c2016-08-31 11:03:27 -07004243 ret = octeon_dev->fn_list.enable_io_queues(octeon_dev);
4244 if (ret) {
4245 dev_err(&octeon_dev->pci_dev->dev, "Failed to enable input/output queues");
4246 return ret;
4247 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004248
4249 atomic_set(&octeon_dev->status, OCT_DEV_IO_QUEUES_DONE);
4250
Rick Farrington088b8742017-09-22 17:12:43 -07004251 if (fw_state == FW_NEEDS_TO_BE_LOADED) {
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004252 dev_dbg(&octeon_dev->pci_dev->dev, "Waiting for DDR initialization...\n");
4253 if (!ddr_timeout) {
4254 dev_info(&octeon_dev->pci_dev->dev,
4255 "WAITING. Set ddr_timeout to non-zero value to proceed with initialization.\n");
4256 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004257
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004258 schedule_timeout_uninterruptible(HZ * LIO_RESET_SECS);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004259
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004260 /* Wait for the octeon to initialize DDR after the soft-reset.*/
4261 while (!ddr_timeout) {
4262 set_current_state(TASK_INTERRUPTIBLE);
4263 if (schedule_timeout(HZ / 10)) {
4264 /* user probably pressed Control-C */
4265 return 1;
4266 }
4267 }
4268 ret = octeon_wait_for_ddr_init(octeon_dev, &ddr_timeout);
4269 if (ret) {
4270 dev_err(&octeon_dev->pci_dev->dev,
4271 "DDR not initialized. Please confirm that board is configured to boot from Flash, ret: %d\n",
4272 ret);
Raghu Vatsavayi4b129ae2016-06-21 22:53:15 -07004273 return 1;
4274 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004275
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004276 if (octeon_wait_for_bootloader(octeon_dev, 1000)) {
4277 dev_err(&octeon_dev->pci_dev->dev, "Board not responding\n");
4278 return 1;
4279 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004280
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004281 /* Divert uboot to take commands from host instead. */
4282 ret = octeon_console_send_cmd(octeon_dev, bootcmd, 50);
Raghu Vatsavayid3d7e6c2016-06-21 22:53:07 -07004283
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004284 dev_dbg(&octeon_dev->pci_dev->dev, "Initializing consoles\n");
4285 ret = octeon_init_consoles(octeon_dev);
4286 if (ret) {
4287 dev_err(&octeon_dev->pci_dev->dev, "Could not access board consoles\n");
4288 return 1;
4289 }
Rick Farringtonda1542b2017-08-11 18:43:14 -07004290 /* If console debug enabled, specify empty string to use default
4291 * enablement ELSE specify NULL string for 'disabled'.
4292 */
4293 dbg_enb = octeon_console_debug_enabled(0) ? "" : NULL;
4294 ret = octeon_add_console(octeon_dev, 0, dbg_enb);
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004295 if (ret) {
4296 dev_err(&octeon_dev->pci_dev->dev, "Could not access board console\n");
4297 return 1;
Rick Farringtonda1542b2017-08-11 18:43:14 -07004298 } else if (octeon_console_debug_enabled(0)) {
4299 /* If console was added AND we're logging console output
4300 * then set our console print function.
4301 */
4302 octeon_dev->console[0].print = octeon_dbg_console_print;
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004303 }
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004304
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004305 atomic_set(&octeon_dev->status, OCT_DEV_CONSOLE_INIT_DONE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004306
Raghu Vatsavayic0eab5b2016-08-31 11:03:29 -07004307 dev_dbg(&octeon_dev->pci_dev->dev, "Loading firmware\n");
4308 ret = load_firmware(octeon_dev);
4309 if (ret) {
4310 dev_err(&octeon_dev->pci_dev->dev, "Could not load firmware to board\n");
4311 return 1;
4312 }
Rick Farrington088b8742017-09-22 17:12:43 -07004313
4314 atomic_set(octeon_dev->adapter_fw_state, FW_HAS_BEEN_LOADED);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004315 }
4316
4317 handshake[octeon_dev->octeon_id].init_ok = 1;
4318 complete(&handshake[octeon_dev->octeon_id].init);
4319
4320 atomic_set(&octeon_dev->status, OCT_DEV_HOST_OK);
4321
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004322 return 0;
4323}
4324
4325/**
Rick Farringtonda1542b2017-08-11 18:43:14 -07004326 * \brief Debug console print function
4327 * @param octeon_dev octeon device
4328 * @param console_num console number
4329 * @param prefix first portion of line to display
4330 * @param suffix second portion of line to display
4331 *
4332 * The OCTEON debug console outputs entire lines (excluding '\n').
4333 * Normally, the line will be passed in the 'prefix' parameter.
4334 * However, due to buffering, it is possible for a line to be split into two
4335 * parts, in which case they will be passed as the 'prefix' parameter and
4336 * 'suffix' parameter.
4337 */
4338static int octeon_dbg_console_print(struct octeon_device *oct, u32 console_num,
4339 char *prefix, char *suffix)
4340{
4341 if (prefix && suffix)
4342 dev_info(&oct->pci_dev->dev, "%u: %s%s\n", console_num, prefix,
4343 suffix);
4344 else if (prefix)
4345 dev_info(&oct->pci_dev->dev, "%u: %s\n", console_num, prefix);
4346 else if (suffix)
4347 dev_info(&oct->pci_dev->dev, "%u: %s\n", console_num, suffix);
4348
4349 return 0;
4350}
4351
4352/**
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07004353 * \brief Exits the module
4354 */
4355static void __exit liquidio_exit(void)
4356{
4357 liquidio_deinit_pci();
4358
4359 pr_info("LiquidIO network module is now unloaded\n");
4360}
4361
4362module_init(liquidio_init);
4363module_exit(liquidio_exit);