Changes in 4.9.337 mm/khugepaged: fix GUP-fast interaction by sending IPI mm/khugepaged: invoke MMU notifiers in shmem/file collapse paths block: unhash blkdev part inode when the part is deleted ASoC: ops: Check bounds for second channel in snd_soc_put_volsw_sx() can: sja1000: fix size of OCR_MODE_MASK define ASoC: ops: Correct bounds check for second channel on SX controls udf: Discard preallocation before extending file with a hole udf: Drop unused arguments of udf_delete_aext() udf: Fix preallocation discarding at indirect extent boundary udf: Do not bother looking for prealloc extents if i_lenExtents matches i_size udf: Fix extending file within last block usb: gadget: uvc: Prevent buffer overflow in setup handler USB: serial: cp210x: add Kamstrup RF sniffer PIDs Bluetooth: L2CAP: Fix u8 overflow net: loopback: use NET_NAME_PREDICTABLE for name_assign_type drivers: soc: ti: knav_qmss_queue: Mark knav_acc_firmwares as static arm: dts: spear600: Fix clcd interrupt soc: ti: smartreflex: Fix PM disable depth imbalance in omap_sr_probe ARM: dts: dove: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-370: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-xp: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-375: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-38x: Fix assigned-addresses for every PCIe Root Port ARM: dts: armada-39x: Fix assigned-addresses for every PCIe Root Port ARM: mmp: fix timer_read delay pstore: Avoid kcore oops by vmap()ing with VM_IOREMAP cpuidle: dt: Return the correct numbers of parsed idle states alpha: fix syscall entry in !AUDUT_SYSCALL case PM: hibernate: Fix mistake in kerneldoc comment fs: don't audit the capability check in simple_xattr_list() perf: Fix possible memleak in pmu_dev_alloc() timerqueue: Use rb_entry_safe() in timerqueue_getnext() ocfs2: fix memory leak in ocfs2_stack_glue_init() MIPS: vpe-mt: fix possible memory leak while module exiting MIPS: vpe-cmp: fix possible memory leak while module exiting PNP: fix name memory leak in pnp_alloc_dev() irqchip: gic-pm: Use pm_runtime_resume_and_get() in gic_probe() libfs: add DEFINE_SIMPLE_ATTRIBUTE_SIGNED for signed value lib/notifier-error-inject: fix error when writing -errno to debugfs file rapidio: fix possible name leaks when rio_add_device() fails rapidio: rio: fix possible name leak in rio_register_mport() ACPICA: Fix use-after-free in acpi_ut_copy_ipackage_to_ipackage() uprobes/x86: Allow to probe a NOP instruction with 0x66 prefix x86/xen: Fix memory leak in xen_init_lock_cpu() MIPS: BCM63xx: Add check for NULL for clk in clk_enable fs: sysv: Fix sysv_nblocks() returns wrong value rapidio: fix possible UAF when kfifo_alloc() fails eventfd: change int to __u64 in eventfd_signal() ifndef CONFIG_EVENTFD hfs: Fix OOB Write in hfs_asc2mac rapidio: devices: fix missing put_device in mport_cdev_open wifi: ath9k: hif_usb: fix memory leak of urbs in ath9k_hif_usb_dealloc_tx_urbs() wifi: ath9k: hif_usb: Fix use-after-free in ath9k_hif_usb_reg_in_cb() media: i2c: ad5820: Fix error path media: vivid: fix compose size exceed boundary mtd: Fix device name leak when register device failed in add_mtd_device() ASoC: pxa: fix null-pointer dereference in filter() regulator: core: fix unbalanced of node refcount in regulator_dev_lookup() ima: Fix misuse of dereference of pointer in template_desc_init_fields() wifi: ath10k: Fix return value in ath10k_pci_init() mtd: lpddr2_nvm: Fix possible null-ptr-deref Input: elants_i2c - properly handle the reset GPIO when power is off media: solo6x10: fix possible memory leak in solo_sysfs_init() media: platform: exynos4-is: Fix error handling in fimc_md_init() HID: hid-sensor-custom: set fixed size for custom attributes ALSA: seq: fix undefined behavior in bit shift for SNDRV_SEQ_FILTER_USE_EVENT clk: rockchip: Fix memory leak in rockchip_clk_register_pll() mtd: maps: pxa2xx-flash: fix memory leak in probe media: imon: fix a race condition in send_packet() pinctrl: pinconf-generic: add missing of_node_put() media: dvb-usb: az6027: fix null-ptr-deref in az6027_i2c_xfer() NFSv4.2: Fix a memory stomp in decode_attr_security_label NFSv4: Fix a deadlock between nfs4_open_recover_helper() and delegreturn ALSA: asihpi: fix missing pci_disable_device() drm/radeon: Fix PCI device refcount leak in radeon_atrm_get_bios() drm/amdgpu: Fix PCI device refcount leak in amdgpu_atrm_get_bios() ASoC: pcm512x: Fix PM disable depth imbalance in pcm512x_probe bonding: uninitialized variable in bond_miimon_inspect() regulator: core: fix module refcount leak in set_supply() media: saa7164: fix missing pci_disable_device() ALSA: mts64: fix possible null-ptr-defer in snd_mts64_interrupt SUNRPC: Fix missing release socket in rpc_sockname() mmc: moxart: fix return value check of mmc_add_host() mmc: mxcmmc: fix return value check of mmc_add_host() mmc: rtsx_usb_sdmmc: fix return value check of mmc_add_host() mmc: toshsd: fix return value check of mmc_add_host() mmc: vub300: fix return value check of mmc_add_host() mmc: via-sdmmc: fix return value check of mmc_add_host() mmc: wbsd: fix return value check of mmc_add_host() mmc: mmci: fix return value check of mmc_add_host() media: c8sectpfe: Add of_node_put() when breaking out of loop media: coda: Add check for dcoda_iram_alloc media: coda: Add check for kmalloc wifi: rtl8xxxu: Add __packed to struct rtl8723bu_c2h wifi: brcmfmac: Fix error return code in brcmf_sdio_download_firmware() blktrace: Fix output non-blktrace event when blk_classic option enabled net: vmw_vsock: vmci: Check memcpy_from_msg() net: defxx: Fix missing err handling in dfx_init() drivers: net: qlcnic: Fix potential memory leak in qlcnic_sriov_init() ethernet: s2io: don't call dev_kfree_skb() under spin_lock_irqsave() net: farsync: Fix kmemleak when rmmods farsync net/tunnel: wait until all sk_user_data reader finish before releasing the sock net: apple: mace: don't call dev_kfree_skb() under spin_lock_irqsave() net: apple: bmac: don't call dev_kfree_skb() under spin_lock_irqsave() net: emaclite: don't call dev_kfree_skb() under spin_lock_irqsave() net: ethernet: dnet: don't call dev_kfree_skb() under spin_lock_irqsave() hamradio: don't call dev_kfree_skb() under spin_lock_irqsave() net: amd: lance: don't call dev_kfree_skb() under spin_lock_irqsave() ntb_netdev: Use dev_kfree_skb_any() in interrupt context Bluetooth: btusb: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_qca: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_h5: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_bcsp: don't call kfree_skb() under spin_lock_irqsave() Bluetooth: hci_core: don't call kfree_skb() under spin_lock_irqsave() stmmac: fix potential division by 0 scsi: hpsa: Fix error handling in hpsa_add_sas_host() scsi: hpsa: Fix possible memory leak in hpsa_add_sas_device() scsi: fcoe: Fix possible name leak when device_register() fails scsi: ipr: Fix WARNING in ipr_init() scsi: fcoe: Fix transport not deattached when fcoe_if_init() fails scsi: snic: Fix possible UAF in snic_tgt_create() orangefs: Fix sysfs not cleanup when dev init failed crypto: img-hash - Fix variable dereferenced before check 'hdev->req' hwrng: amd - Fix PCI device refcount leak hwrng: geode - Fix PCI device refcount leak IB/IPoIB: Fix queue count inconsistency for PKEY child interfaces drivers: dio: fix possible memory leak in dio_init() vfio: platform: Do not pass return buffer to ACPI _RST method uio: uio_dmem_genirq: Fix missing unlock in irq configuration uio: uio_dmem_genirq: Fix deadlock between irq config and handling usb: fotg210-udc: Fix ages old endianness issues staging: vme_user: Fix possible UAF in tsi148_dma_list_add serial: amba-pl011: avoid SBSA UART accessing DMACR register serial: pch: Fix PCI device refcount leak in pch_request_dma() serial: sunsab: Fix error handling in sunsab_init() misc: tifm: fix possible memory leak in tifm_7xx1_switch_media() misc: sgi-gru: fix use-after-free error in gru_set_context_option, gru_fault and gru_handle_user_call_os cxl: fix possible null-ptr-deref in cxl_guest_init_afu|adapter() cxl: fix possible null-ptr-deref in cxl_pci_init_afu|adapter() drivers: mcb: fix resource leak in mcb_probe() mcb: mcb-parse: fix error handing in chameleon_parse_gdd() chardev: fix error handling in cdev_device_add() i2c: pxa-pci: fix missing pci_disable_device() on error in ce4100_i2c_probe staging: rtl8192u: Fix use after free in ieee80211_rx() staging: rtl8192e: Fix potential use-after-free in rtllib_rx_Monitor() vme: Fix error not catched in fake_init() i2c: ismt: Fix an out-of-bounds bug in ismt_access() usb: storage: Add check for kcalloc fbdev: ssd1307fb: Drop optional dependency fbdev: pm2fb: fix missing pci_disable_device() fbdev: via: Fix error in via_core_init() fbdev: vermilion: decrease reference count in error path fbdev: uvesafb: Fixes an error handling path in uvesafb_probe() HSI: omap_ssi_core: fix unbalanced pm_runtime_disable() HSI: omap_ssi_core: fix possible memory leak in ssi_probe() power: supply: fix residue sysfs file in error handle route of __power_supply_register() HSI: omap_ssi_core: Fix error handling in ssi_init() include/uapi/linux/swab: Fix potentially missing __always_inline rtc: snvs: Allow a time difference on clock register read iommu/fsl_pamu: Fix resource leak in fsl_pamu_probe() macintosh: fix possible memory leak in macio_add_one_device() macintosh/macio-adb: check the return value of ioremap() powerpc/52xx: Fix a resource leak in an error handling path powerpc/perf: callchain validate kernel stack pointer bounds powerpc/83xx/mpc832x_rdb: call platform_device_put() in error case in of_fsl_spi_probe() powerpc/hv-gpci: Fix hv_gpci event list selftests/powerpc: Fix resource leaks rtc: st-lpc: Add missing clk_disable_unprepare in st_rtc_probe() nfsd: under NFSv4.1, fix double svc_xprt_put on rpc_create failure mISDN: hfcsusb: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcpci: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() mISDN: hfcmulti: don't call dev_kfree_skb/kfree_skb() under spin_lock_irqsave() nfc: pn533: Clear nfc_target before being used r6040: Fix kmemleak in probe and remove openvswitch: Fix flow lookup to use unmasked key skbuff: Account for tail adjustment during pull operations net_sched: reject TCF_EM_SIMPLE case for complex ematch module myri10ge: Fix an error handling path in myri10ge_probe() net: stream: purge sk_error_queue in sk_stream_kill_queues() binfmt_misc: fix shift-out-of-bounds in check_special_flags fs: jfs: fix shift-out-of-bounds in dbAllocAG udf: Avoid double brelse() in udf_rename() fs: jfs: fix shift-out-of-bounds in dbDiscardAG ACPICA: Fix error code path in acpi_ds_call_control_method() nilfs2: fix shift-out-of-bounds/overflow in nilfs_sb2_bad_offset() acct: fix potential integer overflow in encode_comp_t() hfs: fix OOB Read in __hfs_brec_find wifi: ath9k: verify the expected usb_endpoints are present wifi: ar5523: Fix use-after-free on ar5523_cmd() timed out ipmi: fix memleak when unload ipmi driver net: ethernet: ti: Fix return type of netcp_ndo_start_xmit() hamradio: baycom_epp: Fix return type of baycom_send_packet() wifi: brcmfmac: Fix potential shift-out-of-bounds in brcmf_fw_alloc_request() igb: Do not free q_vector unless new one was allocated s390/ctcm: Fix return type of ctc{mp,}m_tx() s390/netiucv: Fix return type of netiucv_tx() s390/lcs: Fix return type of lcs_start_xmit() drm/sti: Use drm_mode_copy() md/raid1: stop mdx_raid1 thread when raid1 array run failed mrp: introduce active flags to prevent UAF when applicant uninit ppp: associate skb with a device at tx media: dvb-frontends: fix leak of memory fw media: dvb-usb: fix memory leak in dvb_usb_adapter_init() blk-mq: fix possible memleak when register 'hctx' failed mmc: f-sdh30: Add quirks for broken timeout clock capability media: si470x: Fix use-after-free in si470x_int_in_callback() clk: st: Fix memory leak in st_of_quadfs_setup() drm/fsl-dcu: Fix return type of fsl_dcu_drm_connector_mode_valid() drm/sti: Fix return type of sti_{dvo,hda,hdmi}_connector_mode_valid() orangefs: Fix kmemleak in orangefs_prepare_debugfs_help_string() ASoC: mediatek: mt8173-rt5650-rt5514: fix refcount leak in mt8173_rt5650_rt5514_dev_probe() ASoC: wm8994: Fix potential deadlock ASoC: rockchip: spdif: Add missing clk_disable_unprepare() in rk_spdif_runtime_resume() ASoC: rt5670: Remove unbalanced pm_runtime_put() HID: wacom: Ensure bootloader PID is usable in hidraw mode reiserfs: Add missing calls to reiserfs_security_free() iio: adc: ad_sigma_delta: do not use internal iio_dev lock gcov: add support for checksum field powerpc/rtas: avoid scheduling in rtas_os_term() HID: plantronics: Additional PIDs for double volume key presses quirk hfsplus: fix bug causing custom uid and gid being unable to be assigned with mount ALSA: line6: correct midi status byte when receiving data from podxt ALSA: line6: fix stack overflow in line6_midi_transmit pnode: terminate at peers of source md: fix a crash in mempool_free mmc: vub300: fix warning - do not call blocking ops when !TASK_RUNNING media: stv0288: use explicitly signed char ktest.pl minconfig: Unset configs instead of just removing them ARM: ux500: do not directly dereference __iomem dm cache: Fix ABBA deadlock between shrink_slab and dm_cache_metadata_abort dm thin: Use last transaction's pmd->root when commit failed dm thin: Fix UAF in run_timer_softirq() dm cache: Fix UAF in destroy() dm cache: set needs_check flag after aborting metadata tracing: Fix infinite loop in tracing_read_pipe on overflowed print_trace_line ARM: 9256/1: NWFPE: avoid compiler-generated __aeabi_uldivmod media: dvb-core: Fix double free in dvb_register_device() cifs: fix confusing debug message PCI/sysfs: Fix double free in error path crypto: n2 - add missing hash statesize iommu/amd: Fix ivrs_acpihid cmdline parsing code parisc: led: Fix potential null-ptr-deref in start_task() device_cgroup: Roll back to original exceptions after copy failure drm/connector: send hotplug uevent on connector cleanup drm/vmwgfx: Validate the box size for the snooped cursor ext4: add inode table check in __ext4_get_inode_loc to aovid possible infinite loop ext4: fix undefined behavior in bit shift for ext4_check_flag_values ext4: fix bug_on in __es_tree_search caused by bad boot loader inode ext4: init quota for 'old.inode' in 'ext4_rename' ext4: fix error code return to user-space in ext4_get_branch() ext4: avoid BUG_ON when creating xattrs ext4: initialize quota before expanding inode in setproject ioctl Linux 4.9.337 Change-Id: I923e3fef499ae1688b25c70a1a805b55a9f4f027 Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
995 lines
27 KiB
C
995 lines
27 KiB
C
/*
|
|
* Copyright(c) 2011 - 2012 Intel Corporation. All rights reserved.
|
|
*
|
|
* 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.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along with
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*
|
|
* Maintained at www.Open-FCoE.org
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/types.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/etherdevice.h>
|
|
#include <linux/ctype.h>
|
|
|
|
#include <scsi/fcoe_sysfs.h>
|
|
#include <scsi/libfcoe.h>
|
|
|
|
/*
|
|
* OK to include local libfcoe.h for debug_logging, but cannot include
|
|
* <scsi/libfcoe.h> otherwise non-netdev based fcoe solutions would have
|
|
* have to include more than fcoe_sysfs.h.
|
|
*/
|
|
#include "libfcoe.h"
|
|
|
|
static atomic_t ctlr_num;
|
|
static atomic_t fcf_num;
|
|
|
|
/*
|
|
* fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
|
|
* should insulate the loss of a fcf.
|
|
*/
|
|
static unsigned int fcoe_fcf_dev_loss_tmo = 1800; /* seconds */
|
|
|
|
module_param_named(fcf_dev_loss_tmo, fcoe_fcf_dev_loss_tmo,
|
|
uint, S_IRUGO|S_IWUSR);
|
|
MODULE_PARM_DESC(fcf_dev_loss_tmo,
|
|
"Maximum number of seconds that libfcoe should"
|
|
" insulate the loss of a fcf. Once this value is"
|
|
" exceeded, the fcf is removed.");
|
|
|
|
/*
|
|
* These are used by the fcoe_*_show_function routines, they
|
|
* are intentionally placed in the .c file as they're not intended
|
|
* for use throughout the code.
|
|
*/
|
|
#define fcoe_ctlr_id(x) \
|
|
((x)->id)
|
|
#define fcoe_ctlr_work_q_name(x) \
|
|
((x)->work_q_name)
|
|
#define fcoe_ctlr_work_q(x) \
|
|
((x)->work_q)
|
|
#define fcoe_ctlr_devloss_work_q_name(x) \
|
|
((x)->devloss_work_q_name)
|
|
#define fcoe_ctlr_devloss_work_q(x) \
|
|
((x)->devloss_work_q)
|
|
#define fcoe_ctlr_mode(x) \
|
|
((x)->mode)
|
|
#define fcoe_ctlr_fcf_dev_loss_tmo(x) \
|
|
((x)->fcf_dev_loss_tmo)
|
|
#define fcoe_ctlr_link_fail(x) \
|
|
((x)->lesb.lesb_link_fail)
|
|
#define fcoe_ctlr_vlink_fail(x) \
|
|
((x)->lesb.lesb_vlink_fail)
|
|
#define fcoe_ctlr_miss_fka(x) \
|
|
((x)->lesb.lesb_miss_fka)
|
|
#define fcoe_ctlr_symb_err(x) \
|
|
((x)->lesb.lesb_symb_err)
|
|
#define fcoe_ctlr_err_block(x) \
|
|
((x)->lesb.lesb_err_block)
|
|
#define fcoe_ctlr_fcs_error(x) \
|
|
((x)->lesb.lesb_fcs_error)
|
|
#define fcoe_ctlr_enabled(x) \
|
|
((x)->enabled)
|
|
#define fcoe_fcf_state(x) \
|
|
((x)->state)
|
|
#define fcoe_fcf_fabric_name(x) \
|
|
((x)->fabric_name)
|
|
#define fcoe_fcf_switch_name(x) \
|
|
((x)->switch_name)
|
|
#define fcoe_fcf_fc_map(x) \
|
|
((x)->fc_map)
|
|
#define fcoe_fcf_vfid(x) \
|
|
((x)->vfid)
|
|
#define fcoe_fcf_mac(x) \
|
|
((x)->mac)
|
|
#define fcoe_fcf_priority(x) \
|
|
((x)->priority)
|
|
#define fcoe_fcf_fka_period(x) \
|
|
((x)->fka_period)
|
|
#define fcoe_fcf_dev_loss_tmo(x) \
|
|
((x)->dev_loss_tmo)
|
|
#define fcoe_fcf_selected(x) \
|
|
((x)->selected)
|
|
#define fcoe_fcf_vlan_id(x) \
|
|
((x)->vlan_id)
|
|
|
|
/*
|
|
* dev_loss_tmo attribute
|
|
*/
|
|
static int fcoe_str_to_dev_loss(const char *buf, unsigned long *val)
|
|
{
|
|
int ret;
|
|
|
|
ret = kstrtoul(buf, 0, val);
|
|
if (ret)
|
|
return -EINVAL;
|
|
/*
|
|
* Check for overflow; dev_loss_tmo is u32
|
|
*/
|
|
if (*val > UINT_MAX)
|
|
return -EINVAL;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int fcoe_fcf_set_dev_loss_tmo(struct fcoe_fcf_device *fcf,
|
|
unsigned long val)
|
|
{
|
|
if ((fcf->state == FCOE_FCF_STATE_UNKNOWN) ||
|
|
(fcf->state == FCOE_FCF_STATE_DISCONNECTED) ||
|
|
(fcf->state == FCOE_FCF_STATE_DELETED))
|
|
return -EBUSY;
|
|
/*
|
|
* Check for overflow; dev_loss_tmo is u32
|
|
*/
|
|
if (val > UINT_MAX)
|
|
return -EINVAL;
|
|
|
|
fcoe_fcf_dev_loss_tmo(fcf) = val;
|
|
return 0;
|
|
}
|
|
|
|
#define FCOE_DEVICE_ATTR(_prefix, _name, _mode, _show, _store) \
|
|
struct device_attribute device_attr_fcoe_##_prefix##_##_name = \
|
|
__ATTR(_name, _mode, _show, _store)
|
|
|
|
#define fcoe_ctlr_show_function(field, format_string, sz, cast) \
|
|
static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \
|
|
struct device_attribute *attr, \
|
|
char *buf) \
|
|
{ \
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev); \
|
|
if (ctlr->f->get_fcoe_ctlr_##field) \
|
|
ctlr->f->get_fcoe_ctlr_##field(ctlr); \
|
|
return snprintf(buf, sz, format_string, \
|
|
cast fcoe_ctlr_##field(ctlr)); \
|
|
}
|
|
|
|
#define fcoe_fcf_show_function(field, format_string, sz, cast) \
|
|
static ssize_t show_fcoe_fcf_device_##field(struct device *dev, \
|
|
struct device_attribute *attr, \
|
|
char *buf) \
|
|
{ \
|
|
struct fcoe_fcf_device *fcf = dev_to_fcf(dev); \
|
|
struct fcoe_ctlr_device *ctlr = fcoe_fcf_dev_to_ctlr_dev(fcf); \
|
|
if (ctlr->f->get_fcoe_fcf_##field) \
|
|
ctlr->f->get_fcoe_fcf_##field(fcf); \
|
|
return snprintf(buf, sz, format_string, \
|
|
cast fcoe_fcf_##field(fcf)); \
|
|
}
|
|
|
|
#define fcoe_ctlr_private_show_function(field, format_string, sz, cast) \
|
|
static ssize_t show_fcoe_ctlr_device_##field(struct device *dev, \
|
|
struct device_attribute *attr, \
|
|
char *buf) \
|
|
{ \
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev); \
|
|
return snprintf(buf, sz, format_string, cast fcoe_ctlr_##field(ctlr)); \
|
|
}
|
|
|
|
#define fcoe_fcf_private_show_function(field, format_string, sz, cast) \
|
|
static ssize_t show_fcoe_fcf_device_##field(struct device *dev, \
|
|
struct device_attribute *attr, \
|
|
char *buf) \
|
|
{ \
|
|
struct fcoe_fcf_device *fcf = dev_to_fcf(dev); \
|
|
return snprintf(buf, sz, format_string, cast fcoe_fcf_##field(fcf)); \
|
|
}
|
|
|
|
#define fcoe_ctlr_private_rd_attr(field, format_string, sz) \
|
|
fcoe_ctlr_private_show_function(field, format_string, sz, ) \
|
|
static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO, \
|
|
show_fcoe_ctlr_device_##field, NULL)
|
|
|
|
#define fcoe_ctlr_rd_attr(field, format_string, sz) \
|
|
fcoe_ctlr_show_function(field, format_string, sz, ) \
|
|
static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO, \
|
|
show_fcoe_ctlr_device_##field, NULL)
|
|
|
|
#define fcoe_fcf_rd_attr(field, format_string, sz) \
|
|
fcoe_fcf_show_function(field, format_string, sz, ) \
|
|
static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO, \
|
|
show_fcoe_fcf_device_##field, NULL)
|
|
|
|
#define fcoe_fcf_private_rd_attr(field, format_string, sz) \
|
|
fcoe_fcf_private_show_function(field, format_string, sz, ) \
|
|
static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO, \
|
|
show_fcoe_fcf_device_##field, NULL)
|
|
|
|
#define fcoe_ctlr_private_rd_attr_cast(field, format_string, sz, cast) \
|
|
fcoe_ctlr_private_show_function(field, format_string, sz, (cast)) \
|
|
static FCOE_DEVICE_ATTR(ctlr, field, S_IRUGO, \
|
|
show_fcoe_ctlr_device_##field, NULL)
|
|
|
|
#define fcoe_fcf_private_rd_attr_cast(field, format_string, sz, cast) \
|
|
fcoe_fcf_private_show_function(field, format_string, sz, (cast)) \
|
|
static FCOE_DEVICE_ATTR(fcf, field, S_IRUGO, \
|
|
show_fcoe_fcf_device_##field, NULL)
|
|
|
|
#define fcoe_enum_name_search(title, table_type, table) \
|
|
static const char *get_fcoe_##title##_name(enum table_type table_key) \
|
|
{ \
|
|
if (table_key < 0 || table_key >= ARRAY_SIZE(table)) \
|
|
return NULL; \
|
|
return table[table_key]; \
|
|
}
|
|
|
|
static char *fip_conn_type_names[] = {
|
|
[ FIP_CONN_TYPE_UNKNOWN ] = "Unknown",
|
|
[ FIP_CONN_TYPE_FABRIC ] = "Fabric",
|
|
[ FIP_CONN_TYPE_VN2VN ] = "VN2VN",
|
|
};
|
|
fcoe_enum_name_search(ctlr_mode, fip_conn_type, fip_conn_type_names)
|
|
|
|
static enum fip_conn_type fcoe_parse_mode(const char *buf)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(fip_conn_type_names); i++) {
|
|
if (strcasecmp(buf, fip_conn_type_names[i]) == 0)
|
|
return i;
|
|
}
|
|
|
|
return FIP_CONN_TYPE_UNKNOWN;
|
|
}
|
|
|
|
static char *fcf_state_names[] = {
|
|
[ FCOE_FCF_STATE_UNKNOWN ] = "Unknown",
|
|
[ FCOE_FCF_STATE_DISCONNECTED ] = "Disconnected",
|
|
[ FCOE_FCF_STATE_CONNECTED ] = "Connected",
|
|
};
|
|
fcoe_enum_name_search(fcf_state, fcf_state, fcf_state_names)
|
|
#define FCOE_FCF_STATE_MAX_NAMELEN 50
|
|
|
|
static ssize_t show_fcf_state(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct fcoe_fcf_device *fcf = dev_to_fcf(dev);
|
|
const char *name;
|
|
name = get_fcoe_fcf_state_name(fcf->state);
|
|
if (!name)
|
|
return -EINVAL;
|
|
return snprintf(buf, FCOE_FCF_STATE_MAX_NAMELEN, "%s\n", name);
|
|
}
|
|
static FCOE_DEVICE_ATTR(fcf, state, S_IRUGO, show_fcf_state, NULL);
|
|
|
|
#define FCOE_MAX_MODENAME_LEN 20
|
|
static ssize_t show_ctlr_mode(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
const char *name;
|
|
|
|
name = get_fcoe_ctlr_mode_name(ctlr->mode);
|
|
if (!name)
|
|
return -EINVAL;
|
|
return snprintf(buf, FCOE_MAX_MODENAME_LEN,
|
|
"%s\n", name);
|
|
}
|
|
|
|
static ssize_t store_ctlr_mode(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
char mode[FCOE_MAX_MODENAME_LEN + 1];
|
|
|
|
if (count > FCOE_MAX_MODENAME_LEN)
|
|
return -EINVAL;
|
|
|
|
strncpy(mode, buf, count);
|
|
|
|
if (mode[count - 1] == '\n')
|
|
mode[count - 1] = '\0';
|
|
else
|
|
mode[count] = '\0';
|
|
|
|
switch (ctlr->enabled) {
|
|
case FCOE_CTLR_ENABLED:
|
|
LIBFCOE_SYSFS_DBG(ctlr, "Cannot change mode when enabled.\n");
|
|
return -EBUSY;
|
|
case FCOE_CTLR_DISABLED:
|
|
if (!ctlr->f->set_fcoe_ctlr_mode) {
|
|
LIBFCOE_SYSFS_DBG(ctlr,
|
|
"Mode change not supported by LLD.\n");
|
|
return -ENOTSUPP;
|
|
}
|
|
|
|
ctlr->mode = fcoe_parse_mode(mode);
|
|
if (ctlr->mode == FIP_CONN_TYPE_UNKNOWN) {
|
|
LIBFCOE_SYSFS_DBG(ctlr, "Unknown mode %s provided.\n",
|
|
buf);
|
|
return -EINVAL;
|
|
}
|
|
|
|
ctlr->f->set_fcoe_ctlr_mode(ctlr);
|
|
LIBFCOE_SYSFS_DBG(ctlr, "Mode changed to %s.\n", buf);
|
|
|
|
return count;
|
|
case FCOE_CTLR_UNUSED:
|
|
default:
|
|
LIBFCOE_SYSFS_DBG(ctlr, "Mode change not supported.\n");
|
|
return -ENOTSUPP;
|
|
};
|
|
}
|
|
|
|
static FCOE_DEVICE_ATTR(ctlr, mode, S_IRUGO | S_IWUSR,
|
|
show_ctlr_mode, store_ctlr_mode);
|
|
|
|
static ssize_t store_ctlr_enabled(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
int rc;
|
|
|
|
switch (ctlr->enabled) {
|
|
case FCOE_CTLR_ENABLED:
|
|
if (*buf == '1')
|
|
return count;
|
|
ctlr->enabled = FCOE_CTLR_DISABLED;
|
|
break;
|
|
case FCOE_CTLR_DISABLED:
|
|
if (*buf == '0')
|
|
return count;
|
|
ctlr->enabled = FCOE_CTLR_ENABLED;
|
|
break;
|
|
case FCOE_CTLR_UNUSED:
|
|
return -ENOTSUPP;
|
|
};
|
|
|
|
rc = ctlr->f->set_fcoe_ctlr_enabled(ctlr);
|
|
if (rc)
|
|
return rc;
|
|
|
|
return count;
|
|
}
|
|
|
|
static char *ctlr_enabled_state_names[] = {
|
|
[ FCOE_CTLR_ENABLED ] = "1",
|
|
[ FCOE_CTLR_DISABLED ] = "0",
|
|
};
|
|
fcoe_enum_name_search(ctlr_enabled_state, ctlr_enabled_state,
|
|
ctlr_enabled_state_names)
|
|
#define FCOE_CTLR_ENABLED_MAX_NAMELEN 50
|
|
|
|
static ssize_t show_ctlr_enabled_state(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
const char *name;
|
|
|
|
name = get_fcoe_ctlr_enabled_state_name(ctlr->enabled);
|
|
if (!name)
|
|
return -EINVAL;
|
|
return snprintf(buf, FCOE_CTLR_ENABLED_MAX_NAMELEN,
|
|
"%s\n", name);
|
|
}
|
|
|
|
static FCOE_DEVICE_ATTR(ctlr, enabled, S_IRUGO | S_IWUSR,
|
|
show_ctlr_enabled_state,
|
|
store_ctlr_enabled);
|
|
|
|
static ssize_t store_ctlr_fip_resp(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr);
|
|
|
|
mutex_lock(&fip->ctlr_mutex);
|
|
if ((buf[1] == '\0') || ((buf[1] == '\n') && (buf[2] == '\0'))) {
|
|
if (buf[0] == '1') {
|
|
fip->fip_resp = 1;
|
|
mutex_unlock(&fip->ctlr_mutex);
|
|
return count;
|
|
}
|
|
if (buf[0] == '0') {
|
|
fip->fip_resp = 0;
|
|
mutex_unlock(&fip->ctlr_mutex);
|
|
return count;
|
|
}
|
|
}
|
|
mutex_unlock(&fip->ctlr_mutex);
|
|
return -EINVAL;
|
|
}
|
|
|
|
static ssize_t show_ctlr_fip_resp(struct device *dev,
|
|
struct device_attribute *attr,
|
|
char *buf)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
struct fcoe_ctlr *fip = fcoe_ctlr_device_priv(ctlr);
|
|
|
|
return sprintf(buf, "%d\n", fip->fip_resp ? 1 : 0);
|
|
}
|
|
|
|
static FCOE_DEVICE_ATTR(ctlr, fip_vlan_responder, S_IRUGO | S_IWUSR,
|
|
show_ctlr_fip_resp,
|
|
store_ctlr_fip_resp);
|
|
|
|
static ssize_t
|
|
store_private_fcoe_ctlr_fcf_dev_loss_tmo(struct device *dev,
|
|
struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
struct fcoe_fcf_device *fcf;
|
|
unsigned long val;
|
|
int rc;
|
|
|
|
rc = fcoe_str_to_dev_loss(buf, &val);
|
|
if (rc)
|
|
return rc;
|
|
|
|
fcoe_ctlr_fcf_dev_loss_tmo(ctlr) = val;
|
|
mutex_lock(&ctlr->lock);
|
|
list_for_each_entry(fcf, &ctlr->fcfs, peers)
|
|
fcoe_fcf_set_dev_loss_tmo(fcf, val);
|
|
mutex_unlock(&ctlr->lock);
|
|
return count;
|
|
}
|
|
fcoe_ctlr_private_show_function(fcf_dev_loss_tmo, "%d\n", 20, );
|
|
static FCOE_DEVICE_ATTR(ctlr, fcf_dev_loss_tmo, S_IRUGO | S_IWUSR,
|
|
show_fcoe_ctlr_device_fcf_dev_loss_tmo,
|
|
store_private_fcoe_ctlr_fcf_dev_loss_tmo);
|
|
|
|
/* Link Error Status Block (LESB) */
|
|
fcoe_ctlr_rd_attr(link_fail, "%u\n", 20);
|
|
fcoe_ctlr_rd_attr(vlink_fail, "%u\n", 20);
|
|
fcoe_ctlr_rd_attr(miss_fka, "%u\n", 20);
|
|
fcoe_ctlr_rd_attr(symb_err, "%u\n", 20);
|
|
fcoe_ctlr_rd_attr(err_block, "%u\n", 20);
|
|
fcoe_ctlr_rd_attr(fcs_error, "%u\n", 20);
|
|
|
|
fcoe_fcf_private_rd_attr_cast(fabric_name, "0x%llx\n", 20, unsigned long long);
|
|
fcoe_fcf_private_rd_attr_cast(switch_name, "0x%llx\n", 20, unsigned long long);
|
|
fcoe_fcf_private_rd_attr(priority, "%u\n", 20);
|
|
fcoe_fcf_private_rd_attr(fc_map, "0x%x\n", 20);
|
|
fcoe_fcf_private_rd_attr(vfid, "%u\n", 20);
|
|
fcoe_fcf_private_rd_attr(mac, "%pM\n", 20);
|
|
fcoe_fcf_private_rd_attr(fka_period, "%u\n", 20);
|
|
fcoe_fcf_rd_attr(selected, "%u\n", 20);
|
|
fcoe_fcf_rd_attr(vlan_id, "%u\n", 20);
|
|
|
|
fcoe_fcf_private_show_function(dev_loss_tmo, "%d\n", 20, )
|
|
static ssize_t
|
|
store_fcoe_fcf_dev_loss_tmo(struct device *dev, struct device_attribute *attr,
|
|
const char *buf, size_t count)
|
|
{
|
|
struct fcoe_fcf_device *fcf = dev_to_fcf(dev);
|
|
unsigned long val;
|
|
int rc;
|
|
|
|
rc = fcoe_str_to_dev_loss(buf, &val);
|
|
if (rc)
|
|
return rc;
|
|
|
|
rc = fcoe_fcf_set_dev_loss_tmo(fcf, val);
|
|
if (rc)
|
|
return rc;
|
|
return count;
|
|
}
|
|
static FCOE_DEVICE_ATTR(fcf, dev_loss_tmo, S_IRUGO | S_IWUSR,
|
|
show_fcoe_fcf_device_dev_loss_tmo,
|
|
store_fcoe_fcf_dev_loss_tmo);
|
|
|
|
static struct attribute *fcoe_ctlr_lesb_attrs[] = {
|
|
&device_attr_fcoe_ctlr_link_fail.attr,
|
|
&device_attr_fcoe_ctlr_vlink_fail.attr,
|
|
&device_attr_fcoe_ctlr_miss_fka.attr,
|
|
&device_attr_fcoe_ctlr_symb_err.attr,
|
|
&device_attr_fcoe_ctlr_err_block.attr,
|
|
&device_attr_fcoe_ctlr_fcs_error.attr,
|
|
NULL,
|
|
};
|
|
|
|
static struct attribute_group fcoe_ctlr_lesb_attr_group = {
|
|
.name = "lesb",
|
|
.attrs = fcoe_ctlr_lesb_attrs,
|
|
};
|
|
|
|
static struct attribute *fcoe_ctlr_attrs[] = {
|
|
&device_attr_fcoe_ctlr_fip_vlan_responder.attr,
|
|
&device_attr_fcoe_ctlr_fcf_dev_loss_tmo.attr,
|
|
&device_attr_fcoe_ctlr_enabled.attr,
|
|
&device_attr_fcoe_ctlr_mode.attr,
|
|
NULL,
|
|
};
|
|
|
|
static struct attribute_group fcoe_ctlr_attr_group = {
|
|
.attrs = fcoe_ctlr_attrs,
|
|
};
|
|
|
|
static const struct attribute_group *fcoe_ctlr_attr_groups[] = {
|
|
&fcoe_ctlr_attr_group,
|
|
&fcoe_ctlr_lesb_attr_group,
|
|
NULL,
|
|
};
|
|
|
|
static struct attribute *fcoe_fcf_attrs[] = {
|
|
&device_attr_fcoe_fcf_fabric_name.attr,
|
|
&device_attr_fcoe_fcf_switch_name.attr,
|
|
&device_attr_fcoe_fcf_dev_loss_tmo.attr,
|
|
&device_attr_fcoe_fcf_fc_map.attr,
|
|
&device_attr_fcoe_fcf_vfid.attr,
|
|
&device_attr_fcoe_fcf_mac.attr,
|
|
&device_attr_fcoe_fcf_priority.attr,
|
|
&device_attr_fcoe_fcf_fka_period.attr,
|
|
&device_attr_fcoe_fcf_state.attr,
|
|
&device_attr_fcoe_fcf_selected.attr,
|
|
&device_attr_fcoe_fcf_vlan_id.attr,
|
|
NULL
|
|
};
|
|
|
|
static struct attribute_group fcoe_fcf_attr_group = {
|
|
.attrs = fcoe_fcf_attrs,
|
|
};
|
|
|
|
static const struct attribute_group *fcoe_fcf_attr_groups[] = {
|
|
&fcoe_fcf_attr_group,
|
|
NULL,
|
|
};
|
|
|
|
static struct bus_type fcoe_bus_type;
|
|
|
|
static int fcoe_bus_match(struct device *dev,
|
|
struct device_driver *drv)
|
|
{
|
|
if (dev->bus == &fcoe_bus_type)
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* fcoe_ctlr_device_release() - Release the FIP ctlr memory
|
|
* @dev: Pointer to the FIP ctlr's embedded device
|
|
*
|
|
* Called when the last FIP ctlr reference is released.
|
|
*/
|
|
static void fcoe_ctlr_device_release(struct device *dev)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = dev_to_ctlr(dev);
|
|
kfree(ctlr);
|
|
}
|
|
|
|
/**
|
|
* fcoe_fcf_device_release() - Release the FIP fcf memory
|
|
* @dev: Pointer to the fcf's embedded device
|
|
*
|
|
* Called when the last FIP fcf reference is released.
|
|
*/
|
|
static void fcoe_fcf_device_release(struct device *dev)
|
|
{
|
|
struct fcoe_fcf_device *fcf = dev_to_fcf(dev);
|
|
kfree(fcf);
|
|
}
|
|
|
|
static struct device_type fcoe_ctlr_device_type = {
|
|
.name = "fcoe_ctlr",
|
|
.groups = fcoe_ctlr_attr_groups,
|
|
.release = fcoe_ctlr_device_release,
|
|
};
|
|
|
|
static struct device_type fcoe_fcf_device_type = {
|
|
.name = "fcoe_fcf",
|
|
.groups = fcoe_fcf_attr_groups,
|
|
.release = fcoe_fcf_device_release,
|
|
};
|
|
|
|
static BUS_ATTR(ctlr_create, S_IWUSR, NULL, fcoe_ctlr_create_store);
|
|
static BUS_ATTR(ctlr_destroy, S_IWUSR, NULL, fcoe_ctlr_destroy_store);
|
|
|
|
static struct attribute *fcoe_bus_attrs[] = {
|
|
&bus_attr_ctlr_create.attr,
|
|
&bus_attr_ctlr_destroy.attr,
|
|
NULL,
|
|
};
|
|
ATTRIBUTE_GROUPS(fcoe_bus);
|
|
|
|
static struct bus_type fcoe_bus_type = {
|
|
.name = "fcoe",
|
|
.match = &fcoe_bus_match,
|
|
.bus_groups = fcoe_bus_groups,
|
|
};
|
|
|
|
/**
|
|
* fcoe_ctlr_device_flush_work() - Flush a FIP ctlr's workqueue
|
|
* @ctlr: Pointer to the FIP ctlr whose workqueue is to be flushed
|
|
*/
|
|
static void fcoe_ctlr_device_flush_work(struct fcoe_ctlr_device *ctlr)
|
|
{
|
|
if (!fcoe_ctlr_work_q(ctlr)) {
|
|
printk(KERN_ERR
|
|
"ERROR: FIP Ctlr '%d' attempted to flush work, "
|
|
"when no workqueue created.\n", ctlr->id);
|
|
dump_stack();
|
|
return;
|
|
}
|
|
|
|
flush_workqueue(fcoe_ctlr_work_q(ctlr));
|
|
}
|
|
|
|
/**
|
|
* fcoe_ctlr_device_queue_work() - Schedule work for a FIP ctlr's workqueue
|
|
* @ctlr: Pointer to the FIP ctlr who owns the devloss workqueue
|
|
* @work: Work to queue for execution
|
|
*
|
|
* Return value:
|
|
* 1 on success / 0 already queued / < 0 for error
|
|
*/
|
|
static int fcoe_ctlr_device_queue_work(struct fcoe_ctlr_device *ctlr,
|
|
struct work_struct *work)
|
|
{
|
|
if (unlikely(!fcoe_ctlr_work_q(ctlr))) {
|
|
printk(KERN_ERR
|
|
"ERROR: FIP Ctlr '%d' attempted to queue work, "
|
|
"when no workqueue created.\n", ctlr->id);
|
|
dump_stack();
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
return queue_work(fcoe_ctlr_work_q(ctlr), work);
|
|
}
|
|
|
|
/**
|
|
* fcoe_ctlr_device_flush_devloss() - Flush a FIP ctlr's devloss workqueue
|
|
* @ctlr: Pointer to FIP ctlr whose workqueue is to be flushed
|
|
*/
|
|
static void fcoe_ctlr_device_flush_devloss(struct fcoe_ctlr_device *ctlr)
|
|
{
|
|
if (!fcoe_ctlr_devloss_work_q(ctlr)) {
|
|
printk(KERN_ERR
|
|
"ERROR: FIP Ctlr '%d' attempted to flush work, "
|
|
"when no workqueue created.\n", ctlr->id);
|
|
dump_stack();
|
|
return;
|
|
}
|
|
|
|
flush_workqueue(fcoe_ctlr_devloss_work_q(ctlr));
|
|
}
|
|
|
|
/**
|
|
* fcoe_ctlr_device_queue_devloss_work() - Schedule work for a FIP ctlr's devloss workqueue
|
|
* @ctlr: Pointer to the FIP ctlr who owns the devloss workqueue
|
|
* @work: Work to queue for execution
|
|
* @delay: jiffies to delay the work queuing
|
|
*
|
|
* Return value:
|
|
* 1 on success / 0 already queued / < 0 for error
|
|
*/
|
|
static int fcoe_ctlr_device_queue_devloss_work(struct fcoe_ctlr_device *ctlr,
|
|
struct delayed_work *work,
|
|
unsigned long delay)
|
|
{
|
|
if (unlikely(!fcoe_ctlr_devloss_work_q(ctlr))) {
|
|
printk(KERN_ERR
|
|
"ERROR: FIP Ctlr '%d' attempted to queue work, "
|
|
"when no workqueue created.\n", ctlr->id);
|
|
dump_stack();
|
|
|
|
return -EINVAL;
|
|
}
|
|
|
|
return queue_delayed_work(fcoe_ctlr_devloss_work_q(ctlr), work, delay);
|
|
}
|
|
|
|
static int fcoe_fcf_device_match(struct fcoe_fcf_device *new,
|
|
struct fcoe_fcf_device *old)
|
|
{
|
|
if (new->switch_name == old->switch_name &&
|
|
new->fabric_name == old->fabric_name &&
|
|
new->fc_map == old->fc_map &&
|
|
ether_addr_equal(new->mac, old->mac))
|
|
return 1;
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* fcoe_ctlr_device_add() - Add a FIP ctlr to sysfs
|
|
* @parent: The parent device to which the fcoe_ctlr instance
|
|
* should be attached
|
|
* @f: The LLD's FCoE sysfs function template pointer
|
|
* @priv_size: Size to be allocated with the fcoe_ctlr_device for the LLD
|
|
*
|
|
* This routine allocates a FIP ctlr object with some additional memory
|
|
* for the LLD. The FIP ctlr is initialized, added to sysfs and then
|
|
* attributes are added to it.
|
|
*/
|
|
struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
|
|
struct fcoe_sysfs_function_template *f,
|
|
int priv_size)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr;
|
|
int error = 0;
|
|
|
|
ctlr = kzalloc(sizeof(struct fcoe_ctlr_device) + priv_size,
|
|
GFP_KERNEL);
|
|
if (!ctlr)
|
|
goto out;
|
|
|
|
ctlr->id = atomic_inc_return(&ctlr_num) - 1;
|
|
ctlr->f = f;
|
|
ctlr->mode = FIP_CONN_TYPE_FABRIC;
|
|
INIT_LIST_HEAD(&ctlr->fcfs);
|
|
mutex_init(&ctlr->lock);
|
|
ctlr->dev.parent = parent;
|
|
ctlr->dev.bus = &fcoe_bus_type;
|
|
ctlr->dev.type = &fcoe_ctlr_device_type;
|
|
|
|
ctlr->fcf_dev_loss_tmo = fcoe_fcf_dev_loss_tmo;
|
|
|
|
snprintf(ctlr->work_q_name, sizeof(ctlr->work_q_name),
|
|
"ctlr_wq_%d", ctlr->id);
|
|
ctlr->work_q = create_singlethread_workqueue(
|
|
ctlr->work_q_name);
|
|
if (!ctlr->work_q)
|
|
goto out_del;
|
|
|
|
snprintf(ctlr->devloss_work_q_name,
|
|
sizeof(ctlr->devloss_work_q_name),
|
|
"ctlr_dl_wq_%d", ctlr->id);
|
|
ctlr->devloss_work_q = create_singlethread_workqueue(
|
|
ctlr->devloss_work_q_name);
|
|
if (!ctlr->devloss_work_q)
|
|
goto out_del_q;
|
|
|
|
dev_set_name(&ctlr->dev, "ctlr_%d", ctlr->id);
|
|
error = device_register(&ctlr->dev);
|
|
if (error) {
|
|
destroy_workqueue(ctlr->devloss_work_q);
|
|
destroy_workqueue(ctlr->work_q);
|
|
put_device(&ctlr->dev);
|
|
return NULL;
|
|
}
|
|
|
|
return ctlr;
|
|
|
|
out_del_q:
|
|
destroy_workqueue(ctlr->work_q);
|
|
ctlr->work_q = NULL;
|
|
out_del:
|
|
kfree(ctlr);
|
|
out:
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fcoe_ctlr_device_add);
|
|
|
|
/**
|
|
* fcoe_ctlr_device_delete() - Delete a FIP ctlr and its subtree from sysfs
|
|
* @ctlr: A pointer to the ctlr to be deleted
|
|
*
|
|
* Deletes a FIP ctlr and any fcfs attached
|
|
* to it. Deleting fcfs will cause their childen
|
|
* to be deleted as well.
|
|
*
|
|
* The ctlr is detached from sysfs and it's resources
|
|
* are freed (work q), but the memory is not freed
|
|
* until its last reference is released.
|
|
*
|
|
* This routine expects no locks to be held before
|
|
* calling.
|
|
*
|
|
* TODO: Currently there are no callbacks to clean up LLD data
|
|
* for a fcoe_fcf_device. LLDs must keep this in mind as they need
|
|
* to clean up each of their LLD data for all fcoe_fcf_device before
|
|
* calling fcoe_ctlr_device_delete.
|
|
*/
|
|
void fcoe_ctlr_device_delete(struct fcoe_ctlr_device *ctlr)
|
|
{
|
|
struct fcoe_fcf_device *fcf, *next;
|
|
/* Remove any attached fcfs */
|
|
mutex_lock(&ctlr->lock);
|
|
list_for_each_entry_safe(fcf, next,
|
|
&ctlr->fcfs, peers) {
|
|
list_del(&fcf->peers);
|
|
fcf->state = FCOE_FCF_STATE_DELETED;
|
|
fcoe_ctlr_device_queue_work(ctlr, &fcf->delete_work);
|
|
}
|
|
mutex_unlock(&ctlr->lock);
|
|
|
|
fcoe_ctlr_device_flush_work(ctlr);
|
|
|
|
destroy_workqueue(ctlr->devloss_work_q);
|
|
ctlr->devloss_work_q = NULL;
|
|
destroy_workqueue(ctlr->work_q);
|
|
ctlr->work_q = NULL;
|
|
|
|
device_unregister(&ctlr->dev);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fcoe_ctlr_device_delete);
|
|
|
|
/**
|
|
* fcoe_fcf_device_final_delete() - Final delete routine
|
|
* @work: The FIP fcf's embedded work struct
|
|
*
|
|
* It is expected that the fcf has been removed from
|
|
* the FIP ctlr's list before calling this routine.
|
|
*/
|
|
static void fcoe_fcf_device_final_delete(struct work_struct *work)
|
|
{
|
|
struct fcoe_fcf_device *fcf =
|
|
container_of(work, struct fcoe_fcf_device, delete_work);
|
|
struct fcoe_ctlr_device *ctlr = fcoe_fcf_dev_to_ctlr_dev(fcf);
|
|
|
|
/*
|
|
* Cancel any outstanding timers. These should really exist
|
|
* only when rmmod'ing the LLDD and we're asking for
|
|
* immediate termination of the rports
|
|
*/
|
|
if (!cancel_delayed_work(&fcf->dev_loss_work))
|
|
fcoe_ctlr_device_flush_devloss(ctlr);
|
|
|
|
device_unregister(&fcf->dev);
|
|
}
|
|
|
|
/**
|
|
* fip_timeout_deleted_fcf() - Delete a fcf when the devloss timer fires
|
|
* @work: The FIP fcf's embedded work struct
|
|
*
|
|
* Removes the fcf from the FIP ctlr's list of fcfs and
|
|
* queues the final deletion.
|
|
*/
|
|
static void fip_timeout_deleted_fcf(struct work_struct *work)
|
|
{
|
|
struct fcoe_fcf_device *fcf =
|
|
container_of(work, struct fcoe_fcf_device, dev_loss_work.work);
|
|
struct fcoe_ctlr_device *ctlr = fcoe_fcf_dev_to_ctlr_dev(fcf);
|
|
|
|
mutex_lock(&ctlr->lock);
|
|
|
|
/*
|
|
* If the fcf is deleted or reconnected before the timer
|
|
* fires the devloss queue will be flushed, but the state will
|
|
* either be CONNECTED or DELETED. If that is the case we
|
|
* cancel deleting the fcf.
|
|
*/
|
|
if (fcf->state != FCOE_FCF_STATE_DISCONNECTED)
|
|
goto out;
|
|
|
|
dev_printk(KERN_ERR, &fcf->dev,
|
|
"FIP fcf connection time out: removing fcf\n");
|
|
|
|
list_del(&fcf->peers);
|
|
fcf->state = FCOE_FCF_STATE_DELETED;
|
|
fcoe_ctlr_device_queue_work(ctlr, &fcf->delete_work);
|
|
|
|
out:
|
|
mutex_unlock(&ctlr->lock);
|
|
}
|
|
|
|
/**
|
|
* fcoe_fcf_device_delete() - Delete a FIP fcf
|
|
* @fcf: Pointer to the fcf which is to be deleted
|
|
*
|
|
* Queues the FIP fcf on the devloss workqueue
|
|
*
|
|
* Expects the ctlr_attrs mutex to be held for fcf
|
|
* state change.
|
|
*/
|
|
void fcoe_fcf_device_delete(struct fcoe_fcf_device *fcf)
|
|
{
|
|
struct fcoe_ctlr_device *ctlr = fcoe_fcf_dev_to_ctlr_dev(fcf);
|
|
int timeout = fcf->dev_loss_tmo;
|
|
|
|
if (fcf->state != FCOE_FCF_STATE_CONNECTED)
|
|
return;
|
|
|
|
fcf->state = FCOE_FCF_STATE_DISCONNECTED;
|
|
|
|
/*
|
|
* FCF will only be re-connected by the LLD calling
|
|
* fcoe_fcf_device_add, and it should be setting up
|
|
* priv then.
|
|
*/
|
|
fcf->priv = NULL;
|
|
|
|
fcoe_ctlr_device_queue_devloss_work(ctlr, &fcf->dev_loss_work,
|
|
timeout * HZ);
|
|
}
|
|
EXPORT_SYMBOL_GPL(fcoe_fcf_device_delete);
|
|
|
|
/**
|
|
* fcoe_fcf_device_add() - Add a FCoE sysfs fcoe_fcf_device to the system
|
|
* @ctlr: The fcoe_ctlr_device that will be the fcoe_fcf_device parent
|
|
* @new_fcf: A temporary FCF used for lookups on the current list of fcfs
|
|
*
|
|
* Expects to be called with the ctlr->lock held
|
|
*/
|
|
struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
|
|
struct fcoe_fcf_device *new_fcf)
|
|
{
|
|
struct fcoe_fcf_device *fcf;
|
|
int error = 0;
|
|
|
|
list_for_each_entry(fcf, &ctlr->fcfs, peers) {
|
|
if (fcoe_fcf_device_match(new_fcf, fcf)) {
|
|
if (fcf->state == FCOE_FCF_STATE_CONNECTED)
|
|
return fcf;
|
|
|
|
fcf->state = FCOE_FCF_STATE_CONNECTED;
|
|
|
|
if (!cancel_delayed_work(&fcf->dev_loss_work))
|
|
fcoe_ctlr_device_flush_devloss(ctlr);
|
|
|
|
return fcf;
|
|
}
|
|
}
|
|
|
|
fcf = kzalloc(sizeof(struct fcoe_fcf_device), GFP_ATOMIC);
|
|
if (unlikely(!fcf))
|
|
goto out;
|
|
|
|
INIT_WORK(&fcf->delete_work, fcoe_fcf_device_final_delete);
|
|
INIT_DELAYED_WORK(&fcf->dev_loss_work, fip_timeout_deleted_fcf);
|
|
|
|
fcf->dev.parent = &ctlr->dev;
|
|
fcf->dev.bus = &fcoe_bus_type;
|
|
fcf->dev.type = &fcoe_fcf_device_type;
|
|
fcf->id = atomic_inc_return(&fcf_num) - 1;
|
|
fcf->state = FCOE_FCF_STATE_UNKNOWN;
|
|
|
|
fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
|
|
|
|
dev_set_name(&fcf->dev, "fcf_%d", fcf->id);
|
|
|
|
fcf->fabric_name = new_fcf->fabric_name;
|
|
fcf->switch_name = new_fcf->switch_name;
|
|
fcf->fc_map = new_fcf->fc_map;
|
|
fcf->vfid = new_fcf->vfid;
|
|
memcpy(fcf->mac, new_fcf->mac, ETH_ALEN);
|
|
fcf->priority = new_fcf->priority;
|
|
fcf->fka_period = new_fcf->fka_period;
|
|
fcf->selected = new_fcf->selected;
|
|
|
|
error = device_register(&fcf->dev);
|
|
if (error) {
|
|
put_device(&fcf->dev);
|
|
goto out;
|
|
}
|
|
|
|
fcf->state = FCOE_FCF_STATE_CONNECTED;
|
|
list_add_tail(&fcf->peers, &ctlr->fcfs);
|
|
|
|
return fcf;
|
|
|
|
out:
|
|
return NULL;
|
|
}
|
|
EXPORT_SYMBOL_GPL(fcoe_fcf_device_add);
|
|
|
|
int __init fcoe_sysfs_setup(void)
|
|
{
|
|
int error;
|
|
|
|
atomic_set(&ctlr_num, 0);
|
|
atomic_set(&fcf_num, 0);
|
|
|
|
error = bus_register(&fcoe_bus_type);
|
|
if (error)
|
|
return error;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void __exit fcoe_sysfs_teardown(void)
|
|
{
|
|
bus_unregister(&fcoe_bus_type);
|
|
}
|