From f03123783d4e43cd59df58e23e963136e04f8280 Mon Sep 17 00:00:00 2001 From: Ramakrishna Pallala Date: Thu, 30 Apr 2015 20:44:45 +0530 Subject: extcon: axp288: Add axp288 extcon driver support This patch adds the extcon support for AXP288 PMIC which has the BC1.2 charger detection capability. Additionally it also adds the USB mux switching support b/w SOC and PMIC based on GPIO control. Signed-off-by: Ramakrishna Pallala Acked-by: Lee Jones [cw00.choi: Modify the log message to keep the consistent log message pattern] Signed-off-by: Chanwoo Choi --- include/linux/mfd/axp20x.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'include') diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index dfabd6db7ddf..4ed8071d062e 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -275,4 +275,9 @@ struct axp20x_fg_pdata { int thermistor_curve[MAX_THERM_CURVE_SIZE][2]; }; +struct axp288_extcon_pdata { + /* GPIO pin control to switch D+/D- lines b/w PMIC and SOC */ + struct gpio_desc *gpio_mux_cntl; +}; + #endif /* __LINUX_MFD_AXP20X_H */ -- cgit v1.2.3-59-g8ed1b From 707d7550875a9bd245ce5f1077d2d2cb44eab218 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 15 Apr 2015 13:57:51 +0900 Subject: extcon: Add extcon_get_edev_name() API to get the extcon device name This patch adds the extcon_get_edev_name() API to get the name of extcon device because all information inclued in the structure extcon_dev should be accessed by extcon core API instead of directly accessing the data. Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 9 +++++++++ include/linux/extcon.h | 4 ++++ 2 files changed, 13 insertions(+) (limited to 'include') diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 1a932292d6c8..c5e9ebf0a914 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1046,6 +1046,15 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) #endif /* CONFIG_OF */ EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); +/** + * extcon_get_edev_name() - Get the name of the extcon device. + * @edev: the extcon device + */ +const char *extcon_get_edev_name(struct extcon_dev *edev) +{ + return !edev ? NULL : edev->name; +} + static int __init extcon_class_init(void) { return create_extcon_class(); diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 36f49c405dfb..e2cf6254c86a 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -259,6 +259,10 @@ extern int extcon_unregister_notifier(struct extcon_dev *edev, * This function use phandle of devicetree to get extcon device directly. */ extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index); + +/* Following API to get information of extcon device */ +extern const char *extcon_get_edev_name(struct extcon_dev *edev); + #else /* CONFIG_EXTCON */ static inline int extcon_dev_register(struct extcon_dev *edev) { -- cgit v1.2.3-59-g8ed1b From b9ec23c08a0274d31ee626f14b359563ea0cae46 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 24 Apr 2015 14:48:52 +0900 Subject: extcon: Fix the checkpatch warning and minor coding style issue This patch clean up the extcon core driver by fixing the checkpatch warning and minor coding style issue. Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 10 +++++----- include/linux/extcon.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index c5e9ebf0a914..2fb5f757e811 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1,5 +1,5 @@ /* - * drivers/extcon/extcon_class.c + * drivers/extcon/extcon.c - External Connector (extcon) framework. * * External connector (extcon) class driver * @@ -19,8 +19,7 @@ * 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. - * -*/ + */ #include #include @@ -469,7 +468,6 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, ret = raw_notifier_chain_register(&obj->edev->nh, &obj->internal_nb); spin_unlock_irqrestore(&obj->edev->lock, flags); - return ret; } else { struct class_dev_iter iter; struct extcon_dev *extd; @@ -489,8 +487,10 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, cable_name, nb); } - return -ENODEV; + ret = -ENODEV; } + + return ret; } EXPORT_SYMBOL_GPL(extcon_register_interest); diff --git a/include/linux/extcon.h b/include/linux/extcon.h index e2cf6254c86a..799474d9dc48 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -97,8 +97,8 @@ struct extcon_cable; * @state: Attach/detach state of this extcon. Do not provide at * register-time. * @nh: Notifier for the state change events from this extcon - * @entry: To support list of extcon devices so that users can search - * for extcon devices based on the extcon name. + * @entry: To support list of extcon devices so that users can + * search for extcon devices based on the extcon name. * @lock: * @max_supported: Internal value to store the number of cables. * @extcon_dev_type: Device_type struct to provide attribute_groups @@ -258,7 +258,8 @@ extern int extcon_unregister_notifier(struct extcon_dev *edev, * Following API get the extcon device from devicetree. * This function use phandle of devicetree to get extcon device directly. */ -extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index); +extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, + int index); /* Following API to get information of extcon device */ extern const char *extcon_get_edev_name(struct extcon_dev *edev); -- cgit v1.2.3-59-g8ed1b From 9e86b2ad4c11fd52ee8133abce7a29e0b32d29a7 Mon Sep 17 00:00:00 2001 From: Inha Song Date: Mon, 4 May 2015 13:42:13 +0900 Subject: extcon: arizona: Add support for select accessory detect mode when headphone detection This patch add support for select accessory detect mode to HPDETL or HPDETR. Arizona provides a headphone detection circuit on the HPDETL and HPDETR pins to measure the impedance of an external load connected to the headphone. Depending on board design, headphone detect pins can change to HPDETR or HPDETL. Signed-off-by: Inha Song Acked-by: Lee Jones Acked-by: Charles Keepax Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-arizona.c | 38 ++++++++++++++++++++++++++++++-------- include/dt-bindings/mfd/arizona.h | 4 ++++ include/linux/mfd/arizona/pdata.h | 3 +++ 3 files changed, 37 insertions(+), 8 deletions(-) (limited to 'include') diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 5e08c358649b..1ec06b4b4875 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -32,13 +32,10 @@ #include #include #include +#include #define ARIZONA_MAX_MICD_RANGE 8 -#define ARIZONA_ACCDET_MODE_MIC 0 -#define ARIZONA_ACCDET_MODE_HPL 1 -#define ARIZONA_ACCDET_MODE_HPR 2 - #define ARIZONA_MICD_CLAMP_MODE_JDL 0x4 #define ARIZONA_MICD_CLAMP_MODE_JDH 0x5 #define ARIZONA_MICD_CLAMP_MODE_JDL_GP5H 0x9 @@ -671,9 +668,9 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info) ret = regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1, ARIZONA_ACCDET_MODE_MASK, - ARIZONA_ACCDET_MODE_HPL); + arizona->pdata.hpdet_channel); if (ret != 0) { - dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret); + dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret); goto err; } @@ -723,9 +720,9 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info) ARIZONA_ACCESSORY_DETECT_MODE_1, ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK, info->micd_modes[0].src | - ARIZONA_ACCDET_MODE_HPL); + arizona->pdata.hpdet_channel); if (ret != 0) { - dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret); + dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret); goto err; } @@ -1121,6 +1118,26 @@ static void arizona_micd_set_level(struct arizona *arizona, int index, regmap_update_bits(arizona->regmap, reg, mask, level); } +static int arizona_extcon_of_get_pdata(struct arizona *arizona) +{ + struct arizona_pdata *pdata = &arizona->pdata; + unsigned int val = ARIZONA_ACCDET_MODE_HPL; + + of_property_read_u32(arizona->dev->of_node, "wlf,hpdet-channel", &val); + switch (val) { + case ARIZONA_ACCDET_MODE_HPL: + case ARIZONA_ACCDET_MODE_HPR: + pdata->hpdet_channel = val; + break; + default: + dev_err(arizona->dev, + "Wrong wlf,hpdet-channel DT value %d\n", val); + pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL; + } + + return 0; +} + static int arizona_extcon_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); @@ -1138,6 +1155,11 @@ static int arizona_extcon_probe(struct platform_device *pdev) if (!info) return -ENOMEM; + if (IS_ENABLED(CONFIG_OF)) { + if (!dev_get_platdata(arizona->dev)) + arizona_extcon_of_get_pdata(arizona); + } + info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD"); if (IS_ERR(info->micvdd)) { ret = PTR_ERR(info->micvdd); diff --git a/include/dt-bindings/mfd/arizona.h b/include/dt-bindings/mfd/arizona.h index c7af7c7ef793..fee48e624036 100644 --- a/include/dt-bindings/mfd/arizona.h +++ b/include/dt-bindings/mfd/arizona.h @@ -90,4 +90,8 @@ #define ARIZONA_INMODE_SE 1 #define ARIZONA_INMODE_DMIC 2 +#define ARIZONA_ACCDET_MODE_MIC 0 +#define ARIZONA_ACCDET_MODE_HPL 1 +#define ARIZONA_ACCDET_MODE_HPR 2 + #endif diff --git a/include/linux/mfd/arizona/pdata.h b/include/linux/mfd/arizona/pdata.h index 1789cb0f4f17..aa5c48b06755 100644 --- a/include/linux/mfd/arizona/pdata.h +++ b/include/linux/mfd/arizona/pdata.h @@ -121,6 +121,9 @@ struct arizona_pdata { /** GPIO used for mic isolation with HPDET */ int hpdet_id_gpio; + /** Channel to use for headphone detection */ + unsigned int hpdet_channel; + /** Extra debounce timeout used during initial mic detection (ms) */ int micd_detect_debounce; -- cgit v1.2.3-59-g8ed1b From 2a9de9c0f08d61fbe3764a21d22d0b72df97d6ae Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 24 Apr 2015 19:16:05 +0900 Subject: extcon: Use the unique id for external connector instead of string This patch uses the unique id to identify the type of external connector instead of string name. The string name have the many potential issues. So, this patch defines the 'extcon' enumeration which includes all supported external connector on EXTCON subsystem. If new external connector is necessary, the unique id of new connector have to be added in 'extcon' enumeration. There are current supported external connector in 'enum extcon' as following: enum extcon { EXTCON_NONE = 0x0, /* USB external connector */ EXTCON_USB = 0x1, EXTCON_USB_HOST = 0x2, /* Charger external connector */ EXTCON_TA = 0x10, EXTCON_FAST_CHARGER = 0x11, EXTCON_SLOW_CHARGER = 0x12, EXTCON_CHARGE_DOWNSTREAM = 0x13, /* Audio and video external connector */ EXTCON_LINE_IN = 0x20, EXTCON_LINE_OUT = 0x21, EXTCON_MICROPHONE = 0x22, EXTCON_HEADPHONE = 0x23, EXTCON_HDMI = 0x30, EXTCON_MHL = 0x31, EXTCON_DVI = 0x32, EXTCON_VGA = 0x33, EXTCON_SPDIF_IN = 0x34, EXTCON_SPDIF_OUT = 0x35, EXTCON_VIDEO_IN = 0x36, EXTCON_VIDEO_OUT = 0x37, /* Miscellaneous external connector */ EXTCON_DOCK = 0x50, EXTCON_JIG = 0x51, EXTCON_MECHANICAL = 0x52, EXTCON_END, }; For example in extcon-arizona.c: To use unique id removes the potential issue about handling the inconsistent name of external connector with string. - Previously, use the string to register the type of arizona jack connector static const char *arizona_cable[] = { "Mechanical", "Microphone", "Headphone", "Line-out", }; - Newly, use the unique id to register the type of arizona jack connector static const enum extcon arizona_cable[] = { EXTCON_MECHANICAL, EXTCON_MICROPHONE, EXTCON_HEADPHONE, EXTCON_LINE_OUT, EXTCON_NONE, }; And this patch modify the prototype of extcon_{get|set}_cable_state_() which uses the 'enum extcon id' instead of 'cable_index'. Because although one more extcon drivers support USB cable, each extcon driver might has the differnt 'cable_index' for USB cable. All extcon drivers can use the unique id number for same external connector with modified extcon_{get|set}_cable_state_(). - Previously, use 'cable_index' on these functions: extcon_get_cable_state_(struct extcon_dev*, int cable_index) extcon_set_cable_state_(struct extcon_dev*, int cable_index, bool state) -Newly, use 'enum extcon id' on these functions: extcon_get_cable_state_(struct extcon_dev*, enum extcon id) extcon_set_cable_state_(struct extcon_dev*, enum extcon id, bool state) Cc: Arnd Bergmann Cc: Felipe Balbi Signed-off-by: Chanwoo Choi Acked-by: Roger Quadros Acked-by: Charles Keepax Acked-by: Ramakrishna Pallala Reviewed-by: Krzysztof Kozlowski [arnd: Report the build break about drivers/usb/phy/phy-tahvo.c after using the unique id for external connector insteadf of string] Reported-by: Arnd Bergmann [dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()] Reported-by: Dan Carpenter --- drivers/extcon/extcon-arizona.c | 38 +++----- drivers/extcon/extcon-axp288.c | 24 ++--- drivers/extcon/extcon-max14577.c | 45 ++++----- drivers/extcon/extcon-max77693.c | 95 +++++++++---------- drivers/extcon/extcon-max77843.c | 56 +++++------ drivers/extcon/extcon-max8997.c | 59 +++++------- drivers/extcon/extcon-palmas.c | 22 +++-- drivers/extcon/extcon-rt8973a.c | 40 +++----- drivers/extcon/extcon-sm5502.c | 32 ++----- drivers/extcon/extcon-usb-gpio.c | 32 ++----- drivers/extcon/extcon.c | 163 ++++++++++++++++++--------------- drivers/usb/phy/phy-tahvo.c | 9 +- include/linux/extcon.h | 111 ++++++++++------------ include/linux/extcon/extcon-adc-jack.h | 5 +- 14 files changed, 320 insertions(+), 411 deletions(-) (limited to 'include') diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 1ec06b4b4875..9262b45a4484 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -118,17 +118,12 @@ static const int arizona_micd_levels[] = { 1257, }; -#define ARIZONA_CABLE_MECHANICAL 0 -#define ARIZONA_CABLE_MICROPHONE 1 -#define ARIZONA_CABLE_HEADPHONE 2 -#define ARIZONA_CABLE_LINEOUT 3 - -static const char *arizona_cable[] = { - "Mechanical", - "Microphone", - "Headphone", - "Line-out", - NULL, +static const enum extcon arizona_cable[] = { + EXTCON_MECHANICAL, + EXTCON_MICROPHONE, + EXTCON_HEADPHONE, + EXTCON_LINE_OUT, + EXTCON_NONE, }; static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info); @@ -557,7 +552,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) struct arizona_extcon_info *info = data; struct arizona *arizona = info->arizona; int id_gpio = arizona->pdata.hpdet_id_gpio; - int report = ARIZONA_CABLE_HEADPHONE; + enum extcon report = EXTCON_HEADPHONE; int ret, reading; bool mic = false; @@ -571,7 +566,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) } /* If the cable was removed while measuring ignore the result */ - ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL); + ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL); if (ret < 0) { dev_err(arizona->dev, "Failed to check cable state: %d\n", ret); @@ -602,9 +597,9 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) /* Report high impedence cables as line outputs */ if (reading >= 5000) - report = ARIZONA_CABLE_LINEOUT; + report = EXTCON_LINE_OUT; else - report = ARIZONA_CABLE_HEADPHONE; + report = EXTCON_HEADPHONE; ret = extcon_set_cable_state_(info->edev, report, true); if (ret != 0) @@ -689,8 +684,7 @@ err: ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); /* Just report headphone */ - ret = extcon_set_cable_state_(info->edev, - ARIZONA_CABLE_HEADPHONE, true); + ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true); if (ret != 0) dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); @@ -747,8 +741,7 @@ err: ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); /* Just report headphone */ - ret = extcon_set_cable_state_(info->edev, - ARIZONA_CABLE_HEADPHONE, true); + ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true); if (ret != 0) dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); @@ -787,7 +780,7 @@ static void arizona_micd_detect(struct work_struct *work) mutex_lock(&info->lock); /* If the cable was removed while measuring ignore the result */ - ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL); + ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL); if (ret < 0) { dev_err(arizona->dev, "Failed to check cable state: %d\n", ret); @@ -836,8 +829,7 @@ static void arizona_micd_detect(struct work_struct *work) arizona_identify_headphone(info); ret = extcon_set_cable_state_(info->edev, - ARIZONA_CABLE_MICROPHONE, true); - + EXTCON_MICROPHONE, true); if (ret != 0) dev_err(arizona->dev, "Headset report failed: %d\n", ret); @@ -1028,7 +1020,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data) if (info->last_jackdet == present) { dev_dbg(arizona->dev, "Detected jack\n"); ret = extcon_set_cable_state_(info->edev, - ARIZONA_CABLE_MECHANICAL, true); + EXTCON_MECHANICAL, true); if (ret != 0) dev_err(arizona->dev, "Mechanical report failed: %d\n", diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c index 8299adb9b676..3605aa96c25a 100644 --- a/drivers/extcon/extcon-axp288.c +++ b/drivers/extcon/extcon-axp288.c @@ -77,10 +77,6 @@ /* IRQ enable-6 register */ #define BC12_IRQ_CFG_MASK BIT(1) -#define AXP288_EXTCON_SLOW_CHARGER "SLOW-CHARGER" -#define AXP288_EXTCON_DOWNSTREAM_CHARGER "CHARGE-DOWNSTREAM" -#define AXP288_EXTCON_FAST_CHARGER "FAST-CHARGER" - enum axp288_extcon_reg { AXP288_PS_STAT_REG = 0x00, AXP288_PS_BOOT_REASON_REG = 0x02, @@ -105,11 +101,11 @@ enum axp288_extcon_irq { EXTCON_IRQ_END, }; -static const char *axp288_extcon_cables[] = { - AXP288_EXTCON_SLOW_CHARGER, - AXP288_EXTCON_DOWNSTREAM_CHARGER, - AXP288_EXTCON_FAST_CHARGER, - NULL, +static const enum extcon axp288_extcon_cables[] = { + EXTCON_SLOW_CHARGER, + EXTCON_CHARGE_DOWNSTREAM, + EXTCON_FAST_CHARGER, + EXTCON_NONE, }; struct axp288_extcon_info { @@ -161,7 +157,7 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) { static bool notify_otg, notify_charger; - static char *cable; + static enum extcon cable; int ret, stat, cfg, pwr_stat; u8 chrg_type; bool vbus_attach = false; @@ -196,18 +192,18 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) dev_dbg(info->dev, "sdp cable is connecetd\n"); notify_otg = true; notify_charger = true; - cable = AXP288_EXTCON_SLOW_CHARGER; + cable = EXTCON_SLOW_CHARGER; break; case DET_STAT_CDP: dev_dbg(info->dev, "cdp cable is connecetd\n"); notify_otg = true; notify_charger = true; - cable = AXP288_EXTCON_DOWNSTREAM_CHARGER; + cable = EXTCON_CHARGE_DOWNSTREAM; break; case DET_STAT_DCP: dev_dbg(info->dev, "dcp cable is connecetd\n"); notify_charger = true; - cable = AXP288_EXTCON_FAST_CHARGER; + cable = EXTCON_FAST_CHARGER; break; default: dev_warn(info->dev, @@ -230,7 +226,7 @@ notify_otg: } if (notify_charger) - extcon_set_cable_state(info->edev, cable, vbus_attach); + extcon_set_cable_state_(info->edev, cable, vbus_attach); /* Clear the flags on disconnect event */ if (!vbus_attach) diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c index ad8f8ddc8e51..e7c3edb5bd4b 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -148,27 +148,14 @@ enum max14577_muic_acc_type { MAX14577_MUIC_ADC_OPEN, }; -/* max14577 MUIC device support below list of accessories(external connector) */ -enum { - EXTCON_CABLE_USB = 0, - EXTCON_CABLE_TA, - EXTCON_CABLE_FAST_CHARGER, - EXTCON_CABLE_SLOW_CHARGER, - EXTCON_CABLE_CHARGE_DOWNSTREAM, - EXTCON_CABLE_JIG, - - _EXTCON_CABLE_NUM, -}; - -static const char *max14577_extcon_cable[] = { - [EXTCON_CABLE_USB] = "USB", - [EXTCON_CABLE_TA] = "TA", - [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger", - [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", - [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", - [EXTCON_CABLE_JIG] = "JIG", - - NULL, +static const enum extcon max14577_extcon_cable[] = { + EXTCON_USB, + EXTCON_TA, + EXTCON_FAST_CHARGER, + EXTCON_SLOW_CHARGER, + EXTCON_CHARGE_DOWNSTREAM, + EXTCON_JIG, + EXTCON_NONE, }; /* @@ -369,7 +356,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "JIG", attached); + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); return 0; } @@ -466,20 +453,22 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "USB", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB, attached); break; case MAX14577_CHARGER_TYPE_DEDICATED_CHG: - extcon_set_cable_state(info->edev, "TA", attached); + extcon_set_cable_state_(info->edev, EXTCON_TA, attached); break; case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: - extcon_set_cable_state(info->edev, - "Charge-downstream", attached); + extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM, + attached); break; case MAX14577_CHARGER_TYPE_SPECIAL_500MA: - extcon_set_cable_state(info->edev, "Slow-charger", attached); + extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER, + attached); break; case MAX14577_CHARGER_TYPE_SPECIAL_1A: - extcon_set_cable_state(info->edev, "Fast-charger", attached); + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER, + attached); break; case MAX14577_CHARGER_TYPE_NONE: case MAX14577_CHARGER_TYPE_DEAD_BATTERY: diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index c274249245ff..20e796e10e57 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -200,32 +200,17 @@ enum max77693_muic_acc_type { /* * MAX77693 MUIC device support below list of accessories(external connector) */ -enum { - EXTCON_CABLE_USB = 0, - EXTCON_CABLE_USB_HOST, - EXTCON_CABLE_TA, - EXTCON_CABLE_FAST_CHARGER, - EXTCON_CABLE_SLOW_CHARGER, - EXTCON_CABLE_CHARGE_DOWNSTREAM, - EXTCON_CABLE_MHL, - EXTCON_CABLE_JIG, - EXTCON_CABLE_DOCK, - - _EXTCON_CABLE_NUM, -}; - -static const char *max77693_extcon_cable[] = { - [EXTCON_CABLE_USB] = "USB", - [EXTCON_CABLE_USB_HOST] = "USB-Host", - [EXTCON_CABLE_TA] = "TA", - [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger", - [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", - [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", - [EXTCON_CABLE_MHL] = "MHL", - [EXTCON_CABLE_JIG] = "JIG", - [EXTCON_CABLE_DOCK] = "DOCK", - - NULL, +static const enum extcon max77693_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_TA, + EXTCON_FAST_CHARGER, + EXTCON_SLOW_CHARGER, + EXTCON_CHARGE_DOWNSTREAM, + EXTCON_MHL, + EXTCON_JIG, + EXTCON_DOCK, + EXTCON_NONE, }; /* @@ -472,7 +457,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, int ret = 0; int vbvolt; bool cable_attached; - char dock_name[CABLE_NAME_MAX]; + enum extcon dock_id; dev_info(info->dev, "external connector is %s (adc:0x%02x)\n", @@ -517,16 +502,16 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "DOCK", attached); - extcon_set_cable_state(info->edev, "MHL", attached); + extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached); + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached); goto out; case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ - strcpy(dock_name, "DOCK"); + dock_id = EXTCON_DOCK; break; case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ - strcpy(dock_name, "DOCK"); + dock_id = EXTCON_DOCK; if (!attached) - extcon_set_cable_state(info->edev, "USB", false); + extcon_set_cable_state_(info->edev, EXTCON_USB, false); break; default: dev_err(info->dev, "failed to detect %s dock device\n", @@ -538,7 +523,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, dock_name, attached); + extcon_set_cable_state_(info->edev, dock_id, attached); out: return 0; @@ -603,20 +588,19 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info) ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "USB-Host", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); break; case MAX77693_MUIC_GND_AV_CABLE_LOAD: /* Audio Video Cable with load, PATH:AUDIO */ ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, - "Audio-video-load", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB, attached); break; case MAX77693_MUIC_GND_MHL: case MAX77693_MUIC_GND_MHL_VB: /* MHL or MHL with USB/TA cable */ - extcon_set_cable_state(info->edev, "MHL", attached); + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached); break; default: dev_err(info->dev, "failed to detect %s cable of gnd type\n", @@ -658,7 +642,7 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "JIG", attached); + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); return 0; } @@ -812,10 +796,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) * - Support charging through micro-usb port without * data connection */ - extcon_set_cable_state(info->edev, "TA", attached); + extcon_set_cable_state_(info->edev, EXTCON_TA, attached); if (!cable_attached) - extcon_set_cable_state(info->edev, - "MHL", cable_attached); + extcon_set_cable_state_(info->edev, EXTCON_MHL, + cable_attached); break; } @@ -838,11 +822,12 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) * - Support charging through micro-usb port without * data connection. */ - extcon_set_cable_state(info->edev, "USB", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB, + attached); if (!cable_attached) - extcon_set_cable_state(info->edev, "DOCK", - cable_attached); + extcon_set_cable_state_(info->edev, EXTCON_DOCK, + cable_attached); break; case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ /* @@ -870,9 +855,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "DOCK", attached); - extcon_set_cable_state(info->edev, "MHL", attached); - + extcon_set_cable_state_(info->edev, EXTCON_DOCK, + attached); + extcon_set_cable_state_(info->edev, EXTCON_MHL, + attached); break; } @@ -905,23 +891,26 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "USB", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB, + attached); break; case MAX77693_CHARGER_TYPE_DEDICATED_CHG: /* Only TA cable */ - extcon_set_cable_state(info->edev, "TA", attached); + extcon_set_cable_state_(info->edev, EXTCON_TA, attached); break; } break; case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT: - extcon_set_cable_state(info->edev, - "Charge-downstream", attached); + extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM, + attached); break; case MAX77693_CHARGER_TYPE_APPLE_500MA: - extcon_set_cable_state(info->edev, "Slow-charger", attached); + extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER, + attached); break; case MAX77693_CHARGER_TYPE_APPLE_1A_2A: - extcon_set_cable_state(info->edev, "Fast-charger", attached); + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER, + attached); break; case MAX77693_CHARGER_TYPE_DEAD_BATTERY: break; diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index 5746d7bc165f..d78a64d7fc20 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c @@ -118,28 +118,16 @@ enum max77843_muic_charger_type { MAX77843_MUIC_CHG_GND, }; -enum { - MAX77843_CABLE_USB = 0, - MAX77843_CABLE_USB_HOST, - MAX77843_CABLE_TA, - MAX77843_CABLE_CHARGE_DOWNSTREAM, - MAX77843_CABLE_FAST_CHARGER, - MAX77843_CABLE_SLOW_CHARGER, - MAX77843_CABLE_MHL, - MAX77843_CABLE_JIG, - - MAX77843_CABLE_NUM, -}; - -static const char *max77843_extcon_cable[] = { - [MAX77843_CABLE_USB] = "USB", - [MAX77843_CABLE_USB_HOST] = "USB-HOST", - [MAX77843_CABLE_TA] = "TA", - [MAX77843_CABLE_CHARGE_DOWNSTREAM] = "CHARGER-DOWNSTREAM", - [MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER", - [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER", - [MAX77843_CABLE_MHL] = "MHL", - [MAX77843_CABLE_JIG] = "JIG", +static const enum extcon max77843_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_TA, + EXTCON_CHARGE_DOWNSTREAM, + EXTCON_FAST_CHARGER, + EXTCON_SLOW_CHARGER, + EXTCON_MHL, + EXTCON_JIG, + EXTCON_NONE, }; struct max77843_muic_irq { @@ -354,7 +342,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "USB-HOST", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); break; case MAX77843_MUIC_GND_MHL_VB: case MAX77843_MUIC_GND_MHL: @@ -362,7 +350,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "MHL", attached); + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached); break; default: dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", @@ -398,7 +386,7 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "JIG", attached); + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); return 0; } @@ -490,36 +478,38 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "USB", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB, attached); break; case MAX77843_MUIC_CHG_DOWNSTREAM: ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, - "CHARGER-DOWNSTREAM", attached); + extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM, + attached); break; case MAX77843_MUIC_CHG_DEDICATED: ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "TA", attached); + extcon_set_cable_state_(info->edev, EXTCON_TA, attached); break; case MAX77843_MUIC_CHG_SPECIAL_500MA: ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "SLOW-CHAREGER", attached); + extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER, + attached); break; case MAX77843_MUIC_CHG_SPECIAL_1A: ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "FAST-CHARGER", attached); + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER, + attached); break; case MAX77843_MUIC_CHG_GND: gnd_type = max77843_muic_get_cable_type(info, @@ -527,9 +517,9 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info) /* Charger cable on MHL accessory is attach or detach */ if (gnd_type == MAX77843_MUIC_GND_MHL_VB) - extcon_set_cable_state(info->edev, "TA", true); + extcon_set_cable_state_(info->edev, EXTCON_TA, true); else if (gnd_type == MAX77843_MUIC_GND_MHL) - extcon_set_cable_state(info->edev, "TA", false); + extcon_set_cable_state_(info->edev, EXTCON_TA, false); break; case MAX77843_MUIC_CHG_NONE: break; diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index 33613c490d34..4d10949c6eb2 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -145,32 +145,17 @@ struct max8997_muic_info { int path_uart; }; -enum { - EXTCON_CABLE_USB = 0, - EXTCON_CABLE_USB_HOST, - EXTCON_CABLE_TA, - EXTCON_CABLE_FAST_CHARGER, - EXTCON_CABLE_SLOW_CHARGER, - EXTCON_CABLE_CHARGE_DOWNSTREAM, - EXTCON_CABLE_MHL, - EXTCON_CABLE_DOCK, - EXTCON_CABLE_JIG, - - _EXTCON_CABLE_NUM, -}; - -static const char *max8997_extcon_cable[] = { - [EXTCON_CABLE_USB] = "USB", - [EXTCON_CABLE_USB_HOST] = "USB-Host", - [EXTCON_CABLE_TA] = "TA", - [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger", - [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", - [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", - [EXTCON_CABLE_MHL] = "MHL", - [EXTCON_CABLE_DOCK] = "DOCK", - [EXTCON_CABLE_JIG] = "JIG", - - NULL, +static const enum extcon max8997_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_TA, + EXTCON_FAST_CHARGER, + EXTCON_SLOW_CHARGER, + EXTCON_CHARGE_DOWNSTREAM, + EXTCON_MHL, + EXTCON_DOCK, + EXTCON_JIG, + EXTCON_NONE, }; /* @@ -345,10 +330,10 @@ static int max8997_muic_handle_usb(struct max8997_muic_info *info, switch (usb_type) { case MAX8997_USB_HOST: - extcon_set_cable_state(info->edev, "USB-Host", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached); break; case MAX8997_USB_DEVICE: - extcon_set_cable_state(info->edev, "USB", attached); + extcon_set_cable_state_(info->edev, EXTCON_USB, attached); break; default: dev_err(info->dev, "failed to detect %s usb cable\n", @@ -373,7 +358,7 @@ static int max8997_muic_handle_dock(struct max8997_muic_info *info, switch (cable_type) { case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD: case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON: - extcon_set_cable_state(info->edev, "DOCK", attached); + extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached); break; default: dev_err(info->dev, "failed to detect %s dock device\n", @@ -396,7 +381,7 @@ static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info, return ret; } - extcon_set_cable_state(info->edev, "JIG", attached); + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached); return 0; } @@ -418,7 +403,7 @@ static int max8997_muic_adc_handler(struct max8997_muic_info *info) return ret; break; case MAX8997_MUIC_ADC_MHL: - extcon_set_cable_state(info->edev, "MHL", attached); + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached); break; case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF: case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON: @@ -501,17 +486,19 @@ static int max8997_muic_chg_handler(struct max8997_muic_info *info) } break; case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT: - extcon_set_cable_state(info->edev, - "Charge-downstream", attached); + extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM, + attached); break; case MAX8997_CHARGER_TYPE_DEDICATED_CHG: - extcon_set_cable_state(info->edev, "TA", attached); + extcon_set_cable_state_(info->edev, EXTCON_TA, attached); break; case MAX8997_CHARGER_TYPE_500MA: - extcon_set_cable_state(info->edev, "Slow-charger", attached); + extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER, + attached); break; case MAX8997_CHARGER_TYPE_1A: - extcon_set_cable_state(info->edev, "Fast-charger", attached); + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER, + attached); break; default: dev_err(info->dev, diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index 9c8943d691b1..d68954045a33 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -29,10 +29,10 @@ #include #include -static const char *palmas_extcon_cable[] = { - [0] = "USB", - [1] = "USB-HOST", - NULL, +static const enum extcon palmas_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_NONE, }; static const int mutually_exclusive[] = {0x3, 0x0}; @@ -49,6 +49,7 @@ static void palmas_usb_wakeup(struct palmas *palmas, int enable) static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb) { struct palmas_usb *palmas_usb = _palmas_usb; + struct extcon_dev *edev = palmas_usb->edev; unsigned int vbus_line_state; palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE, @@ -57,7 +58,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb) if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) { if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) { palmas_usb->linkstat = PALMAS_USB_STATE_VBUS; - extcon_set_cable_state(palmas_usb->edev, "USB", true); + extcon_set_cable_state_(edev, EXTCON_USB, true); dev_info(palmas_usb->dev, "USB cable is attached\n"); } else { dev_dbg(palmas_usb->dev, @@ -66,7 +67,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb) } else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) { if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) { palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; - extcon_set_cable_state(palmas_usb->edev, "USB", false); + extcon_set_cable_state_(edev, EXTCON_USB, false); dev_info(palmas_usb->dev, "USB cable is detached\n"); } else { dev_dbg(palmas_usb->dev, @@ -81,6 +82,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) { unsigned int set, id_src; struct palmas_usb *palmas_usb = _palmas_usb; + struct extcon_dev *edev = palmas_usb->edev; palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, PALMAS_USB_ID_INT_LATCH_SET, &set); @@ -93,7 +95,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) PALMAS_USB_ID_INT_LATCH_CLR, PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND); palmas_usb->linkstat = PALMAS_USB_STATE_ID; - extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true); + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); dev_info(palmas_usb->dev, "USB-HOST cable is attached\n"); } else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) && (id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) { @@ -101,17 +103,17 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb) PALMAS_USB_ID_INT_LATCH_CLR, PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT); palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; - extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false); + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) && (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) { palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; - extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false); + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false); dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) && (id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) { palmas_usb->linkstat = PALMAS_USB_STATE_ID; - extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true); + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true); dev_info(palmas_usb->dev, " USB-HOST cable is attached\n"); } diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c index 04447f36c994..f2a8672cbf82 100644 --- a/drivers/extcon/extcon-rt8973a.c +++ b/drivers/extcon/extcon-rt8973a.c @@ -90,21 +90,12 @@ static struct reg_data rt8973a_reg_data[] = { }; /* List of detectable cables */ -enum { - EXTCON_CABLE_USB = 0, - EXTCON_CABLE_USB_HOST, - EXTCON_CABLE_TA, - EXTCON_CABLE_JIG, - - EXTCON_CABLE_END, -}; - -static const char *rt8973a_extcon_cable[] = { - [EXTCON_CABLE_USB] = "USB", - [EXTCON_CABLE_USB_HOST] = "USB-Host", - [EXTCON_CABLE_TA] = "TA", - [EXTCON_CABLE_JIG] = "JIG", - NULL, +static const enum extcon rt8973a_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_TA, + EXTCON_JIG, + EXTCON_NONE, }; /* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */ @@ -307,14 +298,11 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info, enum rt8973a_event_type event) { static unsigned int prev_cable_type; - const char **cable_names = info->edev->supported_cable; unsigned int con_sw = DM_DP_SWITCH_UART; - int ret, idx = 0, cable_type; + int ret, cable_type; + enum extcon id; bool attached = false; - if (!cable_names) - return 0; - switch (event) { case RT8973A_EVENT_ATTACH: cable_type = rt8973a_muic_get_cable_type(info); @@ -341,25 +329,25 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info, switch (cable_type) { case RT8973A_MUIC_ADC_OTG: - idx = EXTCON_CABLE_USB_HOST; + id = EXTCON_USB_HOST; con_sw = DM_DP_SWITCH_USB; break; case RT8973A_MUIC_ADC_TA: - idx = EXTCON_CABLE_TA; + id = EXTCON_TA; con_sw = DM_DP_SWITCH_OPEN; break; case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: - idx = EXTCON_CABLE_JIG; + id = EXTCON_JIG; con_sw = DM_DP_SWITCH_USB; break; case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: - idx = EXTCON_CABLE_JIG; + id = EXTCON_JIG; con_sw = DM_DP_SWITCH_UART; break; case RT8973A_MUIC_ADC_USB: - idx = EXTCON_CABLE_USB; + id = EXTCON_USB; con_sw = DM_DP_SWITCH_USB; break; case RT8973A_MUIC_ADC_OPEN: @@ -409,7 +397,7 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info, return ret; /* Change the state of external accessory */ - extcon_set_cable_state(info->edev, cable_names[idx], attached); + extcon_set_cable_state_(info->edev, id, attached); return 0; } diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c index 6f1d11f8723b..520693d6fa8a 100644 --- a/drivers/extcon/extcon-sm5502.c +++ b/drivers/extcon/extcon-sm5502.c @@ -92,19 +92,11 @@ static struct reg_data sm5502_reg_data[] = { }; /* List of detectable cables */ -enum { - EXTCON_CABLE_USB = 0, - EXTCON_CABLE_USB_HOST, - EXTCON_CABLE_TA, - - EXTCON_CABLE_END, -}; - -static const char *sm5502_extcon_cable[] = { - [EXTCON_CABLE_USB] = "USB", - [EXTCON_CABLE_USB_HOST] = "USB-Host", - [EXTCON_CABLE_TA] = "TA", - NULL, +static const enum extcon sm5502_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_TA, + EXTCON_NONE, }; /* Define supported accessory type */ @@ -377,16 +369,12 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, bool attached) { static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND; - const char **cable_names = info->edev->supported_cable; unsigned int cable_type = SM5502_MUIC_ADC_GROUND; unsigned int con_sw = DM_DP_SWITCH_OPEN; unsigned int vbus_sw = VBUSIN_SWITCH_OPEN; - unsigned int idx = 0; + enum extcon id; int ret; - if (!cable_names) - return 0; - /* Get the type of attached or detached cable */ if (attached) cable_type = sm5502_muic_get_cable_type(info); @@ -396,17 +384,17 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, switch (cable_type) { case SM5502_MUIC_ADC_OPEN_USB: - idx = EXTCON_CABLE_USB; + id = EXTCON_USB; con_sw = DM_DP_SWITCH_USB; vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB; break; case SM5502_MUIC_ADC_OPEN_TA: - idx = EXTCON_CABLE_TA; + id = EXTCON_TA; con_sw = DM_DP_SWITCH_OPEN; vbus_sw = VBUSIN_SWITCH_VBUSOUT; break; case SM5502_MUIC_ADC_OPEN_USB_OTG: - idx = EXTCON_CABLE_USB_HOST; + id = EXTCON_USB_HOST; con_sw = DM_DP_SWITCH_USB; vbus_sw = VBUSIN_SWITCH_OPEN; break; @@ -422,7 +410,7 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, return ret; /* Change the state of external accessory */ - extcon_set_cable_state(info->edev, cable_names[idx], attached); + extcon_set_cable_state_(info->edev, id, attached); return 0; } diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index 900744b978fc..14da94cb57fa 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -39,18 +39,10 @@ struct usb_extcon_info { struct delayed_work wq_detcable; }; -/* List of detectable cables */ -enum { - EXTCON_CABLE_USB = 0, - EXTCON_CABLE_USB_HOST, - - EXTCON_CABLE_END, -}; - -static const char *usb_extcon_cable[] = { - [EXTCON_CABLE_USB] = "USB", - [EXTCON_CABLE_USB_HOST] = "USB-HOST", - NULL, +static const enum extcon usb_extcon_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + EXTCON_NONE, }; static void usb_extcon_detect_cable(struct work_struct *work) @@ -68,24 +60,16 @@ static void usb_extcon_detect_cable(struct work_struct *work) * As we don't have event for USB peripheral cable attached, * we simulate USB peripheral attach here. */ - extcon_set_cable_state(info->edev, - usb_extcon_cable[EXTCON_CABLE_USB_HOST], - false); - extcon_set_cable_state(info->edev, - usb_extcon_cable[EXTCON_CABLE_USB], - true); + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false); + extcon_set_cable_state_(info->edev, EXTCON_USB, true); } else { /* * ID = 0 means USB HOST cable attached. * As we don't have event for USB peripheral cable detached, * we simulate USB peripheral detach here. */ - extcon_set_cable_state(info->edev, - usb_extcon_cable[EXTCON_CABLE_USB], - false); - extcon_set_cable_state(info->edev, - usb_extcon_cable[EXTCON_CABLE_USB_HOST], - true); + extcon_set_cable_state_(info->edev, EXTCON_USB, false); + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true); } } diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 2fb5f757e811..a57355fc8fea 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -3,6 +3,9 @@ * * External connector (extcon) class driver * + * Copyright (C) 2015 Samsung Electronics + * Author: Chanwoo Choi + * * Copyright (C) 2012 Samsung Electronics * Author: Donggeun Kim * Author: MyungJoo Ham @@ -32,36 +35,32 @@ #include #include -/* - * extcon_cable_name suggests the standard cable names for commonly used - * cable types. - * - * However, please do not use extcon_cable_name directly for extcon_dev - * struct's supported_cable pointer unless your device really supports - * every single port-type of the following cable names. Please choose cable - * names that are actually used in your extcon device. - */ -const char extcon_cable_name[][CABLE_NAME_MAX + 1] = { +#define SUPPORTED_CABLE_MAX 32 +#define CABLE_NAME_MAX 30 + +static const char *extcon_name[] = { [EXTCON_USB] = "USB", [EXTCON_USB_HOST] = "USB-Host", [EXTCON_TA] = "TA", [EXTCON_FAST_CHARGER] = "Fast-charger", [EXTCON_SLOW_CHARGER] = "Slow-charger", [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream", + [EXTCON_LINE_IN] = "Line-in", + [EXTCON_LINE_OUT] = "Line-out", + [EXTCON_MICROPHONE] = "Microphone", + [EXTCON_HEADPHONE] = "Headphone", [EXTCON_HDMI] = "HDMI", [EXTCON_MHL] = "MHL", [EXTCON_DVI] = "DVI", [EXTCON_VGA] = "VGA", - [EXTCON_DOCK] = "Dock", - [EXTCON_LINE_IN] = "Line-in", - [EXTCON_LINE_OUT] = "Line-out", - [EXTCON_MIC_IN] = "Microphone", - [EXTCON_HEADPHONE_OUT] = "Headphone", [EXTCON_SPDIF_IN] = "SPDIF-in", [EXTCON_SPDIF_OUT] = "SPDIF-out", [EXTCON_VIDEO_IN] = "Video-in", [EXTCON_VIDEO_OUT] = "Video-out", + [EXTCON_DOCK] = "Dock", + [EXTCON_JIG] = "JIG", [EXTCON_MECHANICAL] = "Mechanical", + NULL, }; static struct class *extcon_class; @@ -101,6 +100,43 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) return 0; } +static int find_cable_index_by_id(struct extcon_dev *edev, const enum extcon id) +{ + int i; + + /* Find the the index of extcon cable in edev->supported_cable */ + for (i = 0; i < edev->max_supported; i++) { + if (edev->supported_cable[i] == id) + return i; + } + + return -EINVAL; +} + +static int find_cable_index_by_name(struct extcon_dev *edev, const char *name) +{ + enum extcon id = EXTCON_NONE; + int i; + + if (edev->max_supported == 0) + return -EINVAL; + + /* Find the the number of extcon cable */ + for (i = 0; i < EXTCON_END; i++) { + if (!extcon_name[i]) + continue; + if (!strncmp(extcon_name[i], name, CABLE_NAME_MAX)) { + id = i; + break; + } + } + + if (id == EXTCON_NONE) + return -EINVAL; + + return find_cable_index_by_id(edev, id); +} + static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -118,11 +154,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, if (edev->max_supported == 0) return sprintf(buf, "%u\n", edev->state); - for (i = 0; i < SUPPORTED_CABLE_MAX; i++) { - if (!edev->supported_cable[i]) - break; + for (i = 0; i < edev->max_supported; i++) { count += sprintf(buf + count, "%s=%d\n", - edev->supported_cable[i], + extcon_name[edev->supported_cable[i]], !!(edev->state & (1 << i))); } @@ -171,9 +205,10 @@ static ssize_t cable_name_show(struct device *dev, { struct extcon_cable *cable = container_of(attr, struct extcon_cable, attr_name); + int i = cable->cable_index; return sprintf(buf, "%s\n", - cable->edev->supported_cable[cable->cable_index]); + extcon_name[cable->edev->supported_cable[i]]); } static ssize_t cable_state_show(struct device *dev, @@ -283,39 +318,19 @@ int extcon_set_state(struct extcon_dev *edev, u32 state) EXPORT_SYMBOL_GPL(extcon_set_state); /** - * extcon_find_cable_index() - Get the cable index based on the cable name. + * extcon_get_cable_state_() - Get the status of a specific cable. * @edev: the extcon device that has the cable. - * @cable_name: cable name to be searched. - * - * Note that accessing a cable state based on cable_index is faster than - * cable_name because using cable_name induces a loop with strncmp(). - * Thus, when get/set_cable_state is repeatedly used, using cable_index - * is recommended. + * @id: the unique id of each external connector in extcon enumeration. */ -int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name) +int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id) { - int i; - - if (edev->supported_cable) { - for (i = 0; edev->supported_cable[i]; i++) { - if (!strncmp(edev->supported_cable[i], - cable_name, CABLE_NAME_MAX)) - return i; - } - } + int index; - return -EINVAL; -} -EXPORT_SYMBOL_GPL(extcon_find_cable_index); + index = find_cable_index_by_id(edev, id); + if (index < 0) + return index; -/** - * extcon_get_cable_state_() - Get the status of a specific cable. - * @edev: the extcon device that has the cable. - * @index: cable index that can be retrieved by extcon_find_cable_index(). - */ -int extcon_get_cable_state_(struct extcon_dev *edev, int index) -{ - if (index < 0 || (edev->max_supported && edev->max_supported <= index)) + if (edev->max_supported && edev->max_supported <= index) return -EINVAL; return !!(edev->state & (1 << index)); @@ -331,7 +346,7 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state_); */ int extcon_get_cable_state(struct extcon_dev *edev, const char *cable_name) { - return extcon_get_cable_state_(edev, extcon_find_cable_index + return extcon_get_cable_state_(edev, find_cable_index_by_name (edev, cable_name)); } EXPORT_SYMBOL_GPL(extcon_get_cable_state); @@ -339,17 +354,22 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state); /** * extcon_set_cable_state_() - Set the status of a specific cable. * @edev: the extcon device that has the cable. - * @index: cable index that can be retrieved by - * extcon_find_cable_index(). - * @cable_state: the new cable status. The default semantics is + * @id: the unique id of each external connector + * in extcon enumeration. + * @state: the new cable status. The default semantics is * true: attached / false: detached. */ -int extcon_set_cable_state_(struct extcon_dev *edev, - int index, bool cable_state) +int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id, + bool cable_state) { u32 state; + int index; - if (index < 0 || (edev->max_supported && edev->max_supported <= index)) + index = find_cable_index_by_id(edev, id); + if (index < 0) + return index; + + if (edev->max_supported && edev->max_supported <= index) return -EINVAL; state = cable_state ? (1 << index) : 0; @@ -369,7 +389,7 @@ EXPORT_SYMBOL_GPL(extcon_set_cable_state_); int extcon_set_cable_state(struct extcon_dev *edev, const char *cable_name, bool cable_state) { - return extcon_set_cable_state_(edev, extcon_find_cable_index + return extcon_set_cable_state_(edev, find_cable_index_by_name (edev, cable_name), cable_state); } EXPORT_SYMBOL_GPL(extcon_set_cable_state); @@ -455,8 +475,8 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, if (!obj->edev) return -ENODEV; - obj->cable_index = extcon_find_cable_index(obj->edev, - cable_name); + obj->cable_index = find_cable_index_by_name(obj->edev, + cable_name); if (obj->cable_index < 0) return obj->cable_index; @@ -479,7 +499,7 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, while ((dev = class_dev_iter_next(&iter))) { extd = dev_get_drvdata(dev); - if (extcon_find_cable_index(extd, cable_name) < 0) + if (find_cable_index_by_name(extd, cable_name) < 0) continue; class_dev_iter_exit(&iter); @@ -595,7 +615,7 @@ static void dummy_sysfs_dev_release(struct device *dev) /* * extcon_dev_allocate() - Allocate the memory of extcon device. - * @supported_cable: Array of supported cable names ending with NULL. + * @supported_cable: Array of supported extcon ending with EXTCON_NONE. * If supported_cable is NULL, cable name related APIs * are disabled. * @@ -605,7 +625,7 @@ static void dummy_sysfs_dev_release(struct device *dev) * * Return the pointer of extcon device if success or ERR_PTR(err) if fail */ -struct extcon_dev *extcon_dev_allocate(const char **supported_cable) +struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable) { struct extcon_dev *edev; @@ -647,7 +667,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res) /** * devm_extcon_dev_allocate - Allocate managed extcon device * @dev: device owning the extcon device being created - * @supported_cable: Array of supported cable names ending with NULL. + * @supported_cable: Array of supported extcon ending with EXTCON_NONE. * If supported_cable is NULL, cable name related APIs * are disabled. * @@ -659,7 +679,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res) * or ERR_PTR(err) if fail */ struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const char **supported_cable) + const enum extcon *supported_cable) { struct extcon_dev **ptr, *edev; @@ -709,17 +729,15 @@ int extcon_dev_register(struct extcon_dev *edev) return ret; } - if (edev->supported_cable) { - /* Get size of array */ - for (index = 0; edev->supported_cable[index]; index++) - ; - edev->max_supported = index; - } else { - edev->max_supported = 0; - } + if (!edev->supported_cable) + return -EINVAL; + + for (; edev->supported_cable[index] != EXTCON_NONE; index++); + edev->max_supported = index; if (index > SUPPORTED_CABLE_MAX) { - dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n"); + dev_err(&edev->dev, + "exceed the maximum number of supported cables\n"); return -EINVAL; } @@ -1070,6 +1088,7 @@ static void __exit extcon_class_exit(void) } module_exit(extcon_class_exit); +MODULE_AUTHOR("Chanwoo Choi "); MODULE_AUTHOR("Mike Lockwood "); MODULE_AUTHOR("Donggeun Kim "); MODULE_AUTHOR("MyungJoo Ham "); diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c index 845f658276b1..1d1bb9ad8ccf 100644 --- a/drivers/usb/phy/phy-tahvo.c +++ b/drivers/usb/phy/phy-tahvo.c @@ -60,10 +60,11 @@ struct tahvo_usb { struct extcon_dev extcon; }; -static const char *tahvo_cable[] = { - "USB-HOST", - "USB", - NULL, +static const enum extcon tahvo_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + + EXTCON_NONE, }; static ssize_t vbus_state_show(struct device *device, diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 799474d9dc48..85c882f0029e 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -1,6 +1,9 @@ /* * External connector (extcon) class driver * + * Copyright (C) 2015 Samsung Electronics + * Author: Chanwoo Choi + * * Copyright (C) 2012 Samsung Electronics * Author: Donggeun Kim * Author: MyungJoo Ham @@ -27,50 +30,41 @@ #include #include -#define SUPPORTED_CABLE_MAX 32 -#define CABLE_NAME_MAX 30 - -/* - * The standard cable name is to help support general notifier - * and notifiee device drivers to share the common names. - * Please use standard cable names unless your notifier device has - * a very unique and abnormal cable or - * the cable type is supposed to be used with only one unique - * pair of notifier/notifiee devices. - * - * Please add any other "standard" cables used with extcon dev. - * - * You may add a dot and number to specify version or specification - * of the specific cable if it is required. (e.g., "Fast-charger.18" - * and "Fast-charger.10" for 1.8A and 1.0A chargers) - * However, the notifiee and notifier should be able to handle such - * string and if the notifiee can negotiate the protocol or identify, - * you don't need such convention. This convention is helpful when - * notifier can distinguish but notifiee cannot. - */ -enum extcon_cable_name { - EXTCON_USB = 0, - EXTCON_USB_HOST, - EXTCON_TA, /* Travel Adaptor */ - EXTCON_FAST_CHARGER, - EXTCON_SLOW_CHARGER, - EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device */ - EXTCON_HDMI, - EXTCON_MHL, - EXTCON_DVI, - EXTCON_VGA, - EXTCON_DOCK, - EXTCON_LINE_IN, - EXTCON_LINE_OUT, - EXTCON_MIC_IN, - EXTCON_HEADPHONE_OUT, - EXTCON_SPDIF_IN, - EXTCON_SPDIF_OUT, - EXTCON_VIDEO_IN, - EXTCON_VIDEO_OUT, - EXTCON_MECHANICAL, +enum extcon { + EXTCON_NONE = 0x0, + + /* USB external connector */ + EXTCON_USB = 0x1, + EXTCON_USB_HOST = 0x2, + + /* Charger external connector */ + EXTCON_TA = 0x10, + EXTCON_FAST_CHARGER = 0x11, + EXTCON_SLOW_CHARGER = 0x12, + EXTCON_CHARGE_DOWNSTREAM = 0x13, + + /* Audio/Video external connector */ + EXTCON_LINE_IN = 0x20, + EXTCON_LINE_OUT = 0x21, + EXTCON_MICROPHONE = 0x22, + EXTCON_HEADPHONE = 0x23, + + EXTCON_HDMI = 0x30, + EXTCON_MHL = 0x31, + EXTCON_DVI = 0x32, + EXTCON_VGA = 0x33, + EXTCON_SPDIF_IN = 0x34, + EXTCON_SPDIF_OUT = 0x35, + EXTCON_VIDEO_IN = 0x36, + EXTCON_VIDEO_OUT = 0x37, + + /* Etc external connector */ + EXTCON_DOCK = 0x50, + EXTCON_JIG = 0x51, + EXTCON_MECHANICAL = 0x52, + + EXTCON_END, }; -extern const char extcon_cable_name[][CABLE_NAME_MAX + 1]; struct extcon_cable; @@ -78,7 +72,7 @@ struct extcon_cable; * struct extcon_dev - An extcon device represents one external connector. * @name: The name of this extcon device. Parent device name is * used if NULL. - * @supported_cable: Array of supported cable names ending with NULL. + * @supported_cable: Array of supported cable names ending with EXTCON_NONE. * If supported_cable is NULL, cable name related APIs * are disabled. * @mutually_exclusive: Array of mutually exclusive set of cables that cannot @@ -113,7 +107,7 @@ struct extcon_cable; struct extcon_dev { /* Optional user initializing data */ const char *name; - const char **supported_cable; + const enum extcon *supported_cable; const u32 *mutually_exclusive; /* Optional callbacks to override class functions */ @@ -194,10 +188,10 @@ extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); /* * Following APIs control the memory of extcon device. */ -extern struct extcon_dev *extcon_dev_allocate(const char **cables); +extern struct extcon_dev *extcon_dev_allocate(const enum extcon *cable); extern void extcon_dev_free(struct extcon_dev *edev); extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const char **cables); + const enum extcon *cable); extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev); /* @@ -216,13 +210,10 @@ extern int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state); /* * get/set_cable_state access each bit of the 32b encoded state value. - * They are used to access the status of each cable based on the cable_name - * or cable_index, which is retrieved by extcon_find_cable_index + * They are used to access the status of each cable based on the cable_name. */ -extern int extcon_find_cable_index(struct extcon_dev *sdev, - const char *cable_name); -extern int extcon_get_cable_state_(struct extcon_dev *edev, int cable_index); -extern int extcon_set_cable_state_(struct extcon_dev *edev, int cable_index, +extern int extcon_get_cable_state_(struct extcon_dev *edev, enum extcon id); +extern int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id, bool cable_state); extern int extcon_get_cable_state(struct extcon_dev *edev, @@ -281,7 +272,7 @@ static inline int devm_extcon_dev_register(struct device *dev, static inline void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev) { } -static inline struct extcon_dev *extcon_dev_allocate(const char **cables) +static inline struct extcon_dev *extcon_dev_allocate(const enum extcon *cable) { return ERR_PTR(-ENOSYS); } @@ -289,7 +280,7 @@ static inline struct extcon_dev *extcon_dev_allocate(const char **cables) static inline void extcon_dev_free(struct extcon_dev *edev) { } static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const char **cables) + const enum extcon *cable) { return ERR_PTR(-ENOSYS); } @@ -312,20 +303,14 @@ static inline int extcon_update_state(struct extcon_dev *edev, u32 mask, return 0; } -static inline int extcon_find_cable_index(struct extcon_dev *edev, - const char *cable_name) -{ - return 0; -} - static inline int extcon_get_cable_state_(struct extcon_dev *edev, - int cable_index) + enum extcon id) { return 0; } static inline int extcon_set_cable_state_(struct extcon_dev *edev, - int cable_index, bool cable_state) + enum extcon id, bool cable_state) { return 0; } diff --git a/include/linux/extcon/extcon-adc-jack.h b/include/linux/extcon/extcon-adc-jack.h index 9ca958c4e94c..53c60806bcfb 100644 --- a/include/linux/extcon/extcon-adc-jack.h +++ b/include/linux/extcon/extcon-adc-jack.h @@ -44,7 +44,7 @@ struct adc_jack_cond { * @consumer_channel: Unique name to identify the channel on the consumer * side. This typically describes the channels used within * the consumer. E.g. 'battery_voltage' - * @cable_names: array of cable names ending with null. + * @cable_names: array of extcon id for supported cables. * @adc_contitions: array of struct adc_jack_cond conditions ending * with .state = 0 entry. This describes how to decode * adc values into extcon state. @@ -58,8 +58,7 @@ struct adc_jack_pdata { const char *name; const char *consumer_channel; - /* The last entry should be NULL */ - const char **cable_names; + const enum extcon *cable_names; /* The last entry's state should be 0 */ struct adc_jack_cond *adc_conditions; -- cgit v1.2.3-59-g8ed1b From 046050f6e623e442e9c71c525462ebd395dae526 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 19 May 2015 20:01:12 +0900 Subject: extcon: Update the prototype of extcon_register_notifier() with enum extcon Previously, extcon consumer driver used the extcon_register_interest() to register the notifier chain and then to receive the notifier event when external connector's state is changed. When registering the notifier chain for specific external connector with extcon_register_interest(), it used the the string name of external connector directly. There are potential problem because of unclear, non-standard and inconsequent cable name. Namely, it is not appropriate method to identify each external connector. So, this patch modify the prototype of extcon_register_notifier() by using the 'enum extcon' which are the unique id for each external connector instead of unclear string method. - Previously, the extcon consumer driver used the extcon_register_interest() with 'cable_name' to point out the specific external connector. Also. it used the un-needed structure (struct extcon_specific_cable_nb). : int extcon_register_interest(struct extcon_specific_cable_nb *obj, const char *extcon_name, const char *cable_name, struct notifier_block *nb) - Newly, the updated extcon_register_notifier() would definitely support the same feature to detech the changed state of external connector without any specific structure (struct extcon_specific_cable_nb). : int extcon_register_notifier(struct extcon_dev *edev, enum extcon id, struct notifier_block *nb) This patch support the both extcon_register_interest() and new extcon_register_ notifier(). But the extcon_{register|unregister}_interest() will be deprecated because extcon core would support the notifier event for extcon consumer driver with only updated extcon_register_notifier() and 'extcon_specific_cable_nb' will be removed if there are no extcon consumer driver with legacy extcon_{register|unregister}_interest(). Signed-off-by: Chanwoo Choi Reviewed-by: Krzysztof Kozlowski --- drivers/extcon/extcon.c | 91 ++++++++++++++++++++++++++----------------------- include/linux/extcon.h | 17 +++++---- 2 files changed, 56 insertions(+), 52 deletions(-) (limited to 'include') diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index fce2687bde8e..5099c11d8833 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -146,6 +146,16 @@ static int find_cable_index_by_name(struct extcon_dev *edev, const char *name) return find_cable_index_by_id(edev, id); } +static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached) +{ + if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) { + *attached = new ? true : false; + return true; + } + + return false; +} + static ssize_t state_show(struct device *dev, struct device_attribute *attr, char *buf) { @@ -254,23 +264,27 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state) char *envp[3]; int env_offset = 0; int length; + int index; unsigned long flags; + bool attached; spin_lock_irqsave(&edev->lock, flags); if (edev->state != ((edev->state & ~mask) | (state & mask))) { - u32 old_state = edev->state; - if (check_mutually_exclusive(edev, (edev->state & ~mask) | (state & mask))) { spin_unlock_irqrestore(&edev->lock, flags); return -EPERM; } + for (index = 0; index < edev->max_supported; index++) { + if (is_extcon_changed(edev->state, state, index, &attached)) + raw_notifier_call_chain(&edev->nh[index], attached, edev); + } + edev->state &= ~mask; edev->state |= state & mask; - raw_notifier_call_chain(&edev->nh, old_state, edev); /* This could be in interrupt handler */ prop_buf = (char *)get_zeroed_page(GFP_ATOMIC); if (prop_buf) { @@ -423,29 +437,6 @@ out: } EXPORT_SYMBOL_GPL(extcon_get_extcon_dev); -static int _call_per_cable(struct notifier_block *nb, unsigned long val, - void *ptr) -{ - struct extcon_specific_cable_nb *obj = container_of(nb, - struct extcon_specific_cable_nb, internal_nb); - struct extcon_dev *edev = ptr; - - if ((val & (1 << obj->cable_index)) != - (edev->state & (1 << obj->cable_index))) { - bool cable_state = true; - - obj->previous_value = val; - - if (val & (1 << obj->cable_index)) - cable_state = false; - - return obj->user_nb->notifier_call(obj->user_nb, - cable_state, ptr); - } - - return NOTIFY_OK; -} - /** * extcon_register_interest() - Register a notifier for a state change of a * specific cable, not an entier set of cables of a @@ -491,11 +482,10 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, obj->user_nb = nb; - obj->internal_nb.notifier_call = _call_per_cable; - spin_lock_irqsave(&obj->edev->lock, flags); - ret = raw_notifier_chain_register(&obj->edev->nh, - &obj->internal_nb); + ret = raw_notifier_chain_register( + &obj->edev->nh[obj->cable_index], + obj->user_nb); spin_unlock_irqrestore(&obj->edev->lock, flags); } else { struct class_dev_iter iter; @@ -538,7 +528,8 @@ int extcon_unregister_interest(struct extcon_specific_cable_nb *obj) return -EINVAL; spin_lock_irqsave(&obj->edev->lock, flags); - ret = raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb); + ret = raw_notifier_chain_unregister( + &obj->edev->nh[obj->cable_index], obj->user_nb); spin_unlock_irqrestore(&obj->edev->lock, flags); return ret; @@ -548,21 +539,24 @@ EXPORT_SYMBOL_GPL(extcon_unregister_interest); /** * extcon_register_notifier() - Register a notifiee to get notified by * any attach status changes from the extcon. - * @edev: the extcon device. + * @edev: the extcon device that has the external connecotr. + * @id: the unique id of each external connector in extcon enumeration. * @nb: a notifier block to be registered. * * Note that the second parameter given to the callback of nb (val) is * "old_state", not the current state. The current state can be retrieved * by looking at the third pameter (edev pointer)'s state value. */ -int extcon_register_notifier(struct extcon_dev *edev, - struct notifier_block *nb) +int extcon_register_notifier(struct extcon_dev *edev, enum extcon id, + struct notifier_block *nb) { unsigned long flags; - int ret; + int ret, idx; + + idx = find_cable_index_by_id(edev, id); spin_lock_irqsave(&edev->lock, flags); - ret = raw_notifier_chain_register(&edev->nh, nb); + ret = raw_notifier_chain_register(&edev->nh[idx], nb); spin_unlock_irqrestore(&edev->lock, flags); return ret; @@ -571,17 +565,20 @@ EXPORT_SYMBOL_GPL(extcon_register_notifier); /** * extcon_unregister_notifier() - Unregister a notifiee from the extcon device. - * @edev: the extcon device. - * @nb: a registered notifier block to be unregistered. + * @edev: the extcon device that has the external connecotr. + * @id: the unique id of each external connector in extcon enumeration. + * @nb: a notifier block to be registered. */ -int extcon_unregister_notifier(struct extcon_dev *edev, - struct notifier_block *nb) +int extcon_unregister_notifier(struct extcon_dev *edev, enum extcon id, + struct notifier_block *nb) { unsigned long flags; - int ret; + int ret, idx; + + idx = find_cable_index_by_id(edev, id); spin_lock_irqsave(&edev->lock, flags); - ret = raw_notifier_chain_unregister(&edev->nh, nb); + ret = raw_notifier_chain_unregister(&edev->nh[idx], nb); spin_unlock_irqrestore(&edev->lock, flags); return ret; @@ -893,7 +890,15 @@ int extcon_dev_register(struct extcon_dev *edev) spin_lock_init(&edev->lock); - RAW_INIT_NOTIFIER_HEAD(&edev->nh); + edev->nh = devm_kzalloc(&edev->dev, + sizeof(*edev->nh) * edev->max_supported, GFP_KERNEL); + if (!edev->nh) { + ret = -ENOMEM; + goto err_dev; + } + + for (index = 0; index < edev->max_supported; index++) + RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]); dev_set_drvdata(&edev->dev, edev); edev->state = 0; diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 85c882f0029e..be9652b3a154 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -116,7 +116,7 @@ struct extcon_dev { /* Internal data. Please do not set. */ struct device dev; - struct raw_notifier_head nh; + struct raw_notifier_head *nh; struct list_head entry; int max_supported; spinlock_t lock; /* could be called by irq handler */ @@ -155,8 +155,6 @@ struct extcon_cable { /** * struct extcon_specific_cable_nb - An internal data for * extcon_register_interest(). - * @internal_nb: A notifier block bridging extcon notifier - * and cable notifier. * @user_nb: user provided notifier block for events from * a specific cable. * @cable_index: the target cable. @@ -164,7 +162,6 @@ struct extcon_cable { * @previous_value: the saved previous event value. */ struct extcon_specific_cable_nb { - struct notifier_block internal_nb; struct notifier_block *user_nb; int cable_index; struct extcon_dev *edev; @@ -240,10 +237,10 @@ extern int extcon_unregister_interest(struct extcon_specific_cable_nb *nb); * we do not recommend to use this for normal 'notifiee' device drivers who * want to be notified by a specific external port of the notifier. */ -extern int extcon_register_notifier(struct extcon_dev *edev, +extern int extcon_register_notifier(struct extcon_dev *edev, enum extcon id, + struct notifier_block *nb); +extern int extcon_unregister_notifier(struct extcon_dev *edev, enum extcon id, struct notifier_block *nb); -extern int extcon_unregister_notifier(struct extcon_dev *edev, - struct notifier_block *nb); /* * Following API get the extcon device from devicetree. @@ -333,13 +330,15 @@ static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) } static inline int extcon_register_notifier(struct extcon_dev *edev, - struct notifier_block *nb) + enum extcon id, + struct notifier_block *nb) { return 0; } static inline int extcon_unregister_notifier(struct extcon_dev *edev, - struct notifier_block *nb) + enum extcon id, + struct notifier_block *nb) { return 0; } -- cgit v1.2.3-59-g8ed1b From c93b76b34b4d8dbe8e3443eb27e49ac60034342b Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Thu, 7 May 2015 15:54:02 +0300 Subject: mei: bus: report also uuid in module alias In order to automate modules matching add device uuid which is reported in client enumeration, keep also the name that is needed in for nfc distinguishing radio vendor Report mei:name:uuid Cc: linux-api@vger.kernel.org Cc: Samuel Ortiz Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- Documentation/ABI/testing/sysfs-bus-mei | 2 +- drivers/misc/mei/bus.c | 42 ++++++++++++++++++++++++++------- drivers/misc/mei/mei_dev.h | 2 ++ drivers/nfc/mei_phy.h | 3 +++ drivers/nfc/microread/mei.c | 2 +- drivers/nfc/pn544/mei.c | 2 +- include/linux/mod_devicetable.h | 13 ++++++++++ scripts/mod/devicetable-offsets.c | 1 + scripts/mod/file2alias.c | 18 ++++++++++++-- 9 files changed, 72 insertions(+), 13 deletions(-) (limited to 'include') diff --git a/Documentation/ABI/testing/sysfs-bus-mei b/Documentation/ABI/testing/sysfs-bus-mei index 2066f0bbd453..91967a70313a 100644 --- a/Documentation/ABI/testing/sysfs-bus-mei +++ b/Documentation/ABI/testing/sysfs-bus-mei @@ -4,4 +4,4 @@ KernelVersion: 3.10 Contact: Samuel Ortiz linux-mei@linux.intel.com Description: Stores the same MODALIAS value emitted by uevent - Format: mei: + Format: mei::: diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index 1101d6efaf27..17b00baa53b1 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -30,23 +30,40 @@ #define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver) #define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev) +static inline uuid_le uuid_le_cast(const __u8 uuid[16]) +{ + return *(uuid_le *)uuid; +} + static int mei_cl_device_match(struct device *dev, struct device_driver *drv) { struct mei_cl_device *device = to_mei_cl_device(dev); struct mei_cl_driver *driver = to_mei_cl_driver(drv); const struct mei_cl_device_id *id; + const uuid_le *uuid; + const char *name; if (!device) return 0; + uuid = mei_me_cl_uuid(device->me_cl); + name = device->name; + if (!driver || !driver->id_table) return 0; id = driver->id_table; - while (id->name[0]) { - if (!strncmp(dev_name(dev), id->name, sizeof(id->name))) - return 1; + while (uuid_le_cmp(NULL_UUID_LE, uuid_le_cast(id->uuid))) { + + if (!uuid_le_cmp(*uuid, uuid_le_cast(id->uuid))) { + if (id->name[0]) { + if (!strncmp(name, id->name, sizeof(id->name))) + return 1; + } else { + return 1; + } + } id++; } @@ -69,7 +86,7 @@ static int mei_cl_device_probe(struct device *dev) dev_dbg(dev, "Device probe\n"); - strlcpy(id.name, dev_name(dev), sizeof(id.name)); + strlcpy(id.name, device->name, sizeof(id.name)); return driver->probe(device, &id); } @@ -100,9 +117,12 @@ static int mei_cl_device_remove(struct device *dev) static ssize_t modalias_show(struct device *dev, struct device_attribute *a, char *buf) { - int len; + struct mei_cl_device *device = to_mei_cl_device(dev); + const uuid_le *uuid = mei_me_cl_uuid(device->me_cl); + size_t len; - len = snprintf(buf, PAGE_SIZE, "mei:%s\n", dev_name(dev)); + len = snprintf(buf, PAGE_SIZE, "mei:%s:" MEI_CL_UUID_FMT ":", + device->name, MEI_CL_UUID_ARGS(uuid->b)); return (len >= PAGE_SIZE) ? (PAGE_SIZE - 1) : len; } @@ -116,7 +136,11 @@ ATTRIBUTE_GROUPS(mei_cl_dev); static int mei_cl_uevent(struct device *dev, struct kobj_uevent_env *env) { - if (add_uevent_var(env, "MODALIAS=mei:%s", dev_name(dev))) + struct mei_cl_device *device = to_mei_cl_device(dev); + const uuid_le *uuid = mei_me_cl_uuid(device->me_cl); + + if (add_uevent_var(env, "MODALIAS=mei:%s:" MEI_CL_UUID_FMT ":", + device->name, MEI_CL_UUID_ARGS(uuid->b))) return -ENOMEM; return 0; @@ -185,7 +209,9 @@ struct mei_cl_device *mei_cl_add_device(struct mei_device *dev, device->dev.bus = &mei_cl_bus_type; device->dev.type = &mei_cl_device_type; - dev_set_name(&device->dev, "%s", name); + strlcpy(device->name, name, sizeof(device->name)); + + dev_set_name(&device->dev, "mei:%s:%pUl", name, mei_me_cl_uuid(me_cl)); status = device_register(&device->dev); if (status) { diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 79ab78184523..ab719e674edf 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h @@ -376,6 +376,7 @@ struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid); * @dev: linux driver model device pointer * @me_cl: me client * @cl: mei client + * @name: device name * @ops: ME transport ops * @event_work: async work to execute event callback * @event_cb: Drivers register this callback to get asynchronous ME @@ -389,6 +390,7 @@ struct mei_cl_device { struct mei_me_client *me_cl; struct mei_cl *cl; + char name[MEI_CL_NAME_SIZE]; const struct mei_cl_ops *ops; diff --git a/drivers/nfc/mei_phy.h b/drivers/nfc/mei_phy.h index d669900f8278..06608c28ff14 100644 --- a/drivers/nfc/mei_phy.h +++ b/drivers/nfc/mei_phy.h @@ -3,7 +3,10 @@ #include #include +#include +#define MEI_NFC_UUID __UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \ + 0x94, 0xd4, 0x50, 0x26, 0x67, 0x23, 0x77, 0x5c) #define MEI_NFC_HEADER_SIZE 10 #define MEI_NFC_MAX_HCI_PAYLOAD 300 diff --git a/drivers/nfc/microread/mei.c b/drivers/nfc/microread/mei.c index 2d1395be64ae..f9f5fc97cdd7 100644 --- a/drivers/nfc/microread/mei.c +++ b/drivers/nfc/microread/mei.c @@ -67,7 +67,7 @@ static int microread_mei_remove(struct mei_cl_device *device) } static struct mei_cl_device_id microread_mei_tbl[] = { - { MICROREAD_DRIVER_NAME }, + { MICROREAD_DRIVER_NAME, MEI_NFC_UUID}, /* required last entry */ { } diff --git a/drivers/nfc/pn544/mei.c b/drivers/nfc/pn544/mei.c index 330cd4031009..101a37e12efa 100644 --- a/drivers/nfc/pn544/mei.c +++ b/drivers/nfc/pn544/mei.c @@ -67,7 +67,7 @@ static int pn544_mei_remove(struct mei_cl_device *device) } static struct mei_cl_device_id pn544_mei_tbl[] = { - { PN544_DRIVER_NAME }, + { PN544_DRIVER_NAME, MEI_NFC_UUID}, /* required last entry */ { } diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 3bfd56778c29..2d2b2b571d61 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -599,9 +599,22 @@ struct ipack_device_id { #define MEI_CL_MODULE_PREFIX "mei:" #define MEI_CL_NAME_SIZE 32 +#define MEI_CL_UUID_FMT "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x" +#define MEI_CL_UUID_ARGS(_u) \ + _u[0], _u[1], _u[2], _u[3], _u[4], _u[5], _u[6], _u[7], \ + _u[8], _u[9], _u[10], _u[11], _u[12], _u[13], _u[14], _u[15] +/** + * struct mei_cl_device_id - MEI client device identifier + * @name: helper name + * @uuid: client uuid + * @driver_info: information used by the driver. + * + * identifies mei client device by uuid and name + */ struct mei_cl_device_id { char name[MEI_CL_NAME_SIZE]; + __u8 uuid[16]; kernel_ulong_t driver_info; }; diff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c index fce36d0f6898..091f6290a651 100644 --- a/scripts/mod/devicetable-offsets.c +++ b/scripts/mod/devicetable-offsets.c @@ -182,6 +182,7 @@ int main(void) DEVID(mei_cl_device_id); DEVID_FIELD(mei_cl_device_id, name); + DEVID_FIELD(mei_cl_device_id, uuid); DEVID(rio_device_id); DEVID_FIELD(rio_device_id, did); diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 78691d51a479..62c517f4b592 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -131,6 +131,15 @@ static inline void add_wildcard(char *str) strcat(str + len, "*"); } +static inline void add_uuid(char *str, __u8 uuid[16]) +{ + int len = strlen(str); + int i; + + for (i = 0; i < 16; i++) + sprintf(str + len + (i << 1), "%02x", uuid[i]); +} + /** * Check that sizeof(device_id type) are consistent with size of section * in .o file. If in-consistent then userspace and kernel does not agree @@ -1160,13 +1169,18 @@ static int do_cpu_entry(const char *filename, void *symval, char *alias) } ADD_TO_DEVTABLE("cpu", cpu_feature, do_cpu_entry); -/* Looks like: mei:S */ +/* Looks like: mei:S:uuid */ static int do_mei_entry(const char *filename, void *symval, char *alias) { DEF_FIELD_ADDR(symval, mei_cl_device_id, name); + DEF_FIELD_ADDR(symval, mei_cl_device_id, uuid); + + sprintf(alias, MEI_CL_MODULE_PREFIX); + sprintf(alias + strlen(alias), "%s:", (*name)[0] ? *name : "*"); + add_uuid(alias, *uuid); - sprintf(alias, MEI_CL_MODULE_PREFIX "%s", *name); + strcat(alias, ":*"); return 1; } -- cgit v1.2.3-59-g8ed1b From dbac993f6a6df24d5edc362667e524ba43543472 Mon Sep 17 00:00:00 2001 From: Tomas Winkler Date: Thu, 7 May 2015 15:54:07 +0300 Subject: mei: export mei client device struct to external use Cc: Samuel Ortiz Signed-off-by: Tomas Winkler Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/mei_dev.h | 35 ----------------------------------- include/linux/mei_cl_bus.h | 38 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 37 deletions(-) (limited to 'include') diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 609a2d2c2dba..70a644f688b0 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h @@ -343,41 +343,6 @@ int mei_cl_bus_init(void); void mei_cl_bus_exit(void); struct mei_cl *mei_cl_bus_find_cl_by_uuid(struct mei_device *dev, uuid_le uuid); - -/** - * struct mei_cl_device - MEI device handle - * An mei_cl_device pointer is returned from mei_add_device() - * and links MEI bus clients to their actual ME host client pointer. - * Drivers for MEI devices will get an mei_cl_device pointer - * when being probed and shall use it for doing ME bus I/O. - * - * @dev: linux driver model device pointer - * @me_cl: me client - * @cl: mei client - * @name: device name - * @event_work: async work to execute event callback - * @event_cb: Drivers register this callback to get asynchronous ME - * events (e.g. Rx buffer pending) notifications. - * @event_context: event callback run context - * @events: Events bitmask sent to the driver. - * @priv_data: client private data - */ -struct mei_cl_device { - struct device dev; - - struct mei_me_client *me_cl; - struct mei_cl *cl; - char name[MEI_CL_NAME_SIZE]; - - struct work_struct event_work; - mei_cl_event_cb_t event_cb; - void *event_context; - unsigned long events; - - void *priv_data; -}; - - /** * enum mei_pg_event - power gating transition events * diff --git a/include/linux/mei_cl_bus.h b/include/linux/mei_cl_bus.h index 0819d36a3a74..a16b1f9c1aca 100644 --- a/include/linux/mei_cl_bus.h +++ b/include/linux/mei_cl_bus.h @@ -7,6 +7,42 @@ struct mei_cl_device; +typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device, + u32 events, void *context); + +/** + * struct mei_cl_device - MEI device handle + * An mei_cl_device pointer is returned from mei_add_device() + * and links MEI bus clients to their actual ME host client pointer. + * Drivers for MEI devices will get an mei_cl_device pointer + * when being probed and shall use it for doing ME bus I/O. + * + * @dev: linux driver model device pointer + * @me_cl: me client + * @cl: mei client + * @name: device name + * @event_work: async work to execute event callback + * @event_cb: Drivers register this callback to get asynchronous ME + * events (e.g. Rx buffer pending) notifications. + * @event_context: event callback run context + * @events: Events bitmask sent to the driver. + * @priv_data: client private data + */ +struct mei_cl_device { + struct device dev; + + struct mei_me_client *me_cl; + struct mei_cl *cl; + char name[MEI_CL_NAME_SIZE]; + + struct work_struct event_work; + mei_cl_event_cb_t event_cb; + void *event_context; + unsigned long events; + + void *priv_data; +}; + struct mei_cl_driver { struct device_driver driver; const char *name; @@ -28,8 +64,6 @@ void mei_cl_driver_unregister(struct mei_cl_driver *driver); ssize_t mei_cl_send(struct mei_cl_device *device, u8 *buf, size_t length); ssize_t mei_cl_recv(struct mei_cl_device *device, u8 *buf, size_t length); -typedef void (*mei_cl_event_cb_t)(struct mei_cl_device *device, - u32 events, void *context); int mei_cl_register_event_cb(struct mei_cl_device *device, mei_cl_event_cb_t read_cb, void *context); -- cgit v1.2.3-59-g8ed1b From 7df20f2d893db42eaa1ea1e30a2573c971ec9238 Mon Sep 17 00:00:00 2001 From: Sudeep Dutt Date: Wed, 29 Apr 2015 05:32:28 -0700 Subject: misc: mic: SCIF header file and IOCTL interface This patch introduces the SCIF documentation in the header file and describes the IOCTL interface for user mode. mic_overview.txt is updated with documentation on SCIF and a new document describing SCIF in more details is available in scif_overview.txt. Reviewed-by: Nikhil Rao Reviewed-by: Ashutosh Dixit Signed-off-by: Sudeep Dutt Signed-off-by: Greg Kroah-Hartman --- Documentation/mic/mic_overview.txt | 28 +- Documentation/mic/scif_overview.txt | 98 ++++ include/linux/scif.h | 993 ++++++++++++++++++++++++++++++++++++ include/uapi/linux/Kbuild | 1 + include/uapi/linux/scif_ioctl.h | 130 +++++ 5 files changed, 1238 insertions(+), 12 deletions(-) create mode 100644 Documentation/mic/scif_overview.txt create mode 100644 include/linux/scif.h create mode 100644 include/uapi/linux/scif_ioctl.h (limited to 'include') diff --git a/Documentation/mic/mic_overview.txt b/Documentation/mic/mic_overview.txt index 77c541802ad9..1a2f2c8ec59e 100644 --- a/Documentation/mic/mic_overview.txt +++ b/Documentation/mic/mic_overview.txt @@ -24,6 +24,10 @@ a virtual bus called mic bus is created and virtual dma devices are created on it by the host/card drivers. On host the channels are private and used only by the host driver to transfer data for the virtio devices. +The Symmetric Communication Interface (SCIF (pronounced as skiff)) is a +low level communications API across PCIe currently implemented for MIC. +More details are available at scif_overview.txt. + Here is a block diagram of the various components described above. The virtio backends are situated on the host rather than the card given better single threaded performance for the host compared to MIC, the ability of @@ -47,18 +51,18 @@ the fact that the virtio block storage backend can only be on the host. | | | Virtio over PCIe IOCTLs | | | +--------------------------+ +-----------+ | | | +-----------+ -| MIC DMA | | | | | MIC DMA | -| Driver | | | | | Driver | -+-----------+ | | | +-----------+ - | | | | | -+---------------+ | | | +----------------+ -|MIC virtual Bus| | | | |MIC virtual Bus | -+---------------+ | | | +----------------+ - | | | | | - | +--------------+ | +---------------+ | - | |Intel MIC | | |Intel MIC | | - +---|Card Driver | | |Host Driver | | - +--------------+ | +---------------+-----+ +| MIC DMA | | +----------+ | +-----------+ | | MIC DMA | +| Driver | | | SCIF | | | SCIF | | | Driver | ++-----------+ | +----------+ | +-----------+ | +-----------+ + | | | | | | | ++---------------+ | +-----+-----+ | +-----+-----+ | +---------------+ +|MIC virtual Bus| | |SCIF HW Bus| | |SCIF HW BUS| | |MIC virtual Bus| ++---------------+ | +-----------+ | +-----+-----+ | +---------------+ + | | | | | | | + | +--------------+ | | | +---------------+ | + | |Intel MIC | | | | |Intel MIC | | + +---|Card Driver +----+ | | |Host Driver | | + +--------------+ | +----+---------------+-----+ | | | +-------------------------------------------------------------+ | | diff --git a/Documentation/mic/scif_overview.txt b/Documentation/mic/scif_overview.txt new file mode 100644 index 000000000000..0a280d986731 --- /dev/null +++ b/Documentation/mic/scif_overview.txt @@ -0,0 +1,98 @@ +The Symmetric Communication Interface (SCIF (pronounced as skiff)) is a low +level communications API across PCIe currently implemented for MIC. Currently +SCIF provides inter-node communication within a single host platform, where a +node is a MIC Coprocessor or Xeon based host. SCIF abstracts the details of +communicating over the PCIe bus while providing an API that is symmetric +across all the nodes in the PCIe network. An important design objective for SCIF +is to deliver the maximum possible performance given the communication +abilities of the hardware. SCIF has been used to implement an offload compiler +runtime and OFED support for MPI implementations for MIC coprocessors. + +==== SCIF API Components ==== +The SCIF API has the following parts: +1. Connection establishment using a client server model +2. Byte stream messaging intended for short messages +3. Node enumeration to determine online nodes +4. Poll semantics for detection of incoming connections and messages +5. Memory registration to pin down pages +6. Remote memory mapping for low latency CPU accesses via mmap +7. Remote DMA (RDMA) for high bandwidth DMA transfers +8. Fence APIs for RDMA synchronization + +SCIF exposes the notion of a connection which can be used by peer processes on +nodes in a SCIF PCIe "network" to share memory "windows" and to communicate. A +process in a SCIF node initiates a SCIF connection to a peer process on a +different node via a SCIF "endpoint". SCIF endpoints support messaging APIs +which are similar to connection oriented socket APIs. Connected SCIF endpoints +can also register local memory which is followed by data transfer using either +DMA, CPU copies or remote memory mapping via mmap. SCIF supports both user and +kernel mode clients which are functionally equivalent. + +==== SCIF Performance for MIC ==== +DMA bandwidth comparison between the TCP (over ethernet over PCIe) stack versus +SCIF shows the performance advantages of SCIF for HPC applications and runtimes. + + Comparison of TCP and SCIF based BW + + Throughput (GB/sec) + 8 + PCIe Bandwidth ****** + + TCP ###### + 7 + ************************************** SCIF %%%%%% + | %%%%%%%%%%%%%%%%%%% + 6 + %%%% + | %% + | %%% + 5 + %% + | %% + 4 + %% + | %% + 3 + %% + | % + 2 + %% + | %% + | % + 1 + + + ###################################### + 0 +++---+++--+--+-+--+--+-++-+--+-++-+--+-++-+- + 1 10 100 1000 10000 100000 + Transfer Size (KBytes) + +SCIF allows memory sharing via mmap(..) between processes on different PCIe +nodes and thus provides bare-metal PCIe latency. The round trip SCIF mmap +latency from the host to an x100 MIC for an 8 byte message is 0.44 usecs. + +SCIF has a user space library which is a thin IOCTL wrapper providing a user +space API similar to the kernel API in scif.h. The SCIF user space library +is distributed @ https://software.intel.com/en-us/mic-developer + +Here is some pseudo code for an example of how two applications on two PCIe +nodes would typically use the SCIF API: + +Process A (on node A) Process B (on node B) + +/* get online node information */ +scif_get_node_ids(..) scif_get_node_ids(..) +scif_open(..) scif_open(..) +scif_bind(..) scif_bind(..) +scif_listen(..) +scif_accept(..) scif_connect(..) +/* SCIF connection established */ + +/* Send and receive short messages */ +scif_send(..)/scif_recv(..) scif_send(..)/scif_recv(..) + +/* Register memory */ +scif_register(..) scif_register(..) + +/* RDMA */ +scif_readfrom(..)/scif_writeto(..) scif_readfrom(..)/scif_writeto(..) + +/* Fence DMAs */ +scif_fence_signal(..) scif_fence_signal(..) + +mmap(..) mmap(..) + +/* Access remote registered memory */ + +/* Close the endpoints */ +scif_close(..) scif_close(..) diff --git a/include/linux/scif.h b/include/linux/scif.h new file mode 100644 index 000000000000..44f4f3898bbe --- /dev/null +++ b/include/linux/scif.h @@ -0,0 +1,993 @@ +/* + * Intel MIC Platform Software Stack (MPSS) + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2014 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that 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. + * + * BSD LICENSE + * + * Copyright(c) 2014 Intel Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Intel SCIF driver. + * + */ +#ifndef __SCIF_H__ +#define __SCIF_H__ + +#include +#include +#include + +#define SCIF_ACCEPT_SYNC 1 +#define SCIF_SEND_BLOCK 1 +#define SCIF_RECV_BLOCK 1 + +enum { + SCIF_PROT_READ = (1 << 0), + SCIF_PROT_WRITE = (1 << 1) +}; + +enum { + SCIF_MAP_FIXED = 0x10, + SCIF_MAP_KERNEL = 0x20, +}; + +enum { + SCIF_FENCE_INIT_SELF = (1 << 0), + SCIF_FENCE_INIT_PEER = (1 << 1), + SCIF_SIGNAL_LOCAL = (1 << 4), + SCIF_SIGNAL_REMOTE = (1 << 5) +}; + +enum { + SCIF_RMA_USECPU = (1 << 0), + SCIF_RMA_USECACHE = (1 << 1), + SCIF_RMA_SYNC = (1 << 2), + SCIF_RMA_ORDERED = (1 << 3) +}; + +/* End of SCIF Admin Reserved Ports */ +#define SCIF_ADMIN_PORT_END 1024 + +/* End of SCIF Reserved Ports */ +#define SCIF_PORT_RSVD 1088 + +typedef struct scif_endpt *scif_epd_t; + +#define SCIF_OPEN_FAILED ((scif_epd_t)-1) +#define SCIF_REGISTER_FAILED ((off_t)-1) +#define SCIF_MMAP_FAILED ((void *)-1) + +/** + * scif_open() - Create an endpoint + * + * Return: + * Upon successful completion, scif_open() returns an endpoint descriptor to + * be used in subsequent SCIF functions calls to refer to that endpoint; + * otherwise in user mode SCIF_OPEN_FAILED (that is ((scif_epd_t)-1)) is + * returned and errno is set to indicate the error; in kernel mode a NULL + * scif_epd_t is returned. + * + * Errors: + * ENOMEM - Insufficient kernel memory was available + */ +scif_epd_t scif_open(void); + +/** + * scif_bind() - Bind an endpoint to a port + * @epd: endpoint descriptor + * @pn: port number + * + * scif_bind() binds endpoint epd to port pn, where pn is a port number on the + * local node. If pn is zero, a port number greater than or equal to + * SCIF_PORT_RSVD is assigned and returned. Each endpoint may be bound to + * exactly one local port. Ports less than 1024 when requested can only be bound + * by system (or root) processes or by processes executed by privileged users. + * + * Return: + * Upon successful completion, scif_bind() returns the port number to which epd + * is bound; otherwise in user mode -1 is returned and errno is set to + * indicate the error; in kernel mode the negative of one of the following + * errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * EINVAL - the endpoint or the port is already bound + * EISCONN - The endpoint is already connected + * ENOSPC - No port number available for assignment + * EACCES - The port requested is protected and the user is not the superuser + */ +int scif_bind(scif_epd_t epd, u16 pn); + +/** + * scif_listen() - Listen for connections on an endpoint + * @epd: endpoint descriptor + * @backlog: maximum pending connection requests + * + * scif_listen() marks the endpoint epd as a listening endpoint - that is, as + * an endpoint that will be used to accept incoming connection requests. Once + * so marked, the endpoint is said to be in the listening state and may not be + * used as the endpoint of a connection. + * + * The endpoint, epd, must have been bound to a port. + * + * The backlog argument defines the maximum length to which the queue of + * pending connections for epd may grow. If a connection request arrives when + * the queue is full, the client may receive an error with an indication that + * the connection was refused. + * + * Return: + * Upon successful completion, scif_listen() returns 0; otherwise in user mode + * -1 is returned and errno is set to indicate the error; in kernel mode the + * negative of one of the following errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * EINVAL - the endpoint is not bound to a port + * EISCONN - The endpoint is already connected or listening + */ +int scif_listen(scif_epd_t epd, int backlog); + +/** + * scif_connect() - Initiate a connection on a port + * @epd: endpoint descriptor + * @dst: global id of port to which to connect + * + * The scif_connect() function requests the connection of endpoint epd to remote + * port dst. If the connection is successful, a peer endpoint, bound to dst, is + * created on node dst.node. On successful return, the connection is complete. + * + * If the endpoint epd has not already been bound to a port, scif_connect() + * will bind it to an unused local port. + * + * A connection is terminated when an endpoint of the connection is closed, + * either explicitly by scif_close(), or when a process that owns one of the + * endpoints of the connection is terminated. + * + * In user space, scif_connect() supports an asynchronous connection mode + * if the application has set the O_NONBLOCK flag on the endpoint via the + * fcntl() system call. Setting this flag will result in the calling process + * not to wait during scif_connect(). + * + * Return: + * Upon successful completion, scif_connect() returns the port ID to which the + * endpoint, epd, is bound; otherwise in user mode -1 is returned and errno is + * set to indicate the error; in kernel mode the negative of one of the + * following errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNREFUSED - The destination was not listening for connections or refused + * the connection request + * EINVAL - dst.port is not a valid port ID + * EISCONN - The endpoint is already connected + * ENOMEM - No buffer space is available + * ENODEV - The destination node does not exist, or the node is lost or existed, + * but is not currently in the network since it may have crashed + * ENOSPC - No port number available for assignment + * EOPNOTSUPP - The endpoint is listening and cannot be connected + */ +int scif_connect(scif_epd_t epd, struct scif_port_id *dst); + +/** + * scif_accept() - Accept a connection on an endpoint + * @epd: endpoint descriptor + * @peer: global id of port to which connected + * @newepd: new connected endpoint descriptor + * @flags: flags + * + * The scif_accept() call extracts the first connection request from the queue + * of pending connections for the port on which epd is listening. scif_accept() + * creates a new endpoint, bound to the same port as epd, and allocates a new + * SCIF endpoint descriptor, returned in newepd, for the endpoint. The new + * endpoint is connected to the endpoint through which the connection was + * requested. epd is unaffected by this call, and remains in the listening + * state. + * + * On successful return, peer holds the global port identifier (node id and + * local port number) of the port which requested the connection. + * + * A connection is terminated when an endpoint of the connection is closed, + * either explicitly by scif_close(), or when a process that owns one of the + * endpoints of the connection is terminated. + * + * The number of connections that can (subsequently) be accepted on epd is only + * limited by system resources (memory). + * + * The flags argument is formed by OR'ing together zero or more of the + * following values. + * SCIF_ACCEPT_SYNC - block until a connection request is presented. If + * SCIF_ACCEPT_SYNC is not in flags, and no pending + * connections are present on the queue, scif_accept() + * fails with an EAGAIN error + * + * In user mode, the select() and poll() functions can be used to determine + * when there is a connection request. In kernel mode, the scif_poll() + * function may be used for this purpose. A readable event will be delivered + * when a connection is requested. + * + * Return: + * Upon successful completion, scif_accept() returns 0; otherwise in user mode + * -1 is returned and errno is set to indicate the error; in kernel mode the + * negative of one of the following errors is returned. + * + * Errors: + * EAGAIN - SCIF_ACCEPT_SYNC is not set and no connections are present to be + * accepted or SCIF_ACCEPT_SYNC is not set and remote node failed to complete + * its connection request + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * EINTR - Interrupted function + * EINVAL - epd is not a listening endpoint, or flags is invalid, or peer is + * NULL, or newepd is NULL + * ENODEV - The requesting node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOMEM - Not enough space + * ENOENT - Secondary part of epd registration failed + */ +int scif_accept(scif_epd_t epd, struct scif_port_id *peer, scif_epd_t + *newepd, int flags); + +/** + * scif_close() - Close an endpoint + * @epd: endpoint descriptor + * + * scif_close() closes an endpoint and performs necessary teardown of + * facilities associated with that endpoint. + * + * If epd is a listening endpoint then it will no longer accept connection + * requests on the port to which it is bound. Any pending connection requests + * are rejected. + * + * If epd is a connected endpoint, then its peer endpoint is also closed. RMAs + * which are in-process through epd or its peer endpoint will complete before + * scif_close() returns. Registered windows of the local and peer endpoints are + * released as if scif_unregister() was called against each window. + * + * Closing a SCIF endpoint does not affect local registered memory mapped by + * a SCIF endpoint on a remote node. The local memory remains mapped by the peer + * SCIF endpoint explicitly removed by calling munmap(..) by the peer. + * + * If the peer endpoint's receive queue is not empty at the time that epd is + * closed, then the peer endpoint can be passed as the endpoint parameter to + * scif_recv() until the receive queue is empty. + * + * epd is freed and may no longer be accessed. + * + * Return: + * Upon successful completion, scif_close() returns 0; otherwise in user mode + * -1 is returned and errno is set to indicate the error; in kernel mode the + * negative of one of the following errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + */ +int scif_close(scif_epd_t epd); + +/** + * scif_send() - Send a message + * @epd: endpoint descriptor + * @msg: message buffer address + * @len: message length + * @flags: blocking mode flags + * + * scif_send() sends data to the peer of endpoint epd. Up to len bytes of data + * are copied from memory starting at address msg. On successful execution the + * return value of scif_send() is the number of bytes that were sent, and is + * zero if no bytes were sent because len was zero. scif_send() may be called + * only when the endpoint is in a connected state. + * + * If a scif_send() call is non-blocking, then it sends only those bytes which + * can be sent without waiting, up to a maximum of len bytes. + * + * If a scif_send() call is blocking, then it normally returns after sending + * all len bytes. If a blocking call is interrupted or the connection is + * reset, the call is considered successful if some bytes were sent or len is + * zero, otherwise the call is considered unsuccessful. + * + * In user mode, the select() and poll() functions can be used to determine + * when the send queue is not full. In kernel mode, the scif_poll() function + * may be used for this purpose. + * + * It is recommended that scif_send()/scif_recv() only be used for short + * control-type message communication between SCIF endpoints. The SCIF RMA + * APIs are expected to provide better performance for transfer sizes of + * 1024 bytes or longer for the current MIC hardware and software + * implementation. + * + * scif_send() will block until the entire message is sent if SCIF_SEND_BLOCK + * is passed as the flags argument. + * + * Return: + * Upon successful completion, scif_send() returns the number of bytes sent; + * otherwise in user mode -1 is returned and errno is set to indicate the + * error; in kernel mode the negative of one of the following errors is + * returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EFAULT - An invalid address was specified for a parameter + * EINVAL - flags is invalid, or len is negative + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOMEM - Not enough space + * ENOTCONN - The endpoint is not connected + */ +int scif_send(scif_epd_t epd, void *msg, int len, int flags); + +/** + * scif_recv() - Receive a message + * @epd: endpoint descriptor + * @msg: message buffer address + * @len: message buffer length + * @flags: blocking mode flags + * + * scif_recv() receives data from the peer of endpoint epd. Up to len bytes of + * data are copied to memory starting at address msg. On successful execution + * the return value of scif_recv() is the number of bytes that were received, + * and is zero if no bytes were received because len was zero. scif_recv() may + * be called only when the endpoint is in a connected state. + * + * If a scif_recv() call is non-blocking, then it receives only those bytes + * which can be received without waiting, up to a maximum of len bytes. + * + * If a scif_recv() call is blocking, then it normally returns after receiving + * all len bytes. If the blocking call was interrupted due to a disconnection, + * subsequent calls to scif_recv() will copy all bytes received upto the point + * of disconnection. + * + * In user mode, the select() and poll() functions can be used to determine + * when data is available to be received. In kernel mode, the scif_poll() + * function may be used for this purpose. + * + * It is recommended that scif_send()/scif_recv() only be used for short + * control-type message communication between SCIF endpoints. The SCIF RMA + * APIs are expected to provide better performance for transfer sizes of + * 1024 bytes or longer for the current MIC hardware and software + * implementation. + * + * scif_recv() will block until the entire message is received if + * SCIF_RECV_BLOCK is passed as the flags argument. + * + * Return: + * Upon successful completion, scif_recv() returns the number of bytes + * received; otherwise in user mode -1 is returned and errno is set to + * indicate the error; in kernel mode the negative of one of the following + * errors is returned. + * + * Errors: + * EAGAIN - The destination node is returning from a low power state + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EFAULT - An invalid address was specified for a parameter + * EINVAL - flags is invalid, or len is negative + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOMEM - Not enough space + * ENOTCONN - The endpoint is not connected + */ +int scif_recv(scif_epd_t epd, void *msg, int len, int flags); + +/** + * scif_register() - Mark a memory region for remote access. + * @epd: endpoint descriptor + * @addr: starting virtual address + * @len: length of range + * @offset: offset of window + * @prot_flags: read/write protection flags + * @map_flags: mapping flags + * + * The scif_register() function opens a window, a range of whole pages of the + * registered address space of the endpoint epd, starting at offset po and + * continuing for len bytes. The value of po, further described below, is a + * function of the parameters offset and len, and the value of map_flags. Each + * page of the window represents the physical memory page which backs the + * corresponding page of the range of virtual address pages starting at addr + * and continuing for len bytes. addr and len are constrained to be multiples + * of the page size. A successful scif_register() call returns po. + * + * When SCIF_MAP_FIXED is set in the map_flags argument, po will be offset + * exactly, and offset is constrained to be a multiple of the page size. The + * mapping established by scif_register() will not replace any existing + * registration; an error is returned if any page within the range [offset, + * offset + len - 1] intersects an existing window. + * + * When SCIF_MAP_FIXED is not set, the implementation uses offset in an + * implementation-defined manner to arrive at po. The po value so chosen will + * be an area of the registered address space that the implementation deems + * suitable for a mapping of len bytes. An offset value of 0 is interpreted as + * granting the implementation complete freedom in selecting po, subject to + * constraints described below. A non-zero value of offset is taken to be a + * suggestion of an offset near which the mapping should be placed. When the + * implementation selects a value for po, it does not replace any extant + * window. In all cases, po will be a multiple of the page size. + * + * The physical pages which are so represented by a window are available for + * access in calls to mmap(), scif_readfrom(), scif_writeto(), + * scif_vreadfrom(), and scif_vwriteto(). While a window is registered, the + * physical pages represented by the window will not be reused by the memory + * subsystem for any other purpose. Note that the same physical page may be + * represented by multiple windows. + * + * Subsequent operations which change the memory pages to which virtual + * addresses are mapped (such as mmap(), munmap()) have no effect on + * existing window. + * + * If the process will fork(), it is recommended that the registered + * virtual address range be marked with MADV_DONTFORK. Doing so will prevent + * problems due to copy-on-write semantics. + * + * The prot_flags argument is formed by OR'ing together one or more of the + * following values. + * SCIF_PROT_READ - allow read operations from the window + * SCIF_PROT_WRITE - allow write operations to the window + * + * The map_flags argument can be set to SCIF_MAP_FIXED which interprets a + * fixed offset. + * + * Return: + * Upon successful completion, scif_register() returns the offset at which the + * mapping was placed (po); otherwise in user mode SCIF_REGISTER_FAILED (that + * is (off_t *)-1) is returned and errno is set to indicate the error; in + * kernel mode the negative of one of the following errors is returned. + * + * Errors: + * EADDRINUSE - SCIF_MAP_FIXED is set in map_flags, and pages in the range + * [offset, offset + len -1] are already registered + * EAGAIN - The mapping could not be performed due to lack of resources + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EFAULT - Addresses in the range [addr, addr + len - 1] are invalid + * EINVAL - map_flags is invalid, or prot_flags is invalid, or SCIF_MAP_FIXED is + * set in flags, and offset is not a multiple of the page size, or addr is not a + * multiple of the page size, or len is not a multiple of the page size, or is + * 0, or offset is negative + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOMEM - Not enough space + * ENOTCONN -The endpoint is not connected + */ +off_t scif_register(scif_epd_t epd, void *addr, size_t len, off_t offset, + int prot_flags, int map_flags); + +/** + * scif_unregister() - Mark a memory region for remote access. + * @epd: endpoint descriptor + * @offset: start of range to unregister + * @len: length of range to unregister + * + * The scif_unregister() function closes those previously registered windows + * which are entirely within the range [offset, offset + len - 1]. It is an + * error to specify a range which intersects only a subrange of a window. + * + * On a successful return, pages within the window may no longer be specified + * in calls to mmap(), scif_readfrom(), scif_writeto(), scif_vreadfrom(), + * scif_vwriteto(), scif_get_pages, and scif_fence_signal(). The window, + * however, continues to exist until all previous references against it are + * removed. A window is referenced if there is a mapping to it created by + * mmap(), or if scif_get_pages() was called against the window + * (and the pages have not been returned via scif_put_pages()). A window is + * also referenced while an RMA, in which some range of the window is a source + * or destination, is in progress. Finally a window is referenced while some + * offset in that window was specified to scif_fence_signal(), and the RMAs + * marked by that call to scif_fence_signal() have not completed. While a + * window is in this state, its registered address space pages are not + * available for use in a new registered window. + * + * When all such references to the window have been removed, its references to + * all the physical pages which it represents are removed. Similarly, the + * registered address space pages of the window become available for + * registration in a new window. + * + * Return: + * Upon successful completion, scif_unregister() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. In the event of an + * error, no windows are unregistered. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EINVAL - the range [offset, offset + len - 1] intersects a subrange of a + * window, or offset is negative + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENXIO - Offsets in the range [offset, offset + len - 1] are invalid for the + * registered address space of epd + */ +int scif_unregister(scif_epd_t epd, off_t offset, size_t len); + +/** + * scif_readfrom() - Copy from a remote address space + * @epd: endpoint descriptor + * @loffset: offset in local registered address space to + * which to copy + * @len: length of range to copy + * @roffset: offset in remote registered address space + * from which to copy + * @rma_flags: transfer mode flags + * + * scif_readfrom() copies len bytes from the remote registered address space of + * the peer of endpoint epd, starting at the offset roffset to the local + * registered address space of epd, starting at the offset loffset. + * + * Each of the specified ranges [loffset, loffset + len - 1] and [roffset, + * roffset + len - 1] must be within some registered window or windows of the + * local and remote nodes. A range may intersect multiple registered windows, + * but only if those windows are contiguous in the registered address space. + * + * If rma_flags includes SCIF_RMA_USECPU, then the data is copied using + * programmed read/writes. Otherwise the data is copied using DMA. If rma_- + * flags includes SCIF_RMA_SYNC, then scif_readfrom() will return after the + * transfer is complete. Otherwise, the transfer may be performed asynchron- + * ously. The order in which any two asynchronous RMA operations complete + * is non-deterministic. The synchronization functions, scif_fence_mark()/ + * scif_fence_wait() and scif_fence_signal(), can be used to synchronize to + * the completion of asynchronous RMA operations on the same endpoint. + * + * The DMA transfer of individual bytes is not guaranteed to complete in + * address order. If rma_flags includes SCIF_RMA_ORDERED, then the last + * cacheline or partial cacheline of the source range will become visible on + * the destination node after all other transferred data in the source + * range has become visible on the destination node. + * + * The optimal DMA performance will likely be realized if both + * loffset and roffset are cacheline aligned (are a multiple of 64). Lower + * performance will likely be realized if loffset and roffset are not + * cacheline aligned but are separated by some multiple of 64. The lowest level + * of performance is likely if loffset and roffset are not separated by a + * multiple of 64. + * + * The rma_flags argument is formed by ORing together zero or more of the + * following values. + * SCIF_RMA_USECPU - perform the transfer using the CPU, otherwise use the DMA + * engine. + * SCIF_RMA_SYNC - perform the transfer synchronously, returning after the + * transfer has completed. Passing this flag results in the + * current implementation busy waiting and consuming CPU cycles + * while the DMA transfer is in progress for best performance by + * avoiding the interrupt latency. + * SCIF_RMA_ORDERED - ensure that the last cacheline or partial cacheline of + * the source range becomes visible on the destination node + * after all other transferred data in the source range has + * become visible on the destination + * + * Return: + * Upon successful completion, scif_readfrom() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. + * + * Errors: + * EACCESS - Attempt to write to a read-only range + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EINVAL - rma_flags is invalid + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENXIO - The range [loffset, loffset + len - 1] is invalid for the registered + * address space of epd, or, The range [roffset, roffset + len - 1] is invalid + * for the registered address space of the peer of epd, or loffset or roffset + * is negative + */ +int scif_readfrom(scif_epd_t epd, off_t loffset, size_t len, off_t + roffset, int rma_flags); + +/** + * scif_writeto() - Copy to a remote address space + * @epd: endpoint descriptor + * @loffset: offset in local registered address space + * from which to copy + * @len: length of range to copy + * @roffset: offset in remote registered address space to + * which to copy + * @rma_flags: transfer mode flags + * + * scif_writeto() copies len bytes from the local registered address space of + * epd, starting at the offset loffset to the remote registered address space + * of the peer of endpoint epd, starting at the offset roffset. + * + * Each of the specified ranges [loffset, loffset + len - 1] and [roffset, + * roffset + len - 1] must be within some registered window or windows of the + * local and remote nodes. A range may intersect multiple registered windows, + * but only if those windows are contiguous in the registered address space. + * + * If rma_flags includes SCIF_RMA_USECPU, then the data is copied using + * programmed read/writes. Otherwise the data is copied using DMA. If rma_- + * flags includes SCIF_RMA_SYNC, then scif_writeto() will return after the + * transfer is complete. Otherwise, the transfer may be performed asynchron- + * ously. The order in which any two asynchronous RMA operations complete + * is non-deterministic. The synchronization functions, scif_fence_mark()/ + * scif_fence_wait() and scif_fence_signal(), can be used to synchronize to + * the completion of asynchronous RMA operations on the same endpoint. + * + * The DMA transfer of individual bytes is not guaranteed to complete in + * address order. If rma_flags includes SCIF_RMA_ORDERED, then the last + * cacheline or partial cacheline of the source range will become visible on + * the destination node after all other transferred data in the source + * range has become visible on the destination node. + * + * The optimal DMA performance will likely be realized if both + * loffset and roffset are cacheline aligned (are a multiple of 64). Lower + * performance will likely be realized if loffset and roffset are not cacheline + * aligned but are separated by some multiple of 64. The lowest level of + * performance is likely if loffset and roffset are not separated by a multiple + * of 64. + * + * The rma_flags argument is formed by ORing together zero or more of the + * following values. + * SCIF_RMA_USECPU - perform the transfer using the CPU, otherwise use the DMA + * engine. + * SCIF_RMA_SYNC - perform the transfer synchronously, returning after the + * transfer has completed. Passing this flag results in the + * current implementation busy waiting and consuming CPU cycles + * while the DMA transfer is in progress for best performance by + * avoiding the interrupt latency. + * SCIF_RMA_ORDERED - ensure that the last cacheline or partial cacheline of + * the source range becomes visible on the destination node + * after all other transferred data in the source range has + * become visible on the destination + * + * Return: + * Upon successful completion, scif_readfrom() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. + * + * Errors: + * EACCESS - Attempt to write to a read-only range + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EINVAL - rma_flags is invalid + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENXIO - The range [loffset, loffset + len - 1] is invalid for the registered + * address space of epd, or, The range [roffset , roffset + len -1] is invalid + * for the registered address space of the peer of epd, or loffset or roffset + * is negative + */ +int scif_writeto(scif_epd_t epd, off_t loffset, size_t len, off_t + roffset, int rma_flags); + +/** + * scif_vreadfrom() - Copy from a remote address space + * @epd: endpoint descriptor + * @addr: address to which to copy + * @len: length of range to copy + * @roffset: offset in remote registered address space + * from which to copy + * @rma_flags: transfer mode flags + * + * scif_vreadfrom() copies len bytes from the remote registered address + * space of the peer of endpoint epd, starting at the offset roffset, to local + * memory, starting at addr. + * + * The specified range [roffset, roffset + len - 1] must be within some + * registered window or windows of the remote nodes. The range may + * intersect multiple registered windows, but only if those windows are + * contiguous in the registered address space. + * + * If rma_flags includes SCIF_RMA_USECPU, then the data is copied using + * programmed read/writes. Otherwise the data is copied using DMA. If rma_- + * flags includes SCIF_RMA_SYNC, then scif_vreadfrom() will return after the + * transfer is complete. Otherwise, the transfer may be performed asynchron- + * ously. The order in which any two asynchronous RMA operations complete + * is non-deterministic. The synchronization functions, scif_fence_mark()/ + * scif_fence_wait() and scif_fence_signal(), can be used to synchronize to + * the completion of asynchronous RMA operations on the same endpoint. + * + * The DMA transfer of individual bytes is not guaranteed to complete in + * address order. If rma_flags includes SCIF_RMA_ORDERED, then the last + * cacheline or partial cacheline of the source range will become visible on + * the destination node after all other transferred data in the source + * range has become visible on the destination node. + * + * If rma_flags includes SCIF_RMA_USECACHE, then the physical pages which back + * the specified local memory range may be remain in a pinned state even after + * the specified transfer completes. This may reduce overhead if some or all of + * the same virtual address range is referenced in a subsequent call of + * scif_vreadfrom() or scif_vwriteto(). + * + * The optimal DMA performance will likely be realized if both + * addr and roffset are cacheline aligned (are a multiple of 64). Lower + * performance will likely be realized if addr and roffset are not + * cacheline aligned but are separated by some multiple of 64. The lowest level + * of performance is likely if addr and roffset are not separated by a + * multiple of 64. + * + * The rma_flags argument is formed by ORing together zero or more of the + * following values. + * SCIF_RMA_USECPU - perform the transfer using the CPU, otherwise use the DMA + * engine. + * SCIF_RMA_USECACHE - enable registration caching + * SCIF_RMA_SYNC - perform the transfer synchronously, returning after the + * transfer has completed. Passing this flag results in the + * current implementation busy waiting and consuming CPU cycles + * while the DMA transfer is in progress for best performance by + * avoiding the interrupt latency. + * SCIF_RMA_ORDERED - ensure that the last cacheline or partial cacheline of + * the source range becomes visible on the destination node + * after all other transferred data in the source range has + * become visible on the destination + * + * Return: + * Upon successful completion, scif_vreadfrom() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. + * + * Errors: + * EACCESS - Attempt to write to a read-only range + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EFAULT - Addresses in the range [addr, addr + len - 1] are invalid + * EINVAL - rma_flags is invalid + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENXIO - Offsets in the range [roffset, roffset + len - 1] are invalid for the + * registered address space of epd + */ +int scif_vreadfrom(scif_epd_t epd, void *addr, size_t len, off_t roffset, + int rma_flags); + +/** + * scif_vwriteto() - Copy to a remote address space + * @epd: endpoint descriptor + * @addr: address from which to copy + * @len: length of range to copy + * @roffset: offset in remote registered address space to + * which to copy + * @rma_flags: transfer mode flags + * + * scif_vwriteto() copies len bytes from the local memory, starting at addr, to + * the remote registered address space of the peer of endpoint epd, starting at + * the offset roffset. + * + * The specified range [roffset, roffset + len - 1] must be within some + * registered window or windows of the remote nodes. The range may intersect + * multiple registered windows, but only if those windows are contiguous in the + * registered address space. + * + * If rma_flags includes SCIF_RMA_USECPU, then the data is copied using + * programmed read/writes. Otherwise the data is copied using DMA. If rma_- + * flags includes SCIF_RMA_SYNC, then scif_vwriteto() will return after the + * transfer is complete. Otherwise, the transfer may be performed asynchron- + * ously. The order in which any two asynchronous RMA operations complete + * is non-deterministic. The synchronization functions, scif_fence_mark()/ + * scif_fence_wait() and scif_fence_signal(), can be used to synchronize to + * the completion of asynchronous RMA operations on the same endpoint. + * + * The DMA transfer of individual bytes is not guaranteed to complete in + * address order. If rma_flags includes SCIF_RMA_ORDERED, then the last + * cacheline or partial cacheline of the source range will become visible on + * the destination node after all other transferred data in the source + * range has become visible on the destination node. + * + * If rma_flags includes SCIF_RMA_USECACHE, then the physical pages which back + * the specified local memory range may be remain in a pinned state even after + * the specified transfer completes. This may reduce overhead if some or all of + * the same virtual address range is referenced in a subsequent call of + * scif_vreadfrom() or scif_vwriteto(). + * + * The optimal DMA performance will likely be realized if both + * addr and offset are cacheline aligned (are a multiple of 64). Lower + * performance will likely be realized if addr and offset are not cacheline + * aligned but are separated by some multiple of 64. The lowest level of + * performance is likely if addr and offset are not separated by a multiple of + * 64. + * + * The rma_flags argument is formed by ORing together zero or more of the + * following values. + * SCIF_RMA_USECPU - perform the transfer using the CPU, otherwise use the DMA + * engine. + * SCIF_RMA_USECACHE - allow registration caching + * SCIF_RMA_SYNC - perform the transfer synchronously, returning after the + * transfer has completed. Passing this flag results in the + * current implementation busy waiting and consuming CPU cycles + * while the DMA transfer is in progress for best performance by + * avoiding the interrupt latency. + * SCIF_RMA_ORDERED - ensure that the last cacheline or partial cacheline of + * the source range becomes visible on the destination node + * after all other transferred data in the source range has + * become visible on the destination + * + * Return: + * Upon successful completion, scif_vwriteto() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. + * + * Errors: + * EACCESS - Attempt to write to a read-only range + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EFAULT - Addresses in the range [addr, addr + len - 1] are invalid + * EINVAL - rma_flags is invalid + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENXIO - Offsets in the range [roffset, roffset + len - 1] are invalid for the + * registered address space of epd + */ +int scif_vwriteto(scif_epd_t epd, void *addr, size_t len, off_t roffset, + int rma_flags); + +/** + * scif_fence_mark() - Mark previously issued RMAs + * @epd: endpoint descriptor + * @flags: control flags + * @mark: marked value returned as output. + * + * scif_fence_mark() returns after marking the current set of all uncompleted + * RMAs initiated through the endpoint epd or the current set of all + * uncompleted RMAs initiated through the peer of endpoint epd. The RMAs are + * marked with a value returned at mark. The application may subsequently call + * scif_fence_wait(), passing the value returned at mark, to await completion + * of all RMAs so marked. + * + * The flags argument has exactly one of the following values. + * SCIF_FENCE_INIT_SELF - RMA operations initiated through endpoint + * epd are marked + * SCIF_FENCE_INIT_PEER - RMA operations initiated through the peer + * of endpoint epd are marked + * + * Return: + * Upon successful completion, scif_fence_mark() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EINVAL - flags is invalid + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENOMEM - Insufficient kernel memory was available + */ +int scif_fence_mark(scif_epd_t epd, int flags, int *mark); + +/** + * scif_fence_wait() - Wait for completion of marked RMAs + * @epd: endpoint descriptor + * @mark: mark request + * + * scif_fence_wait() returns after all RMAs marked with mark have completed. + * The value passed in mark must have been obtained in a previous call to + * scif_fence_mark(). + * + * Return: + * Upon successful completion, scif_fence_wait() returns 0; otherwise in user + * mode -1 is returned and errno is set to indicate the error; in kernel mode + * the negative of one of the following errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENOMEM - Insufficient kernel memory was available + */ +int scif_fence_wait(scif_epd_t epd, int mark); + +/** + * scif_fence_signal() - Request a memory update on completion of RMAs + * @epd: endpoint descriptor + * @loff: local offset + * @lval: local value to write to loffset + * @roff: remote offset + * @rval: remote value to write to roffset + * @flags: flags + * + * scif_fence_signal() returns after marking the current set of all uncompleted + * RMAs initiated through the endpoint epd or marking the current set of all + * uncompleted RMAs initiated through the peer of endpoint epd. + * + * If flags includes SCIF_SIGNAL_LOCAL, then on completion of the RMAs in the + * marked set, lval is written to memory at the address corresponding to offset + * loff in the local registered address space of epd. loff must be within a + * registered window. If flags includes SCIF_SIGNAL_REMOTE, then on completion + * of the RMAs in the marked set, rval is written to memory at the address + * corresponding to offset roff in the remote registered address space of epd. + * roff must be within a remote registered window of the peer of epd. Note + * that any specified offset must be DWORD (4 byte / 32 bit) aligned. + * + * The flags argument is formed by OR'ing together the following. + * Exactly one of the following values. + * SCIF_FENCE_INIT_SELF - RMA operations initiated through endpoint + * epd are marked + * SCIF_FENCE_INIT_PEER - RMA operations initiated through the peer + * of endpoint epd are marked + * One or more of the following values. + * SCIF_SIGNAL_LOCAL - On completion of the marked set of RMAs, write lval to + * memory at the address corresponding to offset loff in the local + * registered address space of epd. + * SCIF_SIGNAL_REMOTE - On completion of the marked set of RMAs, write rval to + * memory at the address corresponding to offset roff in the remote + * registered address space of epd. + * + * Return: + * Upon successful completion, scif_fence_signal() returns 0; otherwise in + * user mode -1 is returned and errno is set to indicate the error; in kernel + * mode the negative of one of the following errors is returned. + * + * Errors: + * EBADF, ENOTTY - epd is not a valid endpoint descriptor + * ECONNRESET - Connection reset by peer + * EINVAL - flags is invalid, or loff or roff are not DWORD aligned + * ENODEV - The remote node is lost or existed, but is not currently in the + * network since it may have crashed + * ENOTCONN - The endpoint is not connected + * ENXIO - loff is invalid for the registered address of epd, or roff is invalid + * for the registered address space, of the peer of epd + */ +int scif_fence_signal(scif_epd_t epd, off_t loff, u64 lval, off_t roff, + u64 rval, int flags); + +/** + * scif_get_node_ids() - Return information about online nodes + * @nodes: array in which to return online node IDs + * @len: number of entries in the nodes array + * @self: address to place the node ID of the local node + * + * scif_get_node_ids() fills in the nodes array with up to len node IDs of the + * nodes in the SCIF network. If there is not enough space in nodes, as + * indicated by the len parameter, only len node IDs are returned in nodes. The + * return value of scif_get_node_ids() is the total number of nodes currently in + * the SCIF network. By checking the return value against the len parameter, + * the user may determine if enough space for nodes was allocated. + * + * The node ID of the local node is returned at self. + * + * Return: + * Upon successful completion, scif_get_node_ids() returns the actual number of + * online nodes in the SCIF network including 'self'; otherwise in user mode + * -1 is returned and errno is set to indicate the error; in kernel mode no + * errors are returned. + * + * Errors: + * EFAULT - Bad address + */ +int scif_get_node_ids(u16 *nodes, int len, u16 *self); + +#endif /* __SCIF_H__ */ diff --git a/include/uapi/linux/Kbuild b/include/uapi/linux/Kbuild index 1a0006a76b00..4ad65eebbff8 100644 --- a/include/uapi/linux/Kbuild +++ b/include/uapi/linux/Kbuild @@ -352,6 +352,7 @@ header-y += rtc.h header-y += rtnetlink.h header-y += scc.h header-y += sched.h +header-y += scif_ioctl.h header-y += screen_info.h header-y += sctp.h header-y += sdla.h diff --git a/include/uapi/linux/scif_ioctl.h b/include/uapi/linux/scif_ioctl.h new file mode 100644 index 000000000000..4a94d917cf99 --- /dev/null +++ b/include/uapi/linux/scif_ioctl.h @@ -0,0 +1,130 @@ +/* + * Intel MIC Platform Software Stack (MPSS) + * + * This file is provided under a dual BSD/GPLv2 license. When using or + * redistributing this file, you may do so under either license. + * + * GPL LICENSE SUMMARY + * + * Copyright(c) 2014 Intel Corporation. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of version 2 of the GNU General Public License as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that 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. + * + * BSD LICENSE + * + * Copyright(c) 2014 Intel Corporation. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Intel SCIF driver. + * + */ +/* + * ----------------------------------------- + * SCIF IOCTL interface information + * ----------------------------------------- + */ +#ifndef SCIF_IOCTL_H +#define SCIF_IOCTL_H + +#include + +/** + * struct scif_port_id - SCIF port information + * @node: node on which port resides + * @port: local port number + */ +struct scif_port_id { + __u16 node; + __u16 port; +}; + +/** + * struct scifioctl_connect - used for SCIF_CONNECT IOCTL + * @self: used to read back the assigned port_id + * @peer: destination node and port to connect to + */ +struct scifioctl_connect { + struct scif_port_id self; + struct scif_port_id peer; +}; + +/** + * struct scifioctl_accept - used for SCIF_ACCEPTREQ IOCTL + * @flags: flags + * @peer: global id of peer endpoint + * @endpt: new connected endpoint descriptor + */ +struct scifioctl_accept { + __s32 flags; + struct scif_port_id peer; + __u64 endpt; +}; + +/** + * struct scifioctl_msg - used for SCIF_SEND/SCIF_RECV IOCTL + * @msg: message buffer address + * @len: message length + * @flags: flags + * @out_len: number of bytes sent/received + */ +struct scifioctl_msg { + __u64 msg; + __s32 len; + __s32 flags; + __s32 out_len; +}; + +/** + * struct scifioctl_node_ids - used for SCIF_GET_NODEIDS IOCTL + * @nodes: pointer to an array of node_ids + * @self: ID of the current node + * @len: length of array + */ +struct scifioctl_node_ids { + __u64 nodes; + __u64 self; + __s32 len; +}; + +#define SCIF_BIND _IOWR('s', 1, __u64) +#define SCIF_LISTEN _IOW('s', 2, __s32) +#define SCIF_CONNECT _IOWR('s', 3, struct scifioctl_connect) +#define SCIF_ACCEPTREQ _IOWR('s', 4, struct scifioctl_accept) +#define SCIF_ACCEPTREG _IOWR('s', 5, __u64) +#define SCIF_SEND _IOWR('s', 6, struct scifioctl_msg) +#define SCIF_RECV _IOWR('s', 7, struct scifioctl_msg) +#define SCIF_GET_NODEIDS _IOWR('s', 14, struct scifioctl_node_ids) + +#endif /* SCIF_IOCTL_H */ -- cgit v1.2.3-59-g8ed1b From c9d5c53db959e587d8b59c6a202e2dca741baac4 Mon Sep 17 00:00:00 2001 From: Sudeep Dutt Date: Wed, 29 Apr 2015 05:32:32 -0700 Subject: misc: mic: Common MIC header file changes in preparation for SCIF Update mic_bootparam and define the maximum number of DMA channels Reviewed-by: Nikhil Rao Reviewed-by: Ashutosh Dixit Signed-off-by: Sudeep Dutt Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mic/common/mic_dev.h | 3 +++ include/uapi/linux/mic_common.h | 12 ++++++++++++ 2 files changed, 15 insertions(+) (limited to 'include') diff --git a/drivers/misc/mic/common/mic_dev.h b/drivers/misc/mic/common/mic_dev.h index 92999c2bbf82..0b58c46045dc 100644 --- a/drivers/misc/mic/common/mic_dev.h +++ b/drivers/misc/mic/common/mic_dev.h @@ -48,4 +48,7 @@ struct mic_mw { #define MIC_VIRTIO_PARAM_DEV_REMOVE 0x1 #define MIC_VIRTIO_PARAM_CONFIG_CHANGED 0x2 +/* Maximum number of DMA channels */ +#define MIC_MAX_DMA_CHAN 4 + #endif diff --git a/include/uapi/linux/mic_common.h b/include/uapi/linux/mic_common.h index 6eb40244e019..302a2ced373c 100644 --- a/include/uapi/linux/mic_common.h +++ b/include/uapi/linux/mic_common.h @@ -80,6 +80,12 @@ struct mic_device_ctrl { * @h2c_config_db: Host to Card Virtio config doorbell set by card * @shutdown_status: Card shutdown status set by card * @shutdown_card: Set to 1 by the host when a card shutdown is initiated + * @tot_nodes: Total number of nodes in the SCIF network + * @node_id: Unique id of the node + * @h2c_scif_db - Host to card SCIF doorbell set by card + * @c2h_scif_db - Card to host SCIF doorbell set by host + * @scif_host_dma_addr - SCIF host queue pair DMA address + * @scif_card_dma_addr - SCIF card queue pair DMA address */ struct mic_bootparam { __le32 magic; @@ -88,6 +94,12 @@ struct mic_bootparam { __s8 h2c_config_db; __u8 shutdown_status; __u8 shutdown_card; + __u8 tot_nodes; + __u8 node_id; + __u8 h2c_scif_db; + __u8 c2h_scif_db; + __u64 scif_host_dma_addr; + __u64 scif_card_dma_addr; } __attribute__ ((aligned(8))); /** -- cgit v1.2.3-59-g8ed1b From 3647a83d9dcf00b8e17777ec8aa1e48f1ed4fe06 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sat, 11 Apr 2015 18:07:39 -0700 Subject: Drivers: hv: util: move kvp/vss function declarations to hyperv_vmbus.h These declarations are internal to hv_util module and hv_fcopy_* declarations already reside there. Signed-off-by: Vitaly Kuznetsov Tested-by: Alex Ng Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/hv_kvp.c | 1 + drivers/hv/hv_snapshot.c | 2 ++ drivers/hv/hyperv_vmbus.h | 8 ++++++++ include/linux/hyperv.h | 7 ------- 4 files changed, 11 insertions(+), 7 deletions(-) (limited to 'include') diff --git a/drivers/hv/hv_kvp.c b/drivers/hv/hv_kvp.c index beb8105c0e7b..a414c8397f88 100644 --- a/drivers/hv/hv_kvp.c +++ b/drivers/hv/hv_kvp.c @@ -28,6 +28,7 @@ #include #include +#include "hyperv_vmbus.h" /* * Pre win8 version numbers used in ws2008 and ws 2008 r2 (win7) diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c index 9d5e0d1efdb5..c1a3604c261c 100644 --- a/drivers/hv/hv_snapshot.c +++ b/drivers/hv/hv_snapshot.c @@ -24,6 +24,8 @@ #include #include +#include "hyperv_vmbus.h" + #define VSS_MAJOR 5 #define VSS_MINOR 0 #define VSS_VERSION (VSS_MAJOR << 16 | VSS_MINOR) diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 887287ad411f..ddcf6c405195 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -730,6 +730,14 @@ int vmbus_set_event(struct vmbus_channel *channel); void vmbus_on_event(unsigned long data); +int hv_kvp_init(struct hv_util_service *); +void hv_kvp_deinit(void); +void hv_kvp_onchannelcallback(void *); + +int hv_vss_init(struct hv_util_service *); +void hv_vss_deinit(void); +void hv_vss_onchannelcallback(void *); + int hv_fcopy_init(struct hv_util_service *); void hv_fcopy_deinit(void); void hv_fcopy_onchannelcallback(void *); diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 902c37aef67e..1744148a39f9 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -1236,13 +1236,6 @@ extern bool vmbus_prep_negotiate_resp(struct icmsg_hdr *, struct icmsg_negotiate *, u8 *, int, int); -int hv_kvp_init(struct hv_util_service *); -void hv_kvp_deinit(void); -void hv_kvp_onchannelcallback(void *); - -int hv_vss_init(struct hv_util_service *); -void hv_vss_deinit(void); -void hv_vss_onchannelcallback(void *); void hv_process_channel_removal(struct vmbus_channel *channel, u32 relid); extern struct resource hyperv_mmio; -- cgit v1.2.3-59-g8ed1b From cd8dc0548511efff7a97d978f989ce67a883f9a5 Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sat, 11 Apr 2015 18:07:57 -0700 Subject: Drivers: hv: vss: full handshake support Introduce VSS_OP_REGISTER1 to support kernel replying to the negotiation message with its own version. Signed-off-by: Vitaly Kuznetsov Tested-by: Alex Ng Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/hv_snapshot.c | 49 ++++++++++++++++++++++++++++++++++----------- include/uapi/linux/hyperv.h | 5 +++++ tools/hv/hv_vss_daemon.c | 14 +++++++++++++ 3 files changed, 56 insertions(+), 12 deletions(-) (limited to 'include') diff --git a/drivers/hv/hv_snapshot.c b/drivers/hv/hv_snapshot.c index 2c8c246d09eb..ee1762b39bf2 100644 --- a/drivers/hv/hv_snapshot.c +++ b/drivers/hv/hv_snapshot.c @@ -59,6 +59,11 @@ static struct { static void vss_respond_to_host(int error); +/* + * This state maintains the version number registered by the daemon. + */ +static int dm_reg_value; + static const char vss_devname[] = "vmbus/hv_vss"; static __u8 *recv_buffer; static struct hvutil_transport *hvt; @@ -89,6 +94,29 @@ static void vss_timeout_func(struct work_struct *dummy) hv_vss_onchannelcallback); } +static int vss_handle_handshake(struct hv_vss_msg *vss_msg) +{ + u32 our_ver = VSS_OP_REGISTER1; + + switch (vss_msg->vss_hdr.operation) { + case VSS_OP_REGISTER: + /* Daemon doesn't expect us to reply */ + dm_reg_value = VSS_OP_REGISTER; + break; + case VSS_OP_REGISTER1: + /* Daemon expects us to reply with our own version*/ + if (hvutil_transport_send(hvt, &our_ver, sizeof(our_ver))) + return -EFAULT; + dm_reg_value = VSS_OP_REGISTER1; + break; + default: + return -EINVAL; + } + vss_transaction.state = HVUTIL_READY; + pr_info("VSS daemon registered\n"); + return 0; +} + static int vss_on_msg(void *msg, int len) { struct hv_vss_msg *vss_msg = (struct hv_vss_msg *)msg; @@ -96,18 +124,15 @@ static int vss_on_msg(void *msg, int len) if (len != sizeof(*vss_msg)) return -EINVAL; - /* - * Don't process registration messages if we're in the middle of - * a transaction processing. - */ - if (vss_transaction.state > HVUTIL_READY && - vss_msg->vss_hdr.operation == VSS_OP_REGISTER) - return -EINVAL; - - if (vss_transaction.state == HVUTIL_DEVICE_INIT && - vss_msg->vss_hdr.operation == VSS_OP_REGISTER) { - pr_info("VSS daemon registered\n"); - vss_transaction.state = HVUTIL_READY; + if (vss_msg->vss_hdr.operation == VSS_OP_REGISTER || + vss_msg->vss_hdr.operation == VSS_OP_REGISTER1) { + /* + * Don't process registration messages if we're in the middle + * of a transaction processing. + */ + if (vss_transaction.state > HVUTIL_READY) + return -EINVAL; + return vss_handle_handshake(vss_msg); } else if (vss_transaction.state == HVUTIL_USERSPACE_REQ) { vss_transaction.state = HVUTIL_USERSPACE_RECV; if (cancel_delayed_work_sync(&vss_timeout_work)) { diff --git a/include/uapi/linux/hyperv.h b/include/uapi/linux/hyperv.h index bb1cb73c927a..66c76df2c32d 100644 --- a/include/uapi/linux/hyperv.h +++ b/include/uapi/linux/hyperv.h @@ -45,6 +45,11 @@ #define VSS_OP_REGISTER 128 +/* + Daemon code with full handshake support. + */ +#define VSS_OP_REGISTER1 129 + enum hv_vss_op { VSS_OP_CREATE = 0, VSS_OP_DELETE, diff --git a/tools/hv/hv_vss_daemon.c b/tools/hv/hv_vss_daemon.c index 36f18211afa7..96234b638249 100644 --- a/tools/hv/hv_vss_daemon.c +++ b/tools/hv/hv_vss_daemon.c @@ -148,6 +148,8 @@ int main(int argc, char *argv[]) int op; struct hv_vss_msg vss_msg[1]; int daemonize = 1, long_index = 0, opt; + int in_handshake = 1; + __u32 kernel_modver; static struct option long_options[] = { {"help", no_argument, 0, 'h' }, @@ -211,6 +213,18 @@ int main(int argc, char *argv[]) len = read(vss_fd, vss_msg, sizeof(struct hv_vss_msg)); + if (in_handshake) { + if (len != sizeof(kernel_modver)) { + syslog(LOG_ERR, "invalid version negotiation"); + exit(EXIT_FAILURE); + } + kernel_modver = *(__u32 *)vss_msg; + in_handshake = 0; + syslog(LOG_INFO, "VSS: kernel module version: %d", + kernel_modver); + continue; + } + if (len != sizeof(struct hv_vss_msg)) { syslog(LOG_ERR, "read failed; error:%d %s", errno, strerror(errno)); -- cgit v1.2.3-59-g8ed1b From a4d1ee5b0255a135fead1d62a7fc7e6fe718b66e Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov Date: Sat, 11 Apr 2015 18:07:58 -0700 Subject: Drivers: hv: fcopy: full handshake support Introduce FCOPY_VERSION_1 to support kernel replying to the negotiation message with its own version. Signed-off-by: Vitaly Kuznetsov Tested-by: Alex Ng Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/hv_fcopy.c | 16 +++++++++++++++- include/uapi/linux/hyperv.h | 3 ++- tools/hv/hv_fcopy_daemon.c | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/drivers/hv/hv_fcopy.c b/drivers/hv/hv_fcopy.c index 6a8ec9fb0869..b7b528cd481b 100644 --- a/drivers/hv/hv_fcopy.c +++ b/drivers/hv/hv_fcopy.c @@ -62,6 +62,10 @@ static DECLARE_WORK(fcopy_send_work, fcopy_send_data); static const char fcopy_devname[] = "vmbus/hv_fcopy"; static u8 *recv_buffer; static struct hvutil_transport *hvt; +/* + * This state maintains the version number registered by the daemon. + */ +static int dm_reg_value; static void fcopy_timeout_func(struct work_struct *dummy) { @@ -81,8 +85,18 @@ static void fcopy_timeout_func(struct work_struct *dummy) static int fcopy_handle_handshake(u32 version) { + u32 our_ver = FCOPY_CURRENT_VERSION; + switch (version) { - case FCOPY_CURRENT_VERSION: + case FCOPY_VERSION_0: + /* Daemon doesn't expect us to reply */ + dm_reg_value = version; + break; + case FCOPY_VERSION_1: + /* Daemon expects us to reply with our own version */ + if (hvutil_transport_send(hvt, &our_ver, sizeof(our_ver))) + return -EFAULT; + dm_reg_value = version; break; default: /* diff --git a/include/uapi/linux/hyperv.h b/include/uapi/linux/hyperv.h index 66c76df2c32d..e4c0a35d6417 100644 --- a/include/uapi/linux/hyperv.h +++ b/include/uapi/linux/hyperv.h @@ -105,7 +105,8 @@ struct hv_vss_msg { */ #define FCOPY_VERSION_0 0 -#define FCOPY_CURRENT_VERSION FCOPY_VERSION_0 +#define FCOPY_VERSION_1 1 +#define FCOPY_CURRENT_VERSION FCOPY_VERSION_1 #define W_MAX_PATH 260 enum hv_fcopy_op { diff --git a/tools/hv/hv_fcopy_daemon.c b/tools/hv/hv_fcopy_daemon.c index 9445d8f264a4..5480e4e424eb 100644 --- a/tools/hv/hv_fcopy_daemon.c +++ b/tools/hv/hv_fcopy_daemon.c @@ -137,6 +137,8 @@ int main(int argc, char *argv[]) int version = FCOPY_CURRENT_VERSION; char *buffer[4096 * 2]; struct hv_fcopy_hdr *in_msg; + int in_handshake = 1; + __u32 kernel_modver; static struct option long_options[] = { {"help", no_argument, 0, 'h' }, @@ -191,6 +193,19 @@ int main(int argc, char *argv[]) syslog(LOG_ERR, "pread failed: %s", strerror(errno)); exit(EXIT_FAILURE); } + + if (in_handshake) { + if (len != sizeof(kernel_modver)) { + syslog(LOG_ERR, "invalid version negotiation"); + exit(EXIT_FAILURE); + } + kernel_modver = *(__u32 *)buffer; + in_handshake = 0; + syslog(LOG_INFO, "HV_FCOPY: kernel module version: %d", + kernel_modver); + continue; + } + in_msg = (struct hv_fcopy_hdr *)buffer; switch (in_msg->operation) { -- cgit v1.2.3-59-g8ed1b From db9ba2088f6507fee370904f02db1eb9b49bd088 Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Wed, 22 Apr 2015 21:31:31 -0700 Subject: drivers: hv: vmbus: Get rid of some unused definitions Get rid of some unused definitions. Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- include/linux/hyperv.h | 19 ------------------- 1 file changed, 19 deletions(-) (limited to 'include') diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 1744148a39f9..e29ccddc6300 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -389,10 +389,6 @@ enum vmbus_channel_message_type { CHANNELMSG_INITIATE_CONTACT = 14, CHANNELMSG_VERSION_RESPONSE = 15, CHANNELMSG_UNLOAD = 16, -#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD - CHANNELMSG_VIEWRANGE_ADD = 17, - CHANNELMSG_VIEWRANGE_REMOVE = 18, -#endif CHANNELMSG_COUNT }; @@ -549,21 +545,6 @@ struct vmbus_channel_gpadl_torndown { u32 gpadl; } __packed; -#ifdef VMBUS_FEATURE_PARENT_OR_PEER_MEMORY_MAPPED_INTO_A_CHILD -struct vmbus_channel_view_range_add { - struct vmbus_channel_message_header header; - PHYSICAL_ADDRESS viewrange_base; - u64 viewrange_length; - u32 child_relid; -} __packed; - -struct vmbus_channel_view_range_remove { - struct vmbus_channel_message_header header; - PHYSICAL_ADDRESS viewrange_base; - u32 child_relid; -} __packed; -#endif - struct vmbus_channel_relid_released { struct vmbus_channel_message_header header; u32 child_relid; -- cgit v1.2.3-59-g8ed1b From 2db84eff127e3f4b3635edc589cd6a56db8755a3 Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Wed, 22 Apr 2015 21:31:32 -0700 Subject: Drivers: hv: vmbus: Implement the protocol for tearing down vmbus state Implement the protocol for tearing down the monitor state established with the host. Signed-off-by: K. Y. Srinivasan Tested-by: Vitaly Kuznetsov Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 25 +++++++++++++++++++++++++ drivers/hv/connection.c | 5 +++++ drivers/hv/hyperv_vmbus.h | 2 ++ drivers/hv/vmbus_drv.c | 2 +- include/linux/hyperv.h | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index 865a3afa1d86..4b9d89ab44d3 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -421,6 +421,30 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui channel->target_vp = hv_context.vp_index[cur_cpu]; } +/* + * vmbus_unload_response - Handler for the unload response. + */ +static void vmbus_unload_response(struct vmbus_channel_message_header *hdr) +{ + /* + * This is a global event; just wakeup the waiting thread. + * Once we successfully unload, we can cleanup the monitor state. + */ + complete(&vmbus_connection.unload_event); +} + +void vmbus_initiate_unload(void) +{ + struct vmbus_channel_message_header hdr; + + init_completion(&vmbus_connection.unload_event); + memset(&hdr, 0, sizeof(struct vmbus_channel_message_header)); + hdr.msgtype = CHANNELMSG_UNLOAD; + vmbus_post_msg(&hdr, sizeof(struct vmbus_channel_message_header)); + + wait_for_completion(&vmbus_connection.unload_event); +} + /* * vmbus_onoffer - Handler for channel offers from vmbus in parent partition. * @@ -717,6 +741,7 @@ struct vmbus_channel_message_table_entry {CHANNELMSG_INITIATE_CONTACT, 0, NULL}, {CHANNELMSG_VERSION_RESPONSE, 1, vmbus_onversion_response}, {CHANNELMSG_UNLOAD, 0, NULL}, + {CHANNELMSG_UNLOAD_RESPONSE, 1, vmbus_unload_response}, }; /* diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index b27220a425f4..acd50e9d666a 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -227,6 +227,11 @@ cleanup: void vmbus_disconnect(void) { + /* + * First send the unload request to the host. + */ + vmbus_initiate_unload(); + if (vmbus_connection.work_queue) { drain_workqueue(vmbus_connection.work_queue); destroy_workqueue(vmbus_connection.work_queue); diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h index 138d6634c79d..cddc0c9f6bf9 100644 --- a/drivers/hv/hyperv_vmbus.h +++ b/drivers/hv/hyperv_vmbus.h @@ -647,6 +647,7 @@ struct vmbus_connection { atomic_t next_gpadl_handle; + struct completion unload_event; /* * Represents channel interrupts. Each bit position represents a * channel. When a channel sends an interrupt via VMBUS, it finds its @@ -741,6 +742,7 @@ void hv_vss_onchannelcallback(void *); int hv_fcopy_init(struct hv_util_service *); void hv_fcopy_deinit(void); void hv_fcopy_onchannelcallback(void *); +void vmbus_initiate_unload(void); static inline void hv_poll_channel(struct vmbus_channel *channel, void (*cb)(void *)) diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c index 7870a906365e..2b56260b0eb4 100644 --- a/drivers/hv/vmbus_drv.c +++ b/drivers/hv/vmbus_drv.c @@ -1106,6 +1106,7 @@ static void __exit vmbus_exit(void) vmbus_connection.conn_state = DISCONNECTED; hv_synic_clockevents_cleanup(); + vmbus_disconnect(); hv_remove_vmbus_irq(); vmbus_free_channels(); if (ms_hyperv.features & HV_FEATURE_GUEST_CRASH_MSR_AVAILABLE) { @@ -1118,7 +1119,6 @@ static void __exit vmbus_exit(void) smp_call_function_single(cpu, hv_synic_cleanup, NULL, 1); acpi_bus_unregister_driver(&vmbus_acpi_driver); hv_cpu_hotplug_quirk(false); - vmbus_disconnect(); } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index e29ccddc6300..ea934864293d 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -389,6 +389,7 @@ enum vmbus_channel_message_type { CHANNELMSG_INITIATE_CONTACT = 14, CHANNELMSG_VERSION_RESPONSE = 15, CHANNELMSG_UNLOAD = 16, + CHANNELMSG_UNLOAD_RESPONSE = 17, CHANNELMSG_COUNT }; -- cgit v1.2.3-59-g8ed1b From fea844a2b0edd6540d5cde2cd54a8a3c86e9c53f Mon Sep 17 00:00:00 2001 From: Vitaly Kuznetsov <[mailto:vkuznets@redhat.com]> Date: Wed, 6 May 2015 17:47:43 -0700 Subject: Drivers: hv: vmbus: briefly comment num_sc and next_oc next_oc and num_sc fields of struct vmbus_channel deserve a description. Move them closer to sc_list as these fields are related to it. Signed-off-by: Vitaly Kuznetsov Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- include/linux/hyperv.h | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index ea934864293d..3932a993ff5a 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -726,6 +726,15 @@ struct vmbus_channel { * All Sub-channels of a primary channel are linked here. */ struct list_head sc_list; + /* + * Current number of sub-channels. + */ + int num_sc; + /* + * Number of a sub-channel (position within sc_list) which is supposed + * to be used as the next outgoing channel. + */ + int next_oc; /* * The primary channel this sub-channel belongs to. * This will be NULL for the primary channel. @@ -740,9 +749,6 @@ struct vmbus_channel { * link up channels based on their CPU affinity. */ struct list_head percpu_list; - - int num_sc; - int next_oc; }; static inline void set_channel_read_state(struct vmbus_channel *c, bool state) -- cgit v1.2.3-59-g8ed1b From f8df88081183bd4d3c461c617c3519445eb85642 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 27 May 2015 23:06:30 +0900 Subject: extcon: Remove optional print_name() function pointer of extcon_dev This patch removes the optional print_name() function pointer included in 'struct extcon_dev' because the extcon must maintain the consistent name of extcon device on sysfs instead of inconsistent name. After merged patch[1], extcon can maintain the consistent name of extcon device without any hard-coded device name. [1] https://lkml.org/lkml/2015/4/27/258 Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 8 -------- include/linux/extcon.h | 3 --- 2 files changed, 11 deletions(-) (limited to 'include') diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 5099c11d8833..fafd428cae7f 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -207,14 +207,6 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, { struct extcon_dev *edev = dev_get_drvdata(dev); - /* Optional callback given by the user */ - if (edev->print_name) { - int ret = edev->print_name(edev, buf); - - if (ret >= 0) - return ret; - } - return sprintf(buf, "%s\n", edev->name); } static DEVICE_ATTR_RO(name); diff --git a/include/linux/extcon.h b/include/linux/extcon.h index be9652b3a154..a7b224b20ecc 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -83,8 +83,6 @@ struct extcon_cable; * be attached simulataneously. {0x7, 0} is equivalent to * {0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there * can be no simultaneous connections. - * @print_name: An optional callback to override the method to print the - * name of the extcon device. * @print_state: An optional callback to override the method to print the * status of the extcon device. * @dev: Device of this extcon. @@ -111,7 +109,6 @@ struct extcon_dev { const u32 *mutually_exclusive; /* Optional callbacks to override class functions */ - ssize_t (*print_name)(struct extcon_dev *edev, char *buf); ssize_t (*print_state)(struct extcon_dev *edev, char *buf); /* Internal data. Please do not set. */ -- cgit v1.2.3-59-g8ed1b From b144ce2d37619e05afdb0a15676500d76a64b1be Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 27 May 2015 17:17:27 -0700 Subject: mei: fix up uuid matching A previous commit, c93b76b34b4d ("mei: bus: report also uuid in module alias") caused a build error as I missed applying a needed patch to add some macros to uapi/linux/uuid.h. Instead of those additional macros, change the mei code to use the existing uuid structure directly. Fixes: c93b76b34b4d Cc: Tomas Winkler Cc: Samuel Ortiz Reported-by: Stephen Rothwell Signed-off-by: Greg Kroah-Hartman --- drivers/misc/mei/bus.c | 9 ++------- drivers/nfc/mei_phy.h | 2 +- include/linux/mod_devicetable.h | 2 +- scripts/mod/file2alias.c | 7 +++++-- 4 files changed, 9 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/drivers/misc/mei/bus.c b/drivers/misc/mei/bus.c index de8fd089a8a4..357b6ae4d207 100644 --- a/drivers/misc/mei/bus.c +++ b/drivers/misc/mei/bus.c @@ -30,11 +30,6 @@ #define to_mei_cl_driver(d) container_of(d, struct mei_cl_driver, driver) #define to_mei_cl_device(d) container_of(d, struct mei_cl_device, dev) -static inline uuid_le uuid_le_cast(const __u8 uuid[16]) -{ - return *(uuid_le *)uuid; -} - static int mei_cl_device_match(struct device *dev, struct device_driver *drv) { struct mei_cl_device *device = to_mei_cl_device(dev); @@ -54,9 +49,9 @@ static int mei_cl_device_match(struct device *dev, struct device_driver *drv) id = driver->id_table; - while (uuid_le_cmp(NULL_UUID_LE, uuid_le_cast(id->uuid))) { + while (uuid_le_cmp(NULL_UUID_LE, id->uuid)) { - if (!uuid_le_cmp(*uuid, uuid_le_cast(id->uuid))) { + if (!uuid_le_cmp(*uuid, id->uuid)) { if (id->name[0]) { if (!strncmp(name, id->name, sizeof(id->name))) return 1; diff --git a/drivers/nfc/mei_phy.h b/drivers/nfc/mei_phy.h index a51f8f2685cc..fbfa3e61738f 100644 --- a/drivers/nfc/mei_phy.h +++ b/drivers/nfc/mei_phy.h @@ -5,7 +5,7 @@ #include #include -#define MEI_NFC_UUID __UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \ +#define MEI_NFC_UUID UUID_LE(0x0bb17a78, 0x2a8e, 0x4c50, \ 0x94, 0xd4, 0x50, 0x26, 0x67, 0x23, 0x77, 0x5c) #define MEI_NFC_HEADER_SIZE 10 #define MEI_NFC_MAX_HCI_PAYLOAD 300 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h index 2d2b2b571d61..048c270822f9 100644 --- a/include/linux/mod_devicetable.h +++ b/include/linux/mod_devicetable.h @@ -614,7 +614,7 @@ struct ipack_device_id { */ struct mei_cl_device_id { char name[MEI_CL_NAME_SIZE]; - __u8 uuid[16]; + uuid_le uuid; kernel_ulong_t driver_info; }; diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index 62c517f4b592..718b2a29bd43 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c @@ -34,6 +34,9 @@ typedef Elf64_Addr kernel_ulong_t; typedef uint32_t __u32; typedef uint16_t __u16; typedef unsigned char __u8; +typedef struct { + __u8 b[16]; +} uuid_le; /* Big exception to the "don't include kernel headers into userspace, which * even potentially has different endianness and word sizes, since @@ -131,13 +134,13 @@ static inline void add_wildcard(char *str) strcat(str + len, "*"); } -static inline void add_uuid(char *str, __u8 uuid[16]) +static inline void add_uuid(char *str, uuid_le uuid) { int len = strlen(str); int i; for (i = 0; i < 16; i++) - sprintf(str + len + (i << 1), "%02x", uuid[i]); + sprintf(str + len + (i << 1), "%02x", uuid.b[i]); } /** -- cgit v1.2.3-59-g8ed1b From 6c4e5f9c9ff41ea997fd0f345b3b2b88c113eb68 Mon Sep 17 00:00:00 2001 From: Keith Mange Date: Tue, 26 May 2015 14:23:01 -0700 Subject: Drivers: hv: vmbus:Update preferred vmbus protocol version to windows 10. Add support for Windows 10. Signed-off-by: Keith Mange Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/connection.c | 8 +++++--- include/linux/hyperv.h | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/drivers/hv/connection.c b/drivers/hv/connection.c index acd50e9d666a..4fc2e8836e60 100644 --- a/drivers/hv/connection.c +++ b/drivers/hv/connection.c @@ -58,6 +58,9 @@ static __u32 vmbus_get_next_version(__u32 current_version) case (VERSION_WIN8_1): return VERSION_WIN8; + case (VERSION_WIN10): + return VERSION_WIN8_1; + case (VERSION_WS2008): default: return VERSION_INVAL; @@ -80,7 +83,7 @@ static int vmbus_negotiate_version(struct vmbus_channel_msginfo *msginfo, msg->interrupt_page = virt_to_phys(vmbus_connection.int_page); msg->monitor_page1 = virt_to_phys(vmbus_connection.monitor_pages[0]); msg->monitor_page2 = virt_to_phys(vmbus_connection.monitor_pages[1]); - if (version == VERSION_WIN8_1) { + if (version >= VERSION_WIN8_1) { msg->target_vcpu = hv_context.vp_index[get_cpu()]; put_cpu(); } @@ -376,8 +379,7 @@ void vmbus_on_event(unsigned long data) int cpu = smp_processor_id(); union hv_synic_event_flags *event; - if ((vmbus_proto_version == VERSION_WS2008) || - (vmbus_proto_version == VERSION_WIN7)) { + if (vmbus_proto_version < VERSION_WIN8) { maxdword = MAX_NUM_CHANNELS_SUPPORTED >> 5; recv_int_page = vmbus_connection.recv_int_page; } else { diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 3932a993ff5a..4317cd1b69ed 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -160,16 +160,18 @@ hv_get_ringbuffer_availbytes(struct hv_ring_buffer_info *rbi, * 1 . 1 (Windows 7) * 2 . 4 (Windows 8) * 3 . 0 (Windows 8 R2) + * 4 . 0 (Windows 10) */ #define VERSION_WS2008 ((0 << 16) | (13)) #define VERSION_WIN7 ((1 << 16) | (1)) #define VERSION_WIN8 ((2 << 16) | (4)) #define VERSION_WIN8_1 ((3 << 16) | (0)) +#define VERSION_WIN10 ((4 << 16) | (0)) #define VERSION_INVAL -1 -#define VERSION_CURRENT VERSION_WIN8_1 +#define VERSION_CURRENT VERSION_WIN10 /* Make maximum size of pipe payload of 16K */ #define MAX_PIPE_DATA_PAYLOAD (sizeof(u8) * 16384) -- cgit v1.2.3-59-g8ed1b From 6fa45a22689722dac9f0e90c0931d4b34b334ede Mon Sep 17 00:00:00 2001 From: Sudip Mukherjee Date: Wed, 20 May 2015 20:56:57 +0530 Subject: parport: add device-model to parport subsystem parport subsystem starts using the device-model. Drivers using the device-model has to define devmodel as true and should register the device with parport using parport_register_dev_model(). Tested-by: Jean Delvare Tested-by: Alan Cox Signed-off-by: Sudip Mukherjee Signed-off-by: Greg Kroah-Hartman --- drivers/parport/parport_pc.c | 4 +- drivers/parport/procfs.c | 15 +- drivers/parport/share.c | 345 ++++++++++++++++++++++++++++++++++++++++--- include/linux/parport.h | 43 +++++- 4 files changed, 379 insertions(+), 28 deletions(-) (limited to 'include') diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c index 53d15b30636a..78530d1714dc 100644 --- a/drivers/parport/parport_pc.c +++ b/drivers/parport/parport_pc.c @@ -2255,7 +2255,7 @@ out5: release_region(base+0x3, 5); release_region(base, 3); out4: - parport_put_port(p); + parport_del_port(p); out3: kfree(priv); out2: @@ -2294,7 +2294,7 @@ void parport_pc_unregister_port(struct parport *p) priv->dma_handle); #endif kfree(p->private_data); - parport_put_port(p); + parport_del_port(p); kfree(ops); /* hope no-one cached it */ } EXPORT_SYMBOL(parport_pc_unregister_port); diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c index 3b470801a04f..c776333a68bc 100644 --- a/drivers/parport/procfs.c +++ b/drivers/parport/procfs.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -558,8 +559,18 @@ int parport_device_proc_unregister(struct pardevice *device) static int __init parport_default_proc_register(void) { + int ret; + parport_default_sysctl_table.sysctl_header = register_sysctl_table(parport_default_sysctl_table.dev_dir); + if (!parport_default_sysctl_table.sysctl_header) + return -ENOMEM; + ret = parport_bus_init(); + if (ret) { + unregister_sysctl_table(parport_default_sysctl_table. + sysctl_header); + return ret; + } return 0; } @@ -570,6 +581,7 @@ static void __exit parport_default_proc_unregister(void) sysctl_header); parport_default_sysctl_table.sysctl_header = NULL; } + parport_bus_exit(); } #else /* no sysctl or no procfs*/ @@ -596,11 +608,12 @@ int parport_device_proc_unregister(struct pardevice *device) static int __init parport_default_proc_register (void) { - return 0; + return parport_bus_init(); } static void __exit parport_default_proc_unregister (void) { + parport_bus_exit(); } #endif diff --git a/drivers/parport/share.c b/drivers/parport/share.c index 3fa66244ce32..697c6d7bf0fe 100644 --- a/drivers/parport/share.c +++ b/drivers/parport/share.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -100,13 +101,91 @@ static struct parport_operations dead_ops = { .owner = NULL, }; +static struct device_type parport_device_type = { + .name = "parport", +}; + +static int is_parport(struct device *dev) +{ + return dev->type == &parport_device_type; +} + +static int parport_probe(struct device *dev) +{ + struct parport_driver *drv; + + if (is_parport(dev)) + return -ENODEV; + + drv = to_parport_driver(dev->driver); + if (!drv->probe) { + /* if driver has not defined a custom probe */ + struct pardevice *par_dev = to_pardevice(dev); + + if (strcmp(par_dev->name, drv->name)) + return -ENODEV; + return 0; + } + /* if driver defined its own probe */ + return drv->probe(to_pardevice(dev)); +} + +static struct bus_type parport_bus_type = { + .name = "parport", + .probe = parport_probe, +}; + +int parport_bus_init(void) +{ + return bus_register(&parport_bus_type); +} + +void parport_bus_exit(void) +{ + bus_unregister(&parport_bus_type); +} + +/* + * iterates through all the drivers registered with the bus and sends the port + * details to the match_port callback of the driver, so that the driver can + * know about the new port that just regsitered with the bus and decide if it + * wants to use this new port. + */ +static int driver_check(struct device_driver *dev_drv, void *_port) +{ + struct parport *port = _port; + struct parport_driver *drv = to_parport_driver(dev_drv); + + if (drv->match_port) + drv->match_port(port); + return 0; +} + /* Call attach(port) for each registered driver. */ static void attach_driver_chain(struct parport *port) { /* caller has exclusive registration_lock */ struct parport_driver *drv; + list_for_each_entry(drv, &drivers, list) drv->attach(port); + + /* + * call the driver_check function of the drivers registered in + * new device model + */ + + bus_for_each_drv(&parport_bus_type, NULL, port, driver_check); +} + +static int driver_detach(struct device_driver *_drv, void *_port) +{ + struct parport *port = _port; + struct parport_driver *drv = to_parport_driver(_drv); + + if (drv->detach) + drv->detach(port); + return 0; } /* Call detach(port) for each registered driver. */ @@ -116,6 +195,13 @@ static void detach_driver_chain(struct parport *port) /* caller has exclusive registration_lock */ list_for_each_entry(drv, &drivers, list) drv->detach (port); + + /* + * call the detach function of the drivers registered in + * new device model + */ + + bus_for_each_drv(&parport_bus_type, NULL, port, driver_detach); } /* Ask kmod for some lowlevel drivers. */ @@ -126,17 +212,39 @@ static void get_lowlevel_driver (void) request_module ("parport_lowlevel"); } +/* + * iterates through all the devices connected to the bus and sends the device + * details to the match_port callback of the driver, so that the driver can + * know what are all the ports that are connected to the bus and choose the + * port to which it wants to register its device. + */ +static int port_check(struct device *dev, void *dev_drv) +{ + struct parport_driver *drv = dev_drv; + + /* only send ports, do not send other devices connected to bus */ + if (is_parport(dev)) + drv->match_port(to_parport_dev(dev)); + return 0; +} + /** * parport_register_driver - register a parallel port device driver * @drv: structure describing the driver + * @owner: owner module of drv + * @mod_name: module name string * * This can be called by a parallel port device driver in order * to receive notifications about ports being found in the * system, as well as ports no longer available. * + * If devmodel is true then the new device model is used + * for registration. + * * The @drv structure is allocated by the caller and must not be * deallocated until after calling parport_unregister_driver(). * + * If using the non device model: * The driver's attach() function may block. The port that * attach() is given will be valid for the duration of the * callback, but if the driver wants to take a copy of the @@ -148,21 +256,57 @@ static void get_lowlevel_driver (void) * callback, but if the driver wants to take a copy of the * pointer it must call parport_get_port() to do so. * - * Returns 0 on success. Currently it always succeeds. + * + * Returns 0 on success. The non device model will always succeeds. + * but the new device model can fail and will return the error code. **/ -int parport_register_driver (struct parport_driver *drv) +int __parport_register_driver(struct parport_driver *drv, struct module *owner, + const char *mod_name) { - struct parport *port; - if (list_empty(&portlist)) get_lowlevel_driver (); - mutex_lock(®istration_lock); - list_for_each_entry(port, &portlist, list) - drv->attach(port); - list_add(&drv->list, &drivers); - mutex_unlock(®istration_lock); + if (drv->devmodel) { + /* using device model */ + int ret; + + /* initialize common driver fields */ + drv->driver.name = drv->name; + drv->driver.bus = &parport_bus_type; + drv->driver.owner = owner; + drv->driver.mod_name = mod_name; + ret = driver_register(&drv->driver); + if (ret) + return ret; + + mutex_lock(®istration_lock); + if (drv->match_port) + bus_for_each_dev(&parport_bus_type, NULL, drv, + port_check); + mutex_unlock(®istration_lock); + } else { + struct parport *port; + + drv->devmodel = false; + + mutex_lock(®istration_lock); + list_for_each_entry(port, &portlist, list) + drv->attach(port); + list_add(&drv->list, &drivers); + mutex_unlock(®istration_lock); + } + + return 0; +} +EXPORT_SYMBOL(__parport_register_driver); + +static int port_detach(struct device *dev, void *_drv) +{ + struct parport_driver *drv = _drv; + + if (is_parport(dev) && drv->detach) + drv->detach(to_parport_dev(dev)); return 0; } @@ -189,15 +333,22 @@ void parport_unregister_driver (struct parport_driver *drv) struct parport *port; mutex_lock(®istration_lock); - list_del_init(&drv->list); - list_for_each_entry(port, &portlist, list) - drv->detach(port); + if (drv->devmodel) { + bus_for_each_dev(&parport_bus_type, NULL, drv, port_detach); + driver_unregister(&drv->driver); + } else { + list_del_init(&drv->list); + list_for_each_entry(port, &portlist, list) + drv->detach(port); + } mutex_unlock(®istration_lock); } -static void free_port (struct parport *port) +static void free_port(struct device *dev) { int d; + struct parport *port = to_parport_dev(dev); + spin_lock(&full_list_lock); list_del(&port->full_list); spin_unlock(&full_list_lock); @@ -223,25 +374,29 @@ static void free_port (struct parport *port) struct parport *parport_get_port (struct parport *port) { - atomic_inc (&port->ref_count); - return port; + struct device *dev = get_device(&port->bus_dev); + + return to_parport_dev(dev); +} + +void parport_del_port(struct parport *port) +{ + device_unregister(&port->bus_dev); } +EXPORT_SYMBOL(parport_del_port); /** * parport_put_port - decrement a port's reference count * @port: the port * * This should be called once for each call to parport_get_port(), - * once the port is no longer needed. + * once the port is no longer needed. When the reference count reaches + * zero (port is no longer used), free_port is called. **/ void parport_put_port (struct parport *port) { - if (atomic_dec_and_test (&port->ref_count)) - /* Can destroy it now. */ - free_port (port); - - return; + put_device(&port->bus_dev); } /** @@ -281,6 +436,7 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, int num; int device; char *name; + int ret; tmp = kzalloc(sizeof(struct parport), GFP_KERNEL); if (!tmp) { @@ -333,6 +489,10 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, */ sprintf(name, "parport%d", tmp->portnum = tmp->number); tmp->name = name; + tmp->bus_dev.bus = &parport_bus_type; + tmp->bus_dev.release = free_port; + dev_set_name(&tmp->bus_dev, name); + tmp->bus_dev.type = &parport_device_type; for (device = 0; device < 5; device++) /* assume the worst */ @@ -340,6 +500,12 @@ struct parport *parport_register_port(unsigned long base, int irq, int dma, tmp->waithead = tmp->waittail = NULL; + ret = device_register(&tmp->bus_dev); + if (ret) { + put_device(&tmp->bus_dev); + return NULL; + } + return tmp; } @@ -575,6 +741,7 @@ parport_register_device(struct parport *port, const char *name, tmp->irq_func = irq_func; tmp->waiting = 0; tmp->timeout = 5 * HZ; + tmp->devmodel = false; /* Chain this onto the list */ tmp->prev = NULL; @@ -630,6 +797,136 @@ parport_register_device(struct parport *port, const char *name, return NULL; } +static void free_pardevice(struct device *dev) +{ + struct pardevice *par_dev = to_pardevice(dev); + + kfree(par_dev->name); + kfree(par_dev); +} + +struct pardevice * +parport_register_dev_model(struct parport *port, const char *name, + const struct pardev_cb *par_dev_cb, int id) +{ + struct pardevice *par_dev; + int ret; + char *devname; + + if (port->physport->flags & PARPORT_FLAG_EXCL) { + /* An exclusive device is registered. */ + pr_err("%s: no more devices allowed\n", port->name); + return NULL; + } + + if (par_dev_cb->flags & PARPORT_DEV_LURK) { + if (!par_dev_cb->preempt || !par_dev_cb->wakeup) { + pr_info("%s: refused to register lurking device (%s) without callbacks\n", + port->name, name); + return NULL; + } + } + + if (!try_module_get(port->ops->owner)) + return NULL; + + parport_get_port(port); + + par_dev = kzalloc(sizeof(*par_dev), GFP_KERNEL); + if (!par_dev) + goto err_put_port; + + par_dev->state = kzalloc(sizeof(*par_dev->state), GFP_KERNEL); + if (!par_dev->state) + goto err_put_par_dev; + + devname = kstrdup(name, GFP_KERNEL); + if (!devname) + goto err_free_par_dev; + + par_dev->name = devname; + par_dev->port = port; + par_dev->daisy = -1; + par_dev->preempt = par_dev_cb->preempt; + par_dev->wakeup = par_dev_cb->wakeup; + par_dev->private = par_dev_cb->private; + par_dev->flags = par_dev_cb->flags; + par_dev->irq_func = par_dev_cb->irq_func; + par_dev->waiting = 0; + par_dev->timeout = 5 * HZ; + + par_dev->dev.parent = &port->bus_dev; + par_dev->dev.bus = &parport_bus_type; + ret = dev_set_name(&par_dev->dev, "%s.%d", devname, id); + if (ret) + goto err_free_devname; + par_dev->dev.release = free_pardevice; + par_dev->devmodel = true; + ret = device_register(&par_dev->dev); + if (ret) + goto err_put_dev; + + /* Chain this onto the list */ + par_dev->prev = NULL; + /* + * This function must not run from an irq handler so we don' t need + * to clear irq on the local CPU. -arca + */ + spin_lock(&port->physport->pardevice_lock); + + if (par_dev_cb->flags & PARPORT_DEV_EXCL) { + if (port->physport->devices) { + spin_unlock(&port->physport->pardevice_lock); + pr_debug("%s: cannot grant exclusive access for device %s\n", + port->name, name); + goto err_put_dev; + } + port->flags |= PARPORT_FLAG_EXCL; + } + + par_dev->next = port->physport->devices; + wmb(); /* + * Make sure that tmp->next is written before it's + * added to the list; see comments marked 'no locking + * required' + */ + if (port->physport->devices) + port->physport->devices->prev = par_dev; + port->physport->devices = par_dev; + spin_unlock(&port->physport->pardevice_lock); + + init_waitqueue_head(&par_dev->wait_q); + par_dev->timeslice = parport_default_timeslice; + par_dev->waitnext = NULL; + par_dev->waitprev = NULL; + + /* + * This has to be run as last thing since init_state may need other + * pardevice fields. -arca + */ + port->ops->init_state(par_dev, par_dev->state); + port->proc_device = par_dev; + parport_device_proc_register(par_dev); + + return par_dev; + +err_put_dev: + put_device(&par_dev->dev); +err_free_devname: + kfree(devname); +err_free_par_dev: + kfree(par_dev->state); +err_put_par_dev: + if (!par_dev->devmodel) + kfree(par_dev); +err_put_port: + parport_put_port(port); + module_put(port->ops->owner); + + return NULL; +} +EXPORT_SYMBOL(parport_register_dev_model); + /** * parport_unregister_device - deregister a device on a parallel port * @dev: pointer to structure representing device @@ -691,7 +988,10 @@ void parport_unregister_device(struct pardevice *dev) spin_unlock_irq(&port->waitlist_lock); kfree(dev->state); - kfree(dev); + if (dev->devmodel) + device_unregister(&dev->dev); + else + kfree(dev); module_put(port->ops->owner); parport_put_port (port); @@ -1019,7 +1319,6 @@ EXPORT_SYMBOL(parport_release); EXPORT_SYMBOL(parport_register_port); EXPORT_SYMBOL(parport_announce_port); EXPORT_SYMBOL(parport_remove_port); -EXPORT_SYMBOL(parport_register_driver); EXPORT_SYMBOL(parport_unregister_driver); EXPORT_SYMBOL(parport_register_device); EXPORT_SYMBOL(parport_unregister_device); diff --git a/include/linux/parport.h b/include/linux/parport.h index c22f12547324..58e3c64c6b49 100644 --- a/include/linux/parport.h +++ b/include/linux/parport.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include @@ -145,6 +146,8 @@ struct pardevice { unsigned int flags; struct pardevice *next; struct pardevice *prev; + struct device dev; + bool devmodel; struct parport_state *state; /* saved status over preemption */ wait_queue_head_t wait_q; unsigned long int time; @@ -156,6 +159,8 @@ struct pardevice { void * sysctl_table; }; +#define to_pardevice(n) container_of(n, struct pardevice, dev) + /* IEEE1284 information */ /* IEEE1284 phases. These are exposed to userland through ppdev IOCTL @@ -195,7 +200,7 @@ struct parport { * This may unfortulately be null if the * port has a legacy driver. */ - + struct device bus_dev; /* to link with the bus */ struct parport *physport; /* If this is a non-default mux parport, i.e. we're a clone of a real @@ -245,15 +250,26 @@ struct parport { struct parport *slaves[3]; }; +#define to_parport_dev(n) container_of(n, struct parport, bus_dev) + #define DEFAULT_SPIN_TIME 500 /* us */ struct parport_driver { const char *name; void (*attach) (struct parport *); void (*detach) (struct parport *); + void (*match_port)(struct parport *); + int (*probe)(struct pardevice *); + struct device_driver driver; + bool devmodel; struct list_head list; }; +#define to_parport_driver(n) container_of(n, struct parport_driver, driver) + +int parport_bus_init(void); +void parport_bus_exit(void); + /* parport_register_port registers a new parallel port at the given address (if one does not already exist) and returns a pointer to it. This entails claiming the I/O region, IRQ and DMA. NULL is returned @@ -272,10 +288,20 @@ void parport_announce_port (struct parport *port); extern void parport_remove_port(struct parport *port); /* Register a new high-level driver. */ -extern int parport_register_driver (struct parport_driver *); + +int __must_check __parport_register_driver(struct parport_driver *, + struct module *, + const char *mod_name); +/* + * parport_register_driver must be a macro so that KBUILD_MODNAME can + * be expanded + */ +#define parport_register_driver(driver) \ + __parport_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) /* Unregister a high-level driver. */ extern void parport_unregister_driver (struct parport_driver *); +void parport_unregister_driver(struct parport_driver *); /* If parport_register_driver doesn't fit your needs, perhaps * parport_find_xxx does. */ @@ -288,6 +314,15 @@ extern irqreturn_t parport_irq_handler(int irq, void *dev_id); /* Reference counting for ports. */ extern struct parport *parport_get_port (struct parport *); extern void parport_put_port (struct parport *); +void parport_del_port(struct parport *); + +struct pardev_cb { + int (*preempt)(void *); + void (*wakeup)(void *); + void *private; + void (*irq_func)(void *); + unsigned int flags; +}; /* parport_register_device declares that a device is connected to a port, and tells the kernel all it needs to know. @@ -301,6 +336,10 @@ struct pardevice *parport_register_device(struct parport *port, void (*irq_func)(void *), int flags, void *handle); +struct pardevice * +parport_register_dev_model(struct parport *port, const char *name, + const struct pardev_cb *par_dev_cb, int cnt); + /* parport_unregister unlinks a device from the chain. */ extern void parport_unregister_device(struct pardevice *dev); -- cgit v1.2.3-59-g8ed1b From 1f656ff3fdddc2f59649cc84b633b799908f1f7b Mon Sep 17 00:00:00 2001 From: "K. Y. Srinivasan" Date: Sat, 30 May 2015 23:37:48 -0700 Subject: Drivers: hv: vmbus: Implement NUMA aware CPU affinity for channels Channels/sub-channels can be affinitized to VCPUs in the guest. Implement this affinity in a way that is NUMA aware. The current protocol distributed the primary channels uniformly across all available CPUs. The new protocol is NUMA aware: primary channels are distributed across the available NUMA nodes while the sub-channels within a primary channel are distributed amongst CPUs within the NUMA node assigned to the primary channel. Signed-off-by: K. Y. Srinivasan Signed-off-by: Greg Kroah-Hartman --- drivers/hv/channel_mgmt.c | 72 ++++++++++++++++++++++++++++------------------- include/linux/hyperv.h | 5 ++++ 2 files changed, 48 insertions(+), 29 deletions(-) (limited to 'include') diff --git a/drivers/hv/channel_mgmt.c b/drivers/hv/channel_mgmt.c index c3eba37db9b7..4506a6623618 100644 --- a/drivers/hv/channel_mgmt.c +++ b/drivers/hv/channel_mgmt.c @@ -370,25 +370,27 @@ static const struct hv_vmbus_device_id hp_devs[] = { /* * We use this state to statically distribute the channel interrupt load. */ -static u32 next_vp; +static int next_numa_node_id; /* * Starting with Win8, we can statically distribute the incoming - * channel interrupt load by binding a channel to VCPU. We - * implement here a simple round robin scheme for distributing - * the interrupt load. - * We will bind channels that are not performance critical to cpu 0 and - * performance critical channels (IDE, SCSI and Network) will be uniformly - * distributed across all available CPUs. + * channel interrupt load by binding a channel to VCPU. + * We do this in a hierarchical fashion: + * First distribute the primary channels across available NUMA nodes + * and then distribute the subchannels amongst the CPUs in the NUMA + * node assigned to the primary channel. + * + * For pre-win8 hosts or non-performance critical channels we assign the + * first CPU in the first NUMA node. */ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_guid) { u32 cur_cpu; int i; bool perf_chn = false; - u32 max_cpus = num_online_cpus(); - struct vmbus_channel *primary = channel->primary_channel, *prev; - unsigned long flags; + struct vmbus_channel *primary = channel->primary_channel; + int next_node; + struct cpumask available_mask; for (i = IDE; i < MAX_PERF_CHN; i++) { if (!memcmp(type_guid->b, hp_devs[i].guid, @@ -405,36 +407,48 @@ static void init_vp_index(struct vmbus_channel *channel, const uuid_le *type_gui * Also if the channel is not a performance critical * channel, bind it to cpu 0. */ + channel->numa_node = 0; + cpumask_set_cpu(0, &channel->alloced_cpus_in_node); channel->target_cpu = 0; channel->target_vp = hv_context.vp_index[0]; return; } /* - * Primary channels are distributed evenly across all vcpus we have. - * When the host asks us to create subchannels it usually makes us - * num_cpus-1 offers and we are supposed to distribute the work evenly - * among the channel itself and all its subchannels. Make sure they are - * all assigned to different vcpus. + * We distribute primary channels evenly across all the available + * NUMA nodes and within the assigned NUMA node we will assign the + * first available CPU to the primary channel. + * The sub-channels will be assigned to the CPUs available in the + * NUMA node evenly. */ - if (!primary) - cur_cpu = (++next_vp % max_cpus); - else { + if (!primary) { + while (true) { + next_node = next_numa_node_id++; + if (next_node == nr_node_ids) + next_node = next_numa_node_id = 0; + if (cpumask_empty(cpumask_of_node(next_node))) + continue; + break; + } + channel->numa_node = next_node; + primary = channel; + } + + if (cpumask_weight(&primary->alloced_cpus_in_node) == + cpumask_weight(cpumask_of_node(primary->numa_node))) { /* - * Let's assign the first subchannel of a channel to the - * primary->target_cpu+1 and all the subsequent channels to - * the prev->target_cpu+1. + * We have cycled through all the CPUs in the node; + * reset the alloced map. */ - spin_lock_irqsave(&primary->lock, flags); - if (primary->num_sc == 1) - cur_cpu = (primary->target_cpu + 1) % max_cpus; - else { - prev = list_prev_entry(channel, sc_list); - cur_cpu = (prev->target_cpu + 1) % max_cpus; - } - spin_unlock_irqrestore(&primary->lock, flags); + cpumask_clear(&primary->alloced_cpus_in_node); } + cpumask_xor(&available_mask, &primary->alloced_cpus_in_node, + cpumask_of_node(primary->numa_node)); + + cur_cpu = cpumask_next(-1, &available_mask); + cpumask_set_cpu(cur_cpu, &primary->alloced_cpus_in_node); + channel->target_cpu = cur_cpu; channel->target_vp = hv_context.vp_index[cur_cpu]; } diff --git a/include/linux/hyperv.h b/include/linux/hyperv.h index 4317cd1b69ed..30d3a1f79450 100644 --- a/include/linux/hyperv.h +++ b/include/linux/hyperv.h @@ -696,6 +696,11 @@ struct vmbus_channel { u32 target_vp; /* The corresponding CPUID in the guest */ u32 target_cpu; + /* + * State to manage the CPU affiliation of channels. + */ + struct cpumask alloced_cpus_in_node; + int numa_node; /* * Support for sub-channels. For high performance devices, * it will be useful to have multiple sub-channels to support -- cgit v1.2.3-59-g8ed1b From 73b6ecdb93e8e77752cae9077c424fcdc6f23c39 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 12 Jun 2015 11:10:06 +0900 Subject: extcon: Redefine the unique id of supported external connectors without 'enum extcon' type This patch just redefine the unique id of supported external connectors without 'enum extcon' type. Because unique id would be used on devictree file(*.dts) to indicate the specific external connectors like key number of input framework. So, I have the plan to move this definitions to following header file which includes the unique id of supported external connectors. - include/dt-bindings/extcon/extcon.h Fixes: 2a9de9c0f08d ("extcon: Use the unique id for external connector instead of string") Signed-off-by: Chanwoo Choi Signed-off-by: Greg Kroah-Hartman --- drivers/extcon/extcon-adc-jack.c | 2 +- drivers/extcon/extcon-arizona.c | 4 +- drivers/extcon/extcon-axp288.c | 4 +- drivers/extcon/extcon-max14577.c | 2 +- drivers/extcon/extcon-max77693.c | 4 +- drivers/extcon/extcon-max77843.c | 2 +- drivers/extcon/extcon-max8997.c | 2 +- drivers/extcon/extcon-palmas.c | 2 +- drivers/extcon/extcon-rt8973a.c | 4 +- drivers/extcon/extcon-sm5502.c | 4 +- drivers/extcon/extcon-usb-gpio.c | 2 +- drivers/extcon/extcon.c | 24 +++++------ drivers/usb/phy/phy-tahvo.c | 2 +- include/linux/extcon.h | 90 +++++++++++++++++++--------------------- 14 files changed, 71 insertions(+), 77 deletions(-) (limited to 'include') diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index 5bf08ec1cacf..7fc0ae1912f8 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c @@ -40,7 +40,7 @@ struct adc_jack_data { struct extcon_dev *edev; - const char **cable_names; + const unsigned int **cable_names; struct adc_jack_cond *adc_conditions; int num_conditions; diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 9262b45a4484..ad87f263056f 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -118,7 +118,7 @@ static const int arizona_micd_levels[] = { 1257, }; -static const enum extcon arizona_cable[] = { +static const unsigned int arizona_cable[] = { EXTCON_MECHANICAL, EXTCON_MICROPHONE, EXTCON_HEADPHONE, @@ -552,7 +552,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data) struct arizona_extcon_info *info = data; struct arizona *arizona = info->arizona; int id_gpio = arizona->pdata.hpdet_id_gpio; - enum extcon report = EXTCON_HEADPHONE; + unsigned int report = EXTCON_HEADPHONE; int ret, reading; bool mic = false; diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c index 3605aa96c25a..ea962bc547b8 100644 --- a/drivers/extcon/extcon-axp288.c +++ b/drivers/extcon/extcon-axp288.c @@ -101,7 +101,7 @@ enum axp288_extcon_irq { EXTCON_IRQ_END, }; -static const enum extcon axp288_extcon_cables[] = { +static const unsigned int axp288_extcon_cables[] = { EXTCON_SLOW_CHARGER, EXTCON_CHARGE_DOWNSTREAM, EXTCON_FAST_CHARGER, @@ -157,7 +157,7 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) { static bool notify_otg, notify_charger; - static enum extcon cable; + static unsigned int cable; int ret, stat, cfg, pwr_stat; u8 chrg_type; bool vbus_attach = false; diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c index e7c3edb5bd4b..df0659d98e5a 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -148,7 +148,7 @@ enum max14577_muic_acc_type { MAX14577_MUIC_ADC_OPEN, }; -static const enum extcon max14577_extcon_cable[] = { +static const unsigned int max14577_extcon_cable[] = { EXTCON_USB, EXTCON_TA, EXTCON_FAST_CHARGER, diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 20e796e10e57..f4f3b3d53928 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -200,7 +200,7 @@ enum max77693_muic_acc_type { /* * MAX77693 MUIC device support below list of accessories(external connector) */ -static const enum extcon max77693_extcon_cable[] = { +static const unsigned int max77693_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_TA, @@ -457,7 +457,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, int ret = 0; int vbvolt; bool cable_attached; - enum extcon dock_id; + unsigned int dock_id; dev_info(info->dev, "external connector is %s (adc:0x%02x)\n", diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index d78a64d7fc20..fac2f1417a79 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c @@ -118,7 +118,7 @@ enum max77843_muic_charger_type { MAX77843_MUIC_CHG_GND, }; -static const enum extcon max77843_extcon_cable[] = { +static const unsigned int max77843_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_TA, diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index 4d10949c6eb2..7b1ef200b121 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -145,7 +145,7 @@ struct max8997_muic_info { int path_uart; }; -static const enum extcon max8997_extcon_cable[] = { +static const unsigned int max8997_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_TA, diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index d68954045a33..080d5cc27055 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -29,7 +29,7 @@ #include #include -static const enum extcon palmas_extcon_cable[] = { +static const unsigned int palmas_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_NONE, diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c index f2a8672cbf82..92c939221a41 100644 --- a/drivers/extcon/extcon-rt8973a.c +++ b/drivers/extcon/extcon-rt8973a.c @@ -90,7 +90,7 @@ static struct reg_data rt8973a_reg_data[] = { }; /* List of detectable cables */ -static const enum extcon rt8973a_extcon_cable[] = { +static const unsigned int rt8973a_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_TA, @@ -300,7 +300,7 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info, static unsigned int prev_cable_type; unsigned int con_sw = DM_DP_SWITCH_UART; int ret, cable_type; - enum extcon id; + unsigned int id; bool attached = false; switch (event) { diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c index 520693d6fa8a..817dece23b4c 100644 --- a/drivers/extcon/extcon-sm5502.c +++ b/drivers/extcon/extcon-sm5502.c @@ -92,7 +92,7 @@ static struct reg_data sm5502_reg_data[] = { }; /* List of detectable cables */ -static const enum extcon sm5502_extcon_cable[] = { +static const unsigned int sm5502_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_TA, @@ -372,7 +372,7 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, unsigned int cable_type = SM5502_MUIC_ADC_GROUND; unsigned int con_sw = DM_DP_SWITCH_OPEN; unsigned int vbus_sw = VBUSIN_SWITCH_OPEN; - enum extcon id; + unsigned int id; int ret; /* Get the type of attached or detached cable */ diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index 14da94cb57fa..a2a44536a608 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -39,7 +39,7 @@ struct usb_extcon_info { struct delayed_work wq_detcable; }; -static const enum extcon usb_extcon_cable[] = { +static const unsigned int usb_extcon_cable[] = { EXTCON_USB, EXTCON_USB_HOST, EXTCON_NONE, diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index fafd428cae7f..76157ab9faf3 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -39,6 +39,8 @@ #define CABLE_NAME_MAX 30 static const char *extcon_name[] = { + [EXTCON_NONE] = "NONE", + /* USB external connector */ [EXTCON_USB] = "USB", [EXTCON_USB_HOST] = "USB-HOST", @@ -109,7 +111,7 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) return 0; } -static int find_cable_index_by_id(struct extcon_dev *edev, const enum extcon id) +static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id) { int i; @@ -124,16 +126,14 @@ static int find_cable_index_by_id(struct extcon_dev *edev, const enum extcon id) static int find_cable_index_by_name(struct extcon_dev *edev, const char *name) { - enum extcon id = EXTCON_NONE; - int i; + unsigned int id = EXTCON_NONE; + int i = 0; if (edev->max_supported == 0) return -EINVAL; /* Find the the number of extcon cable */ - for (i = 0; i < EXTCON_END; i++) { - if (!extcon_name[i]) - continue; + while (extcon_name[i]) { if (!strncmp(extcon_name[i], name, CABLE_NAME_MAX)) { id = i; break; @@ -337,7 +337,7 @@ EXPORT_SYMBOL_GPL(extcon_set_state); * @edev: the extcon device that has the cable. * @id: the unique id of each external connector in extcon enumeration. */ -int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id) +int extcon_get_cable_state_(struct extcon_dev *edev, const unsigned int id) { int index; @@ -374,7 +374,7 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state); * @state: the new cable status. The default semantics is * true: attached / false: detached. */ -int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id, +int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, bool cable_state) { u32 state; @@ -539,7 +539,7 @@ EXPORT_SYMBOL_GPL(extcon_unregister_interest); * "old_state", not the current state. The current state can be retrieved * by looking at the third pameter (edev pointer)'s state value. */ -int extcon_register_notifier(struct extcon_dev *edev, enum extcon id, +int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, struct notifier_block *nb) { unsigned long flags; @@ -561,7 +561,7 @@ EXPORT_SYMBOL_GPL(extcon_register_notifier); * @id: the unique id of each external connector in extcon enumeration. * @nb: a notifier block to be registered. */ -int extcon_unregister_notifier(struct extcon_dev *edev, enum extcon id, +int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, struct notifier_block *nb) { unsigned long flags; @@ -623,7 +623,7 @@ static void dummy_sysfs_dev_release(struct device *dev) * * Return the pointer of extcon device if success or ERR_PTR(err) if fail */ -struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable) +struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable) { struct extcon_dev *edev; @@ -677,7 +677,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res) * or ERR_PTR(err) if fail */ struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const enum extcon *supported_cable) + const unsigned int *supported_cable) { struct extcon_dev **ptr, *edev; diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c index 1d1bb9ad8ccf..2f777d22184d 100644 --- a/drivers/usb/phy/phy-tahvo.c +++ b/drivers/usb/phy/phy-tahvo.c @@ -60,7 +60,7 @@ struct tahvo_usb { struct extcon_dev extcon; }; -static const enum extcon tahvo_cable[] = { +static const unsigned int tahvo_cable[] = { EXTCON_USB, EXTCON_USB_HOST, diff --git a/include/linux/extcon.h b/include/linux/extcon.h index a7b224b20ecc..b16d929fa75f 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -30,41 +30,35 @@ #include #include -enum extcon { - EXTCON_NONE = 0x0, - - /* USB external connector */ - EXTCON_USB = 0x1, - EXTCON_USB_HOST = 0x2, - - /* Charger external connector */ - EXTCON_TA = 0x10, - EXTCON_FAST_CHARGER = 0x11, - EXTCON_SLOW_CHARGER = 0x12, - EXTCON_CHARGE_DOWNSTREAM = 0x13, - - /* Audio/Video external connector */ - EXTCON_LINE_IN = 0x20, - EXTCON_LINE_OUT = 0x21, - EXTCON_MICROPHONE = 0x22, - EXTCON_HEADPHONE = 0x23, - - EXTCON_HDMI = 0x30, - EXTCON_MHL = 0x31, - EXTCON_DVI = 0x32, - EXTCON_VGA = 0x33, - EXTCON_SPDIF_IN = 0x34, - EXTCON_SPDIF_OUT = 0x35, - EXTCON_VIDEO_IN = 0x36, - EXTCON_VIDEO_OUT = 0x37, - - /* Etc external connector */ - EXTCON_DOCK = 0x50, - EXTCON_JIG = 0x51, - EXTCON_MECHANICAL = 0x52, - - EXTCON_END, -}; +/* + * Define the unique id of supported external connectors + */ +#define EXTCON_NONE 0 + +#define EXTCON_USB 1 /* USB connector */ +#define EXTCON_USB_HOST 2 + +#define EXTCON_TA 3 /* Charger connector */ +#define EXTCON_FAST_CHARGER 4 +#define EXTCON_SLOW_CHARGER 5 +#define EXTCON_CHARGE_DOWNSTREAM 6 + +#define EXTCON_LINE_IN 7 /* Audio/Video connector */ +#define EXTCON_LINE_OUT 8 +#define EXTCON_MICROPHONE 9 +#define EXTCON_HEADPHONE 10 +#define EXTCON_HDMI 11 +#define EXTCON_MHL 12 +#define EXTCON_DVI 13 +#define EXTCON_VGA 14 +#define EXTCON_SPDIF_IN 15 +#define EXTCON_SPDIF_OUT 16 +#define EXTCON_VIDEO_IN 17 +#define EXTCON_VIDEO_OUT 18 + +#define EXTCON_DOCK 19 /* Misc connector */ +#define EXTCON_JIG 20 +#define EXTCON_MECHANICAL 21 struct extcon_cable; @@ -105,7 +99,7 @@ struct extcon_cable; struct extcon_dev { /* Optional user initializing data */ const char *name; - const enum extcon *supported_cable; + const unsigned int *supported_cable; const u32 *mutually_exclusive; /* Optional callbacks to override class functions */ @@ -182,10 +176,10 @@ extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name); /* * Following APIs control the memory of extcon device. */ -extern struct extcon_dev *extcon_dev_allocate(const enum extcon *cable); +extern struct extcon_dev *extcon_dev_allocate(const unsigned int *cable); extern void extcon_dev_free(struct extcon_dev *edev); extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const enum extcon *cable); + const unsigned int *cable); extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev); /* @@ -206,8 +200,8 @@ extern int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state); * get/set_cable_state access each bit of the 32b encoded state value. * They are used to access the status of each cable based on the cable_name. */ -extern int extcon_get_cable_state_(struct extcon_dev *edev, enum extcon id); -extern int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id, +extern int extcon_get_cable_state_(struct extcon_dev *edev, unsigned int id); +extern int extcon_set_cable_state_(struct extcon_dev *edev, unsigned int id, bool cable_state); extern int extcon_get_cable_state(struct extcon_dev *edev, @@ -234,9 +228,9 @@ extern int extcon_unregister_interest(struct extcon_specific_cable_nb *nb); * we do not recommend to use this for normal 'notifiee' device drivers who * want to be notified by a specific external port of the notifier. */ -extern int extcon_register_notifier(struct extcon_dev *edev, enum extcon id, +extern int extcon_register_notifier(struct extcon_dev *edev, unsigned int id, struct notifier_block *nb); -extern int extcon_unregister_notifier(struct extcon_dev *edev, enum extcon id, +extern int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id, struct notifier_block *nb); /* @@ -266,7 +260,7 @@ static inline int devm_extcon_dev_register(struct device *dev, static inline void devm_extcon_dev_unregister(struct device *dev, struct extcon_dev *edev) { } -static inline struct extcon_dev *extcon_dev_allocate(const enum extcon *cable) +static inline struct extcon_dev *extcon_dev_allocate(const unsigned int *cable) { return ERR_PTR(-ENOSYS); } @@ -274,7 +268,7 @@ static inline struct extcon_dev *extcon_dev_allocate(const enum extcon *cable) static inline void extcon_dev_free(struct extcon_dev *edev) { } static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const enum extcon *cable) + const unsigned int *cable) { return ERR_PTR(-ENOSYS); } @@ -298,13 +292,13 @@ static inline int extcon_update_state(struct extcon_dev *edev, u32 mask, } static inline int extcon_get_cable_state_(struct extcon_dev *edev, - enum extcon id) + unsigned int id) { return 0; } static inline int extcon_set_cable_state_(struct extcon_dev *edev, - enum extcon id, bool cable_state) + unsigned int id, bool cable_state) { return 0; } @@ -327,14 +321,14 @@ static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name) } static inline int extcon_register_notifier(struct extcon_dev *edev, - enum extcon id, + unsigned int id, struct notifier_block *nb) { return 0; } static inline int extcon_unregister_notifier(struct extcon_dev *edev, - enum extcon id, + unsigned int id, struct notifier_block *nb) { return 0; -- cgit v1.2.3-59-g8ed1b