Changes in 4.9.276 ALSA: usb-audio: fix rate on Ozone Z90 USB headset media: dvb-usb: fix wrong definition Input: usbtouchscreen - fix control-request directions net: can: ems_usb: fix use-after-free in ems_usb_disconnect() usb: gadget: eem: fix echo command packet response issue USB: cdc-acm: blacklist Heimann USB Appset device ntfs: fix validity check for file name attribute iov_iter_fault_in_readable() should do nothing in xarray case Input: joydev - prevent use of not validated data in JSIOCSBTNMAP ioctl ARM: dts: at91: sama5d4: fix pinctrl muxing btrfs: clear defrag status of a root if starting transaction fails ext4: fix kernel infoleak via ext4_extent_header ext4: correct the cache_nr in tracepoint ext4_es_shrink_exit ext4: remove check for zero nr_to_scan in ext4_es_scan() ext4: fix avefreec in find_group_orlov SUNRPC: Fix the batch tasks count wraparound. SUNRPC: Should wake up the privileged task firstly. s390/cio: dont call css_wait_for_slow_path() inside a lock iio: ltr501: mark register holding upper 8 bits of ALS_DATA{0,1} and PS_DATA as volatile, too iio: ltr501: ltr559: fix initialization of LTR501_ALS_CONTR iio: ltr501: ltr501_read_ps(): add missing endianness conversion serial: sh-sci: Stop dmaengine transfer in sci_stop_tx() serial_cs: Add Option International GSM-Ready 56K/ISDN modem serial_cs: remove wrong GLOBETROTTER.cis entry ath9k: Fix kernel NULL pointer dereference during ath_reset_internal() ssb: sdio: Don't overwrite const buffer if block_write fails seq_buf: Make trace_seq_putmem_hex() support data longer than 8 fuse: check connected before queueing on fpq->io spi: spi-loopback-test: Fix 'tx_buf' might be 'rx_buf' spi: spi-topcliff-pch: Fix potential double free in pch_spi_process_messages() spi: omap-100k: Fix the length judgment problem crypto: nx - add missing MODULE_DEVICE_TABLE media: cpia2: fix memory leak in cpia2_usb_probe media: cobalt: fix race condition in setting HPD media: pvrusb2: fix warning in pvr2_i2c_core_done crypto: qat - check return code of qat_hal_rd_rel_reg() crypto: qat - remove unused macro in FW loader media: v4l2-core: Avoid the dangling pointer in v4l2_fh_release media: bt8xx: Fix a missing check bug in bt878_probe media: st-hva: Fix potential NULL pointer dereferences mmc: via-sdmmc: add a check against NULL pointer dereference crypto: shash - avoid comparing pointers to exported functions under CFI media: dvb_net: avoid speculation from net slot media: siano: fix device register error path btrfs: abort transaction if we fail to update the delayed inode btrfs: disable build on platforms having page size 256K regulator: da9052: Ensure enough delay time for .set_voltage_time_sel ACPI: processor idle: Fix up C-state latency if not ordered block_dump: remove block_dump feature in mark_inode_dirty() fs: dlm: cancel work sync othercon random32: Fix implicit truncation warning in prandom_seed_state() fs: dlm: fix memory leak when fenced ACPI: bus: Call kobject_put() in acpi_init() error path platform/x86: toshiba_acpi: Fix missing error code in toshiba_acpi_setup_keyboard() ACPI: tables: Add custom DSDT file as makefile prerequisite ia64: mca_drv: fix incorrect array size calculation media: s5p_cec: decrement usage count if disabled crypto: ixp4xx - dma_unmap the correct address crypto: ux500 - Fix error return code in hash_hw_final() sata_highbank: fix deferred probing pata_rb532_cf: fix deferred probing media: I2C: change 'RST' to "RSET" to fix multiple build errors pata_octeon_cf: avoid WARN_ON() in ata_host_activate() pata_ep93xx: fix deferred probing media: tc358743: Fix error return code in tc358743_probe_of() media: siano: Fix out-of-bounds warnings in smscore_load_firmware_family2() mmc: usdhi6rol0: fix error return code in usdhi6_probe() media: s5p-g2d: Fix a memory leak on ctx->fh.m2m_ctx hwmon: (max31722) Remove non-standard ACPI device IDs hwmon: (max31790) Fix fan speed reporting for fan7..12 spi: spi-sun6i: Fix chipselect/clock bug crypto: nx - Fix RCU warning in nx842_OF_upd_status ACPI: sysfs: Fix a buffer overrun problem with description_show() ocfs2: fix snprintf() checking net: pch_gbe: Propagate error from devm_gpio_request_one() ehea: fix error return code in ehea_restart_qps() RDMA/rxe: Fix failure during driver load drm: qxl: ensure surf.data is ininitialized wireless: carl9170: fix LEDS build errors & warnings brcmsmac: mac80211_if: Fix a resource leak in an error handling path ath10k: Fix an error code in ath10k_add_interface() netlabel: Fix memory leak in netlbl_mgmt_add_common netfilter: nft_exthdr: check for IPv6 packet before further processing net: ethernet: aeroflex: fix UAF in greth_of_remove net: ethernet: ezchip: fix UAF in nps_enet_remove net: ethernet: ezchip: fix error handling vxlan: add missing rcu_read_lock() in neigh_reduce() i40e: Fix error handling in i40e_vsi_open Bluetooth: mgmt: Fix slab-out-of-bounds in tlv_data_is_valid writeback: fix obtain a reference to a freeing memcg css net: sched: fix warning in tcindex_alloc_perfect_hash tty: nozomi: Fix a resource leak in an error handling function iio: adis_buffer: do not return ints in irq handlers iio: accel: bma180: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: bma220: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: kxcjk-1013: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8312: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: accel: stk8ba50: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: ti-ads1015: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: adc: vf610: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: gyro: bmg160: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: humidity: am2315: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: prox: pulsed-light: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: isl29125: Fix buffer alignment in iio_push_to_buffers_with_timestamp() iio: light: tcs3414: Fix buffer alignment in iio_push_to_buffers_with_timestamp() Input: hil_kbd - fix error return code in hil_dev_connect() char: pcmcia: error out if 'num_bytes_read' is greater than 4 in set_protocol() tty: nozomi: Fix the error handling path of 'nozomi_card_init()' scsi: FlashPoint: Rename si_flags field s390: appldata depends on PROC_SYSCTL staging: gdm724x: check for buffer overflow in gdm_lte_multi_sdu_pkt() staging: gdm724x: check for overflow in gdm_lte_netif_rx() of: Fix truncation of memory sizes on 32-bit platforms scsi: mpt3sas: Fix error return value in _scsih_expander_add() phy: ti: dm816x: Fix the error handling path in 'dm816x_usb_phy_probe() extcon: sm5502: Drop invalid register write in sm5502_reg_data extcon: max8997: Add missing modalias string configfs: fix memleak in configfs_release_bin_file leds: ktd2692: Fix an error handling path mm/huge_memory.c: don't discard hugepage if other processes are mapping it selftests/vm/pkeys: fix alloc_random_pkey() to make it really, really random mmc: vub3000: fix control-request direction scsi: core: Retry I/O for Notify (Enable Spinup) Required error net: pch_gbe: Use proper accessors to BE data in pch_ptp_match() hugetlb: clear huge pte during flush function on mips platform atm: iphase: fix possible use-after-free in ia_module_exit() mISDN: fix possible use-after-free in HFC_cleanup() atm: nicstar: Fix possible use-after-free in nicstar_cleanup() net: Treat __napi_schedule_irqoff() as __napi_schedule() on PREEMPT_RT reiserfs: add check for invalid 1st journal block drm/virtio: Fix double free on probe failure udf: Fix NULL pointer dereference in udf_symlink function e100: handle eeprom as little endian clk: tegra: Ensure that PLLU configuration is applied properly ipv6: use prandom_u32() for ID generation RDMA/cxgb4: Fix missing error code in create_qp() dm space maps: don't reset space map allocation cursor when committing net: micrel: check return value after calling platform_get_resource() fjes: check return value after calling platform_get_resource() selinux: use __GFP_NOWARN with GFP_NOWAIT in the AVC xfrm: Fix error reporting in xfrm_state_construct. wlcore/wl12xx: Fix wl12xx get_mac error if device is in ELP wl1251: Fix possible buffer overflow in wl1251_cmd_scan cw1200: add missing MODULE_DEVICE_TABLE MIPS: add PMD table accounting into MIPS'pmd_alloc_one atm: nicstar: use 'dma_free_coherent' instead of 'kfree' atm: nicstar: register the interrupt handler in the right place RDMA/rxe: Don't overwrite errno from ib_umem_get() sfc: avoid double pci_remove of VFs sfc: error code if SRIOV cannot be disabled wireless: wext-spy: Fix out-of-bounds warning RDMA/cma: Fix rdma_resolve_route() memory leak Bluetooth: Fix the HCI to MGMT status conversion table Bluetooth: Shutdown controller after workqueues are flushed or cancelled Bluetooth: btusb: fix bt fiwmare downloading failure issue for qca btsoc. sctp: add size validation when walking chunks fuse: reject internal errno can: gw: synchronize rcu operations before removing gw job entry can: bcm: delay release of struct bcm_op after synchronize_rcu() mac80211: fix memory corruption in EAPOL handling powerpc/barrier: Avoid collision with clang's __lwsync macro pinctrl/amd: Add device HID for new AMD GPIO controller mmc: sdhci: Fix warning message when accessing RPMB in HS400 mode mmc: core: clear flags before allowing to retune ata: ahci_sunxi: Disable DIPM ASoC: tegra: Set driver_name=tegra for all machine drivers qemu_fw_cfg: Make fw_cfg_rev_attr a proper kobj_attribute ipmi/watchdog: Stop watchdog timer when the current action is 'none' power: supply: ab8500: Fix an old bug seq_buf: Fix overflow in seq_buf_putmem_hex() ipack/carriers/tpci200: Fix a double free in tpci200_pci_probe dm btree remove: assign new_root only when removal succeeds media: dtv5100: fix control-request directions media: zr364xx: fix memory leak in zr364xx_start_readpipe media: gspca/sq905: fix control-request direction media: gspca/sunplus: fix zero-length control requests media: uvcvideo: Fix pixel format change for Elgato Cam Link 4K jfs: fix GPF in diFree smackfs: restrict bytes count in smk_set_cipso() KVM: x86: Use guest MAXPHYADDR from CPUID.0x8000_0008 iff TDP is enabled KVM: X86: Disable hardware breakpoints unconditionally before kvm_x86->run() scsi: core: Fix bad pointer dereference when ehandler kthread is invalid tracing: Do not reference char * as a string in histograms fscrypt: don't ignore minor_hash when hash is 0 tty: serial: fsl_lpuart: fix the potential risk of division or modulo by zero misc/libmasm/module: Fix two use after free in ibmasm_init_one Revert "ALSA: bebob/oxfw: fix Kconfig entry for Mackie d.2 Pro" scsi: lpfc: Fix "Unexpected timeout" error in direct attach topology tty: serial: 8250: serial_cs: Fix a memory leak in error handling path fs/jfs: Fix missing error code in lmLogInit() scsi: iscsi: Add iscsi_cls_conn refcount helpers mfd: da9052/stmpe: Add and modify MODULE_DEVICE_TABLE s390/sclp_vt220: fix console name to match device ALSA: sb: Fix potential double-free of CSP mixer elements powerpc/ps3: Add dma_mask to ps3_dma_region gpio: zynq: Check return value of pm_runtime_get_sync ALSA: ppc: fix error return code in snd_pmac_probe() selftests/powerpc: Fix "no_handler" EBB selftest ASoC: soc-core: Fix the error return code in snd_soc_of_parse_audio_routing() ALSA: bebob: add support for ToneWeal FW66 usb: gadget: f_hid: fix endianness issue with descriptors usb: gadget: hid: fix error return code in hid_bind() powerpc/boot: Fixup device-tree on little endian backlight: lm3630a: Fix return code of .update_status() callback ALSA: hda: Add IRQ check for platform_get_irq() i2c: core: Disable client irq on reboot/shutdown lib/decompress_unlz4.c: correctly handle zero-padding around initrds. pwm: spear: Don't modify HW state in .remove callback power: supply: ab8500: Avoid NULL pointers power: reset: gpio-poweroff: add missing MODULE_DEVICE_TABLE ARM: 9087/1: kprobes: test-thumb: fix for LLVM_IAS=1 watchdog: Fix possible use-after-free in wdt_startup() watchdog: sc520_wdt: Fix possible use-after-free in wdt_turnoff() watchdog: Fix possible use-after-free by calling del_timer_sync() x86/fpu: Return proper error codes from user access functions orangefs: fix orangefs df output. ceph: remove bogus checks and WARN_ONs from ceph_set_page_dirty power: supply: charger-manager: add missing MODULE_DEVICE_TABLE power: supply: ab8500: add missing MODULE_DEVICE_TABLE pwm: tegra: Don't modify HW state in .remove callback ACPI: AMBA: Fix resource name in /proc/iomem virtio-blk: Fix memory leak among suspend/resume procedure virtio_console: Assure used length from device is limited PCI/sysfs: Fix dsm_label_utf16s_to_utf8s() buffer overrun power: supply: rt5033_battery: Fix device tree enumeration um: fix error return code in slip_open() um: fix error return code in winch_tramp() watchdog: aspeed: fix hardware timeout calculation nfs: fix acl memory leak of posix_acl_create() ubifs: Set/Clear I_LINKABLE under i_lock for whiteout inode x86/fpu: Limit xstate copy size in xstateregs_set() ALSA: isa: Fix error return code in snd_cmi8330_probe() hexagon: use common DISCARDS macro ARM: dts: exynos: fix PWM LED max brightness on Odroid XU/XU3 ARM: dts: exynos: fix PWM LED max brightness on Odroid XU4 rtc: fix snprintf() checking in is_rtc_hctosys() ARM: dts: r8a7779, marzen: Fix DU clock names reset: bail if try_module_get() fails memory: fsl_ifc: fix leak of IO mapping on probe failure memory: fsl_ifc: fix leak of private memory on probe failure ARM: dts: am335x: align ti,pindir-d0-out-d1-in property with dt-shema scsi: be2iscsi: Fix an error handling path in beiscsi_dev_probe() mips: always link byteswap helpers into decompressor mips: disable branch profiling in boot/decompress.o MIPS: vdso: Invalid GIC access through VDSO seq_file: disallow extremely large seq buffer allocations Linux 4.9.276 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com> Change-Id: I595c090068eb1b1934b15a0d54394abc38b4b0cc
687 lines
19 KiB
C
687 lines
19 KiB
C
/*
|
|
* Copyright(c) 2015 EZchip Technologies.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
* under the terms and conditions of the GNU General Public License,
|
|
* version 2, as published by the Free Software Foundation.
|
|
*
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
* more details.
|
|
*
|
|
* The full GNU General Public License is included in this distribution in
|
|
* the file called "COPYING".
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/of_address.h>
|
|
#include <linux/of_irq.h>
|
|
#include <linux/of_net.h>
|
|
#include <linux/of_platform.h>
|
|
#include "nps_enet.h"
|
|
|
|
#define DRV_NAME "nps_mgt_enet"
|
|
|
|
static inline bool nps_enet_is_tx_pending(struct nps_enet_priv *priv)
|
|
{
|
|
u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL);
|
|
u32 tx_ctrl_ct = (tx_ctrl_value & TX_CTL_CT_MASK) >> TX_CTL_CT_SHIFT;
|
|
|
|
return (!tx_ctrl_ct && priv->tx_skb);
|
|
}
|
|
|
|
static void nps_enet_clean_rx_fifo(struct net_device *ndev, u32 frame_len)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 i, len = DIV_ROUND_UP(frame_len, sizeof(u32));
|
|
|
|
/* Empty Rx FIFO buffer by reading all words */
|
|
for (i = 0; i < len; i++)
|
|
nps_enet_reg_get(priv, NPS_ENET_REG_RX_BUF);
|
|
}
|
|
|
|
static void nps_enet_read_rx_fifo(struct net_device *ndev,
|
|
unsigned char *dst, u32 length)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
s32 i, last = length & (sizeof(u32) - 1);
|
|
u32 *reg = (u32 *)dst, len = length / sizeof(u32);
|
|
bool dst_is_aligned = IS_ALIGNED((unsigned long)dst, sizeof(u32));
|
|
|
|
/* In case dst is not aligned we need an intermediate buffer */
|
|
if (dst_is_aligned) {
|
|
ioread32_rep(priv->regs_base + NPS_ENET_REG_RX_BUF, reg, len);
|
|
reg += len;
|
|
} else { /* !dst_is_aligned */
|
|
for (i = 0; i < len; i++, reg++) {
|
|
u32 buf = nps_enet_reg_get(priv, NPS_ENET_REG_RX_BUF);
|
|
|
|
put_unaligned_be32(buf, reg);
|
|
}
|
|
}
|
|
/* copy last bytes (if any) */
|
|
if (last) {
|
|
u32 buf;
|
|
|
|
ioread32_rep(priv->regs_base + NPS_ENET_REG_RX_BUF, &buf, 1);
|
|
memcpy((u8 *)reg, &buf, last);
|
|
}
|
|
}
|
|
|
|
static u32 nps_enet_rx_handler(struct net_device *ndev)
|
|
{
|
|
u32 frame_len, err = 0;
|
|
u32 work_done = 0;
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
struct sk_buff *skb;
|
|
u32 rx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_RX_CTL);
|
|
u32 rx_ctrl_cr = (rx_ctrl_value & RX_CTL_CR_MASK) >> RX_CTL_CR_SHIFT;
|
|
u32 rx_ctrl_er = (rx_ctrl_value & RX_CTL_ER_MASK) >> RX_CTL_ER_SHIFT;
|
|
u32 rx_ctrl_crc = (rx_ctrl_value & RX_CTL_CRC_MASK) >> RX_CTL_CRC_SHIFT;
|
|
|
|
frame_len = (rx_ctrl_value & RX_CTL_NR_MASK) >> RX_CTL_NR_SHIFT;
|
|
|
|
/* Check if we got RX */
|
|
if (!rx_ctrl_cr)
|
|
return work_done;
|
|
|
|
/* If we got here there is a work for us */
|
|
work_done++;
|
|
|
|
/* Check Rx error */
|
|
if (rx_ctrl_er) {
|
|
ndev->stats.rx_errors++;
|
|
err = 1;
|
|
}
|
|
|
|
/* Check Rx CRC error */
|
|
if (rx_ctrl_crc) {
|
|
ndev->stats.rx_crc_errors++;
|
|
ndev->stats.rx_dropped++;
|
|
err = 1;
|
|
}
|
|
|
|
/* Check Frame length Min 64b */
|
|
if (unlikely(frame_len < ETH_ZLEN)) {
|
|
ndev->stats.rx_length_errors++;
|
|
ndev->stats.rx_dropped++;
|
|
err = 1;
|
|
}
|
|
|
|
if (err)
|
|
goto rx_irq_clean;
|
|
|
|
/* Skb allocation */
|
|
skb = netdev_alloc_skb_ip_align(ndev, frame_len);
|
|
if (unlikely(!skb)) {
|
|
ndev->stats.rx_errors++;
|
|
ndev->stats.rx_dropped++;
|
|
goto rx_irq_clean;
|
|
}
|
|
|
|
/* Copy frame from Rx fifo into the skb */
|
|
nps_enet_read_rx_fifo(ndev, skb->data, frame_len);
|
|
|
|
skb_put(skb, frame_len);
|
|
skb->protocol = eth_type_trans(skb, ndev);
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
|
|
|
ndev->stats.rx_packets++;
|
|
ndev->stats.rx_bytes += frame_len;
|
|
netif_receive_skb(skb);
|
|
|
|
goto rx_irq_frame_done;
|
|
|
|
rx_irq_clean:
|
|
/* Clean Rx fifo */
|
|
nps_enet_clean_rx_fifo(ndev, frame_len);
|
|
|
|
rx_irq_frame_done:
|
|
/* Ack Rx ctrl register */
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_RX_CTL, 0);
|
|
|
|
return work_done;
|
|
}
|
|
|
|
static void nps_enet_tx_handler(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 tx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_TX_CTL);
|
|
u32 tx_ctrl_et = (tx_ctrl_value & TX_CTL_ET_MASK) >> TX_CTL_ET_SHIFT;
|
|
u32 tx_ctrl_nt = (tx_ctrl_value & TX_CTL_NT_MASK) >> TX_CTL_NT_SHIFT;
|
|
|
|
/* Check if we got TX */
|
|
if (!nps_enet_is_tx_pending(priv))
|
|
return;
|
|
|
|
/* Ack Tx ctrl register */
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_TX_CTL, 0);
|
|
|
|
/* Check Tx transmit error */
|
|
if (unlikely(tx_ctrl_et)) {
|
|
ndev->stats.tx_errors++;
|
|
} else {
|
|
ndev->stats.tx_packets++;
|
|
ndev->stats.tx_bytes += tx_ctrl_nt;
|
|
}
|
|
|
|
dev_kfree_skb(priv->tx_skb);
|
|
priv->tx_skb = NULL;
|
|
|
|
if (netif_queue_stopped(ndev))
|
|
netif_wake_queue(ndev);
|
|
}
|
|
|
|
/**
|
|
* nps_enet_poll - NAPI poll handler.
|
|
* @napi: Pointer to napi_struct structure.
|
|
* @budget: How many frames to process on one call.
|
|
*
|
|
* returns: Number of processed frames
|
|
*/
|
|
static int nps_enet_poll(struct napi_struct *napi, int budget)
|
|
{
|
|
struct net_device *ndev = napi->dev;
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 work_done;
|
|
|
|
nps_enet_tx_handler(ndev);
|
|
work_done = nps_enet_rx_handler(ndev);
|
|
if (work_done < budget) {
|
|
u32 buf_int_enable_value = 0;
|
|
|
|
napi_complete_done(napi, work_done);
|
|
|
|
/* set tx_done and rx_rdy bits */
|
|
buf_int_enable_value |= NPS_ENET_ENABLE << RX_RDY_SHIFT;
|
|
buf_int_enable_value |= NPS_ENET_ENABLE << TX_DONE_SHIFT;
|
|
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE,
|
|
buf_int_enable_value);
|
|
|
|
/* in case we will get a tx interrupt while interrupts
|
|
* are masked, we will lose it since the tx is edge interrupt.
|
|
* specifically, while executing the code section above,
|
|
* between nps_enet_tx_handler and the interrupts enable, all
|
|
* tx requests will be stuck until we will get an rx interrupt.
|
|
* the two code lines below will solve this situation by
|
|
* re-adding ourselves to the poll list.
|
|
*/
|
|
if (nps_enet_is_tx_pending(priv)) {
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0);
|
|
napi_reschedule(napi);
|
|
}
|
|
}
|
|
|
|
return work_done;
|
|
}
|
|
|
|
/**
|
|
* nps_enet_irq_handler - Global interrupt handler for ENET.
|
|
* @irq: irq number.
|
|
* @dev_instance: device instance.
|
|
*
|
|
* returns: IRQ_HANDLED for all cases.
|
|
*
|
|
* EZchip ENET has 2 interrupt causes, and depending on bits raised in
|
|
* CTRL registers we may tell what is a reason for interrupt to fire up.
|
|
* We got one for RX and the other for TX (completion).
|
|
*/
|
|
static irqreturn_t nps_enet_irq_handler(s32 irq, void *dev_instance)
|
|
{
|
|
struct net_device *ndev = dev_instance;
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 rx_ctrl_value = nps_enet_reg_get(priv, NPS_ENET_REG_RX_CTL);
|
|
u32 rx_ctrl_cr = (rx_ctrl_value & RX_CTL_CR_MASK) >> RX_CTL_CR_SHIFT;
|
|
|
|
if (nps_enet_is_tx_pending(priv) || rx_ctrl_cr)
|
|
if (likely(napi_schedule_prep(&priv->napi))) {
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0);
|
|
__napi_schedule(&priv->napi);
|
|
}
|
|
|
|
return IRQ_HANDLED;
|
|
}
|
|
|
|
static void nps_enet_set_hw_mac_address(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 ge_mac_cfg_1_value = 0;
|
|
u32 *ge_mac_cfg_2_value = &priv->ge_mac_cfg_2_value;
|
|
|
|
/* set MAC address in HW */
|
|
ge_mac_cfg_1_value |= ndev->dev_addr[0] << CFG_1_OCTET_0_SHIFT;
|
|
ge_mac_cfg_1_value |= ndev->dev_addr[1] << CFG_1_OCTET_1_SHIFT;
|
|
ge_mac_cfg_1_value |= ndev->dev_addr[2] << CFG_1_OCTET_2_SHIFT;
|
|
ge_mac_cfg_1_value |= ndev->dev_addr[3] << CFG_1_OCTET_3_SHIFT;
|
|
*ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_OCTET_4_MASK)
|
|
| ndev->dev_addr[4] << CFG_2_OCTET_4_SHIFT;
|
|
*ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_OCTET_5_MASK)
|
|
| ndev->dev_addr[5] << CFG_2_OCTET_5_SHIFT;
|
|
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_1,
|
|
ge_mac_cfg_1_value);
|
|
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_2,
|
|
*ge_mac_cfg_2_value);
|
|
}
|
|
|
|
/**
|
|
* nps_enet_hw_reset - Reset the network device.
|
|
* @ndev: Pointer to the network device.
|
|
*
|
|
* This function reset the PCS and TX fifo.
|
|
* The programming model is to set the relevant reset bits
|
|
* wait for some time for this to propagate and then unset
|
|
* the reset bits. This way we ensure that reset procedure
|
|
* is done successfully by device.
|
|
*/
|
|
static void nps_enet_hw_reset(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 ge_rst_value = 0, phase_fifo_ctl_value = 0;
|
|
|
|
/* Pcs reset sequence*/
|
|
ge_rst_value |= NPS_ENET_ENABLE << RST_GMAC_0_SHIFT;
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_RST, ge_rst_value);
|
|
usleep_range(10, 20);
|
|
ge_rst_value = 0;
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_RST, ge_rst_value);
|
|
|
|
/* Tx fifo reset sequence */
|
|
phase_fifo_ctl_value |= NPS_ENET_ENABLE << PHASE_FIFO_CTL_RST_SHIFT;
|
|
phase_fifo_ctl_value |= NPS_ENET_ENABLE << PHASE_FIFO_CTL_INIT_SHIFT;
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_PHASE_FIFO_CTL,
|
|
phase_fifo_ctl_value);
|
|
usleep_range(10, 20);
|
|
phase_fifo_ctl_value = 0;
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_PHASE_FIFO_CTL,
|
|
phase_fifo_ctl_value);
|
|
}
|
|
|
|
static void nps_enet_hw_enable_control(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 ge_mac_cfg_0_value = 0, buf_int_enable_value = 0;
|
|
u32 *ge_mac_cfg_2_value = &priv->ge_mac_cfg_2_value;
|
|
u32 *ge_mac_cfg_3_value = &priv->ge_mac_cfg_3_value;
|
|
s32 max_frame_length;
|
|
|
|
/* Enable Rx and Tx statistics */
|
|
*ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_STAT_EN_MASK)
|
|
| NPS_ENET_GE_MAC_CFG_2_STAT_EN << CFG_2_STAT_EN_SHIFT;
|
|
|
|
/* Discard packets with different MAC address */
|
|
*ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_DISK_DA_MASK)
|
|
| NPS_ENET_ENABLE << CFG_2_DISK_DA_SHIFT;
|
|
|
|
/* Discard multicast packets */
|
|
*ge_mac_cfg_2_value = (*ge_mac_cfg_2_value & ~CFG_2_DISK_MC_MASK)
|
|
| NPS_ENET_ENABLE << CFG_2_DISK_MC_SHIFT;
|
|
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_2,
|
|
*ge_mac_cfg_2_value);
|
|
|
|
/* Discard Packets bigger than max frame length */
|
|
max_frame_length = ETH_HLEN + ndev->mtu + ETH_FCS_LEN;
|
|
if (max_frame_length <= NPS_ENET_MAX_FRAME_LENGTH) {
|
|
*ge_mac_cfg_3_value =
|
|
(*ge_mac_cfg_3_value & ~CFG_3_MAX_LEN_MASK)
|
|
| max_frame_length << CFG_3_MAX_LEN_SHIFT;
|
|
}
|
|
|
|
/* Enable interrupts */
|
|
buf_int_enable_value |= NPS_ENET_ENABLE << RX_RDY_SHIFT;
|
|
buf_int_enable_value |= NPS_ENET_ENABLE << TX_DONE_SHIFT;
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE,
|
|
buf_int_enable_value);
|
|
|
|
/* Write device MAC address to HW */
|
|
nps_enet_set_hw_mac_address(ndev);
|
|
|
|
/* Rx and Tx HW features */
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_PAD_EN_SHIFT;
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_CRC_EN_SHIFT;
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_CRC_STRIP_SHIFT;
|
|
|
|
/* IFG configuration */
|
|
ge_mac_cfg_0_value |=
|
|
NPS_ENET_GE_MAC_CFG_0_RX_IFG << CFG_0_RX_IFG_SHIFT;
|
|
ge_mac_cfg_0_value |=
|
|
NPS_ENET_GE_MAC_CFG_0_TX_IFG << CFG_0_TX_IFG_SHIFT;
|
|
|
|
/* preamble configuration */
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_PR_CHECK_EN_SHIFT;
|
|
ge_mac_cfg_0_value |=
|
|
NPS_ENET_GE_MAC_CFG_0_TX_PR_LEN << CFG_0_TX_PR_LEN_SHIFT;
|
|
|
|
/* enable flow control frames */
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_FC_EN_SHIFT;
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_FC_EN_SHIFT;
|
|
ge_mac_cfg_0_value |=
|
|
NPS_ENET_GE_MAC_CFG_0_TX_FC_RETR << CFG_0_TX_FC_RETR_SHIFT;
|
|
*ge_mac_cfg_3_value = (*ge_mac_cfg_3_value & ~CFG_3_CF_DROP_MASK)
|
|
| NPS_ENET_ENABLE << CFG_3_CF_DROP_SHIFT;
|
|
|
|
/* Enable Rx and Tx */
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_RX_EN_SHIFT;
|
|
ge_mac_cfg_0_value |= NPS_ENET_ENABLE << CFG_0_TX_EN_SHIFT;
|
|
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_3,
|
|
*ge_mac_cfg_3_value);
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_0,
|
|
ge_mac_cfg_0_value);
|
|
}
|
|
|
|
static void nps_enet_hw_disable_control(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
|
|
/* Disable interrupts */
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_BUF_INT_ENABLE, 0);
|
|
|
|
/* Disable Rx and Tx */
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_0, 0);
|
|
}
|
|
|
|
static void nps_enet_send_frame(struct net_device *ndev,
|
|
struct sk_buff *skb)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 tx_ctrl_value = 0;
|
|
short length = skb->len;
|
|
u32 i, len = DIV_ROUND_UP(length, sizeof(u32));
|
|
u32 *src = (void *)skb->data;
|
|
bool src_is_aligned = IS_ALIGNED((unsigned long)src, sizeof(u32));
|
|
|
|
/* In case src is not aligned we need an intermediate buffer */
|
|
if (src_is_aligned)
|
|
iowrite32_rep(priv->regs_base + NPS_ENET_REG_TX_BUF, src, len);
|
|
else /* !src_is_aligned */
|
|
for (i = 0; i < len; i++, src++)
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_TX_BUF,
|
|
get_unaligned_be32(src));
|
|
|
|
/* Write the length of the Frame */
|
|
tx_ctrl_value |= length << TX_CTL_NT_SHIFT;
|
|
|
|
tx_ctrl_value |= NPS_ENET_ENABLE << TX_CTL_CT_SHIFT;
|
|
/* Send Frame */
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_TX_CTL, tx_ctrl_value);
|
|
}
|
|
|
|
/**
|
|
* nps_enet_set_mac_address - Set the MAC address for this device.
|
|
* @ndev: Pointer to net_device structure.
|
|
* @p: 6 byte Address to be written as MAC address.
|
|
*
|
|
* This function copies the HW address from the sockaddr structure to the
|
|
* net_device structure and updates the address in HW.
|
|
*
|
|
* returns: -EBUSY if the net device is busy or 0 if the address is set
|
|
* successfully.
|
|
*/
|
|
static s32 nps_enet_set_mac_address(struct net_device *ndev, void *p)
|
|
{
|
|
struct sockaddr *addr = p;
|
|
s32 res;
|
|
|
|
if (netif_running(ndev))
|
|
return -EBUSY;
|
|
|
|
res = eth_mac_addr(ndev, p);
|
|
if (!res) {
|
|
ether_addr_copy(ndev->dev_addr, addr->sa_data);
|
|
nps_enet_set_hw_mac_address(ndev);
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
/**
|
|
* nps_enet_set_rx_mode - Change the receive filtering mode.
|
|
* @ndev: Pointer to the network device.
|
|
*
|
|
* This function enables/disables promiscuous mode
|
|
*/
|
|
static void nps_enet_set_rx_mode(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
u32 ge_mac_cfg_2_value = priv->ge_mac_cfg_2_value;
|
|
|
|
if (ndev->flags & IFF_PROMISC) {
|
|
ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_DA_MASK)
|
|
| NPS_ENET_DISABLE << CFG_2_DISK_DA_SHIFT;
|
|
ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_MC_MASK)
|
|
| NPS_ENET_DISABLE << CFG_2_DISK_MC_SHIFT;
|
|
|
|
} else {
|
|
ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_DA_MASK)
|
|
| NPS_ENET_ENABLE << CFG_2_DISK_DA_SHIFT;
|
|
ge_mac_cfg_2_value = (ge_mac_cfg_2_value & ~CFG_2_DISK_MC_MASK)
|
|
| NPS_ENET_ENABLE << CFG_2_DISK_MC_SHIFT;
|
|
}
|
|
|
|
nps_enet_reg_set(priv, NPS_ENET_REG_GE_MAC_CFG_2, ge_mac_cfg_2_value);
|
|
}
|
|
|
|
/**
|
|
* nps_enet_open - Open the network device.
|
|
* @ndev: Pointer to the network device.
|
|
*
|
|
* returns: 0, on success or non-zero error value on failure.
|
|
*
|
|
* This function sets the MAC address, requests and enables an IRQ
|
|
* for the ENET device and starts the Tx queue.
|
|
*/
|
|
static s32 nps_enet_open(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
s32 err;
|
|
|
|
/* Reset private variables */
|
|
priv->tx_skb = NULL;
|
|
priv->ge_mac_cfg_2_value = 0;
|
|
priv->ge_mac_cfg_3_value = 0;
|
|
|
|
/* ge_mac_cfg_3 default values */
|
|
priv->ge_mac_cfg_3_value |=
|
|
NPS_ENET_GE_MAC_CFG_3_RX_IFG_TH << CFG_3_RX_IFG_TH_SHIFT;
|
|
|
|
priv->ge_mac_cfg_3_value |=
|
|
NPS_ENET_GE_MAC_CFG_3_MAX_LEN << CFG_3_MAX_LEN_SHIFT;
|
|
|
|
/* Disable HW device */
|
|
nps_enet_hw_disable_control(ndev);
|
|
|
|
/* irq Rx allocation */
|
|
err = request_irq(priv->irq, nps_enet_irq_handler,
|
|
0, "enet-rx-tx", ndev);
|
|
if (err)
|
|
return err;
|
|
|
|
napi_enable(&priv->napi);
|
|
|
|
/* Enable HW device */
|
|
nps_enet_hw_reset(ndev);
|
|
nps_enet_hw_enable_control(ndev);
|
|
|
|
netif_start_queue(ndev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* nps_enet_stop - Close the network device.
|
|
* @ndev: Pointer to the network device.
|
|
*
|
|
* This function stops the Tx queue, disables interrupts for the ENET device.
|
|
*/
|
|
static s32 nps_enet_stop(struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
|
|
napi_disable(&priv->napi);
|
|
netif_stop_queue(ndev);
|
|
nps_enet_hw_disable_control(ndev);
|
|
free_irq(priv->irq, ndev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* nps_enet_start_xmit - Starts the data transmission.
|
|
* @skb: sk_buff pointer that contains data to be Transmitted.
|
|
* @ndev: Pointer to net_device structure.
|
|
*
|
|
* returns: NETDEV_TX_OK, on success
|
|
* NETDEV_TX_BUSY, if any of the descriptors are not free.
|
|
*
|
|
* This function is invoked from upper layers to initiate transmission.
|
|
*/
|
|
static netdev_tx_t nps_enet_start_xmit(struct sk_buff *skb,
|
|
struct net_device *ndev)
|
|
{
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
|
|
/* This driver handles one frame at a time */
|
|
netif_stop_queue(ndev);
|
|
|
|
priv->tx_skb = skb;
|
|
|
|
/* make sure tx_skb is actually written to the memory
|
|
* before the HW is informed and the IRQ is fired.
|
|
*/
|
|
wmb();
|
|
|
|
nps_enet_send_frame(ndev, skb);
|
|
|
|
return NETDEV_TX_OK;
|
|
}
|
|
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
static void nps_enet_poll_controller(struct net_device *ndev)
|
|
{
|
|
disable_irq(ndev->irq);
|
|
nps_enet_irq_handler(ndev->irq, ndev);
|
|
enable_irq(ndev->irq);
|
|
}
|
|
#endif
|
|
|
|
static const struct net_device_ops nps_netdev_ops = {
|
|
.ndo_open = nps_enet_open,
|
|
.ndo_stop = nps_enet_stop,
|
|
.ndo_start_xmit = nps_enet_start_xmit,
|
|
.ndo_set_mac_address = nps_enet_set_mac_address,
|
|
.ndo_set_rx_mode = nps_enet_set_rx_mode,
|
|
#ifdef CONFIG_NET_POLL_CONTROLLER
|
|
.ndo_poll_controller = nps_enet_poll_controller,
|
|
#endif
|
|
};
|
|
|
|
static s32 nps_enet_probe(struct platform_device *pdev)
|
|
{
|
|
struct device *dev = &pdev->dev;
|
|
struct net_device *ndev;
|
|
struct nps_enet_priv *priv;
|
|
s32 err = 0;
|
|
const char *mac_addr;
|
|
struct resource *res_regs;
|
|
|
|
if (!dev->of_node)
|
|
return -ENODEV;
|
|
|
|
ndev = alloc_etherdev(sizeof(struct nps_enet_priv));
|
|
if (!ndev)
|
|
return -ENOMEM;
|
|
|
|
platform_set_drvdata(pdev, ndev);
|
|
SET_NETDEV_DEV(ndev, dev);
|
|
priv = netdev_priv(ndev);
|
|
|
|
/* The EZ NET specific entries in the device structure. */
|
|
ndev->netdev_ops = &nps_netdev_ops;
|
|
ndev->watchdog_timeo = (400 * HZ / 1000);
|
|
/* FIXME :: no multicast support yet */
|
|
ndev->flags &= ~IFF_MULTICAST;
|
|
|
|
res_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
priv->regs_base = devm_ioremap_resource(dev, res_regs);
|
|
if (IS_ERR(priv->regs_base)) {
|
|
err = PTR_ERR(priv->regs_base);
|
|
goto out_netdev;
|
|
}
|
|
dev_dbg(dev, "Registers base address is 0x%p\n", priv->regs_base);
|
|
|
|
/* set kernel MAC address to dev */
|
|
mac_addr = of_get_mac_address(dev->of_node);
|
|
if (mac_addr)
|
|
ether_addr_copy(ndev->dev_addr, mac_addr);
|
|
else
|
|
eth_hw_addr_random(ndev);
|
|
|
|
/* Get IRQ number */
|
|
priv->irq = platform_get_irq(pdev, 0);
|
|
if (priv->irq < 0) {
|
|
dev_err(dev, "failed to retrieve <irq Rx-Tx> value from device tree\n");
|
|
err = -ENODEV;
|
|
goto out_netdev;
|
|
}
|
|
|
|
netif_napi_add(ndev, &priv->napi, nps_enet_poll,
|
|
NPS_ENET_NAPI_POLL_WEIGHT);
|
|
|
|
/* Register the driver. Should be the last thing in probe */
|
|
err = register_netdev(ndev);
|
|
if (err) {
|
|
dev_err(dev, "Failed to register ndev for %s, err = 0x%08x\n",
|
|
ndev->name, (s32)err);
|
|
goto out_netif_api;
|
|
}
|
|
|
|
dev_info(dev, "(rx/tx=%d)\n", priv->irq);
|
|
return 0;
|
|
|
|
out_netif_api:
|
|
netif_napi_del(&priv->napi);
|
|
out_netdev:
|
|
if (err)
|
|
free_netdev(ndev);
|
|
|
|
return err;
|
|
}
|
|
|
|
static s32 nps_enet_remove(struct platform_device *pdev)
|
|
{
|
|
struct net_device *ndev = platform_get_drvdata(pdev);
|
|
struct nps_enet_priv *priv = netdev_priv(ndev);
|
|
|
|
unregister_netdev(ndev);
|
|
netif_napi_del(&priv->napi);
|
|
free_netdev(ndev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id nps_enet_dt_ids[] = {
|
|
{ .compatible = "ezchip,nps-mgt-enet" },
|
|
{ /* Sentinel */ }
|
|
};
|
|
MODULE_DEVICE_TABLE(of, nps_enet_dt_ids);
|
|
|
|
static struct platform_driver nps_enet_driver = {
|
|
.probe = nps_enet_probe,
|
|
.remove = nps_enet_remove,
|
|
.driver = {
|
|
.name = DRV_NAME,
|
|
.of_match_table = nps_enet_dt_ids,
|
|
},
|
|
};
|
|
|
|
module_platform_driver(nps_enet_driver);
|
|
|
|
MODULE_AUTHOR("EZchip Semiconductor");
|
|
MODULE_LICENSE("GPL v2");
|